@bendyline/squisq-formats 1.4.1 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +48 -2
- package/dist/{chunk-WWBIKRNP.js → chunk-2CSZJEAL.js} +13 -11
- package/dist/chunk-2CSZJEAL.js.map +1 -0
- package/dist/{chunk-RTS5XBZ7.js → chunk-2EFDWKC6.js} +262 -84
- package/dist/chunk-2EFDWKC6.js.map +1 -0
- package/dist/chunk-2PRVLAU3.js +740 -0
- package/dist/chunk-2PRVLAU3.js.map +1 -0
- package/dist/{chunk-SHLPSADL.js → chunk-4HJ6AK2Q.js} +54 -193
- package/dist/chunk-4HJ6AK2Q.js.map +1 -0
- package/dist/{chunk-5LSSWZPU.js → chunk-4VUWTSGM.js} +72 -25
- package/dist/chunk-4VUWTSGM.js.map +1 -0
- package/dist/{chunk-YESS7VY3.js → chunk-CVNVD7VH.js} +154 -39
- package/dist/chunk-CVNVD7VH.js.map +1 -0
- package/dist/chunk-CX3LH47J.js +99 -0
- package/dist/chunk-CX3LH47J.js.map +1 -0
- package/dist/{chunk-D7IFPWNZ.js → chunk-GVS2XXV6.js} +27 -26
- package/dist/chunk-GVS2XXV6.js.map +1 -0
- package/dist/chunk-H7T5DXUU.js +479 -0
- package/dist/chunk-H7T5DXUU.js.map +1 -0
- package/dist/{chunk-EHLGMSTE.js → chunk-HBSCRS5P.js} +10 -8
- package/dist/chunk-HBSCRS5P.js.map +1 -0
- package/dist/{chunk-46FMDOWZ.js → chunk-LXYLOOST.js} +49 -17
- package/dist/chunk-LXYLOOST.js.map +1 -0
- package/dist/{chunk-MJGRI6XR.js → chunk-MLX2BOJC.js} +12 -7
- package/dist/chunk-MLX2BOJC.js.map +1 -0
- package/dist/chunk-NKAJPJ4G.js +106 -0
- package/dist/chunk-NKAJPJ4G.js.map +1 -0
- package/dist/{chunk-DQAZR57U.js → chunk-O3GVVND4.js} +1 -1
- package/dist/chunk-ODL3SSPT.js +18 -0
- package/dist/chunk-ODL3SSPT.js.map +1 -0
- package/dist/chunk-X4USWOQ2.js +131 -0
- package/dist/chunk-X4USWOQ2.js.map +1 -0
- package/dist/chunk-XTLQXR4U.js +195 -0
- package/dist/chunk-XTLQXR4U.js.map +1 -0
- package/dist/chunk-YRT7GQ5Y.js +28 -0
- package/dist/chunk-YRT7GQ5Y.js.map +1 -0
- package/dist/chunk-ZZ7D4DN6.js +97 -0
- package/dist/chunk-ZZ7D4DN6.js.map +1 -0
- package/dist/container/index.d.ts +6 -2
- package/dist/container/index.js +15 -17
- package/dist/container/index.js.map +1 -1
- package/dist/docx/index.d.ts +6 -2
- package/dist/docx/index.js +5 -3
- package/dist/epub/index.d.ts +3 -1
- package/dist/epub/index.js +3 -3
- package/dist/export-Djev9BLU.d.ts +69 -0
- package/dist/extract-LNOA7DBK.js +15 -0
- package/dist/extract-LNOA7DBK.js.map +1 -0
- package/dist/html/index.d.ts +15 -85
- package/dist/html/index.js +3 -3
- package/dist/images-7FBWPKE3.js +7 -0
- package/dist/images-7FBWPKE3.js.map +1 -0
- package/dist/import-DTkDxHmZ.d.ts +84 -0
- package/dist/import-Yivc3kZM.d.ts +136 -0
- package/dist/index.d.ts +13 -4
- package/dist/index.js +30 -11
- package/dist/infer/index.d.ts +138 -0
- package/dist/infer/index.js +28 -0
- package/dist/infer/index.js.map +1 -0
- package/dist/layouts-7OUUVAGU.js +12 -0
- package/dist/layouts-7OUUVAGU.js.map +1 -0
- package/dist/layouts-CZ0bdsNL.d.ts +150 -0
- package/dist/mapTheme-IR27S6IV.js +11 -0
- package/dist/mapTheme-IR27S6IV.js.map +1 -0
- package/dist/ooxml/index.d.ts +21 -127
- package/dist/ooxml/index.js +31 -9
- package/dist/pdf/index.d.ts +3 -1
- package/dist/pdf/index.js +1 -1
- package/dist/pptx/index.d.ts +8 -108
- package/dist/pptx/index.js +13 -4
- package/dist/reader-Gof6OrJX.d.ts +140 -0
- package/dist/registry/index.d.ts +46 -8
- package/dist/registry/index.js +5 -2
- package/dist/themeReader-DPw4J5Ss.d.ts +56 -0
- package/dist/xlsx/index.d.ts +6 -66
- package/dist/xlsx/index.js +4 -2
- package/dist/zipLimits-bGYMS9cI.d.ts +29 -0
- package/package.json +8 -2
- package/src/__tests__/container.test.ts +41 -0
- package/src/__tests__/convert.test.ts +167 -0
- package/src/__tests__/epub.test.ts +102 -1
- package/src/__tests__/html.test.ts +62 -0
- package/src/__tests__/inferTheme.test.ts +135 -0
- package/src/__tests__/lossyWarnings.test.ts +41 -0
- package/src/__tests__/ooxml.test.ts +59 -2
- package/src/__tests__/ooxmlThemeReader.test.ts +92 -0
- package/src/__tests__/plainHtml.test.ts +15 -1
- package/src/__tests__/plainHtmlBundle.test.ts +18 -0
- package/src/__tests__/pptxImport.test.ts +30 -0
- package/src/__tests__/pptxInferFixtures.ts +314 -0
- package/src/__tests__/pptxLayoutInfer.test.ts +395 -0
- package/src/__tests__/zipSafety.test.ts +317 -0
- package/src/container/index.ts +20 -29
- package/src/docx/export.ts +4 -2
- package/src/docx/import.ts +4 -3
- package/src/epub/export.ts +94 -25
- package/src/html/docsHtmlBundle.ts +6 -2
- package/src/html/htmlTemplate.ts +31 -6
- package/src/html/imageUtils.ts +14 -5
- package/src/html/index.ts +12 -1
- package/src/html/plainHtml.ts +7 -3
- package/src/html/plainHtmlBundle.ts +11 -9
- package/src/index.ts +20 -0
- package/src/infer/extract.ts +127 -0
- package/src/infer/index.ts +168 -0
- package/src/infer/mapTheme.ts +176 -0
- package/src/infer/types.ts +27 -0
- package/src/ooxml/index.ts +14 -0
- package/src/ooxml/readUtils.ts +44 -0
- package/src/ooxml/reader.ts +87 -28
- package/src/ooxml/themeReader.ts +197 -0
- package/src/ooxml/types.ts +8 -9
- package/src/ooxml/writer.ts +28 -10
- package/src/pdf/export.ts +4 -2
- package/src/pdf/import.ts +40 -34
- package/src/pptx/export.ts +4 -2
- package/src/pptx/import.ts +214 -32
- package/src/pptx/index.ts +14 -0
- package/src/pptx/layouts.ts +1168 -0
- package/src/registry/convert.ts +54 -23
- package/src/registry/defaultFormats.ts +131 -44
- package/src/registry/index.ts +3 -0
- package/src/registry/types.ts +52 -6
- package/src/shared/boundedZipArchive.ts +342 -0
- package/src/shared/fidelity.ts +130 -0
- package/src/shared/zipEntryCount.ts +97 -0
- package/src/shared/zipLimits.ts +286 -0
- package/src/shared/zipSafety.ts +19 -0
- package/src/xlsx/import.ts +3 -2
- package/dist/chunk-46FMDOWZ.js.map +0 -1
- package/dist/chunk-5LSSWZPU.js.map +0 -1
- package/dist/chunk-D7IFPWNZ.js.map +0 -1
- package/dist/chunk-EHLGMSTE.js.map +0 -1
- package/dist/chunk-MJGRI6XR.js.map +0 -1
- package/dist/chunk-RTS5XBZ7.js.map +0 -1
- package/dist/chunk-SHLPSADL.js.map +0 -1
- package/dist/chunk-WWBIKRNP.js.map +0 -1
- package/dist/chunk-YESS7VY3.js.map +0 -1
- /package/dist/{chunk-DQAZR57U.js.map → chunk-O3GVVND4.js.map} +0 -0
|
@@ -2,12 +2,13 @@ import {
|
|
|
2
2
|
arrayBufferToBase64DataUrl,
|
|
3
3
|
extractFilename,
|
|
4
4
|
inferMimeType
|
|
5
|
-
} from "./chunk-
|
|
5
|
+
} from "./chunk-MLX2BOJC.js";
|
|
6
6
|
|
|
7
7
|
// src/html/index.ts
|
|
8
8
|
import JSZip3 from "jszip";
|
|
9
9
|
|
|
10
10
|
// src/html/htmlTemplate.ts
|
|
11
|
+
import { readFrontmatterThemeId } from "@bendyline/squisq/markdown";
|
|
11
12
|
function collectImagePaths(doc) {
|
|
12
13
|
const paths = /* @__PURE__ */ new Set();
|
|
13
14
|
function addIfRelative(src) {
|
|
@@ -127,11 +128,10 @@ function generateInlineHtml(doc, options) {
|
|
|
127
128
|
mode = "slideshow",
|
|
128
129
|
title = "Squisq Document",
|
|
129
130
|
autoPlay = false,
|
|
130
|
-
themeId
|
|
131
|
+
themeId,
|
|
132
|
+
themeRegistry
|
|
131
133
|
} = options;
|
|
132
|
-
|
|
133
|
-
doc = { ...doc, themeId };
|
|
134
|
-
}
|
|
134
|
+
doc = applyThemeSelection(doc, themeId, themeRegistry);
|
|
135
135
|
const imageMap = {};
|
|
136
136
|
if (images) {
|
|
137
137
|
for (const [path, buffer] of images.entries()) {
|
|
@@ -179,8 +179,11 @@ function generateExternalHtml(doc, options) {
|
|
|
179
179
|
audioPathMap,
|
|
180
180
|
mode = "slideshow",
|
|
181
181
|
title = "Squisq Document",
|
|
182
|
-
autoPlay = false
|
|
182
|
+
autoPlay = false,
|
|
183
|
+
themeId,
|
|
184
|
+
themeRegistry
|
|
183
185
|
} = options;
|
|
186
|
+
doc = applyThemeSelection(doc, themeId, themeRegistry);
|
|
184
187
|
const docJson = escapeForScript(JSON.stringify(doc));
|
|
185
188
|
const imageMapJson = imagePathMap ? escapeForScript(JSON.stringify(imagePathMap)) : "{}";
|
|
186
189
|
const audioMapJson = audioPathMap ? escapeForScript(JSON.stringify(audioPathMap)) : "null";
|
|
@@ -217,6 +220,21 @@ ${mode === "static" ? "#squisq-root{align-items:flex-start;overflow-y:auto;backg
|
|
|
217
220
|
</body>
|
|
218
221
|
</html>`;
|
|
219
222
|
}
|
|
223
|
+
function applyThemeSelection(doc, themeId, registry) {
|
|
224
|
+
const selectedId = themeId ?? doc.themeId ?? readFrontmatterThemeId(doc.frontmatter);
|
|
225
|
+
if (!selectedId) return doc;
|
|
226
|
+
const selectedDocTheme = doc.customThemes?.some((theme) => theme.id === selectedId);
|
|
227
|
+
if (selectedDocTheme || !registry) {
|
|
228
|
+
return selectedId === doc.themeId ? doc : { ...doc, themeId: selectedId };
|
|
229
|
+
}
|
|
230
|
+
const registered = registry.get(selectedId);
|
|
231
|
+
if (!registered) return selectedId === doc.themeId ? doc : { ...doc, themeId: selectedId };
|
|
232
|
+
return {
|
|
233
|
+
...doc,
|
|
234
|
+
themeId: selectedId,
|
|
235
|
+
customThemes: [...doc.customThemes ?? [], registered]
|
|
236
|
+
};
|
|
237
|
+
}
|
|
220
238
|
function escapeHtml(str) {
|
|
221
239
|
return str.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """).replace(/'/g, "'");
|
|
222
240
|
}
|
|
@@ -225,14 +243,14 @@ function escapeHtml(str) {
|
|
|
225
243
|
import {
|
|
226
244
|
sanitizeHtmlNodes,
|
|
227
245
|
sanitizeUrl,
|
|
228
|
-
readFrontmatterThemeId
|
|
246
|
+
readFrontmatterThemeId as readFrontmatterThemeId2
|
|
229
247
|
} from "@bendyline/squisq/markdown";
|
|
230
248
|
import { resolveFontFamily, buildGoogleFontsUrl } from "@bendyline/squisq/schemas";
|
|
231
249
|
import { resolveThemeForDoc } from "@bendyline/squisq/doc";
|
|
232
250
|
function markdownDocToPlainHtml(doc, options = {}) {
|
|
233
251
|
const { title = "Document", images, links, themeId, iconsCss, htmlPolicy = "sanitize" } = options;
|
|
234
|
-
const resolveId = themeId ??
|
|
235
|
-
const theme = options.theme ?? (resolveId ? resolveThemeForDoc(doc, resolveId) : void 0);
|
|
252
|
+
const resolveId = themeId ?? readFrontmatterThemeId2(doc.frontmatter);
|
|
253
|
+
const theme = options.theme ?? (resolveId ? resolveThemeForDoc(doc, resolveId, options.themeRegistry) : void 0);
|
|
236
254
|
const ctx = { images, links, htmlPolicy };
|
|
237
255
|
const body = renderTopLevel(doc.children, ctx);
|
|
238
256
|
const fontsLink = theme ? renderFontsLink(theme) : "";
|
|
@@ -731,7 +749,6 @@ function escapeAttr(s) {
|
|
|
731
749
|
// src/html/plainHtmlBundle.ts
|
|
732
750
|
import JSZip from "jszip";
|
|
733
751
|
import { parseMarkdown, inferDocumentTitle } from "@bendyline/squisq/markdown";
|
|
734
|
-
import { resolveTheme } from "@bendyline/squisq/schemas";
|
|
735
752
|
async function markdownDocsToPlainHtmlBundle(options) {
|
|
736
753
|
const {
|
|
737
754
|
entryPath,
|
|
@@ -740,10 +757,10 @@ async function markdownDocsToPlainHtmlBundle(options) {
|
|
|
740
757
|
title,
|
|
741
758
|
theme,
|
|
742
759
|
themeId,
|
|
760
|
+
themeRegistry,
|
|
743
761
|
maxDepth = Infinity,
|
|
744
762
|
entryAsIndex = false
|
|
745
763
|
} = options;
|
|
746
|
-
const resolvedTheme = theme ?? (themeId ? resolveTheme(themeId) : void 0);
|
|
747
764
|
const entry = normalizePath(entryPath);
|
|
748
765
|
if (!entry) {
|
|
749
766
|
throw new Error("markdownDocsToPlainHtmlBundle: entryPath is required");
|
|
@@ -794,7 +811,9 @@ async function markdownDocsToPlainHtmlBundle(options) {
|
|
|
794
811
|
title: docTitle ?? titleForFilename(path, mdDoc),
|
|
795
812
|
images: imageRewriteMap,
|
|
796
813
|
links: linkMap,
|
|
797
|
-
theme
|
|
814
|
+
theme,
|
|
815
|
+
themeId,
|
|
816
|
+
themeRegistry
|
|
798
817
|
});
|
|
799
818
|
const htmlPath = htmlPathFor(path);
|
|
800
819
|
zip.file(htmlPath, html);
|
|
@@ -954,6 +973,7 @@ async function markdownDocsToHtmlBundle(options) {
|
|
|
954
973
|
playerScript,
|
|
955
974
|
title,
|
|
956
975
|
themeId,
|
|
976
|
+
themeRegistry,
|
|
957
977
|
mode = "static",
|
|
958
978
|
maxDepth = Infinity,
|
|
959
979
|
entryAsIndex = false
|
|
@@ -1008,7 +1028,6 @@ async function markdownDocsToHtmlBundle(options) {
|
|
|
1008
1028
|
imageRewriteMap.set(authored, relativeFrom(docDir, resolvedImg));
|
|
1009
1029
|
}
|
|
1010
1030
|
let doc = markdownToDoc(mdDoc);
|
|
1011
|
-
if (themeId) doc = { ...doc, themeId };
|
|
1012
1031
|
if (linkMap.size > 0) {
|
|
1013
1032
|
doc = rewriteDocLinks(doc, linkMap);
|
|
1014
1033
|
}
|
|
@@ -1022,7 +1041,9 @@ async function markdownDocsToHtmlBundle(options) {
|
|
|
1022
1041
|
// sources before rendering each block.
|
|
1023
1042
|
imagePathMap: imageRewriteMap.size > 0 ? Object.fromEntries(imageRewriteMap.entries()) : void 0,
|
|
1024
1043
|
mode,
|
|
1025
|
-
title: pageTitle
|
|
1044
|
+
title: pageTitle,
|
|
1045
|
+
themeId,
|
|
1046
|
+
themeRegistry
|
|
1026
1047
|
});
|
|
1027
1048
|
zip.file(htmlPath, html);
|
|
1028
1049
|
}
|
|
@@ -1380,7 +1401,16 @@ function docToHtml(doc, options) {
|
|
|
1380
1401
|
return generateInlineHtml(doc, options);
|
|
1381
1402
|
}
|
|
1382
1403
|
async function docToHtmlZip(doc, options) {
|
|
1383
|
-
const {
|
|
1404
|
+
const {
|
|
1405
|
+
playerScript,
|
|
1406
|
+
images,
|
|
1407
|
+
audio,
|
|
1408
|
+
mode = "slideshow",
|
|
1409
|
+
title,
|
|
1410
|
+
autoPlay,
|
|
1411
|
+
themeId,
|
|
1412
|
+
themeRegistry
|
|
1413
|
+
} = options;
|
|
1384
1414
|
const zip = new JSZip3();
|
|
1385
1415
|
zip.file("squisq-player.js", playerScript);
|
|
1386
1416
|
const imagePathMap = {};
|
|
@@ -1408,7 +1438,9 @@ async function docToHtmlZip(doc, options) {
|
|
|
1408
1438
|
audioPathMap: Object.keys(audioPathMap).length > 0 ? audioPathMap : void 0,
|
|
1409
1439
|
mode,
|
|
1410
1440
|
title,
|
|
1411
|
-
autoPlay
|
|
1441
|
+
autoPlay,
|
|
1442
|
+
themeId,
|
|
1443
|
+
themeRegistry
|
|
1412
1444
|
});
|
|
1413
1445
|
zip.file("index.html", html);
|
|
1414
1446
|
return zip.generateAsync({
|
|
@@ -1430,4 +1462,4 @@ export {
|
|
|
1430
1462
|
docToHtml,
|
|
1431
1463
|
docToHtmlZip
|
|
1432
1464
|
};
|
|
1433
|
-
//# sourceMappingURL=chunk-
|
|
1465
|
+
//# sourceMappingURL=chunk-LXYLOOST.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/html/index.ts","../src/html/htmlTemplate.ts","../src/html/plainHtml.ts","../src/html/plainHtmlBundle.ts","../src/html/docsHtmlBundle.ts","../src/html/import.ts"],"sourcesContent":["/**\n * HTML Export Module — @bendyline/squisq-formats/html\n *\n * Exports squisq documents as self-contained HTML files or ZIP archives.\n *\n * Two export modes:\n *\n * 1. **Single HTML** (`docToHtml`) — Everything embedded in one file:\n * - SquisqPlayer IIFE bundle inlined in `<script>`\n * - Images base64-encoded as data URIs\n * - Timer-based playback (no audio — too large for inline)\n *\n * 2. **ZIP Archive** (`docToHtmlZip`) — Multi-file package:\n * - `index.html` referencing external `squisq-player.js`\n * - `squisq-player.js` — the IIFE bundle\n * - `images/` — extracted image files\n * - `audio/` — optional audio segment files (enables full playback)\n *\n * @example\n * ```ts\n * import { PLAYER_BUNDLE } from '@bendyline/squisq-react/standalone-source';\n * import { docToHtml, docToHtmlZip } from '@bendyline/squisq-formats/html';\n *\n * // Single HTML file\n * const html = docToHtml(doc, { playerScript: PLAYER_BUNDLE, images });\n *\n * // ZIP archive\n * const zipBlob = await docToHtmlZip(doc, { playerScript: PLAYER_BUNDLE, images, audio });\n * ```\n */\n\nimport type { Doc } from '@bendyline/squisq/schemas';\nimport JSZip from 'jszip';\nimport {\n generateInlineHtml,\n generateExternalHtml,\n type HtmlExportOptions,\n} from './htmlTemplate.js';\nimport { extractFilename } from './imageUtils.js';\n\n// ── Public Types ───────────────────────────────────────────────────\n\nexport type { HtmlExportOptions };\n\n/**\n * Normalize a doc-referenced path for use as a zip entry name. Strips\n * leading slashes and rejects any path that tries to escape the archive\n * root via `..` segments (a malicious or malformed doc shouldn't be able\n * to write outside the zip when extracted). Backslashes are folded to\n * forward slashes so Windows-authored paths still produce a consistent\n * tree across extractors.\n */\nfunction sanitizeZipPath(path: string): string | null {\n const normalized = path.replace(/\\\\/g, '/').replace(/^\\/+/, '');\n if (!normalized) return null;\n if (normalized.split('/').some((seg) => seg === '..')) return null;\n return normalized;\n}\n\nexport interface HtmlZipExportOptions extends HtmlExportOptions {\n /**\n * Map of audio segment identifiers to binary audio data.\n * Keys should match the audio segment `name` or `url` fields in the Doc.\n * When provided, audio files are included in the ZIP and full playback is enabled.\n */\n audio?: Map<string, ArrayBuffer>;\n}\n\n// ── Single HTML Export ─────────────────────────────────────────────\n\n/**\n * Export a Doc as a single, self-contained HTML file.\n *\n * The player JS is embedded inline, images are base64-encoded as data URIs,\n * and playback uses a timer (no audio) for compact file size.\n *\n * @param doc - The Doc to export\n * @param options - Export options (must include `playerScript`)\n * @returns Complete HTML document as a string\n *\n * @example\n * ```ts\n * const html = docToHtml(myDoc, {\n * playerScript: PLAYER_BUNDLE,\n * images: imageMap,\n * title: 'My Document',\n * mode: 'slideshow',\n * });\n * const blob = new Blob([html], { type: 'text/html' });\n * ```\n */\nexport function docToHtml(doc: Doc, options: HtmlExportOptions): string {\n return generateInlineHtml(doc, options);\n}\n\n// ── ZIP Archive Export ─────────────────────────────────────────────\n\n/**\n * Export a Doc as a ZIP archive containing HTML, JS, images, and optionally audio.\n *\n * The archive structure:\n * ```\n * document.zip\n * ├── index.html # HTML page referencing squisq-player.js\n * ├── squisq-player.js # Standalone IIFE bundle\n * ├── images/ # Extracted image files\n * │ ├── hero.jpg\n * │ └── ...\n * └── audio/ # Optional audio segment files\n * ├── intro.mp3\n * └── ...\n * ```\n *\n * @param doc - The Doc to export\n * @param options - Export options (must include `playerScript`)\n * @returns A Promise resolving to a ZIP Blob\n *\n * @example\n * ```ts\n * const blob = await docToHtmlZip(myDoc, {\n * playerScript: PLAYER_BUNDLE,\n * images: imageMap,\n * audio: audioMap,\n * });\n * // Trigger browser download\n * const url = URL.createObjectURL(blob);\n * ```\n */\nexport async function docToHtmlZip(doc: Doc, options: HtmlZipExportOptions): Promise<Blob> {\n const {\n playerScript,\n images,\n audio,\n mode = 'slideshow',\n title,\n autoPlay,\n themeId,\n themeRegistry,\n } = options;\n\n const zip = new JSZip();\n\n // 1. Add player JS as a separate file\n zip.file('squisq-player.js', playerScript);\n\n // 2. Add images preserving their original relative paths.\n //\n // We used to flatten everything into `images/<basename>`, but that\n // requires the player to rewrite every `<img src>` at render time using\n // the path map — and the static (non-slideshow) renderer doesn't do\n // that, so its emitted `<img>` tags 404'd against the renamed assets.\n // Keeping the original layout means direct `src=\"folder/file.png\"`\n // references just work, and the exported zip mirrors how the source\n // folder is organized (e.g. pandoc-style `notes_files/` sidecars).\n const imagePathMap: Record<string, string> = {};\n if (images) {\n for (const [originalPath, buffer] of images.entries()) {\n const zipPath = sanitizeZipPath(originalPath);\n if (!zipPath) continue;\n zip.file(zipPath, buffer);\n imagePathMap[originalPath] = zipPath;\n }\n }\n\n // 3. Add audio to audio/ folder and build path mapping\n const audioPathMap: Record<string, string> = {};\n if (audio) {\n for (const [segmentKey, buffer] of audio.entries()) {\n const filename = extractFilename(segmentKey);\n // Ensure .mp3 extension\n const finalName = filename.includes('.') ? filename : `${filename}.mp3`;\n const zipPath = `audio/${finalName}`;\n zip.file(zipPath, buffer);\n audioPathMap[segmentKey] = zipPath;\n }\n }\n\n // 4. Generate HTML that references external files\n const html = generateExternalHtml(doc, {\n playerScriptPath: 'squisq-player.js',\n imagePathMap: Object.keys(imagePathMap).length > 0 ? imagePathMap : undefined,\n audioPathMap: Object.keys(audioPathMap).length > 0 ? audioPathMap : undefined,\n mode,\n title,\n autoPlay,\n themeId,\n themeRegistry,\n });\n zip.file('index.html', html);\n\n // 5. Generate ZIP blob\n return zip.generateAsync({\n type: 'blob',\n compression: 'DEFLATE',\n compressionOptions: { level: 6 },\n });\n}\n\n// ── Re-exports ─────────────────────────────────────────────────────\n\nexport { collectImagePaths } from './htmlTemplate.js';\nexport { inferMimeType, arrayBufferToBase64DataUrl, extractFilename } from './imageUtils.js';\nexport { markdownDocToPlainHtml } from './plainHtml.js';\nexport type { PlainHtmlExportOptions } from './plainHtml.js';\nexport { markdownDocsToPlainHtmlBundle, collectLinkRefs } from './plainHtmlBundle.js';\nexport type { PlainHtmlBundleOptions } from './plainHtmlBundle.js';\nexport { markdownDocsToHtmlBundle } from './docsHtmlBundle.js';\nexport type { HtmlBundleOptions } from './docsHtmlBundle.js';\n\n// ── Import (HTML → MarkdownDocument) ────────────────────────────────\nexport { htmlToMarkdown, htmlToMarkdownDoc, htmlToMarkdownDocSync } from './import.js';\nexport type { HtmlImportOptions } from './import.js';\n","/**\n * HTML Template Generation for SquisqPlayer Exports\n *\n * Generates complete, self-contained HTML documents that load the SquisqPlayer\n * IIFE bundle and render a Doc as either an interactive slideshow or a static\n * scrollable document.\n *\n * Two variants:\n * 1. **Inline** — All JS, CSS, and images are embedded in the HTML (single file).\n * 2. **External** — JS is referenced via `<script src>`, images via relative paths.\n */\n\nimport type { Doc, Layer, Block, ThemeRegistry } from '@bendyline/squisq/schemas';\nimport { readFrontmatterThemeId } from '@bendyline/squisq/markdown';\nimport { arrayBufferToBase64DataUrl, inferMimeType } from './imageUtils.js';\n\n// ── Types ──────────────────────────────────────────────────────────\n\nexport interface HtmlExportOptions {\n /** The IIFE player bundle source code (from @bendyline/squisq-react/standalone-source) */\n playerScript: string;\n\n /**\n * Map of relative image paths (as they appear in the Doc) to binary image data.\n * For inline HTML export, these are converted to base64 data URIs.\n * For ZIP export, these are written as separate files.\n */\n images?: Map<string, ArrayBuffer>;\n\n /**\n * Map of audio segment identifiers to binary audio data.\n * Keys should match the audio segment `name` or `url` fields in the Doc.\n * Only used in ZIP exports — single HTML uses timer-based playback.\n */\n audio?: Map<string, ArrayBuffer>;\n\n /** Rendering mode: 'slideshow' (interactive, default) or 'static' (scrollable) */\n mode?: 'slideshow' | 'static';\n\n /** HTML page title (default: 'Squisq Document') */\n title?: string;\n\n /** Auto-play slideshow on load (default: false) */\n autoPlay?: boolean;\n\n /**\n * Squisq theme ID to apply (e.g., 'documentary', 'cinematic').\n * When set, the theme is assigned to the Doc before rendering,\n * so the SquisqPlayer renders with that theme's colors and typography.\n */\n themeId?: string;\n /** Explicit caller-owned registry for non-document custom themes. */\n themeRegistry?: ThemeRegistry;\n}\n\n// ── Image Path Collection ──────────────────────────────────────────\n\n/**\n * Collect all relative image paths referenced in a Doc's layers and template blocks.\n * Returns a Set of unique relative paths that need to be resolved.\n */\nexport function collectImagePaths(doc: Doc): Set<string> {\n const paths = new Set<string>();\n\n function addIfRelative(src: string | undefined) {\n if (\n !src ||\n src.startsWith('data:') ||\n src.startsWith('blob:') ||\n src.startsWith('http://') ||\n src.startsWith('https://')\n ) {\n return;\n }\n paths.add(src);\n }\n\n function scanLayers(layers: Layer[] | undefined) {\n if (!layers) return;\n for (const layer of layers) {\n if (layer.type === 'image') addIfRelative(layer.content.src);\n if (layer.type === 'video') {\n addIfRelative(layer.content.src);\n addIfRelative(layer.content.posterSrc);\n }\n if (layer.type === 'map') addIfRelative(layer.content.staticSrc);\n }\n }\n\n function scanBlock(block: Block) {\n scanLayers(block.layers);\n if (block.contents) scanMarkdownNodes(block.contents, addIfRelative);\n if (block.children) block.children.forEach(scanBlock);\n }\n\n // Scan all blocks\n doc.blocks.forEach(scanBlock);\n\n // Scan start block hero\n if (doc.startBlock?.heroSrc) addIfRelative(doc.startBlock.heroSrc);\n\n // Scan persistent layers\n if (doc.persistentLayers) {\n for (const pl of doc.persistentLayers.bottomLayers ?? []) {\n if ('src' in pl && typeof pl.src === 'string') addIfRelative(pl.src);\n }\n for (const pl of doc.persistentLayers.topLayers ?? []) {\n if ('src' in pl && typeof pl.src === 'string') addIfRelative(pl.src);\n }\n }\n\n // Scan template block fields that reference images\n for (const block of doc.blocks) {\n scanTemplateImageFields(block as unknown as Record<string, unknown>, paths);\n }\n\n return paths;\n}\n\n/**\n * Walk markdown body nodes for image references. Catches both shorthand\n * `` (type `image`, `url` field) and raw HTML `<img src>` tags\n * (type `htmlBlock`/`htmlInline`, `htmlChildren` sub-tree) — the latter is\n * how the WYSIWYG editor round-trips resized images, since markdown\n * shorthand has no width syntax.\n */\nfunction scanMarkdownNodes(nodes: unknown[], visit: (src: string | undefined) => void): void {\n for (const node of nodes) {\n if (!node || typeof node !== 'object') continue;\n const n = node as Record<string, unknown>;\n if (n.type === 'image' && typeof n.url === 'string') {\n visit(n.url);\n }\n if ((n.type === 'htmlBlock' || n.type === 'htmlInline') && Array.isArray(n.htmlChildren)) {\n scanHtmlNodes(n.htmlChildren, visit);\n }\n if (Array.isArray(n.children)) {\n scanMarkdownNodes(n.children, visit);\n }\n }\n}\n\n/** Walk a parsed HTML sub-tree for `<img>` src attributes. */\nfunction scanHtmlNodes(nodes: unknown[], visit: (src: string | undefined) => void): void {\n for (const node of nodes) {\n if (!node || typeof node !== 'object') continue;\n const n = node as Record<string, unknown>;\n if (n.type !== 'htmlElement') continue;\n if (n.tagName === 'img') {\n const attrs = n.attributes as Record<string, string> | undefined;\n if (attrs && typeof attrs.src === 'string') visit(attrs.src);\n }\n if (Array.isArray(n.children)) {\n scanHtmlNodes(n.children, visit);\n }\n }\n}\n\n/**\n * Recursively scan any object for known image-bearing field names.\n */\nfunction scanTemplateImageFields(obj: Record<string, unknown>, paths: Set<string>): void {\n if (!obj || typeof obj !== 'object') return;\n\n const imageFieldNames = [\n 'imageSrc',\n 'src',\n 'heroSrc',\n 'backgroundImage',\n 'posterSrc',\n 'staticSrc',\n 'videoSrc',\n 'thumbnailSrc',\n ];\n\n for (const key of imageFieldNames) {\n const val = obj[key];\n if (typeof val === 'string' && val && !val.startsWith('data:') && !val.startsWith('http')) {\n paths.add(val);\n }\n // Handle nested objects like { src: '...' }\n if (val && typeof val === 'object' && !Array.isArray(val)) {\n scanTemplateImageFields(val as Record<string, unknown>, paths);\n }\n }\n\n // Handle arrays (e.g., images: [{ src: '...' }])\n if (Array.isArray(obj)) {\n for (const item of obj) {\n if (item && typeof item === 'object') {\n scanTemplateImageFields(item as Record<string, unknown>, paths);\n }\n }\n }\n\n // Recurse into known array/object fields\n for (const key of ['images', 'accentImage', 'backgroundVideo', 'children', 'blocks']) {\n const val = obj[key];\n if (Array.isArray(val)) {\n for (const item of val) {\n if (item && typeof item === 'object') {\n scanTemplateImageFields(item as Record<string, unknown>, paths);\n }\n }\n } else if (val && typeof val === 'object') {\n scanTemplateImageFields(val as Record<string, unknown>, paths);\n }\n }\n}\n\n// ── HTML Generation ────────────────────────────────────────────────\n\n/**\n * Escape a string for safe embedding in a `<script>` tag.\n * Prevents `</script>` from closing the tag prematurely.\n */\nfunction escapeForScript(str: string): string {\n return str.replace(/<\\/(script)/gi, '<\\\\/$1');\n}\n\n/**\n * Generate a complete inline HTML document with all JS and images embedded.\n *\n * @param doc - The Doc to render\n * @param options - Export options\n * @returns Complete HTML string\n */\nexport function generateInlineHtml(doc: Doc, options: HtmlExportOptions): string {\n const {\n playerScript,\n images,\n mode = 'slideshow',\n title = 'Squisq Document',\n autoPlay = false,\n themeId,\n themeRegistry,\n } = options;\n\n doc = applyThemeSelection(doc, themeId, themeRegistry);\n\n // Build base64 image map\n const imageMap: Record<string, string> = {};\n if (images) {\n for (const [path, buffer] of images.entries()) {\n const mimeType = inferMimeType(path);\n imageMap[path] = arrayBufferToBase64DataUrl(buffer, mimeType);\n }\n }\n\n const docJson = escapeForScript(JSON.stringify(doc));\n const imageMapJson = escapeForScript(JSON.stringify(imageMap));\n\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*,*::before,*::after{box-sizing:border-box}\nhtml,body{margin:0;padding:0;height:100%;background:#1a1a2e;color:#e0e0e0;font-family:system-ui,-apple-system,sans-serif}\n#squisq-root{width:100%;height:100%;display:flex;align-items:center;justify-content:center}\n${mode === 'static' ? '#squisq-root{align-items:flex-start;overflow-y:auto;background:#fff;color:#1f2937}' : ''}\n</style>\n</head>\n<body>\n<div id=\"squisq-root\"></div>\n<script>${escapeForScript(playerScript)}</script>\n<script>\n(function(){\n var doc = JSON.parse(${JSON.stringify(docJson)});\n var images = JSON.parse(${JSON.stringify(imageMapJson)});\n SquisqPlayer.mount(document.getElementById(\"squisq-root\"), doc, {\n mode: ${JSON.stringify(mode)},\n images: images,\n autoPlay: ${JSON.stringify(autoPlay)},\n basePath: \".\"\n });\n})();\n</script>\n</body>\n</html>`;\n}\n\n/**\n * Generate an HTML document that references external JS and image files.\n * Used for ZIP exports where files sit alongside the HTML.\n *\n * @param doc - The Doc to render (image/audio paths should already be rewritten to relative)\n * @param options - Export options (playerScript is not embedded, referenced via src)\n * @returns Complete HTML string\n */\nexport function generateExternalHtml(\n doc: Doc,\n options: Pick<HtmlExportOptions, 'mode' | 'title' | 'autoPlay' | 'themeId' | 'themeRegistry'> & {\n /** Relative path to the player JS file (e.g., 'squisq-player.js') */\n playerScriptPath: string;\n /** Map of original image paths to their rewritten relative paths in the ZIP */\n imagePathMap?: Record<string, string>;\n /** Map of audio segment IDs to their rewritten relative paths in the ZIP */\n audioPathMap?: Record<string, string>;\n },\n): string {\n const {\n playerScriptPath,\n imagePathMap,\n audioPathMap,\n mode = 'slideshow',\n title = 'Squisq Document',\n autoPlay = false,\n themeId,\n themeRegistry,\n } = options;\n\n doc = applyThemeSelection(doc, themeId, themeRegistry);\n\n const docJson = escapeForScript(JSON.stringify(doc));\n const imageMapJson = imagePathMap ? escapeForScript(JSON.stringify(imagePathMap)) : '{}';\n const audioMapJson = audioPathMap ? escapeForScript(JSON.stringify(audioPathMap)) : 'null';\n\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*,*::before,*::after{box-sizing:border-box}\nhtml,body{margin:0;padding:0;height:100%;background:#1a1a2e;color:#e0e0e0;font-family:system-ui,-apple-system,sans-serif}\n#squisq-root{width:100%;height:100%;display:flex;align-items:center;justify-content:center}\n${mode === 'static' ? '#squisq-root{align-items:flex-start;overflow-y:auto;background:#fff;color:#1f2937}' : ''}\n</style>\n</head>\n<body>\n<div id=\"squisq-root\"></div>\n<script src=\"${escapeHtml(playerScriptPath)}\"></script>\n<script>\n(function(){\n var doc = JSON.parse(${JSON.stringify(docJson)});\n var images = JSON.parse(${JSON.stringify(imageMapJson)});\n var audio = ${audioMapJson};\n SquisqPlayer.mount(document.getElementById(\"squisq-root\"), doc, {\n mode: ${JSON.stringify(mode)},\n images: images,\n audio: audio,\n autoPlay: ${JSON.stringify(autoPlay)},\n basePath: \".\"\n });\n})();\n</script>\n</body>\n</html>`;\n}\n\nfunction applyThemeSelection(\n doc: Doc,\n themeId: string | undefined,\n registry: ThemeRegistry | undefined,\n): Doc {\n const selectedId = themeId ?? doc.themeId ?? readFrontmatterThemeId(doc.frontmatter);\n if (!selectedId) return doc;\n const selectedDocTheme = doc.customThemes?.some((theme) => theme.id === selectedId);\n if (selectedDocTheme || !registry) {\n return selectedId === doc.themeId ? doc : { ...doc, themeId: selectedId };\n }\n const registered = registry.get(selectedId);\n if (!registered) return selectedId === doc.themeId ? doc : { ...doc, themeId: selectedId };\n return {\n ...doc,\n themeId: selectedId,\n customThemes: [...(doc.customThemes ?? []), registered],\n };\n}\n\n/**\n * Escape HTML special characters to prevent injection.\n */\nfunction escapeHtml(str: string): string {\n return str\n .replace(/&/g, '&')\n .replace(/</g, '<')\n .replace(/>/g, '>')\n .replace(/\"/g, '"')\n .replace(/'/g, ''');\n}\n","/**\n * Plain HTML Export — semantic, player-free\n *\n * Renders a MarkdownDocument to a self-contained HTML string. Unlike\n * `docToHtml` (which bundles the SquisqPlayer IIFE and renders SVG block\n * cards), this output is what a reader-mode tool would produce: semantic\n * `<h1>`/`<p>`/`<ul>`/etc. with a small embedded stylesheet, no JS, no\n * runtime path-rewriting. Drives both the \"Page\" preview tab in the\n * editor and the plain-style branch of the export dialog so what users\n * see live matches the file they download.\n *\n * Image URLs default to the markdown's own paths. Pass `images` to\n * substitute a different value per source URL — typically pre-resolved\n * blob URLs (live preview) or data URIs (single-file export).\n */\n\nimport {\n sanitizeHtmlNodes,\n sanitizeUrl,\n type HtmlPolicy,\n type MarkdownDocument,\n type MarkdownNode,\n type HtmlNode,\n readFrontmatterThemeId,\n} from '@bendyline/squisq/markdown';\nimport type { Theme, ThemeRegistry } from '@bendyline/squisq/schemas';\nimport { resolveFontFamily, buildGoogleFontsUrl } from '@bendyline/squisq/schemas';\nimport { resolveThemeForDoc } from '@bendyline/squisq/doc';\n\n// ── Public Types ───────────────────────────────────────────────────\n\nexport interface PlainHtmlExportOptions {\n /** Document title — populates `<title>` and is HTML-escaped. */\n title?: string;\n /**\n * Substitution map for image `src` URLs. Keys are the URL exactly as\n * it appears in the markdown source; values are the URL to emit in\n * the rendered `<img src>`. URLs not present in the map fall through\n * unchanged (so external `https://…` references still work).\n */\n images?: Map<string, string>;\n /**\n * Substitution map for anchor `href` URLs. Keys are the URL exactly\n * as it appears in the markdown source (e.g. `'resume.md'`,\n * `'resume.md#experience'`); values are the URL to emit. URLs not in\n * the map pass through unchanged. Used by the recursive bundle\n * exporter to rewrite `.md` references to `.html` so a static export\n * of a linked document tree is internally browsable.\n */\n links?: Map<string, string>;\n /**\n * Optional Squisq theme. When provided, the rendered page uses the\n * theme's colors and typography, and any Google-hosted fonts the\n * theme references are loaded via a `<link>` to fonts.googleapis.com\n * so the face renders correctly without host preloads.\n *\n * When omitted, the function falls back (in order) to {@link themeId}\n * and then to `doc.frontmatter.themeId` — so an authored\n * `themeId: warm-earth` in the doc's frontmatter styles the export\n * automatically, without the caller having to wire theme resolution\n * themselves.\n */\n theme?: Theme;\n /**\n * Optional theme id (e.g. `'warm-earth'`, `'gezellig'`). Convenient\n * for hosts whose export dialog tracks themes by id — they can pass\n * the id straight through instead of resolving to a `Theme` object.\n * When both `theme` and `themeId` are provided, `theme` wins.\n */\n themeId?: string;\n /** Explicit caller-owned registry for non-document custom themes. */\n themeRegistry?: ThemeRegistry;\n /**\n * Optional FontAwesome CSS text to inline into the rendered page,\n * replacing the default cross-origin `<link>` to cdnjs. Required for\n * sandboxed iframe previews where tracking prevention or stricter\n * origin policies can silently drop cross-origin font fetches —\n * inlining keeps the icons resolvable purely from same-origin\n * resources. Hosts typically gather this string by scraping\n * `document.styleSheets` for `@font-face` rules whose family starts\n * with `\"Font Awesome\"`. The CDN `<link>` is only emitted when this\n * option is not provided.\n */\n iconsCss?: string;\n /**\n * Raw HTML policy. Defaults to `sanitize`, which removes unsafe tags,\n * event handlers, and executable URL schemes before emitting HTML.\n */\n htmlPolicy?: HtmlPolicy;\n}\n\n/**\n * Internal render context — bundles the substitution maps so adding a\n * new one (e.g. `links`) doesn't require threading another parameter\n * through every node renderer.\n */\ninterface RenderCtx {\n images?: Map<string, string>;\n links?: Map<string, string>;\n htmlPolicy: HtmlPolicy;\n}\n\n// ── Public API ─────────────────────────────────────────────────────\n\n/**\n * Render a parsed markdown document as a complete, semantic HTML page.\n *\n * When `options.theme` is provided, the output adopts the theme's\n * colors and typography. Google-hosted fonts referenced by the theme\n * are loaded via a single `<link>` to fonts.googleapis.com so the page\n * renders consistently when opened standalone.\n */\nexport function markdownDocToPlainHtml(\n doc: MarkdownDocument,\n options: PlainHtmlExportOptions = {},\n): string {\n const { title = 'Document', images, links, themeId, iconsCss, htmlPolicy = 'sanitize' } = options;\n // Fall back chain for theme: explicit `theme` → explicit `themeId`\n // option → doc frontmatter `themeId`. Hosts whose export dialog\n // tracks themes by id can pass `themeId` straight through; authored\n // docs with `themeId: warm-earth` in frontmatter get styled\n // automatically when neither is supplied.\n // Resolution is doc-scoped via `resolveThemeForDoc`, so an inline\n // `squisq-custom-themes` id resolves here with no global registration —\n // and `readFrontmatterThemeId` picks up the editor's canonical\n // `squisq-theme` key. Stays undefined when nothing selects a theme so\n // un-themed exports render unstyled (unchanged behavior).\n const resolveId = themeId ?? readFrontmatterThemeId(doc.frontmatter);\n const theme =\n options.theme ??\n (resolveId ? resolveThemeForDoc(doc, resolveId, options.themeRegistry) : undefined);\n const ctx: RenderCtx = { images, links, htmlPolicy };\n const body = renderTopLevel(doc.children, ctx);\n const fontsLink = theme ? renderFontsLink(theme) : '';\n // Resolve how to load FontAwesome — only when the doc actually uses\n // icons. When the host supplies `iconsCss` (typical for sandboxed\n // iframe previews where cross-origin font fetches get blocked), we\n // inline it as a `<style>` block; otherwise we fall back to the\n // public cdnjs `<link>` which works for standalone HTML files.\n const usesIcons = docUsesIcons(doc);\n let iconsLink = '';\n if (usesIcons) {\n iconsLink = iconsCss ? `<style data-fa-inline>\\n${iconsCss}\\n</style>\\n` : FONT_AWESOME_LINK;\n }\n const themedCss = theme ? renderThemedCss(theme) : DEFAULT_CSS;\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${fontsLink}${iconsLink}<style>\n${themedCss}\n${FEATURE_CSS}\n</style>\n</head>\n<body>\n${body}\n</body>\n</html>`;\n}\n\n/**\n * Hosted FontAwesome Free CSS. Pinned to a specific release so the\n * integrity hash stays in sync — bump both fields together when\n * upgrading. Cdnjs serves the matching SRI hash on every release page.\n */\nconst FONT_AWESOME_LINK = `<link rel=\"stylesheet\" href=\"https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.2/css/all.min.css\" integrity=\"sha512-SnH5WK+bZxgPHs44uWIX+LLJAJ9/2PkPKZ5QiAj6Ta86w+fsb2TkcmfRyVX3pBnMFcV7oQPJkl9QevSCWr3W6A==\" crossorigin=\"anonymous\" referrerpolicy=\"no-referrer\">\n`;\n\n/** Walk the doc looking for any `inlineIcon` node. Cheap depth-first\n * traversal — bails out at the first hit. */\nfunction docUsesIcons(doc: MarkdownDocument): boolean {\n function visit(node: unknown): boolean {\n if (!node || typeof node !== 'object') return false;\n const n = node as Record<string, unknown>;\n if (n.type === 'inlineIcon') return true;\n if (Array.isArray(n.children)) {\n for (const child of n.children) if (visit(child)) return true;\n }\n return false;\n }\n return visit(doc);\n}\n\n// ── Top-level walk with feature-section grouping ───────────────────\n\n/**\n * Walk the document's top-level children, grouping headings that carry\n * a `leftFeature` / `rightFeature` template annotation with the body\n * blocks that follow them (up to the next sibling-or-higher heading).\n * Each group renders as a single `<section class=\"squisq-feature ...\">`\n * with a media column and a text column — the plain-HTML analogue of\n * the SVG layer layout produced by `materializeBlockLayers` for the same templates.\n */\nfunction renderTopLevel(children: MarkdownNode[], ctx: RenderCtx | undefined): string {\n const out: string[] = [];\n for (let i = 0; i < children.length; i++) {\n const node = children[i] as { type?: string };\n if (node && node.type === 'heading') {\n const heading = node as MarkdownHeadingLike;\n const tpl = heading.templateAnnotation?.template;\n if (tpl === 'leftFeature' || tpl === 'rightFeature') {\n const end = findSectionEnd(children, i);\n const sectionBody = children.slice(i + 1, end);\n out.push(renderFeatureSection(heading, sectionBody, tpl, ctx));\n i = end - 1;\n continue;\n }\n }\n out.push(nodeToHtml(node as MarkdownNode, ctx));\n }\n return out.join('\\n');\n}\n\ninterface MarkdownHeadingLike {\n type: 'heading';\n depth: number;\n children?: MarkdownNode[];\n templateAnnotation?: { template?: string };\n}\n\n/**\n * Index of the next heading after `from`; otherwise the array length.\n * Feature sections greedily eat the heading's immediate body content\n * (paragraphs, lists, images) up to the next heading of any depth — a\n * nested sub-heading inside a feature would look chaotic in the\n * side-by-side layout, so we keep features short by design.\n */\nfunction findSectionEnd(nodes: MarkdownNode[], from: number): number {\n for (let i = from + 1; i < nodes.length; i++) {\n const n = nodes[i] as { type?: string };\n if (n && n.type === 'heading') return i;\n }\n return nodes.length;\n}\n\n/**\n * Render a feature section as `<section class=\"squisq-feature ...\">`.\n * The first image found in the body becomes the media column; the\n * heading + remaining content (with the image stripped, so it doesn't\n * appear twice) becomes the text column.\n */\nfunction renderFeatureSection(\n heading: MarkdownHeadingLike,\n bodyNodes: MarkdownNode[],\n side: 'leftFeature' | 'rightFeature',\n ctx: RenderCtx | undefined,\n): string {\n const headingTag = `h${Math.min(Math.max(heading.depth ?? 2, 1), 6)}`;\n const headingHtml = `<${headingTag}>${childrenToHtml({ children: heading.children }, ctx)}</${headingTag}>`;\n\n const featured = takeFirstImage(bodyNodes);\n const media = featured.image\n ? renderFeatureImage(featured.image, ctx)\n : '<div class=\"squisq-feature__media squisq-feature__media--empty\"></div>';\n\n const textHtml = [headingHtml, ...featured.remaining.map((n) => nodeToHtml(n, ctx))]\n .filter((s) => s.length > 0)\n .join('\\n');\n\n const sideClass = side === 'leftFeature' ? 'squisq-feature--left' : 'squisq-feature--right';\n\n return `<section class=\"squisq-feature ${sideClass}\">\n${media}\n<div class=\"squisq-feature__body\">\n${textHtml}\n</div>\n</section>`;\n}\n\ninterface FeaturedImage {\n src: string;\n alt: string;\n width?: number;\n height?: number;\n}\n\nfunction renderFeatureImage(img: FeaturedImage, ctx: RenderCtx | undefined): string {\n const resolved = ctx?.images?.get(img.src) ?? img.src;\n const safeSrc = sanitizeUrl(resolved, 'media');\n if (!safeSrc) return '<div class=\"squisq-feature__media squisq-feature__media--empty\"></div>';\n const attrs = [`src=\"${escapeAttr(safeSrc)}\"`, `alt=\"${escapeAttr(img.alt)}\"`];\n // Emit `width` / `height` attributes only when the source HTML had\n // them. The CSS rules then know to honor those values rather than\n // stretching the image to fill the column.\n if (typeof img.width === 'number') attrs.push(`width=\"${img.width}\"`);\n if (typeof img.height === 'number') attrs.push(`height=\"${img.height}\"`);\n const sizedClass =\n typeof img.width === 'number' || typeof img.height === 'number'\n ? ' squisq-feature__media--sized'\n : '';\n return `<div class=\"squisq-feature__media${sizedClass}\"><img ${attrs.join(' ')} /></div>`;\n}\n\n/**\n * Pull the first image reference out of a section's body — either a\n * markdown `image` node (possibly nested inside a paragraph) or a raw\n * HTML `<img>` (the WYSIWYG editor emits these for resized images).\n * Returns the image plus the body with that image removed (so it's not\n * rendered a second time inside the text column).\n */\nfunction takeFirstImage(nodes: MarkdownNode[]): {\n image: FeaturedImage | null;\n remaining: MarkdownNode[];\n} {\n for (let i = 0; i < nodes.length; i++) {\n const found = extractFirstImageFromBlock(nodes[i]);\n if (!found) continue;\n const remaining = [...nodes];\n if (found.replacement === null) {\n remaining.splice(i, 1);\n } else {\n remaining[i] = found.replacement;\n }\n return { image: found.image, remaining };\n }\n return { image: null, remaining: nodes };\n}\n\n/**\n * Look for the first image inside a single block node. If the block is\n * a paragraph that contains only the image (with optional whitespace),\n * we drop the whole paragraph; if there's surrounding text, we strip\n * the image from the paragraph's inline children and keep the rest.\n * For raw `<img>` html blocks we drop the block entirely.\n */\nfunction extractFirstImageFromBlock(\n block: MarkdownNode,\n): { image: FeaturedImage; replacement: MarkdownNode | null } | null {\n if (!block || typeof block !== 'object') return null;\n const b = block as unknown as Record<string, unknown>;\n if (b.type === 'paragraph' && Array.isArray(b.children)) {\n const kids = b.children as MarkdownNode[];\n const imgIdx = kids.findIndex(\n (k) =>\n (k as { type?: string }).type === 'image' &&\n typeof (k as { url?: unknown }).url === 'string',\n );\n if (imgIdx >= 0) {\n const img = kids[imgIdx] as { url: string; alt?: string };\n const remainingKids = [...kids.slice(0, imgIdx), ...kids.slice(imgIdx + 1)].filter(\n (k) => !isBlankInline(k),\n );\n const replacement =\n remainingKids.length === 0\n ? null\n : ({ ...(b as object), children: remainingKids } as MarkdownNode);\n return {\n image: { src: img.url, alt: img.alt ?? '' },\n replacement,\n };\n }\n }\n if (b.type === 'htmlBlock' && Array.isArray(b.htmlChildren)) {\n const hit = findHtmlImg(b.htmlChildren as HtmlNode[]);\n if (hit) return { image: hit, replacement: null };\n }\n return null;\n}\n\nfunction isBlankInline(node: MarkdownNode): boolean {\n if (!node || typeof node !== 'object') return false;\n const n = node as { type?: string; value?: unknown };\n return n.type === 'text' && typeof n.value === 'string' && n.value.trim().length === 0;\n}\n\nfunction findHtmlImg(nodes: HtmlNode[]): FeaturedImage | null {\n for (const n of nodes) {\n if (n.type !== 'htmlElement') continue;\n if (n.tagName.toLowerCase() === 'img') {\n const src = n.attributes.src;\n if (typeof src === 'string' && src) {\n return {\n src,\n alt: typeof n.attributes.alt === 'string' ? n.attributes.alt : '',\n width: parseHtmlDim(n.attributes.width),\n height: parseHtmlDim(n.attributes.height),\n };\n }\n }\n const nested = findHtmlImg(n.children);\n if (nested) return nested;\n }\n return null;\n}\n\nfunction parseHtmlDim(raw: string | undefined): number | undefined {\n if (raw === undefined) return undefined;\n const n = parseFloat(raw);\n return Number.isFinite(n) && n > 0 ? n : undefined;\n}\n\nconst FEATURE_CSS = ` .squisq-feature {\n display: flex;\n flex-wrap: wrap;\n gap: 1.5em;\n align-items: center;\n margin: 1.75em 0;\n }\n .squisq-feature--right { flex-direction: row-reverse; }\n .squisq-feature__media {\n flex: 0 0 42%;\n min-width: 0;\n }\n .squisq-feature__media--empty { display: none; }\n /* Default: image fills the media column. */\n .squisq-feature__media img {\n width: 100%;\n height: auto;\n display: block;\n border-radius: 6px;\n }\n /* \"Sized\" media: the image carried explicit width/height attrs (the\n WYSIWYG editor wrote them after a resize). Honor the attribute\n values and center the image inside the media column with padding. */\n .squisq-feature__media--sized {\n display: flex;\n align-items: center;\n justify-content: center;\n padding: 1em;\n box-sizing: border-box;\n }\n /* Leave width and height untouched here -- the HTML attributes set\n the intrinsic dimensions, and CSS overrides would silently discard\n the author's sizing. max-width: 100% still keeps the image from\n overflowing the column on narrow viewports; HTML5 derives the\n aspect ratio from the width/height pair so the scale stays right. */\n .squisq-feature__media--sized img {\n max-width: 100%;\n display: block;\n border-radius: 6px;\n }\n .squisq-feature__body {\n flex: 1 1 0;\n min-width: 0;\n }\n .squisq-feature__body > :first-child { margin-top: 0; }\n .squisq-feature__body > :last-child { margin-bottom: 0; }\n @media (max-width: 600px) {\n .squisq-feature, .squisq-feature--right { flex-direction: column; }\n .squisq-feature__media { flex-basis: auto; width: 100%; }\n }`;\n\n// ── Theme-driven CSS ───────────────────────────────────────────────\n\nconst DEFAULT_CSS = ` body { font-family: system-ui, -apple-system, sans-serif; max-width: 800px; margin: 2em auto; padding: 0 1em; line-height: 1.6; color: #1f2937; }\n h1, h2, h3, h4, h5, h6 { margin-top: 1.5em; margin-bottom: 0.5em; }\n pre { background: #f3f4f6; padding: 1em; border-radius: 4px; overflow-x: auto; }\n code { background: #f3f4f6; padding: 0.15em 0.3em; border-radius: 3px; font-size: 0.9em; }\n pre code { background: none; padding: 0; }\n blockquote { border-left: 3px solid #d1d5db; margin-left: 0; padding-left: 1em; color: #6b7280; }\n /* Images: cap at the container width so nothing overflows, but only\n force aspect-ratio height when the author didn't set explicit\n dimensions on the <img> tag. The WYSIWYG editor writes width/height\n attributes after a resize — overriding them here would silently\n ignore the user's sizing. */\n img { max-width: 100%; }\n img:not([width]):not([height]) { height: auto; }\n a { color: #3b82f6; }\n table { border-collapse: collapse; width: 100%; margin: 1em 0; }\n th, td { border: 1px solid #d1d5db; padding: 6px 10px; text-align: left; }\n th { background: #f3f4f6; font-weight: 600; }\n hr { border: none; border-top: 1px solid #d1d5db; margin: 1.5em 0; }`;\n\n/**\n * Build the stylesheet for a themed page. We resolve fonts and colors\n * to CSS-ready strings up front (rather than emitting `--squisq-*`\n * custom properties everywhere) so the output works in environments\n * that strip CSS variables.\n */\nfunction renderThemedCss(theme: Theme): string {\n const bodyFamily = resolveFontFamily(theme.typography.bodyFont, 'system-ui, sans-serif');\n const titleFamily = resolveFontFamily(theme.typography.titleFont, 'Georgia, serif');\n const monoFamily = resolveFontFamily(theme.typography.monoFont, 'Consolas, monospace');\n const lineHeight = theme.typography.lineHeight ?? 1.6;\n const titleLineHeight = theme.typography.titleLineHeight ?? 1.25;\n const titleWeight = theme.typography.titleWeight === 'normal' ? 400 : 700;\n const c = theme.colors;\n // A few derived colors so the page doesn't end up unreadable on\n // themes that swing dark (most code/table chrome reads as \"dim panel\n // on background\"). We do this in CSS, not in JS, by mixing with\n // `color-mix` so older browsers without it still get a sensible look.\n return ` :root {\n --plain-bg: ${c.background};\n --plain-text: ${c.text};\n --plain-muted: ${c.textMuted};\n --plain-primary: ${c.primary};\n --plain-secondary: ${c.secondary};\n --plain-accent: ${c.highlight};\n --plain-bg-light: ${c.backgroundLight};\n --plain-body-font: ${bodyFamily};\n --plain-title-font: ${titleFamily};\n --plain-mono-font: ${monoFamily};\n }\n body {\n font-family: var(--plain-body-font);\n max-width: 800px;\n margin: 2em auto;\n padding: 0 1em;\n line-height: ${lineHeight};\n color: var(--plain-text);\n background: var(--plain-bg);\n }\n h1, h2, h3, h4, h5, h6 {\n font-family: var(--plain-title-font);\n color: var(--plain-text);\n margin-top: 1.5em;\n margin-bottom: 0.5em;\n line-height: ${titleLineHeight};\n font-weight: ${titleWeight};\n }\n p { margin: 0.75em 0; }\n pre {\n background: var(--plain-bg-light);\n padding: 1em;\n border-radius: 4px;\n overflow-x: auto;\n font-family: var(--plain-mono-font);\n }\n code {\n background: var(--plain-bg-light);\n padding: 0.15em 0.3em;\n border-radius: 3px;\n font-size: 0.9em;\n font-family: var(--plain-mono-font);\n }\n pre code { background: none; padding: 0; }\n blockquote {\n border-left: 3px solid var(--plain-primary);\n margin-left: 0;\n padding-left: 1em;\n color: var(--plain-muted);\n }\n /* See DEFAULT_CSS comment: only auto-scale height when the author\n didn't set explicit width/height attributes. */\n img { max-width: 100%; }\n img:not([width]):not([height]) { height: auto; }\n /* Blend the theme primary toward the body text color so links stay\n theme-flavored but read clearly on every theme's background — some\n themes (e.g. Gezellig) pick a mid-tone primary that's almost\n invisible on a dark page when used neat. Underline makes the link\n unambiguous independent of the color contrast. */\n a {\n color: color-mix(in srgb, var(--plain-primary) 65%, var(--plain-text));\n text-decoration: underline;\n text-decoration-thickness: 1px;\n text-underline-offset: 2px;\n }\n a:hover { color: var(--plain-accent); }\n table { border-collapse: collapse; width: 100%; margin: 1em 0; }\n th, td {\n border: 1px solid color-mix(in srgb, var(--plain-muted) 30%, transparent);\n padding: 6px 10px;\n text-align: left;\n }\n th {\n background: var(--plain-bg-light);\n color: var(--plain-text);\n font-family: var(--plain-title-font);\n font-weight: 600;\n }\n hr {\n border: none;\n border-top: 1px solid color-mix(in srgb, var(--plain-muted) 40%, transparent);\n margin: 1.5em 0;\n }`;\n}\n\n/**\n * Emit the `<link rel=\"stylesheet\">` line(s) needed to load the theme's\n * fonts. Empty string when nothing in the theme is hosted on Google\n * Fonts (system stacks, custom self-hosted faces).\n */\nfunction renderFontsLink(theme: Theme): string {\n const url = buildGoogleFontsUrl([\n theme.typography.bodyFont,\n theme.typography.titleFont,\n theme.typography.monoFont,\n ]);\n if (!url) return '';\n // Preconnect to Google's CDN to shave a roundtrip off the font load.\n return `<link rel=\"preconnect\" href=\"https://fonts.googleapis.com\">\n<link rel=\"preconnect\" href=\"https://fonts.gstatic.com\" crossorigin>\n<link rel=\"stylesheet\" href=\"${escapeAttr(url)}\">\n`;\n}\n\n// ── Node → HTML ────────────────────────────────────────────────────\n\nfunction nodeToHtml(node: MarkdownNode | undefined | null, ctx?: RenderCtx): string {\n if (!node) return '';\n switch (node.type) {\n case 'heading': {\n const depth = Math.min(Math.max(node.depth ?? 1, 1), 6);\n return `<h${depth}>${childrenToHtml(node, ctx)}</h${depth}>`;\n }\n case 'paragraph':\n return `<p>${childrenToHtml(node, ctx)}</p>`;\n case 'text':\n return escapeHtml(node.value ?? '');\n case 'strong':\n return `<strong>${childrenToHtml(node, ctx)}</strong>`;\n case 'emphasis':\n return `<em>${childrenToHtml(node, ctx)}</em>`;\n case 'delete':\n return `<del>${childrenToHtml(node, ctx)}</del>`;\n case 'inlineCode':\n return `<code>${escapeHtml(node.value ?? '')}</code>`;\n case 'code': {\n const lang = node.lang ? ` class=\"language-${escapeAttr(node.lang)}\"` : '';\n return `<pre><code${lang}>${escapeHtml(node.value ?? '')}</code></pre>`;\n }\n case 'blockquote':\n return `<blockquote>${childrenToHtml(node, ctx)}</blockquote>`;\n case 'list': {\n const tag = node.ordered ? 'ol' : 'ul';\n const start =\n node.ordered && typeof node.start === 'number' && node.start !== 1\n ? ` start=\"${node.start}\"`\n : '';\n return `<${tag}${start}>${childrenToHtml(node, ctx)}</${tag}>`;\n }\n case 'listItem':\n return `<li>${childrenToHtml(node, ctx)}</li>`;\n case 'link': {\n const original = node.url ?? '';\n const rewritten = ctx?.links?.get(original) ?? original;\n const safeHref = sanitizeUrl(rewritten, 'link');\n if (!safeHref) return childrenToHtml(node, ctx);\n return `<a href=\"${escapeAttr(safeHref)}\">${childrenToHtml(node, ctx)}</a>`;\n }\n case 'image': {\n const original = node.url ?? '';\n const resolved = ctx?.images?.get(original) ?? original;\n const safeSrc = sanitizeUrl(resolved, 'media');\n if (!safeSrc) return escapeHtml(node.alt ?? '');\n return `<img src=\"${escapeAttr(safeSrc)}\" alt=\"${escapeAttr(node.alt ?? '')}\" />`;\n }\n case 'thematicBreak':\n return '<hr />';\n case 'table':\n return tableToHtml(node, ctx);\n case 'inlineIcon': {\n // Render via FontAwesome's `fa-<family> fa-<name>` class pair.\n // The `<link>` to the FA CSS is injected into <head> by\n // `markdownDocToPlainHtml` when the doc contains any icon.\n const family = escapeAttr(node.family ?? 'solid');\n const name = escapeAttr(node.name ?? '');\n const token = escapeAttr(node.token ?? `${node.family}:${node.name}`);\n return `<i class=\"fa-${family} fa-${name}\" data-icon=\"${token}\" aria-hidden=\"true\"></i>`;\n }\n case 'htmlBlock':\n case 'htmlInline':\n if (resolveHtmlPolicy(ctx) === 'strip') return '';\n // Resized images and other authored HTML survive the round-trip\n // as parsed `htmlChildren` — rewriting `<img src>` through the\n // image map keeps the preview consistent with the markdown-image\n // path. Other tags pass through unmodified.\n return htmlChildrenToHtml(resolveHtmlNodes(node.htmlChildren, ctx), ctx);\n default: {\n // Unknown / unhandled node — recurse into children if any so we\n // don't drop content (e.g. directives, footnotes).\n const withChildren = node as { children?: unknown; value?: unknown };\n if (Array.isArray(withChildren.children)) {\n return childrenToHtml(node as { children: MarkdownNode[] }, ctx);\n }\n if (typeof withChildren.value === 'string') {\n return escapeHtml(withChildren.value);\n }\n return '';\n }\n }\n}\n\nfunction childrenToHtml(\n node: { children?: MarkdownNode[]; value?: string },\n ctx?: RenderCtx,\n): string {\n if (!node.children) return node.value ? escapeHtml(node.value) : '';\n return node.children.map((child) => nodeToHtml(child, ctx)).join('');\n}\n\nfunction tableToHtml(\n node: { children: { children: { children: MarkdownNode[]; isHeader?: boolean }[] }[] },\n ctx?: RenderCtx,\n): string {\n const [headerRow, ...bodyRows] = node.children;\n const parts: string[] = ['<table>'];\n if (headerRow) {\n parts.push('<thead><tr>');\n for (const cell of headerRow.children) {\n parts.push(`<th>${childrenToHtml(cell, ctx)}</th>`);\n }\n parts.push('</tr></thead>');\n }\n if (bodyRows.length > 0) {\n parts.push('<tbody>');\n for (const row of bodyRows) {\n parts.push('<tr>');\n for (const cell of row.children) {\n parts.push(`<td>${childrenToHtml(cell, ctx)}</td>`);\n }\n parts.push('</tr>');\n }\n parts.push('</tbody>');\n }\n parts.push('</table>');\n return parts.join('');\n}\n\nfunction resolveHtmlPolicy(ctx: RenderCtx | undefined): HtmlPolicy {\n return ctx?.htmlPolicy ?? 'sanitize';\n}\n\nfunction resolveHtmlNodes(nodes: HtmlNode[] | undefined, ctx: RenderCtx | undefined): HtmlNode[] {\n if (!nodes || nodes.length === 0) return [];\n return resolveHtmlPolicy(ctx) === 'trusted' ? nodes : sanitizeHtmlNodes(nodes);\n}\n\nfunction htmlChildrenToHtml(nodes: HtmlNode[] | undefined, ctx?: RenderCtx): string {\n if (!nodes || nodes.length === 0) return '';\n const trusted = resolveHtmlPolicy(ctx) === 'trusted';\n const out: string[] = [];\n for (const node of nodes) {\n if (node.type === 'htmlText') {\n // HtmlText already represents authored HTML — emit verbatim so\n // entity references the user wrote (e.g. `&`) survive.\n out.push(trusted ? node.value : escapeHtml(node.value));\n continue;\n }\n if (node.type === 'htmlComment') {\n if (trusted) out.push(`<!--${node.value}-->`);\n continue;\n }\n // htmlElement\n const tag = node.tagName.toLowerCase();\n const attrs = { ...node.attributes };\n // Route media `src` attrs through the export's `ctx.images` URL\n // map (which is actually a generic media map — see header comment).\n // Without this, raw <video>/<audio> tags inserted by the recorder\n // ship as relative paths that resolve against the export host, not\n // the original ContentContainer.\n if (\n (tag === 'img' || tag === 'video' || tag === 'audio' || tag === 'source') &&\n typeof attrs.src === 'string'\n ) {\n attrs.src = ctx?.images?.get(attrs.src) ?? attrs.src;\n }\n if ((tag === 'video' || tag === 'audio') && typeof attrs.poster === 'string') {\n attrs.poster = ctx?.images?.get(attrs.poster) ?? attrs.poster;\n }\n if (!trusted) {\n if (typeof attrs.src === 'string') {\n const safeSrc = sanitizeUrl(attrs.src, 'media');\n if (!safeSrc) delete attrs.src;\n else attrs.src = safeSrc;\n }\n if (typeof attrs.poster === 'string') {\n const safePoster = sanitizeUrl(attrs.poster, 'media');\n if (!safePoster) delete attrs.poster;\n else attrs.poster = safePoster;\n }\n if (typeof attrs.href === 'string') {\n const safeHref = sanitizeUrl(attrs.href, 'link');\n if (!safeHref) delete attrs.href;\n else attrs.href = safeHref;\n }\n }\n const attrStr = Object.entries(attrs)\n .map(([k, v]) => ` ${k}=\"${escapeAttr(v)}\"`)\n .join('');\n if (node.selfClosing) {\n out.push(`<${tag}${attrStr} />`);\n } else {\n out.push(`<${tag}${attrStr}>${htmlChildrenToHtml(node.children, ctx)}</${tag}>`);\n }\n }\n return out.join('');\n}\n\n// ── Escaping ───────────────────────────────────────────────────────\n\nfunction escapeHtml(s: string): string {\n return s.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>');\n}\n\nfunction escapeAttr(s: string): string {\n return escapeHtml(s).replace(/\"/g, '"');\n}\n","/**\n * Recursive plain-HTML bundle export.\n *\n * `markdownDocsToPlainHtmlBundle` starts from a single entry markdown\n * file, walks its relative `[…](other.md)` links, recursively pulls in\n * any sibling/child documents (scope-limited to the entry doc's\n * directory tree), renders every visited file via\n * `markdownDocToPlainHtml`, rewrites cross-doc references from `.md`\n * to `.html`, and ships everything as a single ZIP.\n *\n * The function is provider-agnostic — callers pass `readDocument` and\n * `readBinary` callbacks that resolve relative paths against whatever\n * storage they use (`FileSystemContentContainer`, `MemoryContent-\n * Container`, in-memory map for tests, …). Failure to read any\n * discovered file aborts the whole export with a thrown error.\n */\n\nimport JSZip from 'jszip';\nimport { parseMarkdown, inferDocumentTitle } from '@bendyline/squisq/markdown';\nimport type { MarkdownDocument, HtmlNode } from '@bendyline/squisq/markdown';\nimport type { Theme, ThemeRegistry } from '@bendyline/squisq/schemas';\nimport { markdownDocToPlainHtml } from './plainHtml.js';\n\n// ── Public Types ───────────────────────────────────────────────────\n\nexport interface PlainHtmlBundleOptions {\n /** Entry document path relative to the container root (e.g. `'home.md'`). */\n entryPath: string;\n /** Reads a UTF-8 markdown file from the container. Returns null when absent. */\n readDocument: (path: string) => Promise<string | null>;\n /** Reads a binary asset (image) from the container. Returns null when absent. */\n readBinary: (path: string) => Promise<ArrayBuffer | null>;\n /** Optional document title for the entry. Others derive from filename. */\n title?: string;\n /** Optional theme applied uniformly to every page. Overrides {@link themeId}. */\n theme?: Theme;\n /**\n * Optional theme id (e.g. `'warm-earth'`, `'gezellig'`) applied to every\n * page. Each document resolves its own inline definition before consulting\n * {@link themeRegistry}. When both `theme` and `themeId` are supplied,\n * `theme` wins.\n */\n themeId?: string;\n /** Explicit caller-owned registry for non-document custom themes. */\n themeRegistry?: ThemeRegistry;\n /** Maximum recursion depth (default: unlimited; cycles always handled). */\n maxDepth?: number;\n /**\n * Emit the entry doc as `index.html` (preserving its parent directory)\n * instead of `<basename>.html`. Cross-doc links pointing at the entry\n * also rewrite to `index.html`, so a sibling `resume.md → home.md`\n * link doesn't 404 after the rename. Convenient for static-site\n * deploys where the landing page must be named `index.html`.\n * Default: false.\n */\n entryAsIndex?: boolean;\n}\n\n// ── Public API ─────────────────────────────────────────────────────\n\n/**\n * Render an entry markdown document and every reachable sibling/child\n * `.md` document it links to, bundled as a single ZIP with plain-HTML\n * pages, per-document asset folders, and cross-doc `<a href>`\n * references rewritten from `.md` to `.html`.\n */\nexport async function markdownDocsToPlainHtmlBundle(\n options: PlainHtmlBundleOptions,\n): Promise<Blob> {\n const {\n entryPath,\n readDocument,\n readBinary,\n title,\n theme,\n themeId,\n themeRegistry,\n maxDepth = Infinity,\n entryAsIndex = false,\n } = options;\n const entry = normalizePath(entryPath);\n if (!entry) {\n throw new Error('markdownDocsToPlainHtmlBundle: entryPath is required');\n }\n const scopeRoot = posixDirname(entry); // '' for root-level files\n // When `entryAsIndex`, the entry doc writes to `<entryDir>/index.html`\n // and every cross-doc link pointing at it rewrites to that path too.\n // Other docs keep the `<basename>.html` convention.\n const entryHtmlPath = entryAsIndex\n ? scopeRoot\n ? `${scopeRoot}/index.html`\n : 'index.html'\n : entry.slice(0, -3) + '.html';\n const htmlPathFor = (mdPath: string): string =>\n mdPath === entry ? entryHtmlPath : mdPath.slice(0, -3) + '.html';\n\n const zip = new JSZip();\n const visited = new Set<string>();\n const queue: Array<{ path: string; depth: number }> = [{ path: entry, depth: 0 }];\n\n while (queue.length > 0) {\n const { path, depth } = queue.shift()!;\n if (visited.has(path)) continue;\n visited.add(path);\n\n const source = await readDocument(path);\n if (source === null) {\n throw new Error(`markdownDocsToPlainHtmlBundle: failed to read \"${path}\"`);\n }\n const mdDoc = parseMarkdown(source);\n\n // Discover this doc's relative .md links — both for enqueueing new\n // targets and for building the per-doc link rewrite map. We resolve\n // each link to a canonical container-relative path so the same doc\n // referenced two different ways (./resume.md vs resume.md) is\n // visited once and rewritten consistently.\n const docDir = posixDirname(path);\n const linkMap = new Map<string, string>();\n for (const raw of collectLinkRefs(mdDoc)) {\n const parsed = parseLinkRef(raw);\n if (!parsed) continue;\n const resolved = resolveRelative(docDir, parsed.path);\n if (resolved === null) continue; // escaped via ..\n if (!isInScope(resolved, scopeRoot)) continue;\n if (!resolved.toLowerCase().endsWith('.md')) continue;\n\n // Compute the .html replacement relative to the current doc so\n // the rewritten href stays local (e.g. `subdir/notes.html`, not\n // an absolute container path). `htmlPathFor` also handles the\n // entry-as-index case so a sibling linking to the entry lands\n // on `index.html` after rename.\n const htmlTarget = htmlPathFor(resolved);\n const relHref = relativeFrom(docDir, htmlTarget) + parsed.fragment;\n linkMap.set(raw, relHref);\n\n if (depth + 1 <= maxDepth && !visited.has(resolved)) {\n queue.push({ path: resolved, depth: depth + 1 });\n }\n }\n\n // Walk images, fetch each one, write at the original relative path\n // resolved against the container root (so `resume_files/hero.png`\n // sits next to `resume.html` in the zip). Failures here are *not*\n // fatal — images can be missing without breaking the document\n // structure — but we surface them as console warnings.\n const images = await readImagesForDoc(mdDoc, docDir, readBinary);\n for (const [, { data, zipPath }] of images) {\n const safe = sanitizeZipPath(zipPath);\n if (!safe) continue;\n zip.file(safe, data);\n }\n\n // Render the document. The image rewrite map keys are the URLs\n // exactly as authored (so `markdownDocToPlainHtml` can match them\n // verbatim), and the values are paths relative to the rendered\n // doc's own location — so `<img src>` works after unzip without\n // any post-processing.\n const imageRewriteMap = new Map<string, string>();\n for (const [authored, { zipPath }] of images) {\n imageRewriteMap.set(authored, relativeFrom(docDir, zipPath));\n }\n\n const docTitle = depth === 0 ? title : undefined;\n const html = markdownDocToPlainHtml(mdDoc, {\n title: docTitle ?? titleForFilename(path, mdDoc),\n images: imageRewriteMap,\n links: linkMap,\n theme,\n themeId,\n themeRegistry,\n });\n\n const htmlPath = htmlPathFor(path);\n zip.file(htmlPath, html);\n }\n\n return zip.generateAsync({\n type: 'blob',\n compression: 'DEFLATE',\n compressionOptions: { level: 6 },\n });\n}\n\n// ── Link discovery ─────────────────────────────────────────────────\n\n/**\n * Collect every `<a>`-style link URL referenced in a document. Markdown\n * `link` nodes plus any raw HTML `<a href>` tags. Returns the raw URLs\n * as authored, so callers can use them as both the linkMap *key* and\n * the basis for resolution.\n */\nexport function collectLinkRefs(doc: MarkdownDocument): Set<string> {\n const refs = new Set<string>();\n\n function visitHtml(nodes: HtmlNode[]): void {\n for (const n of nodes) {\n if (n.type !== 'htmlElement') continue;\n if (n.tagName.toLowerCase() === 'a') {\n const href = n.attributes.href;\n if (typeof href === 'string' && href) refs.add(href);\n }\n visitHtml(n.children);\n }\n }\n\n function visit(node: unknown): void {\n if (!node || typeof node !== 'object') return;\n const n = node as Record<string, unknown>;\n if (n.type === 'link' && typeof n.url === 'string' && n.url) {\n refs.add(n.url);\n }\n if ((n.type === 'htmlBlock' || n.type === 'htmlInline') && Array.isArray(n.htmlChildren)) {\n visitHtml(n.htmlChildren as HtmlNode[]);\n }\n if (Array.isArray(n.children)) {\n for (const child of n.children) visit(child);\n }\n }\n\n for (const child of doc.children) visit(child);\n return refs;\n}\n\nfunction collectImageRefs(doc: MarkdownDocument): Set<string> {\n const refs = new Set<string>();\n function visitHtml(nodes: HtmlNode[]): void {\n for (const n of nodes) {\n if (n.type !== 'htmlElement') continue;\n const tag = n.tagName.toLowerCase();\n // <img>/<video>/<audio>/<source> all reference media via `src`;\n // we feed them into the same `images` map (effectively a generic\n // media map — see header comment) so the export pipeline rewrites\n // and bundles each one the same way.\n if (tag === 'img' || tag === 'video' || tag === 'audio' || tag === 'source') {\n const src = n.attributes.src;\n if (typeof src === 'string' && src) refs.add(src);\n }\n if (tag === 'video' || tag === 'audio') {\n const poster = n.attributes.poster;\n if (typeof poster === 'string' && poster) refs.add(poster);\n }\n visitHtml(n.children);\n }\n }\n function visit(node: unknown): void {\n if (!node || typeof node !== 'object') return;\n const n = node as Record<string, unknown>;\n if (n.type === 'image' && typeof n.url === 'string' && n.url) refs.add(n.url);\n if ((n.type === 'htmlBlock' || n.type === 'htmlInline') && Array.isArray(n.htmlChildren)) {\n visitHtml(n.htmlChildren as HtmlNode[]);\n }\n if (Array.isArray(n.children)) for (const c of n.children) visit(c);\n }\n for (const child of doc.children) visit(child);\n return refs;\n}\n\ninterface ParsedLinkRef {\n /** Pathname portion before any `#` or `?`. */\n path: string;\n /** `#fragment` suffix (with leading `#`) or empty string. */\n fragment: string;\n}\n\n/**\n * Split an authored URL into path + fragment, returning null for\n * external / non-document references (http(s), mailto, data, blob,\n * absolute paths, fragment-only). The fragment is preserved so a\n * link like `resume.md#experience` rewrites cleanly to\n * `resume.html#experience`.\n */\nfunction parseLinkRef(url: string): ParsedLinkRef | null {\n if (!url) return null;\n if (url.startsWith('#')) return null; // intra-doc anchor\n if (\n /^[a-z][a-z0-9+.-]*:/.test(url) || // http:, https:, mailto:, ftp:, …\n url.startsWith('//') ||\n url.startsWith('/')\n ) {\n return null;\n }\n const hashIdx = url.indexOf('#');\n const queryIdx = url.indexOf('?');\n const cut =\n hashIdx >= 0 && queryIdx >= 0 ? Math.min(hashIdx, queryIdx) : hashIdx >= 0 ? hashIdx : queryIdx;\n const path = cut >= 0 ? url.slice(0, cut) : url;\n const fragment = hashIdx >= 0 ? url.slice(hashIdx) : '';\n return { path, fragment };\n}\n\n// ── Image gathering ────────────────────────────────────────────────\n\n/**\n * Resolve every image referenced by a document to container-relative\n * paths and fetch their bytes. The returned map keys are the authored\n * URLs (so the renderer's `images` map can substitute them); the values\n * are tuples of `[bytes, zipPath]` where `zipPath` is the path used\n * inside the zip.\n *\n * Images that can't be read are silently dropped — the rendered HTML\n * will keep its `<img src>` pointing at the authored URL, which a\n * reader's browser will 404. That matches the user-facing \"abort on\n * missing linked doc\" rule which applies to `.md` links only.\n */\nasync function readImagesForDoc(\n mdDoc: MarkdownDocument,\n docDir: string,\n readBinary: (path: string) => Promise<ArrayBuffer | null>,\n): Promise<Map<string, { data: ArrayBuffer; zipPath: string }>> {\n const out = new Map<string, { data: ArrayBuffer; zipPath: string }>();\n for (const authored of collectImageRefs(mdDoc)) {\n if (/^[a-z][a-z0-9+.-]*:/.test(authored) || authored.startsWith('//')) continue;\n const cleanAuthored = authored.replace(/[#?].*$/, '');\n const resolved = resolveRelative(docDir, cleanAuthored);\n if (resolved === null) continue;\n const data = await readBinary(resolved);\n if (!data) continue;\n out.set(authored, { data, zipPath: resolved });\n }\n return out;\n}\n\n// ── Path helpers (POSIX-style, no Node `path`) ─────────────────────\n\n/**\n * Strip a path to its parent directory (POSIX-style). Returns `''`\n * for root-level files so subsequent joins read like a fresh path.\n */\nexport function posixDirname(p: string): string {\n const idx = p.lastIndexOf('/');\n return idx < 0 ? '' : p.slice(0, idx);\n}\n\n/**\n * Normalize a POSIX path: collapse `./`, resolve `..`, drop trailing\n * slashes, never produce a leading `/`. Returns null when the path\n * escapes the start (\"..\").\n */\nexport function normalizePath(p: string): string | null {\n const parts = p.split('/');\n const out: string[] = [];\n for (const segment of parts) {\n if (segment === '' || segment === '.') continue;\n if (segment === '..') {\n if (out.length === 0) return null;\n out.pop();\n continue;\n }\n out.push(segment);\n }\n return out.join('/');\n}\n\n/**\n * Resolve `rel` against `baseDir`. Returns null when the result\n * escapes the container root via `..`.\n */\nexport function resolveRelative(baseDir: string, rel: string): string | null {\n if (rel.startsWith('/')) return null; // absolute paths are out of scope\n const joined = baseDir ? `${baseDir}/${rel}` : rel;\n return normalizePath(joined);\n}\n\n/**\n * True when `target` is inside `root` (or equal to it). Empty root\n * means \"entire container is in scope\".\n */\nexport function isInScope(target: string, root: string): boolean {\n if (!root) return true;\n return target === root || target.startsWith(root + '/');\n}\n\n/**\n * Compute a relative path from `fromDir` to `toPath` (both POSIX-\n * normalized, container-relative). Used to emit hrefs that work after\n * unzipping anywhere — `home.md → subfolder/notes.md` becomes\n * `subfolder/notes.html`; `subfolder/intro.md → resume.md` becomes\n * `../resume.html`.\n */\nexport function relativeFrom(fromDir: string, toPath: string): string {\n const fromParts = fromDir ? fromDir.split('/') : [];\n const toParts = toPath.split('/');\n let common = 0;\n while (\n common < fromParts.length &&\n common < toParts.length - 1 &&\n fromParts[common] === toParts[common]\n ) {\n common++;\n }\n const up = fromParts.length - common;\n const down = toParts.slice(common);\n const prefix = Array(up).fill('..').join('/');\n if (!prefix) return down.join('/');\n return `${prefix}/${down.join('/')}`;\n}\n\n/**\n * Sanitize a path for use as a zip entry. Strips leading slashes,\n * normalizes backslashes (Windows-authored paths), and rejects any\n * path containing `..` segments after normalization (defensive — the\n * resolver above already filters those out for links).\n */\nfunction sanitizeZipPath(path: string): string | null {\n const normalized = path.replace(/\\\\/g, '/').replace(/^\\/+/, '');\n if (!normalized) return null;\n if (normalized.split('/').some((seg) => seg === '..')) return null;\n return normalized;\n}\n\n/**\n * Derive a default page title for a non-entry doc: prefer frontmatter\n * `title`, fall back to the shallowest heading text, then the filename\n * without extension.\n */\nfunction titleForFilename(path: string, mdDoc: MarkdownDocument): string {\n const inferred = inferDocumentTitle(mdDoc);\n if (inferred) return inferred;\n const base = path.split('/').pop() ?? path;\n return base.replace(/\\.md$/i, '');\n}\n","/**\n * Recursive rendered-HTML bundle export.\n *\n * `markdownDocsToHtmlBundle` is the rendered-pipeline counterpart of\n * `markdownDocsToPlainHtmlBundle`. Starting from a single entry markdown\n * file, it walks every relative `[…](other.md)` link, builds a Doc for\n * each visited page via `markdownToDoc`, rewrites cross-doc link URLs\n * inside the Doc tree from `.md` → relative `.html`, then renders each\n * Doc to a SquisqPlayer-backed HTML page sharing one `squisq-player.js`.\n * Images preserve their authored relative paths so per-doc folders\n * (`resume_files/hero.png`, etc.) sit beside the rendered HTML.\n *\n * The rewrite happens on the Doc, *before* JSON serialization, because\n * the rendered HTML embeds the Doc as JSON and SquisqPlayer emits the\n * `<a href>` at runtime — there is no post-render link rewrite hook in\n * the player path.\n */\n\nimport JSZip from 'jszip';\nimport { parseMarkdown, inferDocumentTitle } from '@bendyline/squisq/markdown';\nimport type {\n MarkdownDocument,\n MarkdownBlockNode,\n MarkdownInlineNode,\n HtmlNode,\n} from '@bendyline/squisq/markdown';\nimport { markdownToDoc } from '@bendyline/squisq/doc';\nimport type { Block, Doc, ThemeRegistry } from '@bendyline/squisq/schemas';\nimport { generateExternalHtml } from './htmlTemplate.js';\nimport {\n collectLinkRefs,\n isInScope,\n normalizePath,\n posixDirname,\n relativeFrom,\n resolveRelative,\n} from './plainHtmlBundle.js';\n\n// ── Public Types ───────────────────────────────────────────────────\n\nexport interface HtmlBundleOptions {\n /** Entry document path relative to the container root (e.g. `'home.md'`). */\n entryPath: string;\n /** Reads a UTF-8 markdown file from the container. Returns null when absent. */\n readDocument: (path: string) => Promise<string | null>;\n /** Reads a binary asset (image) from the container. Returns null when absent. */\n readBinary: (path: string) => Promise<ArrayBuffer | null>;\n /** SquisqPlayer IIFE bundle. Written once as `squisq-player.js` in the zip. */\n playerScript: string;\n /** Optional document title for the entry. Other pages derive from filename. */\n title?: string;\n /** Theme id applied uniformly to every page. */\n themeId?: string;\n /** Explicit caller-owned registry for non-document custom themes. */\n themeRegistry?: ThemeRegistry;\n /** Rendering mode for every page (default: 'static' — scrollable, link-friendly). */\n mode?: 'slideshow' | 'static';\n /** Maximum recursion depth (default: unlimited; cycles always handled). */\n maxDepth?: number;\n /**\n * Emit the entry doc as `index.html` (preserving its parent directory)\n * instead of `<basename>.html`. Cross-doc links pointing at the entry\n * also rewrite to `index.html`, so a sibling `resume.md → home.md`\n * link doesn't 404 after the rename. Convenient for static-site\n * deploys where the landing page must be named `index.html`.\n * Default: false.\n */\n entryAsIndex?: boolean;\n}\n\n// ── Public API ─────────────────────────────────────────────────────\n\n/**\n * Render an entry markdown document and every reachable sibling/child\n * `.md` document it links to, bundled as a single ZIP with one rendered\n * HTML page per doc, per-document asset folders, a shared\n * `squisq-player.js`, and cross-doc `<a href>` references rewritten\n * from `.md` to `.html` inside each Doc's serialized AST.\n */\nexport async function markdownDocsToHtmlBundle(options: HtmlBundleOptions): Promise<Blob> {\n const {\n entryPath,\n readDocument,\n readBinary,\n playerScript,\n title,\n themeId,\n themeRegistry,\n mode = 'static',\n maxDepth = Infinity,\n entryAsIndex = false,\n } = options;\n\n const entry = normalizePath(entryPath);\n if (!entry) {\n throw new Error('markdownDocsToHtmlBundle: entryPath is required');\n }\n const scopeRoot = posixDirname(entry);\n // When `entryAsIndex`, the entry doc writes to `<entryDir>/index.html`\n // and every cross-doc link pointing at it rewrites to that path too.\n // Other docs keep the `<basename>.html` convention.\n const entryHtmlPath = entryAsIndex\n ? scopeRoot\n ? `${scopeRoot}/index.html`\n : 'index.html'\n : entry.slice(0, -3) + '.html';\n const htmlPathFor = (mdPath: string): string =>\n mdPath === entry ? entryHtmlPath : mdPath.slice(0, -3) + '.html';\n\n const zip = new JSZip();\n zip.file('squisq-player.js', playerScript);\n\n const visited = new Set<string>();\n const queue: Array<{ path: string; depth: number }> = [{ path: entry, depth: 0 }];\n\n while (queue.length > 0) {\n const { path, depth } = queue.shift()!;\n if (visited.has(path)) continue;\n visited.add(path);\n\n const source = await readDocument(path);\n if (source === null) {\n throw new Error(`markdownDocsToHtmlBundle: failed to read \"${path}\"`);\n }\n const mdDoc = parseMarkdown(source);\n\n const docDir = posixDirname(path);\n const linkMap = new Map<string, string>();\n for (const raw of collectLinkRefs(mdDoc)) {\n const parsed = parseInternalRef(raw);\n if (!parsed) continue;\n const resolved = resolveRelative(docDir, parsed.path);\n if (resolved === null) continue;\n if (!isInScope(resolved, scopeRoot)) continue;\n if (!resolved.toLowerCase().endsWith('.md')) continue;\n\n const htmlTarget = htmlPathFor(resolved);\n const relHref = relativeFrom(docDir, htmlTarget) + parsed.fragment;\n linkMap.set(raw, relHref);\n\n if (depth + 1 <= maxDepth && !visited.has(resolved)) {\n queue.push({ path: resolved, depth: depth + 1 });\n }\n }\n\n // Gather and stash images per doc. Same convention as the plain\n // bundle: keep authored relative paths so `<img src>` paths inside\n // the Doc still resolve after unzip. Missing assets are non-fatal.\n const imageRewriteMap = new Map<string, string>();\n for (const authored of collectImageRefs(mdDoc)) {\n if (/^[a-z][a-z0-9+.-]*:/i.test(authored) || authored.startsWith('//')) continue;\n const clean = authored.replace(/[#?].*$/, '');\n const resolvedImg = resolveRelative(docDir, clean);\n if (resolvedImg === null) continue;\n const data = await readBinary(resolvedImg);\n if (!data) continue;\n const safe = sanitizeZipPath(resolvedImg);\n if (!safe) continue;\n zip.file(safe, data);\n imageRewriteMap.set(authored, relativeFrom(docDir, resolvedImg));\n }\n\n // markdownToDoc embeds the markdown AST in `block.contents`, so the\n // link rewrite must walk that tree on every Doc before we serialize\n // it into the rendered HTML.\n let doc = markdownToDoc(mdDoc);\n if (linkMap.size > 0) {\n doc = rewriteDocLinks(doc, linkMap);\n }\n\n const pageTitle = depth === 0 ? (title ?? titleForDoc(path, mdDoc)) : titleForDoc(path, mdDoc);\n const htmlPath = htmlPathFor(path);\n const playerScriptPath = relativeFrom(docDir, 'squisq-player.js');\n\n const html = generateExternalHtml(doc, {\n playerScriptPath,\n // Convert Map → plain record for the template (which expects a\n // record). The renderer reads this map at runtime to swap image\n // sources before rendering each block.\n imagePathMap:\n imageRewriteMap.size > 0 ? Object.fromEntries(imageRewriteMap.entries()) : undefined,\n mode,\n title: pageTitle,\n themeId,\n themeRegistry,\n });\n zip.file(htmlPath, html);\n }\n\n return zip.generateAsync({\n type: 'blob',\n compression: 'DEFLATE',\n compressionOptions: { level: 6 },\n });\n}\n\n// ── Link rewriting ─────────────────────────────────────────────────\n\n/**\n * Return a deep-cloned Doc with every `[text](url)` link URL inside\n * `block.contents` rewritten through `linkMap`, including raw HTML\n * `<a href=\"…\">` tags carried inside `htmlBlock`/`htmlInline` nodes.\n * Authoring keys that aren't in the map pass through untouched.\n */\nfunction rewriteDocLinks(doc: Doc, linkMap: Map<string, string>): Doc {\n if (linkMap.size === 0) return doc;\n\n function rewriteHtmlNodes(nodes: HtmlNode[]): HtmlNode[] {\n return nodes.map((n) => {\n if (n.type !== 'htmlElement') return n;\n const tag = n.tagName.toLowerCase();\n const nextAttrs =\n tag === 'a' && typeof n.attributes.href === 'string' && linkMap.has(n.attributes.href)\n ? { ...n.attributes, href: linkMap.get(n.attributes.href)! }\n : n.attributes;\n return {\n ...n,\n attributes: nextAttrs,\n children: rewriteHtmlNodes(n.children),\n };\n });\n }\n\n function rewriteInline(node: MarkdownInlineNode): MarkdownInlineNode {\n if (node.type === 'link') {\n const nextUrl = linkMap.get(node.url) ?? node.url;\n return {\n ...node,\n url: nextUrl,\n children: node.children.map(rewriteInline),\n };\n }\n if (node.type === 'htmlInline') {\n const withChildren = node as MarkdownInlineNode & { htmlChildren?: HtmlNode[] };\n if (Array.isArray(withChildren.htmlChildren)) {\n return {\n ...node,\n htmlChildren: rewriteHtmlNodes(withChildren.htmlChildren),\n } as MarkdownInlineNode;\n }\n return node;\n }\n if ('children' in node && Array.isArray((node as { children?: unknown }).children)) {\n const children = (node as { children: MarkdownInlineNode[] }).children.map(rewriteInline);\n return { ...node, children } as MarkdownInlineNode;\n }\n return node;\n }\n\n function rewriteBlockNode(node: MarkdownBlockNode): MarkdownBlockNode {\n if (node.type === 'htmlBlock') {\n const withChildren = node as MarkdownBlockNode & { htmlChildren?: HtmlNode[] };\n if (Array.isArray(withChildren.htmlChildren)) {\n return {\n ...node,\n htmlChildren: rewriteHtmlNodes(withChildren.htmlChildren),\n } as MarkdownBlockNode;\n }\n return node;\n }\n if ('children' in node && Array.isArray((node as { children?: unknown }).children)) {\n const rewritten = (node as { children: unknown[] }).children.map((c) => {\n const child = c as { type?: string };\n if (child && typeof child === 'object' && 'type' in child) {\n if (isBlockNodeType(child.type as string)) {\n return rewriteBlockNode(c as MarkdownBlockNode);\n }\n return rewriteInline(c as MarkdownInlineNode);\n }\n return c;\n });\n return { ...node, children: rewritten } as MarkdownBlockNode;\n }\n return node;\n }\n\n function rewriteBlock(block: Block): Block {\n const next: Block = { ...block };\n if (Array.isArray(block.contents)) {\n next.contents = block.contents.map(rewriteBlockNode);\n }\n if (Array.isArray(block.children)) {\n next.children = block.children.map(rewriteBlock);\n }\n return next;\n }\n\n return {\n ...doc,\n blocks: doc.blocks.map(rewriteBlock),\n };\n}\n\n/** Block-level markdown node `type` discriminator. Inline node types are\n * everything else (text, link, emphasis, strong, image, etc.). Keeps\n * the recursive rewrite from mistakenly applying block logic to inline\n * link descendants. */\nfunction isBlockNodeType(t: string): boolean {\n return (\n t === 'paragraph' ||\n t === 'heading' ||\n t === 'list' ||\n t === 'listItem' ||\n t === 'blockquote' ||\n t === 'code' ||\n t === 'thematicBreak' ||\n t === 'table' ||\n t === 'tableRow' ||\n t === 'tableCell' ||\n t === 'htmlBlock'\n );\n}\n\n// ── Helpers (kept local to avoid widening plainHtmlBundle's API) ───\n\ninterface ParsedRef {\n path: string;\n fragment: string;\n}\n\nfunction parseInternalRef(url: string): ParsedRef | null {\n if (!url) return null;\n if (url.startsWith('#')) return null;\n if (/^[a-z][a-z0-9+.-]*:/i.test(url) || url.startsWith('//') || url.startsWith('/')) {\n return null;\n }\n const hashIdx = url.indexOf('#');\n const queryIdx = url.indexOf('?');\n const cut =\n hashIdx >= 0 && queryIdx >= 0 ? Math.min(hashIdx, queryIdx) : hashIdx >= 0 ? hashIdx : queryIdx;\n const path = cut >= 0 ? url.slice(0, cut) : url;\n const fragment = hashIdx >= 0 ? url.slice(hashIdx) : '';\n return { path, fragment };\n}\n\nfunction collectImageRefs(doc: MarkdownDocument): Set<string> {\n const refs = new Set<string>();\n function visitHtml(nodes: HtmlNode[]): void {\n for (const n of nodes) {\n if (n.type !== 'htmlElement') continue;\n if (n.tagName.toLowerCase() === 'img') {\n const src = n.attributes.src;\n if (typeof src === 'string' && src) refs.add(src);\n }\n visitHtml(n.children);\n }\n }\n function visit(node: unknown): void {\n if (!node || typeof node !== 'object') return;\n const n = node as Record<string, unknown>;\n if (n.type === 'image' && typeof n.url === 'string' && n.url) refs.add(n.url);\n if ((n.type === 'htmlBlock' || n.type === 'htmlInline') && Array.isArray(n.htmlChildren)) {\n visitHtml(n.htmlChildren as HtmlNode[]);\n }\n if (Array.isArray(n.children)) for (const c of n.children) visit(c);\n }\n for (const child of doc.children) visit(child);\n return refs;\n}\n\nfunction sanitizeZipPath(path: string): string | null {\n const normalized = path.replace(/\\\\/g, '/').replace(/^\\/+/, '');\n if (!normalized) return null;\n if (normalized.split('/').some((seg) => seg === '..')) return null;\n return normalized;\n}\n\nfunction titleForDoc(path: string, mdDoc: MarkdownDocument): string {\n const inferred = inferDocumentTitle(mdDoc);\n if (inferred) return inferred;\n const base = path.split('/').pop() ?? path;\n return base.replace(/\\.md$/i, '');\n}\n","/**\n * HTML Import Module — @bendyline/squisq-formats/html\n *\n * Converts an HTML document (or fragment) into a squisq `MarkdownDocument`.\n * Built on the existing `parseHtmlToNodes` (parse5-backed) + `sanitizeHtmlNodes`\n * from `@bendyline/squisq/markdown`, so no new dependency is introduced.\n *\n * The primary consumer is email: HTML mail bodies are hostile input, so the\n * parse is sanitized by default (scripts/styles/event handlers/dangerous URLs\n * stripped) before the tree is walked into markdown nodes.\n *\n * Two entry points mirror the docx/pdf importers:\n * - `htmlToMarkdownDoc(data, options?)` → `MarkdownDocument`\n * - `htmlToMarkdown(html, options?)` → markdown string (convenience for the\n * string-in/string-out path email body conversion needs)\n */\n\nimport {\n type MarkdownBlockNode,\n type MarkdownDocument,\n type MarkdownInlineNode,\n type MarkdownListItem,\n type MarkdownTableCell,\n type MarkdownTableRow,\n type HtmlElement,\n type HtmlNode,\n parseHtmlToNodes,\n sanitizeHtmlNodes,\n stringifyMarkdown,\n} from '@bendyline/squisq/markdown';\n\nexport interface HtmlImportOptions {\n /**\n * Strip scripts / styles / event handlers / dangerous URLs before walking\n * the tree. Default `true` — HTML email is untrusted; only disable for\n * trusted input where you want raw fidelity.\n */\n sanitize?: boolean;\n}\n\n// ── tag classification ──────────────────────────────────────────────\n\nconst HEADINGS: Record<string, 1 | 2 | 3 | 4 | 5 | 6> = {\n h1: 1,\n h2: 2,\n h3: 3,\n h4: 4,\n h5: 5,\n h6: 6,\n};\n\n// Containers with no semantic block meaning — unwrap and walk their children.\nconst TRANSPARENT_BLOCK = new Set([\n 'div',\n 'section',\n 'article',\n 'header',\n 'footer',\n 'main',\n 'aside',\n 'nav',\n 'figure',\n 'figcaption',\n 'form',\n 'fieldset',\n 'body',\n 'html',\n 'center',\n]);\n\n// Elements that carry no content we want (and whose text must not leak).\nconst DROP = new Set(['script', 'style', 'head', 'title', 'noscript', 'template', 'svg']);\n\nconst INLINE_STRONG = new Set(['strong', 'b']);\nconst INLINE_EM = new Set(['em', 'i']);\nconst INLINE_DEL = new Set(['del', 's', 'strike']);\nconst INLINE_TRANSPARENT = new Set(['span', 'font', 'abbr', 'mark', 'small', 'sub', 'sup', 'u']);\n\nconst isElement = (n: HtmlNode): n is HtmlElement => n.type === 'htmlElement';\nconst isText = (n: HtmlNode): n is { type: 'htmlText'; value: string } => n.type === 'htmlText';\n\nconst collapseWs = (s: string): string => s.replace(/\\s+/g, ' ');\n\n// ── inline conversion ───────────────────────────────────────────────\n\nfunction inlinesFromNodes(nodes: HtmlNode[]): MarkdownInlineNode[] {\n const out: MarkdownInlineNode[] = [];\n for (const node of nodes) {\n if (isText(node)) {\n const value = collapseWs(node.value);\n if (value) out.push({ type: 'text', value });\n continue;\n }\n if (!isElement(node)) continue; // comment\n const tag = node.tagName.toLowerCase();\n if (DROP.has(tag)) continue;\n\n if (tag === 'br') {\n out.push({ type: 'break' });\n } else if (INLINE_STRONG.has(tag)) {\n out.push({ type: 'strong', children: inlinesFromNodes(node.children) });\n } else if (INLINE_EM.has(tag)) {\n out.push({ type: 'emphasis', children: inlinesFromNodes(node.children) });\n } else if (INLINE_DEL.has(tag)) {\n out.push({ type: 'delete', children: inlinesFromNodes(node.children) });\n } else if (tag === 'code' || tag === 'kbd' || tag === 'samp' || tag === 'tt') {\n out.push({ type: 'inlineCode', value: textContent(node) });\n } else if (tag === 'a') {\n const url = node.attributes.href ?? '';\n const children = inlinesFromNodes(node.children);\n out.push({\n type: 'link',\n url,\n children: children.length > 0 ? children : [{ type: 'text', value: url }],\n });\n } else if (tag === 'img') {\n const url = node.attributes.src ?? '';\n const alt = node.attributes.alt;\n if (url) out.push({ type: 'image', url, ...(alt ? { alt } : {}) });\n } else {\n // Unknown / transparent inline (span, font, …): flatten children.\n out.push(...inlinesFromNodes(node.children));\n }\n }\n return out;\n}\n\n/** Flatten an element's descendant text (for code blocks / inline code). */\nfunction textContent(node: HtmlNode): string {\n if (isText(node)) return node.value;\n if (isElement(node)) return node.children.map(textContent).join('');\n return '';\n}\n\nconst onlyWhitespace = (inlines: MarkdownInlineNode[]): boolean =>\n inlines.every((n) => n.type === 'text' && n.value.trim() === '');\n\n// ── block conversion ────────────────────────────────────────────────\n\nfunction blocksFromNodes(nodes: HtmlNode[]): MarkdownBlockNode[] {\n const out: MarkdownBlockNode[] = [];\n let inlineBuffer: HtmlNode[] = [];\n\n const flush = () => {\n if (inlineBuffer.length === 0) return;\n const inlines = inlinesFromNodes(inlineBuffer);\n inlineBuffer = [];\n if (inlines.length > 0 && !onlyWhitespace(inlines)) {\n out.push({ type: 'paragraph', children: inlines });\n }\n };\n\n for (const node of nodes) {\n if (isText(node)) {\n inlineBuffer.push(node);\n continue;\n }\n if (!isElement(node)) continue;\n const tag = node.tagName.toLowerCase();\n if (DROP.has(tag)) continue;\n\n const block = blockForElement(node, tag);\n if (block === 'inline') {\n inlineBuffer.push(node);\n } else if (block) {\n flush();\n out.push(...block);\n }\n }\n flush();\n return out;\n}\n\n/** Returns the block node(s) for a block element, `'inline'` for inline ones. */\nfunction blockForElement(node: HtmlElement, tag: string): MarkdownBlockNode[] | 'inline' | null {\n if (tag in HEADINGS) {\n const children = inlinesFromNodes(node.children);\n return [{ type: 'heading', depth: HEADINGS[tag]!, children }];\n }\n if (tag === 'p') {\n const children = inlinesFromNodes(node.children);\n return children.length > 0 && !onlyWhitespace(children)\n ? [{ type: 'paragraph', children }]\n : [];\n }\n if (tag === 'br') return 'inline';\n if (tag === 'hr') return [{ type: 'thematicBreak' }];\n if (tag === 'blockquote') {\n return [{ type: 'blockquote', children: blocksFromNodes(node.children) }];\n }\n if (tag === 'pre') {\n return [{ type: 'code', value: stripTrailingNewline(textContent(node)) }];\n }\n if (tag === 'ul' || tag === 'ol') {\n return [listFromElement(node, tag === 'ol')];\n }\n if (tag === 'table') {\n const table = tableFromElement(node);\n return table ? [table] : [];\n }\n if (TRANSPARENT_BLOCK.has(tag)) {\n return blocksFromNodes(node.children);\n }\n if (\n INLINE_STRONG.has(tag) ||\n INLINE_EM.has(tag) ||\n INLINE_DEL.has(tag) ||\n INLINE_TRANSPARENT.has(tag) ||\n tag === 'a' ||\n tag === 'img' ||\n tag === 'code' ||\n tag === 'kbd' ||\n tag === 'samp'\n ) {\n return 'inline';\n }\n // Unknown element: treat as a transparent container so its content survives.\n return blocksFromNodes(node.children);\n}\n\nfunction listFromElement(node: HtmlElement, ordered: boolean): MarkdownBlockNode {\n const items: MarkdownListItem[] = [];\n for (const child of node.children) {\n if (isElement(child) && child.tagName.toLowerCase() === 'li') {\n const blocks = blocksFromNodes(child.children);\n items.push({ type: 'listItem', children: blocks });\n }\n }\n const startAttr = node.attributes.start;\n const start = ordered && startAttr ? Number.parseInt(startAttr, 10) : undefined;\n return {\n type: 'list',\n ordered,\n ...(start !== undefined && Number.isFinite(start) ? { start } : {}),\n children: items,\n };\n}\n\nfunction tableFromElement(node: HtmlElement): MarkdownBlockNode | null {\n const rows: MarkdownTableRow[] = [];\n const collectRows = (n: HtmlElement) => {\n for (const child of n.children) {\n if (!isElement(child)) continue;\n const t = child.tagName.toLowerCase();\n if (t === 'tr') {\n const cells: MarkdownTableCell[] = [];\n for (const cell of child.children) {\n if (\n isElement(cell) &&\n (cell.tagName.toLowerCase() === 'td' || cell.tagName.toLowerCase() === 'th')\n ) {\n cells.push({ type: 'tableCell', children: inlinesFromNodes(cell.children) });\n }\n }\n if (cells.length > 0) rows.push({ type: 'tableRow', children: cells });\n } else if (t === 'thead' || t === 'tbody' || t === 'tfoot') {\n collectRows(child);\n }\n }\n };\n collectRows(node);\n if (rows.length === 0) return null;\n return { type: 'table', children: rows };\n}\n\nconst stripTrailingNewline = (s: string): string => s.replace(/\\n+$/, '');\n\n// ── public API ──────────────────────────────────────────────────────\n\nfunction toHtmlString(data: ArrayBuffer | Uint8Array | string): string {\n if (typeof data === 'string') return data;\n const bytes = data instanceof Uint8Array ? data : new Uint8Array(data);\n return new TextDecoder('utf-8').decode(bytes);\n}\n\n/** Parse HTML into a squisq `MarkdownDocument`. */\nexport function htmlToMarkdownDocSync(\n html: string,\n options: HtmlImportOptions = {},\n): MarkdownDocument {\n let nodes = parseHtmlToNodes(html);\n if (options.sanitize !== false) nodes = sanitizeHtmlNodes(nodes);\n return { type: 'document', children: blocksFromNodes(nodes) };\n}\n\n/** Async, ArrayBuffer-accepting entry mirroring docx/pdf importers. */\nexport async function htmlToMarkdownDoc(\n data: ArrayBuffer | Uint8Array | string,\n options: HtmlImportOptions = {},\n): Promise<MarkdownDocument> {\n return htmlToMarkdownDocSync(toHtmlString(data), options);\n}\n\n/** Convenience string→string conversion (used for email HTML bodies). */\nexport function htmlToMarkdown(html: string, options: HtmlImportOptions = {}): string {\n return stringifyMarkdown(htmlToMarkdownDocSync(html, options));\n}\n"],"mappings":";;;;;;;AAgCA,OAAOA,YAAW;;;ACnBlB,SAAS,8BAA8B;AAgDhC,SAAS,kBAAkB,KAAuB;AACvD,QAAM,QAAQ,oBAAI,IAAY;AAE9B,WAAS,cAAc,KAAyB;AAC9C,QACE,CAAC,OACD,IAAI,WAAW,OAAO,KACtB,IAAI,WAAW,OAAO,KACtB,IAAI,WAAW,SAAS,KACxB,IAAI,WAAW,UAAU,GACzB;AACA;AAAA,IACF;AACA,UAAM,IAAI,GAAG;AAAA,EACf;AAEA,WAAS,WAAW,QAA6B;AAC/C,QAAI,CAAC,OAAQ;AACb,eAAW,SAAS,QAAQ;AAC1B,UAAI,MAAM,SAAS,QAAS,eAAc,MAAM,QAAQ,GAAG;AAC3D,UAAI,MAAM,SAAS,SAAS;AAC1B,sBAAc,MAAM,QAAQ,GAAG;AAC/B,sBAAc,MAAM,QAAQ,SAAS;AAAA,MACvC;AACA,UAAI,MAAM,SAAS,MAAO,eAAc,MAAM,QAAQ,SAAS;AAAA,IACjE;AAAA,EACF;AAEA,WAAS,UAAU,OAAc;AAC/B,eAAW,MAAM,MAAM;AACvB,QAAI,MAAM,SAAU,mBAAkB,MAAM,UAAU,aAAa;AACnE,QAAI,MAAM,SAAU,OAAM,SAAS,QAAQ,SAAS;AAAA,EACtD;AAGA,MAAI,OAAO,QAAQ,SAAS;AAG5B,MAAI,IAAI,YAAY,QAAS,eAAc,IAAI,WAAW,OAAO;AAGjE,MAAI,IAAI,kBAAkB;AACxB,eAAW,MAAM,IAAI,iBAAiB,gBAAgB,CAAC,GAAG;AACxD,UAAI,SAAS,MAAM,OAAO,GAAG,QAAQ,SAAU,eAAc,GAAG,GAAG;AAAA,IACrE;A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AU,SAA8C;AACzF,QAAM;AAAA,IACJ;AAAA,IACA;AAAA,IACA;AAAA,IACA,OAAO;AAAA,IACP;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF,IAAI;AAEJ,QAAM,MAAM,IAAIC,OAAM;AAGtB,MAAI,KAAK,oBAAoB,YAAY;AAWzC,QAAM,eAAuC,CAAC;AAC9C,MAAI,QAAQ;AACV,eAAW,CAAC,cAAc,MAAM,KAAK,OAAO,QAAQ,GAAG;AACrD,YAAM,UAAUD,iBAAgB,YAAY;AAC5C,UAAI,CAAC,QAAS;AACd,UAAI,KAAK,SAAS,MAAM;AACxB,mBAAa,YAAY,IAAI;AAAA,IAC/B;AAAA,EACF;AAGA,QAAM,eAAuC,CAAC;AAC9C,MAAI,OAAO;AACT,eAAW,CAAC,YAAY,MAAM,KAAK,MAAM,QAAQ,GAAG;AAClD,YAAM,WAAW,gBAAgB,UAAU;AAE3C,YAAM,YAAY,SAAS,SAAS,GAAG,IAAI,WAAW,GAAG,QAAQ;AACjE,YAAM,UAAU,SAAS,SAAS;AAClC,UAAI,KAAK,SAAS,MAAM;AACxB,mBAAa,UAAU,IAAI;AAAA,IAC7B;AAAA,EACF;AAGA,QAAM,OAAO,qBAAqB,KAAK;AAAA,IACrC,kBAAkB;AAAA,IAClB,cAAc,OAAO,KAAK,YAAY,EAAE,SAAS,IAAI,eAAe;AAAA,IACpE,cAAc,OAAO,KAAK,YAAY,EAAE,SAAS,IAAI,eAAe;AAAA,IACpE;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF,CAAC;AACD,MAAI,KAAK,cAAc,IAAI;AAG3B,SAAO,IAAI,cAAc;AAAA,IACvB,MAAM;AAAA,IACN,aAAa;AAAA,IACb,oBAAoB,EAAE,OAAO,EAAE;AAAA,EACjC,CAAC;AACH;","names":["JSZip","readFrontmatterThemeId","escapeHtml","JSZip","parseMarkdown","inferDocumentTitle","JSZip","parseMarkdown","collectImageRefs","sanitizeZipPath","inferDocumentTitle","sanitizeHtmlNodes","sanitizeZipPath","JSZip"]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
extToMime
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-O3GVVND4.js";
|
|
4
4
|
|
|
5
5
|
// src/html/imageUtils.ts
|
|
6
6
|
function inferMimeType(filename) {
|
|
@@ -8,12 +8,17 @@ function inferMimeType(filename) {
|
|
|
8
8
|
}
|
|
9
9
|
function arrayBufferToBase64DataUrl(buffer, mimeType) {
|
|
10
10
|
const bytes = new Uint8Array(buffer);
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
11
|
+
const chunkSize = 3 * 8192;
|
|
12
|
+
const chunks = [];
|
|
13
|
+
for (let offset = 0; offset < bytes.length; offset += chunkSize) {
|
|
14
|
+
const end = Math.min(offset + chunkSize, bytes.length);
|
|
15
|
+
let binary = "";
|
|
16
|
+
for (let i = offset; i < end; i++) {
|
|
17
|
+
binary += String.fromCharCode(bytes[i]);
|
|
18
|
+
}
|
|
19
|
+
chunks.push(btoa(binary));
|
|
14
20
|
}
|
|
15
|
-
|
|
16
|
-
return `data:${mimeType};base64,${base64}`;
|
|
21
|
+
return `data:${mimeType};base64,${chunks.join("")}`;
|
|
17
22
|
}
|
|
18
23
|
function extractFilename(path) {
|
|
19
24
|
const clean = path.split("?")[0].split("#")[0];
|
|
@@ -26,4 +31,4 @@ export {
|
|
|
26
31
|
arrayBufferToBase64DataUrl,
|
|
27
32
|
extractFilename
|
|
28
33
|
};
|
|
29
|
-
//# sourceMappingURL=chunk-
|
|
34
|
+
//# sourceMappingURL=chunk-MLX2BOJC.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/html/imageUtils.ts"],"sourcesContent":["/**\n * Image Utilities for HTML Export\n *\n * Browser-compatible helpers for converting image data to base64 data URIs\n * and inferring MIME types from filenames.\n */\n\nimport { extToMime } from '../shared/images.js';\n\n/**\n * Infer a MIME type from a filename's extension.\n * Returns 'application/octet-stream' for unknown types.\n *\n * Thin wrapper over the shared {@link extToMime} map so html export, docx\n * import, and pptx import all agree on extension → MIME.\n */\nexport function inferMimeType(filename: string): string {\n return extToMime(filename.split('.').pop() ?? '');\n}\n\n/**\n * Convert an ArrayBuffer to a base64-encoded data URI string.\n *\n * @param buffer - The binary image data\n * @param mimeType - MIME type (e.g., 'image/jpeg'). If not provided, defaults to\n * 'application/octet-stream'.\n * @returns A `data:` URI string\n */\nexport function arrayBufferToBase64DataUrl(buffer: ArrayBuffer, mimeType: string): string {\n const bytes = new Uint8Array(buffer);\n // Keep chunks divisible by three so concatenating their independently\n // encoded results cannot introduce padding in the middle of the stream.\n // This avoids both quadratic string concatenation and one image-sized\n // intermediate binary string for large embedded assets.\n const chunkSize = 3 * 8192;\n const chunks: string[] = [];\n for (let offset = 0; offset < bytes.length; offset += chunkSize) {\n const end = Math.min(offset + chunkSize, bytes.length);\n let binary = '';\n for (let i = offset; i < end; i++) {\n binary += String.fromCharCode(bytes[i]);\n }\n chunks.push(btoa(binary));\n }\n return `data:${mimeType};base64,${chunks.join('')}`;\n}\n\n/**\n * Extract the filename from a path or URL (strips directory and query).\n *\n * @example\n * extractFilename('images/hero.jpg') // 'hero.jpg'\n * extractFilename('https://example.com/photo.png?v=2') // 'photo.png'\n */\nexport function extractFilename(path: string): string {\n // Strip query/hash\n const clean = path.split('?')[0].split('#')[0];\n // Get last segment\n const parts = clean.split('/');\n return parts[parts.length - 1] || path;\n}\n"],"mappings":";;;;;AAgBO,SAAS,cAAc,UAA0B;AACtD,SAAO,UAAU,SAAS,MAAM,GAAG,EAAE,IAAI,KAAK,EAAE;AAClD;AAUO,SAAS,2BAA2B,QAAqB,UAA0B;AACxF,QAAM,QAAQ,IAAI,WAAW,MAAM;AAKnC,QAAM,YAAY,IAAI;AACtB,QAAM,SAAmB,CAAC;AAC1B,WAAS,SAAS,GAAG,SAAS,MAAM,QAAQ,UAAU,WAAW;AAC/D,UAAM,MAAM,KAAK,IAAI,SAAS,WAAW,MAAM,MAAM;AACrD,QAAI,SAAS;AACb,aAAS,IAAI,QAAQ,IAAI,KAAK,KAAK;AACjC,gBAAU,OAAO,aAAa,MAAM,CAAC,CAAC;AAAA,IACxC;AACA,WAAO,KAAK,KAAK,MAAM,CAAC;AAAA,EAC1B;AACA,SAAO,QAAQ,QAAQ,WAAW,OAAO,KAAK,EAAE,CAAC;AACnD;AASO,SAAS,gBAAgB,MAAsB;AAEpD,QAAM,QAAQ,KAAK,MAAM,GAAG,EAAE,CAAC,EAAE,MAAM,GAAG,EAAE,CAAC;AAE7C,QAAM,QAAQ,MAAM,MAAM,GAAG;AAC7B,SAAO,MAAM,MAAM,SAAS,CAAC,KAAK;AACpC;","names":[]}
|