Files
fad_oa/ruoyi-ui/public/file-viewer/assets/TypstViewer-gzZvcE-4.js

60 lines
39 KiB
JavaScript
Raw Normal View History

import{h as e,r as t}from"./package-Bop5TfAT.js";import{C as n,D as r,X as i,Y as a,b as o,f as s,g as c,i as l,r as u,s as d,t as ee,y as f}from"./runtime-core.esm-bundler-DO-WTVbd.js";import{a as p,i as m,n as h,r as g,t as _}from"./wasm-C3ukMqzA.js";import{r as v}from"./printLayout-D2pf0W9y.js";var y=[`DejaVuSansMono-Bold.ttf`,`DejaVuSansMono-BoldOblique.ttf`,`DejaVuSansMono-Oblique.ttf`,`DejaVuSansMono.ttf`,`LibertinusSerif-Bold.otf`,`LibertinusSerif-BoldItalic.otf`,`LibertinusSerif-Italic.otf`,`LibertinusSerif-Regular.otf`,`LibertinusSerif-Semibold.otf`,`LibertinusSerif-SemiboldItalic.otf`,`NewCM10-Bold.otf`,`NewCM10-BoldItalic.otf`,`NewCM10-Italic.otf`,`NewCM10-Regular.otf`,`NewCMMath-Bold.otf`,`NewCMMath-Book.otf`,`NewCMMath-Regular.otf`],b=[`InriaSerif-Bold.ttf`,`InriaSerif-BoldItalic.ttf`,`InriaSerif-Italic.ttf`,`InriaSerif-Regular.ttf`,`Roboto-Regular.ttf`,`NotoSerifCJKsc-Regular.otf`],x=[`TwitterColorEmoji.ttf`,`NotoColorEmoji-Regular-COLR.subset.ttf`];function S(){return T([],{assets:!1})}function C(e){return T([],e)}function w(e){let t=[];if(e&&e?.assets!==!1&&e?.assets?.length&&e?.assets?.length>0){let n={text:`https://cdn.jsdelivr.net/gh/typst/typst-assets@v0.13.1/files/fonts/`,_:`https://cdn.jsdelivr.net/gh/typst/typst-dev-assets@v0.13.1/files/fonts/`},r=e.assetUrlPrefix??n;r=typeof r==`string`?{_:r}:{...n,...r};for(let e of Object.keys(r)){let t=r[e];t[t.length-1]!==`/`&&(r[e]=t+`/`)}let i=(e,t)=>t.map(t=>(r[e]||r._)+t);for(let n of e.assets)switch(n){case`text`:t.push(...i(n,y));break;case`cjk`:t.push(...i(n,b));break;case`emoji`:t.push(...i(n,x));break}}return t}function T(e,t){let n=w(t),r=async(r,{ref:i,builder:a})=>{t?.fetcher&&i.setFetcher(t.fetcher),await i.loadFonts(a,[...e,...n])};return r._preloadRemoteFontOptions=t,r._kind=`fontLoader`,r}function E(e){return async(t,{builder:n})=>new Promise(t=>{n.set_package_registry(e,function(t){return e.resolve(t,this)}),t()})}function D(e){return async(t,n)=>{if(n.alreadySetAccessModel)throw Error(`already set some assess model before: ${n.alreadySetAccessModel.constructor?.name}(${n.alreadySetAccessModel})`);return n.alreadySetAccessModel=e,new Promise(t=>{n.builder.set_access_model(e,t=>{let n=e.getMTime(t);return n?n.getTime():0},t=>e.isFile(t)||!1,t=>e.getRealPath(t)||t,t=>e.readAll(t)),t()})}}var O;(function(e){e[e.vector=0]=`vector`,e[e.pdf=1]=`pdf`,e[e._dummy=2]=`_dummy`})(O||={});var k=class{[g];constructor(e){this[g]=e}reset(){this[g].reset()}current(){return this[g].current()}setAttachDebugInfo(e){this[g].set_attach_debug_info(e)}},A;A||={};function j(){return new F}var M=class{[g];constructor(e){this[g]=e}compile(e){return this[g].compile(0,R(e?.diagnostics))}compileHtml(e){return this[g].compile(1,R(e?.diagnostics))}async query(e){return JSON.parse(this[g].query(0,e.selector,e.field))}title(){return this[g].title(0)}vector(e){return this[g].get_artifact(0,R(e?.diagnostics))||{}}pdf(e){return this[g].get_artifact(1,R(e?.diagnostics))||{}}},N=e=>new _(async t=>await e.default(t));function P(){return new I}var F=class{fontBuilderJs;fontBuilder;async init(e){this.fontBuilderJs=await(e?.getWrapper?.()||t(()=>import(`./wasm-pack-shim-BShYmbRf.js`),[],import.meta.url)),await N(this.fontBuilderJs).init(e?.getModule?.()),this.fontBuilder=new this.fontBuilderJs.TypstFontResolverBuilder}async getFontInfo(e){return this.fontBuilder.get_font_info(e)}async addFontData(e){this.fontBuilder.add_raw_font(e)}async addLazyFont(e,t){return this.fontBuilder.add_lazy_font(e,t)}async build(e){let t=await this.fontBuilder.build(),n=await e(t);return t.free(),n}},I=class e{compiler;compilerJs;static defaultAssets=[`text`];constructor(){}async init(n){this.compilerJs=await(n?.getWrapper?.()||t(()=>import(`./wasm-pack-shim-BShYmbRf.js`),[],import.meta.url));let r=this.compilerJs.TypstCompilerBuilder,i={...n||{}},a=i.beforeBuild??=[],o=a.some(e=>e._preloadRemoteFontOptions!==void 0),s=a.some(e=>e._preloadRemoteFontOptions?.assets!==void 0),c=a.some(e=>e._preloadRemoteFontOptions?.assets===!1);if((!o||!s&&!c)&&a.push(T([],{assets:e.defaultAssets})),!a.some(e=>e._kind===`f
`):e instanceof Error?e.message:String(e),E=u(()=>{if(!p.value.length)return`0 pages`;let e=p.value[0];return`${p.value.length} pages / ${Math.round(e.width)} x ${Math.round(e.height)} pt`}),D=()=>`
<style>
.typst-export-document {
box-sizing: border-box;
display: flex;
flex-direction: column;
align-items: center;
gap: 18px;
margin: 0;
padding: 24px;
background: #eef1f4;
}
.typst-export-page {
box-sizing: border-box;
flex: 0 0 auto;
overflow: hidden;
background: #ffffff;
box-shadow: 0 18px 42px rgba(15, 23, 42, 0.14);
}
.typst-export-page svg {
display: block;
width: 100%;
height: auto;
}
</style>
`,O=()=>`${D()}<main class="typst-export-document" aria-label="${b(t.filename||`Typst document`)}">${p.value.map(e=>{let t=v(e.width),n=v(e.height);return`<section class="typst-export-page viewer-print-page" style="--viewer-print-page-width:${t};--viewer-print-page-height:${n};width:${t};height:${n};" aria-label="Page ${e.index}">${e.svg}</section>`}).join(``)}</main>`,k=()=>{let e=p.value[0],t=e?v(e.width):`596px`;return`
@page { size: ${t} ${e?v(e.height):`842px`}; margin: 0; }
@media print {
html,
body {
width: ${t};
min-width: ${t};
margin: 0 !important;
background: #ffffff !important;
}
.typst-export-document {
display: block !important;
margin: 0 !important;
padding: 0 !important;
background: #ffffff !important;
}
.typst-export-page {
display: block !important;
margin: 0 !important;
border: 0 !important;
box-shadow: none !important;
break-after: page;
page-break-after: always;
}
.typst-export-page:last-child {
break-after: auto;
page-break-after: auto;
}
.typst-export-page svg {
width: 100% !important;
height: auto !important;
}
}
`},A=()=>{if(!t.exportAdapter||!p.value.length){t.exportAdapter?.(null);return}t.exportAdapter({includeDocumentStyles:!1,print:!0,exportHtml:!0,printStyle:k,toHtml:O})};return n(()=>t.source,async()=>{let e=++h;s.value=`loading`,m.value=``,p.value=[],t.exportAdapter?.(null);try{y();let n=await Q.svg({mainContent:t.source,data_selection:{body:!0,defs:!0,css:!0,js:!1}});if(e!==h)return;p.value=w(n),s.value=`ready`,A()}catch(t){if(e!==h)return;m.value=T(t),s.value=`error`}},{immediate:!0}),c(()=>{h+=1,t.exportAdapter?.(null)}),(t,n)=>(f(),d(`div`,pe,[l(`header`,me,[l(`div`,null,[l(`strong`,null,i(e.filename||`Typst document`),1),l(`span`,null,i(s.value===`ready`?E.value:`Typst WASM renderer`),1)]),l(`em`,null,i(s.value===`loading`?`正在编译`:s.value===`error`?`编译失败`:`已渲染`),1)]),s.value===`loading`?(f(),d(`div`,he,[...n[0]||=[l(`span`,{"aria-hidden":`true`},null,-1),l(`strong`,null,`正在解析 Typst`,-1),l(`p`,null,`加载编译器并生成页面预览...`,-1)]])):s.value===`error`?(f(),d(`div`,ge,[n[1]||=l(`strong`,null,`Typst 渲染失败`,-1),l(`pre`,null,i(m.value),1)])):(f(),d(`main`,$,[(f(!0),d(ee,null,o(p.value,e=>(f(),d(`section`,{key:e.index,class:`typst-page-shell`,style:a({"--typst-page-width":`${e.width}px`,"--typst-page-height":`${e.height}px`}),"aria-label":`Page ${e.index}`},[l(`div`,{class:`typst-page-content`,innerHTML:e.svg},null,8,ve)],12,_e))),128))]))]))}}),[[`__scopeId`,`data-v-7e2db9f8`]]);export{le as a,F as c,j as d,be as default,ce as i,M as l,J as n,O as o,K as r,k as s,W as t,P as u};