@canvist/headless 0.0.0-stage → 0.2.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.
Files changed (49) hide show
  1. package/dist/calls.d.ts +15 -0
  2. package/dist/calls.js +20 -0
  3. package/dist/create.d.ts +17 -0
  4. package/dist/create.js +29 -0
  5. package/dist/engine.d.ts +125 -0
  6. package/dist/engine.js +176 -0
  7. package/dist/errors.d.ts +13 -0
  8. package/dist/errors.js +5 -0
  9. package/dist/extensions.generated.d.ts +1022 -0
  10. package/dist/extensions.generated.js +744 -0
  11. package/dist/extras.generated.d.ts +5803 -0
  12. package/dist/extras.generated.js +2600 -0
  13. package/dist/full.d.ts +21 -0
  14. package/dist/full.js +63 -0
  15. package/dist/gemoji.generated.d.ts +29 -0
  16. package/dist/gemoji.generated.js +30 -0
  17. package/dist/load.d.ts +21 -0
  18. package/dist/load.js +41 -0
  19. package/dist/mod.d.ts +25 -0
  20. package/dist/mod.js +24 -0
  21. package/dist/native.d.ts +115 -0
  22. package/dist/native.js +235 -0
  23. package/dist/scene-types.d.ts +223 -0
  24. package/dist/scene-types.js +1 -0
  25. package/dist/scene.d.ts +105 -0
  26. package/dist/scene.js +153 -0
  27. package/dist/ssr.d.ts +66 -0
  28. package/dist/ssr.js +98 -0
  29. package/dist/types.d.ts +232 -0
  30. package/dist/types.js +1 -0
  31. package/package.json +89 -5
  32. package/readme.md +96 -0
  33. package/wasm/canvist_headless_wasm.d.ts +216 -0
  34. package/wasm/canvist_headless_wasm.js +910 -0
  35. package/wasm/canvist_headless_wasm_bg.wasm +0 -0
  36. package/wasm/canvist_headless_wasm_bg.wasm.d.ts +44 -0
  37. package/wasm-full/canvist_headless_full.d.ts +223 -0
  38. package/wasm-full/canvist_headless_full.js +923 -0
  39. package/wasm-full/canvist_headless_full_bg.wasm +0 -0
  40. package/wasm-full/canvist_headless_full_bg.wasm.d.ts +45 -0
  41. package/wasm-scene/canvist_headless_scene.d.ts +332 -0
  42. package/wasm-scene/canvist_headless_scene.js +1231 -0
  43. package/wasm-scene/canvist_headless_scene_bg.wasm +0 -0
  44. package/wasm-scene/canvist_headless_scene_bg.wasm.d.ts +66 -0
  45. package/wasm-ssr/canvist_headless_ssr.d.ts +250 -0
  46. package/wasm-ssr/canvist_headless_ssr.js +1025 -0
  47. package/wasm-ssr/canvist_headless_ssr_bg.wasm +0 -0
  48. package/wasm-ssr/canvist_headless_ssr_bg.wasm.d.ts +50 -0
  49. package/README.md +0 -3
@@ -0,0 +1,1025 @@
1
+ /* @ts-self-types="./canvist_headless_ssr.d.ts" */
2
+
3
+ /**
4
+ * One document and its editor.
5
+ */
6
+ export class WasmDoc {
7
+ static __wrap(ptr) {
8
+ const obj = Object.create(WasmDoc.prototype);
9
+ obj.__wbg_ptr = ptr;
10
+ WasmDocFinalization.register(obj, obj.__wbg_ptr, obj);
11
+ return obj;
12
+ }
13
+ __destroy_into_raw() {
14
+ const ptr = this.__wbg_ptr;
15
+ this.__wbg_ptr = 0;
16
+ WasmDocFinalization.unregister(this);
17
+ return ptr;
18
+ }
19
+ free() {
20
+ const ptr = this.__destroy_into_raw();
21
+ wasm.__wbg_wasmdoc_free(ptr, 0);
22
+ }
23
+ /**
24
+ * Apply a v1 Yjs update; returns whether the document changed.
25
+ * @param {Uint8Array} update
26
+ * @returns {boolean}
27
+ */
28
+ applyUpdate(update) {
29
+ const ptr0 = passArray8ToWasm0(update, wasm.__wbindgen_malloc);
30
+ const len0 = WASM_VECTOR_LEN;
31
+ const ret = wasm.wasmdoc_applyUpdate(this.__wbg_ptr, ptr0, len0);
32
+ if (ret[2]) {
33
+ throw takeFromExternrefTable0(ret[1]);
34
+ }
35
+ return ret[0] !== 0;
36
+ }
37
+ /**
38
+ * Whether the named command would apply.
39
+ * @param {string} name
40
+ * @param {string} args
41
+ * @returns {boolean}
42
+ */
43
+ can(name, args) {
44
+ const ptr0 = passStringToWasm0(name, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
45
+ const len0 = WASM_VECTOR_LEN;
46
+ const ptr1 = passStringToWasm0(args, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
47
+ const len1 = WASM_VECTOR_LEN;
48
+ const ret = wasm.wasmdoc_can(this.__wbg_ptr, ptr0, len0, ptr1, len1);
49
+ if (ret[2]) {
50
+ throw takeFromExternrefTable0(ret[1]);
51
+ }
52
+ return ret[0] !== 0;
53
+ }
54
+ /**
55
+ * Delete the selection.
56
+ * @returns {boolean}
57
+ */
58
+ deleteSelection() {
59
+ const ret = wasm.wasmdoc_deleteSelection(this.__wbg_ptr);
60
+ if (ret[2]) {
61
+ throw takeFromExternrefTable0(ret[1]);
62
+ }
63
+ return ret[0] !== 0;
64
+ }
65
+ /**
66
+ * What a peer at `state_vector` is missing, as one v1 update.
67
+ * @param {Uint8Array} state_vector
68
+ * @returns {Uint8Array}
69
+ */
70
+ encodeDiff(state_vector) {
71
+ const ptr0 = passArray8ToWasm0(state_vector, wasm.__wbindgen_malloc);
72
+ const len0 = WASM_VECTOR_LEN;
73
+ const ret = wasm.wasmdoc_encodeDiff(this.__wbg_ptr, ptr0, len0);
74
+ if (ret[3]) {
75
+ throw takeFromExternrefTable0(ret[2]);
76
+ }
77
+ var v2 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
78
+ wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
79
+ return v2;
80
+ }
81
+ /**
82
+ * The whole shared state as one v1 update.
83
+ * @returns {Uint8Array}
84
+ */
85
+ encodeState() {
86
+ const ret = wasm.wasmdoc_encodeState(this.__wbg_ptr);
87
+ if (ret[3]) {
88
+ throw takeFromExternrefTable0(ret[2]);
89
+ }
90
+ var v1 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
91
+ wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
92
+ return v1;
93
+ }
94
+ /**
95
+ * The document as `format`.
96
+ * @param {string} format_name
97
+ * @returns {string}
98
+ */
99
+ export(format_name) {
100
+ let deferred3_0;
101
+ let deferred3_1;
102
+ try {
103
+ const ptr0 = passStringToWasm0(format_name, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
104
+ const len0 = WASM_VECTOR_LEN;
105
+ const ret = wasm.wasmdoc_export(this.__wbg_ptr, ptr0, len0);
106
+ var ptr2 = ret[0];
107
+ var len2 = ret[1];
108
+ if (ret[3]) {
109
+ ptr2 = 0; len2 = 0;
110
+ throw takeFromExternrefTable0(ret[2]);
111
+ }
112
+ deferred3_0 = ptr2;
113
+ deferred3_1 = len2;
114
+ return getStringFromWasm0(ptr2, len2);
115
+ } finally {
116
+ wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);
117
+ }
118
+ }
119
+ /**
120
+ * This peer's changes since the last call, as y-sync update messages.
121
+ * @returns {Uint8Array[]}
122
+ */
123
+ flushSync() {
124
+ const ret = wasm.wasmdoc_flushSync(this.__wbg_ptr);
125
+ if (ret[2]) {
126
+ throw takeFromExternrefTable0(ret[1]);
127
+ }
128
+ return takeFromExternrefTable0(ret[0]);
129
+ }
130
+ /**
131
+ * Replace the selection with `text`, without input rules.
132
+ * @param {string} text
133
+ * @returns {boolean}
134
+ */
135
+ insertText(text) {
136
+ const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
137
+ const len0 = WASM_VECTOR_LEN;
138
+ const ret = wasm.wasmdoc_insertText(this.__wbg_ptr, ptr0, len0);
139
+ if (ret[2]) {
140
+ throw takeFromExternrefTable0(ret[1]);
141
+ }
142
+ return ret[0] !== 0;
143
+ }
144
+ /**
145
+ * Paste `content` read as `format` over the selection.
146
+ * @param {string} format_name
147
+ * @param {string} content
148
+ * @returns {boolean}
149
+ */
150
+ paste(format_name, content) {
151
+ const ptr0 = passStringToWasm0(format_name, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
152
+ const len0 = WASM_VECTOR_LEN;
153
+ const ptr1 = passStringToWasm0(content, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
154
+ const len1 = WASM_VECTOR_LEN;
155
+ const ret = wasm.wasmdoc_paste(this.__wbg_ptr, ptr0, len0, ptr1, len1);
156
+ if (ret[2]) {
157
+ throw takeFromExternrefTable0(ret[1]);
158
+ }
159
+ return ret[0] !== 0;
160
+ }
161
+ /**
162
+ * Press a key binding such as `Enter` or `Mod-b`.
163
+ * @param {string} key
164
+ * @returns {boolean}
165
+ */
166
+ press(key) {
167
+ const ptr0 = passStringToWasm0(key, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
168
+ const len0 = WASM_VECTOR_LEN;
169
+ const ret = wasm.wasmdoc_press(this.__wbg_ptr, ptr0, len0);
170
+ if (ret[2]) {
171
+ throw takeFromExternrefTable0(ret[1]);
172
+ }
173
+ return ret[0] !== 0;
174
+ }
175
+ /**
176
+ * Answer the named query, as JSON.
177
+ * @param {string} name
178
+ * @param {string} args
179
+ * @returns {string}
180
+ */
181
+ query(name, args) {
182
+ let deferred4_0;
183
+ let deferred4_1;
184
+ try {
185
+ const ptr0 = passStringToWasm0(name, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
186
+ const len0 = WASM_VECTOR_LEN;
187
+ const ptr1 = passStringToWasm0(args, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
188
+ const len1 = WASM_VECTOR_LEN;
189
+ const ret = wasm.wasmdoc_query(this.__wbg_ptr, ptr0, len0, ptr1, len1);
190
+ var ptr3 = ret[0];
191
+ var len3 = ret[1];
192
+ if (ret[3]) {
193
+ ptr3 = 0; len3 = 0;
194
+ throw takeFromExternrefTable0(ret[2]);
195
+ }
196
+ deferred4_0 = ptr3;
197
+ deferred4_1 = len3;
198
+ return getStringFromWasm0(ptr3, len3);
199
+ } finally {
200
+ wasm.__wbindgen_free(deferred4_0, deferred4_1, 1);
201
+ }
202
+ }
203
+ /**
204
+ * Handle a y-sync message: returns `[reply, broadcast, changed]`, the
205
+ * messages for the sender, the messages for everyone else, and whether
206
+ * the document changed.
207
+ * @param {Uint8Array} message
208
+ * @returns {[Uint8Array[], Uint8Array[], boolean]}
209
+ */
210
+ receiveSync(message) {
211
+ const ptr0 = passArray8ToWasm0(message, wasm.__wbindgen_malloc);
212
+ const len0 = WASM_VECTOR_LEN;
213
+ const ret = wasm.wasmdoc_receiveSync(this.__wbg_ptr, ptr0, len0);
214
+ if (ret[2]) {
215
+ throw takeFromExternrefTable0(ret[1]);
216
+ }
217
+ return takeFromExternrefTable0(ret[0]);
218
+ }
219
+ /**
220
+ * Redo the last undone call.
221
+ * @returns {boolean}
222
+ */
223
+ redo() {
224
+ const ret = wasm.wasmdoc_redo(this.__wbg_ptr);
225
+ if (ret[2]) {
226
+ throw takeFromExternrefTable0(ret[1]);
227
+ }
228
+ return ret[0] !== 0;
229
+ }
230
+ /**
231
+ * Run the named command with JSON arguments.
232
+ * @param {string} name
233
+ * @param {string} args
234
+ * @returns {boolean}
235
+ */
236
+ run(name, args) {
237
+ const ptr0 = passStringToWasm0(name, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
238
+ const len0 = WASM_VECTOR_LEN;
239
+ const ptr1 = passStringToWasm0(args, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
240
+ const len1 = WASM_VECTOR_LEN;
241
+ const ret = wasm.wasmdoc_run(this.__wbg_ptr, ptr0, len0, ptr1, len1);
242
+ if (ret[2]) {
243
+ throw takeFromExternrefTable0(ret[1]);
244
+ }
245
+ return ret[0] !== 0;
246
+ }
247
+ /**
248
+ * Select the whole document.
249
+ */
250
+ selectAll() {
251
+ const ret = wasm.wasmdoc_selectAll(this.__wbg_ptr);
252
+ if (ret[1]) {
253
+ throw takeFromExternrefTable0(ret[0]);
254
+ }
255
+ }
256
+ /**
257
+ * Select from the anchor to the head; offsets count UTF-16 code units.
258
+ * @param {Uint32Array} anchor_path
259
+ * @param {number} anchor_offset
260
+ * @param {Uint32Array} head_path
261
+ * @param {number} head_offset
262
+ */
263
+ select(anchor_path, anchor_offset, head_path, head_offset) {
264
+ const ptr0 = passArray32ToWasm0(anchor_path, wasm.__wbindgen_malloc);
265
+ const len0 = WASM_VECTOR_LEN;
266
+ const ptr1 = passArray32ToWasm0(head_path, wasm.__wbindgen_malloc);
267
+ const len1 = WASM_VECTOR_LEN;
268
+ const ret = wasm.wasmdoc_select(this.__wbg_ptr, ptr0, len0, anchor_offset, ptr1, len1, head_offset);
269
+ if (ret[1]) {
270
+ throw takeFromExternrefTable0(ret[0]);
271
+ }
272
+ }
273
+ /**
274
+ * The anchor and head as JSON positions, or `null` for a block
275
+ * selection.
276
+ * @returns {string}
277
+ */
278
+ selection() {
279
+ let deferred1_0;
280
+ let deferred1_1;
281
+ try {
282
+ const ret = wasm.wasmdoc_selection(this.__wbg_ptr);
283
+ deferred1_0 = ret[0];
284
+ deferred1_1 = ret[1];
285
+ return getStringFromWasm0(ret[0], ret[1]);
286
+ } finally {
287
+ wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
288
+ }
289
+ }
290
+ /**
291
+ * Start sharing the document as yrs client `client_id`.
292
+ * @param {number} client_id
293
+ */
294
+ share(client_id) {
295
+ const ret = wasm.wasmdoc_share(this.__wbg_ptr, client_id);
296
+ if (ret[1]) {
297
+ throw takeFromExternrefTable0(ret[0]);
298
+ }
299
+ }
300
+ /**
301
+ * The content and selection as snapshot JSON.
302
+ * @returns {string}
303
+ */
304
+ snapshot() {
305
+ let deferred1_0;
306
+ let deferred1_1;
307
+ try {
308
+ const ret = wasm.wasmdoc_snapshot(this.__wbg_ptr);
309
+ deferred1_0 = ret[0];
310
+ deferred1_1 = ret[1];
311
+ return getStringFromWasm0(ret[0], ret[1]);
312
+ } finally {
313
+ wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
314
+ }
315
+ }
316
+ /**
317
+ * The v1 state vector.
318
+ * @returns {Uint8Array}
319
+ */
320
+ stateVector() {
321
+ const ret = wasm.wasmdoc_stateVector(this.__wbg_ptr);
322
+ if (ret[3]) {
323
+ throw takeFromExternrefTable0(ret[2]);
324
+ }
325
+ var v1 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
326
+ wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
327
+ return v1;
328
+ }
329
+ /**
330
+ * The y-sync message to greet a connecting client with.
331
+ * @returns {Uint8Array}
332
+ */
333
+ syncStart() {
334
+ const ret = wasm.wasmdoc_syncStart(this.__wbg_ptr);
335
+ if (ret[3]) {
336
+ throw takeFromExternrefTable0(ret[2]);
337
+ }
338
+ var v1 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
339
+ wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
340
+ return v1;
341
+ }
342
+ /**
343
+ * Drain this peer's own v1 updates.
344
+ * @returns {Uint8Array[]}
345
+ */
346
+ takeUpdates() {
347
+ const ret = wasm.wasmdoc_takeUpdates(this.__wbg_ptr);
348
+ if (ret[2]) {
349
+ throw takeFromExternrefTable0(ret[1]);
350
+ }
351
+ return takeFromExternrefTable0(ret[0]);
352
+ }
353
+ /**
354
+ * Type `text` one character at a time, running input rules.
355
+ * @param {string} text
356
+ * @returns {boolean}
357
+ */
358
+ typeText(text) {
359
+ const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
360
+ const len0 = WASM_VECTOR_LEN;
361
+ const ret = wasm.wasmdoc_typeText(this.__wbg_ptr, ptr0, len0);
362
+ if (ret[2]) {
363
+ throw takeFromExternrefTable0(ret[1]);
364
+ }
365
+ return ret[0] !== 0;
366
+ }
367
+ /**
368
+ * Undo the last call that changed the document.
369
+ * @returns {boolean}
370
+ */
371
+ undo() {
372
+ const ret = wasm.wasmdoc_undo(this.__wbg_ptr);
373
+ if (ret[2]) {
374
+ throw takeFromExternrefTable0(ret[1]);
375
+ }
376
+ return ret[0] !== 0;
377
+ }
378
+ /**
379
+ * `{ rejectedBlocks, waiting }` as JSON.
380
+ * @returns {string}
381
+ */
382
+ validate() {
383
+ let deferred2_0;
384
+ let deferred2_1;
385
+ try {
386
+ const ret = wasm.wasmdoc_validate(this.__wbg_ptr);
387
+ var ptr1 = ret[0];
388
+ var len1 = ret[1];
389
+ if (ret[3]) {
390
+ ptr1 = 0; len1 = 0;
391
+ throw takeFromExternrefTable0(ret[2]);
392
+ }
393
+ deferred2_0 = ptr1;
394
+ deferred2_1 = len1;
395
+ return getStringFromWasm0(ptr1, len1);
396
+ } finally {
397
+ wasm.__wbindgen_free(deferred2_0, deferred2_1, 1);
398
+ }
399
+ }
400
+ }
401
+ if (Symbol.dispose) WasmDoc.prototype[Symbol.dispose] = WasmDoc.prototype.free;
402
+
403
+ /**
404
+ * A configured set of extensions that creates documents.
405
+ */
406
+ export class WasmEngine {
407
+ __destroy_into_raw() {
408
+ const ptr = this.__wbg_ptr;
409
+ this.__wbg_ptr = 0;
410
+ WasmEngineFinalization.unregister(this);
411
+ return ptr;
412
+ }
413
+ free() {
414
+ const ptr = this.__destroy_into_raw();
415
+ wasm.__wbg_wasmengine_free(ptr, 0);
416
+ }
417
+ /**
418
+ * A document with one empty paragraph.
419
+ * @returns {WasmDoc}
420
+ */
421
+ create() {
422
+ const ret = wasm.wasmengine_create(this.__wbg_ptr);
423
+ if (ret[2]) {
424
+ throw takeFromExternrefTable0(ret[1]);
425
+ }
426
+ return WasmDoc.__wrap(ret[0]);
427
+ }
428
+ /**
429
+ * Join a shared document from v1 Yjs state as yrs client `client_id`.
430
+ * @param {Uint8Array} state
431
+ * @param {number} client_id
432
+ * @returns {WasmDoc}
433
+ */
434
+ fromYjs(state, client_id) {
435
+ const ptr0 = passArray8ToWasm0(state, wasm.__wbindgen_malloc);
436
+ const len0 = WASM_VECTOR_LEN;
437
+ const ret = wasm.wasmengine_fromYjs(this.__wbg_ptr, ptr0, len0, client_id);
438
+ if (ret[2]) {
439
+ throw takeFromExternrefTable0(ret[1]);
440
+ }
441
+ return WasmDoc.__wrap(ret[0]);
442
+ }
443
+ /**
444
+ * The registered extensions' metadata as JSON.
445
+ * @returns {string}
446
+ */
447
+ metadata() {
448
+ let deferred1_0;
449
+ let deferred1_1;
450
+ try {
451
+ const ret = wasm.wasmengine_metadata(this.__wbg_ptr);
452
+ deferred1_0 = ret[0];
453
+ deferred1_1 = ret[1];
454
+ return getStringFromWasm0(ret[0], ret[1]);
455
+ } finally {
456
+ wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
457
+ }
458
+ }
459
+ /**
460
+ * An engine with the named extensions, allocating block ids as
461
+ * `client`.
462
+ * @param {string[]} extensions
463
+ * @param {number} client
464
+ */
465
+ constructor(extensions, client) {
466
+ const ptr0 = passArrayJsValueToWasm0(extensions, wasm.__wbindgen_malloc);
467
+ const len0 = WASM_VECTOR_LEN;
468
+ const ret = wasm.wasmengine_new(ptr0, len0, client);
469
+ if (ret[2]) {
470
+ throw takeFromExternrefTable0(ret[1]);
471
+ }
472
+ this.__wbg_ptr = ret[0];
473
+ WasmEngineFinalization.register(this, this.__wbg_ptr, this);
474
+ return this;
475
+ }
476
+ /**
477
+ * Read `input` as `format` (`json`, `html`, `markdown`, or `text`).
478
+ * @param {string} format_name
479
+ * @param {string} input
480
+ * @returns {WasmDoc}
481
+ */
482
+ parse(format_name, input) {
483
+ const ptr0 = passStringToWasm0(format_name, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
484
+ const len0 = WASM_VECTOR_LEN;
485
+ const ptr1 = passStringToWasm0(input, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
486
+ const len1 = WASM_VECTOR_LEN;
487
+ const ret = wasm.wasmengine_parse(this.__wbg_ptr, ptr0, len0, ptr1, len1);
488
+ if (ret[2]) {
489
+ throw takeFromExternrefTable0(ret[1]);
490
+ }
491
+ return WasmDoc.__wrap(ret[0]);
492
+ }
493
+ /**
494
+ * Recreate a document from a snapshot's JSON text.
495
+ * @param {string} snapshot
496
+ * @returns {WasmDoc}
497
+ */
498
+ restore(snapshot) {
499
+ const ptr0 = passStringToWasm0(snapshot, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
500
+ const len0 = WASM_VECTOR_LEN;
501
+ const ret = wasm.wasmengine_restore(this.__wbg_ptr, ptr0, len0);
502
+ if (ret[2]) {
503
+ throw takeFromExternrefTable0(ret[1]);
504
+ }
505
+ return WasmDoc.__wrap(ret[0]);
506
+ }
507
+ }
508
+ if (Symbol.dispose) WasmEngine.prototype[Symbol.dispose] = WasmEngine.prototype.free;
509
+
510
+ /**
511
+ * Renders documents to HTML, CSS, and SVG laid out as the canvas editor
512
+ * lays them out, with the StarterKit theme and the fonts registered here.
513
+ */
514
+ export class WasmRenderer {
515
+ __destroy_into_raw() {
516
+ const ptr = this.__wbg_ptr;
517
+ this.__wbg_ptr = 0;
518
+ WasmRendererFinalization.unregister(this);
519
+ return ptr;
520
+ }
521
+ free() {
522
+ const ptr = this.__destroy_into_raw();
523
+ wasm.__wbg_wasmrenderer_free(ptr, 0);
524
+ }
525
+ /**
526
+ * `input` read as `format`, rendered `width` pixels wide, as
527
+ * `[fragment, stylesheet]`.
528
+ * @param {string} format_name
529
+ * @param {string} input
530
+ * @param {number} width
531
+ * @returns {string[]}
532
+ */
533
+ html(format_name, input, width) {
534
+ const ptr0 = passStringToWasm0(format_name, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
535
+ const len0 = WASM_VECTOR_LEN;
536
+ const ptr1 = passStringToWasm0(input, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
537
+ const len1 = WASM_VECTOR_LEN;
538
+ const ret = wasm.wasmrenderer_html(this.__wbg_ptr, ptr0, len0, ptr1, len1, width);
539
+ if (ret[3]) {
540
+ throw takeFromExternrefTable0(ret[2]);
541
+ }
542
+ var v3 = getArrayJsValueFromWasm0(ret[0], ret[1]);
543
+ wasm.__wbindgen_free(ret[0], ret[1] * 4, 4);
544
+ return v3;
545
+ }
546
+ /**
547
+ * A renderer for documents with the named extensions, themed by JSON
548
+ * `theme` (`@canvist/web`'s `ThemeOptions`).
549
+ * @param {string[]} extensions
550
+ * @param {string} theme
551
+ */
552
+ constructor(extensions, theme) {
553
+ const ptr0 = passArrayJsValueToWasm0(extensions, wasm.__wbindgen_malloc);
554
+ const len0 = WASM_VECTOR_LEN;
555
+ const ptr1 = passStringToWasm0(theme, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
556
+ const len1 = WASM_VECTOR_LEN;
557
+ const ret = wasm.wasmrenderer_new(ptr0, len0, ptr1, len1);
558
+ if (ret[2]) {
559
+ throw takeFromExternrefTable0(ret[1]);
560
+ }
561
+ this.__wbg_ptr = ret[0];
562
+ WasmRendererFinalization.register(this, this.__wbg_ptr, this);
563
+ return this;
564
+ }
565
+ /**
566
+ * Register a TrueType or OpenType font and return the family names it
567
+ * added.
568
+ * @param {Uint8Array} data
569
+ * @returns {string[]}
570
+ */
571
+ registerFont(data) {
572
+ const ptr0 = passArray8ToWasm0(data, wasm.__wbindgen_malloc);
573
+ const len0 = WASM_VECTOR_LEN;
574
+ const ret = wasm.wasmrenderer_registerFont(this.__wbg_ptr, ptr0, len0);
575
+ var v2 = getArrayJsValueFromWasm0(ret[0], ret[1]);
576
+ wasm.__wbindgen_free(ret[0], ret[1] * 4, 4);
577
+ return v2;
578
+ }
579
+ /**
580
+ * `input` read as `format`, as an SVG image `width` pixels wide.
581
+ * @param {string} format_name
582
+ * @param {string} input
583
+ * @param {number} width
584
+ * @returns {string}
585
+ */
586
+ svg(format_name, input, width) {
587
+ let deferred4_0;
588
+ let deferred4_1;
589
+ try {
590
+ const ptr0 = passStringToWasm0(format_name, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
591
+ const len0 = WASM_VECTOR_LEN;
592
+ const ptr1 = passStringToWasm0(input, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
593
+ const len1 = WASM_VECTOR_LEN;
594
+ const ret = wasm.wasmrenderer_svg(this.__wbg_ptr, ptr0, len0, ptr1, len1, width);
595
+ var ptr3 = ret[0];
596
+ var len3 = ret[1];
597
+ if (ret[3]) {
598
+ ptr3 = 0; len3 = 0;
599
+ throw takeFromExternrefTable0(ret[2]);
600
+ }
601
+ deferred4_0 = ptr3;
602
+ deferred4_1 = len3;
603
+ return getStringFromWasm0(ptr3, len3);
604
+ } finally {
605
+ wasm.__wbindgen_free(deferred4_0, deferred4_1, 1);
606
+ }
607
+ }
608
+ }
609
+ if (Symbol.dispose) WasmRenderer.prototype[Symbol.dispose] = WasmRenderer.prototype.free;
610
+ function __wbg_get_imports() {
611
+ const import0 = {
612
+ __proto__: null,
613
+ __wbg___wbindgen_is_function_1f9d30630b8b1d3d: function(arg0) {
614
+ const ret = typeof(arg0) === 'function';
615
+ return ret;
616
+ },
617
+ __wbg___wbindgen_is_object_3c45d4f2dde4e749: function(arg0) {
618
+ const val = arg0;
619
+ const ret = typeof(val) === 'object' && val !== null;
620
+ return ret;
621
+ },
622
+ __wbg___wbindgen_is_string_90b56bc79aad6f6c: function(arg0) {
623
+ const ret = typeof(arg0) === 'string';
624
+ return ret;
625
+ },
626
+ __wbg___wbindgen_is_undefined_8865fb403f8fe9d8: function(arg0) {
627
+ const ret = arg0 === undefined;
628
+ return ret;
629
+ },
630
+ __wbg___wbindgen_string_get_0380ccaa2f57f0d9: function(arg0, arg1) {
631
+ const obj = arg1;
632
+ const ret = typeof(obj) === 'string' ? obj : undefined;
633
+ var ptr1 = isLikeNone(ret) ? 0 : passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
634
+ var len1 = WASM_VECTOR_LEN;
635
+ getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
636
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
637
+ },
638
+ __wbg___wbindgen_throw_41e9ee4f547fc59a: function(arg0, arg1) {
639
+ throw new Error(getStringFromWasm0(arg0, arg1));
640
+ },
641
+ __wbg_call_187d372bd5fdd4aa: function() { return handleError(function (arg0, arg1, arg2) {
642
+ const ret = arg0.call(arg1, arg2);
643
+ return ret;
644
+ }, arguments); },
645
+ __wbg_crypto_38df2bab126b63dc: function(arg0) {
646
+ const ret = arg0.crypto;
647
+ return ret;
648
+ },
649
+ __wbg_getRandomValues_c44a50d8cfdaebeb: function() { return handleError(function (arg0, arg1) {
650
+ arg0.getRandomValues(arg1);
651
+ }, arguments); },
652
+ __wbg_length_7f3c00c40364105e: function(arg0) {
653
+ const ret = arg0.length;
654
+ return ret;
655
+ },
656
+ __wbg_msCrypto_bd5a034af96bcba6: function(arg0) {
657
+ const ret = arg0.msCrypto;
658
+ return ret;
659
+ },
660
+ __wbg_new_343a093a3c2ffb4e: function(arg0, arg1) {
661
+ const ret = new Error(getStringFromWasm0(arg0, arg1));
662
+ return ret;
663
+ },
664
+ __wbg_new_ee2291f50781bf1d: function() {
665
+ const ret = new Array();
666
+ return ret;
667
+ },
668
+ __wbg_new_from_slice_9a868026ffa4208a: function(arg0, arg1) {
669
+ const ret = new Uint8Array(getArrayU8FromWasm0(arg0, arg1));
670
+ return ret;
671
+ },
672
+ __wbg_new_with_length_3da0ad195f6f63ba: function(arg0) {
673
+ const ret = new Uint8Array(arg0 >>> 0);
674
+ return ret;
675
+ },
676
+ __wbg_node_84ea875411254db1: function(arg0) {
677
+ const ret = arg0.node;
678
+ return ret;
679
+ },
680
+ __wbg_of_dde0b9d3265685ee: function(arg0, arg1, arg2) {
681
+ const ret = Array.of(arg0, arg1, arg2);
682
+ return ret;
683
+ },
684
+ __wbg_process_44c7a14e11e9f69e: function(arg0) {
685
+ const ret = arg0.process;
686
+ return ret;
687
+ },
688
+ __wbg_prototypesetcall_bc27214492979395: function(arg0, arg1, arg2) {
689
+ Uint8Array.prototype.set.call(getArrayU8FromWasm0(arg0, arg1), arg2);
690
+ },
691
+ __wbg_push_2baf45db356cf468: function(arg0, arg1) {
692
+ const ret = arg0.push(arg1);
693
+ return ret;
694
+ },
695
+ __wbg_randomFillSync_6c25eac9869eb53c: function() { return handleError(function (arg0, arg1) {
696
+ arg0.randomFillSync(arg1);
697
+ }, arguments); },
698
+ __wbg_require_b4edbdcf3e2a1ef0: function() { return handleError(function () {
699
+ const ret = module.require;
700
+ return ret;
701
+ }, arguments); },
702
+ __wbg_set_145a351398b48c65: function() { return handleError(function (arg0, arg1, arg2) {
703
+ const ret = Reflect.set(arg0, arg1, arg2);
704
+ return ret;
705
+ }, arguments); },
706
+ __wbg_set_name_2c630595dc90a7aa: function(arg0, arg1, arg2) {
707
+ arg0.name = getStringFromWasm0(arg1, arg2);
708
+ },
709
+ __wbg_static_accessor_GLOBAL_266715b9d96ba635: function() {
710
+ const ret = typeof global === 'undefined' ? null : global;
711
+ return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
712
+ },
713
+ __wbg_static_accessor_GLOBAL_THIS_10fb7dc1ae063179: function() {
714
+ const ret = typeof globalThis === 'undefined' ? null : globalThis;
715
+ return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
716
+ },
717
+ __wbg_static_accessor_SELF_0b583911f537483a: function() {
718
+ const ret = typeof self === 'undefined' ? null : self;
719
+ return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
720
+ },
721
+ __wbg_static_accessor_WINDOW_d7f903d1508cbdc4: function() {
722
+ const ret = typeof window === 'undefined' ? null : window;
723
+ return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
724
+ },
725
+ __wbg_subarray_002b94d5e13d1411: function(arg0, arg1, arg2) {
726
+ const ret = arg0.subarray(arg1 >>> 0, arg2 >>> 0);
727
+ return ret;
728
+ },
729
+ __wbg_versions_276b2795b1c6a219: function(arg0) {
730
+ const ret = arg0.versions;
731
+ return ret;
732
+ },
733
+ __wbindgen_generic_0000000000000001: function(arg0, arg1) {
734
+ // Cast intrinsic for `Ref(Slice(U8)) -> NamedExternref("Uint8Array")`.
735
+ const ret = getArrayU8FromWasm0(arg0, arg1);
736
+ return ret;
737
+ },
738
+ __wbindgen_generic_0000000000000002: function(arg0, arg1) {
739
+ // Cast intrinsic for `Ref(String) -> Externref`.
740
+ const ret = getStringFromWasm0(arg0, arg1);
741
+ return ret;
742
+ },
743
+ __wbindgen_init_externref_table: function() {
744
+ const table = wasm.__wbindgen_externrefs;
745
+ const offset = table.grow(4);
746
+ table.set(0, undefined);
747
+ table.set(offset + 0, undefined);
748
+ table.set(offset + 1, null);
749
+ table.set(offset + 2, true);
750
+ table.set(offset + 3, false);
751
+ },
752
+ };
753
+ return {
754
+ __proto__: null,
755
+ "./canvist_headless_ssr_bg.js": import0,
756
+ };
757
+ }
758
+
759
+ const WasmDocFinalization = (typeof FinalizationRegistry === 'undefined')
760
+ ? { register: () => {}, unregister: () => {} }
761
+ : new FinalizationRegistry(ptr => wasm.__wbg_wasmdoc_free(ptr, 1));
762
+ const WasmEngineFinalization = (typeof FinalizationRegistry === 'undefined')
763
+ ? { register: () => {}, unregister: () => {} }
764
+ : new FinalizationRegistry(ptr => wasm.__wbg_wasmengine_free(ptr, 1));
765
+ const WasmRendererFinalization = (typeof FinalizationRegistry === 'undefined')
766
+ ? { register: () => {}, unregister: () => {} }
767
+ : new FinalizationRegistry(ptr => wasm.__wbg_wasmrenderer_free(ptr, 1));
768
+
769
+ function addToExternrefTable0(obj) {
770
+ const idx = wasm.__externref_table_alloc();
771
+ wasm.__wbindgen_externrefs.set(idx, obj);
772
+ return idx;
773
+ }
774
+
775
+ function getArrayJsValueFromWasm0(ptr, len) {
776
+ ptr = ptr >>> 0;
777
+ const mem = getDataViewMemory0();
778
+ const result = [];
779
+ for (let i = ptr; i < ptr + 4 * len; i += 4) {
780
+ result.push(wasm.__wbindgen_externrefs.get(mem.getUint32(i, true)));
781
+ }
782
+ wasm.__externref_drop_slice(ptr, len);
783
+ return result;
784
+ }
785
+
786
+ function getArrayU8FromWasm0(ptr, len) {
787
+ ptr = ptr >>> 0;
788
+ return getUint8ArrayMemory0().subarray(ptr / 1, ptr / 1 + len);
789
+ }
790
+
791
+ let cachedDataViewMemory0 = null;
792
+ function getDataViewMemory0() {
793
+ if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || (cachedDataViewMemory0.buffer.detached === undefined && cachedDataViewMemory0.buffer !== wasm.memory.buffer)) {
794
+ cachedDataViewMemory0 = new DataView(wasm.memory.buffer);
795
+ }
796
+ return cachedDataViewMemory0;
797
+ }
798
+
799
+ function getStringFromWasm0(ptr, len) {
800
+ return decodeText(ptr >>> 0, len);
801
+ }
802
+
803
+ let cachedUint32ArrayMemory0 = null;
804
+ function getUint32ArrayMemory0() {
805
+ if (cachedUint32ArrayMemory0 === null || cachedUint32ArrayMemory0.byteLength === 0) {
806
+ cachedUint32ArrayMemory0 = new Uint32Array(wasm.memory.buffer);
807
+ }
808
+ return cachedUint32ArrayMemory0;
809
+ }
810
+
811
+ let cachedUint8ArrayMemory0 = null;
812
+ function getUint8ArrayMemory0() {
813
+ if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
814
+ cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
815
+ }
816
+ return cachedUint8ArrayMemory0;
817
+ }
818
+
819
+ function handleError(f, args) {
820
+ try {
821
+ return f.apply(this, args);
822
+ } catch (e) {
823
+ const idx = addToExternrefTable0(e);
824
+ wasm.__wbindgen_exn_store(idx);
825
+ }
826
+ }
827
+
828
+ function isLikeNone(x) {
829
+ return x === undefined || x === null;
830
+ }
831
+
832
+ function passArray32ToWasm0(arg, malloc) {
833
+ const ptr = malloc(arg.length * 4, 4) >>> 0;
834
+ getUint32ArrayMemory0().set(arg, ptr / 4);
835
+ WASM_VECTOR_LEN = arg.length;
836
+ return ptr;
837
+ }
838
+
839
+ function passArray8ToWasm0(arg, malloc) {
840
+ const ptr = malloc(arg.length * 1, 1) >>> 0;
841
+ getUint8ArrayMemory0().set(arg, ptr / 1);
842
+ WASM_VECTOR_LEN = arg.length;
843
+ return ptr;
844
+ }
845
+
846
+ function passArrayJsValueToWasm0(array, malloc) {
847
+ const ptr = malloc(array.length * 4, 4) >>> 0;
848
+ for (let i = 0; i < array.length; i++) {
849
+ const add = addToExternrefTable0(array[i]);
850
+ getDataViewMemory0().setUint32(ptr + 4 * i, add, true);
851
+ }
852
+ WASM_VECTOR_LEN = array.length;
853
+ return ptr;
854
+ }
855
+
856
+ function passStringToWasm0(arg, malloc, realloc) {
857
+ if (realloc === undefined) {
858
+ const buf = cachedTextEncoder.encode(arg);
859
+ const ptr = malloc(buf.length, 1) >>> 0;
860
+ getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
861
+ WASM_VECTOR_LEN = buf.length;
862
+ return ptr;
863
+ }
864
+
865
+ let len = arg.length;
866
+ let ptr = malloc(len, 1) >>> 0;
867
+
868
+ const mem = getUint8ArrayMemory0();
869
+
870
+ let offset = 0;
871
+
872
+ for (; offset < len; offset++) {
873
+ const code = arg.charCodeAt(offset);
874
+ if (code > 0x7F) break;
875
+ mem[ptr + offset] = code;
876
+ }
877
+ if (offset !== len) {
878
+ if (offset !== 0) {
879
+ arg = arg.slice(offset);
880
+ }
881
+ ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
882
+ const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
883
+ const ret = cachedTextEncoder.encodeInto(arg, view);
884
+
885
+ offset += ret.written;
886
+ ptr = realloc(ptr, len, offset, 1) >>> 0;
887
+ }
888
+
889
+ WASM_VECTOR_LEN = offset;
890
+ return ptr;
891
+ }
892
+
893
+ function takeFromExternrefTable0(idx) {
894
+ const value = wasm.__wbindgen_externrefs.get(idx);
895
+ wasm.__externref_table_dealloc(idx);
896
+ return value;
897
+ }
898
+
899
+ let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
900
+ cachedTextDecoder.decode();
901
+ const MAX_SAFARI_DECODE_BYTES = 2146435072;
902
+ let numBytesDecoded = 0;
903
+ function decodeText(ptr, len) {
904
+ numBytesDecoded += len;
905
+ if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {
906
+ cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
907
+ cachedTextDecoder.decode();
908
+ numBytesDecoded = len;
909
+ }
910
+ return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
911
+ }
912
+
913
+ const cachedTextEncoder = new TextEncoder();
914
+
915
+ if (!('encodeInto' in cachedTextEncoder)) {
916
+ cachedTextEncoder.encodeInto = function (arg, view) {
917
+ const buf = cachedTextEncoder.encode(arg);
918
+ view.set(buf);
919
+ return {
920
+ read: arg.length,
921
+ written: buf.length
922
+ };
923
+ };
924
+ }
925
+
926
+ let WASM_VECTOR_LEN = 0;
927
+
928
+ let wasmModule, wasmInstance, wasm;
929
+ function __wbg_finalize_init(instance, module) {
930
+ wasmInstance = instance;
931
+ wasm = instance.exports;
932
+ wasmModule = module;
933
+ cachedDataViewMemory0 = null;
934
+ cachedUint32ArrayMemory0 = null;
935
+ cachedUint8ArrayMemory0 = null;
936
+ wasm.__wbindgen_start();
937
+ return wasm;
938
+ }
939
+
940
+ async function __wbg_load(module, imports) {
941
+ if (typeof Response === 'function' && module instanceof Response) {
942
+ if (!module.ok) {
943
+ throw new Error(`failed to fetch Wasm: ${module.status} ${module.statusText} fetching '${module.url}'`);
944
+ }
945
+
946
+ if (typeof WebAssembly.instantiateStreaming === 'function') {
947
+ try {
948
+ return await WebAssembly.instantiateStreaming(module, imports);
949
+ } catch (e) {
950
+ const validResponse = expectedResponseType(module.type);
951
+
952
+ if (validResponse && module.headers.get('Content-Type') !== 'application/wasm') {
953
+ 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);
954
+
955
+ } else { throw e; }
956
+ }
957
+ }
958
+
959
+ const bytes = await module.arrayBuffer();
960
+ return await WebAssembly.instantiate(bytes, imports);
961
+ } else {
962
+ const instance = await WebAssembly.instantiate(module, imports);
963
+
964
+ if (instance instanceof WebAssembly.Instance) {
965
+ return { instance, module };
966
+ } else {
967
+ return instance;
968
+ }
969
+ }
970
+
971
+ function expectedResponseType(type) {
972
+ switch (type) {
973
+ case 'basic': case 'cors': case 'default': return true;
974
+ }
975
+ return false;
976
+ }
977
+ }
978
+
979
+ function initSync(module) {
980
+ if (wasm !== undefined) return wasm;
981
+
982
+
983
+ if (module !== undefined) {
984
+ if (Object.getPrototypeOf(module) === Object.prototype) {
985
+ ({module} = module)
986
+ } else {
987
+ console.warn('using deprecated parameters for `initSync()`; pass a single object instead')
988
+ }
989
+ }
990
+
991
+ const imports = __wbg_get_imports();
992
+ if (!(module instanceof WebAssembly.Module)) {
993
+ module = new WebAssembly.Module(module);
994
+ }
995
+ const instance = new WebAssembly.Instance(module, imports);
996
+ return __wbg_finalize_init(instance, module);
997
+ }
998
+
999
+ async function __wbg_init(module_or_path) {
1000
+ if (wasm !== undefined) return wasm;
1001
+
1002
+
1003
+ if (module_or_path !== undefined) {
1004
+ if (Object.getPrototypeOf(module_or_path) === Object.prototype) {
1005
+ ({module_or_path} = module_or_path)
1006
+ } else {
1007
+ console.warn('using deprecated parameters for the initialization function; pass a single object instead')
1008
+ }
1009
+ }
1010
+
1011
+ if (module_or_path === undefined) {
1012
+ module_or_path = new URL('canvist_headless_ssr_bg.wasm', import.meta.url);
1013
+ }
1014
+ const imports = __wbg_get_imports();
1015
+
1016
+ if (typeof module_or_path === 'string' || (typeof Request === 'function' && module_or_path instanceof Request) || (typeof URL === 'function' && module_or_path instanceof URL)) {
1017
+ module_or_path = fetch(module_or_path);
1018
+ }
1019
+
1020
+ const { instance, module } = await __wbg_load(await module_or_path, imports);
1021
+
1022
+ return __wbg_finalize_init(instance, module);
1023
+ }
1024
+
1025
+ export { initSync, __wbg_init as default };