typewright 0.2.1
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/LICENSE +21 -0
- package/README.md +168 -0
- package/SPEC.md +327 -0
- package/dist/chunk-CZQO7TTL.js +1533 -0
- package/dist/chunk-CZQO7TTL.js.map +1 -0
- package/dist/chunk-KNEKNZXK.js +286 -0
- package/dist/chunk-KNEKNZXK.js.map +1 -0
- package/dist/chunk-M6IVEMXO.js +1398 -0
- package/dist/chunk-M6IVEMXO.js.map +1 -0
- package/dist/chunk-NJ7PJKHN.js +652 -0
- package/dist/chunk-NJ7PJKHN.js.map +1 -0
- package/dist/commands-Z3ndUSza.d.cts +221 -0
- package/dist/commands-Z3ndUSza.d.ts +221 -0
- package/dist/core/index.cjs +2952 -0
- package/dist/core/index.cjs.map +1 -0
- package/dist/core/index.d.cts +410 -0
- package/dist/core/index.d.ts +410 -0
- package/dist/core/index.js +4 -0
- package/dist/core/index.js.map +1 -0
- package/dist/mdx/index.cjs +662 -0
- package/dist/mdx/index.cjs.map +1 -0
- package/dist/mdx/index.d.cts +252 -0
- package/dist/mdx/index.d.ts +252 -0
- package/dist/mdx/index.js +3 -0
- package/dist/mdx/index.js.map +1 -0
- package/dist/react/index.cjs +7439 -0
- package/dist/react/index.cjs.map +1 -0
- package/dist/react/index.d.cts +140 -0
- package/dist/react/index.d.ts +140 -0
- package/dist/react/index.js +3644 -0
- package/dist/react/index.js.map +1 -0
- package/dist/streaming/index.cjs +1494 -0
- package/dist/streaming/index.cjs.map +1 -0
- package/dist/streaming/index.d.cts +64 -0
- package/dist/streaming/index.d.ts +64 -0
- package/dist/streaming/index.js +4 -0
- package/dist/streaming/index.js.map +1 -0
- package/dist/types-CX1GOx0Y.d.cts +319 -0
- package/dist/types-CX1GOx0Y.d.ts +319 -0
- package/package.json +128 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/core/ast.ts","../../src/core/parser.ts","../../src/core/render.ts","../../src/streaming/anticipate.ts","../../src/streaming/index.ts"],"names":["node","MAX_URL","committed","committedHtml"],"mappings":";;;AA8QO,SAAS,IAAA,CAAK,MAAe,KAAA,EAAgD;AAClF,EAAA,MAAM,EAAA,GAAK,CAAC,CAAA,KAAqB;AAC/B,IAAA,IAAI,KAAA,CAAM,CAAC,CAAA,KAAM,KAAA,EAAO;AACxB,IAAA,MAAM,IAAA,GAAO,WAAW,CAAC,CAAA;AACzB,IAAA,KAAA,MAAW,CAAA,IAAK,IAAA,EAAM,EAAA,CAAG,CAAC,CAAA;AAAA,EAC5B,CAAA;AACA,EAAA,EAAA,CAAG,IAAI,CAAA;AACT;AAEO,SAAS,WAAW,IAAA,EAA0B;AACnD,EAAA,QAAQ,KAAK,IAAA;AAAM,IACjB,KAAK,UAAA;AAAA,IACL,KAAK,YAAA;AACH,MAAA,OAAO,IAAA,CAAK,QAAA;AAAA,IACd,KAAK,SAAA;AAAA,IACL,KAAK,WAAA;AAAA,IACL,KAAK,UAAA;AAAA,IACL,KAAK,QAAA;AAAA,IACL,KAAK,eAAA;AAAA,IACL,KAAK,WAAA;AACH,MAAA,OAAO,IAAA,CAAK,QAAA;AAAA,IACd,KAAK,MAAA;AACH,MAAA,OAAO,IAAA,CAAK,QAAA;AAAA,IACd,KAAK,MAAA;AACH,MAAA,OAAO,IAAA,CAAK,KAAA;AAAA,IACd,KAAK,UAAA;AACH,MAAA,OAAO,IAAA,CAAK,QAAA;AAAA,IACd,KAAK,OAAA;AACH,MAAA,OAAO,CAAC,GAAG,IAAA,CAAK,MAAA,EAAQ,GAAG,IAAA,CAAK,IAAA,CAAK,MAAM,CAAA;AAAA,IAC7C,KAAK,aAAA;AACH,MAAA,OAAO,IAAA,CAAK,QAAA;AAAA,IACd,KAAK,SAAA;AACH,MAAA,OAAO,IAAA,CAAK,KAAA;AAAA,IACd,KAAK,SAAA;AACH,MAAA,OAAO,CAAC,GAAG,IAAA,CAAK,IAAA,EAAM,GAAG,IAAA,CA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ACf,EAAA,IAAI,MAAA,CAAO,iBAAiB,MAAA,EAAQ;AAClC,IAAA,WAAA,MAAiB,SAAS,MAAA,EAAiC;AACzD,MAAA,UAAA,CAAW,KAAK,KAAK,CAAA;AAAA,IACvB;AAAA,EACF,CAAA,MAAO;AACL,IAAA,MAAM,MAAA,GAAS,OAAO,SAAA,EAAU;AAChC,IAAA,WAAS;AACP,MAAA,MAAM,EAAE,IAAA,EAAM,KAAA,EAAM,GAAI,MAAM,OAAO,IAAA,EAAK;AAC1C,MAAA,IAAI,IAAA,EAAM;AACV,MAAA,IAAI,KAAA,IAAS,IAAA,EAAM,UAAA,CAAW,IAAA,CAAK,KAAK,CAAA;AAAA,IAC1C;AAAA,EACF;AACA,EAAA,UAAA,CAAW,GAAA,EAAI;AACjB","file":"index.cjs","sourcesContent":["/**\n * Typewright AST — the offset-exact node model the parser produces and the\n * renderer / unified-mode / fold services consume.\n *\n * Every node carries `from`/`to`: UTF-16 offsets into the source string. This\n * is the contract that makes non-destructive rendering, source-revealing, and\n * folding possible — a node always knows exactly which slice of the string it\n * owns. Marker offsets (e.g. a heading's `### `, an emphasis delimiter) are\n * exposed where a consumer needs to hide/reveal them.\n */\n\nexport interface Pos {\n /** Inclusive start offset into the source string. */\n from: number;\n /** Exclusive end offset into the source string. */\n to: number;\n}\n\n/* ------------------------------------------------------------------ *\n * Inline nodes\n * ------------------------------------------------------------------ */\n\nexport interface TextNode extends Pos {\n type: 'text';\n value: string;\n}\n\nexport interface Emphasis extends Pos {\n type: 'emphasis';\n /** The delimiter used (`*` or `_`). */\n marker: string;\n children: Inline[];\n}\n\nexport interface Strong extends Pos {\n type: 'strong';\n marker: string;\n children: Inline[];\n}\n\nexport interface Strikethrough extends Pos {\n type: 'strikethrough';\n children: Inline[];\n}\n\nexport interface InlineCode extends Pos {\n type: 'inlineCode';\n value: string;\n /** Number of backticks in the fence. */\n ticks: number;\n}\n\nexport interface Link extends Pos {\n type: 'link';\n url: string;\n title?: string;\n children: Inline[];\n}\n\nexport interface Image extends Pos {\n type: 'image';\n url: string;\n alt: string;\n title?: string;\n}\n\nexport interface Autolink extends Pos {\n type: 'autolink';\n url: string;\n}\n\nexport interface LineBreak extends Pos {\n type: 'break';\n /** A hard break (two trailing spaces or backslash) vs a soft newline. */\n hard: boolean;\n}\n\n/** Inline math (`$…$` inline, `$$…$$` inline-display). Opt-in via {@link ParseOptions.math}. */\nexport interface Math extends Pos {\n type: 'math';\n /** The TeX source between the delimiters (delimiters excluded). */\n value: string;\n /** `true` for a `$$…$$` display span, `false` for a `$…$` inline span. */\n display: boolean;\n}\n\n/** A footnote reference `[^id]`. Opt-in via {@link ParseOptions.footnotes}. */\nexport interface FootnoteRef extends Pos {\n type: 'footnoteRef';\n /** The referenced footnote label (between `[^` and `]`). */\n id: string;\n}\n\nexport type Inline =\n | TextNode\n | Emphasis\n | Strong\n | Strikethrough\n | InlineCode\n | Link\n | Image\n | Autolink\n | LineBreak\n | Math\n | FootnoteRef;\n\n/* ------------------------------------------------------------------ *\n * Block nodes\n * ------------------------------------------------------------------ */\n\nexport interface Heading extends Pos {\n type: 'heading';\n level: 1 | 2 | 3 | 4 | 5 | 6;\n /** Offset just past the `#`… marker + following space (start of content). */\n contentFrom: number;\n children: Inline[];\n}\n\nexport interface Paragraph extends Pos {\n type: 'paragraph';\n children: Inline[];\n}\n\nexport interface Blockquote extends Pos {\n type: 'blockquote';\n children: Block[];\n}\n\nexport type TaskState = 'checked' | 'unchecked' | null;\n\nexport interface ListItem extends Pos {\n type: 'listItem';\n /** Task-list state, or null for a plain item. */\n task: TaskState;\n /** Offset just past the list marker (`- `, `1. `, `- [x] `). */\n contentFrom: number;\n children: Block[];\n}\n\nexport interface List extends Pos {\n type: 'list';\n ordered: boolean;\n /** Start number for an ordered list. */\n start: number;\n /** Loose lists wrap items in paragraphs; tight lists don't. */\n tight: boolean;\n items: ListItem[];\n}\n\nexport interface CodeBlock extends Pos {\n type: 'codeBlock';\n /** Info string after the opening fence (may be empty). */\n lang: string;\n value: string;\n fenced: boolean;\n}\n\nexport interface ThematicBreak extends Pos {\n type: 'thematicBreak';\n}\n\nexport type CellAlign = 'left' | 'center' | 'right' | null;\n\nexport interface TableCell extends Pos {\n type: 'tableCell';\n children: Inline[];\n}\n\nexport interface Table extends Pos {\n type: 'table';\n align: CellAlign[];\n header: TableCell[];\n rows: TableCell[][];\n}\n\n/** Raw HTML or an MDX/JSX/ESM region — kept verbatim (markup only, not evaluated). */\nexport interface HtmlBlock extends Pos {\n type: 'htmlBlock';\n value: string;\n /** `html` for raw HTML, `mdxFlow` for a JSX element / ESM line at block level. */\n variant: 'html' | 'mdxFlow';\n}\n\n/** A `$$…$$` display-math block. Opt-in via {@link ParseOptions.math}. */\nexport interface MathBlock extends Pos {\n type: 'mathBlock';\n /** The TeX source between the `$$` fences (fences excluded). */\n value: string;\n}\n\n/** A footnote definition `[^id]: …`. Opt-in via {@link ParseOptions.footnotes}. */\nexport interface FootnoteDef extends Pos {\n type: 'footnoteDef';\n /** The footnote label (between `[^` and `]`). */\n id: string;\n children: Block[];\n}\n\n/** A single term + one-or-more definitions inside a {@link DefList}. */\nexport interface DefItem extends Pos {\n type: 'defItem';\n term: Inline[];\n /** Each `: …` definition, parsed as its own block sequence. */\n definitions: Block[][];\n}\n\n/** A definition list — terms with `: …` definitions. Opt-in via {@link ParseOptions.defLists}. */\nexport interface DefList extends Pos {\n type: 'defList';\n items: DefItem[];\n}\n\nexport type Block =\n | Heading\n | Paragraph\n | Blockquote\n | List\n | CodeBlock\n | ThematicBreak\n | Table\n | HtmlBlock\n | MathBlock\n | FootnoteDef\n | DefList;\n\nexport interface Document extends Pos {\n type: 'document';\n children: Block[];\n}\n\nexport type AstNode = Document | Block | ListItem | TableCell | DefItem | Inline;\n\n/**\n * Opt-in parser extensions. Every flag defaults to `false`, so `parse(src)`\n * behaves exactly as it always has; enabling a flag lights up the matching\n * construct (and nothing else). Kept semver-safe so a later wave can turn these\n * on from configuration without a breaking parser change.\n */\nexport interface ParseOptions {\n /** Parse `$…$` inline and `$$…$$` block math. */\n math?: boolean;\n /** Parse `[^id]` footnote references and `[^id]: …` definitions. */\n footnotes?: boolean;\n /** Parse `term` / `: definition` definition lists. */\n defLists?: boolean;\n}\n\n/* ------------------------------------------------------------------ *\n * Helpers\n * ------------------------------------------------------------------ */\n\nconst INLINE_TYPES = new Set([\n 'text',\n 'emphasis',\n 'strong',\n 'strikethrough',\n 'inlineCode',\n 'link',\n 'image',\n 'autolink',\n 'break',\n 'math',\n 'footnoteRef',\n]);\n\nexport function isInline(node: AstNode): node is Inline {\n return INLINE_TYPES.has(node.type);\n}\n\n/** Depth-first walk over the tree; return false from `visit` to skip children. */\nexport function walk(node: AstNode, visit: (node: AstNode) => boolean | void): void {\n const go = (n: AstNode): void => {\n if (visit(n) === false) return;\n const kids = childrenOf(n);\n for (const k of kids) go(k);\n };\n go(node);\n}\n\nexport function childrenOf(node: AstNode): AstNode[] {\n switch (node.type) {\n case 'document':\n case 'blockquote':\n return node.children;\n case 'heading':\n case 'paragraph':\n case 'emphasis':\n case 'strong':\n case 'strikethrough':\n case 'tableCell':\n return node.children;\n case 'link':\n return node.children;\n case 'list':\n return node.items;\n case 'listItem':\n return node.children;\n case 'table':\n return [...node.header, ...node.rows.flat()];\n case 'footnoteDef':\n return node.children;\n case 'defList':\n return node.items;\n case 'defItem':\n return [...node.term, ...node.definitions.flat()];\n default:\n return [];\n }\n}\n","/**\n * Typewright block + inline parser — a hand-written, zero-dependency GitHub\n * Flavored Markdown (+ light MDX-flow) parser that produces the offset-exact\n * AST in `./ast`. Every node carries `from`/`to` UTF-16 source offsets; markers\n * (heading `### `, list bullets, emphasis delimiters) are exposed so a consumer\n * can hide/reveal the raw syntax.\n *\n * Design notes:\n * - Block parsing works line-by-line. Container blocks (blockquote, list) build\n * a fresh line list whose `from` is advanced past the stripped prefix; because\n * only `from` moves, `src.slice(from, to)` still equals the line's content, so\n * offsets stay exact through arbitrary nesting.\n * - Inline parsing stitches a block's content lines into one buffer with a\n * per-character source-offset map, so emphasis/code spanning a soft line break\n * still reports correct absolute offsets.\n * - The parser never throws: unterminated emphasis / code / links / fences all\n * degrade to text (or run to end-of-input) rather than failing.\n */\n\nimport { walk } from './ast';\nimport type {\n AstNode,\n Autolink,\n Block,\n Blockquote,\n CellAlign,\n CodeBlock,\n DefItem,\n DefList,\n Document,\n Emphasis,\n FootnoteDef,\n FootnoteRef,\n Heading,\n HtmlBlock,\n Image,\n Inline,\n InlineCode,\n LineBreak,\n Link,\n List,\n ListItem,\n Math,\n MathBlock,\n Paragraph,\n ParseOptions,\n Strikethrough,\n Strong,\n Table,\n TableCell,\n TaskState,\n TextNode,\n ThematicBreak,\n} from './ast';\nimport type { Change } from './text';\n\n/* ------------------------------------------------------------------ *\n * Bounds — keep user/model-controlled strings sensibly capped.\n * ------------------------------------------------------------------ */\n\nconst MAX_URL = 4096;\nconst MAX_TITLE = 1024;\nconst MAX_ALT = 4096;\nconst MAX_LANG = 256;\nconst MAX_VALUE = 1_000_000;\n/** Footnote labels are short tokens; this caps the `[^…]` lookahead to O(1). */\nconst MAX_FOOTNOTE_ID = 256;\n\nconst cap = (s: string, n: number): string => (s.length > n ? s.slice(0, n) : s);\n\n/* ------------------------------------------------------------------ *\n * Opt-in extensions (math / footnotes / definition lists)\n *\n * All three default to `false`, so `parse(src)` is byte-for-byte what it always\n * was. The resolved flags live in module scope and are set once per `parse()`\n * call; parsing is synchronous and non-reentrant across calls, and every nested\n * `parseBlocks` within a single call shares the same flags — so this reads like\n * a closure variable without threading an argument through every builder.\n * ------------------------------------------------------------------ */\n\ninterface ResolvedOptions {\n math: boolean;\n footnotes: boolean;\n defLists: boolean;\n}\n\nlet opts: ResolvedOptions = { math: false, footnotes: false, defLists: false };\n\n/* ------------------------------------------------------------------ *\n * Line model\n * ------------------------------------------------------------------ */\n\ninterface Line {\n /** Offset of the first character of (stripped) content. */\n from: number;\n /** Offset just past the last content character (before the newline). */\n to: number;\n /** `src.slice(from, to)` — the line's content, minus any container prefix. */\n text: string;\n}\n\n/** Split source into content lines (newline + trailing `\\r` excluded). */\nfunction splitLines(src: string): Line[] {\n const lines: Line[] = [];\n let from = 0;\n for (let i = 0; i <= src.length; i++) {\n if (i === src.length || src[i] === '\\n') {\n let end = i;\n if (end > from && src[end - 1] === '\\r') end--;\n lines.push({ from, to: end, text: src.slice(from, end) });\n from = i + 1;\n }\n }\n return lines;\n}\n\nconst leadingSpaces = (t: string): number => {\n let n = 0;\n while (n < t.length && t[n] === ' ') n++;\n return n;\n};\n\nconst isBlank = (line: Line): boolean => line.text.trim() === '';\n\n/* ------------------------------------------------------------------ *\n * Block detectors\n * ------------------------------------------------------------------ */\n\nconst FENCE_RE = /^( {0,3})(`{3,}|~{3,})(.*)$/;\nconst ATX_RE = /^( {0,3})(#{1,6})(?=\\s|$)/;\nconst ITEM_RE = /^( {0,3})([-+*]|\\d{1,9}[.)])( +|$)/;\nconst HTML_TAG_RE = /^<\\/?([A-Za-z][A-Za-z0-9-]*)(?:[\\s/>]|$)/;\nconst ESM_RE = /^(?:import|export)\\b/;\n\nconst isFence = (t: string): boolean => {\n const m = FENCE_RE.exec(t);\n if (!m) return false;\n // A backtick info string may not itself contain a backtick.\n return m[2]![0] !== '`' || !m[3]!.includes('`');\n};\n\nconst isAtx = (t: string): boolean => ATX_RE.test(t);\n\nconst isThematic = (t: string): boolean => {\n const trimmed = t.trim();\n if (trimmed.length < 3) return false;\n const compact = trimmed.replace(/ /g, '');\n return /^(?:-{3,}|_{3,}|\\*{3,})$/.test(compact);\n};\n\nconst isQuote = (t: string): boolean => /^ {0,3}>/.test(t);\n\ninterface ItemInfo {\n indent: number;\n marker: string;\n markerLen: number;\n spacesAfter: number;\n ordered: boolean;\n}\n\nfunction detectItem(line: Line): ItemInfo | null {\n const m = ITEM_RE.exec(line.text);\n if (!m) return null;\n const marker = m[2]!;\n return {\n indent: m[1]!.length,\n marker,\n markerLen: marker.length,\n spacesAfter: m[3] === '' ? 0 : m[3]!.length,\n ordered: /\\d/.test(marker[0]!),\n };\n}\n\nfunction htmlVariant(t: string): 'html' | 'mdxFlow' | null {\n const s = t.replace(/^ {0,3}/, '');\n if (ESM_RE.test(s)) return 'mdxFlow';\n const m = HTML_TAG_RE.exec(s);\n if (!m) return null;\n return /[A-Z]/.test(m[1]![0]!) ? 'mdxFlow' : 'html';\n}\n\nfunction isDelimRow(t: string): boolean {\n let s = t.trim();\n if (!s.includes('-')) return false;\n s = s.replace(/^\\|/, '').replace(/\\|$/, '');\n const cells = s.split('|');\n return cells.length >= 1 && cells.every((c) => /^ *:?-+:? *$/.test(c));\n}\n\nfunction isTableStartAt(lines: Line[], j: number): boolean {\n const line = lines[j];\n const next = lines[j + 1];\n if (!line || !next) return false;\n if (isBlank(line)) return false;\n return line.text.includes('|') && isDelimRow(next.text);\n}\n\n/* --- opt-in detectors (inert unless the matching flag is on) --- */\n\n/** A `$$` display-math fence on its own line (opener or closer). */\nconst MATH_FENCE_RE = /^ {0,3}\\$\\$[ \\t]*$/;\nconst isMathOpen = (t: string): boolean => opts.math && MATH_FENCE_RE.test(t);\n\n/** A `[^id]:` footnote definition line. Never collides with `ITEM_RE`. */\nconst FOOTNOTE_DEF_RE = /^( {0,3})\\[\\^([^\\]\\s]+)\\]:/;\nconst isFootnoteDef = (line: Line): boolean => opts.footnotes && FOOTNOTE_DEF_RE.test(line.text);\n\n/** A `: …` definition-list definition line (up to 3 leading spaces). */\nconst DEF_RE = /^( {0,3}):[ \\t]+/;\n\n/**\n * Does line `j` open a definition list? Conservative: line `j` must be a plain\n * term (a line that would otherwise be a paragraph — not another block) and the\n * *immediately* following line must be a `: …` definition. The term guard reuses\n * `startsBlock` (which never recurses into this check), so a heading/quote/table\n * term is rejected.\n */\nfunction isDefListStartAt(lines: Line[], j: number): boolean {\n if (!opts.defLists) return false;\n const line = lines[j];\n const next = lines[j + 1];\n if (!line || !next) return false;\n if (isBlank(line)) return false;\n if (startsBlock(lines, j)) return false; // term must not be another block\n return DEF_RE.test(next.text);\n}\n\n/** Does line `j` begin a non-paragraph block (so a paragraph must stop)? */\nfunction startsBlock(lines: Line[], j: number): boolean {\n const line = lines[j]!;\n const t = line.text;\n return (\n isFence(t) ||\n isAtx(t) ||\n isThematic(t) ||\n isQuote(t) ||\n detectItem(line) !== null ||\n htmlVariant(t) !== null ||\n isTableStartAt(lines, j) ||\n isMathOpen(t) ||\n isFootnoteDef(line)\n );\n}\n\n/** Like `startsBlock` but excludes tables (used while consuming table rows). */\nfunction startsOtherBlock(line: Line): boolean {\n const t = line.text;\n return (\n isFence(t) ||\n isAtx(t) ||\n isThematic(t) ||\n isQuote(t) ||\n detectItem(line) !== null ||\n htmlVariant(t) !== null ||\n isMathOpen(t) ||\n isFootnoteDef(line)\n );\n}\n\n/* ------------------------------------------------------------------ *\n * Block builders\n * ------------------------------------------------------------------ */\n\ninterface Built {\n node: Block;\n next: number;\n}\n\nfunction buildHeading(line: Line): Heading {\n const t = line.text;\n const m = ATX_RE.exec(t)!;\n const indent = m[1]!.length;\n const hashes = m[2]!;\n const level = hashes.length as 1 | 2 | 3 | 4 | 5 | 6;\n let ce = indent + hashes.length;\n if (t[ce] === ' ') ce++;\n const contentFrom = line.from + ce;\n\n // Trim trailing whitespace + an optional closing `###` sequence for children.\n let end = t.length;\n while (end > ce && (t[end - 1] === ' ' || t[end - 1] === '\\t')) end--;\n let e2 = end;\n while (e2 > ce && t[e2 - 1] === '#') e2--;\n if (e2 < end && (e2 === ce || t[e2 - 1] === ' ' || t[e2 - 1] === '\\t')) {\n end = e2;\n while (end > ce && (t[end - 1] === ' ' || t[end - 1] === '\\t')) end--;\n }\n\n const children = parseInlineSegs([\n { from: contentFrom, to: line.from + end, text: t.slice(ce, end) },\n ]);\n return { type: 'heading', from: line.from, to: line.to, level, contentFrom, children };\n}\n\nfunction buildFence(lines: Line[], i: number): Built {\n const open = lines[i]!;\n const m = FENCE_RE.exec(open.text)!;\n const indent = m[1]!.length;\n const fenceChar = m[2]![0]!;\n const fenceLen = m[2]!.length;\n const lang = cap(m[3]!.trim(), MAX_LANG);\n\n const inner: Line[] = [];\n let j = i + 1;\n let closeTo: number | null = null;\n while (j < lines.length) {\n const cm = /^( {0,3})(`{3,}|~{3,}) *$/.exec(lines[j]!.text);\n if (cm && cm[2]![0] === fenceChar && cm[2]!.length >= fenceLen) {\n closeTo = lines[j]!.to;\n j++;\n break;\n }\n inner.push(lines[j]!);\n j++;\n }\n\n const value = cap(\n inner.map((l) => (leadingSpaces(l.text) >= indent ? l.text.slice(indent) : l.text.trimStart())).join('\\n'),\n MAX_VALUE,\n );\n const to = closeTo ?? (inner.length ? inner[inner.length - 1]!.to : open.to);\n return { node: { type: 'codeBlock', from: open.from, to, lang, value, fenced: true }, next: j };\n}\n\n/** A `$$` … `$$` display-math block. Unterminated → runs to end (like a fence). */\nfunction buildMathBlock(lines: Line[], i: number): Built {\n const open = lines[i]!;\n const inner: Line[] = [];\n let j = i + 1;\n let closeTo: number | null = null;\n while (j < lines.length) {\n if (MATH_FENCE_RE.test(lines[j]!.text)) {\n closeTo = lines[j]!.to;\n j++;\n break;\n }\n inner.push(lines[j]!);\n j++;\n }\n const value = cap(inner.map((l) => l.text).join('\\n'), MAX_VALUE);\n const to = closeTo ?? (inner.length ? inner[inner.length - 1]!.to : open.to);\n const node: MathBlock = { type: 'mathBlock', from: open.from, to, value };\n return { node, next: j };\n}\n\nfunction buildIndentedCode(lines: Line[], i: number): Built {\n const from = lines[i]!.from;\n const inner: Line[] = [lines[i]!];\n let j = i + 1;\n let pending: Line[] = [];\n while (j < lines.length) {\n const line = lines[j]!;\n if (isBlank(line)) {\n pending.push(line);\n j++;\n continue;\n }\n if (leadingSpaces(line.text) >= 4) {\n inner.push(...pending, line);\n pending = [];\n j++;\n continue;\n }\n break;\n }\n const last = inner[inner.length - 1]!;\n const value = cap(inner.map((l) => l.text.slice(4)).join('\\n'), MAX_VALUE);\n return {\n node: { type: 'codeBlock', from, to: last.to, lang: '', value, fenced: false },\n next: j,\n };\n}\n\nfunction buildThematic(line: Line): ThematicBreak {\n return { type: 'thematicBreak', from: line.from, to: line.to };\n}\n\nfunction stripQuote(line: Line): Line {\n const m = /^( {0,3})>( ?)/.exec(line.text)!;\n const cut = m[0].length;\n return { from: line.from + cut, to: line.to, text: line.text.slice(cut) };\n}\n\nfunction buildBlockquote(lines: Line[], i: number): Built {\n const from = lines[i]!.from;\n const inner: Line[] = [];\n let j = i;\n while (j < lines.length && isQuote(lines[j]!.text)) {\n inner.push(stripQuote(lines[j]!));\n j++;\n }\n const to = lines[j - 1]!.to;\n const children = parseBlocks(inner);\n return { node: { type: 'blockquote', from, to, children }, next: j };\n}\n\nconst TASK_RE = /^\\[([ xX])\\](\\s|$)/;\n\ninterface CollectedItem {\n item: ListItem;\n next: number;\n blankBefore: boolean;\n loose: boolean;\n}\n\nfunction collectItem(lines: Line[], idx: number): CollectedItem {\n const line0 = lines[idx]!;\n const det = detectItem(line0)!;\n const contentCol = det.indent + det.markerLen + 1;\n const localStart = det.indent + det.markerLen + (det.spacesAfter > 0 ? 1 : 0);\n\n let task: TaskState = null;\n let bodyStart = localStart;\n const afterMarker = line0.text.slice(localStart);\n const tm = TASK_RE.exec(afterMarker);\n if (tm) {\n task = tm[1] === ' ' ? 'unchecked' : 'checked';\n bodyStart = localStart + tm[0].length;\n }\n const contentFrom = line0.from + bodyStart;\n\n const body: Line[] = [\n { from: contentFrom, to: line0.to, text: line0.text.slice(bodyStart) },\n ];\n let lastTo = line0.to;\n let loose = false;\n let pendingBlank = false;\n let j = idx + 1;\n\n while (j < lines.length) {\n const lj = lines[j]!;\n if (isBlank(lj)) {\n pendingBlank = true;\n j++;\n continue;\n }\n const ind = leadingSpaces(lj.text);\n if (ind >= contentCol) {\n if (pendingBlank) {\n loose = true;\n body.push({ from: lj.from, to: lj.from, text: '' });\n }\n body.push({\n from: lj.from + contentCol,\n to: lj.to,\n text: lj.text.slice(contentCol),\n });\n lastTo = lj.to;\n pendingBlank = false;\n j++;\n continue;\n }\n if (detectItem(lj)) break; // sibling / new item\n if (pendingBlank) break; // blank then unindented, non-item → item ends\n if (startsOtherBlock(lj)) break; // a new block interrupts\n // lazy paragraph continuation\n body.push({ from: lj.from, to: lj.to, text: lj.text });\n lastTo = lj.to;\n j++;\n }\n\n const children = parseBlocks(body);\n const item: ListItem = {\n type: 'listItem',\n from: line0.from,\n to: lastTo,\n task,\n contentFrom,\n children,\n };\n return { item, next: j, blankBefore: pendingBlank, loose };\n}\n\nfunction buildList(lines: Line[], start: number): Built {\n const first = detectItem(lines[start]!)!;\n const ordered = first.ordered;\n const startNum = ordered ? parseInt(first.marker, 10) || 0 : 1;\n\n const items: ListItem[] = [];\n let loose = false;\n let i = start;\n while (i < lines.length) {\n const det = detectItem(lines[i]!);\n if (!det || det.ordered !== ordered) break;\n const r = collectItem(lines, i);\n if (r.blankBefore) loose = true;\n if (r.loose) loose = true;\n items.push(r.item);\n i = r.next;\n }\n\n const node: List = {\n type: 'list',\n from: items[0]!.from,\n to: items[items.length - 1]!.to,\n ordered,\n start: startNum,\n tight: !loose,\n items,\n };\n return { node, next: i };\n}\n\nfunction parseAligns(delim: string): CellAlign[] {\n return splitCellRanges(delim).map(([a, b]) => {\n const cell = delim.slice(a, b).trim();\n const left = cell.startsWith(':');\n const right = cell.endsWith(':');\n if (left && right) return 'center';\n if (left) return 'left';\n if (right) return 'right';\n return null;\n });\n}\n\n/** Local [start,end) ranges for each pipe-delimited cell, outer pipes dropped. */\nfunction splitCellRanges(t: string): Array<[number, number]> {\n const cells: Array<[number, number]> = [];\n let s = 0;\n for (let k = 0; k < t.length; k++) {\n if (t[k] === '|' && t[k - 1] !== '\\\\') {\n cells.push([s, k]);\n s = k + 1;\n }\n }\n cells.push([s, t.length]);\n if (cells.length > 1 && t.slice(cells[0]![0], cells[0]![1]).trim() === '') cells.shift();\n if (cells.length > 1 && t.slice(cells[cells.length - 1]![0], cells[cells.length - 1]![1]).trim() === '')\n cells.pop();\n return cells;\n}\n\nfunction splitRow(line: Line): TableCell[] {\n const t = line.text;\n return splitCellRanges(t).map(([a, b]) => {\n let ca = a;\n while (ca < b && t[ca] === ' ') ca++;\n let cb = b;\n while (cb > ca && t[cb - 1] === ' ') cb--;\n const from = line.from + ca;\n const to = line.from + cb;\n const children = parseInlineSegs([{ from, to, text: t.slice(ca, cb) }]);\n return { type: 'tableCell', from, to, children };\n });\n}\n\nfunction buildTable(lines: Line[], i: number): Built {\n const header = splitRow(lines[i]!);\n const align = parseAligns(lines[i + 1]!.text);\n const rows: TableCell[][] = [];\n let j = i + 2;\n let lastTo = lines[i + 1]!.to;\n while (j < lines.length) {\n const line = lines[j]!;\n if (isBlank(line) || startsOtherBlock(line)) break;\n rows.push(splitRow(line));\n lastTo = line.to;\n j++;\n }\n return {\n node: { type: 'table', from: lines[i]!.from, to: lastTo, align, header, rows },\n next: j,\n };\n}\n\nfunction buildHtml(lines: Line[], i: number): Built {\n const variant = htmlVariant(lines[i]!.text)!;\n const from = lines[i]!.from;\n const block: Line[] = [];\n let j = i;\n while (j < lines.length && !isBlank(lines[j]!)) {\n block.push(lines[j]!);\n j++;\n }\n const to = block[block.length - 1]!.to;\n const value = cap(block.map((l) => l.text).join('\\n'), MAX_VALUE);\n return { node: { type: 'htmlBlock', from, to, value, variant }, next: j };\n}\n\n/**\n * A `[^id]: …` footnote definition. Its body — the text after `]: ` plus any\n * indented / lazily-continued following lines — is parsed as nested blocks\n * (mirroring `collectItem`'s continuation model), so a def can hold paragraphs,\n * lists, code, etc.\n */\nfunction buildFootnoteDef(lines: Line[], i: number): Built {\n const line0 = lines[i]!;\n const m = FOOTNOTE_DEF_RE.exec(line0.text)!;\n const indent = m[1]!.length;\n const id = m[2]!;\n const markerLen = m[0].length - indent; // length of `[^id]:`\n const contentCol = indent + markerLen + 1; // continuation aligns past `[^id]: `\n let bodyStart = indent + markerLen;\n if (line0.text[bodyStart] === ' ') bodyStart++;\n const contentFrom = line0.from + bodyStart;\n\n const body: Line[] = [\n { from: contentFrom, to: line0.to, text: line0.text.slice(bodyStart) },\n ];\n let lastTo = line0.to;\n let pendingBlank = false;\n let j = i + 1;\n while (j < lines.length) {\n const lj = lines[j]!;\n if (isBlank(lj)) {\n pendingBlank = true;\n j++;\n continue;\n }\n const ind = leadingSpaces(lj.text);\n if (ind >= contentCol) {\n if (pendingBlank) body.push({ from: lj.from, to: lj.from, text: '' });\n body.push({ from: lj.from + contentCol, to: lj.to, text: lj.text.slice(contentCol) });\n lastTo = lj.to;\n pendingBlank = false;\n j++;\n continue;\n }\n if (pendingBlank) break; // blank then unindented → def ends\n if (isFootnoteDef(lj)) break; // sibling definition\n if (startsOtherBlock(lj)) break; // a new block interrupts\n if (isDefListStartAt(lines, j)) break;\n // lazy paragraph continuation\n body.push({ from: lj.from, to: lj.to, text: lj.text });\n lastTo = lj.to;\n j++;\n }\n\n const children = parseBlocks(body);\n const node: FootnoteDef = { type: 'footnoteDef', from: line0.from, to: lastTo, id, children };\n return { node, next: j };\n}\n\n/** One `: …` definition (+ its indented/lazy continuation) as a block sequence. */\nfunction collectDefinition(lines: Line[], idx: number): { blocks: Block[]; to: number; next: number } {\n const line0 = lines[idx]!;\n const m = DEF_RE.exec(line0.text)!;\n const contentCol = m[0].length; // content begins just past `: `\n const body: Line[] = [\n { from: line0.from + contentCol, to: line0.to, text: line0.text.slice(contentCol) },\n ];\n let lastTo = line0.to;\n let pendingBlank = false;\n let j = idx + 1;\n while (j < lines.length) {\n const lj = lines[j]!;\n if (isBlank(lj)) {\n pendingBlank = true;\n j++;\n continue;\n }\n if (DEF_RE.test(lj.text)) break; // next definition of the same term\n const ind = leadingSpaces(lj.text);\n if (ind >= contentCol) {\n if (pendingBlank) body.push({ from: lj.from, to: lj.from, text: '' });\n body.push({ from: lj.from + contentCol, to: lj.to, text: lj.text.slice(contentCol) });\n lastTo = lj.to;\n pendingBlank = false;\n j++;\n continue;\n }\n if (pendingBlank) break;\n if (startsOtherBlock(lj)) break;\n if (isFootnoteDef(lj)) break;\n if (isDefListStartAt(lines, j)) break; // next term/definition group\n // lazy paragraph continuation\n body.push({ from: lj.from, to: lj.to, text: lj.text });\n lastTo = lj.to;\n j++;\n }\n return { blocks: parseBlocks(body), to: lastTo, next: j };\n}\n\n/** A term line plus its one-or-more `: …` definitions. */\nfunction collectDefItem(lines: Line[], idx: number): { item: DefItem; next: number } {\n const termLine = lines[idx]!;\n const term = parseInlineSegs([\n { from: termLine.from, to: termLine.to, text: termLine.text },\n ]);\n const definitions: Block[][] = [];\n let lastTo = termLine.to;\n let j = idx + 1;\n while (j < lines.length && DEF_RE.test(lines[j]!.text)) {\n const d = collectDefinition(lines, j);\n definitions.push(d.blocks);\n lastTo = d.to;\n j = d.next;\n }\n const item: DefItem = { type: 'defItem', from: termLine.from, to: lastTo, term, definitions };\n return { item, next: j };\n}\n\n/** A definition list: consecutive `term` / `: definition` groups. */\nfunction buildDefList(lines: Line[], start: number): Built {\n const items: DefItem[] = [];\n let i = start;\n while (i < lines.length && isDefListStartAt(lines, i)) {\n const r = collectDefItem(lines, i);\n items.push(r.item);\n i = r.next;\n }\n const node: DefList = {\n type: 'defList',\n from: items[0]!.from,\n to: items[items.length - 1]!.to,\n items,\n };\n return { node, next: i };\n}\n\nfunction buildParagraph(lines: Line[], i: number): Built {\n const para: Line[] = [lines[i]!];\n let j = i + 1;\n while (j < lines.length) {\n if (isBlank(lines[j]!)) break;\n if (startsBlock(lines, j)) break;\n para.push(lines[j]!);\n j++;\n }\n const from = para[0]!.from;\n const to = para[para.length - 1]!.to;\n const children = parseInlineSegs(para.map((l) => ({ from: l.from, to: l.to, text: l.text })));\n return { node: { type: 'paragraph', from, to, children }, next: j };\n}\n\n/* ------------------------------------------------------------------ *\n * Block dispatch\n * ------------------------------------------------------------------ */\n\nfunction parseBlocks(lines: Line[]): Block[] {\n const out: Block[] = [];\n let i = 0;\n while (i < lines.length) {\n const line = lines[i]!;\n if (isBlank(line)) {\n i++;\n continue;\n }\n const t = line.text;\n\n if (isFence(t)) {\n const b = buildFence(lines, i);\n out.push(b.node);\n i = b.next;\n } else if (isMathOpen(t)) {\n const b = buildMathBlock(lines, i);\n out.push(b.node);\n i = b.next;\n } else if (leadingSpaces(t) >= 4) {\n const b = buildIndentedCode(lines, i);\n out.push(b.node);\n i = b.next;\n } else if (isAtx(t)) {\n out.push(buildHeading(line));\n i++;\n } else if (isThematic(t)) {\n out.push(buildThematic(line));\n i++;\n } else if (isQuote(t)) {\n const b = buildBlockquote(lines, i);\n out.push(b.node);\n i = b.next;\n } else if (detectItem(line)) {\n const b = buildList(lines, i);\n out.push(b.node);\n i = b.next;\n } else if (isDefListStartAt(lines, i)) {\n const b = buildDefList(lines, i);\n out.push(b.node);\n i = b.next;\n } else if (isTableStartAt(lines, i)) {\n const b = buildTable(lines, i);\n out.push(b.node);\n i = b.next;\n } else if (htmlVariant(t)) {\n const b = buildHtml(lines, i);\n out.push(b.node);\n i = b.next;\n } else if (isFootnoteDef(line)) {\n const b = buildFootnoteDef(lines, i);\n out.push(b.node);\n i = b.next;\n } else {\n const b = buildParagraph(lines, i);\n out.push(b.node);\n i = b.next;\n }\n }\n return out;\n}\n\n/* ------------------------------------------------------------------ *\n * Inline parsing\n * ------------------------------------------------------------------ */\n\ninterface Seg {\n from: number;\n to: number;\n text: string;\n}\n\nconst isWs = (ch: string | undefined): boolean =>\n ch === undefined || ch === ' ' || ch === '\\n' || ch === '\\t' || ch === '\\r';\n\nconst isAlnum = (ch: string | undefined): boolean =>\n ch !== undefined && /[0-9A-Za-z]/.test(ch);\n\n/**\n * Parse the inline content of a block, given its content lines. The lines are\n * stitched into one buffer separated by soft breaks; a per-character map lets\n * every produced node report exact absolute source offsets.\n */\nfunction parseInlineSegs(segs: Seg[]): Inline[] {\n if (segs.length === 0) return [];\n let buf = '';\n const map: number[] = [];\n for (let s = 0; s < segs.length; s++) {\n const seg = segs[s]!;\n if (s > 0) {\n map.push(segs[s - 1]!.to);\n buf += '\\n';\n }\n for (let k = 0; k < seg.text.length; k++) {\n map.push(seg.from + k);\n buf += seg.text[k];\n }\n }\n map.push(segs[segs.length - 1]!.to);\n\n const abs = (k: number): number => (k < map.length ? map[k]! : segs[segs.length - 1]!.to);\n\n /* --- inline node builders --- */\n const text = (from: number, to: number, value: string): TextNode => ({\n type: 'text',\n from,\n to,\n value: cap(value, MAX_VALUE),\n });\n\n /* --- construct scanners (buffer-index based) --- */\n\n interface Hit {\n node: Inline;\n endIdx: number;\n }\n\n function tryCode(i: number, end: number): Hit | null {\n let n = 1;\n while (i + n < end && buf[i + n] === '`') n++;\n let k = i + n;\n while (k < end) {\n if (buf[k] === '`') {\n let m = 1;\n while (k + m < end && buf[k + m] === '`') m++;\n if (m === n) {\n let val = buf.slice(i + n, k);\n if (val.length > 2 && val[0] === ' ' && val[val.length - 1] === ' ' && val.trim() !== '')\n val = val.slice(1, -1);\n const node: InlineCode = {\n type: 'inlineCode',\n from: abs(i),\n to: abs(k + n),\n value: cap(val, MAX_VALUE),\n ticks: n,\n };\n return { node, endIdx: k + n };\n }\n k += m;\n continue;\n }\n k++;\n }\n return null;\n }\n\n /**\n * Inline math `$…$` (or inline-display `$$…$$`). Modeled on `tryCode`: an\n * unterminated run returns null and degrades to literal text. Flanking rules\n * (opener not followed by space, closer not preceded by space) keep bare `$`\n * signs in prose — `$5 and $10` — from being read as math. `\\$` is escaped.\n */\n function tryMath(i: number, end: number): Hit | null {\n let n = 1;\n while (i + n < end && buf[i + n] === '$' && n < 2) n++;\n const after = buf[i + n];\n if (after === undefined || after === ' ' || after === '\\t' || after === '\\n') return null;\n let k = i + n;\n while (k < end) {\n const ch = buf[k];\n if (ch === '\\\\') {\n k += 2; // escaped char (e.g. `\\$`) can't close the span\n continue;\n }\n if (ch === '\\n') return null; // inline math stays on one line\n if (ch === '$') {\n let m = 1;\n while (k + m < end && buf[k + m] === '$' && m < 2) m++;\n if (m === n && k > i + n) {\n const prev = buf[k - 1];\n if (prev !== ' ' && prev !== '\\t' && prev !== '\\n') {\n const node: Math = {\n type: 'math',\n from: abs(i),\n to: abs(k + n),\n value: cap(buf.slice(i + n, k), MAX_VALUE),\n display: n === 2,\n };\n return { node, endIdx: k + n };\n }\n }\n k += m;\n continue;\n }\n k++;\n }\n return null;\n }\n\n /**\n * A footnote reference `[^id]`. The id scan is BOUNDED (`MAX_FOOTNOTE_ID`) and\n * stops at the first `]`, whitespace, or nested bracket — so it is O(1) per\n * `[` and never reintroduces the quadratic blow-up a scan-to-end would. A miss\n * returns null and the caller falls through to `tryLink`.\n */\n function tryFootnoteRef(i: number, end: number): Hit | null {\n const idStart = i + 2; // past `[^`\n const stop = Math.min(end, idStart + MAX_FOOTNOTE_ID);\n let k = idStart;\n while (k < stop) {\n const ch = buf[k];\n if (ch === ']') break;\n if (ch === ' ' || ch === '\\t' || ch === '\\n' || ch === '[' || ch === '^') return null;\n k++;\n }\n if (k >= stop || buf[k] !== ']' || k === idStart) return null;\n const node: FootnoteRef = {\n type: 'footnoteRef',\n from: abs(i),\n to: abs(k + 1),\n id: buf.slice(idStart, k),\n };\n return { node, endIdx: k + 1 };\n }\n\n function tryAutolink(i: number, end: number): Hit | null {\n let k = i + 1;\n while (k < end && buf[k] !== '>' && buf[k] !== '<' && buf[k] !== ' ' && buf[k] !== '\\n') k++;\n if (k >= end || buf[k] !== '>') return null;\n const content = buf.slice(i + 1, k);\n const isUri = /^[a-zA-Z][a-zA-Z0-9+.-]*:[^\\s]*$/.test(content);\n const isEmail = /^[^\\s@]+@[^\\s@]+\\.[^\\s@]+$/.test(content);\n if (!isUri && !isEmail) return null;\n const node: Autolink = {\n type: 'autolink',\n from: abs(i),\n to: abs(k + 1),\n url: cap(content, MAX_URL),\n };\n return { node, endIdx: k + 1 };\n }\n\n /** Index of the `]` matching the `[` at `open`, or -1. */\n function matchLabel(open: number, end: number): number {\n // Bound the forward scan: link labels/text are short in practice, and an\n // unbounded scan from every `[` makes a run of unmatched brackets O(n^2)\n // (parse runs on every keystroke / streamed token).\n const stop = Math.min(end, open + 4096);\n let depth = 0;\n for (let k = open; k < stop; k++) {\n const ch = buf[k];\n if (ch === '\\\\') {\n k++;\n continue;\n }\n if (ch === '[') depth++;\n else if (ch === ']') {\n depth--;\n if (depth === 0) return k;\n }\n }\n return -1;\n }\n\n function tryLink(i: number, end: number, isImage: boolean): Hit | null {\n const br = i + (isImage ? 1 : 0);\n if (buf[br] !== '[') return null;\n const close = matchLabel(br, end);\n if (close < 0) return null;\n let k = close + 1;\n if (buf[k] !== '(') return null;\n k++;\n while (k < end && (buf[k] === ' ' || buf[k] === '\\n')) k++;\n\n let url = '';\n if (buf[k] === '<') {\n k++;\n const s = k;\n while (k < end && buf[k] !== '>' && buf[k] !== '\\n') k++;\n if (buf[k] !== '>') return null;\n url = buf.slice(s, k);\n k++;\n } else {\n const s = k;\n let depth = 0;\n while (k < end) {\n const ch = buf[k];\n if (ch === ' ' || ch === '\\n') break;\n if (ch === '(') depth++;\n else if (ch === ')') {\n if (depth === 0) break;\n depth--;\n }\n k++;\n }\n url = buf.slice(s, k);\n }\n\n let title: string | undefined;\n while (k < end && (buf[k] === ' ' || buf[k] === '\\n')) k++;\n const q = buf[k];\n if (q === '\"' || q === \"'\" || q === '(') {\n const closeCh = q === '(' ? ')' : q;\n k++;\n const s = k;\n while (k < end && buf[k] !== closeCh) k++;\n if (buf[k] !== closeCh) return null;\n title = buf.slice(s, k);\n k++;\n while (k < end && (buf[k] === ' ' || buf[k] === '\\n')) k++;\n }\n if (buf[k] !== ')') return null;\n const endIdx = k + 1;\n const from = abs(i);\n const to = abs(endIdx);\n\n if (isImage) {\n const node: Image = {\n type: 'image',\n from,\n to,\n url: cap(url, MAX_URL),\n alt: cap(buf.slice(br + 1, close), MAX_ALT),\n };\n if (title !== undefined) node.title = cap(title, MAX_TITLE);\n return { node, endIdx };\n }\n const node: Link = {\n type: 'link',\n from,\n to,\n url: cap(url, MAX_URL),\n children: parseInlineRange(br + 1, close),\n };\n if (title !== undefined) node.title = cap(title, MAX_TITLE);\n return { node, endIdx };\n }\n\n function tryEmph(i: number, end: number): Hit | null {\n const c = buf[i]!;\n let n = 1;\n while (i + n < end && buf[i + n] === c) n++;\n const isStrike = c === '~';\n if (isStrike && n < 2) return null;\n const strength = isStrike ? 2 : n >= 2 ? 2 : 1;\n if (i + strength > end) return null;\n\n const after = buf[i + strength];\n const before = buf[i - 1];\n if (isWs(after)) return null; // opener must be left-flanking\n if (c === '_' && isAlnum(before)) return null; // no intraword `_`\n\n let k = i + strength;\n while (k < end) {\n if (buf[k] === c) {\n let m = 1;\n while (k + m < end && buf[k + m] === c) m++;\n if (m >= strength) {\n const prev = buf[k - 1];\n const aft = buf[k + strength];\n if (!isWs(prev) && (c !== '_' || !isAlnum(aft))) {\n const children = parseInlineRange(i + strength, k);\n const from = abs(i);\n const to = abs(k + strength);\n let node: Inline;\n if (isStrike) {\n node = { type: 'strikethrough', from, to, children } satisfies Strikethrough;\n } else if (strength === 2) {\n node = { type: 'strong', from, to, marker: c.repeat(2), children } satisfies Strong;\n } else {\n node = { type: 'emphasis', from, to, marker: c, children } satisfies Emphasis;\n }\n return { node, endIdx: k + strength };\n }\n }\n k += m;\n continue;\n }\n k++;\n }\n return null;\n }\n\n function parseInlineRange(start: number, end: number): Inline[] {\n const out: Inline[] = [];\n let i = start;\n let textStart = start;\n const flush = (upto: number): void => {\n if (upto > textStart) out.push(text(abs(textStart), abs(upto), buf.slice(textStart, upto)));\n };\n const commit = (hit: Hit): void => {\n flush(i);\n out.push(hit.node);\n i = hit.endIdx;\n textStart = i;\n };\n\n while (i < end) {\n const c = buf[i];\n if (c === '\\\\') {\n if (buf[i + 1] === '\\n') {\n flush(i);\n out.push({ type: 'break', from: abs(i), to: abs(i + 2), hard: true } satisfies LineBreak);\n i += 2;\n textStart = i;\n continue;\n }\n i += 2; // escaped char stays part of the text run\n continue;\n }\n if (c === '\\n') {\n let sp = 0;\n let p = i - 1;\n while (p >= textStart && buf[p] === ' ') {\n sp++;\n p--;\n }\n const hard = sp >= 2;\n flush(hard ? i - sp : i);\n out.push({\n type: 'break',\n from: abs(hard ? i - sp : i),\n to: abs(i + 1),\n hard,\n } satisfies LineBreak);\n i++;\n textStart = i;\n continue;\n }\n if (c === '`') {\n const r = tryCode(i, end);\n if (r) {\n commit(r);\n continue;\n }\n i++;\n continue;\n }\n if (c === '$' && opts.math) {\n const r = tryMath(i, end);\n if (r) {\n commit(r);\n continue;\n }\n i++;\n continue;\n }\n if (c === '<') {\n const r = tryAutolink(i, end);\n if (r) {\n commit(r);\n continue;\n }\n i++;\n continue;\n }\n if (c === '!' && buf[i + 1] === '[') {\n const r = tryLink(i, end, true);\n if (r) {\n commit(r);\n continue;\n }\n i++;\n continue;\n }\n if (c === '[') {\n if (opts.footnotes && buf[i + 1] === '^') {\n const rf = tryFootnoteRef(i, end);\n if (rf) {\n commit(rf);\n continue;\n }\n }\n const r = tryLink(i, end, false);\n if (r) {\n commit(r);\n continue;\n }\n i++;\n continue;\n }\n if (c === '*' || c === '_' || c === '~') {\n const r = tryEmph(i, end);\n if (r) {\n commit(r);\n continue;\n }\n i++;\n continue;\n }\n i++;\n }\n flush(end);\n return out;\n }\n\n return parseInlineRange(0, buf.length);\n}\n\n/* ------------------------------------------------------------------ *\n * Entry point\n * ------------------------------------------------------------------ */\n\n/**\n * Parse Markdown/MDX source into an offset-exact {@link Document}.\n *\n * `options` gates the opt-in extensions (math, footnotes, definition lists);\n * every flag defaults to `false`, so `parse(src)` is unchanged from before.\n */\nexport function parse(src: string, options?: ParseOptions): Document {\n opts = {\n math: options?.math === true,\n footnotes: options?.footnotes === true,\n defLists: options?.defLists === true,\n };\n const lines = splitLines(src);\n const children = parseBlocks(lines);\n return { type: 'document', from: 0, to: src.length, children };\n}\n\n/* ------------------------------------------------------------------ *\n * Incremental reparse\n *\n * `parseIncremental` returns a document DEEP-EQUAL to `parse(nextSrc, options)`\n * but computed by reusing the leading top-level blocks of a previous parse that\n * the edit provably cannot have touched, then reparsing from the first safe block\n * boundary at/before the edit through to the end of `nextSrc`.\n *\n * Correctness rests on one invariant: every reused block's parse depends only on\n * the source PREFIX before the reparse cut, and that prefix is byte-identical in\n * `prevSrc` and `nextSrc` (the edit is entirely at/after the cut). Whenever a safe\n * cut cannot be cheaply proven, we fall back to a full `parse` — a correct result\n * is never sacrificed for a fast one.\n *\n * When possible the reparse is ALSO bounded on the RIGHT: rather than reparsing\n * from the cut to end-of-document, we reparse only the dirty block(s) plus a safe\n * look-around, then reuse the unchanged SUFFIX blocks from `prev`, re-offset by the\n * edit's length delta. That suffix reuse is only taken when a clean, self-terminated\n * dirty-region boundary can be PROVEN by a small bounded reparse that includes the\n * join line (an open fence / list / etc. that would bleed past the join makes the\n * proof fail, and we fall back to the reparse-to-EOF path — still correct, just less\n * tight). A small edit near the TOP of a large document therefore reparses a bounded\n * region instead of the whole tail. The one-way property test in\n * `parser.incremental.test.ts` is the oracle that enforces the deep-equality.\n * ------------------------------------------------------------------ */\n\n/** Instrumentation about what an incremental reparse reused vs rebuilt. */\nexport interface IncrementalStats {\n /** True when the fast path bailed and a full {@link parse} produced the result. */\n fellBack: boolean;\n /** Count of leading top-level blocks reused verbatim from the previous document. */\n reusedBlocks: number;\n /** Line index in `nextSrc` from which blocks were reparsed (0 ⇒ whole document). */\n reparsedFromLine: number;\n /**\n * Line index in `nextSrc` at which the reparsed region ENDS (exclusive). Equals\n * {@link totalLines} when the reparse ran to end-of-document (no suffix reuse); a\n * value `< totalLines` means the tail was bounded and trailing blocks were reused.\n */\n reparsedToLine: number;\n /** Count of trailing top-level blocks reused from `prev` (re-offset by the edit delta). */\n reusedSuffixBlocks: number;\n /** Total number of content lines in `nextSrc`. */\n totalLines: number;\n}\n\n/** The document plus {@link IncrementalStats} from {@link parseIncrementalWithStats}. */\nexport interface IncrementalResult {\n doc: Document;\n stats: IncrementalStats;\n}\n\ntype HeadSafety = 'always' | 'needs-blank' | 'never';\n\n/**\n * How safe it is to keep `block` as the LAST block of the reused prefix — i.e.\n * whether, once the source AFTER it changes, `block`'s parse could grow past the\n * cut and swallow the new content.\n *\n * - `always` self-delimiting or single-line: its extent never depends on\n * what follows (heading, thematic break, or a *closed* fenced /\n * `$$` block — an unclosed one runs to EOF and so is never an\n * interior block).\n * - `needs-blank` terminates only at a blank line: safe **iff** a blank line\n * sits between it and the cut. That blank, being before the edit,\n * is preserved in `nextSrc`, so no edit can un-terminate it.\n * - `never` lazily continues across blank lines by indentation, so a later\n * edit could indent a following line into it — indented code,\n * lists, footnote definitions and definition lists.\n */\nfunction headSafety(block: Block): HeadSafety {\n switch (block.type) {\n case 'heading':\n case 'thematicBreak':\n case 'mathBlock':\n return 'always';\n case 'codeBlock':\n return block.fenced ? 'always' : 'never';\n case 'paragraph':\n case 'table':\n case 'htmlBlock':\n case 'blockquote':\n return 'needs-blank';\n default:\n // list, footnoteDef, defList — loose/lazy continuation across blanks.\n return 'never';\n }\n}\n\n/** Is the source line ending just before `lineStart` (itself a line start) blank? */\nfunction prevLineIsBlank(src: string, lineStart: number): boolean {\n if (lineStart <= 0) return false;\n // `lineStart` is a line start ⇒ `src[lineStart - 1]` is the '\\n' ending the\n // previous line. Walk back to that line's own start and test it for blankness.\n const end = lineStart - 1;\n let start = end - 1;\n while (start >= 0 && src[start] !== '\\n') start--;\n start += 1;\n return src.slice(start, end).trim() === '';\n}\n\n/**\n * Like {@link prevLineIsBlank}, but ALSO requires the blank line to lie entirely at\n * or after `minStart` — i.e. wholly inside the source region the edit did not touch.\n * Used to prove a suffix-join boundary sits behind an unchanged blank separator, so\n * no construct can lazily bridge the reparsed dirty region into the reused suffix.\n */\nfunction blankLineFullyAfter(src: string, lineStart: number, minStart: number): boolean {\n if (lineStart <= 0) return false;\n const end = lineStart - 1; // the '\\n' that terminated the previous line\n let start = end - 1;\n while (start >= 0 && src[start] !== '\\n') start--;\n start += 1;\n if (start < minStart) return false; // blank line straddles / precedes the edit\n return src.slice(start, end).trim() === '';\n}\n\n/**\n * Deep-clone a block, shifting every `from`/`to` (and `contentFrom`, where present)\n * by `delta`. Used to re-offset an unchanged SUFFIX block reused from `prev` into\n * `nextSrc` coordinates without reparsing it. Walks the WHOLE subtree (nested\n * blocks, inline children, table cells, list/def items) via the shared {@link walk},\n * so no offset-bearing node is missed. `prev` is never mutated.\n */\nfunction shiftBlock(block: Block, delta: number): Block {\n const clone = structuredClone(block) as Block;\n walk(clone as AstNode, (n) => {\n const p = n as { from: number; to: number; contentFrom?: number };\n p.from += delta;\n p.to += delta;\n if (typeof p.contentFrom === 'number') p.contentFrom += delta;\n });\n return clone;\n}\n\n/** Index of the line in `lines` that begins exactly at offset `off`, or -1. */\nfunction lineStartingAt(lines: Line[], off: number): number {\n let lo = 0;\n let hi = lines.length - 1;\n while (lo <= hi) {\n const mid = (lo + hi) >> 1;\n const f = lines[mid]!.from;\n if (f === off) return mid;\n if (f < off) lo = mid + 1;\n else hi = mid - 1;\n }\n return -1;\n}\n\n/** Largest index `k` with `blocks[k].from <= off` (blocks are offset-ordered), or -1. */\nfunction lastBlockAtOrBefore(blocks: Block[], off: number): number {\n let lo = 0;\n let hi = blocks.length - 1;\n let ans = -1;\n while (lo <= hi) {\n const mid = (lo + hi) >> 1;\n if (blocks[mid]!.from <= off) {\n ans = mid;\n lo = mid + 1;\n } else {\n hi = mid - 1;\n }\n }\n return ans;\n}\n\n/** A proven bounded reparse: the freshly parsed dirty blocks + the reused, re-offset suffix. */\ninterface SuffixReuse {\n /** Freshly parsed dirty blocks, already carrying absolute `nextSrc` offsets. */\n dirty: Block[];\n /** Trailing blocks reused from `prev`, re-offset by the edit delta. */\n shifted: Block[];\n /** Line index in `nextSrc` at which the reparsed dirty region ends (exclusive). */\n endLine: number;\n /** Count of reused suffix blocks. */\n count: number;\n}\n\n/** Cap on how many join candidates we probe before giving up (bounds worst-case cost). */\nconst MAX_JOIN_ATTEMPTS = 4;\n\n/**\n * Try to bound the reparse on the RIGHT so a small edit near the top of a large doc\n * does not reparse the whole tail. Given the prefix cut (`cLine`/`k` already chosen),\n * find a prev block boundary AFTER the change whose reuse can be PROVEN sound, reparse\n * only `[cLine, joinLine)`, and reuse the trailing prev blocks re-offset by `delta`.\n *\n * Correctness rests on three facts:\n * 1. Suffix content is byte-identical (shifted by `delta`) — guaranteed by only\n * considering join offsets `>= to` (everything at/after the edit is unchanged).\n * 2. `parseBlocks` is strictly left-to-right, so the reused suffix `blocks[j..]`\n * equals `parseBlocks(nextLines.slice(joinLine))` shifted — *provided* a real\n * block boundary exists at the join in the full parse of `nextSrc`.\n * 3. That boundary is PROVEN by a bounded reparse that includes the join line: if\n * a block starts exactly at the join offset, no open construct (fence, list,\n * indented code, …) from the dirty region bled across it. If the proof fails we\n * return `null` and the caller falls back to reparse-to-EOF (still correct).\n * `opts` must already be set for `parseBlocks`.\n */\nfunction tryReuseSuffix(\n blocks: Block[],\n prevSrc: string,\n to: number,\n delta: number,\n nextLines: Line[],\n cLine: number,\n): SuffixReuse | null {\n // Last prev block starting at/before the change end — the dirty region covers it;\n // the first reuse candidate is the block after it.\n const dEnd = lastBlockAtOrBefore(blocks, to);\n let attempts = 0;\n for (let j = dEnd + 1; j < blocks.length; j++) {\n const joinOff = blocks[j]!.from;\n if (joinOff < to) continue; // suffix must be entirely in the unchanged region\n // A blank line wholly inside the unchanged region must precede the join, so no\n // lazily-continuing construct can bridge the dirty region into the suffix.\n if (!blankLineFullyAfter(prevSrc, joinOff, to)) continue;\n const nextJoinOff = joinOff + delta;\n const joinLine = lineStartingAt(nextLines, nextJoinOff);\n if (joinLine <= cLine) continue; // must reparse a non-empty region below the cut\n\n if (++attempts > MAX_JOIN_ATTEMPTS) break; // bound the probing cost, then fall back\n\n // Bounded, boundary-proving reparse: include the join line. A block starting\n // exactly at `nextJoinOff` proves the dirty region self-terminates there.\n const guard = parseBlocks(nextLines.slice(cLine, joinLine + 1));\n const dirty: Block[] = [];\n let proven = false;\n for (const b of guard) {\n if (b.from === nextJoinOff) {\n proven = true;\n break;\n }\n if (b.from > nextJoinOff) break; // overshot ⇒ no clean boundary here\n dirty.push(b);\n }\n if (!proven) continue; // an open construct crossed the join — try the next candidate\n\n const rest = blocks.slice(j);\n // Always clone the reused suffix — even at `delta === 0`. Returning `prev`'s\n // own block objects would alias subtrees between the old and new documents;\n // `shiftBlock(b, 0)` is a pure structuredClone (no-op offset shift), so the\n // returned tree never shares node identity with `prev`. (Insertions already\n // pay this clone; a same-length edit is no different.)\n const shifted = rest.map((b) => shiftBlock(b, delta));\n return { dirty, shifted, endLine: joinLine, count: rest.length };\n }\n return null;\n}\n\nfunction runIncremental(\n prev: Document,\n prevSrc: string,\n change: Change,\n nextSrc: string,\n options: ParseOptions | undefined,\n): IncrementalResult {\n const nextLines = splitLines(nextSrc);\n const total = nextLines.length;\n const full = (): IncrementalResult => ({\n doc: parse(nextSrc, options),\n stats: {\n fellBack: true,\n reusedBlocks: 0,\n reparsedFromLine: 0,\n reparsedToLine: total,\n reusedSuffixBlocks: 0,\n totalLines: total,\n },\n });\n\n // Normalize + validate the change against prevSrc. A malformed or inconsistent\n // change is never trusted — a correct full parse is always the safe answer.\n const from = Math.max(0, Math.min(change.from, change.to));\n const to = Math.min(prevSrc.length, Math.max(change.from, change.to));\n if (to < from) return full();\n if (nextSrc.length !== prevSrc.length + change.insert.length - (to - from)) return full();\n // Every candidate cut satisfies `cut <= from`, so a single check that the\n // prefix `[0, from)` is byte-identical proves every reused prefix identical.\n if (prevSrc.slice(0, from) !== nextSrc.slice(0, from)) return full();\n\n // Offset shift applied to any source position at/after the edit end `to`.\n const delta = change.insert.length - (to - from);\n\n const blocks = prev.children;\n const hi = Math.min(blocks.length - 1, lastBlockAtOrBefore(blocks, from));\n for (let k = hi; k >= 1; k--) {\n const cut = blocks[k]!.from; // reuse blocks[0..k-1]; reparse from `cut`\n if (cut > from) continue; // head must lie entirely before the edit\n const safety = headSafety(blocks[k - 1]!);\n if (safety === 'never') continue;\n if (safety === 'needs-blank' && !prevLineIsBlank(prevSrc, cut)) continue;\n const c = lineStartingAt(nextLines, cut);\n if (c < 0) continue; // `cut` is not a line start in nextSrc (should not happen)\n\n // The reparse runs `parseBlocks`, which reads the module-scoped `opts`; set\n // them from `options` so the reparsed region matches a full parse exactly.\n opts = {\n math: options?.math === true,\n footnotes: options?.footnotes === true,\n defLists: options?.defLists === true,\n };\n\n // Try to bound the reparse on the right and reuse the unchanged suffix; this\n // is what makes a top-of-doc edit cheap. If no clean boundary can be proven,\n // fall back to reparsing the whole tail (still correct, just not as tight).\n const suffix = tryReuseSuffix(blocks, prevSrc, to, delta, nextLines, c);\n if (suffix) {\n const children = blocks.slice(0, k).concat(suffix.dirty, suffix.shifted);\n return {\n doc: { type: 'document', from: 0, to: nextSrc.length, children },\n stats: {\n fellBack: false,\n reusedBlocks: k,\n reparsedFromLine: c,\n reparsedToLine: suffix.endLine,\n reusedSuffixBlocks: suffix.count,\n totalLines: total,\n },\n };\n }\n\n const tail = parseBlocks(nextLines.slice(c));\n const children = blocks.slice(0, k).concat(tail);\n return {\n doc: { type: 'document', from: 0, to: nextSrc.length, children },\n stats: {\n fellBack: false,\n reusedBlocks: k,\n reparsedFromLine: c,\n reparsedToLine: total,\n reusedSuffixBlocks: 0,\n totalLines: total,\n },\n };\n }\n return full();\n}\n\n/**\n * Incrementally reparse `prev` (the parse of `prevSrc`) after a single\n * {@link Change} produced `nextSrc`. The result is deep-equal to\n * `parse(nextSrc, options)`; pass the SAME `options` that produced `prev`.\n */\nexport function parseIncremental(\n prev: Document,\n prevSrc: string,\n change: Change,\n nextSrc: string,\n options?: ParseOptions,\n): Document {\n return runIncremental(prev, prevSrc, change, nextSrc, options).doc;\n}\n\n/** {@link parseIncremental} plus {@link IncrementalStats} about what was reused. */\nexport function parseIncrementalWithStats(\n prev: Document,\n prevSrc: string,\n change: Change,\n nextSrc: string,\n options?: ParseOptions,\n): IncrementalResult {\n return runIncremental(prev, prevSrc, change, nextSrc, options);\n}\n","/**\n * AST → sanitized HTML renderer.\n *\n * This is the `read`/`preview` output path (SPEC.md §4): it walks the offset-exact\n * AST produced by the parser and emits HTML that is safe to inject into a host\n * page. Safety is structural, not incidental:\n *\n * - every text / attribute value is HTML-escaped (`&`, `<`, `>`, `\"`);\n * - every URL passes {@link safeUrl}, so `javascript:` / `data:` / other active\n * schemes collapse to `#`;\n * - raw HTML / MDX blocks are emitted ESCAPED inside `<pre>` — this renderer\n * never re-emits untrusted markup, so it can be used on model output;\n * - footnote / definition ids are slugged to a URL-safe charset *and* escaped\n * before they reach an `id`/`href` attribute.\n *\n * The renderer never throws: malformed / partial nodes degrade to escaped text.\n *\n * {@link RenderOptions} lets a host plug in escaped-HTML producers for the two\n * constructs the core cannot render on its own — syntax highlighting and a math\n * engine. Both are trusted to return already-escaped HTML; without them the\n * renderer falls back to the safe escaped-source form. Passing no options\n * reproduces the exact default behaviour.\n */\n\nimport { walk } from './ast';\nimport type {\n Block,\n Document,\n FootnoteDef,\n Inline,\n ListItem,\n Table,\n TableCell,\n} from './ast';\n\n/** Hard cap on a URL length we are willing to place in an attribute. */\nconst MAX_URL = 8192;\n/** Schemes we consider inert enough to keep. */\nconst SAFE_SCHEMES = /^(https?:|mailto:)/;\n\n/* ------------------------------------------------------------------ *\n * Host-supplied render hooks\n * ------------------------------------------------------------------ */\n\n/**\n * Optional, host-supplied output producers for constructs the core cannot\n * render itself. Both hooks MUST return already-escaped, safe HTML — the\n * renderer trusts their output and does not re-escape it. Omitting a hook (or\n * the whole object) falls back to the safe escaped-source form.\n */\nexport interface RenderOptions {\n /**\n * Syntax highlighter for fenced code. Receives the fence info string and the\n * raw code; returns escaped HTML (e.g. `<span class=\"tw-tok-…\">` runs). The\n * host is responsible for escaping — see {@link highlightToHtml}.\n */\n highlight?: (lang: string, code: string) => string;\n /**\n * Math engine. Receives the TeX source and whether it is display math;\n * returns escaped/safe HTML. Without it, math renders as escaped source.\n */\n math?: (src: string, display: boolean) => string;\n}\n\n/**\n * Per-render footnote numbering context. Footnote references are numbered in\n * first-seen order across a single render pass (keyed by the slugged id, so\n * repeated references to the same note share a number). Held in a small object\n * threaded through the walk rather than in module state, so rendering stays\n * re-entrant.\n */\ninterface FnCtx {\n /** Slugged footnote id → its 1-based display number, in first-seen order. */\n nums: Map<string, number>;\n}\n\nfunction newFnCtx(): FnCtx {\n return { nums: new Map() };\n}\n\n/** The display number for a footnote id, allocating one on first sight. */\nfunction fnNumber(ctx: FnCtx, slug: string): number {\n const existing = ctx.nums.get(slug);\n if (existing !== undefined) return existing;\n const n = ctx.nums.size + 1;\n ctx.nums.set(slug, n);\n return n;\n}\n\n/* ------------------------------------------------------------------ *\n * Escaping + URL safety\n * ------------------------------------------------------------------ */\n\n/** Escape the five characters that matter in HTML text / double-quoted attrs. */\nfunction escapeHtml(value: string): string {\n let out = '';\n for (let i = 0; i < value.length; i++) {\n const ch = value.charCodeAt(i);\n switch (ch) {\n case 38 /* & */:\n out += '&';\n break;\n case 60 /* < */:\n out += '<';\n break;\n case 62 /* > */:\n out += '>';\n break;\n case 34 /* \" */:\n out += '"';\n break;\n default:\n out += value[i];\n }\n }\n return out;\n}\n\n/**\n * Reduce a footnote label to a slug that is safe both as an `id` attribute and\n * as a `#fragment` in an `href`: keep ASCII letters/digits/`_`/`-`, collapse any\n * other run to a single `-`. An empty result falls back to `_` so the id is\n * never blank. The same slug is applied to refs and defs, so their ids match.\n */\nfunction slugFootnoteId(id: string): string {\n const slug = id.replace(/[^A-Za-z0-9_-]+/g, '-');\n return slug === '' ? '_' : slug;\n}\n\n/**\n * Return `url` when it is safe to place in an `href`/`src`, otherwise `'#'`.\n *\n * Safe = an http/https/mailto absolute URL, OR anything without an explicit\n * scheme (relative paths, `?query`, `#anchor`, protocol-relative `//host`).\n * Any other scheme (`javascript:`, `data:`, `vbscript:`, `file:`, …) is denied.\n *\n * Scheme detection is done against a copy with whitespace + control characters\n * stripped, so obfuscations like `java\\tscript:` or a leading newline can't\n * smuggle an active scheme past the check.\n */\nexport function safeUrl(url: string): string {\n if (typeof url !== 'string' || url.length === 0) return '#';\n const trimmed = url.trim().slice(0, MAX_URL);\n if (trimmed === '') return '#';\n\n // Fold away whitespace + C0/DEL controls for the scheme test ONLY.\n const probe = trimmed.replace(/[\\u0000-\\u0020\\u007f]/g, '').toLowerCase();\n if (probe === '') return '#';\n\n // An allowed absolute scheme is fine.\n if (SAFE_SCHEMES.test(probe)) return trimmed;\n\n // Any OTHER explicit scheme (letter run followed by a colon) is denied.\n // Relative / anchor / protocol-relative URLs never match (they start with\n // `#`, `/`, `.`, `?`, or a bare path segment with no leading scheme colon).\n if (/^[a-z][a-z0-9+.-]*:/.test(probe)) return '#';\n\n return trimmed;\n}\n\n/** Convenience: an escaped, safety-checked URL ready for an attribute. */\nfunction attrUrl(url: string): string {\n return escapeHtml(safeUrl(url));\n}\n\n/* ------------------------------------------------------------------ *\n * Inline\n * ------------------------------------------------------------------ */\n\n/** Render a run of inline nodes to sanitized HTML. */\nexport function renderInline(nodes: Inline[], options?: RenderOptions): string {\n return inlineRun(nodes, options, newFnCtx());\n}\n\nfunction inlineRun(\n nodes: Inline[],\n options: RenderOptions | undefined,\n ctx: FnCtx,\n): string {\n let out = '';\n for (const node of nodes) out += renderInlineNode(node, options, ctx);\n return out;\n}\n\nfunction renderInlineNode(\n node: Inline,\n options: RenderOptions | undefined,\n ctx: FnCtx,\n): string {\n switch (node.type) {\n case 'text':\n return escapeHtml(node.value);\n case 'strong':\n return `<strong>${inlineRun(node.children, options, ctx)}</strong>`;\n case 'emphasis':\n return `<em>${inlineRun(node.children, options, ctx)}</em>`;\n case 'strikethrough':\n return `<del>${inlineRun(node.children, options, ctx)}</del>`;\n case 'inlineCode':\n return `<code>${escapeHtml(node.value)}</code>`;\n case 'link': {\n const title = node.title ? ` title=\"${escapeHtml(node.title)}\"` : '';\n return `<a href=\"${attrUrl(node.url)}\"${title}>${inlineRun(node.children, options, ctx)}</a>`;\n }\n case 'image': {\n const title = node.title ? ` title=\"${escapeHtml(node.title)}\"` : '';\n return `<img src=\"${attrUrl(node.url)}\" alt=\"${escapeHtml(node.alt)}\"${title}>`;\n }\n case 'autolink':\n return `<a href=\"${attrUrl(node.url)}\">${escapeHtml(node.url)}</a>`;\n case 'break':\n return node.hard ? '<br>\\n' : '\\n';\n case 'math':\n // Host math engine (trusted, returns escaped HTML) or safe escaped source.\n return options?.math\n ? options.math(node.value, node.display)\n : `<span class=\"tw-math-src\">${escapeHtml(node.value)}</span>`;\n case 'footnoteRef': {\n // GitHub-style superscript back-reference. The def with the matching id\n // is collected + rendered once at the end of the document (see\n // renderToHtml). Number is first-seen order; id links the two ends.\n const slug = slugFootnoteId(node.id);\n const n = fnNumber(ctx, slug);\n const safe = escapeHtml(slug);\n return `<sup class=\"tw-fnref\" id=\"fnref-${safe}\"><a href=\"#fn-${safe}\">[${n}]</a></sup>`;\n }\n default: {\n // Exhaustiveness guard — a new inline type must be handled above.\n const _never: never = node;\n return _never as never;\n }\n }\n}\n\n/* ------------------------------------------------------------------ *\n * Blocks\n * ------------------------------------------------------------------ */\n\n/** Render a single block node to sanitized HTML. */\nexport function renderNode(node: Block, options?: RenderOptions): string {\n return renderBlockNode(node, options, newFnCtx());\n}\n\nfunction renderBlockNode(\n node: Block,\n options: RenderOptions | undefined,\n ctx: FnCtx,\n): string {\n switch (node.type) {\n case 'heading': {\n const l = node.level;\n return `<h${l}>${inlineRun(node.children, options, ctx)}</h${l}>`;\n }\n case 'paragraph':\n return `<p>${inlineRun(node.children, options, ctx)}</p>`;\n case 'blockquote':\n return `<blockquote>${renderBlocks(node.children, options, ctx)}</blockquote>`;\n case 'list':\n return renderList(node.ordered, node.start, node.tight, node.items, options, ctx);\n case 'codeBlock': {\n const cls = node.lang\n ? ` class=\"language-${escapeHtml(node.lang)}\"`\n : '';\n // The highlighter is trusted to return escaped HTML; the default path\n // escapes here so raw code is never emitted live either way.\n const body = options?.highlight\n ? options.highlight(node.lang, node.value)\n : escapeHtml(node.value);\n return `<pre><code${cls}>${body}</code></pre>`;\n }\n case 'thematicBreak':\n return '<hr>';\n case 'table':\n return renderTable(node, options, ctx);\n case 'htmlBlock':\n // The safety boundary: raw HTML / MDX is emitted ESCAPED, never live.\n return `<pre>${escapeHtml(node.value)}</pre>`;\n case 'mathBlock':\n // A math block is always display math; host engine or escaped source.\n return options?.math\n ? options.math(node.value, true)\n : `<div class=\"tw-math-src\">${escapeHtml(node.value)}</div>`;\n case 'footnoteDef':\n // Canonical placement is the collected <section> that renderToHtml\n // appends. A standalone renderNode(footnoteDef) still renders its body\n // for completeness (renderBlocks skips defs only in document flow).\n return `<div class=\"tw-footnote-def\">${renderBlocks(node.children, options, ctx)}</div>`;\n case 'defList': {\n let out = '';\n for (const item of node.items) {\n out += `<dt>${inlineRun(item.term, options, ctx)}</dt>`;\n for (const def of item.definitions) {\n out += `<dd>${renderBlocks(def, options, ctx)}</dd>`;\n }\n }\n return `<dl>${out}</dl>`;\n }\n default: {\n const _never: never = node;\n return _never as never;\n }\n }\n}\n\n/**\n * Render a sequence of blocks in document flow. Footnote definitions are\n * skipped here: they are collected by {@link renderToHtml} and emitted once as\n * a trailing `<section>`, never inline where they were authored.\n */\nfunction renderBlocks(\n blocks: Block[],\n options: RenderOptions | undefined,\n ctx: FnCtx,\n): string {\n let out = '';\n for (const b of blocks) {\n if (b.type === 'footnoteDef') continue;\n out += renderBlockNode(b, options, ctx);\n }\n return out;\n}\n\nfunction renderList(\n ordered: boolean,\n start: number,\n tight: boolean,\n items: ListItem[],\n options: RenderOptions | undefined,\n ctx: FnCtx,\n): string {\n const tag = ordered ? 'ol' : 'ul';\n const startAttr =\n ordered && Number.isFinite(start) && start !== 1\n ? ` start=\"${escapeHtml(String(Math.trunc(start)))}\"`\n : '';\n let body = '';\n for (const item of items) body += renderListItem(item, tight, options, ctx);\n return `<${tag}${startAttr}>${body}</${tag}>`;\n}\n\nfunction renderListItem(\n item: ListItem,\n tight: boolean,\n options: RenderOptions | undefined,\n ctx: FnCtx,\n): string {\n let checkbox = '';\n if (item.task !== null) {\n const checked = item.task === 'checked' ? ' checked' : '';\n checkbox = `<input type=\"checkbox\" disabled${checked}> `;\n }\n return `<li>${checkbox}${renderItemChildren(item.children, tight, options, ctx)}</li>`;\n}\n\n/**\n * In a tight list a lone paragraph child renders WITHOUT its `<p>` wrapper\n * (GFM tight-list behaviour), so a task item reads `<li><input…> text</li>`.\n * Loose lists keep full block structure.\n */\nfunction renderItemChildren(\n children: Block[],\n tight: boolean,\n options: RenderOptions | undefined,\n ctx: FnCtx,\n): string {\n if (tight) {\n let out = '';\n for (const child of children) {\n out +=\n child.type === 'paragraph'\n ? inlineRun(child.children, options, ctx)\n : renderBlockNode(child, options, ctx);\n }\n return out;\n }\n return renderBlocks(children, options, ctx);\n}\n\nfunction renderTable(\n node: Table,\n options: RenderOptions | undefined,\n ctx: FnCtx,\n): string {\n const align = node.align;\n const cellStyle = (col: number): string => {\n const a = align[col];\n return a ? ` style=\"text-align:${a}\"` : '';\n };\n\n const headCells = renderRow(node.header, 'th', cellStyle, options, ctx);\n const head = `<thead><tr>${headCells}</tr></thead>`;\n\n let bodyRows = '';\n for (const row of node.rows) {\n bodyRows += `<tr>${renderRow(row, 'td', cellStyle, options, ctx)}</tr>`;\n }\n const body = `<tbody>${bodyRows}</tbody>`;\n\n return `<table>${head}${body}</table>`;\n}\n\nfunction renderRow(\n cells: TableCell[],\n tag: 'th' | 'td',\n cellStyle: (col: number) => string,\n options: RenderOptions | undefined,\n ctx: FnCtx,\n): string {\n let out = '';\n for (let i = 0; i < cells.length; i++) {\n const cell = cells[i]!;\n out += `<${tag}${cellStyle(i)}>${inlineRun(cell.children, options, ctx)}</${tag}>`;\n }\n return out;\n}\n\n/* ------------------------------------------------------------------ *\n * Document\n * ------------------------------------------------------------------ */\n\n/** Every footnote definition in the document, in document order. */\nfunction collectFootnoteDefs(doc: Document): FootnoteDef[] {\n const defs: FootnoteDef[] = [];\n walk(doc, (n) => {\n if (n.type === 'footnoteDef') {\n defs.push(n);\n return false; // don't descend into a def's body while collecting\n }\n return true;\n });\n return defs;\n}\n\n/** Render a whole document to sanitized HTML. */\nexport function renderToHtml(doc: Document, options?: RenderOptions): string {\n const ctx = newFnCtx();\n let out = renderBlocks(doc.children, options, ctx);\n\n // Collect every footnote definition (from anywhere in the tree) and emit it\n // once, GitHub-style, as a trailing ordered list with a back-link per note.\n const defs = collectFootnoteDefs(doc);\n if (defs.length > 0) {\n let items = '';\n for (const def of defs) {\n const safe = escapeHtml(slugFootnoteId(def.id));\n items +=\n `<li id=\"fn-${safe}\">` +\n renderBlocks(def.children, options, ctx) +\n ` <a href=\"#fnref-${safe}\" class=\"tw-fn-back\">↩</a>` +\n `</li>`;\n }\n out += `<section class=\"tw-footnotes\"><ol>${items}</ol></section>`;\n }\n\n return out;\n}\n","/**\n * Anticipatory streaming renderer (SPEC.md §8).\n *\n * Given a PARTIAL Markdown string (as it arrives token-by-token from an LLM),\n * render the confirmed prefix richly via the real parser/renderer, and\n * optimistically resolve the trailing incomplete construct — an unterminated\n * `**bo` renders as in-progress bold, an open ``` opens a code block, a forming\n * `<Comp` shows a component skeleton — so the preview reads as finished prose\n * while it is still streaming. Confirmed content is never reflowed.\n *\n * Open-delimiter detection is PARITY based (an odd number of a delimiter on the\n * active line means the last one is unclosed) so a completed span is never\n * mistaken for an open one.\n */\n\nimport { parse } from '../core/parser';\nimport { renderToHtml, renderInline } from '../core/render';\nimport type { AnticipationOptions } from '../types';\n\nexport interface AnticipateResult {\n /** Sanitized HTML for the current partial (safe to inject — render.ts escapes). */\n html: string;\n /** Which constructs are currently being anticipated (e.g. ['strong']). */\n pending: string[];\n}\n\ntype Opt = Required<AnticipationOptions>;\n\nfunction normalizeOpt(o: AnticipationOptions | boolean): Opt {\n const all = (v: boolean): Opt => ({\n emphasis: v, strong: v, code: v, strikethrough: v, links: v,\n headings: v, fences: v, listItems: v, tables: v, jsx: v,\n });\n if (o === true || o === undefined) return all(true);\n if (o === false) return all(false);\n return { ...all(true), ...o };\n}\n\nfunction esc(s: string): string {\n // escapes text AND attribute values (the fence language class, component name),\n // so `\"`/`'` must be escaped too — this is a security boundary.\n return s\n .replace(/&/g, '&')\n .replace(/</g, '<')\n .replace(/>/g, '>')\n .replace(/\"/g, '"')\n .replace(/'/g, ''');\n}\n\n/** Inline HTML for a single line via the real renderer (no <p> wrapper). */\nfunction inlineHtml(text: string): string {\n const doc = parse(text);\n const first = doc.children[0];\n if (first && (first.type === 'paragraph' || first.type === 'heading')) {\n return renderInline(first.children);\n }\n return esc(text);\n}\n\nconst CARET = '<span class=\"tw-caret\" aria-hidden=\"true\"></span>';\n\ninterface OpenRun {\n kind: string;\n tag: string;\n cls: string;\n /** Offset of the opening delimiter within the line. */\n opener: number;\n /** Delimiter length. */\n dl: number;\n}\n\nfunction indexesOf(line: string, sub: string): number[] {\n const out: number[] = [];\n let i = line.indexOf(sub);\n while (i >= 0) {\n out.push(i);\n i = line.indexOf(sub, i + sub.length);\n }\n return out;\n}\n\n/**\n * Offset of the `[` opening a still-forming link on the line, or null.\n *\n * Forming = an unclosed `[text…` (no `]` yet) OR a `[text](url…` whose\n * destination is still open (no closing `)`). A completed `[text](url)` — or a\n * bare closed `[text]` not followed by `(` — is NOT forming, so a finished link\n * is never mistaken for an open one (the STABILITY RULE).\n */\nfunction findOpenLink(line: string): number | null {\n const bi = line.lastIndexOf('[');\n if (bi < 0) return null;\n const rest = line.slice(bi);\n if (!rest.includes(']')) return bi; // \"[text…\"\n if (/^\\[[^\\]]*\\]\\([^)]*$/.test(rest)) return bi; // \"[text](url…\"\n return null;\n}\n\n/**\n * Push the trailing lone-`ch` emphasis run when its parity is odd. The doubled\n * `strong` form (`**`/`__`) is masked with an EQUAL-LENGTH sentinel first, so\n * strong pairs never count as emphasis while the surviving delimiter offsets\n * still line up with the original line (a plain strip would shift them).\n */\nfunction pushEmphasis(line: string, ch: string, dbl: string, cands: OpenRun[]): void {\n const masked = line.split(dbl).join('\u0001\u0001');\n const idx: number[] = [];\n for (let i = 0; i < masked.length; i++) if (masked[i] === ch) idx.push(i);\n if (idx.length % 2 === 1) {\n cands.push({ kind: 'emphasis', tag: 'em', cls: 'tw-pending tw-pending-em', opener: idx[idx.length - 1]!, dl: 1 });\n }\n}\n\n/** Find the OUTERMOST unclosed inline delimiter on a line, or null. */\nfunction findOpenRun(line: string, opt: Opt): OpenRun | null {\n const cands: OpenRun[] = [];\n\n if (opt.strong) {\n const x = indexesOf(line, '**');\n if (x.length % 2 === 1) cands.push({ kind: 'strong', tag: 'strong', cls: 'tw-pending tw-pending-strong', opener: x[x.length - 1]!, dl: 2 });\n }\n if (opt.strikethrough) {\n const x = indexesOf(line, '~~');\n if (x.length % 2 === 1) cands.push({ kind: 'strikethrough', tag: 'del', cls: 'tw-pending tw-pending-del', opener: x[x.length - 1]!, dl: 2 });\n }\n if (opt.code) {\n // ignore ``` fence runs — those are code-block markers, not inline code\n const ticks: number[] = [];\n for (const m of line.matchAll(/`+/g)) {\n if (m[0].length >= 3) continue;\n for (let k = 0; k < m[0].length; k++) ticks.push(m.index + k);\n }\n if (ticks.length % 2 === 1) cands.push({ kind: 'code', tag: 'code', cls: 'tw-pending tw-pending-code', opener: ticks[ticks.length - 1]!, dl: 1 });\n }\n if (opt.links) {\n const li = findOpenLink(line);\n if (li !== null) cands.push({ kind: 'link', tag: 'a', cls: 'tw-pending tw-pending-link', opener: li, dl: 1 });\n }\n if (opt.emphasis) {\n // `*` and `_` emphasis in parallel (mask their `**`/`__` strong forms first)\n pushEmphasis(line, '*', '**', cands);\n pushEmphasis(line, '_', '__', cands);\n }\n\n if (!cands.length) return null;\n cands.sort((a, b) => a.opener - b.opener); // outermost first\n return cands[0]!;\n}\n\nfunction isFormingJsx(line: string, opt: Opt): boolean {\n return opt.jsx && /<[A-Z][A-Za-z0-9]*\\b[^>]*$/.test(line) && !/\\/?>\\s*$/.test(line);\n}\n\n/**\n * A line whose active tail is a forming list item — `- `, `* `, `+ ` or `1. `\n * followed by a space. The text may be empty while it is still being typed, so\n * only the marker+space is required. Rendered as an in-progress <li>.\n */\nconst LIST_ITEM_RE = /^( {0,3})([-+*]|\\d{1,9}[.)])[ \\t]+(.*)$/;\nfunction isFormingListItem(line: string, opt: Opt): boolean {\n return opt.listItems && LIST_ITEM_RE.test(line);\n}\n\n/** A `| a | b` line — a table row (header, delimiter and data all start `|`). */\nconst TABLE_ROW_RE = /^ {0,3}\\|/;\nfunction splitTableCells(row: string): string[] {\n let s = row.trim();\n if (s.startsWith('|')) s = s.slice(1);\n if (s.endsWith('|')) s = s.slice(0, -1);\n return s.split('|').map((c) => c.trim());\n}\n\nfunction hasTrailing(line: string, opt: Opt): boolean {\n if (!line.trim()) return false;\n return (\n isFormingJsx(line, opt) ||\n isFormingListItem(line, opt) ||\n findOpenRun(line, opt) !== null\n );\n}\n\n/** Render a line whose trailing construct is being anticipated. */\nfunction renderActiveLine(line: string, opt: Opt, pending: string[], fallback?: string): string {\n if (isFormingJsx(line, opt)) {\n const name = /<([A-Z][A-Za-z0-9]*)/.exec(line)?.[1] ?? 'Component';\n pending.push('jsx');\n const label = fallback ? esc(fallback) : `‹${esc(name)}› rendering…`;\n return `<div class=\"tw-skeleton\" data-component=\"${esc(name)}\"><span class=\"tw-skeleton-label\">${label}</span><div class=\"tw-skeleton-bar\"></div><div class=\"tw-skeleton-bar\" style=\"width:70%\"></div></div>`;\n }\n\n if (isFormingListItem(line, opt)) return renderActiveListItem(line, opt, pending);\n\n const heading = /^(#{1,6})\\s+(.*)$/.exec(line);\n const body = heading ? (heading[2] ?? '') : line;\n const inner = renderInlineWithOpen(body, opt, pending);\n if (heading) return `<h${heading[1]!.length}>${inner}${CARET}</h${heading[1]!.length}>`;\n return `<p>${inner}${CARET}</p>`;\n}\n\n/**\n * An in-progress list item as its OWN single-item list. Committed items above\n * render through the real parser (their own <ul>/<ol>) and are never touched,\n * so anticipation only ADDS the forming item ahead of confirmation.\n */\nfunction renderActiveListItem(line: string, opt: Opt, pending: string[]): string {\n const m = LIST_ITEM_RE.exec(line)!;\n const marker = m[2]!;\n const content = m[3] ?? '';\n pending.push('listItem');\n const inner = content ? renderInlineWithOpen(content, opt, pending) : '';\n const li = `<li class=\"tw-pending tw-pending-li\">${inner}${CARET}</li>`;\n if (/\\d/.test(marker)) {\n const n = parseInt(marker, 10);\n const startAttr = Number.isFinite(n) && n !== 1 ? ` start=\"${esc(String(n))}\"` : '';\n return `<ol${startAttr} class=\"tw-pending tw-pending-list\">${li}</ol>`;\n }\n return `<ul class=\"tw-pending tw-pending-list\">${li}</ul>`;\n}\n\nfunction renderInlineWithOpen(text: string, opt: Opt, pending: string[]): string {\n const open = findOpenRun(text, opt);\n if (!open) return inlineHtml(text);\n const prefix = text.slice(0, open.opener);\n pending.push(open.kind);\n if (open.kind === 'link') {\n // Show the resolved link TEXT (up to `]`); the href is withheld until the\n // URL finishes, so a partial/unsafe destination is never emitted.\n const after = text.slice(open.opener + 1);\n const close = after.indexOf(']');\n const label = close >= 0 ? after.slice(0, close) : after;\n return `${inlineHtml(prefix)}<a class=\"${open.cls}\">${inlineHtml(label)}</a>`;\n }\n const content = text.slice(open.opener + open.dl);\n const inner = open.kind === 'code' ? esc(content) : inlineHtml(content);\n return `${inlineHtml(prefix)}<${open.tag} class=\"${open.cls}\">${inner}</${open.tag}>`;\n}\n\nfunction renderOpenFence(block: string, pending: string[]): string {\n const nl = block.indexOf('\\n');\n const info = block.slice(3, nl < 0 ? block.length : nl).trim();\n const lang = info.split(/\\s+/)[0] ?? '';\n const code = nl < 0 ? '' : block.slice(nl + 1);\n pending.push('code');\n const langAttr = lang ? ` class=\"language-${esc(lang)}\"` : '';\n return `<pre class=\"tw-codeblock\"><code${langAttr}>${esc(code)}${CARET}</code></pre>`;\n}\n\n/** An in-progress table row appended under a committed header+delimiter table. */\nfunction renderActiveTableRow(row: string, pending: string[]): string {\n const cells = splitTableCells(row);\n pending.push('tableRow');\n let tds = '';\n for (let i = 0; i < cells.length; i++) {\n const caret = i === cells.length - 1 ? CARET : '';\n tds += `<td>${cells[i] ? inlineHtml(cells[i]!) : ''}${caret}</td>`;\n }\n return `<table class=\"tw-pending tw-pending-table\"><tbody><tr>${tds}</tr></tbody></table>`;\n}\n\nexport function anticipate(\n partial: string,\n options: AnticipationOptions | boolean = true,\n componentFallback?: string,\n): AnticipateResult {\n const opt = normalizeOpt(options);\n const pending: string[] = [];\n if (!partial) return { html: '', pending };\n\n // 1) open fenced code block — an odd number of ``` fences means the last is open\n const fenceCount = (partial.match(/^```/gm) ?? []).length;\n if (opt.fences && fenceCount % 2 === 1) {\n const idx = partial.lastIndexOf('```');\n const committed = partial.slice(0, idx).replace(/\\n+$/, '');\n const open = partial.slice(idx);\n const committedHtml = committed.trim() ? renderToHtml(parse(committed)) : '';\n return { html: committedHtml + renderOpenFence(open, pending), pending };\n }\n\n // 2) in-progress table row — a `| …` last line under a committed table\n // (header+delimiter, or a fuller table above). Uses the multi-line\n // committed/active split like the fence path, so the confirmed rows —\n // which do not change until the active row commits — are never reflowed.\n if (opt.tables) {\n const nl = partial.lastIndexOf('\\n');\n if (nl >= 0) {\n const row = partial.slice(nl + 1);\n if (TABLE_ROW_RE.test(row)) {\n const committed = partial.slice(0, nl);\n const doc = parse(committed);\n const last = doc.children[doc.children.length - 1];\n if (last && last.type === 'table') {\n return { html: renderToHtml(doc) + renderActiveTableRow(row, pending), pending };\n }\n }\n }\n }\n\n // 3) anticipate a trailing construct on the LAST line, if any\n const lastNl = partial.lastIndexOf('\\n');\n const active = lastNl >= 0 ? partial.slice(lastNl + 1) : partial;\n if (!hasTrailing(active, opt)) {\n // nothing to anticipate — render the whole thing as-is\n return { html: renderToHtml(parse(partial)), pending };\n }\n const committed = lastNl >= 0 ? partial.slice(0, lastNl) : '';\n const committedHtml = committed.trim() ? renderToHtml(parse(committed)) : '';\n return { html: committedHtml + renderActiveLine(active, opt, pending, componentFallback), pending };\n}\n","/**\n * `typewright/streaming` — feed an AI/LLM token stream into a preview.\n *\n * Text accumulation, stream piping, and smoothing are implemented:\n * `createStreamController` buffers the incoming stream and, when `smooth` is\n * set, drives a timer that reveals a steadily-growing prefix so bursty chunk\n * arrivals read as smooth typing. The anticipatory formatting renderer —\n * turning an incomplete `*bo` into in-progress bold, an unterminated fence into\n * an open code block, and partial JSX into a component skeleton (SPEC.md §8) —\n * lives in {@link anticipate} and is wired into the React `StreamingPreview`\n * component in `typewright`.\n */\n\nimport type { StreamController, StreamOptions } from '../types';\n\nexport type {\n StreamController,\n StreamOptions,\n AnticipationOptions,\n} from '../types';\n\nexport { anticipate } from './anticipate';\nexport type { AnticipateResult } from './anticipate';\n\n/** Default reveal rate when `smooth` is `true` (chars/second). */\nconst DEFAULT_CPS = 220;\n/** Reveal-timer cadence — ~30fps, so the cursor advances in small steady steps. */\nconst TICK_MS = 1000 / 30;\n\n/**\n * Create a controller that accumulates an incoming token stream and emits the\n * running text on every update.\n *\n * When {@link StreamOptions.smooth} is set the FULL buffer is retained (readable\n * via `.text`) but `onUpdate` receives only a steadily-revealed prefix: a timer\n * advances a reveal cursor at the target rate (`charsPerSecond`, or a default),\n * so bursty chunk arrivals read as smooth typing. `end()` reveals everything and\n * clears the timer; `reset()` clears it too — no timer or handle is ever leaked.\n *\n * @param onUpdate Called with the emitted text (revealed prefix when smoothing)\n * and whether the stream has ended.\n * @param options Anticipation / smoothing options (see SPEC.md §8).\n */\nexport function createStreamController(\n onUpdate: (text: string, complete: boolean) => void,\n options: StreamOptions = {},\n): StreamController {\n const smoothCfg =\n !options.smooth\n ? null\n : typeof options.smooth === 'object'\n ? options.smooth\n : { charsPerSecond: DEFAULT_CPS };\n const cps = smoothCfg && smoothCfg.charsPerSecond > 0 ? smoothCfg.charsPerSecond : DEFAULT_CPS;\n // Chars revealed per tick — deterministic (no wall-clock), so it is stable\n // under fake timers and averages to the requested rate.\n const perTick = Math.max(1, Math.round((cps * TICK_MS) / 1000));\n\n let text = '';\n let revealed = 0;\n let complete = false;\n let timer: ReturnType<typeof setInterval> | null = null;\n\n const emit = (): void => onUpdate(smoothCfg ? text.slice(0, revealed) : text, complete);\n\n const stopTimer = (): void => {\n if (timer !== null) {\n clearInterval(timer);\n timer = null;\n }\n };\n const tick = (): void => {\n revealed = Math.min(text.length, revealed + perTick);\n emit();\n if (revealed >= text.length) stopTimer();\n };\n const ensureTimer = (): void => {\n if (timer !== null || complete || revealed >= text.length) return;\n timer = setInterval(tick, TICK_MS);\n };\n\n return {\n push(chunk: string): void {\n if (complete) return;\n text += chunk;\n if (smoothCfg) ensureTimer();\n emit();\n },\n replace(full: string): void {\n text = full;\n complete = false;\n if (smoothCfg) {\n if (revealed > text.length) revealed = text.length;\n ensureTimer();\n }\n emit();\n },\n end(): void {\n complete = true;\n revealed = text.length; // flush everything on completion\n stopTimer();\n emit();\n },\n reset(): void {\n text = '';\n revealed = 0;\n complete = false;\n stopTimer();\n emit();\n },\n get text(): string {\n return text;\n },\n get complete(): boolean {\n return complete;\n },\n };\n}\n\n/**\n * Drive a controller from an async iterable or a `ReadableStream` of string\n * chunks, calling `end()` when the source is exhausted.\n *\n * @example\n * const controller = createStreamController(setText);\n * await pipeStream(llmResponse.textStream, controller);\n */\nexport async function pipeStream(\n source: AsyncIterable<string> | ReadableStream<string>,\n controller: StreamController,\n): Promise<void> {\n if (Symbol.asyncIterator in source) {\n for await (const chunk of source as AsyncIterable<string>) {\n controller.push(chunk);\n }\n } else {\n const reader = source.getReader();\n for (;;) {\n const { done, value } = await reader.read();\n if (done) break;\n if (value != null) controller.push(value);\n }\n }\n controller.end();\n}\n"]}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { A as AnticipationOptions, p as StreamOptions, o as StreamController } from '../types-CX1GOx0Y.cjs';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Anticipatory streaming renderer (SPEC.md §8).
|
|
5
|
+
*
|
|
6
|
+
* Given a PARTIAL Markdown string (as it arrives token-by-token from an LLM),
|
|
7
|
+
* render the confirmed prefix richly via the real parser/renderer, and
|
|
8
|
+
* optimistically resolve the trailing incomplete construct — an unterminated
|
|
9
|
+
* `**bo` renders as in-progress bold, an open ``` opens a code block, a forming
|
|
10
|
+
* `<Comp` shows a component skeleton — so the preview reads as finished prose
|
|
11
|
+
* while it is still streaming. Confirmed content is never reflowed.
|
|
12
|
+
*
|
|
13
|
+
* Open-delimiter detection is PARITY based (an odd number of a delimiter on the
|
|
14
|
+
* active line means the last one is unclosed) so a completed span is never
|
|
15
|
+
* mistaken for an open one.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
interface AnticipateResult {
|
|
19
|
+
/** Sanitized HTML for the current partial (safe to inject — render.ts escapes). */
|
|
20
|
+
html: string;
|
|
21
|
+
/** Which constructs are currently being anticipated (e.g. ['strong']). */
|
|
22
|
+
pending: string[];
|
|
23
|
+
}
|
|
24
|
+
declare function anticipate(partial: string, options?: AnticipationOptions | boolean, componentFallback?: string): AnticipateResult;
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* `typewright/streaming` — feed an AI/LLM token stream into a preview.
|
|
28
|
+
*
|
|
29
|
+
* Text accumulation, stream piping, and smoothing are implemented:
|
|
30
|
+
* `createStreamController` buffers the incoming stream and, when `smooth` is
|
|
31
|
+
* set, drives a timer that reveals a steadily-growing prefix so bursty chunk
|
|
32
|
+
* arrivals read as smooth typing. The anticipatory formatting renderer —
|
|
33
|
+
* turning an incomplete `*bo` into in-progress bold, an unterminated fence into
|
|
34
|
+
* an open code block, and partial JSX into a component skeleton (SPEC.md §8) —
|
|
35
|
+
* lives in {@link anticipate} and is wired into the React `StreamingPreview`
|
|
36
|
+
* component in `typewright`.
|
|
37
|
+
*/
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Create a controller that accumulates an incoming token stream and emits the
|
|
41
|
+
* running text on every update.
|
|
42
|
+
*
|
|
43
|
+
* When {@link StreamOptions.smooth} is set the FULL buffer is retained (readable
|
|
44
|
+
* via `.text`) but `onUpdate` receives only a steadily-revealed prefix: a timer
|
|
45
|
+
* advances a reveal cursor at the target rate (`charsPerSecond`, or a default),
|
|
46
|
+
* so bursty chunk arrivals read as smooth typing. `end()` reveals everything and
|
|
47
|
+
* clears the timer; `reset()` clears it too — no timer or handle is ever leaked.
|
|
48
|
+
*
|
|
49
|
+
* @param onUpdate Called with the emitted text (revealed prefix when smoothing)
|
|
50
|
+
* and whether the stream has ended.
|
|
51
|
+
* @param options Anticipation / smoothing options (see SPEC.md §8).
|
|
52
|
+
*/
|
|
53
|
+
declare function createStreamController(onUpdate: (text: string, complete: boolean) => void, options?: StreamOptions): StreamController;
|
|
54
|
+
/**
|
|
55
|
+
* Drive a controller from an async iterable or a `ReadableStream` of string
|
|
56
|
+
* chunks, calling `end()` when the source is exhausted.
|
|
57
|
+
*
|
|
58
|
+
* @example
|
|
59
|
+
* const controller = createStreamController(setText);
|
|
60
|
+
* await pipeStream(llmResponse.textStream, controller);
|
|
61
|
+
*/
|
|
62
|
+
declare function pipeStream(source: AsyncIterable<string> | ReadableStream<string>, controller: StreamController): Promise<void>;
|
|
63
|
+
|
|
64
|
+
export { type AnticipateResult, AnticipationOptions, StreamController, StreamOptions, anticipate, createStreamController, pipeStream };
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { A as AnticipationOptions, p as StreamOptions, o as StreamController } from '../types-CX1GOx0Y.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Anticipatory streaming renderer (SPEC.md §8).
|
|
5
|
+
*
|
|
6
|
+
* Given a PARTIAL Markdown string (as it arrives token-by-token from an LLM),
|
|
7
|
+
* render the confirmed prefix richly via the real parser/renderer, and
|
|
8
|
+
* optimistically resolve the trailing incomplete construct — an unterminated
|
|
9
|
+
* `**bo` renders as in-progress bold, an open ``` opens a code block, a forming
|
|
10
|
+
* `<Comp` shows a component skeleton — so the preview reads as finished prose
|
|
11
|
+
* while it is still streaming. Confirmed content is never reflowed.
|
|
12
|
+
*
|
|
13
|
+
* Open-delimiter detection is PARITY based (an odd number of a delimiter on the
|
|
14
|
+
* active line means the last one is unclosed) so a completed span is never
|
|
15
|
+
* mistaken for an open one.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
interface AnticipateResult {
|
|
19
|
+
/** Sanitized HTML for the current partial (safe to inject — render.ts escapes). */
|
|
20
|
+
html: string;
|
|
21
|
+
/** Which constructs are currently being anticipated (e.g. ['strong']). */
|
|
22
|
+
pending: string[];
|
|
23
|
+
}
|
|
24
|
+
declare function anticipate(partial: string, options?: AnticipationOptions | boolean, componentFallback?: string): AnticipateResult;
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* `typewright/streaming` — feed an AI/LLM token stream into a preview.
|
|
28
|
+
*
|
|
29
|
+
* Text accumulation, stream piping, and smoothing are implemented:
|
|
30
|
+
* `createStreamController` buffers the incoming stream and, when `smooth` is
|
|
31
|
+
* set, drives a timer that reveals a steadily-growing prefix so bursty chunk
|
|
32
|
+
* arrivals read as smooth typing. The anticipatory formatting renderer —
|
|
33
|
+
* turning an incomplete `*bo` into in-progress bold, an unterminated fence into
|
|
34
|
+
* an open code block, and partial JSX into a component skeleton (SPEC.md §8) —
|
|
35
|
+
* lives in {@link anticipate} and is wired into the React `StreamingPreview`
|
|
36
|
+
* component in `typewright`.
|
|
37
|
+
*/
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Create a controller that accumulates an incoming token stream and emits the
|
|
41
|
+
* running text on every update.
|
|
42
|
+
*
|
|
43
|
+
* When {@link StreamOptions.smooth} is set the FULL buffer is retained (readable
|
|
44
|
+
* via `.text`) but `onUpdate` receives only a steadily-revealed prefix: a timer
|
|
45
|
+
* advances a reveal cursor at the target rate (`charsPerSecond`, or a default),
|
|
46
|
+
* so bursty chunk arrivals read as smooth typing. `end()` reveals everything and
|
|
47
|
+
* clears the timer; `reset()` clears it too — no timer or handle is ever leaked.
|
|
48
|
+
*
|
|
49
|
+
* @param onUpdate Called with the emitted text (revealed prefix when smoothing)
|
|
50
|
+
* and whether the stream has ended.
|
|
51
|
+
* @param options Anticipation / smoothing options (see SPEC.md §8).
|
|
52
|
+
*/
|
|
53
|
+
declare function createStreamController(onUpdate: (text: string, complete: boolean) => void, options?: StreamOptions): StreamController;
|
|
54
|
+
/**
|
|
55
|
+
* Drive a controller from an async iterable or a `ReadableStream` of string
|
|
56
|
+
* chunks, calling `end()` when the source is exhausted.
|
|
57
|
+
*
|
|
58
|
+
* @example
|
|
59
|
+
* const controller = createStreamController(setText);
|
|
60
|
+
* await pipeStream(llmResponse.textStream, controller);
|
|
61
|
+
*/
|
|
62
|
+
declare function pipeStream(source: AsyncIterable<string> | ReadableStream<string>, controller: StreamController): Promise<void>;
|
|
63
|
+
|
|
64
|
+
export { type AnticipateResult, AnticipationOptions, StreamController, StreamOptions, anticipate, createStreamController, pipeStream };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"index.js"}
|