markemental 0.0.0-stage → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs ADDED
@@ -0,0 +1,775 @@
1
+ 'use strict';
2
+
3
+ // src/renderers/util/inline.ts
4
+ var ESCAPABLE_RE = /^[!"#$%&'()*+,\-./:;<=>?@[\\\]^_`{|}~]$/;
5
+ var AUTOLINK_RE = /^[a-zA-Z][a-zA-Z0-9+.-]*:[^<>\s]*$/;
6
+ var ALNUM_RE = /[A-Za-z0-9]/;
7
+ function tryParseLink(text, start) {
8
+ const labelEnd = text.indexOf("]", start + 1);
9
+ if (labelEnd === -1 || text[labelEnd + 1] !== "(") return null;
10
+ const label = text.slice(start + 1, labelEnd);
11
+ if (label.includes("[") || label.includes("\n")) return null;
12
+ const hrefEnd = text.indexOf(")", labelEnd + 2);
13
+ if (hrefEnd === -1) return null;
14
+ const inside = text.slice(labelEnd + 2, hrefEnd).trim();
15
+ if (inside === "") return null;
16
+ if (/\s/.test(inside) && !/^<?\S+>?\s+"[^"]*"$/.test(inside)) return null;
17
+ const href = inside.replace(/^<(.*)>$/, "$1").split(/\s+/)[0];
18
+ return { label, href, end: hrefEnd + 1 };
19
+ }
20
+ function matchEmphasis(text, i, gfm) {
21
+ if (gfm && text.startsWith("~~", i)) return { marker: "~~", tag: "del", underscore: false };
22
+ if (text.startsWith("**", i)) return { marker: "**", tag: "strong", underscore: false };
23
+ if (text.startsWith("__", i)) return { marker: "__", tag: "strong", underscore: true };
24
+ if (text[i] === "*") return { marker: "*", tag: "em", underscore: false };
25
+ if (text[i] === "_") {
26
+ if (i > 0 && ALNUM_RE.test(text[i - 1])) return null;
27
+ return { marker: "_", tag: "em", underscore: true };
28
+ }
29
+ return null;
30
+ }
31
+ function findEmphasisClose(text, from, token) {
32
+ let at = text.indexOf(token.marker, from);
33
+ while (at !== -1 && token.underscore) {
34
+ const next = text[at + token.marker.length];
35
+ if (next === void 0 || !ALNUM_RE.test(next)) return at;
36
+ at = text.indexOf(token.marker, at + 1);
37
+ }
38
+ return at;
39
+ }
40
+ function appendInline(parent, text, doc, gfm) {
41
+ let i = 0;
42
+ let literal = "";
43
+ const flushLiteral = () => {
44
+ if (literal !== "") {
45
+ parent.appendChild(doc.createTextNode(literal));
46
+ literal = "";
47
+ }
48
+ };
49
+ while (i < text.length) {
50
+ const ch = text[i];
51
+ if (ch === "\\" && i + 1 < text.length && ESCAPABLE_RE.test(text[i + 1])) {
52
+ literal += text[i + 1];
53
+ i += 2;
54
+ continue;
55
+ }
56
+ if (ch === "`") {
57
+ const run = /^`+/.exec(text.slice(i));
58
+ const close = text.indexOf(run[0], i + run[0].length);
59
+ if (close !== -1) {
60
+ flushLiteral();
61
+ const code = doc.createElement("code");
62
+ code.appendChild(doc.createTextNode(text.slice(i + run[0].length, close)));
63
+ parent.appendChild(code);
64
+ i = close + run[0].length;
65
+ continue;
66
+ }
67
+ literal += ch;
68
+ i++;
69
+ continue;
70
+ }
71
+ if (ch === "!" && text[i + 1] === "[") {
72
+ const link = tryParseLink(text, i + 1);
73
+ if (link && link.href !== "") {
74
+ flushLiteral();
75
+ const img = doc.createElement("img");
76
+ img.setAttribute?.("src", link.href);
77
+ img.setAttribute?.("alt", link.label);
78
+ parent.appendChild(img);
79
+ i = link.end;
80
+ continue;
81
+ }
82
+ }
83
+ if (ch === "[") {
84
+ const link = tryParseLink(text, i);
85
+ if (link) {
86
+ flushLiteral();
87
+ const anchor = doc.createElement("a");
88
+ anchor.setAttribute?.("href", link.href);
89
+ appendInline(anchor, link.label, doc, gfm);
90
+ parent.appendChild(anchor);
91
+ i = link.end;
92
+ continue;
93
+ }
94
+ literal += ch;
95
+ i++;
96
+ continue;
97
+ }
98
+ if (ch === "<") {
99
+ const end = text.indexOf(">", i + 1);
100
+ if (end !== -1 && AUTOLINK_RE.test(text.slice(i + 1, end))) {
101
+ flushLiteral();
102
+ const href = text.slice(i + 1, end);
103
+ const anchor = doc.createElement("a");
104
+ anchor.setAttribute?.("href", href);
105
+ anchor.appendChild(doc.createTextNode(href));
106
+ parent.appendChild(anchor);
107
+ i = end + 1;
108
+ continue;
109
+ }
110
+ literal += ch;
111
+ i++;
112
+ continue;
113
+ }
114
+ const token = matchEmphasis(text, i, gfm);
115
+ if (token) {
116
+ const close = findEmphasisClose(text, i + token.marker.length, token);
117
+ if (close !== -1 && close > i + token.marker.length) {
118
+ flushLiteral();
119
+ const el = doc.createElement(token.tag);
120
+ appendInline(el, text.slice(i + token.marker.length, close), doc, gfm);
121
+ parent.appendChild(el);
122
+ i = close + token.marker.length;
123
+ continue;
124
+ }
125
+ literal += token.marker;
126
+ i += token.marker.length;
127
+ continue;
128
+ }
129
+ literal += ch;
130
+ i++;
131
+ }
132
+ flushLiteral();
133
+ }
134
+
135
+ // src/renderers/commonmark.ts
136
+ var CommonMarkRenderer = class {
137
+ /** Rendering options. */
138
+ options;
139
+ /**
140
+ * @param opts - CommonMark rendering options.
141
+ */
142
+ constructor(opts) {
143
+ this.options = opts;
144
+ }
145
+ /**
146
+ * Whether GFM-only inlines are enabled. Always false here; overridden by
147
+ * {@link GFMRenderer}.
148
+ *
149
+ * @returns False.
150
+ */
151
+ inlineGfm() {
152
+ return false;
153
+ }
154
+ /**
155
+ * Render one block to a DOM-like node.
156
+ *
157
+ * @param block - Parsed block to render.
158
+ * @param doc - Document used to create nodes.
159
+ * @returns The rendered node, or `null` to emit nothing.
160
+ */
161
+ renderBlock(block, doc) {
162
+ switch (block.kind) {
163
+ case "heading": {
164
+ const heading = doc.createElement(`h${block.level ?? 1}`);
165
+ this.appendLinesInline(heading, block.lines, doc, " ");
166
+ return heading;
167
+ }
168
+ case "paragraph":
169
+ return this.renderParagraph(block.lines, doc);
170
+ case "fence": {
171
+ const pre = doc.createElement("pre");
172
+ const code = doc.createElement("code");
173
+ if (block.language !== void 0) code.setAttribute?.("class", `language-${block.language}`);
174
+ const text = block.lines.join("\n");
175
+ code.appendChild(doc.createTextNode(text === "" ? "" : `${text}
176
+ `));
177
+ pre.appendChild(code);
178
+ return pre;
179
+ }
180
+ case "list": {
181
+ const list = doc.createElement(block.ordered ? "ol" : "ul");
182
+ for (const item of block.lines) {
183
+ const li = doc.createElement("li");
184
+ appendInline(li, item, doc, this.inlineGfm());
185
+ list.appendChild(li);
186
+ }
187
+ return list;
188
+ }
189
+ case "quote": {
190
+ const quote = doc.createElement("blockquote");
191
+ const body = doc.createElement("p");
192
+ this.appendLinesInline(body, block.lines, doc, " ");
193
+ quote.appendChild(body);
194
+ return quote;
195
+ }
196
+ case "rule":
197
+ return doc.createElement("hr");
198
+ case "table":
199
+ return this.renderParagraph(block.lines.filter((_, at) => at !== 1), doc);
200
+ }
201
+ }
202
+ /**
203
+ * Render paragraph lines, honoring two-space hard breaks.
204
+ *
205
+ * @param lines - Raw paragraph lines.
206
+ * @param doc - Document used to create nodes.
207
+ * @returns The paragraph element.
208
+ */
209
+ renderParagraph(lines, doc) {
210
+ const paragraph = doc.createElement("p");
211
+ lines.forEach((line, at) => {
212
+ const hardBreak = / {2,}$/.test(line);
213
+ appendInline(paragraph, hardBreak ? line.replace(/ {2,}$/, "") : line, doc, this.inlineGfm());
214
+ if (at < lines.length - 1) {
215
+ if (hardBreak) paragraph.appendChild(doc.createElement("br"));
216
+ else paragraph.appendChild(doc.createTextNode(" "));
217
+ }
218
+ });
219
+ return paragraph;
220
+ }
221
+ appendLinesInline(parent, lines, doc, join) {
222
+ lines.forEach((line, at) => {
223
+ if (at > 0) parent.appendChild(doc.createTextNode(join));
224
+ appendInline(parent, line, doc, this.inlineGfm());
225
+ });
226
+ }
227
+ };
228
+
229
+ // src/renderers/gfm.ts
230
+ function splitRow(line) {
231
+ return line.trim().replace(/^\|/, "").replace(/\|$/, "").split("|").map((cell) => cell.trim());
232
+ }
233
+ function parseAlignment(cell) {
234
+ const left = cell.startsWith(":");
235
+ const right = cell.endsWith(":");
236
+ if (left && right) return "center";
237
+ if (right) return "right";
238
+ if (left) return "left";
239
+ return null;
240
+ }
241
+ var GFMRenderer = class extends CommonMarkRenderer {
242
+ /** Rendering options. */
243
+ options;
244
+ /**
245
+ * @param opts - GFM rendering options.
246
+ */
247
+ constructor(opts) {
248
+ super({});
249
+ this.options = opts;
250
+ }
251
+ /**
252
+ * GFM-only inlines are enabled.
253
+ *
254
+ * @returns True.
255
+ */
256
+ inlineGfm() {
257
+ return true;
258
+ }
259
+ /**
260
+ * Render one block to a DOM-like node, handling GFM tables.
261
+ *
262
+ * @param block - Parsed block to render.
263
+ * @param doc - Document used to create nodes.
264
+ * @returns The rendered node, or `null` to emit nothing.
265
+ */
266
+ renderBlock(block, doc) {
267
+ if (block.kind !== "table") return super.renderBlock(block, doc);
268
+ const rows = block.lines.map(splitRow);
269
+ const header = rows[0] ?? [];
270
+ const alignments = (rows[1] ?? []).map(parseAlignment);
271
+ const width = Math.max(header.length, ...rows.map((row) => row.length));
272
+ const table = doc.createElement("table");
273
+ const head = doc.createElement("thead");
274
+ const headRow = doc.createElement("tr");
275
+ for (let col = 0; col < width; col++) {
276
+ const cell = doc.createElement("th");
277
+ const align = alignments[col] ?? null;
278
+ if (align !== null) cell.setAttribute?.("align", align);
279
+ appendInline(cell, header[col] ?? "", doc, true);
280
+ headRow.appendChild(cell);
281
+ }
282
+ head.appendChild(headRow);
283
+ table.appendChild(head);
284
+ const body = doc.createElement("tbody");
285
+ for (const row of rows.slice(2)) {
286
+ const bodyRow = doc.createElement("tr");
287
+ for (let col = 0; col < width; col++) {
288
+ const cell = doc.createElement("td");
289
+ const align = alignments[col] ?? null;
290
+ if (align !== null) cell.setAttribute?.("align", align);
291
+ appendInline(cell, row[col] ?? "", doc, true);
292
+ bodyRow.appendChild(cell);
293
+ }
294
+ body.appendChild(bodyRow);
295
+ }
296
+ table.appendChild(body);
297
+ return table;
298
+ }
299
+ };
300
+
301
+ // src/targets/animated-dom-target.ts
302
+ var AnimatedDOMTarget = class {
303
+ _targetNode;
304
+ _raf;
305
+ _queue = [];
306
+ _scheduled = false;
307
+ _flushResolvers = [];
308
+ /**
309
+ * @param targetNode - Container node receiving rendered output.
310
+ * @param raf - Frame scheduler used to batch writes.
311
+ */
312
+ constructor(targetNode, raf) {
313
+ this._targetNode = targetNode;
314
+ this._raf = raf;
315
+ }
316
+ /**
317
+ * Queue a rendered node for the next frame.
318
+ *
319
+ * @param node - Node to attach.
320
+ */
321
+ append(node) {
322
+ this._queue.push(node);
323
+ if (!this._scheduled) {
324
+ this._scheduled = true;
325
+ this._raf(() => {
326
+ this._scheduled = false;
327
+ const batch = this._queue;
328
+ this._queue = [];
329
+ for (const queued of batch) this._targetNode.appendChild(queued);
330
+ const resolvers = this._flushResolvers;
331
+ this._flushResolvers = [];
332
+ for (const resolve of resolvers) resolve();
333
+ });
334
+ }
335
+ }
336
+ /**
337
+ * Wait until every queued node has been attached.
338
+ *
339
+ * @returns A promise that resolves after the next frame carrying nodes.
340
+ */
341
+ flush() {
342
+ if (!this._scheduled && this._queue.length === 0) return Promise.resolve();
343
+ return new Promise((resolve) => {
344
+ this._flushResolvers.push(resolve);
345
+ });
346
+ }
347
+ };
348
+
349
+ // src/targets/dom-target.ts
350
+ var DOMTarget = class {
351
+ _targetNode;
352
+ /**
353
+ * @param targetNode - Container node receiving rendered output.
354
+ */
355
+ constructor(targetNode) {
356
+ this._targetNode = targetNode;
357
+ }
358
+ /**
359
+ * Append a rendered node immediately.
360
+ *
361
+ * @param node - Node to attach.
362
+ */
363
+ append(node) {
364
+ this._targetNode.appendChild(node);
365
+ }
366
+ /**
367
+ * Resolve immediately: synchronous targets hold every node already.
368
+ *
369
+ * @returns A resolved promise.
370
+ */
371
+ flush() {
372
+ return Promise.resolve();
373
+ }
374
+ };
375
+
376
+ // src/core/util/blocks.ts
377
+ var HEADING_RE = /^(#{1,6})(?:\s+(.*))?\s*$/;
378
+ var RULE_RE = /^(?:\*\s*){3,}$|^(?:-\s*){3,}$|^(?:_\s*){3,}$/;
379
+ var FENCE_RE = /^(`{3,}|~{3,})\s*([^`]*)$/;
380
+ var QUOTE_RE = /^>\s?(.*)$/;
381
+ var BULLET_RE = /^\s*[-*+]\s+(.*)$/;
382
+ var ORDERED_RE = /^\s*\d+[.)]\s+(.*)$/;
383
+ var TABLE_DELIM_CELL_RE = /^:?-{1,}:?$/;
384
+ function isBlankLine(line) {
385
+ return line.trim() === "";
386
+ }
387
+ function isBlank(line) {
388
+ return isBlankLine(line);
389
+ }
390
+ function isTableDelimiter(line) {
391
+ if (!line.includes("|") && !line.includes("-")) return false;
392
+ const cells = line.trim().replace(/^\|/, "").replace(/\|$/, "").split("|");
393
+ return cells.length > 0 && cells.every((cell) => TABLE_DELIM_CELL_RE.test(cell.trim()));
394
+ }
395
+ function hasOpenFence(lines) {
396
+ let openChar = "";
397
+ let openLen = 0;
398
+ for (const line of lines) {
399
+ const match = FENCE_RE.exec(line.trim());
400
+ if (!match || !match[1]) continue;
401
+ const run = match[1];
402
+ if (openChar === "") {
403
+ openChar = run[0];
404
+ openLen = run.length;
405
+ } else if (run[0] === openChar && run.length >= openLen) {
406
+ openChar = "";
407
+ openLen = 0;
408
+ }
409
+ }
410
+ return openChar !== "";
411
+ }
412
+ function makeBlock(block, sourceLineCount) {
413
+ return { ...block, sourceLineCount };
414
+ }
415
+ function splitBlocks(lines) {
416
+ const blocks = [];
417
+ let i = 0;
418
+ while (i < lines.length) {
419
+ const line = lines[i];
420
+ if (isBlank(line)) {
421
+ i++;
422
+ continue;
423
+ }
424
+ const fence = FENCE_RE.exec(line.trim());
425
+ if (fence && fence[1]) {
426
+ const run = fence[1];
427
+ const language = (fence[2] ?? "").trim() || void 0;
428
+ const content = [];
429
+ let j2 = i + 1;
430
+ while (j2 < lines.length) {
431
+ const inner = lines[j2];
432
+ const close = FENCE_RE.exec(inner.trim());
433
+ if (close && close[1] && close[1][0] === run[0] && close[1].length >= run.length) break;
434
+ content.push(inner);
435
+ j2++;
436
+ }
437
+ const closed = j2 < lines.length;
438
+ blocks.push(makeBlock({ kind: "fence", lines: content, language }, j2 - i + (closed ? 1 : 0)));
439
+ i = j2 + (closed ? 1 : 0);
440
+ continue;
441
+ }
442
+ const heading = HEADING_RE.exec(line);
443
+ if (heading && heading[1]) {
444
+ const text = (heading[2] ?? "").replace(/\s+#+\s*$/, "").trim();
445
+ blocks.push(makeBlock({ kind: "heading", lines: [text], level: Math.min(6, heading[1].length) }, 1));
446
+ i++;
447
+ continue;
448
+ }
449
+ if (RULE_RE.test(line.trim())) {
450
+ blocks.push(makeBlock({ kind: "rule", lines: [] }, 1));
451
+ i++;
452
+ continue;
453
+ }
454
+ if (line.includes("|") && i + 1 < lines.length && isTableDelimiter(lines[i + 1])) {
455
+ const rows = [line, lines[i + 1]];
456
+ let j2 = i + 2;
457
+ while (j2 < lines.length && !isBlank(lines[j2]) && lines[j2].includes("|")) {
458
+ rows.push(lines[j2]);
459
+ j2++;
460
+ }
461
+ blocks.push(makeBlock({ kind: "table", lines: rows }, j2 - i));
462
+ i = j2;
463
+ continue;
464
+ }
465
+ const quote = QUOTE_RE.exec(line);
466
+ if (quote) {
467
+ const quoted = [quote[1] ?? ""];
468
+ let j2 = i + 1;
469
+ while (j2 < lines.length) {
470
+ const next = QUOTE_RE.exec(lines[j2]);
471
+ if (!next) break;
472
+ quoted.push(next[1] ?? "");
473
+ j2++;
474
+ }
475
+ blocks.push(makeBlock({ kind: "quote", lines: quoted }, j2 - i));
476
+ i = j2;
477
+ continue;
478
+ }
479
+ const bullet = BULLET_RE.exec(line);
480
+ const ordered = ORDERED_RE.exec(line);
481
+ if (bullet || ordered) {
482
+ const isOrdered = !bullet;
483
+ const items = [bullet?.[1] ?? ordered?.[1] ?? ""];
484
+ let j2 = i + 1;
485
+ while (j2 < lines.length) {
486
+ const nextBullet = BULLET_RE.exec(lines[j2]);
487
+ const nextOrdered = ORDERED_RE.exec(lines[j2]);
488
+ if (isOrdered && nextOrdered) items.push(nextOrdered[1] ?? "");
489
+ else if (!isOrdered && nextBullet && !ORDERED_RE.test(lines[j2])) items.push(nextBullet[1] ?? "");
490
+ else break;
491
+ j2++;
492
+ }
493
+ blocks.push(makeBlock({ kind: "list", lines: items, ordered: isOrdered }, j2 - i));
494
+ i = j2;
495
+ continue;
496
+ }
497
+ const paragraph = [line];
498
+ let j = i + 1;
499
+ while (j < lines.length) {
500
+ const next = lines[j];
501
+ if (isBlank(next) || FENCE_RE.test(next.trim()) || HEADING_RE.test(next) || RULE_RE.test(next.trim()) || QUOTE_RE.test(next) || BULLET_RE.test(next) || ORDERED_RE.test(next) || next.includes("|") && j + 1 < lines.length && isTableDelimiter(lines[j + 1])) {
502
+ break;
503
+ }
504
+ paragraph.push(next);
505
+ j++;
506
+ }
507
+ blocks.push(makeBlock({ kind: "paragraph", lines: paragraph }, j - i));
508
+ i = j;
509
+ }
510
+ return blocks;
511
+ }
512
+
513
+ // src/renderers/renderer-state.ts
514
+ var RendererState = class {
515
+ _pending = [];
516
+ /**
517
+ * Buffer newly arrived lines.
518
+ *
519
+ * @param lines - Complete source lines to buffer.
520
+ */
521
+ addLines(lines) {
522
+ for (const line of lines) this._pending.push(line);
523
+ }
524
+ /**
525
+ * Parse buffered lines, returning every block except a trailing partial one.
526
+ *
527
+ * @remarks
528
+ * The last block is held back because more input may still extend it.
529
+ * Nothing is returned while the buffer ends inside an unclosed fence.
530
+ *
531
+ * @returns Complete blocks ready to render.
532
+ */
533
+ takeCompleteBlocks() {
534
+ let start = 0;
535
+ let end = this._pending.length;
536
+ while (start < end && isBlankLine(this._pending[start])) start++;
537
+ while (end > start && isBlankLine(this._pending[end - 1])) end--;
538
+ const trimmed = this._pending.slice(start, end);
539
+ if (trimmed.length === 0) {
540
+ this._pending = [];
541
+ return [];
542
+ }
543
+ if (hasOpenFence(trimmed)) return [];
544
+ const blocks = splitBlocks(trimmed);
545
+ const last = blocks[blocks.length - 1];
546
+ if (last === void 0) {
547
+ this._pending = [];
548
+ return [];
549
+ }
550
+ this._pending = trimmed.slice(trimmed.length - last.sourceLineCount);
551
+ return blocks.slice(0, -1);
552
+ }
553
+ /**
554
+ * Parse and drain all buffered lines, including a trailing partial block.
555
+ *
556
+ * @returns Every remaining block.
557
+ */
558
+ takeAllBlocks() {
559
+ const blocks = splitBlocks(this._pending);
560
+ this._pending = [];
561
+ return blocks;
562
+ }
563
+ };
564
+
565
+ // src/sources/line-source.ts
566
+ function createLineSource() {
567
+ let buffer = "";
568
+ let closed = false;
569
+ return {
570
+ push(chunk) {
571
+ if (closed) throw new Error("push after close");
572
+ buffer += chunk;
573
+ },
574
+ readLines() {
575
+ const lines = [];
576
+ let at = buffer.indexOf("\n");
577
+ while (at !== -1) {
578
+ lines.push(buffer.slice(0, at).replace(/\r$/, ""));
579
+ buffer = buffer.slice(at + 1);
580
+ at = buffer.indexOf("\n");
581
+ }
582
+ return lines;
583
+ },
584
+ close() {
585
+ closed = true;
586
+ if (buffer === "") return [];
587
+ const rest = buffer.replace(/\r$/, "");
588
+ buffer = "";
589
+ return [rest];
590
+ }
591
+ };
592
+ }
593
+
594
+ // src/core/pipelines/pipeline-engine.ts
595
+ function createPipelineEngine(renderer, target, dom) {
596
+ const source = createLineSource();
597
+ const state = new RendererState();
598
+ function render(blocks) {
599
+ for (const block of blocks) {
600
+ const node = renderer.renderBlock(block, dom);
601
+ if (node !== null) target.append(node);
602
+ }
603
+ }
604
+ return {
605
+ async push(chunk) {
606
+ source.push(await chunk);
607
+ state.addLines(source.readLines());
608
+ render(state.takeCompleteBlocks());
609
+ },
610
+ async flush() {
611
+ state.addLines(source.close());
612
+ render(state.takeAllBlocks());
613
+ await target.flush();
614
+ }
615
+ };
616
+ }
617
+
618
+ // src/core/pipelines/frontend-gfm-pipeline.ts
619
+ function createFrontendGFMPipeline(target, dom, opts, raf) {
620
+ return new FrontendGFMPipeline(target, dom, opts, raf);
621
+ }
622
+ var FrontendGFMPipeline = class {
623
+ _engine;
624
+ /**
625
+ * @param target - Container node receiving rendered blocks.
626
+ * @param dom - Document used to create nodes.
627
+ * @param opts - GFM rendering options.
628
+ * @param raf - Optional frame scheduler for batched DOM writes.
629
+ */
630
+ constructor(target, dom, opts, raf) {
631
+ this._engine = createPipelineEngine(
632
+ new GFMRenderer(opts),
633
+ raf === void 0 ? new DOMTarget(target) : new AnimatedDOMTarget(target, raf),
634
+ dom
635
+ );
636
+ }
637
+ /**
638
+ * Push a chunk of markdown into the pipeline.
639
+ *
640
+ * @param chunk - Markdown text, or a promise resolving to markdown text.
641
+ * @returns A promise that resolves once the chunk has been consumed.
642
+ */
643
+ push(chunk) {
644
+ return this._engine.push(chunk);
645
+ }
646
+ /**
647
+ * Render any buffered remainder.
648
+ *
649
+ * @returns A promise that resolves once all output has been flushed.
650
+ */
651
+ flush() {
652
+ return this._engine.flush();
653
+ }
654
+ };
655
+
656
+ // src/core/pipelines/frontend-commonmark-pipeline.ts
657
+ function createFrontendCommonMarkPipeline(target, dom, opts, raf) {
658
+ return new FrontendCommonMarkPipeline(target, dom, opts, raf);
659
+ }
660
+ var FrontendCommonMarkPipeline = class {
661
+ _engine;
662
+ /**
663
+ * @param target - Container node receiving rendered blocks.
664
+ * @param dom - Document used to create nodes.
665
+ * @param opts - CommonMark rendering options.
666
+ * @param raf - Optional frame scheduler for batched DOM writes.
667
+ */
668
+ constructor(target, dom, opts, raf) {
669
+ this._engine = createPipelineEngine(
670
+ new CommonMarkRenderer(opts),
671
+ raf === void 0 ? new DOMTarget(target) : new AnimatedDOMTarget(target, raf),
672
+ dom
673
+ );
674
+ }
675
+ /**
676
+ * Push a chunk of markdown into the pipeline.
677
+ *
678
+ * @param chunk - Markdown text, or a promise resolving to markdown text.
679
+ * @returns A promise that resolves once the chunk has been consumed.
680
+ */
681
+ push(chunk) {
682
+ return this._engine.push(chunk);
683
+ }
684
+ /**
685
+ * Render any buffered remainder.
686
+ *
687
+ * @returns A promise that resolves once all output has been flushed.
688
+ */
689
+ flush() {
690
+ return this._engine.flush();
691
+ }
692
+ };
693
+
694
+ // src/core/pipelines/backend-gfm-pipeline.ts
695
+ function createBackendGFMPipeline(target, dom, opts) {
696
+ return new BackendGFMPipeline(target, dom, opts);
697
+ }
698
+ var BackendGFMPipeline = class {
699
+ _engine;
700
+ /**
701
+ * @param target - Container node receiving rendered blocks.
702
+ * @param dom - Document used to create nodes.
703
+ * @param opts - GFM rendering options.
704
+ */
705
+ constructor(target, dom, opts) {
706
+ this._engine = createPipelineEngine(new GFMRenderer(opts), new DOMTarget(target), dom);
707
+ }
708
+ /**
709
+ * Push a chunk of markdown into the pipeline.
710
+ *
711
+ * @param chunk - Markdown text, or a promise resolving to markdown text.
712
+ * @returns A promise that resolves once the chunk has been consumed.
713
+ */
714
+ push(chunk) {
715
+ return this._engine.push(chunk);
716
+ }
717
+ /**
718
+ * Render any buffered remainder.
719
+ *
720
+ * @returns A promise that resolves once all output has been flushed.
721
+ */
722
+ flush() {
723
+ return this._engine.flush();
724
+ }
725
+ };
726
+
727
+ // src/core/pipelines/backend-commonmark-pipeline.ts
728
+ function createBackendCommonMarkPipeline(target, dom, opts) {
729
+ return new BackendCommonMarkPipeline(target, dom, opts);
730
+ }
731
+ var BackendCommonMarkPipeline = class {
732
+ _engine;
733
+ /**
734
+ * @param target - Container node receiving rendered blocks.
735
+ * @param dom - Document used to create nodes.
736
+ * @param opts - CommonMark rendering options.
737
+ */
738
+ constructor(target, dom, opts) {
739
+ this._engine = createPipelineEngine(new CommonMarkRenderer(opts), new DOMTarget(target), dom);
740
+ }
741
+ /**
742
+ * Push a chunk of markdown into the pipeline.
743
+ *
744
+ * @param chunk - Markdown text, or a promise resolving to markdown text.
745
+ * @returns A promise that resolves once the chunk has been consumed.
746
+ */
747
+ push(chunk) {
748
+ return this._engine.push(chunk);
749
+ }
750
+ /**
751
+ * Render any buffered remainder.
752
+ *
753
+ * @returns A promise that resolves once all output has been flushed.
754
+ */
755
+ flush() {
756
+ return this._engine.flush();
757
+ }
758
+ };
759
+
760
+ exports.AnimatedDOMTarget = AnimatedDOMTarget;
761
+ exports.BackendCommonMarkPipeline = BackendCommonMarkPipeline;
762
+ exports.BackendGFMPipeline = BackendGFMPipeline;
763
+ exports.CommonMarkRenderer = CommonMarkRenderer;
764
+ exports.DOMTarget = DOMTarget;
765
+ exports.FrontendCommonMarkPipeline = FrontendCommonMarkPipeline;
766
+ exports.FrontendGFMPipeline = FrontendGFMPipeline;
767
+ exports.GFMRenderer = GFMRenderer;
768
+ exports.RendererState = RendererState;
769
+ exports.createBackendCommonMarkPipeline = createBackendCommonMarkPipeline;
770
+ exports.createBackendGFMPipeline = createBackendGFMPipeline;
771
+ exports.createFrontendCommonMarkPipeline = createFrontendCommonMarkPipeline;
772
+ exports.createFrontendGFMPipeline = createFrontendGFMPipeline;
773
+ exports.createLineSource = createLineSource;
774
+ //# sourceMappingURL=index.cjs.map
775
+ //# sourceMappingURL=index.cjs.map