@vedivad/typst-web-service 0.15.4 → 0.17.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +68 -74
- package/dist/index.d.ts +89 -481
- package/dist/index.js +298 -635
- package/dist/index.js.map +1 -1
- package/dist/typsten-worker.js +509 -0
- package/dist/typsten-worker.js.map +1 -0
- package/dist/typsten_bg.wasm +0 -0
- package/package.json +5 -17
- package/dist/analyzer-worker.js +0 -1045
- package/dist/analyzer-worker.js.map +0 -1
- package/dist/compiler-worker.js +0 -2207
- package/dist/compiler-worker.js.map +0 -1
- package/dist/renderer-worker.js +0 -5261
- package/dist/renderer-worker.js.map +0 -1
package/dist/index.js
CHANGED
|
@@ -1,310 +1,74 @@
|
|
|
1
|
-
// src/
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const blob = new Blob([code], { type: "application/javascript" });
|
|
7
|
-
const url = URL.createObjectURL(blob);
|
|
8
|
-
const worker = new Worker(url);
|
|
9
|
-
const origTerminate = worker.terminate.bind(worker);
|
|
10
|
-
worker.terminate = () => {
|
|
11
|
-
origTerminate();
|
|
12
|
-
URL.revokeObjectURL(url);
|
|
13
|
-
};
|
|
14
|
-
return worker;
|
|
1
|
+
// src/coords.ts
|
|
2
|
+
var encoder = new TextEncoder();
|
|
3
|
+
var decoder = new TextDecoder();
|
|
4
|
+
function cmOffsetToByte(text, offset) {
|
|
5
|
+
return encoder.encode(text.slice(0, offset)).length;
|
|
15
6
|
}
|
|
16
|
-
function
|
|
17
|
-
return createBlobWorker('"use strict";(()=>{var ne=Object.defineProperty;var vt=(e,t)=>()=>(e&&(t=e(e=0)),t);var re=(e,t)=>{for(var n in t)ne(e,n,{get:t[n],enumerable:!0})};function f(e){N===S.length&&S.push(S.length+1);let t=N;return N=S[t],S[t]=e,t}function gt(e,t){if(!(e instanceof t))throw new Error(`expected instance of ${t.name}`)}function lt(e){let t=typeof e;if(t=="number"||t=="boolean"||e==null)return`${e}`;if(t=="string")return`"${e}"`;if(t=="symbol"){let o=e.description;return o==null?"Symbol":`Symbol(${o})`}if(t=="function"){let o=e.name;return typeof o=="string"&&o.length>0?`Function(${o})`:"Function"}if(Array.isArray(e)){let o=e.length,s="[";o>0&&(s+=lt(e[0]));for(let _=1;_<o;_++)s+=", "+lt(e[_]);return s+="]",s}let n=/\\[object ([^\\]]+)\\]/.exec(toString.call(e)),r;if(n&&n.length>1)r=n[1];else return toString.call(e);if(r=="Object")try{return"Object("+JSON.stringify(e)+")"}catch{return"Object"}return e instanceof Error?`${e.name}: ${e.message}\n${e.stack}`:r}function Ie(e){e<132||(S[e]=N,N=e)}function ke(e,t){e=e>>>0;let n=a(),r=[];for(let o=e;o<e+4*t;o+=4)r.push(l(n.getUint32(o,!0)));return r}function Se(e,t){return e=e>>>0,Fe().subarray(e/4,e/4+t)}function wt(e,t){return e=e>>>0,C().subarray(e/1,e/1+t)}function a(){return(R===null||R.buffer.detached===!0||R.buffer.detached===void 0&&R.buffer!==i.memory.buffer)&&(R=new DataView(i.memory.buffer)),R}function I(e,t){return e=e>>>0,Me(e,t)}function Fe(){return(U===null||U.byteLength===0)&&(U=new Uint32Array(i.memory.buffer)),U}function C(){return(W===null||W.byteLength===0)&&(W=new Uint8Array(i.memory.buffer)),W}function u(e){return S[e]}function T(e,t){try{return e.apply(this,t)}catch(n){i.__wbindgen_export3(f(n))}}function v(e){return e==null}function Ae(e,t,n,r){let o={a:e,b:t,cnt:1,dtor:n},s=(..._)=>{o.cnt++;let c=o.a;o.a=0;try{return r(c,o.b,..._)}finally{o.a=c,s._wbg_cb_unref()}};return s._wbg_cb_unref=()=>{--o.cnt===0&&(o.dtor(o.a,o.b),o.a=0,Ot.unregister(o))},Ot.register(s,o,o),s}function Ut(e,t){let n=t(e.length*1,1)>>>0;return C().set(e,n/1),b=e.length,n}function nt(e,t){let n=t(e.length*4,4)>>>0,r=a();for(let o=0;o<e.length;o++)r.setUint32(n+4*o,f(e[o]),!0);return b=e.length,n}function h(e,t,n){if(n===void 0){let c=q.encode(e),d=t(c.length,1)>>>0;return C().subarray(d,d+c.length).set(c),b=c.length,d}let r=e.length,o=t(r,1)>>>0,s=C(),_=0;for(;_<r;_++){let c=e.charCodeAt(_);if(c>127)break;s[o+_]=c}if(_!==r){_!==0&&(e=e.slice(_)),o=n(o,r,r=_+e.length*3,1)>>>0;let c=C().subarray(o+_,o+r),d=q.encodeInto(e,c);_+=d.written,o=n(o,r,_,1)>>>0}return b=_,o}function l(e){let t=u(e);return Ie(e),t}function Me(e,t){return ft+=t,ft>=Re&&(rt=new TextDecoder("utf-8",{ignoreBOM:!0,fatal:!0}),rt.decode(),ft=t),rt.decode(C().subarray(e,e+t))}function Ee(e,t,n){i.__wasm_bindgen_func_elem_944(e,t,f(n))}function Te(e,t,n,r){i.__wasm_bindgen_func_elem_37348(e,t,f(n),f(r))}function Ce(e){let t=i.get_font_info(f(e));return l(t)}async function Pe(e,t){if(typeof Response=="function"&&e instanceof Response){if(typeof WebAssembly.instantiateStreaming=="function")try{return await WebAssembly.instantiateStreaming(e,t)}catch(r){if(e.ok&&Oe.has(e.type)&&e.headers.get("Content-Type")!=="application/wasm")console.warn("`WebAssembly.instantiateStreaming` failed because your server does not serve Wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\\n",r);else throw r}let n=await e.arrayBuffer();return await WebAssembly.instantiate(n,t)}else{let n=await WebAssembly.instantiate(e,t);return n instanceof WebAssembly.Instance?{instance:n,module:e}:n}}function Wt(){let e={};return e.wbg={},e.wbg.__wbg_Error_52673b7de5a0ca89=function(t,n){let r=Error(I(t,n));return f(r)},e.wbg.__wbg_Number_2d1dcfcf4ec51736=function(t){return Number(u(t))},e.wbg.__wbg___wbindgen_bigint_get_as_i64_6e32f5e6aff02e1d=function(t,n){let r=u(n),o=typeof r=="bigint"?r:void 0;a().setBigInt64(t+8,v(o)?BigInt(0):o,!0),a().setInt32(t+0,!v(o),!0)},e.wbg.__wbg___wbindgen_boolean_get_dea25b33882b895b=function(t){let n=u(t),r=typeof n=="boolean"?n:void 0;return v(r)?16777215:r?1:0},e.wbg.__wbg___wbindgen_debug_string_adfb662ae34724b6=function(t,n){let r=lt(u(n)),o=h(r,i.__wbindgen_export,i.__wbindgen_export2),s=b;a().setInt32(t+4,s,!0),a().setInt32(t+0,o,!0)},e.wbg.__wbg___wbindgen_in_0d3e1e8f0c669317=function(t,n){return u(t)in u(n)},e.wbg.__wbg___wbindgen_is_bigint_0e1a2e3f55cfae27=function(t){return typeof u(t)=="bigint"},e.wbg.__wbg___wbindgen_is_function_8d400b8b1af978cd=function(t){return typeof u(t)=="function"},e.wbg.__wbg___wbindgen_is_object_ce774f3490692386=function(t){let n=u(t);return typeof n=="object"&&n!==null},e.wbg.__wbg___wbindgen_is_string_704ef9c8fc131030=function(t){return typeof u(t)=="string"},e.wbg.__wbg___wbindgen_is_undefined_f6b95eab589e0269=function(t){return u(t)===void 0},e.wbg.__wbg___wbindgen_jsval_eq_b6101cc9cef1fe36=function(t,n){return u(t)===u(n)},e.wbg.__wbg___wbindgen_jsval_loose_eq_766057600fdd1b0d=function(t,n){return u(t)==u(n)},e.wbg.__wbg___wbindgen_number_get_9619185a74197f95=function(t,n){let r=u(n),o=typeof r=="number"?r:void 0;a().setFloat64(t+8,v(o)?0:o,!0),a().setInt32(t+0,!v(o),!0)},e.wbg.__wbg___wbindgen_string_get_a2a31e16edf96e42=function(t,n){let r=u(n),o=typeof r=="string"?r:void 0;var s=v(o)?0:h(o,i.__wbindgen_export,i.__wbindgen_export2),_=b;a().setInt32(t+4,_,!0),a().setInt32(t+0,s,!0)},e.wbg.__wbg___wbindgen_throw_dd24417ed36fc46e=function(t,n){throw new Error(I(t,n))},e.wbg.__wbg__wbg_cb_unref_87dfb5aaa0cbcea7=function(t){u(t)._wbg_cb_unref()},e.wbg.__wbg_call_3020136f7a2d6e44=function(){return T(function(t,n,r){let o=u(t).call(u(n),u(r));return f(o)},arguments)},e.wbg.__wbg_call_78f94eb02ec7f9b2=function(){return T(function(t,n,r,o,s){let _=u(t).call(u(n),u(r),u(o),u(s));return f(_)},arguments)},e.wbg.__wbg_call_abb4ff46ce38be40=function(){return T(function(t,n){let r=u(t).call(u(n));return f(r)},arguments)},e.wbg.__wbg_done_62ea16af4ce34b24=function(t){return u(t).done},e.wbg.__wbg_entries_83c79938054e065f=function(t){let n=Object.entries(u(t));return f(n)},e.wbg.__wbg_error_7534b8e9a36f1ab4=function(t,n){let r,o;try{r=t,o=n,console.error(I(t,n))}finally{i.__wbindgen_export4(r,o,1)}},e.wbg.__wbg_error_85faeb8919b11cc6=function(t,n,r){console.error(u(t),u(n),u(r))},e.wbg.__wbg_getTimezoneOffset_45389e26d6f46823=function(t){return u(t).getTimezoneOffset()},e.wbg.__wbg_get_6b7bd52aca3f9671=function(t,n){let r=u(t)[n>>>0];return f(r)},e.wbg.__wbg_get_af9dab7e9603ea93=function(){return T(function(t,n){let r=Reflect.get(u(t),u(n));return f(r)},arguments)},e.wbg.__wbg_get_with_ref_key_1dc361bd10053bfe=function(t,n){let r=u(t)[u(n)];return f(r)},e.wbg.__wbg_info_ce6bcc489c22f6f0=function(t){console.info(u(t))},e.wbg.__wbg_instanceof_ArrayBuffer_f3320d2419cd0355=function(t){let n;try{n=u(t)instanceof ArrayBuffer}catch{n=!1}return n},e.wbg.__wbg_instanceof_Map_084be8da74364158=function(t){let n;try{n=u(t)instanceof Map}catch{n=!1}return n},e.wbg.__wbg_instanceof_Uint8Array_da54ccc9d3e09434=function(t){let n;try{n=u(t)instanceof Uint8Array}catch{n=!1}return n},e.wbg.__wbg_isArray_51fd9e6422c0a395=function(t){return Array.isArray(u(t))},e.wbg.__wbg_isSafeInteger_ae7d3f054d55fa16=function(t){return Number.isSafeInteger(u(t))},e.wbg.__wbg_iterator_27b7c8b35ab3e86b=function(){return f(Symbol.iterator)},e.wbg.__wbg_length_22ac23eaec9d8053=function(t){return u(t).length},e.wbg.__wbg_length_d45040a40c570362=function(t){return u(t).length},e.wbg.__wbg_new_1ba21ce319a06297=function(){let t=new Object;return f(t)},e.wbg.__wbg_new_25f239778d6112b9=function(){let t=new Array;return f(t)},e.wbg.__wbg_new_6421f6084cc5bc5a=function(t){let n=new Uint8Array(u(t));return f(n)},e.wbg.__wbg_new_8a6f238a6ece86ea=function(){let t=new Error;return f(t)},e.wbg.__wbg_new_b2db8aa2650f793a=function(t){let n=new Date(u(t));return f(n)},e.wbg.__wbg_new_df1173567d5ff028=function(t,n){let r=new Error(I(t,n));return f(r)},e.wbg.__wbg_new_ff12d2b041fb48f1=function(t,n){try{var r={a:t,b:n},o=(_,c)=>{let d=r.a;r.a=0;try{return Te(d,r.b,_,c)}finally{r.a=d}};let s=new Promise(o);return f(s)}finally{r.a=r.b=0}},e.wbg.__wbg_new_from_slice_db0691b69e9d3891=function(t,n){let r=new Uint32Array(Se(t,n));return f(r)},e.wbg.__wbg_new_from_slice_f9c22b9153b26992=function(t,n){let r=new Uint8Array(wt(t,n));return f(r)},e.wbg.__wbg_new_no_args_cb138f77cf6151ee=function(t,n){let r=new Function(I(t,n));return f(r)},e.wbg.__wbg_new_with_args_df9e7125ffe55248=function(t,n,r,o){let s=new Function(I(t,n),I(r,o));return f(s)},e.wbg.__wbg_next_138a17bbf04e926c=function(t){let n=u(t).next;return f(n)},e.wbg.__wbg_next_3cfe5c0fe2a4cc53=function(){return T(function(t){let n=u(t).next();return f(n)},arguments)},e.wbg.__wbg_now_69d776cd24f5215b=function(){return Date.now()},e.wbg.__wbg_prototypesetcall_dfe9b766cdc1f1fd=function(t,n,r){Uint8Array.prototype.set.call(wt(t,n),u(r))},e.wbg.__wbg_proxycontext_new=function(t){let n=O.__wrap(t);return f(n)},e.wbg.__wbg_push_7d9be8f38fc13975=function(t,n){return u(t).push(u(n))},e.wbg.__wbg_queueMicrotask_9b549dfce8865860=function(t){let n=u(t).queueMicrotask;return f(n)},e.wbg.__wbg_queueMicrotask_fca69f5bfad613a5=function(t){queueMicrotask(u(t))},e.wbg.__wbg_resolve_fd5bfbaa4ce36e1e=function(t){let n=Promise.resolve(u(t));return f(n)},e.wbg.__wbg_set_3f1d0b984ed272ed=function(t,n,r){u(t)[l(n)]=l(r)},e.wbg.__wbg_set_781438a03c0c3c81=function(){return T(function(t,n,r){return Reflect.set(u(t),u(n),u(r))},arguments)},e.wbg.__wbg_set_7df433eea03a5c14=function(t,n,r){u(t)[n>>>0]=l(r)},e.wbg.__wbg_stack_0ed75d68575b0f3c=function(t,n){let r=u(n).stack,o=h(r,i.__wbindgen_export,i.__wbindgen_export2),s=b;a().setInt32(t+4,s,!0),a().setInt32(t+0,o,!0)},e.wbg.__wbg_static_accessor_GLOBAL_769e6b65d6557335=function(){let t=typeof global>"u"?null:global;return v(t)?0:f(t)},e.wbg.__wbg_static_accessor_GLOBAL_THIS_60cf02db4de8e1c1=function(){let t=typeof globalThis>"u"?null:globalThis;return v(t)?0:f(t)},e.wbg.__wbg_static_accessor_SELF_08f5a74c69739274=function(){let t=typeof self>"u"?null:self;return v(t)?0:f(t)},e.wbg.__wbg_static_accessor_WINDOW_a8924b26aa92d024=function(){let t=typeof window>"u"?null:window;return v(t)?0:f(t)},e.wbg.__wbg_then_4f95312d68691235=function(t,n){let r=u(t).then(u(n));return f(r)},e.wbg.__wbg_typstcompiler_new=function(t){let n=j.__wrap(t);return f(n)},e.wbg.__wbg_typstfontresolver_new=function(t){let n=M.__wrap(t);return f(n)},e.wbg.__wbg_value_57b7b035e117f7ee=function(t){let n=u(t).value;return f(n)},e.wbg.__wbindgen_cast_2241b6af4c4b2941=function(t,n){let r=I(t,n);return f(r)},e.wbg.__wbindgen_cast_3334ea73b4b28ba3=function(t,n){let r=Ae(t,n,i.__wasm_bindgen_func_elem_957,Ee);return f(r)},e.wbg.__wbindgen_cast_4625c577ab2ec9ee=function(t){let n=BigInt.asUintN(64,t);return f(n)},e.wbg.__wbindgen_cast_9ae0607507abb057=function(t){return f(t)},e.wbg.__wbindgen_cast_d6cd19b81560fd6e=function(t){return f(t)},e.wbg.__wbindgen_object_clone_ref=function(t){let n=u(t);return f(n)},e.wbg.__wbindgen_object_drop_ref=function(t){l(t)},e}function Nt(e,t){return i=e.exports,qt.__wbindgen_wasm_module=t,R=null,U=null,W=null,i}function je(e){if(i!==void 0)return i;typeof e<"u"&&(Object.getPrototypeOf(e)===Object.prototype?{module:e}=e:console.warn("using deprecated parameters for `initSync()`; pass a single object instead"));let t=Wt();e instanceof WebAssembly.Module||(e=new WebAssembly.Module(e));let n=new WebAssembly.Instance(e,t);return Nt(n,e)}async function qt(e){if(i!==void 0)return i;typeof e<"u"&&(Object.getPrototypeOf(e)===Object.prototype?{module_or_path:e}=e:console.warn("using deprecated parameters for the initialization function; pass a single object instead")),typeof e>"u"&&(e=$t("typst_ts_web_compiler_bg.wasm",Le.url));let t=Wt();(typeof e=="string"||typeof Request=="function"&&e instanceof Request||typeof URL=="function"&&e instanceof URL)&&(e=fetch(e));let{instance:n,module:r}=await Pe(await e,t);return Nt(n,r)}function pt(e){$t=e}var Le,i,Ot,R,U,W,S,N,rt,Re,ft,q,b,Pt,dt,jt,Lt,Bt,Dt,zt,F,O,P,j,V,M,$,Oe,Vt,$t,ot=vt(()=>{Le={};Ot=typeof FinalizationRegistry>"u"?{register:()=>{},unregister:()=>{}}:new FinalizationRegistry(e=>e.dtor(e.a,e.b));R=null;U=null;W=null;S=new Array(128).fill(void 0);S.push(void 0,null,!0,!1);N=S.length;rt=new TextDecoder("utf-8",{ignoreBOM:!0,fatal:!0});rt.decode();Re=2146435072,ft=0;q=new TextEncoder;"encodeInto"in q||(q.encodeInto=function(e,t){let n=q.encode(e);return t.set(n),{read:e.length,written:n.length}});b=0;Pt=typeof FinalizationRegistry>"u"?{register:()=>{},unregister:()=>{}}:new FinalizationRegistry(e=>i.__wbg_incrserver_free(e>>>0,1)),dt=typeof FinalizationRegistry>"u"?{register:()=>{},unregister:()=>{}}:new FinalizationRegistry(e=>i.__wbg_proxycontext_free(e>>>0,1)),jt=typeof FinalizationRegistry>"u"?{register:()=>{},unregister:()=>{}}:new FinalizationRegistry(e=>i.__wbg_typstcompileworld_free(e>>>0,1)),Lt=typeof FinalizationRegistry>"u"?{register:()=>{},unregister:()=>{}}:new FinalizationRegistry(e=>i.__wbg_typstcompiler_free(e>>>0,1)),Bt=typeof FinalizationRegistry>"u"?{register:()=>{},unregister:()=>{}}:new FinalizationRegistry(e=>i.__wbg_typstcompilerbuilder_free(e>>>0,1)),Dt=typeof FinalizationRegistry>"u"?{register:()=>{},unregister:()=>{}}:new FinalizationRegistry(e=>i.__wbg_typstfontresolver_free(e>>>0,1)),zt=typeof FinalizationRegistry>"u"?{register:()=>{},unregister:()=>{}}:new FinalizationRegistry(e=>i.__wbg_typstfontresolverbuilder_free(e>>>0,1)),F=class e{static __wrap(t){t=t>>>0;let n=Object.create(e.prototype);return n.__wbg_ptr=t,Pt.register(n,n.__wbg_ptr,n),n}__destroy_into_raw(){let t=this.__wbg_ptr;return this.__wbg_ptr=0,Pt.unregister(this),t}free(){let t=this.__destroy_into_raw();i.__wbg_incrserver_free(t,0)}set_attach_debug_info(t){i.incrserver_set_attach_debug_info(this.__wbg_ptr,t)}current(){try{let r=i.__wbindgen_add_to_stack_pointer(-16);i.incrserver_current(r,this.__wbg_ptr);var t=a().getInt32(r+0,!0),n=a().getInt32(r+4,!0);let o;return t!==0&&(o=wt(t,n).slice(),i.__wbindgen_export4(t,n*1,1)),o}finally{i.__wbindgen_add_to_stack_pointer(16)}}reset(){i.incrserver_reset(this.__wbg_ptr)}};Symbol.dispose&&(F.prototype[Symbol.dispose]=F.prototype.free);O=class e{static __wrap(t){t=t>>>0;let n=Object.create(e.prototype);return n.__wbg_ptr=t,dt.register(n,n.__wbg_ptr,n),n}__destroy_into_raw(){let t=this.__wbg_ptr;return this.__wbg_ptr=0,dt.unregister(this),t}free(){let t=this.__destroy_into_raw();i.__wbg_proxycontext_free(t,0)}constructor(t){let n=i.proxycontext_new(f(t));return this.__wbg_ptr=n>>>0,dt.register(this,this.__wbg_ptr,this),this}get context(){let t=i.proxycontext_context(this.__wbg_ptr);return l(t)}untar(t,n){try{let s=i.__wbindgen_add_to_stack_pointer(-16),_=Ut(t,i.__wbindgen_export),c=b;i.proxycontext_untar(s,this.__wbg_ptr,_,c,f(n));var r=a().getInt32(s+0,!0),o=a().getInt32(s+4,!0);if(o)throw l(r)}finally{i.__wbindgen_add_to_stack_pointer(16)}}};Symbol.dispose&&(O.prototype[Symbol.dispose]=O.prototype.free);P=class e{static __wrap(t){t=t>>>0;let n=Object.create(e.prototype);return n.__wbg_ptr=t,jt.register(n,n.__wbg_ptr,n),n}__destroy_into_raw(){let t=this.__wbg_ptr;return this.__wbg_ptr=0,jt.unregister(this),t}free(){let t=this.__destroy_into_raw();i.__wbg_typstcompileworld_free(t,0)}compile(t,n){try{let _=i.__wbindgen_add_to_stack_pointer(-16);i.typstcompileworld_compile(_,this.__wbg_ptr,t,n);var r=a().getInt32(_+0,!0),o=a().getInt32(_+4,!0),s=a().getInt32(_+8,!0);if(s)throw l(o);return l(r)}finally{i.__wbindgen_add_to_stack_pointer(16)}}title(t){try{let _=i.__wbindgen_add_to_stack_pointer(-16);i.typstcompileworld_title(_,this.__wbg_ptr,t);var n=a().getInt32(_+0,!0),r=a().getInt32(_+4,!0),o=a().getInt32(_+8,!0),s=a().getInt32(_+12,!0);if(s)throw l(o);let c;return n!==0&&(c=I(n,r).slice(),i.__wbindgen_export4(n,r*1,1)),c}finally{i.__wbindgen_add_to_stack_pointer(16)}}get_artifact(t,n){try{let _=i.__wbindgen_add_to_stack_pointer(-16);i.typstcompileworld_get_artifact(_,this.__wbg_ptr,t,n);var r=a().getInt32(_+0,!0),o=a().getInt32(_+4,!0),s=a().getInt32(_+8,!0);if(s)throw l(o);return l(r)}finally{i.__wbindgen_add_to_stack_pointer(16)}}query(t,n,r){let o,s;try{let k=i.__wbindgen_add_to_stack_pointer(-16),B=h(n,i.__wbindgen_export,i.__wbindgen_export2),D=b;var _=v(r)?0:h(r,i.__wbindgen_export,i.__wbindgen_export2),c=b;i.typstcompileworld_query(k,this.__wbg_ptr,t,B,D,_,c);var d=a().getInt32(k+0,!0),g=a().getInt32(k+4,!0),w=a().getInt32(k+8,!0),y=a().getInt32(k+12,!0),p=d,m=g;if(y)throw p=0,m=0,l(w);return o=p,s=m,I(p,m)}finally{i.__wbindgen_add_to_stack_pointer(16),i.__wbindgen_export4(o,s,1)}}incr_compile(t,n){try{let _=i.__wbindgen_add_to_stack_pointer(-16);gt(t,F),i.typstcompileworld_incr_compile(_,this.__wbg_ptr,t.__wbg_ptr,n);var r=a().getInt32(_+0,!0),o=a().getInt32(_+4,!0),s=a().getInt32(_+8,!0);if(s)throw l(o);return l(r)}finally{i.__wbindgen_add_to_stack_pointer(16)}}};Symbol.dispose&&(P.prototype[Symbol.dispose]=P.prototype.free);j=class e{static __wrap(t){t=t>>>0;let n=Object.create(e.prototype);return n.__wbg_ptr=t,Lt.register(n,n.__wbg_ptr,n),n}__destroy_into_raw(){let t=this.__wbg_ptr;return this.__wbg_ptr=0,Lt.unregister(this),t}free(){let t=this.__destroy_into_raw();i.__wbg_typstcompiler_free(t,0)}reset(){try{let r=i.__wbindgen_add_to_stack_pointer(-16);i.typstcompiler_reset(r,this.__wbg_ptr);var t=a().getInt32(r+0,!0),n=a().getInt32(r+4,!0);if(n)throw l(t)}finally{i.__wbindgen_add_to_stack_pointer(16)}}set_fonts(t){try{let o=i.__wbindgen_add_to_stack_pointer(-16);gt(t,M),i.typstcompiler_set_fonts(o,this.__wbg_ptr,t.__wbg_ptr);var n=a().getInt32(o+0,!0),r=a().getInt32(o+4,!0);if(r)throw l(n)}finally{i.__wbindgen_add_to_stack_pointer(16)}}set_inputs(t){try{let o=i.__wbindgen_add_to_stack_pointer(-16);i.typstcompiler_set_inputs(o,this.__wbg_ptr,f(t));var n=a().getInt32(o+0,!0),r=a().getInt32(o+4,!0);if(r)throw l(n)}finally{i.__wbindgen_add_to_stack_pointer(16)}}add_source(t,n){let r=h(t,i.__wbindgen_export,i.__wbindgen_export2),o=b,s=h(n,i.__wbindgen_export,i.__wbindgen_export2),_=b;return i.typstcompiler_add_source(this.__wbg_ptr,r,o,s,_)!==0}map_shadow(t,n){let r=h(t,i.__wbindgen_export,i.__wbindgen_export2),o=b,s=Ut(n,i.__wbindgen_export),_=b;return i.typstcompiler_map_shadow(this.__wbg_ptr,r,o,s,_)!==0}unmap_shadow(t){let n=h(t,i.__wbindgen_export,i.__wbindgen_export2),r=b;return i.typstcompiler_unmap_shadow(this.__wbg_ptr,n,r)!==0}reset_shadow(){i.typstcompiler_reset_shadow(this.__wbg_ptr)}get_loaded_fonts(){try{let o=i.__wbindgen_add_to_stack_pointer(-16);i.typstcompiler_get_loaded_fonts(o,this.__wbg_ptr);var t=a().getInt32(o+0,!0),n=a().getInt32(o+4,!0),r=ke(t,n).slice();return i.__wbindgen_export4(t,n*4,4),r}finally{i.__wbindgen_add_to_stack_pointer(16)}}get_ast(t){let n,r;try{let w=i.__wbindgen_add_to_stack_pointer(-16),y=h(t,i.__wbindgen_export,i.__wbindgen_export2),p=b;i.typstcompiler_get_ast(w,this.__wbg_ptr,y,p);var o=a().getInt32(w+0,!0),s=a().getInt32(w+4,!0),_=a().getInt32(w+8,!0),c=a().getInt32(w+12,!0),d=o,g=s;if(c)throw d=0,g=0,l(_);return n=d,r=g,I(d,g)}finally{i.__wbindgen_add_to_stack_pointer(16),i.__wbindgen_export4(n,r,1)}}get_semantic_token_legend(){try{let o=i.__wbindgen_add_to_stack_pointer(-16);i.typstcompiler_get_semantic_token_legend(o,this.__wbg_ptr);var t=a().getInt32(o+0,!0),n=a().getInt32(o+4,!0),r=a().getInt32(o+8,!0);if(r)throw l(n);return l(t)}finally{i.__wbindgen_add_to_stack_pointer(16)}}get_semantic_tokens(t,n,r){try{let y=i.__wbindgen_add_to_stack_pointer(-16),p=h(t,i.__wbindgen_export,i.__wbindgen_export2),m=b;var o=v(n)?0:h(n,i.__wbindgen_export,i.__wbindgen_export2),s=b,_=v(r)?0:h(r,i.__wbindgen_export,i.__wbindgen_export2),c=b;i.typstcompiler_get_semantic_tokens(y,this.__wbg_ptr,p,m,o,s,_,c);var d=a().getInt32(y+0,!0),g=a().getInt32(y+4,!0),w=a().getInt32(y+8,!0);if(w)throw l(g);return l(d)}finally{i.__wbindgen_add_to_stack_pointer(16)}}snapshot(t,n,r){try{let m=i.__wbindgen_add_to_stack_pointer(-16);var o=v(t)?0:h(t,i.__wbindgen_export,i.__wbindgen_export2),s=b,_=v(n)?0:h(n,i.__wbindgen_export,i.__wbindgen_export2),c=b,d=v(r)?0:nt(r,i.__wbindgen_export),g=b;i.typstcompiler_snapshot(m,this.__wbg_ptr,o,s,_,c,d,g);var w=a().getInt32(m+0,!0),y=a().getInt32(m+4,!0),p=a().getInt32(m+8,!0);if(p)throw l(y);return P.__wrap(w)}finally{i.__wbindgen_add_to_stack_pointer(16)}}get_artifact(t,n){try{let _=i.__wbindgen_add_to_stack_pointer(-16),c=h(t,i.__wbindgen_export,i.__wbindgen_export2),d=b;i.typstcompiler_get_artifact(_,this.__wbg_ptr,c,d,n);var r=a().getInt32(_+0,!0),o=a().getInt32(_+4,!0),s=a().getInt32(_+8,!0);if(s)throw l(o);return l(r)}finally{i.__wbindgen_add_to_stack_pointer(16)}}compile(t,n,r,o){try{let p=i.__wbindgen_add_to_stack_pointer(-16);var s=v(t)?0:h(t,i.__wbindgen_export,i.__wbindgen_export2),_=b,c=v(n)?0:nt(n,i.__wbindgen_export),d=b;let m=h(r,i.__wbindgen_export,i.__wbindgen_export2),k=b;i.typstcompiler_compile(p,this.__wbg_ptr,s,_,c,d,m,k,o);var g=a().getInt32(p+0,!0),w=a().getInt32(p+4,!0),y=a().getInt32(p+8,!0);if(y)throw l(w);return l(g)}finally{i.__wbindgen_add_to_stack_pointer(16)}}query(t,n,r,o){let s,_;try{let z=i.__wbindgen_add_to_stack_pointer(-16),Qt=h(t,i.__wbindgen_export,i.__wbindgen_export2),Zt=b;var c=v(n)?0:nt(n,i.__wbindgen_export),d=b;let te=h(r,i.__wbindgen_export,i.__wbindgen_export2),ee=b;var g=v(o)?0:h(o,i.__wbindgen_export,i.__wbindgen_export2),w=b;i.typstcompiler_query(z,this.__wbg_ptr,Qt,Zt,c,d,te,ee,g,w);var y=a().getInt32(z+0,!0),p=a().getInt32(z+4,!0),m=a().getInt32(z+8,!0),k=a().getInt32(z+12,!0),B=y,D=p;if(k)throw B=0,D=0,l(m);return s=B,_=D,I(B,D)}finally{i.__wbindgen_add_to_stack_pointer(16),i.__wbindgen_export4(s,_,1)}}create_incr_server(){try{let o=i.__wbindgen_add_to_stack_pointer(-16);i.typstcompiler_create_incr_server(o,this.__wbg_ptr);var t=a().getInt32(o+0,!0),n=a().getInt32(o+4,!0),r=a().getInt32(o+8,!0);if(r)throw l(n);return F.__wrap(t)}finally{i.__wbindgen_add_to_stack_pointer(16)}}incr_compile(t,n,r,o){try{let w=i.__wbindgen_add_to_stack_pointer(-16),y=h(t,i.__wbindgen_export,i.__wbindgen_export2),p=b;var s=v(n)?0:nt(n,i.__wbindgen_export),_=b;gt(r,F),i.typstcompiler_incr_compile(w,this.__wbg_ptr,y,p,s,_,r.__wbg_ptr,o);var c=a().getInt32(w+0,!0),d=a().getInt32(w+4,!0),g=a().getInt32(w+8,!0);if(g)throw l(d);return l(c)}finally{i.__wbindgen_add_to_stack_pointer(16)}}};Symbol.dispose&&(j.prototype[Symbol.dispose]=j.prototype.free);V=class{__destroy_into_raw(){let t=this.__wbg_ptr;return this.__wbg_ptr=0,Bt.unregister(this),t}free(){let t=this.__destroy_into_raw();i.__wbg_typstcompilerbuilder_free(t,0)}constructor(){try{let o=i.__wbindgen_add_to_stack_pointer(-16);i.typstcompilerbuilder_new(o);var t=a().getInt32(o+0,!0),n=a().getInt32(o+4,!0),r=a().getInt32(o+8,!0);if(r)throw l(n);return this.__wbg_ptr=t>>>0,Bt.register(this,this.__wbg_ptr,this),this}finally{i.__wbindgen_add_to_stack_pointer(16)}}set_dummy_access_model(){try{let r=i.__wbindgen_add_to_stack_pointer(-16);i.typstcompilerbuilder_set_dummy_access_model(r,this.__wbg_ptr);var t=a().getInt32(r+0,!0),n=a().getInt32(r+4,!0);if(n)throw l(t)}finally{i.__wbindgen_add_to_stack_pointer(16)}}set_access_model(t,n,r,o,s){let _=i.typstcompilerbuilder_set_access_model(this.__wbg_ptr,f(t),f(n),f(r),f(o),f(s));return l(_)}set_package_registry(t,n){let r=i.typstcompilerbuilder_set_package_registry(this.__wbg_ptr,f(t),f(n));return l(r)}add_raw_font(t){let n=i.typstcompilerbuilder_add_raw_font(this.__wbg_ptr,f(t));return l(n)}add_lazy_font(t,n){let r=i.typstcompilerbuilder_add_lazy_font(this.__wbg_ptr,f(t),f(n));return l(r)}build(){let t=this.__destroy_into_raw(),n=i.typstcompilerbuilder_build(t);return l(n)}};Symbol.dispose&&(V.prototype[Symbol.dispose]=V.prototype.free);M=class e{static __wrap(t){t=t>>>0;let n=Object.create(e.prototype);return n.__wbg_ptr=t,Dt.register(n,n.__wbg_ptr,n),n}__destroy_into_raw(){let t=this.__wbg_ptr;return this.__wbg_ptr=0,Dt.unregister(this),t}free(){let t=this.__destroy_into_raw();i.__wbg_typstfontresolver_free(t,0)}};Symbol.dispose&&(M.prototype[Symbol.dispose]=M.prototype.free);$=class{__destroy_into_raw(){let t=this.__wbg_ptr;return this.__wbg_ptr=0,zt.unregister(this),t}free(){let t=this.__destroy_into_raw();i.__wbg_typstfontresolverbuilder_free(t,0)}constructor(){try{let o=i.__wbindgen_add_to_stack_pointer(-16);i.typstfontresolverbuilder_new(o);var t=a().getInt32(o+0,!0),n=a().getInt32(o+4,!0),r=a().getInt32(o+8,!0);if(r)throw l(n);return this.__wbg_ptr=t>>>0,zt.register(this,this.__wbg_ptr,this),this}finally{i.__wbindgen_add_to_stack_pointer(16)}}get_font_info(t){try{let s=i.__wbindgen_add_to_stack_pointer(-16);i.typstfontresolverbuilder_get_font_info(s,this.__wbg_ptr,f(t));var n=a().getInt32(s+0,!0),r=a().getInt32(s+4,!0),o=a().getInt32(s+8,!0);if(o)throw l(r);return l(n)}finally{i.__wbindgen_add_to_stack_pointer(16)}}add_raw_font(t){try{let o=i.__wbindgen_add_to_stack_pointer(-16);i.typstfontresolverbuilder_add_raw_font(o,this.__wbg_ptr,f(t));var n=a().getInt32(o+0,!0),r=a().getInt32(o+4,!0);if(r)throw l(n)}finally{i.__wbindgen_add_to_stack_pointer(16)}}add_lazy_font(t,n){try{let s=i.__wbindgen_add_to_stack_pointer(-16);i.typstfontresolverbuilder_add_lazy_font(s,this.__wbg_ptr,f(t),f(n));var r=a().getInt32(s+0,!0),o=a().getInt32(s+4,!0);if(o)throw l(r)}finally{i.__wbindgen_add_to_stack_pointer(16)}}build(){let t=this.__destroy_into_raw(),n=i.typstfontresolverbuilder_build(t);return l(n)}};Symbol.dispose&&($.prototype[Symbol.dispose]=$.prototype.free);Oe=new Set(["basic","cors","default"]);Vt=qt,$t=async function(e,t){throw new Error("Cannot import wasm module without importer: "+e+" "+t)}});var Jt={};re(Jt,{IncrServer:()=>F,ProxyContext:()=>O,TypstCompileWorld:()=>P,TypstCompiler:()=>j,TypstCompilerBuilder:()=>V,TypstFontResolver:()=>M,TypstFontResolverBuilder:()=>$,default:()=>Be,get_font_info:()=>Ce,initSync:()=>je,setImportWasmModule:()=>pt});var Be,De,ze,Ht=vt(()=>{ot();ot();ot();Be=Vt,De=async function(e,t){let n=new Function("m","return import(m)"),{readFileSync:r}=await n("fs"),o=new URL(e,t);return await r(o).buffer},ze=typeof process<"u"&&process.versions!=null&&process.versions.node!=null;ze&&pt(De)});var It=Symbol("Comlink.proxy"),oe=Symbol("Comlink.endpoint"),ie=Symbol("Comlink.releaseProxy"),at=Symbol("Comlink.finalizer"),G=Symbol("Comlink.thrown"),kt=e=>typeof e=="object"&&e!==null||typeof e=="function",se={canHandle:e=>kt(e)&&e[It],serialize(e){let{port1:t,port2:n}=new MessageChannel;return Q(e,t),[n,[n]]},deserialize(e){return e.start(),ue(e)}},_e={canHandle:e=>kt(e)&&G in e,serialize({value:e}){let t;return e instanceof Error?t={isError:!0,value:{message:e.message,name:e.name,stack:e.stack}}:t={isError:!1,value:e},[t,[]]},deserialize(e){throw e.isError?Object.assign(new Error(e.value.message),e.value):e.value}},St=new Map([["proxy",se],["throw",_e]]);function ae(e,t){for(let n of e)if(t===n||n==="*"||n instanceof RegExp&&n.test(t))return!0;return!1}function Q(e,t=globalThis,n=["*"]){t.addEventListener("message",function r(o){if(!o||!o.data)return;if(!ae(n,o.origin)){console.warn(`Invalid origin \'${o.origin}\' for comlink proxy`);return}let{id:s,type:_,path:c}=Object.assign({path:[]},o.data),d=(o.data.argumentList||[]).map(A),g;try{let w=c.slice(0,-1).reduce((p,m)=>p[m],e),y=c.reduce((p,m)=>p[m],e);switch(_){case"GET":g=y;break;case"SET":w[c.slice(-1)[0]]=A(o.data.value),g=!0;break;case"APPLY":g=y.apply(w,d);break;case"CONSTRUCT":{let p=new y(...d);g=le(p)}break;case"ENDPOINT":{let{port1:p,port2:m}=new MessageChannel;Q(e,m),g=Z(p,[p])}break;case"RELEASE":g=void 0;break;default:return}}catch(w){g={value:w,[G]:0}}Promise.resolve(g).catch(w=>({value:w,[G]:0})).then(w=>{let[y,p]=K(w);t.postMessage(Object.assign(Object.assign({},y),{id:s}),p),_==="RELEASE"&&(t.removeEventListener("message",r),Ft(t),at in e&&typeof e[at]=="function"&&e[at]())}).catch(w=>{let[y,p]=K({value:new TypeError("Unserializable return value"),[G]:0});t.postMessage(Object.assign(Object.assign({},y),{id:s}),p)})}),t.start&&t.start()}function ce(e){return e.constructor.name==="MessagePort"}function Ft(e){ce(e)&&e.close()}function ue(e,t){let n=new Map;return e.addEventListener("message",function(o){let{data:s}=o;if(!s||!s.id)return;let _=n.get(s.id);if(_)try{_(s)}finally{n.delete(s.id)}}),ct(e,n,[],t)}function H(e){if(e)throw new Error("Proxy has been released and is not useable")}function At(e){return E(e,new Map,{type:"RELEASE"}).then(()=>{Ft(e)})}var X=new WeakMap,Y="FinalizationRegistry"in globalThis&&new FinalizationRegistry(e=>{let t=(X.get(e)||0)-1;X.set(e,t),t===0&&At(e)});function fe(e,t){let n=(X.get(t)||0)+1;X.set(t,n),Y&&Y.register(e,t,e)}function de(e){Y&&Y.unregister(e)}function ct(e,t,n=[],r=function(){}){let o=!1,s=new Proxy(r,{get(_,c){if(H(o),c===ie)return()=>{de(s),At(e),t.clear(),o=!0};if(c==="then"){if(n.length===0)return{then:()=>s};let d=E(e,t,{type:"GET",path:n.map(g=>g.toString())}).then(A);return d.then.bind(d)}return ct(e,t,[...n,c])},set(_,c,d){H(o);let[g,w]=K(d);return E(e,t,{type:"SET",path:[...n,c].map(y=>y.toString()),value:g},w).then(A)},apply(_,c,d){H(o);let g=n[n.length-1];if(g===oe)return E(e,t,{type:"ENDPOINT"}).then(A);if(g==="bind")return ct(e,t,n.slice(0,-1));let[w,y]=xt(d);return E(e,t,{type:"APPLY",path:n.map(p=>p.toString()),argumentList:w},y).then(A)},construct(_,c){H(o);let[d,g]=xt(c);return E(e,t,{type:"CONSTRUCT",path:n.map(w=>w.toString()),argumentList:d},g).then(A)}});return fe(s,e),s}function ge(e){return Array.prototype.concat.apply([],e)}function xt(e){let t=e.map(K);return[t.map(n=>n[0]),ge(t.map(n=>n[1]))]}var Rt=new WeakMap;function Z(e,t){return Rt.set(e,t),e}function le(e){return Object.assign(e,{[It]:!0})}function K(e){for(let[t,n]of St)if(n.canHandle(e)){let[r,o]=n.serialize(e);return[{type:"HANDLER",name:t,value:r},o]}return[{type:"RAW",value:e},Rt.get(e)||[]]}function A(e){switch(e.type){case"HANDLER":return St.get(e.name).deserialize(e.value);case"RAW":return e.value}}function E(e,t,n,r){return new Promise(o=>{let s=we();t.set(s,o),e.start&&e.start(),e.postMessage(Object.assign({id:s},n),r)})}function we(){return new Array(4).fill(0).map(()=>Math.floor(Math.random()*Number.MAX_SAFE_INTEGER).toString(16)).join("-")}var ut=class{loadedFonts=new Set;fetcher=fetch;setFetcher(t){this.fetcher=t}async loadFonts(t,n){let r=new Function("m","return import(m)"),o=this.fetcher||=await(async function(){let{fetchBuilder:c,FileSystemCache:d}=await r("node-fetch-cache"),g=new d({cacheDirectory:".cache/typst/fonts"}),w=c.withCache(g);return function(y,p){let m=setTimeout(()=>{console.warn("font fetching is stucking:",y)},15e3);return w(y,p).finally(()=>{clearTimeout(m)})}})(),s=n.filter(c=>c instanceof Uint8Array||typeof c=="object"&&"info"in c?!0:this.loadedFonts.has(c)?!1:(this.loadedFonts.add(c),!0)),_=await Promise.all(s.map(async c=>{if(c instanceof Uint8Array){await t.add_raw_font(c);return}if(typeof c=="object"&&"info"in c){await t.add_lazy_font(c,"blob"in c?c.blob:be(c));return}return new Uint8Array(await(await o(c)).arrayBuffer())}));for(let c of _)c&&await t.add_raw_font(c)}async build(t,n,r){let o={ref:this,builder:n,hooks:r};for(let s of t?.beforeBuild??[])await s(void 0,o);return r.latelyBuild&&r.latelyBuild(o),await n.build()}};async function Mt(e,t,n,r){return await t.init(e?.getModule?.()),await new ut().build(e,new n,r)}function be(e){return()=>{let t=new XMLHttpRequest;return t.overrideMimeType("text/plain; charset=x-user-defined"),t.open("GET",e.url,!1),t.send(null),t.status===200&&(t.response instanceof String||typeof t.response=="string")?Uint8Array.from(t.response,n=>n.charCodeAt(0)):new Uint8Array}}var x=Symbol.for("reflexo-obj");var Et;(function(e){e[e.PIXEL_PER_PT=3]="PIXEL_PER_PT"})(Et||(Et={}));var ye=["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"],me=["InriaSerif-Bold.ttf","InriaSerif-BoldItalic.ttf","InriaSerif-Italic.ttf","InriaSerif-Regular.ttf","Roboto-Regular.ttf","NotoSerifCJKsc-Regular.otf"],he=["TwitterColorEmoji.ttf","NotoColorEmoji-Regular-COLR.subset.ttf"];function ve(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;typeof r=="string"?r={_:r}:r={...n,...r};for(let s of Object.keys(r)){let _=r[s];_[_.length-1]!=="/"&&(r[s]=_+"/")}let o=(s,_)=>_.map(c=>(r[s]||r._)+c);for(let s of e.assets)switch(s){case"text":t.push(...o(s,ye));break;case"cjk":t.push(...o(s,me));break;case"emoji":t.push(...o(s,he));break}}return t}function tt(e,t){let n=ve(t),r=async(o,{ref:s,builder:_})=>{t?.fetcher&&s.setFetcher(t.fetcher),await s.loadFonts(_,[...e,...n])};return r._preloadRemoteFontOptions=t,r._kind="fontLoader",r}function Tt(e){return async(t,{builder:n})=>new Promise(r=>{n.set_package_registry(e,function(o){return e.resolve(o,this)}),r()})}function Ct(e){return async(t,n)=>{if(n.alreadySetAccessModel)throw new Error(`already set some assess model before: ${n.alreadySetAccessModel.constructor?.name}(${n.alreadySetAccessModel})`);return n.alreadySetAccessModel=e,new Promise(r=>{n.builder.set_access_model(e,o=>{let s=e.getMTime(o);return s?s.getTime():0},o=>e.isFile(o)||!1,o=>e.getRealPath(o)||o,o=>e.readAll(o)),r()})}}var xe=e=>{let t=!1,n;return()=>t?n:(t=!0,n=e())},et=class{wasmBin;initOnce;constructor(t){if(typeof t!="function")throw new Error("initFn is not a function");this.initOnce=xe(async()=>{await t(this.wasmBin)})}async init(t){this.wasmBin=t,await this.initOnce()}};var J;(function(e){e[e.vector=0]="vector",e[e.pdf=1]="pdf",e[e._dummy=2]="_dummy"})(J||(J={}));var bt=class{[x];constructor(t){this[x]=t}reset(){this[x].reset()}current(){return this[x].current()}setAttachDebugInfo(t){this[x].set_attach_debug_info(t)}},Gt;Gt||(Gt={});var yt=class{[x];constructor(t){this[x]=t}compile(t){return this[x].compile(0,L(t?.diagnostics))}compileHtml(t){return this[x].compile(1,L(t?.diagnostics))}async query(t){return JSON.parse(this[x].query(0,t.selector,t.field))}title(){return this[x].title(0)}vector(t){return this[x].get_artifact(0,L(t?.diagnostics))||{}}pdf(t){return this[x].get_artifact(1,L(t?.diagnostics))||{}}},Ue=e=>new et(async t=>await e.default(t));function mt(){return new it}var it=class e{compiler;compilerJs;static defaultAssets=["text"];constructor(){}async init(t){this.compilerJs=await(t?.getWrapper?.()||Promise.resolve().then(()=>(Ht(),Jt)));let n=this.compilerJs.TypstCompilerBuilder,r={...t||{}},o=r.beforeBuild??=[],s=o.some(g=>g._preloadRemoteFontOptions!==void 0),_=o.some(g=>g._preloadRemoteFontOptions?.assets!==void 0),c=o.some(g=>g._preloadRemoteFontOptions?.assets===!1);if((!s||!_&&!c)&&o.push(tt([],{assets:e.defaultAssets})),!o.some(g=>g._kind==="fontLoader"))throw new Error("TypstCompiler: no font loader found, please use font loaders, e.g. loadFonts or preloadSystemFonts");this.compiler=await Mt(t,Ue(this.compilerJs),n,{})}setFonts(t){this.compiler.set_fonts(t)}compile(t){return new Promise(n=>{let r=this.compiler.snapshot(t.root,t.mainFilePath,Xt(t.inputs));if("incrementalServer"in t){n(r.incr_compile(t.incrementalServer[x],L(t.diagnostics)));return}n(r.get_artifact(t.format||J.vector,L(t.diagnostics)))})}async runWithWorld(t,n){let r=this.compiler.snapshot(t.root,t.mainFilePath,Xt(t.inputs)),o=await n(new yt(r));return r.free(),o}query(t){return this.runWithWorld(t,async n=>JSON.parse(await n.query(t)))}getSemanticTokenLegend(){return new Promise(t=>{t(this.compiler.get_semantic_token_legend())})}getSemanticTokens(t){return new Promise(n=>{this.compiler.reset(),n(this.compiler.get_semantic_tokens(t.offsetEncoding||"utf-16",t.mainFilePath,t.resultId))})}async withIncrementalServer(t){let n=new bt(this.compiler.create_incr_server());try{return await t(n)}finally{n[x].free()}}async getAst(t){return this.compiler.get_ast(t)}async reset(){await new Promise(t=>{this.compiler.reset(),t(void 0)})}addSource(t,n){if(arguments.length>2)throw new Error("use of addSource(path, source, isMain) is deprecated, please use addSource(path, source) instead");this.compiler.add_source(t,n)}mapShadow(t,n){this.compiler.map_shadow(t,n)}unmapShadow(t){this.compiler.unmap_shadow(t)}resetShadow(){this.compiler.reset_shadow()}renderPageToCanvas(){throw new Error("Please use the api TypstRenderer.renderToCanvas in v0.4.0")}};mt._impl=it;function Xt(e){return e?Object.entries(e):void 0}function L(e){switch(e){case"none":return 1;case"unix":return 2;default:return 3}}var st=class{mTimes=new Map;mData=new Map;constructor(){}reset(){this.mTimes.clear(),this.mData.clear()}insertFile(t,n,r){this.mTimes.set(t,r),this.mData.set(t,n)}removeFile(t){this.mTimes.delete(t),this.mData.delete(t)}getMTime(t){if(t.startsWith("/@memory/")&&this.mTimes.has(t))return this.mTimes.get(t)}isFile(){return!0}getRealPath(t){return t}readAll(t){if(t.startsWith("/@memory/")&&this.mData.has(t))return this.mData.get(t)}};var _t=class{am;cache=new Map;constructor(t){this.am=t}resolvePath(t){return`https://packages.typst.org/preview/${t.name}-${t.version}.tar.gz`}pullPackageData(t){let n=new XMLHttpRequest;if(n.overrideMimeType("text/plain; charset=x-user-defined"),n.open("GET",this.resolvePath(t),!1),n.send(null),n.status===200&&(n.response instanceof String||typeof n.response=="string"))return Uint8Array.from(n.response,r=>r.charCodeAt(0))}resolve(t,n){if(t.namespace!=="preview")return;let r=this.resolvePath(t);if(this.cache.has(r))return this.cache.get(r)();let o=this.pullPackageData(t);if(!o)return;let s=`/@memory/fetch/packages/${t.namespace}/${t.name}/${t.version}`,_=[];n.untar(o,(d,g,w)=>{_.push([s+"/"+d,g,new Date(w)])});let c=()=>{for(let[d,g,w]of _)this.am.insertFile(d,g,w);return s};return this.cache.set(r,c),c()}};function Yt(e){return[...e].sort((t,n)=>t.path.localeCompare(n.path)||t.range.startLine-n.range.startLine||t.range.startCol-n.range.startCol||t.range.endLine-n.range.endLine||t.range.endCol-n.range.endCol||t.message.localeCompare(n.message))}var Kt="/main.typ",ht=class{#e=null;#n=new st;#r;constructor(){this.#r=new _t(this.#n)}#t(){if(!this.#e)throw new Error("Compiler not initialized");return this.#e}async init(t,n,r){this.#e=mt(),await this.#e.init({getModule:()=>t,beforeBuild:[tt(n),...r?[Ct(this.#n),Tt(this.#r)]:[]]})}async compile(t){let{rawDiagnostics:n,vector:r}=await this.#t().runWithWorld({mainFilePath:t??Kt},async s=>{let _=await s.vector({diagnostics:"full"});if(!("result"in _))return{rawDiagnostics:_.diagnostics,vector:void 0};let c=[];try{c=(await s.compile({diagnostics:"full"})).diagnostics}catch(d){console.error("[typst-web-service] compile() threw after vector():",d)}return{rawDiagnostics:c,vector:_.result}}),o=Yt(n.map(s=>{let _=s.range.match(/(\\d+):(\\d+)-(\\d+):(\\d+)/);return{...s,severity:s.severity,range:_?{startLine:+_[1],startCol:+_[2],endLine:+_[3],endCol:+_[4]}:{startLine:0,startCol:0,endLine:0,endCol:0}}}));return r?Z({diagnostics:o,vector:r},[r.buffer]):{diagnostics:o}}async compilePdf(t){let n=await this.#t().compile({mainFilePath:t??Kt,format:J.pdf,diagnostics:"none"});if(!n.result)throw new Error("Compilation produced no output");return Z(n.result,[n.result.buffer])}mapShadow(t,n){this.#t().mapShadow(t,n)}mapShadowMany(t){let n=this.#t();for(let[r,o]of Object.entries(t))n.mapShadow(r,o)}unmapShadow(t){this.#t().unmapShadow(t)}resetShadow(){this.#t().resetShadow()}destroy(){this.#e=null}};Q(new ht);})();\n/*! Bundled license information:\n\ncomlink/dist/esm/comlink.mjs:\n (**\n * @license\n * Copyright 2019 Google LLC\n * SPDX-License-Identifier: Apache-2.0\n *)\n*/\n');
|
|
7
|
+
function byteToCmOffset(text, byte) {
|
|
8
|
+
if (byte <= 0) return 0;
|
|
9
|
+
const bytes = encoder.encode(text);
|
|
10
|
+
if (byte >= bytes.length) return text.length;
|
|
11
|
+
return decoder.decode(bytes.subarray(0, byte)).length;
|
|
18
12
|
}
|
|
19
|
-
function
|
|
20
|
-
return createBlobWorker('"use strict";(()=>{var $=Symbol("Comlink.proxy"),se=Symbol("Comlink.endpoint"),_e=Symbol("Comlink.releaseProxy"),W=Symbol("Comlink.finalizer"),L=Symbol("Comlink.thrown"),G=t=>typeof t=="object"&&t!==null||typeof t=="function",ce={canHandle:t=>G(t)&&t[$],serialize(t){let{port1:e,port2:n}=new MessageChannel;return z(t,e),[n,[n]]},deserialize(t){return t.start(),ge(t)}},ae={canHandle:t=>G(t)&&L in t,serialize({value:t}){let e;return t instanceof Error?e={isError:!0,value:{message:t.message,name:t.name,stack:t.stack}}:e={isError:!1,value:t},[e,[]]},deserialize(t){throw t.isError?Object.assign(new Error(t.value.message),t.value):t.value}},Y=new Map([["proxy",ce],["throw",ae]]);function fe(t,e){for(let n of t)if(e===n||n==="*"||n instanceof RegExp&&n.test(e))return!0;return!1}function z(t,e=globalThis,n=["*"]){e.addEventListener("message",function r(i){if(!i||!i.data)return;if(!fe(n,i.origin)){console.warn(`Invalid origin \'${i.origin}\' for comlink proxy`);return}let{id:s,type:_,path:c}=Object.assign({path:[]},i.data),a=(i.data.argumentList||[]).map(p),f;try{let u=c.slice(0,-1).reduce((g,A)=>g[A],t),d=c.reduce((g,A)=>g[A],t);switch(_){case"GET":f=d;break;case"SET":u[c.slice(-1)[0]]=p(i.data.value),f=!0;break;case"APPLY":f=d.apply(u,a);break;case"CONSTRUCT":{let g=new d(...a);f=ye(g)}break;case"ENDPOINT":{let{port1:g,port2:A}=new MessageChannel;z(t,A),f=we(g,[g])}break;case"RELEASE":f=void 0;break;default:return}}catch(u){f={value:u,[L]:0}}Promise.resolve(f).catch(u=>({value:u,[L]:0})).then(u=>{let[d,g]=D(u);e.postMessage(Object.assign(Object.assign({},d),{id:s}),g),_==="RELEASE"&&(e.removeEventListener("message",r),X(e),W in t&&typeof t[W]=="function"&&t[W]())}).catch(u=>{let[d,g]=D({value:new TypeError("Unserializable return value"),[L]:0});e.postMessage(Object.assign(Object.assign({},d),{id:s}),g)})}),e.start&&e.start()}function ue(t){return t.constructor.name==="MessagePort"}function X(t){ue(t)&&t.close()}function ge(t,e){let n=new Map;return t.addEventListener("message",function(i){let{data:s}=i;if(!s||!s.id)return;let _=n.get(s.id);if(_)try{_(s)}finally{n.delete(s.id)}}),N(t,n,[],e)}function k(t){if(t)throw new Error("Proxy has been released and is not useable")}function J(t){return h(t,new Map,{type:"RELEASE"}).then(()=>{X(t)})}var F=new WeakMap,C="FinalizationRegistry"in globalThis&&new FinalizationRegistry(t=>{let e=(F.get(t)||0)-1;F.set(t,e),e===0&&J(t)});function be(t,e){let n=(F.get(e)||0)+1;F.set(e,n),C&&C.register(t,e,t)}function le(t){C&&C.unregister(t)}function N(t,e,n=[],r=function(){}){let i=!1,s=new Proxy(r,{get(_,c){if(k(i),c===_e)return()=>{le(s),J(t),e.clear(),i=!0};if(c==="then"){if(n.length===0)return{then:()=>s};let a=h(t,e,{type:"GET",path:n.map(f=>f.toString())}).then(p);return a.then.bind(a)}return N(t,e,[...n,c])},set(_,c,a){k(i);let[f,u]=D(a);return h(t,e,{type:"SET",path:[...n,c].map(d=>d.toString()),value:f},u).then(p)},apply(_,c,a){k(i);let f=n[n.length-1];if(f===se)return h(t,e,{type:"ENDPOINT"}).then(p);if(f==="bind")return N(t,e,n.slice(0,-1));let[u,d]=V(a);return h(t,e,{type:"APPLY",path:n.map(g=>g.toString()),argumentList:u},d).then(p)},construct(_,c){k(i);let[a,f]=V(c);return h(t,e,{type:"CONSTRUCT",path:n.map(u=>u.toString()),argumentList:a},f).then(p)}});return be(s,t),s}function de(t){return Array.prototype.concat.apply([],t)}function V(t){let e=t.map(D);return[e.map(n=>n[0]),de(e.map(n=>n[1]))]}var K=new WeakMap;function we(t,e){return K.set(t,e),t}function ye(t){return Object.assign(t,{[$]:!0})}function D(t){for(let[e,n]of Y)if(n.canHandle(t)){let[r,i]=n.serialize(t);return[{type:"HANDLER",name:e,value:r},i]}return[{type:"RAW",value:t},K.get(t)||[]]}function p(t){switch(t.type){case"HANDLER":return Y.get(t.name).deserialize(t.value);case"RAW":return t.value}}function h(t,e,n,r){return new Promise(i=>{let s=pe();e.set(s,i),t.start&&t.start(),t.postMessage(Object.assign({id:s},n),r)})}function pe(){return new Array(4).fill(0).map(()=>Math.floor(Math.random()*Number.MAX_SAFE_INTEGER).toString(16)).join("-")}var Te={},o;function R(t){let e=o.__externref_table_alloc();return o.__wbindgen_externrefs.set(e,t),e}var Q=typeof FinalizationRegistry>"u"?{register:()=>{},unregister:()=>{}}:new FinalizationRegistry(t=>t.dtor(t.a,t.b));function H(t){let e=typeof t;if(e=="number"||e=="boolean"||t==null)return`${t}`;if(e=="string")return`"${t}"`;if(e=="symbol"){let i=t.description;return i==null?"Symbol":`Symbol(${i})`}if(e=="function"){let i=t.name;return typeof i=="string"&&i.length>0?`Function(${i})`:"Function"}if(Array.isArray(t)){let i=t.length,s="[";i>0&&(s+=H(t[0]));for(let _=1;_<i;_++)s+=", "+H(t[_]);return s+="]",s}let n=/\\[object ([^\\]]+)\\]/.exec(toString.call(t)),r;if(n&&n.length>1)r=n[1];else return toString.call(t);if(r=="Object")try{return"Object("+JSON.stringify(t)+")"}catch{return"Object"}return t instanceof Error?`${t.name}: ${t.message}\n${t.stack}`:r}function Z(t,e){return t=t>>>0,E().subarray(t/1,t/1+e)}var m=null;function l(){return(m===null||m.buffer.detached===!0||m.buffer.detached===void 0&&m.buffer!==o.memory.buffer)&&(m=new DataView(o.memory.buffer)),m}function b(t,e){return t=t>>>0,Ee(t,e)}var O=null;function E(){return(O===null||O.byteLength===0)&&(O=new Uint8Array(o.memory.buffer)),O}function x(t,e){try{return t.apply(this,e)}catch(n){let r=R(n);o.__wbindgen_exn_store(r)}}function w(t){return t==null}function he(t,e,n,r){let i={a:t,b:e,cnt:1,dtor:n},s=(..._)=>{i.cnt++;let c=i.a;i.a=0;try{return r(c,i.b,..._)}finally{i.a=c,s._wbg_cb_unref()}};return s._wbg_cb_unref=()=>{--i.cnt===0&&(i.dtor(i.a,i.b),i.a=0,Q.unregister(i))},Q.register(s,i,i),s}function xe(t,e){let n=e(t.length*1,1)>>>0;return E().set(t,n/1),y=t.length,n}function v(t,e,n){if(n===void 0){let c=M.encode(t),a=e(c.length,1)>>>0;return E().subarray(a,a+c.length).set(c),y=c.length,a}let r=t.length,i=e(r,1)>>>0,s=E(),_=0;for(;_<r;_++){let c=t.charCodeAt(_);if(c>127)break;s[i+_]=c}if(_!==r){_!==0&&(t=t.slice(_)),i=n(i,r,r=_+t.length*3,1)>>>0;let c=E().subarray(i+_,i+r),a=M.encodeInto(t,c);_+=a.written,i=n(i,r,_,1)>>>0}return y=_,i}function re(t){let e=o.__wbindgen_externrefs.get(t);return o.__externref_table_dealloc(t),e}var I=new TextDecoder("utf-8",{ignoreBOM:!0,fatal:!0});I.decode();var ve=2146435072,U=0;function Ee(t,e){return U+=e,U>=ve&&(I=new TextDecoder("utf-8",{ignoreBOM:!0,fatal:!0}),I.decode(),U=e),I.decode(E().subarray(t,t+e))}var M=new TextEncoder;"encodeInto"in M||(M.encodeInto=function(t,e){let n=M.encode(t);return e.set(n),{read:t.length,written:n.length}});var y=0;function Se(t,e,n){o.wasm_bindgen__convert__closures_____invoke__h4b569589ab16bc8b(t,e,n)}function Ae(t,e,n,r){o.wasm_bindgen__convert__closures_____invoke__h298f91ca76697d7d(t,e,n,r)}var ee=typeof FinalizationRegistry>"u"?{register:()=>{},unregister:()=>{}}:new FinalizationRegistry(t=>o.__wbg_individuallanguages_free(t>>>0,1)),te=typeof FinalizationRegistry>"u"?{register:()=>{},unregister:()=>{}}:new FinalizationRegistry(t=>o.__wbg_languagecode_free(t>>>0,1)),q=typeof FinalizationRegistry>"u"?{register:()=>{},unregister:()=>{}}:new FinalizationRegistry(t=>o.__wbg_proxycontext_free(t>>>0,1)),ne=typeof FinalizationRegistry>"u"?{register:()=>{},unregister:()=>{}}:new FinalizationRegistry(t=>o.__wbg_tinymistlanguageserver_free(t>>>0,1)),P=class t{static __wrap(e){e=e>>>0;let n=Object.create(t.prototype);return n.__wbg_ptr=e,ee.register(n,n.__wbg_ptr,n),n}__destroy_into_raw(){let e=this.__wbg_ptr;return this.__wbg_ptr=0,ee.unregister(this),e}free(){let e=this.__destroy_into_raw();o.__wbg_individuallanguages_free(e,0)}get name(){let e,n;try{let r=o.individuallanguages_name(this.__wbg_ptr);return e=r[0],n=r[1],b(r[0],r[1])}finally{o.__wbindgen_free(e,n,1)}}get code(){let e,n;try{let r=o.individuallanguages_code(this.__wbg_ptr);return e=r[0],n=r[1],b(r[0],r[1])}finally{o.__wbindgen_free(e,n,1)}}};Symbol.dispose&&(P.prototype[Symbol.dispose]=P.prototype.free);var j=class t{static __wrap(e){e=e>>>0;let n=Object.create(t.prototype);return n.__wbg_ptr=e,te.register(n,n.__wbg_ptr,n),n}__destroy_into_raw(){let e=this.__wbg_ptr;return this.__wbg_ptr=0,te.unregister(this),e}free(){let e=this.__destroy_into_raw();o.__wbg_languagecode_free(e,0)}get name(){let e,n;try{let r=o.languagecode_name(this.__wbg_ptr);return e=r[0],n=r[1],b(r[0],r[1])}finally{o.__wbindgen_free(e,n,1)}}get code(){let e,n;try{let r=o.languagecode_code(this.__wbg_ptr);return e=r[0],n=r[1],b(r[0],r[1])}finally{o.__wbindgen_free(e,n,1)}}get code_2t(){let e,n;try{let r=o.languagecode_code_2t(this.__wbg_ptr);return e=r[0],n=r[1],b(r[0],r[1])}finally{o.__wbindgen_free(e,n,1)}}get code_2b(){let e,n;try{let r=o.languagecode_code_2b(this.__wbg_ptr);return e=r[0],n=r[1],b(r[0],r[1])}finally{o.__wbindgen_free(e,n,1)}}get code_3(){let e,n;try{let r=o.languagecode_code_3(this.__wbg_ptr);return e=r[0],n=r[1],b(r[0],r[1])}finally{o.__wbindgen_free(e,n,1)}}get individual_languages(){return o.languagecode_individual_languages(this.__wbg_ptr)}};Symbol.dispose&&(j.prototype[Symbol.dispose]=j.prototype.free);var T=class t{static __wrap(e){e=e>>>0;let n=Object.create(t.prototype);return n.__wbg_ptr=e,q.register(n,n.__wbg_ptr,n),n}__destroy_into_raw(){let e=this.__wbg_ptr;return this.__wbg_ptr=0,q.unregister(this),e}free(){let e=this.__destroy_into_raw();o.__wbg_proxycontext_free(e,0)}constructor(e){let n=o.proxycontext_new(e);return this.__wbg_ptr=n>>>0,q.register(this,this.__wbg_ptr,this),this}get context(){return o.proxycontext_context(this.__wbg_ptr)}untar(e,n){let r=xe(e,o.__wbindgen_malloc),i=y,s=o.proxycontext_untar(this.__wbg_ptr,r,i,n);if(s[1])throw re(s[0])}};Symbol.dispose&&(T.prototype[Symbol.dispose]=T.prototype.free);var S=class{__destroy_into_raw(){let e=this.__wbg_ptr;return this.__wbg_ptr=0,ne.unregister(this),e}free(){let e=this.__destroy_into_raw();o.__wbg_tinymistlanguageserver_free(e,0)}constructor(e){let n=o.tinymistlanguageserver_new(e);if(n[2])throw re(n[1]);return this.__wbg_ptr=n[0]>>>0,ne.register(this,this.__wbg_ptr,this),this}on_event(e){o.tinymistlanguageserver_on_event(this.__wbg_ptr,e)}on_request(e,n){let r=v(e,o.__wbindgen_malloc,o.__wbindgen_realloc),i=y;return o.tinymistlanguageserver_on_request(this.__wbg_ptr,r,i,n)}on_notification(e,n){let r=v(e,o.__wbindgen_malloc,o.__wbindgen_realloc),i=y;o.tinymistlanguageserver_on_notification(this.__wbg_ptr,r,i,n)}on_response(e){o.tinymistlanguageserver_on_response(this.__wbg_ptr,e)}static version(){let e,n;try{let r=o.tinymistlanguageserver_version();return e=r[0],n=r[1],b(r[0],r[1])}finally{o.__wbindgen_free(e,n,1)}}};Symbol.dispose&&(S.prototype[Symbol.dispose]=S.prototype.free);var Re=new Set(["basic","cors","default"]);async function Oe(t,e){if(typeof Response=="function"&&t instanceof Response){if(typeof WebAssembly.instantiateStreaming=="function")try{return await WebAssembly.instantiateStreaming(t,e)}catch(r){if(t.ok&&Re.has(t.type)&&t.headers.get("Content-Type")!=="application/wasm")console.warn("`WebAssembly.instantiateStreaming` failed because your server does not serve Wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\\n",r);else throw r}let n=await t.arrayBuffer();return await WebAssembly.instantiate(n,e)}else{let n=await WebAssembly.instantiate(t,e);return n instanceof WebAssembly.Instance?{instance:n,module:t}:n}}function Me(){let t={};return t.wbg={},t.wbg.__wbg_Error_52673b7de5a0ca89=function(e,n){return Error(b(e,n))},t.wbg.__wbg_Number_2d1dcfcf4ec51736=function(e){return Number(e)},t.wbg.__wbg_String_8f0eb39a4a4c2f66=function(e,n){let r=String(n),i=v(r,o.__wbindgen_malloc,o.__wbindgen_realloc),s=y;l().setInt32(e+4,s,!0),l().setInt32(e+0,i,!0)},t.wbg.__wbg___wbindgen_bigint_get_as_i64_6e32f5e6aff02e1d=function(e,n){let r=n,i=typeof r=="bigint"?r:void 0;l().setBigInt64(e+8,w(i)?BigInt(0):i,!0),l().setInt32(e+0,!w(i),!0)},t.wbg.__wbg___wbindgen_boolean_get_dea25b33882b895b=function(e){let n=e,r=typeof n=="boolean"?n:void 0;return w(r)?16777215:r?1:0},t.wbg.__wbg___wbindgen_debug_string_adfb662ae34724b6=function(e,n){let r=H(n),i=v(r,o.__wbindgen_malloc,o.__wbindgen_realloc),s=y;l().setInt32(e+4,s,!0),l().setInt32(e+0,i,!0)},t.wbg.__wbg___wbindgen_in_0d3e1e8f0c669317=function(e,n){return e in n},t.wbg.__wbg___wbindgen_is_bigint_0e1a2e3f55cfae27=function(e){return typeof e=="bigint"},t.wbg.__wbg___wbindgen_is_function_8d400b8b1af978cd=function(e){return typeof e=="function"},t.wbg.__wbg___wbindgen_is_object_ce774f3490692386=function(e){let n=e;return typeof n=="object"&&n!==null},t.wbg.__wbg___wbindgen_is_string_704ef9c8fc131030=function(e){return typeof e=="string"},t.wbg.__wbg___wbindgen_is_undefined_f6b95eab589e0269=function(e){return e===void 0},t.wbg.__wbg___wbindgen_jsval_eq_b6101cc9cef1fe36=function(e,n){return e===n},t.wbg.__wbg___wbindgen_jsval_loose_eq_766057600fdd1b0d=function(e,n){return e==n},t.wbg.__wbg___wbindgen_number_get_9619185a74197f95=function(e,n){let r=n,i=typeof r=="number"?r:void 0;l().setFloat64(e+8,w(i)?0:i,!0),l().setInt32(e+0,!w(i),!0)},t.wbg.__wbg___wbindgen_string_get_a2a31e16edf96e42=function(e,n){let r=n,i=typeof r=="string"?r:void 0;var s=w(i)?0:v(i,o.__wbindgen_malloc,o.__wbindgen_realloc),_=y;l().setInt32(e+4,_,!0),l().setInt32(e+0,s,!0)},t.wbg.__wbg___wbindgen_throw_dd24417ed36fc46e=function(e,n){throw new Error(b(e,n))},t.wbg.__wbg__wbg_cb_unref_87dfb5aaa0cbcea7=function(e){e._wbg_cb_unref()},t.wbg.__wbg_call_3020136f7a2d6e44=function(){return x(function(e,n,r){return e.call(n,r)},arguments)},t.wbg.__wbg_call_78f94eb02ec7f9b2=function(){return x(function(e,n,r,i,s){return e.call(n,r,i,s)},arguments)},t.wbg.__wbg_call_abb4ff46ce38be40=function(){return x(function(e,n){return e.call(n)},arguments)},t.wbg.__wbg_done_62ea16af4ce34b24=function(e){return e.done},t.wbg.__wbg_entries_83c79938054e065f=function(e){return Object.entries(e)},t.wbg.__wbg_error_7534b8e9a36f1ab4=function(e,n){let r,i;try{r=e,i=n,console.error(b(e,n))}finally{o.__wbindgen_free(r,i,1)}},t.wbg.__wbg_getTimezoneOffset_45389e26d6f46823=function(e){return e.getTimezoneOffset()},t.wbg.__wbg_get_6b7bd52aca3f9671=function(e,n){return e[n>>>0]},t.wbg.__wbg_get_af9dab7e9603ea93=function(){return x(function(e,n){return Reflect.get(e,n)},arguments)},t.wbg.__wbg_get_with_ref_key_1dc361bd10053bfe=function(e,n){return e[n]},t.wbg.__wbg_individuallanguages_new=function(e){return P.__wrap(e)},t.wbg.__wbg_instanceof_ArrayBuffer_f3320d2419cd0355=function(e){let n;try{n=e instanceof ArrayBuffer}catch{n=!1}return n},t.wbg.__wbg_instanceof_Map_084be8da74364158=function(e){let n;try{n=e instanceof Map}catch{n=!1}return n},t.wbg.__wbg_instanceof_Uint8Array_da54ccc9d3e09434=function(e){let n;try{n=e instanceof Uint8Array}catch{n=!1}return n},t.wbg.__wbg_isArray_51fd9e6422c0a395=function(e){return Array.isArray(e)},t.wbg.__wbg_isSafeInteger_ae7d3f054d55fa16=function(e){return Number.isSafeInteger(e)},t.wbg.__wbg_iterator_27b7c8b35ab3e86b=function(){return Symbol.iterator},t.wbg.__wbg_length_22ac23eaec9d8053=function(e){return e.length},t.wbg.__wbg_length_d45040a40c570362=function(e){return e.length},t.wbg.__wbg_new_1ba21ce319a06297=function(){return new Object},t.wbg.__wbg_new_25f239778d6112b9=function(){return new Array},t.wbg.__wbg_new_6421f6084cc5bc5a=function(e){return new Uint8Array(e)},t.wbg.__wbg_new_8a6f238a6ece86ea=function(){return new Error},t.wbg.__wbg_new_b2db8aa2650f793a=function(e){return new Date(e)},t.wbg.__wbg_new_b546ae120718850e=function(){return new Map},t.wbg.__wbg_new_ff12d2b041fb48f1=function(e,n){try{var r={a:e,b:n},i=(_,c)=>{let a=r.a;r.a=0;try{return Ae(a,r.b,_,c)}finally{r.a=a}};return new Promise(i)}finally{r.a=r.b=0}},t.wbg.__wbg_new_from_slice_f9c22b9153b26992=function(e,n){return new Uint8Array(Z(e,n))},t.wbg.__wbg_new_no_args_cb138f77cf6151ee=function(e,n){return new Function(b(e,n))},t.wbg.__wbg_next_138a17bbf04e926c=function(e){return e.next},t.wbg.__wbg_next_3cfe5c0fe2a4cc53=function(){return x(function(e){return e.next()},arguments)},t.wbg.__wbg_now_2c95c9de01293173=function(e){return e.now()},t.wbg.__wbg_now_69d776cd24f5215b=function(){return Date.now()},t.wbg.__wbg_performance_7a3ffd0b17f663ad=function(e){return e.performance},t.wbg.__wbg_prototypesetcall_dfe9b766cdc1f1fd=function(e,n,r){Uint8Array.prototype.set.call(Z(e,n),r)},t.wbg.__wbg_proxycontext_new=function(e){return T.__wrap(e)},t.wbg.__wbg_push_7d9be8f38fc13975=function(e,n){return e.push(n)},t.wbg.__wbg_queueMicrotask_9b549dfce8865860=function(e){return e.queueMicrotask},t.wbg.__wbg_queueMicrotask_fca69f5bfad613a5=function(e){queueMicrotask(e)},t.wbg.__wbg_resolve_fd5bfbaa4ce36e1e=function(e){return Promise.resolve(e)},t.wbg.__wbg_set_3f1d0b984ed272ed=function(e,n,r){e[n]=r},t.wbg.__wbg_set_781438a03c0c3c81=function(){return x(function(e,n,r){return Reflect.set(e,n,r)},arguments)},t.wbg.__wbg_set_7df433eea03a5c14=function(e,n,r){e[n>>>0]=r},t.wbg.__wbg_set_efaaf145b9377369=function(e,n,r){return e.set(n,r)},t.wbg.__wbg_stack_0ed75d68575b0f3c=function(e,n){let r=n.stack,i=v(r,o.__wbindgen_malloc,o.__wbindgen_realloc),s=y;l().setInt32(e+4,s,!0),l().setInt32(e+0,i,!0)},t.wbg.__wbg_static_accessor_GLOBAL_769e6b65d6557335=function(){let e=typeof global>"u"?null:global;return w(e)?0:R(e)},t.wbg.__wbg_static_accessor_GLOBAL_THIS_60cf02db4de8e1c1=function(){let e=typeof globalThis>"u"?null:globalThis;return w(e)?0:R(e)},t.wbg.__wbg_static_accessor_SELF_08f5a74c69739274=function(){let e=typeof self>"u"?null:self;return w(e)?0:R(e)},t.wbg.__wbg_static_accessor_WINDOW_a8924b26aa92d024=function(){let e=typeof window>"u"?null:window;return w(e)?0:R(e)},t.wbg.__wbg_then_4f95312d68691235=function(e,n){return e.then(n)},t.wbg.__wbg_value_57b7b035e117f7ee=function(e){return e.value},t.wbg.__wbindgen_cast_2241b6af4c4b2941=function(e,n){return b(e,n)},t.wbg.__wbindgen_cast_4625c577ab2ec9ee=function(e){return BigInt.asUintN(64,e)},t.wbg.__wbindgen_cast_9ae0607507abb057=function(e){return e},t.wbg.__wbindgen_cast_b5bc9a99b1b9b782=function(e,n){return he(e,n,o.wasm_bindgen__closure__destroy__h21ca932816a58917,Se)},t.wbg.__wbindgen_cast_d6cd19b81560fd6e=function(e){return e},t.wbg.__wbindgen_init_externref_table=function(){let e=o.__wbindgen_externrefs,n=e.grow(4);e.set(0,void 0),e.set(n+0,void 0),e.set(n+1,null),e.set(n+2,!0),e.set(n+3,!1)},t}function Pe(t,e){return o=t.exports,ie.__wbindgen_wasm_module=e,m=null,O=null,o.__wbindgen_start(),o}async function ie(t){if(o!==void 0)return o;typeof t<"u"&&(Object.getPrototypeOf(t)===Object.prototype?{module_or_path:t}=t:console.warn("using deprecated parameters for the initialization function; pass a single object instead")),typeof t>"u"&&(t=new URL("tinymist_bg.wasm",Te.url));let e=Me();(typeof t=="string"||typeof Request=="function"&&t instanceof Request||typeof URL=="function"&&t instanceof URL)&&(t=fetch(t));let{instance:n,module:r}=await Oe(await t,e);return Pe(n,r)}var oe=ie;var B=class{#e=null;#o=[];#n(){if(!this.#e)throw new Error("Analyzer not initialized");return this.#e}#r(e,n){this.#n().on_notification("textDocument/didOpen",{textDocument:{uri:e,languageId:"typst",version:1,text:n}})}#s(e){this.#n().on_notification("textDocument/didClose",{textDocument:{uri:e}})}#i(e,n,r){this.#n().on_notification("textDocument/didChange",{textDocument:{uri:e,version:n},contentChanges:[{text:r}]})}#t(){if(this.#e)for(;this.#o.length>0;)for(let e of this.#o.splice(0))this.#e.on_event(e)}async init(e){await oe({module_or_path:e}),this.#e=new S({sendEvent:r=>{this.#o.push(r)},sendRequest:({id:r})=>{this.#e.on_response({id:r,result:null})},sendNotification:()=>{},resolveFn:()=>{}});let n=this.#e.on_request("initialize",{capabilities:{textDocument:{completion:{completionItem:{snippetSupport:!0}},hover:{contentFormat:["markdown","plaintext"]}}},rootUri:"file:///"});n&&typeof n=="object"&&"then"in n&&await n,this.#t(),this.#e.on_notification("initialized",{}),this.#t()}async didOpen(e,n){this.#r(e,n),this.#t()}async didClose(e){this.#s(e),this.#t()}async didChange(e,n,r){this.#i(e,n,r),this.#t()}async didChangeMany(e,n){this.#n();for(let{uri:r,content:i}of e)this.#r(r,i);for(let{uri:r,version:i,content:s}of n)this.#i(r,i,s);this.#t()}async didCloseMany(e){this.#n();for(let n of e)this.#s(n);this.#t()}async completion(e,n){let r=await this.#n().on_request("textDocument/completion",{textDocument:{uri:e},position:n});return this.#t(),r??null}async hover(e,n){let r=await this.#n().on_request("textDocument/hover",{textDocument:{uri:e},position:n});return this.#t(),r??null}async completionWithDoc(e,n,r,i,s){return s==="open"?this.#r(e,r):this.#i(e,n,r),this.completion(e,i)}async hoverWithDoc(e,n,r,i,s){return s==="open"?this.#r(e,r):this.#i(e,n,r),this.hover(e,i)}destroy(){this.#e?.free(),this.#e=null}};z(new B);})();\n/*! Bundled license information:\n\ncomlink/dist/esm/comlink.mjs:\n (**\n * @license\n * Copyright 2019 Google LLC\n * SPDX-License-Identifier: Apache-2.0\n *)\n*/\n');
|
|
13
|
+
function hasNonAscii(text) {
|
|
14
|
+
for (let i = 0; i < text.length; i++) {
|
|
15
|
+
if (text.charCodeAt(i) > 127) return true;
|
|
16
|
+
}
|
|
17
|
+
return false;
|
|
21
18
|
}
|
|
22
|
-
function
|
|
23
|
-
return createBlobWorker('"use strict";(()=>{var nn=Object.defineProperty;var z=(r,t)=>()=>(r&&(t=r(r=0)),t);var rt=(r,t)=>{for(var e in t)nn(r,e,{get:t[e],enumerable:!0})};function Ye(){return X([],{assets:!1})}function Qe(r){return X([],r)}function xn(r){let t=[];if(r&&r?.assets!==!1&&r?.assets?.length&&r?.assets?.length>0){let e={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/"},n=r.assetUrlPrefix??e;typeof n=="string"?n={_:n}:n={...e,...n};for(let o of Object.keys(n)){let s=n[o];s[s.length-1]!=="/"&&(n[o]=s+"/")}let i=(o,s)=>s.map(_=>(n[o]||n._)+_);for(let o of r.assets)switch(o){case"text":t.push(...i(o,mn));break;case"cjk":t.push(...i(o,yn));break;case"emoji":t.push(...i(o,vn));break}}return t}function X(r,t){let e=xn(t),n=async(i,{ref:o,builder:s})=>{t?.fetcher&&o.setFetcher(t.fetcher),await o.loadFonts(s,[...r,...e])};return n._preloadRemoteFontOptions=t,n._kind="fontLoader",n}function Jt(r){return async(t,{builder:e})=>new Promise(n=>{e.set_package_registry(r,function(i){return r.resolve(i,this)}),n()})}function ye(r){return async(t,e)=>{if(e.alreadySetAccessModel)throw new Error(`already set some assess model before: ${e.alreadySetAccessModel.constructor?.name}(${e.alreadySetAccessModel})`);return e.alreadySetAccessModel=r,new Promise(n=>{e.builder.set_access_model(r,i=>{let o=r.getMTime(i);return o?o.getTime():0},i=>r.isFile(i)||!1,i=>r.getRealPath(i)||i,i=>r.readAll(i)),n()})}}var mn,yn,vn,It=z(()=>{mn=["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"],yn=["InriaSerif-Bold.ttf","InriaSerif-BoldItalic.ttf","InriaSerif-Italic.ttf","InriaSerif-Regular.ttf","Roboto-Regular.ttf","NotoSerifCJKsc-Regular.otf"],vn=["TwitterColorEmoji.ttf","NotoColorEmoji-Regular-COLR.subset.ttf"]});var x,it,Et=z(()=>{x=Symbol.for("reflexo-obj");(function(r){r[r.PIXEL_PER_PT=3]="PIXEL_PER_PT"})(it||(it={}))});var Gt,Ze=z(()=>{Et();Gt=class{pageInfos;loadPageCount;imageScaleFactor;container;canvasList;textLayerList;commonList;textLayerParentList;semanticLayerList;constructor(t,e,n){this.pageInfos=t,this.imageScaleFactor=n.pixelPerPt??it.PIXEL_PER_PT,e.innerHTML="",e.style.width="100%",this.container=e,this.canvasList=new Array(this.loadPageCount),this.textLayerList=new Array(this.loadPageCount),this.commonList=new Array(this.loadPageCount),this.textLayerParentList=new Array(this.loadPageCount),this.semanticLayerList=new Array(this.loadPageCount);let i=(o,s,_)=>{let d=Math.ceil(s.width)*this.imageScaleFactor,l=Math.ceil(s.height)*this.imageScaleFactor,f=this.canvasList[o]=document.createElement("canvas"),v=this.semanticLayerList[o]=document.createElement("div"),S=this.textLayerList[o]=document.createElement("div"),E=this.textLayerParentList[o]=document.createElement("div");if(f.getContext("2d")){let j=document.createElement("div");f.width=d,f.height=l,j.appendChild(f),_.appendChild(j),j.style.position="absolute"}{E.appendChild(S),E.className="typst-html-semantics";let j=e.offsetWidth,T=j/s.width;E.style.width=`${j}px`,E.style.height=`${s.height*T}px`,E.style.setProperty("--data-text-width",`${T}px`),E.style.setProperty("--data-text-height",`${T}px`),_.classList.add("typst-page"),_.classList.add("canvas"),_.style.width=`${j}px`,_.style.height=`${l*T}px`,_.style.position="relative",v.appendChild(E),_.appendChild(v)}};for(let o=0;o<this.pageInfos.length;o++){let s=this.pageInfos[o],_;_=this.commonList[o]=document.createElement("div"),e.appendChild(_),i(o,s,_)}}resetLayout(){for(let t=0;t<this.pageInfos.length;t++){let e=this.pageInfos[t],n=Math.ceil(e.width)*this.imageScaleFactor,i=Math.ceil(e.height)*this.imageScaleFactor,o=this.canvasList[t].parentElement;if(!o)throw new Error(`canvasDiv is null for page ${t}, canvas list length ${this.canvasList.length}`);let s=this.commonList[t],_=this.textLayerParentList[t],d=this.container.offsetWidth,l=d/n;_.style.width=`${d}px`,_.style.height=`${i*l}px`,s.style.width=`${d}px`,s.style.height=`${i*l}px`;let f=this.container.offsetWidth/n;o.style.transformOrigin="0px 0px",o.style.transform=`scale(${f})`}}}});var kn,ot,ve=z(()=>{kn=r=>{let t=!1,e;return()=>t?e:(t=!0,e=r())},ot=class{wasmBin;initOnce;constructor(t){if(typeof t!="function")throw new Error("initFn is not a function");this.initOnce=kn(async()=>{await t(this.wasmBin)})}async init(t){this.wasmBin=t,await this.initOnce()}}});async function Xt(r,t,e,n){return await t.init(r?.getModule?.()),await new xe().build(r,new e,n)}function Se(r){return()=>{let t=new XMLHttpRequest;return t.overrideMimeType("text/plain; charset=x-user-defined"),t.open("GET",r.url,!1),t.send(null),t.status===200&&(t.response instanceof String||typeof t.response=="string")?Uint8Array.from(t.response,e=>e.charCodeAt(0)):new Uint8Array}}var xe,Kt=z(()=>{xe=class{loadedFonts=new Set;fetcher=fetch;setFetcher(t){this.fetcher=t}async loadFonts(t,e){let n=new Function("m","return import(m)"),i=this.fetcher||=await(async function(){let{fetchBuilder:_,FileSystemCache:d}=await n("node-fetch-cache"),l=new d({cacheDirectory:".cache/typst/fonts"}),f=_.withCache(l);return function(v,S){let E=setTimeout(()=>{console.warn("font fetching is stucking:",v)},15e3);return f(v,S).finally(()=>{clearTimeout(E)})}})(),o=e.filter(_=>_ instanceof Uint8Array||typeof _=="object"&&"info"in _?!0:this.loadedFonts.has(_)?!1:(this.loadedFonts.add(_),!0)),s=await Promise.all(o.map(async _=>{if(_ instanceof Uint8Array){await t.add_raw_font(_);return}if(typeof _=="object"&&"info"in _){await t.add_lazy_font(_,"blob"in _?_.blob:Se(_));return}return new Uint8Array(await(await i(_)).arrayBuffer())}));for(let _ of s)_&&await t.add_raw_font(_)}async build(t,e,n){let i={ref:this,builder:e,hooks:n};for(let o of t?.beforeBuild??[])await o(void 0,i);return n.latelyBuild&&n.latelyBuild(i),await e.build()}}});function tr(r){return class{impl;kModule;constructor(e){if(e.isContentPreview&&(e.renderMode="canvas"),this.kModule=e.kModule,this.impl=new r(e),!this.impl.r)throw new Error(`mode is not supported, ${e?.renderMode}`);e.isContentPreview&&(this.impl.partialRendering=!0,this.impl.pixelPerPt=1,this.impl.isMixinOutline=!0)}dispose(){this.impl.dispose()}reset(){this.impl.reset()}addChangement(e){this.impl.addChangement(e)}addViewportChange(){this.impl.addViewportChange()}setPageColor(e){this.impl.pageColor=e,this.addViewportChange()}setPartialRendering(e){this.impl.partialRendering=e}setCursor(e,n,i){this.impl.cursorPosition=[e,n,i]}setPartialPageNumber(e){return e<=0||e>this.kModule.retrievePagesInfo().length?!1:(this.impl.partialRenderPage=e-1,this.addViewportChange(),!0)}getPartialPageNumber(){return this.impl.partialRenderPage+1}setOutineData(e){this.impl.outline=e,this.addViewportChange()}}}function er(r,...t){return t.reduce((e,n)=>n(e),r)}var V,Yt,rr=z(()=>{(function(r){r[r.Doc=0]="Doc",r[r.Slide=1]="Slide"})(V||(V={}));Yt=class r{hookedElem;kModule;opts;modes=[];partialRendering=!0;renderMode="svg";r=void 0;previewMode=V.Doc;isContentPreview=!1;isMixinOutline=!1;backgroundColor="black";pageColor="white";pixelPerPt=3;retrieveDOMState;isRendering=!1;moduleInitialized=!1;patchQueue=[];disposeList=[];canvasRenderCToken;currentRealScale=1;currentScaleRatio=1;vpTimeout=void 0;sampledRenderTime=0;partialRenderPage=0;outline=void 0;cursorPosition=void 0;cachedDOMState={width:0,height:0,window:{innerWidth:0,innerHeight:0},boundingRect:{left:0,top:0,right:0}};constructor(t){this.hookedElem=t.hookedElem,this.kModule=t.kModule,this.opts=t||{};{let{renderMode:e,previewMode:n,isContentPreview:i,retrieveDOMState:o}=t||{};this.partialRendering=!1,this.renderMode=e??this.renderMode,this.previewMode=n??this.previewMode,this.isContentPreview=i||!1,this.retrieveDOMState=o??(()=>({width:this.hookedElem.offsetWidth,height:this.hookedElem.offsetHeight,window:{innerWidth:window.innerWidth,innerHeight:window.innerHeight},boundingRect:this.hookedElem.getBoundingClientRect()})),this.backgroundColor=getComputedStyle(document.documentElement).getPropertyValue("--typst-preview-background-color")}this.hookedElem.classList.add("hide-scrollbar-x"),this.hookedElem.parentElement?.classList.add("hide-scrollbar-x"),this.previewMode===V.Slide&&(this.hookedElem.classList.add("hide-scrollbar-y"),this.hookedElem.parentElement?.classList.add("hide-scrollbar-y")),this.installCtrlWheelHandler()}reset(){this.kModule.reset(),this.moduleInitialized=!1}dispose(){let t=this.disposeList;this.disposeList=[],t.forEach(e=>e())}static derive(t,e){return["rescale","rerender","postRender"].reduce((n,i)=>(n[i]=t[`${i}$${e}`].bind(t),console.assert(n[i]!==void 0,`${i}$${e} is undefined`),n),{})}registerMode(t){let e=r.derive(this,t);this.modes.push([t,e]),t===this.renderMode&&(this.r=e)}installCtrlWheelHandler(){let t=[.1,.2,.3,.4,.5,.6,.7,.8,.9,1,1.1,1.3,1.5,1.7,1.9,2.1,2.4,2.7,3,3.3,3.7,4.1,4.6,5.1,5.7,6.3,7,7.7,8.5,9.4,10],e=n=>{if(n.ctrlKey){n.preventDefault(),this.cachedDOMState=this.retrieveDOMState(),window.onresize!==null&&(window.onresize=null);let i=this.currentScaleRatio;if(n.deltaY<0){if(this.currentScaleRatio>=t.at(-1))return;this.currentScaleRatio=t.filter(l=>l>this.currentScaleRatio).at(0)}else if(n.deltaY>0){if(this.currentScaleRatio<=t.at(0))return;this.currentScaleRatio=t.filter(l=>l<this.currentScaleRatio).at(-1)}else return;let o=this.currentScaleRatio/i,s=n.pageX*(o-1),_=n.pageY*(o-1);Math.abs(this.currentScaleRatio-1)<1e-5?(this.hookedElem.classList.add("hide-scrollbar-x"),this.hookedElem.parentElement?.classList.add("hide-scrollbar-x"),this.previewMode===V.Slide&&(this.hookedElem.classList.add("hide-scrollbar-y"),this.hookedElem.parentElement?.classList.add("hide-scrollbar-y"))):(this.hookedElem.classList.remove("hide-scrollbar-x"),this.hookedElem.parentElement?.classList.remove("hide-scrollbar-x"),this.previewMode===V.Slide&&(this.hookedElem.classList.remove("hide-scrollbar-y"),this.hookedElem.parentElement?.classList.remove("hide-scrollbar-y")));let d=this.hookedElem.firstElementChild;if(d){let l=this.getSvgScaleRatio(),f=Number.parseFloat(d.getAttribute("data-height")),v=Math.ceil(f*l);this.hookedElem.style.height=`${v*2}px`}return window.scrollBy(s,_),this.addViewportChange(),!1}};this.renderMode!=="dom"&&(typeof acquireVsCodeApi<"u"?(window.addEventListener("wheel",e,{passive:!1}),this.disposeList.push(()=>{window.removeEventListener("wheel",e)})):(document.body.addEventListener("wheel",e,{passive:!1}),this.disposeList.push(()=>{document.body.removeEventListener("wheel",e)})))}getSvgScaleRatio(){let t=this.hookedElem.firstElementChild;if(!t)return 0;let e=this.cachedDOMState,n=Number.parseFloat(t.getAttribute("data-width")||t.getAttribute("width")||"1"),i=Number.parseFloat(t.getAttribute("data-height")||t.getAttribute("height")||"1");return this.currentRealScale=this.previewMode===V.Slide?Math.min(e.width/n,e.height/i):e.width/n,this.currentRealScale*this.currentScaleRatio}processQueue(t){let e=t[0];switch(e){case"new":case"diff-v1":return e==="new"&&this.reset(),this.kModule.manipulateData({action:"merge",data:t[1]}),this.moduleInitialized=!0,!0;case"viewport-change":return this.moduleInitialized?!0:(console.log("viewport-change before initialization"),!1);default:return console.log("svgUpdateEvent",t),!1}}triggerUpdate(){if(this.isRendering)return;this.isRendering=!0;let t=async()=>{if(this.cachedDOMState=this.retrieveDOMState(),this.patchQueue.length===0){this.isRendering=!1,this.postprocessChanges();return}try{let e=performance.now(),n=this.canvasRenderCToken;n&&(await n.cancel(),await n.wait(),this.canvasRenderCToken=void 0,console.log("cancel canvas rendering"));let i=!1;for(;this.patchQueue.length>0;)i=this.processQueue(this.patchQueue.shift())||i;let o=performance.now();i&&(this.r.rescale(),await this.r.rerender(),this.r.rescale());let s=performance.now(),_=(d,l,f)=>`${d} ${(f-l).toFixed(2)} ms`;this.sampledRenderTime=s-e,requestAnimationFrame(t)}catch(e){console.error(e),this.isRendering=!1,this.postprocessChanges()}};requestAnimationFrame(t)}postprocessChanges(){this.r.postRender(),this.previewMode===V.Slide&&document.querySelectorAll(".typst-page-number-indicator").forEach(t=>{t.textContent=`${this.kModule.retrievePagesInfo().length}`})}addChangement(t){t[0]==="new"&&this.patchQueue.splice(0,this.patchQueue.length);let e=()=>{this.vpTimeout=void 0,this.patchQueue.push(t),this.triggerUpdate()};this.vpTimeout!==void 0&&clearTimeout(this.vpTimeout),t[0]==="viewport-change"&&this.isRendering?this.vpTimeout=setTimeout(e,this.sampledRenderTime||100):e()}addViewportChange(){this.addChangement(["viewport-change",""])}}});var Qt,nr=z(()=>{Qt=class{isCancellationRequested=!1;_onCancelled;_onCancelledResolveResolved;constructor(){let t,e;this._onCancelled=new Promise(n=>{t=n,e&&e(n)}),this._onCancelledResolveResolved=new Promise(n=>{e=n,t&&n(t)})}async cancel(){await this._onCancelledResolveResolved,this.isCancellationRequested=!0}isCancelRequested(){return this.isCancellationRequested}async consume(){(await this._onCancelledResolveResolved)()}wait(){return this._onCancelled}}});function En(r){return class extends r{tmpl=document.createElement("template");stub=this.createElement("<stub></stub>");plugin;docKernel;resourceHeader=void 0;pages=[];domScale=1;track_mode=ke.Doc;current_task=void 0;viewport;constructor(...e){if(super(...e),this.registerMode("dom"),this.disposeList.push(()=>{this.dispose()}),this.plugin=this.opts.renderer,this.opts.domScale!==void 0){if(this.opts.domScale<=0)throw new Error("domScale must be positive");this.domScale=this.opts.domScale}}dispose(){for(let e of this.pages)e.dispose();this.docKernel&&this.docKernel.free()}createElement(e){return this.tmpl.innerHTML=e,this.tmpl.content.firstElementChild}async mountDom(e){if(this.docKernel)throw new Error("already mounted");this.hookedElem.innerHTML=\'<svg class="typst-svg-resources" viewBox="0 0 0 0" width="0" height="0" style="opacity: 0; position: absolute;"></svg>\',this.resourceHeader=this.hookedElem.querySelector(".typst-svg-resources"),this.docKernel=await this.plugin.renderer.mount_dom(this.kModule[x],this.hookedElem),this.docKernel.bind_functions({populateGlyphs:n=>{let o=this.createElement(n).firstElementChild;this.resourceHeader.append(o)}})}async cancelAnyway$dom(){if(this.current_task){let e=this.current_task;this.current_task=void 0,await e.cancel()}}retrieveDOMPages(){return Array.from(this.hookedElem.querySelectorAll(".typst-dom-page"))}postRender$dom(){}rescale$dom(){}getDomViewport(e,n){let i=n.left,o=-n.top,s=n.right,_=e.innerHeight-n.top,d={x:0,y:o/this.domScale,width:Math.max(s-i,0)/this.domScale,height:Math.max(_-o,0)/this.domScale};return(d.width<=0||d.height<=0)&&(d.x=d.y=d.width=d.height=0),d}async rerender$dom(){let e=this.retrieveDOMState(),{x:n,y:i,width:o,height:s}=this.getDomViewport(e.window,e.boundingRect);if(!await this.docKernel.relayout(n,i,o,s))return;let d=new Qt;this.doRender$dom(d),this.current_task=d}async doRender$dom(e){let n=(_,d)=>{if(_&&!e.isCancelRequested()&&d)return d()},i=this.retrieveDOMPages().map(_=>{let{innerWidth:d,innerHeight:l}=window,f=_.getBoundingClientRect();return{inWindow:!(f.left>d||f.right<0||f.top>l||f.bottom<0),page:_}}),o=async _=>{if(await In(),e.isCancelRequested())return;let d=i[_].page,l=d.getBoundingClientRect(),f=this.getDomViewport(window,l),v=T=>this.docKernel.need_repaint(_,f.x,f.y,f.width,f.height,T),S=T=>this.docKernel.repaint(_,f.x,f.y,f.width,f.height,T),E=T=>{if(!e.isCancelRequested())return n(v(T),()=>S(T))};await E(q.Layout);let B=(l.width?Number.parseFloat(d.getAttribute("data-width"))/l.width:1)*this.domScale,j=(l.height?Number.parseFloat(d.getAttribute("data-height"))/l.height:1)*this.domScale;f.x*=B,f.y*=j,f.y-=100,f.width*=B,f.height*=j,f.height+=200,await E(q.Svg),await E(q.Semantics),!e.isCancelRequested()&&(v(q.PrepareCanvas)?(async()=>{if(await S(q.PrepareCanvas),!e.isCancelRequested())return E(q.Canvas)})():await E(q.Canvas))},s=async _=>{for(let d=0;d<i.length;++d){if(e.isCancelRequested())return;i[d].inWindow===_&&await o(d)}};this.cancelAnyway$dom(),await s(!0),await s(!1),e.isCancelRequested()}}}var In,ke,q,Zt,ir=z(()=>{Et();rr();nr();In=()=>new Promise(r=>requestAnimationFrame(r));(function(r){r[r.Doc=0]="Doc",r[r.Pages=1]="Pages"})(ke||(ke={}));(function(r){r[r.Layout=0]="Layout",r[r.Svg=1]="Svg",r[r.Semantics=2]="Semantics",r[r.PrepareCanvas=3]="PrepareCanvas",r[r.Canvas=4]="Canvas"})(q||(q={}));Zt=class extends tr(er(Yt,En)){}});function m(r){st===N.length&&N.push(N.length+1);let t=st;if(st=N[t],typeof st!="number")throw new Error("corrupt heap");return N[t]=r,t}function L(r){if(typeof r!="boolean")throw new Error(`expected a boolean argument, found ${typeof r}`)}function $(r,t){if(!(r instanceof t))throw new Error(`expected instance of ${t.name}`)}function w(r){if(typeof r!="number")throw new Error(`expected a number argument, found ${typeof r}`)}function Re(r){let t=typeof r;if(t=="number"||t=="boolean"||r==null)return`${r}`;if(t=="string")return`"${r}"`;if(t=="symbol"){let i=r.description;return i==null?"Symbol":`Symbol(${i})`}if(t=="function"){let i=r.name;return typeof i=="string"&&i.length>0?`Function(${i})`:"Function"}if(Array.isArray(r)){let i=r.length,o="[";i>0&&(o+=Re(r[0]));for(let s=1;s<i;s++)o+=", "+Re(r[s]);return o+="]",o}let e=/\\[object ([^\\]]+)\\]/.exec(toString.call(r)),n;if(e&&e.length>1)n=e[1];else return toString.call(r);if(n=="Object")try{return"Object("+JSON.stringify(r)+")"}catch{return"Object"}return r instanceof Error?`${r.name}: ${r.message}\n${r.stack}`:n}function Rn(r){r<132||(N[r]=st,st=r)}function or(r,t){return r=r>>>0,at().subarray(r/1,r/1+t)}function b(){return(K===null||K.buffer.detached===!0||K.buffer.detached===void 0&&K.buffer!==a.memory.buffer)&&(K=new DataView(a.memory.buffer)),K}function R(r,t){return r=r>>>0,On(r,t)}function Cn(){return(Rt===null||Rt.byteLength===0)&&(Rt=new Uint32Array(a.memory.buffer)),Rt}function at(){return(Ct===null||Ct.byteLength===0)&&(Ct=new Uint8Array(a.memory.buffer)),Ct}function u(r){return N[r]}function I(r,t){try{return r.apply(this,t)}catch(e){a.__wbindgen_export3(m(e))}}function A(r){return r==null}function g(r,t){try{return r.apply(this,t)}catch(e){let n=(function(){try{return e instanceof Error?`${e.message}\n\nStack:\n${e.stack}`:e.toString()}catch{return"<failed to stringify thrown value>"}})();throw console.error("wasm-bindgen: imported JS function that was not marked as `catch` threw an error:",n),e}}function sr(r,t,e,n){let i={a:r,b:t,cnt:1,dtor:e},o=(...s)=>{i.cnt++;try{return n(i.a,i.b,...s)}finally{o._wbg_cb_unref()}};return o._wbg_cb_unref=()=>{--i.cnt===0&&(i.dtor(i.a,i.b),i.a=0,ee.unregister(i))},ee.register(o,i,i),o}function An(r,t,e,n){let i={a:r,b:t,cnt:1,dtor:e},o=(...s)=>{i.cnt++;let _=i.a;i.a=0;try{return n(_,i.b,...s)}finally{i.a=_,o._wbg_cb_unref()}};return o._wbg_cb_unref=()=>{--i.cnt===0&&(i.dtor(i.a,i.b),i.a=0,ee.unregister(i))},ee.register(o,i,i),o}function Pn(r,t){let e=t(r.length*4,4)>>>0;return Cn().set(r,e/4),F=r.length,e}function re(r,t){let e=t(r.length*1,1)>>>0;return at().set(r,e/1),F=r.length,e}function ar(r,t){let e=t(r.length*4,4)>>>0,n=b();for(let i=0;i<r.length;i++)n.setUint32(e+4*i,m(r[i]),!0);return F=r.length,e}function D(r,t,e){if(typeof r!="string")throw new Error(`expected a string argument, found ${typeof r}`);if(e===void 0){let _=At.encode(r),d=t(_.length,1)>>>0;return at().subarray(d,d+_.length).set(_),F=_.length,d}let n=r.length,i=t(n,1)>>>0,o=at(),s=0;for(;s<n;s++){let _=r.charCodeAt(s);if(_>127)break;o[i+s]=_}if(s!==n){s!==0&&(r=r.slice(s)),i=e(i,n,n=s+r.length*3,1)>>>0;let _=at().subarray(i+s,i+n),d=At.encodeInto(r,_);if(d.read!==r.length)throw new Error("failed to pass whole string");s+=d.written,i=e(i,n,s,1)>>>0}return F=s,i}function P(r){let t=u(r);return Rn(r),t}function On(r,t){return Ie+=t,Ie>=Fn&&(te=new TextDecoder("utf-8",{ignoreBOM:!0,fatal:!0}),te.decode(),Ie=t),te.decode(at().subarray(r,r+t))}function Mn(r,t){w(r),w(t),a.__wasm_bindgen_func_elem_1034(r,t)}function Tn(r,t,e){w(r),w(t),a.__wasm_bindgen_func_elem_1035(r,t,m(e))}function Ln(r,t,e){w(r),w(t),a.__wasm_bindgen_func_elem_1056(r,t,m(e))}function Dn(r,t,e,n){w(r),w(t),a.__wasm_bindgen_func_elem_3553(r,t,m(e),m(n))}function zn(){let r=a.renderer_build_info();return P(r)}async function Bn(r,t){if(typeof Response=="function"&&r instanceof Response){if(typeof WebAssembly.instantiateStreaming=="function")try{return await WebAssembly.instantiateStreaming(r,t)}catch(n){if(r.ok&&Wn.has(r.type)&&r.headers.get("Content-Type")!=="application/wasm")console.warn("`WebAssembly.instantiateStreaming` failed because your server does not serve Wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\\n",n);else throw n}let e=await r.arrayBuffer();return await WebAssembly.instantiate(e,t)}else{let e=await WebAssembly.instantiate(r,t);return e instanceof WebAssembly.Instance?{instance:e,module:r}:e}}function hr(){let r={};return r.wbg={},r.wbg.__wbg___wbindgen_debug_string_adfb662ae34724b6=function(t,e){let n=Re(u(e)),i=D(n,a.__wbindgen_export,a.__wbindgen_export2),o=F;b().setInt32(t+4,o,!0),b().setInt32(t+0,i,!0)},r.wbg.__wbg___wbindgen_is_function_8d400b8b1af978cd=function(t){let e=typeof u(t)=="function";return L(e),e},r.wbg.__wbg___wbindgen_is_undefined_f6b95eab589e0269=function(t){let e=u(t)===void 0;return L(e),e},r.wbg.__wbg___wbindgen_jsval_eq_b6101cc9cef1fe36=function(t,e){let n=u(t)===u(e);return L(n),n},r.wbg.__wbg___wbindgen_string_get_a2a31e16edf96e42=function(t,e){let n=u(e),i=typeof n=="string"?n:void 0;var o=A(i)?0:D(i,a.__wbindgen_export,a.__wbindgen_export2),s=F;b().setInt32(t+4,s,!0),b().setInt32(t+0,o,!0)},r.wbg.__wbg___wbindgen_throw_dd24417ed36fc46e=function(t,e){throw new Error(R(t,e))},r.wbg.__wbg__wbg_cb_unref_87dfb5aaa0cbcea7=function(){return g(function(t){u(t)._wbg_cb_unref()},arguments)},r.wbg.__wbg_appendChild_7465eba84213c75f=function(){return I(function(t,e){let n=u(t).appendChild(u(e));return m(n)},arguments)},r.wbg.__wbg_call_3020136f7a2d6e44=function(){return I(function(t,e,n){let i=u(t).call(u(e),u(n));return m(i)},arguments)},r.wbg.__wbg_call_78f94eb02ec7f9b2=function(){return I(function(t,e,n,i,o){let s=u(t).call(u(e),u(n),u(i),u(o));return m(s)},arguments)},r.wbg.__wbg_call_abb4ff46ce38be40=function(){return I(function(t,e){let n=u(t).call(u(e));return m(n)},arguments)},r.wbg.__wbg_call_c8baa5c5e72d274e=function(){return I(function(t,e,n,i){let o=u(t).call(u(e),u(n),u(i));return m(o)},arguments)},r.wbg.__wbg_clearRect_c2909c2f38887f82=function(){return g(function(t,e,n,i,o){u(t).clearRect(e,n,i,o)},arguments)},r.wbg.__wbg_clientWidth_dbc9540f4ebdce2a=function(){return g(function(t){let e=u(t).clientWidth;return w(e),e},arguments)},r.wbg.__wbg_clip_35de02bb25d222d9=function(){return g(function(t,e){u(t).clip(u(e))},arguments)},r.wbg.__wbg_clip_afc9a92171eee96e=function(){return g(function(t,e){u(t).clip(u(e))},arguments)},r.wbg.__wbg_cloneNode_c9c45b24b171a776=function(){return I(function(t){let e=u(t).cloneNode();return m(e)},arguments)},r.wbg.__wbg_content_ad90fa08b8c037c5=function(){return g(function(t){let e=u(t).content;return m(e)},arguments)},r.wbg.__wbg_createElement_da4ed2b219560fc6=function(){return I(function(t,e,n){let i=u(t).createElement(R(e,n));return m(i)},arguments)},r.wbg.__wbg_createImageBitmap_15b94d7a7277d0be=function(){return I(function(t,e){let n=u(t).createImageBitmap(u(e));return m(n)},arguments)},r.wbg.__wbg_createImageBitmap_4772db6cb0dff013=function(){return I(function(t,e){let n=u(t).createImageBitmap(u(e));return m(n)},arguments)},r.wbg.__wbg_createObjectURL_7d9f7f8f41373850=function(){return I(function(t,e){let n=URL.createObjectURL(u(e)),i=D(n,a.__wbindgen_export,a.__wbindgen_export2),o=F;b().setInt32(t+4,o,!0),b().setInt32(t+0,i,!0)},arguments)},r.wbg.__wbg_document_5b745e82ba551ca5=function(){return g(function(t){let e=u(t).document;return A(e)?0:m(e)},arguments)},r.wbg.__wbg_drawImage_2859dfb229439d8c=function(){return I(function(t,e,n,i,o,s){u(t).drawImage(u(e),n,i,o,s)},arguments)},r.wbg.__wbg_drawImage_6949f7679b2a9758=function(){return I(function(t,e,n,i,o,s){u(t).drawImage(u(e),n,i,o,s)},arguments)},r.wbg.__wbg_drawImage_c2aacfe3133aedb7=function(){return I(function(t,e,n,i){u(t).drawImage(u(e),n,i)},arguments)},r.wbg.__wbg_drawImage_c40aff4a38206f4a=function(){return I(function(t,e,n,i,o,s){u(t).drawImage(u(e),n,i,o,s)},arguments)},r.wbg.__wbg_drawImage_c4f2c6d2bcfa9463=function(){return I(function(t,e,n,i){u(t).drawImage(u(e),n,i)},arguments)},r.wbg.__wbg_drawImage_de5946f9cc23c2b9=function(){return I(function(t,e,n,i){u(t).drawImage(u(e),n,i)},arguments)},r.wbg.__wbg_drawImage_e2012c2a2d434ee2=function(){return I(function(t,e,n,i,o,s){u(t).drawImage(u(e),n,i,o,s)},arguments)},r.wbg.__wbg_error_7534b8e9a36f1ab4=function(){return g(function(t,e){let n,i;try{n=t,i=e,console.error(R(t,e))}finally{a.__wbindgen_export4(n,i,1)}},arguments)},r.wbg.__wbg_fillRect_84131220403e26a4=function(){return g(function(t,e,n,i,o){u(t).fillRect(e,n,i,o)},arguments)},r.wbg.__wbg_fillRect_e0efe328740308e7=function(){return g(function(t,e,n,i,o){u(t).fillRect(e,n,i,o)},arguments)},r.wbg.__wbg_fill_2f2cb4f3f75aadd4=function(){return g(function(t,e,n){u(t).fill(u(e),_r[n])},arguments)},r.wbg.__wbg_fill_38a7d7455451c001=function(){return g(function(t,e,n){u(t).fill(u(e),_r[n])},arguments)},r.wbg.__wbg_fill_3d82e52894462c95=function(){return g(function(t,e){u(t).fill(u(e))},arguments)},r.wbg.__wbg_fill_f1043be5324533f3=function(){return g(function(t,e){u(t).fill(u(e))},arguments)},r.wbg.__wbg_firstElementChild_54d515b19cee5ae7=function(){return g(function(t){let e=u(t).firstElementChild;return A(e)?0:m(e)},arguments)},r.wbg.__wbg_firstElementChild_e207b33aaa4a86df=function(){return g(function(t){let e=u(t).firstElementChild;return A(e)?0:m(e)},arguments)},r.wbg.__wbg_getAttribute_80900eec94cb3636=function(){return g(function(t,e,n,i){let o=u(e).getAttribute(R(n,i));var s=A(o)?0:D(o,a.__wbindgen_export,a.__wbindgen_export2),_=F;b().setInt32(t+4,_,!0),b().setInt32(t+0,s,!0)},arguments)},r.wbg.__wbg_getContext_01f42b234e833f0a=function(){return I(function(t,e,n){let i=u(t).getContext(R(e,n));return A(i)?0:m(i)},arguments)},r.wbg.__wbg_getContext_2f210d0a58d43d95=function(){return I(function(t,e,n){let i=u(t).getContext(R(e,n));return A(i)?0:m(i)},arguments)},r.wbg.__wbg_get_af9dab7e9603ea93=function(){return I(function(t,e){let n=Reflect.get(u(t),u(e));return m(n)},arguments)},r.wbg.__wbg_globalCompositeOperation_03e6a5201c8ee369=function(){return I(function(t,e){let n=u(e).globalCompositeOperation,i=D(n,a.__wbindgen_export,a.__wbindgen_export2),o=F;b().setInt32(t+4,o,!0),b().setInt32(t+0,i,!0)},arguments)},r.wbg.__wbg_globalCompositeOperation_d52c6e6666e4be00=function(){return I(function(t,e){let n=u(e).globalCompositeOperation,i=D(n,a.__wbindgen_export,a.__wbindgen_export2),o=F;b().setInt32(t+4,o,!0),b().setInt32(t+0,i,!0)},arguments)},r.wbg.__wbg_height_3a0b31e52a5b7f17=function(){return g(function(t){let e=u(t).height;return w(e),e},arguments)},r.wbg.__wbg_incrdomdocclient_new=function(){return g(function(t){let e=ct.__wrap(t);return m(e)},arguments)},r.wbg.__wbg_instanceof_CanvasRenderingContext2d_d070139aaac1459f=function(){return g(function(t){let e;try{e=u(t)instanceof CanvasRenderingContext2D}catch{e=!1}let n=e;return L(n),n},arguments)},r.wbg.__wbg_instanceof_Element_6f7ba982258cfc0f=function(){return g(function(t){let e;try{e=u(t)instanceof Element}catch{e=!1}let n=e;return L(n),n},arguments)},r.wbg.__wbg_instanceof_HtmlCanvasElement_c4251b1b6a15edcc=function(){return g(function(t){let e;try{e=u(t)instanceof HTMLCanvasElement}catch{e=!1}let n=e;return L(n),n},arguments)},r.wbg.__wbg_instanceof_HtmlDivElement_a55b9d453d2d8037=function(){return g(function(t){let e;try{e=u(t)instanceof HTMLDivElement}catch{e=!1}let n=e;return L(n),n},arguments)},r.wbg.__wbg_instanceof_HtmlElement_20a3acb594113d73=function(){return g(function(t){let e;try{e=u(t)instanceof HTMLElement}catch{e=!1}let n=e;return L(n),n},arguments)},r.wbg.__wbg_instanceof_HtmlTemplateElement_702a22ea7e74d089=function(){return g(function(t){let e;try{e=u(t)instanceof HTMLTemplateElement}catch{e=!1}let n=e;return L(n),n},arguments)},r.wbg.__wbg_instanceof_ImageBitmap_e44697c70dffc0fe=function(){return g(function(t){let e;try{e=u(t)instanceof ImageBitmap}catch{e=!1}let n=e;return L(n),n},arguments)},r.wbg.__wbg_instanceof_OffscreenCanvasRenderingContext2d_52996da29a2bf2f5=function(){return g(function(t){let e;try{e=u(t)instanceof OffscreenCanvasRenderingContext2D}catch{e=!1}let n=e;return L(n),n},arguments)},r.wbg.__wbg_instanceof_OffscreenCanvas_8fb961f5ea27473f=function(){return g(function(t){let e;try{e=u(t)instanceof OffscreenCanvas}catch{e=!1}let n=e;return L(n),n},arguments)},r.wbg.__wbg_instanceof_Promise_eca6c43a2610558d=function(){return g(function(t){let e;try{e=u(t)instanceof Promise}catch{e=!1}let n=e;return L(n),n},arguments)},r.wbg.__wbg_instanceof_SvgGraphicsElement_16c442d1a36270b3=function(){return g(function(t){let e;try{e=u(t)instanceof SVGGraphicsElement}catch{e=!1}let n=e;return L(n),n},arguments)},r.wbg.__wbg_instanceof_SvgsvgElement_27a38efc9750b6fa=function(){return g(function(t){let e;try{e=u(t)instanceof SVGSVGElement}catch{e=!1}let n=e;return L(n),n},arguments)},r.wbg.__wbg_instanceof_Window_b5cf7783caa68180=function(){return g(function(t){let e;try{e=u(t)instanceof Window}catch{e=!1}let n=e;return L(n),n},arguments)},r.wbg.__wbg_instanceof_WorkerGlobalScope_9a3411db21c65a54=function(){return g(function(t){let e;try{e=u(t)instanceof WorkerGlobalScope}catch{e=!1}let n=e;return L(n),n},arguments)},r.wbg.__wbg_lastElementChild_6b90fe10adf639a2=function(){return g(function(t){let e=u(t).lastElementChild;return A(e)?0:m(e)},arguments)},r.wbg.__wbg_length_22ac23eaec9d8053=function(){return g(function(t){let e=u(t).length;return w(e),e},arguments)},r.wbg.__wbg_log_1d990106d99dacb7=function(){return g(function(t){console.log(u(t))},arguments)},r.wbg.__wbg_log_fd6486c6d5396ce5=function(){return g(function(t,e){console.log(u(t),u(e))},arguments)},r.wbg.__wbg_measureText_a465ecc06491802d=function(){return I(function(t,e,n){let i=u(t).measureText(R(e,n));return m(i)},arguments)},r.wbg.__wbg_new_1ba21ce319a06297=function(){return g(function(){let t=new Object;return m(t)},arguments)},r.wbg.__wbg_new_25f239778d6112b9=function(){return g(function(){let t=new Array;return m(t)},arguments)},r.wbg.__wbg_new_2884ddbcda091bc1=function(){return I(function(){let t=new Image;return m(t)},arguments)},r.wbg.__wbg_new_8a6f238a6ece86ea=function(){return g(function(){let t=new Error;return m(t)},arguments)},r.wbg.__wbg_new_9468dd6e5df427f6=function(){return I(function(t,e){let n=new OffscreenCanvas(t>>>0,e>>>0);return m(n)},arguments)},r.wbg.__wbg_new_df1173567d5ff028=function(){return g(function(t,e){let n=new Error(R(t,e));return m(n)},arguments)},r.wbg.__wbg_new_ff12d2b041fb48f1=function(){return g(function(t,e){try{var n={a:t,b:e},i=(s,_)=>{let d=n.a;n.a=0;try{return Dn(d,n.b,s,_)}finally{n.a=d}};let o=new Promise(i);return m(o)}finally{n.a=n.b=0}},arguments)},r.wbg.__wbg_new_from_slice_f9c22b9153b26992=function(){return g(function(t,e){let n=new Uint8Array(or(t,e));return m(n)},arguments)},r.wbg.__wbg_new_no_args_cb138f77cf6151ee=function(){return g(function(t,e){let n=new Function(R(t,e));return m(n)},arguments)},r.wbg.__wbg_new_with_length_aa5eaf41d35235e5=function(){return g(function(t){let e=new Uint8Array(t>>>0);return m(e)},arguments)},r.wbg.__wbg_new_with_path_string_3aea637e78135c46=function(){return I(function(t,e){let n=new Path2D(R(t,e));return m(n)},arguments)},r.wbg.__wbg_new_with_u8_array_sequence_and_options_d4def9ec0588c7ec=function(){return I(function(t,e){let n=new Blob(u(t),u(e));return m(n)},arguments)},r.wbg.__wbg_nextElementSibling_c745ee48314963c0=function(){return g(function(t){let e=u(t).nextElementSibling;return A(e)?0:m(e)},arguments)},r.wbg.__wbg_push_7d9be8f38fc13975=function(){return g(function(t,e){let n=u(t).push(u(e));return w(n),n},arguments)},r.wbg.__wbg_putImageData_c280ca107c4b7828=function(){return I(function(t,e,n,i){u(t).putImageData(u(e),n,i)},arguments)},r.wbg.__wbg_putImageData_e96eabf0e9610ed3=function(){return I(function(t,e,n,i){u(t).putImageData(u(e),n,i)},arguments)},r.wbg.__wbg_queueMicrotask_9b549dfce8865860=function(){return g(function(t){let e=u(t).queueMicrotask;return m(e)},arguments)},r.wbg.__wbg_queueMicrotask_fca69f5bfad613a5=function(){return g(function(t){queueMicrotask(u(t))},arguments)},r.wbg.__wbg_removeProperty_c2e16faee2834bef=function(){return I(function(t,e,n,i){let o=u(e).removeProperty(R(n,i)),s=D(o,a.__wbindgen_export,a.__wbindgen_export2),_=F;b().setInt32(t+4,_,!0),b().setInt32(t+0,s,!0)},arguments)},r.wbg.__wbg_remove_32f69ffabcbc4072=function(){return g(function(t){u(t).remove()},arguments)},r.wbg.__wbg_renderpageimageoptions_unwrap=function(){return g(function(t){let e=Q.__unwrap(u(t));return w(e),e},arguments)},r.wbg.__wbg_replaceWith_923cfb1b2f584408=function(){return I(function(t,e){u(t).replaceWith(u(e))},arguments)},r.wbg.__wbg_resolve_fd5bfbaa4ce36e1e=function(){return g(function(t){let e=Promise.resolve(u(t));return m(e)},arguments)},r.wbg.__wbg_restore_352c39c9bbeedc91=function(){return g(function(t){u(t).restore()},arguments)},r.wbg.__wbg_restore_6486cb1a7aa3af7b=function(){return g(function(t){u(t).restore()},arguments)},r.wbg.__wbg_revokeObjectURL_88db3468842ff09e=function(){return I(function(t,e){URL.revokeObjectURL(R(t,e))},arguments)},r.wbg.__wbg_save_131c8dc648f702b6=function(){return g(function(t){u(t).save()},arguments)},r.wbg.__wbg_save_b8767cfd2ee7f600=function(){return g(function(t){u(t).save()},arguments)},r.wbg.__wbg_setAttribute_34747dd193f45828=function(){return I(function(t,e,n,i,o){u(t).setAttribute(R(e,n),R(i,o))},arguments)},r.wbg.__wbg_setLineDash_7e3aad159aa2710c=function(){return I(function(t,e){u(t).setLineDash(u(e))},arguments)},r.wbg.__wbg_setLineDash_cfbc3a6bfddeee62=function(){return I(function(t,e){u(t).setLineDash(u(e))},arguments)},r.wbg.__wbg_setProperty_f27b2c05323daf8a=function(){return I(function(t,e,n,i,o){u(t).setProperty(R(e,n),R(i,o))},arguments)},r.wbg.__wbg_setTransform_9de588d9f080f5bc=function(){return I(function(t,e,n,i,o,s,_){u(t).setTransform(e,n,i,o,s,_)},arguments)},r.wbg.__wbg_setTransform_c55eca1193bf5ea1=function(){return I(function(t,e,n,i,o,s,_){u(t).setTransform(e,n,i,o,s,_)},arguments)},r.wbg.__wbg_set_169e13b608078b7b=function(){return g(function(t,e,n){u(t).set(or(e,n))},arguments)},r.wbg.__wbg_set_781438a03c0c3c81=function(){return I(function(t,e,n){let i=Reflect.set(u(t),u(e),u(n));return L(i),i},arguments)},r.wbg.__wbg_set_7df433eea03a5c14=function(){return g(function(t,e,n){u(t)[e>>>0]=P(n)},arguments)},r.wbg.__wbg_set_fillStyle_b26e462a87b14315=function(){return g(function(t,e,n){u(t).fillStyle=R(e,n)},arguments)},r.wbg.__wbg_set_fillStyle_c9a0550307cd4671=function(){return g(function(t,e,n){u(t).fillStyle=R(e,n)},arguments)},r.wbg.__wbg_set_font_6d67b15564a1e344=function(){return g(function(t,e,n){u(t).font=R(e,n)},arguments)},r.wbg.__wbg_set_globalCompositeOperation_418a0b97ba91a947=function(){return I(function(t,e,n){u(t).globalCompositeOperation=R(e,n)},arguments)},r.wbg.__wbg_set_globalCompositeOperation_7e16c72877ba5f86=function(){return I(function(t,e,n){u(t).globalCompositeOperation=R(e,n)},arguments)},r.wbg.__wbg_set_height_6f8f8ef4cb40e496=function(){return g(function(t,e){u(t).height=e>>>0},arguments)},r.wbg.__wbg_set_innerHTML_f1d03f780518a596=function(){return g(function(t,e,n){u(t).innerHTML=R(e,n)},arguments)},r.wbg.__wbg_set_lineCap_74b37c7ff968f854=function(){return g(function(t,e,n){u(t).lineCap=R(e,n)},arguments)},r.wbg.__wbg_set_lineCap_791e7648138cc371=function(){return g(function(t,e,n){u(t).lineCap=R(e,n)},arguments)},r.wbg.__wbg_set_lineDashOffset_85f21a63ddf34d2c=function(){return g(function(t,e){u(t).lineDashOffset=e},arguments)},r.wbg.__wbg_set_lineDashOffset_f032b4e2a273a2f5=function(){return g(function(t,e){u(t).lineDashOffset=e},arguments)},r.wbg.__wbg_set_lineJoin_196c6ac02fd494c3=function(){return g(function(t,e,n){u(t).lineJoin=R(e,n)},arguments)},r.wbg.__wbg_set_lineJoin_a136f09dd803e0cc=function(){return g(function(t,e,n){u(t).lineJoin=R(e,n)},arguments)},r.wbg.__wbg_set_lineWidth_ed39767bf75d602d=function(){return g(function(t,e){u(t).lineWidth=e},arguments)},r.wbg.__wbg_set_lineWidth_feda4b79a15c660b=function(){return g(function(t,e){u(t).lineWidth=e},arguments)},r.wbg.__wbg_set_miterLimit_b12c03757937d228=function(){return g(function(t,e){u(t).miterLimit=e},arguments)},r.wbg.__wbg_set_miterLimit_d891f47e244a915c=function(){return g(function(t,e){u(t).miterLimit=e},arguments)},r.wbg.__wbg_set_onerror_e7e40c62a55a0770=function(){return g(function(t,e){u(t).onerror=u(e)},arguments)},r.wbg.__wbg_set_onload_5e2862e3453854de=function(){return g(function(t,e){u(t).onload=u(e)},arguments)},r.wbg.__wbg_set_src_84f27c5105946dce=function(){return g(function(t,e,n){u(t).src=R(e,n)},arguments)},r.wbg.__wbg_set_strokeStyle_25d5381be570e780=function(){return g(function(t,e,n){u(t).strokeStyle=R(e,n)},arguments)},r.wbg.__wbg_set_strokeStyle_697a576d2d3fbeaa=function(){return g(function(t,e,n){u(t).strokeStyle=R(e,n)},arguments)},r.wbg.__wbg_set_type_7ce650670a34c68f=function(){return g(function(t,e,n){u(t).type=R(e,n)},arguments)},r.wbg.__wbg_set_width_7ff7a22c6e9f423e=function(){return g(function(t,e){u(t).width=e>>>0},arguments)},r.wbg.__wbg_stack_0ed75d68575b0f3c=function(){return g(function(t,e){let n=u(e).stack,i=D(n,a.__wbindgen_export,a.__wbindgen_export2),o=F;b().setInt32(t+4,o,!0),b().setInt32(t+0,i,!0)},arguments)},r.wbg.__wbg_static_accessor_GLOBAL_769e6b65d6557335=function(){return g(function(){let t=typeof global>"u"?null:global;return A(t)?0:m(t)},arguments)},r.wbg.__wbg_static_accessor_GLOBAL_THIS_60cf02db4de8e1c1=function(){return g(function(){let t=typeof globalThis>"u"?null:globalThis;return A(t)?0:m(t)},arguments)},r.wbg.__wbg_static_accessor_SELF_08f5a74c69739274=function(){return g(function(){let t=typeof self>"u"?null:self;return A(t)?0:m(t)},arguments)},r.wbg.__wbg_static_accessor_WINDOW_a8924b26aa92d024=function(){return g(function(){let t=typeof window>"u"?null:window;return A(t)?0:m(t)},arguments)},r.wbg.__wbg_stringify_655a6390e1f5eb6b=function(){return I(function(t){let e=JSON.stringify(u(t));return m(e)},arguments)},r.wbg.__wbg_stroke_41b0736a6a0b61aa=function(){return g(function(t,e){u(t).stroke(u(e))},arguments)},r.wbg.__wbg_stroke_7cfe6d60a6c48303=function(){return g(function(t,e){u(t).stroke(u(e))},arguments)},r.wbg.__wbg_style_521a717da50e53c6=function(){return g(function(t){let e=u(t).style;return m(e)},arguments)},r.wbg.__wbg_then_429f7caf1026411d=function(){return g(function(t,e,n){let i=u(t).then(u(e),u(n));return m(i)},arguments)},r.wbg.__wbg_then_4f95312d68691235=function(){return g(function(t,e){let n=u(t).then(u(e));return m(n)},arguments)},r.wbg.__wbg_transferToImageBitmap_7048556ff33da7ed=function(){return I(function(t){let e=u(t).transferToImageBitmap();return m(e)},arguments)},r.wbg.__wbg_typstrenderer_new=function(){return g(function(t){let e=dt.__wrap(t);return m(e)},arguments)},r.wbg.__wbg_warn_6e567d0d926ff881=function(){return g(function(t){console.warn(u(t))},arguments)},r.wbg.__wbg_width_c3f96f2ca7ab208d=function(){return g(function(t){return u(t).width},arguments)},r.wbg.__wbg_width_f13d2e86324fc226=function(){return g(function(t){let e=u(t).width;return w(e),e},arguments)},r.wbg.__wbindgen_cast_034b33c9b274ad29=function(){return g(function(t,e){let n=sr(t,e,a.__wasm_bindgen_func_elem_1022,Mn);return m(n)},arguments)},r.wbg.__wbindgen_cast_2241b6af4c4b2941=function(){return g(function(t,e){let n=R(t,e);return m(n)},arguments)},r.wbg.__wbindgen_cast_aa4fe27cfdb2d557=function(){return g(function(t,e){let n=sr(t,e,a.__wasm_bindgen_func_elem_1022,Tn);return m(n)},arguments)},r.wbg.__wbindgen_cast_b2e692da0ea8478a=function(){return g(function(t,e){let n=An(t,e,a.__wasm_bindgen_func_elem_1077,Ln);return m(n)},arguments)},r.wbg.__wbindgen_cast_d6cd19b81560fd6e=function(){return g(function(t){return m(t)},arguments)},r.wbg.__wbindgen_object_clone_ref=function(t){let e=u(t);return m(e)},r.wbg.__wbindgen_object_drop_ref=function(t){P(t)},r}function mr(r,t){return a=r.exports,yr.__wbindgen_wasm_module=t,K=null,Rt=null,Ct=null,a}function Un(r){if(a!==void 0)return a;typeof r<"u"&&(Object.getPrototypeOf(r)===Object.prototype?{module:r}=r:console.warn("using deprecated parameters for `initSync()`; pass a single object instead"));let t=hr();r instanceof WebAssembly.Module||(r=new WebAssembly.Module(r));let e=new WebAssembly.Instance(r,t);return mr(e,r)}async function yr(r){if(a!==void 0)return a;typeof r<"u"&&(Object.getPrototypeOf(r)===Object.prototype?{module_or_path:r}=r:console.warn("using deprecated parameters for the initialization function; pass a single object instead")),typeof r>"u"&&(r=xr("typst_ts_renderer_bg.wasm",$n.url));let t=hr();(typeof r=="string"||typeof Request=="function"&&r instanceof Request||typeof URL=="function"&&r instanceof URL)&&(r=fetch(r));let{instance:e,module:n}=await Bn(await r,t);return mr(e,n)}function Ce(r){xr=r}var $n,a,ee,K,Rt,Ct,N,st,te,Fn,Ie,At,F,_r,cr,ur,dr,fr,lr,gr,wr,Ee,pr,jn,br,_t,ct,Y,ut,Q,W,Pt,dt,Ft,Ot,ft,Wn,vr,xr,ne=z(()=>{$n={};ee=typeof FinalizationRegistry>"u"?{register:()=>{},unregister:()=>{}}:new FinalizationRegistry(r=>r.dtor(r.a,r.b));K=null;Rt=null;Ct=null;N=new Array(128).fill(void 0);N.push(void 0,null,!0,!1);st=N.length;te=new TextDecoder("utf-8",{ignoreBOM:!0,fatal:!0});te.decode();Fn=2146435072,Ie=0;At=new TextEncoder;"encodeInto"in At||(At.encodeInto=function(r,t){let e=At.encode(r);return t.set(e),{read:r.length,written:e.length}});F=0;_r=["nonzero","evenodd"],cr=typeof FinalizationRegistry>"u"?{register:()=>{},unregister:()=>{}}:new FinalizationRegistry(r=>a.__wbg_createsessionoptions_free(r>>>0,1)),ur=typeof FinalizationRegistry>"u"?{register:()=>{},unregister:()=>{}}:new FinalizationRegistry(r=>a.__wbg_incrdomdocclient_free(r>>>0,1)),dr=typeof FinalizationRegistry>"u"?{register:()=>{},unregister:()=>{}}:new FinalizationRegistry(r=>a.__wbg_pageinfo_free(r>>>0,1)),fr=typeof FinalizationRegistry>"u"?{register:()=>{},unregister:()=>{}}:new FinalizationRegistry(r=>a.__wbg_pagesinfo_free(r>>>0,1)),lr=typeof FinalizationRegistry>"u"?{register:()=>{},unregister:()=>{}}:new FinalizationRegistry(r=>a.__wbg_renderpageimageoptions_free(r>>>0,1)),gr=typeof FinalizationRegistry>"u"?{register:()=>{},unregister:()=>{}}:new FinalizationRegistry(r=>a.__wbg_rendersession_free(r>>>0,1)),wr=typeof FinalizationRegistry>"u"?{register:()=>{},unregister:()=>{}}:new FinalizationRegistry(r=>a.__wbg_rendersessionoptions_free(r>>>0,1)),Ee=typeof FinalizationRegistry>"u"?{register:()=>{},unregister:()=>{}}:new FinalizationRegistry(r=>a.__wbg_typstrenderer_free(r>>>0,1)),pr=typeof FinalizationRegistry>"u"?{register:()=>{},unregister:()=>{}}:new FinalizationRegistry(r=>a.__wbg_typstrendererbuilder_free(r>>>0,1)),jn=typeof FinalizationRegistry>"u"?{register:()=>{},unregister:()=>{}}:new FinalizationRegistry(r=>a.__wbg_typstworker_free(r>>>0,1)),br=typeof FinalizationRegistry>"u"?{register:()=>{},unregister:()=>{}}:new FinalizationRegistry(r=>a.__wbg_workerbridge_free(r>>>0,1)),_t=class{__destroy_into_raw(){let t=this.__wbg_ptr;return this.__wbg_ptr=0,cr.unregister(this),t}free(){let t=this.__destroy_into_raw();a.__wbg_createsessionoptions_free(t,0)}constructor(){let t=a.createsessionoptions_new();return this.__wbg_ptr=t>>>0,cr.register(this,this.__wbg_ptr,this),this}set format(t){if(this.__wbg_ptr==0)throw new Error("Attempt to use a moved value");w(this.__wbg_ptr);let e=D(t,a.__wbindgen_export,a.__wbindgen_export2),n=F;a.createsessionoptions_set_format(this.__wbg_ptr,e,n)}set artifact_content(t){if(this.__wbg_ptr==0)throw new Error("Attempt to use a moved value");w(this.__wbg_ptr);let e=re(t,a.__wbindgen_export),n=F;a.createsessionoptions_set_artifact_content(this.__wbg_ptr,e,n)}};Symbol.dispose&&(_t.prototype[Symbol.dispose]=_t.prototype.free);ct=class r{constructor(){throw new Error("cannot invoke `new` directly")}static __wrap(t){t=t>>>0;let e=Object.create(r.prototype);return e.__wbg_ptr=t,ur.register(e,e.__wbg_ptr,e),e}__destroy_into_raw(){let t=this.__wbg_ptr;return this.__wbg_ptr=0,ur.unregister(this),t}free(){let t=this.__destroy_into_raw();a.__wbg_incrdomdocclient_free(t,0)}bind_functions(t){if(this.__wbg_ptr==0)throw new Error("Attempt to use a moved value");w(this.__wbg_ptr),a.incrdomdocclient_bind_functions(this.__wbg_ptr,m(t))}relayout(t,e,n,i){if(this.__wbg_ptr==0)throw new Error("Attempt to use a moved value");w(this.__wbg_ptr);let o=a.incrdomdocclient_relayout(this.__wbg_ptr,t,e,n,i);return P(o)}need_repaint(t,e,n,i,o,s){try{if(this.__wbg_ptr==0)throw new Error("Attempt to use a moved value");let f=a.__wbindgen_add_to_stack_pointer(-16);w(this.__wbg_ptr),w(t),w(s),a.incrdomdocclient_need_repaint(f,this.__wbg_ptr,t,e,n,i,o,s);var _=b().getInt32(f+0,!0),d=b().getInt32(f+4,!0),l=b().getInt32(f+8,!0);if(l)throw P(d);return _!==0}finally{a.__wbindgen_add_to_stack_pointer(16)}}repaint(t,e,n,i,o,s){try{if(this.__wbg_ptr==0)throw new Error("Attempt to use a moved value");let f=a.__wbindgen_add_to_stack_pointer(-16);w(this.__wbg_ptr),w(t),w(s),a.incrdomdocclient_repaint(f,this.__wbg_ptr,t,e,n,i,o,s);var _=b().getInt32(f+0,!0),d=b().getInt32(f+4,!0),l=b().getInt32(f+8,!0);if(l)throw P(d);return P(_)}finally{a.__wbindgen_add_to_stack_pointer(16)}}};Symbol.dispose&&(ct.prototype[Symbol.dispose]=ct.prototype.free);Y=class r{constructor(){throw new Error("cannot invoke `new` directly")}static __wrap(t){t=t>>>0;let e=Object.create(r.prototype);return e.__wbg_ptr=t,dr.register(e,e.__wbg_ptr,e),e}__destroy_into_raw(){let t=this.__wbg_ptr;return this.__wbg_ptr=0,dr.unregister(this),t}free(){let t=this.__destroy_into_raw();a.__wbg_pageinfo_free(t,0)}get page_off(){if(this.__wbg_ptr==0)throw new Error("Attempt to use a moved value");return w(this.__wbg_ptr),a.pageinfo_page_off(this.__wbg_ptr)>>>0}get width_pt(){if(this.__wbg_ptr==0)throw new Error("Attempt to use a moved value");return w(this.__wbg_ptr),a.pageinfo_width_pt(this.__wbg_ptr)}get height_pt(){if(this.__wbg_ptr==0)throw new Error("Attempt to use a moved value");return w(this.__wbg_ptr),a.pageinfo_height_pt(this.__wbg_ptr)}};Symbol.dispose&&(Y.prototype[Symbol.dispose]=Y.prototype.free);ut=class r{constructor(){throw new Error("cannot invoke `new` directly")}static __wrap(t){t=t>>>0;let e=Object.create(r.prototype);return e.__wbg_ptr=t,fr.register(e,e.__wbg_ptr,e),e}__destroy_into_raw(){let t=this.__wbg_ptr;return this.__wbg_ptr=0,fr.unregister(this),t}free(){let t=this.__destroy_into_raw();a.__wbg_pagesinfo_free(t,0)}get page_count(){if(this.__wbg_ptr==0)throw new Error("Attempt to use a moved value");return w(this.__wbg_ptr),a.pagesinfo_page_count(this.__wbg_ptr)>>>0}page_by_number(t){if(this.__wbg_ptr==0)throw new Error("Attempt to use a moved value");w(this.__wbg_ptr),w(t);let e=a.pagesinfo_page_by_number(this.__wbg_ptr,t);return e===0?void 0:Y.__wrap(e)}page(t){if(this.__wbg_ptr==0)throw new Error("Attempt to use a moved value");w(this.__wbg_ptr),w(t);let e=a.pagesinfo_page(this.__wbg_ptr,t);return Y.__wrap(e)}width(){if(this.__wbg_ptr==0)throw new Error("Attempt to use a moved value");return w(this.__wbg_ptr),a.pagesinfo_width(this.__wbg_ptr)}height(){if(this.__wbg_ptr==0)throw new Error("Attempt to use a moved value");return w(this.__wbg_ptr),a.pagesinfo_height(this.__wbg_ptr)}};Symbol.dispose&&(ut.prototype[Symbol.dispose]=ut.prototype.free);Q=class r{static __unwrap(t){return t instanceof r?t.__destroy_into_raw():0}__destroy_into_raw(){let t=this.__wbg_ptr;return this.__wbg_ptr=0,lr.unregister(this),t}free(){let t=this.__destroy_into_raw();a.__wbg_renderpageimageoptions_free(t,0)}constructor(){let t=a.renderpageimageoptions_new();return this.__wbg_ptr=t>>>0,lr.register(this,this.__wbg_ptr,this),this}get pixel_per_pt(){if(this.__wbg_ptr==0)throw new Error("Attempt to use a moved value");w(this.__wbg_ptr);let t=a.renderpageimageoptions_pixel_per_pt(this.__wbg_ptr);return t===4294967297?void 0:t}set pixel_per_pt(t){if(this.__wbg_ptr==0)throw new Error("Attempt to use a moved value");w(this.__wbg_ptr),A(t)||w(t),a.renderpageimageoptions_set_pixel_per_pt(this.__wbg_ptr,A(t)?4294967297:Math.fround(t))}get background_color(){try{if(this.__wbg_ptr==0)throw new Error("Attempt to use a moved value");let n=a.__wbindgen_add_to_stack_pointer(-16);w(this.__wbg_ptr),a.renderpageimageoptions_background_color(n,this.__wbg_ptr);var t=b().getInt32(n+0,!0),e=b().getInt32(n+4,!0);let i;return t!==0&&(i=R(t,e).slice(),a.__wbindgen_export4(t,e*1,1)),i}finally{a.__wbindgen_add_to_stack_pointer(16)}}set background_color(t){if(this.__wbg_ptr==0)throw new Error("Attempt to use a moved value");w(this.__wbg_ptr);var e=A(t)?0:D(t,a.__wbindgen_export,a.__wbindgen_export2),n=F;a.renderpageimageoptions_set_background_color(this.__wbg_ptr,e,n)}get page_off(){if(this.__wbg_ptr==0)throw new Error("Attempt to use a moved value");return w(this.__wbg_ptr),a.renderpageimageoptions_page_off(this.__wbg_ptr)>>>0}set page_off(t){if(this.__wbg_ptr==0)throw new Error("Attempt to use a moved value");w(this.__wbg_ptr),w(t),a.renderpageimageoptions_set_page_off(this.__wbg_ptr,t)}get cache_key(){try{if(this.__wbg_ptr==0)throw new Error("Attempt to use a moved value");let n=a.__wbindgen_add_to_stack_pointer(-16);w(this.__wbg_ptr),a.renderpageimageoptions_cache_key(n,this.__wbg_ptr);var t=b().getInt32(n+0,!0),e=b().getInt32(n+4,!0);let i;return t!==0&&(i=R(t,e).slice(),a.__wbindgen_export4(t,e*1,1)),i}finally{a.__wbindgen_add_to_stack_pointer(16)}}set cache_key(t){if(this.__wbg_ptr==0)throw new Error("Attempt to use a moved value");w(this.__wbg_ptr);var e=A(t)?0:D(t,a.__wbindgen_export,a.__wbindgen_export2),n=F;a.renderpageimageoptions_set_cache_key(this.__wbg_ptr,e,n)}get data_selection(){if(this.__wbg_ptr==0)throw new Error("Attempt to use a moved value");w(this.__wbg_ptr);let t=a.renderpageimageoptions_data_selection(this.__wbg_ptr);return t===4294967297?void 0:t}set data_selection(t){if(this.__wbg_ptr==0)throw new Error("Attempt to use a moved value");w(this.__wbg_ptr),A(t)||w(t),a.renderpageimageoptions_set_data_selection(this.__wbg_ptr,A(t)?4294967297:t>>>0)}};Symbol.dispose&&(Q.prototype[Symbol.dispose]=Q.prototype.free);W=class r{constructor(){throw new Error("cannot invoke `new` directly")}static __wrap(t){t=t>>>0;let e=Object.create(r.prototype);return e.__wbg_ptr=t,gr.register(e,e.__wbg_ptr,e),e}__destroy_into_raw(){let t=this.__wbg_ptr;return this.__wbg_ptr=0,gr.unregister(this),t}free(){let t=this.__destroy_into_raw();a.__wbg_rendersession_free(t,0)}render_in_window(t,e,n,i){let o,s;try{if(this.__wbg_ptr==0)throw new Error("Attempt to use a moved value");let l=a.__wbindgen_add_to_stack_pointer(-16);w(this.__wbg_ptr),a.rendersession_render_in_window(l,this.__wbg_ptr,t,e,n,i);var _=b().getInt32(l+0,!0),d=b().getInt32(l+4,!0);return o=_,s=d,R(_,d)}finally{a.__wbindgen_add_to_stack_pointer(16),a.__wbindgen_export4(o,s,1)}}get pixel_per_pt(){if(this.__wbg_ptr==0)throw new Error("Attempt to use a moved value");w(this.__wbg_ptr);let t=a.rendersession_pixel_per_pt(this.__wbg_ptr);return t===4294967297?void 0:t}set pixel_per_pt(t){if(this.__wbg_ptr==0)throw new Error("Attempt to use a moved value");w(this.__wbg_ptr),A(t)||w(t),a.rendersession_set_pixel_per_pt(this.__wbg_ptr,A(t)?4294967297:Math.fround(t))}get background_color(){try{if(this.__wbg_ptr==0)throw new Error("Attempt to use a moved value");let n=a.__wbindgen_add_to_stack_pointer(-16);w(this.__wbg_ptr),a.rendersession_background_color(n,this.__wbg_ptr);var t=b().getInt32(n+0,!0),e=b().getInt32(n+4,!0);let i;return t!==0&&(i=R(t,e).slice(),a.__wbindgen_export4(t,e*1,1)),i}finally{a.__wbindgen_add_to_stack_pointer(16)}}set background_color(t){if(this.__wbg_ptr==0)throw new Error("Attempt to use a moved value");w(this.__wbg_ptr);var e=A(t)?0:D(t,a.__wbindgen_export,a.__wbindgen_export2),n=F;a.rendersession_set_background_color(this.__wbg_ptr,e,n)}get pages_info(){if(this.__wbg_ptr==0)throw new Error("Attempt to use a moved value");w(this.__wbg_ptr);let t=a.rendersession_pages_info(this.__wbg_ptr);return ut.__wrap(t)}get doc_width(){if(this.__wbg_ptr==0)throw new Error("Attempt to use a moved value");return w(this.__wbg_ptr),a.rendersession_doc_width(this.__wbg_ptr)}get doc_height(){if(this.__wbg_ptr==0)throw new Error("Attempt to use a moved value");return w(this.__wbg_ptr),a.rendersession_doc_height(this.__wbg_ptr)}source_span(t){try{if(this.__wbg_ptr==0)throw new Error("Attempt to use a moved value");let s=a.__wbindgen_add_to_stack_pointer(-16);w(this.__wbg_ptr);let _=Pn(t,a.__wbindgen_export),d=F;a.rendersession_source_span(s,this.__wbg_ptr,_,d);var e=b().getInt32(s+0,!0),n=b().getInt32(s+4,!0),i=b().getInt32(s+8,!0),o=b().getInt32(s+12,!0);if(o)throw P(i);let l;return e!==0&&(l=R(e,n).slice(),a.__wbindgen_export4(e,n*1,1)),l}finally{a.__wbindgen_add_to_stack_pointer(16)}}};Symbol.dispose&&(W.prototype[Symbol.dispose]=W.prototype.free);Pt=class{__destroy_into_raw(){let t=this.__wbg_ptr;return this.__wbg_ptr=0,wr.unregister(this),t}free(){let t=this.__destroy_into_raw();a.__wbg_rendersessionoptions_free(t,0)}constructor(){let t=a.rendersessionoptions_new();return this.__wbg_ptr=t>>>0,wr.register(this,this.__wbg_ptr,this),this}get pixel_per_pt(){if(this.__wbg_ptr==0)throw new Error("Attempt to use a moved value");w(this.__wbg_ptr);let t=a.rendersession_pixel_per_pt(this.__wbg_ptr);return t===4294967297?void 0:t}set pixel_per_pt(t){if(this.__wbg_ptr==0)throw new Error("Attempt to use a moved value");w(this.__wbg_ptr),A(t)||w(t),a.rendersession_set_pixel_per_pt(this.__wbg_ptr,A(t)?4294967297:Math.fround(t))}get background_color(){try{if(this.__wbg_ptr==0)throw new Error("Attempt to use a moved value");let n=a.__wbindgen_add_to_stack_pointer(-16);w(this.__wbg_ptr),a.rendersessionoptions_background_color(n,this.__wbg_ptr);var t=b().getInt32(n+0,!0),e=b().getInt32(n+4,!0);let i;return t!==0&&(i=R(t,e).slice(),a.__wbindgen_export4(t,e*1,1)),i}finally{a.__wbindgen_add_to_stack_pointer(16)}}set background_color(t){if(this.__wbg_ptr==0)throw new Error("Attempt to use a moved value");w(this.__wbg_ptr);var e=A(t)?0:D(t,a.__wbindgen_export,a.__wbindgen_export2),n=F;a.rendersessionoptions_set_background_color(this.__wbg_ptr,e,n)}get format(){try{if(this.__wbg_ptr==0)throw new Error("Attempt to use a moved value");let n=a.__wbindgen_add_to_stack_pointer(-16);w(this.__wbg_ptr),a.rendersessionoptions_format(n,this.__wbg_ptr);var t=b().getInt32(n+0,!0),e=b().getInt32(n+4,!0);let i;return t!==0&&(i=R(t,e).slice(),a.__wbindgen_export4(t,e*1,1)),i}finally{a.__wbindgen_add_to_stack_pointer(16)}}set format(t){if(this.__wbg_ptr==0)throw new Error("Attempt to use a moved value");w(this.__wbg_ptr);var e=A(t)?0:D(t,a.__wbindgen_export,a.__wbindgen_export2),n=F;a.rendersessionoptions_set_format(this.__wbg_ptr,e,n)}};Symbol.dispose&&(Pt.prototype[Symbol.dispose]=Pt.prototype.free);dt=class r{static __wrap(t){t=t>>>0;let e=Object.create(r.prototype);return e.__wbg_ptr=t,Ee.register(e,e.__wbg_ptr,e),e}__destroy_into_raw(){let t=this.__wbg_ptr;return this.__wbg_ptr=0,Ee.unregister(this),t}free(){let t=this.__destroy_into_raw();a.__wbg_typstrenderer_free(t,0)}constructor(){let t=a.typstrenderer_new();return this.__wbg_ptr=t>>>0,Ee.register(this,this.__wbg_ptr,this),this}create_session(t){try{if(this.__wbg_ptr==0)throw new Error("Attempt to use a moved value");let o=a.__wbindgen_add_to_stack_pointer(-16);w(this.__wbg_ptr);let s=0;if(!A(t)){if($(t,_t),t.__wbg_ptr===0)throw new Error("Attempt to use a moved value");s=t.__destroy_into_raw()}a.typstrenderer_create_session(o,this.__wbg_ptr,s);var e=b().getInt32(o+0,!0),n=b().getInt32(o+4,!0),i=b().getInt32(o+8,!0);if(i)throw P(n);return W.__wrap(e)}finally{a.__wbindgen_add_to_stack_pointer(16)}}reset(t){try{if(this.__wbg_ptr==0)throw new Error("Attempt to use a moved value");let i=a.__wbindgen_add_to_stack_pointer(-16);if(w(this.__wbg_ptr),$(t,W),t.__wbg_ptr===0)throw new Error("Attempt to use a moved value");a.typstrenderer_reset(i,this.__wbg_ptr,t.__wbg_ptr);var e=b().getInt32(i+0,!0),n=b().getInt32(i+4,!0);if(n)throw P(e)}finally{a.__wbindgen_add_to_stack_pointer(16)}}manipulate_data(t,e,n){try{if(this.__wbg_ptr==0)throw new Error("Attempt to use a moved value");let s=a.__wbindgen_add_to_stack_pointer(-16);if(w(this.__wbg_ptr),$(t,W),t.__wbg_ptr===0)throw new Error("Attempt to use a moved value");let _=D(e,a.__wbindgen_export,a.__wbindgen_export2),d=F,l=re(n,a.__wbindgen_export),f=F;a.typstrenderer_manipulate_data(s,this.__wbg_ptr,t.__wbg_ptr,_,d,l,f);var i=b().getInt32(s+0,!0),o=b().getInt32(s+4,!0);if(o)throw P(i)}finally{a.__wbindgen_add_to_stack_pointer(16)}}session_from_artifact(t,e){try{if(this.__wbg_ptr==0)throw new Error("Attempt to use a moved value");let s=a.__wbindgen_add_to_stack_pointer(-16);w(this.__wbg_ptr);let _=re(t,a.__wbindgen_export),d=F,l=D(e,a.__wbindgen_export,a.__wbindgen_export2),f=F;a.typstrenderer_session_from_artifact(s,this.__wbg_ptr,_,d,l,f);var n=b().getInt32(s+0,!0),i=b().getInt32(s+4,!0),o=b().getInt32(s+8,!0);if(o)throw P(i);return W.__wrap(n)}finally{a.__wbindgen_add_to_stack_pointer(16)}}load_glyph_pack(t){try{if(this.__wbg_ptr==0)throw new Error("Attempt to use a moved value");let i=a.__wbindgen_add_to_stack_pointer(-16);w(this.__wbg_ptr),a.typstrenderer_load_glyph_pack(i,this.__wbg_ptr,m(t));var e=b().getInt32(i+0,!0),n=b().getInt32(i+4,!0);if(n)throw P(e)}finally{a.__wbindgen_add_to_stack_pointer(16)}}render_svg_diff(t,e,n,i,o){let s,_;try{if(this.__wbg_ptr==0)throw new Error("Attempt to use a moved value");let f=a.__wbindgen_add_to_stack_pointer(-16);if(w(this.__wbg_ptr),$(t,W),t.__wbg_ptr===0)throw new Error("Attempt to use a moved value");a.typstrenderer_render_svg_diff(f,this.__wbg_ptr,t.__wbg_ptr,e,n,i,o);var d=b().getInt32(f+0,!0),l=b().getInt32(f+4,!0);return s=d,_=l,R(d,l)}finally{a.__wbindgen_add_to_stack_pointer(16),a.__wbindgen_export4(s,_,1)}}svg_data(t,e){let n,i;try{if(this.__wbg_ptr==0)throw new Error("Attempt to use a moved value");let v=a.__wbindgen_add_to_stack_pointer(-16);if(w(this.__wbg_ptr),$(t,W),t.__wbg_ptr===0)throw new Error("Attempt to use a moved value");A(e)||w(e),a.typstrenderer_svg_data(v,this.__wbg_ptr,t.__wbg_ptr,A(e)?4294967297:e>>>0);var o=b().getInt32(v+0,!0),s=b().getInt32(v+4,!0),_=b().getInt32(v+8,!0),d=b().getInt32(v+12,!0),l=o,f=s;if(d)throw l=0,f=0,P(_);return n=l,i=f,R(l,f)}finally{a.__wbindgen_add_to_stack_pointer(16),a.__wbindgen_export4(n,i,1)}}get_customs(t){if(this.__wbg_ptr==0)throw new Error("Attempt to use a moved value");if(w(this.__wbg_ptr),$(t,W),t.__wbg_ptr===0)throw new Error("Attempt to use a moved value");let e=a.typstrenderer_get_customs(this.__wbg_ptr,t.__wbg_ptr);return P(e)}render_svg(t,e){try{if(this.__wbg_ptr==0)throw new Error("Attempt to use a moved value");let s=a.__wbindgen_add_to_stack_pointer(-16);if(w(this.__wbg_ptr),$(t,W),t.__wbg_ptr===0)throw new Error("Attempt to use a moved value");a.typstrenderer_render_svg(s,this.__wbg_ptr,t.__wbg_ptr,m(e));var n=b().getInt32(s+0,!0),i=b().getInt32(s+4,!0),o=b().getInt32(s+8,!0);if(o)throw P(i);return n!==0}finally{a.__wbindgen_add_to_stack_pointer(16)}}create_worker(t){if(this.__wbg_ptr==0)throw new Error("Attempt to use a moved value");w(this.__wbg_ptr);let e=a.typstrenderer_create_worker(this.__wbg_ptr,m(t));return P(e)}create_worker_bridge(){try{if(this.__wbg_ptr==0)throw new Error("Attempt to use a moved value");let i=this.__destroy_into_raw(),o=a.__wbindgen_add_to_stack_pointer(-16);w(i),a.typstrenderer_create_worker_bridge(o,i);var t=b().getInt32(o+0,!0),e=b().getInt32(o+4,!0),n=b().getInt32(o+8,!0);if(n)throw P(e);return ft.__wrap(t)}finally{a.__wbindgen_add_to_stack_pointer(16)}}render_page_to_canvas(t,e,n){if(this.__wbg_ptr==0)throw new Error("Attempt to use a moved value");if(w(this.__wbg_ptr),$(t,W),t.__wbg_ptr===0)throw new Error("Attempt to use a moved value");let i=0;if(!A(n)){if($(n,Q),n.__wbg_ptr===0)throw new Error("Attempt to use a moved value");i=n.__destroy_into_raw()}let o=a.typstrenderer_render_page_to_canvas(this.__wbg_ptr,t.__wbg_ptr,m(e),i);return P(o)}mount_dom(t,e){if(this.__wbg_ptr==0)throw new Error("Attempt to use a moved value");if(w(this.__wbg_ptr),$(t,W),t.__wbg_ptr===0)throw new Error("Attempt to use a moved value");let n=a.typstrenderer_mount_dom(this.__wbg_ptr,t.__wbg_ptr,m(e));return P(n)}};Symbol.dispose&&(dt.prototype[Symbol.dispose]=dt.prototype.free);Ft=class{__destroy_into_raw(){let t=this.__wbg_ptr;return this.__wbg_ptr=0,pr.unregister(this),t}free(){let t=this.__destroy_into_raw();a.__wbg_typstrendererbuilder_free(t,0)}constructor(){try{let i=a.__wbindgen_add_to_stack_pointer(-16);a.typstrendererbuilder_new(i);var t=b().getInt32(i+0,!0),e=b().getInt32(i+4,!0),n=b().getInt32(i+8,!0);if(n)throw P(e);return this.__wbg_ptr=t>>>0,pr.register(this,this.__wbg_ptr,this),this}finally{a.__wbindgen_add_to_stack_pointer(16)}}build(){if(this.__wbg_ptr==0)throw new Error("Attempt to use a moved value");let t=this.__destroy_into_raw();w(t);let e=a.typstrendererbuilder_build(t);return P(e)}add_glyph_pack(t){if(this.__wbg_ptr==0)throw new Error("Attempt to use a moved value");w(this.__wbg_ptr);let e=a.typstrendererbuilder_add_glyph_pack(this.__wbg_ptr,m(t));return P(e)}add_raw_font(t){if(this.__wbg_ptr==0)throw new Error("Attempt to use a moved value");w(this.__wbg_ptr);let e=a.typstrendererbuilder_add_raw_font(this.__wbg_ptr,m(t));return P(e)}add_lazy_font(t,e){if(this.__wbg_ptr==0)throw new Error("Attempt to use a moved value");w(this.__wbg_ptr);let n=a.typstrendererbuilder_add_lazy_font(this.__wbg_ptr,m(t),m(e));return P(n)}};Symbol.dispose&&(Ft.prototype[Symbol.dispose]=Ft.prototype.free);Ot=class{constructor(){throw new Error("cannot invoke `new` directly")}__destroy_into_raw(){let t=this.__wbg_ptr;return this.__wbg_ptr=0,jn.unregister(this),t}free(){let t=this.__destroy_into_raw();a.__wbg_typstworker_free(t,0)}manipulate_data(t,e){try{if(this.__wbg_ptr==0)throw new Error("Attempt to use a moved value");let s=a.__wbindgen_add_to_stack_pointer(-16);w(this.__wbg_ptr);let _=D(t,a.__wbindgen_export,a.__wbindgen_export2),d=F;a.typstworker_manipulate_data(s,this.__wbg_ptr,_,d,m(e));var n=b().getInt32(s+0,!0),i=b().getInt32(s+4,!0),o=b().getInt32(s+8,!0);if(o)throw P(i);return P(n)}finally{a.__wbindgen_add_to_stack_pointer(16)}}get_pages_info(){if(this.__wbg_ptr==0)throw new Error("Attempt to use a moved value");w(this.__wbg_ptr);let t=a.typstworker_get_pages_info(this.__wbg_ptr);return P(t)}render_canvas(t,e,n){try{if(this.__wbg_ptr==0)throw new Error("Attempt to use a moved value");let _=a.__wbindgen_add_to_stack_pointer(-16);w(this.__wbg_ptr);let d=re(t,a.__wbindgen_export),l=F,f=ar(e,a.__wbindgen_export),v=F,S=ar(n,a.__wbindgen_export),E=F;a.typstworker_render_canvas(_,this.__wbg_ptr,d,l,f,v,S,E);var i=b().getInt32(_+0,!0),o=b().getInt32(_+4,!0),s=b().getInt32(_+8,!0);if(s)throw P(o);return P(i)}finally{a.__wbindgen_add_to_stack_pointer(16)}}};Symbol.dispose&&(Ot.prototype[Symbol.dispose]=Ot.prototype.free);ft=class r{constructor(){throw new Error("cannot invoke `new` directly")}static __wrap(t){t=t>>>0;let e=Object.create(r.prototype);return e.__wbg_ptr=t,br.register(e,e.__wbg_ptr,e),e}__destroy_into_raw(){let t=this.__wbg_ptr;return this.__wbg_ptr=0,br.unregister(this),t}free(){let t=this.__destroy_into_raw();a.__wbg_workerbridge_free(t,0)}};Symbol.dispose&&(ft.prototype[Symbol.dispose]=ft.prototype.free);Wn=new Set(["basic","cors","default"]);vr=yr,xr=async function(r,t){throw new Error("Cannot import wasm module without importer: "+r+" "+t)}});var Mt={};rt(Mt,{CreateSessionOptions:()=>_t,IncrDomDocClient:()=>ct,PageInfo:()=>Y,PagesInfo:()=>ut,RenderPageImageOptions:()=>Q,RenderSession:()=>W,RenderSessionOptions:()=>Pt,TypstRenderer:()=>dt,TypstRendererBuilder:()=>Ft,TypstWorker:()=>Ot,WorkerBridge:()=>ft,default:()=>qn,initSync:()=>Un,renderer_build_info:()=>zn,setImportWasmModule:()=>Ce});var qn,Nn,Hn,ie=z(()=>{ne();ne();ne();qn=vr,Nn=async function(r,t){let e=new Function("m","return import(m)"),{readFileSync:n}=await e("fs"),i=new URL(r,t);return await n(i).buffer},Hn=typeof process<"u"&&process.versions!=null&&process.versions.node!=null;Hn&&Ce(Nn)});var Ae={};rt(Ae,{RenderSession:()=>gt,TypstRendererDriver:()=>se,TypstWorker:()=>oe,createTypstRenderer:()=>ae,rendererBuildInfo:()=>kr});function ae(){return new se}async function kr(){return(await Promise.resolve().then(()=>(ie(),Mt))).renderer_build_info()}var gt,lt,oe,Vn,Sr,se,_e=z(()=>{Et();Ze();ve();Kt();ir();gt=class{plugin;[x];constructor(t,e){this.plugin=t,this[x]=e}set backgroundColor(t){t!==void 0&&(this[x].background_color=t)}get backgroundColor(){return this[x].background_color}set pixelPerPt(t){t!==void 0&&(this[x].pixel_per_pt=t)}get pixelPerPt(){return this[x].pixel_per_pt}reset(){this.plugin.resetSession(this)}get doc_width(){return this[x].doc_width}get docWidth(){return this[x].doc_width}get doc_height(){return this[x].doc_height}get docHeight(){return this[x].doc_height}retrievePagesInfo(){let t=this[x].pages_info,e=[],n=t.page_count;for(let i=0;i<n;i++){let o=t.page(i);e.push({pageOffset:o.page_off,width:o.width_pt,height:o.height_pt})}return e}getSourceLoc(t){return this[x].source_span(t)}renderSvg(t){return this.plugin.renderSvg({renderSession:this,...t})}renderToSvg(t){return this.plugin.renderToSvg({renderSession:this,...t})}renderCanvas(t){return this.plugin.renderCanvas({renderSession:this,...t})}manipulateData(t){this.plugin.manipulateData({renderSession:this,...t})}renderSvgDiff(t){return this.plugin.renderSvgDiff({renderSession:this,...t})}get_source_loc(t){return this[x].source_span(t)}render_in_window(t,e,n,i){return this[x].render_in_window(t,e,n,i)}merge_delta(t){this.plugin.manipulateData({renderSession:this,action:"merge",data:t})}};(function(r){r[r.Delete=0]="Delete",r[r.New=1]="New",r[r.Update=2]="Update"})(lt||(lt={}));oe=class{plugin;[x];constructor(t,e){this.plugin=t,this[x]=e}manipulateData(t,e){return this[x].manipulate_data(t,e)}managedCanvasElemList=new Map;canvasCounter=Math.random();renderCanvas(t){let e=this.managedCanvasElemList;for(let[_,d]of e)d[0]=lt.Delete;for(let _ of t){let d=_.canvas,l=d.dataset.manageId,f=lt.Update;l||(l=this.canvasCounter.toFixed(5),this.canvasCounter+=1,d.dataset.manageId=l,f=lt.New);let v=e.get(l);if(v&&v[0]!==lt.Delete)throw new Error("cannot update a canvas for two times in batch");e.set(l,[f,{..._}])}let n=Array.from(e.entries()),i=new Uint8Array(n.length),o=new Array(n.length),s=n.map(([_,[d,l]],f)=>(d||e.delete(_),i[f]=d,o[f]=l.canvas,this.plugin.canvasOptionsToRust(l)));return this[x].render_canvas(i,o,s)}async retrievePagesInfo(){let t=await this[x].get_pages_info();console.log(t);let e=[],n=t.page_count;for(let i=0;i<n;i++){let o=t.page(i);e.push({pageOffset:o.page_off,width:o.width_pt,height:o.height_pt})}return e}},Vn=r=>new ot(async t=>await r.default(t));Sr=!0,se=class{renderer;rendererJs;constructor(){}async init(t){this.rendererJs=await(t?.getWrapper?.()||Promise.resolve().then(()=>(ie(),Mt)));let e=this.rendererJs.TypstRendererBuilder;this.renderer=await Xt(t,Vn(this.rendererJs),e,{})}loadGlyphPack(t){return Promise.resolve()}createOptionsToRust(t){let e=new this.rendererJs.CreateSessionOptions;return t.format!==void 0&&(e.format=t.format),t.artifactContent!==void 0&&(e.artifact_content=t.artifactContent),e}canvasOptionsToRust(t){let e=new this.rendererJs.RenderPageImageOptions;if(t.pageOffset===void 0)throw new Error("pageOffset is required in reflexo v0.5.0");if(e.page_off=t.pageOffset,t.cacheKey!==void 0&&(e.cache_key=t.cacheKey),t.backgroundColor!==void 0&&(e.background_color=t.backgroundColor),t.pixelPerPt!==void 0&&(e.pixel_per_pt=t.pixelPerPt),t.dataSelection!==void 0){let n=0;t.dataSelection.body?n|=1:t.canvas&&Sr&&(Sr=!1,console.warn("dataSelection.body is not set but providing canvas for body")),(t.dataSelection.text||t.dataSelection.annotation)&&console.error("dataSelection.text and dataSelection.annotation are deprecated"),t.dataSelection.semantics&&(n|=8),e.data_selection=n}return e}retrievePagesInfoFromSession(t){return t.retrievePagesInfo()}renderCanvas(t){return this.withinOptionSession(t,async e=>this.renderer.render_page_to_canvas(e[x],t.canvas||void 0,this.canvasOptionsToRust(t)))}async inAnimationFrame(t){return new Promise((e,n)=>{requestAnimationFrame(()=>{try{e(t())}catch(i){n(i)}})})}async renderDisplayLayer(t,e,n){let o=t[x].pages_info.page_count,s=async(f,v)=>{let E=e[f].getContext("2d");if(!E)throw new Error("canvas context is null");return await this.renderCanvas({...n,canvas:E,renderSession:t,pageOffset:v})},_=performance.now(),d=await(async()=>{let f=[];for(let v=0;v<o;v++)f.push(await this.inAnimationFrame(()=>s(v,v)));return f})(),l=performance.now();return console.log(`display layer used: render = ${(l-_).toFixed(1)}ms`),d}renderTextLayer(t,e){let n=performance.now();t.forEach((o,s)=>{o.innerHTML=e[s].htmlSemantics[0]});let i=performance.now();console.log(`text layer used: render = ${(i-n).toFixed(1)}ms`)}async render(t){if("format"in t&&t.format!=="vector"&&["serde_json","js","ir"].includes(t.format))throw new Error(`deprecated format ${t.format}, please use vector format`);return this.renderToCanvas(t)}async renderDom(t){if("format"in t&&t.format!=="vector"&&["serde_json","js","ir"].includes(t.format))throw new Error(`deprecated format ${t.format}, please use vector format`);return this.withinOptionSession(t,async e=>{let n=new Zt({...t,renderMode:"dom",hookedElem:t.container,kModule:e,renderer:this});return await n.impl.mountDom(t.pixelPerPt),n})}async renderToCanvas(t){let e,n,i=t.container;i.style.visibility="hidden";let o=async(s,_)=>{try{n=await this.renderDisplayLayer(e,s,t),_()}finally{i.style.visibility="visible"}};return this.withinOptionSession(t,async s=>{if(e=s,e[x].pages_info.page_count===0)throw new Error("No page found in session");if(t.pixelPerPt!==void 0&&t.pixelPerPt<=0)throw new Error("Invalid typst.RenderOptions.pixelPerPt, should be a positive number "+t.pixelPerPt);let _=t.backgroundColor;if(_!==void 0&&!/^#[0-9a-f]{6}$/.test(_))throw new Error("Invalid typst.backgroundColor color for matching ^#?[0-9a-f]{6}$ "+_);e.pixelPerPt=t.pixelPerPt??it.PIXEL_PER_PT,e.backgroundColor=_??"#ffffff";let d=performance.now(),l=new Gt(this.retrievePagesInfoFromSession(e),i,t),f=performance.now();console.log(`layer used: retrieve = ${(f-d).toFixed(1)}ms`),await o(l.canvasList,()=>l.resetLayout()),this.renderTextLayer(l.textLayerList,n)})}createModule(t){return Promise.resolve(new gt(this,this.renderer.create_session(t&&this.createOptionsToRust({format:"vector",artifactContent:t}))))}async createWorkerV0(t){return new oe(this,await this.renderer.create_worker(t))}workerBridge(){return this.renderer.create_worker_bridge()}renderSvg(t,e){if(t instanceof gt||e)throw new Error("removed api, please use renderToSvg({ renderSession, container }) instead");return this.withinOptionSession(t,async n=>{let i;return t.data_selection&&(i=0,t.data_selection.body&&(i|=1),t.data_selection.defs&&(i|=2),t.data_selection.css&&(i|=4),t.data_selection.js&&(i|=8)),Promise.resolve(this.renderer.svg_data(n[x],i))})}renderSvgDiff(t){return t.window?this.renderer.render_svg_diff(t.renderSession[x],t.window.lo.x,t.window.lo.y,t.window.hi.x,t.window.hi.y):this.renderer.render_svg_diff(t.renderSession[x],0,0,1e33,1e33)}renderToSvg(t){return this.withinOptionSession(t,async e=>Promise.resolve(this.renderer.render_svg(e[x],t.container)))}getCustomV1(t){return Promise.resolve(this.renderer.get_customs(t.renderSession[x]))}resetSession(t){return this.renderer.reset(t[x])}manipulateData(t){return this.renderer.manipulate_data(t.renderSession[x],t.action??"reset",t.data)}withinOptionSession(t,e){function n(i){return"artifactContent"in i}if("renderSession"in t)return e(t.renderSession);if(n(t))return this.runWithSession(t,e);throw new Error("Invalid render options, should be one of RenderByContentOptions|RenderBySessionOptions")}async runWithSession(t,e){let n=t,i=e;e||(n=void 0,i=t);let o=this.renderer.create_session(n&&this.createOptionsToRust(n));try{let s=await i(new gt(this,o));return o.free(),s}catch(s){throw o.free(),s}}}});function y(r){Dt===H.length&&H.push(H.length+1);let t=Dt;return Dt=H[t],H[t]=r,t}function Oe(r,t){if(!(r instanceof t))throw new Error(`expected instance of ${t.name}`)}function Me(r){let t=typeof r;if(t=="number"||t=="boolean"||r==null)return`${r}`;if(t=="string")return`"${r}"`;if(t=="symbol"){let i=r.description;return i==null?"Symbol":`Symbol(${i})`}if(t=="function"){let i=r.name;return typeof i=="string"&&i.length>0?`Function(${i})`:"Function"}if(Array.isArray(r)){let i=r.length,o="[";i>0&&(o+=Me(r[0]));for(let s=1;s<i;s++)o+=", "+Me(r[s]);return o+="]",o}let e=/\\[object ([^\\]]+)\\]/.exec(toString.call(r)),n;if(e&&e.length>1)n=e[1];else return toString.call(r);if(n=="Object")try{return"Object("+JSON.stringify(r)+")"}catch{return"Object"}return r instanceof Error?`${r.name}: ${r.message}\n${r.stack}`:n}function Gn(r){r<132||(H[r]=Dt,Dt=r)}function Xn(r,t){r=r>>>0;let e=p(),n=[];for(let i=r;i<r+4*t;i+=4)n.push(k(e.getUint32(i,!0)));return n}function Kn(r,t){return r=r>>>0,Yn().subarray(r/4,r/4+t)}function Te(r,t){return r=r>>>0,bt().subarray(r/1,r/1+t)}function p(){return(tt===null||tt.buffer.detached===!0||tt.buffer.detached===void 0&&tt.buffer!==c.memory.buffer)&&(tt=new DataView(c.memory.buffer)),tt}function U(r,t){return r=r>>>0,ti(r,t)}function Yn(){return(Tt===null||Tt.byteLength===0)&&(Tt=new Uint32Array(c.memory.buffer)),Tt}function bt(){return(Lt===null||Lt.byteLength===0)&&(Lt=new Uint8Array(c.memory.buffer)),Lt}function h(r){return H[r]}function pt(r,t){try{return r.apply(this,t)}catch(e){c.__wbindgen_export3(y(e))}}function M(r){return r==null}function Qn(r,t,e,n){let i={a:r,b:t,cnt:1,dtor:e},o=(...s)=>{i.cnt++;let _=i.a;i.a=0;try{return n(_,i.b,...s)}finally{i.a=_,o._wbg_cb_unref()}};return o._wbg_cb_unref=()=>{--i.cnt===0&&(i.dtor(i.a,i.b),i.a=0,Ir.unregister(i))},Ir.register(o,i,i),o}function Or(r,t){let e=t(r.length*1,1)>>>0;return bt().set(r,e/1),C=r.length,e}function ce(r,t){let e=t(r.length*4,4)>>>0,n=p();for(let i=0;i<r.length;i++)n.setUint32(e+4*i,y(r[i]),!0);return C=r.length,e}function O(r,t,e){if(e===void 0){let _=jt.encode(r),d=t(_.length,1)>>>0;return bt().subarray(d,d+_.length).set(_),C=_.length,d}let n=r.length,i=t(n,1)>>>0,o=bt(),s=0;for(;s<n;s++){let _=r.charCodeAt(s);if(_>127)break;o[i+s]=_}if(s!==n){s!==0&&(r=r.slice(s)),i=e(i,n,n=s+r.length*3,1)>>>0;let _=bt().subarray(i+s,i+n),d=jt.encodeInto(r,_);s+=d.written,i=e(i,n,s,1)>>>0}return C=s,i}function k(r){let t=h(r);return Gn(r),t}function ti(r,t){return Pe+=t,Pe>=Zn&&(ue=new TextDecoder("utf-8",{ignoreBOM:!0,fatal:!0}),ue.decode(),Pe=t),ue.decode(bt().subarray(r,r+t))}function ei(r,t,e){c.__wasm_bindgen_func_elem_944(r,t,y(e))}function ri(r,t,e,n){c.__wasm_bindgen_func_elem_37348(r,t,y(e),y(n))}function ni(r){let t=c.get_font_info(y(r));return k(t)}async function oi(r,t){if(typeof Response=="function"&&r instanceof Response){if(typeof WebAssembly.instantiateStreaming=="function")try{return await WebAssembly.instantiateStreaming(r,t)}catch(n){if(r.ok&&ii.has(r.type)&&r.headers.get("Content-Type")!=="application/wasm")console.warn("`WebAssembly.instantiateStreaming` failed because your server does not serve Wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\\n",n);else throw n}let e=await r.arrayBuffer();return await WebAssembly.instantiate(e,t)}else{let e=await WebAssembly.instantiate(r,t);return e instanceof WebAssembly.Instance?{instance:e,module:r}:e}}function Mr(){let r={};return r.wbg={},r.wbg.__wbg_Error_52673b7de5a0ca89=function(t,e){let n=Error(U(t,e));return y(n)},r.wbg.__wbg_Number_2d1dcfcf4ec51736=function(t){return Number(h(t))},r.wbg.__wbg___wbindgen_bigint_get_as_i64_6e32f5e6aff02e1d=function(t,e){let n=h(e),i=typeof n=="bigint"?n:void 0;p().setBigInt64(t+8,M(i)?BigInt(0):i,!0),p().setInt32(t+0,!M(i),!0)},r.wbg.__wbg___wbindgen_boolean_get_dea25b33882b895b=function(t){let e=h(t),n=typeof e=="boolean"?e:void 0;return M(n)?16777215:n?1:0},r.wbg.__wbg___wbindgen_debug_string_adfb662ae34724b6=function(t,e){let n=Me(h(e)),i=O(n,c.__wbindgen_export,c.__wbindgen_export2),o=C;p().setInt32(t+4,o,!0),p().setInt32(t+0,i,!0)},r.wbg.__wbg___wbindgen_in_0d3e1e8f0c669317=function(t,e){return h(t)in h(e)},r.wbg.__wbg___wbindgen_is_bigint_0e1a2e3f55cfae27=function(t){return typeof h(t)=="bigint"},r.wbg.__wbg___wbindgen_is_function_8d400b8b1af978cd=function(t){return typeof h(t)=="function"},r.wbg.__wbg___wbindgen_is_object_ce774f3490692386=function(t){let e=h(t);return typeof e=="object"&&e!==null},r.wbg.__wbg___wbindgen_is_string_704ef9c8fc131030=function(t){return typeof h(t)=="string"},r.wbg.__wbg___wbindgen_is_undefined_f6b95eab589e0269=function(t){return h(t)===void 0},r.wbg.__wbg___wbindgen_jsval_eq_b6101cc9cef1fe36=function(t,e){return h(t)===h(e)},r.wbg.__wbg___wbindgen_jsval_loose_eq_766057600fdd1b0d=function(t,e){return h(t)==h(e)},r.wbg.__wbg___wbindgen_number_get_9619185a74197f95=function(t,e){let n=h(e),i=typeof n=="number"?n:void 0;p().setFloat64(t+8,M(i)?0:i,!0),p().setInt32(t+0,!M(i),!0)},r.wbg.__wbg___wbindgen_string_get_a2a31e16edf96e42=function(t,e){let n=h(e),i=typeof n=="string"?n:void 0;var o=M(i)?0:O(i,c.__wbindgen_export,c.__wbindgen_export2),s=C;p().setInt32(t+4,s,!0),p().setInt32(t+0,o,!0)},r.wbg.__wbg___wbindgen_throw_dd24417ed36fc46e=function(t,e){throw new Error(U(t,e))},r.wbg.__wbg__wbg_cb_unref_87dfb5aaa0cbcea7=function(t){h(t)._wbg_cb_unref()},r.wbg.__wbg_call_3020136f7a2d6e44=function(){return pt(function(t,e,n){let i=h(t).call(h(e),h(n));return y(i)},arguments)},r.wbg.__wbg_call_78f94eb02ec7f9b2=function(){return pt(function(t,e,n,i,o){let s=h(t).call(h(e),h(n),h(i),h(o));return y(s)},arguments)},r.wbg.__wbg_call_abb4ff46ce38be40=function(){return pt(function(t,e){let n=h(t).call(h(e));return y(n)},arguments)},r.wbg.__wbg_done_62ea16af4ce34b24=function(t){return h(t).done},r.wbg.__wbg_entries_83c79938054e065f=function(t){let e=Object.entries(h(t));return y(e)},r.wbg.__wbg_error_7534b8e9a36f1ab4=function(t,e){let n,i;try{n=t,i=e,console.error(U(t,e))}finally{c.__wbindgen_export4(n,i,1)}},r.wbg.__wbg_error_85faeb8919b11cc6=function(t,e,n){console.error(h(t),h(e),h(n))},r.wbg.__wbg_getTimezoneOffset_45389e26d6f46823=function(t){return h(t).getTimezoneOffset()},r.wbg.__wbg_get_6b7bd52aca3f9671=function(t,e){let n=h(t)[e>>>0];return y(n)},r.wbg.__wbg_get_af9dab7e9603ea93=function(){return pt(function(t,e){let n=Reflect.get(h(t),h(e));return y(n)},arguments)},r.wbg.__wbg_get_with_ref_key_1dc361bd10053bfe=function(t,e){let n=h(t)[h(e)];return y(n)},r.wbg.__wbg_info_ce6bcc489c22f6f0=function(t){console.info(h(t))},r.wbg.__wbg_instanceof_ArrayBuffer_f3320d2419cd0355=function(t){let e;try{e=h(t)instanceof ArrayBuffer}catch{e=!1}return e},r.wbg.__wbg_instanceof_Map_084be8da74364158=function(t){let e;try{e=h(t)instanceof Map}catch{e=!1}return e},r.wbg.__wbg_instanceof_Uint8Array_da54ccc9d3e09434=function(t){let e;try{e=h(t)instanceof Uint8Array}catch{e=!1}return e},r.wbg.__wbg_isArray_51fd9e6422c0a395=function(t){return Array.isArray(h(t))},r.wbg.__wbg_isSafeInteger_ae7d3f054d55fa16=function(t){return Number.isSafeInteger(h(t))},r.wbg.__wbg_iterator_27b7c8b35ab3e86b=function(){return y(Symbol.iterator)},r.wbg.__wbg_length_22ac23eaec9d8053=function(t){return h(t).length},r.wbg.__wbg_length_d45040a40c570362=function(t){return h(t).length},r.wbg.__wbg_new_1ba21ce319a06297=function(){let t=new Object;return y(t)},r.wbg.__wbg_new_25f239778d6112b9=function(){let t=new Array;return y(t)},r.wbg.__wbg_new_6421f6084cc5bc5a=function(t){let e=new Uint8Array(h(t));return y(e)},r.wbg.__wbg_new_8a6f238a6ece86ea=function(){let t=new Error;return y(t)},r.wbg.__wbg_new_b2db8aa2650f793a=function(t){let e=new Date(h(t));return y(e)},r.wbg.__wbg_new_df1173567d5ff028=function(t,e){let n=new Error(U(t,e));return y(n)},r.wbg.__wbg_new_ff12d2b041fb48f1=function(t,e){try{var n={a:t,b:e},i=(s,_)=>{let d=n.a;n.a=0;try{return ri(d,n.b,s,_)}finally{n.a=d}};let o=new Promise(i);return y(o)}finally{n.a=n.b=0}},r.wbg.__wbg_new_from_slice_db0691b69e9d3891=function(t,e){let n=new Uint32Array(Kn(t,e));return y(n)},r.wbg.__wbg_new_from_slice_f9c22b9153b26992=function(t,e){let n=new Uint8Array(Te(t,e));return y(n)},r.wbg.__wbg_new_no_args_cb138f77cf6151ee=function(t,e){let n=new Function(U(t,e));return y(n)},r.wbg.__wbg_new_with_args_df9e7125ffe55248=function(t,e,n,i){let o=new Function(U(t,e),U(n,i));return y(o)},r.wbg.__wbg_next_138a17bbf04e926c=function(t){let e=h(t).next;return y(e)},r.wbg.__wbg_next_3cfe5c0fe2a4cc53=function(){return pt(function(t){let e=h(t).next();return y(e)},arguments)},r.wbg.__wbg_now_69d776cd24f5215b=function(){return Date.now()},r.wbg.__wbg_prototypesetcall_dfe9b766cdc1f1fd=function(t,e,n){Uint8Array.prototype.set.call(Te(t,e),h(n))},r.wbg.__wbg_proxycontext_new=function(t){let e=ht.__wrap(t);return y(e)},r.wbg.__wbg_push_7d9be8f38fc13975=function(t,e){return h(t).push(h(e))},r.wbg.__wbg_queueMicrotask_9b549dfce8865860=function(t){let e=h(t).queueMicrotask;return y(e)},r.wbg.__wbg_queueMicrotask_fca69f5bfad613a5=function(t){queueMicrotask(h(t))},r.wbg.__wbg_resolve_fd5bfbaa4ce36e1e=function(t){let e=Promise.resolve(h(t));return y(e)},r.wbg.__wbg_set_3f1d0b984ed272ed=function(t,e,n){h(t)[k(e)]=k(n)},r.wbg.__wbg_set_781438a03c0c3c81=function(){return pt(function(t,e,n){return Reflect.set(h(t),h(e),h(n))},arguments)},r.wbg.__wbg_set_7df433eea03a5c14=function(t,e,n){h(t)[e>>>0]=k(n)},r.wbg.__wbg_stack_0ed75d68575b0f3c=function(t,e){let n=h(e).stack,i=O(n,c.__wbindgen_export,c.__wbindgen_export2),o=C;p().setInt32(t+4,o,!0),p().setInt32(t+0,i,!0)},r.wbg.__wbg_static_accessor_GLOBAL_769e6b65d6557335=function(){let t=typeof global>"u"?null:global;return M(t)?0:y(t)},r.wbg.__wbg_static_accessor_GLOBAL_THIS_60cf02db4de8e1c1=function(){let t=typeof globalThis>"u"?null:globalThis;return M(t)?0:y(t)},r.wbg.__wbg_static_accessor_SELF_08f5a74c69739274=function(){let t=typeof self>"u"?null:self;return M(t)?0:y(t)},r.wbg.__wbg_static_accessor_WINDOW_a8924b26aa92d024=function(){let t=typeof window>"u"?null:window;return M(t)?0:y(t)},r.wbg.__wbg_then_4f95312d68691235=function(t,e){let n=h(t).then(h(e));return y(n)},r.wbg.__wbg_typstcompiler_new=function(t){let e=yt.__wrap(t);return y(e)},r.wbg.__wbg_typstfontresolver_new=function(t){let e=et.__wrap(t);return y(e)},r.wbg.__wbg_value_57b7b035e117f7ee=function(t){let e=h(t).value;return y(e)},r.wbg.__wbindgen_cast_2241b6af4c4b2941=function(t,e){let n=U(t,e);return y(n)},r.wbg.__wbindgen_cast_3334ea73b4b28ba3=function(t,e){let n=Qn(t,e,c.__wasm_bindgen_func_elem_957,ei);return y(n)},r.wbg.__wbindgen_cast_4625c577ab2ec9ee=function(t){let e=BigInt.asUintN(64,t);return y(e)},r.wbg.__wbindgen_cast_9ae0607507abb057=function(t){return y(t)},r.wbg.__wbindgen_cast_d6cd19b81560fd6e=function(t){return y(t)},r.wbg.__wbindgen_object_clone_ref=function(t){let e=h(t);return y(e)},r.wbg.__wbindgen_object_drop_ref=function(t){k(t)},r}function Tr(r,t){return c=r.exports,Lr.__wbindgen_wasm_module=t,tt=null,Tt=null,Lt=null,c}function si(r){if(c!==void 0)return c;typeof r<"u"&&(Object.getPrototypeOf(r)===Object.prototype?{module:r}=r:console.warn("using deprecated parameters for `initSync()`; pass a single object instead"));let t=Mr();r instanceof WebAssembly.Module||(r=new WebAssembly.Module(r));let e=new WebAssembly.Instance(r,t);return Tr(e,r)}async function Lr(r){if(c!==void 0)return c;typeof r<"u"&&(Object.getPrototypeOf(r)===Object.prototype?{module_or_path:r}=r:console.warn("using deprecated parameters for the initialization function; pass a single object instead")),typeof r>"u"&&(r=jr("typst_ts_web_compiler_bg.wasm",ai.url));let t=Mr();(typeof r=="string"||typeof Request=="function"&&r instanceof Request||typeof URL=="function"&&r instanceof URL)&&(r=fetch(r));let{instance:e,module:n}=await oi(await r,t);return Tr(e,n)}function Le(r){jr=r}var ai,c,Ir,tt,Tt,Lt,H,Dt,ue,Zn,Pe,jt,C,Er,Fe,Rr,Cr,Ar,Pr,Fr,J,ht,mt,yt,zt,et,Wt,ii,Dr,jr,de=z(()=>{ai={};Ir=typeof FinalizationRegistry>"u"?{register:()=>{},unregister:()=>{}}:new FinalizationRegistry(r=>r.dtor(r.a,r.b));tt=null;Tt=null;Lt=null;H=new Array(128).fill(void 0);H.push(void 0,null,!0,!1);Dt=H.length;ue=new TextDecoder("utf-8",{ignoreBOM:!0,fatal:!0});ue.decode();Zn=2146435072,Pe=0;jt=new TextEncoder;"encodeInto"in jt||(jt.encodeInto=function(r,t){let e=jt.encode(r);return t.set(e),{read:r.length,written:e.length}});C=0;Er=typeof FinalizationRegistry>"u"?{register:()=>{},unregister:()=>{}}:new FinalizationRegistry(r=>c.__wbg_incrserver_free(r>>>0,1)),Fe=typeof FinalizationRegistry>"u"?{register:()=>{},unregister:()=>{}}:new FinalizationRegistry(r=>c.__wbg_proxycontext_free(r>>>0,1)),Rr=typeof FinalizationRegistry>"u"?{register:()=>{},unregister:()=>{}}:new FinalizationRegistry(r=>c.__wbg_typstcompileworld_free(r>>>0,1)),Cr=typeof FinalizationRegistry>"u"?{register:()=>{},unregister:()=>{}}:new FinalizationRegistry(r=>c.__wbg_typstcompiler_free(r>>>0,1)),Ar=typeof FinalizationRegistry>"u"?{register:()=>{},unregister:()=>{}}:new FinalizationRegistry(r=>c.__wbg_typstcompilerbuilder_free(r>>>0,1)),Pr=typeof FinalizationRegistry>"u"?{register:()=>{},unregister:()=>{}}:new FinalizationRegistry(r=>c.__wbg_typstfontresolver_free(r>>>0,1)),Fr=typeof FinalizationRegistry>"u"?{register:()=>{},unregister:()=>{}}:new FinalizationRegistry(r=>c.__wbg_typstfontresolverbuilder_free(r>>>0,1)),J=class r{static __wrap(t){t=t>>>0;let e=Object.create(r.prototype);return e.__wbg_ptr=t,Er.register(e,e.__wbg_ptr,e),e}__destroy_into_raw(){let t=this.__wbg_ptr;return this.__wbg_ptr=0,Er.unregister(this),t}free(){let t=this.__destroy_into_raw();c.__wbg_incrserver_free(t,0)}set_attach_debug_info(t){c.incrserver_set_attach_debug_info(this.__wbg_ptr,t)}current(){try{let n=c.__wbindgen_add_to_stack_pointer(-16);c.incrserver_current(n,this.__wbg_ptr);var t=p().getInt32(n+0,!0),e=p().getInt32(n+4,!0);let i;return t!==0&&(i=Te(t,e).slice(),c.__wbindgen_export4(t,e*1,1)),i}finally{c.__wbindgen_add_to_stack_pointer(16)}}reset(){c.incrserver_reset(this.__wbg_ptr)}};Symbol.dispose&&(J.prototype[Symbol.dispose]=J.prototype.free);ht=class r{static __wrap(t){t=t>>>0;let e=Object.create(r.prototype);return e.__wbg_ptr=t,Fe.register(e,e.__wbg_ptr,e),e}__destroy_into_raw(){let t=this.__wbg_ptr;return this.__wbg_ptr=0,Fe.unregister(this),t}free(){let t=this.__destroy_into_raw();c.__wbg_proxycontext_free(t,0)}constructor(t){let e=c.proxycontext_new(y(t));return this.__wbg_ptr=e>>>0,Fe.register(this,this.__wbg_ptr,this),this}get context(){let t=c.proxycontext_context(this.__wbg_ptr);return k(t)}untar(t,e){try{let o=c.__wbindgen_add_to_stack_pointer(-16),s=Or(t,c.__wbindgen_export),_=C;c.proxycontext_untar(o,this.__wbg_ptr,s,_,y(e));var n=p().getInt32(o+0,!0),i=p().getInt32(o+4,!0);if(i)throw k(n)}finally{c.__wbindgen_add_to_stack_pointer(16)}}};Symbol.dispose&&(ht.prototype[Symbol.dispose]=ht.prototype.free);mt=class r{static __wrap(t){t=t>>>0;let e=Object.create(r.prototype);return e.__wbg_ptr=t,Rr.register(e,e.__wbg_ptr,e),e}__destroy_into_raw(){let t=this.__wbg_ptr;return this.__wbg_ptr=0,Rr.unregister(this),t}free(){let t=this.__destroy_into_raw();c.__wbg_typstcompileworld_free(t,0)}compile(t,e){try{let s=c.__wbindgen_add_to_stack_pointer(-16);c.typstcompileworld_compile(s,this.__wbg_ptr,t,e);var n=p().getInt32(s+0,!0),i=p().getInt32(s+4,!0),o=p().getInt32(s+8,!0);if(o)throw k(i);return k(n)}finally{c.__wbindgen_add_to_stack_pointer(16)}}title(t){try{let s=c.__wbindgen_add_to_stack_pointer(-16);c.typstcompileworld_title(s,this.__wbg_ptr,t);var e=p().getInt32(s+0,!0),n=p().getInt32(s+4,!0),i=p().getInt32(s+8,!0),o=p().getInt32(s+12,!0);if(o)throw k(i);let _;return e!==0&&(_=U(e,n).slice(),c.__wbindgen_export4(e,n*1,1)),_}finally{c.__wbindgen_add_to_stack_pointer(16)}}get_artifact(t,e){try{let s=c.__wbindgen_add_to_stack_pointer(-16);c.typstcompileworld_get_artifact(s,this.__wbg_ptr,t,e);var n=p().getInt32(s+0,!0),i=p().getInt32(s+4,!0),o=p().getInt32(s+8,!0);if(o)throw k(i);return k(n)}finally{c.__wbindgen_add_to_stack_pointer(16)}}query(t,e,n){let i,o;try{let B=c.__wbindgen_add_to_stack_pointer(-16),j=O(e,c.__wbindgen_export,c.__wbindgen_export2),T=C;var s=M(n)?0:O(n,c.__wbindgen_export,c.__wbindgen_export2),_=C;c.typstcompileworld_query(B,this.__wbg_ptr,t,j,T,s,_);var d=p().getInt32(B+0,!0),l=p().getInt32(B+4,!0),f=p().getInt32(B+8,!0),v=p().getInt32(B+12,!0),S=d,E=l;if(v)throw S=0,E=0,k(f);return i=S,o=E,U(S,E)}finally{c.__wbindgen_add_to_stack_pointer(16),c.__wbindgen_export4(i,o,1)}}incr_compile(t,e){try{let s=c.__wbindgen_add_to_stack_pointer(-16);Oe(t,J),c.typstcompileworld_incr_compile(s,this.__wbg_ptr,t.__wbg_ptr,e);var n=p().getInt32(s+0,!0),i=p().getInt32(s+4,!0),o=p().getInt32(s+8,!0);if(o)throw k(i);return k(n)}finally{c.__wbindgen_add_to_stack_pointer(16)}}};Symbol.dispose&&(mt.prototype[Symbol.dispose]=mt.prototype.free);yt=class r{static __wrap(t){t=t>>>0;let e=Object.create(r.prototype);return e.__wbg_ptr=t,Cr.register(e,e.__wbg_ptr,e),e}__destroy_into_raw(){let t=this.__wbg_ptr;return this.__wbg_ptr=0,Cr.unregister(this),t}free(){let t=this.__destroy_into_raw();c.__wbg_typstcompiler_free(t,0)}reset(){try{let n=c.__wbindgen_add_to_stack_pointer(-16);c.typstcompiler_reset(n,this.__wbg_ptr);var t=p().getInt32(n+0,!0),e=p().getInt32(n+4,!0);if(e)throw k(t)}finally{c.__wbindgen_add_to_stack_pointer(16)}}set_fonts(t){try{let i=c.__wbindgen_add_to_stack_pointer(-16);Oe(t,et),c.typstcompiler_set_fonts(i,this.__wbg_ptr,t.__wbg_ptr);var e=p().getInt32(i+0,!0),n=p().getInt32(i+4,!0);if(n)throw k(e)}finally{c.__wbindgen_add_to_stack_pointer(16)}}set_inputs(t){try{let i=c.__wbindgen_add_to_stack_pointer(-16);c.typstcompiler_set_inputs(i,this.__wbg_ptr,y(t));var e=p().getInt32(i+0,!0),n=p().getInt32(i+4,!0);if(n)throw k(e)}finally{c.__wbindgen_add_to_stack_pointer(16)}}add_source(t,e){let n=O(t,c.__wbindgen_export,c.__wbindgen_export2),i=C,o=O(e,c.__wbindgen_export,c.__wbindgen_export2),s=C;return c.typstcompiler_add_source(this.__wbg_ptr,n,i,o,s)!==0}map_shadow(t,e){let n=O(t,c.__wbindgen_export,c.__wbindgen_export2),i=C,o=Or(e,c.__wbindgen_export),s=C;return c.typstcompiler_map_shadow(this.__wbg_ptr,n,i,o,s)!==0}unmap_shadow(t){let e=O(t,c.__wbindgen_export,c.__wbindgen_export2),n=C;return c.typstcompiler_unmap_shadow(this.__wbg_ptr,e,n)!==0}reset_shadow(){c.typstcompiler_reset_shadow(this.__wbg_ptr)}get_loaded_fonts(){try{let i=c.__wbindgen_add_to_stack_pointer(-16);c.typstcompiler_get_loaded_fonts(i,this.__wbg_ptr);var t=p().getInt32(i+0,!0),e=p().getInt32(i+4,!0),n=Xn(t,e).slice();return c.__wbindgen_export4(t,e*4,4),n}finally{c.__wbindgen_add_to_stack_pointer(16)}}get_ast(t){let e,n;try{let f=c.__wbindgen_add_to_stack_pointer(-16),v=O(t,c.__wbindgen_export,c.__wbindgen_export2),S=C;c.typstcompiler_get_ast(f,this.__wbg_ptr,v,S);var i=p().getInt32(f+0,!0),o=p().getInt32(f+4,!0),s=p().getInt32(f+8,!0),_=p().getInt32(f+12,!0),d=i,l=o;if(_)throw d=0,l=0,k(s);return e=d,n=l,U(d,l)}finally{c.__wbindgen_add_to_stack_pointer(16),c.__wbindgen_export4(e,n,1)}}get_semantic_token_legend(){try{let i=c.__wbindgen_add_to_stack_pointer(-16);c.typstcompiler_get_semantic_token_legend(i,this.__wbg_ptr);var t=p().getInt32(i+0,!0),e=p().getInt32(i+4,!0),n=p().getInt32(i+8,!0);if(n)throw k(e);return k(t)}finally{c.__wbindgen_add_to_stack_pointer(16)}}get_semantic_tokens(t,e,n){try{let v=c.__wbindgen_add_to_stack_pointer(-16),S=O(t,c.__wbindgen_export,c.__wbindgen_export2),E=C;var i=M(e)?0:O(e,c.__wbindgen_export,c.__wbindgen_export2),o=C,s=M(n)?0:O(n,c.__wbindgen_export,c.__wbindgen_export2),_=C;c.typstcompiler_get_semantic_tokens(v,this.__wbg_ptr,S,E,i,o,s,_);var d=p().getInt32(v+0,!0),l=p().getInt32(v+4,!0),f=p().getInt32(v+8,!0);if(f)throw k(l);return k(d)}finally{c.__wbindgen_add_to_stack_pointer(16)}}snapshot(t,e,n){try{let E=c.__wbindgen_add_to_stack_pointer(-16);var i=M(t)?0:O(t,c.__wbindgen_export,c.__wbindgen_export2),o=C,s=M(e)?0:O(e,c.__wbindgen_export,c.__wbindgen_export2),_=C,d=M(n)?0:ce(n,c.__wbindgen_export),l=C;c.typstcompiler_snapshot(E,this.__wbg_ptr,i,o,s,_,d,l);var f=p().getInt32(E+0,!0),v=p().getInt32(E+4,!0),S=p().getInt32(E+8,!0);if(S)throw k(v);return mt.__wrap(f)}finally{c.__wbindgen_add_to_stack_pointer(16)}}get_artifact(t,e){try{let s=c.__wbindgen_add_to_stack_pointer(-16),_=O(t,c.__wbindgen_export,c.__wbindgen_export2),d=C;c.typstcompiler_get_artifact(s,this.__wbg_ptr,_,d,e);var n=p().getInt32(s+0,!0),i=p().getInt32(s+4,!0),o=p().getInt32(s+8,!0);if(o)throw k(i);return k(n)}finally{c.__wbindgen_add_to_stack_pointer(16)}}compile(t,e,n,i){try{let S=c.__wbindgen_add_to_stack_pointer(-16);var o=M(t)?0:O(t,c.__wbindgen_export,c.__wbindgen_export2),s=C,_=M(e)?0:ce(e,c.__wbindgen_export),d=C;let E=O(n,c.__wbindgen_export,c.__wbindgen_export2),B=C;c.typstcompiler_compile(S,this.__wbg_ptr,o,s,_,d,E,B,i);var l=p().getInt32(S+0,!0),f=p().getInt32(S+4,!0),v=p().getInt32(S+8,!0);if(v)throw k(f);return k(l)}finally{c.__wbindgen_add_to_stack_pointer(16)}}query(t,e,n,i){let o,s;try{let kt=c.__wbindgen_add_to_stack_pointer(-16),Zr=O(t,c.__wbindgen_export,c.__wbindgen_export2),tn=C;var _=M(e)?0:ce(e,c.__wbindgen_export),d=C;let en=O(n,c.__wbindgen_export,c.__wbindgen_export2),rn=C;var l=M(i)?0:O(i,c.__wbindgen_export,c.__wbindgen_export2),f=C;c.typstcompiler_query(kt,this.__wbg_ptr,Zr,tn,_,d,en,rn,l,f);var v=p().getInt32(kt+0,!0),S=p().getInt32(kt+4,!0),E=p().getInt32(kt+8,!0),B=p().getInt32(kt+12,!0),j=v,T=S;if(B)throw j=0,T=0,k(E);return o=j,s=T,U(j,T)}finally{c.__wbindgen_add_to_stack_pointer(16),c.__wbindgen_export4(o,s,1)}}create_incr_server(){try{let i=c.__wbindgen_add_to_stack_pointer(-16);c.typstcompiler_create_incr_server(i,this.__wbg_ptr);var t=p().getInt32(i+0,!0),e=p().getInt32(i+4,!0),n=p().getInt32(i+8,!0);if(n)throw k(e);return J.__wrap(t)}finally{c.__wbindgen_add_to_stack_pointer(16)}}incr_compile(t,e,n,i){try{let f=c.__wbindgen_add_to_stack_pointer(-16),v=O(t,c.__wbindgen_export,c.__wbindgen_export2),S=C;var o=M(e)?0:ce(e,c.__wbindgen_export),s=C;Oe(n,J),c.typstcompiler_incr_compile(f,this.__wbg_ptr,v,S,o,s,n.__wbg_ptr,i);var _=p().getInt32(f+0,!0),d=p().getInt32(f+4,!0),l=p().getInt32(f+8,!0);if(l)throw k(d);return k(_)}finally{c.__wbindgen_add_to_stack_pointer(16)}}};Symbol.dispose&&(yt.prototype[Symbol.dispose]=yt.prototype.free);zt=class{__destroy_into_raw(){let t=this.__wbg_ptr;return this.__wbg_ptr=0,Ar.unregister(this),t}free(){let t=this.__destroy_into_raw();c.__wbg_typstcompilerbuilder_free(t,0)}constructor(){try{let i=c.__wbindgen_add_to_stack_pointer(-16);c.typstcompilerbuilder_new(i);var t=p().getInt32(i+0,!0),e=p().getInt32(i+4,!0),n=p().getInt32(i+8,!0);if(n)throw k(e);return this.__wbg_ptr=t>>>0,Ar.register(this,this.__wbg_ptr,this),this}finally{c.__wbindgen_add_to_stack_pointer(16)}}set_dummy_access_model(){try{let n=c.__wbindgen_add_to_stack_pointer(-16);c.typstcompilerbuilder_set_dummy_access_model(n,this.__wbg_ptr);var t=p().getInt32(n+0,!0),e=p().getInt32(n+4,!0);if(e)throw k(t)}finally{c.__wbindgen_add_to_stack_pointer(16)}}set_access_model(t,e,n,i,o){let s=c.typstcompilerbuilder_set_access_model(this.__wbg_ptr,y(t),y(e),y(n),y(i),y(o));return k(s)}set_package_registry(t,e){let n=c.typstcompilerbuilder_set_package_registry(this.__wbg_ptr,y(t),y(e));return k(n)}add_raw_font(t){let e=c.typstcompilerbuilder_add_raw_font(this.__wbg_ptr,y(t));return k(e)}add_lazy_font(t,e){let n=c.typstcompilerbuilder_add_lazy_font(this.__wbg_ptr,y(t),y(e));return k(n)}build(){let t=this.__destroy_into_raw(),e=c.typstcompilerbuilder_build(t);return k(e)}};Symbol.dispose&&(zt.prototype[Symbol.dispose]=zt.prototype.free);et=class r{static __wrap(t){t=t>>>0;let e=Object.create(r.prototype);return e.__wbg_ptr=t,Pr.register(e,e.__wbg_ptr,e),e}__destroy_into_raw(){let t=this.__wbg_ptr;return this.__wbg_ptr=0,Pr.unregister(this),t}free(){let t=this.__destroy_into_raw();c.__wbg_typstfontresolver_free(t,0)}};Symbol.dispose&&(et.prototype[Symbol.dispose]=et.prototype.free);Wt=class{__destroy_into_raw(){let t=this.__wbg_ptr;return this.__wbg_ptr=0,Fr.unregister(this),t}free(){let t=this.__destroy_into_raw();c.__wbg_typstfontresolverbuilder_free(t,0)}constructor(){try{let i=c.__wbindgen_add_to_stack_pointer(-16);c.typstfontresolverbuilder_new(i);var t=p().getInt32(i+0,!0),e=p().getInt32(i+4,!0),n=p().getInt32(i+8,!0);if(n)throw k(e);return this.__wbg_ptr=t>>>0,Fr.register(this,this.__wbg_ptr,this),this}finally{c.__wbindgen_add_to_stack_pointer(16)}}get_font_info(t){try{let o=c.__wbindgen_add_to_stack_pointer(-16);c.typstfontresolverbuilder_get_font_info(o,this.__wbg_ptr,y(t));var e=p().getInt32(o+0,!0),n=p().getInt32(o+4,!0),i=p().getInt32(o+8,!0);if(i)throw k(n);return k(e)}finally{c.__wbindgen_add_to_stack_pointer(16)}}add_raw_font(t){try{let i=c.__wbindgen_add_to_stack_pointer(-16);c.typstfontresolverbuilder_add_raw_font(i,this.__wbg_ptr,y(t));var e=p().getInt32(i+0,!0),n=p().getInt32(i+4,!0);if(n)throw k(e)}finally{c.__wbindgen_add_to_stack_pointer(16)}}add_lazy_font(t,e){try{let o=c.__wbindgen_add_to_stack_pointer(-16);c.typstfontresolverbuilder_add_lazy_font(o,this.__wbg_ptr,y(t),y(e));var n=p().getInt32(o+0,!0),i=p().getInt32(o+4,!0);if(i)throw k(n)}finally{c.__wbindgen_add_to_stack_pointer(16)}}build(){let t=this.__destroy_into_raw(),e=c.typstfontresolverbuilder_build(t);return k(e)}};Symbol.dispose&&(Wt.prototype[Symbol.dispose]=Wt.prototype.free);ii=new Set(["basic","cors","default"]);Dr=Lr,jr=async function(r,t){throw new Error("Cannot import wasm module without importer: "+r+" "+t)}});var De={};rt(De,{IncrServer:()=>J,ProxyContext:()=>ht,TypstCompileWorld:()=>mt,TypstCompiler:()=>yt,TypstCompilerBuilder:()=>zt,TypstFontResolver:()=>et,TypstFontResolverBuilder:()=>Wt,default:()=>_i,get_font_info:()=>ni,initSync:()=>si,setImportWasmModule:()=>Le});var _i,ci,ui,je=z(()=>{de();de();de();_i=Dr,ci=async function(r,t){let e=new Function("m","return import(m)"),{readFileSync:n}=await e("fs"),i=new URL(r,t);return await n(i).buffer},ui=typeof process<"u"&&process.versions!=null&&process.versions.node!=null;ui&&Le(ci)});var pe={};rt(pe,{CompileFormatEnum:()=>xt,IncrementalServer:()=>fe,TypstFontBuilderDriver:()=>ge,TypstWorld:()=>le,createTypstCompiler:()=>ze,createTypstFontBuilder:()=>Br});function Br(){return new ge}function ze(){return new we}function Wr(r){return r?Object.entries(r):void 0}function vt(r){switch(r){case"none":return 1;case"unix":return 2;default:return 3}}var xt,fe,zr,le,Ur,ge,we,St=z(()=>{Kt();Et();It();ve();(function(r){r[r.vector=0]="vector",r[r.pdf=1]="pdf",r[r._dummy=2]="_dummy"})(xt||(xt={}));fe=class{[x];constructor(t){this[x]=t}reset(){this[x].reset()}current(){return this[x].current()}setAttachDebugInfo(t){this[x].set_attach_debug_info(t)}};zr||(zr={});le=class{[x];constructor(t){this[x]=t}compile(t){return this[x].compile(0,vt(t?.diagnostics))}compileHtml(t){return this[x].compile(1,vt(t?.diagnostics))}async query(t){return JSON.parse(this[x].query(0,t.selector,t.field))}title(){return this[x].title(0)}vector(t){return this[x].get_artifact(0,vt(t?.diagnostics))||{}}pdf(t){return this[x].get_artifact(1,vt(t?.diagnostics))||{}}},Ur=r=>new ot(async t=>await r.default(t));ge=class{fontBuilderJs;fontBuilder;async init(t){this.fontBuilderJs=await(t?.getWrapper?.()||Promise.resolve().then(()=>(je(),De))),await Ur(this.fontBuilderJs).init(t?.getModule?.()),this.fontBuilder=new this.fontBuilderJs.TypstFontResolverBuilder}async getFontInfo(t){return this.fontBuilder.get_font_info(t)}async addFontData(t){this.fontBuilder.add_raw_font(t)}async addLazyFont(t,e){return this.fontBuilder.add_lazy_font(t,e)}async build(t){let e=await this.fontBuilder.build(),n=await t(e);return e.free(),n}},we=class r{compiler;compilerJs;static defaultAssets=["text"];constructor(){}async init(t){this.compilerJs=await(t?.getWrapper?.()||Promise.resolve().then(()=>(je(),De)));let e=this.compilerJs.TypstCompilerBuilder,n={...t||{}},i=n.beforeBuild??=[],o=i.some(l=>l._preloadRemoteFontOptions!==void 0),s=i.some(l=>l._preloadRemoteFontOptions?.assets!==void 0),_=i.some(l=>l._preloadRemoteFontOptions?.assets===!1);if((!o||!s&&!_)&&i.push(X([],{assets:r.defaultAssets})),!i.some(l=>l._kind==="fontLoader"))throw new Error("TypstCompiler: no font loader found, please use font loaders, e.g. loadFonts or preloadSystemFonts");this.compiler=await Xt(t,Ur(this.compilerJs),e,{})}setFonts(t){this.compiler.set_fonts(t)}compile(t){return new Promise(e=>{let n=this.compiler.snapshot(t.root,t.mainFilePath,Wr(t.inputs));if("incrementalServer"in t){e(n.incr_compile(t.incrementalServer[x],vt(t.diagnostics)));return}e(n.get_artifact(t.format||xt.vector,vt(t.diagnostics)))})}async runWithWorld(t,e){let n=this.compiler.snapshot(t.root,t.mainFilePath,Wr(t.inputs)),i=await e(new le(n));return n.free(),i}query(t){return this.runWithWorld(t,async e=>JSON.parse(await e.query(t)))}getSemanticTokenLegend(){return new Promise(t=>{t(this.compiler.get_semantic_token_legend())})}getSemanticTokens(t){return new Promise(e=>{this.compiler.reset(),e(this.compiler.get_semantic_tokens(t.offsetEncoding||"utf-16",t.mainFilePath,t.resultId))})}async withIncrementalServer(t){let e=new fe(this.compiler.create_incr_server());try{return await t(e)}finally{e[x].free()}}async getAst(t){return this.compiler.get_ast(t)}async reset(){await new Promise(t=>{this.compiler.reset(),t(void 0)})}addSource(t,e){if(arguments.length>2)throw new Error("use of addSource(path, source, isMain) is deprecated, please use addSource(path, source) instead");this.compiler.add_source(t,e)}mapShadow(t,e){this.compiler.map_shadow(t,e)}unmapShadow(t){this.compiler.unmap_shadow(t)}resetShadow(){this.compiler.reset_shadow()}renderPageToCanvas(){throw new Error("Please use the api TypstRenderer.renderToCanvas in v0.4.0")}};ze._impl=we});var Vr={};rt(Vr,{createGlobalCompiler:()=>Hr,getGlobalCompiler:()=>Nr,withGlobalCompiler:()=>di});function Nr(){return qr?Be:void 0}function Hr(r,t){let e=Be||r();return We!==void 0?We:We=(async()=>(qr=!0,await e.init(t),Be=e))()}function di(r,t,e,n){let i=Nr();if(i){e(i);return}Hr(r,t).then(e).catch(n)}var Be,We,qr,Jr=z(()=>{qr=!1});var Yr={};rt(Yr,{createGlobalRenderer:()=>Kr,getGlobalRenderer:()=>Xr,withGlobalRenderer:()=>fi});function Xr(){return Gr?$e:void 0}function Kr(r,t){let e=$e||r();return Ue!==void 0?Ue:Ue=(async()=>(Gr=!0,await e.init(t),$e=e))()}function fi(r,t,e,n){let i=Xr();if(i){e(i);return}Kr(r,t).then(e).catch(n)}var $e,Ue,Gr,Qr=z(()=>{Gr=!1});var He=Symbol("Comlink.proxy"),on=Symbol("Comlink.endpoint"),sn=Symbol("Comlink.releaseProxy"),he=Symbol("Comlink.finalizer"),$t=Symbol("Comlink.thrown"),Ve=r=>typeof r=="object"&&r!==null||typeof r=="function",an={canHandle:r=>Ve(r)&&r[He],serialize(r){let{port1:t,port2:e}=new MessageChannel;return Vt(r,t),[e,[e]]},deserialize(r){return r.start(),dn(r)}},_n={canHandle:r=>Ve(r)&&$t in r,serialize({value:r}){let t;return r instanceof Error?t={isError:!0,value:{message:r.message,name:r.name,stack:r.stack}}:t={isError:!1,value:r},[t,[]]},deserialize(r){throw r.isError?Object.assign(new Error(r.value.message),r.value):r.value}},Je=new Map([["proxy",an],["throw",_n]]);function cn(r,t){for(let e of r)if(t===e||e==="*"||e instanceof RegExp&&e.test(t))return!0;return!1}function Vt(r,t=globalThis,e=["*"]){t.addEventListener("message",function n(i){if(!i||!i.data)return;if(!cn(e,i.origin)){console.warn(`Invalid origin \'${i.origin}\' for comlink proxy`);return}let{id:o,type:s,path:_}=Object.assign({path:[]},i.data),d=(i.data.argumentList||[]).map(G),l;try{let f=_.slice(0,-1).reduce((S,E)=>S[E],r),v=_.reduce((S,E)=>S[E],r);switch(s){case"GET":l=v;break;case"SET":f[_.slice(-1)[0]]=G(i.data.value),l=!0;break;case"APPLY":l=v.apply(f,d);break;case"CONSTRUCT":{let S=new v(...d);l=pn(S)}break;case"ENDPOINT":{let{port1:S,port2:E}=new MessageChannel;Vt(r,E),l=wn(S,[S])}break;case"RELEASE":l=void 0;break;default:return}}catch(f){l={value:f,[$t]:0}}Promise.resolve(l).catch(f=>({value:f,[$t]:0})).then(f=>{let[v,S]=Ht(f);t.postMessage(Object.assign(Object.assign({},v),{id:o}),S),s==="RELEASE"&&(t.removeEventListener("message",n),Ge(t),he in r&&typeof r[he]=="function"&&r[he]())}).catch(f=>{let[v,S]=Ht({value:new TypeError("Unserializable return value"),[$t]:0});t.postMessage(Object.assign(Object.assign({},v),{id:o}),S)})}),t.start&&t.start()}function un(r){return r.constructor.name==="MessagePort"}function Ge(r){un(r)&&r.close()}function dn(r,t){let e=new Map;return r.addEventListener("message",function(i){let{data:o}=i;if(!o||!o.id)return;let s=e.get(o.id);if(s)try{s(o)}finally{e.delete(o.id)}}),me(r,e,[],t)}function Ut(r){if(r)throw new Error("Proxy has been released and is not useable")}function Xe(r){return nt(r,new Map,{type:"RELEASE"}).then(()=>{Ge(r)})}var qt=new WeakMap,Nt="FinalizationRegistry"in globalThis&&new FinalizationRegistry(r=>{let t=(qt.get(r)||0)-1;qt.set(r,t),t===0&&Xe(r)});function fn(r,t){let e=(qt.get(t)||0)+1;qt.set(t,e),Nt&&Nt.register(r,t,r)}function ln(r){Nt&&Nt.unregister(r)}function me(r,t,e=[],n=function(){}){let i=!1,o=new Proxy(n,{get(s,_){if(Ut(i),_===sn)return()=>{ln(o),Xe(r),t.clear(),i=!0};if(_==="then"){if(e.length===0)return{then:()=>o};let d=nt(r,t,{type:"GET",path:e.map(l=>l.toString())}).then(G);return d.then.bind(d)}return me(r,t,[...e,_])},set(s,_,d){Ut(i);let[l,f]=Ht(d);return nt(r,t,{type:"SET",path:[...e,_].map(v=>v.toString()),value:l},f).then(G)},apply(s,_,d){Ut(i);let l=e[e.length-1];if(l===on)return nt(r,t,{type:"ENDPOINT"}).then(G);if(l==="bind")return me(r,t,e.slice(0,-1));let[f,v]=Ne(d);return nt(r,t,{type:"APPLY",path:e.map(S=>S.toString()),argumentList:f},v).then(G)},construct(s,_){Ut(i);let[d,l]=Ne(_);return nt(r,t,{type:"CONSTRUCT",path:e.map(f=>f.toString()),argumentList:d},l).then(G)}});return fn(o,r),o}function gn(r){return Array.prototype.concat.apply([],r)}function Ne(r){let t=r.map(Ht);return[t.map(e=>e[0]),gn(t.map(e=>e[1]))]}var Ke=new WeakMap;function wn(r,t){return Ke.set(r,t),r}function pn(r){return Object.assign(r,{[He]:!0})}function Ht(r){for(let[t,e]of Je)if(e.canHandle(r)){let[n,i]=e.serialize(r);return[{type:"HANDLER",name:t,value:n},i]}return[{type:"RAW",value:r},Ke.get(r)||[]]}function G(r){switch(r.type){case"HANDLER":return Je.get(r.name).deserialize(r.value);case"RAW":return r.value}}function nt(r,t,e,n){return new Promise(i=>{let o=bn();t.set(o,i),r.start&&r.start(),r.postMessage(Object.assign({id:o},e),n)})}function bn(){return new Array(4).fill(0).map(()=>Math.floor(Math.random()*Number.MAX_SAFE_INTEGER).toString(16)).join("-")}It();It();_e();var Z=class{mTimes=new Map;mData=new Map;constructor(){}reset(){this.mTimes.clear(),this.mData.clear()}insertFile(t,e,n){this.mTimes.set(t,n),this.mData.set(t,e)}removeFile(t){this.mTimes.delete(t),this.mData.delete(t)}getMTime(t){if(t.startsWith("/@memory/")&&this.mTimes.has(t))return this.mTimes.get(t)}isFile(){return!0}getRealPath(t){return t}readAll(t){if(t.startsWith("/@memory/")&&this.mData.has(t))return this.mData.get(t)}};var wt=class{am;cache=new Map;constructor(t){this.am=t}resolvePath(t){return`https://packages.typst.org/preview/${t.name}-${t.version}.tar.gz`}pullPackageData(t){let e=new XMLHttpRequest;if(e.overrideMimeType("text/plain; charset=x-user-defined"),e.open("GET",this.resolvePath(t),!1),e.send(null),e.status===200&&(e.response instanceof String||typeof e.response=="string"))return Uint8Array.from(e.response,n=>n.charCodeAt(0))}resolve(t,e){if(t.namespace!=="preview")return;let n=this.resolvePath(t);if(this.cache.has(n))return this.cache.get(n)();let i=this.pullPackageData(t);if(!i)return;let o=`/@memory/fetch/packages/${t.namespace}/${t.name}/${t.version}`,s=[];e.untar(i,(d,l,f)=>{s.push([o+"/"+d,l,new Date(f)])});let _=()=>{for(let[d,l,f]of s)this.am.insertFile(d,l,f);return o};return this.cache.set(n,_),_()}};St();It();Kt();function $r(r){return Math.random().toString(36).replace("0.",r||"")}St();var li=typeof process<"u"&&process.versions!=null&&process.versions.node!=null,Bt=class r{mainFilePath;cc;fr;ex;constructor(t){this.cc=t?.compiler||r.buildLocalCompiler,this.fr=t?.fontResolver||r.buildLocalFontResolver,this.ex=t?.renderer||r.buildLocalRenderer,this.mainFilePath="/main.typ",this.providers=[]}setCompiler(t){this.cc=t}async getFontResolver(){return typeof this.fr=="function"?this.fr=await this.fr():this.fr}async getCompiler(){return typeof this.cc=="function"?this.cc=await this.cc():this.cc}async getCompilerReset(){let t=await this.getCompiler();return await t.reset(),t}setRenderer(t){this.ex=t}async getRenderer(){return typeof this.ex=="function"?this.ex=await this.ex():this.ex}providers;use(...t){if(!this.providers)throw new Error("already prepare uses for instances");this.providers.push(...t)}static preloadFontFromUrl(t){return r.preloadFonts([t])}static preloadFontData(t){return r.preloadFonts([t])}static preloadFonts(t){return{key:"access-model",forRoles:["compiler"],provides:[X(t)]}}static disableDefaultFontAssets(){return{key:"access-model",forRoles:["compiler"],provides:[Ye()]}}static preloadFontAssets(t){return{key:"access-model",forRoles:["compiler"],provides:[Qe(t)]}}static withAccessModel(t){return{key:"access-model",forRoles:["compiler"],provides:[ye(t)]}}static withPackageRegistry(t){return{key:"package-registry",forRoles:["compiler"],provides:[Jt(t)]}}static fetchPackageRegistry(t){let e=t||new Z,n=[...t?[]:[ye(e)],Jt(new wt(e))];return{key:"package-registry$fetch",forRoles:["compiler"],provides:n}}static fetchPackageBy(t,e){class n extends wt{pullPackageData(o){return e(o,this.resolvePath(o))}}return{key:"package-registry$lambda",forRoles:["compiler"],provides:[Jt(new n(t))]}}ccOptions;setCompilerInitOptions(t){this.requireIsUninitialized("compiler",this.cc),this.ccOptions=t}exOptions;setRendererInitOptions(t){this.requireIsUninitialized("renderer",this.ex),this.exOptions=t}setMainFilePath(t){this.mainFilePath=t}getMainFilePath(){return this.mainFilePath}removeTmp(t){return t.mainFilePath.startsWith("/tmp/")?this.unmapShadow(t.mainFilePath):Promise.resolve()}async setFonts(t){let e=await this.getFontResolver();for(let i of t)await e.addLazyFont(i,"blob"in i?i.blob:Se(i),i);let n=await this.getCompiler();await e.build(async i=>n.setFonts(i))}async addSource(t,e){(await this.getCompiler()).addSource(t,e)}async resetShadow(){(await this.getCompiler()).resetShadow()}async mapShadow(t,e){(await this.getCompiler()).mapShadow(t,e)}async unmapShadow(t){(await this.getCompiler()).unmapShadow(t)}async vector(t){let e=await this.getCompileOptions(t);return(await this.getCompilerReset()).compile(e).then(i=>i.result).finally(()=>this.removeTmp(e))}async pdf(t){let e=await this.getCompileOptions(t);return e.format=xt.pdf,(await this.getCompilerReset()).compile(e).then(i=>i.result).finally(()=>this.removeTmp(e))}async svg(t){return this.transientRender(t,(e,n)=>e.renderSvg({...t,renderSession:n}))}async canvas(t,e){return this.transientRender(e,(n,i)=>n.renderToCanvas({container:t,...e,renderSession:i}))}async query(t){let e=await this.getCompileOptions(t);return(await this.getCompilerReset()).query({...t,...e}).finally(()=>this.removeTmp(e))}async getSemanticTokenLegend(){return(await this.getCompilerReset()).getSemanticTokenLegend()}async getSemanticTokens(t){let e=await this.getCompileOptions(t);return(await this.getCompilerReset()).getSemanticTokens({mainFilePath:e.mainFilePath,resultId:t.resultId}).finally(()=>this.removeTmp(e))}async getCompileOptions(t){if(t===void 0)return{mainFilePath:this.mainFilePath,diagnostics:"none"};if(typeof t=="string")throw new Error("please specify opts as {mainContent: \'...\'} or {mainFilePath: \'...\'}");if("mainFilePath"in t)return{...t,diagnostics:"none"};{let e=`/tmp/${$r()}.typ`;return await this.addSource(e,t.mainContent),{mainFilePath:e,inputs:t.inputs,diagnostics:"none"}}}async getVector(t){if(t&&"vectorData"in t)return t.vectorData;let e=await this.getCompileOptions(t);return(await this.getCompiler()).compile(e).then(n=>n.result).finally(()=>this.removeTmp(e))}async transientRender(t,e){let n=await this.getRenderer();if(!n)throw new Error("does not provide renderer instance");let i=await this.getVector(t);return await n.runWithSession(async o=>(n.manipulateData({renderSession:o,action:"reset",data:i}),e(n,o)))}prepareUseOnce=void 0;async prepareUse(){return this.prepareUseOnce?this.prepareUseOnce:this.prepareUseOnce=this.doPrepareUse()}async doPrepareUse(){if(!this.providers)return;let t=await Promise.all(this.providers.map(_=>typeof _=="function"?_():_));if(this.providers=[],be==this&&!t.some(_=>_.key.includes("package-registry")||_.key.includes("access-model")))if(li){let _=new Function("m","return import(m)");try{let d=new Z,{default:l}=await _("sync-request");be.use(r.withAccessModel(d),r.fetchPackageBy(d,(f,v)=>{let S=l("GET",v);if(S.statusCode===200)return S.getBody(void 0)}))}catch{}}else be.use(r.fetchPackageRegistry());let e=await Promise.all(this.providers.map(_=>typeof _=="function"?_():_)),n=this.ccOptions||={},i=n.beforeBuild||=[],o=this.exOptions||={},s=o.beforeBuild||=[];for(let _ of[...t,...e])_.forRoles.includes("compiler")&&(this.requireIsUninitialized("compiler",this.cc),i.push(..._.provides)),_.forRoles.includes("renderer")&&(this.requireIsUninitialized("renderer",this.ex),s.push(..._.provides));this.providers=void 0}requireIsUninitialized(t,e,n){if(e&&typeof e!="function")throw new Error(`${t} has been initialized: ${e}`)}static async buildLocalCompiler(){let{createTypstCompiler:t}=await Promise.resolve().then(()=>(St(),pe));await this.prepareUse();let e=t();return await e.init(this.ccOptions),e}static async buildLocalFontResolver(){let{createTypstFontBuilder:t}=await Promise.resolve().then(()=>(St(),pe));await this.prepareUse();let e=t();return await e.init(this.ccOptions),e}static async buildGlobalCompiler(){let{createGlobalCompiler:t}=await Promise.resolve().then(()=>(Jr(),Vr)),{createTypstCompiler:e}=await Promise.resolve().then(()=>(St(),pe));return await this.prepareUse(),t(e,this.ccOptions)}static async buildLocalRenderer(){let{createTypstRenderer:t}=await Promise.resolve().then(()=>(_e(),Ae));await this.prepareUse();let e=t();return await e.init(this.exOptions),e}static async buildGlobalRenderer(){let{createGlobalRenderer:t}=await Promise.resolve().then(()=>(Qr(),Yr)),{createTypstRenderer:e}=await Promise.resolve().then(()=>(_e(),Ae));return await this.prepareUse(),t(e,this.exOptions)}},be=new Bt({compiler:Bt.buildGlobalCompiler,renderer:Bt.buildGlobalRenderer});ie();var qe=class{#t=null;#e=null;#n=null;#r=new Map;#i(){if(!this.#t)throw new Error("Renderer not initialized");return this.#t}#o(){if(!this.#e)throw new Error("Renderer not initialized");return this.#e}async init(t){this.#t=ae(),await this.#t.init({getModule:()=>t,getWrapper:()=>Promise.resolve(Mt)});let{session:e,close:n}=await wi(this.#t);this.#e=e,this.#n=n}async renderSvg(t){let e=this.#o();e.manipulateData({action:"reset",data:t});let n=await this.#i().renderSvg({renderSession:e});return this.#s(n)}#s(t){return t.replaceAll(/(xlink:href|href)="(data:image\\/[^;,]+;base64,[^"]+)"/g,(e,n,i)=>{let o=this.#r.get(i);return o||(o=URL.createObjectURL(gi(i)),this.#r.set(i,o)),`${n}="${o}"`})}destroy(){for(let t of this.#r.values())URL.revokeObjectURL(t);this.#r.clear(),this.#n?.(),this.#n=null,this.#e=null,this.#t=null}};function gi(r){let t=r.indexOf(","),e=r.slice(0,t),n=r.slice(t+1),i=/data:([^;]+)/.exec(e)?.[1]??"application/octet-stream",o=atob(n),s=new Uint8Array(o.length);for(let _=0;_<o.length;_++)s[_]=o.codePointAt(_);return new Blob([s],{type:i})}async function wi(r){let t,e=new Promise(i=>{t=i}),n;return await new Promise((i,o)=>{r.runWithSession(async s=>{n=s,i(),await e}).catch(o)}),{session:n,close:t}}Vt(new qe);})();\n/*! Bundled license information:\n\ncomlink/dist/esm/comlink.mjs:\n (**\n * @license\n * Copyright 2019 Google LLC\n * SPDX-License-Identifier: Apache-2.0\n *)\n*/\n');
|
|
19
|
+
function utf8Len(codePoint) {
|
|
20
|
+
if (codePoint < 128) return 1;
|
|
21
|
+
if (codePoint < 2048) return 2;
|
|
22
|
+
if (codePoint < 65536) return 3;
|
|
23
|
+
return 4;
|
|
24
|
+
}
|
|
25
|
+
function mapOffsets(text, offsets, keyStep, valStep) {
|
|
26
|
+
if (offsets.length === 0 || !hasNonAscii(text)) return offsets;
|
|
27
|
+
const order = offsets.map((offset, i) => [offset, i]);
|
|
28
|
+
order.sort((a, b) => a[0] - b[0]);
|
|
29
|
+
const out = new Array(offsets.length);
|
|
30
|
+
let key = 0;
|
|
31
|
+
let val = 0;
|
|
32
|
+
let next = 0;
|
|
33
|
+
const flush = () => {
|
|
34
|
+
while (next < order.length && order[next][0] <= key)
|
|
35
|
+
out[order[next++][1]] = val;
|
|
36
|
+
};
|
|
37
|
+
flush();
|
|
38
|
+
for (const ch of text) {
|
|
39
|
+
if (next >= order.length) break;
|
|
40
|
+
const cp = ch.codePointAt(0);
|
|
41
|
+
key += keyStep(cp, ch);
|
|
42
|
+
val += valStep(cp, ch);
|
|
43
|
+
flush();
|
|
44
|
+
}
|
|
45
|
+
while (next < order.length) out[order[next++][1]] = val;
|
|
46
|
+
return out;
|
|
47
|
+
}
|
|
48
|
+
function byteOffsetsToCm(text, offsets) {
|
|
49
|
+
return mapOffsets(
|
|
50
|
+
text,
|
|
51
|
+
offsets,
|
|
52
|
+
(cp) => utf8Len(cp),
|
|
53
|
+
(_cp, ch) => ch.length
|
|
54
|
+
);
|
|
55
|
+
}
|
|
56
|
+
function cmOffsetsToByte(text, offsets) {
|
|
57
|
+
return mapOffsets(
|
|
58
|
+
text,
|
|
59
|
+
offsets,
|
|
60
|
+
(_cp, ch) => ch.length,
|
|
61
|
+
(cp) => utf8Len(cp)
|
|
62
|
+
);
|
|
24
63
|
}
|
|
25
|
-
|
|
26
|
-
// src/analyzer.ts
|
|
27
|
-
var TypstAnalyzer = class _TypstAnalyzer {
|
|
28
|
-
proxy;
|
|
29
|
-
worker;
|
|
30
|
-
versionCounter = 0;
|
|
31
|
-
/**
|
|
32
|
-
* Last content pushed to the worker per URI. Presence is the source of
|
|
33
|
-
* truth for "is this URI opened on the worker?"; value drives own-RPC dedup.
|
|
34
|
-
*/
|
|
35
|
-
content = /* @__PURE__ */ new Map();
|
|
36
|
-
constructor(worker, proxy) {
|
|
37
|
-
this.worker = worker;
|
|
38
|
-
this.proxy = proxy;
|
|
39
|
-
}
|
|
40
|
-
static async create(options) {
|
|
41
|
-
const worker = options.worker ?? createAnalyzerWorker();
|
|
42
|
-
const proxy = Comlink.wrap(worker);
|
|
43
|
-
const absoluteWasmUrl = new URL(options.wasmUrl, globalThis.location?.href).href;
|
|
44
|
-
const analyzer = new _TypstAnalyzer(worker, proxy);
|
|
45
|
-
await proxy.init(absoluteWasmUrl);
|
|
46
|
-
return analyzer;
|
|
47
|
-
}
|
|
48
|
-
async didOpen(uri, content) {
|
|
49
|
-
await this.proxy.didOpen(uri, content);
|
|
50
|
-
this.content.set(uri, content);
|
|
51
|
-
}
|
|
52
|
-
async didClose(uri) {
|
|
53
|
-
if (!this.content.has(uri)) return;
|
|
54
|
-
await this.proxy.didClose(uri);
|
|
55
|
-
this.content.delete(uri);
|
|
56
|
-
}
|
|
57
|
-
/**
|
|
58
|
-
* Notify the analyzer that a document has changed. Skips the RPC when the
|
|
59
|
-
* content matches what the worker last saw.
|
|
60
|
-
*/
|
|
61
|
-
async didChange(uri, content) {
|
|
62
|
-
if (!this.content.has(uri)) {
|
|
63
|
-
await this.didOpen(uri, content);
|
|
64
|
-
return;
|
|
65
|
-
}
|
|
66
|
-
if (this.content.get(uri) === content) return;
|
|
67
|
-
const version = ++this.versionCounter;
|
|
68
|
-
await this.proxy.didChange(uri, version, content);
|
|
69
|
-
this.content.set(uri, content);
|
|
70
|
-
}
|
|
71
|
-
/**
|
|
72
|
-
* Batch document changes. Splits inputs into opens (first-time URIs) and
|
|
73
|
-
* changes (already-open URIs) and sends them in a single worker roundtrip.
|
|
74
|
-
* Skips unchanged documents; returns without an RPC if nothing is pending.
|
|
75
|
-
*/
|
|
76
|
-
async didChangeMany(docs) {
|
|
77
|
-
const opens = [];
|
|
78
|
-
const changes = [];
|
|
79
|
-
const updates = [];
|
|
80
|
-
for (const [uri, content] of Object.entries(docs)) {
|
|
81
|
-
if (!this.content.has(uri)) {
|
|
82
|
-
opens.push({ uri, content });
|
|
83
|
-
updates.push([uri, content]);
|
|
84
|
-
} else if (this.content.get(uri) !== content) {
|
|
85
|
-
changes.push({ uri, version: ++this.versionCounter, content });
|
|
86
|
-
updates.push([uri, content]);
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
if (opens.length === 0 && changes.length === 0) return;
|
|
90
|
-
await this.proxy.didChangeMany(opens, changes);
|
|
91
|
-
for (const [uri, content] of updates) this.content.set(uri, content);
|
|
92
|
-
}
|
|
93
|
-
/**
|
|
94
|
-
* Batch document closes. Filters to currently-open URIs and sends the set
|
|
95
|
-
* in a single worker roundtrip.
|
|
96
|
-
*/
|
|
97
|
-
async didCloseMany(uris) {
|
|
98
|
-
const toClose = [];
|
|
99
|
-
for (const uri of uris) {
|
|
100
|
-
if (this.content.has(uri)) toClose.push(uri);
|
|
101
|
-
}
|
|
102
|
-
if (toClose.length === 0) return;
|
|
103
|
-
await this.proxy.didCloseMany(toClose);
|
|
104
|
-
for (const uri of toClose) this.content.delete(uri);
|
|
105
|
-
}
|
|
106
|
-
/**
|
|
107
|
-
* Request completion at `position` for `uri`, with `content` as the current
|
|
108
|
-
* document state. Bundles the didChange notification with the request in one
|
|
109
|
-
* worker roundtrip; degrades to a plain completion request when the worker
|
|
110
|
-
* already has this exact content.
|
|
111
|
-
*/
|
|
112
|
-
async completion(uri, content, position) {
|
|
113
|
-
if (this.content.get(uri) === content) {
|
|
114
|
-
return this.proxy.completion(uri, position);
|
|
115
|
-
}
|
|
116
|
-
const isOpen = this.content.has(uri);
|
|
117
|
-
const version = ++this.versionCounter;
|
|
118
|
-
const result = await this.proxy.completionWithDoc(
|
|
119
|
-
uri,
|
|
120
|
-
version,
|
|
121
|
-
content,
|
|
122
|
-
position,
|
|
123
|
-
isOpen ? "change" : "open"
|
|
124
|
-
);
|
|
125
|
-
this.content.set(uri, content);
|
|
126
|
-
return result;
|
|
127
|
-
}
|
|
128
|
-
/**
|
|
129
|
-
* Request hover at `position` for `uri`, with `content` as the current
|
|
130
|
-
* document state. Bundles the didChange notification with the request in one
|
|
131
|
-
* worker roundtrip; degrades to a plain hover request when the worker
|
|
132
|
-
* already has this exact content.
|
|
133
|
-
*/
|
|
134
|
-
async hover(uri, content, position) {
|
|
135
|
-
if (this.content.get(uri) === content) {
|
|
136
|
-
return this.proxy.hover(uri, position);
|
|
137
|
-
}
|
|
138
|
-
const isOpen = this.content.has(uri);
|
|
139
|
-
const version = ++this.versionCounter;
|
|
140
|
-
const result = await this.proxy.hoverWithDoc(
|
|
141
|
-
uri,
|
|
142
|
-
version,
|
|
143
|
-
content,
|
|
144
|
-
position,
|
|
145
|
-
isOpen ? "change" : "open"
|
|
146
|
-
);
|
|
147
|
-
this.content.set(uri, content);
|
|
148
|
-
return result;
|
|
149
|
-
}
|
|
150
|
-
destroy() {
|
|
151
|
-
this.proxy[Comlink.releaseProxy]();
|
|
152
|
-
this.worker.terminate();
|
|
153
|
-
}
|
|
154
|
-
};
|
|
155
64
|
|
|
156
65
|
// src/identifiers.ts
|
|
157
66
|
function normalizePath(path) {
|
|
158
67
|
return path.startsWith("/") ? path : `/${path}`;
|
|
159
68
|
}
|
|
160
|
-
function normalizeRoot(rootPath) {
|
|
161
|
-
const root = normalizePath(rootPath);
|
|
162
|
-
return root === "/" ? "" : root.replace(/\/+$/, "");
|
|
163
|
-
}
|
|
164
|
-
function pathToAnalyzerUri(path, root) {
|
|
165
|
-
const bare = root.replace(/^\//, "");
|
|
166
|
-
return `untitled:${bare}${normalizePath(path)}`;
|
|
167
|
-
}
|
|
168
69
|
|
|
169
|
-
// src/
|
|
170
|
-
import * as
|
|
171
|
-
var DEFAULT_FONTS = [
|
|
172
|
-
"https://cdn.jsdelivr.net/npm/roboto-font@0.1.0/fonts/Roboto/roboto-regular-webfont.ttf"
|
|
173
|
-
];
|
|
174
|
-
var defaultWasmUrl = () => `https://cdn.jsdelivr.net/npm/@myriaddreamin/typst-ts-web-compiler@${"0.7.0-rc2"}/pkg/typst_ts_web_compiler_bg.wasm`;
|
|
175
|
-
var TypstCompiler = class _TypstCompiler {
|
|
176
|
-
proxy;
|
|
177
|
-
worker;
|
|
178
|
-
encoder = new TextEncoder();
|
|
179
|
-
/** Last text content pushed per path. Drives own-RPC dedup. Invalidated by binary writes. */
|
|
180
|
-
content = /* @__PURE__ */ new Map();
|
|
181
|
-
constructor(worker, proxy) {
|
|
182
|
-
this.worker = worker;
|
|
183
|
-
this.proxy = proxy;
|
|
184
|
-
}
|
|
185
|
-
static async create(options = {}) {
|
|
186
|
-
const worker = options.worker ?? createWorker();
|
|
187
|
-
const proxy = Comlink2.wrap(worker);
|
|
188
|
-
await proxy.init(
|
|
189
|
-
options.wasmUrl ?? defaultWasmUrl(),
|
|
190
|
-
options.fonts ?? DEFAULT_FONTS,
|
|
191
|
-
options.packages ?? true
|
|
192
|
-
);
|
|
193
|
-
return new _TypstCompiler(worker, proxy);
|
|
194
|
-
}
|
|
195
|
-
/**
|
|
196
|
-
* Compile whatever is currently in the VFS (populated via
|
|
197
|
-
* setText/setBinary/setJson/setMany). Defaults to compiling "/main.typ";
|
|
198
|
-
* override with `entry`.
|
|
199
|
-
*/
|
|
200
|
-
compile(entry) {
|
|
201
|
-
return this.proxy.compile(entry);
|
|
202
|
-
}
|
|
203
|
-
/**
|
|
204
|
-
* Compile to PDF. Operates on whatever is currently in the VFS (populated
|
|
205
|
-
* via setText/setBinary/setJson/setMany). Defaults to compiling "/main.typ";
|
|
206
|
-
* override with `entry`.
|
|
207
|
-
*/
|
|
208
|
-
compilePdf(entry) {
|
|
209
|
-
return this.proxy.compilePdf(entry);
|
|
210
|
-
}
|
|
211
|
-
/**
|
|
212
|
-
* Add or overwrite a text file in the virtual compiler filesystem. Skips
|
|
213
|
-
* the worker RPC when `source` matches the last value pushed for `path`.
|
|
214
|
-
*/
|
|
215
|
-
async setText(path, source) {
|
|
216
|
-
if (this.content.get(path) === source) return;
|
|
217
|
-
await this.proxy.mapShadow(path, this.encoder.encode(source));
|
|
218
|
-
this.content.set(path, source);
|
|
219
|
-
}
|
|
220
|
-
/** Add or overwrite a JSON file in the virtual compiler filesystem. */
|
|
221
|
-
setJson(path, value, replacer, space) {
|
|
222
|
-
return this.setText(path, JSON.stringify(value, replacer, space));
|
|
223
|
-
}
|
|
224
|
-
/**
|
|
225
|
-
* Add or overwrite multiple files in the virtual compiler filesystem in a
|
|
226
|
-
* single worker roundtrip. Strings are UTF-8 encoded; Uint8Arrays are
|
|
227
|
-
* passed through. Text entries unchanged since their last push are skipped;
|
|
228
|
-
* binary entries always push and invalidate the text cache for their path.
|
|
229
|
-
*/
|
|
230
|
-
async setMany(files) {
|
|
231
|
-
const encoded = {};
|
|
232
|
-
const textUpdates = [];
|
|
233
|
-
const binaryInvalidations = [];
|
|
234
|
-
for (const [path, content] of Object.entries(files)) {
|
|
235
|
-
if (typeof content === "string") {
|
|
236
|
-
if (this.content.get(path) === content) continue;
|
|
237
|
-
textUpdates.push([path, content]);
|
|
238
|
-
encoded[path] = this.encoder.encode(content);
|
|
239
|
-
} else {
|
|
240
|
-
binaryInvalidations.push(path);
|
|
241
|
-
encoded[path] = content;
|
|
242
|
-
}
|
|
243
|
-
}
|
|
244
|
-
if (Object.keys(encoded).length === 0) return;
|
|
245
|
-
await this.proxy.mapShadowMany(encoded);
|
|
246
|
-
for (const [path, content] of textUpdates) this.content.set(path, content);
|
|
247
|
-
for (const path of binaryInvalidations) this.content.delete(path);
|
|
248
|
-
}
|
|
249
|
-
/** Add or overwrite a binary file in the virtual compiler filesystem. */
|
|
250
|
-
async setBinary(path, content) {
|
|
251
|
-
const bytes = content instanceof ArrayBuffer ? new Uint8Array(content) : new Uint8Array(
|
|
252
|
-
content.buffer,
|
|
253
|
-
content.byteOffset,
|
|
254
|
-
content.byteLength
|
|
255
|
-
);
|
|
256
|
-
await this.proxy.mapShadow(path, bytes);
|
|
257
|
-
this.content.delete(path);
|
|
258
|
-
}
|
|
259
|
-
/** Remove a file from the virtual compiler filesystem. */
|
|
260
|
-
async remove(path) {
|
|
261
|
-
await this.proxy.unmapShadow(path);
|
|
262
|
-
this.content.delete(path);
|
|
263
|
-
}
|
|
264
|
-
/** Clear all virtual files from the compiler filesystem. */
|
|
265
|
-
async clear() {
|
|
266
|
-
await this.proxy.resetShadow();
|
|
267
|
-
this.content.clear();
|
|
268
|
-
}
|
|
269
|
-
destroy() {
|
|
270
|
-
this.proxy[Comlink2.releaseProxy]();
|
|
271
|
-
this.worker.terminate();
|
|
272
|
-
}
|
|
273
|
-
};
|
|
274
|
-
|
|
275
|
-
// src/formatter.ts
|
|
276
|
-
var typstylePromise = null;
|
|
277
|
-
function getTypstyle() {
|
|
278
|
-
if (!typstylePromise) {
|
|
279
|
-
typstylePromise = import("@typstyle/typstyle-wasm-bundler").catch((err) => {
|
|
280
|
-
typstylePromise = null;
|
|
281
|
-
throw err;
|
|
282
|
-
});
|
|
283
|
-
}
|
|
284
|
-
return typstylePromise;
|
|
285
|
-
}
|
|
286
|
-
var TypstFormatter = class _TypstFormatter {
|
|
287
|
-
config;
|
|
288
|
-
constructor(config = {}) {
|
|
289
|
-
this.config = config;
|
|
290
|
-
getTypstyle().catch(() => {
|
|
291
|
-
});
|
|
292
|
-
}
|
|
293
|
-
static create(config = {}) {
|
|
294
|
-
return new _TypstFormatter(config);
|
|
295
|
-
}
|
|
296
|
-
/** Format an entire Typst source string. */
|
|
297
|
-
async format(source) {
|
|
298
|
-
const typstyle = await getTypstyle();
|
|
299
|
-
return typstyle.format(source, this.config);
|
|
300
|
-
}
|
|
301
|
-
/** Format a range within a Typst source string. Indices are UTF-16 code units. */
|
|
302
|
-
async formatRange(source, start, end) {
|
|
303
|
-
const typstyle = await getTypstyle();
|
|
304
|
-
const result = typstyle.format_range(source, start, end, this.config);
|
|
305
|
-
return { start: result.start, end: result.end, text: result.text };
|
|
306
|
-
}
|
|
307
|
-
};
|
|
70
|
+
// src/project.ts
|
|
71
|
+
import * as Comlink from "comlink";
|
|
308
72
|
|
|
309
73
|
// src/compile-scheduler.ts
|
|
310
74
|
var CompileScheduler = class {
|
|
@@ -352,70 +116,137 @@ var CompileScheduler = class {
|
|
|
352
116
|
}
|
|
353
117
|
};
|
|
354
118
|
|
|
119
|
+
// src/packages.ts
|
|
120
|
+
import { gunzipSync } from "fflate";
|
|
121
|
+
import { parseTar } from "nanotar";
|
|
122
|
+
var REGISTRY = "https://packages.typst.org/preview";
|
|
123
|
+
var PREVIEW_IMPORT = /@preview\/([a-zA-Z0-9_-]+):(\d+\.\d+\.\d+)/g;
|
|
124
|
+
function createPackageLoader(setFile) {
|
|
125
|
+
const loaded = /* @__PURE__ */ new Set();
|
|
126
|
+
const inflight = /* @__PURE__ */ new Map();
|
|
127
|
+
async function fetchPackage(name, version) {
|
|
128
|
+
const spec = `@preview/${name}:${version}`;
|
|
129
|
+
const res = await fetch(`${REGISTRY}/${name}-${version}.tar.gz`);
|
|
130
|
+
if (!res.ok) {
|
|
131
|
+
throw new Error(
|
|
132
|
+
`failed to fetch ${spec}: ${res.status} ${res.statusText}`
|
|
133
|
+
);
|
|
134
|
+
}
|
|
135
|
+
const tar = gunzipSync(new Uint8Array(await res.arrayBuffer()));
|
|
136
|
+
for (const entry of parseTar(tar)) {
|
|
137
|
+
if (!entry.data || entry.name.endsWith("/")) continue;
|
|
138
|
+
await setFile(`${spec}/${entry.name}`, entry.data);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
return {
|
|
142
|
+
async ensure(sources) {
|
|
143
|
+
const specs = /* @__PURE__ */ new Set();
|
|
144
|
+
for (const text of sources) {
|
|
145
|
+
for (const m of text.matchAll(PREVIEW_IMPORT)) {
|
|
146
|
+
specs.add(`${m[1]}:${m[2]}`);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
const tasks = [];
|
|
150
|
+
for (const spec of specs) {
|
|
151
|
+
if (loaded.has(spec)) continue;
|
|
152
|
+
let task = inflight.get(spec);
|
|
153
|
+
if (!task) {
|
|
154
|
+
const [name, version] = spec.split(":");
|
|
155
|
+
task = fetchPackage(name, version).then(() => {
|
|
156
|
+
loaded.add(spec);
|
|
157
|
+
}).finally(() => {
|
|
158
|
+
inflight.delete(spec);
|
|
159
|
+
});
|
|
160
|
+
inflight.set(spec, task);
|
|
161
|
+
}
|
|
162
|
+
tasks.push(task);
|
|
163
|
+
}
|
|
164
|
+
await Promise.all(tasks);
|
|
165
|
+
}
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
|
|
355
169
|
// src/project.ts
|
|
356
170
|
var DEFAULT_ENTRY = "/main.typ";
|
|
357
|
-
var
|
|
358
|
-
function errorAsCompileResult(err
|
|
171
|
+
var encoder2 = new TextEncoder();
|
|
172
|
+
function errorAsCompileResult(err) {
|
|
359
173
|
const message = err instanceof Error ? err.message : String(err);
|
|
360
174
|
return {
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
range: { startLine: 0, startCol: 0, endLine: 0, endCol: 1 },
|
|
366
|
-
message
|
|
367
|
-
}))
|
|
175
|
+
pages: [],
|
|
176
|
+
diagnostics: [
|
|
177
|
+
{ severity: "error", message, hints: [], location: void 0 }
|
|
178
|
+
]
|
|
368
179
|
};
|
|
369
180
|
}
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
181
|
+
function toBytes(content) {
|
|
182
|
+
if (content instanceof Uint8Array) return content;
|
|
183
|
+
if (ArrayBuffer.isView(content)) {
|
|
184
|
+
return new Uint8Array(
|
|
185
|
+
content.buffer,
|
|
186
|
+
content.byteOffset,
|
|
187
|
+
content.byteLength
|
|
188
|
+
);
|
|
189
|
+
}
|
|
190
|
+
return new Uint8Array(content);
|
|
191
|
+
}
|
|
192
|
+
var TypstProject = class _TypstProject {
|
|
193
|
+
constructor(engine, worker, options) {
|
|
194
|
+
this.engine = engine;
|
|
195
|
+
this.worker = worker;
|
|
196
|
+
this._entry = normalizePath(options.entry ?? DEFAULT_ENTRY);
|
|
197
|
+
this.scheduler = new CompileScheduler({
|
|
198
|
+
debounceMs: options.autoCompile?.debounceMs,
|
|
199
|
+
maxWaitMs: options.autoCompile?.maxWaitMs
|
|
200
|
+
});
|
|
201
|
+
this.packageLoader = createPackageLoader(
|
|
202
|
+
(path, bytes) => this.engine.setFile(path, bytes)
|
|
203
|
+
);
|
|
204
|
+
}
|
|
374
205
|
/**
|
|
375
|
-
* Tracked
|
|
376
|
-
*
|
|
377
|
-
*
|
|
378
|
-
* analyzer.
|
|
206
|
+
* Tracked project files: the text content for a text file, or `null` for a
|
|
207
|
+
* binary one. Drives dedup, `getText`, `files`, and `clear`. (Cached `@preview`
|
|
208
|
+
* package files live only in the worker VFS, never here.)
|
|
379
209
|
*/
|
|
380
|
-
|
|
210
|
+
tracked = /* @__PURE__ */ new Map();
|
|
381
211
|
compileListeners = /* @__PURE__ */ new Set();
|
|
382
212
|
scheduler;
|
|
213
|
+
packageLoader;
|
|
383
214
|
compileVersion = 0;
|
|
384
215
|
_lastResult;
|
|
385
216
|
_entry;
|
|
386
217
|
destroyed = false;
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
console.error("[typst] compile listener threw:", err);
|
|
392
|
-
}
|
|
393
|
-
}
|
|
394
|
-
constructor(options) {
|
|
395
|
-
this.compiler = options.compiler;
|
|
396
|
-
this.analyzer = options.analyzer;
|
|
397
|
-
this.analyzerUriRoot = normalizeRoot(
|
|
398
|
-
options.analyzerUriRoot ?? DEFAULT_ROOT
|
|
399
|
-
);
|
|
400
|
-
this._entry = normalizePath(options.entry ?? DEFAULT_ENTRY);
|
|
401
|
-
this.scheduler = new CompileScheduler({
|
|
402
|
-
debounceMs: options.autoCompile?.debounceMs,
|
|
403
|
-
maxWaitMs: options.autoCompile?.maxWaitMs
|
|
218
|
+
/** Create a project: spin up the worker, init the wasm, set the entry. */
|
|
219
|
+
static async create(options = {}) {
|
|
220
|
+
const worker = new Worker(new URL("./typsten-worker.js", import.meta.url), {
|
|
221
|
+
type: "module"
|
|
404
222
|
});
|
|
223
|
+
const engine = Comlink.wrap(worker);
|
|
224
|
+
const wasmUrl = new URL("./typsten_bg.wasm", import.meta.url).href;
|
|
225
|
+
await engine.init(wasmUrl);
|
|
226
|
+
const project = new _TypstProject(engine, worker, options);
|
|
227
|
+
await engine.setEntry(project._entry);
|
|
228
|
+
return project;
|
|
405
229
|
}
|
|
406
|
-
/**
|
|
407
|
-
* Schedule an auto-compile after VFS mutations. Coalesces rapid calls via
|
|
408
|
-
* the configured debounce/throttle. Errors surface through `onCompile`
|
|
409
|
-
* listeners via a synthetic diagnostic; callers awaiting a specific compile
|
|
410
|
-
* should call `compile()` directly.
|
|
411
|
-
*/
|
|
412
230
|
scheduleCompile() {
|
|
413
231
|
if (this.destroyed) return;
|
|
414
232
|
this.scheduler.schedule(() => {
|
|
415
233
|
this.compile().catch((err) => console.error("[typst]", err));
|
|
416
234
|
});
|
|
417
235
|
}
|
|
418
|
-
/**
|
|
236
|
+
/**
|
|
237
|
+
* Mirror text into the VFS without scheduling a compile. Returns the in-flight
|
|
238
|
+
* write to await, or `null` if the content is unchanged (deduped to a no-op).
|
|
239
|
+
*/
|
|
240
|
+
writeText(p, content) {
|
|
241
|
+
if (this.tracked.get(p) === content) return null;
|
|
242
|
+
this.tracked.set(p, content);
|
|
243
|
+
return this.engine.setFile(p, encoder2.encode(content));
|
|
244
|
+
}
|
|
245
|
+
/** Mirror binary bytes into the VFS (always writes; binaries are not deduped). */
|
|
246
|
+
writeBinary(p, bytes) {
|
|
247
|
+
this.tracked.set(p, null);
|
|
248
|
+
return this.engine.setFile(p, bytes);
|
|
249
|
+
}
|
|
419
250
|
get entry() {
|
|
420
251
|
return this._entry;
|
|
421
252
|
}
|
|
@@ -423,376 +254,208 @@ var TypstProject = class {
|
|
|
423
254
|
const next = normalizePath(path);
|
|
424
255
|
if (next === this._entry) return;
|
|
425
256
|
this._entry = next;
|
|
257
|
+
void this.engine.setEntry(next);
|
|
426
258
|
this.scheduleCompile();
|
|
427
259
|
}
|
|
428
|
-
/**
|
|
429
|
-
get hasAnalyzer() {
|
|
430
|
-
return this.analyzer !== void 0;
|
|
431
|
-
}
|
|
432
|
-
/**
|
|
433
|
-
* Most recent compile result, or `undefined` before the first compile has
|
|
434
|
-
* settled. Useful for lazy-mounted UI that subscribes after boot and needs
|
|
435
|
-
* an initial value.
|
|
436
|
-
*/
|
|
260
|
+
/** Most recent compile result, or `undefined` before the first compile. */
|
|
437
261
|
get lastResult() {
|
|
438
262
|
return this._lastResult;
|
|
439
263
|
}
|
|
440
|
-
/**
|
|
441
|
-
* Snapshot of tracked text file paths, in insertion order. Updated by
|
|
442
|
-
* `setText`, `setMany`, `remove`, and `clear`. Returns a fresh array — mutate
|
|
443
|
-
* freely without affecting project state.
|
|
444
|
-
*/
|
|
264
|
+
/** Tracked text file paths, in insertion order (fresh array). */
|
|
445
265
|
get files() {
|
|
446
|
-
return [...this.
|
|
266
|
+
return [...this.tracked].filter(([, content]) => content !== null).map(([path]) => path);
|
|
447
267
|
}
|
|
448
|
-
/**
|
|
449
|
-
* Current text content for a tracked file, or `undefined` if the path was
|
|
450
|
-
* never written via `setText`/`setMany` (or was removed). Read-through to the
|
|
451
|
-
* project's sync cache — lets consumers avoid shadowing the VFS themselves.
|
|
452
|
-
*/
|
|
268
|
+
/** Current text for a tracked file, or `undefined` (binary or absent). */
|
|
453
269
|
getText(path) {
|
|
454
|
-
return this.
|
|
270
|
+
return this.tracked.get(normalizePath(path)) ?? void 0;
|
|
455
271
|
}
|
|
456
|
-
/**
|
|
457
|
-
* Add or overwrite a text file. Goes to the compiler's VFS and, when an
|
|
458
|
-
* analyzer is attached, to the analyzer as a document change. No-op when
|
|
459
|
-
* the tracked path already has this exact content — skips both worker RPCs
|
|
460
|
-
* and the auto-scheduled compile.
|
|
461
|
-
*/
|
|
272
|
+
/** Add or overwrite a text file. No-op if unchanged. */
|
|
462
273
|
async setText(path, content) {
|
|
463
|
-
const
|
|
464
|
-
if (
|
|
465
|
-
|
|
466
|
-
this.
|
|
467
|
-
|
|
468
|
-
pathToAnalyzerUri(p, this.analyzerUriRoot),
|
|
469
|
-
content
|
|
470
|
-
) ?? Promise.resolve()
|
|
471
|
-
]);
|
|
472
|
-
this.contentByPath.set(p, content);
|
|
473
|
-
this.scheduleCompile();
|
|
474
|
-
}
|
|
475
|
-
/**
|
|
476
|
-
* Add or overwrite a JSON file. The analyzer does not track data files, but
|
|
477
|
-
* if `path` was previously tracked as text the analyzer document is closed
|
|
478
|
-
* and the text entry retired so the three views stay consistent.
|
|
479
|
-
*/
|
|
480
|
-
async setJson(path, value) {
|
|
481
|
-
const p = normalizePath(path);
|
|
482
|
-
const wasText = this.contentByPath.has(p);
|
|
483
|
-
await Promise.all([
|
|
484
|
-
this.compiler.setJson(p, value),
|
|
485
|
-
wasText ? this.analyzer?.didClose(pathToAnalyzerUri(p, this.analyzerUriRoot)) : void 0
|
|
486
|
-
]);
|
|
487
|
-
this.contentByPath.delete(p);
|
|
488
|
-
this.scheduleCompile();
|
|
274
|
+
const write = this.writeText(normalizePath(path), content);
|
|
275
|
+
if (write) {
|
|
276
|
+
await write;
|
|
277
|
+
this.scheduleCompile();
|
|
278
|
+
}
|
|
489
279
|
}
|
|
490
|
-
/**
|
|
491
|
-
* Add or overwrite a binary file. If `path` was previously tracked as text,
|
|
492
|
-
* the analyzer document is closed and the text entry retired in the same
|
|
493
|
-
* call so the compiler / analyzer / project views stay consistent.
|
|
494
|
-
*/
|
|
280
|
+
/** Add or overwrite a binary file (retires any text tracking for the path). */
|
|
495
281
|
async setBinary(path, content) {
|
|
496
|
-
|
|
497
|
-
const wasText = this.contentByPath.has(p);
|
|
498
|
-
await Promise.all([
|
|
499
|
-
this.compiler.setBinary(p, content),
|
|
500
|
-
wasText ? this.analyzer?.didClose(pathToAnalyzerUri(p, this.analyzerUriRoot)) : void 0
|
|
501
|
-
]);
|
|
502
|
-
this.contentByPath.delete(p);
|
|
282
|
+
await this.writeBinary(normalizePath(path), toBytes(content));
|
|
503
283
|
this.scheduleCompile();
|
|
504
284
|
}
|
|
505
|
-
/**
|
|
506
|
-
* Batch set multiple files. Strings route to both compiler and analyzer;
|
|
507
|
-
* Uint8Array entries go to the compiler only. Strings matching the last
|
|
508
|
-
* tracked content for their path are skipped on both sinks. Binary entries
|
|
509
|
-
* always go through (no content cache, so no dedup).
|
|
510
|
-
*/
|
|
285
|
+
/** Batch set files. Strings dedup against tracked content; binaries always write. */
|
|
511
286
|
async setMany(files) {
|
|
512
|
-
const
|
|
287
|
+
const writes = [];
|
|
513
288
|
for (const [path, content] of Object.entries(files)) {
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
const analyzerDocs = {};
|
|
518
|
-
const textUpdates = [];
|
|
519
|
-
const analyzerCloses = [];
|
|
520
|
-
const binaryRetirements = [];
|
|
521
|
-
for (const [p, content] of canonical) {
|
|
522
|
-
if (typeof content !== "string") {
|
|
523
|
-
normalized[p] = content;
|
|
524
|
-
if (this.contentByPath.has(p)) {
|
|
525
|
-
analyzerCloses.push(pathToAnalyzerUri(p, this.analyzerUriRoot));
|
|
526
|
-
binaryRetirements.push(p);
|
|
527
|
-
}
|
|
528
|
-
continue;
|
|
529
|
-
}
|
|
530
|
-
if (this.contentByPath.get(p) === content) continue;
|
|
531
|
-
textUpdates.push([p, content]);
|
|
532
|
-
normalized[p] = content;
|
|
533
|
-
analyzerDocs[pathToAnalyzerUri(p, this.analyzerUriRoot)] = content;
|
|
289
|
+
const p = normalizePath(path);
|
|
290
|
+
const write = typeof content === "string" ? this.writeText(p, content) : this.writeBinary(p, content);
|
|
291
|
+
if (write) writes.push(write);
|
|
534
292
|
}
|
|
535
|
-
if (
|
|
536
|
-
await Promise.all(
|
|
537
|
-
this.compiler.setMany(normalized),
|
|
538
|
-
this.analyzer?.didChangeMany(analyzerDocs) ?? Promise.resolve(),
|
|
539
|
-
analyzerCloses.length > 0 ? this.analyzer?.didCloseMany(analyzerCloses) ?? Promise.resolve() : Promise.resolve()
|
|
540
|
-
]);
|
|
541
|
-
for (const [p, content] of textUpdates) this.contentByPath.set(p, content);
|
|
542
|
-
for (const p of binaryRetirements) this.contentByPath.delete(p);
|
|
293
|
+
if (writes.length === 0) return;
|
|
294
|
+
await Promise.all(writes);
|
|
543
295
|
this.scheduleCompile();
|
|
544
296
|
}
|
|
545
|
-
/**
|
|
546
|
-
* Remove a file. Always removed from the compiler's VFS; also closed on the
|
|
547
|
-
* analyzer when it was previously tracked as text.
|
|
548
|
-
*/
|
|
297
|
+
/** Remove a file from the VFS. */
|
|
549
298
|
async remove(path) {
|
|
550
299
|
const p = normalizePath(path);
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
this.compiler.remove(p),
|
|
554
|
-
wasText ? this.analyzer?.didClose(pathToAnalyzerUri(p, this.analyzerUriRoot)) : void 0
|
|
555
|
-
]);
|
|
556
|
-
this.contentByPath.delete(p);
|
|
300
|
+
await this.engine.remove(p);
|
|
301
|
+
this.tracked.delete(p);
|
|
557
302
|
this.scheduleCompile();
|
|
558
303
|
}
|
|
559
|
-
/**
|
|
304
|
+
/** Remove all tracked project files (cached `@preview` packages are kept). */
|
|
560
305
|
async clear() {
|
|
561
|
-
|
|
562
|
-
this.
|
|
563
|
-
(p) => pathToAnalyzerUri(p, this.analyzerUriRoot)
|
|
306
|
+
await Promise.all(
|
|
307
|
+
[...this.tracked.keys()].map((p) => this.engine.remove(p))
|
|
564
308
|
);
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
309
|
+
this.tracked.clear();
|
|
310
|
+
this.scheduleCompile();
|
|
311
|
+
}
|
|
312
|
+
/**
|
|
313
|
+
* Register a font (TTF/OTF, or TTC collection bytes) so compilation can use
|
|
314
|
+
* it, then recompile. The engine bundles default body, math, and monospace
|
|
315
|
+
* fonts; use this to add families it does not ship (e.g. CJK or a custom
|
|
316
|
+
* font). Fonts persist for the project's lifetime.
|
|
317
|
+
*/
|
|
318
|
+
async addFont(bytes) {
|
|
319
|
+
await this.engine.addFont(bytes);
|
|
570
320
|
this.scheduleCompile();
|
|
571
321
|
}
|
|
572
322
|
/**
|
|
573
|
-
* Subscribe to compile results.
|
|
574
|
-
*
|
|
575
|
-
* dropped). If a compile has already settled, the most recent result is
|
|
576
|
-
* delivered synchronously so late-mounted listeners aren't stuck blank until
|
|
577
|
-
* the next compile. Returns an unsubscribe function.
|
|
323
|
+
* Subscribe to compile results. Late subscribers get `lastResult` synchronously.
|
|
324
|
+
* Returns an unsubscribe function.
|
|
578
325
|
*/
|
|
579
326
|
onCompile(listener) {
|
|
580
327
|
this.compileListeners.add(listener);
|
|
581
328
|
if (this._lastResult !== void 0) {
|
|
582
|
-
|
|
329
|
+
try {
|
|
330
|
+
listener(this._lastResult);
|
|
331
|
+
} catch (err) {
|
|
332
|
+
console.error("[typst] compile listener threw:", err);
|
|
333
|
+
}
|
|
583
334
|
}
|
|
584
335
|
return () => {
|
|
585
336
|
this.compileListeners.delete(listener);
|
|
586
337
|
};
|
|
587
338
|
}
|
|
588
339
|
/**
|
|
589
|
-
* Compile the current VFS state
|
|
590
|
-
*
|
|
591
|
-
*
|
|
592
|
-
* notified only for the most recent compile — results from an earlier call
|
|
593
|
-
* that resolves after a later one are suppressed.
|
|
594
|
-
*
|
|
595
|
-
* VFS mutations (`setText`, `remove`, etc.) auto-schedule a debounced
|
|
596
|
-
* compile; call this directly only when you need an awaitable handle on the
|
|
597
|
-
* result (e.g., to flush before rendering to PDF).
|
|
340
|
+
* Compile the current VFS state. Fetches any referenced `@preview` packages
|
|
341
|
+
* first. Errors become a synthetic diagnostic. Listeners fire only for the
|
|
342
|
+
* most recent compile (stale results are dropped).
|
|
598
343
|
*/
|
|
599
344
|
async compile() {
|
|
600
345
|
this.scheduler.cancel();
|
|
601
346
|
const version = ++this.compileVersion;
|
|
602
347
|
let result;
|
|
603
348
|
try {
|
|
604
|
-
|
|
349
|
+
await this.packageLoader.ensure(
|
|
350
|
+
[...this.tracked.values()].filter((v) => v !== null)
|
|
351
|
+
);
|
|
352
|
+
result = await this.engine.compile();
|
|
605
353
|
} catch (err) {
|
|
606
|
-
|
|
607
|
-
result = errorAsCompileResult(err, paths);
|
|
354
|
+
result = errorAsCompileResult(err);
|
|
608
355
|
}
|
|
609
356
|
if (version === this.compileVersion) {
|
|
610
357
|
this._lastResult = result;
|
|
611
358
|
for (const listener of this.compileListeners) {
|
|
612
|
-
|
|
359
|
+
try {
|
|
360
|
+
listener(result);
|
|
361
|
+
} catch (err) {
|
|
362
|
+
console.error("[typst] compile listener threw:", err);
|
|
363
|
+
}
|
|
613
364
|
}
|
|
614
365
|
}
|
|
615
366
|
return result;
|
|
616
367
|
}
|
|
617
|
-
/**
|
|
618
|
-
|
|
619
|
-
return this.
|
|
368
|
+
/** Render a single page of the last compile to SVG, or `undefined`. */
|
|
369
|
+
renderPage(index) {
|
|
370
|
+
return this.engine.renderPage(index);
|
|
620
371
|
}
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
372
|
+
/**
|
|
373
|
+
* Render pages `[start, end)` as `RenderedSvgPage`s (index + dims + svg),
|
|
374
|
+
* zipping the SVG strings with the page metadata from the last compile.
|
|
375
|
+
*/
|
|
376
|
+
async renderedPages(start, end) {
|
|
377
|
+
const pages = this._lastResult?.pages ?? [];
|
|
378
|
+
const svgs = await this.engine.renderPages(start, end);
|
|
379
|
+
return svgs.map((svg, i) => {
|
|
380
|
+
const index = start + i;
|
|
381
|
+
const dims = pages[index];
|
|
382
|
+
return {
|
|
383
|
+
index,
|
|
384
|
+
width: dims?.width ?? 0,
|
|
385
|
+
height: dims?.height ?? 0,
|
|
386
|
+
svg
|
|
387
|
+
};
|
|
388
|
+
});
|
|
626
389
|
}
|
|
627
390
|
/**
|
|
628
|
-
*
|
|
629
|
-
*
|
|
630
|
-
* nor project tracking (`files`/`getText`) is touched. Throws when no
|
|
631
|
-
* analyzer is attached.
|
|
391
|
+
* Export the last compile as a PDF, or `undefined` if nothing has compiled
|
|
392
|
+
* yet. The bytes are a fresh `Uint8Array` (copied across the worker boundary).
|
|
632
393
|
*/
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
);
|
|
394
|
+
exportPdf() {
|
|
395
|
+
return this.engine.exportPdf();
|
|
396
|
+
}
|
|
397
|
+
/** Completions at a CodeMirror `offset` in `path`, using `source` as the live buffer. */
|
|
398
|
+
async completion(path, source, offset, explicit = false) {
|
|
399
|
+
const p = normalizePath(path);
|
|
400
|
+
await this.writeText(p, source);
|
|
401
|
+
return this.engine.complete(p, cmOffsetToByte(source, offset), explicit);
|
|
402
|
+
}
|
|
403
|
+
/** Hover tooltip at a CodeMirror `offset` in `path`, using `source` as the live buffer. */
|
|
404
|
+
async hover(path, source, offset) {
|
|
405
|
+
const p = normalizePath(path);
|
|
406
|
+
await this.writeText(p, source);
|
|
407
|
+
return this.engine.hover(p, cmOffsetToByte(source, offset));
|
|
408
|
+
}
|
|
409
|
+
/** Format `source` (the live buffer for `path`); returns the formatted text or `undefined`. */
|
|
410
|
+
async format(path, source) {
|
|
411
|
+
const p = normalizePath(path);
|
|
412
|
+
await this.writeText(p, source);
|
|
413
|
+
return this.engine.format(p);
|
|
640
414
|
}
|
|
641
415
|
/**
|
|
642
|
-
*
|
|
643
|
-
*
|
|
644
|
-
*
|
|
416
|
+
* Syntax-highlight `source` over the CodeMirror window `[from, to)` (UTF-16
|
|
417
|
+
* offsets; defaults to the whole string). Returns spans whose `from`/`to` are
|
|
418
|
+
* CodeMirror offsets, ready to drive decorations. Stateless: the worker parses
|
|
419
|
+
* `source` directly via typst-syntax, so this neither reads nor mutates the
|
|
420
|
+
* VFS and works for any text (the live buffer, a hover code snippet).
|
|
645
421
|
*/
|
|
646
|
-
|
|
647
|
-
const
|
|
648
|
-
|
|
649
|
-
|
|
422
|
+
async highlight(source, from = 0, to = source.length) {
|
|
423
|
+
const [byteFrom, byteTo] = cmOffsetsToByte(source, [from, to]);
|
|
424
|
+
const spans = await this.engine.highlight(source, byteFrom, byteTo);
|
|
425
|
+
if (spans.length === 0) return spans;
|
|
426
|
+
const cm = byteOffsetsToCm(
|
|
650
427
|
source,
|
|
651
|
-
|
|
428
|
+
spans.flatMap((s) => [s.from, s.to])
|
|
652
429
|
);
|
|
430
|
+
return spans.map((s, i) => ({
|
|
431
|
+
from: cm[i * 2],
|
|
432
|
+
to: cm[i * 2 + 1],
|
|
433
|
+
tag: s.tag
|
|
434
|
+
}));
|
|
653
435
|
}
|
|
654
436
|
/**
|
|
655
|
-
*
|
|
656
|
-
*
|
|
657
|
-
* Idempotent — calling twice is a no-op. After destruction, further calls on
|
|
658
|
-
* the project are not supported; construct a new one.
|
|
659
|
-
*
|
|
660
|
-
* If you need to share a compiler or analyzer across projects, destroy them
|
|
661
|
-
* yourself and don't call this method — the project does not provide an
|
|
662
|
-
* ownership toggle.
|
|
437
|
+
* Syntax-highlight `source` to nested `<span class="typ-*">` HTML for a static
|
|
438
|
+
* context (e.g. a hover tooltip). Stateless, like `highlight`.
|
|
663
439
|
*/
|
|
440
|
+
highlightHtml(source) {
|
|
441
|
+
return this.engine.highlightHtml(source);
|
|
442
|
+
}
|
|
443
|
+
/** Tear down the worker and drop all state. Idempotent. */
|
|
664
444
|
destroy() {
|
|
665
445
|
if (this.destroyed) return;
|
|
666
446
|
this.destroyed = true;
|
|
667
447
|
this.scheduler.cancel();
|
|
668
448
|
this.compileListeners.clear();
|
|
669
|
-
this.
|
|
449
|
+
this.tracked.clear();
|
|
670
450
|
this._lastResult = void 0;
|
|
671
|
-
this.
|
|
672
|
-
this.
|
|
673
|
-
}
|
|
674
|
-
};
|
|
675
|
-
|
|
676
|
-
// src/renderer.ts
|
|
677
|
-
import * as Comlink3 from "comlink";
|
|
678
|
-
var DEFAULT_RENDERER_WASM_URL = `https://cdn.jsdelivr.net/npm/@myriaddreamin/typst-ts-renderer@${"0.7.0-rc2"}/pkg/typst_ts_renderer_bg.wasm`;
|
|
679
|
-
var TypstRenderer = class _TypstRenderer {
|
|
680
|
-
#proxy;
|
|
681
|
-
#worker;
|
|
682
|
-
#wasmUrl;
|
|
683
|
-
#initPromise = null;
|
|
684
|
-
#pending = null;
|
|
685
|
-
#inflight = null;
|
|
686
|
-
constructor(worker, proxy, wasmUrl) {
|
|
687
|
-
this.#worker = worker;
|
|
688
|
-
this.#proxy = proxy;
|
|
689
|
-
this.#wasmUrl = wasmUrl;
|
|
690
|
-
void this.#ensureInit();
|
|
691
|
-
}
|
|
692
|
-
static create(options = {}) {
|
|
693
|
-
const worker = options.worker ?? createRendererWorker();
|
|
694
|
-
const proxy = Comlink3.wrap(worker);
|
|
695
|
-
return new _TypstRenderer(
|
|
696
|
-
worker,
|
|
697
|
-
proxy,
|
|
698
|
-
options.wasmUrl ?? DEFAULT_RENDERER_WASM_URL
|
|
699
|
-
);
|
|
700
|
-
}
|
|
701
|
-
#ensureInit() {
|
|
702
|
-
if (!this.#initPromise) {
|
|
703
|
-
this.#initPromise = this.#proxy.init(this.#wasmUrl).catch((err) => {
|
|
704
|
-
this.#initPromise = null;
|
|
705
|
-
throw err;
|
|
706
|
-
});
|
|
707
|
-
}
|
|
708
|
-
return this.#initPromise;
|
|
709
|
-
}
|
|
710
|
-
/** Terminate the worker. The instance is unusable afterwards. */
|
|
711
|
-
destroy() {
|
|
712
|
-
this.#proxy[Comlink3.releaseProxy]();
|
|
713
|
-
this.#worker.terminate();
|
|
714
|
-
}
|
|
715
|
-
/**
|
|
716
|
-
* Render a Typst vector artifact to a single merged SVG string.
|
|
717
|
-
*
|
|
718
|
-
* Ownership of `vector.buffer` transfers to the worker (zero-copy).
|
|
719
|
-
* Don't reuse the vector after passing it in — accessing its bytes from
|
|
720
|
-
* the main thread after this call is undefined behavior.
|
|
721
|
-
*
|
|
722
|
-
* Concurrent calls are serialized in the worker: while a render is in
|
|
723
|
-
* flight, the most recent `vector` becomes the next render and any
|
|
724
|
-
* intermediate calls are dropped. All overlapping callers share one
|
|
725
|
-
* returned promise that resolves with the LAST rendered SVG — your
|
|
726
|
-
* specific vector may have been superseded.
|
|
727
|
-
*/
|
|
728
|
-
renderSvg(vector) {
|
|
729
|
-
this.#pending = vector;
|
|
730
|
-
this.#inflight ??= this.#drain();
|
|
731
|
-
return this.#inflight;
|
|
732
|
-
}
|
|
733
|
-
async #drain() {
|
|
734
|
-
try {
|
|
735
|
-
await this.#ensureInit();
|
|
736
|
-
let result = "";
|
|
737
|
-
while (this.#pending) {
|
|
738
|
-
const vector = this.#pending;
|
|
739
|
-
this.#pending = null;
|
|
740
|
-
result = await this.#proxy.renderSvg(
|
|
741
|
-
Comlink3.transfer(vector, [vector.buffer])
|
|
742
|
-
);
|
|
743
|
-
}
|
|
744
|
-
return result;
|
|
745
|
-
} finally {
|
|
746
|
-
this.#inflight = null;
|
|
747
|
-
}
|
|
748
|
-
}
|
|
749
|
-
/**
|
|
750
|
-
* Render a Typst vector artifact into one self-contained SVG string per
|
|
751
|
-
* physical page. The merged SVG is split by `<g class="typst-page">`
|
|
752
|
-
* children; each group's `data-page-width` / `data-page-height` give the
|
|
753
|
-
* page-local viewBox. Shared `<defs>` / `<style>` are duplicated into each
|
|
754
|
-
* page so the output SVGs render independently. Returns an empty array if
|
|
755
|
-
* the document has no page groups.
|
|
756
|
-
*/
|
|
757
|
-
async renderSvgPages(vector) {
|
|
758
|
-
return splitMergedSvgPages(await this.renderSvg(vector));
|
|
451
|
+
this.engine[Comlink.releaseProxy]();
|
|
452
|
+
this.worker.terminate();
|
|
759
453
|
}
|
|
760
454
|
};
|
|
761
|
-
function splitMergedSvgPages(svg) {
|
|
762
|
-
const doc = new DOMParser().parseFromString(svg, "text/html");
|
|
763
|
-
const root = doc.querySelector("svg");
|
|
764
|
-
if (!root) return [];
|
|
765
|
-
const children = Array.from(root.children);
|
|
766
|
-
const pageGroups = children.filter(
|
|
767
|
-
(el) => el.tagName.toLowerCase() === "g" && el.classList.contains("typst-page")
|
|
768
|
-
);
|
|
769
|
-
if (pageGroups.length === 0) return [];
|
|
770
|
-
const sharedHtml = children.filter((el) => !el.classList.contains("typst-page")).map((el) => el.outerHTML).join("");
|
|
771
|
-
const namespaceAttrs = Array.from(root.attributes).filter((attr) => attr.name === "xmlns" || attr.name.startsWith("xmlns:")).map((attr) => `${attr.name}="${attr.value}"`).join(" ");
|
|
772
|
-
return pageGroups.flatMap((group, index) => {
|
|
773
|
-
const width = Number(group.getAttribute("data-page-width")) || 0;
|
|
774
|
-
const height = Number(group.getAttribute("data-page-height")) || 0;
|
|
775
|
-
if (width <= 0 || height <= 0) return [];
|
|
776
|
-
const clone = group.cloneNode(true);
|
|
777
|
-
clone.removeAttribute("transform");
|
|
778
|
-
return [
|
|
779
|
-
{
|
|
780
|
-
index,
|
|
781
|
-
width,
|
|
782
|
-
height,
|
|
783
|
-
svg: `<svg ${namespaceAttrs} viewBox="0 0 ${width} ${height}" width="${width}" height="${height}">${sharedHtml}${clone.outerHTML}</svg>`
|
|
784
|
-
}
|
|
785
|
-
];
|
|
786
|
-
});
|
|
787
|
-
}
|
|
788
455
|
export {
|
|
789
|
-
TypstAnalyzer,
|
|
790
|
-
TypstCompiler,
|
|
791
|
-
TypstFormatter,
|
|
792
456
|
TypstProject,
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
pathToAnalyzerUri
|
|
457
|
+
byteToCmOffset,
|
|
458
|
+
cmOffsetToByte,
|
|
459
|
+
normalizePath
|
|
797
460
|
};
|
|
798
461
|
//# sourceMappingURL=index.js.map
|