brookmd 0.22.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (59) hide show
  1. package/CHANGELOG.md +1229 -0
  2. package/LICENSE +21 -0
  3. package/README.md +1265 -0
  4. package/dist/block-props.d.ts +18 -0
  5. package/dist/block-props.js +75 -0
  6. package/dist/client.d.ts +370 -0
  7. package/dist/client.js +754 -0
  8. package/dist/decorate.d.ts +24 -0
  9. package/dist/decorate.js +71 -0
  10. package/dist/dom.d.ts +130 -0
  11. package/dist/dom.js +627 -0
  12. package/dist/element.d.ts +20 -0
  13. package/dist/element.js +288 -0
  14. package/dist/hi.d.ts +12 -0
  15. package/dist/hi.js +215 -0
  16. package/dist/html-to-react.d.ts +61 -0
  17. package/dist/html-to-react.js +338 -0
  18. package/dist/index.d.ts +22 -0
  19. package/dist/index.js +18 -0
  20. package/dist/morph.d.ts +28 -0
  21. package/dist/morph.js +166 -0
  22. package/dist/react.d.ts +236 -0
  23. package/dist/react.js +539 -0
  24. package/dist/renderers/CodeBlock.d.ts +7 -0
  25. package/dist/renderers/CodeBlock.js +75 -0
  26. package/dist/renderers/Math.d.ts +14 -0
  27. package/dist/renderers/Math.js +15 -0
  28. package/dist/renderers/Mermaid.d.ts +13 -0
  29. package/dist/renderers/Mermaid.js +15 -0
  30. package/dist/server-react.d.ts +32 -0
  31. package/dist/server-react.js +48 -0
  32. package/dist/server.d.ts +31 -0
  33. package/dist/server.js +82 -0
  34. package/dist/solid.d.ts +104 -0
  35. package/dist/solid.js +54 -0
  36. package/dist/styles.css +188 -0
  37. package/dist/svelte.d.ts +80 -0
  38. package/dist/svelte.js +59 -0
  39. package/dist/types-core.d.ts +436 -0
  40. package/dist/types-core.js +0 -0
  41. package/dist/types-react.d.ts +13 -0
  42. package/dist/types-react.js +0 -0
  43. package/dist/types.d.ts +2 -0
  44. package/dist/types.js +2 -0
  45. package/dist/url-safety.d.ts +12 -0
  46. package/dist/url-safety.js +45 -0
  47. package/dist/vue.d.ts +94 -0
  48. package/dist/vue.js +79 -0
  49. package/dist/wasm/LICENSE +21 -0
  50. package/dist/wasm/README.md +71 -0
  51. package/dist/wasm/brook_md_core.d.ts +166 -0
  52. package/dist/wasm/brook_md_core.js +512 -0
  53. package/dist/wasm/brook_md_core_bg.wasm +0 -0
  54. package/dist/wasm/brook_md_core_bg.wasm.d.ts +26 -0
  55. package/dist/worker-core.d.ts +65 -0
  56. package/dist/worker-core.js +155 -0
  57. package/dist/worker.d.ts +1 -0
  58. package/dist/worker.js +49 -0
  59. package/package.json +87 -0
@@ -0,0 +1,512 @@
1
+ /* @ts-self-types="./brook_md_core.d.ts" */
2
+
3
+ export class BrookParser {
4
+ __destroy_into_raw() {
5
+ const ptr = this.__wbg_ptr;
6
+ this.__wbg_ptr = 0;
7
+ BrookParserFinalization.unregister(this);
8
+ return ptr;
9
+ }
10
+ free() {
11
+ const ptr = this.__destroy_into_raw();
12
+ wasm.__wbg_brookparser_free(ptr, 0);
13
+ }
14
+ /**
15
+ * All blocks currently parsed (committed + active), in document order — the
16
+ * whole rendered document as a **JSON string** of a `Block[]` (parse with
17
+ * `JSON.parse`). The one-shot / server-side render primitive: feed the full
18
+ * markdown via `append`, call `finalize`, then read `allBlocks()` (no worker,
19
+ * no patch accumulation).
20
+ * @returns {string}
21
+ */
22
+ allBlocks() {
23
+ let deferred2_0;
24
+ let deferred2_1;
25
+ try {
26
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
27
+ wasm.brookparser_allBlocks(retptr, this.__wbg_ptr);
28
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
29
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
30
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
31
+ var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
32
+ var ptr1 = r0;
33
+ var len1 = r1;
34
+ if (r3) {
35
+ ptr1 = 0; len1 = 0;
36
+ throw takeObject(r2);
37
+ }
38
+ deferred2_0 = ptr1;
39
+ deferred2_1 = len1;
40
+ return getStringFromWasm0(ptr1, len1);
41
+ } finally {
42
+ wasm.__wbindgen_add_to_stack_pointer(16);
43
+ wasm.__wbindgen_export3(deferred2_0, deferred2_1, 1);
44
+ }
45
+ }
46
+ /**
47
+ * Returns the patch as a **JSON string** (parsed with `JSON.parse` on the
48
+ * main thread), not a live JS object. This is deliberate: serializing once to
49
+ * a string in Rust avoids serde-wasm-bindgen's per-node boundary calls, and a
50
+ * string is far cheaper than an object graph to `structuredClone` across the
51
+ * worker→main `postMessage` (the worker forwards the string verbatim).
52
+ * @param {string} chunk
53
+ * @returns {string}
54
+ */
55
+ append(chunk) {
56
+ let deferred3_0;
57
+ let deferred3_1;
58
+ try {
59
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
60
+ const ptr0 = passStringToWasm0(chunk, wasm.__wbindgen_export, wasm.__wbindgen_export2);
61
+ const len0 = WASM_VECTOR_LEN;
62
+ wasm.brookparser_append(retptr, this.__wbg_ptr, ptr0, len0);
63
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
64
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
65
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
66
+ var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
67
+ var ptr2 = r0;
68
+ var len2 = r1;
69
+ if (r3) {
70
+ ptr2 = 0; len2 = 0;
71
+ throw takeObject(r2);
72
+ }
73
+ deferred3_0 = ptr2;
74
+ deferred3_1 = len2;
75
+ return getStringFromWasm0(ptr2, len2);
76
+ } finally {
77
+ wasm.__wbindgen_add_to_stack_pointer(16);
78
+ wasm.__wbindgen_export3(deferred3_0, deferred3_1, 1);
79
+ }
80
+ }
81
+ /**
82
+ * @returns {number}
83
+ */
84
+ bufferLen() {
85
+ const ret = wasm.brookparser_bufferLen(this.__wbg_ptr);
86
+ return ret >>> 0;
87
+ }
88
+ /**
89
+ * JSON-string patch — see [`BrookParser::append`].
90
+ * @returns {string}
91
+ */
92
+ finalize() {
93
+ let deferred2_0;
94
+ let deferred2_1;
95
+ try {
96
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
97
+ wasm.brookparser_finalize(retptr, this.__wbg_ptr);
98
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
99
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
100
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
101
+ var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
102
+ var ptr1 = r0;
103
+ var len1 = r1;
104
+ if (r3) {
105
+ ptr1 = 0; len1 = 0;
106
+ throw takeObject(r2);
107
+ }
108
+ deferred2_0 = ptr1;
109
+ deferred2_1 = len1;
110
+ return getStringFromWasm0(ptr1, len1);
111
+ } finally {
112
+ wasm.__wbindgen_add_to_stack_pointer(16);
113
+ wasm.__wbindgen_export3(deferred2_0, deferred2_1, 1);
114
+ }
115
+ }
116
+ constructor() {
117
+ const ret = wasm.brookparser_new();
118
+ this.__wbg_ptr = ret;
119
+ BrookParserFinalization.register(this, this.__wbg_ptr, this);
120
+ return this;
121
+ }
122
+ /**
123
+ * Total bytes the parser is retaining: source buffer + all rendered
124
+ * HTML for committed and active blocks. Use to compare per-parser
125
+ * memory cost against alternatives.
126
+ * @returns {number}
127
+ */
128
+ retainedBytes() {
129
+ const ret = wasm.brookparser_retainedBytes(this.__wbg_ptr);
130
+ return ret >>> 0;
131
+ }
132
+ /**
133
+ * Opt-in accessibility markup that deviates from strict GFM byte-output:
134
+ * `<label>`-wrap a task-list checkbox with its text, and add `scope="col"`
135
+ * to table header cells. Off by default (conformance output unchanged).
136
+ * @param {boolean} on
137
+ */
138
+ setA11y(on) {
139
+ wasm.brookparser_setA11y(this.__wbg_ptr, on);
140
+ }
141
+ /**
142
+ * Opt-in structured `kind.data` channel for Table blocks: a Table then
143
+ * carries `{ headers, rows, aligns }` (per-cell `{ text, html }`) so a
144
+ * consumer can build a sort/filter/transpose/chart/CSV toolbar from DATA
145
+ * without re-parsing the HTML. Off by default — when off, Table serializes
146
+ * as `{"type":"Table"}` (no `data` key) and output is byte-identical.
147
+ * @param {boolean} on
148
+ */
149
+ setBlockData(on) {
150
+ wasm.brookparser_setBlockData(this.__wbg_ptr, on);
151
+ }
152
+ /**
153
+ * Set the opt-in component-tag allowlist (e.g. `["Thinking", "Callout"]`).
154
+ * A `<Tag>…</Tag>` whose name is listed renders as a component whose inner
155
+ * content is markdown — safely, without unsafe HTML (the tag is allowlisted
156
+ * and its attributes are sanitized). Empty by default (feature off).
157
+ * @param {string[]} tags
158
+ */
159
+ setComponentTags(tags) {
160
+ const ptr0 = passArrayJsValueToWasm0(tags, wasm.__wbindgen_export);
161
+ const len0 = WASM_VECTOR_LEN;
162
+ wasm.brookparser_setComponentTags(this.__wbg_ptr, ptr0, len0);
163
+ }
164
+ /**
165
+ * Emit `dir="auto"` on block-level text elements so the browser detects
166
+ * each block's direction (LTR/RTL) independently — correct rendering for
167
+ * documents that mix English with Arabic/Hebrew. Off by default; code
168
+ * blocks never get it (code is always LTR).
169
+ * @param {boolean} on
170
+ */
171
+ setDirAuto(on) {
172
+ wasm.brookparser_setDirAuto(this.__wbg_ptr, on);
173
+ }
174
+ /**
175
+ * Enable GitHub alerts (`> [!NOTE]` blockquotes render as styled callouts
176
+ * with GitHub-compatible class names). Off by default.
177
+ * @param {boolean} on
178
+ */
179
+ setGfmAlerts(on) {
180
+ wasm.brookparser_setGfmAlerts(this.__wbg_ptr, on);
181
+ }
182
+ /**
183
+ * Enable GFM extended autolinks (bare www./http(s)://ftp:// URLs and email
184
+ * addresses become links). Useful for LLM output, which is full of them.
185
+ * @param {boolean} on
186
+ */
187
+ setGfmAutolinks(on) {
188
+ wasm.brookparser_setGfmAutolinks(this.__wbg_ptr, on);
189
+ }
190
+ /**
191
+ * Enable GFM footnotes (`[^1]` references + `[^1]:` definitions → a
192
+ * footnote section emitted at finalize). Off by default.
193
+ * @param {boolean} on
194
+ */
195
+ setGfmFootnotes(on) {
196
+ wasm.brookparser_setGfmFootnotes(this.__wbg_ptr, on);
197
+ }
198
+ /**
199
+ * Enable math: `$…$` / `\(…\)` inline and `$$…$$` / `\[…\]` display math.
200
+ * Off by default (so `$` in prose / currency stays literal). The emitted
201
+ * HTML carries the LaTeX in `<span class="math math-inline">` /
202
+ * `<div class="math math-display">` for a KaTeX pass on the JS side.
203
+ * @param {boolean} on
204
+ */
205
+ setGfmMath(on) {
206
+ wasm.brookparser_setGfmMath(this.__wbg_ptr, on);
207
+ }
208
+ /**
209
+ * Enable the GFM "Disallowed Raw HTML" extension (tagfilter): with raw
210
+ * HTML passing through (`setUnsafeHtml(true)`), the nine disallowed tags
211
+ * (`<title>`, `<script>`, `<iframe>`, …) get their leading `<` escaped so
212
+ * they display as text instead of taking effect. Off by default; no
213
+ * effect while raw HTML is escaped or sanitized (already inert).
214
+ * @param {boolean} on
215
+ */
216
+ setGfmTagfilter(on) {
217
+ wasm.brookparser_setGfmTagfilter(this.__wbg_ptr, on);
218
+ }
219
+ /**
220
+ * Engage the safe raw-HTML sanitizer. When `on`, inline raw HTML renders
221
+ * sanitized without full unsafe HTML: `allow` empty = allow all tags except
222
+ * a built-in dangerous set (`script`, `style`, `iframe`, …); `allow`
223
+ * non-empty = only those render (others escaped); `drop` tags are removed
224
+ * entirely; HTML comments are dropped; every rendered tag's attributes are
225
+ * sanitized. Off by default (raw-HTML handling unchanged).
226
+ * @param {boolean} on
227
+ * @param {string[]} allow
228
+ * @param {string[]} drop
229
+ */
230
+ setHtmlSanitize(on, allow, drop) {
231
+ const ptr0 = passArrayJsValueToWasm0(allow, wasm.__wbindgen_export);
232
+ const len0 = WASM_VECTOR_LEN;
233
+ const ptr1 = passArrayJsValueToWasm0(drop, wasm.__wbindgen_export);
234
+ const len1 = WASM_VECTOR_LEN;
235
+ wasm.brookparser_setHtmlSanitize(this.__wbg_ptr, on, ptr0, len0, ptr1, len1);
236
+ }
237
+ /**
238
+ * Set the opt-in INLINE component-tag allowlist (e.g. `["tik", "cite"]`).
239
+ * An allowlisted inline `<tik>…</tik>` (or self-closing `<tik/>`) renders as
240
+ * a custom element (markdown inner, sanitized attributes) so a JSX/DOM layer
241
+ * can dispatch it via `components[tag]` — in paragraphs, headings, table
242
+ * cells, and list items. Empty by default (inline output unchanged).
243
+ * @param {string[]} tags
244
+ */
245
+ setInlineComponentTags(tags) {
246
+ const ptr0 = passArrayJsValueToWasm0(tags, wasm.__wbindgen_export);
247
+ const len0 = WASM_VECTOR_LEN;
248
+ wasm.brookparser_setInlineComponentTags(this.__wbg_ptr, ptr0, len0);
249
+ }
250
+ /**
251
+ * Enable or disable raw-HTML pass-through. Default off. Do not enable
252
+ * when rendering untrusted input — bypasses XSS protection.
253
+ * @param {boolean} on
254
+ */
255
+ setUnsafeHtml(on) {
256
+ wasm.brookparser_setUnsafeHtml(this.__wbg_ptr, on);
257
+ }
258
+ }
259
+ if (Symbol.dispose) BrookParser.prototype[Symbol.dispose] = BrookParser.prototype.free;
260
+ function __wbg_get_imports() {
261
+ const import0 = {
262
+ __proto__: null,
263
+ __wbg___wbindgen_string_get_72bdf95d3ae505b1: function(arg0, arg1) {
264
+ const obj = getObject(arg1);
265
+ const ret = typeof(obj) === 'string' ? obj : undefined;
266
+ var ptr1 = isLikeNone(ret) ? 0 : passStringToWasm0(ret, wasm.__wbindgen_export, wasm.__wbindgen_export2);
267
+ var len1 = WASM_VECTOR_LEN;
268
+ getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
269
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
270
+ },
271
+ __wbg___wbindgen_throw_1506f2235d1bdba0: function(arg0, arg1) {
272
+ throw new Error(getStringFromWasm0(arg0, arg1));
273
+ },
274
+ __wbindgen_cast_0000000000000001: function(arg0, arg1) {
275
+ // Cast intrinsic for `Ref(String) -> Externref`.
276
+ const ret = getStringFromWasm0(arg0, arg1);
277
+ return addHeapObject(ret);
278
+ },
279
+ __wbindgen_object_drop_ref: function(arg0) {
280
+ takeObject(arg0);
281
+ },
282
+ };
283
+ return {
284
+ __proto__: null,
285
+ "./brook_md_core_bg.js": import0,
286
+ };
287
+ }
288
+
289
+ const BrookParserFinalization = (typeof FinalizationRegistry === 'undefined')
290
+ ? { register: () => {}, unregister: () => {} }
291
+ : new FinalizationRegistry(ptr => wasm.__wbg_brookparser_free(ptr, 1));
292
+
293
+ function addHeapObject(obj) {
294
+ if (heap_next === heap.length) heap.push(heap.length + 1);
295
+ const idx = heap_next;
296
+ heap_next = heap[idx];
297
+
298
+ heap[idx] = obj;
299
+ return idx;
300
+ }
301
+
302
+ function dropObject(idx) {
303
+ if (idx < 1028) return;
304
+ heap[idx] = heap_next;
305
+ heap_next = idx;
306
+ }
307
+
308
+ let cachedDataViewMemory0 = null;
309
+ function getDataViewMemory0() {
310
+ if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || (cachedDataViewMemory0.buffer.detached === undefined && cachedDataViewMemory0.buffer !== wasm.memory.buffer)) {
311
+ cachedDataViewMemory0 = new DataView(wasm.memory.buffer);
312
+ }
313
+ return cachedDataViewMemory0;
314
+ }
315
+
316
+ function getStringFromWasm0(ptr, len) {
317
+ return decodeText(ptr >>> 0, len);
318
+ }
319
+
320
+ let cachedUint8ArrayMemory0 = null;
321
+ function getUint8ArrayMemory0() {
322
+ if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
323
+ cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
324
+ }
325
+ return cachedUint8ArrayMemory0;
326
+ }
327
+
328
+ function getObject(idx) { return heap[idx]; }
329
+
330
+ let heap = new Array(1024).fill(undefined);
331
+ heap.push(undefined, null, true, false);
332
+
333
+ let heap_next = heap.length;
334
+
335
+ function isLikeNone(x) {
336
+ return x === undefined || x === null;
337
+ }
338
+
339
+ function passArrayJsValueToWasm0(array, malloc) {
340
+ const ptr = malloc(array.length * 4, 4) >>> 0;
341
+ const mem = getDataViewMemory0();
342
+ for (let i = 0; i < array.length; i++) {
343
+ mem.setUint32(ptr + 4 * i, addHeapObject(array[i]), true);
344
+ }
345
+ WASM_VECTOR_LEN = array.length;
346
+ return ptr;
347
+ }
348
+
349
+ function passStringToWasm0(arg, malloc, realloc) {
350
+ if (realloc === undefined) {
351
+ const buf = cachedTextEncoder.encode(arg);
352
+ const ptr = malloc(buf.length, 1) >>> 0;
353
+ getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
354
+ WASM_VECTOR_LEN = buf.length;
355
+ return ptr;
356
+ }
357
+
358
+ let len = arg.length;
359
+ let ptr = malloc(len, 1) >>> 0;
360
+
361
+ const mem = getUint8ArrayMemory0();
362
+
363
+ let offset = 0;
364
+
365
+ for (; offset < len; offset++) {
366
+ const code = arg.charCodeAt(offset);
367
+ if (code > 0x7F) break;
368
+ mem[ptr + offset] = code;
369
+ }
370
+ if (offset !== len) {
371
+ if (offset !== 0) {
372
+ arg = arg.slice(offset);
373
+ }
374
+ ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
375
+ const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
376
+ const ret = cachedTextEncoder.encodeInto(arg, view);
377
+
378
+ offset += ret.written;
379
+ ptr = realloc(ptr, len, offset, 1) >>> 0;
380
+ }
381
+
382
+ WASM_VECTOR_LEN = offset;
383
+ return ptr;
384
+ }
385
+
386
+ function takeObject(idx) {
387
+ const ret = getObject(idx);
388
+ dropObject(idx);
389
+ return ret;
390
+ }
391
+
392
+ let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
393
+ cachedTextDecoder.decode();
394
+ const MAX_SAFARI_DECODE_BYTES = 2146435072;
395
+ let numBytesDecoded = 0;
396
+ function decodeText(ptr, len) {
397
+ numBytesDecoded += len;
398
+ if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {
399
+ cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
400
+ cachedTextDecoder.decode();
401
+ numBytesDecoded = len;
402
+ }
403
+ return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
404
+ }
405
+
406
+ const cachedTextEncoder = new TextEncoder();
407
+
408
+ if (!('encodeInto' in cachedTextEncoder)) {
409
+ cachedTextEncoder.encodeInto = function (arg, view) {
410
+ const buf = cachedTextEncoder.encode(arg);
411
+ view.set(buf);
412
+ return {
413
+ read: arg.length,
414
+ written: buf.length
415
+ };
416
+ };
417
+ }
418
+
419
+ let WASM_VECTOR_LEN = 0;
420
+
421
+ let wasmModule, wasmInstance, wasm;
422
+ function __wbg_finalize_init(instance, module) {
423
+ wasmInstance = instance;
424
+ wasm = instance.exports;
425
+ wasmModule = module;
426
+ cachedDataViewMemory0 = null;
427
+ cachedUint8ArrayMemory0 = null;
428
+ return wasm;
429
+ }
430
+
431
+ async function __wbg_load(module, imports) {
432
+ if (typeof Response === 'function' && module instanceof Response) {
433
+ if (typeof WebAssembly.instantiateStreaming === 'function') {
434
+ try {
435
+ return await WebAssembly.instantiateStreaming(module, imports);
436
+ } catch (e) {
437
+ const validResponse = module.ok && expectedResponseType(module.type);
438
+
439
+ if (validResponse && module.headers.get('Content-Type') !== 'application/wasm') {
440
+ 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);
441
+
442
+ } else { throw e; }
443
+ }
444
+ }
445
+
446
+ const bytes = await module.arrayBuffer();
447
+ return await WebAssembly.instantiate(bytes, imports);
448
+ } else {
449
+ const instance = await WebAssembly.instantiate(module, imports);
450
+
451
+ if (instance instanceof WebAssembly.Instance) {
452
+ return { instance, module };
453
+ } else {
454
+ return instance;
455
+ }
456
+ }
457
+
458
+ function expectedResponseType(type) {
459
+ switch (type) {
460
+ case 'basic': case 'cors': case 'default': return true;
461
+ }
462
+ return false;
463
+ }
464
+ }
465
+
466
+ function initSync(module) {
467
+ if (wasm !== undefined) return wasm;
468
+
469
+
470
+ if (module !== undefined) {
471
+ if (Object.getPrototypeOf(module) === Object.prototype) {
472
+ ({module} = module)
473
+ } else {
474
+ console.warn('using deprecated parameters for `initSync()`; pass a single object instead')
475
+ }
476
+ }
477
+
478
+ const imports = __wbg_get_imports();
479
+ if (!(module instanceof WebAssembly.Module)) {
480
+ module = new WebAssembly.Module(module);
481
+ }
482
+ const instance = new WebAssembly.Instance(module, imports);
483
+ return __wbg_finalize_init(instance, module);
484
+ }
485
+
486
+ async function __wbg_init(module_or_path) {
487
+ if (wasm !== undefined) return wasm;
488
+
489
+
490
+ if (module_or_path !== undefined) {
491
+ if (Object.getPrototypeOf(module_or_path) === Object.prototype) {
492
+ ({module_or_path} = module_or_path)
493
+ } else {
494
+ console.warn('using deprecated parameters for the initialization function; pass a single object instead')
495
+ }
496
+ }
497
+
498
+ if (module_or_path === undefined) {
499
+ module_or_path = new URL('brook_md_core_bg.wasm', import.meta.url);
500
+ }
501
+ const imports = __wbg_get_imports();
502
+
503
+ if (typeof module_or_path === 'string' || (typeof Request === 'function' && module_or_path instanceof Request) || (typeof URL === 'function' && module_or_path instanceof URL)) {
504
+ module_or_path = fetch(module_or_path);
505
+ }
506
+
507
+ const { instance, module } = await __wbg_load(await module_or_path, imports);
508
+
509
+ return __wbg_finalize_init(instance, module);
510
+ }
511
+
512
+ export { initSync, __wbg_init as default };
Binary file
@@ -0,0 +1,26 @@
1
+ /* tslint:disable */
2
+ /* eslint-disable */
3
+ export const memory: WebAssembly.Memory;
4
+ export const __wbg_brookparser_free: (a: number, b: number) => void;
5
+ export const brookparser_allBlocks: (a: number, b: number) => void;
6
+ export const brookparser_append: (a: number, b: number, c: number, d: number) => void;
7
+ export const brookparser_bufferLen: (a: number) => number;
8
+ export const brookparser_finalize: (a: number, b: number) => void;
9
+ export const brookparser_new: () => number;
10
+ export const brookparser_retainedBytes: (a: number) => number;
11
+ export const brookparser_setA11y: (a: number, b: number) => void;
12
+ export const brookparser_setBlockData: (a: number, b: number) => void;
13
+ export const brookparser_setComponentTags: (a: number, b: number, c: number) => void;
14
+ export const brookparser_setDirAuto: (a: number, b: number) => void;
15
+ export const brookparser_setGfmAlerts: (a: number, b: number) => void;
16
+ export const brookparser_setGfmAutolinks: (a: number, b: number) => void;
17
+ export const brookparser_setGfmFootnotes: (a: number, b: number) => void;
18
+ export const brookparser_setGfmMath: (a: number, b: number) => void;
19
+ export const brookparser_setGfmTagfilter: (a: number, b: number) => void;
20
+ export const brookparser_setHtmlSanitize: (a: number, b: number, c: number, d: number, e: number, f: number) => void;
21
+ export const brookparser_setInlineComponentTags: (a: number, b: number, c: number) => void;
22
+ export const brookparser_setUnsafeHtml: (a: number, b: number) => void;
23
+ export const __wbindgen_export: (a: number, b: number) => number;
24
+ export const __wbindgen_export2: (a: number, b: number, c: number, d: number) => number;
25
+ export const __wbindgen_add_to_stack_pointer: (a: number) => number;
26
+ export const __wbindgen_export3: (a: number, b: number, c: number) => void;
@@ -0,0 +1,65 @@
1
+ import type { FromWorker, ParserConfig, ToWorker } from "./types-core.js";
2
+ /** The slice of `BrookParser` the worker drives — narrowed to an interface so the
3
+ * message/readiness state machine is unit-testable with a fake parser, no WASM.
4
+ * (Same testability move as {@link BrookPool} taking an injected worker factory.)
5
+ *
6
+ * `append`/`finalize` return the patch as a **JSON string**, not an object: the
7
+ * worker forwards it verbatim to the main thread (a string structuredClones far
8
+ * cheaper than an object graph) where it is `JSON.parse`d exactly once. */
9
+ export interface ParserLike {
10
+ append(chunk: string): string;
11
+ finalize(): string;
12
+ free(): void;
13
+ retainedBytes(): number;
14
+ }
15
+ /** Dependencies injected into {@link WorkerCore}, isolating it from the worker
16
+ * globals (`self`, `queueMicrotask`) and the WASM module so it can be tested. */
17
+ export interface WorkerCoreDeps {
18
+ /** Create + configure a parser for a stream (prod: `new BrookParser()` + setX). */
19
+ makeParser(config: ParserConfig | undefined): ParserLike;
20
+ /** Post a message to the main thread (prod: `self.postMessage`). */
21
+ post(msg: FromWorker): void;
22
+ /** Current WASM heap size in bytes, reported on each patch (0 if unknown). */
23
+ memBytes(): number;
24
+ /** Defer a flush to a future microtask (prod: `queueMicrotask`). */
25
+ schedule(fn: () => void): void;
26
+ }
27
+ /**
28
+ * The worker's message reducer + WASM-readiness gate, extracted from the worker
29
+ * shell so its trickiest invariant is testable without a real Worker or WASM.
30
+ *
31
+ * **The invariant:** WASM `init()` is async, and the client does NOT wait for
32
+ * readiness before appending — so chunks can arrive first. A parser must never
33
+ * be constructed before init resolves (`new BrookParser()` against an
34
+ * uninitialized module throws `brookparser_new of undefined` and silently drops
35
+ * that chunk). So while `ready` is false, appends only accumulate in `pending`
36
+ * (scheduleFlush is a no-op) and `finalize` is deferred; {@link markReady}
37
+ * drains both — appends first (creating each parser + applying buffered text),
38
+ * then any deferred finalize — once init has completed.
39
+ */
40
+ export declare class WorkerCore {
41
+ private deps;
42
+ private parsers;
43
+ private config;
44
+ private pending;
45
+ private totalAppended;
46
+ private finalizePending;
47
+ private epochs;
48
+ private flushScheduled;
49
+ private ready;
50
+ constructor(deps: WorkerCoreDeps);
51
+ /** Handle one message from the main thread (append/finalize/reset/dispose). */
52
+ handle(msg: ToWorker): void;
53
+ /** Called once WASM init resolves: open the gate and drain what was buffered. */
54
+ markReady(): void;
55
+ private getOrCreate;
56
+ private dispose;
57
+ /** free() a stream's parser, swallowing a throw from a poisoned WASM instance
58
+ * so teardown can never escape the message loop. */
59
+ private safeFree;
60
+ private emitPatch;
61
+ private scheduleFlush;
62
+ private flush;
63
+ private doFinalize;
64
+ private postParseError;
65
+ }