@arbidocs/react 0.4.68 → 0.4.70
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/README.md +8 -0
- package/dist/annotations/index.cjs +186 -2450
- package/dist/annotations/index.cjs.map +1 -1
- package/dist/annotations/index.d.cts +3 -33
- package/dist/annotations/index.d.ts +3 -33
- package/dist/annotations/index.js +4 -2411
- package/dist/annotations/index.js.map +1 -1
- package/dist/artifacts/index.cjs +88 -112
- package/dist/artifacts/index.cjs.map +1 -1
- package/dist/artifacts/index.js +12 -61
- package/dist/artifacts/index.js.map +1 -1
- package/dist/artifacts/redline-core.cjs +8 -7
- package/dist/artifacts/redline-core.js +2 -1
- package/dist/{chunk-PATLJSAO.cjs → chunk-3AADNIOK.cjs} +9 -52
- package/dist/chunk-3AADNIOK.cjs.map +1 -0
- package/dist/chunk-3QF5DNAP.js +2413 -0
- package/dist/chunk-3QF5DNAP.js.map +1 -0
- package/dist/chunk-5DCRIWCA.cjs +243 -0
- package/dist/chunk-5DCRIWCA.cjs.map +1 -0
- package/dist/{chunk-NA3FOYSF.cjs → chunk-5SZ2J2WT.cjs} +5 -177
- package/dist/chunk-5SZ2J2WT.cjs.map +1 -0
- package/dist/{chunk-43AKLNBC.js → chunk-74N436VK.js} +4 -40
- package/dist/chunk-74N436VK.js.map +1 -0
- package/dist/{chunk-Z3RRZ3KV.cjs → chunk-7CL7QHT6.cjs} +2 -240
- package/dist/chunk-7CL7QHT6.cjs.map +1 -0
- package/dist/{chunk-BWVIAATD.cjs → chunk-BTRIS3HY.cjs} +4 -4
- package/dist/{chunk-BWVIAATD.cjs.map → chunk-BTRIS3HY.cjs.map} +1 -1
- package/dist/chunk-G6FHNURH.js +234 -0
- package/dist/chunk-G6FHNURH.js.map +1 -0
- package/dist/chunk-HKUD2NZN.js +61 -0
- package/dist/chunk-HKUD2NZN.js.map +1 -0
- package/dist/chunk-QRCMKEE6.js +173 -0
- package/dist/chunk-QRCMKEE6.js.map +1 -0
- package/dist/{chunk-PFKLOVGQ.js → chunk-SYPUFZGA.js} +3 -233
- package/dist/chunk-SYPUFZGA.js.map +1 -0
- package/dist/chunk-T4IJHRRD.cjs +71 -0
- package/dist/chunk-T4IJHRRD.cjs.map +1 -0
- package/dist/chunk-ULU5LEWF.cjs +2460 -0
- package/dist/chunk-ULU5LEWF.cjs.map +1 -0
- package/dist/{chunk-TQ6FRVAH.js → chunk-V4CXOPLB.js} +3 -3
- package/dist/{chunk-TQ6FRVAH.js.map → chunk-V4CXOPLB.js.map} +1 -1
- package/dist/chunk-VOFNX4P6.cjs +50 -0
- package/dist/chunk-VOFNX4P6.cjs.map +1 -0
- package/dist/chunk-WUTL62MC.js +42 -0
- package/dist/chunk-WUTL62MC.js.map +1 -0
- package/dist/{chunk-JPGV7NMY.js → chunk-YXSXGTYQ.js} +4 -173
- package/dist/chunk-YXSXGTYQ.js.map +1 -0
- package/dist/chunk-Z3LLUO32.cjs +177 -0
- package/dist/chunk-Z3LLUO32.cjs.map +1 -0
- package/dist/document-tools/index.cjs +683 -0
- package/dist/document-tools/index.cjs.map +1 -0
- package/dist/document-tools/index.d.cts +392 -0
- package/dist/document-tools/index.d.ts +392 -0
- package/dist/document-tools/index.js +639 -0
- package/dist/document-tools/index.js.map +1 -0
- package/dist/index.cjs +320 -318
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +9 -6
- package/dist/index.js.map +1 -1
- package/dist/store-CqkkD7Ho.d.cts +35 -0
- package/dist/store-D1nhbkgk.d.ts +35 -0
- package/dist/ui/index.cjs +138 -137
- package/dist/ui/index.js +3 -2
- package/package.json +11 -3
- package/dist/chunk-43AKLNBC.js.map +0 -1
- package/dist/chunk-JPGV7NMY.js.map +0 -1
- package/dist/chunk-NA3FOYSF.cjs.map +0 -1
- package/dist/chunk-PATLJSAO.cjs.map +0 -1
- package/dist/chunk-PFKLOVGQ.js.map +0 -1
- package/dist/chunk-Z3RRZ3KV.cjs.map +0 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@arbidocs/react",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.70",
|
|
4
4
|
"description": "React hooks and provider for the ARBI SDK",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -47,6 +47,11 @@
|
|
|
47
47
|
"types": "./dist/annotations/freeze/index.d.ts",
|
|
48
48
|
"import": "./dist/annotations/freeze/index.js",
|
|
49
49
|
"require": "./dist/annotations/freeze/index.cjs"
|
|
50
|
+
},
|
|
51
|
+
"./document-tools": {
|
|
52
|
+
"types": "./dist/document-tools/index.d.ts",
|
|
53
|
+
"import": "./dist/document-tools/index.js",
|
|
54
|
+
"require": "./dist/document-tools/index.cjs"
|
|
50
55
|
}
|
|
51
56
|
},
|
|
52
57
|
"typesVersions": {
|
|
@@ -71,6 +76,9 @@
|
|
|
71
76
|
],
|
|
72
77
|
"annotations/freeze": [
|
|
73
78
|
"./dist/annotations/freeze/index.d.ts"
|
|
79
|
+
],
|
|
80
|
+
"document-tools": [
|
|
81
|
+
"./dist/document-tools/index.d.ts"
|
|
74
82
|
]
|
|
75
83
|
}
|
|
76
84
|
},
|
|
@@ -85,8 +93,8 @@
|
|
|
85
93
|
"build-storybook": "storybook build"
|
|
86
94
|
},
|
|
87
95
|
"dependencies": {
|
|
88
|
-
"@arbidocs/client": "0.4.
|
|
89
|
-
"@arbidocs/sdk": "0.4.
|
|
96
|
+
"@arbidocs/client": "0.4.70",
|
|
97
|
+
"@arbidocs/sdk": "0.4.70",
|
|
90
98
|
"@radix-ui/react-avatar": "^1.2.0",
|
|
91
99
|
"@radix-ui/react-checkbox": "^1.3.5",
|
|
92
100
|
"@radix-ui/react-collapsible": "^1.1.14",
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/artifacts/normalize-markdown.ts","../src/artifacts/redline-diff.ts"],"names":[],"mappings":";;;;;;;AAeA,IAAM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AACzC,MAAA,IAAI,EAAA,KAAO,QAAA,EAAU,GAAA,CAAI,IAAA,CAAK,IAAI,KAAK,CAAA;AAAA,IACzC,CAAA,MAAO;AACL,MAAA,GAAA,CAAI,IAAA,CAAK,IAAI,KAAK,CAAA;AAAA,IACpB;AAAA,EACF;AAEA,EAAA,OAAO,SAAA,CAAU,GAAA,CAAI,IAAA,CAAK,EAAE,GAAG,UAAU,CAAA;AAC3C","file":"chunk-43AKLNBC.js","sourcesContent":["/**\n * Canonical markdown form. Two texts with the same meaning but different spelling (an editor that\n * escapes `_` and `*`, `*` vs `-` bullets, padded tables, trailing spaces, `&` entities, CRLF)\n * normalise to the identical string, so a diff only reports real edits.\n *\n * Both sides are parsed with the same remark pipeline and re-stringified with fixed options. Pure\n * JS with no DOM, so it runs in a Web Worker too.\n */\nimport { unified } from 'unified'\nimport remarkParse from 'remark-parse'\nimport remarkGfm from 'remark-gfm'\nimport remarkStringify from 'remark-stringify'\n\n// An underscore between two word characters can never open emphasis (CommonMark), so the escape\n// the serializer adds there is noise. Only text nodes are touched: code keeps its backslashes.\nconst INTRAWORD_ESCAPED_UNDERSCORE = /(?<=[\\p{L}\\p{N}])\\\\_(?=[\\p{L}\\p{N}])/gu\n\nconst processor = unified()\n .use(remarkParse)\n // No column alignment: padding would make one wider cell re-space every row of the table.\n .use(remarkGfm, { tablePipeAlign: false })\n .use(remarkStringify, {\n bullet: '-',\n bulletOther: '*',\n emphasis: '*',\n strong: '*',\n fence: '`',\n fences: true,\n rule: '-',\n listItemIndent: 'one',\n incrementListMarker: true,\n resourceLink: false,\n handlers: {\n text: (node, _parent, state, info) =>\n state.safe(node.value, info).replace(INTRAWORD_ESCAPED_UNDERSCORE, '_'),\n },\n })\n\nconst cache = new Map<string, string>()\nconst CACHE_LIMIT = 16\n\n/** Normalise markdown to its canonical spelling. Falls back to a light cleanup if parsing throws. */\nexport function normalizeMarkdown(text: string): string {\n if (!text) return ''\n const hit = cache.get(text)\n if (hit !== undefined) return hit\n let out: string\n try {\n out = String(processor.processSync(text.replace(/\\r\\n?/g, '\\n'))).replace(/\\n*$/, '\\n')\n } catch {\n out = text.replace(/\\r\\n?/g, '\\n').replace(/[ \\t]+$/gm, '')\n }\n if (cache.size >= CACHE_LIMIT) cache.delete(cache.keys().next().value as string)\n cache.set(text, out)\n return out\n}\n","/**\n * Redline diff core\n *\n * Pure (no DOM, no Worker globals) logic for building a Word-style redline\n * markdown string from two flattened document texts. Lives outside the\n * worker file so it's straightforward to unit test.\n *\n * Strategy: hybrid line + word diff with structural safety.\n * 1. `diffLines` splits the texts into add/remove/equal blocks.\n * 2. For an adjacent [removed, added] pair (a modified region):\n * - If either side contains markdown structure that can't safely host\n * inline tags (code fences, table rows, horizontal rules), fall back\n * to block-level wrapping (whole-line del/ins, line by line).\n * - Otherwise run `diffWords`. Markdown leading markers (#, -, *, 1., >)\n * become unchanged word tokens, so when only the heading/list text\n * changes the marker stays *outside* the inline tags and the heading\n * still parses.\n * 3. Pure removed / added blocks (no paired counterpart) are wrapped\n * line-by-line so structural prefixes stay outside the tag.\n */\n\nimport { diffLines, diffWords } from 'diff'\nimport { normalizeMarkdown } from './normalize-markdown'\n\n// Lines that can't safely host inline <del>/<ins> tags without breaking\n// markdown parsing. Code fences, table rows, and horizontal rules.\nconst UNSAFE_LINE = /^(?:\\s*(?:```|~~~).*|\\s*\\|.*\\||\\s*(?:[-=*_]\\s*){3,})\\s*$/\n\n// Block-level markdown structural prefix. When present on a line, putting\n// it INSIDE an inline tag stops the heading/list/blockquote from parsing,\n// so we always preserve it outside the wrapping tag.\nconst STRUCTURAL_PREFIX = /^(\\s*(?:#{1,6}\\s+|[-*+]\\s+|\\d+[.)]\\s+|>\\s*)+)/\n\nfunction escapeForHtmlTag(text: string): string {\n return text.replace(/</g, '<').replace(/>/g, '>')\n}\n\nfunction wrapLineAsRedline(line: string, tag: 'del' | 'ins'): string {\n if (line === '' || line.trim() === '') return line\n if (UNSAFE_LINE.test(line)) {\n return `<${tag}>${escapeForHtmlTag(line)}</${tag}>`\n }\n const m = line.match(STRUCTURAL_PREFIX)\n if (m) {\n const prefix = m[1]\n const rest = line.slice(prefix.length)\n if (rest === '') return line\n return `${prefix}<${tag}>${escapeForHtmlTag(rest)}</${tag}>`\n }\n return `<${tag}>${escapeForHtmlTag(line)}</${tag}>`\n}\n\nfunction wrapBlockAsRedline(block: string, tag: 'del' | 'ins'): string {\n const lines = block.split('\\n')\n return lines\n .map((line, i) => {\n const wrapped = wrapLineAsRedline(line, tag)\n return i < lines.length - 1 ? wrapped + '\\n' : wrapped\n })\n .join('')\n}\n\nfunction pairContainsUnsafeLine(text: string): boolean {\n for (const line of text.split('\\n')) {\n if (UNSAFE_LINE.test(line)) return true\n }\n return false\n}\n\n// The canonical text always ends in one newline; give a result back the caller's own ending.\nfunction matchTail(result: string, raw: string): string {\n return raw.endsWith('\\n') ? result : result.replace(/\\n$/, '')\n}\n\nexport function buildHybridRedlineMarkdown(rawBase: string, rawCompare: string): string {\n // Both sides go through one canonical form so escaping-only differences are not changes.\n const baseText = normalizeMarkdown(rawBase)\n const compareText = normalizeMarkdown(rawCompare)\n const lineChanges = diffLines(baseText, compareText)\n const out: string[] = []\n\n for (let i = 0; i < lineChanges.length; i++) {\n const cur = lineChanges[i]\n const next = lineChanges[i + 1]\n\n if (cur.removed && next?.added) {\n if (pairContainsUnsafeLine(cur.value) || pairContainsUnsafeLine(next.value)) {\n out.push(wrapBlockAsRedline(cur.value, 'del'))\n out.push(wrapBlockAsRedline(next.value, 'ins'))\n } else {\n const wordChanges = diffWords(cur.value, next.value)\n for (const w of wordChanges) {\n if (w.removed) out.push(`<del>${escapeForHtmlTag(w.value)}</del>`)\n else if (w.added) out.push(`<ins>${escapeForHtmlTag(w.value)}</ins>`)\n else out.push(w.value)\n }\n }\n i++ // consume the paired added entry\n } else if (cur.removed) {\n out.push(wrapBlockAsRedline(cur.value, 'del'))\n } else if (cur.added) {\n out.push(wrapBlockAsRedline(cur.value, 'ins'))\n } else {\n out.push(cur.value)\n }\n }\n\n return matchTail(out.join(''), rawCompare)\n}\n\n// ─── Regions extension ────────────────────────────────────────────────────────\n//\n// Same redline as above, but every <del>/<ins> tag carries a stable\n// `data-cid` attribute identifying the \"change region\" it belongs to. A\n// region is the smallest independently revertable change:\n//\n// - inside a safe [REM, ADD] pair, each contiguous changed-word run is its\n// own region, so a single button can revert one phrase without touching\n// other edits in the same paragraph;\n// - unsafe pairs (tables, code fences, horizontal rules) are still one\n// region for the whole block, since line-level wrapping can't safely\n// split them;\n// - a non-adjacent [removed text == added text] pair is a *move*: both\n// endpoints share one cid, render green, and one undo reverts the move.\n//\n// `revertRedlineRegion` mirrors the same walk and rebuilds the working-tree text\n// with one region \"as if it never changed\", so cids round-trip identically\n// from build → render → revert.\n\nexport type RegionKind = 'replace' | 'remove' | 'add' | 'move'\n\nexport interface RedlineRegion {\n id: string\n kind: RegionKind\n baseText: string // what the base side has for this slice\n compareText: string // what the compare side has for this slice\n}\n\nexport interface RedlineWithRegions {\n markdown: string\n regions: RedlineRegion[]\n}\n\n// Tiny deterministic hash (FNV-1a 32-bit, hex). Stable across runs and JS\n// runtimes, with no Node-only deps so this stays browser-safe.\nfunction fnv1aHex(...parts: string[]): string {\n let h = 0x811c9dc5\n for (const part of parts) {\n h ^= 0x5f5f\n h = Math.imul(h, 0x01000193) >>> 0\n for (let i = 0; i < part.length; i++) {\n h ^= part.charCodeAt(i)\n h = Math.imul(h, 0x01000193) >>> 0\n }\n }\n return ('00000000' + h.toString(16)).slice(-8)\n}\n\n// First char of the cid encodes the kind so consumers can style without a\n// region-table lookup: p=replace r=remove a=add m=move.\nfunction makeRegionId(\n kind: RegionKind,\n baseText: string,\n compareText: string,\n seq: number\n): string {\n const prefix = kind === 'replace' ? 'p' : kind === 'remove' ? 'r' : kind === 'add' ? 'a' : 'm'\n return `${prefix}${fnv1aHex(kind, baseText, compareText, String(seq))}`\n}\n\n// Move detection: a non-adjacent removed/added pair with identical text is a\n// move. Returns the move endpoints' lineChanges-indices plus a region per\n// distinct move.\nfunction detectMoves(lineChanges: { value: string; removed?: boolean; added?: boolean }[]): {\n moveByIndex: Map<number, string>\n moveRegions: RedlineRegion[]\n} {\n const moveByIndex = new Map<number, string>()\n const moveRegions: RedlineRegion[] = []\n const removedByText = new Map<string, number[]>()\n const addedByText = new Map<string, number[]>()\n\n for (let i = 0; i < lineChanges.length; i++) {\n const c = lineChanges[i]\n if (c.removed) {\n const arr = removedByText.get(c.value) ?? []\n arr.push(i)\n removedByText.set(c.value, arr)\n } else if (c.added) {\n const arr = addedByText.get(c.value) ?? []\n arr.push(i)\n addedByText.set(c.value, arr)\n }\n }\n\n let seq = 0\n for (const [text, removedIdx] of removedByText) {\n const addedIdx = addedByText.get(text)\n if (!addedIdx || addedIdx.length === 0) continue\n if (text.trim().length === 0) continue\n const n = Math.min(removedIdx.length, addedIdx.length)\n for (let k = 0; k < n; k++) {\n const rI = removedIdx[k]\n const aI = addedIdx[k]\n if (aI === rI + 1 || rI === aI + 1) continue // adjacent = replace, not move\n if (moveByIndex.has(rI) || moveByIndex.has(aI)) continue\n const id = makeRegionId('move', text, text, seq++)\n moveByIndex.set(rI, id)\n moveByIndex.set(aI, id)\n moveRegions.push({ id, kind: 'move', baseText: text, compareText: text })\n }\n }\n\n return { moveByIndex, moveRegions }\n}\n\nfunction wrapLineWithCid(line: string, tag: 'del' | 'ins', cid: string): string {\n if (line === '' || line.trim() === '') return line\n if (UNSAFE_LINE.test(line)) {\n return `<${tag} data-cid=\"${cid}\">${escapeForHtmlTag(line)}</${tag}>`\n }\n const m = line.match(STRUCTURAL_PREFIX)\n if (m) {\n const prefix = m[1]\n const rest = line.slice(prefix.length)\n if (rest === '') return line\n return `${prefix}<${tag} data-cid=\"${cid}\">${escapeForHtmlTag(rest)}</${tag}>`\n }\n return `<${tag} data-cid=\"${cid}\">${escapeForHtmlTag(line)}</${tag}>`\n}\n\nfunction wrapBlockWithCid(block: string, tag: 'del' | 'ins', cid: string): string {\n const lines = block.split('\\n')\n return lines\n .map((line, i) => {\n const wrapped = wrapLineWithCid(line, tag, cid)\n return i < lines.length - 1 ? wrapped + '\\n' : wrapped\n })\n .join('')\n}\n\n// Word-level region emission inside a safe [REM, ADD] pair.\nfunction emitWordLevelRegions(\n basePara: string,\n comparePara: string,\n reserveId: (kind: RegionKind, baseT: string, compareT: string) => string,\n regions: RedlineRegion[]\n): string {\n const wordChanges = diffWords(basePara, comparePara)\n const out: string[] = []\n let k = 0\n while (k < wordChanges.length) {\n const w = wordChanges[k]\n const wNext = wordChanges[k + 1]\n if (w.removed && wNext?.added) {\n const id = reserveId('replace', w.value, wNext.value)\n regions.push({ id, kind: 'replace', baseText: w.value, compareText: wNext.value })\n out.push(`<del data-cid=\"${id}\">${escapeForHtmlTag(w.value)}</del>`)\n out.push(`<ins data-cid=\"${id}\">${escapeForHtmlTag(wNext.value)}</ins>`)\n k += 2\n } else if (w.removed) {\n const id = reserveId('remove', w.value, '')\n regions.push({ id, kind: 'remove', baseText: w.value, compareText: '' })\n out.push(`<del data-cid=\"${id}\">${escapeForHtmlTag(w.value)}</del>`)\n k++\n } else if (w.added) {\n const id = reserveId('add', '', w.value)\n regions.push({ id, kind: 'add', baseText: '', compareText: w.value })\n out.push(`<ins data-cid=\"${id}\">${escapeForHtmlTag(w.value)}</ins>`)\n k++\n } else {\n out.push(w.value)\n k++\n }\n }\n return out.join('')\n}\n\nexport function buildHybridRedlineWithRegions(\n rawBase: string,\n rawCompare: string\n): RedlineWithRegions {\n const baseText = normalizeMarkdown(rawBase)\n const compareText = normalizeMarkdown(rawCompare)\n const lineChanges = diffLines(baseText, compareText)\n const { moveByIndex, moveRegions } = detectMoves(lineChanges)\n const out: string[] = []\n const regions: RedlineRegion[] = [...moveRegions]\n const seenIds = new Map<string, number>()\n\n const reserveId = (kind: RegionKind, baseT: string, compareT: string): string => {\n const baseHash = fnv1aHex(kind, baseT, compareT)\n const seq = seenIds.get(baseHash) ?? 0\n seenIds.set(baseHash, seq + 1)\n return makeRegionId(kind, baseT, compareT, seq)\n }\n\n for (let i = 0; i < lineChanges.length; i++) {\n const cur = lineChanges[i]\n const next = lineChanges[i + 1]\n const moveId = moveByIndex.get(i)\n\n if (moveId) {\n const tag = cur.removed ? 'del' : 'ins'\n out.push(wrapBlockWithCid(cur.value, tag, moveId))\n continue\n }\n\n if (cur.removed && next?.added) {\n if (pairContainsUnsafeLine(cur.value) || pairContainsUnsafeLine(next.value)) {\n const id = reserveId('replace', cur.value, next.value)\n regions.push({ id, kind: 'replace', baseText: cur.value, compareText: next.value })\n out.push(wrapBlockWithCid(cur.value, 'del', id))\n out.push(wrapBlockWithCid(next.value, 'ins', id))\n } else {\n out.push(emitWordLevelRegions(cur.value, next.value, reserveId, regions))\n }\n i++\n } else if (cur.removed) {\n const id = reserveId('remove', cur.value, '')\n regions.push({ id, kind: 'remove', baseText: cur.value, compareText: '' })\n out.push(wrapBlockWithCid(cur.value, 'del', id))\n } else if (cur.added) {\n const id = reserveId('add', '', cur.value)\n regions.push({ id, kind: 'add', baseText: '', compareText: cur.value })\n out.push(wrapBlockWithCid(cur.value, 'ins', id))\n } else {\n out.push(cur.value)\n }\n }\n\n return { markdown: matchTail(out.join(''), rawCompare), regions }\n}\n\n// Word-level partial revert inside a [REM, ADD] pair.\nfunction revertWordRegion(\n basePara: string,\n comparePara: string,\n targetId: string,\n reserveId: (kind: RegionKind, baseT: string, compareT: string) => string\n): { text: string; matched: boolean } {\n const wordChanges = diffWords(basePara, comparePara)\n const out: string[] = []\n let matched = false\n let k = 0\n while (k < wordChanges.length) {\n const w = wordChanges[k]\n const wNext = wordChanges[k + 1]\n if (w.removed && wNext?.added) {\n const id = reserveId('replace', w.value, wNext.value)\n if (id === targetId) {\n out.push(w.value)\n matched = true\n } else {\n out.push(wNext.value)\n }\n k += 2\n } else if (w.removed) {\n const id = reserveId('remove', w.value, '')\n if (id === targetId) {\n out.push(w.value)\n matched = true\n }\n k++\n } else if (w.added) {\n const id = reserveId('add', '', w.value)\n if (id !== targetId) {\n out.push(w.value)\n } else {\n matched = true\n }\n k++\n } else {\n out.push(w.value)\n k++\n }\n }\n return { text: out.join(''), matched }\n}\n\n// Apply a per-region revert: rebuild the working-tree text from scratch by\n// walking the same diff and treating the target region as unchanged from\n// the base. Walking the diff ourselves (rather than string-replacing in the\n// working tree) means we don't have to worry about ambiguous matches.\nexport function revertRedlineRegion(rawBase: string, rawCompare: string, targetId: string): string {\n const baseText = normalizeMarkdown(rawBase)\n const compareText = normalizeMarkdown(rawCompare)\n const lineChanges = diffLines(baseText, compareText)\n const { moveByIndex } = detectMoves(lineChanges)\n const out: string[] = []\n const seenIds = new Map<string, number>()\n\n const reserveId = (kind: RegionKind, baseT: string, compareT: string): string => {\n const baseHash = fnv1aHex(kind, baseT, compareT)\n const seq = seenIds.get(baseHash) ?? 0\n seenIds.set(baseHash, seq + 1)\n return makeRegionId(kind, baseT, compareT, seq)\n }\n\n for (let i = 0; i < lineChanges.length; i++) {\n const cur = lineChanges[i]\n const next = lineChanges[i + 1]\n const moveId = moveByIndex.get(i)\n\n if (moveId) {\n if (moveId === targetId) {\n if (cur.removed) out.push(cur.value)\n } else {\n if (cur.added) out.push(cur.value)\n }\n continue\n }\n\n if (cur.removed && next?.added) {\n if (pairContainsUnsafeLine(cur.value) || pairContainsUnsafeLine(next.value)) {\n const id = reserveId('replace', cur.value, next.value)\n out.push(id === targetId ? cur.value : next.value)\n } else {\n const { text, matched } = revertWordRegion(cur.value, next.value, targetId, reserveId)\n out.push(matched ? text : next.value)\n }\n i++\n } else if (cur.removed) {\n const id = reserveId('remove', cur.value, '')\n if (id === targetId) out.push(cur.value)\n } else if (cur.added) {\n const id = reserveId('add', '', cur.value)\n if (id !== targetId) out.push(cur.value)\n } else {\n out.push(cur.value)\n }\n }\n\n return matchTail(out.join(''), rawCompare)\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/ai/markdown-base-components.tsx","../src/ai/markdown-streaming-context.ts","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AQ,CAAC,CAAA,GAAI;AAAA;AAChE,KACF;AAAA,IACF,CAAC,UAAU,WAAW;AAAA,GACxB;AAEA,EAAA,uBACEA,GAAAA;AAAA,IAAC,qBAAA;AAAA,IAAA;AAAA,MACC,QAAA,kBAAUA,GAAAA,CAAC,KAAA,EAAA,EAAI,WAAW,EAAA,CAAG,iCAAA,EAAmC,SAAS,CAAA,EAAI,QAAA,EAAS,CAAA;AAAA,MAEtF,0BAAAA,GAAAA,CAAC,wBAAA,CAAyB,UAAzB,EAAkC,KAAA,EAAO,aACxC,QAAA,kBAAAA,GAAAA;AAAA,QAAC,KAAA;AAAA,QAAA;AAAA,UACC,SAAA,EAAW,EAAA,CAAG,wDAAA,EAA0D,SAAS,CAAA;AAAA,UACjF,aAAA,EAAa,MAAA;AAAA,UAEZ,QAAA,EAAA,MAAA,CAAO,GAAA,CAAI,CAAC,KAAA,EAAO,KAAA,qBAClBA,GAAAA,CAAC,aAAA,EAAA,EAA0B,OAAA,EAAS,KAAA,EAAO,UAAA,EAAA,EAAvB,KAA+C,CACpE;AAAA;AAAA,OACH,EACF;AAAA;AAAA,GACF;AAEJ;AAOO,IAAM,gBAAA,GAAmB,KAAA,CAAM,IAAA,CAAK,yBAAyB","file":"chunk-JPGV7NMY.js","sourcesContent":["import React from 'react'\nimport type { Components } from 'react-markdown'\n\n/**\n * Brand-neutral presentational component overrides for react-markdown, shared by\n * every markdown surface in the workspace (the monolith's `MarkdownRenderer` and\n * the AI kit's `AiMarkdown`). One house style for headings, lists, tables and the\n * inline text elements — token-based, so it themes per app.\n *\n * Deliberately excluded (kept per-consumer): `a` (external-link confirm vs\n * plain), `code`/`pre` (rich CodeBlock + Mermaid vs inline), `span` (doc-entity\n * pills), and `del`/`ins`/`mark` (general emphasis vs redline tracked-changes) —\n * these differ by intent or carry heavy/coupled behaviour, so each renderer owns\n * them and spreads this base underneath.\n */\nexport const markdownBaseComponents: Partial<Components> = {\n h1: ({ children, ...props }: React.ComponentPropsWithoutRef<'h1'>) => (\n <h1 className=\"text-lg font-semibold\" data-testid=\"markdown-heading-1\" {...props}>\n {children}\n </h1>\n ),\n h2: ({ children, ...props }: React.ComponentPropsWithoutRef<'h2'>) => (\n <h2 className=\"font-semibold text-base\" data-testid=\"markdown-heading-2\" {...props}>\n {children}\n </h2>\n ),\n h3: ({ children, ...props }: React.ComponentPropsWithoutRef<'h3'>) => (\n <h3 className=\"font-semibold text-base\" data-testid=\"markdown-heading-3\" {...props}>\n {children}\n </h3>\n ),\n h4: ({ children, ...props }: React.ComponentPropsWithoutRef<'h4'>) => (\n <h4 className=\"font-semibold text-base\" {...props}>\n {children}\n </h4>\n ),\n h5: ({ children, ...props }: React.ComponentPropsWithoutRef<'h5'>) => (\n <h5 className=\"font-medium\" {...props}>\n {children}\n </h5>\n ),\n strong: ({ children, ...props }: React.ComponentPropsWithoutRef<'strong'>) => (\n <strong className=\"font-semibold\" {...props}>\n {children}\n </strong>\n ),\n blockquote: ({ children, ...props }: React.ComponentPropsWithoutRef<'blockquote'>) => (\n <blockquote className=\"border-l-2 border-primary pl-4\" {...props}>\n {children}\n </blockquote>\n ),\n ol: ({ children, ...props }: React.ComponentPropsWithoutRef<'ol'>) => (\n <ol className=\"list-decimal space-y-2 pl-6\" data-testid=\"markdown-ordered-list\" {...props}>\n {children}\n </ol>\n ),\n ul: ({ children, ...props }: React.ComponentPropsWithoutRef<'ul'>) => (\n <ul className=\"list-none space-y-2 pl-6\" data-testid=\"markdown-unordered-list\" {...props}>\n {children}\n </ul>\n ),\n li: ({ children, ...props }: React.ComponentPropsWithoutRef<'li'>) => (\n <li className=\"my-1.5\" {...props}>\n {children}\n </li>\n ),\n table: ({ children, ...props }: React.ComponentPropsWithoutRef<'table'>) => (\n <table data-testid=\"markdown-table\" {...props}>\n {children}\n </table>\n ),\n th: ({ children, ...props }: React.ComponentPropsWithoutRef<'th'>) => (\n <th {...props}>{children}</th>\n ),\n td: ({ children, ...props }: React.ComponentPropsWithoutRef<'td'>) => (\n <td {...props}>{children}</td>\n ),\n tr: ({ children, ...props }: React.ComponentPropsWithoutRef<'tr'>) => (\n <tr {...props}>{children}</tr>\n ),\n p: ({ children, ...props }: React.ComponentPropsWithoutRef<'p'>) => (\n <p className=\"whitespace-pre-wrap\" {...props}>\n {children}\n </p>\n ),\n hr: (props: React.ComponentPropsWithoutRef<'hr'>) => (\n <hr className=\"border-foreground/20\" {...props} />\n ),\n sup: ({ children, ...props }: React.ComponentPropsWithoutRef<'sup'>) => (\n <sup className=\"text-xs\" {...props}>\n {children}\n </sup>\n ),\n sub: ({ children, ...props }: React.ComponentPropsWithoutRef<'sub'>) => (\n <sub className=\"text-xs\" {...props}>\n {children}\n </sub>\n ),\n div: ({ children, className, ...props }: React.ComponentPropsWithoutRef<'div'>) => (\n <div className={className} {...props}>\n {children}\n </div>\n ),\n br: (props: React.ComponentPropsWithoutRef<'br'>) => <br {...props} />,\n kbd: ({ children, ...props }: React.ComponentPropsWithoutRef<'kbd'>) => (\n <kbd\n className=\"px-1.5 py-0.5 text-xs font-mono bg-muted border border-border rounded\"\n {...props}\n >\n {children}\n </kbd>\n ),\n abbr: ({ children, title, ...props }: React.ComponentPropsWithoutRef<'abbr'>) => (\n <abbr title={title} className=\"underline decoration-dotted cursor-help\" {...props}>\n {children}\n </abbr>\n ),\n cite: ({ children, ...props }: React.ComponentPropsWithoutRef<'cite'>) => (\n <cite className=\"italic\" {...props}>\n {children}\n </cite>\n ),\n}\n","import { createContext } from 'react'\n\n/**\n * Signals to `MarkdownRenderer`'s component overrides that the surrounding\n * message is still streaming tokens. Heavy renderers can defer their work while\n * this is true to avoid burning CPU on partially complete fences and to keep the\n * UI responsive during long generations.\n *\n * Default `false` means non-streaming usages (parsed documents, static answers,\n * DM bubbles) get the full rendering with no behaviour change.\n */\nexport const MarkdownStreamingContext = createContext(false)\n","/**\n * Splits a markdown string into top-level blocks at `\\n\\n` boundaries.\n *\n * Streaming AI responses arrive token-by-token; passing the full string to\n * react-markdown re-parses the entire AST on every flush. By splitting into\n * blocks and memoizing each, only the trailing (still-growing) block re-parses\n * — completed blocks stay frozen in the DOM.\n *\n * The split avoids three correctness pitfalls:\n * - never splits inside an open ``` code fence (would corrupt the language)\n * - never splits between two adjacent list items (would render as two lists)\n * - never splits between two blockquote lines (would render as two quotes)\n */\nconst LIST_ITEM_RE = /^\\s*([-*+]|\\d+[.)])\\s/\nconst BLOCKQUOTE_RE = /^\\s*>/\n\nexport function splitMarkdownBlocks(content: string): string[] {\n if (!content) return []\n const blocks: string[] = []\n let start = 0\n let inFence = false\n let i = 0\n while (i < content.length) {\n if (content.startsWith('```', i)) {\n inFence = !inFence\n i += 3\n continue\n }\n if (!inFence && content[i] === '\\n' && content[i + 1] === '\\n') {\n const before = content.slice(start, i)\n const lastLine = before.slice(before.lastIndexOf('\\n') + 1)\n const afterStart = i + 2\n const nextNewline = content.indexOf('\\n', afterStart)\n const nextLine = content.slice(afterStart, nextNewline === -1 ? undefined : nextNewline)\n const bothListItems = LIST_ITEM_RE.test(lastLine) && LIST_ITEM_RE.test(nextLine)\n const bothBlockquotes = BLOCKQUOTE_RE.test(lastLine) && BLOCKQUOTE_RE.test(nextLine)\n if (bothListItems || bothBlockquotes) {\n i += 2\n continue\n }\n blocks.push(content.slice(start, afterStart))\n start = afterStart\n i = afterStart\n continue\n }\n i++\n }\n if (start < content.length) blocks.push(content.slice(start))\n return blocks\n}\n","/**\n * Citation markup normaliser.\n *\n * The backend marks a cited statement as a markdown link, `[statement](#cite-N)`, and the\n * statement can include the markdown that surrounds it: a list marker, a heading marker or the\n * opener of a bold/italic span whose closer sits after the link. Inside link text those tokens\n * are not parsed as block or inline syntax, so they show literally and break lists and bold:\n *\n * [- **Claimed quantum (by Claimant)](#cite-1):** **USD 47 million**\n *\n * `normalizeCitationMarkup` hoists the leading tokens out of the link text (and a trailing\n * emphasis closer after it), so the link only wraps the words:\n *\n * - **[Claimed quantum (by Claimant)](#cite-1):** **USD 47 million**\n *\n * It is conservative: emphasis that opens and closes inside the link text is valid markdown and\n * is left alone, an opener is only hoisted when its closer follows on the same line, and fenced\n * code blocks are never touched. The result is idempotent.\n *\n * It also tidies the residue the model leaves when it cites in prose as well: a literal\n * `(*Source: Award.pdf, p. 12*)` shows its asterisks, because `(*` does not open emphasis. It\n * becomes the italic note `*(Source: Award.pdf, p. 12)*`.\n */\n\nconst SOURCE_RESIDUE = /\\(\\*+\\s*(Sources?\\s*:[^\\n]*?)\\s*\\*+\\)/g\n\nconst CITE_CLOSE = /^\\]\\((#cite-[\\w-]+)\\)/\nconst BLOCK_MARKER = /^(?:[-*+]|\\d{1,9}[.)]|#{1,6})[ \\t]+/\nconst LEADING_EMPHASIS = /^(?:\\*\\*|__|\\*|_)+/\nconst TRAILING_EMPHASIS = /(\\*\\*|__|\\*|_)(:?)$/\n\n/** Occurrences of `token` in `text`; a single `*` is counted outside any `**` pair. */\nfunction countToken(text: string, token: string): number {\n const double = token + token\n if (token.length === 2) return text.split(token).length - 1\n const withoutDouble = text.split(double).join('')\n return withoutDouble.split(token).length - 1\n}\n\n/** Split a run of emphasis characters (`***`, `**`, `*`...) into its parser-level tokens. */\nfunction emphasisTokens(run: string): string[] {\n const char = run[0]\n const tokens: string[] = []\n let rest = run\n while (rest.length > 0) {\n const size = rest.length >= 2 ? 2 : 1\n tokens.push(char.repeat(size))\n rest = rest.slice(size)\n }\n return tokens\n}\n\nfunction hoistFromLink(text: string, before: string, after: string): [string, string, string] {\n let body = text\n let prefix = ''\n let suffix = ''\n\n if (before.trim() === '') {\n const marker = BLOCK_MARKER.exec(body)\n if (marker) {\n prefix += marker[0]\n body = body.slice(marker[0].length)\n }\n }\n\n // The link opened inside an emphasis span: `*Sources:[* Letter](#cite-2)`. A leading token that\n // the text before the link left open, and that is followed by a space, is the span's CLOSER (an\n // opener cannot precede a space), so it moves out in front of the link with its space.\n const closer = /^(\\*\\*|__|\\*|_)(\\s+)(?=\\S)/.exec(body)\n if (closer && countToken(before + prefix, closer[1]) % 2 === 1) {\n prefix += closer[1] + closer[2]\n body = body.slice(closer[0].length)\n }\n\n const leading = LEADING_EMPHASIS.exec(body)\n if (leading) {\n let kept = ''\n let rest = body.slice(leading[0].length)\n for (const token of emphasisTokens(leading[0]).reverse()) {\n // Balanced inside the link text: valid as written.\n if (countToken(rest, token) % 2 === 1) {\n kept = token + kept\n continue\n }\n // Unmatched here: hoist only if the line closes it after the link.\n if (countToken(after, token) % 2 === 1) prefix += token\n else kept = token + kept\n }\n body = kept + rest\n rest = ''\n }\n\n // A span opened before the link and closed inside it (`**Spence v. [Costa Rica** arbitration.]`)\n // cannot close across the link boundary: move the words up to the closer out of the link.\n for (const token of ['**', '__']) {\n const at = body.indexOf(token)\n if (at === -1 || countToken(body, token) % 2 === 0) continue\n if (countToken(before + prefix, token) % 2 === 0) continue\n const rest = body.slice(at + token.length)\n if (!/[\\p{L}\\p{N}]/u.test(rest)) continue\n prefix +=\n body.slice(0, at + token.length) + rest.slice(0, rest.length - rest.trimStart().length)\n body = rest.trimStart()\n break\n }\n\n const trailing = TRAILING_EMPHASIS.exec(body)\n if (trailing) {\n const token = trailing[1]\n const inner = body.slice(0, body.length - trailing[0].length)\n const openedBefore = countToken(before + prefix, token) % 2 === 1\n if (countToken(inner, token) % 2 === 0 && openedBefore) {\n body = inner\n suffix = trailing[0]\n }\n }\n\n // The link ends inside an emphasis span that closes after it: `*(Source](#cite-1): a.md)*`. The\n // unmatched opener and the words after it leave the link, so the span opens and closes in the\n // same text again: `[words](#cite-1) *(Source: a.md)*`.\n if (!suffix) {\n for (const token of ['**', '*']) {\n const at = lastUnmatchedOpener(body, token)\n if (at > 0 && countToken(after, token) % 2 === 1) {\n suffix = ' ' + body.slice(at)\n body = body.slice(0, at).trimEnd()\n break\n }\n }\n }\n\n return [prefix, body, suffix]\n}\n\n/** Index of the last `token` in `text` that opens emphasis (followed by a non-space) and has no closer. */\nfunction lastUnmatchedOpener(text: string, token: string): number {\n if (countToken(text, token) % 2 === 0) return -1\n const pattern = token === '**' ? /\\*\\*(?=\\S)/g : /(?<!\\*)\\*(?![*\\s])/g\n let at = -1\n for (const m of text.matchAll(pattern)) at = m.index ?? -1\n return at\n}\n\ninterface CiteLink {\n start: number\n end: number\n text: string\n href: string\n}\n\n/**\n * The `[text](#cite-N)` links of a line. The text may hold brackets of its own\n * (`[2. **[PLACEHOLDER]** names the claimant.](#cite-3)`), so a regex cannot find the opener: a\n * stack of `[` is scanned, and a `](#cite-N)` takes the nearest open one.\n */\nfunction findCiteLinks(line: string): CiteLink[] {\n const links: CiteLink[] = []\n const open: number[] = []\n for (let i = 0; i < line.length; i++) {\n const c = line[i]\n if (c === '[') open.push(i)\n else if (c === ']') {\n const opener = open.pop()\n const close = CITE_CLOSE.exec(line.slice(i, i + 40))\n if (opener !== undefined && close) {\n links.push({\n start: opener,\n end: i + close[0].length,\n text: line.slice(opener + 1, i),\n href: close[1],\n })\n i += close[0].length - 1\n }\n }\n }\n return links.sort((x, y) => x.start - y.start)\n}\n\nfunction normalizeLine(line: string): string {\n if (!line.includes('](#cite-')) return line\n let out = ''\n let last = 0\n for (const link of findCiteLinks(line)) {\n // A link inside another link's text is part of that text.\n if (link.start < last) continue\n // Markdown links do not nest: a citation that wraps another citation (`[a [9](#cite-9)](#cite-10)`)\n // keeps the words and the inner mark, and the outer wrapper is dropped.\n if (link.text.includes('](#cite-')) {\n out += line.slice(last, link.start) + link.text\n last = link.end\n continue\n }\n const before = line.slice(0, link.start)\n const after = line.slice(link.end)\n const [prefix, body, suffix] = hoistFromLink(link.text, before, after)\n out += line.slice(last, link.start)\n out += `${prefix}[${body}](${link.href})${suffix}`\n last = link.end\n }\n return out + line.slice(last)\n}\n\nfunction normalizeSourceResidue(line: string): string {\n return line.includes('(*') ? line.replace(SOURCE_RESIDUE, '*($1)*') : line\n}\n\nexport function normalizeCitationMarkup(markdown: string): string {\n if (!markdown.includes('](#cite-') && !markdown.includes('(*')) return markdown\n let inFence = false\n return markdown\n .split('\\n')\n .map((line) => {\n if (/^\\s*(```|~~~)/.test(line)) {\n inFence = !inFence\n return line\n }\n return inFence ? line : normalizeSourceResidue(normalizeLine(line))\n })\n .join('\\n')\n}\n\n/** A trailing, still-open `[words](#cite-N` marker (or an unclosed `[words`) on the last line. */\nconst OPEN_CITATION_TAIL = /\\[[^\\]\\n]*(?:\\](?:\\((?:#(?:c(?:i(?:t(?:e(?:-[\\w-]*)?)?)?)?)?)?)?)?$/\n\n/**\n * Drops an unfinished citation marker from the end of text that is still streaming (or was\n * stopped mid-marker), so `[Change of control](#cite-` never shows as raw markup: the words appear\n * once the marker is complete. Complete markers and everything else are left alone.\n */\nexport function trimOpenCitation(markdown: string): string {\n return markdown.replace(OPEN_CITATION_TAIL, '')\n}\n\n/** `**` pairs outside inline code in a line. */\nfunction boldMarks(line: string): number {\n return (line.replace(/`[^`]*`/g, '').match(/\\*\\*/g) ?? []).length\n}\n\n/**\n * Makes the tail of text that is still streaming (or was stopped) render cleanly: a `**` opened\n * in the last line and not yet closed (`| Valuation | **[USD 6.2 million](#cite-2)`) would show as\n * literal asterisks until its closer arrives, because an unclosed emphasis is not emphasis. The\n * open bold is closed at the end of the line, or removed when it has no text yet (`| **`, or a\n * half-typed closer `**USD 6*`). Text with balanced emphasis, and every line but the last, is\n * left alone. Apply after `trimOpenCitation`.\n */\nexport function closeOpenEmphasis(markdown: string): string {\n const cut = markdown.lastIndexOf('\\n') + 1\n const head = markdown.slice(0, cut)\n const fences = head.split('\\n').filter((l) => /^\\s*(```|~~~)/.test(l)).length\n let line = markdown.slice(cut)\n if (fences % 2 === 1 || /^\\s*(```|~~~)/.test(line)) return markdown\n // A half-typed opener: the first `*` of `**` after a space or a cell border.\n line = line.replace(/(^|[\\s|])\\*$/, '$1')\n if (boldMarks(line) % 2 === 0) return head + line\n // A half-typed closer: `**USD 6*` -> the second asterisk has not arrived.\n line = line.replace(/([^*\\s])\\*$/, '$1')\n if (boldMarks(line) % 2 === 0) return head + line\n if (/\\*\\*\\s*$/.test(line)) return head + line.replace(/\\s*\\*\\*\\s*$/, ' ')\n return head + line + '**'\n}\n","import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react'\nimport Markdown, { type Components } from 'react-markdown'\nimport remarkGfm from 'remark-gfm'\nimport rehypeRaw from 'rehype-raw'\nimport { Copy, Check } from 'lucide-react'\nimport { cn } from '../lib/utils'\nimport { markdownBaseComponents } from './markdown-base-components'\nimport { MarkdownStreamingContext } from './markdown-streaming-context'\nimport { splitMarkdownBlocks } from './split-markdown-blocks'\nimport { closeOpenEmphasis, normalizeCitationMarkup, trimOpenCitation } from './normalize-citations'\n\n/**\n * MarkdownRenderer — the single, full-featured markdown surface for the kit.\n *\n * Renders AI answers, chat/DM messages and parsed-document panes with one house\n * style: headings, paragraphs, bold/italic, ordered/unordered lists, GFM tables,\n * fenced code blocks (monospace + copy button), inline code, blockquotes, safe\n * links (`rel=\"noopener\"`, new tab) and horizontal rules.\n *\n * Styling is 100% semantic Tailwind tokens (`text-foreground`,\n * `text-muted-foreground`, `border-border`, `bg-muted`, `text-primary`) so it\n * themes per firm — no hardcoded brand colours. It sizes to its container, so it\n * looks right in a compact chat bubble and in a full-width document pane alike.\n *\n * Streaming: the content is split into block-level chunks (see\n * `splitMarkdownBlocks`) and each chunk is memoised, so streaming token updates\n * only re-parse the trailing block instead of the whole message. Pass\n * `isStreaming` to let heavy custom components defer via `MarkdownStreamingContext`.\n *\n * Extending: pass `components` to override any element (the kit's `AiMarkdown`\n * and `CitationRenderer` layer their accent links / citation popovers on top).\n */\n\nconst EDGE_FADE = '1.5rem'\n\n/**\n * A GFM table in its own horizontal scroller. The table keeps a minimum width per column\n * (`min-w-[7rem]` cells, words never broken mid-word), so on a narrow screen it scrolls sideways\n * inside this wrapper instead of squeezing cells to a letter per line. The edge(s) with more\n * content to scroll to fade out, which is the scroll hint. Wide containers are unchanged: the\n * table is `w-full` and nothing overflows.\n */\nfunction MarkdownTable({ children, ...props }: React.ComponentPropsWithoutRef<'table'>) {\n const ref = useRef<HTMLDivElement>(null)\n const [edges, setEdges] = useState({ start: false, end: false })\n const measure = useCallback(() => {\n const el = ref.current\n if (!el) return\n const start = el.scrollLeft > 1\n const end = el.scrollLeft + el.clientWidth < el.scrollWidth - 1\n setEdges((prev) => (prev.start === start && prev.end === end ? prev : { start, end }))\n }, [])\n useEffect(() => {\n const el = ref.current\n if (!el) return\n measure()\n if (typeof ResizeObserver === 'undefined') return\n const observer = new ResizeObserver(measure)\n observer.observe(el)\n if (el.firstElementChild) observer.observe(el.firstElementChild)\n return () => observer.disconnect()\n }, [measure])\n const mask =\n edges.start || edges.end\n ? `linear-gradient(to right, ${edges.start ? 'transparent' : '#000'}, #000 ${EDGE_FADE}, #000 calc(100% - ${EDGE_FADE}), ${edges.end ? 'transparent' : '#000'})`\n : undefined\n return (\n <div\n ref={ref}\n onScroll={measure}\n data-testid=\"markdown-table-scroller\"\n data-scroll-start={edges.start || undefined}\n data-scroll-end={edges.end || undefined}\n className=\"my-3 overflow-x-auto rounded-lg border border-border\"\n style={mask ? { maskImage: mask, WebkitMaskImage: mask } : undefined}\n >\n <table\n data-testid=\"markdown-table\"\n className=\"w-full border-collapse text-sm [overflow-wrap:normal] [word-break:normal]\"\n {...props}\n >\n {children}\n </table>\n </div>\n )\n}\n\n/** Fenced code block with a language label and copy-to-clipboard button. */\nfunction CodeBlock({ language, code }: { language: string; code: string }) {\n const [copied, setCopied] = useState(false)\n\n const handleCopy = async () => {\n try {\n await navigator.clipboard.writeText(code)\n setCopied(true)\n setTimeout(() => setCopied(false), 2000)\n } catch {\n // Clipboard unavailable (insecure context / permissions) — no-op.\n }\n }\n\n return (\n <div\n className=\"code-block relative my-3 overflow-hidden rounded-md border border-current/20 bg-current/5\"\n data-testid=\"markdown-code-block\"\n >\n <div className=\"flex items-center justify-between border-b border-current/20 px-3 py-1.5\">\n <span className=\"font-mono text-xs text-muted-foreground\">{language || 'code'}</span>\n <button\n type=\"button\"\n onClick={handleCopy}\n className=\"flex items-center gap-1 text-xs text-muted-foreground transition-colors hover:text-foreground\"\n title={copied ? 'Copied!' : 'Copy code'}\n >\n {copied ? <Check size={12} /> : <Copy size={12} />}\n <span>{copied ? 'Copied' : 'Copy'}</span>\n </button>\n </div>\n <pre className=\"overflow-x-auto p-3 text-sm leading-relaxed\">\n <code className={cn('font-mono', language && `language-${language}`)}>{code}</code>\n </pre>\n </div>\n )\n}\n\n/**\n * Links. Internal hash/anchor links stay in-page; everything else opens safely in a new tab\n * (`rel=\"noopener noreferrer\"` prevents reverse-tabnabbing). A backend citation marker\n * (`#cite-N`) has no popover here: the cited words stay in the surface's own colour with a quiet\n * superscript number after them (no underline, so a cited sentence does not read as a link).\n * Pass `renderCitation` to `MarkdownRenderer` to swap in a real source popover.\n */\nfunction MarkdownLink({ href, children, ...props }: React.ComponentPropsWithoutRef<'a'>) {\n if (href?.startsWith('#cite-')) {\n return (\n <span\n className=\"cited-text after:ml-px after:align-super after:text-[max(0.8em,var(--text-xs))] after:font-semibold after:text-muted-foreground after:content-[attr(data-cite)]\"\n data-cite={href.slice(6)}\n >\n {children}\n </span>\n )\n }\n const isInternal = !href || href.startsWith('#') || href.startsWith('cite:')\n return (\n <a\n className=\"text-primary underline underline-offset-2\"\n href={href}\n {...(isInternal ? {} : { target: '_blank', rel: 'noopener noreferrer' })}\n {...props}\n >\n {children}\n </a>\n )\n}\n\n/**\n * Default component overrides. Spreads the shared brand-neutral base\n * (`markdownBaseComponents`: headings, lists, paragraphs, emphasis, hr…) and adds\n * the elements that carry behaviour or need self-contained styling: safe links,\n * code (inline + fenced), bordered tables and blockquotes. Module-scoped so the\n * reference is stable across renders and react-markdown can skip re-parsing.\n */\nconst defaultComponents: Partial<Components> = {\n ...markdownBaseComponents,\n a: MarkdownLink,\n em: ({ children, ...props }: React.ComponentPropsWithoutRef<'em'>) => (\n <em className=\"italic\" {...props}>\n {children}\n </em>\n ),\n code: function MarkdownCode({\n className,\n children,\n ...props\n }: React.ComponentPropsWithoutRef<'code'>) {\n const match = /language-(\\w+)/.exec(className || '')\n if (!match) {\n return (\n <code\n className=\"rounded bg-current/10 px-1 py-0.5 font-mono text-[0.9em]\"\n data-testid=\"markdown-inline-code\"\n {...props}\n >\n {children}\n </code>\n )\n }\n return <CodeBlock language={match[1]} code={String(children).replace(/\\n$/, '')} />\n },\n // The CodeBlock renders its own <pre>; unwrap react-markdown's wrapper so we\n // don't nest <pre><pre>.\n pre: ({ children }: React.ComponentPropsWithoutRef<'pre'>) => <>{children}</>,\n blockquote: ({ children, ...props }: React.ComponentPropsWithoutRef<'blockquote'>) => (\n <blockquote className=\"border-l-2 border-border pl-4 italic text-muted-foreground\" {...props}>\n {children}\n </blockquote>\n ),\n table: MarkdownTable,\n thead: ({ children, ...props }: React.ComponentPropsWithoutRef<'thead'>) => (\n <thead className=\"bg-current/10\" {...props}>\n {children}\n </thead>\n ),\n th: ({ children, ...props }: React.ComponentPropsWithoutRef<'th'>) => (\n <th\n className=\"min-w-[7rem] border-b border-border px-3 py-2 text-left font-semibold\"\n {...props}\n >\n {children}\n </th>\n ),\n td: ({ children, ...props }: React.ComponentPropsWithoutRef<'td'>) => (\n <td className=\"min-w-[7rem] border-b border-border px-3 py-2 align-top\" {...props}>\n {children}\n </td>\n ),\n // General emphasis marks (GFM `~~strikethrough~~` → <del>, raw <ins>/<mark>).\n del: ({ children, ...props }: React.ComponentPropsWithoutRef<'del'>) => (\n <del className=\"text-muted-foreground line-through\" {...props}>\n {children}\n </del>\n ),\n ins: ({ children, ...props }: React.ComponentPropsWithoutRef<'ins'>) => (\n <ins className=\"underline decoration-primary/60\" {...props}>\n {children}\n </ins>\n ),\n mark: ({ children, ...props }: React.ComponentPropsWithoutRef<'mark'>) => (\n <mark className=\"rounded bg-primary/15 px-0.5 text-inherit\" {...props}>\n {children}\n </mark>\n ),\n}\n\n// Stable module-scope plugin arrays so react-markdown compares them by reference\n// and skips re-running the remark/rehype pipeline when nothing else changed.\n// `rehype-raw` enables inline HTML (e.g. redline <del>/<ins>); no math/mermaid\n// plugins are bundled to keep the kit light.\nconst remarkPlugins = [remarkGfm]\nconst rehypePlugins = [rehypeRaw]\n\n/**\n * One parsed markdown block, memoised on (content, components) so already-rendered\n * blocks don't re-parse when a later block streams new tokens. This is the core\n * of the streaming-rendering optimisation.\n */\nconst MemoizedBlock = React.memo(function MarkdownBlock({\n content,\n components,\n}: {\n content: string\n components: Partial<Components>\n}) {\n return (\n <Markdown remarkPlugins={remarkPlugins} rehypePlugins={rehypePlugins} components={components}>\n {content}\n </Markdown>\n )\n})\n\n/** Prevents a malformed-markdown render error from crashing the whole surface. */\nclass MarkdownErrorBoundary extends React.Component<\n { fallback: React.ReactNode; children: React.ReactNode },\n { hasError: boolean }\n> {\n state = { hasError: false }\n static getDerivedStateFromError() {\n return { hasError: true }\n }\n render() {\n return this.state.hasError ? this.props.fallback : this.props.children\n }\n}\n\nexport interface MarkdownRendererProps {\n /** Markdown content to render. */\n children: string\n /** Custom component overrides merged on top of the defaults. */\n components?: Partial<Components>\n /**\n * When true, signals heavy custom components (via `MarkdownStreamingContext`)\n * to defer their work while tokens are still arriving. Defaults to false.\n */\n isStreaming?: boolean\n /**\n * Renders a citation marker `[words](#cite-N)`: `children` are the cited words, `num` the N.\n * Keep it referentially stable (`useCallback`/`useMemo`), or every block re-parses.\n */\n renderCitation?: (citation: { num: string; children: React.ReactNode }) => React.ReactNode\n /** Extra classes on the wrapper (font-size, prose width, etc.). */\n className?: string\n /** Overrides the `data-testid` on the wrapper (default `markdown-renderer`). */\n testId?: string\n}\n\nfunction MarkdownRendererComponent({\n children,\n components: customComponents,\n renderCitation,\n isStreaming = false,\n className,\n testId = 'markdown-renderer',\n}: MarkdownRendererProps) {\n const components = useMemo(() => {\n const base = customComponents\n ? { ...defaultComponents, ...customComponents }\n : defaultComponents\n if (!renderCitation) return base\n const Link = base.a ?? MarkdownLink\n return {\n ...base,\n a: (props: React.ComponentPropsWithoutRef<'a'>) =>\n props.href?.startsWith('#cite-')\n ? renderCitation({ num: props.href.slice(6), children: props.children })\n : React.createElement(Link as React.ElementType, props),\n }\n }, [customComponents, renderCitation])\n\n const blocks = useMemo(\n () =>\n splitMarkdownBlocks(\n normalizeCitationMarkup(\n isStreaming ? closeOpenEmphasis(trimOpenCitation(children)) : children\n )\n ),\n [children, isStreaming]\n )\n\n return (\n <MarkdownErrorBoundary\n fallback={<div className={cn('whitespace-pre-wrap break-words', className)}>{children}</div>}\n >\n <MarkdownStreamingContext.Provider value={isStreaming}>\n <div\n className={cn('markdown-content space-y-3 break-words leading-relaxed', className)}\n data-testid={testId}\n >\n {blocks.map((block, index) => (\n <MemoizedBlock key={index} content={block} components={components} />\n ))}\n </div>\n </MarkdownStreamingContext.Provider>\n </MarkdownErrorBoundary>\n )\n}\n\n/**\n * Memoised so a stable message in a long thread doesn't re-parse when unrelated\n * tokens arrive elsewhere; a streaming message gets a fresh `children` each flush\n * and re-renders (only its trailing block re-parses, thanks to `MemoizedBlock`).\n */\nexport const MarkdownRenderer = React.memo(MarkdownRendererComponent)\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/ai/markdown-base-components.tsx","../src/ai/markdown-streaming-context.ts","../src/ai/split-markdown-blocks.ts","../src/ai/normalize-citations.ts","../src/ai/MarkdownRenderer.tsx"],"names":["jsx","createContext","useRef","useState","useCallback","useEffect","jsxs","Check","Copy","cn","Fragment","remarkGfm","rehypeRaw","React","Markdown","useMemo"],"mappings":";;;;;;;;;;;;;;;;;AAeO,IAAM,sBAAA,GAA8C;AAAA,EACzD,EAAA,EAAI,CAAC,EAAE,QAAA,EAAU,GAAG,KAAA,EAAM,qBACxBA,cAAA,CAAC,IAAA,EAAA,EAAG,WAAU,uBAAA,EAAwB,aAAA,EAAY,oBAAA,EAAsB,GAAG,OACxE,QAAA,EACH,CAAA;AAAA,EAEF,EAAA,EAAI,CAAC,EAAE,QAAA,EAAU,GAAG,KAAA,EAAM,qBACxBA,cAAA,CAAC,IAAA,EAAA,EAAG,WAAU,yBAAA,EAA0B,aAAA,E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A,QAAC,KAAA;AAAA,QAAA;AAAA,UACC,SAAA,EAAWS,oBAAA,CAAG,wDAAA,EAA0D,SAAS,CAAA;AAAA,UACjF,aAAA,EAAa,MAAA;AAAA,UAEZ,QAAA,EAAA,MAAA,CAAO,GAAA,CAAI,CAAC,KAAA,EAAO,KAAA,qBAClBT,cAAAA,CAAC,aAAA,EAAA,EAA0B,OAAA,EAAS,KAAA,EAAO,UAAA,EAAA,EAAvB,KAA+C,CACpE;AAAA;AAAA,OACH,EACF;AAAA;AAAA,GACF;AAEJ;AAOO,IAAM,gBAAA,GAAmBa,sBAAA,CAAM,IAAA,CAAK,yBAAyB","file":"chunk-NA3FOYSF.cjs","sourcesContent":["import React from 'react'\nimport type { Components } from 'react-markdown'\n\n/**\n * Brand-neutral presentational component overrides for react-markdown, shared by\n * every markdown surface in the workspace (the monolith's `MarkdownRenderer` and\n * the AI kit's `AiMarkdown`). One house style for headings, lists, tables and the\n * inline text elements — token-based, so it themes per app.\n *\n * Deliberately excluded (kept per-consumer): `a` (external-link confirm vs\n * plain), `code`/`pre` (rich CodeBlock + Mermaid vs inline), `span` (doc-entity\n * pills), and `del`/`ins`/`mark` (general emphasis vs redline tracked-changes) —\n * these differ by intent or carry heavy/coupled behaviour, so each renderer owns\n * them and spreads this base underneath.\n */\nexport const markdownBaseComponents: Partial<Components> = {\n h1: ({ children, ...props }: React.ComponentPropsWithoutRef<'h1'>) => (\n <h1 className=\"text-lg font-semibold\" data-testid=\"markdown-heading-1\" {...props}>\n {children}\n </h1>\n ),\n h2: ({ children, ...props }: React.ComponentPropsWithoutRef<'h2'>) => (\n <h2 className=\"font-semibold text-base\" data-testid=\"markdown-heading-2\" {...props}>\n {children}\n </h2>\n ),\n h3: ({ children, ...props }: React.ComponentPropsWithoutRef<'h3'>) => (\n <h3 className=\"font-semibold text-base\" data-testid=\"markdown-heading-3\" {...props}>\n {children}\n </h3>\n ),\n h4: ({ children, ...props }: React.ComponentPropsWithoutRef<'h4'>) => (\n <h4 className=\"font-semibold text-base\" {...props}>\n {children}\n </h4>\n ),\n h5: ({ children, ...props }: React.ComponentPropsWithoutRef<'h5'>) => (\n <h5 className=\"font-medium\" {...props}>\n {children}\n </h5>\n ),\n strong: ({ children, ...props }: React.ComponentPropsWithoutRef<'strong'>) => (\n <strong className=\"font-semibold\" {...props}>\n {children}\n </strong>\n ),\n blockquote: ({ children, ...props }: React.ComponentPropsWithoutRef<'blockquote'>) => (\n <blockquote className=\"border-l-2 border-primary pl-4\" {...props}>\n {children}\n </blockquote>\n ),\n ol: ({ children, ...props }: React.ComponentPropsWithoutRef<'ol'>) => (\n <ol className=\"list-decimal space-y-2 pl-6\" data-testid=\"markdown-ordered-list\" {...props}>\n {children}\n </ol>\n ),\n ul: ({ children, ...props }: React.ComponentPropsWithoutRef<'ul'>) => (\n <ul className=\"list-none space-y-2 pl-6\" data-testid=\"markdown-unordered-list\" {...props}>\n {children}\n </ul>\n ),\n li: ({ children, ...props }: React.ComponentPropsWithoutRef<'li'>) => (\n <li className=\"my-1.5\" {...props}>\n {children}\n </li>\n ),\n table: ({ children, ...props }: React.ComponentPropsWithoutRef<'table'>) => (\n <table data-testid=\"markdown-table\" {...props}>\n {children}\n </table>\n ),\n th: ({ children, ...props }: React.ComponentPropsWithoutRef<'th'>) => (\n <th {...props}>{children}</th>\n ),\n td: ({ children, ...props }: React.ComponentPropsWithoutRef<'td'>) => (\n <td {...props}>{children}</td>\n ),\n tr: ({ children, ...props }: React.ComponentPropsWithoutRef<'tr'>) => (\n <tr {...props}>{children}</tr>\n ),\n p: ({ children, ...props }: React.ComponentPropsWithoutRef<'p'>) => (\n <p className=\"whitespace-pre-wrap\" {...props}>\n {children}\n </p>\n ),\n hr: (props: React.ComponentPropsWithoutRef<'hr'>) => (\n <hr className=\"border-foreground/20\" {...props} />\n ),\n sup: ({ children, ...props }: React.ComponentPropsWithoutRef<'sup'>) => (\n <sup className=\"text-xs\" {...props}>\n {children}\n </sup>\n ),\n sub: ({ children, ...props }: React.ComponentPropsWithoutRef<'sub'>) => (\n <sub className=\"text-xs\" {...props}>\n {children}\n </sub>\n ),\n div: ({ children, className, ...props }: React.ComponentPropsWithoutRef<'div'>) => (\n <div className={className} {...props}>\n {children}\n </div>\n ),\n br: (props: React.ComponentPropsWithoutRef<'br'>) => <br {...props} />,\n kbd: ({ children, ...props }: React.ComponentPropsWithoutRef<'kbd'>) => (\n <kbd\n className=\"px-1.5 py-0.5 text-xs font-mono bg-muted border border-border rounded\"\n {...props}\n >\n {children}\n </kbd>\n ),\n abbr: ({ children, title, ...props }: React.ComponentPropsWithoutRef<'abbr'>) => (\n <abbr title={title} className=\"underline decoration-dotted cursor-help\" {...props}>\n {children}\n </abbr>\n ),\n cite: ({ children, ...props }: React.ComponentPropsWithoutRef<'cite'>) => (\n <cite className=\"italic\" {...props}>\n {children}\n </cite>\n ),\n}\n","import { createContext } from 'react'\n\n/**\n * Signals to `MarkdownRenderer`'s component overrides that the surrounding\n * message is still streaming tokens. Heavy renderers can defer their work while\n * this is true to avoid burning CPU on partially complete fences and to keep the\n * UI responsive during long generations.\n *\n * Default `false` means non-streaming usages (parsed documents, static answers,\n * DM bubbles) get the full rendering with no behaviour change.\n */\nexport const MarkdownStreamingContext = createContext(false)\n","/**\n * Splits a markdown string into top-level blocks at `\\n\\n` boundaries.\n *\n * Streaming AI responses arrive token-by-token; passing the full string to\n * react-markdown re-parses the entire AST on every flush. By splitting into\n * blocks and memoizing each, only the trailing (still-growing) block re-parses\n * — completed blocks stay frozen in the DOM.\n *\n * The split avoids three correctness pitfalls:\n * - never splits inside an open ``` code fence (would corrupt the language)\n * - never splits between two adjacent list items (would render as two lists)\n * - never splits between two blockquote lines (would render as two quotes)\n */\nconst LIST_ITEM_RE = /^\\s*([-*+]|\\d+[.)])\\s/\nconst BLOCKQUOTE_RE = /^\\s*>/\n\nexport function splitMarkdownBlocks(content: string): string[] {\n if (!content) return []\n const blocks: string[] = []\n let start = 0\n let inFence = false\n let i = 0\n while (i < content.length) {\n if (content.startsWith('```', i)) {\n inFence = !inFence\n i += 3\n continue\n }\n if (!inFence && content[i] === '\\n' && content[i + 1] === '\\n') {\n const before = content.slice(start, i)\n const lastLine = before.slice(before.lastIndexOf('\\n') + 1)\n const afterStart = i + 2\n const nextNewline = content.indexOf('\\n', afterStart)\n const nextLine = content.slice(afterStart, nextNewline === -1 ? undefined : nextNewline)\n const bothListItems = LIST_ITEM_RE.test(lastLine) && LIST_ITEM_RE.test(nextLine)\n const bothBlockquotes = BLOCKQUOTE_RE.test(lastLine) && BLOCKQUOTE_RE.test(nextLine)\n if (bothListItems || bothBlockquotes) {\n i += 2\n continue\n }\n blocks.push(content.slice(start, afterStart))\n start = afterStart\n i = afterStart\n continue\n }\n i++\n }\n if (start < content.length) blocks.push(content.slice(start))\n return blocks\n}\n","/**\n * Citation markup normaliser.\n *\n * The backend marks a cited statement as a markdown link, `[statement](#cite-N)`, and the\n * statement can include the markdown that surrounds it: a list marker, a heading marker or the\n * opener of a bold/italic span whose closer sits after the link. Inside link text those tokens\n * are not parsed as block or inline syntax, so they show literally and break lists and bold:\n *\n * [- **Claimed quantum (by Claimant)](#cite-1):** **USD 47 million**\n *\n * `normalizeCitationMarkup` hoists the leading tokens out of the link text (and a trailing\n * emphasis closer after it), so the link only wraps the words:\n *\n * - **[Claimed quantum (by Claimant)](#cite-1):** **USD 47 million**\n *\n * It is conservative: emphasis that opens and closes inside the link text is valid markdown and\n * is left alone, an opener is only hoisted when its closer follows on the same line, and fenced\n * code blocks are never touched. The result is idempotent.\n *\n * It also tidies the residue the model leaves when it cites in prose as well: a literal\n * `(*Source: Award.pdf, p. 12*)` shows its asterisks, because `(*` does not open emphasis. It\n * becomes the italic note `*(Source: Award.pdf, p. 12)*`.\n */\n\nconst SOURCE_RESIDUE = /\\(\\*+\\s*(Sources?\\s*:[^\\n]*?)\\s*\\*+\\)/g\n\nconst CITE_CLOSE = /^\\]\\((#cite-[\\w-]+)\\)/\nconst BLOCK_MARKER = /^(?:[-*+]|\\d{1,9}[.)]|#{1,6})[ \\t]+/\nconst LEADING_EMPHASIS = /^(?:\\*\\*|__|\\*|_)+/\nconst TRAILING_EMPHASIS = /(\\*\\*|__|\\*|_)(:?)$/\n\n/** Occurrences of `token` in `text`; a single `*` is counted outside any `**` pair. */\nfunction countToken(text: string, token: string): number {\n const double = token + token\n if (token.length === 2) return text.split(token).length - 1\n const withoutDouble = text.split(double).join('')\n return withoutDouble.split(token).length - 1\n}\n\n/** Split a run of emphasis characters (`***`, `**`, `*`...) into its parser-level tokens. */\nfunction emphasisTokens(run: string): string[] {\n const char = run[0]\n const tokens: string[] = []\n let rest = run\n while (rest.length > 0) {\n const size = rest.length >= 2 ? 2 : 1\n tokens.push(char.repeat(size))\n rest = rest.slice(size)\n }\n return tokens\n}\n\nfunction hoistFromLink(text: string, before: string, after: string): [string, string, string] {\n let body = text\n let prefix = ''\n let suffix = ''\n\n if (before.trim() === '') {\n const marker = BLOCK_MARKER.exec(body)\n if (marker) {\n prefix += marker[0]\n body = body.slice(marker[0].length)\n }\n }\n\n // The link opened inside an emphasis span: `*Sources:[* Letter](#cite-2)`. A leading token that\n // the text before the link left open, and that is followed by a space, is the span's CLOSER (an\n // opener cannot precede a space), so it moves out in front of the link with its space.\n const closer = /^(\\*\\*|__|\\*|_)(\\s+)(?=\\S)/.exec(body)\n if (closer && countToken(before + prefix, closer[1]) % 2 === 1) {\n prefix += closer[1] + closer[2]\n body = body.slice(closer[0].length)\n }\n\n const leading = LEADING_EMPHASIS.exec(body)\n if (leading) {\n let kept = ''\n let rest = body.slice(leading[0].length)\n for (const token of emphasisTokens(leading[0]).reverse()) {\n // Balanced inside the link text: valid as written.\n if (countToken(rest, token) % 2 === 1) {\n kept = token + kept\n continue\n }\n // Unmatched here: hoist only if the line closes it after the link.\n if (countToken(after, token) % 2 === 1) prefix += token\n else kept = token + kept\n }\n body = kept + rest\n rest = ''\n }\n\n // A span opened before the link and closed inside it (`**Spence v. [Costa Rica** arbitration.]`)\n // cannot close across the link boundary: move the words up to the closer out of the link.\n for (const token of ['**', '__']) {\n const at = body.indexOf(token)\n if (at === -1 || countToken(body, token) % 2 === 0) continue\n if (countToken(before + prefix, token) % 2 === 0) continue\n const rest = body.slice(at + token.length)\n if (!/[\\p{L}\\p{N}]/u.test(rest)) continue\n prefix +=\n body.slice(0, at + token.length) + rest.slice(0, rest.length - rest.trimStart().length)\n body = rest.trimStart()\n break\n }\n\n const trailing = TRAILING_EMPHASIS.exec(body)\n if (trailing) {\n const token = trailing[1]\n const inner = body.slice(0, body.length - trailing[0].length)\n const openedBefore = countToken(before + prefix, token) % 2 === 1\n if (countToken(inner, token) % 2 === 0 && openedBefore) {\n body = inner\n suffix = trailing[0]\n }\n }\n\n // The link ends inside an emphasis span that closes after it: `*(Source](#cite-1): a.md)*`. The\n // unmatched opener and the words after it leave the link, so the span opens and closes in the\n // same text again: `[words](#cite-1) *(Source: a.md)*`.\n if (!suffix) {\n for (const token of ['**', '*']) {\n const at = lastUnmatchedOpener(body, token)\n if (at > 0 && countToken(after, token) % 2 === 1) {\n suffix = ' ' + body.slice(at)\n body = body.slice(0, at).trimEnd()\n break\n }\n }\n }\n\n return [prefix, body, suffix]\n}\n\n/** Index of the last `token` in `text` that opens emphasis (followed by a non-space) and has no closer. */\nfunction lastUnmatchedOpener(text: string, token: string): number {\n if (countToken(text, token) % 2 === 0) return -1\n const pattern = token === '**' ? /\\*\\*(?=\\S)/g : /(?<!\\*)\\*(?![*\\s])/g\n let at = -1\n for (const m of text.matchAll(pattern)) at = m.index ?? -1\n return at\n}\n\ninterface CiteLink {\n start: number\n end: number\n text: string\n href: string\n}\n\n/**\n * The `[text](#cite-N)` links of a line. The text may hold brackets of its own\n * (`[2. **[PLACEHOLDER]** names the claimant.](#cite-3)`), so a regex cannot find the opener: a\n * stack of `[` is scanned, and a `](#cite-N)` takes the nearest open one.\n */\nfunction findCiteLinks(line: string): CiteLink[] {\n const links: CiteLink[] = []\n const open: number[] = []\n for (let i = 0; i < line.length; i++) {\n const c = line[i]\n if (c === '[') open.push(i)\n else if (c === ']') {\n const opener = open.pop()\n const close = CITE_CLOSE.exec(line.slice(i, i + 40))\n if (opener !== undefined && close) {\n links.push({\n start: opener,\n end: i + close[0].length,\n text: line.slice(opener + 1, i),\n href: close[1],\n })\n i += close[0].length - 1\n }\n }\n }\n return links.sort((x, y) => x.start - y.start)\n}\n\nfunction normalizeLine(line: string): string {\n if (!line.includes('](#cite-')) return line\n let out = ''\n let last = 0\n for (const link of findCiteLinks(line)) {\n // A link inside another link's text is part of that text.\n if (link.start < last) continue\n // Markdown links do not nest: a citation that wraps another citation (`[a [9](#cite-9)](#cite-10)`)\n // keeps the words and the inner mark, and the outer wrapper is dropped.\n if (link.text.includes('](#cite-')) {\n out += line.slice(last, link.start) + link.text\n last = link.end\n continue\n }\n const before = line.slice(0, link.start)\n const after = line.slice(link.end)\n const [prefix, body, suffix] = hoistFromLink(link.text, before, after)\n out += line.slice(last, link.start)\n out += `${prefix}[${body}](${link.href})${suffix}`\n last = link.end\n }\n return out + line.slice(last)\n}\n\nfunction normalizeSourceResidue(line: string): string {\n return line.includes('(*') ? line.replace(SOURCE_RESIDUE, '*($1)*') : line\n}\n\nexport function normalizeCitationMarkup(markdown: string): string {\n if (!markdown.includes('](#cite-') && !markdown.includes('(*')) return markdown\n let inFence = false\n return markdown\n .split('\\n')\n .map((line) => {\n if (/^\\s*(```|~~~)/.test(line)) {\n inFence = !inFence\n return line\n }\n return inFence ? line : normalizeSourceResidue(normalizeLine(line))\n })\n .join('\\n')\n}\n\n/** A trailing, still-open `[words](#cite-N` marker (or an unclosed `[words`) on the last line. */\nconst OPEN_CITATION_TAIL = /\\[[^\\]\\n]*(?:\\](?:\\((?:#(?:c(?:i(?:t(?:e(?:-[\\w-]*)?)?)?)?)?)?)?)?$/\n\n/**\n * Drops an unfinished citation marker from the end of text that is still streaming (or was\n * stopped mid-marker), so `[Change of control](#cite-` never shows as raw markup: the words appear\n * once the marker is complete. Complete markers and everything else are left alone.\n */\nexport function trimOpenCitation(markdown: string): string {\n return markdown.replace(OPEN_CITATION_TAIL, '')\n}\n\n/** `**` pairs outside inline code in a line. */\nfunction boldMarks(line: string): number {\n return (line.replace(/`[^`]*`/g, '').match(/\\*\\*/g) ?? []).length\n}\n\n/**\n * Makes the tail of text that is still streaming (or was stopped) render cleanly: a `**` opened\n * in the last line and not yet closed (`| Valuation | **[USD 6.2 million](#cite-2)`) would show as\n * literal asterisks until its closer arrives, because an unclosed emphasis is not emphasis. The\n * open bold is closed at the end of the line, or removed when it has no text yet (`| **`, or a\n * half-typed closer `**USD 6*`). Text with balanced emphasis, and every line but the last, is\n * left alone. Apply after `trimOpenCitation`.\n */\nexport function closeOpenEmphasis(markdown: string): string {\n const cut = markdown.lastIndexOf('\\n') + 1\n const head = markdown.slice(0, cut)\n const fences = head.split('\\n').filter((l) => /^\\s*(```|~~~)/.test(l)).length\n let line = markdown.slice(cut)\n if (fences % 2 === 1 || /^\\s*(```|~~~)/.test(line)) return markdown\n // A half-typed opener: the first `*` of `**` after a space or a cell border.\n line = line.replace(/(^|[\\s|])\\*$/, '$1')\n if (boldMarks(line) % 2 === 0) return head + line\n // A half-typed closer: `**USD 6*` -> the second asterisk has not arrived.\n line = line.replace(/([^*\\s])\\*$/, '$1')\n if (boldMarks(line) % 2 === 0) return head + line\n if (/\\*\\*\\s*$/.test(line)) return head + line.replace(/\\s*\\*\\*\\s*$/, ' ')\n return head + line + '**'\n}\n","import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react'\nimport Markdown, { type Components } from 'react-markdown'\nimport remarkGfm from 'remark-gfm'\nimport rehypeRaw from 'rehype-raw'\nimport { Copy, Check } from 'lucide-react'\nimport { cn } from '../lib/utils'\nimport { markdownBaseComponents } from './markdown-base-components'\nimport { MarkdownStreamingContext } from './markdown-streaming-context'\nimport { splitMarkdownBlocks } from './split-markdown-blocks'\nimport { closeOpenEmphasis, normalizeCitationMarkup, trimOpenCitation } from './normalize-citations'\n\n/**\n * MarkdownRenderer — the single, full-featured markdown surface for the kit.\n *\n * Renders AI answers, chat/DM messages and parsed-document panes with one house\n * style: headings, paragraphs, bold/italic, ordered/unordered lists, GFM tables,\n * fenced code blocks (monospace + copy button), inline code, blockquotes, safe\n * links (`rel=\"noopener\"`, new tab) and horizontal rules.\n *\n * Styling is 100% semantic Tailwind tokens (`text-foreground`,\n * `text-muted-foreground`, `border-border`, `bg-muted`, `text-primary`) so it\n * themes per firm — no hardcoded brand colours. It sizes to its container, so it\n * looks right in a compact chat bubble and in a full-width document pane alike.\n *\n * Streaming: the content is split into block-level chunks (see\n * `splitMarkdownBlocks`) and each chunk is memoised, so streaming token updates\n * only re-parse the trailing block instead of the whole message. Pass\n * `isStreaming` to let heavy custom components defer via `MarkdownStreamingContext`.\n *\n * Extending: pass `components` to override any element (the kit's `AiMarkdown`\n * and `CitationRenderer` layer their accent links / citation popovers on top).\n */\n\nconst EDGE_FADE = '1.5rem'\n\n/**\n * A GFM table in its own horizontal scroller. The table keeps a minimum width per column\n * (`min-w-[7rem]` cells, words never broken mid-word), so on a narrow screen it scrolls sideways\n * inside this wrapper instead of squeezing cells to a letter per line. The edge(s) with more\n * content to scroll to fade out, which is the scroll hint. Wide containers are unchanged: the\n * table is `w-full` and nothing overflows.\n */\nfunction MarkdownTable({ children, ...props }: React.ComponentPropsWithoutRef<'table'>) {\n const ref = useRef<HTMLDivElement>(null)\n const [edges, setEdges] = useState({ start: false, end: false })\n const measure = useCallback(() => {\n const el = ref.current\n if (!el) return\n const start = el.scrollLeft > 1\n const end = el.scrollLeft + el.clientWidth < el.scrollWidth - 1\n setEdges((prev) => (prev.start === start && prev.end === end ? prev : { start, end }))\n }, [])\n useEffect(() => {\n const el = ref.current\n if (!el) return\n measure()\n if (typeof ResizeObserver === 'undefined') return\n const observer = new ResizeObserver(measure)\n observer.observe(el)\n if (el.firstElementChild) observer.observe(el.firstElementChild)\n return () => observer.disconnect()\n }, [measure])\n const mask =\n edges.start || edges.end\n ? `linear-gradient(to right, ${edges.start ? 'transparent' : '#000'}, #000 ${EDGE_FADE}, #000 calc(100% - ${EDGE_FADE}), ${edges.end ? 'transparent' : '#000'})`\n : undefined\n return (\n <div\n ref={ref}\n onScroll={measure}\n data-testid=\"markdown-table-scroller\"\n data-scroll-start={edges.start || undefined}\n data-scroll-end={edges.end || undefined}\n className=\"my-3 overflow-x-auto rounded-lg border border-border\"\n style={mask ? { maskImage: mask, WebkitMaskImage: mask } : undefined}\n >\n <table\n data-testid=\"markdown-table\"\n className=\"w-full border-collapse text-sm [overflow-wrap:normal] [word-break:normal]\"\n {...props}\n >\n {children}\n </table>\n </div>\n )\n}\n\n/** Fenced code block with a language label and copy-to-clipboard button. */\nfunction CodeBlock({ language, code }: { language: string; code: string }) {\n const [copied, setCopied] = useState(false)\n\n const handleCopy = async () => {\n try {\n await navigator.clipboard.writeText(code)\n setCopied(true)\n setTimeout(() => setCopied(false), 2000)\n } catch {\n // Clipboard unavailable (insecure context / permissions) — no-op.\n }\n }\n\n return (\n <div\n className=\"code-block relative my-3 overflow-hidden rounded-md border border-current/20 bg-current/5\"\n data-testid=\"markdown-code-block\"\n >\n <div className=\"flex items-center justify-between border-b border-current/20 px-3 py-1.5\">\n <span className=\"font-mono text-xs text-muted-foreground\">{language || 'code'}</span>\n <button\n type=\"button\"\n onClick={handleCopy}\n className=\"flex items-center gap-1 text-xs text-muted-foreground transition-colors hover:text-foreground\"\n title={copied ? 'Copied!' : 'Copy code'}\n >\n {copied ? <Check size={12} /> : <Copy size={12} />}\n <span>{copied ? 'Copied' : 'Copy'}</span>\n </button>\n </div>\n <pre className=\"overflow-x-auto p-3 text-sm leading-relaxed\">\n <code className={cn('font-mono', language && `language-${language}`)}>{code}</code>\n </pre>\n </div>\n )\n}\n\n/**\n * Links. Internal hash/anchor links stay in-page; everything else opens safely in a new tab\n * (`rel=\"noopener noreferrer\"` prevents reverse-tabnabbing). A backend citation marker\n * (`#cite-N`) has no popover here: the cited words stay in the surface's own colour with a quiet\n * superscript number after them (no underline, so a cited sentence does not read as a link).\n * Pass `renderCitation` to `MarkdownRenderer` to swap in a real source popover.\n */\nfunction MarkdownLink({ href, children, ...props }: React.ComponentPropsWithoutRef<'a'>) {\n if (href?.startsWith('#cite-')) {\n return (\n <span\n className=\"cited-text after:ml-px after:align-super after:text-[max(0.8em,var(--text-xs))] after:font-semibold after:text-muted-foreground after:content-[attr(data-cite)]\"\n data-cite={href.slice(6)}\n >\n {children}\n </span>\n )\n }\n const isInternal = !href || href.startsWith('#') || href.startsWith('cite:')\n return (\n <a\n className=\"text-primary underline underline-offset-2\"\n href={href}\n {...(isInternal ? {} : { target: '_blank', rel: 'noopener noreferrer' })}\n {...props}\n >\n {children}\n </a>\n )\n}\n\n/**\n * Default component overrides. Spreads the shared brand-neutral base\n * (`markdownBaseComponents`: headings, lists, paragraphs, emphasis, hr…) and adds\n * the elements that carry behaviour or need self-contained styling: safe links,\n * code (inline + fenced), bordered tables and blockquotes. Module-scoped so the\n * reference is stable across renders and react-markdown can skip re-parsing.\n */\nconst defaultComponents: Partial<Components> = {\n ...markdownBaseComponents,\n a: MarkdownLink,\n em: ({ children, ...props }: React.ComponentPropsWithoutRef<'em'>) => (\n <em className=\"italic\" {...props}>\n {children}\n </em>\n ),\n code: function MarkdownCode({\n className,\n children,\n ...props\n }: React.ComponentPropsWithoutRef<'code'>) {\n const match = /language-(\\w+)/.exec(className || '')\n if (!match) {\n return (\n <code\n className=\"rounded bg-current/10 px-1 py-0.5 font-mono text-[0.9em]\"\n data-testid=\"markdown-inline-code\"\n {...props}\n >\n {children}\n </code>\n )\n }\n return <CodeBlock language={match[1]} code={String(children).replace(/\\n$/, '')} />\n },\n // The CodeBlock renders its own <pre>; unwrap react-markdown's wrapper so we\n // don't nest <pre><pre>.\n pre: ({ children }: React.ComponentPropsWithoutRef<'pre'>) => <>{children}</>,\n blockquote: ({ children, ...props }: React.ComponentPropsWithoutRef<'blockquote'>) => (\n <blockquote className=\"border-l-2 border-border pl-4 italic text-muted-foreground\" {...props}>\n {children}\n </blockquote>\n ),\n table: MarkdownTable,\n thead: ({ children, ...props }: React.ComponentPropsWithoutRef<'thead'>) => (\n <thead className=\"bg-current/10\" {...props}>\n {children}\n </thead>\n ),\n th: ({ children, ...props }: React.ComponentPropsWithoutRef<'th'>) => (\n <th\n className=\"min-w-[7rem] border-b border-border px-3 py-2 text-left font-semibold\"\n {...props}\n >\n {children}\n </th>\n ),\n td: ({ children, ...props }: React.ComponentPropsWithoutRef<'td'>) => (\n <td className=\"min-w-[7rem] border-b border-border px-3 py-2 align-top\" {...props}>\n {children}\n </td>\n ),\n // General emphasis marks (GFM `~~strikethrough~~` → <del>, raw <ins>/<mark>).\n del: ({ children, ...props }: React.ComponentPropsWithoutRef<'del'>) => (\n <del className=\"text-muted-foreground line-through\" {...props}>\n {children}\n </del>\n ),\n ins: ({ children, ...props }: React.ComponentPropsWithoutRef<'ins'>) => (\n <ins className=\"underline decoration-primary/60\" {...props}>\n {children}\n </ins>\n ),\n mark: ({ children, ...props }: React.ComponentPropsWithoutRef<'mark'>) => (\n <mark className=\"rounded bg-primary/15 px-0.5 text-inherit\" {...props}>\n {children}\n </mark>\n ),\n}\n\n// Stable module-scope plugin arrays so react-markdown compares them by reference\n// and skips re-running the remark/rehype pipeline when nothing else changed.\n// `rehype-raw` enables inline HTML (e.g. redline <del>/<ins>); no math/mermaid\n// plugins are bundled to keep the kit light.\nconst remarkPlugins = [remarkGfm]\nconst rehypePlugins = [rehypeRaw]\n\n/**\n * One parsed markdown block, memoised on (content, components) so already-rendered\n * blocks don't re-parse when a later block streams new tokens. This is the core\n * of the streaming-rendering optimisation.\n */\nconst MemoizedBlock = React.memo(function MarkdownBlock({\n content,\n components,\n}: {\n content: string\n components: Partial<Components>\n}) {\n return (\n <Markdown remarkPlugins={remarkPlugins} rehypePlugins={rehypePlugins} components={components}>\n {content}\n </Markdown>\n )\n})\n\n/** Prevents a malformed-markdown render error from crashing the whole surface. */\nclass MarkdownErrorBoundary extends React.Component<\n { fallback: React.ReactNode; children: React.ReactNode },\n { hasError: boolean }\n> {\n state = { hasError: false }\n static getDerivedStateFromError() {\n return { hasError: true }\n }\n render() {\n return this.state.hasError ? this.props.fallback : this.props.children\n }\n}\n\nexport interface MarkdownRendererProps {\n /** Markdown content to render. */\n children: string\n /** Custom component overrides merged on top of the defaults. */\n components?: Partial<Components>\n /**\n * When true, signals heavy custom components (via `MarkdownStreamingContext`)\n * to defer their work while tokens are still arriving. Defaults to false.\n */\n isStreaming?: boolean\n /**\n * Renders a citation marker `[words](#cite-N)`: `children` are the cited words, `num` the N.\n * Keep it referentially stable (`useCallback`/`useMemo`), or every block re-parses.\n */\n renderCitation?: (citation: { num: string; children: React.ReactNode }) => React.ReactNode\n /** Extra classes on the wrapper (font-size, prose width, etc.). */\n className?: string\n /** Overrides the `data-testid` on the wrapper (default `markdown-renderer`). */\n testId?: string\n}\n\nfunction MarkdownRendererComponent({\n children,\n components: customComponents,\n renderCitation,\n isStreaming = false,\n className,\n testId = 'markdown-renderer',\n}: MarkdownRendererProps) {\n const components = useMemo(() => {\n const base = customComponents\n ? { ...defaultComponents, ...customComponents }\n : defaultComponents\n if (!renderCitation) return base\n const Link = base.a ?? MarkdownLink\n return {\n ...base,\n a: (props: React.ComponentPropsWithoutRef<'a'>) =>\n props.href?.startsWith('#cite-')\n ? renderCitation({ num: props.href.slice(6), children: props.children })\n : React.createElement(Link as React.ElementType, props),\n }\n }, [customComponents, renderCitation])\n\n const blocks = useMemo(\n () =>\n splitMarkdownBlocks(\n normalizeCitationMarkup(\n isStreaming ? closeOpenEmphasis(trimOpenCitation(children)) : children\n )\n ),\n [children, isStreaming]\n )\n\n return (\n <MarkdownErrorBoundary\n fallback={<div className={cn('whitespace-pre-wrap break-words', className)}>{children}</div>}\n >\n <MarkdownStreamingContext.Provider value={isStreaming}>\n <div\n className={cn('markdown-content space-y-3 break-words leading-relaxed', className)}\n data-testid={testId}\n >\n {blocks.map((block, index) => (\n <MemoizedBlock key={index} content={block} components={components} />\n ))}\n </div>\n </MarkdownStreamingContext.Provider>\n </MarkdownErrorBoundary>\n )\n}\n\n/**\n * Memoised so a stable message in a long thread doesn't re-parse when unrelated\n * tokens arrive elsewhere; a streaming message gets a fresh `children` each flush\n * and re-renders (only its trailing block re-parses, thanks to `MemoizedBlock`).\n */\nexport const MarkdownRenderer = React.memo(MarkdownRendererComponent)\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/artifacts/normalize-markdown.ts","../src/artifacts/redline-diff.ts"],"names":["unified","remarkParse","remarkGfm","remarkStringify","diffLines","diffWords"],"mappings":";;;;;;;;;;;;;;;AAeA,IAAM,4BAAA,GAA+B,wCAAA;AAErC,IAAM,SAAA,GAAYA,eAAA,EAAQ,CACvB,GAAA,CAAIC,4BAAW,CAAA,CAEf,GAAA,CAAIC,0BAAA,EAAW,EAAE,cAAA,EAAgB,KAAA,EAAO,CAAA,CACxC,IAAIC,gCAAA,EAAiB;AAAA,EACpB,MAAA,EAAQ,GAAA;AAAA,EACR,WAAA,EAAa,GAAA;AAAA,EACb,QAAA,EAAU,GAAA;AAAA,EACV,MAAA,EAAQ,GAAA;AAAA,EACR,KAAA,EAAO,GAAA;AAAA,EACP,MAAA,EAAQ,IAAA;AAAA,EACR,IAAA,EAAM,GAAA;AAAA,EACN,cAAA,EAAgB,KAAA;AAAA,EAChB,mBAAA,EAAqB,IAAA;AAAA,EACrB,YAAA,EAAc,KAAA;AAAA,EACd,QAAA,EAAU;AAAA,IACR,IAAA,EAAM,CAAC,IAAA,EAAM,OAAA,EAAS,OAAO,IAAA,KAC3B,KAAA,CAAM,IAAA,CAAK,IAAA,CAAK,KAAA,EAAO,IAAI,CAAA,CAAE,OAAA,CAAQ,8BAA8B,GAAG;AAAA;AAE5E,CAAC,CAAA;AAEH,IAAM,KAAA,uBAAY,GAAA,EAAoB;AACtC,IAAM,WAAA,GAAc,EAAA;AAGb,SAAS,kBAAkB,IAAA,EAAsB;A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,CAAK,OAAA,GAAU,IAAA,GAAO,IAAA,CAAK,KAAK,CAAA;AAAA,MACtC;AACA,MAAA,CAAA,EAAA;AAAA,IACF,CAAA,MAAA,IAAW,IAAI,OAAA,EAAS;AACtB,MAAA,MAAM,EAAA,GAAK,SAAA,CAAU,QAAA,EAAU,GAAA,CAAI,OAAO,EAAE,CAAA;AAC5C,MAAA,IAAI,EAAA,KAAO,QAAA,EAAU,GAAA,CAAI,IAAA,CAAK,IAAI,KAAK,CAAA;AAAA,IACzC,CAAA,MAAA,IAAW,IAAI,KAAA,EAAO;AACpB,MAAA,MAAM,EAAA,GAAK,SAAA,CAAU,KAAA,EAAO,EAAA,EAAI,IAAI,KAAK,CAAA;AACzC,MAAA,IAAI,EAAA,KAAO,QAAA,EAAU,GAAA,CAAI,IAAA,CAAK,IAAI,KAAK,CAAA;AAAA,IACzC,CAAA,MAAO;AACL,MAAA,GAAA,CAAI,IAAA,CAAK,IAAI,KAAK,CAAA;AAAA,IACpB;AAAA,EACF;AAEA,EAAA,OAAO,SAAA,CAAU,GAAA,CAAI,IAAA,CAAK,EAAE,GAAG,UAAU,CAAA;AAC3C","file":"chunk-PATLJSAO.cjs","sourcesContent":["/**\n * Canonical markdown form. Two texts with the same meaning but different spelling (an editor that\n * escapes `_` and `*`, `*` vs `-` bullets, padded tables, trailing spaces, `&` entities, CRLF)\n * normalise to the identical string, so a diff only reports real edits.\n *\n * Both sides are parsed with the same remark pipeline and re-stringified with fixed options. Pure\n * JS with no DOM, so it runs in a Web Worker too.\n */\nimport { unified } from 'unified'\nimport remarkParse from 'remark-parse'\nimport remarkGfm from 'remark-gfm'\nimport remarkStringify from 'remark-stringify'\n\n// An underscore between two word characters can never open emphasis (CommonMark), so the escape\n// the serializer adds there is noise. Only text nodes are touched: code keeps its backslashes.\nconst INTRAWORD_ESCAPED_UNDERSCORE = /(?<=[\\p{L}\\p{N}])\\\\_(?=[\\p{L}\\p{N}])/gu\n\nconst processor = unified()\n .use(remarkParse)\n // No column alignment: padding would make one wider cell re-space every row of the table.\n .use(remarkGfm, { tablePipeAlign: false })\n .use(remarkStringify, {\n bullet: '-',\n bulletOther: '*',\n emphasis: '*',\n strong: '*',\n fence: '`',\n fences: true,\n rule: '-',\n listItemIndent: 'one',\n incrementListMarker: true,\n resourceLink: false,\n handlers: {\n text: (node, _parent, state, info) =>\n state.safe(node.value, info).replace(INTRAWORD_ESCAPED_UNDERSCORE, '_'),\n },\n })\n\nconst cache = new Map<string, string>()\nconst CACHE_LIMIT = 16\n\n/** Normalise markdown to its canonical spelling. Falls back to a light cleanup if parsing throws. */\nexport function normalizeMarkdown(text: string): string {\n if (!text) return ''\n const hit = cache.get(text)\n if (hit !== undefined) return hit\n let out: string\n try {\n out = String(processor.processSync(text.replace(/\\r\\n?/g, '\\n'))).replace(/\\n*$/, '\\n')\n } catch {\n out = text.replace(/\\r\\n?/g, '\\n').replace(/[ \\t]+$/gm, '')\n }\n if (cache.size >= CACHE_LIMIT) cache.delete(cache.keys().next().value as string)\n cache.set(text, out)\n return out\n}\n","/**\n * Redline diff core\n *\n * Pure (no DOM, no Worker globals) logic for building a Word-style redline\n * markdown string from two flattened document texts. Lives outside the\n * worker file so it's straightforward to unit test.\n *\n * Strategy: hybrid line + word diff with structural safety.\n * 1. `diffLines` splits the texts into add/remove/equal blocks.\n * 2. For an adjacent [removed, added] pair (a modified region):\n * - If either side contains markdown structure that can't safely host\n * inline tags (code fences, table rows, horizontal rules), fall back\n * to block-level wrapping (whole-line del/ins, line by line).\n * - Otherwise run `diffWords`. Markdown leading markers (#, -, *, 1., >)\n * become unchanged word tokens, so when only the heading/list text\n * changes the marker stays *outside* the inline tags and the heading\n * still parses.\n * 3. Pure removed / added blocks (no paired counterpart) are wrapped\n * line-by-line so structural prefixes stay outside the tag.\n */\n\nimport { diffLines, diffWords } from 'diff'\nimport { normalizeMarkdown } from './normalize-markdown'\n\n// Lines that can't safely host inline <del>/<ins> tags without breaking\n// markdown parsing. Code fences, table rows, and horizontal rules.\nconst UNSAFE_LINE = /^(?:\\s*(?:```|~~~).*|\\s*\\|.*\\||\\s*(?:[-=*_]\\s*){3,})\\s*$/\n\n// Block-level markdown structural prefix. When present on a line, putting\n// it INSIDE an inline tag stops the heading/list/blockquote from parsing,\n// so we always preserve it outside the wrapping tag.\nconst STRUCTURAL_PREFIX = /^(\\s*(?:#{1,6}\\s+|[-*+]\\s+|\\d+[.)]\\s+|>\\s*)+)/\n\nfunction escapeForHtmlTag(text: string): string {\n return text.replace(/</g, '<').replace(/>/g, '>')\n}\n\nfunction wrapLineAsRedline(line: string, tag: 'del' | 'ins'): string {\n if (line === '' || line.trim() === '') return line\n if (UNSAFE_LINE.test(line)) {\n return `<${tag}>${escapeForHtmlTag(line)}</${tag}>`\n }\n const m = line.match(STRUCTURAL_PREFIX)\n if (m) {\n const prefix = m[1]\n const rest = line.slice(prefix.length)\n if (rest === '') return line\n return `${prefix}<${tag}>${escapeForHtmlTag(rest)}</${tag}>`\n }\n return `<${tag}>${escapeForHtmlTag(line)}</${tag}>`\n}\n\nfunction wrapBlockAsRedline(block: string, tag: 'del' | 'ins'): string {\n const lines = block.split('\\n')\n return lines\n .map((line, i) => {\n const wrapped = wrapLineAsRedline(line, tag)\n return i < lines.length - 1 ? wrapped + '\\n' : wrapped\n })\n .join('')\n}\n\nfunction pairContainsUnsafeLine(text: string): boolean {\n for (const line of text.split('\\n')) {\n if (UNSAFE_LINE.test(line)) return true\n }\n return false\n}\n\n// The canonical text always ends in one newline; give a result back the caller's own ending.\nfunction matchTail(result: string, raw: string): string {\n return raw.endsWith('\\n') ? result : result.replace(/\\n$/, '')\n}\n\nexport function buildHybridRedlineMarkdown(rawBase: string, rawCompare: string): string {\n // Both sides go through one canonical form so escaping-only differences are not changes.\n const baseText = normalizeMarkdown(rawBase)\n const compareText = normalizeMarkdown(rawCompare)\n const lineChanges = diffLines(baseText, compareText)\n const out: string[] = []\n\n for (let i = 0; i < lineChanges.length; i++) {\n const cur = lineChanges[i]\n const next = lineChanges[i + 1]\n\n if (cur.removed && next?.added) {\n if (pairContainsUnsafeLine(cur.value) || pairContainsUnsafeLine(next.value)) {\n out.push(wrapBlockAsRedline(cur.value, 'del'))\n out.push(wrapBlockAsRedline(next.value, 'ins'))\n } else {\n const wordChanges = diffWords(cur.value, next.value)\n for (const w of wordChanges) {\n if (w.removed) out.push(`<del>${escapeForHtmlTag(w.value)}</del>`)\n else if (w.added) out.push(`<ins>${escapeForHtmlTag(w.value)}</ins>`)\n else out.push(w.value)\n }\n }\n i++ // consume the paired added entry\n } else if (cur.removed) {\n out.push(wrapBlockAsRedline(cur.value, 'del'))\n } else if (cur.added) {\n out.push(wrapBlockAsRedline(cur.value, 'ins'))\n } else {\n out.push(cur.value)\n }\n }\n\n return matchTail(out.join(''), rawCompare)\n}\n\n// ─── Regions extension ────────────────────────────────────────────────────────\n//\n// Same redline as above, but every <del>/<ins> tag carries a stable\n// `data-cid` attribute identifying the \"change region\" it belongs to. A\n// region is the smallest independently revertable change:\n//\n// - inside a safe [REM, ADD] pair, each contiguous changed-word run is its\n// own region, so a single button can revert one phrase without touching\n// other edits in the same paragraph;\n// - unsafe pairs (tables, code fences, horizontal rules) are still one\n// region for the whole block, since line-level wrapping can't safely\n// split them;\n// - a non-adjacent [removed text == added text] pair is a *move*: both\n// endpoints share one cid, render green, and one undo reverts the move.\n//\n// `revertRedlineRegion` mirrors the same walk and rebuilds the working-tree text\n// with one region \"as if it never changed\", so cids round-trip identically\n// from build → render → revert.\n\nexport type RegionKind = 'replace' | 'remove' | 'add' | 'move'\n\nexport interface RedlineRegion {\n id: string\n kind: RegionKind\n baseText: string // what the base side has for this slice\n compareText: string // what the compare side has for this slice\n}\n\nexport interface RedlineWithRegions {\n markdown: string\n regions: RedlineRegion[]\n}\n\n// Tiny deterministic hash (FNV-1a 32-bit, hex). Stable across runs and JS\n// runtimes, with no Node-only deps so this stays browser-safe.\nfunction fnv1aHex(...parts: string[]): string {\n let h = 0x811c9dc5\n for (const part of parts) {\n h ^= 0x5f5f\n h = Math.imul(h, 0x01000193) >>> 0\n for (let i = 0; i < part.length; i++) {\n h ^= part.charCodeAt(i)\n h = Math.imul(h, 0x01000193) >>> 0\n }\n }\n return ('00000000' + h.toString(16)).slice(-8)\n}\n\n// First char of the cid encodes the kind so consumers can style without a\n// region-table lookup: p=replace r=remove a=add m=move.\nfunction makeRegionId(\n kind: RegionKind,\n baseText: string,\n compareText: string,\n seq: number\n): string {\n const prefix = kind === 'replace' ? 'p' : kind === 'remove' ? 'r' : kind === 'add' ? 'a' : 'm'\n return `${prefix}${fnv1aHex(kind, baseText, compareText, String(seq))}`\n}\n\n// Move detection: a non-adjacent removed/added pair with identical text is a\n// move. Returns the move endpoints' lineChanges-indices plus a region per\n// distinct move.\nfunction detectMoves(lineChanges: { value: string; removed?: boolean; added?: boolean }[]): {\n moveByIndex: Map<number, string>\n moveRegions: RedlineRegion[]\n} {\n const moveByIndex = new Map<number, string>()\n const moveRegions: RedlineRegion[] = []\n const removedByText = new Map<string, number[]>()\n const addedByText = new Map<string, number[]>()\n\n for (let i = 0; i < lineChanges.length; i++) {\n const c = lineChanges[i]\n if (c.removed) {\n const arr = removedByText.get(c.value) ?? []\n arr.push(i)\n removedByText.set(c.value, arr)\n } else if (c.added) {\n const arr = addedByText.get(c.value) ?? []\n arr.push(i)\n addedByText.set(c.value, arr)\n }\n }\n\n let seq = 0\n for (const [text, removedIdx] of removedByText) {\n const addedIdx = addedByText.get(text)\n if (!addedIdx || addedIdx.length === 0) continue\n if (text.trim().length === 0) continue\n const n = Math.min(removedIdx.length, addedIdx.length)\n for (let k = 0; k < n; k++) {\n const rI = removedIdx[k]\n const aI = addedIdx[k]\n if (aI === rI + 1 || rI === aI + 1) continue // adjacent = replace, not move\n if (moveByIndex.has(rI) || moveByIndex.has(aI)) continue\n const id = makeRegionId('move', text, text, seq++)\n moveByIndex.set(rI, id)\n moveByIndex.set(aI, id)\n moveRegions.push({ id, kind: 'move', baseText: text, compareText: text })\n }\n }\n\n return { moveByIndex, moveRegions }\n}\n\nfunction wrapLineWithCid(line: string, tag: 'del' | 'ins', cid: string): string {\n if (line === '' || line.trim() === '') return line\n if (UNSAFE_LINE.test(line)) {\n return `<${tag} data-cid=\"${cid}\">${escapeForHtmlTag(line)}</${tag}>`\n }\n const m = line.match(STRUCTURAL_PREFIX)\n if (m) {\n const prefix = m[1]\n const rest = line.slice(prefix.length)\n if (rest === '') return line\n return `${prefix}<${tag} data-cid=\"${cid}\">${escapeForHtmlTag(rest)}</${tag}>`\n }\n return `<${tag} data-cid=\"${cid}\">${escapeForHtmlTag(line)}</${tag}>`\n}\n\nfunction wrapBlockWithCid(block: string, tag: 'del' | 'ins', cid: string): string {\n const lines = block.split('\\n')\n return lines\n .map((line, i) => {\n const wrapped = wrapLineWithCid(line, tag, cid)\n return i < lines.length - 1 ? wrapped + '\\n' : wrapped\n })\n .join('')\n}\n\n// Word-level region emission inside a safe [REM, ADD] pair.\nfunction emitWordLevelRegions(\n basePara: string,\n comparePara: string,\n reserveId: (kind: RegionKind, baseT: string, compareT: string) => string,\n regions: RedlineRegion[]\n): string {\n const wordChanges = diffWords(basePara, comparePara)\n const out: string[] = []\n let k = 0\n while (k < wordChanges.length) {\n const w = wordChanges[k]\n const wNext = wordChanges[k + 1]\n if (w.removed && wNext?.added) {\n const id = reserveId('replace', w.value, wNext.value)\n regions.push({ id, kind: 'replace', baseText: w.value, compareText: wNext.value })\n out.push(`<del data-cid=\"${id}\">${escapeForHtmlTag(w.value)}</del>`)\n out.push(`<ins data-cid=\"${id}\">${escapeForHtmlTag(wNext.value)}</ins>`)\n k += 2\n } else if (w.removed) {\n const id = reserveId('remove', w.value, '')\n regions.push({ id, kind: 'remove', baseText: w.value, compareText: '' })\n out.push(`<del data-cid=\"${id}\">${escapeForHtmlTag(w.value)}</del>`)\n k++\n } else if (w.added) {\n const id = reserveId('add', '', w.value)\n regions.push({ id, kind: 'add', baseText: '', compareText: w.value })\n out.push(`<ins data-cid=\"${id}\">${escapeForHtmlTag(w.value)}</ins>`)\n k++\n } else {\n out.push(w.value)\n k++\n }\n }\n return out.join('')\n}\n\nexport function buildHybridRedlineWithRegions(\n rawBase: string,\n rawCompare: string\n): RedlineWithRegions {\n const baseText = normalizeMarkdown(rawBase)\n const compareText = normalizeMarkdown(rawCompare)\n const lineChanges = diffLines(baseText, compareText)\n const { moveByIndex, moveRegions } = detectMoves(lineChanges)\n const out: string[] = []\n const regions: RedlineRegion[] = [...moveRegions]\n const seenIds = new Map<string, number>()\n\n const reserveId = (kind: RegionKind, baseT: string, compareT: string): string => {\n const baseHash = fnv1aHex(kind, baseT, compareT)\n const seq = seenIds.get(baseHash) ?? 0\n seenIds.set(baseHash, seq + 1)\n return makeRegionId(kind, baseT, compareT, seq)\n }\n\n for (let i = 0; i < lineChanges.length; i++) {\n const cur = lineChanges[i]\n const next = lineChanges[i + 1]\n const moveId = moveByIndex.get(i)\n\n if (moveId) {\n const tag = cur.removed ? 'del' : 'ins'\n out.push(wrapBlockWithCid(cur.value, tag, moveId))\n continue\n }\n\n if (cur.removed && next?.added) {\n if (pairContainsUnsafeLine(cur.value) || pairContainsUnsafeLine(next.value)) {\n const id = reserveId('replace', cur.value, next.value)\n regions.push({ id, kind: 'replace', baseText: cur.value, compareText: next.value })\n out.push(wrapBlockWithCid(cur.value, 'del', id))\n out.push(wrapBlockWithCid(next.value, 'ins', id))\n } else {\n out.push(emitWordLevelRegions(cur.value, next.value, reserveId, regions))\n }\n i++\n } else if (cur.removed) {\n const id = reserveId('remove', cur.value, '')\n regions.push({ id, kind: 'remove', baseText: cur.value, compareText: '' })\n out.push(wrapBlockWithCid(cur.value, 'del', id))\n } else if (cur.added) {\n const id = reserveId('add', '', cur.value)\n regions.push({ id, kind: 'add', baseText: '', compareText: cur.value })\n out.push(wrapBlockWithCid(cur.value, 'ins', id))\n } else {\n out.push(cur.value)\n }\n }\n\n return { markdown: matchTail(out.join(''), rawCompare), regions }\n}\n\n// Word-level partial revert inside a [REM, ADD] pair.\nfunction revertWordRegion(\n basePara: string,\n comparePara: string,\n targetId: string,\n reserveId: (kind: RegionKind, baseT: string, compareT: string) => string\n): { text: string; matched: boolean } {\n const wordChanges = diffWords(basePara, comparePara)\n const out: string[] = []\n let matched = false\n let k = 0\n while (k < wordChanges.length) {\n const w = wordChanges[k]\n const wNext = wordChanges[k + 1]\n if (w.removed && wNext?.added) {\n const id = reserveId('replace', w.value, wNext.value)\n if (id === targetId) {\n out.push(w.value)\n matched = true\n } else {\n out.push(wNext.value)\n }\n k += 2\n } else if (w.removed) {\n const id = reserveId('remove', w.value, '')\n if (id === targetId) {\n out.push(w.value)\n matched = true\n }\n k++\n } else if (w.added) {\n const id = reserveId('add', '', w.value)\n if (id !== targetId) {\n out.push(w.value)\n } else {\n matched = true\n }\n k++\n } else {\n out.push(w.value)\n k++\n }\n }\n return { text: out.join(''), matched }\n}\n\n// Apply a per-region revert: rebuild the working-tree text from scratch by\n// walking the same diff and treating the target region as unchanged from\n// the base. Walking the diff ourselves (rather than string-replacing in the\n// working tree) means we don't have to worry about ambiguous matches.\nexport function revertRedlineRegion(rawBase: string, rawCompare: string, targetId: string): string {\n const baseText = normalizeMarkdown(rawBase)\n const compareText = normalizeMarkdown(rawCompare)\n const lineChanges = diffLines(baseText, compareText)\n const { moveByIndex } = detectMoves(lineChanges)\n const out: string[] = []\n const seenIds = new Map<string, number>()\n\n const reserveId = (kind: RegionKind, baseT: string, compareT: string): string => {\n const baseHash = fnv1aHex(kind, baseT, compareT)\n const seq = seenIds.get(baseHash) ?? 0\n seenIds.set(baseHash, seq + 1)\n return makeRegionId(kind, baseT, compareT, seq)\n }\n\n for (let i = 0; i < lineChanges.length; i++) {\n const cur = lineChanges[i]\n const next = lineChanges[i + 1]\n const moveId = moveByIndex.get(i)\n\n if (moveId) {\n if (moveId === targetId) {\n if (cur.removed) out.push(cur.value)\n } else {\n if (cur.added) out.push(cur.value)\n }\n continue\n }\n\n if (cur.removed && next?.added) {\n if (pairContainsUnsafeLine(cur.value) || pairContainsUnsafeLine(next.value)) {\n const id = reserveId('replace', cur.value, next.value)\n out.push(id === targetId ? cur.value : next.value)\n } else {\n const { text, matched } = revertWordRegion(cur.value, next.value, targetId, reserveId)\n out.push(matched ? text : next.value)\n }\n i++\n } else if (cur.removed) {\n const id = reserveId('remove', cur.value, '')\n if (id === targetId) out.push(cur.value)\n } else if (cur.added) {\n const id = reserveId('add', '', cur.value)\n if (id !== targetId) out.push(cur.value)\n } else {\n out.push(cur.value)\n }\n }\n\n return matchTail(out.join(''), rawCompare)\n}\n"]}
|