@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,29 @@
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
+
23
+ // Export
24
+ export { markdownDocToPdf, docToPdf } from './export.js';
25
+ export type { PdfExportOptions } from './export.js';
26
+
27
+ // Import
28
+ export { pdfToMarkdownDoc, pdfToDoc, configurePdfWorker } from './import.js';
29
+ export type { PdfImportOptions } from './import.js';
@@ -0,0 +1,180 @@
1
+ /**
2
+ * PDF Style / Layout Constants
3
+ *
4
+ * Shared constants used by both PDF export and import. Defines page
5
+ * dimensions, margins, font sizes, colours, and spacing for rendering
6
+ * MarkdownDocument content as a paginated PDF.
7
+ */
8
+
9
+ // ============================================
10
+ // Page Layout
11
+ // ============================================
12
+
13
+ /** Standard US Letter page width in points (8.5 in × 72 pt/in). */
14
+ export const PAGE_WIDTH_LETTER = 612;
15
+
16
+ /** Standard US Letter page height in points (11 in × 72 pt/in). */
17
+ export const PAGE_HEIGHT_LETTER = 792;
18
+
19
+ /** A4 page width in points (210 mm ≈ 595 pt). */
20
+ export const PAGE_WIDTH_A4 = 595.28;
21
+
22
+ /** A4 page height in points (297 mm ≈ 842 pt). */
23
+ export const PAGE_HEIGHT_A4 = 841.89;
24
+
25
+ /** Default page margins in points (1 inch = 72 pt). */
26
+ export const DEFAULT_MARGIN = 72;
27
+
28
+ // ============================================
29
+ // Fonts — pdf-lib standard font names
30
+ // ============================================
31
+
32
+ export const FONT_REGULAR = 'Helvetica';
33
+ export const FONT_BOLD = 'Helvetica-Bold';
34
+ export const FONT_ITALIC = 'Helvetica-Oblique';
35
+ export const FONT_BOLD_ITALIC = 'Helvetica-BoldOblique';
36
+ export const FONT_MONO = 'Courier';
37
+ export const FONT_MONO_BOLD = 'Courier-Bold';
38
+
39
+ // ============================================
40
+ // Font Sizes
41
+ // ============================================
42
+
43
+ /** Default body font size in points. */
44
+ export const DEFAULT_FONT_SIZE = 11;
45
+
46
+ /** Heading font sizes indexed by depth (1-based). */
47
+ export const HEADING_SIZES: Record<number, number> = {
48
+ 1: 24,
49
+ 2: 20,
50
+ 3: 16,
51
+ 4: 14,
52
+ 5: 13,
53
+ 6: 12,
54
+ };
55
+
56
+ /** Font size used for code blocks and inline code. */
57
+ export const CODE_FONT_SIZE = 10;
58
+
59
+ // ============================================
60
+ // Spacing (in points)
61
+ // ============================================
62
+
63
+ /** Line height multiplier (leading). */
64
+ export const LINE_HEIGHT_FACTOR = 1.4;
65
+
66
+ /** Space above a heading. */
67
+ export const HEADING_SPACE_BEFORE = 18;
68
+
69
+ /** Space below a heading. */
70
+ export const HEADING_SPACE_AFTER = 6;
71
+
72
+ /** Space between paragraphs. */
73
+ export const PARAGRAPH_SPACING = 8;
74
+
75
+ /** Extra indent per list nesting level. */
76
+ export const LIST_INDENT = 24;
77
+
78
+ /** Bullet character for unordered lists. */
79
+ export const BULLET_CHAR = '\u2022'; // •
80
+
81
+ /** Indent for blockquotes. */
82
+ export const BLOCKQUOTE_INDENT = 24;
83
+
84
+ /** Width of the blockquote left bar. */
85
+ export const BLOCKQUOTE_BAR_WIDTH = 3;
86
+
87
+ // ============================================
88
+ // Colours (RGB 0-1)
89
+ // ============================================
90
+
91
+ export const COLOR_TEXT = { r: 0.12, g: 0.12, b: 0.14 };
92
+ export const COLOR_HEADING = { r: 0.08, g: 0.08, b: 0.1 };
93
+ export const COLOR_LINK = { r: 0.05, g: 0.27, b: 0.73 };
94
+ export const COLOR_CODE_BG = { r: 0.95, g: 0.95, b: 0.97 };
95
+ export const COLOR_CODE_TEXT = { r: 0.2, g: 0.2, b: 0.22 };
96
+ export const COLOR_BLOCKQUOTE_BAR = { r: 0.75, g: 0.75, b: 0.78 };
97
+ export const COLOR_BLOCKQUOTE_TEXT = { r: 0.35, g: 0.35, b: 0.38 };
98
+ export const COLOR_THEMATIC_BREAK = { r: 0.78, g: 0.78, b: 0.8 };
99
+ export const COLOR_TABLE_BORDER = { r: 0.75, g: 0.75, b: 0.78 };
100
+ export const COLOR_TABLE_HEADER_BG = { r: 0.93, g: 0.93, b: 0.95 };
101
+
102
+ // ============================================
103
+ // Table Constants
104
+ // ============================================
105
+
106
+ /** Table cell horizontal padding in points. */
107
+ export const TABLE_CELL_PAD_X = 6;
108
+
109
+ /** Table cell vertical padding in points. */
110
+ export const TABLE_CELL_PAD_Y = 4;
111
+
112
+ /** Table border line width. */
113
+ export const TABLE_BORDER_WIDTH = 0.5;
114
+
115
+ // ============================================
116
+ // Import Heuristic Thresholds
117
+ // ============================================
118
+
119
+ /**
120
+ * Minimum font size (in PDF points) to consider as a heading.
121
+ * Anything ≥ this and larger than the detected body size is a heading.
122
+ */
123
+ export const IMPORT_HEADING_MIN_SIZE = 13;
124
+
125
+ /**
126
+ * Font size ranges mapped to heading depth for import heuristics.
127
+ * Applied when a text item's font size exceeds the body size.
128
+ */
129
+ export const IMPORT_HEADING_SIZE_RANGES: Array<{ min: number; depth: number }> = [
130
+ { min: 22, depth: 1 },
131
+ { min: 18, depth: 2 },
132
+ { min: 15, depth: 3 },
133
+ { min: 13.5, depth: 4 },
134
+ { min: 12.5, depth: 5 },
135
+ { min: 12, depth: 6 },
136
+ ];
137
+
138
+ /**
139
+ * Y-distance (in points) between lines that implies a paragraph break
140
+ * rather than a continuation of the same paragraph.
141
+ */
142
+ export const IMPORT_PARAGRAPH_GAP = 4;
143
+
144
+ /**
145
+ * Characters that indicate an unordered list bullet at the start of a line.
146
+ */
147
+ export const IMPORT_BULLET_CHARS = new Set([
148
+ '\u2022',
149
+ '\u2023',
150
+ '\u25E6',
151
+ '\u2043',
152
+ '-',
153
+ '*',
154
+ '\u2013',
155
+ '\u2014',
156
+ '\u25AA',
157
+ '\u25AB',
158
+ ]);
159
+
160
+ /**
161
+ * Regex to detect an ordered list prefix (e.g. "1.", "2)", "iv.").
162
+ */
163
+ export const IMPORT_ORDERED_PREFIX = /^(\d+|[a-z]+|[ivxlcdm]+)[.)]\s/i;
164
+
165
+ /**
166
+ * Column alignment tolerance — text items whose x-positions differ by
167
+ * less than this are considered to be in the same column (for table detection).
168
+ */
169
+ export const IMPORT_COLUMN_TOLERANCE = 8;
170
+
171
+ /**
172
+ * Minimum number of consecutive rows with the same column count to
173
+ * consider them a table.
174
+ */
175
+ export const IMPORT_TABLE_MIN_ROWS = 2;
176
+
177
+ /**
178
+ * URL pattern for detecting links in extracted text.
179
+ */
180
+ export const IMPORT_URL_PATTERN = /https?:\/\/[^\s)>\]]+/g;
@@ -0,0 +1,78 @@
1
+ /**
2
+ * @bendyline/squisq-formats PPTX Module (Stub)
3
+ *
4
+ * Placeholder for PowerPoint .pptx import/export support.
5
+ * Will use PresentationML (`<p:presentation>`, `<p:sld>`) via the
6
+ * shared ooxml/ infrastructure.
7
+ *
8
+ * @example
9
+ * ```ts
10
+ * import { markdownDocToPptx } from '@bendyline/squisq-formats/pptx';
11
+ * ```
12
+ */
13
+
14
+ import type { MarkdownDocument } from '@bendyline/squisq/markdown';
15
+ import type { Doc } from '@bendyline/squisq/schemas';
16
+
17
+ /**
18
+ * Options for PPTX export (placeholder).
19
+ */
20
+ export interface PptxExportOptions {
21
+ /** Presentation title */
22
+ title?: string;
23
+ /** Presentation author */
24
+ author?: string;
25
+ }
26
+
27
+ /**
28
+ * Options for PPTX import (placeholder).
29
+ */
30
+ export interface PptxImportOptions {
31
+ /** Whether to extract embedded images as data URIs */
32
+ extractImages?: boolean;
33
+ }
34
+
35
+ /**
36
+ * Convert a MarkdownDocument to a .pptx Blob.
37
+ *
38
+ * @throws Error — PPTX support is not yet implemented
39
+ */
40
+ export async function markdownDocToPptx(
41
+ _doc: MarkdownDocument,
42
+ _options?: PptxExportOptions,
43
+ ): Promise<Blob> {
44
+ throw new Error('PPTX export is not yet implemented');
45
+ }
46
+
47
+ /**
48
+ * Convert a squisq Doc to a .pptx Blob.
49
+ *
50
+ * @throws Error — PPTX support is not yet implemented
51
+ */
52
+ export async function docToPptx(_doc: Doc, _options?: PptxExportOptions): Promise<Blob> {
53
+ throw new Error('PPTX export is not yet implemented');
54
+ }
55
+
56
+ /**
57
+ * Convert a .pptx file to a MarkdownDocument.
58
+ *
59
+ * @throws Error — PPTX support is not yet implemented
60
+ */
61
+ export async function pptxToMarkdownDoc(
62
+ _data: ArrayBuffer | Blob,
63
+ _options?: PptxImportOptions,
64
+ ): Promise<MarkdownDocument> {
65
+ throw new Error('PPTX import is not yet implemented');
66
+ }
67
+
68
+ /**
69
+ * Convert a .pptx file to a squisq Doc.
70
+ *
71
+ * @throws Error — PPTX support is not yet implemented
72
+ */
73
+ export async function pptxToDoc(
74
+ _data: ArrayBuffer | Blob,
75
+ _options?: PptxImportOptions,
76
+ ): Promise<Doc> {
77
+ throw new Error('PPTX import is not yet implemented');
78
+ }
@@ -0,0 +1,78 @@
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
+ import type { MarkdownDocument } from '@bendyline/squisq/markdown';
15
+ import type { Doc } from '@bendyline/squisq/schemas';
16
+
17
+ /**
18
+ * Options for XLSX export (placeholder).
19
+ */
20
+ export interface XlsxExportOptions {
21
+ /** Workbook title */
22
+ title?: string;
23
+ /** Workbook author */
24
+ author?: string;
25
+ }
26
+
27
+ /**
28
+ * Options for XLSX import (placeholder).
29
+ */
30
+ export interface XlsxImportOptions {
31
+ /** Which sheet to import (0-based index or name). Default: 0 */
32
+ sheet?: number | string;
33
+ }
34
+
35
+ /**
36
+ * Convert a MarkdownDocument to a .xlsx Blob.
37
+ *
38
+ * @throws Error — XLSX support is not yet implemented
39
+ */
40
+ export async function markdownDocToXlsx(
41
+ _doc: MarkdownDocument,
42
+ _options?: XlsxExportOptions,
43
+ ): Promise<Blob> {
44
+ throw new Error('XLSX export is not yet implemented');
45
+ }
46
+
47
+ /**
48
+ * Convert a squisq Doc to a .xlsx Blob.
49
+ *
50
+ * @throws Error — XLSX support is not yet implemented
51
+ */
52
+ export async function docToXlsx(_doc: Doc, _options?: XlsxExportOptions): Promise<Blob> {
53
+ throw new Error('XLSX export is not yet implemented');
54
+ }
55
+
56
+ /**
57
+ * Convert a .xlsx file to a MarkdownDocument.
58
+ *
59
+ * @throws Error — XLSX support is not yet implemented
60
+ */
61
+ export async function xlsxToMarkdownDoc(
62
+ _data: ArrayBuffer | Blob,
63
+ _options?: XlsxImportOptions,
64
+ ): Promise<MarkdownDocument> {
65
+ throw new Error('XLSX import is not yet implemented');
66
+ }
67
+
68
+ /**
69
+ * Convert a .xlsx file to a squisq Doc.
70
+ *
71
+ * @throws Error — XLSX support is not yet implemented
72
+ */
73
+ export async function xlsxToDoc(
74
+ _data: ArrayBuffer | Blob,
75
+ _options?: XlsxImportOptions,
76
+ ): Promise<Doc> {
77
+ throw new Error('XLSX import is not yet implemented');
78
+ }