@markup-carve/carve-wasm 0.1.4 → 0.1.6

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