@markup-carve/carve-wasm 0.1.5 → 0.1.7

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.
@@ -0,0 +1,2373 @@
1
+ /* @ts-self-types="./carve_wasm.d.ts" */
2
+
3
+ /**
4
+ * A parser snapshot retained between editor updates. Call `free()` when done.
5
+ */
6
+ class ParserSession {
7
+ __destroy_into_raw() {
8
+ const ptr = this.__wbg_ptr;
9
+ this.__wbg_ptr = 0;
10
+ ParserSessionFinalization.unregister(this);
11
+ return ptr;
12
+ }
13
+ free() {
14
+ const ptr = this.__destroy_into_raw();
15
+ wasm.__wbg_parsersession_free(ptr, 0);
16
+ }
17
+ /**
18
+ * Apply byte edits; a rejected edit leaves the session unchanged.
19
+ * @param {string} changes
20
+ * @returns {string}
21
+ */
22
+ edit(changes) {
23
+ let deferred3_0;
24
+ let deferred3_1;
25
+ try {
26
+ const ptr0 = passStringToWasm0(changes, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
27
+ const len0 = WASM_VECTOR_LEN;
28
+ const ret = wasm.parsersession_edit(this.__wbg_ptr, ptr0, len0);
29
+ var ptr2 = ret[0];
30
+ var len2 = ret[1];
31
+ if (ret[3]) {
32
+ ptr2 = 0; len2 = 0;
33
+ throw takeFromExternrefTable0(ret[2]);
34
+ }
35
+ deferred3_0 = ptr2;
36
+ deferred3_1 = len2;
37
+ return getStringFromWasm0(ptr2, len2);
38
+ } finally {
39
+ wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);
40
+ }
41
+ }
42
+ /**
43
+ * @param {string} source
44
+ */
45
+ constructor(source) {
46
+ const ptr0 = passStringToWasm0(source, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
47
+ const len0 = WASM_VECTOR_LEN;
48
+ const ret = wasm.parsersession_new(ptr0, len0);
49
+ this.__wbg_ptr = ret >>> 0;
50
+ ParserSessionFinalization.register(this, this.__wbg_ptr, this);
51
+ return this;
52
+ }
53
+ /**
54
+ * The current result, with byte ranges and parser-work counters.
55
+ * @returns {string}
56
+ */
57
+ snapshot() {
58
+ let deferred1_0;
59
+ let deferred1_1;
60
+ try {
61
+ const ret = wasm.parsersession_snapshot(this.__wbg_ptr);
62
+ deferred1_0 = ret[0];
63
+ deferred1_1 = ret[1];
64
+ return getStringFromWasm0(ret[0], ret[1]);
65
+ } finally {
66
+ wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
67
+ }
68
+ }
69
+ }
70
+ if (Symbol.dispose) ParserSession.prototype[Symbol.dispose] = ParserSession.prototype.free;
71
+ exports.ParserSession = ParserSession;
72
+
73
+ /**
74
+ * Replay patch JSON onto a PART 12 tree, returning the result as AST JSON.
75
+ * @param {string} ast
76
+ * @param {string} patch
77
+ * @returns {string}
78
+ */
79
+ function applyAstPatch(ast, patch) {
80
+ let deferred4_0;
81
+ let deferred4_1;
82
+ try {
83
+ const ptr0 = passStringToWasm0(ast, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
84
+ const len0 = WASM_VECTOR_LEN;
85
+ const ptr1 = passStringToWasm0(patch, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
86
+ const len1 = WASM_VECTOR_LEN;
87
+ const ret = wasm.applyAstPatch(ptr0, len0, ptr1, len1);
88
+ var ptr3 = ret[0];
89
+ var len3 = ret[1];
90
+ if (ret[3]) {
91
+ ptr3 = 0; len3 = 0;
92
+ throw takeFromExternrefTable0(ret[2]);
93
+ }
94
+ deferred4_0 = ptr3;
95
+ deferred4_1 = len3;
96
+ return getStringFromWasm0(ptr3, len3);
97
+ } finally {
98
+ wasm.__wbindgen_free(deferred4_0, deferred4_1, 1);
99
+ }
100
+ }
101
+ exports.applyAstPatch = applyAstPatch;
102
+
103
+ /**
104
+ * Apply a security profile to an AST-JSON document (PART 12), keeping the
105
+ * filtered tree.
106
+ *
107
+ * The `profile` render option filters on the way to HTML and throws the result
108
+ * of the filtering away. This is the same pass with the tree kept, so a host
109
+ * that stores, diffs or re-renders an untrusted document does not have to
110
+ * render HTML and parse it back to get one.
111
+ *
112
+ * `violations` reports what the filter degraded or stripped, which the HTML
113
+ * path cannot: a profile whose action is `error` throws instead, so a
114
+ * resolved call under `to-text` or `strip` is the only place this is visible.
115
+ *
116
+ * Only `profileBaseHost` and `smartTypography` are read from `options`. The
117
+ * rest of the render options describe a renderer, and this is not one.
118
+ *
119
+ * The profile's `max_length` is NOT enforced here: the engine applies it to the
120
+ * source bytes before a parse, and this entry point is handed a tree.
121
+ * @param {string} json
122
+ * @param {string} profile
123
+ * @param {object | null} [options]
124
+ * @returns {ProfileFilterResult}
125
+ */
126
+ function applyProfile(json, profile, options) {
127
+ const ptr0 = passStringToWasm0(json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
128
+ const len0 = WASM_VECTOR_LEN;
129
+ const ptr1 = passStringToWasm0(profile, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
130
+ const len1 = WASM_VECTOR_LEN;
131
+ const ret = wasm.applyProfile(ptr0, len0, ptr1, len1, isLikeNone(options) ? 0 : addToExternrefTable0(options));
132
+ if (ret[2]) {
133
+ throw takeFromExternrefTable0(ret[1]);
134
+ }
135
+ return takeFromExternrefTable0(ret[0]);
136
+ }
137
+ exports.applyProfile = applyProfile;
138
+
139
+ /**
140
+ * Replay a reversible patch, forward or inverted.
141
+ *
142
+ * The fingerprint is checked first: a tree that is not the one this patch was
143
+ * made against is refused rather than half-patched. That is a broken caller
144
+ * contract, so it throws.
145
+ * @param {string} ast
146
+ * @param {string} patch
147
+ * @param {boolean | null} [inverse]
148
+ * @returns {string}
149
+ */
150
+ function applyReversibleAstPatch(ast, patch, inverse) {
151
+ let deferred4_0;
152
+ let deferred4_1;
153
+ try {
154
+ const ptr0 = passStringToWasm0(ast, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
155
+ const len0 = WASM_VECTOR_LEN;
156
+ const ptr1 = passStringToWasm0(patch, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
157
+ const len1 = WASM_VECTOR_LEN;
158
+ const ret = wasm.applyReversibleAstPatch(ptr0, len0, ptr1, len1, isLikeNone(inverse) ? 0xFFFFFF : inverse ? 1 : 0);
159
+ var ptr3 = ret[0];
160
+ var len3 = ret[1];
161
+ if (ret[3]) {
162
+ ptr3 = 0; len3 = 0;
163
+ throw takeFromExternrefTable0(ret[2]);
164
+ }
165
+ deferred4_0 = ptr3;
166
+ deferred4_1 = len3;
167
+ return getStringFromWasm0(ptr3, len3);
168
+ } finally {
169
+ wasm.__wbindgen_free(deferred4_0, deferred4_1, 1);
170
+ }
171
+ }
172
+ exports.applyReversibleAstPatch = applyReversibleAstPatch;
173
+
174
+ /**
175
+ * Apply a trusted patch after its source length and fingerprint still match.
176
+ * @param {string} source
177
+ * @param {SourcePatch} patch
178
+ * @returns {string}
179
+ */
180
+ function applySourcePatch(source, patch) {
181
+ let deferred3_0;
182
+ let deferred3_1;
183
+ try {
184
+ const ptr0 = passStringToWasm0(source, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
185
+ const len0 = WASM_VECTOR_LEN;
186
+ const ret = wasm.applySourcePatch(ptr0, len0, patch);
187
+ var ptr2 = ret[0];
188
+ var len2 = ret[1];
189
+ if (ret[3]) {
190
+ ptr2 = 0; len2 = 0;
191
+ throw takeFromExternrefTable0(ret[2]);
192
+ }
193
+ deferred3_0 = ptr2;
194
+ deferred3_1 = len2;
195
+ return getStringFromWasm0(ptr2, len2);
196
+ } finally {
197
+ wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);
198
+ }
199
+ }
200
+ exports.applySourcePatch = applySourcePatch;
201
+
202
+ /**
203
+ * Render an AST-JSON document (PART 12) to ANSI-styled text. See
204
+ * [`ast_json_to_markdown`], including what a tree without positions costs.
205
+ * @param {string} json
206
+ * @param {RenderOptions | null} options
207
+ * @returns {string}
208
+ */
209
+ function astJsonToAnsi(json, options) {
210
+ let deferred3_0;
211
+ let deferred3_1;
212
+ try {
213
+ const ptr0 = passStringToWasm0(json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
214
+ const len0 = WASM_VECTOR_LEN;
215
+ const ret = wasm.astJsonToAnsi(ptr0, len0, isLikeNone(options) ? 0 : addToExternrefTable0(options));
216
+ var ptr2 = ret[0];
217
+ var len2 = ret[1];
218
+ if (ret[3]) {
219
+ ptr2 = 0; len2 = 0;
220
+ throw takeFromExternrefTable0(ret[2]);
221
+ }
222
+ deferred3_0 = ptr2;
223
+ deferred3_1 = len2;
224
+ return getStringFromWasm0(ptr2, len2);
225
+ } finally {
226
+ wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);
227
+ }
228
+ }
229
+ exports.astJsonToAnsi = astJsonToAnsi;
230
+
231
+ /**
232
+ * Render an AST-JSON document (PART 12) back to canonical Carve source.
233
+ *
234
+ * The round trip a host needs to SAVE an edited tree, rather than only display
235
+ * it. A tree holding something no Carve source can spell is refused rather
236
+ * than written approximately.
237
+ * @param {string} json
238
+ * @returns {string}
239
+ */
240
+ function astJsonToCarve(json) {
241
+ let deferred3_0;
242
+ let deferred3_1;
243
+ try {
244
+ const ptr0 = passStringToWasm0(json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
245
+ const len0 = WASM_VECTOR_LEN;
246
+ const ret = wasm.astJsonToCarve(ptr0, len0);
247
+ var ptr2 = ret[0];
248
+ var len2 = ret[1];
249
+ if (ret[3]) {
250
+ ptr2 = 0; len2 = 0;
251
+ throw takeFromExternrefTable0(ret[2]);
252
+ }
253
+ deferred3_0 = ptr2;
254
+ deferred3_1 = len2;
255
+ return getStringFromWasm0(ptr2, len2);
256
+ } finally {
257
+ wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);
258
+ }
259
+ }
260
+ exports.astJsonToCarve = astJsonToCarve;
261
+
262
+ /**
263
+ * Render an AST-JSON document (PART 12) to HTML.
264
+ *
265
+ * The other half of `parseJson`. A host that reads the tree in a browser does
266
+ * it to CHANGE something, and until now there was no way to render the result:
267
+ * the binding could serialize a tree out and not take one back.
268
+ *
269
+ * Takes the same options object as [`to_html_with_options`], so an edited tree
270
+ * renders under the profile, labels and switches the host already configured.
271
+ * @param {string} json
272
+ * @param {RenderOptions | null} options
273
+ * @returns {string}
274
+ */
275
+ function astJsonToHtml(json, options) {
276
+ let deferred3_0;
277
+ let deferred3_1;
278
+ try {
279
+ const ptr0 = passStringToWasm0(json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
280
+ const len0 = WASM_VECTOR_LEN;
281
+ const ret = wasm.astJsonToHtml(ptr0, len0, isLikeNone(options) ? 0 : addToExternrefTable0(options));
282
+ var ptr2 = ret[0];
283
+ var len2 = ret[1];
284
+ if (ret[3]) {
285
+ ptr2 = 0; len2 = 0;
286
+ throw takeFromExternrefTable0(ret[2]);
287
+ }
288
+ deferred3_0 = ptr2;
289
+ deferred3_1 = len2;
290
+ return getStringFromWasm0(ptr2, len2);
291
+ } finally {
292
+ wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);
293
+ }
294
+ }
295
+ exports.astJsonToHtml = astJsonToHtml;
296
+
297
+ /**
298
+ * Render an AST-JSON document (PART 12) to Markdown.
299
+ *
300
+ * The direct call for a host that already holds a tree. Without it Markdown was
301
+ * reached through `astJsonToCarve` and then `toMarkdown`: a canonical write, a
302
+ * re-parse and a second render for one answer, and lossier than this, because a
303
+ * tree holding something no Carve source can spell is refused by the write
304
+ * rather than rendered.
305
+ *
306
+ * Takes the same options object as [`to_markdown_with_options`], and reads the
307
+ * same narrow part of it. The profile filter and the `before_render` hooks run,
308
+ * as they do in [`ast_json_to_html`].
309
+ *
310
+ * ORDERING FOLLOWS THE TREE. `toMarkdown` parses with positions on, because
311
+ * section 7 orders collected definitions by source position. A tree arriving as
312
+ * JSON carries whatever positions its producer put there, and one carrying none
313
+ * prints its footnote and link definitions in label order. That is the only
314
+ * order available to a tree without spans, so it is reported here rather than
315
+ * repaired.
316
+ * @param {string} json
317
+ * @param {RenderOptions | null} options
318
+ * @returns {string}
319
+ */
320
+ function astJsonToMarkdown(json, options) {
321
+ let deferred3_0;
322
+ let deferred3_1;
323
+ try {
324
+ const ptr0 = passStringToWasm0(json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
325
+ const len0 = WASM_VECTOR_LEN;
326
+ const ret = wasm.astJsonToMarkdown(ptr0, len0, isLikeNone(options) ? 0 : addToExternrefTable0(options));
327
+ var ptr2 = ret[0];
328
+ var len2 = ret[1];
329
+ if (ret[3]) {
330
+ ptr2 = 0; len2 = 0;
331
+ throw takeFromExternrefTable0(ret[2]);
332
+ }
333
+ deferred3_0 = ptr2;
334
+ deferred3_1 = len2;
335
+ return getStringFromWasm0(ptr2, len2);
336
+ } finally {
337
+ wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);
338
+ }
339
+ }
340
+ exports.astJsonToMarkdown = astJsonToMarkdown;
341
+
342
+ /**
343
+ * Render an AST-JSON document (PART 12) to plain text. See
344
+ * [`ast_json_to_markdown`], including what a tree without positions costs.
345
+ * @param {string} json
346
+ * @param {RenderOptions | null} options
347
+ * @returns {string}
348
+ */
349
+ function astJsonToPlainText(json, options) {
350
+ let deferred3_0;
351
+ let deferred3_1;
352
+ try {
353
+ const ptr0 = passStringToWasm0(json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
354
+ const len0 = WASM_VECTOR_LEN;
355
+ const ret = wasm.astJsonToPlainText(ptr0, len0, isLikeNone(options) ? 0 : addToExternrefTable0(options));
356
+ var ptr2 = ret[0];
357
+ var len2 = ret[1];
358
+ if (ret[3]) {
359
+ ptr2 = 0; len2 = 0;
360
+ throw takeFromExternrefTable0(ret[2]);
361
+ }
362
+ deferred3_0 = ptr2;
363
+ deferred3_1 = len2;
364
+ return getStringFromWasm0(ptr2, len2);
365
+ } finally {
366
+ wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);
367
+ }
368
+ }
369
+ exports.astJsonToPlainText = astJsonToPlainText;
370
+
371
+ /**
372
+ * The difference between two PART 12 trees, as patch JSON.
373
+ *
374
+ * ```js
375
+ * const patch = createAstPatch(parseJson('# One\n'), parseJson('# Two\n'))
376
+ * applyAstPatch(parseJson('# One\n'), patch) // the '# Two' tree
377
+ * ```
378
+ *
379
+ * Trees and patches both cross as JSON strings, matching `parseJson` and
380
+ * `astJsonToHtml`. A patch carries node payloads, so it carries arbitrary
381
+ * document text - the reason `parseJson` chose a string in the first place.
382
+ *
383
+ * The engine's `ast_patch_to_json` and `ast_patch_from_json` are not bound
384
+ * separately. With the patch crossing as JSON they ARE the encoding of this
385
+ * pair, and a host calling them would be converting JSON it already holds.
386
+ *
387
+ * The operations are position-independent `{ op, path, value }`, so a patch
388
+ * stays meaningful against a tree that moved underneath it - unlike a source
389
+ * patch, which `createSourcePatch` fingerprints against staleness.
390
+ * @param {string} before
391
+ * @param {string} after
392
+ * @returns {string}
393
+ */
394
+ function createAstPatch(before, after) {
395
+ let deferred4_0;
396
+ let deferred4_1;
397
+ try {
398
+ const ptr0 = passStringToWasm0(before, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
399
+ const len0 = WASM_VECTOR_LEN;
400
+ const ptr1 = passStringToWasm0(after, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
401
+ const len1 = WASM_VECTOR_LEN;
402
+ const ret = wasm.createAstPatch(ptr0, len0, ptr1, len1);
403
+ var ptr3 = ret[0];
404
+ var len3 = ret[1];
405
+ if (ret[3]) {
406
+ ptr3 = 0; len3 = 0;
407
+ throw takeFromExternrefTable0(ret[2]);
408
+ }
409
+ deferred4_0 = ptr3;
410
+ deferred4_1 = len3;
411
+ return getStringFromWasm0(ptr3, len3);
412
+ } finally {
413
+ wasm.__wbindgen_free(deferred4_0, deferred4_1, 1);
414
+ }
415
+ }
416
+ exports.createAstPatch = createAstPatch;
417
+
418
+ /**
419
+ * The same difference with its inverse and both fingerprints, as one JSON
420
+ * object: `{ forward, inverse, beforeFingerprint, afterFingerprint }`.
421
+ *
422
+ * This is the shape an undo step wants. THE STACK IS THE HOST'S: every entry
423
+ * point in this package is a pure function that owns nothing, so there is no
424
+ * history kept here to undo against, and a browser host already has one - a
425
+ * key handler, a toolbar, an editor's own history plugin.
426
+ *
427
+ * What the pair adds over two `createAstPatch` calls is the precondition.
428
+ * [`apply_reversible_ast_patch`] refuses a tree whose fingerprint is not the
429
+ * one the patch was made against, so an undo cannot be replayed onto a
430
+ * document that has moved on.
431
+ * @param {string} before
432
+ * @param {string} after
433
+ * @returns {string}
434
+ */
435
+ function createReversibleAstPatch(before, after) {
436
+ let deferred4_0;
437
+ let deferred4_1;
438
+ try {
439
+ const ptr0 = passStringToWasm0(before, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
440
+ const len0 = WASM_VECTOR_LEN;
441
+ const ptr1 = passStringToWasm0(after, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
442
+ const len1 = WASM_VECTOR_LEN;
443
+ const ret = wasm.createReversibleAstPatch(ptr0, len0, ptr1, len1);
444
+ var ptr3 = ret[0];
445
+ var len3 = ret[1];
446
+ if (ret[3]) {
447
+ ptr3 = 0; len3 = 0;
448
+ throw takeFromExternrefTable0(ret[2]);
449
+ }
450
+ deferred4_0 = ptr3;
451
+ deferred4_1 = len3;
452
+ return getStringFromWasm0(ptr3, len3);
453
+ } finally {
454
+ wasm.__wbindgen_free(deferred4_0, deferred4_1, 1);
455
+ }
456
+ }
457
+ exports.createReversibleAstPatch = createReversibleAstPatch;
458
+
459
+ /**
460
+ * Build the smallest single UTF-8 byte-range replacement between two sources.
461
+ * @param {string} source
462
+ * @param {string} replacement
463
+ * @param {string} kind
464
+ * @param {string} code
465
+ * @returns {SourcePatch}
466
+ */
467
+ function createSourcePatch(source, replacement, kind, code) {
468
+ const ptr0 = passStringToWasm0(source, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
469
+ const len0 = WASM_VECTOR_LEN;
470
+ const ptr1 = passStringToWasm0(replacement, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
471
+ const len1 = WASM_VECTOR_LEN;
472
+ const ptr2 = passStringToWasm0(kind, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
473
+ const len2 = WASM_VECTOR_LEN;
474
+ const ptr3 = passStringToWasm0(code, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
475
+ const len3 = WASM_VECTOR_LEN;
476
+ const ret = wasm.createSourcePatch(ptr0, len0, ptr1, len1, ptr2, len2, ptr3, len3);
477
+ if (ret[2]) {
478
+ throw takeFromExternrefTable0(ret[1]);
479
+ }
480
+ return takeFromExternrefTable0(ret[0]);
481
+ }
482
+ exports.createSourcePatch = createSourcePatch;
483
+
484
+ /**
485
+ * Expand `{{ path }}` include directives (spec PART 9 §19) through a JS
486
+ * resolver, and hand back the expanded tree as AST JSON.
487
+ *
488
+ * The resolver MUST BE SYNCHRONOUS, which decides who can use this. A browser
489
+ * host that would resolve a path by `fetch` cannot: `fetch` is a Promise and
490
+ * wasm-bindgen cannot await across the call. A host whose files are already in
491
+ * memory - an editor with its open buffers, a bundler, a VFS, a test harness -
492
+ * resolves from that map and is exactly who this is for.
493
+ *
494
+ * ```js
495
+ * const files = new Map([['child.crv', 'Included body.\n']])
496
+ * expandIncludes('Before.\n\n{{ child.crv }}\n', {
497
+ * resolve: (path) => files.get(path) ?? null,
498
+ * })
499
+ * // { json, warnings: [], suppressedWarnings: 0, dependencies: […],
500
+ * // chargedBytes: 15, resolverErrors: [] }
501
+ * ```
502
+ *
503
+ * The resolver returns the child's source as a string, or
504
+ * `{ source, id }` when it can name the file canonically - the id is what the
505
+ * cycle guard compares, so two spellings of one file defeat it without one.
506
+ * `null` refuses the directive as `not-found`; `{ denial }` refuses it in one
507
+ * of the classes §19 names.
508
+ *
509
+ * An `async` resolver returns a Promise, which is not a string and cannot be
510
+ * awaited. That is a per-document failure reported in `resolverErrors`,
511
+ * matching what an `async` `renderers.math` gets from
512
+ * [`to_html_with_renderers`]: the directive stays literal and the caller is
513
+ * told why, rather than the value being swallowed or stringified.
514
+ *
515
+ * The BUDGETS are part of the contract, not a detail: `maxBytes` defaults to
516
+ * `max(1 MB, 8 x source bytes)`, `maxDepth` to 16, `maxResolverCalls` to 1000
517
+ * and `maxWarnings` to 100. They bound what a document of directives can make
518
+ * a host do, and lowering them is how a host serving untrusted documents keeps
519
+ * that bounded.
520
+ *
521
+ * The tree carries no positions. Expansion merges nodes from several files,
522
+ * and a span on a node that came from a child would point into a source the
523
+ * caller did not pass.
524
+ * @param {string} source
525
+ * @param {IncludeOptions} options
526
+ * @returns {IncludeExpansion}
527
+ */
528
+ function expandIncludes(source, options) {
529
+ const ptr0 = passStringToWasm0(source, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
530
+ const len0 = WASM_VECTOR_LEN;
531
+ const ret = wasm.expandIncludes(ptr0, len0, options);
532
+ if (ret[2]) {
533
+ throw takeFromExternrefTable0(ret[1]);
534
+ }
535
+ return takeFromExternrefTable0(ret[0]);
536
+ }
537
+ exports.expandIncludes = expandIncludes;
538
+
539
+ /**
540
+ * Every extension name this build accepts, in registry order.
541
+ *
542
+ * Taken from the engine, so a new extension is reachable as soon as the pin
543
+ * moves. Nothing here lists names.
544
+ * @returns {string[]}
545
+ */
546
+ function extensions() {
547
+ const ret = wasm.extensions();
548
+ var v1 = getArrayJsValueFromWasm0(ret[0], ret[1]).slice();
549
+ wasm.__wbindgen_free(ret[0], ret[1] * 4, 4);
550
+ return v1;
551
+ }
552
+ exports.extensions = extensions;
553
+
554
+ /**
555
+ * Convert BBCode source to Carve.
556
+ *
557
+ * Rejects input past the engine's `BBCODE_MAX_INPUT_LENGTH` rather than
558
+ * working on it: the importer's cost is superlinear in places, and a browser
559
+ * host cannot afford to find that out on the main thread.
560
+ * @param {string} source
561
+ * @returns {string}
562
+ */
563
+ function fromBbcode(source) {
564
+ let deferred3_0;
565
+ let deferred3_1;
566
+ try {
567
+ const ptr0 = passStringToWasm0(source, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
568
+ const len0 = WASM_VECTOR_LEN;
569
+ const ret = wasm.fromBbcode(ptr0, len0);
570
+ var ptr2 = ret[0];
571
+ var len2 = ret[1];
572
+ if (ret[3]) {
573
+ ptr2 = 0; len2 = 0;
574
+ throw takeFromExternrefTable0(ret[2]);
575
+ }
576
+ deferred3_0 = ptr2;
577
+ deferred3_1 = len2;
578
+ return getStringFromWasm0(ptr2, len2);
579
+ } finally {
580
+ wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);
581
+ }
582
+ }
583
+ exports.fromBbcode = fromBbcode;
584
+
585
+ /**
586
+ * Convert Djot source to Carve.
587
+ *
588
+ * Carve diverges from Djot deliberately - the emphasis delimiters are swapped,
589
+ * among others - so a Djot document is not Carve source and pasting one in
590
+ * renders wrongly rather than failing.
591
+ * @param {string} source
592
+ * @returns {string}
593
+ */
594
+ function fromDjot(source) {
595
+ let deferred2_0;
596
+ let deferred2_1;
597
+ try {
598
+ const ptr0 = passStringToWasm0(source, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
599
+ const len0 = WASM_VECTOR_LEN;
600
+ const ret = wasm.fromDjot(ptr0, len0);
601
+ deferred2_0 = ret[0];
602
+ deferred2_1 = ret[1];
603
+ return getStringFromWasm0(ret[0], ret[1]);
604
+ } finally {
605
+ wasm.__wbindgen_free(deferred2_0, deferred2_1, 1);
606
+ }
607
+ }
608
+ exports.fromDjot = fromDjot;
609
+
610
+ /**
611
+ * @param {string} source
612
+ * @param {string | null} [mode]
613
+ * @returns {MigrationResult}
614
+ */
615
+ function fromHtml(source, mode) {
616
+ const ptr0 = passStringToWasm0(source, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
617
+ const len0 = WASM_VECTOR_LEN;
618
+ var ptr1 = isLikeNone(mode) ? 0 : passStringToWasm0(mode, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
619
+ var len1 = WASM_VECTOR_LEN;
620
+ const ret = wasm.fromHtml(ptr0, len0, ptr1, len1);
621
+ if (ret[2]) {
622
+ throw takeFromExternrefTable0(ret[1]);
623
+ }
624
+ return takeFromExternrefTable0(ret[0]);
625
+ }
626
+ exports.fromHtml = fromHtml;
627
+
628
+ /**
629
+ * @param {string} source
630
+ * @returns {MigrationResult}
631
+ */
632
+ function fromMarkdown(source) {
633
+ const ptr0 = passStringToWasm0(source, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
634
+ const len0 = WASM_VECTOR_LEN;
635
+ const ret = wasm.fromMarkdown(ptr0, len0);
636
+ if (ret[2]) {
637
+ throw takeFromExternrefTable0(ret[1]);
638
+ }
639
+ return takeFromExternrefTable0(ret[0]);
640
+ }
641
+ exports.fromMarkdown = fromMarkdown;
642
+
643
+ /**
644
+ * Convert a ProseMirror document back to canonical Carve source.
645
+ *
646
+ * The save half of the editor loop. A payload the schema map does not describe
647
+ * is refused rather than written approximately, so an editor extended with a
648
+ * node the bridge has never seen fails where it can be reported.
649
+ * @param {string} doc
650
+ * @returns {string}
651
+ */
652
+ function fromProseMirror(doc) {
653
+ let deferred3_0;
654
+ let deferred3_1;
655
+ try {
656
+ const ptr0 = passStringToWasm0(doc, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
657
+ const len0 = WASM_VECTOR_LEN;
658
+ const ret = wasm.fromProseMirror(ptr0, len0);
659
+ var ptr2 = ret[0];
660
+ var len2 = ret[1];
661
+ if (ret[3]) {
662
+ ptr2 = 0; len2 = 0;
663
+ throw takeFromExternrefTable0(ret[2]);
664
+ }
665
+ deferred3_0 = ptr2;
666
+ deferred3_1 = len2;
667
+ return getStringFromWasm0(ptr2, len2);
668
+ } finally {
669
+ wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);
670
+ }
671
+ }
672
+ exports.fromProseMirror = fromProseMirror;
673
+
674
+ /**
675
+ * Import HTML straight to the tree, as AST JSON.
676
+ *
677
+ * `htmlToCarve` writes Carve SOURCE, so a host that wanted the tree had to
678
+ * re-parse what it had just written - two parses of one document to get one
679
+ * answer. This is the same importer without that round trip.
680
+ *
681
+ * ```js
682
+ * const { value, report } = htmlToAst('<p>Hello <b>world</b></p>', 'safe')
683
+ * astJsonToHtml(value)
684
+ * ```
685
+ *
686
+ * Returns the SAME `{ value, report }` shape `htmlToCarve` does, with `value`
687
+ * holding the tree instead of the source, in the same fidelity vocabulary. A
688
+ * third result shape for one importer is what that avoids.
689
+ *
690
+ * The REPORT IS NOT ALWAYS IDENTICAL, and the difference is the point. A loss
691
+ * only a WRITER takes is not reported here, because no writer ran (PART 12
692
+ * §16): a `<figure>` wrapping a table, or a table with an explicit
693
+ * head/body/foot grouping, has no Carve spelling, so `htmlToCarve` reports
694
+ * `structure-unspellable` and this does not - the tree keeps the thing that
695
+ * would have been lost.
696
+ *
697
+ * `mode` is spelled as it is there: `safe` (the default), `semantic`, and
698
+ * trusted-only `roundtrip`.
699
+ * @param {string} source
700
+ * @param {string | null} [mode]
701
+ * @returns {MigrationResult}
702
+ */
703
+ function htmlToAst(source, mode) {
704
+ const ptr0 = passStringToWasm0(source, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
705
+ const len0 = WASM_VECTOR_LEN;
706
+ var ptr1 = isLikeNone(mode) ? 0 : passStringToWasm0(mode, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
707
+ var len1 = WASM_VECTOR_LEN;
708
+ const ret = wasm.htmlToAst(ptr0, len0, ptr1, len1);
709
+ if (ret[2]) {
710
+ throw takeFromExternrefTable0(ret[1]);
711
+ }
712
+ return takeFromExternrefTable0(ret[0]);
713
+ }
714
+ exports.htmlToAst = htmlToAst;
715
+
716
+ /**
717
+ * Import HTML through the Rust HTML5 DOM and canonical Carve writer.
718
+ *
719
+ * Returns `{ value, report }`; `report.diagnostics` makes every lossy import
720
+ * decision observable. `roundtrip` is only safe for Carve-produced HTML.
721
+ * @param {string} source
722
+ * @param {string | null} [mode]
723
+ * @returns {MigrationResult}
724
+ */
725
+ function htmlToCarve(source, mode) {
726
+ const ptr0 = passStringToWasm0(source, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
727
+ const len0 = WASM_VECTOR_LEN;
728
+ var ptr1 = isLikeNone(mode) ? 0 : passStringToWasm0(mode, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
729
+ var len1 = WASM_VECTOR_LEN;
730
+ const ret = wasm.htmlToCarve(ptr0, len0, ptr1, len1);
731
+ if (ret[2]) {
732
+ throw takeFromExternrefTable0(ret[1]);
733
+ }
734
+ return takeFromExternrefTable0(ret[0]);
735
+ }
736
+ exports.htmlToCarve = htmlToCarve;
737
+
738
+ /**
739
+ * The accessibility diagnostics, a second family beside `lintCarve`.
740
+ *
741
+ * Its own rule ids (`a11y/image-alt`, `a11y/heading-jump`) and its own
742
+ * severity, which `lintCarve` has no field for. Offsets are `null` when the
743
+ * node that triggered the rule carried no position.
744
+ * @param {string} source
745
+ * @returns {AccessibilityDiagnostic[]}
746
+ */
747
+ function lintAccessibility(source) {
748
+ const ptr0 = passStringToWasm0(source, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
749
+ const len0 = WASM_VECTOR_LEN;
750
+ const ret = wasm.lintAccessibility(ptr0, len0);
751
+ if (ret[2]) {
752
+ throw takeFromExternrefTable0(ret[1]);
753
+ }
754
+ return takeFromExternrefTable0(ret[0]);
755
+ }
756
+ exports.lintAccessibility = lintAccessibility;
757
+
758
+ /**
759
+ * Lint a document for the degradations PART 15 describes.
760
+ *
761
+ * Returns an array of `{ line, column, rule, message, start, end }`. The rule
762
+ * ids are shared with carve-js and carve-php, so the same trigger reports the
763
+ * same id everywhere. Offsets count UTF-16 CODE UNITS, so they index the
764
+ * JavaScript string the caller holds; the engine answers in bytes and this
765
+ * wrapper converts (#164).
766
+ *
767
+ * Built as JS objects rather than a JSON string: a message carries arbitrary
768
+ * document text, and hand-rolled JSON escaping is where that goes wrong.
769
+ * @param {string} source
770
+ * @returns {LintWarning[]}
771
+ */
772
+ function lintCarve(source) {
773
+ const ptr0 = passStringToWasm0(source, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
774
+ const len0 = WASM_VECTOR_LEN;
775
+ const ret = wasm.lintCarve(ptr0, len0);
776
+ if (ret[2]) {
777
+ throw takeFromExternrefTable0(ret[1]);
778
+ }
779
+ return takeFromExternrefTable0(ret[0]);
780
+ }
781
+ exports.lintCarve = lintCarve;
782
+
783
+ /**
784
+ * Lint a document with the same options object the render entry points take.
785
+ *
786
+ * `lintCarve` is the option-less form. Which degradations exist depends on the
787
+ * extensions in play, so a host that renders with a set has to lint with it.
788
+ * @param {string} source
789
+ * @param {RenderOptions | null} options
790
+ * @returns {any}
791
+ */
792
+ function lintCarveWithOptions(source, options) {
793
+ const ptr0 = passStringToWasm0(source, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
794
+ const len0 = WASM_VECTOR_LEN;
795
+ const ret = wasm.lintCarveWithOptions(ptr0, len0, isLikeNone(options) ? 0 : addToExternrefTable0(options));
796
+ if (ret[2]) {
797
+ throw takeFromExternrefTable0(ret[1]);
798
+ }
799
+ return takeFromExternrefTable0(ret[0]);
800
+ }
801
+ exports.lintCarveWithOptions = lintCarveWithOptions;
802
+
803
+ /**
804
+ * Import Markdown straight to the tree, as AST JSON.
805
+ *
806
+ * `fromMarkdown` writes Carve SOURCE, so a host that wanted the tree had to
807
+ * re-parse what it had just written. This is the same importer without that
808
+ * round trip. The losses `fromMarkdown` reports are not repeated here; a host
809
+ * that needs them calls that one.
810
+ * @param {string} source
811
+ * @returns {string}
812
+ */
813
+ function markdownToAstJson(source) {
814
+ let deferred3_0;
815
+ let deferred3_1;
816
+ try {
817
+ const ptr0 = passStringToWasm0(source, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
818
+ const len0 = WASM_VECTOR_LEN;
819
+ const ret = wasm.markdownToAstJson(ptr0, len0);
820
+ var ptr2 = ret[0];
821
+ var len2 = ret[1];
822
+ if (ret[3]) {
823
+ ptr2 = 0; len2 = 0;
824
+ throw takeFromExternrefTable0(ret[2]);
825
+ }
826
+ deferred3_0 = ptr2;
827
+ deferred3_1 = len2;
828
+ return getStringFromWasm0(ptr2, len2);
829
+ } finally {
830
+ wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);
831
+ }
832
+ }
833
+ exports.markdownToAstJson = markdownToAstJson;
834
+
835
+ /**
836
+ * Three-way merge over PART 12 trees, with conflicts as a VALUE.
837
+ *
838
+ * ```js
839
+ * const { ok, ast, conflicts } = JSON.parse(mergeAst(base, ours, theirs))
840
+ * ```
841
+ *
842
+ * Returns `{ ok, ast, conflicts, resolverErrors }` as one JSON string. A
843
+ * conflict does NOT throw: it is a result the caller asked for, and two people
844
+ * editing one document is the ordinary case rather than a broken contract.
845
+ * `ok` is false, `ast` is null, and `conflicts` says where and why.
846
+ *
847
+ * The `{ ok, ast, conflicts }` shape and the three `reason` names -
848
+ * `both-changed`, `delete-edit`, `concurrent-sequence-edit` - are carve-js's,
849
+ * so a host merging with either engine reads one contract. The Rust engine
850
+ * carries no `deleted` flags on a conflict, so that optional carve-js field is
851
+ * absent here rather than guessed at.
852
+ *
853
+ * `options.resolve` is an optional `(conflict) => 'base' | 'ours' | 'theirs' |
854
+ * { value } | null`, answering conflicts while the merge runs; an answer of
855
+ * `null` leaves one unresolved. IT MUST BE SYNCHRONOUS. A resolver that asks a
856
+ * server, or asks the user, returns a Promise the merge cannot await - that is
857
+ * reported in `resolverErrors` and the conflict is left unresolved, the same
858
+ * treatment an `async` `renderers.math` gets.
859
+ * @param {string} base
860
+ * @param {string} ours
861
+ * @param {string} theirs
862
+ * @param {object | null} [options]
863
+ * @returns {string}
864
+ */
865
+ function mergeAst(base, ours, theirs, options) {
866
+ let deferred5_0;
867
+ let deferred5_1;
868
+ try {
869
+ const ptr0 = passStringToWasm0(base, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
870
+ const len0 = WASM_VECTOR_LEN;
871
+ const ptr1 = passStringToWasm0(ours, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
872
+ const len1 = WASM_VECTOR_LEN;
873
+ const ptr2 = passStringToWasm0(theirs, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
874
+ const len2 = WASM_VECTOR_LEN;
875
+ const ret = wasm.mergeAst(ptr0, len0, ptr1, len1, ptr2, len2, isLikeNone(options) ? 0 : addToExternrefTable0(options));
876
+ var ptr4 = ret[0];
877
+ var len4 = ret[1];
878
+ if (ret[3]) {
879
+ ptr4 = 0; len4 = 0;
880
+ throw takeFromExternrefTable0(ret[2]);
881
+ }
882
+ deferred5_0 = ptr4;
883
+ deferred5_1 = len4;
884
+ return getStringFromWasm0(ptr4, len4);
885
+ } finally {
886
+ wasm.__wbindgen_free(deferred5_0, deferred5_1, 1);
887
+ }
888
+ }
889
+ exports.mergeAst = mergeAst;
890
+
891
+ /**
892
+ * Convert BBCode and retain a conservative v2 fidelity report.
893
+ * @param {string} source
894
+ * @returns {MigrationResult}
895
+ */
896
+ function migrateBbcode(source) {
897
+ const ptr0 = passStringToWasm0(source, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
898
+ const len0 = WASM_VECTOR_LEN;
899
+ const ret = wasm.migrateBbcode(ptr0, len0);
900
+ if (ret[2]) {
901
+ throw takeFromExternrefTable0(ret[1]);
902
+ }
903
+ return takeFromExternrefTable0(ret[0]);
904
+ }
905
+ exports.migrateBbcode = migrateBbcode;
906
+
907
+ /**
908
+ * Convert Djot and retain a conservative v2 fidelity report.
909
+ * @param {string} source
910
+ * @returns {MigrationResult}
911
+ */
912
+ function migrateDjot(source) {
913
+ const ptr0 = passStringToWasm0(source, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
914
+ const len0 = WASM_VECTOR_LEN;
915
+ const ret = wasm.migrateDjot(ptr0, len0);
916
+ if (ret[2]) {
917
+ throw takeFromExternrefTable0(ret[1]);
918
+ }
919
+ return takeFromExternrefTable0(ret[0]);
920
+ }
921
+ exports.migrateDjot = migrateDjot;
922
+
923
+ /**
924
+ * Whether a document was last processed under an older spec version than
925
+ * `currentVersion`. An unstamped document counts as needing review.
926
+ * @param {string} source
927
+ * @param {string} current_version
928
+ * @returns {boolean}
929
+ */
930
+ function needsReview(source, current_version) {
931
+ const ptr0 = passStringToWasm0(source, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
932
+ const len0 = WASM_VECTOR_LEN;
933
+ const ptr1 = passStringToWasm0(current_version, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
934
+ const len1 = WASM_VECTOR_LEN;
935
+ const ret = wasm.needsReview(ptr0, len0, ptr1, len1);
936
+ return ret !== 0;
937
+ }
938
+ exports.needsReview = needsReview;
939
+
940
+ /**
941
+ * Parse Carve source and return its AST as a JSON string.
942
+ *
943
+ * The PART 12 exchange shape (https://markup-carve.github.io/carve/ast-json):
944
+ * the same tree every Carve engine publishes, so a consumer written against
945
+ * one implementation reads another's output. The root carries exactly `type`,
946
+ * `children` and `srcByteLength`; frontmatter and footnote definitions are
947
+ * block nodes inside `children`, not root fields.
948
+ *
949
+ * Returns a STRING rather than a JS object: the caller runs `JSON.parse`, which
950
+ * is what a browser does natively and faster than building the object graph
951
+ * across the wasm boundary one property at a time. It also keeps the bytes
952
+ * available for a caller that stores or forwards them.
953
+ *
954
+ * Position tracking is on for this entry point and nowhere else. PART 12 §4
955
+ * lets an engine gate tracking behind a parse option but requires the
956
+ * serialized form to carry it, and rendering would pay for spans nobody reads.
957
+ * @param {string} source
958
+ * @returns {string}
959
+ */
960
+ function parseJson(source) {
961
+ let deferred2_0;
962
+ let deferred2_1;
963
+ try {
964
+ const ptr0 = passStringToWasm0(source, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
965
+ const len0 = WASM_VECTOR_LEN;
966
+ const ret = wasm.parseJson(ptr0, len0);
967
+ deferred2_0 = ret[0];
968
+ deferred2_1 = ret[1];
969
+ return getStringFromWasm0(ret[0], ret[1]);
970
+ } finally {
971
+ wasm.__wbindgen_free(deferred2_0, deferred2_1, 1);
972
+ }
973
+ }
974
+ exports.parseJson = parseJson;
975
+
976
+ /**
977
+ * Serialize the tree with the same options object as
978
+ * [`to_html_with_options`], so a host can export the tree of an untrusted
979
+ * document under the `profile` it renders that document with.
980
+ *
981
+ * `positions` is not read: every serialized tree this binding produces carries
982
+ * them, as in [`parse_json`].
983
+ * @param {string} source
984
+ * @param {RenderOptions | null} options
985
+ * @returns {string}
986
+ */
987
+ function parseJsonWithOptions(source, options) {
988
+ let deferred3_0;
989
+ let deferred3_1;
990
+ try {
991
+ const ptr0 = passStringToWasm0(source, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
992
+ const len0 = WASM_VECTOR_LEN;
993
+ const ret = wasm.parseJsonWithOptions(ptr0, len0, isLikeNone(options) ? 0 : addToExternrefTable0(options));
994
+ var ptr2 = ret[0];
995
+ var len2 = ret[1];
996
+ if (ret[3]) {
997
+ ptr2 = 0; len2 = 0;
998
+ throw takeFromExternrefTable0(ret[2]);
999
+ }
1000
+ deferred3_0 = ptr2;
1001
+ deferred3_1 = len2;
1002
+ return getStringFromWasm0(ptr2, len2);
1003
+ } finally {
1004
+ wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);
1005
+ }
1006
+ }
1007
+ exports.parseJsonWithOptions = parseJsonWithOptions;
1008
+
1009
+ /**
1010
+ * Parse the locator portion of a citation into `{ label, value, suffixText }`.
1011
+ *
1012
+ * A field the source did not carry is `null`. Same shape as carve-js
1013
+ * `parseLocator`; pure, and never throws on bad input.
1014
+ * @param {string} loc
1015
+ * @returns {ParsedLocator}
1016
+ */
1017
+ function parseLocator(loc) {
1018
+ const ptr0 = passStringToWasm0(loc, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
1019
+ const len0 = WASM_VECTOR_LEN;
1020
+ const ret = wasm.parseLocator(ptr0, len0);
1021
+ if (ret[2]) {
1022
+ throw takeFromExternrefTable0(ret[1]);
1023
+ }
1024
+ return takeFromExternrefTable0(ret[0]);
1025
+ }
1026
+ exports.parseLocator = parseLocator;
1027
+
1028
+ /**
1029
+ * Parse a document and keep what a later [`reparse`] needs.
1030
+ *
1031
+ * Returns one JSON object: `{ source, document, sourceLayout, changedSource,
1032
+ * reusedPreviousTree }`. `document` is the PART 12 tree, `sourceLayout` the
1033
+ * byte-exact record [`parse_source_layout_json`] produces, and
1034
+ * `changedSource` the byte ranges this parse covered - the whole document, on
1035
+ * a first parse.
1036
+ *
1037
+ * The snapshot crosses as JSON rather than as a handle a host has to `free()`.
1038
+ * Every other entry point here is a pure function that owns nothing, and the
1039
+ * engine's own snapshot holds only the source, so there is no tree being kept
1040
+ * alive in wasm memory for a handle to point at.
1041
+ * @param {string} source
1042
+ * @returns {string}
1043
+ */
1044
+ function parseSnapshot(source) {
1045
+ let deferred2_0;
1046
+ let deferred2_1;
1047
+ try {
1048
+ const ptr0 = passStringToWasm0(source, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
1049
+ const len0 = WASM_VECTOR_LEN;
1050
+ const ret = wasm.parseSnapshot(ptr0, len0);
1051
+ deferred2_0 = ret[0];
1052
+ deferred2_1 = ret[1];
1053
+ return getStringFromWasm0(ret[0], ret[1]);
1054
+ } finally {
1055
+ wasm.__wbindgen_free(deferred2_0, deferred2_1, 1);
1056
+ }
1057
+ }
1058
+ exports.parseSnapshot = parseSnapshot;
1059
+
1060
+ /**
1061
+ * The PART 12 §13 source-layout sidecar for a document.
1062
+ *
1063
+ * Separate from `parseJson`, which carries semantic positions on the nodes.
1064
+ * This is the byte-exact record of the SOURCE: its line endings, whether it
1065
+ * had a BOM, and a path-addressed byte span per node - what a host needs to
1066
+ * write an edit back into the file it came from.
1067
+ * @param {string} source
1068
+ * @returns {string}
1069
+ */
1070
+ function parseSourceLayoutJson(source) {
1071
+ let deferred2_0;
1072
+ let deferred2_1;
1073
+ try {
1074
+ const ptr0 = passStringToWasm0(source, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
1075
+ const len0 = WASM_VECTOR_LEN;
1076
+ const ret = wasm.parseSourceLayoutJson(ptr0, len0);
1077
+ deferred2_0 = ret[0];
1078
+ deferred2_1 = ret[1];
1079
+ return getStringFromWasm0(ret[0], ret[1]);
1080
+ } finally {
1081
+ wasm.__wbindgen_free(deferred2_0, deferred2_1, 1);
1082
+ }
1083
+ }
1084
+ exports.parseSourceLayoutJson = parseSourceLayoutJson;
1085
+
1086
+ /**
1087
+ * Read a document's provenance marker: `{ version, generatedBy }`, or `null`.
1088
+ * @param {string} source
1089
+ * @returns {Stamp | null}
1090
+ */
1091
+ function readStamp(source) {
1092
+ const ptr0 = passStringToWasm0(source, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
1093
+ const len0 = WASM_VECTOR_LEN;
1094
+ const ret = wasm.readStamp(ptr0, len0);
1095
+ if (ret[2]) {
1096
+ throw takeFromExternrefTable0(ret[1]);
1097
+ }
1098
+ return takeFromExternrefTable0(ret[0]);
1099
+ }
1100
+ exports.readStamp = readStamp;
1101
+
1102
+ /**
1103
+ * Re-parse `source` with `changes` applied.
1104
+ *
1105
+ * ```js
1106
+ * const first = JSON.parse(parseSnapshot('# One\n'))
1107
+ * const next = JSON.parse(reparse(first.source, '[{"range":[2,5],"replacement":"Two"}]'))
1108
+ * ```
1109
+ *
1110
+ * `changes` is a JSON array of `{ range: [start, end], replacement }`.
1111
+ *
1112
+ * THE OFFSETS ARE UTF-8 BYTE OFFSETS, matching `createSourcePatch` ranges.
1113
+ * `parseJson` positions count Unicode codepoints instead. A browser editor counts UTF-16 code
1114
+ * units, so a host holding a `selectionStart` converts before calling - an
1115
+ * offset that lands inside a multi-byte character is refused rather than
1116
+ * guessed at.
1117
+ *
1118
+ * A malformed change THROWS: overlapping ranges, an end past the source, and a
1119
+ * range that splits a code point are all a broken caller contract, not a
1120
+ * result the caller asked for.
1121
+ *
1122
+ * `reusedPreviousTree` says whether the parse reused any of the previous one.
1123
+ * The engine can reuse unchanged plain paragraphs. Other syntax falls back
1124
+ * to a full parse. This function rebuilds the initial snapshot from source;
1125
+ * use a parser session to retain it across edits.
1126
+ * @param {string} source
1127
+ * @param {string} changes
1128
+ * @returns {string}
1129
+ */
1130
+ function reparse(source, changes) {
1131
+ let deferred4_0;
1132
+ let deferred4_1;
1133
+ try {
1134
+ const ptr0 = passStringToWasm0(source, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
1135
+ const len0 = WASM_VECTOR_LEN;
1136
+ const ptr1 = passStringToWasm0(changes, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
1137
+ const len1 = WASM_VECTOR_LEN;
1138
+ const ret = wasm.reparse(ptr0, len0, ptr1, len1);
1139
+ var ptr3 = ret[0];
1140
+ var len3 = ret[1];
1141
+ if (ret[3]) {
1142
+ ptr3 = 0; len3 = 0;
1143
+ throw takeFromExternrefTable0(ret[2]);
1144
+ }
1145
+ deferred4_0 = ptr3;
1146
+ deferred4_1 = len3;
1147
+ return getStringFromWasm0(ptr3, len3);
1148
+ } finally {
1149
+ wasm.__wbindgen_free(deferred4_0, deferred4_1, 1);
1150
+ }
1151
+ }
1152
+ exports.reparse = reparse;
1153
+
1154
+ /**
1155
+ * Sanitize an SVG document, the helper a host embedding SVG would otherwise
1156
+ * reimplement.
1157
+ *
1158
+ * `{ svg, ok }`. `ok` false means the input was not a single well-formed
1159
+ * `<svg>` root, and a caller must then show the SOURCE rather than the input:
1160
+ * `svg` carries nothing to display. Every option defaults to `false`, which is
1161
+ * the strict setting.
1162
+ * @param {string} source
1163
+ * @param {object | null} [options]
1164
+ * @returns {SanitizeResult}
1165
+ */
1166
+ function sanitizeSvg(source, options) {
1167
+ const ptr0 = passStringToWasm0(source, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
1168
+ const len0 = WASM_VECTOR_LEN;
1169
+ const ret = wasm.sanitizeSvg(ptr0, len0, isLikeNone(options) ? 0 : addToExternrefTable0(options));
1170
+ if (ret[2]) {
1171
+ throw takeFromExternrefTable0(ret[1]);
1172
+ }
1173
+ return takeFromExternrefTable0(ret[0]);
1174
+ }
1175
+ exports.sanitizeSvg = sanitizeSvg;
1176
+
1177
+ /**
1178
+ * Write a provenance marker onto already-formatted Carve.
1179
+ *
1180
+ * The other half of `readStamp` and `needsReview`, which could read a marker
1181
+ * this package had no way to write. `generatedBy` is the engine identity a
1182
+ * host wants recorded, e.g. `"my-app 1.2"`; `form` is `"line"` (default) or
1183
+ * `"block"`. Same signature as carve-js `stampCarve`.
1184
+ *
1185
+ * The input is expected to be formatted already: this appends the marker and
1186
+ * replaces one the document carries, it does not canonicalize. `toCarve` is
1187
+ * the formatter.
1188
+ * @param {string} formatted
1189
+ * @param {string} generated_by
1190
+ * @param {string | null} [form]
1191
+ * @returns {string}
1192
+ */
1193
+ function stampCarve(formatted, generated_by, form) {
1194
+ let deferred5_0;
1195
+ let deferred5_1;
1196
+ try {
1197
+ const ptr0 = passStringToWasm0(formatted, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
1198
+ const len0 = WASM_VECTOR_LEN;
1199
+ const ptr1 = passStringToWasm0(generated_by, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
1200
+ const len1 = WASM_VECTOR_LEN;
1201
+ var ptr2 = isLikeNone(form) ? 0 : passStringToWasm0(form, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
1202
+ var len2 = WASM_VECTOR_LEN;
1203
+ const ret = wasm.stampCarve(ptr0, len0, ptr1, len1, ptr2, len2);
1204
+ var ptr4 = ret[0];
1205
+ var len4 = ret[1];
1206
+ if (ret[3]) {
1207
+ ptr4 = 0; len4 = 0;
1208
+ throw takeFromExternrefTable0(ret[2]);
1209
+ }
1210
+ deferred5_0 = ptr4;
1211
+ deferred5_1 = len4;
1212
+ return getStringFromWasm0(ptr4, len4);
1213
+ } finally {
1214
+ wasm.__wbindgen_free(deferred5_0, deferred5_1, 1);
1215
+ }
1216
+ }
1217
+ exports.stampCarve = stampCarve;
1218
+
1219
+ /**
1220
+ * @param {string} source
1221
+ * @returns {string}
1222
+ */
1223
+ function toAnsi(source) {
1224
+ let deferred2_0;
1225
+ let deferred2_1;
1226
+ try {
1227
+ const ptr0 = passStringToWasm0(source, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
1228
+ const len0 = WASM_VECTOR_LEN;
1229
+ const ret = wasm.toAnsi(ptr0, len0);
1230
+ deferred2_0 = ret[0];
1231
+ deferred2_1 = ret[1];
1232
+ return getStringFromWasm0(ret[0], ret[1]);
1233
+ } finally {
1234
+ wasm.__wbindgen_free(deferred2_0, deferred2_1, 1);
1235
+ }
1236
+ }
1237
+ exports.toAnsi = toAnsi;
1238
+
1239
+ /**
1240
+ * Render to ANSI text with an options object. See
1241
+ * [`to_markdown_with_options`].
1242
+ * @param {string} source
1243
+ * @param {RenderOptions | null} options
1244
+ * @returns {string}
1245
+ */
1246
+ function toAnsiWithOptions(source, options) {
1247
+ let deferred3_0;
1248
+ let deferred3_1;
1249
+ try {
1250
+ const ptr0 = passStringToWasm0(source, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
1251
+ const len0 = WASM_VECTOR_LEN;
1252
+ const ret = wasm.toAnsiWithOptions(ptr0, len0, isLikeNone(options) ? 0 : addToExternrefTable0(options));
1253
+ var ptr2 = ret[0];
1254
+ var len2 = ret[1];
1255
+ if (ret[3]) {
1256
+ ptr2 = 0; len2 = 0;
1257
+ throw takeFromExternrefTable0(ret[2]);
1258
+ }
1259
+ deferred3_0 = ptr2;
1260
+ deferred3_1 = len2;
1261
+ return getStringFromWasm0(ptr2, len2);
1262
+ } finally {
1263
+ wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);
1264
+ }
1265
+ }
1266
+ exports.toAnsiWithOptions = toAnsiWithOptions;
1267
+
1268
+ /**
1269
+ * @param {string} source
1270
+ * @param {boolean | null} strict
1271
+ * @param {number | null} maximum
1272
+ * @returns {any}
1273
+ */
1274
+ function toAnsiWithReport(source, strict, maximum) {
1275
+ const ptr0 = passStringToWasm0(source, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
1276
+ const len0 = WASM_VECTOR_LEN;
1277
+ const ret = wasm.toAnsiWithReport(ptr0, len0, isLikeNone(strict) ? 0 : addToExternrefTable0(strict), isLikeNone(maximum) ? 0 : addToExternrefTable0(maximum));
1278
+ if (ret[2]) {
1279
+ throw takeFromExternrefTable0(ret[1]);
1280
+ }
1281
+ return takeFromExternrefTable0(ret[0]);
1282
+ }
1283
+ exports.toAnsiWithReport = toAnsiWithReport;
1284
+
1285
+ /**
1286
+ * @param {string} source
1287
+ * @returns {string}
1288
+ */
1289
+ function toCarve(source) {
1290
+ let deferred2_0;
1291
+ let deferred2_1;
1292
+ try {
1293
+ const ptr0 = passStringToWasm0(source, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
1294
+ const len0 = WASM_VECTOR_LEN;
1295
+ const ret = wasm.toCarve(ptr0, len0);
1296
+ deferred2_0 = ret[0];
1297
+ deferred2_1 = ret[1];
1298
+ return getStringFromWasm0(ret[0], ret[1]);
1299
+ } finally {
1300
+ wasm.__wbindgen_free(deferred2_0, deferred2_1, 1);
1301
+ }
1302
+ }
1303
+ exports.toCarve = toCarve;
1304
+
1305
+ /**
1306
+ * Preview canonical formatting as a source-preserving patch.
1307
+ * @param {string} source
1308
+ * @returns {SourcePatch}
1309
+ */
1310
+ function toCarvePatch(source) {
1311
+ const ptr0 = passStringToWasm0(source, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
1312
+ const len0 = WASM_VECTOR_LEN;
1313
+ const ret = wasm.toCarvePatch(ptr0, len0);
1314
+ if (ret[2]) {
1315
+ throw takeFromExternrefTable0(ret[1]);
1316
+ }
1317
+ return takeFromExternrefTable0(ret[0]);
1318
+ }
1319
+ exports.toCarvePatch = toCarvePatch;
1320
+
1321
+ /**
1322
+ * Write canonical Carve with an options object.
1323
+ *
1324
+ * `profile` is the only option this target reads; see
1325
+ * [`to_markdown_with_options`] for why.
1326
+ * @param {string} source
1327
+ * @param {RenderOptions | null} options
1328
+ * @returns {string}
1329
+ */
1330
+ function toCarveWithOptions(source, options) {
1331
+ let deferred3_0;
1332
+ let deferred3_1;
1333
+ try {
1334
+ const ptr0 = passStringToWasm0(source, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
1335
+ const len0 = WASM_VECTOR_LEN;
1336
+ const ret = wasm.toCarveWithOptions(ptr0, len0, isLikeNone(options) ? 0 : addToExternrefTable0(options));
1337
+ var ptr2 = ret[0];
1338
+ var len2 = ret[1];
1339
+ if (ret[3]) {
1340
+ ptr2 = 0; len2 = 0;
1341
+ throw takeFromExternrefTable0(ret[2]);
1342
+ }
1343
+ deferred3_0 = ptr2;
1344
+ deferred3_1 = len2;
1345
+ return getStringFromWasm0(ptr2, len2);
1346
+ } finally {
1347
+ wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);
1348
+ }
1349
+ }
1350
+ exports.toCarveWithOptions = toCarveWithOptions;
1351
+
1352
+ /**
1353
+ * @param {string} source
1354
+ * @param {boolean | null} strict
1355
+ * @param {number | null} maximum
1356
+ * @returns {any}
1357
+ */
1358
+ function toCarveWithReport(source, strict, maximum) {
1359
+ const ptr0 = passStringToWasm0(source, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
1360
+ const len0 = WASM_VECTOR_LEN;
1361
+ const ret = wasm.toCarveWithReport(ptr0, len0, isLikeNone(strict) ? 0 : addToExternrefTable0(strict), isLikeNone(maximum) ? 0 : addToExternrefTable0(maximum));
1362
+ if (ret[2]) {
1363
+ throw takeFromExternrefTable0(ret[1]);
1364
+ }
1365
+ return takeFromExternrefTable0(ret[0]);
1366
+ }
1367
+ exports.toCarveWithReport = toCarveWithReport;
1368
+
1369
+ /**
1370
+ * @param {string} source
1371
+ * @returns {string}
1372
+ */
1373
+ function toHtml(source) {
1374
+ let deferred2_0;
1375
+ let deferred2_1;
1376
+ try {
1377
+ const ptr0 = passStringToWasm0(source, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
1378
+ const len0 = WASM_VECTOR_LEN;
1379
+ const ret = wasm.toHtml(ptr0, len0);
1380
+ deferred2_0 = ret[0];
1381
+ deferred2_1 = ret[1];
1382
+ return getStringFromWasm0(ret[0], ret[1]);
1383
+ } finally {
1384
+ wasm.__wbindgen_free(deferred2_0, deferred2_1, 1);
1385
+ }
1386
+ }
1387
+ exports.toHtml = toHtml;
1388
+
1389
+ /**
1390
+ * Render with the preview extension set enabled (`PREVIEW_EXTENSIONS`), so the
1391
+ * WASM engine matches an extensions-on host such as the docs Playground rather
1392
+ * than the core-only `toHtml`.
1393
+ *
1394
+ * The set is curated, not "everything the engine has": `heading-numbers` and
1395
+ * `table-of-contents` rewrite a document that never asked for it, which is
1396
+ * wrong for a preview. Callers who want an exact set pass `extensions` to
1397
+ * `toHtmlWithOptions`, and `extensions()` reports what this build accepts.
1398
+ *
1399
+ * The optional second argument is the same **symbols map** as
1400
+ * [`to_html_with_symbols`], with the same trusted-raw contract: mapped values
1401
+ * are emitted UNESCAPED, so never feed it untrusted input.
1402
+ * @param {string} source
1403
+ * @param {object | null} [symbols]
1404
+ * @returns {string}
1405
+ */
1406
+ function toHtmlFull(source, symbols) {
1407
+ let deferred3_0;
1408
+ let deferred3_1;
1409
+ try {
1410
+ const ptr0 = passStringToWasm0(source, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
1411
+ const len0 = WASM_VECTOR_LEN;
1412
+ const ret = wasm.toHtmlFull(ptr0, len0, isLikeNone(symbols) ? 0 : addToExternrefTable0(symbols));
1413
+ var ptr2 = ret[0];
1414
+ var len2 = ret[1];
1415
+ if (ret[3]) {
1416
+ ptr2 = 0; len2 = 0;
1417
+ throw takeFromExternrefTable0(ret[2]);
1418
+ }
1419
+ deferred3_0 = ptr2;
1420
+ deferred3_1 = len2;
1421
+ return getStringFromWasm0(ptr2, len2);
1422
+ } finally {
1423
+ wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);
1424
+ }
1425
+ }
1426
+ exports.toHtmlFull = toHtmlFull;
1427
+
1428
+ /**
1429
+ * Render with an options object, the general form of the three shorthands
1430
+ * above.
1431
+ *
1432
+ * ```js
1433
+ * toHtmlWithOptions('# A\n\np\n', { sections: false })
1434
+ * // '<h1 id="A">A</h1>\n<p>p</p>'
1435
+ *
1436
+ * toHtmlWithOptions(src, { sections: false, symbols: { rocket: '🚀' }, full: true })
1437
+ *
1438
+ * toHtmlWithOptions(untrusted, { rawHtml: false })
1439
+ * ```
1440
+ *
1441
+ * Every field is optional:
1442
+ *
1443
+ * * `sections` (default `true`) - wrap each top-level heading, and the content
1444
+ * following it up to the next same-or-shallower heading, in a
1445
+ * `<section id="…">` (spec PART 9 §13). `false` renders headings flat with
1446
+ * the id back on the `<h*>` and the former section children as siblings.
1447
+ * For a host whose CSS or JS assumes rendered blocks are direct children of
1448
+ * the content container - the `.stack > * + *` spacing idiom,
1449
+ * `:first-child`, `nth-child()` counting, `element.children` walks - the
1450
+ * wrapper is the one output change a clean source migration still breaks.
1451
+ * * `symbols` - the same map as [`to_html_with_symbols`], with the same
1452
+ * TRUSTED-RAW contract: mapped values are emitted UNESCAPED, so never build
1453
+ * it from untrusted input.
1454
+ * * `extensions` - an array of extension names to enable, e.g.
1455
+ * `["glossary", "table-of-contents"]`. `extensions()` reports what this
1456
+ * build accepts. An unknown name throws: a silently ignored extension would
1457
+ * render as missing behavior that looks like a Carve bug. Takes precedence
1458
+ * over `full`.
1459
+ * * `full` (default `false`) - enable the preview extension set instead of
1460
+ * rendering core-only.
1461
+ * * `rawHtml` (default `true`) - render an explicit passthrough - the `=html`
1462
+ * raw block and the `` `…`{=html} `` inline raw span - as markup. `false`
1463
+ * emits it as escaped text instead, the same switch carve-js spells
1464
+ * `allowRawHtml`. A host that renders a document it did not author (a shared
1465
+ * link, a comment field, anything a reader supplies) wants `false`: without
1466
+ * it a passthrough is a way to run script on the host's origin.
1467
+ * * `profile` - one of `"full"`, `"article"`, `"comment"`, `"minimal"`. The
1468
+ * rest of the untrusted-input story: input length, denied constructs, link
1469
+ * policy. A document the profile REJECTS throws a `ProfileViolationError`
1470
+ * carrying `violations`, rather than resolving to an empty string.
1471
+ * * `profileBaseHost` - the host counted as internal when the profile's link
1472
+ * policy distinguishes internal from external links.
1473
+ * * `mode` - `"interactive"` (default) or `"static"`, the self-contained form
1474
+ * for print, PDF and archival: no client scripts.
1475
+ * * `sourceLine` (default `false`) - stamp top-level blocks with
1476
+ * `data-source-line`, for editor preview scroll-sync.
1477
+ * * `positions` (default `false`) - keep source offsets on the nodes.
1478
+ * * `labels` - override the engine-written strings (admonition names, the
1479
+ * endnotes heading, backlink text) for a page that is not in English. These
1480
+ * are TEXT and are escaped where they land, unlike `symbols`.
1481
+ * * `smartTypography` - `"glyph"` or `true` (default) resolves `...` to an
1482
+ * ellipsis, `"source"` or `false` keeps the author's run, and
1483
+ * `{ quotes: false }` keeps only the author's quotes.
1484
+ * * `lowercaseHeadingIds` (default `false`) and `asciiHeadingIds`
1485
+ * (`"off"` (default), `"fold"`, `"strict"`) - the slug policy, for a host
1486
+ * whose anchors have to match another generator's.
1487
+ * * `mentionUrl` and `tagUrl` - URL templates for `@mention` and `#tag`.
1488
+ * Without them both render as inert spans, which is why a host that wants
1489
+ * them linked has to say where to. The token name is percent-encoded into
1490
+ * `{name}` - `{user}` works too for a mention - and the result goes through
1491
+ * the same URL sanitizer as an authored link. These are the HOST's
1492
+ * configuration, not the document's: the template is trusted, the name
1493
+ * substituted into it is not.
1494
+ *
1495
+ * An unrecognized key is ignored: the object is configuration, and a caller
1496
+ * who mistypes one deserves the render to still work. A wrong TYPE on a key
1497
+ * that is recognized does throw, because that changes behavior silently.
1498
+ *
1499
+ * `renderers` is the one recognized key this entry point refuses, because a
1500
+ * render callback can fail and a bare string has nowhere to report that. Use
1501
+ * [`to_html_with_renderers`].
1502
+ *
1503
+ * Turning sections off changes nothing else. Ids, collision dedup, `</#id>`
1504
+ * crossrefs, implicit `[Heading][]` references and heading numbering all
1505
+ * resolve against the slug rather than the element carrying it, and the
1506
+ * endnotes `<section role="doc-endnotes">` is a separate construct that is
1507
+ * still emitted.
1508
+ * @param {string} source
1509
+ * @param {RenderOptions | null} options
1510
+ * @returns {string}
1511
+ */
1512
+ function toHtmlWithOptions(source, options) {
1513
+ let deferred3_0;
1514
+ let deferred3_1;
1515
+ try {
1516
+ const ptr0 = passStringToWasm0(source, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
1517
+ const len0 = WASM_VECTOR_LEN;
1518
+ const ret = wasm.toHtmlWithOptions(ptr0, len0, isLikeNone(options) ? 0 : addToExternrefTable0(options));
1519
+ var ptr2 = ret[0];
1520
+ var len2 = ret[1];
1521
+ if (ret[3]) {
1522
+ ptr2 = 0; len2 = 0;
1523
+ throw takeFromExternrefTable0(ret[2]);
1524
+ }
1525
+ deferred3_0 = ptr2;
1526
+ deferred3_1 = len2;
1527
+ return getStringFromWasm0(ptr2, len2);
1528
+ } finally {
1529
+ wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);
1530
+ }
1531
+ }
1532
+ exports.toHtmlWithOptions = toHtmlWithOptions;
1533
+
1534
+ /**
1535
+ * Render with a build-time math renderer, the option `mode: "static"` needs.
1536
+ *
1537
+ * Static output carries no client scripts, so a formula it contains has to be
1538
+ * rendered while the HTML is being written. `renderers.math` is the callback
1539
+ * the engine calls for each ``` ```math ``` fence, with the TeX source and a
1540
+ * display flag; KaTeX's `renderToString` has that exact shape.
1541
+ *
1542
+ * ```js
1543
+ * toHtmlWithRenderers(src, {
1544
+ * mode: 'static',
1545
+ * extensions: ['math-block'],
1546
+ * renderers: { math: (tex, display) => katex.renderToString(tex, { displayMode: display }) },
1547
+ * })
1548
+ * // { html: '…', rendererErrors: [] }
1549
+ * ```
1550
+ *
1551
+ * SECURITY: what the callback returns is inserted as **TRUSTED RAW HTML**, the
1552
+ * same trust class as a `symbols` value. The difference worth stating: a symbol
1553
+ * value is host configuration keyed by a NAME, while a renderer is host
1554
+ * configuration that is HANDED DOCUMENT CONTENT and typically echoes some of it
1555
+ * back. A host rendering documents it did not author is accepting whatever its
1556
+ * renderer makes of that input, so the escaping is the renderer's job.
1557
+ *
1558
+ * The engine consults the renderer only under `mode: "static"`; interactive
1559
+ * output keeps the `\[…\]` source for the client to typeset, and so does a
1560
+ * static render with no renderer supplied.
1561
+ *
1562
+ * The callback must be SYNCHRONOUS. wasm-bindgen cannot await across it, so an
1563
+ * `async` renderer returns a Promise the engine has no way to resolve; that is
1564
+ * recorded as a failure rather than stringified into the document.
1565
+ *
1566
+ * `renderers.diagrams` is the same callback one level down, keyed by the
1567
+ * fence's css class: `{ mermaid: (source) => html }`. A host that renders its
1568
+ * diagrams beforehand passes the lookup in that one line -
1569
+ * `(source) => prerendered.get(source)`. Mermaid itself cannot be passed,
1570
+ * because its `render` returns a Promise from v10 on.
1571
+ *
1572
+ * ```js
1573
+ * toHtmlWithRenderers(src, {
1574
+ * mode: 'static',
1575
+ * extensions: ['fenced-render'],
1576
+ * renderers: { diagrams: { mermaid: (source) => prerendered.get(source) } },
1577
+ * })
1578
+ * ```
1579
+ *
1580
+ * A diagram key the document never uses renders nothing and reports nothing.
1581
+ * So does a fence whose class the caller did not configure: the engine
1582
+ * degrades it to an escaped source block, and this binding never sees the
1583
+ * node.
1584
+ *
1585
+ * A callback that throws, or returns anything other than a string, does not
1586
+ * abort the render: the node it was called for emits nothing and the failure
1587
+ * is reported in `rendererErrors`, with `renderer` naming the css class.
1588
+ * This entry point exists because [`to_html_with_options`] returns a bare
1589
+ * string with nowhere to put that, and so it rejects `renderers` rather than
1590
+ * dropping the failures.
1591
+ * @param {string} source
1592
+ * @param {StaticRenderOptions | null} options
1593
+ * @returns {any}
1594
+ */
1595
+ function toHtmlWithRenderers(source, options) {
1596
+ const ptr0 = passStringToWasm0(source, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
1597
+ const len0 = WASM_VECTOR_LEN;
1598
+ const ret = wasm.toHtmlWithRenderers(ptr0, len0, isLikeNone(options) ? 0 : addToExternrefTable0(options));
1599
+ if (ret[2]) {
1600
+ throw takeFromExternrefTable0(ret[1]);
1601
+ }
1602
+ return takeFromExternrefTable0(ret[0]);
1603
+ }
1604
+ exports.toHtmlWithRenderers = toHtmlWithRenderers;
1605
+
1606
+ /**
1607
+ * @param {string} source
1608
+ * @param {boolean | null} strict
1609
+ * @param {number | null} maximum
1610
+ * @returns {any}
1611
+ */
1612
+ function toHtmlWithReport(source, strict, maximum) {
1613
+ const ptr0 = passStringToWasm0(source, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
1614
+ const len0 = WASM_VECTOR_LEN;
1615
+ const ret = wasm.toHtmlWithReport(ptr0, len0, isLikeNone(strict) ? 0 : addToExternrefTable0(strict), isLikeNone(maximum) ? 0 : addToExternrefTable0(maximum));
1616
+ if (ret[2]) {
1617
+ throw takeFromExternrefTable0(ret[1]);
1618
+ }
1619
+ return takeFromExternrefTable0(ret[0]);
1620
+ }
1621
+ exports.toHtmlWithReport = toHtmlWithReport;
1622
+
1623
+ /**
1624
+ * Render with the core profile and a **symbols map**: `{ rocket: "🚀" }` (a
1625
+ * plain object or a `Map`). A `:name:` symbol whose name is in the map renders
1626
+ * the mapped value; an unmapped `:name:` stays literal `:name:` text, and the
1627
+ * leading word-boundary guard still applies (`a:b:c`, `10:30:`,
1628
+ * `me@example.com` never become symbols).
1629
+ *
1630
+ * Names and values must both be strings; a non-string value throws a JS
1631
+ * `TypeError`.
1632
+ *
1633
+ * SECURITY: a mapped value is inserted as **TRUSTED RAW output in the target
1634
+ * format** - it is NOT escaped, the same trust class as the static `renderers`
1635
+ * map. So `{ b: "<b>x</b>" }` emits a real `<b>` element, not escaped text.
1636
+ * This is deliberate: processor configuration is trusted. NEVER build a
1637
+ * symbols map out of untrusted / user-supplied input.
1638
+ * @param {string} source
1639
+ * @param {object | null} [symbols]
1640
+ * @returns {string}
1641
+ */
1642
+ function toHtmlWithSymbols(source, symbols) {
1643
+ let deferred3_0;
1644
+ let deferred3_1;
1645
+ try {
1646
+ const ptr0 = passStringToWasm0(source, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
1647
+ const len0 = WASM_VECTOR_LEN;
1648
+ const ret = wasm.toHtmlWithSymbols(ptr0, len0, isLikeNone(symbols) ? 0 : addToExternrefTable0(symbols));
1649
+ var ptr2 = ret[0];
1650
+ var len2 = ret[1];
1651
+ if (ret[3]) {
1652
+ ptr2 = 0; len2 = 0;
1653
+ throw takeFromExternrefTable0(ret[2]);
1654
+ }
1655
+ deferred3_0 = ptr2;
1656
+ deferred3_1 = len2;
1657
+ return getStringFromWasm0(ptr2, len2);
1658
+ } finally {
1659
+ wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);
1660
+ }
1661
+ }
1662
+ exports.toHtmlWithSymbols = toHtmlWithSymbols;
1663
+
1664
+ /**
1665
+ * @param {string} source
1666
+ * @returns {string}
1667
+ */
1668
+ function toMarkdown(source) {
1669
+ let deferred2_0;
1670
+ let deferred2_1;
1671
+ try {
1672
+ const ptr0 = passStringToWasm0(source, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
1673
+ const len0 = WASM_VECTOR_LEN;
1674
+ const ret = wasm.toMarkdown(ptr0, len0);
1675
+ deferred2_0 = ret[0];
1676
+ deferred2_1 = ret[1];
1677
+ return getStringFromWasm0(ret[0], ret[1]);
1678
+ } finally {
1679
+ wasm.__wbindgen_free(deferred2_0, deferred2_1, 1);
1680
+ }
1681
+ }
1682
+ exports.toMarkdown = toMarkdown;
1683
+
1684
+ /**
1685
+ * Render to Markdown with the same options object as
1686
+ * [`to_html_with_options`].
1687
+ *
1688
+ * `profile` is why this exists. Without it a host can hold an untrusted
1689
+ * document to a profile on the way to HTML and not on the way to Markdown,
1690
+ * out of one package: the max-length bound, the denied constructs and the
1691
+ * link policy were all unreachable here. A document the profile rejects
1692
+ * throws a `ProfileViolationError` rather than resolving to an empty string.
1693
+ *
1694
+ * What these targets read is narrower than HTML's list: `profile` and
1695
+ * `smartTypography` change the output and extensions run, while `symbols`
1696
+ * (markup-carve/carve-rs#1668), `labels`, `sections`, `sourceLine`, `mode` and
1697
+ * the heading-id switches are HTML-side concerns the engine's other renderers
1698
+ * do not consult. `renderers` is refused for the reason
1699
+ * [`to_html_with_options`] refuses it.
1700
+ *
1701
+ * [`to_carve_with_options`] is narrower again and reads `profile` alone: the
1702
+ * engine's canonical writer is parse-only by contract, so extensions and
1703
+ * `smartTypography` are inert there. They are accepted rather than refused
1704
+ * because one options object is meant to serve every target.
1705
+ * @param {string} source
1706
+ * @param {RenderOptions | null} options
1707
+ * @returns {string}
1708
+ */
1709
+ function toMarkdownWithOptions(source, options) {
1710
+ let deferred3_0;
1711
+ let deferred3_1;
1712
+ try {
1713
+ const ptr0 = passStringToWasm0(source, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
1714
+ const len0 = WASM_VECTOR_LEN;
1715
+ const ret = wasm.toMarkdownWithOptions(ptr0, len0, isLikeNone(options) ? 0 : addToExternrefTable0(options));
1716
+ var ptr2 = ret[0];
1717
+ var len2 = ret[1];
1718
+ if (ret[3]) {
1719
+ ptr2 = 0; len2 = 0;
1720
+ throw takeFromExternrefTable0(ret[2]);
1721
+ }
1722
+ deferred3_0 = ptr2;
1723
+ deferred3_1 = len2;
1724
+ return getStringFromWasm0(ptr2, len2);
1725
+ } finally {
1726
+ wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);
1727
+ }
1728
+ }
1729
+ exports.toMarkdownWithOptions = toMarkdownWithOptions;
1730
+
1731
+ /**
1732
+ * @param {string} source
1733
+ * @param {boolean | null} strict
1734
+ * @param {number | null} maximum
1735
+ * @returns {any}
1736
+ */
1737
+ function toMarkdownWithReport(source, strict, maximum) {
1738
+ const ptr0 = passStringToWasm0(source, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
1739
+ const len0 = WASM_VECTOR_LEN;
1740
+ const ret = wasm.toMarkdownWithReport(ptr0, len0, isLikeNone(strict) ? 0 : addToExternrefTable0(strict), isLikeNone(maximum) ? 0 : addToExternrefTable0(maximum));
1741
+ if (ret[2]) {
1742
+ throw takeFromExternrefTable0(ret[1]);
1743
+ }
1744
+ return takeFromExternrefTable0(ret[0]);
1745
+ }
1746
+ exports.toMarkdownWithReport = toMarkdownWithReport;
1747
+
1748
+ /**
1749
+ * @param {string} source
1750
+ * @returns {string}
1751
+ */
1752
+ function toPlainText(source) {
1753
+ let deferred2_0;
1754
+ let deferred2_1;
1755
+ try {
1756
+ const ptr0 = passStringToWasm0(source, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
1757
+ const len0 = WASM_VECTOR_LEN;
1758
+ const ret = wasm.toPlainText(ptr0, len0);
1759
+ deferred2_0 = ret[0];
1760
+ deferred2_1 = ret[1];
1761
+ return getStringFromWasm0(ret[0], ret[1]);
1762
+ } finally {
1763
+ wasm.__wbindgen_free(deferred2_0, deferred2_1, 1);
1764
+ }
1765
+ }
1766
+ exports.toPlainText = toPlainText;
1767
+
1768
+ /**
1769
+ * Render to plain text with an options object. See
1770
+ * [`to_markdown_with_options`].
1771
+ * @param {string} source
1772
+ * @param {RenderOptions | null} options
1773
+ * @returns {string}
1774
+ */
1775
+ function toPlainTextWithOptions(source, options) {
1776
+ let deferred3_0;
1777
+ let deferred3_1;
1778
+ try {
1779
+ const ptr0 = passStringToWasm0(source, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
1780
+ const len0 = WASM_VECTOR_LEN;
1781
+ const ret = wasm.toPlainTextWithOptions(ptr0, len0, isLikeNone(options) ? 0 : addToExternrefTable0(options));
1782
+ var ptr2 = ret[0];
1783
+ var len2 = ret[1];
1784
+ if (ret[3]) {
1785
+ ptr2 = 0; len2 = 0;
1786
+ throw takeFromExternrefTable0(ret[2]);
1787
+ }
1788
+ deferred3_0 = ptr2;
1789
+ deferred3_1 = len2;
1790
+ return getStringFromWasm0(ptr2, len2);
1791
+ } finally {
1792
+ wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);
1793
+ }
1794
+ }
1795
+ exports.toPlainTextWithOptions = toPlainTextWithOptions;
1796
+
1797
+ /**
1798
+ * @param {string} source
1799
+ * @param {boolean | null} strict
1800
+ * @param {number | null} maximum
1801
+ * @returns {any}
1802
+ */
1803
+ function toPlainTextWithReport(source, strict, maximum) {
1804
+ const ptr0 = passStringToWasm0(source, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
1805
+ const len0 = WASM_VECTOR_LEN;
1806
+ const ret = wasm.toPlainTextWithReport(ptr0, len0, isLikeNone(strict) ? 0 : addToExternrefTable0(strict), isLikeNone(maximum) ? 0 : addToExternrefTable0(maximum));
1807
+ if (ret[2]) {
1808
+ throw takeFromExternrefTable0(ret[1]);
1809
+ }
1810
+ return takeFromExternrefTable0(ret[0]);
1811
+ }
1812
+ exports.toPlainTextWithReport = toPlainTextWithReport;
1813
+
1814
+ /**
1815
+ * Convert Carve source to the ProseMirror document shape.
1816
+ *
1817
+ * ProseMirror runs in a browser and nowhere else, so this is the one engine
1818
+ * capability whose whole audience sits behind a WASM binding. Without it a host
1819
+ * wiring a Carve editor either round-trips to a server or reimplements the node
1820
+ * mapping in JS, where it drifts from the engine's.
1821
+ *
1822
+ * Returns `{ json, dropped, degraded }`. `json` is the ProseMirror document as
1823
+ * a JSON string, the same choice `parseJson` makes and for the same reason.
1824
+ * The two maps say what the ProseMirror model could not hold: `dropped` where
1825
+ * the content is gone, `degraded` where the text survives without its node
1826
+ * type. A silent conversion is the degradation shape `lintCarve` exists to
1827
+ * avoid.
1828
+ * @param {string} source
1829
+ * @returns {ProseMirrorResult}
1830
+ */
1831
+ function toProseMirror(source) {
1832
+ const ptr0 = passStringToWasm0(source, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
1833
+ const len0 = WASM_VECTOR_LEN;
1834
+ const ret = wasm.toProseMirror(ptr0, len0);
1835
+ if (ret[2]) {
1836
+ throw takeFromExternrefTable0(ret[1]);
1837
+ }
1838
+ return takeFromExternrefTable0(ret[0]);
1839
+ }
1840
+ exports.toProseMirror = toProseMirror;
1841
+
1842
+ /**
1843
+ * @returns {string}
1844
+ */
1845
+ function version() {
1846
+ let deferred1_0;
1847
+ let deferred1_1;
1848
+ try {
1849
+ const ret = wasm.version();
1850
+ deferred1_0 = ret[0];
1851
+ deferred1_1 = ret[1];
1852
+ return getStringFromWasm0(ret[0], ret[1]);
1853
+ } finally {
1854
+ wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
1855
+ }
1856
+ }
1857
+ exports.version = version;
1858
+
1859
+ function __wbg_get_imports() {
1860
+ const import0 = {
1861
+ __proto__: null,
1862
+ __wbg_Error_2e59b1b37a9a34c3: function(arg0, arg1) {
1863
+ const ret = Error(getStringFromWasm0(arg0, arg1));
1864
+ return ret;
1865
+ },
1866
+ __wbg_Number_e6ffdb596c888833: function(arg0) {
1867
+ const ret = Number(arg0);
1868
+ return ret;
1869
+ },
1870
+ __wbg_String_8564e559799eccda: function(arg0, arg1) {
1871
+ const ret = String(arg1);
1872
+ const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
1873
+ const len1 = WASM_VECTOR_LEN;
1874
+ getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
1875
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
1876
+ },
1877
+ __wbg___wbindgen_bigint_get_as_i64_2c5082002e4826e2: function(arg0, arg1) {
1878
+ const v = arg1;
1879
+ const ret = typeof(v) === 'bigint' ? v : undefined;
1880
+ getDataViewMemory0().setBigInt64(arg0 + 8 * 1, isLikeNone(ret) ? BigInt(0) : ret, true);
1881
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, !isLikeNone(ret), true);
1882
+ },
1883
+ __wbg___wbindgen_boolean_get_a86c216575a75c30: function(arg0) {
1884
+ const v = arg0;
1885
+ const ret = typeof(v) === 'boolean' ? v : undefined;
1886
+ return isLikeNone(ret) ? 0xFFFFFF : ret ? 1 : 0;
1887
+ },
1888
+ __wbg___wbindgen_debug_string_dd5d2d07ce9e6c57: function(arg0, arg1) {
1889
+ const ret = debugString(arg1);
1890
+ const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
1891
+ const len1 = WASM_VECTOR_LEN;
1892
+ getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
1893
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
1894
+ },
1895
+ __wbg___wbindgen_in_4bd7a57e54337366: function(arg0, arg1) {
1896
+ const ret = arg0 in arg1;
1897
+ return ret;
1898
+ },
1899
+ __wbg___wbindgen_is_bigint_6c98f7e945dacdde: function(arg0) {
1900
+ const ret = typeof(arg0) === 'bigint';
1901
+ return ret;
1902
+ },
1903
+ __wbg___wbindgen_is_function_49868bde5eb1e745: function(arg0) {
1904
+ const ret = typeof(arg0) === 'function';
1905
+ return ret;
1906
+ },
1907
+ __wbg___wbindgen_is_null_344c8750a8525473: function(arg0) {
1908
+ const ret = arg0 === null;
1909
+ return ret;
1910
+ },
1911
+ __wbg___wbindgen_is_object_40c5a80572e8f9d3: function(arg0) {
1912
+ const val = arg0;
1913
+ const ret = typeof(val) === 'object' && val !== null;
1914
+ return ret;
1915
+ },
1916
+ __wbg___wbindgen_is_string_b29b5c5a8065ba1a: function(arg0) {
1917
+ const ret = typeof(arg0) === 'string';
1918
+ return ret;
1919
+ },
1920
+ __wbg___wbindgen_is_undefined_c0cca72b82b86f4d: function(arg0) {
1921
+ const ret = arg0 === undefined;
1922
+ return ret;
1923
+ },
1924
+ __wbg___wbindgen_jsval_eq_7d430e744a913d26: function(arg0, arg1) {
1925
+ const ret = arg0 === arg1;
1926
+ return ret;
1927
+ },
1928
+ __wbg___wbindgen_jsval_loose_eq_3a72ae764d46d944: function(arg0, arg1) {
1929
+ const ret = arg0 == arg1;
1930
+ return ret;
1931
+ },
1932
+ __wbg___wbindgen_number_get_7579aab02a8a620c: function(arg0, arg1) {
1933
+ const obj = arg1;
1934
+ const ret = typeof(obj) === 'number' ? obj : undefined;
1935
+ getDataViewMemory0().setFloat64(arg0 + 8 * 1, isLikeNone(ret) ? 0 : ret, true);
1936
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, !isLikeNone(ret), true);
1937
+ },
1938
+ __wbg___wbindgen_string_get_914df97fcfa788f2: function(arg0, arg1) {
1939
+ const obj = arg1;
1940
+ const ret = typeof(obj) === 'string' ? obj : undefined;
1941
+ var ptr1 = isLikeNone(ret) ? 0 : passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
1942
+ var len1 = WASM_VECTOR_LEN;
1943
+ getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
1944
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
1945
+ },
1946
+ __wbg___wbindgen_throw_81fc77679af83bc6: function(arg0, arg1) {
1947
+ throw new Error(getStringFromWasm0(arg0, arg1));
1948
+ },
1949
+ __wbg___wbindgen_typeof_ec2e006152efc95c: function(arg0) {
1950
+ const ret = typeof arg0;
1951
+ return ret;
1952
+ },
1953
+ __wbg_call_368fa9c372d473ba: function() { return handleError(function (arg0, arg1, arg2, arg3) {
1954
+ const ret = arg0.call(arg1, arg2, arg3);
1955
+ return ret;
1956
+ }, arguments); },
1957
+ __wbg_call_7f2987183bb62793: function() { return handleError(function (arg0, arg1) {
1958
+ const ret = arg0.call(arg1);
1959
+ return ret;
1960
+ }, arguments); },
1961
+ __wbg_call_d578befcc3145dee: function() { return handleError(function (arg0, arg1, arg2) {
1962
+ const ret = arg0.call(arg1, arg2);
1963
+ return ret;
1964
+ }, arguments); },
1965
+ __wbg_done_547d467e97529006: function(arg0) {
1966
+ const ret = arg0.done;
1967
+ return ret;
1968
+ },
1969
+ __wbg_entries_616b1a459b85be0b: function(arg0) {
1970
+ const ret = Object.entries(arg0);
1971
+ return ret;
1972
+ },
1973
+ __wbg_entries_7d89e479ff037f54: function(arg0) {
1974
+ const ret = arg0.entries();
1975
+ return ret;
1976
+ },
1977
+ __wbg_from_741da0f916ab74aa: function(arg0) {
1978
+ const ret = Array.from(arg0);
1979
+ return ret;
1980
+ },
1981
+ __wbg_get_4848e350b40afc16: function(arg0, arg1) {
1982
+ const ret = arg0[arg1 >>> 0];
1983
+ return ret;
1984
+ },
1985
+ __wbg_get_ed0642c4b9d31ddf: function() { return handleError(function (arg0, arg1) {
1986
+ const ret = Reflect.get(arg0, arg1);
1987
+ return ret;
1988
+ }, arguments); },
1989
+ __wbg_get_f96702c6245e4ef9: function() { return handleError(function (arg0, arg1) {
1990
+ const ret = Reflect.get(arg0, arg1);
1991
+ return ret;
1992
+ }, arguments); },
1993
+ __wbg_get_unchecked_7d7babe32e9e6a54: function(arg0, arg1) {
1994
+ const ret = arg0[arg1 >>> 0];
1995
+ return ret;
1996
+ },
1997
+ __wbg_get_with_ref_key_6412cf3094599694: function(arg0, arg1) {
1998
+ const ret = arg0[arg1];
1999
+ return ret;
2000
+ },
2001
+ __wbg_instanceof_ArrayBuffer_ff7c1337a5e3b33a: function(arg0) {
2002
+ let result;
2003
+ try {
2004
+ result = arg0 instanceof ArrayBuffer;
2005
+ } catch (_) {
2006
+ result = false;
2007
+ }
2008
+ const ret = result;
2009
+ return ret;
2010
+ },
2011
+ __wbg_instanceof_Error_e3390d6805733dad: function(arg0) {
2012
+ let result;
2013
+ try {
2014
+ result = arg0 instanceof Error;
2015
+ } catch (_) {
2016
+ result = false;
2017
+ }
2018
+ const ret = result;
2019
+ return ret;
2020
+ },
2021
+ __wbg_instanceof_Map_a10a2795ef4bfe97: function(arg0) {
2022
+ let result;
2023
+ try {
2024
+ result = arg0 instanceof Map;
2025
+ } catch (_) {
2026
+ result = false;
2027
+ }
2028
+ const ret = result;
2029
+ return ret;
2030
+ },
2031
+ __wbg_instanceof_Object_72ee0c53dd8f0726: function(arg0) {
2032
+ let result;
2033
+ try {
2034
+ result = arg0 instanceof Object;
2035
+ } catch (_) {
2036
+ result = false;
2037
+ }
2038
+ const ret = result;
2039
+ return ret;
2040
+ },
2041
+ __wbg_instanceof_Promise_95d523058012a13d: function(arg0) {
2042
+ let result;
2043
+ try {
2044
+ result = arg0 instanceof Promise;
2045
+ } catch (_) {
2046
+ result = false;
2047
+ }
2048
+ const ret = result;
2049
+ return ret;
2050
+ },
2051
+ __wbg_instanceof_Uint8Array_4b8da683deb25d72: function(arg0) {
2052
+ let result;
2053
+ try {
2054
+ result = arg0 instanceof Uint8Array;
2055
+ } catch (_) {
2056
+ result = false;
2057
+ }
2058
+ const ret = result;
2059
+ return ret;
2060
+ },
2061
+ __wbg_isArray_db61795ad004c139: function(arg0) {
2062
+ const ret = Array.isArray(arg0);
2063
+ return ret;
2064
+ },
2065
+ __wbg_isSafeInteger_ea83862ba994770c: function(arg0) {
2066
+ const ret = Number.isSafeInteger(arg0);
2067
+ return ret;
2068
+ },
2069
+ __wbg_iterator_de403ef31815a3e6: function() {
2070
+ const ret = Symbol.iterator;
2071
+ return ret;
2072
+ },
2073
+ __wbg_keys_e611eeb7873788db: function(arg0) {
2074
+ const ret = Object.keys(arg0);
2075
+ return ret;
2076
+ },
2077
+ __wbg_length_0c32cb8543c8e4c8: function(arg0) {
2078
+ const ret = arg0.length;
2079
+ return ret;
2080
+ },
2081
+ __wbg_length_6e821edde497a532: function(arg0) {
2082
+ const ret = arg0.length;
2083
+ return ret;
2084
+ },
2085
+ __wbg_message_7367f8c7d0fa1589: function(arg0) {
2086
+ const ret = arg0.message;
2087
+ return ret;
2088
+ },
2089
+ __wbg_new_47dfee3855dec446: function(arg0, arg1) {
2090
+ const ret = new TypeError(getStringFromWasm0(arg0, arg1));
2091
+ return ret;
2092
+ },
2093
+ __wbg_new_4f9fafbb3909af72: function() {
2094
+ const ret = new Object();
2095
+ return ret;
2096
+ },
2097
+ __wbg_new_a560378ea1240b14: function(arg0) {
2098
+ const ret = new Uint8Array(arg0);
2099
+ return ret;
2100
+ },
2101
+ __wbg_new_e3b04b4d53d1b593: function(arg0, arg1) {
2102
+ const ret = new Error(getStringFromWasm0(arg0, arg1));
2103
+ return ret;
2104
+ },
2105
+ __wbg_new_f3c9df4f38f3f798: function() {
2106
+ const ret = new Array();
2107
+ return ret;
2108
+ },
2109
+ __wbg_next_01132ed6134b8ef5: function(arg0) {
2110
+ const ret = arg0.next;
2111
+ return ret;
2112
+ },
2113
+ __wbg_next_b3713ec761a9dbfd: function() { return handleError(function (arg0) {
2114
+ const ret = arg0.next();
2115
+ return ret;
2116
+ }, arguments); },
2117
+ __wbg_parse_545d11396395fbbd: function() { return handleError(function (arg0, arg1) {
2118
+ const ret = JSON.parse(getStringFromWasm0(arg0, arg1));
2119
+ return ret;
2120
+ }, arguments); },
2121
+ __wbg_prototypesetcall_3e05eb9545565046: function(arg0, arg1, arg2) {
2122
+ Uint8Array.prototype.set.call(getArrayU8FromWasm0(arg0, arg1), arg2);
2123
+ },
2124
+ __wbg_push_6bdbc990be5ac37b: function(arg0, arg1) {
2125
+ const ret = arg0.push(arg1);
2126
+ return ret;
2127
+ },
2128
+ __wbg_set_6be42768c690e380: function(arg0, arg1, arg2) {
2129
+ arg0[arg1] = arg2;
2130
+ },
2131
+ __wbg_set_6c60b2e8ad0e9383: function(arg0, arg1, arg2) {
2132
+ arg0[arg1 >>> 0] = arg2;
2133
+ },
2134
+ __wbg_set_8ee2d34facb8466e: function() { return handleError(function (arg0, arg1, arg2) {
2135
+ const ret = Reflect.set(arg0, arg1, arg2);
2136
+ return ret;
2137
+ }, arguments); },
2138
+ __wbg_set_name_ab9c98596fd7310a: function(arg0, arg1, arg2) {
2139
+ arg0.name = getStringFromWasm0(arg1, arg2);
2140
+ },
2141
+ __wbg_stringify_a2c39d991e1bf91d: function() { return handleError(function (arg0) {
2142
+ const ret = JSON.stringify(arg0);
2143
+ return ret;
2144
+ }, arguments); },
2145
+ __wbg_value_7f6052747ccf940f: function(arg0) {
2146
+ const ret = arg0.value;
2147
+ return ret;
2148
+ },
2149
+ __wbindgen_cast_0000000000000001: function(arg0) {
2150
+ // Cast intrinsic for `F64 -> Externref`.
2151
+ const ret = arg0;
2152
+ return ret;
2153
+ },
2154
+ __wbindgen_cast_0000000000000002: function(arg0, arg1) {
2155
+ // Cast intrinsic for `Ref(String) -> Externref`.
2156
+ const ret = getStringFromWasm0(arg0, arg1);
2157
+ return ret;
2158
+ },
2159
+ __wbindgen_cast_0000000000000003: function(arg0) {
2160
+ // Cast intrinsic for `U64 -> Externref`.
2161
+ const ret = BigInt.asUintN(64, arg0);
2162
+ return ret;
2163
+ },
2164
+ __wbindgen_init_externref_table: function() {
2165
+ const table = wasm.__wbindgen_externrefs;
2166
+ const offset = table.grow(4);
2167
+ table.set(0, undefined);
2168
+ table.set(offset + 0, undefined);
2169
+ table.set(offset + 1, null);
2170
+ table.set(offset + 2, true);
2171
+ table.set(offset + 3, false);
2172
+ },
2173
+ };
2174
+ return {
2175
+ __proto__: null,
2176
+ "./carve_wasm_bg.js": import0,
2177
+ };
2178
+ }
2179
+
2180
+ const ParserSessionFinalization = (typeof FinalizationRegistry === 'undefined')
2181
+ ? { register: () => {}, unregister: () => {} }
2182
+ : new FinalizationRegistry(ptr => wasm.__wbg_parsersession_free(ptr >>> 0, 1));
2183
+
2184
+ function addToExternrefTable0(obj) {
2185
+ const idx = wasm.__externref_table_alloc();
2186
+ wasm.__wbindgen_externrefs.set(idx, obj);
2187
+ return idx;
2188
+ }
2189
+
2190
+ function debugString(val) {
2191
+ // primitive types
2192
+ const type = typeof val;
2193
+ if (type == 'number' || type == 'boolean' || val == null) {
2194
+ return `${val}`;
2195
+ }
2196
+ if (type == 'string') {
2197
+ return `"${val}"`;
2198
+ }
2199
+ if (type == 'symbol') {
2200
+ const description = val.description;
2201
+ if (description == null) {
2202
+ return 'Symbol';
2203
+ } else {
2204
+ return `Symbol(${description})`;
2205
+ }
2206
+ }
2207
+ if (type == 'function') {
2208
+ const name = val.name;
2209
+ if (typeof name == 'string' && name.length > 0) {
2210
+ return `Function(${name})`;
2211
+ } else {
2212
+ return 'Function';
2213
+ }
2214
+ }
2215
+ // objects
2216
+ if (Array.isArray(val)) {
2217
+ const length = val.length;
2218
+ let debug = '[';
2219
+ if (length > 0) {
2220
+ debug += debugString(val[0]);
2221
+ }
2222
+ for(let i = 1; i < length; i++) {
2223
+ debug += ', ' + debugString(val[i]);
2224
+ }
2225
+ debug += ']';
2226
+ return debug;
2227
+ }
2228
+ // Test for built-in
2229
+ const builtInMatches = /\[object ([^\]]+)\]/.exec(toString.call(val));
2230
+ let className;
2231
+ if (builtInMatches && builtInMatches.length > 1) {
2232
+ className = builtInMatches[1];
2233
+ } else {
2234
+ // Failed to match the standard '[object ClassName]'
2235
+ return toString.call(val);
2236
+ }
2237
+ if (className == 'Object') {
2238
+ // we're a user defined class or Object
2239
+ // JSON.stringify avoids problems with cycles, and is generally much
2240
+ // easier than looping through ownProperties of `val`.
2241
+ try {
2242
+ return 'Object(' + JSON.stringify(val) + ')';
2243
+ } catch (_) {
2244
+ return 'Object';
2245
+ }
2246
+ }
2247
+ // errors
2248
+ if (val instanceof Error) {
2249
+ return `${val.name}: ${val.message}\n${val.stack}`;
2250
+ }
2251
+ // TODO we could test for more things here, like `Set`s and `Map`s.
2252
+ return className;
2253
+ }
2254
+
2255
+ function getArrayJsValueFromWasm0(ptr, len) {
2256
+ ptr = ptr >>> 0;
2257
+ const mem = getDataViewMemory0();
2258
+ const result = [];
2259
+ for (let i = ptr; i < ptr + 4 * len; i += 4) {
2260
+ result.push(wasm.__wbindgen_externrefs.get(mem.getUint32(i, true)));
2261
+ }
2262
+ wasm.__externref_drop_slice(ptr, len);
2263
+ return result;
2264
+ }
2265
+
2266
+ function getArrayU8FromWasm0(ptr, len) {
2267
+ ptr = ptr >>> 0;
2268
+ return getUint8ArrayMemory0().subarray(ptr / 1, ptr / 1 + len);
2269
+ }
2270
+
2271
+ let cachedDataViewMemory0 = null;
2272
+ function getDataViewMemory0() {
2273
+ if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || (cachedDataViewMemory0.buffer.detached === undefined && cachedDataViewMemory0.buffer !== wasm.memory.buffer)) {
2274
+ cachedDataViewMemory0 = new DataView(wasm.memory.buffer);
2275
+ }
2276
+ return cachedDataViewMemory0;
2277
+ }
2278
+
2279
+ function getStringFromWasm0(ptr, len) {
2280
+ ptr = ptr >>> 0;
2281
+ return decodeText(ptr, len);
2282
+ }
2283
+
2284
+ let cachedUint8ArrayMemory0 = null;
2285
+ function getUint8ArrayMemory0() {
2286
+ if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
2287
+ cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
2288
+ }
2289
+ return cachedUint8ArrayMemory0;
2290
+ }
2291
+
2292
+ function handleError(f, args) {
2293
+ try {
2294
+ return f.apply(this, args);
2295
+ } catch (e) {
2296
+ const idx = addToExternrefTable0(e);
2297
+ wasm.__wbindgen_exn_store(idx);
2298
+ }
2299
+ }
2300
+
2301
+ function isLikeNone(x) {
2302
+ return x === undefined || x === null;
2303
+ }
2304
+
2305
+ function passStringToWasm0(arg, malloc, realloc) {
2306
+ if (realloc === undefined) {
2307
+ const buf = cachedTextEncoder.encode(arg);
2308
+ const ptr = malloc(buf.length, 1) >>> 0;
2309
+ getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
2310
+ WASM_VECTOR_LEN = buf.length;
2311
+ return ptr;
2312
+ }
2313
+
2314
+ let len = arg.length;
2315
+ let ptr = malloc(len, 1) >>> 0;
2316
+
2317
+ const mem = getUint8ArrayMemory0();
2318
+
2319
+ let offset = 0;
2320
+
2321
+ for (; offset < len; offset++) {
2322
+ const code = arg.charCodeAt(offset);
2323
+ if (code > 0x7F) break;
2324
+ mem[ptr + offset] = code;
2325
+ }
2326
+ if (offset !== len) {
2327
+ if (offset !== 0) {
2328
+ arg = arg.slice(offset);
2329
+ }
2330
+ ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
2331
+ const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
2332
+ const ret = cachedTextEncoder.encodeInto(arg, view);
2333
+
2334
+ offset += ret.written;
2335
+ ptr = realloc(ptr, len, offset, 1) >>> 0;
2336
+ }
2337
+
2338
+ WASM_VECTOR_LEN = offset;
2339
+ return ptr;
2340
+ }
2341
+
2342
+ function takeFromExternrefTable0(idx) {
2343
+ const value = wasm.__wbindgen_externrefs.get(idx);
2344
+ wasm.__externref_table_dealloc(idx);
2345
+ return value;
2346
+ }
2347
+
2348
+ let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
2349
+ cachedTextDecoder.decode();
2350
+ function decodeText(ptr, len) {
2351
+ return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
2352
+ }
2353
+
2354
+ const cachedTextEncoder = new TextEncoder();
2355
+
2356
+ if (!('encodeInto' in cachedTextEncoder)) {
2357
+ cachedTextEncoder.encodeInto = function (arg, view) {
2358
+ const buf = cachedTextEncoder.encode(arg);
2359
+ view.set(buf);
2360
+ return {
2361
+ read: arg.length,
2362
+ written: buf.length
2363
+ };
2364
+ };
2365
+ }
2366
+
2367
+ let WASM_VECTOR_LEN = 0;
2368
+
2369
+ const wasmPath = `${__dirname}/../carve_wasm_bg.wasm`;
2370
+ const wasmBytes = require('fs').readFileSync(wasmPath);
2371
+ const wasmModule = new WebAssembly.Module(wasmBytes);
2372
+ let wasm = new WebAssembly.Instance(wasmModule, __wbg_get_imports()).exports;
2373
+ wasm.__wbindgen_start();