@bendyline/squisq-formats 0.1.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 (61) hide show
  1. package/dist/chunk-532L4D5D.js +21 -0
  2. package/dist/chunk-532L4D5D.js.map +1 -0
  3. package/dist/chunk-67KIJHV2.js +21 -0
  4. package/dist/chunk-67KIJHV2.js.map +1 -0
  5. package/dist/chunk-KAK4V57E.js +387 -0
  6. package/dist/chunk-KAK4V57E.js.map +1 -0
  7. package/dist/chunk-MQHCXI56.js +1035 -0
  8. package/dist/chunk-MQHCXI56.js.map +1 -0
  9. package/dist/chunk-TBPD5PCU.js +1136 -0
  10. package/dist/chunk-TBPD5PCU.js.map +1 -0
  11. package/dist/chunk-ULLIPBEJ.js +271 -0
  12. package/dist/chunk-ULLIPBEJ.js.map +1 -0
  13. package/dist/docx/index.d.ts +108 -0
  14. package/dist/docx/index.js +14 -0
  15. package/dist/docx/index.js.map +1 -0
  16. package/dist/html/index.d.ts +166 -0
  17. package/dist/html/index.js +17 -0
  18. package/dist/html/index.js.map +1 -0
  19. package/dist/index.d.ts +7 -0
  20. package/dist/index.js +54 -0
  21. package/dist/index.js.map +1 -0
  22. package/dist/ooxml/index.d.ts +351 -0
  23. package/dist/ooxml/index.js +99 -0
  24. package/dist/ooxml/index.js.map +1 -0
  25. package/dist/pdf/index.d.ts +130 -0
  26. package/dist/pdf/index.js +15 -0
  27. package/dist/pdf/index.js.map +1 -0
  28. package/dist/pptx/index.d.ts +58 -0
  29. package/dist/pptx/index.js +13 -0
  30. package/dist/pptx/index.js.map +1 -0
  31. package/dist/xlsx/index.d.ts +58 -0
  32. package/dist/xlsx/index.js +13 -0
  33. package/dist/xlsx/index.js.map +1 -0
  34. package/package.json +85 -0
  35. package/src/__tests__/docxExport.test.ts +457 -0
  36. package/src/__tests__/docxImport.test.ts +410 -0
  37. package/src/__tests__/html.test.ts +295 -0
  38. package/src/__tests__/ooxml.test.ts +197 -0
  39. package/src/__tests__/pdfExport.test.ts +322 -0
  40. package/src/__tests__/pdfImport.test.ts +290 -0
  41. package/src/__tests__/roundTrip.test.ts +201 -0
  42. package/src/docx/export.ts +978 -0
  43. package/src/docx/import.ts +909 -0
  44. package/src/docx/index.ts +26 -0
  45. package/src/docx/styles.ts +145 -0
  46. package/src/html/htmlTemplate.ts +307 -0
  47. package/src/html/imageUtils.ts +66 -0
  48. package/src/html/index.ts +168 -0
  49. package/src/index.ts +51 -0
  50. package/src/ooxml/index.ts +87 -0
  51. package/src/ooxml/namespaces.ts +160 -0
  52. package/src/ooxml/reader.ts +218 -0
  53. package/src/ooxml/types.ts +104 -0
  54. package/src/ooxml/writer.ts +321 -0
  55. package/src/ooxml/xmlUtils.ts +123 -0
  56. package/src/pdf/export.ts +1029 -0
  57. package/src/pdf/import.ts +835 -0
  58. package/src/pdf/index.ts +29 -0
  59. package/src/pdf/styles.ts +180 -0
  60. package/src/pptx/index.ts +78 -0
  61. package/src/xlsx/index.ts +78 -0
@@ -0,0 +1,99 @@
1
+ import {
2
+ CONTENT_TYPE_CORE_PROPERTIES,
3
+ CONTENT_TYPE_DOCX_DOCUMENT,
4
+ CONTENT_TYPE_DOCX_FONT_TABLE,
5
+ CONTENT_TYPE_DOCX_FOOTNOTES,
6
+ CONTENT_TYPE_DOCX_NUMBERING,
7
+ CONTENT_TYPE_DOCX_SETTINGS,
8
+ CONTENT_TYPE_DOCX_STYLES,
9
+ CONTENT_TYPE_PPTX_PRESENTATION,
10
+ CONTENT_TYPE_RELATIONSHIPS,
11
+ CONTENT_TYPE_XLSX_WORKBOOK,
12
+ NS_CONTENT_TYPES,
13
+ NS_CORE_PROPERTIES,
14
+ NS_DC,
15
+ NS_DCTERMS,
16
+ NS_DRAWINGML,
17
+ NS_MC,
18
+ NS_PICTURE,
19
+ NS_PML,
20
+ NS_R,
21
+ NS_RELATIONSHIPS,
22
+ NS_SML,
23
+ NS_WML,
24
+ NS_WP_DRAWING,
25
+ NS_XSI,
26
+ REL_CORE_PROPERTIES,
27
+ REL_EXTENDED_PROPERTIES,
28
+ REL_FONT_TABLE,
29
+ REL_FOOTNOTES,
30
+ REL_HYPERLINK,
31
+ REL_IMAGE,
32
+ REL_NUMBERING,
33
+ REL_OFFICE_DOCUMENT,
34
+ REL_SETTINGS,
35
+ REL_STYLES,
36
+ REL_THEME,
37
+ attrString,
38
+ createPackage,
39
+ escapeXml,
40
+ getCoreProperties,
41
+ getPartBinary,
42
+ getPartRelationships,
43
+ getPartXml,
44
+ openPackage,
45
+ selfClosingElement,
46
+ textElement,
47
+ xmlDeclaration,
48
+ xmlElement
49
+ } from "../chunk-KAK4V57E.js";
50
+ export {
51
+ CONTENT_TYPE_CORE_PROPERTIES,
52
+ CONTENT_TYPE_DOCX_DOCUMENT,
53
+ CONTENT_TYPE_DOCX_FONT_TABLE,
54
+ CONTENT_TYPE_DOCX_FOOTNOTES,
55
+ CONTENT_TYPE_DOCX_NUMBERING,
56
+ CONTENT_TYPE_DOCX_SETTINGS,
57
+ CONTENT_TYPE_DOCX_STYLES,
58
+ CONTENT_TYPE_PPTX_PRESENTATION,
59
+ CONTENT_TYPE_RELATIONSHIPS,
60
+ CONTENT_TYPE_XLSX_WORKBOOK,
61
+ NS_CONTENT_TYPES,
62
+ NS_CORE_PROPERTIES,
63
+ NS_DC,
64
+ NS_DCTERMS,
65
+ NS_DRAWINGML,
66
+ NS_MC,
67
+ NS_PICTURE,
68
+ NS_PML,
69
+ NS_R,
70
+ NS_RELATIONSHIPS,
71
+ NS_SML,
72
+ NS_WML,
73
+ NS_WP_DRAWING,
74
+ NS_XSI,
75
+ REL_CORE_PROPERTIES,
76
+ REL_EXTENDED_PROPERTIES,
77
+ REL_FONT_TABLE,
78
+ REL_FOOTNOTES,
79
+ REL_HYPERLINK,
80
+ REL_IMAGE,
81
+ REL_NUMBERING,
82
+ REL_OFFICE_DOCUMENT,
83
+ REL_SETTINGS,
84
+ REL_STYLES,
85
+ REL_THEME,
86
+ attrString,
87
+ createPackage,
88
+ escapeXml,
89
+ getCoreProperties,
90
+ getPartBinary,
91
+ getPartRelationships,
92
+ getPartXml,
93
+ openPackage,
94
+ selfClosingElement,
95
+ textElement,
96
+ xmlDeclaration,
97
+ xmlElement
98
+ };
99
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -0,0 +1,130 @@
1
+ import { Doc } from '@bendyline/squisq/schemas';
2
+ import { MarkdownDocument } from '@bendyline/squisq/markdown';
3
+
4
+ /**
5
+ * PDF Export
6
+ *
7
+ * Converts a squisq MarkdownDocument (or Doc) into a PDF file
8
+ * using pdf-lib. Generates paginated, styled output with support for
9
+ * headings, paragraphs, inline formatting, lists, code blocks,
10
+ * blockquotes, tables, thematic breaks, and hyperlinks.
11
+ *
12
+ * Uses only the 14 standard PDF fonts (no font embedding required),
13
+ * keeping output size small and rendering fast.
14
+ *
15
+ * @example
16
+ * ```ts
17
+ * import { parseMarkdown } from '@bendyline/squisq/markdown';
18
+ * import { markdownDocToPdf } from '@bendyline/squisq-formats/pdf';
19
+ *
20
+ * const md = parseMarkdown('# Hello\n\nWorld **bold** text');
21
+ * const buffer = await markdownDocToPdf(md);
22
+ * ```
23
+ */
24
+
25
+ /** Page size presets. */
26
+ type PdfPageSize = 'letter' | 'a4';
27
+ /**
28
+ * Options for PDF export.
29
+ */
30
+ interface PdfExportOptions {
31
+ /** Document title (PDF metadata). */
32
+ title?: string;
33
+ /** Document author (PDF metadata). */
34
+ author?: string;
35
+ /** Page size preset. Default: "letter". */
36
+ pageSize?: PdfPageSize;
37
+ /** Page margins in points. Default: 72 (1 inch). */
38
+ margin?: number;
39
+ /** Default body font size in points. Default: 11. */
40
+ defaultFontSize?: number;
41
+ }
42
+ /**
43
+ * Convert a MarkdownDocument to a PDF ArrayBuffer.
44
+ */
45
+ declare function markdownDocToPdf(doc: MarkdownDocument, options?: PdfExportOptions): Promise<ArrayBuffer>;
46
+ /**
47
+ * Convert a squisq Doc to a PDF ArrayBuffer.
48
+ *
49
+ * Convenience wrapper: Doc → MarkdownDocument → PDF.
50
+ */
51
+ declare function docToPdf(doc: Doc, options?: PdfExportOptions): Promise<ArrayBuffer>;
52
+
53
+ /**
54
+ * PDF Import
55
+ *
56
+ * Parses a PDF file and converts its content into a squisq
57
+ * MarkdownDocument (or Doc) using heuristic detection of headings,
58
+ * lists, code blocks, tables, blockquotes, and hyperlinks.
59
+ *
60
+ * Uses pdfjs-dist (Mozilla pdf.js) for text extraction — a battle-tested,
61
+ * browser-compatible PDF parser. Since PDFs encode positioned glyphs
62
+ * rather than semantic structure, all structure detection is inherently
63
+ * heuristic and works best on simply-formatted documents.
64
+ *
65
+ * @example
66
+ * ```ts
67
+ * import { pdfToMarkdownDoc } from '@bendyline/squisq-formats/pdf';
68
+ *
69
+ * const response = await fetch('document.pdf');
70
+ * const data = await response.arrayBuffer();
71
+ * const doc = await pdfToMarkdownDoc(data);
72
+ * ```
73
+ */
74
+
75
+ /**
76
+ * Options for PDF import.
77
+ */
78
+ interface PdfImportOptions {
79
+ /**
80
+ * Hint for the body font size used in the PDF (in points).
81
+ * Text items larger than this are considered headings.
82
+ * If not provided, the importer detects the most common font size.
83
+ */
84
+ bodyFontSize?: number;
85
+ /** Whether to detect tables from column-aligned text. Default: true. */
86
+ detectTables?: boolean;
87
+ /** Whether to detect code blocks from monospace fonts. Default: true. */
88
+ detectCodeBlocks?: boolean;
89
+ /** Whether to detect blockquotes from indentation. Default: true. */
90
+ detectBlockquotes?: boolean;
91
+ /** Whether to detect URLs in text and convert to links. Default: true. */
92
+ detectLinks?: boolean;
93
+ }
94
+ /**
95
+ * Convert a PDF file to a MarkdownDocument.
96
+ *
97
+ * Structure detection is heuristic — results are best-effort.
98
+ *
99
+ * @param data - The raw PDF file as ArrayBuffer, Uint8Array, or Blob
100
+ * @param options - Import options
101
+ * @returns A MarkdownDocument representing the detected content
102
+ */
103
+ declare function pdfToMarkdownDoc(data: ArrayBuffer | Uint8Array | Blob, options?: PdfImportOptions): Promise<MarkdownDocument>;
104
+ /**
105
+ * Convert a PDF file to a squisq Doc.
106
+ *
107
+ * Convenience wrapper: PDF → MarkdownDocument → Doc.
108
+ */
109
+ declare function pdfToDoc(data: ArrayBuffer | Uint8Array | Blob, options?: PdfImportOptions): Promise<Doc>;
110
+ /**
111
+ * Configure the pdfjs-dist PDF worker source URL.
112
+ *
113
+ * pdfjs-dist requires a worker for PDF parsing. In the **browser**, bundlers
114
+ * (Vite, webpack) typically handle this automatically, or you can point to a
115
+ * CDN-hosted worker script. In **Node.js / SSR / test** environments, call
116
+ * this with a `file://` URL to the worker module **before** any import call.
117
+ *
118
+ * @example
119
+ * ```ts
120
+ * // Browser — CDN
121
+ * configurePdfWorker('https://cdn.jsdelivr.net/npm/pdfjs-dist@4/legacy/build/pdf.worker.min.mjs');
122
+ *
123
+ * // Node / vitest — file URL
124
+ * import { pathToFileURL } from 'url';
125
+ * configurePdfWorker(pathToFileURL(require.resolve('pdfjs-dist/legacy/build/pdf.worker.mjs')).href);
126
+ * ```
127
+ */
128
+ declare function configurePdfWorker(workerSrc: string): void;
129
+
130
+ export { type PdfExportOptions, type PdfImportOptions, configurePdfWorker, docToPdf, markdownDocToPdf, pdfToDoc, pdfToMarkdownDoc };
@@ -0,0 +1,15 @@
1
+ import {
2
+ configurePdfWorker,
3
+ docToPdf,
4
+ markdownDocToPdf,
5
+ pdfToDoc,
6
+ pdfToMarkdownDoc
7
+ } from "../chunk-TBPD5PCU.js";
8
+ export {
9
+ configurePdfWorker,
10
+ docToPdf,
11
+ markdownDocToPdf,
12
+ pdfToDoc,
13
+ pdfToMarkdownDoc
14
+ };
15
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -0,0 +1,58 @@
1
+ import { MarkdownDocument } from '@bendyline/squisq/markdown';
2
+ import { Doc } from '@bendyline/squisq/schemas';
3
+
4
+ /**
5
+ * @bendyline/squisq-formats PPTX Module (Stub)
6
+ *
7
+ * Placeholder for PowerPoint .pptx import/export support.
8
+ * Will use PresentationML (`<p:presentation>`, `<p:sld>`) via the
9
+ * shared ooxml/ infrastructure.
10
+ *
11
+ * @example
12
+ * ```ts
13
+ * import { markdownDocToPptx } from '@bendyline/squisq-formats/pptx';
14
+ * ```
15
+ */
16
+
17
+ /**
18
+ * Options for PPTX export (placeholder).
19
+ */
20
+ interface PptxExportOptions {
21
+ /** Presentation title */
22
+ title?: string;
23
+ /** Presentation author */
24
+ author?: string;
25
+ }
26
+ /**
27
+ * Options for PPTX import (placeholder).
28
+ */
29
+ interface PptxImportOptions {
30
+ /** Whether to extract embedded images as data URIs */
31
+ extractImages?: boolean;
32
+ }
33
+ /**
34
+ * Convert a MarkdownDocument to a .pptx Blob.
35
+ *
36
+ * @throws Error — PPTX support is not yet implemented
37
+ */
38
+ declare function markdownDocToPptx(_doc: MarkdownDocument, _options?: PptxExportOptions): Promise<Blob>;
39
+ /**
40
+ * Convert a squisq Doc to a .pptx Blob.
41
+ *
42
+ * @throws Error — PPTX support is not yet implemented
43
+ */
44
+ declare function docToPptx(_doc: Doc, _options?: PptxExportOptions): Promise<Blob>;
45
+ /**
46
+ * Convert a .pptx file to a MarkdownDocument.
47
+ *
48
+ * @throws Error — PPTX support is not yet implemented
49
+ */
50
+ declare function pptxToMarkdownDoc(_data: ArrayBuffer | Blob, _options?: PptxImportOptions): Promise<MarkdownDocument>;
51
+ /**
52
+ * Convert a .pptx file to a squisq Doc.
53
+ *
54
+ * @throws Error — PPTX support is not yet implemented
55
+ */
56
+ declare function pptxToDoc(_data: ArrayBuffer | Blob, _options?: PptxImportOptions): Promise<Doc>;
57
+
58
+ export { type PptxExportOptions, type PptxImportOptions, docToPptx, markdownDocToPptx, pptxToDoc, pptxToMarkdownDoc };
@@ -0,0 +1,13 @@
1
+ import {
2
+ docToPptx,
3
+ markdownDocToPptx,
4
+ pptxToDoc,
5
+ pptxToMarkdownDoc
6
+ } from "../chunk-532L4D5D.js";
7
+ export {
8
+ docToPptx,
9
+ markdownDocToPptx,
10
+ pptxToDoc,
11
+ pptxToMarkdownDoc
12
+ };
13
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -0,0 +1,58 @@
1
+ import { MarkdownDocument } from '@bendyline/squisq/markdown';
2
+ import { Doc } from '@bendyline/squisq/schemas';
3
+
4
+ /**
5
+ * @bendyline/squisq-formats XLSX Module (Stub)
6
+ *
7
+ * Placeholder for Excel .xlsx import/export support.
8
+ * Will use SpreadsheetML (`<spreadsheet>`, `<worksheet>`, `<sheetData>`)
9
+ * via the shared ooxml/ infrastructure.
10
+ *
11
+ * @example
12
+ * ```ts
13
+ * import { markdownDocToXlsx } from '@bendyline/squisq-formats/xlsx';
14
+ * ```
15
+ */
16
+
17
+ /**
18
+ * Options for XLSX export (placeholder).
19
+ */
20
+ interface XlsxExportOptions {
21
+ /** Workbook title */
22
+ title?: string;
23
+ /** Workbook author */
24
+ author?: string;
25
+ }
26
+ /**
27
+ * Options for XLSX import (placeholder).
28
+ */
29
+ interface XlsxImportOptions {
30
+ /** Which sheet to import (0-based index or name). Default: 0 */
31
+ sheet?: number | string;
32
+ }
33
+ /**
34
+ * Convert a MarkdownDocument to a .xlsx Blob.
35
+ *
36
+ * @throws Error — XLSX support is not yet implemented
37
+ */
38
+ declare function markdownDocToXlsx(_doc: MarkdownDocument, _options?: XlsxExportOptions): Promise<Blob>;
39
+ /**
40
+ * Convert a squisq Doc to a .xlsx Blob.
41
+ *
42
+ * @throws Error — XLSX support is not yet implemented
43
+ */
44
+ declare function docToXlsx(_doc: Doc, _options?: XlsxExportOptions): Promise<Blob>;
45
+ /**
46
+ * Convert a .xlsx file to a MarkdownDocument.
47
+ *
48
+ * @throws Error — XLSX support is not yet implemented
49
+ */
50
+ declare function xlsxToMarkdownDoc(_data: ArrayBuffer | Blob, _options?: XlsxImportOptions): Promise<MarkdownDocument>;
51
+ /**
52
+ * Convert a .xlsx file to a squisq Doc.
53
+ *
54
+ * @throws Error — XLSX support is not yet implemented
55
+ */
56
+ declare function xlsxToDoc(_data: ArrayBuffer | Blob, _options?: XlsxImportOptions): Promise<Doc>;
57
+
58
+ export { type XlsxExportOptions, type XlsxImportOptions, docToXlsx, markdownDocToXlsx, xlsxToDoc, xlsxToMarkdownDoc };
@@ -0,0 +1,13 @@
1
+ import {
2
+ docToXlsx,
3
+ markdownDocToXlsx,
4
+ xlsxToDoc,
5
+ xlsxToMarkdownDoc
6
+ } from "../chunk-67KIJHV2.js";
7
+ export {
8
+ docToXlsx,
9
+ markdownDocToXlsx,
10
+ xlsxToDoc,
11
+ xlsxToMarkdownDoc
12
+ };
13
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
package/package.json ADDED
@@ -0,0 +1,85 @@
1
+ {
2
+ "name": "@bendyline/squisq-formats",
3
+ "version": "0.1.0",
4
+ "description": "Document format converters — DOCX, PDF, OOXML import/export",
5
+ "license": "MIT",
6
+ "author": "Bendyline",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "https://github.com/nicknisi/squisq.git",
10
+ "directory": "packages/formats"
11
+ },
12
+ "homepage": "https://github.com/nicknisi/squisq",
13
+ "keywords": [
14
+ "docx",
15
+ "pdf",
16
+ "ooxml",
17
+ "pptx",
18
+ "xlsx",
19
+ "document",
20
+ "converter"
21
+ ],
22
+ "publishConfig": {
23
+ "access": "public"
24
+ },
25
+ "type": "module",
26
+ "main": "./dist/index.js",
27
+ "module": "./dist/index.js",
28
+ "types": "./dist/index.d.ts",
29
+ "files": [
30
+ "dist",
31
+ "src"
32
+ ],
33
+ "exports": {
34
+ ".": {
35
+ "types": "./dist/index.d.ts",
36
+ "import": "./dist/index.js",
37
+ "default": "./dist/index.js"
38
+ },
39
+ "./docx": {
40
+ "types": "./dist/docx/index.d.ts",
41
+ "import": "./dist/docx/index.js",
42
+ "default": "./dist/docx/index.js"
43
+ },
44
+ "./pptx": {
45
+ "types": "./dist/pptx/index.d.ts",
46
+ "import": "./dist/pptx/index.js",
47
+ "default": "./dist/pptx/index.js"
48
+ },
49
+ "./xlsx": {
50
+ "types": "./dist/xlsx/index.d.ts",
51
+ "import": "./dist/xlsx/index.js",
52
+ "default": "./dist/xlsx/index.js"
53
+ },
54
+ "./ooxml": {
55
+ "types": "./dist/ooxml/index.d.ts",
56
+ "import": "./dist/ooxml/index.js",
57
+ "default": "./dist/ooxml/index.js"
58
+ },
59
+ "./pdf": {
60
+ "types": "./dist/pdf/index.d.ts",
61
+ "import": "./dist/pdf/index.js",
62
+ "default": "./dist/pdf/index.js"
63
+ },
64
+ "./html": {
65
+ "types": "./dist/html/index.d.ts",
66
+ "import": "./dist/html/index.js",
67
+ "default": "./dist/html/index.js"
68
+ }
69
+ },
70
+ "scripts": {
71
+ "build": "tsup",
72
+ "typecheck": "tsc --noEmit",
73
+ "prepublishOnly": "npm run build"
74
+ },
75
+ "dependencies": {
76
+ "@bendyline/squisq": "0.1.1",
77
+ "jszip": "^3.10.1",
78
+ "pdf-lib": "^1.17.1",
79
+ "pdfjs-dist": "^4.9.155"
80
+ },
81
+ "devDependencies": {
82
+ "tsup": "^8.0.0",
83
+ "typescript": "^5.3.0"
84
+ }
85
+ }