@ai-matrx/print 0.12.3 → 0.12.4

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.
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/education.ts","../src/core.ts","../src/katex-css.generated.ts","../src/math-text.ts","../src/document/math.ts"],"sourcesContent":["/**\n * @ai-matrx/print/education — the education / test-prep artifact library.\n *\n * Wave 3. Modeled on what the test-prep leaders actually hand a student\n * (Magoosh/7Sage one-pagers, Kaplan/Quizlet vocabulary lists, 7Sage's\n * week-by-week study calendar) per\n * `common-docs/projects/npm-package-extraction/PRINT-EDUCATION-RESEARCH.md`:\n *\n * - density WITH hierarchy — never a wall of text; every unit is a titled,\n * break-safe block inside a dense column flow;\n * - every artifact is independently printable — one sheet, no companion file;\n * - ONE content source → MANY layouts chosen at print time (the Quizlet\n * Table/Glossary/Small/Large picker). Our BlockPrinter variants ARE that\n * picker: the caller's data never changes, only the variant id.\n *\n * Three printers, all pure string composition over `./core`:\n * cheatSheetPrinter — the dense one-pager (2-col / 3-col ultra / large print)\n * glossaryPrinter — vocabulary list (term/definition table / compact list)\n * studyCalendarPrinter — week-by-week schedule (week rows / landscape grid)\n *\n * Zero dependencies, no module-level mutable state, import-inert: `window` is\n * only touched inside `print()` via core's `openPrintWindow`.\n */\n\nimport {\n buildPrintDocument,\n openPrintWindow,\n type BlockPrinter,\n type PrintOutcome,\n type PrintSettings,\n} from \"./core\";\nimport { formulaHtml, mathTextHtml } from \"./math-text\";\nimport { escapeHtml } from \"@ai-matrx/kit/html-escape\";\n\n// ---------------------------------------------------------------------------\n// Data contracts\n// ---------------------------------------------------------------------------\n\n/** One line of a cheat sheet: a term, and any of definition / formula / note. */\nexport interface CheatSheetItem {\n term: string;\n definition?: string;\n formula?: string;\n note?: string;\n}\n\n/** A titled group of cheat-sheet items — renders as a dense heading bar. */\nexport interface CheatSheetSection {\n heading: string;\n items: CheatSheetItem[];\n}\n\n/** The whole one-pager. */\nexport interface CheatSheetData {\n title: string;\n subtitle?: string;\n sections: CheatSheetSection[];\n}\n\n/** One glossary / vocabulary row. */\nexport interface GlossaryEntry {\n term: string;\n definition: string;\n}\n\n/** The whole vocabulary list. */\nexport interface GlossaryData {\n title: string;\n entries: GlossaryEntry[];\n}\n\n/** One day of a study plan — its tasks, and optionally a milestone banner. */\nexport interface StudyDay {\n label: string;\n tasks: string[];\n milestone?: string;\n}\n\n/** One week of a study plan. */\nexport interface StudyWeek {\n label: string;\n days: StudyDay[];\n}\n\n/** The whole study calendar. */\nexport interface StudyCalendarData {\n title: string;\n subtitle?: string;\n weeks: StudyWeek[];\n}\n\nexport type CheatSheetVariant = \"two-column\" | \"three-column\" | \"one-column\";\nexport type GlossaryVariant = \"table\" | \"compact-list\";\nexport type StudyCalendarVariant = \"week-rows\" | \"landscape-grid\";\n\n// ---------------------------------------------------------------------------\n// Structural readers — the host may hand us anything; nothing here throws.\n// ---------------------------------------------------------------------------\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n return typeof value === \"object\" && value !== null && !Array.isArray(value);\n}\n\nfunction readString(source: unknown, key: string): string {\n if (!isRecord(source)) return \"\";\n const value = source[key];\n return typeof value === \"string\" ? value : \"\";\n}\n\nfunction readArray(source: unknown, key: string): unknown[] {\n if (!isRecord(source)) return [];\n const value = source[key];\n return Array.isArray(value) ? value : [];\n}\n\n/** A trimmed title, or the given fallback when the host supplied none. */\nfunction readTitle(data: unknown, fallback: string): string {\n const title = readString(data, \"title\").trim();\n return title.length > 0 ? title : fallback;\n}\n\n/** String list with non-strings and blank entries dropped. */\nfunction readStringList(source: unknown, key: string): string[] {\n return readArray(source, key)\n .filter((entry): entry is string => typeof entry === \"string\")\n .map((entry) => entry.trim())\n .filter((entry) => entry.length > 0);\n}\n\nfunction extractCheatSheetSections(data: unknown): CheatSheetSection[] {\n return readArray(data, \"sections\")\n .map((raw): CheatSheetSection => {\n const items = readArray(raw, \"items\")\n .filter(isRecord)\n .map(\n (rawItem): CheatSheetItem => ({\n term: readString(rawItem, \"term\"),\n definition: readString(rawItem, \"definition\"),\n formula: readString(rawItem, \"formula\"),\n note: readString(rawItem, \"note\"),\n }),\n )\n .filter(\n (item) =>\n item.term.trim().length > 0 ||\n (item.definition ?? \"\").trim().length > 0 ||\n (item.formula ?? \"\").trim().length > 0,\n );\n return { heading: readString(raw, \"heading\"), items };\n })\n .filter((section) => section.items.length > 0);\n}\n\nfunction extractGlossaryEntries(data: unknown): GlossaryEntry[] {\n return readArray(data, \"entries\")\n .filter(isRecord)\n .map(\n (raw): GlossaryEntry => ({\n term: readString(raw, \"term\"),\n definition: readString(raw, \"definition\"),\n }),\n )\n .filter(\n (entry) =>\n entry.term.trim().length > 0 || entry.definition.trim().length > 0,\n );\n}\n\nfunction extractStudyWeeks(data: unknown): StudyWeek[] {\n return readArray(data, \"weeks\")\n .map((rawWeek): StudyWeek => {\n const days = readArray(rawWeek, \"days\")\n .filter(isRecord)\n .map((rawDay): StudyDay => {\n const milestone = readString(rawDay, \"milestone\");\n return {\n label: readString(rawDay, \"label\"),\n tasks: readStringList(rawDay, \"tasks\"),\n milestone,\n };\n })\n .filter(\n (day) =>\n day.label.trim().length > 0 ||\n day.tasks.length > 0 ||\n (day.milestone ?? \"\").trim().length > 0,\n );\n return { label: readString(rawWeek, \"label\"), days };\n })\n .filter((week) => week.days.length > 0);\n}\n\n// ---------------------------------------------------------------------------\n// Settings helpers\n// ---------------------------------------------------------------------------\n\nfunction boolSetting(\n raw: PrintSettings | undefined,\n key: string,\n fallback: boolean,\n): boolean {\n const value = raw?.[key];\n return value === undefined ? fallback : Boolean(value);\n}\n\nfunction numberSetting(raw: PrintSettings | undefined, key: string): number {\n const value = raw?.[key];\n return typeof value === \"number\" && Number.isFinite(value) ? value : 0;\n}\n\n/**\n * Resolve a `range` setting against a list length, the flashcards precedent:\n * 0 / missing / out-of-bounds fall back to the ends, an inverted pair is\n * swapped, and the result is always a valid 1-based inclusive window.\n * `startIndex` is the 0-based offset of the first kept item, so callers can\n * keep numbering items by their position in the FULL list.\n */\nfunction resolveRange(\n raw: PrintSettings | undefined,\n fromKey: string,\n toKey: string,\n total: number,\n): { startIndex: number; endIndex: number } {\n const rawFrom = numberSetting(raw, fromKey);\n const rawTo = numberSetting(raw, toKey);\n const start = rawFrom > 0 ? Math.min(rawFrom, total) : 1;\n const end = rawTo > 0 ? Math.min(rawTo, total) : total;\n const [from, to] = start <= end ? [start, end] : [end, start];\n return { startIndex: from - 1, endIndex: to };\n}\n\n/** The polite empty-data document (the flashcards precedent). */\nfunction printEmptyDocument(\n message: string,\n title: string,\n styles: string,\n filename: string,\n): PrintOutcome {\n return openPrintWindow(\n buildPrintDocument(`<p>${escapeHtml(message)}</p>`, title, styles),\n filename,\n );\n}\n\n/** A printable, ink-free checkbox — the \"mastered\" / task-done square. */\nconst CHECKBOX_HTML = `<span class=\"edu-check\" aria-hidden=\"true\"></span>`;\n\n/** Shared header + checkbox styles for every education artifact. */\nconst EDU_BASE_STYLES = `\n h1.edu-title {\n font-size: 15pt !important;\n font-weight: 700;\n color: #0f172a;\n margin: 0 0 3px 0;\n letter-spacing: -0.01em;\n border-bottom: none !important;\n }\n .edu-subtitle {\n font-size: 9pt;\n color: #475569;\n margin: 0;\n }\n .edu-meta {\n font-size: 8pt;\n color: #64748b;\n margin-top: 2px;\n }\n .edu-header {\n border-bottom: 1.5px solid #cbd5e1;\n padding-bottom: 8px;\n margin-bottom: 12px;\n }\n .edu-hint {\n font-size: 8pt;\n color: #475569;\n background: #f1f5f9;\n border: 1px solid #cbd5e1;\n border-radius: 6px;\n padding: 6px 10px;\n margin-bottom: 12px;\n line-height: 1.45;\n }\n .edu-check {\n display: inline-block;\n width: 9pt;\n height: 9pt;\n border: 1px solid #64748b;\n border-radius: 2px;\n background: #fff;\n vertical-align: -1px;\n margin-right: 6px;\n flex: 0 0 auto;\n }\n\n @media print {\n @page { margin: 12mm 10mm; }\n .edu-hint { display: none !important; }\n .edu-check {\n -webkit-print-color-adjust: exact;\n print-color-adjust: exact;\n }\n }\n`;\n\n// ---------------------------------------------------------------------------\n// 1. Cheat sheet — the Magoosh / 7Sage dense one-pager\n// ---------------------------------------------------------------------------\n\nconst CHEAT_SHEET_STYLES = `\n ${EDU_BASE_STYLES}\n\n .cs-sheet {\n column-gap: 14px;\n column-fill: auto;\n }\n .cs-cols-2 { column-count: 2; font-size: 8.5pt; }\n .cs-cols-3 { column-count: 3; font-size: 7.5pt; }\n .cs-cols-1 { column-count: 1; font-size: 11.5pt; }\n\n .cs-section {\n break-inside: auto;\n page-break-inside: auto;\n margin-bottom: 10px;\n }\n\n /* Section headings are dense BARS, not airy titles — the hierarchy that\n keeps a one-pager scannable instead of a wall of text. */\n .cs-section-bar {\n display: block;\n background: #1e293b;\n color: #f8fafc;\n font-size: 8pt !important;\n font-weight: 700;\n letter-spacing: 0.07em;\n text-transform: uppercase;\n padding: 3px 7px;\n margin: 0 0 5px 0 !important;\n border-radius: 3px;\n border-bottom: none !important;\n break-after: avoid;\n page-break-after: avoid;\n }\n .cs-cols-1 .cs-section-bar { font-size: 11pt !important; padding: 5px 10px; }\n\n .cs-section-rule {\n height: 0;\n border-bottom: 1px solid #cbd5e1;\n margin: 0 0 6px 0;\n }\n\n .cs-item {\n break-inside: avoid;\n page-break-inside: avoid;\n margin-bottom: 6px;\n padding-left: 5px;\n border-left: 2px solid #e2e8f0;\n line-height: 1.4;\n }\n .cs-term {\n font-weight: 700;\n color: #0f172a;\n }\n .cs-def {\n color: #334155;\n }\n .cs-note {\n color: #64748b;\n font-style: italic;\n }\n\n /* Boxed formula — mono + border is how every leader prints an equation. */\n code.cs-formula {\n display: block;\n font-family: \"SFMono-Regular\", Menlo, Consolas, \"Liberation Mono\", monospace;\n font-size: 0.95em;\n background: #f8fafc;\n border: 1px solid #94a3b8;\n border-radius: 3px;\n padding: 2px 5px;\n margin: 3px 0;\n white-space: pre-wrap;\n word-break: break-word;\n }\n\n /* Compact: tighter leading and a smaller floor for a true single sheet. */\n .cs-compact.cs-cols-2 { font-size: 7.5pt; }\n .cs-compact.cs-cols-3 { font-size: 6.5pt; }\n .cs-compact.cs-cols-1 { font-size: 10pt; }\n .cs-compact .cs-item { margin-bottom: 3px; line-height: 1.25; }\n .cs-compact .cs-section { margin-bottom: 6px; }\n .cs-compact .cs-section-bar { padding: 2px 6px; margin-bottom: 3px !important; }\n\n @media print {\n .cs-section-bar {\n -webkit-print-color-adjust: exact;\n print-color-adjust: exact;\n }\n code.cs-formula {\n -webkit-print-color-adjust: exact;\n print-color-adjust: exact;\n }\n }\n`;\n\nconst CHEAT_SHEET_COLUMN_CLASS: Record<CheatSheetVariant, string> = {\n \"two-column\": \"cs-cols-2\",\n \"three-column\": \"cs-cols-3\",\n \"one-column\": \"cs-cols-1\",\n};\n\nfunction renderCheatSheetItem(item: CheatSheetItem): string {\n const parts: string[] = [];\n const term = item.term.trim();\n const definition = (item.definition ?? \"\").trim();\n const formula = (item.formula ?? \"\").trim();\n const note = (item.note ?? \"\").trim();\n\n if (term) parts.push(`<span class=\"cs-term\">${mathTextHtml(term)}</span>`);\n if (definition) {\n parts.push(\n `${term ? \" \" : \"\"}<span class=\"cs-def\">${mathTextHtml(definition)}</span>`,\n );\n }\n if (formula) {\n parts.push(`<code class=\"cs-formula\">${formulaHtml(formula)}</code>`);\n }\n if (note) parts.push(`<div class=\"cs-note\">${mathTextHtml(note)}</div>`);\n\n return `<div class=\"cs-item\">${parts.join(\"\")}</div>`;\n}\n\nfunction renderCheatSheet(\n data: CheatSheetData,\n variant: CheatSheetVariant,\n opts: { showSectionRules: boolean; compact: boolean; duplexHint: boolean },\n): string {\n const itemCount = data.sections.reduce(\n (total, section) => total + section.items.length,\n 0,\n );\n const subtitle = (data.subtitle ?? \"\").trim();\n\n const sections = data.sections\n .map((section) => {\n const heading = section.heading.trim();\n const bar = heading\n ? `<h2 class=\"cs-section-bar\">${mathTextHtml(heading)}</h2>`\n : \"\";\n const rule = opts.showSectionRules\n ? `<div class=\"cs-section-rule\"></div>`\n : \"\";\n const items = section.items.map(renderCheatSheetItem).join(\"\\n\");\n return `<section class=\"cs-section\">\n${bar}${rule}\n${items}\n</section>`;\n })\n .join(\"\\n\");\n\n const hint = opts.duplexHint\n ? `<div class=\"edu-hint\">Two-sided sheet: print double-sided, flip on <strong>long edge</strong>, 100% scale, no margins — then trim or slip it into a sleeve.</div>`\n : \"\";\n\n const columnClass = CHEAT_SHEET_COLUMN_CLASS[variant];\n const compactClass = opts.compact ? \" cs-compact\" : \"\";\n\n return `<div class=\"edu-header\">\n <h1 class=\"edu-title\">${mathTextHtml(data.title)}</h1>\n ${subtitle ? `<p class=\"edu-subtitle\">${mathTextHtml(subtitle)}</p>` : \"\"}\n <div class=\"edu-meta\">${data.sections.length} section${data.sections.length !== 1 ? \"s\" : \"\"} &nbsp;·&nbsp; ${itemCount} item${itemCount !== 1 ? \"s\" : \"\"}</div>\n</div>\n${hint}\n<div class=\"cs-sheet ${columnClass}${compactClass}\">\n${sections}\n</div>`;\n}\n\nexport const cheatSheetPrinter: BlockPrinter = {\n label: \"Print cheat sheet\",\n\n variants: [\n {\n id: \"two-column\",\n label: \"Two column (recommended)\",\n description:\n \"The classic dense one-pager — two columns, boxed formulas, section bars. Fits a surprising amount on a single sheet and still reads at arm's length\",\n },\n {\n id: \"three-column\",\n label: \"Three column (ultra-dense)\",\n description:\n \"Maximum content per sheet — three narrow columns at a smaller type size. Best for a reference you scan rather than read\",\n },\n {\n id: \"one-column\",\n label: \"Single column (large print)\",\n description:\n \"One wide column at a comfortable reading size — for studying, for a wall, or for anyone who needs bigger type\",\n },\n ],\n\n settings: [\n {\n type: \"boolean\" as const,\n id: \"showSectionRules\",\n label: \"Rule under each section\",\n description:\n \"Draws a hairline under every section heading — extra separation when sections run together\",\n defaultValue: true,\n },\n {\n type: \"boolean\" as const,\n id: \"compact\",\n label: \"Compact\",\n description:\n \"Tighter leading and a smaller type floor — use when the sheet spills onto a second page\",\n defaultValue: false,\n },\n {\n type: \"boolean\" as const,\n id: \"duplexHint\",\n label: \"Show double-sided printing tip\",\n description:\n \"Adds an on-screen note with the duplex settings for a two-sided sheet. Never printed\",\n defaultValue: false,\n },\n ],\n\n print(\n data: unknown,\n variantId: string = \"two-column\",\n rawSettings?: PrintSettings,\n ): PrintOutcome {\n const title = readTitle(data, \"Cheat Sheet\");\n const sections = extractCheatSheetSections(data);\n\n if (sections.length === 0) {\n return printEmptyDocument(\n \"No cheat sheet data available to print.\",\n title,\n CHEAT_SHEET_STYLES,\n \"cheat-sheet\",\n );\n }\n\n const variant: CheatSheetVariant =\n variantId === \"three-column\" || variantId === \"one-column\"\n ? variantId\n : \"two-column\";\n\n const subtitle = readString(data, \"subtitle\");\n const body = renderCheatSheet(\n { title, subtitle, sections },\n variant,\n {\n showSectionRules: boolSetting(rawSettings, \"showSectionRules\", true),\n compact: boolSetting(rawSettings, \"compact\", false),\n duplexHint: boolSetting(rawSettings, \"duplexHint\", false),\n },\n );\n\n return openPrintWindow(\n buildPrintDocument(body, title, CHEAT_SHEET_STYLES),\n \"cheat-sheet\",\n );\n },\n};\n\n// ---------------------------------------------------------------------------\n// 2. Glossary / vocabulary list — Kaplan / Quizlet Glossary\n// ---------------------------------------------------------------------------\n\nconst GLOSSARY_STYLES = `\n ${EDU_BASE_STYLES}\n\n table.gl-table {\n width: 100%;\n border-collapse: collapse;\n margin-top: 4px;\n font-size: 9.5pt;\n }\n table.gl-table thead th {\n background: #1e293b;\n color: #f8fafc;\n text-align: left;\n font-size: 8pt;\n font-weight: 700;\n letter-spacing: 0.06em;\n text-transform: uppercase;\n padding: 5px 9px;\n border: none;\n }\n table.gl-table th.gl-th-check { width: 22px; }\n table.gl-table th.gl-th-term { width: 32%; }\n\n table.gl-table tbody tr.gl-row {\n break-inside: avoid;\n page-break-inside: avoid;\n }\n table.gl-table tbody td {\n padding: 4px 9px;\n border-bottom: 1px solid #e2e8f0;\n vertical-align: top;\n line-height: 1.4;\n background: transparent;\n }\n table.gl-table tbody tr:nth-child(even) td { background: #f8fafc; }\n td.gl-check-cell { width: 22px; text-align: center; }\n td.gl-term-cell { font-weight: 700; color: #0f172a; }\n .gl-index {\n display: inline-block;\n min-width: 20px;\n font-size: 8pt;\n font-weight: 400;\n color: #94a3b8;\n }\n\n ul.gl-list {\n column-count: 2;\n column-gap: 18px;\n list-style: none;\n margin: 4px 0 0 0;\n padding: 0;\n font-size: 8.5pt;\n }\n ul.gl-list li.gl-entry {\n break-inside: avoid;\n page-break-inside: avoid;\n margin-bottom: 5px;\n padding-left: 4px;\n border-left: 2px solid #e2e8f0;\n line-height: 1.35;\n }\n .gl-term { font-weight: 700; color: #0f172a; }\n .gl-def { color: #334155; }\n\n @media print {\n table.gl-table thead th {\n -webkit-print-color-adjust: exact;\n print-color-adjust: exact;\n }\n table.gl-table tbody tr:nth-child(even) td {\n -webkit-print-color-adjust: exact;\n print-color-adjust: exact;\n }\n }\n`;\n\n/**\n * Alphabetize by term, case- and accent-insensitively. `Array.sort` is stable\n * (ES2019+), so equal terms keep their authored order — and with the setting\n * OFF the authored order is returned untouched.\n */\nfunction orderGlossaryEntries(\n entries: GlossaryEntry[],\n alphabetize: boolean,\n): GlossaryEntry[] {\n if (!alphabetize) return entries;\n return [...entries].sort((a, b) =>\n a.term.localeCompare(b.term, undefined, { sensitivity: \"base\" }),\n );\n}\n\nfunction renderGlossaryTable(\n entries: GlossaryEntry[],\n opts: { masteredCheckbox: boolean; showIndex: boolean; startIndex: number },\n): string {\n const rows = entries\n .map((entry, i) => {\n const check = opts.masteredCheckbox\n ? `<td class=\"gl-check-cell\">${CHECKBOX_HTML}</td>`\n : \"\";\n const index = opts.showIndex\n ? `<span class=\"gl-index\">${opts.startIndex + i + 1}.</span>`\n : \"\";\n return ` <tr class=\"gl-row\">\n${check ? ` ${check}\\n` : \"\"} <td class=\"gl-term-cell\">${index}${mathTextHtml(entry.term)}</td>\n <td class=\"gl-def\">${mathTextHtml(entry.definition)}</td>\n </tr>`;\n })\n .join(\"\\n\");\n\n const checkHead = opts.masteredCheckbox\n ? `<th class=\"gl-th-check\">✓</th>`\n : \"\";\n\n return `<table class=\"gl-table\">\n <thead>\n <tr>\n ${checkHead}<th class=\"gl-th-term\">Term</th>\n <th>Definition</th>\n </tr>\n </thead>\n <tbody>\n${rows}\n </tbody>\n</table>`;\n}\n\nfunction renderGlossaryList(\n entries: GlossaryEntry[],\n opts: { masteredCheckbox: boolean; showIndex: boolean; startIndex: number },\n): string {\n const items = entries\n .map((entry, i) => {\n const check = opts.masteredCheckbox ? CHECKBOX_HTML : \"\";\n const index = opts.showIndex\n ? `<span class=\"gl-index\">${opts.startIndex + i + 1}.</span>`\n : \"\";\n return ` <li class=\"gl-entry\">${check}${index}<span class=\"gl-term\">${mathTextHtml(entry.term)}</span> — <span class=\"gl-def\">${mathTextHtml(entry.definition)}</span></li>`;\n })\n .join(\"\\n\");\n\n return `<ul class=\"gl-list\">\n${items}\n</ul>`;\n}\n\nexport const glossaryPrinter: BlockPrinter = {\n label: \"Print glossary\",\n\n variants: [\n {\n id: \"table\",\n label: \"Term / definition table (recommended)\",\n description:\n \"Two-column table with a mastered checkbox per row — the Kaplan/Quizlet vocabulary sheet\",\n },\n {\n id: \"compact-list\",\n label: \"Compact list\",\n description:\n \"Two columns of one-line entries — many more terms per sheet, for a final review pass\",\n },\n ],\n\n settings: [\n {\n type: \"range\" as const,\n id: \"entryRange\",\n label: \"Entries to print\",\n description: \"Leave blank to print the whole list\",\n fromId: \"fromEntry\",\n toId: \"toEntry\",\n defaultFrom: 0,\n defaultTo: 0,\n min: 1,\n fromPlaceholder: \"1\",\n toPlaceholder: \"end\",\n },\n {\n type: \"boolean\" as const,\n id: \"alphabetize\",\n label: \"Alphabetize\",\n description:\n \"Sorts by term. Off prints the entries in the order they were authored\",\n defaultValue: false,\n },\n {\n type: \"boolean\" as const,\n id: \"masteredCheckbox\",\n label: \"Mastered checkbox\",\n description:\n \"An empty box on every row to tick off as each term is learned\",\n defaultValue: true,\n },\n {\n type: \"boolean\" as const,\n id: \"showIndex\",\n label: \"Number the entries\",\n description:\n \"Prints 1., 2., 3. … so a study partner can call out terms by number\",\n defaultValue: false,\n },\n ],\n\n print(\n data: unknown,\n variantId: string = \"table\",\n rawSettings?: PrintSettings,\n ): PrintOutcome {\n const title = readTitle(data, \"Glossary\");\n const allEntries = extractGlossaryEntries(data);\n\n if (allEntries.length === 0) {\n return printEmptyDocument(\n \"No glossary data available to print.\",\n title,\n GLOSSARY_STYLES,\n \"glossary\",\n );\n }\n\n // Order first, THEN slice: the range names positions on the printed page,\n // so \"entries 1–20\" alphabetized means the first twenty alphabetically.\n const ordered = orderGlossaryEntries(\n allEntries,\n boolSetting(rawSettings, \"alphabetize\", false),\n );\n const { startIndex, endIndex } = resolveRange(\n rawSettings,\n \"fromEntry\",\n \"toEntry\",\n ordered.length,\n );\n const entries = ordered.slice(startIndex, endIndex);\n\n const opts = {\n masteredCheckbox: boolSetting(rawSettings, \"masteredCheckbox\", true),\n showIndex: boolSetting(rawSettings, \"showIndex\", false),\n startIndex,\n };\n\n const variant: GlossaryVariant =\n variantId === \"compact-list\" ? \"compact-list\" : \"table\";\n const body =\n variant === \"compact-list\"\n ? renderGlossaryList(entries, opts)\n : renderGlossaryTable(entries, opts);\n\n const header = `<div class=\"edu-header\">\n <h1 class=\"edu-title\">${mathTextHtml(title)}</h1>\n <div class=\"edu-meta\">${entries.length} term${entries.length !== 1 ? \"s\" : \"\"}${entries.length !== allEntries.length ? ` of ${allEntries.length}` : \"\"}</div>\n</div>`;\n\n return openPrintWindow(\n buildPrintDocument(`${header}\\n${body}`, title, GLOSSARY_STYLES),\n \"glossary\",\n );\n },\n};\n\n// ---------------------------------------------------------------------------\n// 3. Study calendar / schedule — the 7Sage week-by-week plan\n// ---------------------------------------------------------------------------\n\nconst STUDY_CALENDAR_STYLES = `\n ${EDU_BASE_STYLES}\n\n /* A week is the unit that must never split across pages when it fits. */\n .sc-week {\n break-inside: avoid;\n page-break-inside: avoid;\n margin-bottom: 12px;\n border: 1px solid #cbd5e1;\n border-radius: 5px;\n overflow: hidden;\n }\n .sc-week-label {\n background: #1e293b;\n color: #f8fafc;\n font-size: 9pt !important;\n font-weight: 700;\n letter-spacing: 0.06em;\n text-transform: uppercase;\n padding: 4px 9px;\n margin: 0 !important;\n border-bottom: none !important;\n }\n\n .sc-days-rows .sc-day {\n display: block;\n border-top: 1px solid #e2e8f0;\n padding: 5px 9px;\n }\n .sc-days-rows .sc-day:first-child { border-top: none; }\n\n .sc-days-grid {\n display: grid;\n grid-auto-flow: column;\n grid-auto-columns: 1fr;\n }\n .sc-days-grid .sc-day {\n border-left: 1px solid #e2e8f0;\n padding: 5px 7px;\n min-height: 1.1in;\n }\n .sc-days-grid .sc-day:first-child { border-left: none; }\n\n .sc-day-label {\n font-size: 8pt;\n font-weight: 700;\n color: #0f172a;\n letter-spacing: 0.04em;\n text-transform: uppercase;\n margin-bottom: 3px;\n }\n\n ul.sc-tasks {\n list-style: none;\n margin: 0;\n padding: 0;\n font-size: 8.5pt;\n }\n li.sc-task {\n display: flex;\n align-items: flex-start;\n line-height: 1.35;\n margin-bottom: 2px;\n break-inside: avoid;\n page-break-inside: avoid;\n color: #334155;\n }\n\n /* Milestones are the thing a student actually plans around — they are\n visually LOUD and survive a black-and-white printer. */\n .sc-milestone {\n margin-top: 4px;\n border: 1.5px solid #b45309;\n border-left-width: 5px;\n background: #fef3c7;\n color: #78350f;\n font-size: 8pt;\n font-weight: 700;\n padding: 3px 7px;\n border-radius: 3px;\n line-height: 1.3;\n }\n .sc-milestone-flag {\n letter-spacing: 0.08em;\n text-transform: uppercase;\n margin-right: 5px;\n font-size: 7pt;\n }\n\n .sc-empty-day { font-size: 8pt; color: #94a3b8; font-style: italic; }\n\n @media print {\n .sc-week-label,\n .sc-milestone {\n -webkit-print-color-adjust: exact;\n print-color-adjust: exact;\n }\n }\n`;\n\n/** Landscape geometry lives with the variant, not the shared sheet. */\nconst STUDY_CALENDAR_LANDSCAPE_STYLES = `\n ${STUDY_CALENDAR_STYLES}\n\n @media print {\n @page { size: landscape; margin: 10mm; }\n }\n`;\n\nfunction renderStudyDay(\n day: StudyDay,\n opts: { taskCheckbox: boolean; showMilestones: boolean },\n): string {\n const label = day.label.trim();\n const milestone = (day.milestone ?? \"\").trim();\n\n const tasks =\n day.tasks.length > 0\n ? `<ul class=\"sc-tasks\">\n${day.tasks\n .map(\n (task) =>\n ` <li class=\"sc-task\">${opts.taskCheckbox ? CHECKBOX_HTML : \"\"}<span class=\"sc-task-text\">${mathTextHtml(task)}</span></li>`,\n )\n .join(\"\\n\")}\n </ul>`\n : `<div class=\"sc-empty-day\">Rest / catch-up</div>`;\n\n const milestoneHtml =\n opts.showMilestones && milestone\n ? `\\n <div class=\"sc-milestone\"><span class=\"sc-milestone-flag\">Milestone</span>${mathTextHtml(milestone)}</div>`\n : \"\";\n\n return ` <div class=\"sc-day\">\n ${label ? `<div class=\"sc-day-label\">${mathTextHtml(label)}</div>` : \"\"}\n ${tasks}${milestoneHtml}\n </div>`;\n}\n\nfunction renderStudyCalendar(\n data: StudyCalendarData,\n variant: StudyCalendarVariant,\n opts: { taskCheckbox: boolean; showMilestones: boolean },\n): string {\n const daysClass =\n variant === \"landscape-grid\" ? \"sc-days sc-days-grid\" : \"sc-days sc-days-rows\";\n const subtitle = (data.subtitle ?? \"\").trim();\n const taskCount = data.weeks.reduce(\n (total, week) =>\n total + week.days.reduce((sum, day) => sum + day.tasks.length, 0),\n 0,\n );\n\n const weeks = data.weeks\n .map((week) => {\n const label = week.label.trim();\n return `<section class=\"sc-week\">\n ${label ? `<h2 class=\"sc-week-label\">${mathTextHtml(label)}</h2>` : \"\"}\n <div class=\"${daysClass}\">\n${week.days.map((day) => renderStudyDay(day, opts)).join(\"\\n\")}\n </div>\n</section>`;\n })\n .join(\"\\n\");\n\n const hint =\n variant === \"landscape-grid\"\n ? `<div class=\"edu-hint\">Set your printer to <strong>Landscape</strong> — each week prints as a row of day columns.</div>`\n : \"\";\n\n return `<div class=\"edu-header\">\n <h1 class=\"edu-title\">${mathTextHtml(data.title)}</h1>\n ${subtitle ? `<p class=\"edu-subtitle\">${mathTextHtml(subtitle)}</p>` : \"\"}\n <div class=\"edu-meta\">${data.weeks.length} week${data.weeks.length !== 1 ? \"s\" : \"\"} &nbsp;·&nbsp; ${taskCount} task${taskCount !== 1 ? \"s\" : \"\"}</div>\n</div>\n${hint}\n<div class=\"sc-plan\">\n${weeks}\n</div>`;\n}\n\nexport const studyCalendarPrinter: BlockPrinter = {\n label: \"Print study calendar\",\n\n variants: [\n {\n id: \"week-rows\",\n label: \"Week per block (portrait, recommended)\",\n description:\n \"Each week is one block with its days stacked as rows — the most room for tasks, and a week never splits across pages when it fits\",\n },\n {\n id: \"landscape-grid\",\n label: \"Calendar grid (landscape)\",\n description:\n \"Each week is a row of day columns, calendar-style — best for a wall or a binder pocket\",\n },\n ],\n\n settings: [\n {\n type: \"range\" as const,\n id: \"weekRange\",\n label: \"Weeks to print\",\n description: \"Leave blank to print the whole plan\",\n fromId: \"fromWeek\",\n toId: \"toWeek\",\n defaultFrom: 0,\n defaultTo: 0,\n min: 1,\n fromPlaceholder: \"1\",\n toPlaceholder: \"end\",\n },\n {\n type: \"boolean\" as const,\n id: \"taskCheckbox\",\n label: \"Checkbox per task\",\n description: \"An empty box in front of every task to tick off as it is done\",\n defaultValue: true,\n },\n {\n type: \"boolean\" as const,\n id: \"showMilestones\",\n label: \"Show milestones\",\n description:\n \"Prints each milestone as a bordered banner on its day — practice tests, deadlines, review checkpoints\",\n defaultValue: true,\n },\n ],\n\n print(\n data: unknown,\n variantId: string = \"week-rows\",\n rawSettings?: PrintSettings,\n ): PrintOutcome {\n const title = readTitle(data, \"Study Calendar\");\n const allWeeks = extractStudyWeeks(data);\n const variant: StudyCalendarVariant =\n variantId === \"landscape-grid\" ? \"landscape-grid\" : \"week-rows\";\n const styles =\n variant === \"landscape-grid\"\n ? STUDY_CALENDAR_LANDSCAPE_STYLES\n : STUDY_CALENDAR_STYLES;\n\n if (allWeeks.length === 0) {\n return printEmptyDocument(\n \"No study calendar data available to print.\",\n title,\n styles,\n \"study-calendar\",\n );\n }\n\n const { startIndex, endIndex } = resolveRange(\n rawSettings,\n \"fromWeek\",\n \"toWeek\",\n allWeeks.length,\n );\n const weeks = allWeeks.slice(startIndex, endIndex);\n\n const subtitle = readString(data, \"subtitle\");\n const body = renderStudyCalendar({ title, subtitle, weeks }, variant, {\n taskCheckbox: boolSetting(rawSettings, \"taskCheckbox\", true),\n showMilestones: boolSetting(rawSettings, \"showMilestones\", true),\n });\n\n return openPrintWindow(\n buildPrintDocument(body, title, styles),\n \"study-calendar\",\n );\n },\n};\n","/**\n * @ai-matrx/print/core — the Block Print contract & print-window composition.\n *\n * Ported VERBATIM from matrx-frontend `lib/block-print/block-print-utils.ts`\n * (2026-08-29 state, including the `number` and `select` PrintSetting types the\n * commerce label lane added). Zero dependencies; touches `window` only at call\n * time, so the module stays import-inert and RSC-safe.\n *\n * BlockPrinter is the only interface a host system needs to know about.\n * Each printable unit exports its own BlockPrinter alongside its render\n * component; host code only ever calls print(data, variantId, settings).\n *\n * `buildFitTextScript` is the ONE auto-shrink script (the flashcards\n * FIT_TEXT pattern, parameterized by selector so the label lane shares it).\n */\n\n// THE ONE HTML escaper (duplication census row 14). Nine copies of\n// `escapeHtml` were live across the fleet and THEY DID NOT ESCAPE THE SAME\n// CHARACTERS — a string safe through one was an attribute break-out through\n// another. It moved to `@ai-matrx/kit/html-escape` with a decided character\n// set: an HTML escaper must not require this package's jspdf + html2canvas\n// graph. Not re-exported from here; import `@ai-matrx/kit/html-escape`.\nimport { downloadFile } from \"@ai-matrx/kit/download\";\nimport { escapeHtml } from \"@ai-matrx/kit/html-escape\";\nimport { KATEX_CSS, KATEX_CSS_MARKER } from \"./katex-css.generated\";\n\n// ─── Contract ────────────────────────────────────────────────────────────────\n\nexport interface PrintVariant {\n id: string;\n label: string;\n description?: string;\n}\n\n/**\n * A single user-configurable setting shown in the print dialog.\n * Extend the discriminated union for new control types\n * without breaking existing printers.\n */\nexport type PrintSetting =\n | {\n type: \"boolean\";\n id: string;\n label: string;\n description?: string;\n /** Default value shown when the dialog first opens */\n defaultValue: boolean;\n /** Which variant IDs this setting applies to. Omit = applies to all. */\n appliesTo?: string[];\n }\n | {\n /**\n * A numeric \"from → to\" range control, rendered as two small number inputs.\n * Writes two entries into the resolved PrintSettings map — one under fromId,\n * one under toId. Printers interpret 0 (or missing) as \"no bound\" by convention.\n */\n type: \"range\";\n /** Stable id used as React key — not written to the settings map */\n id: string;\n label: string;\n description?: string;\n /** Settings map key for the lower bound value */\n fromId: string;\n /** Settings map key for the upper bound value */\n toId: string;\n defaultFrom: number;\n defaultTo: number;\n /** Minimum accepted value for each input (inclusive). Default 0. */\n min?: number;\n /** Placeholder shown when the input is empty (0). Default \"start\" / \"end\". */\n fromPlaceholder?: string;\n toPlaceholder?: string;\n /** Which variant IDs this setting applies to. Omit = applies to all. */\n appliesTo?: string[];\n }\n | {\n /** A single numeric input (e.g. \"start at label #\", \"copies\"). */\n type: \"number\";\n id: string;\n label: string;\n description?: string;\n defaultValue: number;\n /** Minimum accepted value (inclusive). Default 0. */\n min?: number;\n /** Maximum accepted value (inclusive). Omit = unbounded. */\n max?: number;\n /** Which variant IDs this setting applies to. Omit = applies to all. */\n appliesTo?: string[];\n }\n | {\n /** A one-of-N choice rendered as a compact segmented row. */\n type: \"select\";\n id: string;\n label: string;\n description?: string;\n options: { value: string; label: string }[];\n defaultValue: string;\n /** Which variant IDs this setting applies to. Omit = applies to all. */\n appliesTo?: string[];\n };\n\n/** A resolved map of setting id → current value, passed to print(). */\nexport type PrintSettings = Record<string, boolean | string | number>;\n\n/**\n * The self-contained print capability that each block can export.\n * Host code only ever calls print(data, variantId, settings) — it never inspects internals.\n */\nexport interface BlockPrinter {\n /** Tooltip / aria-label for the print button in the block header */\n label: string;\n\n /**\n * Variants offered to the user before printing.\n * Empty array = no options dialog shown; prints immediately with defaults.\n */\n variants: PrintVariant[];\n\n /**\n * Optional user-configurable settings shown below the variant picker.\n * Omit entirely if the block has no configurable settings.\n */\n settings?: PrintSetting[];\n\n /**\n * Execute the print.\n * data — the block's structured data (serverData or parsed content)\n * variantId — which variant was chosen (undefined = default / no variants)\n * settings — resolved setting values chosen by the user\n *\n * MAY resolve to a PrintOutcome (\"opened\" | \"downloaded\") so the host can\n * tell the user when the popup-blocked download fallback fired; `void`\n * stays legal for printers that don't go through a print window.\n */\n print: (\n data: unknown,\n variantId?: string,\n settings?: PrintSettings,\n ) => void | PrintOutcome | Promise<void | PrintOutcome>;\n\n /**\n * The block as it appears INSIDE a composed print (a message's Print / Full\n * Print, a document export): the same adapter the block's own print uses,\n * returning body HTML or a picture. A frame block (an HTML page) answers\n * with an image — a composed print window runs no author scripts — or an\n * honest `{ notice }` when no picture can be made. Absent ⇒ the composer\n * prints the block's source.\n */\n toPrintHtml?: (data: unknown, context: PrintBlockContext) => PrintBlockOutput | null | Promise<PrintBlockOutput | null>;\n}\n\n/** Where a block sits when a composer asks for its print form. */\nexport interface PrintBlockContext {\n /** The registry key the block was found under (artifact type or `__kind`). */\n readonly type: string;\n /** The block's raw source text, exactly as it sits in the message. */\n readonly raw: string;\n /** The block's title, when the wire form carries one. */\n readonly title?: string | undefined;\n /** The wire form's attributes (an `<artifact>`'s `id`, `version`) — how a printer finds the block's record. */\n readonly attributes?: Readonly<Record<string, string>> | undefined;\n}\n\n/**\n * A block's print form inside a composed print. `html` is trusted body HTML\n * from a printer (escape what you interpolate); `image` is a picture (a\n * captured page, a drawn diagram); `notice` is an honest line printed in the\n * block's place when neither exists.\n */\nexport type PrintBlockOutput =\n | { readonly html: string }\n | { readonly image: { readonly src: string; readonly alt?: string | undefined; readonly caption?: string | undefined } }\n | { readonly notice: string };\n\n// ─── The ONE block-printer registry ───────────────────────────────────────────\n//\n// Keyed by artifact type / `__kind`. A block's own print button, the canvas\n// tab's Print and the message composer all read the same entry, so a block\n// has one print adapter with every caller. Lives on globalThis under a\n// Symbol.for key so duplicated bundles (ESM + CJS) share one registry.\n\nconst PRINTER_REGISTRY = Symbol.for(\"ai-matrx.print.block-printers\");\n\nfunction printerRegistry(): Map<string, BlockPrinter> {\n const g = globalThis as unknown as { [PRINTER_REGISTRY]?: Map<string, BlockPrinter> };\n g[PRINTER_REGISTRY] ??= new Map();\n return g[PRINTER_REGISTRY];\n}\n\n/** Registers `printer` under each key (artifact type and/or `__kind`). Returns the unregister. */\nexport function registerBlockPrinter(keys: string | readonly string[], printer: BlockPrinter): () => void {\n const map = printerRegistry();\n const list = (typeof keys === \"string\" ? [keys] : keys).map((key) => key.toLowerCase());\n for (const key of list) map.set(key, printer);\n return () => {\n for (const key of list) if (map.get(key) === printer) map.delete(key);\n };\n}\n\n/** The printer registered for an artifact type or `__kind` (case-insensitive). */\nexport function getBlockPrinter(key: string | null | undefined): BlockPrinter | undefined {\n return key ? printerRegistry().get(key.toLowerCase()) : undefined;\n}\n\n/** Every registered key — for guards and diagnostics. */\nexport function listBlockPrinterKeys(): string[] {\n return [...printerRegistry().keys()];\n}\n\n/** The HTML a composer puts in a block's place for a `PrintBlockOutput`. */\nexport function printBlockOutputHtml(output: PrintBlockOutput): string {\n if (\"html\" in output) return `<div class=\"matrx-print-block\">${output.html}</div>`;\n if (\"image\" in output) {\n const { src, alt, caption } = output.image;\n return `<figure class=\"matrx-print-block matrx-print-image\"><img src=\"${escapeHtml(src)}\" alt=\"${escapeHtml(\n alt ?? \"Picture\",\n )}\" style=\"max-width:100%;height:auto\">${caption ? `<figcaption>${escapeHtml(caption)}</figcaption>` : \"\"}</figure>`;\n }\n return `<p class=\"matrx-print-block matrx-print-notice\" style=\"border:1px dashed #94a3b8;border-radius:6px;padding:10px 12px;color:#475569;font-style:italic\">${escapeHtml(\n output.notice,\n )}</p>`;\n}\n\n// ─── Shared Utilities ─────────────────────────────────────────────────────────\n\nconst PRINT_STYLES = `\n *, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }\n\n body {\n font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Helvetica Neue', Arial, sans-serif;\n font-size: 11pt;\n line-height: 1.6;\n color: #1a1a1a;\n background: #fff;\n max-width: 860px;\n margin: 0 auto;\n padding: 28px 36px;\n }\n\n .print-actions {\n display: flex;\n gap: 10px;\n margin-bottom: 24px;\n padding-bottom: 18px;\n border-bottom: 2px solid #e5e7eb;\n }\n\n .print-btn {\n display: inline-flex;\n align-items: center;\n gap: 6px;\n padding: 8px 20px;\n border-radius: 8px;\n font-size: 13px;\n font-family: inherit;\n cursor: pointer;\n border: none;\n font-weight: 600;\n }\n\n .print-btn-primary { background: #2563eb; color: #fff; }\n .print-btn-secondary { background: #f3f4f6; color: #374151; border: 1px solid #d1d5db; }\n\n h1 { font-size: 22pt; font-weight: 700; margin-bottom: 0.5em; }\n h2 { font-size: 16pt; font-weight: 700; margin: 1.2em 0 0.4em; border-bottom: 1px solid #e5e7eb; padding-bottom: 0.2em; }\n h3 { font-size: 13pt; font-weight: 600; margin: 1em 0 0.3em; }\n p { margin-bottom: 0.7em; }\n\n table {\n width: 100%;\n border-collapse: collapse;\n margin: 1em 0;\n font-size: 10pt;\n }\n th {\n background: #1e293b;\n color: #f8fafc;\n font-weight: 600;\n text-align: left;\n padding: 7px 12px;\n border: 1px solid #334155;\n }\n td {\n padding: 6px 12px;\n border: 1px solid #e2e8f0;\n vertical-align: top;\n }\n tr:nth-child(even) td { background: #f8fafc; }\n\n @media print {\n body { max-width: 100%; padding: 0; }\n .print-actions { display: none !important; }\n th { -webkit-print-color-adjust: exact; print-color-adjust: exact; }\n }\n`;\n\n/**\n * Wrap body HTML in a complete, styled print document.\n */\nexport function buildPrintDocument(\n bodyHtml: string,\n title = \"AI Response\",\n extraStyles = \"\",\n): string {\n return `<!DOCTYPE html>\n<html lang=\"en\">\n<head>\n <meta charset=\"UTF-8\">\n <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">\n <title>${escapeHtml(title)}</title>\n <style>\n${PRINT_STYLES}\n${extraStyles}\n </style>\n</head>\n<body>\n <div class=\"print-actions\">\n <button class=\"print-btn print-btn-primary\" onclick=\"window.print()\">Print / Save as PDF</button>\n <button class=\"print-btn print-btn-secondary\" onclick=\"window.close()\">Close</button>\n </div>\n <div class=\"content\">\n${bodyHtml}\n </div>\n</body>\n</html>`;\n}\n\n/**\n * How a print request actually reached the user.\n *\n * \"opened\" — a print window/tab was opened and the document written into it.\n * \"downloaded\" — the popup was blocked, so the document was downloaded as an\n * .html file instead (the contract's fallback). Hosts SHOULD\n * surface this to the user (e.g. a toast saying the print file\n * was downloaded) — a blocked popup plus a silent download is\n * indistinguishable from \"nothing happened\", which is exactly\n * how QA filed it (2026-08-30, F5/F6/F8).\n */\nexport type PrintOutcome = \"opened\" | \"downloaded\";\n\n/**\n * Open a new browser window and write a complete HTML document into it.\n * Falls back to downloading an .html file if the popup is blocked.\n *\n * Returns which path was taken so callers can tell the user when the\n * fallback fired. `windowFeatures` customizes the popup geometry (the\n * flashcards fixed-geometry variants pass a wider window).\n */\n/**\n * Every printed document leaves through here, so this is where typeset math\n * gets its stylesheet: when the page carries KaTeX output and does not already\n * carry the sheet, it is added to <head>. A page with no math is untouched,\n * byte for byte (the flashcard golden master holds every printer to that).\n */\nexport function withMathStyles(htmlDocument: string): string {\n if (!htmlDocument.includes('class=\"katex\"') || htmlDocument.includes(KATEX_CSS_MARKER)) {\n return htmlDocument;\n }\n const style = `<style data-matrx-katex>${KATEX_CSS}</style>`;\n const head = htmlDocument.search(/<\\/head>/i);\n return head >= 0\n ? htmlDocument.slice(0, head) + style + htmlDocument.slice(head)\n : style + htmlDocument;\n}\n\nexport function openPrintWindow(\n rawDocument: string,\n filename = \"print\",\n windowFeatures = \"width=920,height=720,scrollbars=yes\",\n): PrintOutcome {\n const htmlDocument = withMathStyles(rawDocument);\n const win = window.open(\"\", \"_blank\", windowFeatures);\n // Popup blocked — fall back to file download.\n if (!win) return openPrintWindowFallback(htmlDocument, filename);\n win.document.open();\n win.document.write(htmlDocument);\n win.document.close();\n return \"opened\";\n}\n\n/** A print window opened before its document is ready (see `openPendingPrintWindow`). */\nexport interface PendingPrintWindow {\n /** Write the finished document; downloads it when the popup was blocked or closed. */\n write(htmlDocument: string): PrintOutcome;\n}\n\n/**\n * Open the print window NOW — inside the click, where popup blockers allow it —\n * and write the document later, once async preparation (drawing diagrams) is\n * done. The window says \"Preparing…\" meanwhile.\n */\nexport function openPendingPrintWindow(\n filename = \"print\",\n windowFeatures = \"width=920,height=720,scrollbars=yes\",\n): PendingPrintWindow {\n const win = window.open(\"\", \"_blank\", windowFeatures);\n if (win) {\n win.document.open();\n win.document.write(\n '<!DOCTYPE html><html><head><meta charset=\"UTF-8\"><title>Preparing…</title></head><body style=\"font:14px -apple-system,BlinkMacSystemFont,sans-serif;color:#555;padding:2rem\">Preparing the document for print…</body></html>',\n );\n win.document.close();\n }\n return {\n write(rawDocument: string): PrintOutcome {\n const htmlDocument = withMathStyles(rawDocument);\n if (!win || win.closed) return openPrintWindowFallback(htmlDocument, filename);\n win.document.open();\n win.document.write(htmlDocument);\n win.document.close();\n return \"opened\";\n },\n };\n}\n\nfunction openPrintWindowFallback(htmlDocument: string, filename: string): PrintOutcome {\n downloadFile(`${filename.replace(/\\s+/g, \"-\").toLowerCase()}.html`, htmlDocument, \"text/html;charset=utf-8\");\n return \"downloaded\";\n}\n\n/**\n * Shorthand: build the document and open it in one call.\n * Returns the same PrintOutcome as openPrintWindow.\n */\nexport function printHtmlContent(\n bodyHtml: string,\n title = \"AI Response\",\n extraStyles = \"\",\n): PrintOutcome {\n const doc = buildPrintDocument(bodyHtml, title, extraStyles);\n return openPrintWindow(doc, title);\n}\n\n/**\n * Build the auto-shrink script that runs INSIDE a printed window: for every\n * element matching each selector, its font-size is reduced (0.5pt steps, 6pt\n * floor) until it fits its parent element's box. This is the flashcards\n * FIT_TEXT behavior verbatim, parameterized by selector so every lane\n * (flashcards card text, Avery text, label captions) shares the ONE loop.\n *\n * Pass the same selectors the original used to get byte-identical behavior:\n * flashcards passes `[\".card-text .card-text-inner\", \".avery-text-wrap .avery-text\"]`.\n */\nexport function buildFitTextScript(selectors: readonly string[]): string {\n const selectorsJson = JSON.stringify([...selectors]);\n return `\n<script>\n(function() {\n function fitText(el, container) {\n // container is the bounding box we must fit inside\n var maxW = container.clientWidth;\n var maxH = container.clientHeight;\n var size = parseFloat(window.getComputedStyle(el).fontSize);\n var minSize = 6;\n // Give the element a chance to reflow at current size before measuring\n el.style.fontSize = size + \"pt\";\n while (size > minSize && (el.scrollWidth > maxW + 1 || el.scrollHeight > maxH + 1)) {\n size -= 0.5;\n el.style.fontSize = size + \"pt\";\n }\n }\n function runAll() {\n var selectors = ${selectorsJson};\n for (var s = 0; s < selectors.length; s++) {\n var els = document.querySelectorAll(selectors[s]);\n for (var i = 0; i < els.length; i++) {\n fitText(els[i], els[i].parentElement);\n }\n }\n }\n if (document.readyState === \"loading\") {\n document.addEventListener(\"DOMContentLoaded\", runAll);\n } else {\n // document.write pages may already be loaded\n setTimeout(runAll, 0);\n }\n})();\n</script>`;\n}\n\n\n// ─── DOM print: a rendered body, as it looks ─────────────────────────────────\n\nexport interface PrintElementOptions {\n /** The print window's title (and the download fallback's file name). */\n title?: string;\n /** Open the system print dialog once the window has loaded. Default true. */\n autoPrint?: boolean;\n}\n\nconst ELEMENT_PRINT_CSS = `\n html, body { height: auto !important; min-height: 0 !important; overflow: visible !important; background: #fff !important; }\n body { margin: 0; padding: 16px; }\n *, *::before, *::after { -webkit-print-color-adjust: exact !important; print-color-adjust: exact !important; }\n .matrx-print-root, .matrx-print-root * { max-height: none !important; }\n .matrx-print-root [class*=\"overflow-\"], .matrx-print-root [class*=\"h-full\"], .matrx-print-root [class*=\"min-h-0\"] { overflow: visible !important; height: auto !important; }\n .matrx-print-frame-notice { border: 1px dashed #94a3b8; border-radius: 6px; padding: 10px 12px; color: #475569; font: italic 12px sans-serif; }\n @media print { .matrx-print-root * { break-inside: auto; } img, svg, figure, tr { break-inside: avoid; } }\n`;\n\n/**\n * Prints a same-origin DOM body exactly as it is drawn: the element's markup\n * with the page's own stylesheets, light theme, backgrounds kept, scroll\n * containers opened to full height. A `<canvas>` prints as its picture; an\n * `<iframe>` cannot be copied and prints an honest notice in its place (a\n * frame kind declares its own print instead). Opens inside the click.\n */\nexport function printElement(element: HTMLElement, options: PrintElementOptions = {}): PrintOutcome {\n const title = options.title ?? (document.title || \"Print\");\n const head = [...document.querySelectorAll<HTMLLinkElement | HTMLStyleElement>('link[rel=\"stylesheet\"], style')]\n .map((node) => {\n if (node instanceof HTMLLinkElement) return `<link rel=\"stylesheet\" href=\"${escapeHtml(node.href)}\">`;\n return `<style>${node.textContent ?? \"\"}</style>`;\n })\n .join(\"\\n\");\n const clone = element.cloneNode(true) as HTMLElement;\n const liveCanvases = element.querySelectorAll(\"canvas\");\n clone.querySelectorAll(\"canvas\").forEach((canvas, i) => {\n const live = liveCanvases[i];\n const img = document.createElement(\"img\");\n try {\n img.src = live ? live.toDataURL(\"image/png\") : \"\";\n } catch {\n img.alt = \"This drawing cannot be copied for print.\";\n }\n img.style.maxWidth = \"100%\";\n canvas.replaceWith(img);\n });\n clone.querySelectorAll(\"iframe\").forEach((frame) => {\n const note = document.createElement(\"p\");\n note.className = \"matrx-print-frame-notice\";\n note.textContent = \"An embedded page is here — print it from its own Print.\";\n frame.replaceWith(note);\n });\n clone.querySelectorAll(\"script\").forEach((node) => node.remove());\n const htmlClass = document.documentElement.className.replace(/\\bdark\\b/g, \"light\");\n const autoPrint = options.autoPrint ?? true;\n const doc = `<!DOCTYPE html><html lang=\"en\" class=\"${escapeHtml(htmlClass)}\"><head><meta charset=\"UTF-8\"><base href=\"${escapeHtml(\n document.baseURI,\n )}\"><title>${escapeHtml(title)}</title>${head}<style>${ELEMENT_PRINT_CSS}</style></head><body><div class=\"matrx-print-root\">${\n clone.outerHTML\n }</div>${\n autoPrint\n ? '<script>window.addEventListener(\"load\",function(){setTimeout(function(){window.focus();window.print();},250);});</script>'\n : \"\"\n }</body></html>`;\n return openPrintWindow(doc, title);\n}\n","// GENERATED by scripts/gen-katex-css.mjs from katex@0.18.9 — do not edit.\nexport const KATEX_VERSION = \"0.18.9\";\n/** Leads KATEX_CSS; lets openPrintWindow see the sheet is already present. */\nexport const KATEX_CSS_MARKER = \"/* matrx-katex@0.18.9 */\";\nexport const KATEX_CSS = \"/* matrx-katex@0.18.9 */@font-face{font-display:block;font-family:KaTeX_AMS;font-style:normal;font-weight:400;src:url(https://cdn.jsdelivr.net/npm/katex@0.18.9/dist/fonts/KaTeX_AMS-Regular.woff2) format(\\\"woff2\\\"),url(https://cdn.jsdelivr.net/npm/katex@0.18.9/dist/fonts/KaTeX_AMS-Regular.woff) format(\\\"woff\\\"),url(https://cdn.jsdelivr.net/npm/katex@0.18.9/dist/fonts/KaTeX_AMS-Regular.ttf) format(\\\"truetype\\\")}@font-face{font-display:block;font-family:KaTeX_Caligraphic;font-style:normal;font-weight:700;src:url(https://cdn.jsdelivr.net/npm/katex@0.18.9/dist/fonts/KaTeX_Caligraphic-Bold.woff2) format(\\\"woff2\\\"),url(https://cdn.jsdelivr.net/npm/katex@0.18.9/dist/fonts/KaTeX_Caligraphic-Bold.woff) format(\\\"woff\\\"),url(https://cdn.jsdelivr.net/npm/katex@0.18.9/dist/fonts/KaTeX_Caligraphic-Bold.ttf) format(\\\"truetype\\\")}@font-face{font-display:block;font-family:KaTeX_Caligraphic;font-style:normal;font-weight:400;src:url(https://cdn.jsdelivr.net/npm/katex@0.18.9/dist/fonts/KaTeX_Caligraphic-Regular.woff2) format(\\\"woff2\\\"),url(https://cdn.jsdelivr.net/npm/katex@0.18.9/dist/fonts/KaTeX_Caligraphic-Regular.woff) format(\\\"woff\\\"),url(https://cdn.jsdelivr.net/npm/katex@0.18.9/dist/fonts/KaTeX_Caligraphic-Regular.ttf) format(\\\"truetype\\\")}@font-face{font-display:block;font-family:KaTeX_Fraktur;font-style:normal;font-weight:700;src:url(https://cdn.jsdelivr.net/npm/katex@0.18.9/dist/fonts/KaTeX_Fraktur-Bold.woff2) format(\\\"woff2\\\"),url(https://cdn.jsdelivr.net/npm/katex@0.18.9/dist/fonts/KaTeX_Fraktur-Bold.woff) format(\\\"woff\\\"),url(https://cdn.jsdelivr.net/npm/katex@0.18.9/dist/fonts/KaTeX_Fraktur-Bold.ttf) format(\\\"truetype\\\")}@font-face{font-display:block;font-family:KaTeX_Fraktur;font-style:normal;font-weight:400;src:url(https://cdn.jsdelivr.net/npm/katex@0.18.9/dist/fonts/KaTeX_Fraktur-Regular.woff2) format(\\\"woff2\\\"),url(https://cdn.jsdelivr.net/npm/katex@0.18.9/dist/fonts/KaTeX_Fraktur-Regular.woff) format(\\\"woff\\\"),url(https://cdn.jsdelivr.net/npm/katex@0.18.9/dist/fonts/KaTeX_Fraktur-Regular.ttf) format(\\\"truetype\\\")}@font-face{font-display:block;font-family:KaTeX_Main;font-style:normal;font-weight:700;src:url(https://cdn.jsdelivr.net/npm/katex@0.18.9/dist/fonts/KaTeX_Main-Bold.woff2) format(\\\"woff2\\\"),url(https://cdn.jsdelivr.net/npm/katex@0.18.9/dist/fonts/KaTeX_Main-Bold.woff) format(\\\"woff\\\"),url(https://cdn.jsdelivr.net/npm/katex@0.18.9/dist/fonts/KaTeX_Main-Bold.ttf) format(\\\"truetype\\\")}@font-face{font-display:block;font-family:KaTeX_Main;font-style:italic;font-weight:700;src:url(https://cdn.jsdelivr.net/npm/katex@0.18.9/dist/fonts/KaTeX_Main-BoldItalic.woff2) format(\\\"woff2\\\"),url(https://cdn.jsdelivr.net/npm/katex@0.18.9/dist/fonts/KaTeX_Main-BoldItalic.woff) format(\\\"woff\\\"),url(https://cdn.jsdelivr.net/npm/katex@0.18.9/dist/fonts/KaTeX_Main-BoldItalic.ttf) format(\\\"truetype\\\")}@font-face{font-display:block;font-family:KaTeX_Main;font-style:italic;font-weight:400;src:url(https://cdn.jsdelivr.net/npm/katex@0.18.9/dist/fonts/KaTeX_Main-Italic.woff2) format(\\\"woff2\\\"),url(https://cdn.jsdelivr.net/npm/katex@0.18.9/dist/fonts/KaTeX_Main-Italic.woff) format(\\\"woff\\\"),url(https://cdn.jsdelivr.net/npm/katex@0.18.9/dist/fonts/KaTeX_Main-Italic.ttf) format(\\\"truetype\\\")}@font-face{font-display:block;font-family:KaTeX_Main;font-style:normal;font-weight:400;src:url(https://cdn.jsdelivr.net/npm/katex@0.18.9/dist/fonts/KaTeX_Main-Regular.woff2) format(\\\"woff2\\\"),url(https://cdn.jsdelivr.net/npm/katex@0.18.9/dist/fonts/KaTeX_Main-Regular.woff) format(\\\"woff\\\"),url(https://cdn.jsdelivr.net/npm/katex@0.18.9/dist/fonts/KaTeX_Main-Regular.ttf) format(\\\"truetype\\\")}@font-face{font-display:block;font-family:KaTeX_Math;font-style:italic;font-weight:700;src:url(https://cdn.jsdelivr.net/npm/katex@0.18.9/dist/fonts/KaTeX_Math-BoldItalic.woff2) format(\\\"woff2\\\"),url(https://cdn.jsdelivr.net/npm/katex@0.18.9/dist/fonts/KaTeX_Math-BoldItalic.woff) format(\\\"woff\\\"),url(https://cdn.jsdelivr.net/npm/katex@0.18.9/dist/fonts/KaTeX_Math-BoldItalic.ttf) format(\\\"truetype\\\")}@font-face{font-display:block;font-family:KaTeX_Math;font-style:italic;font-weight:400;src:url(https://cdn.jsdelivr.net/npm/katex@0.18.9/dist/fonts/KaTeX_Math-Italic.woff2) format(\\\"woff2\\\"),url(https://cdn.jsdelivr.net/npm/katex@0.18.9/dist/fonts/KaTeX_Math-Italic.woff) format(\\\"woff\\\"),url(https://cdn.jsdelivr.net/npm/katex@0.18.9/dist/fonts/KaTeX_Math-Italic.ttf) format(\\\"truetype\\\")}@font-face{font-display:block;font-family:\\\"KaTeX_SansSerif\\\";font-style:normal;font-weight:700;src:url(https://cdn.jsdelivr.net/npm/katex@0.18.9/dist/fonts/KaTeX_SansSerif-Bold.woff2) format(\\\"woff2\\\"),url(https://cdn.jsdelivr.net/npm/katex@0.18.9/dist/fonts/KaTeX_SansSerif-Bold.woff) format(\\\"woff\\\"),url(https://cdn.jsdelivr.net/npm/katex@0.18.9/dist/fonts/KaTeX_SansSerif-Bold.ttf) format(\\\"truetype\\\")}@font-face{font-display:block;font-family:\\\"KaTeX_SansSerif\\\";font-style:italic;font-weight:400;src:url(https://cdn.jsdelivr.net/npm/katex@0.18.9/dist/fonts/KaTeX_SansSerif-Italic.woff2) format(\\\"woff2\\\"),url(https://cdn.jsdelivr.net/npm/katex@0.18.9/dist/fonts/KaTeX_SansSerif-Italic.woff) format(\\\"woff\\\"),url(https://cdn.jsdelivr.net/npm/katex@0.18.9/dist/fonts/KaTeX_SansSerif-Italic.ttf) format(\\\"truetype\\\")}@font-face{font-display:block;font-family:\\\"KaTeX_SansSerif\\\";font-style:normal;font-weight:400;src:url(https://cdn.jsdelivr.net/npm/katex@0.18.9/dist/fonts/KaTeX_SansSerif-Regular.woff2) format(\\\"woff2\\\"),url(https://cdn.jsdelivr.net/npm/katex@0.18.9/dist/fonts/KaTeX_SansSerif-Regular.woff) format(\\\"woff\\\"),url(https://cdn.jsdelivr.net/npm/katex@0.18.9/dist/fonts/KaTeX_SansSerif-Regular.ttf) format(\\\"truetype\\\")}@font-face{font-display:block;font-family:KaTeX_Script;font-style:normal;font-weight:400;src:url(https://cdn.jsdelivr.net/npm/katex@0.18.9/dist/fonts/KaTeX_Script-Regular.woff2) format(\\\"woff2\\\"),url(https://cdn.jsdelivr.net/npm/katex@0.18.9/dist/fonts/KaTeX_Script-Regular.woff) format(\\\"woff\\\"),url(https://cdn.jsdelivr.net/npm/katex@0.18.9/dist/fonts/KaTeX_Script-Regular.ttf) format(\\\"truetype\\\")}@font-face{font-display:block;font-family:KaTeX_Size1;font-style:normal;font-weight:400;src:url(https://cdn.jsdelivr.net/npm/katex@0.18.9/dist/fonts/KaTeX_Size1-Regular.woff2) format(\\\"woff2\\\"),url(https://cdn.jsdelivr.net/npm/katex@0.18.9/dist/fonts/KaTeX_Size1-Regular.woff) format(\\\"woff\\\"),url(https://cdn.jsdelivr.net/npm/katex@0.18.9/dist/fonts/KaTeX_Size1-Regular.ttf) format(\\\"truetype\\\")}@font-face{font-display:block;font-family:KaTeX_Size2;font-style:normal;font-weight:400;src:url(https://cdn.jsdelivr.net/npm/katex@0.18.9/dist/fonts/KaTeX_Size2-Regular.woff2) format(\\\"woff2\\\"),url(https://cdn.jsdelivr.net/npm/katex@0.18.9/dist/fonts/KaTeX_Size2-Regular.woff) format(\\\"woff\\\"),url(https://cdn.jsdelivr.net/npm/katex@0.18.9/dist/fonts/KaTeX_Size2-Regular.ttf) format(\\\"truetype\\\")}@font-face{font-display:block;font-family:KaTeX_Size3;font-style:normal;font-weight:400;src:url(https://cdn.jsdelivr.net/npm/katex@0.18.9/dist/fonts/KaTeX_Size3-Regular.woff2) format(\\\"woff2\\\"),url(https://cdn.jsdelivr.net/npm/katex@0.18.9/dist/fonts/KaTeX_Size3-Regular.woff) format(\\\"woff\\\"),url(https://cdn.jsdelivr.net/npm/katex@0.18.9/dist/fonts/KaTeX_Size3-Regular.ttf) format(\\\"truetype\\\")}@font-face{font-display:block;font-family:KaTeX_Size4;font-style:normal;font-weight:400;src:url(https://cdn.jsdelivr.net/npm/katex@0.18.9/dist/fonts/KaTeX_Size4-Regular.woff2) format(\\\"woff2\\\"),url(https://cdn.jsdelivr.net/npm/katex@0.18.9/dist/fonts/KaTeX_Size4-Regular.woff) format(\\\"woff\\\"),url(https://cdn.jsdelivr.net/npm/katex@0.18.9/dist/fonts/KaTeX_Size4-Regular.ttf) format(\\\"truetype\\\")}@font-face{font-display:block;font-family:KaTeX_Typewriter;font-style:normal;font-weight:400;src:url(https://cdn.jsdelivr.net/npm/katex@0.18.9/dist/fonts/KaTeX_Typewriter-Regular.woff2) format(\\\"woff2\\\"),url(https://cdn.jsdelivr.net/npm/katex@0.18.9/dist/fonts/KaTeX_Typewriter-Regular.woff) format(\\\"woff\\\"),url(https://cdn.jsdelivr.net/npm/katex@0.18.9/dist/fonts/KaTeX_Typewriter-Regular.ttf) format(\\\"truetype\\\")}.katex{font:normal 1.21em KaTeX_Main,Times New Roman,serif;line-height:1.2;position:relative;text-indent:0;text-rendering:auto}.katex *{-ms-high-contrast-adjust:none!important;border-color:currentColor}.katex .katex-version:after{content:\\\"0.18.9\\\"}.katex .katex-mathml{border:0;-webkit-clip-path:inset(50%);clip-path:inset(50%);height:1px;overflow:hidden;padding:0;position:absolute;width:1px}.katex .katex-html>.katex-newline{display:block}.katex .katex-base{position:relative;white-space:nowrap;width:-webkit-min-content;width:-moz-min-content;width:min-content}.katex .katex-base,.katex .katex-strut{display:inline-block}.katex .textbf{font-weight:700}.katex .textit{font-style:italic}.katex .textrm{font-family:KaTeX_Main}.katex .textsf{font-family:KaTeX_SansSerif}.katex .texttt{font-family:KaTeX_Typewriter}.katex .mathnormal{font-family:KaTeX_Math;font-style:italic}.katex .mathit{font-family:KaTeX_Main;font-style:italic}.katex .mathrm{font-style:normal}.katex .mathbf{font-family:KaTeX_Main;font-weight:700}.katex .boldsymbol{font-family:KaTeX_Math;font-style:italic;font-weight:700}.katex .amsrm,.katex .mathbb,.katex .textbb{font-family:KaTeX_AMS}.katex .mathcal{font-family:KaTeX_Caligraphic}.katex .mathfrak,.katex .textfrak{font-family:KaTeX_Fraktur}.katex .mathboldfrak,.katex .textboldfrak{font-family:KaTeX_Fraktur;font-weight:700}.katex .mathtt{font-family:KaTeX_Typewriter}.katex .mathscr,.katex .textscr{font-family:KaTeX_Script}.katex .mathsf,.katex .textsf{font-family:KaTeX_SansSerif}.katex .mathboldsf,.katex .textboldsf{font-family:KaTeX_SansSerif;font-weight:700}.katex .mathitsf,.katex .mathsfit,.katex .textitsf{font-family:KaTeX_SansSerif;font-style:italic}.katex .mainrm{font-family:KaTeX_Main;font-style:normal}.katex .vlist-t{border-collapse:collapse;display:inline-table;table-layout:fixed}.katex .vlist-r{display:table-row}.katex .vlist{display:table-cell;position:relative;vertical-align:bottom}.katex .vlist>span{display:block;height:0;position:relative}.katex .vlist>span>span{display:inline-block}.katex .vlist>span>.pstrut{overflow:hidden;width:0}.katex .vlist-t2{margin-right:-2px}.katex .vlist-s{display:table-cell;font-size:1px;min-width:2px;vertical-align:bottom;width:2px}.katex .katex-vbox{align-items:baseline;display:inline-flex;flex-direction:column}.katex .katex-thinbox{display:inline-flex;flex-direction:row;max-width:0;width:0}.katex .msupsub{text-align:left}.katex .mfrac>span>span{text-align:center}.katex .mfrac .frac-line{border-bottom-style:solid;display:inline-block;width:100%}.katex .katex-hdashline,.katex .katex-hline,.katex .katex-overline .overline-line,.katex .katex-rule,.katex .katex-underline .underline-line,.katex .mfrac .frac-line{min-height:1px}.katex .mspace{display:inline-block}.katex .katex-smash{display:inline;line-height:0}.katex .clap,.katex .llap,.katex .rlap{position:relative;width:0}.katex .clap>.katex-inner,.katex .llap>.katex-inner,.katex .rlap>.katex-inner{position:absolute}.katex .clap>.katex-fix,.katex .llap>.katex-fix,.katex .rlap>.katex-fix{display:inline-block}.katex .llap>.katex-inner{right:0}.katex .clap>.katex-inner,.katex .rlap>.katex-inner{left:0}.katex .clap>.katex-inner>span{margin-left:-50%;margin-right:50%}.katex .katex-rule{border:0 solid;display:inline-block;position:relative}.katex .katex-hline,.katex .katex-overline .overline-line,.katex .katex-underline .underline-line{border-bottom-style:solid;display:inline-block;width:100%}.katex .katex-hdashline{border-bottom-style:dashed;display:inline-block;width:100%}.katex .sqrt>.katex-root{margin-left:.2777777778em;margin-right:-.5555555556em}.katex .fontsize-ensurer.reset-size1.size1,.katex .katex-sizing.reset-size1.size1{font-size:1em}.katex .fontsize-ensurer.reset-size1.size2,.katex .katex-sizing.reset-size1.size2{font-size:1.2em}.katex .fontsize-ensurer.reset-size1.size3,.katex .katex-sizing.reset-size1.size3{font-size:1.4em}.katex .fontsize-ensurer.reset-size1.size4,.katex .katex-sizing.reset-size1.size4{font-size:1.6em}.katex .fontsize-ensurer.reset-size1.size5,.katex .katex-sizing.reset-size1.size5{font-size:1.8em}.katex .fontsize-ensurer.reset-size1.size6,.katex .katex-sizing.reset-size1.size6{font-size:2em}.katex .fontsize-ensurer.reset-size1.size7,.katex .katex-sizing.reset-size1.size7{font-size:2.4em}.katex .fontsize-ensurer.reset-size1.size8,.katex .katex-sizing.reset-size1.size8{font-size:2.88em}.katex .fontsize-ensurer.reset-size1.size9,.katex .katex-sizing.reset-size1.size9{font-size:3.456em}.katex .fontsize-ensurer.reset-size1.size10,.katex .katex-sizing.reset-size1.size10{font-size:4.148em}.katex .fontsize-ensurer.reset-size1.size11,.katex .katex-sizing.reset-size1.size11{font-size:4.976em}.katex .fontsize-ensurer.reset-size2.size1,.katex .katex-sizing.reset-size2.size1{font-size:.8333333333em}.katex .fontsize-ensurer.reset-size2.size2,.katex .katex-sizing.reset-size2.size2{font-size:1em}.katex .fontsize-ensurer.reset-size2.size3,.katex .katex-sizing.reset-size2.size3{font-size:1.1666666667em}.katex .fontsize-ensurer.reset-size2.size4,.katex .katex-sizing.reset-size2.size4{font-size:1.3333333333em}.katex .fontsize-ensurer.reset-size2.size5,.katex .katex-sizing.reset-size2.size5{font-size:1.5em}.katex .fontsize-ensurer.reset-size2.size6,.katex .katex-sizing.reset-size2.size6{font-size:1.6666666667em}.katex .fontsize-ensurer.reset-size2.size7,.katex .katex-sizing.reset-size2.size7{font-size:2em}.katex .fontsize-ensurer.reset-size2.size8,.katex .katex-sizing.reset-size2.size8{font-size:2.4em}.katex .fontsize-ensurer.reset-size2.size9,.katex .katex-sizing.reset-size2.size9{font-size:2.88em}.katex .fontsize-ensurer.reset-size2.size10,.katex .katex-sizing.reset-size2.size10{font-size:3.4566666667em}.katex .fontsize-ensurer.reset-size2.size11,.katex .katex-sizing.reset-size2.size11{font-size:4.1466666667em}.katex .fontsize-ensurer.reset-size3.size1,.katex .katex-sizing.reset-size3.size1{font-size:.7142857143em}.katex .fontsize-ensurer.reset-size3.size2,.katex .katex-sizing.reset-size3.size2{font-size:.8571428571em}.katex .fontsize-ensurer.reset-size3.size3,.katex .katex-sizing.reset-size3.size3{font-size:1em}.katex .fontsize-ensurer.reset-size3.size4,.katex .katex-sizing.reset-size3.size4{font-size:1.1428571429em}.katex .fontsize-ensurer.reset-size3.size5,.katex .katex-sizing.reset-size3.size5{font-size:1.2857142857em}.katex .fontsize-ensurer.reset-size3.size6,.katex .katex-sizing.reset-size3.size6{font-size:1.4285714286em}.katex .fontsize-ensurer.reset-size3.size7,.katex .katex-sizing.reset-size3.size7{font-size:1.7142857143em}.katex .fontsize-ensurer.reset-size3.size8,.katex .katex-sizing.reset-size3.size8{font-size:2.0571428571em}.katex .fontsize-ensurer.reset-size3.size9,.katex .katex-sizing.reset-size3.size9{font-size:2.4685714286em}.katex .fontsize-ensurer.reset-size3.size10,.katex .katex-sizing.reset-size3.size10{font-size:2.9628571429em}.katex .fontsize-ensurer.reset-size3.size11,.katex .katex-sizing.reset-size3.size11{font-size:3.5542857143em}.katex .fontsize-ensurer.reset-size4.size1,.katex .katex-sizing.reset-size4.size1{font-size:.625em}.katex .fontsize-ensurer.reset-size4.size2,.katex .katex-sizing.reset-size4.size2{font-size:.75em}.katex .fontsize-ensurer.reset-size4.size3,.katex .katex-sizing.reset-size4.size3{font-size:.875em}.katex .fontsize-ensurer.reset-size4.size4,.katex .katex-sizing.reset-size4.size4{font-size:1em}.katex .fontsize-ensurer.reset-size4.size5,.katex .katex-sizing.reset-size4.size5{font-size:1.125em}.katex .fontsize-ensurer.reset-size4.size6,.katex .katex-sizing.reset-size4.size6{font-size:1.25em}.katex .fontsize-ensurer.reset-size4.size7,.katex .katex-sizing.reset-size4.size7{font-size:1.5em}.katex .fontsize-ensurer.reset-size4.size8,.katex .katex-sizing.reset-size4.size8{font-size:1.8em}.katex .fontsize-ensurer.reset-size4.size9,.katex .katex-sizing.reset-size4.size9{font-size:2.16em}.katex .fontsize-ensurer.reset-size4.size10,.katex .katex-sizing.reset-size4.size10{font-size:2.5925em}.katex .fontsize-ensurer.reset-size4.size11,.katex .katex-sizing.reset-size4.size11{font-size:3.11em}.katex .fontsize-ensurer.reset-size5.size1,.katex .katex-sizing.reset-size5.size1{font-size:.5555555556em}.katex .fontsize-ensurer.reset-size5.size2,.katex .katex-sizing.reset-size5.size2{font-size:.6666666667em}.katex .fontsize-ensurer.reset-size5.size3,.katex .katex-sizing.reset-size5.size3{font-size:.7777777778em}.katex .fontsize-ensurer.reset-size5.size4,.katex .katex-sizing.reset-size5.size4{font-size:.8888888889em}.katex .fontsize-ensurer.reset-size5.size5,.katex .katex-sizing.reset-size5.size5{font-size:1em}.katex .fontsize-ensurer.reset-size5.size6,.katex .katex-sizing.reset-size5.size6{font-size:1.1111111111em}.katex .fontsize-ensurer.reset-size5.size7,.katex .katex-sizing.reset-size5.size7{font-size:1.3333333333em}.katex .fontsize-ensurer.reset-size5.size8,.katex .katex-sizing.reset-size5.size8{font-size:1.6em}.katex .fontsize-ensurer.reset-size5.size9,.katex .katex-sizing.reset-size5.size9{font-size:1.92em}.katex .fontsize-ensurer.reset-size5.size10,.katex .katex-sizing.reset-size5.size10{font-size:2.3044444444em}.katex .fontsize-ensurer.reset-size5.size11,.katex .katex-sizing.reset-size5.size11{font-size:2.7644444444em}.katex .fontsize-ensurer.reset-size6.size1,.katex .katex-sizing.reset-size6.size1{font-size:.5em}.katex .fontsize-ensurer.reset-size6.size2,.katex .katex-sizing.reset-size6.size2{font-size:.6em}.katex .fontsize-ensurer.reset-size6.size3,.katex .katex-sizing.reset-size6.size3{font-size:.7em}.katex .fontsize-ensurer.reset-size6.size4,.katex .katex-sizing.reset-size6.size4{font-size:.8em}.katex .fontsize-ensurer.reset-size6.size5,.katex .katex-sizing.reset-size6.size5{font-size:.9em}.katex .fontsize-ensurer.reset-size6.size6,.katex .katex-sizing.reset-size6.size6{font-size:1em}.katex .fontsize-ensurer.reset-size6.size7,.katex .katex-sizing.reset-size6.size7{font-size:1.2em}.katex .fontsize-ensurer.reset-size6.size8,.katex .katex-sizing.reset-size6.size8{font-size:1.44em}.katex .fontsize-ensurer.reset-size6.size9,.katex .katex-sizing.reset-size6.size9{font-size:1.728em}.katex .fontsize-ensurer.reset-size6.size10,.katex .katex-sizing.reset-size6.size10{font-size:2.074em}.katex .fontsize-ensurer.reset-size6.size11,.katex .katex-sizing.reset-size6.size11{font-size:2.488em}.katex .fontsize-ensurer.reset-size7.size1,.katex .katex-sizing.reset-size7.size1{font-size:.4166666667em}.katex .fontsize-ensurer.reset-size7.size2,.katex .katex-sizing.reset-size7.size2{font-size:.5em}.katex .fontsize-ensurer.reset-size7.size3,.katex .katex-sizing.reset-size7.size3{font-size:.5833333333em}.katex .fontsize-ensurer.reset-size7.size4,.katex .katex-sizing.reset-size7.size4{font-size:.6666666667em}.katex .fontsize-ensurer.reset-size7.size5,.katex .katex-sizing.reset-size7.size5{font-size:.75em}.katex .fontsize-ensurer.reset-size7.size6,.katex .katex-sizing.reset-size7.size6{font-size:.8333333333em}.katex .fontsize-ensurer.reset-size7.size7,.katex .katex-sizing.reset-size7.size7{font-size:1em}.katex .fontsize-ensurer.reset-size7.size8,.katex .katex-sizing.reset-size7.size8{font-size:1.2em}.katex .fontsize-ensurer.reset-size7.size9,.katex .katex-sizing.reset-size7.size9{font-size:1.44em}.katex .fontsize-ensurer.reset-size7.size10,.katex .katex-sizing.reset-size7.size10{font-size:1.7283333333em}.katex .fontsize-ensurer.reset-size7.size11,.katex .katex-sizing.reset-size7.size11{font-size:2.0733333333em}.katex .fontsize-ensurer.reset-size8.size1,.katex .katex-sizing.reset-size8.size1{font-size:.3472222222em}.katex .fontsize-ensurer.reset-size8.size2,.katex .katex-sizing.reset-size8.size2{font-size:.4166666667em}.katex .fontsize-ensurer.reset-size8.size3,.katex .katex-sizing.reset-size8.size3{font-size:.4861111111em}.katex .fontsize-ensurer.reset-size8.size4,.katex .katex-sizing.reset-size8.size4{font-size:.5555555556em}.katex .fontsize-ensurer.reset-size8.size5,.katex .katex-sizing.reset-size8.size5{font-size:.625em}.katex .fontsize-ensurer.reset-size8.size6,.katex .katex-sizing.reset-size8.size6{font-size:.6944444444em}.katex .fontsize-ensurer.reset-size8.size7,.katex .katex-sizing.reset-size8.size7{font-size:.8333333333em}.katex .fontsize-ensurer.reset-size8.size8,.katex .katex-sizing.reset-size8.size8{font-size:1em}.katex .fontsize-ensurer.reset-size8.size9,.katex .katex-sizing.reset-size8.size9{font-size:1.2em}.katex .fontsize-ensurer.reset-size8.size10,.katex .katex-sizing.reset-size8.size10{font-size:1.4402777778em}.katex .fontsize-ensurer.reset-size8.size11,.katex .katex-sizing.reset-size8.size11{font-size:1.7277777778em}.katex .fontsize-ensurer.reset-size9.size1,.katex .katex-sizing.reset-size9.size1{font-size:.2893518519em}.katex .fontsize-ensurer.reset-size9.size2,.katex .katex-sizing.reset-size9.size2{font-size:.3472222222em}.katex .fontsize-ensurer.reset-size9.size3,.katex .katex-sizing.reset-size9.size3{font-size:.4050925926em}.katex .fontsize-ensurer.reset-size9.size4,.katex .katex-sizing.reset-size9.size4{font-size:.462962963em}.katex .fontsize-ensurer.reset-size9.size5,.katex .katex-sizing.reset-size9.size5{font-size:.5208333333em}.katex .fontsize-ensurer.reset-size9.size6,.katex .katex-sizing.reset-size9.size6{font-size:.5787037037em}.katex .fontsize-ensurer.reset-size9.size7,.katex .katex-sizing.reset-size9.size7{font-size:.6944444444em}.katex .fontsize-ensurer.reset-size9.size8,.katex .katex-sizing.reset-size9.size8{font-size:.8333333333em}.katex .fontsize-ensurer.reset-size9.size9,.katex .katex-sizing.reset-size9.size9{font-size:1em}.katex .fontsize-ensurer.reset-size9.size10,.katex .katex-sizing.reset-size9.size10{font-size:1.2002314815em}.katex .fontsize-ensurer.reset-size9.size11,.katex .katex-sizing.reset-size9.size11{font-size:1.4398148148em}.katex .fontsize-ensurer.reset-size10.size1,.katex .katex-sizing.reset-size10.size1{font-size:.2410800386em}.katex .fontsize-ensurer.reset-size10.size2,.katex .katex-sizing.reset-size10.size2{font-size:.2892960463em}.katex .fontsize-ensurer.reset-size10.size3,.katex .katex-sizing.reset-size10.size3{font-size:.337512054em}.katex .fontsize-ensurer.reset-size10.size4,.katex .katex-sizing.reset-size10.size4{font-size:.3857280617em}.katex .fontsize-ensurer.reset-size10.size5,.katex .katex-sizing.reset-size10.size5{font-size:.4339440694em}.katex .fontsize-ensurer.reset-size10.size6,.katex .katex-sizing.reset-size10.size6{font-size:.4821600771em}.katex .fontsize-ensurer.reset-size10.size7,.katex .katex-sizing.reset-size10.size7{font-size:.5785920926em}.katex .fontsize-ensurer.reset-size10.size8,.katex .katex-sizing.reset-size10.size8{font-size:.6943105111em}.katex .fontsize-ensurer.reset-size10.size9,.katex .katex-sizing.reset-size10.size9{font-size:.8331726133em}.katex .fontsize-ensurer.reset-size10.size10,.katex .katex-sizing.reset-size10.size10{font-size:1em}.katex .fontsize-ensurer.reset-size10.size11,.katex .katex-sizing.reset-size10.size11{font-size:1.1996142719em}.katex .fontsize-ensurer.reset-size11.size1,.katex .katex-sizing.reset-size11.size1{font-size:.2009646302em}.katex .fontsize-ensurer.reset-size11.size2,.katex .katex-sizing.reset-size11.size2{font-size:.2411575563em}.katex .fontsize-ensurer.reset-size11.size3,.katex .katex-sizing.reset-size11.size3{font-size:.2813504823em}.katex .fontsize-ensurer.reset-size11.size4,.katex .katex-sizing.reset-size11.size4{font-size:.3215434084em}.katex .fontsize-ensurer.reset-size11.size5,.katex .katex-sizing.reset-size11.size5{font-size:.3617363344em}.katex .fontsize-ensurer.reset-size11.size6,.katex .katex-sizing.reset-size11.size6{font-size:.4019292605em}.katex .fontsize-ensurer.reset-size11.size7,.katex .katex-sizing.reset-size11.size7{font-size:.4823151125em}.katex .fontsize-ensurer.reset-size11.size8,.katex .katex-sizing.reset-size11.size8{font-size:.578778135em}.katex .fontsize-ensurer.reset-size11.size9,.katex .katex-sizing.reset-size11.size9{font-size:.6945337621em}.katex .fontsize-ensurer.reset-size11.size10,.katex .katex-sizing.reset-size11.size10{font-size:.8336012862em}.katex .fontsize-ensurer.reset-size11.size11,.katex .katex-sizing.reset-size11.size11{font-size:1em}.katex .delimsizing.size1{font-family:KaTeX_Size1}.katex .delimsizing.size2{font-family:KaTeX_Size2}.katex .delimsizing.size3{font-family:KaTeX_Size3}.katex .delimsizing.size4{font-family:KaTeX_Size4}.katex .delimsizing.mult .delim-size1>span{font-family:KaTeX_Size1}.katex .delimsizing.mult .delim-size4>span{font-family:KaTeX_Size4}.katex .nulldelimiter{display:inline-block;width:.12em}.katex .delimcenter,.katex .op-symbol{position:relative}.katex .op-symbol.small-op{font-family:KaTeX_Size1}.katex .op-symbol.large-op{font-family:KaTeX_Size2}.katex .katex-accent>.vlist-t,.katex .op-limits>.vlist-t{text-align:center}.katex .katex-accent .accent-body{position:relative}.katex .katex-accent .accent-body:not(.accent-full){width:0}.katex .katex-overlay{display:block}.katex .mtable .vertical-separator{display:inline-block;min-width:1px}.katex .mtable .arraycolsep{display:inline-block}.katex .mtable .col-align-c>.vlist-t{text-align:center}.katex .mtable .col-align-l>.vlist-t{text-align:left}.katex .mtable .col-align-r>.vlist-t{text-align:right}.katex .svg-align{text-align:left}.katex svg{fill:currentColor;stroke:currentColor;display:block;height:inherit;position:absolute;width:100%}.katex svg path{stroke:none}.katex svg{fill-rule:nonzero;fill-opacity:1;stroke-width:1;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1}.katex img{border-style:none;max-height:none;max-width:none;min-height:0;min-width:0}.katex .katex-stretchy{display:block;overflow:hidden;position:relative;width:100%}.katex .katex-stretchy:after,.katex .katex-stretchy:before{content:\\\"\\\"}.katex .hide-tail{overflow:hidden;position:relative;width:100%}.katex .halfarrow-left{left:0;overflow:hidden;position:absolute;width:50.2%}.katex .halfarrow-right{overflow:hidden;position:absolute;right:0;width:50.2%}.katex .brace-left{left:0;overflow:hidden;position:absolute;width:25.1%}.katex .brace-center{left:25%;overflow:hidden;position:absolute;width:50%}.katex .brace-right{overflow:hidden;position:absolute;right:0;width:25.1%}.katex .x-arrow-pad{padding:0 .5em}.katex .cd-arrow-pad{padding:0 .55556em 0 .27778em}.katex .mover,.katex .munder,.katex .x-arrow{text-align:center}.katex .boxpad{padding:0 .3em}.katex .fbox,.katex .fcolorbox{border:.04em solid;box-sizing:border-box}.katex .cancel-pad{padding:0 .2em}.katex .cancel-lap{margin-left:-.2em;margin-right:-.2em}.katex .katex-sout{border-bottom-style:solid;border-bottom-width:.08em}.katex .angl{border-right:.049em solid;border-top:.049em solid;box-sizing:border-box;margin-right:.03889em}.katex .anglpad{padding:0 .03889em}.katex .reflectbox{display:inline-block;transform:scaleX(-1)}.katex .eqn-num:before{content:\\\"(\\\" counter(katexEqnNo) \\\")\\\";counter-increment:katexEqnNo}.katex .mml-eqn-num:before{content:\\\"(\\\" counter(mmlEqnNo) \\\")\\\";counter-increment:mmlEqnNo}.katex .mtr-glue{width:50%}.katex .cd-vert-arrow{display:inline-block;position:relative}.katex .cd-label-left{display:inline-block;position:absolute;right:calc(50% + .3em);text-align:left}.katex .cd-label-right{display:inline-block;left:calc(50% + .3em);position:absolute;text-align:right}.katex-display{display:block;margin:1em 0;text-align:center}.katex-display>.katex{display:block;text-align:center;white-space:nowrap}.katex-display>.katex>.katex-html{display:block;position:relative}.katex-display>.katex>.katex-html>.katex-tag{position:absolute;right:0}.katex-display.leqno>.katex>.katex-html>.katex-tag{left:0;right:auto}.katex-display.fleqn>.katex{padding-left:2em;text-align:left}body{counter-reset:katexEqnNo mmlEqnNo}\\n\";\n","/**\n * Plain text with math → safe HTML: THE one way a printer turns authored text\n * (a flashcard face, an exam prompt, a glossary definition) into markup.\n *\n * Every non-markdown printer used to `escapeHtml()` its text, so `\\(\\text{IO}_3^-\\)`\n * on a flashcard printed as that literal source (Arman, 2026-09-27). What is math\n * is decided by the shared tokenizer (`extractMath` — the same rule the screen,\n * the markdown lane and the /document pipeline use: code and `$5` prices are\n * never math); everything else is escaped exactly as before.\n *\n * Typeset output is KaTeX's laid-out HTML plus MathML, chemistry (mhchem)\n * loaded. KaTeX runs with `trust: false`, which refuses every command that could\n * inject HTML (\\href, \\url, \\htmlClass, \\htmlId, \\htmlStyle, \\htmlData,\n * \\includegraphics). The stylesheet is added by `openPrintWindow` whenever a\n * document contains math, so no printer can forget it.\n */\nimport katex from \"katex\";\n// Registers \\ce{…} and \\pu{…} on the same katex instance.\nimport \"katex/contrib/mhchem\";\nimport { escapeHtml } from \"@ai-matrx/kit/html-escape\";\nimport { extractMath, MATH_TOKEN_RE } from \"./document/math\";\n\n/** Typeset one TeX span — the ONE KaTeX configuration every print lane uses. */\nexport function typesetTex(tex: string, display: boolean): string {\n return katex.renderToString(tex, {\n displayMode: display,\n output: \"htmlAndMathml\",\n throwOnError: false,\n trust: false,\n strict: \"ignore\",\n });\n}\n\n/**\n * Escape `text` for HTML, with every math span typeset. Newlines are kept as\n * `\\n` in the prose so callers that turn them into `<br>` keep doing so; a\n * newline inside a formula is folded to a space (TeX treats it as one).\n */\nexport function mathTextHtml(text: string | null | undefined): string {\n // The tokenizer's own markers can never come from an author.\n const source = (text ?? \"\").replace(/[\\uE100\\uE101]/g, \"\");\n if (!/[$\\\\]/.test(source)) return escapeHtml(source);\n const { text: prose, spans } = extractMath(source);\n if (spans.length === 0) return escapeHtml(source);\n return escapeHtml(prose).replace(MATH_TOKEN_RE, (_m: string, i: string) => {\n const span = spans[Number(i)];\n return span ? typesetTex(span.tex.replace(/\\s*\\n\\s*/g, \" \"), span.display) : \"\";\n });\n}\n\n/**\n * A field that IS a formula (a cheat-sheet \"formula\" slot): delimited math is\n * typeset as usual; undelimited TeX (it has a command, `^` or `_`) is typeset\n * whole as inline math; anything else is escaped text.\n */\nexport function formulaHtml(formula: string | null | undefined): string {\n const source = (formula ?? \"\").trim();\n const withMath = mathTextHtml(source);\n if (withMath.includes('class=\"katex\"')) return withMath;\n return /\\\\[a-zA-Z]|[\\^_]/.test(source) ? typesetTex(source, false) : withMath;\n}\n","/**\n * Math in documents — ONE math dialect, typeset in every format.\n *\n * What is math is decided ONLY by the shared tokenizer (`@ai-matrx/content-ir/\n * source`): its fence-nesting rule finds code, its pairing finds `$$…$$`,\n * `$…$` (math, not currency), `\\[…\\]` and `\\(…\\)`. Math is lifted out\n * BEFORE markdown parsing, so a TeX `\\,` is never eaten as a markdown escape\n * and `_`/`*` inside a formula never become emphasis.\n *\n * Typesetting: MathJax (TeX → its internal tree) produces\n * - SVG for PDF display math (drawn as vector paths; allow-list sanitized),\n * - MathML for HTML and EPUB (rendered natively by browsers and readers),\n * - MathML that the Word writer turns into native OMML equations and the\n * PDF writer turns into inline text with real super/subscripts.\n */\n\nimport { listIslands, tokenizeSource } from \"@ai-matrx/content-ir/source\";\nimport { sanitizeMathml, sanitizeMathSvg } from \"../safe-html\";\n\nexport const MATH_OPEN = \"\\uE100\";\nexport const MATH_CLOSE = \"\\uE101\";\nexport const MATH_TOKEN_RE = /\\uE100(\\d+)\\uE101/g;\n\nexport interface MathSpan {\n tex: string;\n display: boolean;\n}\n\nconst DELIMITERS: Record<string, { open: number; close: number; display: boolean }> = {\n $$: { open: 2, close: 2, display: true },\n \"\\\\[\": { open: 2, close: 2, display: true },\n $: { open: 1, close: 1, display: false },\n \"\\\\(\": { open: 2, close: 2, display: false },\n};\n\n/**\n * Replace every math span with a private-use token; returns the spans.\n *\n * Print keeps NO fence, code-span or math detection of its own: the spans are\n * the shared tokenizer's complete `math_block` / `math_inline` islands\n * (`tokenizeSource` + `listIslands` from `@ai-matrx/content-ir/source` — the\n * one fence-nesting rule and the one math pairing), so print, the renderer and\n * the editor can never disagree about what is math. The delimiter decides the\n * form: `$$`/`\\[` display, `$`/`\\(` inline.\n */\nexport function extractMath(body: string): { text: string; spans: MathSpan[] } {\n const spans: MathSpan[] = [];\n if (!/[$\\\\]/.test(body)) return { text: body, spans };\n const islands = listIslands(tokenizeSource(body))\n .filter((isl) => isl.complete && (isl.islandType === \"math_block\" || isl.islandType === \"math_inline\"))\n .sort((a, b) => a.start - b.start);\n let out = \"\";\n let at = 0;\n for (const isl of islands) {\n const d = DELIMITERS[String(isl.meta.delimiter ?? \"\")];\n if (!d || isl.start < at) continue;\n out += body.slice(at, isl.start);\n spans.push({ tex: body.slice(isl.start + d.open, isl.end - d.close).trim(), display: d.display });\n out += `${MATH_OPEN}${spans.length - 1}${MATH_CLOSE}`;\n at = isl.end;\n }\n return { text: out + body.slice(at), spans };\n}\n\n// ── typesetting ────────────────────────────────────────────────────────────\n\nexport interface TypesetMath {\n /** MathML (<math …>…</math>) for HTML/EPUB and the Word/PDF-inline writers. */\n mathml: string;\n /** SVG for PDF display math; widths in ex (1ex ≈ 0.442em in MathJax). */\n svg?: string | undefined;\n widthEx?: number | undefined;\n heightEx?: number | undefined;\n /** Error message when the TeX could not be typeset. */\n error?: string | undefined;\n}\n\nexport const mathKey = (tex: string, display: boolean): string => `${display ? \"D\" : \"I\"}:${tex}`;\n\ntype MathJaxKit = {\n svg: (tex: string, display: boolean) => string;\n mml: (tex: string, display: boolean) => string;\n};\n\nconst MATHJAX = Symbol.for(\"ai-matrx.print.document.mathjax\");\n\nasync function loadMathJax(): Promise<MathJaxKit> {\n const g = globalThis as unknown as Record<symbol, Promise<MathJaxKit> | undefined>;\n if (g[MATHJAX]) return g[MATHJAX] as Promise<MathJaxKit>;\n g[MATHJAX] = (async () => {\n const [{ mathjax }, { TeX }, { SVG }, { liteAdaptor }, { RegisterHTMLHandler }, { AllPackages }, { SerializedMmlVisitor }, { STATE }] =\n await Promise.all([\n import(\"mathjax-full/js/mathjax.js\"),\n import(\"mathjax-full/js/input/tex.js\"),\n import(\"mathjax-full/js/output/svg.js\"),\n import(\"mathjax-full/js/adaptors/liteAdaptor.js\"),\n import(\"mathjax-full/js/handlers/html.js\"),\n import(\"mathjax-full/js/input/tex/AllPackages.js\"),\n import(\"mathjax-full/js/core/MmlTree/SerializedMmlVisitor.js\"),\n import(\"mathjax-full/js/core/MathItem.js\"),\n ]);\n const adaptor = liteAdaptor();\n RegisterHTMLHandler(adaptor);\n const doc = mathjax.document(\"\", {\n InputJax: new TeX({ packages: AllPackages }),\n OutputJax: new SVG({ fontCache: \"none\" }),\n });\n const visitor = new SerializedMmlVisitor();\n return {\n svg: (tex, display) => adaptor.innerHTML(doc.convert(tex, { display }) as never),\n mml: (tex, display) => visitor.visitTree(doc.convert(tex, { display, end: STATE.CONVERT }) as never),\n };\n })();\n return g[MATHJAX] as Promise<MathJaxKit>;\n}\n\n/** Typeset every math span once; keyed by `mathKey`. */\nexport async function typesetMathSpans(spans: MathSpan[]): Promise<Map<string, TypesetMath>> {\n const out = new Map<string, TypesetMath>();\n if (spans.length === 0) return out;\n const mj = await loadMathJax();\n for (const s of spans) {\n const key = mathKey(s.tex, s.display);\n if (out.has(key)) continue;\n try {\n const mathml = mj.mml(s.tex, s.display);\n const err = /<merror[\\s\\S]*?<mtext[^>]*>([\\s\\S]*?)<\\/mtext>/.exec(mathml);\n if (err) {\n out.set(key, { mathml: sanitizeMathml(mathml), error: decodeXml(err[1] as string) });\n continue;\n }\n // TeX is author input: `\\href`, `\\style`, `\\bbox[…]`, `\\mmlToken` reach\n // MathML attributes, so the typeset MathML goes through the allow-list.\n const entry: TypesetMath = { mathml: sanitizeMathml(mathml.replace(/\\n\\s*/g, \"\")) };\n if (s.display) {\n // The same author TeX reaches the SVG as <a href>, style, class and id\n // (LIST T26): only the drawing survives.\n const svg = sanitizeMathSvg(mj.svg(s.tex, true));\n entry.svg = svg;\n entry.widthEx = Number(/width=\"([\\d.]+)ex\"/.exec(svg)?.[1] ?? 0);\n entry.heightEx = Number(/height=\"([\\d.]+)ex\"/.exec(svg)?.[1] ?? 0);\n }\n out.set(key, entry);\n } catch (e) {\n out.set(key, { mathml: \"\", error: (e as Error).message });\n }\n }\n return out;\n}\n\n// ── a small MathML reader (MathJax's serializer output is well-formed XML) ──\n\nexport interface MNode {\n tag: string;\n attrs: Record<string, string>;\n children: MNode[];\n text: string;\n}\n\nexport function decodeXml(s: string): string {\n return s.replace(/&(#x[0-9a-f]+|#\\d+|amp|lt|gt|quot|apos);/gi, (m, e: string) => {\n if (e[0] === \"#\") return String.fromCodePoint(e[1] === \"x\" || e[1] === \"X\" ? parseInt(e.slice(2), 16) : Number(e.slice(1)));\n return ({ amp: \"&\", lt: \"<\", gt: \">\", quot: '\"', apos: \"'\" } as Record<string, string>)[e.toLowerCase()] ?? m;\n });\n}\n\nexport function parseMathML(xml: string): MNode {\n const root: MNode = { tag: \"#root\", attrs: {}, children: [], text: \"\" };\n const stack: MNode[] = [root];\n for (const m of xml.matchAll(/<(\\/?)([\\w:-]+)((?:\\s+[\\w:-]+=\"[^\"]*\")*)\\s*(\\/?)>|([^<]+)/g)) {\n const top = stack[stack.length - 1] as MNode;\n if (m[5] !== undefined) {\n const t = decodeXml(m[5]);\n if (t.trim() || top.tag === \"mtext\" || top.tag === \"mo\") top.text += t;\n continue;\n }\n if (m[1] === \"/\") {\n if (stack.length > 1) stack.pop();\n continue;\n }\n const attrs: Record<string, string> = {};\n for (const a of (m[3] ?? \"\").matchAll(/([\\w:-]+)=\"([^\"]*)\"/g)) attrs[a[1] as string] = decodeXml(a[2] as string);\n const node: MNode = { tag: (m[2] as string).replace(/^m:/, \"\"), attrs, children: [], text: \"\" };\n top.children.push(node);\n if (m[4] !== \"/\") stack.push(node);\n }\n return root.children[0] ?? root;\n}\n\n/** Flatten to plain text (the linear reading of a formula). */\nexport function mathText(n: MNode): string {\n if (n.children.length === 0) return n.text;\n return n.children.map(mathText).join(\"\");\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACsBA,sBAA6B;AAC7B,yBAA2B;;;ACpBpB,IAAM,mBAAmB;AACzB,IAAM,YAAY;;;AD6NzB,IAAM,eAAe;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;A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AAAA,MACjB,eAAe;AAAA,IACjB;AAAA,IACA;AAAA,MACE,MAAM;AAAA,MACN,IAAI;AAAA,MACJ,OAAO;AAAA,MACP,aAAa;AAAA,MACb,cAAc;AAAA,IAChB;AAAA,IACA;AAAA,MACE,MAAM;AAAA,MACN,IAAI;AAAA,MACJ,OAAO;AAAA,MACP,aACE;AAAA,MACF,cAAc;AAAA,IAChB;AAAA,EACF;AAAA,EAEA,MACE,MACA,YAAoB,aACpB,aACc;AACd,UAAM,QAAQ,UAAU,MAAM,gBAAgB;AAC9C,UAAM,WAAW,kBAAkB,IAAI;AACvC,UAAM,UACJ,cAAc,mBAAmB,mBAAmB;AACtD,UAAM,SACJ,YAAY,mBACR,kCACA;AAEN,QAAI,SAAS,WAAW,GAAG;AACzB,aAAO;AAAA,QACL;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,MACF;AAAA,IACF;AAEA,UAAM,EAAE,YAAY,SAAS,IAAI;AAAA,MAC/B;AAAA,MACA;AAAA,MACA;AAAA,MACA,SAAS;AAAA,IACX;AACA,UAAM,QAAQ,SAAS,MAAM,YAAY,QAAQ;AAEjD,UAAM,WAAW,WAAW,MAAM,UAAU;AAC5C,UAAM,OAAO,oBAAoB,EAAE,OAAO,UAAU,MAAM,GAAG,SAAS;AAAA,MACpE,cAAc,YAAY,aAAa,gBAAgB,IAAI;AAAA,MAC3D,gBAAgB,YAAY,aAAa,kBAAkB,IAAI;AAAA,IACjE,CAAC;AAED,WAAO;AAAA,MACL,mBAAmB,MAAM,OAAO,MAAM;AAAA,MACtC;AAAA,IACF;AAAA,EACF;AACF;","names":["import_html_escape","katex","import_html_escape"]}
1
+ {"version":3,"sources":["../src/education.ts","../src/core.ts","../src/katex-css.generated.ts","../src/math-text.ts","../src/document/math.ts"],"sourcesContent":["/**\n * @ai-matrx/print/education — the education / test-prep artifact library.\n *\n * Wave 3. Modeled on what the test-prep leaders actually hand a student\n * (Magoosh/7Sage one-pagers, Kaplan/Quizlet vocabulary lists, 7Sage's\n * week-by-week study calendar) per\n * `common-docs/projects/npm-package-extraction/PRINT-EDUCATION-RESEARCH.md`:\n *\n * - density WITH hierarchy — never a wall of text; every unit is a titled,\n * break-safe block inside a dense column flow;\n * - every artifact is independently printable — one sheet, no companion file;\n * - ONE content source → MANY layouts chosen at print time (the Quizlet\n * Table/Glossary/Small/Large picker). Our BlockPrinter variants ARE that\n * picker: the caller's data never changes, only the variant id.\n *\n * Three printers, all pure string composition over `./core`:\n * cheatSheetPrinter — the dense one-pager (2-col / 3-col ultra / large print)\n * glossaryPrinter — vocabulary list (term/definition table / compact list)\n * studyCalendarPrinter — week-by-week schedule (week rows / landscape grid)\n *\n * Zero dependencies, no module-level mutable state, import-inert: `window` is\n * only touched inside `print()` via core's `openPrintWindow`.\n */\n\nimport {\n buildPrintDocument,\n openPrintWindow,\n type BlockPrinter,\n type PrintOutcome,\n type PrintSettings,\n} from \"./core\";\nimport { formulaHtml, mathTextHtml } from \"./math-text\";\nimport { escapeHtml } from \"@ai-matrx/kit/html-escape\";\n\n// ---------------------------------------------------------------------------\n// Data contracts\n// ---------------------------------------------------------------------------\n\n/** One line of a cheat sheet: a term, and any of definition / formula / note. */\nexport interface CheatSheetItem {\n term: string;\n definition?: string;\n formula?: string;\n note?: string;\n}\n\n/** A titled group of cheat-sheet items — renders as a dense heading bar. */\nexport interface CheatSheetSection {\n heading: string;\n items: CheatSheetItem[];\n}\n\n/** The whole one-pager. */\nexport interface CheatSheetData {\n title: string;\n subtitle?: string;\n sections: CheatSheetSection[];\n}\n\n/** One glossary / vocabulary row. */\nexport interface GlossaryEntry {\n term: string;\n definition: string;\n}\n\n/** The whole vocabulary list. */\nexport interface GlossaryData {\n title: string;\n entries: GlossaryEntry[];\n}\n\n/** One day of a study plan — its tasks, and optionally a milestone banner. */\nexport interface StudyDay {\n label: string;\n tasks: string[];\n milestone?: string;\n}\n\n/** One week of a study plan. */\nexport interface StudyWeek {\n label: string;\n days: StudyDay[];\n}\n\n/** The whole study calendar. */\nexport interface StudyCalendarData {\n title: string;\n subtitle?: string;\n weeks: StudyWeek[];\n}\n\nexport type CheatSheetVariant = \"two-column\" | \"three-column\" | \"one-column\";\nexport type GlossaryVariant = \"table\" | \"compact-list\";\nexport type StudyCalendarVariant = \"week-rows\" | \"landscape-grid\";\n\n// ---------------------------------------------------------------------------\n// Structural readers — the host may hand us anything; nothing here throws.\n// ---------------------------------------------------------------------------\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n return typeof value === \"object\" && value !== null && !Array.isArray(value);\n}\n\nfunction readString(source: unknown, key: string): string {\n if (!isRecord(source)) return \"\";\n const value = source[key];\n return typeof value === \"string\" ? value : \"\";\n}\n\nfunction readArray(source: unknown, key: string): unknown[] {\n if (!isRecord(source)) return [];\n const value = source[key];\n return Array.isArray(value) ? value : [];\n}\n\n/** A trimmed title, or the given fallback when the host supplied none. */\nfunction readTitle(data: unknown, fallback: string): string {\n const title = readString(data, \"title\").trim();\n return title.length > 0 ? title : fallback;\n}\n\n/** String list with non-strings and blank entries dropped. */\nfunction readStringList(source: unknown, key: string): string[] {\n return readArray(source, key)\n .filter((entry): entry is string => typeof entry === \"string\")\n .map((entry) => entry.trim())\n .filter((entry) => entry.length > 0);\n}\n\nfunction extractCheatSheetSections(data: unknown): CheatSheetSection[] {\n return readArray(data, \"sections\")\n .map((raw): CheatSheetSection => {\n const items = readArray(raw, \"items\")\n .filter(isRecord)\n .map(\n (rawItem): CheatSheetItem => ({\n term: readString(rawItem, \"term\"),\n definition: readString(rawItem, \"definition\"),\n formula: readString(rawItem, \"formula\"),\n note: readString(rawItem, \"note\"),\n }),\n )\n .filter(\n (item) =>\n item.term.trim().length > 0 ||\n (item.definition ?? \"\").trim().length > 0 ||\n (item.formula ?? \"\").trim().length > 0,\n );\n return { heading: readString(raw, \"heading\"), items };\n })\n .filter((section) => section.items.length > 0);\n}\n\nfunction extractGlossaryEntries(data: unknown): GlossaryEntry[] {\n return readArray(data, \"entries\")\n .filter(isRecord)\n .map(\n (raw): GlossaryEntry => ({\n term: readString(raw, \"term\"),\n definition: readString(raw, \"definition\"),\n }),\n )\n .filter(\n (entry) =>\n entry.term.trim().length > 0 || entry.definition.trim().length > 0,\n );\n}\n\nfunction extractStudyWeeks(data: unknown): StudyWeek[] {\n return readArray(data, \"weeks\")\n .map((rawWeek): StudyWeek => {\n const days = readArray(rawWeek, \"days\")\n .filter(isRecord)\n .map((rawDay): StudyDay => {\n const milestone = readString(rawDay, \"milestone\");\n return {\n label: readString(rawDay, \"label\"),\n tasks: readStringList(rawDay, \"tasks\"),\n milestone,\n };\n })\n .filter(\n (day) =>\n day.label.trim().length > 0 ||\n day.tasks.length > 0 ||\n (day.milestone ?? \"\").trim().length > 0,\n );\n return { label: readString(rawWeek, \"label\"), days };\n })\n .filter((week) => week.days.length > 0);\n}\n\n// ---------------------------------------------------------------------------\n// Settings helpers\n// ---------------------------------------------------------------------------\n\nfunction boolSetting(\n raw: PrintSettings | undefined,\n key: string,\n fallback: boolean,\n): boolean {\n const value = raw?.[key];\n return value === undefined ? fallback : Boolean(value);\n}\n\nfunction numberSetting(raw: PrintSettings | undefined, key: string): number {\n const value = raw?.[key];\n return typeof value === \"number\" && Number.isFinite(value) ? value : 0;\n}\n\n/**\n * Resolve a `range` setting against a list length, the flashcards precedent:\n * 0 / missing / out-of-bounds fall back to the ends, an inverted pair is\n * swapped, and the result is always a valid 1-based inclusive window.\n * `startIndex` is the 0-based offset of the first kept item, so callers can\n * keep numbering items by their position in the FULL list.\n */\nfunction resolveRange(\n raw: PrintSettings | undefined,\n fromKey: string,\n toKey: string,\n total: number,\n): { startIndex: number; endIndex: number } {\n const rawFrom = numberSetting(raw, fromKey);\n const rawTo = numberSetting(raw, toKey);\n const start = rawFrom > 0 ? Math.min(rawFrom, total) : 1;\n const end = rawTo > 0 ? Math.min(rawTo, total) : total;\n const [from, to] = start <= end ? [start, end] : [end, start];\n return { startIndex: from - 1, endIndex: to };\n}\n\n/** The polite empty-data document (the flashcards precedent). */\nfunction printEmptyDocument(\n message: string,\n title: string,\n styles: string,\n filename: string,\n): PrintOutcome {\n return openPrintWindow(\n buildPrintDocument(`<p>${escapeHtml(message)}</p>`, title, styles),\n filename,\n );\n}\n\n/** A printable, ink-free checkbox — the \"mastered\" / task-done square. */\nconst CHECKBOX_HTML = `<span class=\"edu-check\" aria-hidden=\"true\"></span>`;\n\n/** Shared header + checkbox styles for every education artifact. */\nconst EDU_BASE_STYLES = `\n h1.edu-title {\n font-size: 15pt !important;\n font-weight: 700;\n color: #0f172a;\n margin: 0 0 3px 0;\n letter-spacing: -0.01em;\n border-bottom: none !important;\n }\n .edu-subtitle {\n font-size: 9pt;\n color: #475569;\n margin: 0;\n }\n .edu-meta {\n font-size: 8pt;\n color: #64748b;\n margin-top: 2px;\n }\n .edu-header {\n border-bottom: 1.5px solid #cbd5e1;\n padding-bottom: 8px;\n margin-bottom: 12px;\n }\n .edu-hint {\n font-size: 8pt;\n color: #475569;\n background: #f1f5f9;\n border: 1px solid #cbd5e1;\n border-radius: 6px;\n padding: 6px 10px;\n margin-bottom: 12px;\n line-height: 1.45;\n }\n .edu-check {\n display: inline-block;\n width: 9pt;\n height: 9pt;\n border: 1px solid #64748b;\n border-radius: 2px;\n background: #fff;\n vertical-align: -1px;\n margin-right: 6px;\n flex: 0 0 auto;\n }\n\n @media print {\n @page { margin: 12mm 10mm; }\n .edu-hint { display: none !important; }\n .edu-check {\n -webkit-print-color-adjust: exact;\n print-color-adjust: exact;\n }\n }\n`;\n\n// ---------------------------------------------------------------------------\n// 1. Cheat sheet — the Magoosh / 7Sage dense one-pager\n// ---------------------------------------------------------------------------\n\nconst CHEAT_SHEET_STYLES = `\n ${EDU_BASE_STYLES}\n\n .cs-sheet {\n column-gap: 14px;\n column-fill: auto;\n }\n .cs-cols-2 { column-count: 2; font-size: 8.5pt; }\n .cs-cols-3 { column-count: 3; font-size: 7.5pt; }\n .cs-cols-1 { column-count: 1; font-size: 11.5pt; }\n\n .cs-section {\n break-inside: auto;\n page-break-inside: auto;\n margin-bottom: 10px;\n }\n\n /* Section headings are dense BARS, not airy titles — the hierarchy that\n keeps a one-pager scannable instead of a wall of text. */\n .cs-section-bar {\n display: block;\n background: #1e293b;\n color: #f8fafc;\n font-size: 8pt !important;\n font-weight: 700;\n letter-spacing: 0.07em;\n text-transform: uppercase;\n padding: 3px 7px;\n margin: 0 0 5px 0 !important;\n border-radius: 3px;\n border-bottom: none !important;\n break-after: avoid;\n page-break-after: avoid;\n }\n .cs-cols-1 .cs-section-bar { font-size: 11pt !important; padding: 5px 10px; }\n\n .cs-section-rule {\n height: 0;\n border-bottom: 1px solid #cbd5e1;\n margin: 0 0 6px 0;\n }\n\n .cs-item {\n break-inside: avoid;\n page-break-inside: avoid;\n margin-bottom: 6px;\n padding-left: 5px;\n border-left: 2px solid #e2e8f0;\n line-height: 1.4;\n }\n .cs-term {\n font-weight: 700;\n color: #0f172a;\n }\n .cs-def {\n color: #334155;\n }\n .cs-note {\n color: #64748b;\n font-style: italic;\n }\n\n /* Boxed formula — mono + border is how every leader prints an equation. */\n code.cs-formula {\n display: block;\n font-family: \"SFMono-Regular\", Menlo, Consolas, \"Liberation Mono\", monospace;\n font-size: 0.95em;\n background: #f8fafc;\n border: 1px solid #94a3b8;\n border-radius: 3px;\n padding: 2px 5px;\n margin: 3px 0;\n white-space: pre-wrap;\n word-break: break-word;\n }\n\n /* Compact: tighter leading and a smaller floor for a true single sheet. */\n .cs-compact.cs-cols-2 { font-size: 7.5pt; }\n .cs-compact.cs-cols-3 { font-size: 6.5pt; }\n .cs-compact.cs-cols-1 { font-size: 10pt; }\n .cs-compact .cs-item { margin-bottom: 3px; line-height: 1.25; }\n .cs-compact .cs-section { margin-bottom: 6px; }\n .cs-compact .cs-section-bar { padding: 2px 6px; margin-bottom: 3px !important; }\n\n @media print {\n .cs-section-bar {\n -webkit-print-color-adjust: exact;\n print-color-adjust: exact;\n }\n code.cs-formula {\n -webkit-print-color-adjust: exact;\n print-color-adjust: exact;\n }\n }\n`;\n\nconst CHEAT_SHEET_COLUMN_CLASS: Record<CheatSheetVariant, string> = {\n \"two-column\": \"cs-cols-2\",\n \"three-column\": \"cs-cols-3\",\n \"one-column\": \"cs-cols-1\",\n};\n\nfunction renderCheatSheetItem(item: CheatSheetItem): string {\n const parts: string[] = [];\n const term = item.term.trim();\n const definition = (item.definition ?? \"\").trim();\n const formula = (item.formula ?? \"\").trim();\n const note = (item.note ?? \"\").trim();\n\n if (term) parts.push(`<span class=\"cs-term\">${mathTextHtml(term)}</span>`);\n if (definition) {\n parts.push(\n `${term ? \" \" : \"\"}<span class=\"cs-def\">${mathTextHtml(definition)}</span>`,\n );\n }\n if (formula) {\n parts.push(`<code class=\"cs-formula\">${formulaHtml(formula)}</code>`);\n }\n if (note) parts.push(`<div class=\"cs-note\">${mathTextHtml(note)}</div>`);\n\n return `<div class=\"cs-item\">${parts.join(\"\")}</div>`;\n}\n\nfunction renderCheatSheet(\n data: CheatSheetData,\n variant: CheatSheetVariant,\n opts: { showSectionRules: boolean; compact: boolean; duplexHint: boolean },\n): string {\n const itemCount = data.sections.reduce(\n (total, section) => total + section.items.length,\n 0,\n );\n const subtitle = (data.subtitle ?? \"\").trim();\n\n const sections = data.sections\n .map((section) => {\n const heading = section.heading.trim();\n const bar = heading\n ? `<h2 class=\"cs-section-bar\">${mathTextHtml(heading)}</h2>`\n : \"\";\n const rule = opts.showSectionRules\n ? `<div class=\"cs-section-rule\"></div>`\n : \"\";\n const items = section.items.map(renderCheatSheetItem).join(\"\\n\");\n return `<section class=\"cs-section\">\n${bar}${rule}\n${items}\n</section>`;\n })\n .join(\"\\n\");\n\n const hint = opts.duplexHint\n ? `<div class=\"edu-hint\">Two-sided sheet: print double-sided, flip on <strong>long edge</strong>, 100% scale, no margins — then trim or slip it into a sleeve.</div>`\n : \"\";\n\n const columnClass = CHEAT_SHEET_COLUMN_CLASS[variant];\n const compactClass = opts.compact ? \" cs-compact\" : \"\";\n\n return `<div class=\"edu-header\">\n <h1 class=\"edu-title\">${mathTextHtml(data.title)}</h1>\n ${subtitle ? `<p class=\"edu-subtitle\">${mathTextHtml(subtitle)}</p>` : \"\"}\n <div class=\"edu-meta\">${data.sections.length} section${data.sections.length !== 1 ? \"s\" : \"\"} &nbsp;·&nbsp; ${itemCount} item${itemCount !== 1 ? \"s\" : \"\"}</div>\n</div>\n${hint}\n<div class=\"cs-sheet ${columnClass}${compactClass}\">\n${sections}\n</div>`;\n}\n\nexport const cheatSheetPrinter: BlockPrinter = {\n label: \"Print cheat sheet\",\n\n variants: [\n {\n id: \"two-column\",\n label: \"Two column (recommended)\",\n description:\n \"The classic dense one-pager — two columns, boxed formulas, section bars. Fits a surprising amount on a single sheet and still reads at arm's length\",\n },\n {\n id: \"three-column\",\n label: \"Three column (ultra-dense)\",\n description:\n \"Maximum content per sheet — three narrow columns at a smaller type size. Best for a reference you scan rather than read\",\n },\n {\n id: \"one-column\",\n label: \"Single column (large print)\",\n description:\n \"One wide column at a comfortable reading size — for studying, for a wall, or for anyone who needs bigger type\",\n },\n ],\n\n settings: [\n {\n type: \"boolean\" as const,\n id: \"showSectionRules\",\n label: \"Rule under each section\",\n description:\n \"Draws a hairline under every section heading — extra separation when sections run together\",\n defaultValue: true,\n },\n {\n type: \"boolean\" as const,\n id: \"compact\",\n label: \"Compact\",\n description:\n \"Tighter leading and a smaller type floor — use when the sheet spills onto a second page\",\n defaultValue: false,\n },\n {\n type: \"boolean\" as const,\n id: \"duplexHint\",\n label: \"Show double-sided printing tip\",\n description:\n \"Adds an on-screen note with the duplex settings for a two-sided sheet. Never printed\",\n defaultValue: false,\n },\n ],\n\n print(\n data: unknown,\n variantId: string = \"two-column\",\n rawSettings?: PrintSettings,\n ): PrintOutcome {\n const title = readTitle(data, \"Cheat Sheet\");\n const sections = extractCheatSheetSections(data);\n\n if (sections.length === 0) {\n return printEmptyDocument(\n \"No cheat sheet data available to print.\",\n title,\n CHEAT_SHEET_STYLES,\n \"cheat-sheet\",\n );\n }\n\n const variant: CheatSheetVariant =\n variantId === \"three-column\" || variantId === \"one-column\"\n ? variantId\n : \"two-column\";\n\n const subtitle = readString(data, \"subtitle\");\n const body = renderCheatSheet(\n { title, subtitle, sections },\n variant,\n {\n showSectionRules: boolSetting(rawSettings, \"showSectionRules\", true),\n compact: boolSetting(rawSettings, \"compact\", false),\n duplexHint: boolSetting(rawSettings, \"duplexHint\", false),\n },\n );\n\n return openPrintWindow(\n buildPrintDocument(body, title, CHEAT_SHEET_STYLES),\n \"cheat-sheet\",\n );\n },\n};\n\n// ---------------------------------------------------------------------------\n// 2. Glossary / vocabulary list — Kaplan / Quizlet Glossary\n// ---------------------------------------------------------------------------\n\nconst GLOSSARY_STYLES = `\n ${EDU_BASE_STYLES}\n\n table.gl-table {\n width: 100%;\n border-collapse: collapse;\n margin-top: 4px;\n font-size: 9.5pt;\n }\n table.gl-table thead th {\n background: #1e293b;\n color: #f8fafc;\n text-align: left;\n font-size: 8pt;\n font-weight: 700;\n letter-spacing: 0.06em;\n text-transform: uppercase;\n padding: 5px 9px;\n border: none;\n }\n table.gl-table th.gl-th-check { width: 22px; }\n table.gl-table th.gl-th-term { width: 32%; }\n\n table.gl-table tbody tr.gl-row {\n break-inside: avoid;\n page-break-inside: avoid;\n }\n table.gl-table tbody td {\n padding: 4px 9px;\n border-bottom: 1px solid #e2e8f0;\n vertical-align: top;\n line-height: 1.4;\n background: transparent;\n }\n table.gl-table tbody tr:nth-child(even) td { background: #f8fafc; }\n td.gl-check-cell { width: 22px; text-align: center; }\n td.gl-term-cell { font-weight: 700; color: #0f172a; }\n .gl-index {\n display: inline-block;\n min-width: 20px;\n font-size: 8pt;\n font-weight: 400;\n color: #94a3b8;\n }\n\n ul.gl-list {\n column-count: 2;\n column-gap: 18px;\n list-style: none;\n margin: 4px 0 0 0;\n padding: 0;\n font-size: 8.5pt;\n }\n ul.gl-list li.gl-entry {\n break-inside: avoid;\n page-break-inside: avoid;\n margin-bottom: 5px;\n padding-left: 4px;\n border-left: 2px solid #e2e8f0;\n line-height: 1.35;\n }\n .gl-term { font-weight: 700; color: #0f172a; }\n .gl-def { color: #334155; }\n\n @media print {\n table.gl-table thead th {\n -webkit-print-color-adjust: exact;\n print-color-adjust: exact;\n }\n table.gl-table tbody tr:nth-child(even) td {\n -webkit-print-color-adjust: exact;\n print-color-adjust: exact;\n }\n }\n`;\n\n/**\n * Alphabetize by term, case- and accent-insensitively. `Array.sort` is stable\n * (ES2019+), so equal terms keep their authored order — and with the setting\n * OFF the authored order is returned untouched.\n */\nfunction orderGlossaryEntries(\n entries: GlossaryEntry[],\n alphabetize: boolean,\n): GlossaryEntry[] {\n if (!alphabetize) return entries;\n return [...entries].sort((a, b) =>\n a.term.localeCompare(b.term, undefined, { sensitivity: \"base\" }),\n );\n}\n\nfunction renderGlossaryTable(\n entries: GlossaryEntry[],\n opts: { masteredCheckbox: boolean; showIndex: boolean; startIndex: number },\n): string {\n const rows = entries\n .map((entry, i) => {\n const check = opts.masteredCheckbox\n ? `<td class=\"gl-check-cell\">${CHECKBOX_HTML}</td>`\n : \"\";\n const index = opts.showIndex\n ? `<span class=\"gl-index\">${opts.startIndex + i + 1}.</span>`\n : \"\";\n return ` <tr class=\"gl-row\">\n${check ? ` ${check}\\n` : \"\"} <td class=\"gl-term-cell\">${index}${mathTextHtml(entry.term)}</td>\n <td class=\"gl-def\">${mathTextHtml(entry.definition)}</td>\n </tr>`;\n })\n .join(\"\\n\");\n\n const checkHead = opts.masteredCheckbox\n ? `<th class=\"gl-th-check\">✓</th>`\n : \"\";\n\n return `<table class=\"gl-table\">\n <thead>\n <tr>\n ${checkHead}<th class=\"gl-th-term\">Term</th>\n <th>Definition</th>\n </tr>\n </thead>\n <tbody>\n${rows}\n </tbody>\n</table>`;\n}\n\nfunction renderGlossaryList(\n entries: GlossaryEntry[],\n opts: { masteredCheckbox: boolean; showIndex: boolean; startIndex: number },\n): string {\n const items = entries\n .map((entry, i) => {\n const check = opts.masteredCheckbox ? CHECKBOX_HTML : \"\";\n const index = opts.showIndex\n ? `<span class=\"gl-index\">${opts.startIndex + i + 1}.</span>`\n : \"\";\n return ` <li class=\"gl-entry\">${check}${index}<span class=\"gl-term\">${mathTextHtml(entry.term)}</span> — <span class=\"gl-def\">${mathTextHtml(entry.definition)}</span></li>`;\n })\n .join(\"\\n\");\n\n return `<ul class=\"gl-list\">\n${items}\n</ul>`;\n}\n\nexport const glossaryPrinter: BlockPrinter = {\n label: \"Print glossary\",\n\n variants: [\n {\n id: \"table\",\n label: \"Term / definition table (recommended)\",\n description:\n \"Two-column table with a mastered checkbox per row — the Kaplan/Quizlet vocabulary sheet\",\n },\n {\n id: \"compact-list\",\n label: \"Compact list\",\n description:\n \"Two columns of one-line entries — many more terms per sheet, for a final review pass\",\n },\n ],\n\n settings: [\n {\n type: \"range\" as const,\n id: \"entryRange\",\n label: \"Entries to print\",\n description: \"Leave blank to print the whole list\",\n fromId: \"fromEntry\",\n toId: \"toEntry\",\n defaultFrom: 0,\n defaultTo: 0,\n min: 1,\n fromPlaceholder: \"1\",\n toPlaceholder: \"end\",\n },\n {\n type: \"boolean\" as const,\n id: \"alphabetize\",\n label: \"Alphabetize\",\n description:\n \"Sorts by term. Off prints the entries in the order they were authored\",\n defaultValue: false,\n },\n {\n type: \"boolean\" as const,\n id: \"masteredCheckbox\",\n label: \"Mastered checkbox\",\n description:\n \"An empty box on every row to tick off as each term is learned\",\n defaultValue: true,\n },\n {\n type: \"boolean\" as const,\n id: \"showIndex\",\n label: \"Number the entries\",\n description:\n \"Prints 1., 2., 3. … so a study partner can call out terms by number\",\n defaultValue: false,\n },\n ],\n\n print(\n data: unknown,\n variantId: string = \"table\",\n rawSettings?: PrintSettings,\n ): PrintOutcome {\n const title = readTitle(data, \"Glossary\");\n const allEntries = extractGlossaryEntries(data);\n\n if (allEntries.length === 0) {\n return printEmptyDocument(\n \"No glossary data available to print.\",\n title,\n GLOSSARY_STYLES,\n \"glossary\",\n );\n }\n\n // Order first, THEN slice: the range names positions on the printed page,\n // so \"entries 1–20\" alphabetized means the first twenty alphabetically.\n const ordered = orderGlossaryEntries(\n allEntries,\n boolSetting(rawSettings, \"alphabetize\", false),\n );\n const { startIndex, endIndex } = resolveRange(\n rawSettings,\n \"fromEntry\",\n \"toEntry\",\n ordered.length,\n );\n const entries = ordered.slice(startIndex, endIndex);\n\n const opts = {\n masteredCheckbox: boolSetting(rawSettings, \"masteredCheckbox\", true),\n showIndex: boolSetting(rawSettings, \"showIndex\", false),\n startIndex,\n };\n\n const variant: GlossaryVariant =\n variantId === \"compact-list\" ? \"compact-list\" : \"table\";\n const body =\n variant === \"compact-list\"\n ? renderGlossaryList(entries, opts)\n : renderGlossaryTable(entries, opts);\n\n const header = `<div class=\"edu-header\">\n <h1 class=\"edu-title\">${mathTextHtml(title)}</h1>\n <div class=\"edu-meta\">${entries.length} term${entries.length !== 1 ? \"s\" : \"\"}${entries.length !== allEntries.length ? ` of ${allEntries.length}` : \"\"}</div>\n</div>`;\n\n return openPrintWindow(\n buildPrintDocument(`${header}\\n${body}`, title, GLOSSARY_STYLES),\n \"glossary\",\n );\n },\n};\n\n// ---------------------------------------------------------------------------\n// 3. Study calendar / schedule — the 7Sage week-by-week plan\n// ---------------------------------------------------------------------------\n\nconst STUDY_CALENDAR_STYLES = `\n ${EDU_BASE_STYLES}\n\n /* A week is the unit that must never split across pages when it fits. */\n .sc-week {\n break-inside: avoid;\n page-break-inside: avoid;\n margin-bottom: 12px;\n border: 1px solid #cbd5e1;\n border-radius: 5px;\n overflow: hidden;\n }\n .sc-week-label {\n background: #1e293b;\n color: #f8fafc;\n font-size: 9pt !important;\n font-weight: 700;\n letter-spacing: 0.06em;\n text-transform: uppercase;\n padding: 4px 9px;\n margin: 0 !important;\n border-bottom: none !important;\n }\n\n .sc-days-rows .sc-day {\n display: block;\n border-top: 1px solid #e2e8f0;\n padding: 5px 9px;\n }\n .sc-days-rows .sc-day:first-child { border-top: none; }\n\n .sc-days-grid {\n display: grid;\n grid-auto-flow: column;\n grid-auto-columns: 1fr;\n }\n .sc-days-grid .sc-day {\n border-left: 1px solid #e2e8f0;\n padding: 5px 7px;\n min-height: 1.1in;\n }\n .sc-days-grid .sc-day:first-child { border-left: none; }\n\n .sc-day-label {\n font-size: 8pt;\n font-weight: 700;\n color: #0f172a;\n letter-spacing: 0.04em;\n text-transform: uppercase;\n margin-bottom: 3px;\n }\n\n ul.sc-tasks {\n list-style: none;\n margin: 0;\n padding: 0;\n font-size: 8.5pt;\n }\n li.sc-task {\n display: flex;\n align-items: flex-start;\n line-height: 1.35;\n margin-bottom: 2px;\n break-inside: avoid;\n page-break-inside: avoid;\n color: #334155;\n }\n\n /* Milestones are the thing a student actually plans around — they are\n visually LOUD and survive a black-and-white printer. */\n .sc-milestone {\n margin-top: 4px;\n border: 1.5px solid #b45309;\n border-left-width: 5px;\n background: #fef3c7;\n color: #78350f;\n font-size: 8pt;\n font-weight: 700;\n padding: 3px 7px;\n border-radius: 3px;\n line-height: 1.3;\n }\n .sc-milestone-flag {\n letter-spacing: 0.08em;\n text-transform: uppercase;\n margin-right: 5px;\n font-size: 7pt;\n }\n\n .sc-empty-day { font-size: 8pt; color: #94a3b8; font-style: italic; }\n\n @media print {\n .sc-week-label,\n .sc-milestone {\n -webkit-print-color-adjust: exact;\n print-color-adjust: exact;\n }\n }\n`;\n\n/** Landscape geometry lives with the variant, not the shared sheet. */\nconst STUDY_CALENDAR_LANDSCAPE_STYLES = `\n ${STUDY_CALENDAR_STYLES}\n\n @media print {\n @page { size: landscape; margin: 10mm; }\n }\n`;\n\nfunction renderStudyDay(\n day: StudyDay,\n opts: { taskCheckbox: boolean; showMilestones: boolean },\n): string {\n const label = day.label.trim();\n const milestone = (day.milestone ?? \"\").trim();\n\n const tasks =\n day.tasks.length > 0\n ? `<ul class=\"sc-tasks\">\n${day.tasks\n .map(\n (task) =>\n ` <li class=\"sc-task\">${opts.taskCheckbox ? CHECKBOX_HTML : \"\"}<span class=\"sc-task-text\">${mathTextHtml(task)}</span></li>`,\n )\n .join(\"\\n\")}\n </ul>`\n : `<div class=\"sc-empty-day\">Rest / catch-up</div>`;\n\n const milestoneHtml =\n opts.showMilestones && milestone\n ? `\\n <div class=\"sc-milestone\"><span class=\"sc-milestone-flag\">Milestone</span>${mathTextHtml(milestone)}</div>`\n : \"\";\n\n return ` <div class=\"sc-day\">\n ${label ? `<div class=\"sc-day-label\">${mathTextHtml(label)}</div>` : \"\"}\n ${tasks}${milestoneHtml}\n </div>`;\n}\n\nfunction renderStudyCalendar(\n data: StudyCalendarData,\n variant: StudyCalendarVariant,\n opts: { taskCheckbox: boolean; showMilestones: boolean },\n): string {\n const daysClass =\n variant === \"landscape-grid\" ? \"sc-days sc-days-grid\" : \"sc-days sc-days-rows\";\n const subtitle = (data.subtitle ?? \"\").trim();\n const taskCount = data.weeks.reduce(\n (total, week) =>\n total + week.days.reduce((sum, day) => sum + day.tasks.length, 0),\n 0,\n );\n\n const weeks = data.weeks\n .map((week) => {\n const label = week.label.trim();\n return `<section class=\"sc-week\">\n ${label ? `<h2 class=\"sc-week-label\">${mathTextHtml(label)}</h2>` : \"\"}\n <div class=\"${daysClass}\">\n${week.days.map((day) => renderStudyDay(day, opts)).join(\"\\n\")}\n </div>\n</section>`;\n })\n .join(\"\\n\");\n\n const hint =\n variant === \"landscape-grid\"\n ? `<div class=\"edu-hint\">Set your printer to <strong>Landscape</strong> — each week prints as a row of day columns.</div>`\n : \"\";\n\n return `<div class=\"edu-header\">\n <h1 class=\"edu-title\">${mathTextHtml(data.title)}</h1>\n ${subtitle ? `<p class=\"edu-subtitle\">${mathTextHtml(subtitle)}</p>` : \"\"}\n <div class=\"edu-meta\">${data.weeks.length} week${data.weeks.length !== 1 ? \"s\" : \"\"} &nbsp;·&nbsp; ${taskCount} task${taskCount !== 1 ? \"s\" : \"\"}</div>\n</div>\n${hint}\n<div class=\"sc-plan\">\n${weeks}\n</div>`;\n}\n\nexport const studyCalendarPrinter: BlockPrinter = {\n label: \"Print study calendar\",\n\n variants: [\n {\n id: \"week-rows\",\n label: \"Week per block (portrait, recommended)\",\n description:\n \"Each week is one block with its days stacked as rows — the most room for tasks, and a week never splits across pages when it fits\",\n },\n {\n id: \"landscape-grid\",\n label: \"Calendar grid (landscape)\",\n description:\n \"Each week is a row of day columns, calendar-style — best for a wall or a binder pocket\",\n },\n ],\n\n settings: [\n {\n type: \"range\" as const,\n id: \"weekRange\",\n label: \"Weeks to print\",\n description: \"Leave blank to print the whole plan\",\n fromId: \"fromWeek\",\n toId: \"toWeek\",\n defaultFrom: 0,\n defaultTo: 0,\n min: 1,\n fromPlaceholder: \"1\",\n toPlaceholder: \"end\",\n },\n {\n type: \"boolean\" as const,\n id: \"taskCheckbox\",\n label: \"Checkbox per task\",\n description: \"An empty box in front of every task to tick off as it is done\",\n defaultValue: true,\n },\n {\n type: \"boolean\" as const,\n id: \"showMilestones\",\n label: \"Show milestones\",\n description:\n \"Prints each milestone as a bordered banner on its day — practice tests, deadlines, review checkpoints\",\n defaultValue: true,\n },\n ],\n\n print(\n data: unknown,\n variantId: string = \"week-rows\",\n rawSettings?: PrintSettings,\n ): PrintOutcome {\n const title = readTitle(data, \"Study Calendar\");\n const allWeeks = extractStudyWeeks(data);\n const variant: StudyCalendarVariant =\n variantId === \"landscape-grid\" ? \"landscape-grid\" : \"week-rows\";\n const styles =\n variant === \"landscape-grid\"\n ? STUDY_CALENDAR_LANDSCAPE_STYLES\n : STUDY_CALENDAR_STYLES;\n\n if (allWeeks.length === 0) {\n return printEmptyDocument(\n \"No study calendar data available to print.\",\n title,\n styles,\n \"study-calendar\",\n );\n }\n\n const { startIndex, endIndex } = resolveRange(\n rawSettings,\n \"fromWeek\",\n \"toWeek\",\n allWeeks.length,\n );\n const weeks = allWeeks.slice(startIndex, endIndex);\n\n const subtitle = readString(data, \"subtitle\");\n const body = renderStudyCalendar({ title, subtitle, weeks }, variant, {\n taskCheckbox: boolSetting(rawSettings, \"taskCheckbox\", true),\n showMilestones: boolSetting(rawSettings, \"showMilestones\", true),\n });\n\n return openPrintWindow(\n buildPrintDocument(body, title, styles),\n \"study-calendar\",\n );\n },\n};\n","/**\n * @ai-matrx/print/core — the Block Print contract & print-window composition.\n *\n * Ported VERBATIM from matrx-frontend `lib/block-print/block-print-utils.ts`\n * (2026-08-29 state, including the `number` and `select` PrintSetting types the\n * commerce label lane added). Zero dependencies; touches `window` only at call\n * time, so the module stays import-inert and RSC-safe.\n *\n * BlockPrinter is the only interface a host system needs to know about.\n * Each printable unit exports its own BlockPrinter alongside its render\n * component; host code only ever calls print(data, variantId, settings).\n *\n * `buildFitTextScript` is the ONE auto-shrink script (the flashcards\n * FIT_TEXT pattern, parameterized by selector so the label lane shares it).\n */\n\n// THE ONE HTML escaper (duplication census row 14). Nine copies of\n// `escapeHtml` were live across the fleet and THEY DID NOT ESCAPE THE SAME\n// CHARACTERS — a string safe through one was an attribute break-out through\n// another. It moved to `@ai-matrx/kit/html-escape` with a decided character\n// set: an HTML escaper must not require this package's jspdf + html2canvas\n// graph. Not re-exported from here; import `@ai-matrx/kit/html-escape`.\nimport { downloadFile } from \"@ai-matrx/kit/download\";\nimport { escapeHtml } from \"@ai-matrx/kit/html-escape\";\nimport { KATEX_CSS, KATEX_CSS_MARKER } from \"./katex-css.generated\";\n\n// ─── Contract ────────────────────────────────────────────────────────────────\n\nexport interface PrintVariant {\n id: string;\n label: string;\n description?: string;\n}\n\n/**\n * A single user-configurable setting shown in the print dialog.\n * Extend the discriminated union for new control types\n * without breaking existing printers.\n */\nexport type PrintSetting =\n | {\n type: \"boolean\";\n id: string;\n label: string;\n description?: string;\n /** Default value shown when the dialog first opens */\n defaultValue: boolean;\n /** Which variant IDs this setting applies to. Omit = applies to all. */\n appliesTo?: string[];\n }\n | {\n /**\n * A numeric \"from → to\" range control, rendered as two small number inputs.\n * Writes two entries into the resolved PrintSettings map — one under fromId,\n * one under toId. Printers interpret 0 (or missing) as \"no bound\" by convention.\n */\n type: \"range\";\n /** Stable id used as React key — not written to the settings map */\n id: string;\n label: string;\n description?: string;\n /** Settings map key for the lower bound value */\n fromId: string;\n /** Settings map key for the upper bound value */\n toId: string;\n defaultFrom: number;\n defaultTo: number;\n /** Minimum accepted value for each input (inclusive). Default 0. */\n min?: number;\n /** Placeholder shown when the input is empty (0). Default \"start\" / \"end\". */\n fromPlaceholder?: string;\n toPlaceholder?: string;\n /** Which variant IDs this setting applies to. Omit = applies to all. */\n appliesTo?: string[];\n }\n | {\n /** A single numeric input (e.g. \"start at label #\", \"copies\"). */\n type: \"number\";\n id: string;\n label: string;\n description?: string;\n defaultValue: number;\n /** Minimum accepted value (inclusive). Default 0. */\n min?: number;\n /** Maximum accepted value (inclusive). Omit = unbounded. */\n max?: number;\n /** Which variant IDs this setting applies to. Omit = applies to all. */\n appliesTo?: string[];\n }\n | {\n /** A one-of-N choice rendered as a compact segmented row. */\n type: \"select\";\n id: string;\n label: string;\n description?: string;\n options: { value: string; label: string }[];\n defaultValue: string;\n /** Which variant IDs this setting applies to. Omit = applies to all. */\n appliesTo?: string[];\n };\n\n/** A resolved map of setting id → current value, passed to print(). */\nexport type PrintSettings = Record<string, boolean | string | number>;\n\n/**\n * The self-contained print capability that each block can export.\n * Host code only ever calls print(data, variantId, settings) — it never inspects internals.\n */\nexport interface BlockPrinter {\n /** Tooltip / aria-label for the print button in the block header */\n label: string;\n\n /**\n * Variants offered to the user before printing.\n * Empty array = no options dialog shown; prints immediately with defaults.\n */\n variants: PrintVariant[];\n\n /**\n * Optional user-configurable settings shown below the variant picker.\n * Omit entirely if the block has no configurable settings.\n */\n settings?: PrintSetting[];\n\n /**\n * Execute the print.\n * data — the block's structured data (serverData or parsed content)\n * variantId — which variant was chosen (undefined = default / no variants)\n * settings — resolved setting values chosen by the user\n *\n * MAY resolve to a PrintOutcome (\"opened\" | \"downloaded\") so the host can\n * tell the user when the popup-blocked download fallback fired; `void`\n * stays legal for printers that don't go through a print window.\n */\n print: (\n data: unknown,\n variantId?: string,\n settings?: PrintSettings,\n ) => void | PrintOutcome | Promise<void | PrintOutcome>;\n\n /**\n * The block as it appears INSIDE a composed print (a message's Print / Full\n * Print, a document export): the same adapter the block's own print uses,\n * returning body HTML or a picture. A frame block (an HTML page) answers\n * with an image — a composed print window runs no author scripts — or an\n * honest `{ notice }` when no picture can be made. Absent ⇒ the composer\n * prints the block's source.\n */\n toPrintHtml?: (data: unknown, context: PrintBlockContext) => PrintBlockOutput | null | Promise<PrintBlockOutput | null>;\n}\n\n/** Where a block sits when a composer asks for its print form. */\nexport interface PrintBlockContext {\n /** The registry key the block was found under (artifact type or `__kind`). */\n readonly type: string;\n /** The block's raw source text, exactly as it sits in the message. */\n readonly raw: string;\n /** The block's title, when the wire form carries one. */\n readonly title?: string | undefined;\n /** The wire form's attributes (an `<artifact>`'s `id`, `version`) — how a printer finds the block's record. */\n readonly attributes?: Readonly<Record<string, string>> | undefined;\n}\n\n/**\n * A block's print form inside a composed print. `html` is trusted body HTML\n * from a printer (escape what you interpolate); `image` is a picture (a\n * captured page, a drawn diagram); `notice` is an honest line printed in the\n * block's place when neither exists.\n */\nexport type PrintBlockOutput =\n | { readonly html: string }\n | { readonly image: { readonly src: string; readonly alt?: string | undefined; readonly caption?: string | undefined } }\n | { readonly notice: string };\n\n// ─── The ONE block-printer registry ───────────────────────────────────────────\n//\n// Keyed by artifact type / `__kind`. A block's own print button, the canvas\n// tab's Print and the message composer all read the same entry, so a block\n// has one print adapter with every caller. Lives on globalThis under a\n// Symbol.for key so duplicated bundles (ESM + CJS) share one registry.\n\nconst PRINTER_REGISTRY = Symbol.for(\"ai-matrx.print.block-printers\");\n\nfunction printerRegistry(): Map<string, BlockPrinter> {\n const g = globalThis as unknown as { [PRINTER_REGISTRY]?: Map<string, BlockPrinter> };\n g[PRINTER_REGISTRY] ??= new Map();\n return g[PRINTER_REGISTRY];\n}\n\n/** Registers `printer` under each key (artifact type and/or `__kind`). Returns the unregister. */\nexport function registerBlockPrinter(keys: string | readonly string[], printer: BlockPrinter): () => void {\n const map = printerRegistry();\n const list = (typeof keys === \"string\" ? [keys] : keys).map((key) => key.toLowerCase());\n for (const key of list) map.set(key, printer);\n return () => {\n for (const key of list) if (map.get(key) === printer) map.delete(key);\n };\n}\n\n/** The printer registered for an artifact type or `__kind` (case-insensitive). */\nexport function getBlockPrinter(key: string | null | undefined): BlockPrinter | undefined {\n return key ? printerRegistry().get(key.toLowerCase()) : undefined;\n}\n\n/** Every registered key — for guards and diagnostics. */\nexport function listBlockPrinterKeys(): string[] {\n return [...printerRegistry().keys()];\n}\n\n/** The HTML a composer puts in a block's place for a `PrintBlockOutput`. */\nexport function printBlockOutputHtml(output: PrintBlockOutput): string {\n if (\"html\" in output) return `<div class=\"matrx-print-block\">${output.html}</div>`;\n if (\"image\" in output) {\n const { src, alt, caption } = output.image;\n return `<figure class=\"matrx-print-block matrx-print-image\"><img src=\"${escapeHtml(src)}\" alt=\"${escapeHtml(\n alt ?? \"Picture\",\n )}\" style=\"max-width:100%;height:auto\">${caption ? `<figcaption>${escapeHtml(caption)}</figcaption>` : \"\"}</figure>`;\n }\n return `<p class=\"matrx-print-block matrx-print-notice\" style=\"border:1px dashed #94a3b8;border-radius:6px;padding:10px 12px;color:#475569;font-style:italic\">${escapeHtml(\n output.notice,\n )}</p>`;\n}\n\n// ─── Shared Utilities ─────────────────────────────────────────────────────────\n\nconst PRINT_STYLES = `\n *, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }\n\n body {\n font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Helvetica Neue', Arial, sans-serif;\n font-size: 11pt;\n line-height: 1.6;\n color: #1a1a1a;\n background: #fff;\n max-width: 860px;\n margin: 0 auto;\n padding: 28px 36px;\n }\n\n .print-actions {\n display: flex;\n gap: 10px;\n margin-bottom: 24px;\n padding-bottom: 18px;\n border-bottom: 2px solid #e5e7eb;\n }\n\n .print-btn {\n display: inline-flex;\n align-items: center;\n gap: 6px;\n padding: 8px 20px;\n border-radius: 8px;\n font-size: 13px;\n font-family: inherit;\n cursor: pointer;\n border: none;\n font-weight: 600;\n }\n\n .print-btn-primary { background: #2563eb; color: #fff; }\n .print-btn-secondary { background: #f3f4f6; color: #374151; border: 1px solid #d1d5db; }\n\n h1 { font-size: 22pt; font-weight: 700; margin-bottom: 0.5em; }\n h2 { font-size: 16pt; font-weight: 700; margin: 1.2em 0 0.4em; border-bottom: 1px solid #e5e7eb; padding-bottom: 0.2em; }\n h3 { font-size: 13pt; font-weight: 600; margin: 1em 0 0.3em; }\n p { margin-bottom: 0.7em; }\n\n table {\n width: 100%;\n border-collapse: collapse;\n margin: 1em 0;\n font-size: 10pt;\n }\n th {\n background: #1e293b;\n color: #f8fafc;\n font-weight: 600;\n text-align: left;\n padding: 7px 12px;\n border: 1px solid #334155;\n }\n td {\n padding: 6px 12px;\n border: 1px solid #e2e8f0;\n vertical-align: top;\n }\n tr:nth-child(even) td { background: #f8fafc; }\n\n @media print {\n body { max-width: 100%; padding: 0; }\n .print-actions { display: none !important; }\n th { -webkit-print-color-adjust: exact; print-color-adjust: exact; }\n }\n`;\n\n/**\n * Wrap body HTML in a complete, styled print document.\n */\nexport function buildPrintDocument(\n bodyHtml: string,\n title = \"AI Response\",\n extraStyles = \"\",\n): string {\n return `<!DOCTYPE html>\n<html lang=\"en\">\n<head>\n <meta charset=\"UTF-8\">\n <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">\n <title>${escapeHtml(title)}</title>\n <style>\n${PRINT_STYLES}\n${extraStyles}\n </style>\n</head>\n<body>\n <div class=\"print-actions\">\n <button class=\"print-btn print-btn-primary\" onclick=\"window.print()\">Print / Save as PDF</button>\n <button class=\"print-btn print-btn-secondary\" onclick=\"window.close()\">Close</button>\n </div>\n <div class=\"content\">\n${bodyHtml}\n </div>\n</body>\n</html>`;\n}\n\n/**\n * How a print request actually reached the user.\n *\n * \"opened\" — a print window/tab was opened and the document written into it.\n * \"downloaded\" — the popup was blocked, so the document was downloaded as an\n * .html file instead (the contract's fallback). Hosts SHOULD\n * surface this to the user (e.g. a toast saying the print file\n * was downloaded) — a blocked popup plus a silent download is\n * indistinguishable from \"nothing happened\", which is exactly\n * how QA filed it (2026-08-30, F5/F6/F8).\n */\nexport type PrintOutcome = \"opened\" | \"downloaded\";\n\n/**\n * Open a new browser window and write a complete HTML document into it.\n * Falls back to downloading an .html file if the popup is blocked.\n *\n * Returns which path was taken so callers can tell the user when the\n * fallback fired. `windowFeatures` customizes the popup geometry (the\n * flashcards fixed-geometry variants pass a wider window).\n */\n/**\n * Every printed document leaves through here, so this is where typeset math\n * gets its stylesheet: when the page carries KaTeX output and does not already\n * carry the sheet, it is added to <head>. A page with no math is untouched,\n * byte for byte (the flashcard golden master holds every printer to that).\n */\nexport function withMathStyles(htmlDocument: string): string {\n if (!htmlDocument.includes('class=\"katex\"') || htmlDocument.includes(KATEX_CSS_MARKER)) {\n return htmlDocument;\n }\n const style = `<style data-matrx-katex>${KATEX_CSS}</style>`;\n const head = htmlDocument.search(/<\\/head>/i);\n return head >= 0\n ? htmlDocument.slice(0, head) + style + htmlDocument.slice(head)\n : style + htmlDocument;\n}\n\nexport function openPrintWindow(\n rawDocument: string,\n filename = \"print\",\n windowFeatures = \"width=920,height=720,scrollbars=yes\",\n): PrintOutcome {\n const htmlDocument = withMathStyles(rawDocument);\n const win = window.open(\"\", \"_blank\", windowFeatures);\n // Popup blocked — fall back to file download.\n if (!win) return openPrintWindowFallback(htmlDocument, filename);\n win.document.open();\n win.document.write(htmlDocument);\n win.document.close();\n return \"opened\";\n}\n\n/** A print window opened before its document is ready (see `openPendingPrintWindow`). */\nexport interface PendingPrintWindow {\n /** Write the finished document; downloads it when the popup was blocked or closed. */\n write(htmlDocument: string): PrintOutcome;\n}\n\n/**\n * Open the print window NOW — inside the click, where popup blockers allow it —\n * and write the document later, once async preparation (drawing diagrams) is\n * done. The window says \"Preparing…\" meanwhile.\n */\nexport function openPendingPrintWindow(\n filename = \"print\",\n windowFeatures = \"width=920,height=720,scrollbars=yes\",\n): PendingPrintWindow {\n const win = window.open(\"\", \"_blank\", windowFeatures);\n if (win) {\n win.document.open();\n win.document.write(\n '<!DOCTYPE html><html><head><meta charset=\"UTF-8\"><title>Preparing…</title></head><body style=\"font:14px -apple-system,BlinkMacSystemFont,sans-serif;color:#555;padding:2rem\">Preparing the document for print…</body></html>',\n );\n win.document.close();\n }\n return {\n write(rawDocument: string): PrintOutcome {\n const htmlDocument = withMathStyles(rawDocument);\n if (!win || win.closed) return openPrintWindowFallback(htmlDocument, filename);\n win.document.open();\n win.document.write(htmlDocument);\n win.document.close();\n return \"opened\";\n },\n };\n}\n\nfunction openPrintWindowFallback(htmlDocument: string, filename: string): PrintOutcome {\n downloadFile(`${filename.replace(/\\s+/g, \"-\").toLowerCase()}.html`, htmlDocument, \"text/html;charset=utf-8\");\n return \"downloaded\";\n}\n\n/**\n * Shorthand: build the document and open it in one call.\n * Returns the same PrintOutcome as openPrintWindow.\n */\nexport function printHtmlContent(\n bodyHtml: string,\n title = \"AI Response\",\n extraStyles = \"\",\n): PrintOutcome {\n const doc = buildPrintDocument(bodyHtml, title, extraStyles);\n return openPrintWindow(doc, title);\n}\n\n/**\n * Build the auto-shrink script that runs INSIDE a printed window: for every\n * element matching each selector, its font-size is reduced (0.5pt steps, 6pt\n * floor) until it fits its parent element's box. This is the flashcards\n * FIT_TEXT behavior verbatim, parameterized by selector so every lane\n * (flashcards card text, Avery text, label captions) shares the ONE loop.\n *\n * Pass the same selectors the original used to get byte-identical behavior:\n * flashcards passes `[\".card-text .card-text-inner\", \".avery-text-wrap .avery-text\"]`.\n */\nexport function buildFitTextScript(selectors: readonly string[]): string {\n const selectorsJson = JSON.stringify([...selectors]);\n return `\n<script>\n(function() {\n function fitText(el, container) {\n // container is the bounding box we must fit inside\n var maxW = container.clientWidth;\n var maxH = container.clientHeight;\n var size = parseFloat(window.getComputedStyle(el).fontSize);\n var minSize = 6;\n // Give the element a chance to reflow at current size before measuring\n el.style.fontSize = size + \"pt\";\n while (size > minSize && (el.scrollWidth > maxW + 1 || el.scrollHeight > maxH + 1)) {\n size -= 0.5;\n el.style.fontSize = size + \"pt\";\n }\n }\n function runAll() {\n var selectors = ${selectorsJson};\n for (var s = 0; s < selectors.length; s++) {\n var els = document.querySelectorAll(selectors[s]);\n for (var i = 0; i < els.length; i++) {\n fitText(els[i], els[i].parentElement);\n }\n }\n }\n if (document.readyState === \"loading\") {\n document.addEventListener(\"DOMContentLoaded\", runAll);\n } else {\n // document.write pages may already be loaded\n setTimeout(runAll, 0);\n }\n})();\n</script>`;\n}\n\n\n// ─── DOM print: a rendered body, as it looks ─────────────────────────────────\n\nexport interface PrintElementOptions {\n /** The print window's title (and the download fallback's file name). */\n title?: string;\n /** Open the system print dialog once the window has loaded. Default true. */\n autoPrint?: boolean;\n /** Keep buttons, toolbars and menus in the print (default false: they are chrome, not content). */\n keepInteractive?: boolean;\n}\n\n/**\n * Interactive chrome that is not content: anything marked `data-print-hide`,\n * toolbars and menus, and buttons (\"Chart this\", \"Save to\", icon actions).\n * A button stays when it IS content — marked `data-print-keep`, or a disclosure\n * trigger (`aria-expanded`) whose label is a heading — and so does anything\n * inside a `data-print-keep` region. Removal runs on the print clone only.\n */\nconst PRINT_CHROME_SELECTOR = [\n \"[data-print-hide]\",\n '[role=\"toolbar\"]',\n '[role=\"menu\"]',\n '[role=\"menubar\"]',\n \"button\",\n '[role=\"button\"]',\n 'input[type=\"button\"]',\n 'input[type=\"submit\"]',\n 'input[type=\"reset\"]',\n].join(\",\");\n\nexport function stripInteractiveChrome(root: ParentNode): number {\n let removed = 0;\n root.querySelectorAll(PRINT_CHROME_SELECTOR).forEach((node) => {\n if (!root.contains(node)) return; // already gone with a removed ancestor\n const explicit = node.hasAttribute(\"data-print-hide\");\n if (!explicit) {\n if (node.closest(\"[data-print-keep]\")) return;\n if (node.matches(\"button, [role=\\\"button\\\"]\") && node.hasAttribute(\"aria-expanded\")) return;\n }\n node.remove();\n removed += 1;\n });\n return removed;\n}\n\nconst ELEMENT_PRINT_CSS = `\n html, body { height: auto !important; min-height: 0 !important; overflow: visible !important; background: #fff !important; }\n body { margin: 0; padding: 16px; }\n *, *::before, *::after { -webkit-print-color-adjust: exact !important; print-color-adjust: exact !important; }\n .matrx-print-root, .matrx-print-root * { max-height: none !important; }\n .matrx-print-root [class*=\"overflow-\"], .matrx-print-root [class*=\"h-full\"], .matrx-print-root [class*=\"min-h-0\"] { overflow: visible !important; height: auto !important; }\n .matrx-print-frame-notice { border: 1px dashed #94a3b8; border-radius: 6px; padding: 10px 12px; color: #475569; font: italic 12px sans-serif; }\n @media print { .matrx-print-root * { break-inside: auto; } img, svg, figure, tr { break-inside: avoid; } }\n`;\n\n/**\n * Prints a same-origin DOM body exactly as it is drawn: the element's markup\n * with the page's own stylesheets, light theme, backgrounds kept, scroll\n * containers opened to full height. A `<canvas>` prints as its picture; an\n * `<iframe>` cannot be copied and prints an honest notice in its place (a\n * frame kind declares its own print instead). Opens inside the click.\n */\nexport function printElement(element: HTMLElement, options: PrintElementOptions = {}): PrintOutcome {\n const title = options.title ?? (document.title || \"Print\");\n const head = [...document.querySelectorAll<HTMLLinkElement | HTMLStyleElement>('link[rel=\"stylesheet\"], style')]\n .map((node) => {\n if (node instanceof HTMLLinkElement) return `<link rel=\"stylesheet\" href=\"${escapeHtml(node.href)}\">`;\n return `<style>${node.textContent ?? \"\"}</style>`;\n })\n .join(\"\\n\");\n const clone = element.cloneNode(true) as HTMLElement;\n const liveCanvases = element.querySelectorAll(\"canvas\");\n clone.querySelectorAll(\"canvas\").forEach((canvas, i) => {\n const live = liveCanvases[i];\n const img = document.createElement(\"img\");\n try {\n img.src = live ? live.toDataURL(\"image/png\") : \"\";\n } catch {\n img.alt = \"This drawing cannot be copied for print.\";\n }\n img.style.maxWidth = \"100%\";\n canvas.replaceWith(img);\n });\n clone.querySelectorAll(\"iframe\").forEach((frame) => {\n const note = document.createElement(\"p\");\n note.className = \"matrx-print-frame-notice\";\n note.textContent = \"An embedded page is here — print it from its own Print.\";\n frame.replaceWith(note);\n });\n clone.querySelectorAll(\"script\").forEach((node) => node.remove());\n if (options.keepInteractive !== true) stripInteractiveChrome(clone);\n const htmlClass = document.documentElement.className.replace(/\\bdark\\b/g, \"light\");\n const autoPrint = options.autoPrint ?? true;\n const doc = `<!DOCTYPE html><html lang=\"en\" class=\"${escapeHtml(htmlClass)}\"><head><meta charset=\"UTF-8\"><base href=\"${escapeHtml(\n document.baseURI,\n )}\"><title>${escapeHtml(title)}</title>${head}<style>${ELEMENT_PRINT_CSS}</style></head><body><div class=\"matrx-print-root\">${\n clone.outerHTML\n }</div>${\n autoPrint\n ? '<script>window.addEventListener(\"load\",function(){setTimeout(function(){window.focus();window.print();},250);});</script>'\n : \"\"\n }</body></html>`;\n return openPrintWindow(doc, title);\n}\n","// GENERATED by scripts/gen-katex-css.mjs from katex@0.18.9 — do not edit.\nexport const KATEX_VERSION = \"0.18.9\";\n/** Leads KATEX_CSS; lets openPrintWindow see the sheet is already present. */\nexport const KATEX_CSS_MARKER = \"/* matrx-katex@0.18.9 */\";\nexport const KATEX_CSS = \"/* matrx-katex@0.18.9 */@font-face{font-display:block;font-family:KaTeX_AMS;font-style:normal;font-weight:400;src:url(https://cdn.jsdelivr.net/npm/katex@0.18.9/dist/fonts/KaTeX_AMS-Regular.woff2) format(\\\"woff2\\\"),url(https://cdn.jsdelivr.net/npm/katex@0.18.9/dist/fonts/KaTeX_AMS-Regular.woff) format(\\\"woff\\\"),url(https://cdn.jsdelivr.net/npm/katex@0.18.9/dist/fonts/KaTeX_AMS-Regular.ttf) format(\\\"truetype\\\")}@font-face{font-display:block;font-family:KaTeX_Caligraphic;font-style:normal;font-weight:700;src:url(https://cdn.jsdelivr.net/npm/katex@0.18.9/dist/fonts/KaTeX_Caligraphic-Bold.woff2) format(\\\"woff2\\\"),url(https://cdn.jsdelivr.net/npm/katex@0.18.9/dist/fonts/KaTeX_Caligraphic-Bold.woff) format(\\\"woff\\\"),url(https://cdn.jsdelivr.net/npm/katex@0.18.9/dist/fonts/KaTeX_Caligraphic-Bold.ttf) format(\\\"truetype\\\")}@font-face{font-display:block;font-family:KaTeX_Caligraphic;font-style:normal;font-weight:400;src:url(https://cdn.jsdelivr.net/npm/katex@0.18.9/dist/fonts/KaTeX_Caligraphic-Regular.woff2) format(\\\"woff2\\\"),url(https://cdn.jsdelivr.net/npm/katex@0.18.9/dist/fonts/KaTeX_Caligraphic-Regular.woff) format(\\\"woff\\\"),url(https://cdn.jsdelivr.net/npm/katex@0.18.9/dist/fonts/KaTeX_Caligraphic-Regular.ttf) format(\\\"truetype\\\")}@font-face{font-display:block;font-family:KaTeX_Fraktur;font-style:normal;font-weight:700;src:url(https://cdn.jsdelivr.net/npm/katex@0.18.9/dist/fonts/KaTeX_Fraktur-Bold.woff2) format(\\\"woff2\\\"),url(https://cdn.jsdelivr.net/npm/katex@0.18.9/dist/fonts/KaTeX_Fraktur-Bold.woff) format(\\\"woff\\\"),url(https://cdn.jsdelivr.net/npm/katex@0.18.9/dist/fonts/KaTeX_Fraktur-Bold.ttf) format(\\\"truetype\\\")}@font-face{font-display:block;font-family:KaTeX_Fraktur;font-style:normal;font-weight:400;src:url(https://cdn.jsdelivr.net/npm/katex@0.18.9/dist/fonts/KaTeX_Fraktur-Regular.woff2) format(\\\"woff2\\\"),url(https://cdn.jsdelivr.net/npm/katex@0.18.9/dist/fonts/KaTeX_Fraktur-Regular.woff) format(\\\"woff\\\"),url(https://cdn.jsdelivr.net/npm/katex@0.18.9/dist/fonts/KaTeX_Fraktur-Regular.ttf) format(\\\"truetype\\\")}@font-face{font-display:block;font-family:KaTeX_Main;font-style:normal;font-weight:700;src:url(https://cdn.jsdelivr.net/npm/katex@0.18.9/dist/fonts/KaTeX_Main-Bold.woff2) format(\\\"woff2\\\"),url(https://cdn.jsdelivr.net/npm/katex@0.18.9/dist/fonts/KaTeX_Main-Bold.woff) format(\\\"woff\\\"),url(https://cdn.jsdelivr.net/npm/katex@0.18.9/dist/fonts/KaTeX_Main-Bold.ttf) format(\\\"truetype\\\")}@font-face{font-display:block;font-family:KaTeX_Main;font-style:italic;font-weight:700;src:url(https://cdn.jsdelivr.net/npm/katex@0.18.9/dist/fonts/KaTeX_Main-BoldItalic.woff2) format(\\\"woff2\\\"),url(https://cdn.jsdelivr.net/npm/katex@0.18.9/dist/fonts/KaTeX_Main-BoldItalic.woff) format(\\\"woff\\\"),url(https://cdn.jsdelivr.net/npm/katex@0.18.9/dist/fonts/KaTeX_Main-BoldItalic.ttf) format(\\\"truetype\\\")}@font-face{font-display:block;font-family:KaTeX_Main;font-style:italic;font-weight:400;src:url(https://cdn.jsdelivr.net/npm/katex@0.18.9/dist/fonts/KaTeX_Main-Italic.woff2) format(\\\"woff2\\\"),url(https://cdn.jsdelivr.net/npm/katex@0.18.9/dist/fonts/KaTeX_Main-Italic.woff) format(\\\"woff\\\"),url(https://cdn.jsdelivr.net/npm/katex@0.18.9/dist/fonts/KaTeX_Main-Italic.ttf) format(\\\"truetype\\\")}@font-face{font-display:block;font-family:KaTeX_Main;font-style:normal;font-weight:400;src:url(https://cdn.jsdelivr.net/npm/katex@0.18.9/dist/fonts/KaTeX_Main-Regular.woff2) format(\\\"woff2\\\"),url(https://cdn.jsdelivr.net/npm/katex@0.18.9/dist/fonts/KaTeX_Main-Regular.woff) format(\\\"woff\\\"),url(https://cdn.jsdelivr.net/npm/katex@0.18.9/dist/fonts/KaTeX_Main-Regular.ttf) format(\\\"truetype\\\")}@font-face{font-display:block;font-family:KaTeX_Math;font-style:italic;font-weight:700;src:url(https://cdn.jsdelivr.net/npm/katex@0.18.9/dist/fonts/KaTeX_Math-BoldItalic.woff2) format(\\\"woff2\\\"),url(https://cdn.jsdelivr.net/npm/katex@0.18.9/dist/fonts/KaTeX_Math-BoldItalic.woff) format(\\\"woff\\\"),url(https://cdn.jsdelivr.net/npm/katex@0.18.9/dist/fonts/KaTeX_Math-BoldItalic.ttf) format(\\\"truetype\\\")}@font-face{font-display:block;font-family:KaTeX_Math;font-style:italic;font-weight:400;src:url(https://cdn.jsdelivr.net/npm/katex@0.18.9/dist/fonts/KaTeX_Math-Italic.woff2) format(\\\"woff2\\\"),url(https://cdn.jsdelivr.net/npm/katex@0.18.9/dist/fonts/KaTeX_Math-Italic.woff) format(\\\"woff\\\"),url(https://cdn.jsdelivr.net/npm/katex@0.18.9/dist/fonts/KaTeX_Math-Italic.ttf) format(\\\"truetype\\\")}@font-face{font-display:block;font-family:\\\"KaTeX_SansSerif\\\";font-style:normal;font-weight:700;src:url(https://cdn.jsdelivr.net/npm/katex@0.18.9/dist/fonts/KaTeX_SansSerif-Bold.woff2) format(\\\"woff2\\\"),url(https://cdn.jsdelivr.net/npm/katex@0.18.9/dist/fonts/KaTeX_SansSerif-Bold.woff) format(\\\"woff\\\"),url(https://cdn.jsdelivr.net/npm/katex@0.18.9/dist/fonts/KaTeX_SansSerif-Bold.ttf) format(\\\"truetype\\\")}@font-face{font-display:block;font-family:\\\"KaTeX_SansSerif\\\";font-style:italic;font-weight:400;src:url(https://cdn.jsdelivr.net/npm/katex@0.18.9/dist/fonts/KaTeX_SansSerif-Italic.woff2) format(\\\"woff2\\\"),url(https://cdn.jsdelivr.net/npm/katex@0.18.9/dist/fonts/KaTeX_SansSerif-Italic.woff) format(\\\"woff\\\"),url(https://cdn.jsdelivr.net/npm/katex@0.18.9/dist/fonts/KaTeX_SansSerif-Italic.ttf) format(\\\"truetype\\\")}@font-face{font-display:block;font-family:\\\"KaTeX_SansSerif\\\";font-style:normal;font-weight:400;src:url(https://cdn.jsdelivr.net/npm/katex@0.18.9/dist/fonts/KaTeX_SansSerif-Regular.woff2) format(\\\"woff2\\\"),url(https://cdn.jsdelivr.net/npm/katex@0.18.9/dist/fonts/KaTeX_SansSerif-Regular.woff) format(\\\"woff\\\"),url(https://cdn.jsdelivr.net/npm/katex@0.18.9/dist/fonts/KaTeX_SansSerif-Regular.ttf) format(\\\"truetype\\\")}@font-face{font-display:block;font-family:KaTeX_Script;font-style:normal;font-weight:400;src:url(https://cdn.jsdelivr.net/npm/katex@0.18.9/dist/fonts/KaTeX_Script-Regular.woff2) format(\\\"woff2\\\"),url(https://cdn.jsdelivr.net/npm/katex@0.18.9/dist/fonts/KaTeX_Script-Regular.woff) format(\\\"woff\\\"),url(https://cdn.jsdelivr.net/npm/katex@0.18.9/dist/fonts/KaTeX_Script-Regular.ttf) format(\\\"truetype\\\")}@font-face{font-display:block;font-family:KaTeX_Size1;font-style:normal;font-weight:400;src:url(https://cdn.jsdelivr.net/npm/katex@0.18.9/dist/fonts/KaTeX_Size1-Regular.woff2) format(\\\"woff2\\\"),url(https://cdn.jsdelivr.net/npm/katex@0.18.9/dist/fonts/KaTeX_Size1-Regular.woff) format(\\\"woff\\\"),url(https://cdn.jsdelivr.net/npm/katex@0.18.9/dist/fonts/KaTeX_Size1-Regular.ttf) format(\\\"truetype\\\")}@font-face{font-display:block;font-family:KaTeX_Size2;font-style:normal;font-weight:400;src:url(https://cdn.jsdelivr.net/npm/katex@0.18.9/dist/fonts/KaTeX_Size2-Regular.woff2) format(\\\"woff2\\\"),url(https://cdn.jsdelivr.net/npm/katex@0.18.9/dist/fonts/KaTeX_Size2-Regular.woff) format(\\\"woff\\\"),url(https://cdn.jsdelivr.net/npm/katex@0.18.9/dist/fonts/KaTeX_Size2-Regular.ttf) format(\\\"truetype\\\")}@font-face{font-display:block;font-family:KaTeX_Size3;font-style:normal;font-weight:400;src:url(https://cdn.jsdelivr.net/npm/katex@0.18.9/dist/fonts/KaTeX_Size3-Regular.woff2) format(\\\"woff2\\\"),url(https://cdn.jsdelivr.net/npm/katex@0.18.9/dist/fonts/KaTeX_Size3-Regular.woff) format(\\\"woff\\\"),url(https://cdn.jsdelivr.net/npm/katex@0.18.9/dist/fonts/KaTeX_Size3-Regular.ttf) format(\\\"truetype\\\")}@font-face{font-display:block;font-family:KaTeX_Size4;font-style:normal;font-weight:400;src:url(https://cdn.jsdelivr.net/npm/katex@0.18.9/dist/fonts/KaTeX_Size4-Regular.woff2) format(\\\"woff2\\\"),url(https://cdn.jsdelivr.net/npm/katex@0.18.9/dist/fonts/KaTeX_Size4-Regular.woff) format(\\\"woff\\\"),url(https://cdn.jsdelivr.net/npm/katex@0.18.9/dist/fonts/KaTeX_Size4-Regular.ttf) format(\\\"truetype\\\")}@font-face{font-display:block;font-family:KaTeX_Typewriter;font-style:normal;font-weight:400;src:url(https://cdn.jsdelivr.net/npm/katex@0.18.9/dist/fonts/KaTeX_Typewriter-Regular.woff2) format(\\\"woff2\\\"),url(https://cdn.jsdelivr.net/npm/katex@0.18.9/dist/fonts/KaTeX_Typewriter-Regular.woff) format(\\\"woff\\\"),url(https://cdn.jsdelivr.net/npm/katex@0.18.9/dist/fonts/KaTeX_Typewriter-Regular.ttf) format(\\\"truetype\\\")}.katex{font:normal 1.21em KaTeX_Main,Times New Roman,serif;line-height:1.2;position:relative;text-indent:0;text-rendering:auto}.katex *{-ms-high-contrast-adjust:none!important;border-color:currentColor}.katex .katex-version:after{content:\\\"0.18.9\\\"}.katex .katex-mathml{border:0;-webkit-clip-path:inset(50%);clip-path:inset(50%);height:1px;overflow:hidden;padding:0;position:absolute;width:1px}.katex .katex-html>.katex-newline{display:block}.katex .katex-base{position:relative;white-space:nowrap;width:-webkit-min-content;width:-moz-min-content;width:min-content}.katex .katex-base,.katex .katex-strut{display:inline-block}.katex .textbf{font-weight:700}.katex .textit{font-style:italic}.katex .textrm{font-family:KaTeX_Main}.katex .textsf{font-family:KaTeX_SansSerif}.katex .texttt{font-family:KaTeX_Typewriter}.katex .mathnormal{font-family:KaTeX_Math;font-style:italic}.katex .mathit{font-family:KaTeX_Main;font-style:italic}.katex .mathrm{font-style:normal}.katex .mathbf{font-family:KaTeX_Main;font-weight:700}.katex .boldsymbol{font-family:KaTeX_Math;font-style:italic;font-weight:700}.katex .amsrm,.katex .mathbb,.katex .textbb{font-family:KaTeX_AMS}.katex .mathcal{font-family:KaTeX_Caligraphic}.katex .mathfrak,.katex .textfrak{font-family:KaTeX_Fraktur}.katex .mathboldfrak,.katex .textboldfrak{font-family:KaTeX_Fraktur;font-weight:700}.katex .mathtt{font-family:KaTeX_Typewriter}.katex .mathscr,.katex .textscr{font-family:KaTeX_Script}.katex .mathsf,.katex .textsf{font-family:KaTeX_SansSerif}.katex .mathboldsf,.katex .textboldsf{font-family:KaTeX_SansSerif;font-weight:700}.katex .mathitsf,.katex .mathsfit,.katex .textitsf{font-family:KaTeX_SansSerif;font-style:italic}.katex .mainrm{font-family:KaTeX_Main;font-style:normal}.katex .vlist-t{border-collapse:collapse;display:inline-table;table-layout:fixed}.katex .vlist-r{display:table-row}.katex .vlist{display:table-cell;position:relative;vertical-align:bottom}.katex .vlist>span{display:block;height:0;position:relative}.katex .vlist>span>span{display:inline-block}.katex .vlist>span>.pstrut{overflow:hidden;width:0}.katex .vlist-t2{margin-right:-2px}.katex .vlist-s{display:table-cell;font-size:1px;min-width:2px;vertical-align:bottom;width:2px}.katex .katex-vbox{align-items:baseline;display:inline-flex;flex-direction:column}.katex .katex-thinbox{display:inline-flex;flex-direction:row;max-width:0;width:0}.katex .msupsub{text-align:left}.katex .mfrac>span>span{text-align:center}.katex .mfrac .frac-line{border-bottom-style:solid;display:inline-block;width:100%}.katex .katex-hdashline,.katex .katex-hline,.katex .katex-overline .overline-line,.katex .katex-rule,.katex .katex-underline .underline-line,.katex .mfrac .frac-line{min-height:1px}.katex .mspace{display:inline-block}.katex .katex-smash{display:inline;line-height:0}.katex .clap,.katex .llap,.katex .rlap{position:relative;width:0}.katex .clap>.katex-inner,.katex .llap>.katex-inner,.katex .rlap>.katex-inner{position:absolute}.katex .clap>.katex-fix,.katex .llap>.katex-fix,.katex .rlap>.katex-fix{display:inline-block}.katex .llap>.katex-inner{right:0}.katex .clap>.katex-inner,.katex .rlap>.katex-inner{left:0}.katex .clap>.katex-inner>span{margin-left:-50%;margin-right:50%}.katex .katex-rule{border:0 solid;display:inline-block;position:relative}.katex .katex-hline,.katex .katex-overline .overline-line,.katex .katex-underline .underline-line{border-bottom-style:solid;display:inline-block;width:100%}.katex .katex-hdashline{border-bottom-style:dashed;display:inline-block;width:100%}.katex .sqrt>.katex-root{margin-left:.2777777778em;margin-right:-.5555555556em}.katex .fontsize-ensurer.reset-size1.size1,.katex .katex-sizing.reset-size1.size1{font-size:1em}.katex .fontsize-ensurer.reset-size1.size2,.katex .katex-sizing.reset-size1.size2{font-size:1.2em}.katex .fontsize-ensurer.reset-size1.size3,.katex .katex-sizing.reset-size1.size3{font-size:1.4em}.katex .fontsize-ensurer.reset-size1.size4,.katex .katex-sizing.reset-size1.size4{font-size:1.6em}.katex .fontsize-ensurer.reset-size1.size5,.katex .katex-sizing.reset-size1.size5{font-size:1.8em}.katex .fontsize-ensurer.reset-size1.size6,.katex .katex-sizing.reset-size1.size6{font-size:2em}.katex .fontsize-ensurer.reset-size1.size7,.katex .katex-sizing.reset-size1.size7{font-size:2.4em}.katex .fontsize-ensurer.reset-size1.size8,.katex .katex-sizing.reset-size1.size8{font-size:2.88em}.katex .fontsize-ensurer.reset-size1.size9,.katex .katex-sizing.reset-size1.size9{font-size:3.456em}.katex .fontsize-ensurer.reset-size1.size10,.katex .katex-sizing.reset-size1.size10{font-size:4.148em}.katex .fontsize-ensurer.reset-size1.size11,.katex .katex-sizing.reset-size1.size11{font-size:4.976em}.katex .fontsize-ensurer.reset-size2.size1,.katex .katex-sizing.reset-size2.size1{font-size:.8333333333em}.katex .fontsize-ensurer.reset-size2.size2,.katex .katex-sizing.reset-size2.size2{font-size:1em}.katex .fontsize-ensurer.reset-size2.size3,.katex .katex-sizing.reset-size2.size3{font-size:1.1666666667em}.katex .fontsize-ensurer.reset-size2.size4,.katex .katex-sizing.reset-size2.size4{font-size:1.3333333333em}.katex .fontsize-ensurer.reset-size2.size5,.katex .katex-sizing.reset-size2.size5{font-size:1.5em}.katex .fontsize-ensurer.reset-size2.size6,.katex .katex-sizing.reset-size2.size6{font-size:1.6666666667em}.katex .fontsize-ensurer.reset-size2.size7,.katex .katex-sizing.reset-size2.size7{font-size:2em}.katex .fontsize-ensurer.reset-size2.size8,.katex .katex-sizing.reset-size2.size8{font-size:2.4em}.katex .fontsize-ensurer.reset-size2.size9,.katex .katex-sizing.reset-size2.size9{font-size:2.88em}.katex .fontsize-ensurer.reset-size2.size10,.katex .katex-sizing.reset-size2.size10{font-size:3.4566666667em}.katex .fontsize-ensurer.reset-size2.size11,.katex .katex-sizing.reset-size2.size11{font-size:4.1466666667em}.katex .fontsize-ensurer.reset-size3.size1,.katex .katex-sizing.reset-size3.size1{font-size:.7142857143em}.katex .fontsize-ensurer.reset-size3.size2,.katex .katex-sizing.reset-size3.size2{font-size:.8571428571em}.katex .fontsize-ensurer.reset-size3.size3,.katex .katex-sizing.reset-size3.size3{font-size:1em}.katex .fontsize-ensurer.reset-size3.size4,.katex .katex-sizing.reset-size3.size4{font-size:1.1428571429em}.katex .fontsize-ensurer.reset-size3.size5,.katex .katex-sizing.reset-size3.size5{font-size:1.2857142857em}.katex .fontsize-ensurer.reset-size3.size6,.katex .katex-sizing.reset-size3.size6{font-size:1.4285714286em}.katex .fontsize-ensurer.reset-size3.size7,.katex .katex-sizing.reset-size3.size7{font-size:1.7142857143em}.katex .fontsize-ensurer.reset-size3.size8,.katex .katex-sizing.reset-size3.size8{font-size:2.0571428571em}.katex .fontsize-ensurer.reset-size3.size9,.katex .katex-sizing.reset-size3.size9{font-size:2.4685714286em}.katex .fontsize-ensurer.reset-size3.size10,.katex .katex-sizing.reset-size3.size10{font-size:2.9628571429em}.katex .fontsize-ensurer.reset-size3.size11,.katex .katex-sizing.reset-size3.size11{font-size:3.5542857143em}.katex .fontsize-ensurer.reset-size4.size1,.katex .katex-sizing.reset-size4.size1{font-size:.625em}.katex .fontsize-ensurer.reset-size4.size2,.katex .katex-sizing.reset-size4.size2{font-size:.75em}.katex .fontsize-ensurer.reset-size4.size3,.katex .katex-sizing.reset-size4.size3{font-size:.875em}.katex .fontsize-ensurer.reset-size4.size4,.katex .katex-sizing.reset-size4.size4{font-size:1em}.katex .fontsize-ensurer.reset-size4.size5,.katex .katex-sizing.reset-size4.size5{font-size:1.125em}.katex .fontsize-ensurer.reset-size4.size6,.katex .katex-sizing.reset-size4.size6{font-size:1.25em}.katex .fontsize-ensurer.reset-size4.size7,.katex .katex-sizing.reset-size4.size7{font-size:1.5em}.katex .fontsize-ensurer.reset-size4.size8,.katex .katex-sizing.reset-size4.size8{font-size:1.8em}.katex .fontsize-ensurer.reset-size4.size9,.katex .katex-sizing.reset-size4.size9{font-size:2.16em}.katex .fontsize-ensurer.reset-size4.size10,.katex .katex-sizing.reset-size4.size10{font-size:2.5925em}.katex .fontsize-ensurer.reset-size4.size11,.katex .katex-sizing.reset-size4.size11{font-size:3.11em}.katex .fontsize-ensurer.reset-size5.size1,.katex .katex-sizing.reset-size5.size1{font-size:.5555555556em}.katex .fontsize-ensurer.reset-size5.size2,.katex .katex-sizing.reset-size5.size2{font-size:.6666666667em}.katex .fontsize-ensurer.reset-size5.size3,.katex .katex-sizing.reset-size5.size3{font-size:.7777777778em}.katex .fontsize-ensurer.reset-size5.size4,.katex .katex-sizing.reset-size5.size4{font-size:.8888888889em}.katex .fontsize-ensurer.reset-size5.size5,.katex .katex-sizing.reset-size5.size5{font-size:1em}.katex .fontsize-ensurer.reset-size5.size6,.katex .katex-sizing.reset-size5.size6{font-size:1.1111111111em}.katex .fontsize-ensurer.reset-size5.size7,.katex .katex-sizing.reset-size5.size7{font-size:1.3333333333em}.katex .fontsize-ensurer.reset-size5.size8,.katex .katex-sizing.reset-size5.size8{font-size:1.6em}.katex .fontsize-ensurer.reset-size5.size9,.katex .katex-sizing.reset-size5.size9{font-size:1.92em}.katex .fontsize-ensurer.reset-size5.size10,.katex .katex-sizing.reset-size5.size10{font-size:2.3044444444em}.katex .fontsize-ensurer.reset-size5.size11,.katex .katex-sizing.reset-size5.size11{font-size:2.7644444444em}.katex .fontsize-ensurer.reset-size6.size1,.katex .katex-sizing.reset-size6.size1{font-size:.5em}.katex .fontsize-ensurer.reset-size6.size2,.katex .katex-sizing.reset-size6.size2{font-size:.6em}.katex .fontsize-ensurer.reset-size6.size3,.katex .katex-sizing.reset-size6.size3{font-size:.7em}.katex .fontsize-ensurer.reset-size6.size4,.katex .katex-sizing.reset-size6.size4{font-size:.8em}.katex .fontsize-ensurer.reset-size6.size5,.katex .katex-sizing.reset-size6.size5{font-size:.9em}.katex .fontsize-ensurer.reset-size6.size6,.katex .katex-sizing.reset-size6.size6{font-size:1em}.katex .fontsize-ensurer.reset-size6.size7,.katex .katex-sizing.reset-size6.size7{font-size:1.2em}.katex .fontsize-ensurer.reset-size6.size8,.katex .katex-sizing.reset-size6.size8{font-size:1.44em}.katex .fontsize-ensurer.reset-size6.size9,.katex .katex-sizing.reset-size6.size9{font-size:1.728em}.katex .fontsize-ensurer.reset-size6.size10,.katex .katex-sizing.reset-size6.size10{font-size:2.074em}.katex .fontsize-ensurer.reset-size6.size11,.katex .katex-sizing.reset-size6.size11{font-size:2.488em}.katex .fontsize-ensurer.reset-size7.size1,.katex .katex-sizing.reset-size7.size1{font-size:.4166666667em}.katex .fontsize-ensurer.reset-size7.size2,.katex .katex-sizing.reset-size7.size2{font-size:.5em}.katex .fontsize-ensurer.reset-size7.size3,.katex .katex-sizing.reset-size7.size3{font-size:.5833333333em}.katex .fontsize-ensurer.reset-size7.size4,.katex .katex-sizing.reset-size7.size4{font-size:.6666666667em}.katex .fontsize-ensurer.reset-size7.size5,.katex .katex-sizing.reset-size7.size5{font-size:.75em}.katex .fontsize-ensurer.reset-size7.size6,.katex .katex-sizing.reset-size7.size6{font-size:.8333333333em}.katex .fontsize-ensurer.reset-size7.size7,.katex .katex-sizing.reset-size7.size7{font-size:1em}.katex .fontsize-ensurer.reset-size7.size8,.katex .katex-sizing.reset-size7.size8{font-size:1.2em}.katex .fontsize-ensurer.reset-size7.size9,.katex .katex-sizing.reset-size7.size9{font-size:1.44em}.katex .fontsize-ensurer.reset-size7.size10,.katex .katex-sizing.reset-size7.size10{font-size:1.7283333333em}.katex .fontsize-ensurer.reset-size7.size11,.katex .katex-sizing.reset-size7.size11{font-size:2.0733333333em}.katex .fontsize-ensurer.reset-size8.size1,.katex .katex-sizing.reset-size8.size1{font-size:.3472222222em}.katex .fontsize-ensurer.reset-size8.size2,.katex .katex-sizing.reset-size8.size2{font-size:.4166666667em}.katex .fontsize-ensurer.reset-size8.size3,.katex .katex-sizing.reset-size8.size3{font-size:.4861111111em}.katex .fontsize-ensurer.reset-size8.size4,.katex .katex-sizing.reset-size8.size4{font-size:.5555555556em}.katex .fontsize-ensurer.reset-size8.size5,.katex .katex-sizing.reset-size8.size5{font-size:.625em}.katex .fontsize-ensurer.reset-size8.size6,.katex .katex-sizing.reset-size8.size6{font-size:.6944444444em}.katex .fontsize-ensurer.reset-size8.size7,.katex .katex-sizing.reset-size8.size7{font-size:.8333333333em}.katex .fontsize-ensurer.reset-size8.size8,.katex .katex-sizing.reset-size8.size8{font-size:1em}.katex .fontsize-ensurer.reset-size8.size9,.katex .katex-sizing.reset-size8.size9{font-size:1.2em}.katex .fontsize-ensurer.reset-size8.size10,.katex .katex-sizing.reset-size8.size10{font-size:1.4402777778em}.katex .fontsize-ensurer.reset-size8.size11,.katex .katex-sizing.reset-size8.size11{font-size:1.7277777778em}.katex .fontsize-ensurer.reset-size9.size1,.katex .katex-sizing.reset-size9.size1{font-size:.2893518519em}.katex .fontsize-ensurer.reset-size9.size2,.katex .katex-sizing.reset-size9.size2{font-size:.3472222222em}.katex .fontsize-ensurer.reset-size9.size3,.katex .katex-sizing.reset-size9.size3{font-size:.4050925926em}.katex .fontsize-ensurer.reset-size9.size4,.katex .katex-sizing.reset-size9.size4{font-size:.462962963em}.katex .fontsize-ensurer.reset-size9.size5,.katex .katex-sizing.reset-size9.size5{font-size:.5208333333em}.katex .fontsize-ensurer.reset-size9.size6,.katex .katex-sizing.reset-size9.size6{font-size:.5787037037em}.katex .fontsize-ensurer.reset-size9.size7,.katex .katex-sizing.reset-size9.size7{font-size:.6944444444em}.katex .fontsize-ensurer.reset-size9.size8,.katex .katex-sizing.reset-size9.size8{font-size:.8333333333em}.katex .fontsize-ensurer.reset-size9.size9,.katex .katex-sizing.reset-size9.size9{font-size:1em}.katex .fontsize-ensurer.reset-size9.size10,.katex .katex-sizing.reset-size9.size10{font-size:1.2002314815em}.katex .fontsize-ensurer.reset-size9.size11,.katex .katex-sizing.reset-size9.size11{font-size:1.4398148148em}.katex .fontsize-ensurer.reset-size10.size1,.katex .katex-sizing.reset-size10.size1{font-size:.2410800386em}.katex .fontsize-ensurer.reset-size10.size2,.katex .katex-sizing.reset-size10.size2{font-size:.2892960463em}.katex .fontsize-ensurer.reset-size10.size3,.katex .katex-sizing.reset-size10.size3{font-size:.337512054em}.katex .fontsize-ensurer.reset-size10.size4,.katex .katex-sizing.reset-size10.size4{font-size:.3857280617em}.katex .fontsize-ensurer.reset-size10.size5,.katex .katex-sizing.reset-size10.size5{font-size:.4339440694em}.katex .fontsize-ensurer.reset-size10.size6,.katex .katex-sizing.reset-size10.size6{font-size:.4821600771em}.katex .fontsize-ensurer.reset-size10.size7,.katex .katex-sizing.reset-size10.size7{font-size:.5785920926em}.katex .fontsize-ensurer.reset-size10.size8,.katex .katex-sizing.reset-size10.size8{font-size:.6943105111em}.katex .fontsize-ensurer.reset-size10.size9,.katex .katex-sizing.reset-size10.size9{font-size:.8331726133em}.katex .fontsize-ensurer.reset-size10.size10,.katex .katex-sizing.reset-size10.size10{font-size:1em}.katex .fontsize-ensurer.reset-size10.size11,.katex .katex-sizing.reset-size10.size11{font-size:1.1996142719em}.katex .fontsize-ensurer.reset-size11.size1,.katex .katex-sizing.reset-size11.size1{font-size:.2009646302em}.katex .fontsize-ensurer.reset-size11.size2,.katex .katex-sizing.reset-size11.size2{font-size:.2411575563em}.katex .fontsize-ensurer.reset-size11.size3,.katex .katex-sizing.reset-size11.size3{font-size:.2813504823em}.katex .fontsize-ensurer.reset-size11.size4,.katex .katex-sizing.reset-size11.size4{font-size:.3215434084em}.katex .fontsize-ensurer.reset-size11.size5,.katex .katex-sizing.reset-size11.size5{font-size:.3617363344em}.katex .fontsize-ensurer.reset-size11.size6,.katex .katex-sizing.reset-size11.size6{font-size:.4019292605em}.katex .fontsize-ensurer.reset-size11.size7,.katex .katex-sizing.reset-size11.size7{font-size:.4823151125em}.katex .fontsize-ensurer.reset-size11.size8,.katex .katex-sizing.reset-size11.size8{font-size:.578778135em}.katex .fontsize-ensurer.reset-size11.size9,.katex .katex-sizing.reset-size11.size9{font-size:.6945337621em}.katex .fontsize-ensurer.reset-size11.size10,.katex .katex-sizing.reset-size11.size10{font-size:.8336012862em}.katex .fontsize-ensurer.reset-size11.size11,.katex .katex-sizing.reset-size11.size11{font-size:1em}.katex .delimsizing.size1{font-family:KaTeX_Size1}.katex .delimsizing.size2{font-family:KaTeX_Size2}.katex .delimsizing.size3{font-family:KaTeX_Size3}.katex .delimsizing.size4{font-family:KaTeX_Size4}.katex .delimsizing.mult .delim-size1>span{font-family:KaTeX_Size1}.katex .delimsizing.mult .delim-size4>span{font-family:KaTeX_Size4}.katex .nulldelimiter{display:inline-block;width:.12em}.katex .delimcenter,.katex .op-symbol{position:relative}.katex .op-symbol.small-op{font-family:KaTeX_Size1}.katex .op-symbol.large-op{font-family:KaTeX_Size2}.katex .katex-accent>.vlist-t,.katex .op-limits>.vlist-t{text-align:center}.katex .katex-accent .accent-body{position:relative}.katex .katex-accent .accent-body:not(.accent-full){width:0}.katex .katex-overlay{display:block}.katex .mtable .vertical-separator{display:inline-block;min-width:1px}.katex .mtable .arraycolsep{display:inline-block}.katex .mtable .col-align-c>.vlist-t{text-align:center}.katex .mtable .col-align-l>.vlist-t{text-align:left}.katex .mtable .col-align-r>.vlist-t{text-align:right}.katex .svg-align{text-align:left}.katex svg{fill:currentColor;stroke:currentColor;display:block;height:inherit;position:absolute;width:100%}.katex svg path{stroke:none}.katex svg{fill-rule:nonzero;fill-opacity:1;stroke-width:1;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1}.katex img{border-style:none;max-height:none;max-width:none;min-height:0;min-width:0}.katex .katex-stretchy{display:block;overflow:hidden;position:relative;width:100%}.katex .katex-stretchy:after,.katex .katex-stretchy:before{content:\\\"\\\"}.katex .hide-tail{overflow:hidden;position:relative;width:100%}.katex .halfarrow-left{left:0;overflow:hidden;position:absolute;width:50.2%}.katex .halfarrow-right{overflow:hidden;position:absolute;right:0;width:50.2%}.katex .brace-left{left:0;overflow:hidden;position:absolute;width:25.1%}.katex .brace-center{left:25%;overflow:hidden;position:absolute;width:50%}.katex .brace-right{overflow:hidden;position:absolute;right:0;width:25.1%}.katex .x-arrow-pad{padding:0 .5em}.katex .cd-arrow-pad{padding:0 .55556em 0 .27778em}.katex .mover,.katex .munder,.katex .x-arrow{text-align:center}.katex .boxpad{padding:0 .3em}.katex .fbox,.katex .fcolorbox{border:.04em solid;box-sizing:border-box}.katex .cancel-pad{padding:0 .2em}.katex .cancel-lap{margin-left:-.2em;margin-right:-.2em}.katex .katex-sout{border-bottom-style:solid;border-bottom-width:.08em}.katex .angl{border-right:.049em solid;border-top:.049em solid;box-sizing:border-box;margin-right:.03889em}.katex .anglpad{padding:0 .03889em}.katex .reflectbox{display:inline-block;transform:scaleX(-1)}.katex .eqn-num:before{content:\\\"(\\\" counter(katexEqnNo) \\\")\\\";counter-increment:katexEqnNo}.katex .mml-eqn-num:before{content:\\\"(\\\" counter(mmlEqnNo) \\\")\\\";counter-increment:mmlEqnNo}.katex .mtr-glue{width:50%}.katex .cd-vert-arrow{display:inline-block;position:relative}.katex .cd-label-left{display:inline-block;position:absolute;right:calc(50% + .3em);text-align:left}.katex .cd-label-right{display:inline-block;left:calc(50% + .3em);position:absolute;text-align:right}.katex-display{display:block;margin:1em 0;text-align:center}.katex-display>.katex{display:block;text-align:center;white-space:nowrap}.katex-display>.katex>.katex-html{display:block;position:relative}.katex-display>.katex>.katex-html>.katex-tag{position:absolute;right:0}.katex-display.leqno>.katex>.katex-html>.katex-tag{left:0;right:auto}.katex-display.fleqn>.katex{padding-left:2em;text-align:left}body{counter-reset:katexEqnNo mmlEqnNo}\\n\";\n","/**\n * Plain text with math → safe HTML: THE one way a printer turns authored text\n * (a flashcard face, an exam prompt, a glossary definition) into markup.\n *\n * Every non-markdown printer used to `escapeHtml()` its text, so `\\(\\text{IO}_3^-\\)`\n * on a flashcard printed as that literal source (Arman, 2026-09-27). What is math\n * is decided by the shared tokenizer (`extractMath` — the same rule the screen,\n * the markdown lane and the /document pipeline use: code and `$5` prices are\n * never math); everything else is escaped exactly as before.\n *\n * Typeset output is KaTeX's laid-out HTML plus MathML, chemistry (mhchem)\n * loaded. KaTeX runs with `trust: false`, which refuses every command that could\n * inject HTML (\\href, \\url, \\htmlClass, \\htmlId, \\htmlStyle, \\htmlData,\n * \\includegraphics). The stylesheet is added by `openPrintWindow` whenever a\n * document contains math, so no printer can forget it.\n */\nimport katex from \"katex\";\n// Registers \\ce{…} and \\pu{…} on the same katex instance.\nimport \"katex/contrib/mhchem\";\nimport { escapeHtml } from \"@ai-matrx/kit/html-escape\";\nimport { extractMath, MATH_TOKEN_RE } from \"./document/math\";\n\n/** Typeset one TeX span — the ONE KaTeX configuration every print lane uses. */\nexport function typesetTex(tex: string, display: boolean): string {\n return katex.renderToString(tex, {\n displayMode: display,\n output: \"htmlAndMathml\",\n throwOnError: false,\n trust: false,\n strict: \"ignore\",\n });\n}\n\n/**\n * Escape `text` for HTML, with every math span typeset. Newlines are kept as\n * `\\n` in the prose so callers that turn them into `<br>` keep doing so; a\n * newline inside a formula is folded to a space (TeX treats it as one).\n */\nexport function mathTextHtml(text: string | null | undefined): string {\n // The tokenizer's own markers can never come from an author.\n const source = (text ?? \"\").replace(/[\\uE100\\uE101]/g, \"\");\n if (!/[$\\\\]/.test(source)) return escapeHtml(source);\n const { text: prose, spans } = extractMath(source);\n if (spans.length === 0) return escapeHtml(source);\n return escapeHtml(prose).replace(MATH_TOKEN_RE, (_m: string, i: string) => {\n const span = spans[Number(i)];\n return span ? typesetTex(span.tex.replace(/\\s*\\n\\s*/g, \" \"), span.display) : \"\";\n });\n}\n\n/**\n * A field that IS a formula (a cheat-sheet \"formula\" slot): delimited math is\n * typeset as usual; undelimited TeX (it has a command, `^` or `_`) is typeset\n * whole as inline math; anything else is escaped text.\n */\nexport function formulaHtml(formula: string | null | undefined): string {\n const source = (formula ?? \"\").trim();\n const withMath = mathTextHtml(source);\n if (withMath.includes('class=\"katex\"')) return withMath;\n return /\\\\[a-zA-Z]|[\\^_]/.test(source) ? typesetTex(source, false) : withMath;\n}\n","/**\n * Math in documents — ONE math dialect, typeset in every format.\n *\n * What is math is decided ONLY by the shared tokenizer (`@ai-matrx/content-ir/\n * source`): its fence-nesting rule finds code, its pairing finds `$$…$$`,\n * `$…$` (math, not currency), `\\[…\\]` and `\\(…\\)`. Math is lifted out\n * BEFORE markdown parsing, so a TeX `\\,` is never eaten as a markdown escape\n * and `_`/`*` inside a formula never become emphasis.\n *\n * Typesetting: MathJax (TeX → its internal tree) produces\n * - SVG for PDF display math (drawn as vector paths; allow-list sanitized),\n * - MathML for HTML and EPUB (rendered natively by browsers and readers),\n * - MathML that the Word writer turns into native OMML equations and the\n * PDF writer turns into inline text with real super/subscripts.\n */\n\nimport { listIslands, tokenizeSource } from \"@ai-matrx/content-ir/source\";\nimport { sanitizeMathml, sanitizeMathSvg } from \"../safe-html\";\n\nexport const MATH_OPEN = \"\\uE100\";\nexport const MATH_CLOSE = \"\\uE101\";\nexport const MATH_TOKEN_RE = /\\uE100(\\d+)\\uE101/g;\n\nexport interface MathSpan {\n tex: string;\n display: boolean;\n}\n\nconst DELIMITERS: Record<string, { open: number; close: number; display: boolean }> = {\n $$: { open: 2, close: 2, display: true },\n \"\\\\[\": { open: 2, close: 2, display: true },\n $: { open: 1, close: 1, display: false },\n \"\\\\(\": { open: 2, close: 2, display: false },\n};\n\n/**\n * Replace every math span with a private-use token; returns the spans.\n *\n * Print keeps NO fence, code-span or math detection of its own: the spans are\n * the shared tokenizer's complete `math_block` / `math_inline` islands\n * (`tokenizeSource` + `listIslands` from `@ai-matrx/content-ir/source` — the\n * one fence-nesting rule and the one math pairing), so print, the renderer and\n * the editor can never disagree about what is math. The delimiter decides the\n * form: `$$`/`\\[` display, `$`/`\\(` inline.\n */\nexport function extractMath(body: string): { text: string; spans: MathSpan[] } {\n const spans: MathSpan[] = [];\n if (!/[$\\\\]/.test(body)) return { text: body, spans };\n const islands = listIslands(tokenizeSource(body))\n .filter((isl) => isl.complete && (isl.islandType === \"math_block\" || isl.islandType === \"math_inline\"))\n .sort((a, b) => a.start - b.start);\n let out = \"\";\n let at = 0;\n for (const isl of islands) {\n const d = DELIMITERS[String(isl.meta.delimiter ?? \"\")];\n if (!d || isl.start < at) continue;\n out += body.slice(at, isl.start);\n spans.push({ tex: body.slice(isl.start + d.open, isl.end - d.close).trim(), display: d.display });\n out += `${MATH_OPEN}${spans.length - 1}${MATH_CLOSE}`;\n at = isl.end;\n }\n return { text: out + body.slice(at), spans };\n}\n\n// ── typesetting ────────────────────────────────────────────────────────────\n\nexport interface TypesetMath {\n /** MathML (<math …>…</math>) for HTML/EPUB and the Word/PDF-inline writers. */\n mathml: string;\n /** SVG for PDF display math; widths in ex (1ex ≈ 0.442em in MathJax). */\n svg?: string | undefined;\n widthEx?: number | undefined;\n heightEx?: number | undefined;\n /** Error message when the TeX could not be typeset. */\n error?: string | undefined;\n}\n\nexport const mathKey = (tex: string, display: boolean): string => `${display ? \"D\" : \"I\"}:${tex}`;\n\ntype MathJaxKit = {\n svg: (tex: string, display: boolean) => string;\n mml: (tex: string, display: boolean) => string;\n};\n\nconst MATHJAX = Symbol.for(\"ai-matrx.print.document.mathjax\");\n\nasync function loadMathJax(): Promise<MathJaxKit> {\n const g = globalThis as unknown as Record<symbol, Promise<MathJaxKit> | undefined>;\n if (g[MATHJAX]) return g[MATHJAX] as Promise<MathJaxKit>;\n g[MATHJAX] = (async () => {\n const [{ mathjax }, { TeX }, { SVG }, { liteAdaptor }, { RegisterHTMLHandler }, { AllPackages }, { SerializedMmlVisitor }, { STATE }] =\n await Promise.all([\n import(\"mathjax-full/js/mathjax.js\"),\n import(\"mathjax-full/js/input/tex.js\"),\n import(\"mathjax-full/js/output/svg.js\"),\n import(\"mathjax-full/js/adaptors/liteAdaptor.js\"),\n import(\"mathjax-full/js/handlers/html.js\"),\n import(\"mathjax-full/js/input/tex/AllPackages.js\"),\n import(\"mathjax-full/js/core/MmlTree/SerializedMmlVisitor.js\"),\n import(\"mathjax-full/js/core/MathItem.js\"),\n ]);\n const adaptor = liteAdaptor();\n RegisterHTMLHandler(adaptor);\n const doc = mathjax.document(\"\", {\n InputJax: new TeX({ packages: AllPackages }),\n OutputJax: new SVG({ fontCache: \"none\" }),\n });\n const visitor = new SerializedMmlVisitor();\n return {\n svg: (tex, display) => adaptor.innerHTML(doc.convert(tex, { display }) as never),\n mml: (tex, display) => visitor.visitTree(doc.convert(tex, { display, end: STATE.CONVERT }) as never),\n };\n })();\n return g[MATHJAX] as Promise<MathJaxKit>;\n}\n\n/** Typeset every math span once; keyed by `mathKey`. */\nexport async function typesetMathSpans(spans: MathSpan[]): Promise<Map<string, TypesetMath>> {\n const out = new Map<string, TypesetMath>();\n if (spans.length === 0) return out;\n const mj = await loadMathJax();\n for (const s of spans) {\n const key = mathKey(s.tex, s.display);\n if (out.has(key)) continue;\n try {\n const mathml = mj.mml(s.tex, s.display);\n const err = /<merror[\\s\\S]*?<mtext[^>]*>([\\s\\S]*?)<\\/mtext>/.exec(mathml);\n if (err) {\n out.set(key, { mathml: sanitizeMathml(mathml), error: decodeXml(err[1] as string) });\n continue;\n }\n // TeX is author input: `\\href`, `\\style`, `\\bbox[…]`, `\\mmlToken` reach\n // MathML attributes, so the typeset MathML goes through the allow-list.\n const entry: TypesetMath = { mathml: sanitizeMathml(mathml.replace(/\\n\\s*/g, \"\")) };\n if (s.display) {\n // The same author TeX reaches the SVG as <a href>, style, class and id\n // (LIST T26): only the drawing survives.\n const svg = sanitizeMathSvg(mj.svg(s.tex, true));\n entry.svg = svg;\n entry.widthEx = Number(/width=\"([\\d.]+)ex\"/.exec(svg)?.[1] ?? 0);\n entry.heightEx = Number(/height=\"([\\d.]+)ex\"/.exec(svg)?.[1] ?? 0);\n }\n out.set(key, entry);\n } catch (e) {\n out.set(key, { mathml: \"\", error: (e as Error).message });\n }\n }\n return out;\n}\n\n// ── a small MathML reader (MathJax's serializer output is well-formed XML) ──\n\nexport interface MNode {\n tag: string;\n attrs: Record<string, string>;\n children: MNode[];\n text: string;\n}\n\nexport function decodeXml(s: string): string {\n return s.replace(/&(#x[0-9a-f]+|#\\d+|amp|lt|gt|quot|apos);/gi, (m, e: string) => {\n if (e[0] === \"#\") return String.fromCodePoint(e[1] === \"x\" || e[1] === \"X\" ? parseInt(e.slice(2), 16) : Number(e.slice(1)));\n return ({ amp: \"&\", lt: \"<\", gt: \">\", quot: '\"', apos: \"'\" } as Record<string, string>)[e.toLowerCase()] ?? m;\n });\n}\n\nexport function parseMathML(xml: string): MNode {\n const root: MNode = { tag: \"#root\", attrs: {}, children: [], text: \"\" };\n const stack: MNode[] = [root];\n for (const m of xml.matchAll(/<(\\/?)([\\w:-]+)((?:\\s+[\\w:-]+=\"[^\"]*\")*)\\s*(\\/?)>|([^<]+)/g)) {\n const top = stack[stack.length - 1] as MNode;\n if (m[5] !== undefined) {\n const t = decodeXml(m[5]);\n if (t.trim() || top.tag === \"mtext\" || top.tag === \"mo\") top.text += t;\n continue;\n }\n if (m[1] === \"/\") {\n if (stack.length > 1) stack.pop();\n continue;\n }\n const attrs: Record<string, string> = {};\n for (const a of (m[3] ?? \"\").matchAll(/([\\w:-]+)=\"([^\"]*)\"/g)) attrs[a[1] as string] = decodeXml(a[2] as string);\n const node: MNode = { tag: (m[2] as string).replace(/^m:/, \"\"), attrs, children: [], text: \"\" };\n top.children.push(node);\n if (m[4] !== \"/\") stack.push(node);\n }\n return root.children[0] ?? root;\n}\n\n/** Flatten to plain text (the linear reading of a formula). */\nexport function m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,UAAM,QAAQ,SAAS,MAAM,YAAY,QAAQ;AAEjD,UAAM,WAAW,WAAW,MAAM,UAAU;AAC5C,UAAM,OAAO,oBAAoB,EAAE,OAAO,UAAU,MAAM,GAAG,SAAS;AAAA,MACpE,cAAc,YAAY,aAAa,gBAAgB,IAAI;AAAA,MAC3D,gBAAgB,YAAY,aAAa,kBAAkB,IAAI;AAAA,IACjE,CAAC;AAED,WAAO;AAAA,MACL,mBAAmB,MAAM,OAAO,MAAM;AAAA,MACtC;AAAA,IACF;AAAA,EACF;AACF;","names":["import_html_escape","katex","import_html_escape"]}
package/dist/education.js CHANGED
@@ -121,6 +121,17 @@ function openPrintWindowFallback(htmlDocument, filename) {
121
121
  downloadFile(`${filename.replace(/\s+/g, "-").toLowerCase()}.html`, htmlDocument, "text/html;charset=utf-8");
122
122
  return "downloaded";
123
123
  }
124
+ var PRINT_CHROME_SELECTOR = [
125
+ "[data-print-hide]",
126
+ '[role="toolbar"]',
127
+ '[role="menu"]',
128
+ '[role="menubar"]',
129
+ "button",
130
+ '[role="button"]',
131
+ 'input[type="button"]',
132
+ 'input[type="submit"]',
133
+ 'input[type="reset"]'
134
+ ].join(",");
124
135
 
125
136
  // src/math-text.ts
126
137
  import katex from "katex";