@supersolutions/super-chat-ui-core 0.2.3 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +3 -2
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -166,7 +166,7 @@ var SETEXT_EQUALS = /\n {0,3}=+[ \t]*$/;
|
|
|
166
166
|
var isPlainProse = (raw) => !MARKDOWN_SIGNIFICANT.test(raw) && !ORDERED_ITEM.test(raw) && !SETEXT_EQUALS.test(raw);
|
|
167
167
|
var MAX_DEPTH = 4;
|
|
168
168
|
var escapeHtml = (s) => s.replace(/\0/g, "").replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """);
|
|
169
|
-
var LINK = /\[([^\]]+)\]\((https?:\/\/(?:[^()\s]|\([^()\s]*\))
|
|
169
|
+
var LINK = /\[([^\]]+)\]\((https?:\/\/(?:[^()\s]|\([^()\s]*\))+|ref:[A-Za-z0-9._:~%=&;?-]{1,3000})\)/g;
|
|
170
170
|
var emphasize = (s) => s.replace(/~~([^~\n]+)~~/g, "<del>$1</del>").replace(/\*\*([^*]+)\*\*/g, "<strong>$1</strong>").replace(/(^|[^*])\*([^*\n]+)\*/g, "$1<em>$2</em>");
|
|
171
171
|
function inline(raw) {
|
|
172
172
|
const spans = [];
|
|
@@ -180,13 +180,14 @@ function inline(raw) {
|
|
|
180
180
|
const links = [];
|
|
181
181
|
s = s.replace(LINK, (_all, text, url) => {
|
|
182
182
|
const literal = url.replace(/\0(\d+)\0/g, (_m, i) => spanSource[Number(i)]);
|
|
183
|
-
links.push({ text, url: literal });
|
|
183
|
+
links.push({ text, url: literal, ref: literal.startsWith("ref:") });
|
|
184
184
|
return `\0L${links.length - 1}\0`;
|
|
185
185
|
});
|
|
186
186
|
s = emphasize(s).replace(
|
|
187
187
|
/\0L(\d+)\0/g,
|
|
188
188
|
(_all, i) => {
|
|
189
189
|
const link = links[Number(i)];
|
|
190
|
+
if (link.ref) return `<span class="sc-ref" data-ref="${link.url}">${emphasize(link.text)}</span>`;
|
|
190
191
|
return `<a href="${link.url}" target="_blank" rel="noopener noreferrer">${emphasize(link.text)}</a>`;
|
|
191
192
|
}
|
|
192
193
|
);
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/format.ts","../src/export.ts","../src/markdown.ts"],"sourcesContent":["// Value formatting shared by every card renderer.\n//\n// Centralised because a table cell and a stat tile showing the same number in\n// different formats is the fastest way to make an interface look untrustworthy.\n\nimport type { CardValueFormat } from \"@supersolutions/super-chat-core\";\n\nexport type FormatOptions = {\n /** BCP 47 locale. Omitted means the viewer's own. */\n locale?: string;\n /** IANA time zone for `datetime` values. Omitted means the viewer's own. */\n timeZone?: string;\n};\n\n/**\n * Fixed settings for HTML rendered ahead of the browser. A build server and a\n * viewer rarely share a locale or time zone, so server output and the first\n * client render must both use these or hydration fails.\n */\nexport const STABLE_FORMAT: FormatOptions = { locale: \"en-US\", timeZone: \"UTC\" };\n\nfunction createNumberFormats(locale?: string) {\n return {\n compact: new Intl.NumberFormat(locale, { notation: \"compact\", maximumFractionDigits: 2 }),\n plain: new Intl.NumberFormat(locale, { maximumFractionDigits: 6 }),\n pctWide: new Intl.NumberFormat(locale, { maximumFractionDigits: 1, useGrouping: false }),\n pctNarrow: new Intl.NumberFormat(locale, { maximumFractionDigits: 2, useGrouping: false }),\n };\n}\n\nconst numberFormats = new Map<string, ReturnType<typeof createNumberFormats>>();\n\nfunction numbersFor(locale?: string) {\n const key = locale ?? \"\";\n let formats = numberFormats.get(key);\n if (!formats) {\n formats = createNumberFormats(locale);\n numberFormats.set(key, formats);\n }\n return formats;\n}\n\nexport function formatValue(value: unknown, format: CardValueFormat = \"text\", options: FormatOptions = {}): string {\n if (value == null) return \"—\";\n const { locale, timeZone } = options;\n const numbers = numbersFor(locale);\n\n switch (format) {\n case \"number\": {\n const n = Number(value);\n if (!Number.isFinite(n)) return String(value);\n // Compact only above 5 digits: \"12.3K\" is helpful, \"1.2K\" hides precision\n // people expect to see on small counts.\n return Math.abs(n) >= 100_000 ? numbers.compact.format(n) : numbers.plain.format(n);\n }\n case \"currency\": {\n const n = Number(value);\n if (!Number.isFinite(n)) return String(value);\n const abs = Math.abs(n);\n // Sub-cent values are common in crypto; fixed 2dp would render them as $0.00.\n const digits = abs >= 1 ? 2 : abs >= 0.01 ? 4 : 8;\n // A whole amount in the thousands reads as \"$48,200\". Forcing \".00\" onto\n // it is the machine-printed look; amounts with cents keep them.\n const min = abs >= 1000 && Number.isInteger(n) ? 0 : 2;\n return `$${n.toLocaleString(locale, { minimumFractionDigits: min, maximumFractionDigits: Math.max(min, digits) })}`;\n }\n case \"percent\": {\n const n = Number(value);\n if (!Number.isFinite(n)) return String(value);\n // One decimal at most (\"8.2%\", \"12%\"), two only below 1% where the\n // second digit is the signal (\"0.04%\"). A fixed \"8.20%\" is false precision.\n return `${(Math.abs(n) < 1 ? numbers.pctNarrow : numbers.pctWide).format(n)}%`;\n }\n case \"bytes\": {\n const n = Number(value);\n if (!Number.isFinite(n)) return String(value);\n const units = [\"B\", \"KB\", \"MB\", \"GB\", \"TB\"];\n let i = 0;\n let v = n;\n while (v >= 1024 && i < units.length - 1) {\n v /= 1024;\n i += 1;\n }\n return `${v.toFixed(i === 0 ? 0 : 1)} ${units[i]}`;\n }\n case \"duration\": {\n const ms = Number(value);\n if (!Number.isFinite(ms)) return String(value);\n if (ms < 1000) return `${Math.round(ms)}ms`;\n if (ms < 60_000) return `${(ms / 1000).toFixed(1)}s`;\n if (ms < 3_600_000) return `${Math.floor(ms / 60_000)}m ${Math.round((ms % 60_000) / 1000)}s`;\n return `${(ms / 3_600_000).toFixed(1)}h`;\n }\n case \"datetime\": {\n const d = typeof value === \"number\" ? new Date(value) : new Date(String(value));\n if (Number.isNaN(d.getTime())) return String(value);\n return d.toLocaleString(locale, timeZone ? { timeZone, timeZoneName: \"short\" } : undefined);\n }\n case \"code\":\n case \"text\":\n default:\n return typeof value === \"object\" ? JSON.stringify(value) : String(value);\n }\n}\n\nexport function formatDelta(delta: number, format: CardValueFormat = \"number\", options: FormatOptions = {}): string {\n // A true minus sign: the hyphen-minus is narrower and misaligns a column of\n // signed deltas against the plus signs above it.\n const sign = delta > 0 ? \"+\" : delta < 0 ? \"−\" : \"\";\n return `${sign}${formatValue(Math.abs(delta), format, options)}`;\n}\n\nexport const toneClass = (tone?: string): string => (tone && tone !== \"neutral\" ? ` sc-tone--${tone}` : \"\");\n\n/** Positive is not always good — but for a delta with no stated tone it is the useful default. */\nexport const deltaTone = (delta: number): \"positive\" | \"negative\" | \"neutral\" =>\n delta > 0 ? \"positive\" : delta < 0 ? \"negative\" : \"neutral\";\n\n/**\n * A URL that came from a model or a tool, made safe to put in an `href`: only http(s) links\n * pass, anything else (`javascript:`, `data:`, `vbscript:`, a relative path that could be read\n * as a scheme after whitespace tricks) comes back as `undefined` and the caller renders plain\n * text. React 19 refuses `javascript:` hrefs itself, but this package supports React 18, which\n * only warns and then navigates.\n */\nexport function safeHref(url: string | undefined | null): string | undefined {\n if (typeof url !== \"string\") return undefined;\n const trimmed = url.trim();\n // Browsers strip tab and newline characters inside a URL before parsing it, so\n // `java\\tscript:` is a javascript: URL; reject anything with control characters outright.\n // eslint-disable-next-line no-control-regex\n if (/[\\u0000-\\u001f\\u007f]/.test(trimmed)) return undefined;\n return /^https?:\\/\\/[^\\s]+$/i.test(trimmed) ? trimmed : undefined;\n}\n","// Thread export.\n//\n// Markdown rather than JSON: the point of exporting a conversation is to read it\n// somewhere else or paste it into a ticket, and JSON serves neither. Cards are\n// rendered as their data, not as their markup — a table exported as HTML is\n// useless in a text file, but as a markdown table it survives.\n//\n// Sharing (a hosted link) is deliberately NOT here: it needs a backend the kit\n// does not have, and faking it with a data: URL would produce links that break\n// the moment they leave the browser.\n\nimport type { Card, ContentPart, Message } from \"@supersolutions/super-chat-core\";\n\nfunction cardToMarkdown(spec: Record<string, unknown>): string {\n const kind = String(spec.kind ?? \"unknown\");\n const title = spec.title ? `**${spec.title}**\\n\\n` : \"\";\n\n if (kind === \"table\" && Array.isArray(spec.columns) && Array.isArray(spec.rows)) {\n const cols = spec.columns as { key: string; label: string }[];\n const rows = spec.rows as Record<string, unknown>[];\n const head = `| ${cols.map((c) => c.label).join(\" | \")} |`;\n const rule = `| ${cols.map(() => \"---\").join(\" | \")} |`;\n const body = rows.map((r) => `| ${cols.map((c) => String(r[c.key] ?? \"\")).join(\" | \")} |`).join(\"\\n\");\n return `${title}${head}\\n${rule}\\n${body}`;\n }\n\n if (kind === \"markdown\" && typeof spec.body === \"string\") return `${title}${spec.body}`;\n if (kind === \"code\" && typeof spec.code === \"string\") {\n return `${title}\\`\\`\\`${spec.language ?? \"\"}\\n${spec.code}\\n\\`\\`\\``;\n }\n if (kind === \"callout\" && typeof spec.body === \"string\") return `> ${title}${spec.body}`;\n\n // Everything else keeps its data rather than being dropped — an export that\n // silently omits a card is worse than one that is a little verbose.\n return `${title}\\`\\`\\`json\\n${JSON.stringify(spec, null, 2)}\\n\\`\\`\\``;\n}\n\nfunction partToMarkdown(part: ContentPart): string | null {\n switch (part.type) {\n case \"text\":\n return part.text;\n case \"reasoning\":\n return `<details><summary>Reasoning</summary>\\n\\n${part.text}\\n\\n</details>`;\n case \"tool-call\":\n return `- \\`${part.name}(${JSON.stringify(part.input ?? {})})\\``;\n case \"tool-result\":\n return part.failure ? `- \\`${part.name}\\` failed: ${part.failure}` : null;\n case \"image\":\n return \"_(image)_\";\n case \"file\":\n return `_(file: ${part.filename ?? \"attachment\"})_`;\n case \"artifact\":\n return part.kind.startsWith(\"card:\")\n ? cardToMarkdown(((part.data as { spec?: Card[\"spec\"] }).spec ?? part.data) as Record<string, unknown>)\n : null;\n default:\n return null;\n }\n}\n\n/** Render a thread as markdown. `title` becomes the H1 when given. */\nexport function threadToMarkdown(messages: readonly Message[], title?: string): string {\n const out: string[] = title ? [`# ${title}`, \"\"] : [];\n\n for (const m of messages) {\n if (m.role === \"system\") continue;\n const body = m.parts.map(partToMarkdown).filter(Boolean).join(\"\\n\\n\");\n if (!body) continue;\n const who = m.role === \"user\" ? \"You\" : m.role === \"tool\" ? \"Tools\" : \"Assistant\";\n const when = m.createdAt ? ` · ${new Date(m.createdAt).toISOString().slice(0, 16).replace(\"T\", \" \")}` : \"\";\n out.push(`## ${who}${when}`, \"\", body, \"\");\n }\n\n return out.join(\"\\n\").trimEnd() + \"\\n\";\n}\n\n/** Trigger a download of the thread as a `.md` file. */\nexport function downloadThread(messages: readonly Message[], filename = \"conversation.md\", title?: string): void {\n const blob = new Blob([threadToMarkdown(messages, title)], { type: \"text/markdown;charset=utf-8\" });\n const url = URL.createObjectURL(blob);\n const a = document.createElement(\"a\");\n a.href = url;\n a.download = filename;\n a.click();\n // Revoking immediately can race the download in some browsers; one frame is\n // enough for the click to have been consumed.\n requestAnimationFrame(() => URL.revokeObjectURL(url));\n}\n","// Minimal markdown renderer for assistant text, markdown cards and document\n// artifacts.\n//\n// Deliberately not a full parser — a chat message or card body is short, and\n// pulling in a markdown library plus a sanitizer for this is disproportionate.\n//\n// It does now split into blocks before rendering, and that is not a stylistic\n// change. A document previewer has to answer \"the user selected this on screen;\n// where is it in the source?\", because that span is both what gets quoted into\n// the next request and what an edit has to anchor against. The previous shape —\n// escape the whole string, pull fences out into placeholders, then run a chain\n// of global regexes — destroyed source positions in its first statement.\n//\n// So the order is inverted: split on the RAW source and record offsets, then\n// escape and transform each block independently. Escaping per block rather than\n// up front is load-bearing, not tidiness: `&` → `&` changes the string\n// length, so escaping first would shift every offset recorded afterwards. That\n// failure is invisible on screen — the page renders perfectly and the anchors\n// silently point at the wrong text — which is why markdown.test.ts asserts the\n// offsets round-trip rather than trusting the output to look right.\n//\n// ── Why it grew ──────────────────────────────────────────────────────────────\n//\n// The block set used to be headings, emphasis, code, links and bullet lists,\n// and for a chat bubble that is the right amount of renderer. A document\n// artifact changed the requirement under it: a document is a thing the user\n// KEEPS, reads in a previewer and downloads as `.md`, and a report whose table\n// renders as a column of literal pipes is not a document — it is the source of\n// one. Tables, quotes, ordered lists and indented code are not exotic; they are\n// what anyone writing a report reaches for in the first paragraph.\n//\n// The structure changed with the scope. A chain of global regexes over one\n// escaped string cannot tell a table from a paragraph, so each block is now\n// CLASSIFIED first and rendered by shape, and only the leaves run inline\n// transforms. Nesting (a list inside a quote, a quote inside a list) falls out\n// of rendering a block's interior through the same splitter, with a depth cap\n// so a pathological `> > > > …` cannot recurse without end.\n\nimport { splitBlocks, type MarkdownBlock } from \"@supersolutions/super-chat-core\";\n\nexport type AnchoredMarkdown = {\n html: string;\n /** Index-aligned with the `data-sc-block` attribute on the rendered HTML. */\n blocks: MarkdownBlock[];\n};\n\n// Cheap pre-check carried over from main: with none of these characters\n// present, no heading, emphasis, code, link, list, quote or table rule below\n// could match, so the whole chain is skippable. Applied per BLOCK rather than\n// per document — one fenced snippet in an otherwise plain artifact should not\n// cost the other forty paragraphs their shortcut.\nconst MARKDOWN_SIGNIFICANT = /[`*_#[\\]>~|-]/;\n// Two constructs carry no character the test above would catch: an ordered\n// item, and a setext heading underlined with `=`. Adding `=` and the digits to\n// MARKDOWN_SIGNIFICANT would cost the shortcut on most prose, so they get their\n// own (equally cheap) look instead.\nconst ORDERED_ITEM = /^ {0,3}\\d{1,9}[.)]\\s/m;\nconst SETEXT_EQUALS = /\\n {0,3}=+[ \\t]*$/;\n\nconst isPlainProse = (raw: string) =>\n !MARKDOWN_SIGNIFICANT.test(raw) && !ORDERED_ITEM.test(raw) && !SETEXT_EQUALS.test(raw);\n\n/** How deep a quote or list may nest before its interior is rendered flat. */\nconst MAX_DEPTH = 4;\n\n// Quotes are escaped because link URLs are interpolated into href=\"…\" — an\n// unescaped quote in a URL would close the attribute and open a new one\n// (browsers recover from the missing-whitespace parse error by reading\n// `\"onmouseover=\"…` as a fresh attribute).\n//\n// NUL is dropped here, at the one place every leaf is escaped, rather than only in\n// `inline`: the inline placeholders below are built from it, so it must never come from\n// the source, and code blocks and the plain-prose shortcut would otherwise let a raw\n// U+0000 through into the output. (Block offsets are computed on the raw source, so\n// removing it from the output moves no anchor.)\nconst escapeHtml = (s: string) =>\n s.replace(/\\0/g, \"\").replace(/&/g, \"&\").replace(/</g, \"<\").replace(/>/g, \">\").replace(/\"/g, \""\");\n\n// ── Inline ───────────────────────────────────────────────────────────────────\n\n/**\n * Escape, then transform. Every leaf goes through here and nothing else does.\n *\n * Code spans are lifted out FIRST and put back last, so `**not bold**` inside\n * backticks stays literal — the same protection fenced blocks get, which the\n * old chain gave only to fences. NUL is stripped from the input because the\n * placeholders are built from it; without that, text could forge one.\n */\n// Only http(s) links — a javascript: URL must never survive. The destination may\n// contain one level of balanced parentheses (`…/wiki/Foo_(bar)`), as CommonMark\n// allows; the two alternatives cannot match the same character, so there is no\n// backtracking blow-up on a hostile string.\nconst LINK = /\\[([^\\]]+)\\]\\((https?:\\/\\/(?:[^()\\s]|\\([^()\\s]*\\))+)\\)/g;\n\n/** Strike-through, strong, emphasis. Runs on already-escaped text. */\nconst emphasize = (s: string) =>\n s\n .replace(/~~([^~\\n]+)~~/g, \"<del>$1</del>\")\n .replace(/\\*\\*([^*]+)\\*\\*/g, \"<strong>$1</strong>\")\n .replace(/(^|[^*])\\*([^*\\n]+)\\*/g, \"$1<em>$2</em>\");\n\nfunction inline(raw: string): string {\n const spans: string[] = [];\n const spanSource: string[] = []; // what each code span looked like, for where it must stay literal\n let s = escapeHtml(raw);\n\n s = s.replace(/(`+)([\\s\\S]+?)\\1(?!`)/g, (all, _ticks, body: string) => {\n spans.push(body);\n spanSource.push(all);\n return `\\0${spans.length - 1}\\0`;\n });\n\n // Links are lifted out the same way, BEFORE emphasis. Otherwise the emphasis rules\n // run over the destination too, and `…/a*b*c` becomes `href=\"…/a<em>b</em>c\"`: the\n // link silently points somewhere else. Only the link's text is emphasised.\n const links: { text: string; url: string }[] = [];\n s = s.replace(LINK, (_all, text: string, url: string) => {\n // A backtick pair inside a URL is part of the URL, not a code span.\n const literal = url.replace(/\\0(\\d+)\\0/g, (_m, i: string) => spanSource[Number(i)]!);\n links.push({ text, url: literal });\n return `\\0L${links.length - 1}\\0`;\n });\n\n s = emphasize(s).replace(\n /\\0L(\\d+)\\0/g,\n (_all, i: string) => {\n const link = links[Number(i)]!;\n return `<a href=\"${link.url}\" target=\"_blank\" rel=\"noopener noreferrer\">${emphasize(link.text)}</a>`;\n },\n );\n\n return s.replace(/\\0(\\d+)\\0/g, (_all, i: string) => `<code>${spans[Number(i)]}</code>`);\n}\n\n// ── Verbatim blocks ──────────────────────────────────────────────────────────\n\nconst CLOSING_FENCE = /^ {0,3}(?:`{3,}|~{3,})\\s*$/;\n\nfunction renderFence(raw: string): string {\n // Drop the opening fence line (which may carry a language) and the closing\n // one if it is there — an unterminated fence has none. Content is escaped but\n // never sees an inline transform.\n const lines = raw.split(\"\\n\").slice(1);\n if (lines.length && CLOSING_FENCE.test(lines[lines.length - 1]!)) lines.pop();\n return `<pre><code>${escapeHtml(lines.join(\"\\n\"))}</code></pre>`;\n}\n\nfunction renderIndentedCode(raw: string): string {\n const body = raw.split(\"\\n\").map((l) => l.replace(/^(?: {4}|\\t)/, \"\")).join(\"\\n\");\n return `<pre><code>${escapeHtml(body)}</code></pre>`;\n}\n\n// ── Tables ───────────────────────────────────────────────────────────────────\n\ntype Align = \"left\" | \"center\" | \"right\" | null;\n\nconst DELIMITER_CELL = /^:?-+:?$/;\n\n/** Split a pipe row into cells, honouring `\\|` as a literal pipe. */\nfunction cellsOf(line: string): string[] {\n const trimmed = line.trim().replace(/^\\|/, \"\").replace(/\\|$/, \"\");\n return trimmed\n .split(/(?<!\\\\)\\|/)\n .map((c) => c.trim().replace(/\\\\\\|/g, \"|\"));\n}\n\nconst alignOf = (cell: string): Align => {\n const left = cell.startsWith(\":\");\n const right = cell.endsWith(\":\");\n return left && right ? \"center\" : right ? \"right\" : left ? \"left\" : null;\n};\n\nfunction renderTable(lines: string[]): string | null {\n if (lines.length < 2 || !lines[0]!.includes(\"|\")) return null;\n const delimiter = cellsOf(lines[1]!);\n if (!delimiter.length || !delimiter.every((c) => DELIMITER_CELL.test(c))) return null;\n\n const head = cellsOf(lines[0]!);\n if (head.length !== delimiter.length) return null;\n const align = delimiter.map(alignOf);\n\n // Alignment rides on a class rather than a style attribute: a host with a\n // strict CSP can ship this without allowing inline styles.\n const cell = (tag: \"th\" | \"td\", text: string, i: number) => {\n const a = align[i];\n return `<${tag}${a ? ` class=\"sc-md-${a}\"` : \"\"}>${inline(text)}</${tag}>`;\n };\n\n const body = lines\n .slice(2)\n .filter((l) => l.trim() !== \"\")\n .map((l) => {\n const row = cellsOf(l);\n // Short rows are padded and long ones cut, so a ragged table still lines\n // up under its header instead of leaking cells into a new column.\n const cells = Array.from({ length: head.length }, (_, i) => cell(\"td\", row[i] ?? \"\", i));\n return `<tr>${cells.join(\"\")}</tr>`;\n })\n .join(\"\");\n\n return `<table class=\"sc-md-table\"><thead><tr>${head\n .map((h, i) => cell(\"th\", h, i))\n .join(\"\")}</tr></thead><tbody>${body}</tbody></table>`;\n}\n\n// ── Lists ────────────────────────────────────────────────────────────────────\n\nconst LIST_ITEM = /^(\\s*)([-*+]|\\d{1,9}[.)])[ \\t]+(.*)$/;\n\ntype ParsedList = { ordered: boolean; start: number; items: string[] };\n\nfunction parseList(lines: string[]): ParsedList | null {\n const first = LIST_ITEM.exec(lines[0] ?? \"\");\n if (!first) return null;\n const base = first[1]!.length;\n const marker = first[2]!;\n const ordered = /^\\d/.test(marker);\n // Everything indented at least as far as the first item's text belongs to\n // that item — its wrapped lines, its paragraphs, and any list nested under it.\n const strip = new RegExp(`^ {0,${base + marker.length + 1}}`);\n\n const items: string[][] = [];\n for (const line of lines) {\n const m = LIST_ITEM.exec(line);\n if (m && m[1]!.length <= base) {\n items.push([m[3]!]);\n continue;\n }\n if (!items.length) return null;\n items[items.length - 1]!.push(line.replace(strip, \"\"));\n }\n\n return { ordered, start: ordered ? Number.parseInt(marker, 10) : 1, items: items.map((l) => l.join(\"\\n\")) };\n}\n\n/**\n * One item's interior.\n *\n * A single-paragraph item stays tight — `<li>text</li>`, not\n * `<li><p>text</p></li>` — because the paragraph margin inside a list item is\n * the classic \"why is my list double-spaced\" bug. Anything with a blank line or\n * a nested list goes back through the block pipeline, which is where nesting\n * comes from.\n */\nfunction renderItem(item: string, depth: number): string {\n const lines = item.replace(/\\s+$/, \"\").split(\"\\n\");\n const nestedAt = lines.findIndex((l, i) => i > 0 && LIST_ITEM.test(l));\n const head = (nestedAt === -1 ? lines : lines.slice(0, nestedAt)).filter((l) => l.trim() !== \"\");\n const rest = nestedAt === -1 ? [] : lines.slice(nestedAt);\n const loose = /\\n[ \\t]*\\n/.test(item.trim());\n\n const headHtml = head.length\n ? loose\n ? renderSource(head.join(\"\\n\"), depth + 1)\n : inline(head.join(\" \").trim())\n : \"\";\n return headHtml + (rest.length ? renderSource(rest.join(\"\\n\"), depth + 1) : \"\");\n}\n\nfunction renderList(lines: string[], depth: number): string | null {\n const parsed = parseList(lines);\n if (!parsed) return null;\n const items = parsed.items.map((item) => `<li>${renderItem(item, depth)}</li>`).join(\"\");\n if (!parsed.ordered) return `<ul>${items}</ul>`;\n return `<ol${parsed.start !== 1 ? ` start=\"${parsed.start}\"` : \"\"}>${items}</ol>`;\n}\n\n// ── Prose ────────────────────────────────────────────────────────────────────\n\nconst QUOTE_MARK = /^ {0,3}> ?/;\nconst THEMATIC_BREAK = /^ {0,3}(?:-{3,}|\\*{3,}|_{3,})\\s*$/;\nconst SETEXT = /^ {0,3}(=+|-+)\\s*$/;\n// Headings shift down one: the card or page owns the h1, so a document's own\n// `#` must not compete with it for the document outline a screen reader builds.\nconst ATX = /^ {0,3}(#{1,6})\\s+(.*?)\\s*#*\\s*$/;\n\nfunction renderProse(lines: string[]): string {\n const out: string[] = [];\n let para: string[] = [];\n const flush = () => {\n if (!para.length) return;\n out.push(`<p>${para.map(inline).join(\"<br/>\")}</p>`);\n para = [];\n };\n\n for (const line of lines) {\n const h = ATX.exec(line);\n if (h) {\n flush();\n const level = Math.min(h[1]!.length + 1, 6);\n out.push(`<h${level}>${inline(h[2]!)}</h${level}>`);\n continue;\n }\n para.push(line);\n }\n flush();\n return out.join(\"\");\n}\n\nfunction renderTextBlock(raw: string, depth: number): string {\n if (isPlainProse(raw)) {\n // Escaping still happens — safety is not what the shortcut skips.\n return `<p>${escapeHtml(raw).replace(/\\n/g, \"<br/>\")}</p>`;\n }\n\n const lines = raw.split(\"\\n\");\n\n const table = renderTable(lines);\n if (table) return table;\n\n if (depth < MAX_DEPTH && QUOTE_MARK.test(lines[0]!)) {\n const inner = lines.map((l) => l.replace(QUOTE_MARK, \"\")).join(\"\\n\");\n return `<blockquote>${renderSource(inner, depth + 1)}</blockquote>`;\n }\n\n if (depth < MAX_DEPTH) {\n const list = renderList(lines, depth);\n if (list) return list;\n }\n\n if (lines.length === 1 && THEMATIC_BREAK.test(lines[0]!)) return \"<hr/>\";\n\n // Setext: the underline belongs to the lines above it, and reading it as a\n // paragraph followed by a rule is the wrong document — the title stops being\n // a heading, which is exactly what the outline is built from.\n const last = lines[lines.length - 1]!;\n if (lines.length >= 2 && SETEXT.test(last)) {\n const level = last.trim().startsWith(\"=\") ? 2 : 3;\n const text = lines.slice(0, -1).join(\" \").trim();\n return `<h${level}>${inline(text)}</h${level}>`;\n }\n\n return renderProse(lines);\n}\n\n// ── Assembly ─────────────────────────────────────────────────────────────────\n\nfunction renderBlock(src: string, block: MarkdownBlock, depth: number): string {\n const raw = src.slice(block.start, block.end);\n if (block.kind === \"fence\") return renderFence(raw);\n if (block.kind === \"code\") return renderIndentedCode(raw);\n return renderTextBlock(raw, depth);\n}\n\n/** Split and render a source, with no anchors. Also the recursion step. */\nfunction renderSource(src: string, depth: number): string {\n return splitBlocks(src)\n .map((b) => renderBlock(src, b, depth))\n .join(\"\");\n}\n\n/** Render for the transcript: no anchors, because chat prose is not addressed. */\nexport function renderMarkdown(src: string): string {\n return renderSource(src, 0);\n}\n\n/** What renderMarkdownStream keeps between calls. Start from newMarkdownStream(). */\nexport type MarkdownStream = {\n /** The source the cached blocks were decided on; valid while the text starts with it. */\n settled: string;\n /** Rendered HTML of those blocks. */\n html: string;\n /** Where the block after them starts looking: the line after the last one. */\n resume: number;\n};\n\nexport const newMarkdownStream = (): MarkdownStream => ({ settled: \"\", html: \"\", resume: 0 });\n\n/**\n * renderMarkdown for text that grows while it is shown — always the same\n * string renderMarkdown(src) returns, but blocks that can no longer change are\n * rendered once and reused, so a streamed answer costs its open tail per\n * frame instead of its whole length.\n *\n * Every block renders from its own source slice alone, so the only question\n * is which blocks later text can still move. splitBlocks decides a block's\n * extent from its own lines and, at most, the first line of the block after\n * it: the blank line or fence opener that ends it, and for a list or quote the\n * next non-blank line, which may continue it. Whether a line is blank, a fence\n * opener or closer, a list item or a quote can change while it is the last,\n * unterminated line — `1` becomes `1.`, a closing ``` becomes ```js, ``` gains\n * a backtick and stops opening a fence, a blank line gets text. Every line\n * before the last is final. So a block is settled once the block after it\n * starts before the last line: a setext underline, a loose list's next item,\n * a table's delimiter row or the rest of an open fence all belong to the\n * block that is still open. (This renderer has no reference definitions,\n * footnotes or raw HTML blocks, the other constructs that reach back.) And\n * splitBlocks never looks behind the line it stands on, so splitting from the\n * line after the settled blocks yields the same blocks the whole text would.\n *\n * Text that does not start with `stream.settled` — a new run, an edit — drops\n * the cache and renders from scratch.\n */\nexport function renderMarkdownStream(src: string, stream: MarkdownStream): string {\n if (!src.startsWith(stream.settled)) Object.assign(stream, newMarkdownStream());\n\n const from = stream.resume;\n const tail = src.slice(from);\n const blocks = splitBlocks(tail);\n const lastLine = src.lastIndexOf(\"\\n\") + 1 - from;\n let html = stream.html;\n for (let i = 0; i < blocks.length; i += 1) {\n const rendered = renderBlock(tail, blocks[i]!, 0);\n html += rendered;\n if (i + 1 < blocks.length && blocks[i + 1]!.start < lastLine) {\n stream.html += rendered;\n stream.resume = from + blocks[i]!.end + 1;\n }\n }\n stream.settled = src.slice(0, lastLine + from);\n return html;\n}\n\n/**\n * Render for a document previewer: every block carries `data-sc-block`, so a\n * DOM selection resolves to a source span by walking up to the nearest one.\n *\n * Kept separate from renderMarkdown rather than added as an option, because\n * assistant prose has nothing to address and the extra attributes would be\n * noise in every message bubble.\n */\nexport function renderMarkdownWithAnchors(src: string): AnchoredMarkdown {\n const blocks = splitBlocks(src);\n const html = blocks\n .map((block, i) => {\n const rendered = renderBlock(src, block, 0);\n // Every branch of renderBlock returns markup, so the first tag always\n // exists; the anchor rides on it instead of an extra wrapper element,\n // which keeps the DOM (and therefore .sc-prose's spacing rules) unchanged.\n return rendered.replace(/^(\\s*<[a-z][a-z0-9]*)/i, `$1 data-sc-block=\"${i}\"`);\n })\n .join(\"\");\n return { html, blocks };\n}\n"],"mappings":";AAmBO,IAAM,gBAA+B,EAAE,QAAQ,SAAS,UAAU,MAAM;AAE/E,SAAS,oBAAoB,QAAiB;AAC5C,SAAO;AAAA,IACL,SAAS,IAAI,KAAK,aAAa,QAAQ,EAAE,UAAU,WAAW,uBAAuB,EAAE,CAAC;AAAA,IACxF,OAAO,IAAI,KAAK,aAAa,QAAQ,EAAE,uBAAuB,EAAE,CAAC;AAAA,IACjE,SAAS,IAAI,KAAK,aAAa,QAAQ,EAAE,uBAAuB,GAAG,aAAa,MAAM,CAAC;AAAA,IACvF,WAAW,IAAI,KAAK,aAAa,QAAQ,EAAE,uBAAuB,GAAG,aAAa,MAAM,CAAC;AAAA,EAC3F;AACF;AAEA,IAAM,gBAAgB,oBAAI,IAAoD;AAE9E,SAAS,WAAW,QAAiB;AACnC,QAAM,MAAM,UAAU;AACtB,MAAI,UAAU,cAAc,IAAI,GAAG;AACnC,MAAI,CAAC,SAAS;AACZ,cAAU,oBAAoB,MAAM;AACpC,kBAAc,IAAI,KAAK,OAAO;AAAA,EAChC;AACA,SAAO;AACT;AAEO,SAAS,YAAY,OAAgB,SAA0B,QAAQ,UAAyB,CAAC,GAAW;AACjH,MAAI,SAAS,KAAM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,WAAW,OAAO,OAAO,EAAG,QAAO,OAAO,QAAQ,kBAAkB,CAAC;AAE9E,QAAM,OAAO,OAAO;AACpB,QAAM,OAAO,IAAI,MAAM,IAAI;AAC3B,QAAM,SAAS,YAAY,IAAI;AAC/B,QAAM,WAAW,IAAI,YAAY,IAAI,IAAI,IAAI;AAC7C,MAAI,OAAO,OAAO;AAClB,WAAS,IAAI,GAAG,IAAI,OAAO,QAAQ,KAAK,GAAG;AACzC,UAAM,WAAW,YAAY,MAAM,OAAO,CAAC,GAAI,CAAC;AAChD,YAAQ;AACR,QAAI,IAAI,IAAI,OAAO,UAAU,OAAO,IAAI,CAAC,EAAG,QAAQ,UAAU;AAC5D,aAAO,QAAQ;AACf,aAAO,SAAS,OAAO,OAAO,CAAC,EAAG,MAAM;AAAA,IAC1C;AAAA,EACF;AACA,SAAO,UAAU,IAAI,MAAM,GAAG,WAAW,IAAI;AAC7C,SAAO;AACT;AAUO,SAAS,0BAA0B,KAA+B;AACvE,QAAM,SAAS,YAAY,GAAG;AAC9B,QAAM,OAAO,OACV,IAAI,CAAC,OAAO,MAAM;AACjB,UAAM,WAAW,YAAY,KAAK,OAAO,CAAC;AAI1C,WAAO,SAAS,QAAQ,0BAA0B,qBAAqB,CAAC,GAAG;AAAA,EAC7E,CAAC,EACA,KAAK,EAAE;AACV,SAAO,EAAE,MAAM,OAAO;AACxB;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../src/format.ts","../src/export.ts","../src/markdown.ts"],"sourcesContent":["// Value formatting shared by every card renderer.\n//\n// Centralised because a table cell and a stat tile showing the same number in\n// different formats is the fastest way to make an interface look untrustworthy.\n\nimport type { CardValueFormat } from \"@supersolutions/super-chat-core\";\n\nexport type FormatOptions = {\n /** BCP 47 locale. Omitted means the viewer's own. */\n locale?: string;\n /** IANA time zone for `datetime` values. Omitted means the viewer's own. */\n timeZone?: string;\n};\n\n/**\n * Fixed settings for HTML rendered ahead of the browser. A build server and a\n * viewer rarely share a locale or time zone, so server output and the first\n * client render must both use these or hydration fails.\n */\nexport const STABLE_FORMAT: FormatOptions = { locale: \"en-US\", timeZone: \"UTC\" };\n\nfunction createNumberFormats(locale?: string) {\n return {\n compact: new Intl.NumberFormat(locale, { notation: \"compact\", maximumFractionDigits: 2 }),\n plain: new Intl.NumberFormat(locale, { maximumFractionDigits: 6 }),\n pctWide: new Intl.NumberFormat(locale, { maximumFractionDigits: 1, useGrouping: false }),\n pctNarrow: new Intl.NumberFormat(locale, { maximumFractionDigits: 2, useGrouping: false }),\n };\n}\n\nconst numberFormats = new Map<string, ReturnType<typeof createNumberFormats>>();\n\nfunction numbersFor(locale?: string) {\n const key = locale ?? \"\";\n let formats = numberFormats.get(key);\n if (!formats) {\n formats = createNumberFormats(locale);\n numberFormats.set(key, formats);\n }\n return formats;\n}\n\nexport function formatValue(value: unknown, format: CardValueFormat = \"text\", options: FormatOptions = {}): string {\n if (value == null) return \"—\";\n const { locale, timeZone } = options;\n const numbers = numbersFor(locale);\n\n switch (format) {\n case \"number\": {\n const n = Number(value);\n if (!Number.isFinite(n)) return String(value);\n // Compact only above 5 digits: \"12.3K\" is helpful, \"1.2K\" hides precision\n // people expect to see on small counts.\n return Math.abs(n) >= 100_000 ? numbers.compact.format(n) : numbers.plain.format(n);\n }\n case \"currency\": {\n const n = Number(value);\n if (!Number.isFinite(n)) return String(value);\n const abs = Math.abs(n);\n // Sub-cent values are common in crypto; fixed 2dp would render them as $0.00.\n const digits = abs >= 1 ? 2 : abs >= 0.01 ? 4 : 8;\n // A whole amount in the thousands reads as \"$48,200\". Forcing \".00\" onto\n // it is the machine-printed look; amounts with cents keep them.\n const min = abs >= 1000 && Number.isInteger(n) ? 0 : 2;\n return `$${n.toLocaleString(locale, { minimumFractionDigits: min, maximumFractionDigits: Math.max(min, digits) })}`;\n }\n case \"percent\": {\n const n = Number(value);\n if (!Number.isFinite(n)) return String(value);\n // One decimal at most (\"8.2%\", \"12%\"), two only below 1% where the\n // second digit is the signal (\"0.04%\"). A fixed \"8.20%\" is false precision.\n return `${(Math.abs(n) < 1 ? numbers.pctNarrow : numbers.pctWide).format(n)}%`;\n }\n case \"bytes\": {\n const n = Number(value);\n if (!Number.isFinite(n)) return String(value);\n const units = [\"B\", \"KB\", \"MB\", \"GB\", \"TB\"];\n let i = 0;\n let v = n;\n while (v >= 1024 && i < units.length - 1) {\n v /= 1024;\n i += 1;\n }\n return `${v.toFixed(i === 0 ? 0 : 1)} ${units[i]}`;\n }\n case \"duration\": {\n const ms = Number(value);\n if (!Number.isFinite(ms)) return String(value);\n if (ms < 1000) return `${Math.round(ms)}ms`;\n if (ms < 60_000) return `${(ms / 1000).toFixed(1)}s`;\n if (ms < 3_600_000) return `${Math.floor(ms / 60_000)}m ${Math.round((ms % 60_000) / 1000)}s`;\n return `${(ms / 3_600_000).toFixed(1)}h`;\n }\n case \"datetime\": {\n const d = typeof value === \"number\" ? new Date(value) : new Date(String(value));\n if (Number.isNaN(d.getTime())) return String(value);\n return d.toLocaleString(locale, timeZone ? { timeZone, timeZoneName: \"short\" } : undefined);\n }\n case \"code\":\n case \"text\":\n default:\n return typeof value === \"object\" ? JSON.stringify(value) : String(value);\n }\n}\n\nexport function formatDelta(delta: number, format: CardValueFormat = \"number\", options: FormatOptions = {}): string {\n // A true minus sign: the hyphen-minus is narrower and misaligns a column of\n // signed deltas against the plus signs above it.\n const sign = delta > 0 ? \"+\" : delta < 0 ? \"−\" : \"\";\n return `${sign}${formatValue(Math.abs(delta), format, options)}`;\n}\n\nexport const toneClass = (tone?: string): string => (tone && tone !== \"neutral\" ? ` sc-tone--${tone}` : \"\");\n\n/** Positive is not always good — but for a delta with no stated tone it is the useful default. */\nexport const deltaTone = (delta: number): \"positive\" | \"negative\" | \"neutral\" =>\n delta > 0 ? \"positive\" : delta < 0 ? \"negative\" : \"neutral\";\n\n/**\n * A URL that came from a model or a tool, made safe to put in an `href`: only http(s) links\n * pass, anything else (`javascript:`, `data:`, `vbscript:`, a relative path that could be read\n * as a scheme after whitespace tricks) comes back as `undefined` and the caller renders plain\n * text. React 19 refuses `javascript:` hrefs itself, but this package supports React 18, which\n * only warns and then navigates.\n */\nexport function safeHref(url: string | undefined | null): string | undefined {\n if (typeof url !== \"string\") return undefined;\n const trimmed = url.trim();\n // Browsers strip tab and newline characters inside a URL before parsing it, so\n // `java\\tscript:` is a javascript: URL; reject anything with control characters outright.\n // eslint-disable-next-line no-control-regex\n if (/[\\u0000-\\u001f\\u007f]/.test(trimmed)) return undefined;\n return /^https?:\\/\\/[^\\s]+$/i.test(trimmed) ? trimmed : undefined;\n}\n","// Thread export.\n//\n// Markdown rather than JSON: the point of exporting a conversation is to read it\n// somewhere else or paste it into a ticket, and JSON serves neither. Cards are\n// rendered as their data, not as their markup — a table exported as HTML is\n// useless in a text file, but as a markdown table it survives.\n//\n// Sharing (a hosted link) is deliberately NOT here: it needs a backend the kit\n// does not have, and faking it with a data: URL would produce links that break\n// the moment they leave the browser.\n\nimport type { Card, ContentPart, Message } from \"@supersolutions/super-chat-core\";\n\nfunction cardToMarkdown(spec: Record<string, unknown>): string {\n const kind = String(spec.kind ?? \"unknown\");\n const title = spec.title ? `**${spec.title}**\\n\\n` : \"\";\n\n if (kind === \"table\" && Array.isArray(spec.columns) && Array.isArray(spec.rows)) {\n const cols = spec.columns as { key: string; label: string }[];\n const rows = spec.rows as Record<string, unknown>[];\n const head = `| ${cols.map((c) => c.label).join(\" | \")} |`;\n const rule = `| ${cols.map(() => \"---\").join(\" | \")} |`;\n const body = rows.map((r) => `| ${cols.map((c) => String(r[c.key] ?? \"\")).join(\" | \")} |`).join(\"\\n\");\n return `${title}${head}\\n${rule}\\n${body}`;\n }\n\n if (kind === \"markdown\" && typeof spec.body === \"string\") return `${title}${spec.body}`;\n if (kind === \"code\" && typeof spec.code === \"string\") {\n return `${title}\\`\\`\\`${spec.language ?? \"\"}\\n${spec.code}\\n\\`\\`\\``;\n }\n if (kind === \"callout\" && typeof spec.body === \"string\") return `> ${title}${spec.body}`;\n\n // Everything else keeps its data rather than being dropped — an export that\n // silently omits a card is worse than one that is a little verbose.\n return `${title}\\`\\`\\`json\\n${JSON.stringify(spec, null, 2)}\\n\\`\\`\\``;\n}\n\nfunction partToMarkdown(part: ContentPart): string | null {\n switch (part.type) {\n case \"text\":\n return part.text;\n case \"reasoning\":\n return `<details><summary>Reasoning</summary>\\n\\n${part.text}\\n\\n</details>`;\n case \"tool-call\":\n return `- \\`${part.name}(${JSON.stringify(part.input ?? {})})\\``;\n case \"tool-result\":\n return part.failure ? `- \\`${part.name}\\` failed: ${part.failure}` : null;\n case \"image\":\n return \"_(image)_\";\n case \"file\":\n return `_(file: ${part.filename ?? \"attachment\"})_`;\n case \"artifact\":\n return part.kind.startsWith(\"card:\")\n ? cardToMarkdown(((part.data as { spec?: Card[\"spec\"] }).spec ?? part.data) as Record<string, unknown>)\n : null;\n default:\n return null;\n }\n}\n\n/** Render a thread as markdown. `title` becomes the H1 when given. */\nexport function threadToMarkdown(messages: readonly Message[], title?: string): string {\n const out: string[] = title ? [`# ${title}`, \"\"] : [];\n\n for (const m of messages) {\n if (m.role === \"system\") continue;\n const body = m.parts.map(partToMarkdown).filter(Boolean).join(\"\\n\\n\");\n if (!body) continue;\n const who = m.role === \"user\" ? \"You\" : m.role === \"tool\" ? \"Tools\" : \"Assistant\";\n const when = m.createdAt ? ` · ${new Date(m.createdAt).toISOString().slice(0, 16).replace(\"T\", \" \")}` : \"\";\n out.push(`## ${who}${when}`, \"\", body, \"\");\n }\n\n return out.join(\"\\n\").trimEnd() + \"\\n\";\n}\n\n/** Trigger a download of the thread as a `.md` file. */\nexport function downloadThread(messages: readonly Message[], filename = \"conversation.md\", title?: string): void {\n const blob = new Blob([threadToMarkdown(messages, title)], { type: \"text/markdown;charset=utf-8\" });\n const url = URL.createObjectURL(blob);\n const a = document.createElement(\"a\");\n a.href = url;\n a.download = filename;\n a.click();\n // Revoking immediately can race the download in some browsers; one frame is\n // enough for the click to have been consumed.\n requestAnimationFrame(() => URL.revokeObjectURL(url));\n}\n","// Minimal markdown renderer for assistant text, markdown cards and document\n// artifacts.\n//\n// Deliberately not a full parser — a chat message or card body is short, and\n// pulling in a markdown library plus a sanitizer for this is disproportionate.\n//\n// It does now split into blocks before rendering, and that is not a stylistic\n// change. A document previewer has to answer \"the user selected this on screen;\n// where is it in the source?\", because that span is both what gets quoted into\n// the next request and what an edit has to anchor against. The previous shape —\n// escape the whole string, pull fences out into placeholders, then run a chain\n// of global regexes — destroyed source positions in its first statement.\n//\n// So the order is inverted: split on the RAW source and record offsets, then\n// escape and transform each block independently. Escaping per block rather than\n// up front is load-bearing, not tidiness: `&` → `&` changes the string\n// length, so escaping first would shift every offset recorded afterwards. That\n// failure is invisible on screen — the page renders perfectly and the anchors\n// silently point at the wrong text — which is why markdown.test.ts asserts the\n// offsets round-trip rather than trusting the output to look right.\n//\n// ── Why it grew ──────────────────────────────────────────────────────────────\n//\n// The block set used to be headings, emphasis, code, links and bullet lists,\n// and for a chat bubble that is the right amount of renderer. A document\n// artifact changed the requirement under it: a document is a thing the user\n// KEEPS, reads in a previewer and downloads as `.md`, and a report whose table\n// renders as a column of literal pipes is not a document — it is the source of\n// one. Tables, quotes, ordered lists and indented code are not exotic; they are\n// what anyone writing a report reaches for in the first paragraph.\n//\n// The structure changed with the scope. A chain of global regexes over one\n// escaped string cannot tell a table from a paragraph, so each block is now\n// CLASSIFIED first and rendered by shape, and only the leaves run inline\n// transforms. Nesting (a list inside a quote, a quote inside a list) falls out\n// of rendering a block's interior through the same splitter, with a depth cap\n// so a pathological `> > > > …` cannot recurse without end.\n\nimport { splitBlocks, type MarkdownBlock } from \"@supersolutions/super-chat-core\";\n\nexport type AnchoredMarkdown = {\n html: string;\n /** Index-aligned with the `data-sc-block` attribute on the rendered HTML. */\n blocks: MarkdownBlock[];\n};\n\n// Cheap pre-check carried over from main: with none of these characters\n// present, no heading, emphasis, code, link, list, quote or table rule below\n// could match, so the whole chain is skippable. Applied per BLOCK rather than\n// per document — one fenced snippet in an otherwise plain artifact should not\n// cost the other forty paragraphs their shortcut.\nconst MARKDOWN_SIGNIFICANT = /[`*_#[\\]>~|-]/;\n// Two constructs carry no character the test above would catch: an ordered\n// item, and a setext heading underlined with `=`. Adding `=` and the digits to\n// MARKDOWN_SIGNIFICANT would cost the shortcut on most prose, so they get their\n// own (equally cheap) look instead.\nconst ORDERED_ITEM = /^ {0,3}\\d{1,9}[.)]\\s/m;\nconst SETEXT_EQUALS = /\\n {0,3}=+[ \\t]*$/;\n\nconst isPlainProse = (raw: string) =>\n !MARKDOWN_SIGNIFICANT.test(raw) && !ORDERED_ITEM.test(raw) && !SETEXT_EQUALS.test(raw);\n\n/** How deep a quote or list may nest before its interior is rendered flat. */\nconst MAX_DEPTH = 4;\n\n// Quotes are escaped because link URLs are interpolated into href=\"…\" — an\n// unescaped quote in a URL would close the attribute and open a new one\n// (browsers recover from the missing-whitespace parse error by reading\n// `\"onmouseover=\"…` as a fresh attribute).\n//\n// NUL is dropped here, at the one place every leaf is escaped, rather than only in\n// `inline`: the inline placeholders below are built from it, so it must never come from\n// the source, and code blocks and the plain-prose shortcut would otherwise let a raw\n// U+0000 through into the output. (Block offsets are computed on the raw source, so\n// removing it from the output moves no anchor.)\nconst escapeHtml = (s: string) =>\n s.replace(/\\0/g, \"\").replace(/&/g, \"&\").replace(/</g, \"<\").replace(/>/g, \">\").replace(/\"/g, \""\");\n\n// ── Inline ───────────────────────────────────────────────────────────────────\n\n/**\n * Escape, then transform. Every leaf goes through here and nothing else does.\n *\n * Code spans are lifted out FIRST and put back last, so `**not bold**` inside\n * backticks stays literal — the same protection fenced blocks get, which the\n * old chain gave only to fences. NUL is stripped from the input because the\n * placeholders are built from it; without that, text could forge one.\n */\n// Only http(s) links — a javascript: URL must never survive. The destination may\n// contain one level of balanced parentheses (`…/wiki/Foo_(bar)`), as CommonMark\n// allows; the two alternatives cannot match the same character, so there is no\n// backtracking blow-up on a hostile string.\n//\n// The other destination is a card reference, `ref:<card>?key=value&…` (super-protocol\n// docs/CARD-REFS.md). It is not a link: it becomes a span the host wires to a card, and it\n// stays plain text where no host does. The character set is the envelope's own, plus the `;`\n// that escaping gives `&`, so nothing in it can close an attribute or open a tag. The limits\n// are the parser's to enforce (a ref that breaks them degrades where it is used), not this\n// regex's; the bound here only keeps a hostile string from costing a long scan.\nconst LINK = /\\[([^\\]]+)\\]\\((https?:\\/\\/(?:[^()\\s]|\\([^()\\s]*\\))+|ref:[A-Za-z0-9._:~%=&;?-]{1,3000})\\)/g;\n\n/** Strike-through, strong, emphasis. Runs on already-escaped text. */\nconst emphasize = (s: string) =>\n s\n .replace(/~~([^~\\n]+)~~/g, \"<del>$1</del>\")\n .replace(/\\*\\*([^*]+)\\*\\*/g, \"<strong>$1</strong>\")\n .replace(/(^|[^*])\\*([^*\\n]+)\\*/g, \"$1<em>$2</em>\");\n\nfunction inline(raw: string): string {\n const spans: string[] = [];\n const spanSource: string[] = []; // what each code span looked like, for where it must stay literal\n let s = escapeHtml(raw);\n\n s = s.replace(/(`+)([\\s\\S]+?)\\1(?!`)/g, (all, _ticks, body: string) => {\n spans.push(body);\n spanSource.push(all);\n return `\\0${spans.length - 1}\\0`;\n });\n\n // Links are lifted out the same way, BEFORE emphasis. Otherwise the emphasis rules\n // run over the destination too, and `…/a*b*c` becomes `href=\"…/a<em>b</em>c\"`: the\n // link silently points somewhere else. Only the link's text is emphasised.\n const links: { text: string; url: string; ref: boolean }[] = [];\n s = s.replace(LINK, (_all, text: string, url: string) => {\n // A backtick pair inside a URL is part of the URL, not a code span.\n const literal = url.replace(/\\0(\\d+)\\0/g, (_m, i: string) => spanSource[Number(i)]!);\n links.push({ text, url: literal, ref: literal.startsWith(\"ref:\") });\n return `\\0L${links.length - 1}\\0`;\n });\n\n s = emphasize(s).replace(\n /\\0L(\\d+)\\0/g,\n (_all, i: string) => {\n const link = links[Number(i)]!;\n if (link.ref) return `<span class=\"sc-ref\" data-ref=\"${link.url}\">${emphasize(link.text)}</span>`;\n return `<a href=\"${link.url}\" target=\"_blank\" rel=\"noopener noreferrer\">${emphasize(link.text)}</a>`;\n },\n );\n\n return s.replace(/\\0(\\d+)\\0/g, (_all, i: string) => `<code>${spans[Number(i)]}</code>`);\n}\n\n// ── Verbatim blocks ──────────────────────────────────────────────────────────\n\nconst CLOSING_FENCE = /^ {0,3}(?:`{3,}|~{3,})\\s*$/;\n\nfunction renderFence(raw: string): string {\n // Drop the opening fence line (which may carry a language) and the closing\n // one if it is there — an unterminated fence has none. Content is escaped but\n // never sees an inline transform.\n const lines = raw.split(\"\\n\").slice(1);\n if (lines.length && CLOSING_FENCE.test(lines[lines.length - 1]!)) lines.pop();\n return `<pre><code>${escapeHtml(lines.join(\"\\n\"))}</code></pre>`;\n}\n\nfunction renderIndentedCode(raw: string): string {\n const body = raw.split(\"\\n\").map((l) => l.replace(/^(?: {4}|\\t)/, \"\")).join(\"\\n\");\n return `<pre><code>${escapeHtml(body)}</code></pre>`;\n}\n\n// ── Tables ───────────────────────────────────────────────────────────────────\n\ntype Align = \"left\" | \"center\" | \"right\" | null;\n\nconst DELIMITER_CELL = /^:?-+:?$/;\n\n/** Split a pipe row into cells, honouring `\\|` as a literal pipe. */\nfunction cellsOf(line: string): string[] {\n const trimmed = line.trim().replace(/^\\|/, \"\").replace(/\\|$/, \"\");\n return trimmed\n .split(/(?<!\\\\)\\|/)\n .map((c) => c.trim().replace(/\\\\\\|/g, \"|\"));\n}\n\nconst alignOf = (cell: string): Align => {\n const left = cell.startsWith(\":\");\n const right = cell.endsWith(\":\");\n return left && right ? \"center\" : right ? \"right\" : left ? \"left\" : null;\n};\n\nfunction renderTable(lines: string[]): string | null {\n if (lines.length < 2 || !lines[0]!.includes(\"|\")) return null;\n const delimiter = cellsOf(lines[1]!);\n if (!delimiter.length || !delimiter.every((c) => DELIMITER_CELL.test(c))) return null;\n\n const head = cellsOf(lines[0]!);\n if (head.length !== delimiter.length) return null;\n const align = delimiter.map(alignOf);\n\n // Alignment rides on a class rather than a style attribute: a host with a\n // strict CSP can ship this without allowing inline styles.\n const cell = (tag: \"th\" | \"td\", text: string, i: number) => {\n const a = align[i];\n return `<${tag}${a ? ` class=\"sc-md-${a}\"` : \"\"}>${inline(text)}</${tag}>`;\n };\n\n const body = lines\n .slice(2)\n .filter((l) => l.trim() !== \"\")\n .map((l) => {\n const row = cellsOf(l);\n // Short rows are padded and long ones cut, so a ragged table still lines\n // up under its header instead of leaking cells into a new column.\n const cells = Array.from({ length: head.length }, (_, i) => cell(\"td\", row[i] ?? \"\", i));\n return `<tr>${cells.join(\"\")}</tr>`;\n })\n .join(\"\");\n\n return `<table class=\"sc-md-table\"><thead><tr>${head\n .map((h, i) => cell(\"th\", h, i))\n .join(\"\")}</tr></thead><tbody>${body}</tbody></table>`;\n}\n\n// ── Lists ────────────────────────────────────────────────────────────────────\n\nconst LIST_ITEM = /^(\\s*)([-*+]|\\d{1,9}[.)])[ \\t]+(.*)$/;\n\ntype ParsedList = { ordered: boolean; start: number; items: string[] };\n\nfunction parseList(lines: string[]): ParsedList | null {\n const first = LIST_ITEM.exec(lines[0] ?? \"\");\n if (!first) return null;\n const base = first[1]!.length;\n const marker = first[2]!;\n const ordered = /^\\d/.test(marker);\n // Everything indented at least as far as the first item's text belongs to\n // that item — its wrapped lines, its paragraphs, and any list nested under it.\n const strip = new RegExp(`^ {0,${base + marker.length + 1}}`);\n\n const items: string[][] = [];\n for (const line of lines) {\n const m = LIST_ITEM.exec(line);\n if (m && m[1]!.length <= base) {\n items.push([m[3]!]);\n continue;\n }\n if (!items.length) return null;\n items[items.length - 1]!.push(line.replace(strip, \"\"));\n }\n\n return { ordered, start: ordered ? Number.parseInt(marker, 10) : 1, items: items.map((l) => l.join(\"\\n\")) };\n}\n\n/**\n * One item's interior.\n *\n * A single-paragraph item stays tight — `<li>text</li>`, not\n * `<li><p>text</p></li>` — because the paragraph margin inside a list item is\n * the classic \"why is my list double-spaced\" bug. Anything with a blank line or\n * a nested list goes back through the block pipeline, which is where nesting\n * comes from.\n */\nfunction renderItem(item: string, depth: number): string {\n const lines = item.replace(/\\s+$/, \"\").split(\"\\n\");\n const nestedAt = lines.findIndex((l, i) => i > 0 && LIST_ITEM.test(l));\n const head = (nestedAt === -1 ? lines : lines.slice(0, nestedAt)).filter((l) => l.trim() !== \"\");\n const rest = nestedAt === -1 ? [] : lines.slice(nestedAt);\n const loose = /\\n[ \\t]*\\n/.test(item.trim());\n\n const headHtml = head.length\n ? loose\n ? renderSource(head.join(\"\\n\"), depth + 1)\n : inline(head.join(\" \").trim())\n : \"\";\n return headHtml + (rest.length ? renderSource(rest.join(\"\\n\"), depth + 1) : \"\");\n}\n\nfunction renderList(lines: string[], depth: number): string | null {\n const parsed = parseList(lines);\n if (!parsed) return null;\n const items = parsed.items.map((item) => `<li>${renderItem(item, depth)}</li>`).join(\"\");\n if (!parsed.ordered) return `<ul>${items}</ul>`;\n return `<ol${parsed.start !== 1 ? ` start=\"${parsed.start}\"` : \"\"}>${items}</ol>`;\n}\n\n// ── Prose ────────────────────────────────────────────────────────────────────\n\nconst QUOTE_MARK = /^ {0,3}> ?/;\nconst THEMATIC_BREAK = /^ {0,3}(?:-{3,}|\\*{3,}|_{3,})\\s*$/;\nconst SETEXT = /^ {0,3}(=+|-+)\\s*$/;\n// Headings shift down one: the card or page owns the h1, so a document's own\n// `#` must not compete with it for the document outline a screen reader builds.\nconst ATX = /^ {0,3}(#{1,6})\\s+(.*?)\\s*#*\\s*$/;\n\nfunction renderProse(lines: string[]): string {\n const out: string[] = [];\n let para: string[] = [];\n const flush = () => {\n if (!para.length) return;\n out.push(`<p>${para.map(inline).join(\"<br/>\")}</p>`);\n para = [];\n };\n\n for (const line of lines) {\n const h = ATX.exec(line);\n if (h) {\n flush();\n const level = Math.min(h[1]!.length + 1, 6);\n out.push(`<h${level}>${inline(h[2]!)}</h${level}>`);\n continue;\n }\n para.push(line);\n }\n flush();\n return out.join(\"\");\n}\n\nfunction renderTextBlock(raw: string, depth: number): string {\n if (isPlainProse(raw)) {\n // Escaping still happens — safety is not what the shortcut skips.\n return `<p>${escapeHtml(raw).replace(/\\n/g, \"<br/>\")}</p>`;\n }\n\n const lines = raw.split(\"\\n\");\n\n const table = renderTable(lines);\n if (table) return table;\n\n if (depth < MAX_DEPTH && QUOTE_MARK.test(lines[0]!)) {\n const inner = lines.map((l) => l.replace(QUOTE_MARK, \"\")).join(\"\\n\");\n return `<blockquote>${renderSource(inner, depth + 1)}</blockquote>`;\n }\n\n if (depth < MAX_DEPTH) {\n const list = renderList(lines, depth);\n if (list) return list;\n }\n\n if (lines.length === 1 && THEMATIC_BREAK.test(lines[0]!)) return \"<hr/>\";\n\n // Setext: the underline belongs to the lines above it, and reading it as a\n // paragraph followed by a rule is the wrong document — the title stops being\n // a heading, which is exactly what the outline is built from.\n const last = lines[lines.length - 1]!;\n if (lines.length >= 2 && SETEXT.test(last)) {\n const level = last.trim().startsWith(\"=\") ? 2 : 3;\n const text = lines.slice(0, -1).join(\" \").trim();\n return `<h${level}>${inline(text)}</h${level}>`;\n }\n\n return renderProse(lines);\n}\n\n// ── Assembly ─────────────────────────────────────────────────────────────────\n\nfunction renderBlock(src: string, block: MarkdownBlock, depth: number): string {\n const raw = src.slice(block.start, block.end);\n if (block.kind === \"fence\") return renderFence(raw);\n if (block.kind === \"code\") return renderIndentedCode(raw);\n return renderTextBlock(raw, depth);\n}\n\n/** Split and render a source, with no anchors. Also the recursion step. */\nfunction renderSource(src: string, depth: number): string {\n return splitBlocks(src)\n .map((b) => renderBlock(src, b, depth))\n .join(\"\");\n}\n\n/** Render for the transcript: no anchors, because chat prose is not addressed. */\nexport function renderMarkdown(src: string): string {\n return renderSource(src, 0);\n}\n\n/** What renderMarkdownStream keeps between calls. Start from newMarkdownStream(). */\nexport type MarkdownStream = {\n /** The source the cached blocks were decided on; valid while the text starts with it. */\n settled: string;\n /** Rendered HTML of those blocks. */\n html: string;\n /** Where the block after them starts looking: the line after the last one. */\n resume: number;\n};\n\nexport const newMarkdownStream = (): MarkdownStream => ({ settled: \"\", html: \"\", resume: 0 });\n\n/**\n * renderMarkdown for text that grows while it is shown — always the same\n * string renderMarkdown(src) returns, but blocks that can no longer change are\n * rendered once and reused, so a streamed answer costs its open tail per\n * frame instead of its whole length.\n *\n * Every block renders from its own source slice alone, so the only question\n * is which blocks later text can still move. splitBlocks decides a block's\n * extent from its own lines and, at most, the first line of the block after\n * it: the blank line or fence opener that ends it, and for a list or quote the\n * next non-blank line, which may continue it. Whether a line is blank, a fence\n * opener or closer, a list item or a quote can change while it is the last,\n * unterminated line — `1` becomes `1.`, a closing ``` becomes ```js, ``` gains\n * a backtick and stops opening a fence, a blank line gets text. Every line\n * before the last is final. So a block is settled once the block after it\n * starts before the last line: a setext underline, a loose list's next item,\n * a table's delimiter row or the rest of an open fence all belong to the\n * block that is still open. (This renderer has no reference definitions,\n * footnotes or raw HTML blocks, the other constructs that reach back.) And\n * splitBlocks never looks behind the line it stands on, so splitting from the\n * line after the settled blocks yields the same blocks the whole text would.\n *\n * Text that does not start with `stream.settled` — a new run, an edit — drops\n * the cache and renders from scratch.\n */\nexport function renderMarkdownStream(src: string, stream: MarkdownStream): string {\n if (!src.startsWith(stream.settled)) Object.assign(stream, newMarkdownStream());\n\n const from = stream.resume;\n const tail = src.slice(from);\n const blocks = splitBlocks(tail);\n const lastLine = src.lastIndexOf(\"\\n\") + 1 - from;\n let html = stream.html;\n for (let i = 0; i < blocks.length; i += 1) {\n const rendered = renderBlock(tail, blocks[i]!, 0);\n html += rendered;\n if (i + 1 < blocks.length && blocks[i + 1]!.start < lastLine) {\n stream.html += rendered;\n stream.resume = from + blocks[i]!.end + 1;\n }\n }\n stream.settled = src.slice(0, lastLine + from);\n return html;\n}\n\n/**\n * Render for a document previewer: every block carries `data-sc-block`, so a\n * DOM selection resolves to a source span by walking up to the nearest one.\n *\n * Kept separate from renderMarkdown rather than added as an option, because\n * assistant prose has nothing to address and the extra attributes would be\n * noise in every message bubble.\n */\nexport function renderMarkdownWithAnchors(src: string): AnchoredMarkdown {\n const blocks = splitBlocks(src);\n const html = blocks\n .map((block, i) => {\n const rendered = renderBlock(src, block, 0);\n // Every branch of renderBlock returns markup, so the first tag always\n // exists; the anchor rides on it instead of an extra wrapper element,\n // which keeps the DOM (and therefore .sc-prose's spacing rules) unchanged.\n return rendered.replace(/^(\\s*<[a-z][a-z0-9]*)/i, `$1 data-sc-block=\"${i}\"`);\n })\n .join(\"\");\n return { html, blocks };\n}\n"],"mappings":";AAmBO,IAAM,gBAA+B,EAAE,QAAQ,SAAS,UAAU,MAAM;AAE/E,SAAS,oBAAoB,QAAiB;AAC5C,SAAO;AAAA,IACL,SAAS,IAAI,KAAK,aAAa,QAAQ,EAAE,UAAU,WAAW,uBAAuB,EAAE,CAAC;AAAA,IACxF,OAAO,IAAI,KAAK,aAAa,QAAQ,EAAE,uBAAuB,EAAE,CAAC;AAAA,IACjE,SAAS,IAAI,KAAK,aAAa,QAAQ,EAAE,uBAAuB,GAAG,aAAa,MAAM,CAAC;AAAA,IACvF,WAAW,IAAI,KAAK,aAAa,QAAQ,EAAE,uBAAuB,GAAG,aAAa,MAAM,CAAC;AAAA,EAC3F;AACF;AAEA,IAAM,gBAAgB,oBAAI,IAAoD;AAE9E,SAAS,WAAW,QAAiB;AACnC,QAAM,MAAM,UAAU;AACtB,MAAI,UAAU,cAAc,IAAI,GAAG;AACnC,MAAI,CAAC,SAAS;AACZ,cAAU,oBAAoB,MAAM;AACpC,kBAAc,IAAI,KAAK,OAAO;AAAA,EAChC;AACA,SAAO;AACT;AAEO,SAAS,YAAY,OAAgB,SAA0B,QAAQ,UAAyB,CAAC,GAAW;AACjH,MAAI,SAAS,KAAM,QAAO;AAC1B,QAAM,EAAE,QAAQ,SAAS,IAAI;AAC7B,QAAM,UAAU,WAAW,MAAM;AAEjC,UAAQ,QAAQ;AAAA,IACd,KAAK,UAAU;AACb,YAAM,IAAI,OAAO,KAAK;AACtB,UAAI,CAAC,OAAO,SAAS,CAAC,EAAG,QAAO,OAAO,KAAK;AAG5C,aA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MAAM,IAAI;AAC3B,QAAM,SAAS,YAAY,IAAI;AAC/B,QAAM,WAAW,IAAI,YAAY,IAAI,IAAI,IAAI;AAC7C,MAAI,OAAO,OAAO;AAClB,WAAS,IAAI,GAAG,IAAI,OAAO,QAAQ,KAAK,GAAG;AACzC,UAAM,WAAW,YAAY,MAAM,OAAO,CAAC,GAAI,CAAC;AAChD,YAAQ;AACR,QAAI,IAAI,IAAI,OAAO,UAAU,OAAO,IAAI,CAAC,EAAG,QAAQ,UAAU;AAC5D,aAAO,QAAQ;AACf,aAAO,SAAS,OAAO,OAAO,CAAC,EAAG,MAAM;AAAA,IAC1C;AAAA,EACF;AACA,SAAO,UAAU,IAAI,MAAM,GAAG,WAAW,IAAI;AAC7C,SAAO;AACT;AAUO,SAAS,0BAA0B,KAA+B;AACvE,QAAM,SAAS,YAAY,GAAG;AAC9B,QAAM,OAAO,OACV,IAAI,CAAC,OAAO,MAAM;AACjB,UAAM,WAAW,YAAY,KAAK,OAAO,CAAC;AAI1C,WAAO,SAAS,QAAQ,0BAA0B,qBAAqB,CAAC,GAAG;AAAA,EAC7E,CAAC,EACA,KAAK,EAAE;AACV,SAAO,EAAE,MAAM,OAAO;AACxB;","names":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@supersolutions/super-chat-ui-core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"description": "Framework-free helpers shared by superchat UI bindings: markdown rendering (incl. streaming), value formatting and thread export.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"author": "SUPER SOLUTION LABS INC",
|
|
@@ -44,7 +44,7 @@
|
|
|
44
44
|
"access": "public"
|
|
45
45
|
},
|
|
46
46
|
"dependencies": {
|
|
47
|
-
"@supersolutions/super-chat-core": "0.
|
|
47
|
+
"@supersolutions/super-chat-core": "0.4.0"
|
|
48
48
|
},
|
|
49
49
|
"devDependencies": {
|
|
50
50
|
"tsup": "^8.3.5",
|