@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,26 +1,152 @@
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 PDF Module
6
+ * PDF Export
3
7
  *
4
- * Import and export squisq documents (MarkdownDocument / Doc)
5
- * to/from PDF files.
8
+ * Converts a squisq MarkdownDocument (or Doc) into a PDF file
9
+ * using pdf-lib. Generates paginated, styled output with support for
10
+ * headings, paragraphs, inline formatting, lists, code blocks,
11
+ * blockquotes, tables, thematic breaks, and hyperlinks.
6
12
  *
7
- * - **Export** uses pdf-lib (zero dependencies, standard fonts, pure JS).
8
- * - **Import** uses pdfjs-dist (Mozilla pdf.js) with heuristic structure detection.
13
+ * Uses only the 14 standard PDF fonts (no font embedding required),
14
+ * keeping output size small and rendering fast.
9
15
  *
10
- * All operations run in the browser — no server required.
16
+ * @example
17
+ * ```ts
18
+ * import { parseMarkdown } from '@bendyline/squisq/markdown';
19
+ * import { markdownDocToPdf } from '@bendyline/squisq-formats/pdf';
20
+ *
21
+ * const md = parseMarkdown('# Hello\n\nWorld **bold** text');
22
+ * const buffer = await markdownDocToPdf(md);
23
+ * ```
24
+ */
25
+
26
+ /** Page size presets. */
27
+ type PdfPageSize = 'letter' | 'a4';
28
+ /**
29
+ * Options for PDF export.
30
+ */
31
+ interface PdfExportOptions {
32
+ /** Document title (PDF metadata). */
33
+ title?: string;
34
+ /** Document author (PDF metadata). */
35
+ author?: string;
36
+ /** Page size preset. Default: "letter". */
37
+ pageSize?: PdfPageSize;
38
+ /** Page margins in points. Default: 72 (1 inch). */
39
+ margin?: number;
40
+ /** Default body font size in points. Default: 11. */
41
+ defaultFontSize?: number;
42
+ /**
43
+ * Squisq theme ID to apply (e.g., 'documentary', 'cinematic').
44
+ * When set, overrides heading, text, and link colors with the theme palette.
45
+ * Font changes are not supported (pdf-lib uses standard 14 PDF fonts only).
46
+ */
47
+ themeId?: string;
48
+ }
49
+ /**
50
+ * Convert a MarkdownDocument to a PDF ArrayBuffer.
51
+ */
52
+ declare function markdownDocToPdf(doc: MarkdownDocument, options?: PdfExportOptions): Promise<ArrayBuffer>;
53
+ /**
54
+ * Convert a squisq Doc to a PDF ArrayBuffer.
55
+ *
56
+ * Convenience wrapper: Doc → MarkdownDocument → PDF.
57
+ */
58
+ declare function docToPdf(doc: Doc, options?: PdfExportOptions): Promise<ArrayBuffer>;
59
+
60
+ /**
61
+ * PDF Import
62
+ *
63
+ * Parses a PDF file and converts its content into a squisq
64
+ * MarkdownDocument (or Doc) using heuristic detection of headings,
65
+ * lists, code blocks, tables, blockquotes, and hyperlinks.
66
+ *
67
+ * Uses pdfjs-dist (Mozilla pdf.js) for text extraction — a battle-tested,
68
+ * browser-compatible PDF parser. Since PDFs encode positioned glyphs
69
+ * rather than semantic structure, all structure detection is inherently
70
+ * heuristic and works best on simply-formatted documents.
71
+ *
72
+ * @example
73
+ * ```ts
74
+ * import { pdfToMarkdownDoc } from '@bendyline/squisq-formats/pdf';
75
+ *
76
+ * const response = await fetch('document.pdf');
77
+ * const data = await response.arrayBuffer();
78
+ * const doc = await pdfToMarkdownDoc(data);
79
+ * ```
80
+ */
81
+
82
+ /**
83
+ * Options for PDF import.
84
+ */
85
+ interface PdfImportOptions {
86
+ /**
87
+ * Hint for the body font size used in the PDF (in points).
88
+ * Text items larger than this are considered headings.
89
+ * If not provided, the importer detects the most common font size.
90
+ */
91
+ bodyFontSize?: number;
92
+ /** Whether to detect tables from column-aligned text. Default: true. */
93
+ detectTables?: boolean;
94
+ /** Whether to detect code blocks from monospace fonts. Default: true. */
95
+ detectCodeBlocks?: boolean;
96
+ /** Whether to detect blockquotes from indentation. Default: true. */
97
+ detectBlockquotes?: boolean;
98
+ /** Whether to detect URLs in text and convert to links. Default: true. */
99
+ detectLinks?: boolean;
100
+ }
101
+ /**
102
+ * Convert a PDF file to a MarkdownDocument.
103
+ *
104
+ * Structure detection is heuristic — results are best-effort.
105
+ *
106
+ * @param data - The raw PDF file as ArrayBuffer, Uint8Array, or Blob
107
+ * @param options - Import options
108
+ * @returns A MarkdownDocument representing the detected content
109
+ */
110
+ declare function pdfToMarkdownDoc(data: ArrayBuffer | Uint8Array | Blob, options?: PdfImportOptions): Promise<MarkdownDocument>;
111
+ /**
112
+ * Convert a PDF file to a squisq Doc.
113
+ *
114
+ * Convenience wrapper: PDF → MarkdownDocument → Doc.
115
+ */
116
+ declare function pdfToDoc(data: ArrayBuffer | Uint8Array | Blob, options?: PdfImportOptions): Promise<Doc>;
117
+ /**
118
+ * Convert a PDF file to a ContentContainer with markdown + extracted images.
119
+ *
120
+ * The container will contain:
121
+ * - The primary markdown document (index.md)
122
+ * - Any embedded images under images/ (e.g., images/image1.png)
123
+ *
124
+ * Image extraction uses pdfjs-dist's operator list API and requires a browser
125
+ * environment (canvas is used to encode pixel data to PNG).
126
+ *
127
+ * @param data - The raw PDF file as ArrayBuffer, Uint8Array, or Blob
128
+ * @param options - Import options
129
+ * @returns A ContentContainer with the document and its media
130
+ */
131
+ declare function pdfToContainer(data: ArrayBuffer | Uint8Array | Blob, options?: PdfImportOptions): Promise<ContentContainer>;
132
+ /**
133
+ * Configure the pdfjs-dist PDF worker source URL.
134
+ *
135
+ * pdfjs-dist requires a worker for PDF parsing. In the **browser**, bundlers
136
+ * (Vite, webpack) typically handle this automatically, or you can point to a
137
+ * CDN-hosted worker script. In **Node.js / SSR / test** environments, call
138
+ * this with a `file://` URL to the worker module **before** any import call.
11
139
  *
12
140
  * @example
13
141
  * ```ts
14
- * import {
15
- * markdownDocToPdf,
16
- * docToPdf,
17
- * pdfToMarkdownDoc,
18
- * pdfToDoc,
19
- * } from '@bendyline/squisq-formats/pdf';
142
+ * // Browser — CDN
143
+ * configurePdfWorker('https://cdn.jsdelivr.net/npm/pdfjs-dist@4/legacy/build/pdf.worker.min.mjs');
144
+ *
145
+ * // Node / vitest — file URL
146
+ * import { pathToFileURL } from 'url';
147
+ * configurePdfWorker(pathToFileURL(require.resolve('pdfjs-dist/legacy/build/pdf.worker.mjs')).href);
20
148
  * ```
21
149
  */
22
- export { markdownDocToPdf, docToPdf } from './export.js';
23
- export type { PdfExportOptions } from './export.js';
24
- export { pdfToMarkdownDoc, pdfToDoc, pdfToContainer, configurePdfWorker } from './import.js';
25
- export type { PdfImportOptions } from './import.js';
26
- //# sourceMappingURL=index.d.ts.map
150
+ declare function configurePdfWorker(workerSrc: string): void;
151
+
152
+ export { type PdfExportOptions, type PdfImportOptions, configurePdfWorker, docToPdf, markdownDocToPdf, pdfToContainer, pdfToDoc, pdfToMarkdownDoc };
package/dist/pdf/index.js CHANGED
@@ -1,26 +1,17 @@
1
- /**
2
- * @bendyline/squisq-formats PDF Module
3
- *
4
- * Import and export squisq documents (MarkdownDocument / Doc)
5
- * to/from PDF files.
6
- *
7
- * - **Export** uses pdf-lib (zero dependencies, standard fonts, pure JS).
8
- * - **Import** uses pdfjs-dist (Mozilla pdf.js) with heuristic structure detection.
9
- *
10
- * All operations run in the browser — no server required.
11
- *
12
- * @example
13
- * ```ts
14
- * import {
15
- * markdownDocToPdf,
16
- * docToPdf,
17
- * pdfToMarkdownDoc,
18
- * pdfToDoc,
19
- * } from '@bendyline/squisq-formats/pdf';
20
- * ```
21
- */
22
- // Export
23
- export { markdownDocToPdf, docToPdf } from './export.js';
24
- // Import
25
- export { pdfToMarkdownDoc, pdfToDoc, pdfToContainer, configurePdfWorker } from './import.js';
1
+ import {
2
+ configurePdfWorker,
3
+ docToPdf,
4
+ markdownDocToPdf,
5
+ pdfToContainer,
6
+ pdfToDoc,
7
+ pdfToMarkdownDoc
8
+ } from "../chunk-APSIAEXL.js";
9
+ export {
10
+ configurePdfWorker,
11
+ docToPdf,
12
+ markdownDocToPdf,
13
+ pdfToContainer,
14
+ pdfToDoc,
15
+ pdfToMarkdownDoc
16
+ };
26
17
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/pdf/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,SAAS;AACT,OAAO,EAAE,gBAAgB,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAGzD,SAAS;AACT,OAAO,EAAE,gBAAgB,EAAE,QAAQ,EAAE,cAAc,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC"}
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -1,40 +1,117 @@
1
+ import { Doc } from '@bendyline/squisq/schemas';
2
+ import { MarkdownDocument } from '@bendyline/squisq/markdown';
3
+
1
4
  /**
2
- * @bendyline/squisq-formats PPTX Module
5
+ * PPTX Export
3
6
  *
4
- * PowerPoint .pptx export support using PresentationML (`<p:presentation>`,
5
- * `<p:sld>`) via the shared ooxml/ infrastructure.
7
+ * Converts a squisq MarkdownDocument (or Doc) into a .pptx file
8
+ * by generating PresentationML + DrawingML XML and assembling the
9
+ * OOXML package.
6
10
  *
7
- * Slide segmentation: each H1/H2 heading starts a new slide by default.
8
- * Inline formatting (bold, italic, code, links) is preserved as DrawingML runs.
11
+ * Slide segmentation: each H1 or H2 heading starts a new slide.
12
+ * The heading becomes the slide title; content below becomes the body.
13
+ *
14
+ * Supports:
15
+ * - Theme-based styling (background, text colors, fonts from squisq themes)
16
+ * - Image embedding (pass images as ArrayBuffers via options)
17
+ * - Inline formatting (bold, italic, strikethrough, code, links)
18
+ * - Lists, code blocks, blockquotes, tables, math
9
19
  *
10
- * Import is not yet implemented.
20
+ * No third-party pptx library — all XML is generated directly using
21
+ * the shared ooxml/ infrastructure.
11
22
  *
12
23
  * @example
13
24
  * ```ts
25
+ * import { parseMarkdown } from '@bendyline/squisq/markdown';
14
26
  * import { markdownDocToPptx } from '@bendyline/squisq-formats/pptx';
27
+ *
28
+ * const md = parseMarkdown('# Slide 1\n\nHello world\n\n## Slide 2\n\nMore content');
29
+ * const blob = await markdownDocToPptx(md, { themeId: 'documentary' });
15
30
  * ```
16
31
  */
17
- export { markdownDocToPptx, docToPptx } from './export.js';
18
- export type { PptxExportOptions } from './export.js';
19
- import type { MarkdownDocument } from '@bendyline/squisq/markdown';
20
- import type { Doc } from '@bendyline/squisq/schemas';
32
+
21
33
  /**
22
- * Options for PPTX import (placeholder).
34
+ * Options for PPTX export.
23
35
  */
24
- export interface PptxImportOptions {
25
- /** Whether to extract embedded images as data URIs */
26
- extractImages?: boolean;
36
+ interface PptxExportOptions {
37
+ /** Presentation title (appears in core properties) */
38
+ title?: string;
39
+ /** Presentation author */
40
+ author?: string;
41
+ /** Presentation description */
42
+ description?: string;
43
+ /**
44
+ * Which heading depth triggers a new slide.
45
+ * - `'h1'` — only H1 headings start slides
46
+ * - `'h2'` — H1 and H2 headings start slides (default)
47
+ * - `'heading'` — any heading (H1–H6) starts a slide
48
+ */
49
+ slideBreak?: 'h1' | 'h2' | 'heading';
50
+ /** Default body font family. Default: "Calibri" */
51
+ defaultFont?: string;
52
+ /** Default body font size in points. Default: 18 */
53
+ defaultFontSize?: number;
54
+ /**
55
+ * Squisq theme ID to apply (e.g., 'documentary', 'cinematic', 'bold').
56
+ * Controls slide background, text colors, and fonts.
57
+ * Falls back to the document's frontmatter `themeId` if not set here.
58
+ */
59
+ themeId?: string;
60
+ /**
61
+ * Image data keyed by the path/URL used in markdown.
62
+ * When provided, images are embedded as picture shapes instead of
63
+ * showing `[Image: alt]` placeholders.
64
+ */
65
+ images?: Map<string, ArrayBuffer>;
27
66
  }
28
67
  /**
29
- * Convert a .pptx file to a MarkdownDocument.
68
+ * Convert a MarkdownDocument to a .pptx ArrayBuffer.
69
+ */
70
+ declare function markdownDocToPptx(doc: MarkdownDocument, options?: PptxExportOptions): Promise<ArrayBuffer>;
71
+ /**
72
+ * Convert a squisq Doc to a .pptx ArrayBuffer.
30
73
  *
31
- * @throws Error PPTX import is not yet implemented
74
+ * Convenience wrapper: Doc -> MarkdownDocument -> PPTX.
32
75
  */
33
- export declare function pptxToMarkdownDoc(_data: ArrayBuffer | Blob, _options?: PptxImportOptions): Promise<MarkdownDocument>;
76
+ declare function docToPptx(doc: Doc, options?: PptxExportOptions): Promise<ArrayBuffer>;
77
+
34
78
  /**
35
- * Convert a .pptx file to a squisq Doc.
79
+ * PPTX import — PresentationML (.pptx) MarkdownDocument.
36
80
  *
37
- * @throws Error PPTX import is not yet implemented
81
+ * Reuses the shared ooxml/ reader. Reads slide order from
82
+ * `ppt/presentation.xml` (`<p:sldIdLst>`), resolves each slide part via
83
+ * relationships, and converts each slide to: an H2 of the title placeholder
84
+ * (or "Slide N"), the remaining text as a bullet list, and any slide tables
85
+ * (`<a:tbl>`) as markdown tables. Text lives in the DrawingML namespace
86
+ * (`a:p` / `a:r` / `a:t`) inside PresentationML shapes (`p:sp`).
87
+ */
88
+
89
+ interface PptxImportOptions {
90
+ /** Whether to extract embedded images as data URIs (not yet used). */
91
+ extractImages?: boolean;
92
+ }
93
+ declare function pptxToMarkdownDoc(data: ArrayBuffer | Blob, _options?: PptxImportOptions): Promise<MarkdownDocument>;
94
+
95
+ /**
96
+ * @bendyline/squisq-formats PPTX Module
97
+ *
98
+ * PowerPoint .pptx export support using PresentationML (`<p:presentation>`,
99
+ * `<p:sld>`) via the shared ooxml/ infrastructure.
100
+ *
101
+ * Slide segmentation: each H1/H2 heading starts a new slide by default.
102
+ * Inline formatting (bold, italic, code, links) is preserved as DrawingML runs.
103
+ *
104
+ * Includes both export and import paths.
105
+ *
106
+ * @example
107
+ * ```ts
108
+ * import { markdownDocToPptx } from '@bendyline/squisq-formats/pptx';
109
+ * ```
110
+ */
111
+
112
+ /**
113
+ * Convert a .pptx file to a squisq Doc (via the markdown model).
38
114
  */
39
- export declare function pptxToDoc(_data: ArrayBuffer | Blob, _options?: PptxImportOptions): Promise<Doc>;
40
- //# sourceMappingURL=index.d.ts.map
115
+ declare function pptxToDoc(data: ArrayBuffer | Blob, options?: PptxImportOptions): Promise<Doc>;
116
+
117
+ export { type PptxExportOptions, type PptxImportOptions, docToPptx, markdownDocToPptx, pptxToDoc, pptxToMarkdownDoc };
@@ -1,35 +1,19 @@
1
- /**
2
- * @bendyline/squisq-formats PPTX Module
3
- *
4
- * PowerPoint .pptx export support using PresentationML (`<p:presentation>`,
5
- * `<p:sld>`) via the shared ooxml/ infrastructure.
6
- *
7
- * Slide segmentation: each H1/H2 heading starts a new slide by default.
8
- * Inline formatting (bold, italic, code, links) is preserved as DrawingML runs.
9
- *
10
- * Import is not yet implemented.
11
- *
12
- * @example
13
- * ```ts
14
- * import { markdownDocToPptx } from '@bendyline/squisq-formats/pptx';
15
- * ```
16
- */
17
- // Export
18
- export { markdownDocToPptx, docToPptx } from './export.js';
19
- /**
20
- * Convert a .pptx file to a MarkdownDocument.
21
- *
22
- * @throws Error — PPTX import is not yet implemented
23
- */
24
- export async function pptxToMarkdownDoc(_data, _options) {
25
- throw new Error('PPTX import is not yet implemented');
26
- }
27
- /**
28
- * Convert a .pptx file to a squisq Doc.
29
- *
30
- * @throws Error — PPTX import is not yet implemented
31
- */
32
- export async function pptxToDoc(_data, _options) {
33
- throw new Error('PPTX import is not yet implemented');
34
- }
1
+ import {
2
+ docToPptx,
3
+ markdownDocToPptx,
4
+ pptxToDoc,
5
+ pptxToMarkdownDoc
6
+ } from "../chunk-I2GFTEOV.js";
7
+ import "../chunk-6M7Z25LA.js";
8
+ import "../chunk-PN52A5AA.js";
9
+ import "../chunk-QSE7EWE7.js";
10
+ import "../chunk-U4MRIFKL.js";
11
+ import "../chunk-FMOIGA5T.js";
12
+ import "../chunk-A3FHLTY5.js";
13
+ export {
14
+ docToPptx,
15
+ markdownDocToPptx,
16
+ pptxToDoc,
17
+ pptxToMarkdownDoc
18
+ };
35
19
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/pptx/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,SAAS;AACT,OAAO,EAAE,iBAAiB,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAe3D;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,iBAAiB,CACrC,KAAyB,EACzB,QAA4B;IAE5B,MAAM,IAAI,KAAK,CAAC,oCAAoC,CAAC,CAAC;AACxD,CAAC;AAED;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,SAAS,CAC7B,KAAyB,EACzB,QAA4B;IAE5B,MAAM,IAAI,KAAK,CAAC,oCAAoC,CAAC,CAAC;AACxD,CAAC"}
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -1,3 +1,22 @@
1
+ import { MarkdownDocument } from '@bendyline/squisq/markdown';
2
+ import { Doc } from '@bendyline/squisq/schemas';
3
+
4
+ /**
5
+ * XLSX import — SpreadsheetML (.xlsx) → MarkdownDocument.
6
+ *
7
+ * Reuses the shared ooxml/ reader (zip + DOMParser). Reads the workbook's
8
+ * sheet list, resolves each sheet part via relationships, pulls shared strings,
9
+ * and turns each worksheet's cell grid into a markdown table (first row treated
10
+ * as the header). By default every sheet is imported, each preceded by an H1 of
11
+ * the sheet name; pass `options.sheet` (index or name) to import just one.
12
+ */
13
+
14
+ interface XlsxImportOptions {
15
+ /** Which sheet to import (0-based index or sheet name). Default: all sheets. */
16
+ sheet?: number | string;
17
+ }
18
+ declare function xlsxToMarkdownDoc(data: ArrayBuffer | Blob, options?: XlsxImportOptions): Promise<MarkdownDocument>;
19
+
1
20
  /**
2
21
  * @bendyline/squisq-formats XLSX Module (Stub)
3
22
  *
@@ -10,46 +29,31 @@
10
29
  * import { markdownDocToXlsx } from '@bendyline/squisq-formats/xlsx';
11
30
  * ```
12
31
  */
13
- import type { MarkdownDocument } from '@bendyline/squisq/markdown';
14
- import type { Doc } from '@bendyline/squisq/schemas';
32
+
15
33
  /**
16
34
  * Options for XLSX export (placeholder).
17
35
  */
18
- export interface XlsxExportOptions {
36
+ interface XlsxExportOptions {
19
37
  /** Workbook title */
20
38
  title?: string;
21
39
  /** Workbook author */
22
40
  author?: string;
23
41
  }
24
- /**
25
- * Options for XLSX import (placeholder).
26
- */
27
- export interface XlsxImportOptions {
28
- /** Which sheet to import (0-based index or name). Default: 0 */
29
- sheet?: number | string;
30
- }
31
42
  /**
32
43
  * Convert a MarkdownDocument to a .xlsx Blob.
33
44
  *
34
- * @throws Error — XLSX support is not yet implemented
45
+ * @throws Error — XLSX export is not yet implemented
35
46
  */
36
- export declare function markdownDocToXlsx(_doc: MarkdownDocument, _options?: XlsxExportOptions): Promise<Blob>;
47
+ declare function markdownDocToXlsx(_doc: MarkdownDocument, _options?: XlsxExportOptions): Promise<Blob>;
37
48
  /**
38
49
  * Convert a squisq Doc to a .xlsx Blob.
39
50
  *
40
- * @throws Error — XLSX support is not yet implemented
41
- */
42
- export declare function docToXlsx(_doc: Doc, _options?: XlsxExportOptions): Promise<Blob>;
43
- /**
44
- * Convert a .xlsx file to a MarkdownDocument.
45
- *
46
- * @throws Error — XLSX support is not yet implemented
51
+ * @throws Error — XLSX export is not yet implemented
47
52
  */
48
- export declare function xlsxToMarkdownDoc(_data: ArrayBuffer | Blob, _options?: XlsxImportOptions): Promise<MarkdownDocument>;
53
+ declare function docToXlsx(_doc: Doc, _options?: XlsxExportOptions): Promise<Blob>;
49
54
  /**
50
- * Convert a .xlsx file to a squisq Doc.
51
- *
52
- * @throws Error — XLSX support is not yet implemented
55
+ * Convert a .xlsx file to a squisq Doc (via the markdown table model).
53
56
  */
54
- export declare function xlsxToDoc(_data: ArrayBuffer | Blob, _options?: XlsxImportOptions): Promise<Doc>;
55
- //# sourceMappingURL=index.d.ts.map
57
+ declare function xlsxToDoc(data: ArrayBuffer | Blob, options?: XlsxImportOptions): Promise<Doc>;
58
+
59
+ export { type XlsxExportOptions, type XlsxImportOptions, docToXlsx, markdownDocToXlsx, xlsxToDoc, xlsxToMarkdownDoc };
@@ -1,45 +1,14 @@
1
- /**
2
- * @bendyline/squisq-formats XLSX Module (Stub)
3
- *
4
- * Placeholder for Excel .xlsx import/export support.
5
- * Will use SpreadsheetML (`<spreadsheet>`, `<worksheet>`, `<sheetData>`)
6
- * via the shared ooxml/ infrastructure.
7
- *
8
- * @example
9
- * ```ts
10
- * import { markdownDocToXlsx } from '@bendyline/squisq-formats/xlsx';
11
- * ```
12
- */
13
- /**
14
- * Convert a MarkdownDocument to a .xlsx Blob.
15
- *
16
- * @throws Error — XLSX support is not yet implemented
17
- */
18
- export async function markdownDocToXlsx(_doc, _options) {
19
- throw new Error('XLSX export is not yet implemented');
20
- }
21
- /**
22
- * Convert a squisq Doc to a .xlsx Blob.
23
- *
24
- * @throws Error — XLSX support is not yet implemented
25
- */
26
- export async function docToXlsx(_doc, _options) {
27
- throw new Error('XLSX export is not yet implemented');
28
- }
29
- /**
30
- * Convert a .xlsx file to a MarkdownDocument.
31
- *
32
- * @throws Error — XLSX support is not yet implemented
33
- */
34
- export async function xlsxToMarkdownDoc(_data, _options) {
35
- throw new Error('XLSX import is not yet implemented');
36
- }
37
- /**
38
- * Convert a .xlsx file to a squisq Doc.
39
- *
40
- * @throws Error — XLSX support is not yet implemented
41
- */
42
- export async function xlsxToDoc(_data, _options) {
43
- throw new Error('XLSX import is not yet implemented');
44
- }
1
+ import {
2
+ docToXlsx,
3
+ markdownDocToXlsx,
4
+ xlsxToDoc,
5
+ xlsxToMarkdownDoc
6
+ } from "../chunk-L53YIGYS.js";
7
+ import "../chunk-FMOIGA5T.js";
8
+ export {
9
+ docToXlsx,
10
+ markdownDocToXlsx,
11
+ xlsxToDoc,
12
+ xlsxToMarkdownDoc
13
+ };
45
14
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/xlsx/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAuBH;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,iBAAiB,CACrC,IAAsB,EACtB,QAA4B;IAE5B,MAAM,IAAI,KAAK,CAAC,oCAAoC,CAAC,CAAC;AACxD,CAAC;AAED;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,SAAS,CAAC,IAAS,EAAE,QAA4B;IACrE,MAAM,IAAI,KAAK,CAAC,oCAAoC,CAAC,CAAC;AACxD,CAAC;AAED;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,iBAAiB,CACrC,KAAyB,EACzB,QAA4B;IAE5B,MAAM,IAAI,KAAK,CAAC,oCAAoC,CAAC,CAAC;AACxD,CAAC;AAED;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,SAAS,CAC7B,KAAyB,EACzB,QAA4B;IAE5B,MAAM,IAAI,KAAK,CAAC,oCAAoC,CAAC,CAAC;AACxD,CAAC"}
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bendyline/squisq-formats",
3
- "version": "1.3.0",
3
+ "version": "1.4.0",
4
4
  "description": "Document format converters — DOCX, PDF, OOXML import/export",
5
5
  "license": "MIT",
6
6
  "author": "Bendyline",
@@ -52,6 +52,11 @@
52
52
  "import": "./dist/xlsx/index.js",
53
53
  "default": "./dist/xlsx/index.js"
54
54
  },
55
+ "./csv": {
56
+ "types": "./dist/csv/index.d.ts",
57
+ "import": "./dist/csv/index.js",
58
+ "default": "./dist/csv/index.js"
59
+ },
55
60
  "./ooxml": {
56
61
  "types": "./dist/ooxml/index.d.ts",
57
62
  "import": "./dist/ooxml/index.js",
@@ -84,7 +89,7 @@
84
89
  "typecheck": "tsc --noEmit"
85
90
  },
86
91
  "dependencies": {
87
- "@bendyline/squisq": "1.4.0",
92
+ "@bendyline/squisq": "1.5.0",
88
93
  "jszip": "3.10.1",
89
94
  "pdf-lib": "1.17.1",
90
95
  "pdfjs-dist": "4.10.38"
@@ -0,0 +1,51 @@
1
+ /**
2
+ * Tests for CSV import/export: csvToMarkdownDoc, markdownDocToCsv, parseCsv.
3
+ */
4
+
5
+ import { describe, expect, it } from 'vitest';
6
+ import type { MarkdownTable, MarkdownText } from '@bendyline/squisq/markdown';
7
+ import { csvToMarkdownDoc, markdownDocToCsv, parseCsv } from '../csv/index';
8
+
9
+ function cellValue(table: MarkdownTable, row: number, col: number): string {
10
+ const cell = table.children[row]?.children[col];
11
+ const first = cell?.children[0] as MarkdownText | undefined;
12
+ return first?.value ?? '';
13
+ }
14
+
15
+ describe('parseCsv', () => {
16
+ it('parses quoted fields, escaped quotes, and embedded delimiters', () => {
17
+ const rows = parseCsv('a,b,c\n"x,y","he said ""hi""",z\n');
18
+ expect(rows).toEqual([
19
+ ['a', 'b', 'c'],
20
+ ['x,y', 'he said "hi"', 'z'],
21
+ ]);
22
+ });
23
+
24
+ it('handles CRLF line endings', () => {
25
+ expect(parseCsv('a,b\r\n1,2\r\n')).toEqual([
26
+ ['a', 'b'],
27
+ ['1', '2'],
28
+ ]);
29
+ });
30
+ });
31
+
32
+ describe('csvToMarkdownDoc', () => {
33
+ it('builds a table with a header row by default', async () => {
34
+ const doc = await csvToMarkdownDoc('Name,Age\nAlice,30\n"Bob, Jr.",40\n');
35
+ expect(doc.type).toBe('document');
36
+ const table = doc.children[0] as MarkdownTable;
37
+ expect(table.type).toBe('table');
38
+ expect(table.children).toHaveLength(3);
39
+ expect(table.children[0]!.children[0]!.isHeader).toBe(true);
40
+ expect(cellValue(table, 0, 0)).toBe('Name');
41
+ expect(cellValue(table, 0, 1)).toBe('Age');
42
+ expect(cellValue(table, 2, 0)).toBe('Bob, Jr.');
43
+ expect(cellValue(table, 2, 1)).toBe('40');
44
+ });
45
+
46
+ it('round-trips through markdownDocToCsv', async () => {
47
+ const csv = 'Name,Age\r\nAlice,30\r\n"Bob, Jr.",40';
48
+ const doc = await csvToMarkdownDoc(csv);
49
+ expect(markdownDocToCsv(doc)).toBe(csv);
50
+ });
51
+ });