@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.
Files changed (139) hide show
  1. package/README.md +48 -2
  2. package/dist/{chunk-WWBIKRNP.js → chunk-2CSZJEAL.js} +13 -11
  3. package/dist/chunk-2CSZJEAL.js.map +1 -0
  4. package/dist/{chunk-RTS5XBZ7.js → chunk-2EFDWKC6.js} +262 -84
  5. package/dist/chunk-2EFDWKC6.js.map +1 -0
  6. package/dist/chunk-2PRVLAU3.js +740 -0
  7. package/dist/chunk-2PRVLAU3.js.map +1 -0
  8. package/dist/{chunk-SHLPSADL.js → chunk-4HJ6AK2Q.js} +54 -193
  9. package/dist/chunk-4HJ6AK2Q.js.map +1 -0
  10. package/dist/{chunk-5LSSWZPU.js → chunk-4VUWTSGM.js} +72 -25
  11. package/dist/chunk-4VUWTSGM.js.map +1 -0
  12. package/dist/{chunk-YESS7VY3.js → chunk-CVNVD7VH.js} +154 -39
  13. package/dist/chunk-CVNVD7VH.js.map +1 -0
  14. package/dist/chunk-CX3LH47J.js +99 -0
  15. package/dist/chunk-CX3LH47J.js.map +1 -0
  16. package/dist/{chunk-D7IFPWNZ.js → chunk-GVS2XXV6.js} +27 -26
  17. package/dist/chunk-GVS2XXV6.js.map +1 -0
  18. package/dist/chunk-H7T5DXUU.js +479 -0
  19. package/dist/chunk-H7T5DXUU.js.map +1 -0
  20. package/dist/{chunk-EHLGMSTE.js → chunk-HBSCRS5P.js} +10 -8
  21. package/dist/chunk-HBSCRS5P.js.map +1 -0
  22. package/dist/{chunk-46FMDOWZ.js → chunk-LXYLOOST.js} +49 -17
  23. package/dist/chunk-LXYLOOST.js.map +1 -0
  24. package/dist/{chunk-MJGRI6XR.js → chunk-MLX2BOJC.js} +12 -7
  25. package/dist/chunk-MLX2BOJC.js.map +1 -0
  26. package/dist/chunk-NKAJPJ4G.js +106 -0
  27. package/dist/chunk-NKAJPJ4G.js.map +1 -0
  28. package/dist/{chunk-DQAZR57U.js → chunk-O3GVVND4.js} +1 -1
  29. package/dist/chunk-ODL3SSPT.js +18 -0
  30. package/dist/chunk-ODL3SSPT.js.map +1 -0
  31. package/dist/chunk-X4USWOQ2.js +131 -0
  32. package/dist/chunk-X4USWOQ2.js.map +1 -0
  33. package/dist/chunk-XTLQXR4U.js +195 -0
  34. package/dist/chunk-XTLQXR4U.js.map +1 -0
  35. package/dist/chunk-YRT7GQ5Y.js +28 -0
  36. package/dist/chunk-YRT7GQ5Y.js.map +1 -0
  37. package/dist/chunk-ZZ7D4DN6.js +97 -0
  38. package/dist/chunk-ZZ7D4DN6.js.map +1 -0
  39. package/dist/container/index.d.ts +6 -2
  40. package/dist/container/index.js +15 -17
  41. package/dist/container/index.js.map +1 -1
  42. package/dist/docx/index.d.ts +6 -2
  43. package/dist/docx/index.js +5 -3
  44. package/dist/epub/index.d.ts +3 -1
  45. package/dist/epub/index.js +3 -3
  46. package/dist/export-Djev9BLU.d.ts +69 -0
  47. package/dist/extract-LNOA7DBK.js +15 -0
  48. package/dist/extract-LNOA7DBK.js.map +1 -0
  49. package/dist/html/index.d.ts +15 -85
  50. package/dist/html/index.js +3 -3
  51. package/dist/images-7FBWPKE3.js +7 -0
  52. package/dist/images-7FBWPKE3.js.map +1 -0
  53. package/dist/import-DTkDxHmZ.d.ts +84 -0
  54. package/dist/import-Yivc3kZM.d.ts +136 -0
  55. package/dist/index.d.ts +13 -4
  56. package/dist/index.js +30 -11
  57. package/dist/infer/index.d.ts +138 -0
  58. package/dist/infer/index.js +28 -0
  59. package/dist/infer/index.js.map +1 -0
  60. package/dist/layouts-7OUUVAGU.js +12 -0
  61. package/dist/layouts-7OUUVAGU.js.map +1 -0
  62. package/dist/layouts-CZ0bdsNL.d.ts +150 -0
  63. package/dist/mapTheme-IR27S6IV.js +11 -0
  64. package/dist/mapTheme-IR27S6IV.js.map +1 -0
  65. package/dist/ooxml/index.d.ts +21 -127
  66. package/dist/ooxml/index.js +31 -9
  67. package/dist/pdf/index.d.ts +3 -1
  68. package/dist/pdf/index.js +1 -1
  69. package/dist/pptx/index.d.ts +8 -108
  70. package/dist/pptx/index.js +13 -4
  71. package/dist/reader-Gof6OrJX.d.ts +140 -0
  72. package/dist/registry/index.d.ts +46 -8
  73. package/dist/registry/index.js +5 -2
  74. package/dist/themeReader-DPw4J5Ss.d.ts +56 -0
  75. package/dist/xlsx/index.d.ts +6 -66
  76. package/dist/xlsx/index.js +4 -2
  77. package/dist/zipLimits-bGYMS9cI.d.ts +29 -0
  78. package/package.json +8 -2
  79. package/src/__tests__/container.test.ts +41 -0
  80. package/src/__tests__/convert.test.ts +167 -0
  81. package/src/__tests__/epub.test.ts +102 -1
  82. package/src/__tests__/html.test.ts +62 -0
  83. package/src/__tests__/inferTheme.test.ts +135 -0
  84. package/src/__tests__/lossyWarnings.test.ts +41 -0
  85. package/src/__tests__/ooxml.test.ts +59 -2
  86. package/src/__tests__/ooxmlThemeReader.test.ts +92 -0
  87. package/src/__tests__/plainHtml.test.ts +15 -1
  88. package/src/__tests__/plainHtmlBundle.test.ts +18 -0
  89. package/src/__tests__/pptxImport.test.ts +30 -0
  90. package/src/__tests__/pptxInferFixtures.ts +314 -0
  91. package/src/__tests__/pptxLayoutInfer.test.ts +395 -0
  92. package/src/__tests__/zipSafety.test.ts +317 -0
  93. package/src/container/index.ts +20 -29
  94. package/src/docx/export.ts +4 -2
  95. package/src/docx/import.ts +4 -3
  96. package/src/epub/export.ts +94 -25
  97. package/src/html/docsHtmlBundle.ts +6 -2
  98. package/src/html/htmlTemplate.ts +31 -6
  99. package/src/html/imageUtils.ts +14 -5
  100. package/src/html/index.ts +12 -1
  101. package/src/html/plainHtml.ts +7 -3
  102. package/src/html/plainHtmlBundle.ts +11 -9
  103. package/src/index.ts +20 -0
  104. package/src/infer/extract.ts +127 -0
  105. package/src/infer/index.ts +168 -0
  106. package/src/infer/mapTheme.ts +176 -0
  107. package/src/infer/types.ts +27 -0
  108. package/src/ooxml/index.ts +14 -0
  109. package/src/ooxml/readUtils.ts +44 -0
  110. package/src/ooxml/reader.ts +87 -28
  111. package/src/ooxml/themeReader.ts +197 -0
  112. package/src/ooxml/types.ts +8 -9
  113. package/src/ooxml/writer.ts +28 -10
  114. package/src/pdf/export.ts +4 -2
  115. package/src/pdf/import.ts +40 -34
  116. package/src/pptx/export.ts +4 -2
  117. package/src/pptx/import.ts +214 -32
  118. package/src/pptx/index.ts +14 -0
  119. package/src/pptx/layouts.ts +1168 -0
  120. package/src/registry/convert.ts +54 -23
  121. package/src/registry/defaultFormats.ts +131 -44
  122. package/src/registry/index.ts +3 -0
  123. package/src/registry/types.ts +52 -6
  124. package/src/shared/boundedZipArchive.ts +342 -0
  125. package/src/shared/fidelity.ts +130 -0
  126. package/src/shared/zipEntryCount.ts +97 -0
  127. package/src/shared/zipLimits.ts +286 -0
  128. package/src/shared/zipSafety.ts +19 -0
  129. package/src/xlsx/import.ts +3 -2
  130. package/dist/chunk-46FMDOWZ.js.map +0 -1
  131. package/dist/chunk-5LSSWZPU.js.map +0 -1
  132. package/dist/chunk-D7IFPWNZ.js.map +0 -1
  133. package/dist/chunk-EHLGMSTE.js.map +0 -1
  134. package/dist/chunk-MJGRI6XR.js.map +0 -1
  135. package/dist/chunk-RTS5XBZ7.js.map +0 -1
  136. package/dist/chunk-SHLPSADL.js.map +0 -1
  137. package/dist/chunk-WWBIKRNP.js.map +0 -1
  138. package/dist/chunk-YESS7VY3.js.map +0 -1
  139. /package/dist/{chunk-DQAZR57U.js.map → chunk-O3GVVND4.js.map} +0 -0
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/registry/types.ts","../src/shared/fidelity.ts","../src/registry/defaultFormats.ts","../src/registry/registry.ts","../src/registry/convert.ts"],"sourcesContent":["/**\n * Format registry — shared types.\n *\n * The registry is the programmatic heart of `convert()`: it maps a small set of\n * format ids (`md`, `docx`, `pdf`, …) to `FormatDefinition`s, each of which\n * knows how to import to / export from squisq's markdown + Doc model. Every\n * converter module is loaded lazily via `import()` inside the definition\n * methods, so pulling in the registry never eagerly bundles heavy converters.\n */\n\nimport type { Doc, ThemeRegistry } from '@bendyline/squisq/schemas';\nimport type { TransformStyleInput, TransformStyleRegistry } from '@bendyline/squisq/transform';\nimport type { MarkdownDocument } from '@bendyline/squisq/markdown';\nimport type { ContentContainer } from '@bendyline/squisq/storage';\nimport type { ParseOptions, StringifyOptions } from '@bendyline/squisq/markdown';\nimport type { DocxExportOptions } from '../docx/export.js';\nimport type { DocxImportOptions } from '../docx/import.js';\nimport type { PptxExportOptions } from '../pptx/export.js';\nimport type { PptxImportOptions } from '../pptx/import.js';\nimport type { XlsxExportOptions } from '../xlsx/export.js';\nimport type { XlsxImportOptions } from '../xlsx/import.js';\nimport type { CsvExportOptions, CsvImportOptions } from '../csv/index.js';\nimport type { PdfExportOptions } from '../pdf/export.js';\nimport type { PdfImportOptions } from '../pdf/import.js';\nimport type { HtmlExportOptions } from '../html/htmlTemplate.js';\nimport type { HtmlImportOptions } from '../html/import.js';\nimport type { EpubExportOptions } from '../epub/export.js';\nimport type { ZipSafetyLimits } from '../shared/zipSafety.js';\n\n/** A format identifier (e.g. `'docx'`). Strings so hosts can register their own. */\nexport type FormatId = string;\n\n/** The built-in formats the default registry ships with. */\nexport const BUILTIN_FORMAT_IDS = [\n 'md',\n 'docx',\n 'pdf',\n 'pptx',\n 'xlsx',\n 'csv',\n 'html',\n 'htmlzip',\n 'epub',\n 'dbk',\n] as const;\n\n/** The bytes + metadata produced by a successful export. */\nexport interface ConversionResult {\n /** Encoded output bytes. */\n bytes: Uint8Array;\n /** MIME type of the output. */\n mimeType: string;\n /** A sensible download filename (`<baseName>.<ext>`). */\n suggestedFilename: string;\n /** Non-fatal notes accumulated during conversion (may be empty). */\n warnings: string[];\n}\n\nexport interface MarkdownFormatOptions {\n parse?: ParseOptions;\n stringify?: StringifyOptions;\n}\n\n/** Resource limits applied when importing a DBK/ZIP container. */\nexport type DbkFormatOptions = ZipSafetyLimits;\n\n/**\n * Strongly typed option bags for built-in formats. Import and export options\n * share a bag because a single conversion may use the format on either side.\n * Custom registries may add arbitrary keys through the intersection used by\n * {@link ConvertOptions.formatOptions}.\n */\nexport interface BuiltinFormatOptions {\n md: MarkdownFormatOptions;\n docx: DocxImportOptions & DocxExportOptions;\n pptx: PptxImportOptions & PptxExportOptions;\n xlsx: XlsxImportOptions & XlsxExportOptions;\n csv: CsvImportOptions & CsvExportOptions;\n pdf: PdfImportOptions & PdfExportOptions;\n html: HtmlImportOptions & Partial<Omit<HtmlExportOptions, 'playerScript'>>;\n htmlzip: Partial<Omit<HtmlExportOptions, 'playerScript'>>;\n epub: EpubExportOptions;\n dbk: DbkFormatOptions;\n}\n\n/**\n * A source normalized into every shape an exporter might need. `doc` is always\n * present; `markdownDoc` is present when the source was markdown-shaped (an\n * exporter that wants markdown but finds none derives it from `doc`).\n */\nexport interface NormalizedInput {\n doc: Doc;\n markdownDoc?: MarkdownDocument;\n container: ContentContainer;\n baseName: string;\n}\n\n/** Options threaded through `convert()` and into every format method. */\nexport interface ConvertOptions {\n /** Registry to resolve formats against. Defaults to `defaultRegistry()`. */\n registry?: FormatRegistry;\n /** Explicit source format id (skips extension/byte sniffing). */\n from?: FormatId;\n /** Theme id to apply to the exported document. */\n themeId?: string;\n /** Explicit caller-owned registry for non-document custom themes. */\n themeRegistry?: ThemeRegistry;\n /** Built-in/registry id or call-scoped style to apply before export. */\n transformStyle?: TransformStyleInput;\n /** Explicit caller-owned registry used to resolve transform style ids. */\n transformRegistry?: TransformStyleRegistry;\n /** Content-aware auto-templating when deriving a Doc from markdown. */\n autoTemplates?: boolean;\n /** Title hint for exporters that expose document metadata. */\n title?: string;\n /** Lazily resolve the standalone player IIFE bundle (required for HTML export). */\n resolvePlayerScript?: () => Promise<string>;\n /** Typed per-format options for built-ins; custom format ids remain extensible. */\n formatOptions?: Partial<BuiltinFormatOptions> & Record<FormatId, unknown>;\n}\n\n/** Describes how a single format imports to / exports from the squisq model. */\nexport interface FormatDefinition {\n id: FormatId;\n label: string;\n mimeType: string;\n extensions: readonly string[];\n /** Import raw bytes to a MarkdownDocument. */\n importDoc?(data: ArrayBuffer, options: ConvertOptions): Promise<MarkdownDocument>;\n /** Import raw bytes to a ContentContainer (markdown + extracted media). */\n importContainer?(data: ArrayBuffer, options: ConvertOptions): Promise<ContentContainer>;\n /** Export a normalized input to bytes. */\n exportDoc?(input: NormalizedInput, options: ConvertOptions): Promise<ConversionResult>;\n}\n\n/** A mutable collection of format definitions keyed by id. */\nexport interface FormatRegistry {\n register(def: FormatDefinition): void;\n get(id: FormatId): FormatDefinition | undefined;\n byExtension(ext: string): FormatDefinition | undefined;\n list(): FormatDefinition[];\n}\n\n/** The three shapes `convert()` accepts as a source. */\nexport type ConvertSource =\n | { kind: 'bytes'; data: ArrayBuffer | Uint8Array; filename?: string }\n | {\n kind: 'markdown';\n markdown: string | MarkdownDocument;\n container?: ContentContainer;\n baseName?: string;\n }\n | { kind: 'doc'; doc: Doc; container?: ContentContainer; baseName?: string };\n","/**\n * Shared Markdown fidelity reporting for exporters that intentionally support\n * only a subset of the core Markdown AST. Keeping the capability profiles in\n * one exhaustive table prevents each exporter from silently drifting as the\n * core AST grows.\n */\n\nimport type {\n MarkdownBlockNode,\n MarkdownDocument,\n MarkdownInlineNode,\n} from '@bendyline/squisq/markdown';\n\ntype ContentNodeType = MarkdownBlockNode['type'] | MarkdownInlineNode['type'];\nexport type MarkdownExportProfile = 'docx' | 'pdf' | 'pptx' | 'epub';\n\n/**\n * Exhaustive by construction: adding a Markdown node type in core makes this\n * package fail typechecking until its export fidelity is considered here.\n */\nconst CONTENT_NODE_TYPES: Record<ContentNodeType, true> = {\n heading: true,\n paragraph: true,\n blockquote: true,\n list: true,\n code: true,\n thematicBreak: true,\n table: true,\n htmlBlock: true,\n math: true,\n definition: true,\n footnoteDefinition: true,\n containerDirective: true,\n leafDirective: true,\n definitionList: true,\n text: true,\n emphasis: true,\n strong: true,\n delete: true,\n inlineCode: true,\n link: true,\n image: true,\n break: true,\n htmlInline: true,\n inlineMath: true,\n footnoteReference: true,\n linkReference: true,\n imageReference: true,\n textDirective: true,\n mention: true,\n inlineIcon: true,\n};\n\nconst COMMON_SUPPORTED: readonly ContentNodeType[] = [\n 'heading',\n 'paragraph',\n 'blockquote',\n 'list',\n 'code',\n 'thematicBreak',\n 'table',\n 'htmlBlock',\n 'math',\n 'text',\n 'emphasis',\n 'strong',\n 'delete',\n 'inlineCode',\n 'link',\n 'image',\n 'break',\n 'htmlInline',\n 'inlineMath',\n];\n\nconst PROFILE_SUPPORT: Record<MarkdownExportProfile, ReadonlySet<ContentNodeType>> = {\n docx: new Set([...COMMON_SUPPORTED, 'footnoteDefinition', 'footnoteReference']),\n pdf: new Set([...COMMON_SUPPORTED, 'footnoteDefinition', 'footnoteReference']),\n pptx: new Set(COMMON_SUPPORTED),\n epub: new Set(COMMON_SUPPORTED),\n};\n\nconst PROFILE_LABELS: Record<MarkdownExportProfile, string> = {\n docx: 'DOCX',\n pdf: 'PDF',\n pptx: 'PPTX',\n epub: 'EPUB',\n};\n\ninterface AstLikeNode {\n type?: string;\n children?: unknown;\n}\n\n/** Return a user-facing warning when an exporter will omit Markdown nodes. */\nexport function markdownFidelityWarnings(\n document: MarkdownDocument,\n profile: MarkdownExportProfile,\n): string[] {\n const supported = PROFILE_SUPPORT[profile];\n const omitted = new Map<ContentNodeType, number>();\n\n const visit = (candidate: unknown): void => {\n if (!candidate || typeof candidate !== 'object') return;\n const node = candidate as AstLikeNode;\n const type = node.type as ContentNodeType | undefined;\n\n if (type && Object.prototype.hasOwnProperty.call(CONTENT_NODE_TYPES, type)) {\n if (!supported.has(type)) {\n // The exporter drops this whole subtree, so report the highest-fidelity\n // boundary once instead of inflating the count with its descendants.\n omitted.set(type, (omitted.get(type) ?? 0) + 1);\n return;\n }\n }\n\n if (Array.isArray(node.children)) {\n for (const child of node.children) visit(child);\n }\n };\n\n for (const child of document.children) visit(child);\n if (omitted.size === 0) return [];\n\n const total = [...omitted.values()].reduce((sum, count) => sum + count, 0);\n const details = [...omitted].map(([type, count]) => `${type} (${count})`).join(', ');\n return [\n `${PROFILE_LABELS[profile]} export omitted ${total} unsupported Markdown node(s): ${details}.`,\n ];\n}\n","/**\n * Built-in format definitions.\n *\n * Each definition loads its converter module lazily via `import()` inside the\n * method body, so importing the registry never eagerly bundles a heavy\n * converter (pdf-lib, jszip, the OOXML writers, …). The capability of each\n * format — which of import/export it supports — is expressed purely by which\n * methods are present.\n */\n\nimport type { ContentContainer } from '@bendyline/squisq/storage';\nimport type { MarkdownDocument } from '@bendyline/squisq/markdown';\nimport { ConversionError } from './errors.js';\nimport { markdownFidelityWarnings } from '../shared/fidelity.js';\nimport type {\n ConversionResult,\n BuiltinFormatOptions,\n ConvertOptions,\n FormatDefinition,\n NormalizedInput,\n} from './types.js';\n\n// ── MIME constants ──────────────────────────────────────────────────\n\nconst MIME = {\n md: 'text/markdown',\n docx: 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',\n pdf: 'application/pdf',\n pptx: 'application/vnd.openxmlformats-officedocument.presentationml.presentation',\n xlsx: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',\n csv: 'text/csv',\n html: 'text/html',\n zip: 'application/zip',\n epub: 'application/epub+zip',\n} as const;\n\n// ── Small shared helpers ────────────────────────────────────────────\n\n/** Normalize any binary export return shape to Uint8Array. */\nasync function toBytes(data: ArrayBuffer | Uint8Array | Blob): Promise<Uint8Array> {\n if (data instanceof Uint8Array) return data;\n if (data instanceof ArrayBuffer) return new Uint8Array(data);\n // Blob. Prefer the modern arrayBuffer() method; fall back to FileReader for\n // environments (e.g. some jsdom builds) whose Blob lacks it.\n if (typeof data.arrayBuffer === 'function') {\n return new Uint8Array(await data.arrayBuffer());\n }\n const buffer = await new Promise<ArrayBuffer>((resolve, reject) => {\n const reader = new FileReader();\n reader.onload = () => resolve(reader.result as ArrayBuffer);\n reader.onerror = () => reject(reader.error);\n reader.readAsArrayBuffer(data);\n });\n return new Uint8Array(buffer);\n}\n\n/** The theme to apply: explicit option wins, then the doc's own theme. */\nfunction resolveThemeId(input: NormalizedInput, options: ConvertOptions): string | undefined {\n return options.themeId ?? input.doc.themeId;\n}\n\nfunction optionsFor<K extends keyof BuiltinFormatOptions>(\n options: ConvertOptions,\n id: K,\n): BuiltinFormatOptions[K] {\n return (options.formatOptions?.[id] ?? {}) as BuiltinFormatOptions[K];\n}\n\n/** The markdown shape an exporter needs — reuse the source's, else derive it. */\nasync function markdownOf(input: NormalizedInput): Promise<MarkdownDocument> {\n if (input.markdownDoc) return input.markdownDoc;\n const { docToMarkdown } = await import('@bendyline/squisq/doc');\n return docToMarkdown(input.doc);\n}\n\n/**\n * Collect image files from a container, keyed by both their container path and\n * their bare filename. Exporters that resolve by url (PPTX) and the standalone\n * player (HTML) both match against one of those two keys.\n */\nasync function collectContainerImages(\n container: ContentContainer,\n): Promise<Map<string, ArrayBuffer>> {\n const images = new Map<string, ArrayBuffer>();\n const files = await container.listFiles();\n for (const file of files) {\n if (!/\\.(jpg|jpeg|png|gif|webp|svg|bmp|avif)$/i.test(file.path)) continue;\n const data = await container.readFile(file.path);\n if (!data) continue;\n images.set(file.path, data);\n const slash = file.path.lastIndexOf('/');\n if (slash !== -1) images.set(file.path.slice(slash + 1), data);\n }\n return images;\n}\n\nasync function collectContainerDocxImages(\n container: ContentContainer,\n): Promise<Map<string, { data: ArrayBuffer; contentType: string }>> {\n const images = await collectContainerImages(container);\n const { extToMime } = await import('../shared/images.js');\n return new Map(\n [...images].map(([path, data]) => [\n path,\n { data, contentType: extToMime(path.split('.').pop() ?? '') },\n ]),\n );\n}\n\n/** Copy a container and make its primary document match the normalized source. */\nasync function snapshotContainerWithDocument(input: NormalizedInput): Promise<ContentContainer> {\n const { MemoryContentContainer } = await import('@bendyline/squisq/storage');\n const snapshot = new MemoryContentContainer();\n const entries = await input.container.listFiles();\n for (const entry of entries) {\n const data = await input.container.readFile(entry.path);\n if (data) await snapshot.writeFile(entry.path, new Uint8Array(data), entry.mimeType);\n }\n const { stringifyMarkdown } = await import('@bendyline/squisq/markdown');\n const documentPath = (await input.container.getDocumentPath()) ?? 'index.md';\n await snapshot.writeDocument(stringifyMarkdown(await markdownOf(input)), documentPath);\n return snapshot;\n}\n\n/** Resolve the player IIFE bundle or throw a helpful missing-dependency error. */\nasync function requirePlayerScript(options: ConvertOptions, format: string): Promise<string> {\n const script = await options.resolvePlayerScript?.();\n if (!script) {\n throw new ConversionError('missing-dependency', 'HTML export needs a player script.', {\n format,\n hint: \"pass resolvePlayerScript, e.g. () => import('@bendyline/squisq-react/standalone-source').then(m => m.PLAYER_BUNDLE)\",\n });\n }\n return script;\n}\n\nfunction ok(bytes: Uint8Array, mimeType: string, warnings: string[] = []): ConversionResult {\n // suggestedFilename is filled in by convert() once the baseName is known.\n return { bytes, mimeType, suggestedFilename: '', warnings };\n}\n\n/**\n * Narrow the untyped per-format escape hatch (`options.formatOptions.pptx`)\n * into the PPTX importer's options. Theme + layout inference default ON;\n * only an explicit `false` disables them.\n */\nfunction pptxImportOptionsFrom(options: ConvertOptions): BuiltinFormatOptions['pptx'] {\n const raw = optionsFor(options, 'pptx');\n return {\n ...raw,\n inferTheme: raw?.inferTheme !== false,\n inferLayouts: raw?.inferLayouts !== false,\n };\n}\n\n// ── Definitions ─────────────────────────────────────────────────────\n\nexport function defaultFormats(): FormatDefinition[] {\n const md: FormatDefinition = {\n id: 'md',\n label: 'Markdown',\n mimeType: MIME.md,\n extensions: ['.md', '.markdown'],\n async importDoc(data, options): Promise<MarkdownDocument> {\n const { parseMarkdown } = await import('@bendyline/squisq/markdown');\n return parseMarkdown(new TextDecoder().decode(data), optionsFor(options, 'md').parse);\n },\n async exportDoc(input, options): Promise<ConversionResult> {\n const { stringifyMarkdown } = await import('@bendyline/squisq/markdown');\n const text = stringifyMarkdown(await markdownOf(input), optionsFor(options, 'md').stringify);\n return ok(new TextEncoder().encode(text), MIME.md);\n },\n };\n\n const docx: FormatDefinition = {\n id: 'docx',\n label: 'Word (DOCX)',\n mimeType: MIME.docx,\n extensions: ['.docx'],\n async importContainer(data, options): Promise<ContentContainer> {\n const { docxToContainer } = await import('../docx/index.js');\n return docxToContainer(data, optionsFor(options, 'docx'));\n },\n async importDoc(data, options): Promise<MarkdownDocument> {\n const { docxToMarkdownDoc } = await import('../docx/index.js');\n return docxToMarkdownDoc(data, optionsFor(options, 'docx'));\n },\n async exportDoc(input, options): Promise<ConversionResult> {\n const { markdownDocToDocx } = await import('../docx/index.js');\n const raw = optionsFor(options, 'docx');\n const markdownDoc = await markdownOf(input);\n const containerImages = await collectContainerDocxImages(input.container);\n const images = new Map([...containerImages, ...(raw.images ?? new Map())]);\n const buf = await markdownDocToDocx(markdownDoc, {\n ...raw,\n ...(options.title !== undefined ? { title: options.title } : {}),\n themeId: resolveThemeId(input, options),\n themeRegistry: options.themeRegistry ?? raw.themeRegistry,\n images,\n });\n return ok(await toBytes(buf), MIME.docx, markdownFidelityWarnings(markdownDoc, 'docx'));\n },\n };\n\n const pdf: FormatDefinition = {\n id: 'pdf',\n label: 'PDF',\n mimeType: MIME.pdf,\n extensions: ['.pdf'],\n async importContainer(data, options): Promise<ContentContainer> {\n const { pdfToContainer } = await import('../pdf/index.js');\n return pdfToContainer(data, optionsFor(options, 'pdf'));\n },\n async importDoc(data, options): Promise<MarkdownDocument> {\n const { pdfToMarkdownDoc } = await import('../pdf/index.js');\n return pdfToMarkdownDoc(data, optionsFor(options, 'pdf'));\n },\n async exportDoc(input, options): Promise<ConversionResult> {\n const { markdownDocToPdf } = await import('../pdf/index.js');\n const raw = optionsFor(options, 'pdf');\n const markdownDoc = await markdownOf(input);\n const buf = await markdownDocToPdf(markdownDoc, {\n ...raw,\n ...(options.title !== undefined ? { title: options.title } : {}),\n themeId: resolveThemeId(input, options),\n themeRegistry: options.themeRegistry ?? raw.themeRegistry,\n });\n return ok(await toBytes(buf), MIME.pdf, markdownFidelityWarnings(markdownDoc, 'pdf'));\n },\n };\n\n const pptx: FormatDefinition = {\n id: 'pptx',\n label: 'PowerPoint (PPTX)',\n mimeType: MIME.pptx,\n extensions: ['.pptx'],\n async importContainer(data, options): Promise<ContentContainer> {\n const { pptxToContainer } = await import('../pptx/index.js');\n return pptxToContainer(data, pptxImportOptionsFrom(options));\n },\n async importDoc(data, options): Promise<MarkdownDocument> {\n const { pptxToMarkdownDoc } = await import('../pptx/index.js');\n return pptxToMarkdownDoc(data, pptxImportOptionsFrom(options));\n },\n async exportDoc(input, options): Promise<ConversionResult> {\n const { markdownDocToPptx } = await import('../pptx/index.js');\n const raw = optionsFor(options, 'pptx');\n const markdownDoc = await markdownOf(input);\n const containerImages = await collectContainerImages(input.container);\n const images = new Map([...containerImages, ...(raw.images ?? new Map())]);\n const buf = await markdownDocToPptx(markdownDoc, {\n ...raw,\n ...(options.title !== undefined ? { title: options.title } : {}),\n themeId: resolveThemeId(input, options),\n themeRegistry: options.themeRegistry ?? raw.themeRegistry,\n images,\n });\n return ok(await toBytes(buf), MIME.pptx, markdownFidelityWarnings(markdownDoc, 'pptx'));\n },\n };\n\n const xlsx: FormatDefinition = {\n id: 'xlsx',\n label: 'Excel (XLSX)',\n mimeType: MIME.xlsx,\n extensions: ['.xlsx'],\n async importDoc(data, options): Promise<MarkdownDocument> {\n const { xlsxToMarkdownDoc } = await import('../xlsx/index.js');\n return xlsxToMarkdownDoc(data, optionsFor(options, 'xlsx'));\n },\n async exportDoc(input, options): Promise<ConversionResult> {\n const { markdownDocToXlsx } = await import('../xlsx/index.js');\n const markdownDoc = await markdownOf(input);\n // XLSX fidelity is tables-only: `table` nodes become worksheets and\n // headings name them, but every other top-level block (prose, lists,\n // images, code, …) is dropped. Count those and warn honestly.\n const omitted = markdownDoc.children.filter(\n (n) => n.type !== 'table' && n.type !== 'heading',\n ).length;\n const warnings =\n omitted > 0\n ? [`XLSX export is tables-only; ${omitted} non-table block(s) were omitted.`]\n : [];\n const blob = await markdownDocToXlsx(markdownDoc, {\n ...optionsFor(options, 'xlsx'),\n ...(options.title !== undefined ? { title: options.title } : {}),\n });\n return ok(await toBytes(blob), MIME.xlsx, warnings);\n },\n };\n\n const csv: FormatDefinition = {\n id: 'csv',\n label: 'CSV',\n mimeType: MIME.csv,\n extensions: ['.csv'],\n async importDoc(data, options): Promise<MarkdownDocument> {\n const { csvToMarkdownDoc } = await import('../csv/index.js');\n return csvToMarkdownDoc(data, optionsFor(options, 'csv'));\n },\n async exportDoc(input, options): Promise<ConversionResult> {\n const { markdownDocToCsv } = await import('../csv/index.js');\n const markdownDoc = await markdownOf(input);\n const raw = optionsFor(options, 'csv');\n const tableCount = markdownDoc.children.filter((n) => n.type === 'table').length;\n const warnings: string[] = [];\n if (tableCount > 1 && raw.tableIndex === undefined) {\n warnings.push(\n `Document has ${tableCount} tables; CSV export emitted only the first. Use the csv converter's tableIndex option to select another.`,\n );\n }\n const text = markdownDocToCsv(markdownDoc, raw);\n return ok(new TextEncoder().encode(text), MIME.csv, warnings);\n },\n };\n\n const html: FormatDefinition = {\n id: 'html',\n label: 'HTML (single file)',\n mimeType: MIME.html,\n extensions: ['.html', '.htm'],\n async importDoc(data, options): Promise<MarkdownDocument> {\n const { htmlToMarkdownDoc } = await import('../html/index.js');\n return htmlToMarkdownDoc(data, optionsFor(options, 'html'));\n },\n // importContainer omitted: HTML import already inlines images as data URIs,\n // so there is nothing to extract into a container this wave.\n async exportDoc(input, options): Promise<ConversionResult> {\n const playerScript = await requirePlayerScript(options, 'html');\n const { docToHtml } = await import('../html/index.js');\n const raw = optionsFor(options, 'html');\n const containerImages = await collectContainerImages(input.container);\n const images = new Map([...containerImages, ...(raw.images ?? new Map())]);\n const htmlText = docToHtml(input.doc, {\n ...raw,\n playerScript,\n images,\n title: options.title ?? input.baseName,\n mode: raw.mode ?? 'static',\n themeId: resolveThemeId(input, options),\n themeRegistry: options.themeRegistry ?? raw.themeRegistry,\n });\n return ok(new TextEncoder().encode(htmlText), MIME.html);\n },\n };\n\n const htmlzip: FormatDefinition = {\n id: 'htmlzip',\n label: 'HTML (ZIP archive)',\n mimeType: MIME.zip,\n extensions: ['.html.zip'],\n async exportDoc(input, options): Promise<ConversionResult> {\n const playerScript = await requirePlayerScript(options, 'htmlzip');\n const { docToHtmlZip } = await import('../html/index.js');\n const raw = optionsFor(options, 'htmlzip');\n const containerImages = await collectContainerImages(input.container);\n const images = new Map([...containerImages, ...(raw.images ?? new Map())]);\n const blob = await docToHtmlZip(input.doc, {\n ...raw,\n playerScript,\n images,\n title: options.title ?? input.baseName,\n mode: raw.mode ?? 'static',\n themeId: resolveThemeId(input, options),\n themeRegistry: options.themeRegistry ?? raw.themeRegistry,\n });\n return ok(await toBytes(blob), MIME.zip);\n },\n };\n\n const epub: FormatDefinition = {\n id: 'epub',\n label: 'EPUB',\n mimeType: MIME.epub,\n extensions: ['.epub'],\n async exportDoc(input, options): Promise<ConversionResult> {\n const { markdownDocToEpub } = await import('../epub/index.js');\n const raw = optionsFor(options, 'epub');\n const markdownDoc = await markdownOf(input);\n const containerImages = await collectContainerImages(input.container);\n const images = new Map([...containerImages, ...(raw.images ?? new Map())]);\n const buf = await markdownDocToEpub(markdownDoc, {\n ...raw,\n title: options.title ?? input.baseName,\n themeId: resolveThemeId(input, options),\n themeRegistry: options.themeRegistry ?? raw.themeRegistry,\n images,\n });\n return ok(await toBytes(buf), MIME.epub, markdownFidelityWarnings(markdownDoc, 'epub'));\n },\n };\n\n const dbk: FormatDefinition = {\n id: 'dbk',\n label: 'Squisq container (DBK)',\n mimeType: MIME.zip,\n extensions: ['.dbk', '.zip'],\n async importContainer(data, options): Promise<ContentContainer> {\n const { zipToContainer } = await import('../container/index.js');\n return zipToContainer(data, optionsFor(options, 'dbk'));\n },\n async exportDoc(input): Promise<ConversionResult> {\n const { containerToZip } = await import('../container/index.js');\n const blob = await containerToZip(await snapshotContainerWithDocument(input));\n return ok(await toBytes(blob), MIME.zip);\n },\n };\n\n return [md, docx, pdf, pptx, xlsx, csv, html, htmlzip, epub, dbk];\n}\n","/**\n * Format registry implementation.\n *\n * `createRegistry()` returns an empty, mutable registry (last-write-wins by id);\n * `defaultRegistry()` returns one preloaded with every built-in format.\n */\n\nimport type { FormatDefinition, FormatId, FormatRegistry } from './types.js';\nimport { defaultFormats } from './defaultFormats.js';\n\n/** Normalize an extension to lowercase, without a leading dot. */\nfunction normalizeExt(ext: string): string {\n return ext.replace(/^\\.+/, '').toLowerCase();\n}\n\n/** Create an empty registry. Registering an existing id overwrites it. */\nexport function createRegistry(): FormatRegistry {\n const byId = new Map<FormatId, FormatDefinition>();\n\n return {\n register(def: FormatDefinition): void {\n byId.set(def.id, def);\n },\n get(id: FormatId): FormatDefinition | undefined {\n return byId.get(id);\n },\n byExtension(ext: string): FormatDefinition | undefined {\n const target = normalizeExt(ext);\n if (!target) return undefined;\n for (const def of byId.values()) {\n if (def.extensions.some((e) => normalizeExt(e) === target)) return def;\n }\n return undefined;\n },\n list(): FormatDefinition[] {\n return [...byId.values()];\n },\n };\n}\n\n/** Create a registry preloaded with all built-in formats. */\nexport function defaultRegistry(): FormatRegistry {\n const registry = createRegistry();\n for (const def of defaultFormats()) {\n registry.register(def);\n }\n return registry;\n}\n","/**\n * Programmatic `convert()` — the format-registry front door.\n *\n * Normalizes any {@link ConvertSource} into a {@link NormalizedInput} (always\n * yielding a `Doc`, keeping the `MarkdownDocument` when the source was\n * markdown-shaped, and always carrying a `ContentContainer` for media), applies\n * an optional transform, then hands off to the target format's exporter.\n */\n\nimport type { MarkdownDocument } from '@bendyline/squisq/markdown';\nimport type { ContentContainer } from '@bendyline/squisq/storage';\nimport type { TransformStyleInput, TransformStyleRegistry } from '@bendyline/squisq/transform';\nimport { ConversionError } from './errors.js';\nimport { defaultRegistry } from './registry.js';\nimport { openBoundedZipArchive, ZipSafetyError } from '../shared/zipSafety.js';\nimport type {\n BuiltinFormatOptions,\n ConversionResult,\n ConvertOptions,\n ConvertSource,\n FormatDefinition,\n FormatId,\n FormatRegistry,\n NormalizedInput,\n} from './types.js';\n\nfunction markdownFormatOptions(options: ConvertOptions): BuiltinFormatOptions['md'] {\n return (options.formatOptions?.md ?? {}) as BuiltinFormatOptions['md'];\n}\n\n// ── Byte sniffing ───────────────────────────────────────────────────\n\nfunction hasPrefix(bytes: Uint8Array, prefix: number[]): boolean {\n if (bytes.length < prefix.length) return false;\n for (let i = 0; i < prefix.length; i++) {\n if (bytes[i] !== prefix[i]) return false;\n }\n return true;\n}\n\nconst ZIP_MAGIC = [0x50, 0x4b, 0x03, 0x04]; // \"PK\\x03\\x04\"\nconst PDF_MAGIC = [0x25, 0x50, 0x44, 0x46]; // \"%PDF\"\n\n/**\n * Disambiguate a ZIP-based file. OOXML formats (docx/pptx/xlsx) all carry a\n * `[Content_Types].xml` whose content-type strings name the flavor; a squisq\n * container (.dbk) is a plain ZIP with no such part, so absence of the OOXML\n * marker means `dbk`.\n */\nasync function sniffZip(bytes: Uint8Array): Promise<FormatId> {\n const archive = await openBoundedZipArchive(bytes).catch((cause: unknown) => {\n if (cause instanceof ZipSafetyError && cause.code !== 'invalid-archive') throw cause;\n throw new ConversionError('invalid-input', 'Input is not a readable ZIP archive.', { cause });\n });\n const contentTypes = archive.entries.find((entry) => entry.path === '[Content_Types].xml');\n if (!contentTypes) return 'dbk';\n const maxContentTypesBytes = 1024 * 1024;\n if ((contentTypes.declaredSize ?? 0) > maxContentTypesBytes) {\n throw new ConversionError('invalid-input', 'OOXML content-types metadata is too large.');\n }\n const xmlBytes = await archive.read(contentTypes.path, maxContentTypesBytes);\n if (!xmlBytes) return 'dbk';\n const xml = new TextDecoder().decode(xmlBytes);\n if (xml.includes('wordprocessingml')) return 'docx';\n if (xml.includes('presentationml')) return 'pptx';\n if (xml.includes('spreadsheetml')) return 'xlsx';\n return 'dbk';\n}\n\n/** Determine the source format for raw bytes. */\nasync function detectByteFormat(\n bytes: Uint8Array,\n filename: string | undefined,\n options: ConvertOptions,\n registry: FormatRegistry,\n): Promise<FormatId> {\n if (options.from) return options.from;\n\n const ext = filename ? extractExt(filename) : undefined;\n if (ext) {\n const byExt = registry.byExtension(ext);\n if (byExt) return byExt.id;\n }\n\n if (hasPrefix(bytes, PDF_MAGIC)) return 'pdf';\n if (hasPrefix(bytes, ZIP_MAGIC)) return sniffZip(bytes);\n\n // No magic and no recognized extension → assume UTF-8 markdown.\n return 'md';\n}\n\n// ── Filename helpers ────────────────────────────────────────────────\n\n/** Lowercased extension without the leading dot (`report.DocX` → `docx`). */\nfunction extractExt(filename: string): string {\n const normalized = filename.replace(/\\\\/g, '/');\n const base = normalized.split('/').pop() ?? normalized;\n const dot = base.lastIndexOf('.');\n if (dot <= 0) return '';\n return base.slice(dot + 1).toLowerCase();\n}\n\n/** Basename without its final extension (`a/b/report.docx` → `report`). */\nfunction baseNameOf(filename: string): string {\n const normalized = filename.replace(/\\\\/g, '/');\n const base = normalized.split('/').pop() ?? normalized;\n const dot = base.lastIndexOf('.');\n return dot > 0 ? base.slice(0, dot) : base;\n}\n\n// ── Normalization ───────────────────────────────────────────────────\n\ninterface Normalized {\n input: NormalizedInput;\n warnings: string[];\n}\n\nasync function normalizeBytes(\n source: Extract<ConvertSource, { kind: 'bytes' }>,\n options: ConvertOptions,\n registry: FormatRegistry,\n): Promise<Normalized> {\n const bytes = source.data instanceof Uint8Array ? source.data : new Uint8Array(source.data);\n const buffer = bytes.buffer.slice(\n bytes.byteOffset,\n bytes.byteOffset + bytes.byteLength,\n ) as ArrayBuffer;\n\n const fromId = await detectByteFormat(bytes, source.filename, options, registry);\n const fromDef = registry.get(fromId);\n if (!fromDef) {\n throw new ConversionError('unknown-format', `Unknown source format \"${fromId}\".`, {\n format: fromId,\n });\n }\n if (!fromDef.importContainer && !fromDef.importDoc) {\n throw new ConversionError(\n 'unsupported-input',\n `Format \"${fromDef.label}\" cannot be used as a conversion source.`,\n {\n format: fromId,\n hint: 'This format is export-only.',\n },\n );\n }\n\n const { markdownToDoc } = await import('@bendyline/squisq/doc');\n const { parseMarkdown, stringifyMarkdown } = await import('@bendyline/squisq/markdown');\n\n const warnings: string[] = [];\n let markdownDoc: MarkdownDocument;\n let container: ContentContainer;\n\n if (fromDef.importContainer) {\n container = await fromDef.importContainer(buffer, options);\n // PDF embedded-image extraction needs a browser canvas; under Node it's\n // skipped inside pdfToContainer. importContainer has no warnings channel of\n // its own, so surface that degraded path here where warnings are collected.\n if (fromDef.id === 'pdf' && typeof document === 'undefined') {\n warnings.push(\n 'PDF embedded images were skipped — image decoding requires a browser canvas (running under Node).',\n );\n }\n const text = await container.readDocument();\n markdownDoc = text\n ? parseMarkdown(text, markdownFormatOptions(options).parse)\n : { type: 'document', children: [] };\n } else {\n // importDoc is guaranteed present by the guard above.\n markdownDoc = await fromDef.importDoc!(buffer, options);\n const { MemoryContentContainer } = await import('@bendyline/squisq/storage');\n const mem = new MemoryContentContainer();\n await mem.writeDocument(stringifyMarkdown(markdownDoc));\n container = mem;\n }\n\n const doc = markdownToDoc(markdownDoc, { autoTemplates: options.autoTemplates });\n const baseName = source.filename ? baseNameOf(source.filename) : 'document';\n\n return {\n input: { doc, markdownDoc, container, baseName },\n warnings,\n };\n}\n\nasync function normalizeMarkdown(\n source: Extract<ConvertSource, { kind: 'markdown' }>,\n options: ConvertOptions,\n): Promise<Normalized> {\n const { markdownToDoc } = await import('@bendyline/squisq/doc');\n const { parseMarkdown } = await import('@bendyline/squisq/markdown');\n\n const { stringifyMarkdown } = await import('@bendyline/squisq/markdown');\n\n const markdownDoc =\n typeof source.markdown === 'string'\n ? parseMarkdown(source.markdown, markdownFormatOptions(options).parse)\n : source.markdown;\n\n let container = source.container;\n if (!container) {\n // Seed a fresh container with the document so container-backed exports\n // (dbk) and media resolution have the markdown to serialize.\n const { MemoryContentContainer } = await import('@bendyline/squisq/storage');\n const mem = new MemoryContentContainer();\n await mem.writeDocument(stringifyMarkdown(markdownDoc));\n container = mem;\n }\n\n const doc = markdownToDoc(markdownDoc, { autoTemplates: options.autoTemplates });\n const baseName = source.baseName ?? 'document';\n\n return { input: { doc, markdownDoc, container, baseName }, warnings: [] };\n}\n\nasync function normalizeDoc(source: Extract<ConvertSource, { kind: 'doc' }>): Promise<Normalized> {\n let container = source.container;\n if (!container) {\n const { MemoryContentContainer } = await import('@bendyline/squisq/storage');\n const { docToMarkdown } = await import('@bendyline/squisq/doc');\n const { stringifyMarkdown } = await import('@bendyline/squisq/markdown');\n const mem = new MemoryContentContainer();\n await mem.writeDocument(stringifyMarkdown(docToMarkdown(source.doc)));\n container = mem;\n }\n const baseName = source.baseName ?? 'document';\n // markdownDoc is intentionally omitted — exporters derive it lazily via docToMarkdown.\n return { input: { doc: source.doc, container, baseName }, warnings: [] };\n}\n\nasync function normalize(\n source: ConvertSource,\n options: ConvertOptions,\n registry: FormatRegistry,\n): Promise<Normalized> {\n switch (source.kind) {\n case 'bytes':\n return normalizeBytes(source, options, registry);\n case 'markdown':\n return normalizeMarkdown(source, options);\n case 'doc':\n return normalizeDoc(source);\n }\n}\n\n// ── Transform ───────────────────────────────────────────────────────\n\nasync function applyTransformStyle(\n input: NormalizedInput,\n transformStyle: TransformStyleInput,\n themeId?: string,\n registry?: TransformStyleRegistry,\n): Promise<string[]> {\n const { applyTransform, extractDocImages } = await import('@bendyline/squisq/transform');\n const { docToMarkdown, markdownToDoc } = await import('@bendyline/squisq/doc');\n const images = extractDocImages(input.doc.blocks);\n const result = applyTransform(input.doc, transformStyle, { themeId, images, registry });\n input.doc = result.doc;\n const markdownDoc = docToMarkdown(result.doc);\n input.markdownDoc = markdownDoc;\n\n // Lossy-path detection: transforms can emit template blocks whose data lives\n // in template inputs rather than in round-trippable markdown `contents`, so\n // `docToMarkdown` silently drops them. Re-parse with auto-templating off (so\n // the comparison stays ~1:1 and isn't confused by content-aware promotion)\n // and compare block counts. Best-effort — most blocks carry `contents` and\n // round-trip fine, so this only fires on a genuine collapse.\n const roundTripped = markdownToDoc(markdownDoc, { autoTemplates: false });\n if (roundTripped.blocks.length < result.doc.blocks.length) {\n return [\n 'Transform produced blocks that don’t round-trip to markdown; export may be incomplete.',\n ];\n }\n return [];\n}\n\n// ── convert() ───────────────────────────────────────────────────────\n\n/**\n * Convert a source document to a target format.\n *\n * @param source - A bytes / markdown / doc source.\n * @param to - The target format id (must be registered and support export).\n * @param options - Conversion options (registry, theme, transform, …).\n * @throws {@link ConversionError} on any failure, with a stable `code`.\n */\nexport async function convert(\n source: ConvertSource,\n to: FormatId,\n options: ConvertOptions = {},\n): Promise<ConversionResult> {\n const registry = options.registry ?? defaultRegistry();\n\n const target: FormatDefinition | undefined = registry.get(to);\n if (!target) {\n throw new ConversionError('unknown-format', `Unknown target format \"${to}\".`, { format: to });\n }\n if (!target.exportDoc) {\n throw new ConversionError(\n 'unsupported-output',\n `Format \"${target.label}\" does not support export.`,\n { format: to, hint: 'This format is import-only.' },\n );\n }\n\n let normalized: Normalized;\n try {\n normalized = await normalize(source, options, registry);\n } catch (err: unknown) {\n if (err instanceof ConversionError) throw err;\n const message = err instanceof Error ? err.message : String(err);\n throw new ConversionError('invalid-input', message, {\n format: options.from,\n cause: err,\n });\n }\n const { input, warnings } = normalized;\n\n // Respect an existing doc theme; only fill it in from options when absent.\n if (options.themeId && !input.doc.themeId) {\n input.doc = { ...input.doc, themeId: options.themeId };\n }\n\n let result: ConversionResult;\n try {\n if (options.transformStyle) {\n warnings.push(\n ...(await applyTransformStyle(\n input,\n options.transformStyle,\n options.themeId ?? input.doc.themeId,\n options.transformRegistry,\n )),\n );\n }\n result = await target.exportDoc(input, options);\n } catch (err: unknown) {\n if (err instanceof ConversionError) throw err;\n const message = err instanceof Error ? err.message : String(err);\n throw new ConversionError('conversion-failed', message, { format: to, cause: err });\n }\n\n const ext = target.extensions[0]?.replace(/^\\.+/, '') ?? to;\n return {\n ...result,\n suggestedFilename: `${input.baseName}.${ext}`,\n warnings: [...warnings, ...result.warnings],\n };\n}\n"],"mappings":";;;;;;;;;AAiCO,IAAM,qBAAqB;AAAA,EAChC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAA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