@bendyline/squisq-formats 1.3.0 → 1.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (224) hide show
  1. package/dist/chunk-6M7Z25LA.js +46 -0
  2. package/dist/chunk-6M7Z25LA.js.map +1 -0
  3. package/dist/{chunk-S3Y7H2BK.js → chunk-APSIAEXL.js} +9 -8
  4. package/dist/chunk-APSIAEXL.js.map +1 -0
  5. package/dist/{chunk-UDS45KUJ.js → chunk-BJQIJ4S4.js} +36 -52
  6. package/dist/chunk-BJQIJ4S4.js.map +1 -0
  7. package/dist/{chunk-33YRFXZZ.js → chunk-CRTC6DEX.js} +259 -13
  8. package/dist/chunk-CRTC6DEX.js.map +1 -0
  9. package/dist/chunk-FMOIGA5T.js +201 -0
  10. package/dist/chunk-FMOIGA5T.js.map +1 -0
  11. package/dist/{chunk-VN2KEOYB.js → chunk-I2GFTEOV.js} +321 -91
  12. package/dist/chunk-I2GFTEOV.js.map +1 -0
  13. package/dist/chunk-JBNVE2GV.js +116 -0
  14. package/dist/chunk-JBNVE2GV.js.map +1 -0
  15. package/dist/chunk-L53YIGYS.js +141 -0
  16. package/dist/chunk-L53YIGYS.js.map +1 -0
  17. package/dist/{chunk-ERZ627GR.js → chunk-ON232HJR.js} +11 -26
  18. package/dist/chunk-ON232HJR.js.map +1 -0
  19. package/dist/chunk-PN52A5AA.js +32 -0
  20. package/dist/chunk-PN52A5AA.js.map +1 -0
  21. package/dist/{chunk-7DEUGIOO.js → chunk-QSE7EWE7.js} +12 -87
  22. package/dist/chunk-QSE7EWE7.js.map +1 -0
  23. package/dist/container/index.d.ts +7 -5
  24. package/dist/container/index.js +39 -70
  25. package/dist/container/index.js.map +1 -1
  26. package/dist/csv/index.d.ts +37 -0
  27. package/dist/csv/index.js +13 -0
  28. package/dist/csv/index.js.map +1 -0
  29. package/dist/docx/index.d.ts +128 -15
  30. package/dist/docx/index.js +19 -22
  31. package/dist/docx/index.js.map +1 -1
  32. package/dist/epub/index.d.ts +66 -11
  33. package/dist/epub/index.js +11 -18
  34. package/dist/epub/index.js.map +1 -1
  35. package/dist/html/index.d.ts +315 -15
  36. package/dist/html/index.js +32 -165
  37. package/dist/html/index.js.map +1 -1
  38. package/dist/index.d.ts +10 -38
  39. package/dist/index.js +80 -37
  40. package/dist/index.js.map +1 -1
  41. package/dist/ooxml/index.d.ts +353 -14
  42. package/dist/ooxml/index.js +116 -22
  43. package/dist/ooxml/index.js.map +1 -1
  44. package/dist/pdf/index.d.ts +143 -17
  45. package/dist/pdf/index.js +16 -25
  46. package/dist/pdf/index.js.map +1 -1
  47. package/dist/pptx/index.d.ts +98 -21
  48. package/dist/pptx/index.js +18 -34
  49. package/dist/pptx/index.js.map +1 -1
  50. package/dist/xlsx/index.d.ts +29 -25
  51. package/dist/xlsx/index.js +13 -44
  52. package/dist/xlsx/index.js.map +1 -1
  53. package/package.json +7 -2
  54. package/src/__tests__/csvImport.test.ts +51 -0
  55. package/src/__tests__/exportThemeReconciliation.test.ts +87 -0
  56. package/src/__tests__/htmlImport.test.ts +57 -0
  57. package/src/__tests__/plainHtml.test.ts +31 -0
  58. package/src/__tests__/pptxExport.test.ts +138 -0
  59. package/src/__tests__/pptxImport.test.ts +70 -0
  60. package/src/__tests__/roundTripMatrix.fixtures.ts +86 -0
  61. package/src/__tests__/roundTripMatrix.helpers.ts +154 -0
  62. package/src/__tests__/roundTripMatrix.test.ts +136 -0
  63. package/src/__tests__/xlsxImport.test.ts +80 -0
  64. package/src/csv/index.ts +165 -0
  65. package/src/docx/export.ts +27 -44
  66. package/src/docx/import.ts +1 -2
  67. package/src/epub/export.ts +10 -27
  68. package/src/html/import.ts +297 -0
  69. package/src/html/index.ts +4 -0
  70. package/src/html/plainHtml.ts +66 -16
  71. package/src/index.ts +10 -3
  72. package/src/ooxml/namespaces.ts +3 -0
  73. package/src/pdf/export.ts +10 -5
  74. package/src/pdf/import.ts +1 -1
  75. package/src/pptx/export.ts +225 -85
  76. package/src/pptx/import.ts +156 -0
  77. package/src/pptx/index.ts +10 -28
  78. package/src/shared/inlineRuns.ts +99 -0
  79. package/src/shared/text.ts +41 -0
  80. package/src/xlsx/import.ts +159 -0
  81. package/src/xlsx/index.ts +11 -28
  82. package/dist/__tests__/container.test.d.ts +0 -8
  83. package/dist/__tests__/container.test.d.ts.map +0 -1
  84. package/dist/__tests__/container.test.js +0 -147
  85. package/dist/__tests__/container.test.js.map +0 -1
  86. package/dist/__tests__/docxExport.test.d.ts +0 -8
  87. package/dist/__tests__/docxExport.test.d.ts.map +0 -1
  88. package/dist/__tests__/docxExport.test.js +0 -383
  89. package/dist/__tests__/docxExport.test.js.map +0 -1
  90. package/dist/__tests__/docxImport.test.d.ts +0 -8
  91. package/dist/__tests__/docxImport.test.d.ts.map +0 -1
  92. package/dist/__tests__/docxImport.test.js +0 -309
  93. package/dist/__tests__/docxImport.test.js.map +0 -1
  94. package/dist/__tests__/epub.test.d.ts +0 -8
  95. package/dist/__tests__/epub.test.d.ts.map +0 -1
  96. package/dist/__tests__/epub.test.js +0 -472
  97. package/dist/__tests__/epub.test.js.map +0 -1
  98. package/dist/__tests__/html.test.d.ts +0 -8
  99. package/dist/__tests__/html.test.d.ts.map +0 -1
  100. package/dist/__tests__/html.test.js +0 -317
  101. package/dist/__tests__/html.test.js.map +0 -1
  102. package/dist/__tests__/ooxml.test.d.ts +0 -5
  103. package/dist/__tests__/ooxml.test.d.ts.map +0 -1
  104. package/dist/__tests__/ooxml.test.js +0 -152
  105. package/dist/__tests__/ooxml.test.js.map +0 -1
  106. package/dist/__tests__/pdfExport.test.d.ts +0 -8
  107. package/dist/__tests__/pdfExport.test.d.ts.map +0 -1
  108. package/dist/__tests__/pdfExport.test.js +0 -275
  109. package/dist/__tests__/pdfExport.test.js.map +0 -1
  110. package/dist/__tests__/pdfImport.test.d.ts +0 -11
  111. package/dist/__tests__/pdfImport.test.d.ts.map +0 -1
  112. package/dist/__tests__/pdfImport.test.js +0 -254
  113. package/dist/__tests__/pdfImport.test.js.map +0 -1
  114. package/dist/__tests__/plainHtml.test.d.ts +0 -5
  115. package/dist/__tests__/plainHtml.test.d.ts.map +0 -1
  116. package/dist/__tests__/plainHtml.test.js +0 -327
  117. package/dist/__tests__/plainHtml.test.js.map +0 -1
  118. package/dist/__tests__/plainHtmlBundle.test.d.ts +0 -11
  119. package/dist/__tests__/plainHtmlBundle.test.d.ts.map +0 -1
  120. package/dist/__tests__/plainHtmlBundle.test.js +0 -210
  121. package/dist/__tests__/plainHtmlBundle.test.js.map +0 -1
  122. package/dist/__tests__/roundTrip.test.d.ts +0 -7
  123. package/dist/__tests__/roundTrip.test.d.ts.map +0 -1
  124. package/dist/__tests__/roundTrip.test.js +0 -173
  125. package/dist/__tests__/roundTrip.test.js.map +0 -1
  126. package/dist/chunk-33YRFXZZ.js.map +0 -1
  127. package/dist/chunk-67KIJHV2.js +0 -21
  128. package/dist/chunk-67KIJHV2.js.map +0 -1
  129. package/dist/chunk-7DEUGIOO.js.map +0 -1
  130. package/dist/chunk-ERZ627GR.js.map +0 -1
  131. package/dist/chunk-S3Y7H2BK.js.map +0 -1
  132. package/dist/chunk-UDS45KUJ.js.map +0 -1
  133. package/dist/chunk-VN2KEOYB.js.map +0 -1
  134. package/dist/chunk-YN5HFCEW.js +0 -120
  135. package/dist/chunk-YN5HFCEW.js.map +0 -1
  136. package/dist/container/index.d.ts.map +0 -1
  137. package/dist/docx/export.d.ts +0 -69
  138. package/dist/docx/export.d.ts.map +0 -1
  139. package/dist/docx/export.js +0 -985
  140. package/dist/docx/export.js.map +0 -1
  141. package/dist/docx/import.d.ts +0 -65
  142. package/dist/docx/import.d.ts.map +0 -1
  143. package/dist/docx/import.js +0 -779
  144. package/dist/docx/import.js.map +0 -1
  145. package/dist/docx/index.d.ts.map +0 -1
  146. package/dist/docx/styles.d.ts +0 -68
  147. package/dist/docx/styles.d.ts.map +0 -1
  148. package/dist/docx/styles.js +0 -125
  149. package/dist/docx/styles.js.map +0 -1
  150. package/dist/epub/export.d.ts +0 -72
  151. package/dist/epub/export.d.ts.map +0 -1
  152. package/dist/epub/export.js +0 -698
  153. package/dist/epub/export.js.map +0 -1
  154. package/dist/epub/index.d.ts.map +0 -1
  155. package/dist/html/docsHtmlBundle.d.ts +0 -53
  156. package/dist/html/docsHtmlBundle.d.ts.map +0 -1
  157. package/dist/html/docsHtmlBundle.js +0 -299
  158. package/dist/html/docsHtmlBundle.js.map +0 -1
  159. package/dist/html/htmlTemplate.d.ts +0 -70
  160. package/dist/html/htmlTemplate.d.ts.map +0 -1
  161. package/dist/html/htmlTemplate.js +0 -282
  162. package/dist/html/htmlTemplate.js.map +0 -1
  163. package/dist/html/imageUtils.d.ts +0 -29
  164. package/dist/html/imageUtils.d.ts.map +0 -1
  165. package/dist/html/imageUtils.js +0 -63
  166. package/dist/html/imageUtils.js.map +0 -1
  167. package/dist/html/index.d.ts.map +0 -1
  168. package/dist/html/plainHtml.d.ts +0 -79
  169. package/dist/html/plainHtml.d.ts.map +0 -1
  170. package/dist/html/plainHtml.js +0 -614
  171. package/dist/html/plainHtml.js.map +0 -1
  172. package/dist/html/plainHtmlBundle.d.ts +0 -93
  173. package/dist/html/plainHtmlBundle.d.ts.map +0 -1
  174. package/dist/html/plainHtmlBundle.js +0 -357
  175. package/dist/html/plainHtmlBundle.js.map +0 -1
  176. package/dist/index.d.ts.map +0 -1
  177. package/dist/ooxml/index.d.ts.map +0 -1
  178. package/dist/ooxml/namespaces.d.ts +0 -77
  179. package/dist/ooxml/namespaces.d.ts.map +0 -1
  180. package/dist/ooxml/namespaces.js +0 -104
  181. package/dist/ooxml/namespaces.js.map +0 -1
  182. package/dist/ooxml/reader.d.ts +0 -52
  183. package/dist/ooxml/reader.d.ts.map +0 -1
  184. package/dist/ooxml/reader.js +0 -190
  185. package/dist/ooxml/reader.js.map +0 -1
  186. package/dist/ooxml/types.d.ts +0 -82
  187. package/dist/ooxml/types.d.ts.map +0 -1
  188. package/dist/ooxml/types.js +0 -9
  189. package/dist/ooxml/types.js.map +0 -1
  190. package/dist/ooxml/writer.d.ts +0 -71
  191. package/dist/ooxml/writer.d.ts.map +0 -1
  192. package/dist/ooxml/writer.js +0 -200
  193. package/dist/ooxml/writer.js.map +0 -1
  194. package/dist/ooxml/xmlUtils.d.ts +0 -76
  195. package/dist/ooxml/xmlUtils.d.ts.map +0 -1
  196. package/dist/ooxml/xmlUtils.js +0 -108
  197. package/dist/ooxml/xmlUtils.js.map +0 -1
  198. package/dist/pdf/export.d.ts +0 -56
  199. package/dist/pdf/export.d.ts.map +0 -1
  200. package/dist/pdf/export.js +0 -768
  201. package/dist/pdf/export.js.map +0 -1
  202. package/dist/pdf/import.d.ts +0 -94
  203. package/dist/pdf/import.d.ts.map +0 -1
  204. package/dist/pdf/import.js +0 -796
  205. package/dist/pdf/import.js.map +0 -1
  206. package/dist/pdf/index.d.ts.map +0 -1
  207. package/dist/pdf/styles.d.ts +0 -142
  208. package/dist/pdf/styles.d.ts.map +0 -1
  209. package/dist/pdf/styles.js +0 -145
  210. package/dist/pdf/styles.js.map +0 -1
  211. package/dist/pptx/export.d.ts +0 -75
  212. package/dist/pptx/export.d.ts.map +0 -1
  213. package/dist/pptx/export.js +0 -724
  214. package/dist/pptx/export.js.map +0 -1
  215. package/dist/pptx/index.d.ts.map +0 -1
  216. package/dist/pptx/styles.d.ts +0 -54
  217. package/dist/pptx/styles.d.ts.map +0 -1
  218. package/dist/pptx/styles.js +0 -73
  219. package/dist/pptx/styles.js.map +0 -1
  220. package/dist/pptx/templates.d.ts +0 -24
  221. package/dist/pptx/templates.d.ts.map +0 -1
  222. package/dist/pptx/templates.js +0 -158
  223. package/dist/pptx/templates.js.map +0 -1
  224. package/dist/xlsx/index.d.ts.map +0 -1
@@ -1,23 +1,136 @@
1
+ import { Doc } from '@bendyline/squisq/schemas';
2
+ import { MarkdownDocument } from '@bendyline/squisq/markdown';
3
+ import { ContentContainer } from '@bendyline/squisq/storage';
4
+
1
5
  /**
2
- * @bendyline/squisq-formats DOCX Module
6
+ * DOCX Export
3
7
  *
4
- * Import and export squisq documents (MarkdownDocument / Doc)
5
- * to/from Microsoft Word .docx files (Office Open XML WordprocessingML).
8
+ * Converts a squisq MarkdownDocument (or Doc) into a .docx file
9
+ * by generating WordprocessingML XML and assembling the OOXML package.
6
10
  *
7
- * All operations run in the browser no server required.
11
+ * No third-party docx library all XML is generated directly using
12
+ * the shared ooxml/ infrastructure of this package.
8
13
  *
9
14
  * @example
10
15
  * ```ts
11
- * import {
12
- * markdownDocToDocx,
13
- * docToDocx,
14
- * docxToMarkdownDoc,
15
- * docxToDoc,
16
- * } from '@bendyline/squisq-formats/docx';
16
+ * import { parseMarkdown } from '@bendyline/squisq/markdown';
17
+ * import { markdownDocToDocx } from '@bendyline/squisq-formats/docx';
18
+ *
19
+ * const md = parseMarkdown('# Hello\n\nWorld **bold** text');
20
+ * const blob = await markdownDocToDocx(md);
21
+ * ```
22
+ */
23
+
24
+ /**
25
+ * Options for DOCX export.
26
+ */
27
+ interface DocxExportOptions {
28
+ /** Document title (appears in core properties) */
29
+ title?: string;
30
+ /** Document author */
31
+ author?: string;
32
+ /** Document description */
33
+ description?: string;
34
+ /** Default body font family. Default: "Calibri" */
35
+ defaultFont?: string;
36
+ /** Default body font size in points. Default: 11 */
37
+ defaultFontSize?: number;
38
+ /**
39
+ * Squisq theme ID to apply (e.g., 'documentary', 'cinematic').
40
+ * When set, overrides fonts with the theme's typography and applies
41
+ * the theme's primary color to headings.
42
+ */
43
+ themeId?: string;
44
+ /**
45
+ * Pre-resolved image data keyed by image URL/path as it appears in the
46
+ * markdown source. When provided, images are embedded in the .docx file
47
+ * as binary parts instead of emitting placeholder text.
48
+ */
49
+ images?: Map<string, {
50
+ data: ArrayBuffer | Uint8Array;
51
+ contentType: string;
52
+ }>;
53
+ }
54
+ /**
55
+ * Convert a MarkdownDocument to a .docx Blob.
56
+ *
57
+ * @param doc - The parsed markdown document
58
+ * @param options - Export options
59
+ * @returns An ArrayBuffer containing the .docx file
60
+ */
61
+ declare function markdownDocToDocx(doc: MarkdownDocument, options?: DocxExportOptions): Promise<ArrayBuffer>;
62
+ /**
63
+ * Convert a squisq Doc to a .docx Blob.
64
+ *
65
+ * Convenience wrapper that converts Doc → MarkdownDocument → DOCX.
66
+ *
67
+ * @param doc - The squisq Doc
68
+ * @param options - Export options
69
+ * @returns An ArrayBuffer containing the .docx file
70
+ */
71
+ declare function docToDocx(doc: Doc, options?: DocxExportOptions): Promise<ArrayBuffer>;
72
+
73
+ /**
74
+ * DOCX Import
75
+ *
76
+ * Parses a .docx file (Office Open XML WordprocessingML) and converts
77
+ * its content into a squisq MarkdownDocument (or Doc).
78
+ *
79
+ * Uses JSZip + DOMParser to read the archive and parse the XML — no
80
+ * third-party docx library. Handles headings, paragraphs, inline
81
+ * formatting (bold, italic, strikethrough), hyperlinks, lists, tables,
82
+ * blockquotes, code blocks, images, and footnotes.
83
+ *
84
+ * @example
85
+ * ```ts
86
+ * import { docxToMarkdownDoc } from '@bendyline/squisq-formats/docx';
87
+ *
88
+ * const response = await fetch('document.docx');
89
+ * const data = await response.arrayBuffer();
90
+ * const doc = await docxToMarkdownDoc(data);
17
91
  * ```
18
92
  */
19
- export { markdownDocToDocx, docToDocx } from './export.js';
20
- export type { DocxExportOptions } from './export.js';
21
- export { docxToMarkdownDoc, docxToDoc, docxToContainer } from './import.js';
22
- export type { DocxImportOptions } from './import.js';
23
- //# sourceMappingURL=index.d.ts.map
93
+
94
+ /**
95
+ * Options for DOCX import.
96
+ */
97
+ interface DocxImportOptions {
98
+ /**
99
+ * Whether to extract embedded images as base64 data URIs.
100
+ * When false, images are represented as `[Image]` placeholders.
101
+ * Default: false
102
+ */
103
+ extractImages?: boolean;
104
+ }
105
+ /**
106
+ * Convert a .docx file to a MarkdownDocument.
107
+ *
108
+ * @param data - The raw .docx file as ArrayBuffer or Blob
109
+ * @param options - Import options
110
+ * @returns A MarkdownDocument representing the document content
111
+ */
112
+ declare function docxToMarkdownDoc(data: ArrayBuffer | Blob, options?: DocxImportOptions): Promise<MarkdownDocument>;
113
+ /**
114
+ * Convert a .docx file to a squisq Doc.
115
+ *
116
+ * Convenience wrapper: DOCX → MarkdownDocument → Doc.
117
+ *
118
+ * @param data - The raw .docx file as ArrayBuffer or Blob
119
+ * @param options - Import options
120
+ * @returns A squisq Doc
121
+ */
122
+ declare function docxToDoc(data: ArrayBuffer | Blob, options?: DocxImportOptions): Promise<Doc>;
123
+ /**
124
+ * Convert a .docx file to a ContentContainer with markdown + extracted images.
125
+ *
126
+ * The container will contain:
127
+ * - The primary markdown document (index.md)
128
+ * - Any embedded images under images/ (e.g., images/image1.png)
129
+ *
130
+ * @param data - The raw .docx file as ArrayBuffer or Blob
131
+ * @param options - Import options
132
+ * @returns A ContentContainer with the document and its media
133
+ */
134
+ declare function docxToContainer(data: ArrayBuffer | Blob, options?: DocxImportOptions): Promise<ContentContainer>;
135
+
136
+ export { type DocxExportOptions, type DocxImportOptions, docToDocx, docxToContainer, docxToDoc, docxToMarkdownDoc, markdownDocToDocx };
@@ -1,23 +1,20 @@
1
- /**
2
- * @bendyline/squisq-formats DOCX Module
3
- *
4
- * Import and export squisq documents (MarkdownDocument / Doc)
5
- * to/from Microsoft Word .docx files (Office Open XML WordprocessingML).
6
- *
7
- * All operations run in the browser — no server required.
8
- *
9
- * @example
10
- * ```ts
11
- * import {
12
- * markdownDocToDocx,
13
- * docToDocx,
14
- * docxToMarkdownDoc,
15
- * docxToDoc,
16
- * } from '@bendyline/squisq-formats/docx';
17
- * ```
18
- */
19
- // Export
20
- export { markdownDocToDocx, docToDocx } from './export.js';
21
- // Import
22
- export { docxToMarkdownDoc, docxToDoc, docxToContainer } from './import.js';
1
+ import {
2
+ docToDocx,
3
+ docxToContainer,
4
+ docxToDoc,
5
+ docxToMarkdownDoc,
6
+ markdownDocToDocx
7
+ } from "../chunk-BJQIJ4S4.js";
8
+ import "../chunk-6M7Z25LA.js";
9
+ import "../chunk-PN52A5AA.js";
10
+ import "../chunk-QSE7EWE7.js";
11
+ import "../chunk-U4MRIFKL.js";
12
+ import "../chunk-FMOIGA5T.js";
13
+ export {
14
+ docToDocx,
15
+ docxToContainer,
16
+ docxToDoc,
17
+ docxToMarkdownDoc,
18
+ markdownDocToDocx
19
+ };
23
20
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/docx/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,SAAS;AACT,OAAO,EAAE,iBAAiB,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAG3D,SAAS;AACT,OAAO,EAAE,iBAAiB,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC"}
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -1,20 +1,75 @@
1
+ import { AudioSegment, Doc } from '@bendyline/squisq/schemas';
2
+ import { MarkdownDocument } from '@bendyline/squisq/markdown';
3
+
1
4
  /**
2
- * @bendyline/squisq-formats EPUB Module
5
+ * EPUB 3 Export
3
6
  *
4
- * Export squisq documents (MarkdownDocument / Doc) to EPUB 3 e-book files.
7
+ * Converts a MarkdownDocument (or Doc) to an EPUB 3 file (.epub).
5
8
  *
6
- * Content is split into chapters at H1/H2 heading boundaries. Images
7
- * referenced in the markdown are embedded in the archive when provided
8
- * via the `images` option.
9
+ * An EPUB is a ZIP archive containing XHTML chapter files, images,
10
+ * a package manifest (content.opf), and a navigation document (toc.xhtml).
11
+ * Content is split into chapters at H1/H2 heading boundaries.
12
+ *
13
+ * Uses JSZip for packaging (already a dependency), escapeXml from the
14
+ * OOXML utils, and image utilities from the HTML exporter.
9
15
  *
10
16
  * @example
11
17
  * ```ts
12
- * import { markdownDocToEpub, docToEpub } from '@bendyline/squisq-formats/epub';
18
+ * import { markdownDocToEpub } from '@bendyline/squisq-formats/epub';
13
19
  *
14
- * const epub = await markdownDocToEpub(markdownDoc, { title: 'My Book' });
15
- * const epub2 = await docToEpub(doc, { author: 'Jane Doe' });
20
+ * const epub = await markdownDocToEpub(markdownDoc, {
21
+ * title: 'My Book',
22
+ * author: 'Jane Doe',
23
+ * });
16
24
  * ```
17
25
  */
18
- export { markdownDocToEpub, docToEpub } from './export.js';
19
- export type { EpubExportOptions } from './export.js';
20
- //# sourceMappingURL=index.d.ts.map
26
+
27
+ interface EpubExportOptions {
28
+ /** Book title (default: 'Untitled') */
29
+ title?: string;
30
+ /** Author name */
31
+ author?: string;
32
+ /** Book description / summary */
33
+ description?: string;
34
+ /** BCP-47 language code (default: 'en') */
35
+ language?: string;
36
+ /** Publisher name */
37
+ publisher?: string;
38
+ /** Squisq theme ID for CSS styling */
39
+ themeId?: string;
40
+ /** Pre-resolved image data keyed by relative path as it appears in the markdown */
41
+ images?: Map<string, ArrayBuffer>;
42
+ /** Cover image data (JPEG or PNG) */
43
+ coverImage?: ArrayBuffer;
44
+ /**
45
+ * Audio narration data keyed by segment src/name.
46
+ * When provided alongside audioSegments, EPUB 3 Media Overlays (SMIL)
47
+ * are generated for synchronized audio playback.
48
+ */
49
+ audio?: Map<string, ArrayBuffer>;
50
+ /**
51
+ * Audio segment metadata (from Doc.audio.segments).
52
+ * Required together with `audio` to generate Media Overlays.
53
+ * Each segment's duration and startTime are used to build SMIL timing.
54
+ */
55
+ audioSegments?: AudioSegment[];
56
+ /** Total document duration in seconds (used for Media Overlay metadata) */
57
+ totalDuration?: number;
58
+ }
59
+ /**
60
+ * Convert a MarkdownDocument to an EPUB 3 file.
61
+ *
62
+ * Chapters are split at H1/H2 heading boundaries. All referenced images
63
+ * (provided via `options.images`) are embedded in the archive.
64
+ */
65
+ declare function markdownDocToEpub(doc: MarkdownDocument, options?: EpubExportOptions): Promise<ArrayBuffer>;
66
+ /**
67
+ * Convert a squisq Doc to an EPUB 3 file.
68
+ *
69
+ * Convenience wrapper: Doc → MarkdownDocument → EPUB.
70
+ * When the Doc has audio segments and `options.audio` is provided,
71
+ * EPUB 3 Media Overlays are generated for narrated playback.
72
+ */
73
+ declare function docToEpub(doc: Doc, options?: EpubExportOptions): Promise<ArrayBuffer>;
74
+
75
+ export { type EpubExportOptions, docToEpub, markdownDocToEpub };
@@ -1,19 +1,12 @@
1
- /**
2
- * @bendyline/squisq-formats EPUB Module
3
- *
4
- * Export squisq documents (MarkdownDocument / Doc) to EPUB 3 e-book files.
5
- *
6
- * Content is split into chapters at H1/H2 heading boundaries. Images
7
- * referenced in the markdown are embedded in the archive when provided
8
- * via the `images` option.
9
- *
10
- * @example
11
- * ```ts
12
- * import { markdownDocToEpub, docToEpub } from '@bendyline/squisq-formats/epub';
13
- *
14
- * const epub = await markdownDocToEpub(markdownDoc, { title: 'My Book' });
15
- * const epub2 = await docToEpub(doc, { author: 'Jane Doe' });
16
- * ```
17
- */
18
- export { markdownDocToEpub, docToEpub } from './export.js';
1
+ import {
2
+ docToEpub,
3
+ markdownDocToEpub
4
+ } from "../chunk-ON232HJR.js";
5
+ import "../chunk-PN52A5AA.js";
6
+ import "../chunk-U4MRIFKL.js";
7
+ import "../chunk-A3FHLTY5.js";
8
+ export {
9
+ docToEpub,
10
+ markdownDocToEpub
11
+ };
19
12
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/epub/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,EAAE,iBAAiB,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC"}
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -1,3 +1,312 @@
1
+ import { Doc, Theme } from '@bendyline/squisq/schemas';
2
+ import { HtmlPolicy, MarkdownDocument } from '@bendyline/squisq/markdown';
3
+
4
+ /**
5
+ * HTML Template Generation for SquisqPlayer Exports
6
+ *
7
+ * Generates complete, self-contained HTML documents that load the SquisqPlayer
8
+ * IIFE bundle and render a Doc as either an interactive slideshow or a static
9
+ * scrollable document.
10
+ *
11
+ * Two variants:
12
+ * 1. **Inline** — All JS, CSS, and images are embedded in the HTML (single file).
13
+ * 2. **External** — JS is referenced via `<script src>`, images via relative paths.
14
+ */
15
+
16
+ interface HtmlExportOptions {
17
+ /** The IIFE player bundle source code (from @bendyline/squisq-react/standalone-source) */
18
+ playerScript: string;
19
+ /**
20
+ * Map of relative image paths (as they appear in the Doc) to binary image data.
21
+ * For inline HTML export, these are converted to base64 data URIs.
22
+ * For ZIP export, these are written as separate files.
23
+ */
24
+ images?: Map<string, ArrayBuffer>;
25
+ /**
26
+ * Map of audio segment identifiers to binary audio data.
27
+ * Keys should match the audio segment `name` or `url` fields in the Doc.
28
+ * Only used in ZIP exports — single HTML uses timer-based playback.
29
+ */
30
+ audio?: Map<string, ArrayBuffer>;
31
+ /** Rendering mode: 'slideshow' (interactive, default) or 'static' (scrollable) */
32
+ mode?: 'slideshow' | 'static';
33
+ /** HTML page title (default: 'Squisq Document') */
34
+ title?: string;
35
+ /** Auto-play slideshow on load (default: false) */
36
+ autoPlay?: boolean;
37
+ /**
38
+ * Squisq theme ID to apply (e.g., 'documentary', 'cinematic').
39
+ * When set, the theme is assigned to the Doc before rendering,
40
+ * so the SquisqPlayer renders with that theme's colors and typography.
41
+ */
42
+ themeId?: string;
43
+ }
44
+ /**
45
+ * Collect all relative image paths referenced in a Doc's layers and template blocks.
46
+ * Returns a Set of unique relative paths that need to be resolved.
47
+ */
48
+ declare function collectImagePaths(doc: Doc): Set<string>;
49
+
50
+ /**
51
+ * Image Utilities for HTML Export
52
+ *
53
+ * Browser-compatible helpers for converting image data to base64 data URIs
54
+ * and inferring MIME types from filenames.
55
+ */
56
+ /**
57
+ * Infer a MIME type from a filename's extension.
58
+ * Returns 'application/octet-stream' for unknown types.
59
+ */
60
+ declare function inferMimeType(filename: string): string;
61
+ /**
62
+ * Convert an ArrayBuffer to a base64-encoded data URI string.
63
+ *
64
+ * @param buffer - The binary image data
65
+ * @param mimeType - MIME type (e.g., 'image/jpeg'). If not provided, defaults to
66
+ * 'application/octet-stream'.
67
+ * @returns A `data:` URI string
68
+ */
69
+ declare function arrayBufferToBase64DataUrl(buffer: ArrayBuffer, mimeType: string): string;
70
+ /**
71
+ * Extract the filename from a path or URL (strips directory and query).
72
+ *
73
+ * @example
74
+ * extractFilename('images/hero.jpg') // 'hero.jpg'
75
+ * extractFilename('https://example.com/photo.png?v=2') // 'photo.png'
76
+ */
77
+ declare function extractFilename(path: string): string;
78
+
79
+ /**
80
+ * Plain HTML Export — semantic, player-free
81
+ *
82
+ * Renders a MarkdownDocument to a self-contained HTML string. Unlike
83
+ * `docToHtml` (which bundles the SquisqPlayer IIFE and renders SVG block
84
+ * cards), this output is what a reader-mode tool would produce: semantic
85
+ * `<h1>`/`<p>`/`<ul>`/etc. with a small embedded stylesheet, no JS, no
86
+ * runtime path-rewriting. Drives both the "Page" preview tab in the
87
+ * editor and the plain-style branch of the export dialog so what users
88
+ * see live matches the file they download.
89
+ *
90
+ * Image URLs default to the markdown's own paths. Pass `images` to
91
+ * substitute a different value per source URL — typically pre-resolved
92
+ * blob URLs (live preview) or data URIs (single-file export).
93
+ */
94
+
95
+ interface PlainHtmlExportOptions {
96
+ /** Document title — populates `<title>` and is HTML-escaped. */
97
+ title?: string;
98
+ /**
99
+ * Substitution map for image `src` URLs. Keys are the URL exactly as
100
+ * it appears in the markdown source; values are the URL to emit in
101
+ * the rendered `<img src>`. URLs not present in the map fall through
102
+ * unchanged (so external `https://…` references still work).
103
+ */
104
+ images?: Map<string, string>;
105
+ /**
106
+ * Substitution map for anchor `href` URLs. Keys are the URL exactly
107
+ * as it appears in the markdown source (e.g. `'resume.md'`,
108
+ * `'resume.md#experience'`); values are the URL to emit. URLs not in
109
+ * the map pass through unchanged. Used by the recursive bundle
110
+ * exporter to rewrite `.md` references to `.html` so a static export
111
+ * of a linked document tree is internally browsable.
112
+ */
113
+ links?: Map<string, string>;
114
+ /**
115
+ * Optional Squisq theme. When provided, the rendered page uses the
116
+ * theme's colors and typography, and any Google-hosted fonts the
117
+ * theme references are loaded via a `<link>` to fonts.googleapis.com
118
+ * so the face renders correctly without host preloads.
119
+ *
120
+ * When omitted, the function falls back (in order) to {@link themeId}
121
+ * and then to `doc.frontmatter.themeId` — so an authored
122
+ * `themeId: warm-earth` in the doc's frontmatter styles the export
123
+ * automatically, without the caller having to wire theme resolution
124
+ * themselves.
125
+ */
126
+ theme?: Theme;
127
+ /**
128
+ * Optional theme id (e.g. `'warm-earth'`, `'gezellig'`). Convenient
129
+ * for hosts whose export dialog tracks themes by id — they can pass
130
+ * the id straight through instead of resolving to a `Theme` object.
131
+ * When both `theme` and `themeId` are provided, `theme` wins.
132
+ */
133
+ themeId?: string;
134
+ /**
135
+ * Optional FontAwesome CSS text to inline into the rendered page,
136
+ * replacing the default cross-origin `<link>` to cdnjs. Required for
137
+ * sandboxed iframe previews where tracking prevention or stricter
138
+ * origin policies can silently drop cross-origin font fetches —
139
+ * inlining keeps the icons resolvable purely from same-origin
140
+ * resources. Hosts typically gather this string by scraping
141
+ * `document.styleSheets` for `@font-face` rules whose family starts
142
+ * with `"Font Awesome"`. The CDN `<link>` is only emitted when this
143
+ * option is not provided.
144
+ */
145
+ iconsCss?: string;
146
+ /**
147
+ * Raw HTML policy. Defaults to `sanitize`, which removes unsafe tags,
148
+ * event handlers, and executable URL schemes before emitting HTML.
149
+ */
150
+ htmlPolicy?: HtmlPolicy;
151
+ }
152
+ /**
153
+ * Render a parsed markdown document as a complete, semantic HTML page.
154
+ *
155
+ * When `options.theme` is provided, the output adopts the theme's
156
+ * colors and typography. Google-hosted fonts referenced by the theme
157
+ * are loaded via a single `<link>` to fonts.googleapis.com so the page
158
+ * renders consistently when opened standalone.
159
+ */
160
+ declare function markdownDocToPlainHtml(doc: MarkdownDocument, options?: PlainHtmlExportOptions): string;
161
+
162
+ /**
163
+ * Recursive plain-HTML bundle export.
164
+ *
165
+ * `markdownDocsToPlainHtmlBundle` starts from a single entry markdown
166
+ * file, walks its relative `[…](other.md)` links, recursively pulls in
167
+ * any sibling/child documents (scope-limited to the entry doc's
168
+ * directory tree), renders every visited file via
169
+ * `markdownDocToPlainHtml`, rewrites cross-doc references from `.md`
170
+ * to `.html`, and ships everything as a single ZIP.
171
+ *
172
+ * The function is provider-agnostic — callers pass `readDocument` and
173
+ * `readBinary` callbacks that resolve relative paths against whatever
174
+ * storage they use (`FileSystemContentContainer`, `MemoryContent-
175
+ * Container`, in-memory map for tests, …). Failure to read any
176
+ * discovered file aborts the whole export with a thrown error.
177
+ */
178
+
179
+ interface PlainHtmlBundleOptions {
180
+ /** Entry document path relative to the container root (e.g. `'home.md'`). */
181
+ entryPath: string;
182
+ /** Reads a UTF-8 markdown file from the container. Returns null when absent. */
183
+ readDocument: (path: string) => Promise<string | null>;
184
+ /** Reads a binary asset (image) from the container. Returns null when absent. */
185
+ readBinary: (path: string) => Promise<ArrayBuffer | null>;
186
+ /** Optional document title for the entry. Others derive from filename. */
187
+ title?: string;
188
+ /** Optional theme applied uniformly to every page. Overrides {@link themeId}. */
189
+ theme?: Theme;
190
+ /**
191
+ * Optional theme id (e.g. `'warm-earth'`, `'gezellig'`). Resolved via
192
+ * `resolveTheme` and applied to every page. Convenient for callers
193
+ * that track themes by id (like the host export dialog) without
194
+ * having to resolve to a `Theme` object first. When both `theme` and
195
+ * `themeId` are supplied, `theme` wins.
196
+ */
197
+ themeId?: string;
198
+ /** Maximum recursion depth (default: unlimited; cycles always handled). */
199
+ maxDepth?: number;
200
+ /**
201
+ * Emit the entry doc as `index.html` (preserving its parent directory)
202
+ * instead of `<basename>.html`. Cross-doc links pointing at the entry
203
+ * also rewrite to `index.html`, so a sibling `resume.md → home.md`
204
+ * link doesn't 404 after the rename. Convenient for static-site
205
+ * deploys where the landing page must be named `index.html`.
206
+ * Default: false.
207
+ */
208
+ entryAsIndex?: boolean;
209
+ }
210
+ /**
211
+ * Render an entry markdown document and every reachable sibling/child
212
+ * `.md` document it links to, bundled as a single ZIP with plain-HTML
213
+ * pages, per-document asset folders, and cross-doc `<a href>`
214
+ * references rewritten from `.md` to `.html`.
215
+ */
216
+ declare function markdownDocsToPlainHtmlBundle(options: PlainHtmlBundleOptions): Promise<Blob>;
217
+ /**
218
+ * Collect every `<a>`-style link URL referenced in a document. Markdown
219
+ * `link` nodes plus any raw HTML `<a href>` tags. Returns the raw URLs
220
+ * as authored, so callers can use them as both the linkMap *key* and
221
+ * the basis for resolution.
222
+ */
223
+ declare function collectLinkRefs(doc: MarkdownDocument): Set<string>;
224
+
225
+ /**
226
+ * Recursive rendered-HTML bundle export.
227
+ *
228
+ * `markdownDocsToHtmlBundle` is the rendered-pipeline counterpart of
229
+ * `markdownDocsToPlainHtmlBundle`. Starting from a single entry markdown
230
+ * file, it walks every relative `[…](other.md)` link, builds a Doc for
231
+ * each visited page via `markdownToDoc`, rewrites cross-doc link URLs
232
+ * inside the Doc tree from `.md` → relative `.html`, then renders each
233
+ * Doc to a SquisqPlayer-backed HTML page sharing one `squisq-player.js`.
234
+ * Images preserve their authored relative paths so per-doc folders
235
+ * (`resume_files/hero.png`, etc.) sit beside the rendered HTML.
236
+ *
237
+ * The rewrite happens on the Doc, *before* JSON serialization, because
238
+ * the rendered HTML embeds the Doc as JSON and SquisqPlayer emits the
239
+ * `<a href>` at runtime — there is no post-render link rewrite hook in
240
+ * the player path.
241
+ */
242
+ interface HtmlBundleOptions {
243
+ /** Entry document path relative to the container root (e.g. `'home.md'`). */
244
+ entryPath: string;
245
+ /** Reads a UTF-8 markdown file from the container. Returns null when absent. */
246
+ readDocument: (path: string) => Promise<string | null>;
247
+ /** Reads a binary asset (image) from the container. Returns null when absent. */
248
+ readBinary: (path: string) => Promise<ArrayBuffer | null>;
249
+ /** SquisqPlayer IIFE bundle. Written once as `squisq-player.js` in the zip. */
250
+ playerScript: string;
251
+ /** Optional document title for the entry. Other pages derive from filename. */
252
+ title?: string;
253
+ /** Theme id applied uniformly to every page. */
254
+ themeId?: string;
255
+ /** Rendering mode for every page (default: 'static' — scrollable, link-friendly). */
256
+ mode?: 'slideshow' | 'static';
257
+ /** Maximum recursion depth (default: unlimited; cycles always handled). */
258
+ maxDepth?: number;
259
+ /**
260
+ * Emit the entry doc as `index.html` (preserving its parent directory)
261
+ * instead of `<basename>.html`. Cross-doc links pointing at the entry
262
+ * also rewrite to `index.html`, so a sibling `resume.md → home.md`
263
+ * link doesn't 404 after the rename. Convenient for static-site
264
+ * deploys where the landing page must be named `index.html`.
265
+ * Default: false.
266
+ */
267
+ entryAsIndex?: boolean;
268
+ }
269
+ /**
270
+ * Render an entry markdown document and every reachable sibling/child
271
+ * `.md` document it links to, bundled as a single ZIP with one rendered
272
+ * HTML page per doc, per-document asset folders, a shared
273
+ * `squisq-player.js`, and cross-doc `<a href>` references rewritten
274
+ * from `.md` to `.html` inside each Doc's serialized AST.
275
+ */
276
+ declare function markdownDocsToHtmlBundle(options: HtmlBundleOptions): Promise<Blob>;
277
+
278
+ /**
279
+ * HTML Import Module — @bendyline/squisq-formats/html
280
+ *
281
+ * Converts an HTML document (or fragment) into a squisq `MarkdownDocument`.
282
+ * Built on the existing `parseHtmlToNodes` (parse5-backed) + `sanitizeHtmlNodes`
283
+ * from `@bendyline/squisq/markdown`, so no new dependency is introduced.
284
+ *
285
+ * The primary consumer is email: HTML mail bodies are hostile input, so the
286
+ * parse is sanitized by default (scripts/styles/event handlers/dangerous URLs
287
+ * stripped) before the tree is walked into markdown nodes.
288
+ *
289
+ * Two entry points mirror the docx/pdf importers:
290
+ * - `htmlToMarkdownDoc(data, options?)` → `MarkdownDocument`
291
+ * - `htmlToMarkdown(html, options?)` → markdown string (convenience for the
292
+ * string-in/string-out path email body conversion needs)
293
+ */
294
+
295
+ interface HtmlImportOptions {
296
+ /**
297
+ * Strip scripts / styles / event handlers / dangerous URLs before walking
298
+ * the tree. Default `true` — HTML email is untrusted; only disable for
299
+ * trusted input where you want raw fidelity.
300
+ */
301
+ sanitize?: boolean;
302
+ }
303
+ /** Parse HTML into a squisq `MarkdownDocument`. */
304
+ declare function htmlToMarkdownDocSync(html: string, options?: HtmlImportOptions): MarkdownDocument;
305
+ /** Async, ArrayBuffer-accepting entry mirroring docx/pdf importers. */
306
+ declare function htmlToMarkdownDoc(data: ArrayBuffer | Uint8Array | string, options?: HtmlImportOptions): Promise<MarkdownDocument>;
307
+ /** Convenience string→string conversion (used for email HTML bodies). */
308
+ declare function htmlToMarkdown(html: string, options?: HtmlImportOptions): string;
309
+
1
310
  /**
2
311
  * HTML Export Module — @bendyline/squisq-formats/html
3
312
  *
@@ -28,10 +337,8 @@
28
337
  * const zipBlob = await docToHtmlZip(doc, { playerScript: PLAYER_BUNDLE, images, audio });
29
338
  * ```
30
339
  */
31
- import type { Doc } from '@bendyline/squisq/schemas';
32
- import { type HtmlExportOptions } from './htmlTemplate.js';
33
- export type { HtmlExportOptions };
34
- export interface HtmlZipExportOptions extends HtmlExportOptions {
340
+
341
+ interface HtmlZipExportOptions extends HtmlExportOptions {
35
342
  /**
36
343
  * Map of audio segment identifiers to binary audio data.
37
344
  * Keys should match the audio segment `name` or `url` fields in the Doc.
@@ -60,7 +367,7 @@ export interface HtmlZipExportOptions extends HtmlExportOptions {
60
367
  * const blob = new Blob([html], { type: 'text/html' });
61
368
  * ```
62
369
  */
63
- export declare function docToHtml(doc: Doc, options: HtmlExportOptions): string;
370
+ declare function docToHtml(doc: Doc, options: HtmlExportOptions): string;
64
371
  /**
65
372
  * Export a Doc as a ZIP archive containing HTML, JS, images, and optionally audio.
66
373
  *
@@ -92,13 +399,6 @@ export declare function docToHtml(doc: Doc, options: HtmlExportOptions): string;
92
399
  * const url = URL.createObjectURL(blob);
93
400
  * ```
94
401
  */
95
- export declare function docToHtmlZip(doc: Doc, options: HtmlZipExportOptions): Promise<Blob>;
96
- export { collectImagePaths } from './htmlTemplate.js';
97
- export { inferMimeType, arrayBufferToBase64DataUrl, extractFilename } from './imageUtils.js';
98
- export { markdownDocToPlainHtml } from './plainHtml.js';
99
- export type { PlainHtmlExportOptions } from './plainHtml.js';
100
- export { markdownDocsToPlainHtmlBundle, collectLinkRefs } from './plainHtmlBundle.js';
101
- export type { PlainHtmlBundleOptions } from './plainHtmlBundle.js';
102
- export { markdownDocsToHtmlBundle } from './docsHtmlBundle.js';
103
- export type { HtmlBundleOptions } from './docsHtmlBundle.js';
104
- //# sourceMappingURL=index.d.ts.map
402
+ declare function docToHtmlZip(doc: Doc, options: HtmlZipExportOptions): Promise<Blob>;
403
+
404
+ export { type HtmlBundleOptions, type HtmlExportOptions, type HtmlImportOptions, type HtmlZipExportOptions, type PlainHtmlBundleOptions, type PlainHtmlExportOptions, arrayBufferToBase64DataUrl, collectImagePaths, collectLinkRefs, docToHtml, docToHtmlZip, extractFilename, htmlToMarkdown, htmlToMarkdownDoc, htmlToMarkdownDocSync, inferMimeType, markdownDocToPlainHtml, markdownDocsToHtmlBundle, markdownDocsToPlainHtmlBundle };