@vedivad/typst-web-service 0.1.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/dist/worker.js ADDED
@@ -0,0 +1,2233 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropNames = Object.getOwnPropertyNames;
3
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
4
+ var __esm = (fn, res) => function __init() {
5
+ return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
6
+ };
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
12
+
13
+ // ../../node_modules/.bun/@myriaddreamin+typst-ts-web-compiler@0.7.0-rc2/node_modules/@myriaddreamin/typst-ts-web-compiler/pkg/typst_ts_web_compiler.mjs
14
+ function addHeapObject(obj) {
15
+ if (heap_next === heap.length) heap.push(heap.length + 1);
16
+ const idx = heap_next;
17
+ heap_next = heap[idx];
18
+ heap[idx] = obj;
19
+ return idx;
20
+ }
21
+ function _assertClass(instance, klass) {
22
+ if (!(instance instanceof klass)) {
23
+ throw new Error(`expected instance of ${klass.name}`);
24
+ }
25
+ }
26
+ function debugString(val) {
27
+ const type = typeof val;
28
+ if (type == "number" || type == "boolean" || val == null) {
29
+ return `${val}`;
30
+ }
31
+ if (type == "string") {
32
+ return `"${val}"`;
33
+ }
34
+ if (type == "symbol") {
35
+ const description = val.description;
36
+ if (description == null) {
37
+ return "Symbol";
38
+ } else {
39
+ return `Symbol(${description})`;
40
+ }
41
+ }
42
+ if (type == "function") {
43
+ const name = val.name;
44
+ if (typeof name == "string" && name.length > 0) {
45
+ return `Function(${name})`;
46
+ } else {
47
+ return "Function";
48
+ }
49
+ }
50
+ if (Array.isArray(val)) {
51
+ const length = val.length;
52
+ let debug = "[";
53
+ if (length > 0) {
54
+ debug += debugString(val[0]);
55
+ }
56
+ for (let i = 1; i < length; i++) {
57
+ debug += ", " + debugString(val[i]);
58
+ }
59
+ debug += "]";
60
+ return debug;
61
+ }
62
+ const builtInMatches = /\[object ([^\]]+)\]/.exec(toString.call(val));
63
+ let className;
64
+ if (builtInMatches && builtInMatches.length > 1) {
65
+ className = builtInMatches[1];
66
+ } else {
67
+ return toString.call(val);
68
+ }
69
+ if (className == "Object") {
70
+ try {
71
+ return "Object(" + JSON.stringify(val) + ")";
72
+ } catch (_) {
73
+ return "Object";
74
+ }
75
+ }
76
+ if (val instanceof Error) {
77
+ return `${val.name}: ${val.message}
78
+ ${val.stack}`;
79
+ }
80
+ return className;
81
+ }
82
+ function dropObject(idx) {
83
+ if (idx < 132) return;
84
+ heap[idx] = heap_next;
85
+ heap_next = idx;
86
+ }
87
+ function getArrayJsValueFromWasm0(ptr, len) {
88
+ ptr = ptr >>> 0;
89
+ const mem = getDataViewMemory0();
90
+ const result = [];
91
+ for (let i = ptr; i < ptr + 4 * len; i += 4) {
92
+ result.push(takeObject(mem.getUint32(i, true)));
93
+ }
94
+ return result;
95
+ }
96
+ function getArrayU32FromWasm0(ptr, len) {
97
+ ptr = ptr >>> 0;
98
+ return getUint32ArrayMemory0().subarray(ptr / 4, ptr / 4 + len);
99
+ }
100
+ function getArrayU8FromWasm0(ptr, len) {
101
+ ptr = ptr >>> 0;
102
+ return getUint8ArrayMemory0().subarray(ptr / 1, ptr / 1 + len);
103
+ }
104
+ function getDataViewMemory0() {
105
+ if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || cachedDataViewMemory0.buffer.detached === void 0 && cachedDataViewMemory0.buffer !== wasm.memory.buffer) {
106
+ cachedDataViewMemory0 = new DataView(wasm.memory.buffer);
107
+ }
108
+ return cachedDataViewMemory0;
109
+ }
110
+ function getStringFromWasm0(ptr, len) {
111
+ ptr = ptr >>> 0;
112
+ return decodeText(ptr, len);
113
+ }
114
+ function getUint32ArrayMemory0() {
115
+ if (cachedUint32ArrayMemory0 === null || cachedUint32ArrayMemory0.byteLength === 0) {
116
+ cachedUint32ArrayMemory0 = new Uint32Array(wasm.memory.buffer);
117
+ }
118
+ return cachedUint32ArrayMemory0;
119
+ }
120
+ function getUint8ArrayMemory0() {
121
+ if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
122
+ cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
123
+ }
124
+ return cachedUint8ArrayMemory0;
125
+ }
126
+ function getObject(idx) {
127
+ return heap[idx];
128
+ }
129
+ function handleError(f, args) {
130
+ try {
131
+ return f.apply(this, args);
132
+ } catch (e) {
133
+ wasm.__wbindgen_export3(addHeapObject(e));
134
+ }
135
+ }
136
+ function isLikeNone(x) {
137
+ return x === void 0 || x === null;
138
+ }
139
+ function makeMutClosure(arg0, arg1, dtor, f) {
140
+ const state = { a: arg0, b: arg1, cnt: 1, dtor };
141
+ const real = (...args) => {
142
+ state.cnt++;
143
+ const a = state.a;
144
+ state.a = 0;
145
+ try {
146
+ return f(a, state.b, ...args);
147
+ } finally {
148
+ state.a = a;
149
+ real._wbg_cb_unref();
150
+ }
151
+ };
152
+ real._wbg_cb_unref = () => {
153
+ if (--state.cnt === 0) {
154
+ state.dtor(state.a, state.b);
155
+ state.a = 0;
156
+ CLOSURE_DTORS.unregister(state);
157
+ }
158
+ };
159
+ CLOSURE_DTORS.register(real, state, state);
160
+ return real;
161
+ }
162
+ function passArray8ToWasm0(arg, malloc) {
163
+ const ptr = malloc(arg.length * 1, 1) >>> 0;
164
+ getUint8ArrayMemory0().set(arg, ptr / 1);
165
+ WASM_VECTOR_LEN = arg.length;
166
+ return ptr;
167
+ }
168
+ function passArrayJsValueToWasm0(array, malloc) {
169
+ const ptr = malloc(array.length * 4, 4) >>> 0;
170
+ const mem = getDataViewMemory0();
171
+ for (let i = 0; i < array.length; i++) {
172
+ mem.setUint32(ptr + 4 * i, addHeapObject(array[i]), true);
173
+ }
174
+ WASM_VECTOR_LEN = array.length;
175
+ return ptr;
176
+ }
177
+ function passStringToWasm0(arg, malloc, realloc) {
178
+ if (realloc === void 0) {
179
+ const buf = cachedTextEncoder.encode(arg);
180
+ const ptr2 = malloc(buf.length, 1) >>> 0;
181
+ getUint8ArrayMemory0().subarray(ptr2, ptr2 + buf.length).set(buf);
182
+ WASM_VECTOR_LEN = buf.length;
183
+ return ptr2;
184
+ }
185
+ let len = arg.length;
186
+ let ptr = malloc(len, 1) >>> 0;
187
+ const mem = getUint8ArrayMemory0();
188
+ let offset = 0;
189
+ for (; offset < len; offset++) {
190
+ const code = arg.charCodeAt(offset);
191
+ if (code > 127) break;
192
+ mem[ptr + offset] = code;
193
+ }
194
+ if (offset !== len) {
195
+ if (offset !== 0) {
196
+ arg = arg.slice(offset);
197
+ }
198
+ ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
199
+ const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
200
+ const ret = cachedTextEncoder.encodeInto(arg, view);
201
+ offset += ret.written;
202
+ ptr = realloc(ptr, len, offset, 1) >>> 0;
203
+ }
204
+ WASM_VECTOR_LEN = offset;
205
+ return ptr;
206
+ }
207
+ function takeObject(idx) {
208
+ const ret = getObject(idx);
209
+ dropObject(idx);
210
+ return ret;
211
+ }
212
+ function decodeText(ptr, len) {
213
+ numBytesDecoded += len;
214
+ if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {
215
+ cachedTextDecoder = new TextDecoder("utf-8", { ignoreBOM: true, fatal: true });
216
+ cachedTextDecoder.decode();
217
+ numBytesDecoded = len;
218
+ }
219
+ return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
220
+ }
221
+ function __wasm_bindgen_func_elem_944(arg0, arg1, arg2) {
222
+ wasm.__wasm_bindgen_func_elem_944(arg0, arg1, addHeapObject(arg2));
223
+ }
224
+ function __wasm_bindgen_func_elem_37348(arg0, arg1, arg2, arg3) {
225
+ wasm.__wasm_bindgen_func_elem_37348(arg0, arg1, addHeapObject(arg2), addHeapObject(arg3));
226
+ }
227
+ function get_font_info(buffer) {
228
+ const ret = wasm.get_font_info(addHeapObject(buffer));
229
+ return takeObject(ret);
230
+ }
231
+ async function __wbg_load(module, imports) {
232
+ if (typeof Response === "function" && module instanceof Response) {
233
+ if (typeof WebAssembly.instantiateStreaming === "function") {
234
+ try {
235
+ return await WebAssembly.instantiateStreaming(module, imports);
236
+ } catch (e) {
237
+ const validResponse = module.ok && EXPECTED_RESPONSE_TYPES.has(module.type);
238
+ if (validResponse && module.headers.get("Content-Type") !== "application/wasm") {
239
+ 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", e);
240
+ } else {
241
+ throw e;
242
+ }
243
+ }
244
+ }
245
+ const bytes = await module.arrayBuffer();
246
+ return await WebAssembly.instantiate(bytes, imports);
247
+ } else {
248
+ const instance = await WebAssembly.instantiate(module, imports);
249
+ if (instance instanceof WebAssembly.Instance) {
250
+ return { instance, module };
251
+ } else {
252
+ return instance;
253
+ }
254
+ }
255
+ }
256
+ function __wbg_get_imports() {
257
+ const imports = {};
258
+ imports.wbg = {};
259
+ imports.wbg.__wbg_Error_52673b7de5a0ca89 = function(arg0, arg1) {
260
+ const ret = Error(getStringFromWasm0(arg0, arg1));
261
+ return addHeapObject(ret);
262
+ };
263
+ imports.wbg.__wbg_Number_2d1dcfcf4ec51736 = function(arg0) {
264
+ const ret = Number(getObject(arg0));
265
+ return ret;
266
+ };
267
+ imports.wbg.__wbg___wbindgen_bigint_get_as_i64_6e32f5e6aff02e1d = function(arg0, arg1) {
268
+ const v = getObject(arg1);
269
+ const ret = typeof v === "bigint" ? v : void 0;
270
+ getDataViewMemory0().setBigInt64(arg0 + 8 * 1, isLikeNone(ret) ? BigInt(0) : ret, true);
271
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, !isLikeNone(ret), true);
272
+ };
273
+ imports.wbg.__wbg___wbindgen_boolean_get_dea25b33882b895b = function(arg0) {
274
+ const v = getObject(arg0);
275
+ const ret = typeof v === "boolean" ? v : void 0;
276
+ return isLikeNone(ret) ? 16777215 : ret ? 1 : 0;
277
+ };
278
+ imports.wbg.__wbg___wbindgen_debug_string_adfb662ae34724b6 = function(arg0, arg1) {
279
+ const ret = debugString(getObject(arg1));
280
+ const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_export, wasm.__wbindgen_export2);
281
+ const len1 = WASM_VECTOR_LEN;
282
+ getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
283
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
284
+ };
285
+ imports.wbg.__wbg___wbindgen_in_0d3e1e8f0c669317 = function(arg0, arg1) {
286
+ const ret = getObject(arg0) in getObject(arg1);
287
+ return ret;
288
+ };
289
+ imports.wbg.__wbg___wbindgen_is_bigint_0e1a2e3f55cfae27 = function(arg0) {
290
+ const ret = typeof getObject(arg0) === "bigint";
291
+ return ret;
292
+ };
293
+ imports.wbg.__wbg___wbindgen_is_function_8d400b8b1af978cd = function(arg0) {
294
+ const ret = typeof getObject(arg0) === "function";
295
+ return ret;
296
+ };
297
+ imports.wbg.__wbg___wbindgen_is_object_ce774f3490692386 = function(arg0) {
298
+ const val = getObject(arg0);
299
+ const ret = typeof val === "object" && val !== null;
300
+ return ret;
301
+ };
302
+ imports.wbg.__wbg___wbindgen_is_string_704ef9c8fc131030 = function(arg0) {
303
+ const ret = typeof getObject(arg0) === "string";
304
+ return ret;
305
+ };
306
+ imports.wbg.__wbg___wbindgen_is_undefined_f6b95eab589e0269 = function(arg0) {
307
+ const ret = getObject(arg0) === void 0;
308
+ return ret;
309
+ };
310
+ imports.wbg.__wbg___wbindgen_jsval_eq_b6101cc9cef1fe36 = function(arg0, arg1) {
311
+ const ret = getObject(arg0) === getObject(arg1);
312
+ return ret;
313
+ };
314
+ imports.wbg.__wbg___wbindgen_jsval_loose_eq_766057600fdd1b0d = function(arg0, arg1) {
315
+ const ret = getObject(arg0) == getObject(arg1);
316
+ return ret;
317
+ };
318
+ imports.wbg.__wbg___wbindgen_number_get_9619185a74197f95 = function(arg0, arg1) {
319
+ const obj = getObject(arg1);
320
+ const ret = typeof obj === "number" ? obj : void 0;
321
+ getDataViewMemory0().setFloat64(arg0 + 8 * 1, isLikeNone(ret) ? 0 : ret, true);
322
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, !isLikeNone(ret), true);
323
+ };
324
+ imports.wbg.__wbg___wbindgen_string_get_a2a31e16edf96e42 = function(arg0, arg1) {
325
+ const obj = getObject(arg1);
326
+ const ret = typeof obj === "string" ? obj : void 0;
327
+ var ptr1 = isLikeNone(ret) ? 0 : passStringToWasm0(ret, wasm.__wbindgen_export, wasm.__wbindgen_export2);
328
+ var len1 = WASM_VECTOR_LEN;
329
+ getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
330
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
331
+ };
332
+ imports.wbg.__wbg___wbindgen_throw_dd24417ed36fc46e = function(arg0, arg1) {
333
+ throw new Error(getStringFromWasm0(arg0, arg1));
334
+ };
335
+ imports.wbg.__wbg__wbg_cb_unref_87dfb5aaa0cbcea7 = function(arg0) {
336
+ getObject(arg0)._wbg_cb_unref();
337
+ };
338
+ imports.wbg.__wbg_call_3020136f7a2d6e44 = function() {
339
+ return handleError(function(arg0, arg1, arg2) {
340
+ const ret = getObject(arg0).call(getObject(arg1), getObject(arg2));
341
+ return addHeapObject(ret);
342
+ }, arguments);
343
+ };
344
+ imports.wbg.__wbg_call_78f94eb02ec7f9b2 = function() {
345
+ return handleError(function(arg0, arg1, arg2, arg3, arg4) {
346
+ const ret = getObject(arg0).call(getObject(arg1), getObject(arg2), getObject(arg3), getObject(arg4));
347
+ return addHeapObject(ret);
348
+ }, arguments);
349
+ };
350
+ imports.wbg.__wbg_call_abb4ff46ce38be40 = function() {
351
+ return handleError(function(arg0, arg1) {
352
+ const ret = getObject(arg0).call(getObject(arg1));
353
+ return addHeapObject(ret);
354
+ }, arguments);
355
+ };
356
+ imports.wbg.__wbg_done_62ea16af4ce34b24 = function(arg0) {
357
+ const ret = getObject(arg0).done;
358
+ return ret;
359
+ };
360
+ imports.wbg.__wbg_entries_83c79938054e065f = function(arg0) {
361
+ const ret = Object.entries(getObject(arg0));
362
+ return addHeapObject(ret);
363
+ };
364
+ imports.wbg.__wbg_error_7534b8e9a36f1ab4 = function(arg0, arg1) {
365
+ let deferred0_0;
366
+ let deferred0_1;
367
+ try {
368
+ deferred0_0 = arg0;
369
+ deferred0_1 = arg1;
370
+ console.error(getStringFromWasm0(arg0, arg1));
371
+ } finally {
372
+ wasm.__wbindgen_export4(deferred0_0, deferred0_1, 1);
373
+ }
374
+ };
375
+ imports.wbg.__wbg_error_85faeb8919b11cc6 = function(arg0, arg1, arg2) {
376
+ console.error(getObject(arg0), getObject(arg1), getObject(arg2));
377
+ };
378
+ imports.wbg.__wbg_getTimezoneOffset_45389e26d6f46823 = function(arg0) {
379
+ const ret = getObject(arg0).getTimezoneOffset();
380
+ return ret;
381
+ };
382
+ imports.wbg.__wbg_get_6b7bd52aca3f9671 = function(arg0, arg1) {
383
+ const ret = getObject(arg0)[arg1 >>> 0];
384
+ return addHeapObject(ret);
385
+ };
386
+ imports.wbg.__wbg_get_af9dab7e9603ea93 = function() {
387
+ return handleError(function(arg0, arg1) {
388
+ const ret = Reflect.get(getObject(arg0), getObject(arg1));
389
+ return addHeapObject(ret);
390
+ }, arguments);
391
+ };
392
+ imports.wbg.__wbg_get_with_ref_key_1dc361bd10053bfe = function(arg0, arg1) {
393
+ const ret = getObject(arg0)[getObject(arg1)];
394
+ return addHeapObject(ret);
395
+ };
396
+ imports.wbg.__wbg_info_ce6bcc489c22f6f0 = function(arg0) {
397
+ console.info(getObject(arg0));
398
+ };
399
+ imports.wbg.__wbg_instanceof_ArrayBuffer_f3320d2419cd0355 = function(arg0) {
400
+ let result;
401
+ try {
402
+ result = getObject(arg0) instanceof ArrayBuffer;
403
+ } catch (_) {
404
+ result = false;
405
+ }
406
+ const ret = result;
407
+ return ret;
408
+ };
409
+ imports.wbg.__wbg_instanceof_Map_084be8da74364158 = function(arg0) {
410
+ let result;
411
+ try {
412
+ result = getObject(arg0) instanceof Map;
413
+ } catch (_) {
414
+ result = false;
415
+ }
416
+ const ret = result;
417
+ return ret;
418
+ };
419
+ imports.wbg.__wbg_instanceof_Uint8Array_da54ccc9d3e09434 = function(arg0) {
420
+ let result;
421
+ try {
422
+ result = getObject(arg0) instanceof Uint8Array;
423
+ } catch (_) {
424
+ result = false;
425
+ }
426
+ const ret = result;
427
+ return ret;
428
+ };
429
+ imports.wbg.__wbg_isArray_51fd9e6422c0a395 = function(arg0) {
430
+ const ret = Array.isArray(getObject(arg0));
431
+ return ret;
432
+ };
433
+ imports.wbg.__wbg_isSafeInteger_ae7d3f054d55fa16 = function(arg0) {
434
+ const ret = Number.isSafeInteger(getObject(arg0));
435
+ return ret;
436
+ };
437
+ imports.wbg.__wbg_iterator_27b7c8b35ab3e86b = function() {
438
+ const ret = Symbol.iterator;
439
+ return addHeapObject(ret);
440
+ };
441
+ imports.wbg.__wbg_length_22ac23eaec9d8053 = function(arg0) {
442
+ const ret = getObject(arg0).length;
443
+ return ret;
444
+ };
445
+ imports.wbg.__wbg_length_d45040a40c570362 = function(arg0) {
446
+ const ret = getObject(arg0).length;
447
+ return ret;
448
+ };
449
+ imports.wbg.__wbg_new_1ba21ce319a06297 = function() {
450
+ const ret = new Object();
451
+ return addHeapObject(ret);
452
+ };
453
+ imports.wbg.__wbg_new_25f239778d6112b9 = function() {
454
+ const ret = new Array();
455
+ return addHeapObject(ret);
456
+ };
457
+ imports.wbg.__wbg_new_6421f6084cc5bc5a = function(arg0) {
458
+ const ret = new Uint8Array(getObject(arg0));
459
+ return addHeapObject(ret);
460
+ };
461
+ imports.wbg.__wbg_new_8a6f238a6ece86ea = function() {
462
+ const ret = new Error();
463
+ return addHeapObject(ret);
464
+ };
465
+ imports.wbg.__wbg_new_b2db8aa2650f793a = function(arg0) {
466
+ const ret = new Date(getObject(arg0));
467
+ return addHeapObject(ret);
468
+ };
469
+ imports.wbg.__wbg_new_df1173567d5ff028 = function(arg0, arg1) {
470
+ const ret = new Error(getStringFromWasm0(arg0, arg1));
471
+ return addHeapObject(ret);
472
+ };
473
+ imports.wbg.__wbg_new_ff12d2b041fb48f1 = function(arg0, arg1) {
474
+ try {
475
+ var state0 = { a: arg0, b: arg1 };
476
+ var cb0 = (arg02, arg12) => {
477
+ const a = state0.a;
478
+ state0.a = 0;
479
+ try {
480
+ return __wasm_bindgen_func_elem_37348(a, state0.b, arg02, arg12);
481
+ } finally {
482
+ state0.a = a;
483
+ }
484
+ };
485
+ const ret = new Promise(cb0);
486
+ return addHeapObject(ret);
487
+ } finally {
488
+ state0.a = state0.b = 0;
489
+ }
490
+ };
491
+ imports.wbg.__wbg_new_from_slice_db0691b69e9d3891 = function(arg0, arg1) {
492
+ const ret = new Uint32Array(getArrayU32FromWasm0(arg0, arg1));
493
+ return addHeapObject(ret);
494
+ };
495
+ imports.wbg.__wbg_new_from_slice_f9c22b9153b26992 = function(arg0, arg1) {
496
+ const ret = new Uint8Array(getArrayU8FromWasm0(arg0, arg1));
497
+ return addHeapObject(ret);
498
+ };
499
+ imports.wbg.__wbg_new_no_args_cb138f77cf6151ee = function(arg0, arg1) {
500
+ const ret = new Function(getStringFromWasm0(arg0, arg1));
501
+ return addHeapObject(ret);
502
+ };
503
+ imports.wbg.__wbg_new_with_args_df9e7125ffe55248 = function(arg0, arg1, arg2, arg3) {
504
+ const ret = new Function(getStringFromWasm0(arg0, arg1), getStringFromWasm0(arg2, arg3));
505
+ return addHeapObject(ret);
506
+ };
507
+ imports.wbg.__wbg_next_138a17bbf04e926c = function(arg0) {
508
+ const ret = getObject(arg0).next;
509
+ return addHeapObject(ret);
510
+ };
511
+ imports.wbg.__wbg_next_3cfe5c0fe2a4cc53 = function() {
512
+ return handleError(function(arg0) {
513
+ const ret = getObject(arg0).next();
514
+ return addHeapObject(ret);
515
+ }, arguments);
516
+ };
517
+ imports.wbg.__wbg_now_69d776cd24f5215b = function() {
518
+ const ret = Date.now();
519
+ return ret;
520
+ };
521
+ imports.wbg.__wbg_prototypesetcall_dfe9b766cdc1f1fd = function(arg0, arg1, arg2) {
522
+ Uint8Array.prototype.set.call(getArrayU8FromWasm0(arg0, arg1), getObject(arg2));
523
+ };
524
+ imports.wbg.__wbg_proxycontext_new = function(arg0) {
525
+ const ret = ProxyContext.__wrap(arg0);
526
+ return addHeapObject(ret);
527
+ };
528
+ imports.wbg.__wbg_push_7d9be8f38fc13975 = function(arg0, arg1) {
529
+ const ret = getObject(arg0).push(getObject(arg1));
530
+ return ret;
531
+ };
532
+ imports.wbg.__wbg_queueMicrotask_9b549dfce8865860 = function(arg0) {
533
+ const ret = getObject(arg0).queueMicrotask;
534
+ return addHeapObject(ret);
535
+ };
536
+ imports.wbg.__wbg_queueMicrotask_fca69f5bfad613a5 = function(arg0) {
537
+ queueMicrotask(getObject(arg0));
538
+ };
539
+ imports.wbg.__wbg_resolve_fd5bfbaa4ce36e1e = function(arg0) {
540
+ const ret = Promise.resolve(getObject(arg0));
541
+ return addHeapObject(ret);
542
+ };
543
+ imports.wbg.__wbg_set_3f1d0b984ed272ed = function(arg0, arg1, arg2) {
544
+ getObject(arg0)[takeObject(arg1)] = takeObject(arg2);
545
+ };
546
+ imports.wbg.__wbg_set_781438a03c0c3c81 = function() {
547
+ return handleError(function(arg0, arg1, arg2) {
548
+ const ret = Reflect.set(getObject(arg0), getObject(arg1), getObject(arg2));
549
+ return ret;
550
+ }, arguments);
551
+ };
552
+ imports.wbg.__wbg_set_7df433eea03a5c14 = function(arg0, arg1, arg2) {
553
+ getObject(arg0)[arg1 >>> 0] = takeObject(arg2);
554
+ };
555
+ imports.wbg.__wbg_stack_0ed75d68575b0f3c = function(arg0, arg1) {
556
+ const ret = getObject(arg1).stack;
557
+ const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_export, wasm.__wbindgen_export2);
558
+ const len1 = WASM_VECTOR_LEN;
559
+ getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
560
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
561
+ };
562
+ imports.wbg.__wbg_static_accessor_GLOBAL_769e6b65d6557335 = function() {
563
+ const ret = typeof global === "undefined" ? null : global;
564
+ return isLikeNone(ret) ? 0 : addHeapObject(ret);
565
+ };
566
+ imports.wbg.__wbg_static_accessor_GLOBAL_THIS_60cf02db4de8e1c1 = function() {
567
+ const ret = typeof globalThis === "undefined" ? null : globalThis;
568
+ return isLikeNone(ret) ? 0 : addHeapObject(ret);
569
+ };
570
+ imports.wbg.__wbg_static_accessor_SELF_08f5a74c69739274 = function() {
571
+ const ret = typeof self === "undefined" ? null : self;
572
+ return isLikeNone(ret) ? 0 : addHeapObject(ret);
573
+ };
574
+ imports.wbg.__wbg_static_accessor_WINDOW_a8924b26aa92d024 = function() {
575
+ const ret = typeof window === "undefined" ? null : window;
576
+ return isLikeNone(ret) ? 0 : addHeapObject(ret);
577
+ };
578
+ imports.wbg.__wbg_then_4f95312d68691235 = function(arg0, arg1) {
579
+ const ret = getObject(arg0).then(getObject(arg1));
580
+ return addHeapObject(ret);
581
+ };
582
+ imports.wbg.__wbg_typstcompiler_new = function(arg0) {
583
+ const ret = TypstCompiler.__wrap(arg0);
584
+ return addHeapObject(ret);
585
+ };
586
+ imports.wbg.__wbg_typstfontresolver_new = function(arg0) {
587
+ const ret = TypstFontResolver.__wrap(arg0);
588
+ return addHeapObject(ret);
589
+ };
590
+ imports.wbg.__wbg_value_57b7b035e117f7ee = function(arg0) {
591
+ const ret = getObject(arg0).value;
592
+ return addHeapObject(ret);
593
+ };
594
+ imports.wbg.__wbindgen_cast_2241b6af4c4b2941 = function(arg0, arg1) {
595
+ const ret = getStringFromWasm0(arg0, arg1);
596
+ return addHeapObject(ret);
597
+ };
598
+ imports.wbg.__wbindgen_cast_3334ea73b4b28ba3 = function(arg0, arg1) {
599
+ const ret = makeMutClosure(arg0, arg1, wasm.__wasm_bindgen_func_elem_957, __wasm_bindgen_func_elem_944);
600
+ return addHeapObject(ret);
601
+ };
602
+ imports.wbg.__wbindgen_cast_4625c577ab2ec9ee = function(arg0) {
603
+ const ret = BigInt.asUintN(64, arg0);
604
+ return addHeapObject(ret);
605
+ };
606
+ imports.wbg.__wbindgen_cast_9ae0607507abb057 = function(arg0) {
607
+ const ret = arg0;
608
+ return addHeapObject(ret);
609
+ };
610
+ imports.wbg.__wbindgen_cast_d6cd19b81560fd6e = function(arg0) {
611
+ const ret = arg0;
612
+ return addHeapObject(ret);
613
+ };
614
+ imports.wbg.__wbindgen_object_clone_ref = function(arg0) {
615
+ const ret = getObject(arg0);
616
+ return addHeapObject(ret);
617
+ };
618
+ imports.wbg.__wbindgen_object_drop_ref = function(arg0) {
619
+ takeObject(arg0);
620
+ };
621
+ return imports;
622
+ }
623
+ function __wbg_finalize_init(instance, module) {
624
+ wasm = instance.exports;
625
+ __wbg_init.__wbindgen_wasm_module = module;
626
+ cachedDataViewMemory0 = null;
627
+ cachedUint32ArrayMemory0 = null;
628
+ cachedUint8ArrayMemory0 = null;
629
+ return wasm;
630
+ }
631
+ function initSync(module) {
632
+ if (wasm !== void 0) return wasm;
633
+ if (typeof module !== "undefined") {
634
+ if (Object.getPrototypeOf(module) === Object.prototype) {
635
+ ({ module } = module);
636
+ } else {
637
+ console.warn("using deprecated parameters for `initSync()`; pass a single object instead");
638
+ }
639
+ }
640
+ const imports = __wbg_get_imports();
641
+ if (!(module instanceof WebAssembly.Module)) {
642
+ module = new WebAssembly.Module(module);
643
+ }
644
+ const instance = new WebAssembly.Instance(module, imports);
645
+ return __wbg_finalize_init(instance, module);
646
+ }
647
+ async function __wbg_init(module_or_path) {
648
+ if (wasm !== void 0) return wasm;
649
+ if (typeof module_or_path !== "undefined") {
650
+ if (Object.getPrototypeOf(module_or_path) === Object.prototype) {
651
+ ({ module_or_path } = module_or_path);
652
+ } else {
653
+ console.warn("using deprecated parameters for the initialization function; pass a single object instead");
654
+ }
655
+ }
656
+ if (typeof module_or_path === "undefined") {
657
+ module_or_path = importWasmModule("typst_ts_web_compiler_bg.wasm", import.meta.url);
658
+ }
659
+ const imports = __wbg_get_imports();
660
+ if (typeof module_or_path === "string" || typeof Request === "function" && module_or_path instanceof Request || typeof URL === "function" && module_or_path instanceof URL) {
661
+ module_or_path = fetch(module_or_path);
662
+ }
663
+ const { instance, module } = await __wbg_load(await module_or_path, imports);
664
+ return __wbg_finalize_init(instance, module);
665
+ }
666
+ function setImportWasmModule(importer) {
667
+ importWasmModule = importer;
668
+ }
669
+ var wasm, CLOSURE_DTORS, cachedDataViewMemory0, cachedUint32ArrayMemory0, cachedUint8ArrayMemory0, heap, heap_next, cachedTextDecoder, MAX_SAFARI_DECODE_BYTES, numBytesDecoded, cachedTextEncoder, WASM_VECTOR_LEN, IncrServerFinalization, ProxyContextFinalization, TypstCompileWorldFinalization, TypstCompilerFinalization, TypstCompilerBuilderFinalization, TypstFontResolverFinalization, TypstFontResolverBuilderFinalization, IncrServer, ProxyContext, TypstCompileWorld, TypstCompiler, TypstCompilerBuilder, TypstFontResolver, TypstFontResolverBuilder, EXPECTED_RESPONSE_TYPES, typst_ts_web_compiler_default, importWasmModule;
670
+ var init_typst_ts_web_compiler = __esm({
671
+ "../../node_modules/.bun/@myriaddreamin+typst-ts-web-compiler@0.7.0-rc2/node_modules/@myriaddreamin/typst-ts-web-compiler/pkg/typst_ts_web_compiler.mjs"() {
672
+ "use strict";
673
+ CLOSURE_DTORS = typeof FinalizationRegistry === "undefined" ? { register: () => {
674
+ }, unregister: () => {
675
+ } } : new FinalizationRegistry((state) => state.dtor(state.a, state.b));
676
+ cachedDataViewMemory0 = null;
677
+ cachedUint32ArrayMemory0 = null;
678
+ cachedUint8ArrayMemory0 = null;
679
+ heap = new Array(128).fill(void 0);
680
+ heap.push(void 0, null, true, false);
681
+ heap_next = heap.length;
682
+ cachedTextDecoder = new TextDecoder("utf-8", { ignoreBOM: true, fatal: true });
683
+ cachedTextDecoder.decode();
684
+ MAX_SAFARI_DECODE_BYTES = 2146435072;
685
+ numBytesDecoded = 0;
686
+ cachedTextEncoder = new TextEncoder();
687
+ if (!("encodeInto" in cachedTextEncoder)) {
688
+ cachedTextEncoder.encodeInto = function(arg, view) {
689
+ const buf = cachedTextEncoder.encode(arg);
690
+ view.set(buf);
691
+ return {
692
+ read: arg.length,
693
+ written: buf.length
694
+ };
695
+ };
696
+ }
697
+ WASM_VECTOR_LEN = 0;
698
+ IncrServerFinalization = typeof FinalizationRegistry === "undefined" ? { register: () => {
699
+ }, unregister: () => {
700
+ } } : new FinalizationRegistry((ptr) => wasm.__wbg_incrserver_free(ptr >>> 0, 1));
701
+ ProxyContextFinalization = typeof FinalizationRegistry === "undefined" ? { register: () => {
702
+ }, unregister: () => {
703
+ } } : new FinalizationRegistry((ptr) => wasm.__wbg_proxycontext_free(ptr >>> 0, 1));
704
+ TypstCompileWorldFinalization = typeof FinalizationRegistry === "undefined" ? { register: () => {
705
+ }, unregister: () => {
706
+ } } : new FinalizationRegistry((ptr) => wasm.__wbg_typstcompileworld_free(ptr >>> 0, 1));
707
+ TypstCompilerFinalization = typeof FinalizationRegistry === "undefined" ? { register: () => {
708
+ }, unregister: () => {
709
+ } } : new FinalizationRegistry((ptr) => wasm.__wbg_typstcompiler_free(ptr >>> 0, 1));
710
+ TypstCompilerBuilderFinalization = typeof FinalizationRegistry === "undefined" ? { register: () => {
711
+ }, unregister: () => {
712
+ } } : new FinalizationRegistry((ptr) => wasm.__wbg_typstcompilerbuilder_free(ptr >>> 0, 1));
713
+ TypstFontResolverFinalization = typeof FinalizationRegistry === "undefined" ? { register: () => {
714
+ }, unregister: () => {
715
+ } } : new FinalizationRegistry((ptr) => wasm.__wbg_typstfontresolver_free(ptr >>> 0, 1));
716
+ TypstFontResolverBuilderFinalization = typeof FinalizationRegistry === "undefined" ? { register: () => {
717
+ }, unregister: () => {
718
+ } } : new FinalizationRegistry((ptr) => wasm.__wbg_typstfontresolverbuilder_free(ptr >>> 0, 1));
719
+ IncrServer = class _IncrServer {
720
+ static __wrap(ptr) {
721
+ ptr = ptr >>> 0;
722
+ const obj = Object.create(_IncrServer.prototype);
723
+ obj.__wbg_ptr = ptr;
724
+ IncrServerFinalization.register(obj, obj.__wbg_ptr, obj);
725
+ return obj;
726
+ }
727
+ __destroy_into_raw() {
728
+ const ptr = this.__wbg_ptr;
729
+ this.__wbg_ptr = 0;
730
+ IncrServerFinalization.unregister(this);
731
+ return ptr;
732
+ }
733
+ free() {
734
+ const ptr = this.__destroy_into_raw();
735
+ wasm.__wbg_incrserver_free(ptr, 0);
736
+ }
737
+ /**
738
+ * @param {boolean} attach
739
+ */
740
+ set_attach_debug_info(attach) {
741
+ wasm.incrserver_set_attach_debug_info(this.__wbg_ptr, attach);
742
+ }
743
+ /**
744
+ * @returns {Uint8Array | undefined}
745
+ */
746
+ current() {
747
+ try {
748
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
749
+ wasm.incrserver_current(retptr, this.__wbg_ptr);
750
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
751
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
752
+ let v1;
753
+ if (r0 !== 0) {
754
+ v1 = getArrayU8FromWasm0(r0, r1).slice();
755
+ wasm.__wbindgen_export4(r0, r1 * 1, 1);
756
+ }
757
+ return v1;
758
+ } finally {
759
+ wasm.__wbindgen_add_to_stack_pointer(16);
760
+ }
761
+ }
762
+ reset() {
763
+ wasm.incrserver_reset(this.__wbg_ptr);
764
+ }
765
+ };
766
+ if (Symbol.dispose) IncrServer.prototype[Symbol.dispose] = IncrServer.prototype.free;
767
+ ProxyContext = class _ProxyContext {
768
+ static __wrap(ptr) {
769
+ ptr = ptr >>> 0;
770
+ const obj = Object.create(_ProxyContext.prototype);
771
+ obj.__wbg_ptr = ptr;
772
+ ProxyContextFinalization.register(obj, obj.__wbg_ptr, obj);
773
+ return obj;
774
+ }
775
+ __destroy_into_raw() {
776
+ const ptr = this.__wbg_ptr;
777
+ this.__wbg_ptr = 0;
778
+ ProxyContextFinalization.unregister(this);
779
+ return ptr;
780
+ }
781
+ free() {
782
+ const ptr = this.__destroy_into_raw();
783
+ wasm.__wbg_proxycontext_free(ptr, 0);
784
+ }
785
+ /**
786
+ * Creates a new `ProxyContext` instance.
787
+ * @param {any} context
788
+ */
789
+ constructor(context) {
790
+ const ret = wasm.proxycontext_new(addHeapObject(context));
791
+ this.__wbg_ptr = ret >>> 0;
792
+ ProxyContextFinalization.register(this, this.__wbg_ptr, this);
793
+ return this;
794
+ }
795
+ /**
796
+ * Returns the JavaScript this.
797
+ * @returns {any}
798
+ */
799
+ get context() {
800
+ const ret = wasm.proxycontext_context(this.__wbg_ptr);
801
+ return takeObject(ret);
802
+ }
803
+ /**
804
+ * A convenience function to untar a tarball and call a callback for each
805
+ * entry.
806
+ * @param {Uint8Array} data
807
+ * @param {Function} cb
808
+ */
809
+ untar(data, cb) {
810
+ try {
811
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
812
+ const ptr0 = passArray8ToWasm0(data, wasm.__wbindgen_export);
813
+ const len0 = WASM_VECTOR_LEN;
814
+ wasm.proxycontext_untar(retptr, this.__wbg_ptr, ptr0, len0, addHeapObject(cb));
815
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
816
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
817
+ if (r1) {
818
+ throw takeObject(r0);
819
+ }
820
+ } finally {
821
+ wasm.__wbindgen_add_to_stack_pointer(16);
822
+ }
823
+ }
824
+ };
825
+ if (Symbol.dispose) ProxyContext.prototype[Symbol.dispose] = ProxyContext.prototype.free;
826
+ TypstCompileWorld = class _TypstCompileWorld {
827
+ static __wrap(ptr) {
828
+ ptr = ptr >>> 0;
829
+ const obj = Object.create(_TypstCompileWorld.prototype);
830
+ obj.__wbg_ptr = ptr;
831
+ TypstCompileWorldFinalization.register(obj, obj.__wbg_ptr, obj);
832
+ return obj;
833
+ }
834
+ __destroy_into_raw() {
835
+ const ptr = this.__wbg_ptr;
836
+ this.__wbg_ptr = 0;
837
+ TypstCompileWorldFinalization.unregister(this);
838
+ return ptr;
839
+ }
840
+ free() {
841
+ const ptr = this.__destroy_into_raw();
842
+ wasm.__wbg_typstcompileworld_free(ptr, 0);
843
+ }
844
+ /**
845
+ * @param {number} kind
846
+ * @param {number} diagnostics_format
847
+ * @returns {any}
848
+ */
849
+ compile(kind, diagnostics_format) {
850
+ try {
851
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
852
+ wasm.typstcompileworld_compile(retptr, this.__wbg_ptr, kind, diagnostics_format);
853
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
854
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
855
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
856
+ if (r2) {
857
+ throw takeObject(r1);
858
+ }
859
+ return takeObject(r0);
860
+ } finally {
861
+ wasm.__wbindgen_add_to_stack_pointer(16);
862
+ }
863
+ }
864
+ /**
865
+ * @param {number} kind
866
+ * @returns {string | undefined}
867
+ */
868
+ title(kind) {
869
+ try {
870
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
871
+ wasm.typstcompileworld_title(retptr, this.__wbg_ptr, kind);
872
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
873
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
874
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
875
+ var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
876
+ if (r3) {
877
+ throw takeObject(r2);
878
+ }
879
+ let v1;
880
+ if (r0 !== 0) {
881
+ v1 = getStringFromWasm0(r0, r1).slice();
882
+ wasm.__wbindgen_export4(r0, r1 * 1, 1);
883
+ }
884
+ return v1;
885
+ } finally {
886
+ wasm.__wbindgen_add_to_stack_pointer(16);
887
+ }
888
+ }
889
+ /**
890
+ * @param {number} fmt
891
+ * @param {number} diagnostics_format
892
+ * @returns {any}
893
+ */
894
+ get_artifact(fmt, diagnostics_format) {
895
+ try {
896
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
897
+ wasm.typstcompileworld_get_artifact(retptr, this.__wbg_ptr, fmt, diagnostics_format);
898
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
899
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
900
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
901
+ if (r2) {
902
+ throw takeObject(r1);
903
+ }
904
+ return takeObject(r0);
905
+ } finally {
906
+ wasm.__wbindgen_add_to_stack_pointer(16);
907
+ }
908
+ }
909
+ /**
910
+ * @param {number} kind
911
+ * @param {string} selector
912
+ * @param {string | null} [field]
913
+ * @returns {string}
914
+ */
915
+ query(kind, selector, field) {
916
+ let deferred4_0;
917
+ let deferred4_1;
918
+ try {
919
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
920
+ const ptr0 = passStringToWasm0(selector, wasm.__wbindgen_export, wasm.__wbindgen_export2);
921
+ const len0 = WASM_VECTOR_LEN;
922
+ var ptr1 = isLikeNone(field) ? 0 : passStringToWasm0(field, wasm.__wbindgen_export, wasm.__wbindgen_export2);
923
+ var len1 = WASM_VECTOR_LEN;
924
+ wasm.typstcompileworld_query(retptr, this.__wbg_ptr, kind, ptr0, len0, ptr1, len1);
925
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
926
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
927
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
928
+ var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
929
+ var ptr3 = r0;
930
+ var len3 = r1;
931
+ if (r3) {
932
+ ptr3 = 0;
933
+ len3 = 0;
934
+ throw takeObject(r2);
935
+ }
936
+ deferred4_0 = ptr3;
937
+ deferred4_1 = len3;
938
+ return getStringFromWasm0(ptr3, len3);
939
+ } finally {
940
+ wasm.__wbindgen_add_to_stack_pointer(16);
941
+ wasm.__wbindgen_export4(deferred4_0, deferred4_1, 1);
942
+ }
943
+ }
944
+ /**
945
+ * @param {IncrServer} state
946
+ * @param {number} diagnostics_format
947
+ * @returns {any}
948
+ */
949
+ incr_compile(state, diagnostics_format) {
950
+ try {
951
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
952
+ _assertClass(state, IncrServer);
953
+ wasm.typstcompileworld_incr_compile(retptr, this.__wbg_ptr, state.__wbg_ptr, diagnostics_format);
954
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
955
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
956
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
957
+ if (r2) {
958
+ throw takeObject(r1);
959
+ }
960
+ return takeObject(r0);
961
+ } finally {
962
+ wasm.__wbindgen_add_to_stack_pointer(16);
963
+ }
964
+ }
965
+ };
966
+ if (Symbol.dispose) TypstCompileWorld.prototype[Symbol.dispose] = TypstCompileWorld.prototype.free;
967
+ TypstCompiler = class _TypstCompiler {
968
+ static __wrap(ptr) {
969
+ ptr = ptr >>> 0;
970
+ const obj = Object.create(_TypstCompiler.prototype);
971
+ obj.__wbg_ptr = ptr;
972
+ TypstCompilerFinalization.register(obj, obj.__wbg_ptr, obj);
973
+ return obj;
974
+ }
975
+ __destroy_into_raw() {
976
+ const ptr = this.__wbg_ptr;
977
+ this.__wbg_ptr = 0;
978
+ TypstCompilerFinalization.unregister(this);
979
+ return ptr;
980
+ }
981
+ free() {
982
+ const ptr = this.__destroy_into_raw();
983
+ wasm.__wbg_typstcompiler_free(ptr, 0);
984
+ }
985
+ reset() {
986
+ try {
987
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
988
+ wasm.typstcompiler_reset(retptr, this.__wbg_ptr);
989
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
990
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
991
+ if (r1) {
992
+ throw takeObject(r0);
993
+ }
994
+ } finally {
995
+ wasm.__wbindgen_add_to_stack_pointer(16);
996
+ }
997
+ }
998
+ /**
999
+ * @param {TypstFontResolver} fonts
1000
+ */
1001
+ set_fonts(fonts) {
1002
+ try {
1003
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
1004
+ _assertClass(fonts, TypstFontResolver);
1005
+ wasm.typstcompiler_set_fonts(retptr, this.__wbg_ptr, fonts.__wbg_ptr);
1006
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
1007
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
1008
+ if (r1) {
1009
+ throw takeObject(r0);
1010
+ }
1011
+ } finally {
1012
+ wasm.__wbindgen_add_to_stack_pointer(16);
1013
+ }
1014
+ }
1015
+ /**
1016
+ * @param {any} inputs
1017
+ */
1018
+ set_inputs(inputs) {
1019
+ try {
1020
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
1021
+ wasm.typstcompiler_set_inputs(retptr, this.__wbg_ptr, addHeapObject(inputs));
1022
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
1023
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
1024
+ if (r1) {
1025
+ throw takeObject(r0);
1026
+ }
1027
+ } finally {
1028
+ wasm.__wbindgen_add_to_stack_pointer(16);
1029
+ }
1030
+ }
1031
+ /**
1032
+ * @param {string} path
1033
+ * @param {string} content
1034
+ * @returns {boolean}
1035
+ */
1036
+ add_source(path, content) {
1037
+ const ptr0 = passStringToWasm0(path, wasm.__wbindgen_export, wasm.__wbindgen_export2);
1038
+ const len0 = WASM_VECTOR_LEN;
1039
+ const ptr1 = passStringToWasm0(content, wasm.__wbindgen_export, wasm.__wbindgen_export2);
1040
+ const len1 = WASM_VECTOR_LEN;
1041
+ const ret = wasm.typstcompiler_add_source(this.__wbg_ptr, ptr0, len0, ptr1, len1);
1042
+ return ret !== 0;
1043
+ }
1044
+ /**
1045
+ * @param {string} path
1046
+ * @param {Uint8Array} content
1047
+ * @returns {boolean}
1048
+ */
1049
+ map_shadow(path, content) {
1050
+ const ptr0 = passStringToWasm0(path, wasm.__wbindgen_export, wasm.__wbindgen_export2);
1051
+ const len0 = WASM_VECTOR_LEN;
1052
+ const ptr1 = passArray8ToWasm0(content, wasm.__wbindgen_export);
1053
+ const len1 = WASM_VECTOR_LEN;
1054
+ const ret = wasm.typstcompiler_map_shadow(this.__wbg_ptr, ptr0, len0, ptr1, len1);
1055
+ return ret !== 0;
1056
+ }
1057
+ /**
1058
+ * @param {string} path
1059
+ * @returns {boolean}
1060
+ */
1061
+ unmap_shadow(path) {
1062
+ const ptr0 = passStringToWasm0(path, wasm.__wbindgen_export, wasm.__wbindgen_export2);
1063
+ const len0 = WASM_VECTOR_LEN;
1064
+ const ret = wasm.typstcompiler_unmap_shadow(this.__wbg_ptr, ptr0, len0);
1065
+ return ret !== 0;
1066
+ }
1067
+ reset_shadow() {
1068
+ wasm.typstcompiler_reset_shadow(this.__wbg_ptr);
1069
+ }
1070
+ /**
1071
+ * @returns {string[]}
1072
+ */
1073
+ get_loaded_fonts() {
1074
+ try {
1075
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
1076
+ wasm.typstcompiler_get_loaded_fonts(retptr, this.__wbg_ptr);
1077
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
1078
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
1079
+ var v1 = getArrayJsValueFromWasm0(r0, r1).slice();
1080
+ wasm.__wbindgen_export4(r0, r1 * 4, 4);
1081
+ return v1;
1082
+ } finally {
1083
+ wasm.__wbindgen_add_to_stack_pointer(16);
1084
+ }
1085
+ }
1086
+ /**
1087
+ * @param {string} main_file_path
1088
+ * @returns {string}
1089
+ */
1090
+ get_ast(main_file_path) {
1091
+ let deferred3_0;
1092
+ let deferred3_1;
1093
+ try {
1094
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
1095
+ const ptr0 = passStringToWasm0(main_file_path, wasm.__wbindgen_export, wasm.__wbindgen_export2);
1096
+ const len0 = WASM_VECTOR_LEN;
1097
+ wasm.typstcompiler_get_ast(retptr, this.__wbg_ptr, ptr0, len0);
1098
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
1099
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
1100
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
1101
+ var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
1102
+ var ptr2 = r0;
1103
+ var len2 = r1;
1104
+ if (r3) {
1105
+ ptr2 = 0;
1106
+ len2 = 0;
1107
+ throw takeObject(r2);
1108
+ }
1109
+ deferred3_0 = ptr2;
1110
+ deferred3_1 = len2;
1111
+ return getStringFromWasm0(ptr2, len2);
1112
+ } finally {
1113
+ wasm.__wbindgen_add_to_stack_pointer(16);
1114
+ wasm.__wbindgen_export4(deferred3_0, deferred3_1, 1);
1115
+ }
1116
+ }
1117
+ /**
1118
+ * @returns {any}
1119
+ */
1120
+ get_semantic_token_legend() {
1121
+ try {
1122
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
1123
+ wasm.typstcompiler_get_semantic_token_legend(retptr, this.__wbg_ptr);
1124
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
1125
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
1126
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
1127
+ if (r2) {
1128
+ throw takeObject(r1);
1129
+ }
1130
+ return takeObject(r0);
1131
+ } finally {
1132
+ wasm.__wbindgen_add_to_stack_pointer(16);
1133
+ }
1134
+ }
1135
+ /**
1136
+ * @param {string} offset_encoding
1137
+ * @param {string | null} [file_path]
1138
+ * @param {string | null} [result_id]
1139
+ * @returns {object}
1140
+ */
1141
+ get_semantic_tokens(offset_encoding, file_path, result_id) {
1142
+ try {
1143
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
1144
+ const ptr0 = passStringToWasm0(offset_encoding, wasm.__wbindgen_export, wasm.__wbindgen_export2);
1145
+ const len0 = WASM_VECTOR_LEN;
1146
+ var ptr1 = isLikeNone(file_path) ? 0 : passStringToWasm0(file_path, wasm.__wbindgen_export, wasm.__wbindgen_export2);
1147
+ var len1 = WASM_VECTOR_LEN;
1148
+ var ptr2 = isLikeNone(result_id) ? 0 : passStringToWasm0(result_id, wasm.__wbindgen_export, wasm.__wbindgen_export2);
1149
+ var len2 = WASM_VECTOR_LEN;
1150
+ wasm.typstcompiler_get_semantic_tokens(retptr, this.__wbg_ptr, ptr0, len0, ptr1, len1, ptr2, len2);
1151
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
1152
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
1153
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
1154
+ if (r2) {
1155
+ throw takeObject(r1);
1156
+ }
1157
+ return takeObject(r0);
1158
+ } finally {
1159
+ wasm.__wbindgen_add_to_stack_pointer(16);
1160
+ }
1161
+ }
1162
+ /**
1163
+ * @param {string | null} [root]
1164
+ * @param {string | null} [main_file_path]
1165
+ * @param {(Array<any>)[] | null} [inputs]
1166
+ * @returns {TypstCompileWorld}
1167
+ */
1168
+ snapshot(root, main_file_path, inputs) {
1169
+ try {
1170
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
1171
+ var ptr0 = isLikeNone(root) ? 0 : passStringToWasm0(root, wasm.__wbindgen_export, wasm.__wbindgen_export2);
1172
+ var len0 = WASM_VECTOR_LEN;
1173
+ var ptr1 = isLikeNone(main_file_path) ? 0 : passStringToWasm0(main_file_path, wasm.__wbindgen_export, wasm.__wbindgen_export2);
1174
+ var len1 = WASM_VECTOR_LEN;
1175
+ var ptr2 = isLikeNone(inputs) ? 0 : passArrayJsValueToWasm0(inputs, wasm.__wbindgen_export);
1176
+ var len2 = WASM_VECTOR_LEN;
1177
+ wasm.typstcompiler_snapshot(retptr, this.__wbg_ptr, ptr0, len0, ptr1, len1, ptr2, len2);
1178
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
1179
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
1180
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
1181
+ if (r2) {
1182
+ throw takeObject(r1);
1183
+ }
1184
+ return TypstCompileWorld.__wrap(r0);
1185
+ } finally {
1186
+ wasm.__wbindgen_add_to_stack_pointer(16);
1187
+ }
1188
+ }
1189
+ /**
1190
+ * @param {string} fmt
1191
+ * @param {number} diagnostics_format
1192
+ * @returns {any}
1193
+ */
1194
+ get_artifact(fmt, diagnostics_format) {
1195
+ try {
1196
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
1197
+ const ptr0 = passStringToWasm0(fmt, wasm.__wbindgen_export, wasm.__wbindgen_export2);
1198
+ const len0 = WASM_VECTOR_LEN;
1199
+ wasm.typstcompiler_get_artifact(retptr, this.__wbg_ptr, ptr0, len0, diagnostics_format);
1200
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
1201
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
1202
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
1203
+ if (r2) {
1204
+ throw takeObject(r1);
1205
+ }
1206
+ return takeObject(r0);
1207
+ } finally {
1208
+ wasm.__wbindgen_add_to_stack_pointer(16);
1209
+ }
1210
+ }
1211
+ /**
1212
+ * @param {string | null | undefined} main_file_path
1213
+ * @param {(Array<any>)[] | null | undefined} inputs
1214
+ * @param {string} fmt
1215
+ * @param {number} diagnostics_format
1216
+ * @returns {any}
1217
+ */
1218
+ compile(main_file_path, inputs, fmt, diagnostics_format) {
1219
+ try {
1220
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
1221
+ var ptr0 = isLikeNone(main_file_path) ? 0 : passStringToWasm0(main_file_path, wasm.__wbindgen_export, wasm.__wbindgen_export2);
1222
+ var len0 = WASM_VECTOR_LEN;
1223
+ var ptr1 = isLikeNone(inputs) ? 0 : passArrayJsValueToWasm0(inputs, wasm.__wbindgen_export);
1224
+ var len1 = WASM_VECTOR_LEN;
1225
+ const ptr2 = passStringToWasm0(fmt, wasm.__wbindgen_export, wasm.__wbindgen_export2);
1226
+ const len2 = WASM_VECTOR_LEN;
1227
+ wasm.typstcompiler_compile(retptr, this.__wbg_ptr, ptr0, len0, ptr1, len1, ptr2, len2, diagnostics_format);
1228
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
1229
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
1230
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
1231
+ if (r2) {
1232
+ throw takeObject(r1);
1233
+ }
1234
+ return takeObject(r0);
1235
+ } finally {
1236
+ wasm.__wbindgen_add_to_stack_pointer(16);
1237
+ }
1238
+ }
1239
+ /**
1240
+ * @param {string} main_file_path
1241
+ * @param {(Array<any>)[] | null | undefined} inputs
1242
+ * @param {string} selector
1243
+ * @param {string | null} [field]
1244
+ * @returns {string}
1245
+ */
1246
+ query(main_file_path, inputs, selector, field) {
1247
+ let deferred6_0;
1248
+ let deferred6_1;
1249
+ try {
1250
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
1251
+ const ptr0 = passStringToWasm0(main_file_path, wasm.__wbindgen_export, wasm.__wbindgen_export2);
1252
+ const len0 = WASM_VECTOR_LEN;
1253
+ var ptr1 = isLikeNone(inputs) ? 0 : passArrayJsValueToWasm0(inputs, wasm.__wbindgen_export);
1254
+ var len1 = WASM_VECTOR_LEN;
1255
+ const ptr2 = passStringToWasm0(selector, wasm.__wbindgen_export, wasm.__wbindgen_export2);
1256
+ const len2 = WASM_VECTOR_LEN;
1257
+ var ptr3 = isLikeNone(field) ? 0 : passStringToWasm0(field, wasm.__wbindgen_export, wasm.__wbindgen_export2);
1258
+ var len3 = WASM_VECTOR_LEN;
1259
+ wasm.typstcompiler_query(retptr, this.__wbg_ptr, ptr0, len0, ptr1, len1, ptr2, len2, ptr3, len3);
1260
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
1261
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
1262
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
1263
+ var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
1264
+ var ptr5 = r0;
1265
+ var len5 = r1;
1266
+ if (r3) {
1267
+ ptr5 = 0;
1268
+ len5 = 0;
1269
+ throw takeObject(r2);
1270
+ }
1271
+ deferred6_0 = ptr5;
1272
+ deferred6_1 = len5;
1273
+ return getStringFromWasm0(ptr5, len5);
1274
+ } finally {
1275
+ wasm.__wbindgen_add_to_stack_pointer(16);
1276
+ wasm.__wbindgen_export4(deferred6_0, deferred6_1, 1);
1277
+ }
1278
+ }
1279
+ /**
1280
+ * @returns {IncrServer}
1281
+ */
1282
+ create_incr_server() {
1283
+ try {
1284
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
1285
+ wasm.typstcompiler_create_incr_server(retptr, this.__wbg_ptr);
1286
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
1287
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
1288
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
1289
+ if (r2) {
1290
+ throw takeObject(r1);
1291
+ }
1292
+ return IncrServer.__wrap(r0);
1293
+ } finally {
1294
+ wasm.__wbindgen_add_to_stack_pointer(16);
1295
+ }
1296
+ }
1297
+ /**
1298
+ * @param {string} main_file_path
1299
+ * @param {(Array<any>)[] | null | undefined} inputs
1300
+ * @param {IncrServer} state
1301
+ * @param {number} diagnostics_format
1302
+ * @returns {any}
1303
+ */
1304
+ incr_compile(main_file_path, inputs, state, diagnostics_format) {
1305
+ try {
1306
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
1307
+ const ptr0 = passStringToWasm0(main_file_path, wasm.__wbindgen_export, wasm.__wbindgen_export2);
1308
+ const len0 = WASM_VECTOR_LEN;
1309
+ var ptr1 = isLikeNone(inputs) ? 0 : passArrayJsValueToWasm0(inputs, wasm.__wbindgen_export);
1310
+ var len1 = WASM_VECTOR_LEN;
1311
+ _assertClass(state, IncrServer);
1312
+ wasm.typstcompiler_incr_compile(retptr, this.__wbg_ptr, ptr0, len0, ptr1, len1, state.__wbg_ptr, diagnostics_format);
1313
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
1314
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
1315
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
1316
+ if (r2) {
1317
+ throw takeObject(r1);
1318
+ }
1319
+ return takeObject(r0);
1320
+ } finally {
1321
+ wasm.__wbindgen_add_to_stack_pointer(16);
1322
+ }
1323
+ }
1324
+ };
1325
+ if (Symbol.dispose) TypstCompiler.prototype[Symbol.dispose] = TypstCompiler.prototype.free;
1326
+ TypstCompilerBuilder = class {
1327
+ __destroy_into_raw() {
1328
+ const ptr = this.__wbg_ptr;
1329
+ this.__wbg_ptr = 0;
1330
+ TypstCompilerBuilderFinalization.unregister(this);
1331
+ return ptr;
1332
+ }
1333
+ free() {
1334
+ const ptr = this.__destroy_into_raw();
1335
+ wasm.__wbg_typstcompilerbuilder_free(ptr, 0);
1336
+ }
1337
+ constructor() {
1338
+ try {
1339
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
1340
+ wasm.typstcompilerbuilder_new(retptr);
1341
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
1342
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
1343
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
1344
+ if (r2) {
1345
+ throw takeObject(r1);
1346
+ }
1347
+ this.__wbg_ptr = r0 >>> 0;
1348
+ TypstCompilerBuilderFinalization.register(this, this.__wbg_ptr, this);
1349
+ return this;
1350
+ } finally {
1351
+ wasm.__wbindgen_add_to_stack_pointer(16);
1352
+ }
1353
+ }
1354
+ set_dummy_access_model() {
1355
+ try {
1356
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
1357
+ wasm.typstcompilerbuilder_set_dummy_access_model(retptr, this.__wbg_ptr);
1358
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
1359
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
1360
+ if (r1) {
1361
+ throw takeObject(r0);
1362
+ }
1363
+ } finally {
1364
+ wasm.__wbindgen_add_to_stack_pointer(16);
1365
+ }
1366
+ }
1367
+ /**
1368
+ * @param {any} context
1369
+ * @param {Function} mtime_fn
1370
+ * @param {Function} is_file_fn
1371
+ * @param {Function} real_path_fn
1372
+ * @param {Function} read_all_fn
1373
+ * @returns {Promise<void>}
1374
+ */
1375
+ set_access_model(context, mtime_fn, is_file_fn, real_path_fn, read_all_fn) {
1376
+ const ret = wasm.typstcompilerbuilder_set_access_model(this.__wbg_ptr, addHeapObject(context), addHeapObject(mtime_fn), addHeapObject(is_file_fn), addHeapObject(real_path_fn), addHeapObject(read_all_fn));
1377
+ return takeObject(ret);
1378
+ }
1379
+ /**
1380
+ * @param {any} context
1381
+ * @param {Function} real_resolve_fn
1382
+ * @returns {Promise<void>}
1383
+ */
1384
+ set_package_registry(context, real_resolve_fn) {
1385
+ const ret = wasm.typstcompilerbuilder_set_package_registry(this.__wbg_ptr, addHeapObject(context), addHeapObject(real_resolve_fn));
1386
+ return takeObject(ret);
1387
+ }
1388
+ /**
1389
+ * @param {Uint8Array} data
1390
+ * @returns {Promise<void>}
1391
+ */
1392
+ add_raw_font(data) {
1393
+ const ret = wasm.typstcompilerbuilder_add_raw_font(this.__wbg_ptr, addHeapObject(data));
1394
+ return takeObject(ret);
1395
+ }
1396
+ /**
1397
+ * @param {any} font
1398
+ * @param {Function} blob
1399
+ * @returns {Promise<void>}
1400
+ */
1401
+ add_lazy_font(font, blob) {
1402
+ const ret = wasm.typstcompilerbuilder_add_lazy_font(this.__wbg_ptr, addHeapObject(font), addHeapObject(blob));
1403
+ return takeObject(ret);
1404
+ }
1405
+ /**
1406
+ * @returns {Promise<TypstCompiler>}
1407
+ */
1408
+ build() {
1409
+ const ptr = this.__destroy_into_raw();
1410
+ const ret = wasm.typstcompilerbuilder_build(ptr);
1411
+ return takeObject(ret);
1412
+ }
1413
+ };
1414
+ if (Symbol.dispose) TypstCompilerBuilder.prototype[Symbol.dispose] = TypstCompilerBuilder.prototype.free;
1415
+ TypstFontResolver = class _TypstFontResolver {
1416
+ static __wrap(ptr) {
1417
+ ptr = ptr >>> 0;
1418
+ const obj = Object.create(_TypstFontResolver.prototype);
1419
+ obj.__wbg_ptr = ptr;
1420
+ TypstFontResolverFinalization.register(obj, obj.__wbg_ptr, obj);
1421
+ return obj;
1422
+ }
1423
+ __destroy_into_raw() {
1424
+ const ptr = this.__wbg_ptr;
1425
+ this.__wbg_ptr = 0;
1426
+ TypstFontResolverFinalization.unregister(this);
1427
+ return ptr;
1428
+ }
1429
+ free() {
1430
+ const ptr = this.__destroy_into_raw();
1431
+ wasm.__wbg_typstfontresolver_free(ptr, 0);
1432
+ }
1433
+ };
1434
+ if (Symbol.dispose) TypstFontResolver.prototype[Symbol.dispose] = TypstFontResolver.prototype.free;
1435
+ TypstFontResolverBuilder = class {
1436
+ __destroy_into_raw() {
1437
+ const ptr = this.__wbg_ptr;
1438
+ this.__wbg_ptr = 0;
1439
+ TypstFontResolverBuilderFinalization.unregister(this);
1440
+ return ptr;
1441
+ }
1442
+ free() {
1443
+ const ptr = this.__destroy_into_raw();
1444
+ wasm.__wbg_typstfontresolverbuilder_free(ptr, 0);
1445
+ }
1446
+ constructor() {
1447
+ try {
1448
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
1449
+ wasm.typstfontresolverbuilder_new(retptr);
1450
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
1451
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
1452
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
1453
+ if (r2) {
1454
+ throw takeObject(r1);
1455
+ }
1456
+ this.__wbg_ptr = r0 >>> 0;
1457
+ TypstFontResolverBuilderFinalization.register(this, this.__wbg_ptr, this);
1458
+ return this;
1459
+ } finally {
1460
+ wasm.__wbindgen_add_to_stack_pointer(16);
1461
+ }
1462
+ }
1463
+ /**
1464
+ * @param {Uint8Array} buffer
1465
+ * @returns {any}
1466
+ */
1467
+ get_font_info(buffer) {
1468
+ try {
1469
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
1470
+ wasm.typstfontresolverbuilder_get_font_info(retptr, this.__wbg_ptr, addHeapObject(buffer));
1471
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
1472
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
1473
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
1474
+ if (r2) {
1475
+ throw takeObject(r1);
1476
+ }
1477
+ return takeObject(r0);
1478
+ } finally {
1479
+ wasm.__wbindgen_add_to_stack_pointer(16);
1480
+ }
1481
+ }
1482
+ /**
1483
+ * Adds font data to the searcher.
1484
+ * @param {Uint8Array} buffer
1485
+ */
1486
+ add_raw_font(buffer) {
1487
+ try {
1488
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
1489
+ wasm.typstfontresolverbuilder_add_raw_font(retptr, this.__wbg_ptr, addHeapObject(buffer));
1490
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
1491
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
1492
+ if (r1) {
1493
+ throw takeObject(r0);
1494
+ }
1495
+ } finally {
1496
+ wasm.__wbindgen_add_to_stack_pointer(16);
1497
+ }
1498
+ }
1499
+ /**
1500
+ * Adds callback that loads font data lazily to the searcher.
1501
+ * `get_font_info` can be used to get the font info.
1502
+ * @param {any} font
1503
+ * @param {Function} blob
1504
+ */
1505
+ add_lazy_font(font, blob) {
1506
+ try {
1507
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
1508
+ wasm.typstfontresolverbuilder_add_lazy_font(retptr, this.__wbg_ptr, addHeapObject(font), addHeapObject(blob));
1509
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
1510
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
1511
+ if (r1) {
1512
+ throw takeObject(r0);
1513
+ }
1514
+ } finally {
1515
+ wasm.__wbindgen_add_to_stack_pointer(16);
1516
+ }
1517
+ }
1518
+ /**
1519
+ * @returns {Promise<TypstFontResolver>}
1520
+ */
1521
+ build() {
1522
+ const ptr = this.__destroy_into_raw();
1523
+ const ret = wasm.typstfontresolverbuilder_build(ptr);
1524
+ return takeObject(ret);
1525
+ }
1526
+ };
1527
+ if (Symbol.dispose) TypstFontResolverBuilder.prototype[Symbol.dispose] = TypstFontResolverBuilder.prototype.free;
1528
+ EXPECTED_RESPONSE_TYPES = /* @__PURE__ */ new Set(["basic", "cors", "default"]);
1529
+ typst_ts_web_compiler_default = __wbg_init;
1530
+ importWasmModule = async function(wasm_name, url) {
1531
+ throw new Error("Cannot import wasm module without importer: " + wasm_name + " " + url);
1532
+ };
1533
+ }
1534
+ });
1535
+
1536
+ // ../../node_modules/.bun/@myriaddreamin+typst-ts-web-compiler@0.7.0-rc2/node_modules/@myriaddreamin/typst-ts-web-compiler/pkg/wasm-pack-shim.mjs
1537
+ var wasm_pack_shim_exports = {};
1538
+ __export(wasm_pack_shim_exports, {
1539
+ IncrServer: () => IncrServer,
1540
+ ProxyContext: () => ProxyContext,
1541
+ TypstCompileWorld: () => TypstCompileWorld,
1542
+ TypstCompiler: () => TypstCompiler,
1543
+ TypstCompilerBuilder: () => TypstCompilerBuilder,
1544
+ TypstFontResolver: () => TypstFontResolver,
1545
+ TypstFontResolverBuilder: () => TypstFontResolverBuilder,
1546
+ default: () => wasm_pack_shim_default,
1547
+ get_font_info: () => get_font_info,
1548
+ initSync: () => initSync,
1549
+ setImportWasmModule: () => setImportWasmModule
1550
+ });
1551
+ var wasm_pack_shim_default, nodeJsImportWasmModule, isNode;
1552
+ var init_wasm_pack_shim = __esm({
1553
+ "../../node_modules/.bun/@myriaddreamin+typst-ts-web-compiler@0.7.0-rc2/node_modules/@myriaddreamin/typst-ts-web-compiler/pkg/wasm-pack-shim.mjs"() {
1554
+ "use strict";
1555
+ init_typst_ts_web_compiler();
1556
+ init_typst_ts_web_compiler();
1557
+ init_typst_ts_web_compiler();
1558
+ wasm_pack_shim_default = typst_ts_web_compiler_default;
1559
+ nodeJsImportWasmModule = async function(wasm_name, url) {
1560
+ const escapeImport = new Function("m", "return import(m)");
1561
+ const { readFileSync } = await escapeImport("fs");
1562
+ const wasmPath = new URL(wasm_name, url);
1563
+ return await readFileSync(wasmPath).buffer;
1564
+ };
1565
+ isNode = typeof process !== "undefined" && process.versions != null && process.versions.node != null;
1566
+ if (isNode) {
1567
+ setImportWasmModule(nodeJsImportWasmModule);
1568
+ }
1569
+ }
1570
+ });
1571
+
1572
+ // ../../node_modules/.bun/@myriaddreamin+typst.ts@0.7.0-rc2+5e675a3c06b42b50/node_modules/@myriaddreamin/typst.ts/dist/esm/init.mjs
1573
+ var ComponentBuilder = class {
1574
+ constructor() {
1575
+ __publicField(this, "loadedFonts", /* @__PURE__ */ new Set());
1576
+ __publicField(this, "fetcher", fetch);
1577
+ }
1578
+ setFetcher(fetcher) {
1579
+ this.fetcher = fetcher;
1580
+ }
1581
+ async loadFonts(builder, fonts) {
1582
+ const escapeImport = new Function("m", "return import(m)");
1583
+ const fetcher = this.fetcher || (this.fetcher = await (async function() {
1584
+ const { fetchBuilder, FileSystemCache } = await escapeImport("node-fetch-cache");
1585
+ const cache = new FileSystemCache({
1586
+ /// By default, we don't have a complicated cache policy.
1587
+ cacheDirectory: ".cache/typst/fonts"
1588
+ });
1589
+ const cachedFetcher = fetchBuilder.withCache(cache);
1590
+ return function(input, init) {
1591
+ const timeout = setTimeout(() => {
1592
+ console.warn("font fetching is stucking:", input);
1593
+ }, 15e3);
1594
+ return cachedFetcher(input, init).finally(() => {
1595
+ clearTimeout(timeout);
1596
+ });
1597
+ };
1598
+ })());
1599
+ const fontsToLoad = fonts.filter((font) => {
1600
+ if (font instanceof Uint8Array || typeof font === "object" && "info" in font) {
1601
+ return true;
1602
+ }
1603
+ if (this.loadedFonts.has(font)) {
1604
+ return false;
1605
+ }
1606
+ this.loadedFonts.add(font);
1607
+ return true;
1608
+ });
1609
+ const fontLists = await Promise.all(fontsToLoad.map(async (font) => {
1610
+ if (font instanceof Uint8Array) {
1611
+ await builder.add_raw_font(font);
1612
+ return;
1613
+ }
1614
+ if (typeof font === "object" && "info" in font) {
1615
+ await builder.add_lazy_font(font, "blob" in font ? font.blob : loadFontSync(font));
1616
+ return;
1617
+ }
1618
+ return new Uint8Array(await (await fetcher(font)).arrayBuffer());
1619
+ }));
1620
+ for (const font of fontLists) {
1621
+ if (!font) {
1622
+ continue;
1623
+ }
1624
+ await builder.add_raw_font(font);
1625
+ }
1626
+ }
1627
+ async build(options, builder, hooks) {
1628
+ const buildCtx = { ref: this, builder, hooks };
1629
+ for (const fn of options?.beforeBuild ?? []) {
1630
+ await fn(void 0, buildCtx);
1631
+ }
1632
+ if (hooks.latelyBuild) {
1633
+ hooks.latelyBuild(buildCtx);
1634
+ }
1635
+ return await builder.build();
1636
+ }
1637
+ };
1638
+ async function buildComponent(options, gModule, Builder, hooks) {
1639
+ await gModule.init(options?.getModule?.());
1640
+ return await new ComponentBuilder().build(options, new Builder(), hooks);
1641
+ }
1642
+ function loadFontSync(font) {
1643
+ return () => {
1644
+ const xhr = new XMLHttpRequest();
1645
+ xhr.overrideMimeType("text/plain; charset=x-user-defined");
1646
+ xhr.open("GET", font.url, false);
1647
+ xhr.send(null);
1648
+ if (xhr.status === 200 && (xhr.response instanceof String || typeof xhr.response === "string")) {
1649
+ return Uint8Array.from(xhr.response, (c) => c.charCodeAt(0));
1650
+ }
1651
+ return new Uint8Array();
1652
+ };
1653
+ }
1654
+
1655
+ // ../../node_modules/.bun/@myriaddreamin+typst.ts@0.7.0-rc2+5e675a3c06b42b50/node_modules/@myriaddreamin/typst.ts/dist/esm/internal.types.mjs
1656
+ var kObject = /* @__PURE__ */ Symbol.for("reflexo-obj");
1657
+ var TypstDefaultParams;
1658
+ (function(TypstDefaultParams2) {
1659
+ TypstDefaultParams2[TypstDefaultParams2["PIXEL_PER_PT"] = 3] = "PIXEL_PER_PT";
1660
+ })(TypstDefaultParams || (TypstDefaultParams = {}));
1661
+
1662
+ // ../../node_modules/.bun/@myriaddreamin+typst.ts@0.7.0-rc2+5e675a3c06b42b50/node_modules/@myriaddreamin/typst.ts/dist/esm/options.init.mjs
1663
+ var _textFonts = [
1664
+ "DejaVuSansMono-Bold.ttf",
1665
+ "DejaVuSansMono-BoldOblique.ttf",
1666
+ "DejaVuSansMono-Oblique.ttf",
1667
+ "DejaVuSansMono.ttf",
1668
+ "LibertinusSerif-Bold.otf",
1669
+ "LibertinusSerif-BoldItalic.otf",
1670
+ "LibertinusSerif-Italic.otf",
1671
+ "LibertinusSerif-Regular.otf",
1672
+ "LibertinusSerif-Semibold.otf",
1673
+ "LibertinusSerif-SemiboldItalic.otf",
1674
+ "NewCM10-Bold.otf",
1675
+ "NewCM10-BoldItalic.otf",
1676
+ "NewCM10-Italic.otf",
1677
+ "NewCM10-Regular.otf",
1678
+ "NewCMMath-Bold.otf",
1679
+ "NewCMMath-Book.otf",
1680
+ "NewCMMath-Regular.otf"
1681
+ ];
1682
+ var _cjkFonts = [
1683
+ "InriaSerif-Bold.ttf",
1684
+ "InriaSerif-BoldItalic.ttf",
1685
+ "InriaSerif-Italic.ttf",
1686
+ "InriaSerif-Regular.ttf",
1687
+ "Roboto-Regular.ttf",
1688
+ "NotoSerifCJKsc-Regular.otf"
1689
+ ];
1690
+ var _emojiFonts = ["TwitterColorEmoji.ttf", "NotoColorEmoji-Regular-COLR.subset.ttf"];
1691
+ function _resolveAssets(options) {
1692
+ const fonts = [];
1693
+ if (options && options?.assets !== false && options?.assets?.length && options?.assets?.length > 0) {
1694
+ let defaultPrefix = {
1695
+ text: "https://cdn.jsdelivr.net/gh/typst/typst-assets@v0.13.1/files/fonts/",
1696
+ _: "https://cdn.jsdelivr.net/gh/typst/typst-dev-assets@v0.13.1/files/fonts/"
1697
+ };
1698
+ let assetUrlPrefix = options.assetUrlPrefix ?? defaultPrefix;
1699
+ if (typeof assetUrlPrefix === "string") {
1700
+ assetUrlPrefix = { _: assetUrlPrefix };
1701
+ } else {
1702
+ assetUrlPrefix = { ...defaultPrefix, ...assetUrlPrefix };
1703
+ }
1704
+ for (const key of Object.keys(assetUrlPrefix)) {
1705
+ const u = assetUrlPrefix[key];
1706
+ if (u[u.length - 1] !== "/") {
1707
+ assetUrlPrefix[key] = u + "/";
1708
+ }
1709
+ }
1710
+ const prefix = (asset, f) => f.map((font) => (assetUrlPrefix[asset] || assetUrlPrefix["_"]) + font);
1711
+ for (const asset of options.assets) {
1712
+ switch (asset) {
1713
+ case "text":
1714
+ fonts.push(...prefix(asset, _textFonts));
1715
+ break;
1716
+ case "cjk":
1717
+ fonts.push(...prefix(asset, _cjkFonts));
1718
+ break;
1719
+ case "emoji":
1720
+ fonts.push(...prefix(asset, _emojiFonts));
1721
+ break;
1722
+ }
1723
+ }
1724
+ }
1725
+ return fonts;
1726
+ }
1727
+ function loadFonts(userFonts, options) {
1728
+ const assetFonts = _resolveAssets(options);
1729
+ const loader = async (_, { ref, builder }) => {
1730
+ if (options?.fetcher) {
1731
+ ref.setFetcher(options.fetcher);
1732
+ }
1733
+ await ref.loadFonts(builder, [...userFonts, ...assetFonts]);
1734
+ };
1735
+ loader._preloadRemoteFontOptions = options;
1736
+ loader._kind = "fontLoader";
1737
+ return loader;
1738
+ }
1739
+ function withPackageRegistry(packageRegistry2) {
1740
+ return async (_, { builder }) => {
1741
+ return new Promise((resolve) => {
1742
+ builder.set_package_registry(packageRegistry2, function(spec) {
1743
+ return packageRegistry2.resolve(spec, this);
1744
+ });
1745
+ resolve();
1746
+ });
1747
+ };
1748
+ }
1749
+ function withAccessModel(accessModel2) {
1750
+ return async (_, ctx) => {
1751
+ if (ctx.alreadySetAccessModel) {
1752
+ throw new Error(`already set some assess model before: ${ctx.alreadySetAccessModel.constructor?.name}(${ctx.alreadySetAccessModel})`);
1753
+ }
1754
+ ctx.alreadySetAccessModel = accessModel2;
1755
+ return new Promise((resolve) => {
1756
+ ctx.builder.set_access_model(accessModel2, (path) => {
1757
+ const lastModified = accessModel2.getMTime(path);
1758
+ if (lastModified) {
1759
+ return lastModified.getTime();
1760
+ }
1761
+ return 0;
1762
+ }, (path) => {
1763
+ return accessModel2.isFile(path) || false;
1764
+ }, (path) => {
1765
+ return accessModel2.getRealPath(path) || path;
1766
+ }, (path) => {
1767
+ return accessModel2.readAll(path);
1768
+ });
1769
+ resolve();
1770
+ });
1771
+ };
1772
+ }
1773
+
1774
+ // ../../node_modules/.bun/@myriaddreamin+typst.ts@0.7.0-rc2+5e675a3c06b42b50/node_modules/@myriaddreamin/typst.ts/dist/esm/wasm.mjs
1775
+ var once = (fn) => {
1776
+ let called = false;
1777
+ let res;
1778
+ return () => {
1779
+ if (called) {
1780
+ return res;
1781
+ }
1782
+ called = true;
1783
+ return res = fn();
1784
+ };
1785
+ };
1786
+ var LazyWasmModule = class {
1787
+ constructor(initFn) {
1788
+ __publicField(this, "wasmBin");
1789
+ __publicField(this, "initOnce");
1790
+ if (typeof initFn !== "function") {
1791
+ throw new Error("initFn is not a function");
1792
+ }
1793
+ this.initOnce = once(async () => {
1794
+ await initFn(this.wasmBin);
1795
+ });
1796
+ }
1797
+ async init(module) {
1798
+ this.wasmBin = module;
1799
+ await this.initOnce();
1800
+ }
1801
+ };
1802
+
1803
+ // ../../node_modules/.bun/@myriaddreamin+typst.ts@0.7.0-rc2+5e675a3c06b42b50/node_modules/@myriaddreamin/typst.ts/dist/esm/compiler.mjs
1804
+ var CompileFormatEnum;
1805
+ (function(CompileFormatEnum2) {
1806
+ CompileFormatEnum2[CompileFormatEnum2["vector"] = 0] = "vector";
1807
+ CompileFormatEnum2[CompileFormatEnum2["pdf"] = 1] = "pdf";
1808
+ CompileFormatEnum2[CompileFormatEnum2["_dummy"] = 2] = "_dummy";
1809
+ })(CompileFormatEnum || (CompileFormatEnum = {}));
1810
+ var _a;
1811
+ _a = kObject;
1812
+ var IncrementalServer = class {
1813
+ /**
1814
+ * @internal
1815
+ */
1816
+ constructor(s) {
1817
+ /**
1818
+ * @internal
1819
+ */
1820
+ __publicField(this, _a);
1821
+ this[kObject] = s;
1822
+ }
1823
+ /**
1824
+ * Reset the incremental server to the initial state.
1825
+ */
1826
+ reset() {
1827
+ this[kObject].reset();
1828
+ }
1829
+ /**
1830
+ * Return current result.
1831
+ */
1832
+ current() {
1833
+ return this[kObject].current();
1834
+ }
1835
+ /**
1836
+ * Also attach the debug info to the result.
1837
+ */
1838
+ setAttachDebugInfo(enable) {
1839
+ this[kObject].set_attach_debug_info(enable);
1840
+ }
1841
+ };
1842
+ var TypstFontResolverCons;
1843
+ /* @__PURE__ */ (function(TypstFontResolverCons2) {
1844
+ })(TypstFontResolverCons || (TypstFontResolverCons = {}));
1845
+ var _a2;
1846
+ _a2 = kObject;
1847
+ var TypstWorld = class {
1848
+ constructor(world) {
1849
+ __publicField(this, _a2);
1850
+ this[kObject] = world;
1851
+ }
1852
+ /**
1853
+ * Compile the paged document.
1854
+ *
1855
+ * @param {DiagnosticsFormat} format - The format of the diagnostics.
1856
+ * @returns {Promise<{ diagnostics?: DiagnosticsData[DiagnosticsFormat][] }>} - The result of the compilation.
1857
+ */
1858
+ compile(opts) {
1859
+ return this[kObject].compile(0, getDiagnosticsArg(opts?.diagnostics));
1860
+ }
1861
+ /**
1862
+ * Compile the paged document.
1863
+ *
1864
+ * @param {DiagnosticsFormat} format - The format of the diagnostics.
1865
+ * @returns {Promise<{ diagnostics?: DiagnosticsData[DiagnosticsFormat][] }>} - The result of the compilation.
1866
+ */
1867
+ compileHtml(opts) {
1868
+ return this[kObject].compile(1, getDiagnosticsArg(opts?.diagnostics));
1869
+ }
1870
+ /**
1871
+ * Runs query on the paged document.
1872
+ */
1873
+ async query(options) {
1874
+ return JSON.parse(this[kObject].query(0, options.selector, options.field));
1875
+ }
1876
+ /**
1877
+ * Get the title of the paged document.
1878
+ * Throw error if the world didn't compile the paged document.
1879
+ *
1880
+ * @returns {string | undefined} - The title of the paged document.
1881
+ */
1882
+ title() {
1883
+ return this[kObject].title(0);
1884
+ }
1885
+ /**
1886
+ * Export the paged document as vector format.
1887
+ *
1888
+ * @returns {Uint8Array | undefined} - The title of the paged document.
1889
+ */
1890
+ vector(opts) {
1891
+ return this[kObject].get_artifact(0, getDiagnosticsArg(opts?.diagnostics)) || {};
1892
+ }
1893
+ /**
1894
+ * Export the paged document to PDF.
1895
+ *
1896
+ * @returns {Uint8Array | undefined} - The title of the paged document.
1897
+ */
1898
+ pdf(opts) {
1899
+ return this[kObject].get_artifact(1, getDiagnosticsArg(opts?.diagnostics)) || {};
1900
+ }
1901
+ };
1902
+ var gCompilerModule = (module) => new LazyWasmModule(async (bin) => {
1903
+ return await module.default(bin);
1904
+ });
1905
+ function createTypstCompiler() {
1906
+ return new TypstCompilerDriver();
1907
+ }
1908
+ var _TypstCompilerDriver = class _TypstCompilerDriver {
1909
+ constructor() {
1910
+ __publicField(this, "compiler");
1911
+ __publicField(this, "compilerJs");
1912
+ }
1913
+ async init(options) {
1914
+ this.compilerJs = await (options?.getWrapper?.() || Promise.resolve().then(() => (init_wasm_pack_shim(), wasm_pack_shim_exports)));
1915
+ const TypstCompilerBuilder2 = this.compilerJs.TypstCompilerBuilder;
1916
+ const compilerOptions = { ...options || {} };
1917
+ const beforeBuild = compilerOptions.beforeBuild ?? (compilerOptions.beforeBuild = []);
1918
+ const hasPreloadRemoteFonts = beforeBuild.some((fn) => fn._preloadRemoteFontOptions !== void 0);
1919
+ const hasSpecifiedAssets = beforeBuild.some((fn) => fn._preloadRemoteFontOptions?.assets !== void 0);
1920
+ const hasDisableAssets = beforeBuild.some((fn) => fn._preloadRemoteFontOptions?.assets === false);
1921
+ if (!hasPreloadRemoteFonts || !hasSpecifiedAssets && !hasDisableAssets) {
1922
+ beforeBuild.push(loadFonts([], { assets: _TypstCompilerDriver.defaultAssets }));
1923
+ }
1924
+ const hasFontLoader = beforeBuild.some((fn) => fn._kind === "fontLoader");
1925
+ if (!hasFontLoader) {
1926
+ throw new Error("TypstCompiler: no font loader found, please use font loaders, e.g. loadFonts or preloadSystemFonts");
1927
+ }
1928
+ this.compiler = await buildComponent(options, gCompilerModule(this.compilerJs), TypstCompilerBuilder2, {});
1929
+ }
1930
+ setFonts(fonts) {
1931
+ this.compiler.set_fonts(fonts);
1932
+ }
1933
+ compile(options) {
1934
+ return new Promise((resolve) => {
1935
+ const world = this.compiler.snapshot(options.root, options.mainFilePath, convertInputs(options.inputs));
1936
+ if ("incrementalServer" in options) {
1937
+ resolve(world.incr_compile(options.incrementalServer[kObject], getDiagnosticsArg(options.diagnostics)));
1938
+ return;
1939
+ }
1940
+ resolve(world.get_artifact(options.format || CompileFormatEnum.vector, getDiagnosticsArg(options.diagnostics)));
1941
+ });
1942
+ }
1943
+ async runWithWorld(options, cb) {
1944
+ const world = this.compiler.snapshot(options.root, options.mainFilePath, convertInputs(options.inputs));
1945
+ let result = await cb(new TypstWorld(world));
1946
+ world.free();
1947
+ return result;
1948
+ }
1949
+ query(options) {
1950
+ return this.runWithWorld(options, async (world) => {
1951
+ return JSON.parse(await world.query(options));
1952
+ });
1953
+ }
1954
+ getSemanticTokenLegend() {
1955
+ return new Promise((resolve) => {
1956
+ resolve(this.compiler.get_semantic_token_legend());
1957
+ });
1958
+ }
1959
+ getSemanticTokens(opts) {
1960
+ return new Promise((resolve) => {
1961
+ this.compiler.reset();
1962
+ resolve(this.compiler.get_semantic_tokens(opts.offsetEncoding || "utf-16", opts.mainFilePath, opts.resultId));
1963
+ });
1964
+ }
1965
+ async withIncrementalServer(f) {
1966
+ const srv = new IncrementalServer(this.compiler.create_incr_server());
1967
+ try {
1968
+ return await f(srv);
1969
+ } finally {
1970
+ srv[kObject].free();
1971
+ }
1972
+ }
1973
+ async getAst(mainFilePath) {
1974
+ return this.compiler.get_ast(mainFilePath);
1975
+ }
1976
+ async reset() {
1977
+ await new Promise((resolve) => {
1978
+ this.compiler.reset();
1979
+ resolve(void 0);
1980
+ });
1981
+ }
1982
+ addSource(path, source) {
1983
+ if (arguments.length > 2) {
1984
+ throw new Error("use of addSource(path, source, isMain) is deprecated, please use addSource(path, source) instead");
1985
+ }
1986
+ this.compiler.add_source(path, source);
1987
+ }
1988
+ mapShadow(path, content) {
1989
+ this.compiler.map_shadow(path, content);
1990
+ }
1991
+ unmapShadow(path) {
1992
+ this.compiler.unmap_shadow(path);
1993
+ }
1994
+ resetShadow() {
1995
+ this.compiler.reset_shadow();
1996
+ }
1997
+ renderPageToCanvas() {
1998
+ throw new Error("Please use the api TypstRenderer.renderToCanvas in v0.4.0");
1999
+ }
2000
+ };
2001
+ __publicField(_TypstCompilerDriver, "defaultAssets", ["text"]);
2002
+ var TypstCompilerDriver = _TypstCompilerDriver;
2003
+ createTypstCompiler._impl = TypstCompilerDriver;
2004
+ function convertInputs(inputs) {
2005
+ return inputs ? Object.entries(inputs) : void 0;
2006
+ }
2007
+ function getDiagnosticsArg(diagnostics) {
2008
+ switch (diagnostics) {
2009
+ case "none":
2010
+ return 1;
2011
+ case "unix":
2012
+ return 2;
2013
+ case "full":
2014
+ default:
2015
+ return 3;
2016
+ }
2017
+ }
2018
+
2019
+ // ../../node_modules/.bun/@myriaddreamin+typst.ts@0.7.0-rc2+5e675a3c06b42b50/node_modules/@myriaddreamin/typst.ts/dist/esm/fs/package.mjs
2020
+ var FetchPackageRegistry = class {
2021
+ constructor(am) {
2022
+ __publicField(this, "am");
2023
+ __publicField(this, "cache", /* @__PURE__ */ new Map());
2024
+ this.am = am;
2025
+ }
2026
+ resolvePath(path) {
2027
+ return `https://packages.typst.org/preview/${path.name}-${path.version}.tar.gz`;
2028
+ }
2029
+ pullPackageData(path) {
2030
+ const request = new XMLHttpRequest();
2031
+ request.overrideMimeType("text/plain; charset=x-user-defined");
2032
+ request.open("GET", this.resolvePath(path), false);
2033
+ request.send(null);
2034
+ if (request.status === 200 && (request.response instanceof String || typeof request.response === "string")) {
2035
+ return Uint8Array.from(request.response, (c) => c.charCodeAt(0));
2036
+ }
2037
+ return void 0;
2038
+ }
2039
+ resolve(spec, context) {
2040
+ if (spec.namespace !== "preview") {
2041
+ return void 0;
2042
+ }
2043
+ const path = this.resolvePath(spec);
2044
+ if (this.cache.has(path)) {
2045
+ return this.cache.get(path)();
2046
+ }
2047
+ const data = this.pullPackageData(spec);
2048
+ if (!data) {
2049
+ return void 0;
2050
+ }
2051
+ const previewDir = `/@memory/fetch/packages/${spec.namespace}/${spec.name}/${spec.version}`;
2052
+ const entries = [];
2053
+ context.untar(data, (path2, data2, mtime) => {
2054
+ entries.push([previewDir + "/" + path2, data2, new Date(mtime)]);
2055
+ });
2056
+ const cacheClosure = () => {
2057
+ for (const [path2, data2, mtime] of entries) {
2058
+ this.am.insertFile(path2, data2, mtime);
2059
+ }
2060
+ return previewDir;
2061
+ };
2062
+ this.cache.set(path, cacheClosure);
2063
+ return cacheClosure();
2064
+ }
2065
+ };
2066
+
2067
+ // ../../node_modules/.bun/@myriaddreamin+typst.ts@0.7.0-rc2+5e675a3c06b42b50/node_modules/@myriaddreamin/typst.ts/dist/esm/fs/memory.mjs
2068
+ var MemoryAccessModel = class {
2069
+ constructor() {
2070
+ __publicField(this, "mTimes", /* @__PURE__ */ new Map());
2071
+ __publicField(this, "mData", /* @__PURE__ */ new Map());
2072
+ }
2073
+ reset() {
2074
+ this.mTimes.clear();
2075
+ this.mData.clear();
2076
+ }
2077
+ insertFile(path, data, mtime) {
2078
+ this.mTimes.set(path, mtime);
2079
+ this.mData.set(path, data);
2080
+ }
2081
+ removeFile(path) {
2082
+ this.mTimes.delete(path);
2083
+ this.mData.delete(path);
2084
+ }
2085
+ getMTime(path) {
2086
+ if (!path.startsWith("/@memory/")) {
2087
+ return void 0;
2088
+ }
2089
+ if (this.mTimes.has(path)) {
2090
+ return this.mTimes.get(path);
2091
+ }
2092
+ return void 0;
2093
+ }
2094
+ isFile() {
2095
+ return true;
2096
+ }
2097
+ getRealPath(path) {
2098
+ return path;
2099
+ }
2100
+ readAll(path) {
2101
+ if (!path.startsWith("/@memory/")) {
2102
+ return void 0;
2103
+ }
2104
+ if (this.mData.has(path)) {
2105
+ return this.mData.get(path);
2106
+ }
2107
+ return void 0;
2108
+ }
2109
+ };
2110
+
2111
+ // src/worker.ts
2112
+ var PDF_FORMAT = 1;
2113
+ var accessModel = new MemoryAccessModel();
2114
+ var packageRegistry = new FetchPackageRegistry(accessModel);
2115
+ var compiler = null;
2116
+ async function initCompiler(wasmUrl, fontUrls, packages) {
2117
+ compiler = createTypstCompiler();
2118
+ await compiler.init({
2119
+ getModule: () => wasmUrl,
2120
+ beforeBuild: [
2121
+ loadFonts(fontUrls),
2122
+ ...packages ? [withAccessModel(accessModel), withPackageRegistry(packageRegistry)] : []
2123
+ ]
2124
+ });
2125
+ }
2126
+ function parseRange(range) {
2127
+ const m = range.match(/(\d+):(\d+)-(\d+):(\d+)/);
2128
+ if (!m) {
2129
+ console.warn(`[typst-web-service] Skipping diagnostic with unrecognized range format: ${JSON.stringify(range)}`);
2130
+ return null;
2131
+ }
2132
+ return { startLine: +m[1], startCol: +m[2], endLine: +m[3], endCol: +m[4] };
2133
+ }
2134
+ async function compile(source) {
2135
+ if (!compiler) throw new Error("Compiler not initialized");
2136
+ compiler.addSource("/main.typ", source);
2137
+ const result = await compiler.compile({ mainFilePath: "/main.typ", diagnostics: "full" });
2138
+ const diagnostics = (result.diagnostics ?? []).flatMap((d) => {
2139
+ const range = parseRange(d.range);
2140
+ if (!range) return [];
2141
+ return [{ ...d, severity: d.severity, range }];
2142
+ });
2143
+ return { diagnostics, vector: result.result ?? void 0 };
2144
+ }
2145
+ function postError(id, err) {
2146
+ self.postMessage({
2147
+ type: "error",
2148
+ id,
2149
+ message: err instanceof Error ? err.message : String(err)
2150
+ });
2151
+ }
2152
+ function transferBuffer(data) {
2153
+ return data.buffer.slice(data.byteOffset, data.byteOffset + data.byteLength);
2154
+ }
2155
+ var yieldToEventLoop = () => new Promise((r) => setTimeout(r, 0));
2156
+ var pendingCompile = null;
2157
+ var processingCompile = false;
2158
+ var pendingRender = null;
2159
+ var processingRender = false;
2160
+ async function drainCompileQueue() {
2161
+ processingCompile = true;
2162
+ while (pendingCompile) {
2163
+ const req = pendingCompile;
2164
+ pendingCompile = null;
2165
+ await yieldToEventLoop();
2166
+ if (pendingCompile) {
2167
+ self.postMessage({ type: "cancelled", id: req.id });
2168
+ continue;
2169
+ }
2170
+ try {
2171
+ const { diagnostics, vector: vectorData } = await compile(req.source);
2172
+ const vector = vectorData ? transferBuffer(vectorData) : void 0;
2173
+ const msg = { type: "result", id: req.id, diagnostics, vector };
2174
+ self.postMessage(msg, vector ? [vector] : []);
2175
+ } catch (err) {
2176
+ postError(req.id, err);
2177
+ }
2178
+ }
2179
+ processingCompile = false;
2180
+ }
2181
+ async function drainRenderQueue() {
2182
+ processingRender = true;
2183
+ while (pendingRender) {
2184
+ const req = pendingRender;
2185
+ pendingRender = null;
2186
+ await yieldToEventLoop();
2187
+ if (pendingRender) {
2188
+ self.postMessage({ type: "cancelled", id: req.id });
2189
+ continue;
2190
+ }
2191
+ try {
2192
+ if (!compiler) throw new Error("Compiler not initialized");
2193
+ compiler.addSource("/main.typ", req.source);
2194
+ const result = await compiler.compile({
2195
+ mainFilePath: "/main.typ",
2196
+ format: PDF_FORMAT,
2197
+ diagnostics: "none"
2198
+ });
2199
+ if (!result.result) throw new Error("Compilation produced no output");
2200
+ const data = transferBuffer(result.result);
2201
+ self.postMessage({ type: "pdf", id: req.id, data }, [data]);
2202
+ } catch (err) {
2203
+ postError(req.id, err);
2204
+ }
2205
+ }
2206
+ processingRender = false;
2207
+ }
2208
+ self.onmessage = async (e) => {
2209
+ const req = e.data;
2210
+ if (req.type === "init") {
2211
+ try {
2212
+ await initCompiler(req.wasmUrl, req.fonts, req.packages);
2213
+ self.postMessage({ type: "ready", id: req.id });
2214
+ } catch (err) {
2215
+ postError(req.id, err);
2216
+ }
2217
+ return;
2218
+ }
2219
+ if (req.type === "compile") {
2220
+ pendingCompile = req;
2221
+ if (!processingCompile) drainCompileQueue();
2222
+ return;
2223
+ }
2224
+ if (req.type === "render") {
2225
+ pendingRender = req;
2226
+ if (!processingRender) drainRenderQueue();
2227
+ return;
2228
+ }
2229
+ if (req.type === "destroy") {
2230
+ self.postMessage({ type: "destroyed", id: req.id });
2231
+ }
2232
+ };
2233
+ //# sourceMappingURL=worker.js.map