@bendyline/squisq-formats 2.0.1 → 2.2.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.
- package/LICENSE +21 -0
- package/NOTICE.md +20 -0
- package/README.md +1 -1
- package/dist/{chunk-CRAVSMPZ.js → chunk-26ISNJ7Y.js} +356 -114
- package/dist/{chunk-NKAJPJ4G.js → chunk-2JJ5RFDZ.js} +0 -1
- package/dist/{chunk-HTW2M27H.js → chunk-3NKXBZSR.js} +193 -42
- package/dist/{chunk-U32AG3G3.js → chunk-4V3KCHAP.js} +3 -4
- package/dist/{chunk-MLX2BOJC.js → chunk-6RQOV3B3.js} +1 -2
- package/dist/{chunk-QRVN6A6E.js → chunk-6S6GU3ZG.js} +5 -6
- package/dist/{chunk-FE6OJV6O.js → chunk-7AWFHP5U.js} +1 -1
- package/dist/{chunk-RFAPOKHJ.js → chunk-AD2WT564.js} +59 -9
- package/dist/{chunk-O3GVVND4.js → chunk-AONELFLA.js} +0 -1
- package/dist/{chunk-XKUMNGBW.js → chunk-EJTNGKEA.js} +5 -8
- package/dist/chunk-GX7RAUME.js +121 -0
- package/dist/{chunk-SSUPBUF5.js → chunk-IIQYS2YH.js} +0 -1
- package/dist/{chunk-ABVI556T.js → chunk-IPN56VLW.js} +83 -58
- package/dist/{chunk-LXYLOOST.js → chunk-JE6LSIHE.js} +83 -22
- package/dist/{chunk-U4MRIFKL.js → chunk-JU2RHXUB.js} +0 -1
- package/dist/{chunk-4VUWTSGM.js → chunk-K6XRMVPW.js} +64 -31
- package/dist/{chunk-ODL3SSPT.js → chunk-KXOZMWBS.js} +0 -1
- package/dist/chunk-OGS5VCGJ.js +446 -0
- package/dist/{chunk-GVS2XXV6.js → chunk-PJXJI2LY.js} +449 -57
- package/dist/{chunk-2KPARF2P.js → chunk-PU7REGWV.js} +5 -8
- package/dist/{chunk-PN52A5AA.js → chunk-SBUW7NHR.js} +0 -1
- package/dist/{chunk-VSYHZECT.js → chunk-TAAENIRB.js} +5 -8
- package/dist/{chunk-WC7WULGV.js → chunk-X2DEAXNK.js} +62 -2
- package/dist/container/index.js +1 -2
- package/dist/csv/index.d.ts +27 -2
- package/dist/csv/index.js +1 -2
- package/dist/docx/index.d.ts +5 -1
- package/dist/docx/index.js +9 -10
- package/dist/epub/index.d.ts +2 -0
- package/dist/epub/index.js +5 -6
- package/dist/{export-D2NkylDT.d.ts → export-D9msROJS.d.ts} +18 -6
- package/dist/extract-MN7LA3NL.js +13 -0
- package/dist/html/index.d.ts +11 -4
- package/dist/html/index.js +3 -4
- package/dist/images-ESPQKVTW.js +6 -0
- package/dist/{import-K8mfc0fz.d.ts → import-C3htUTss.d.ts} +5 -1
- package/dist/{import-DTkDxHmZ.d.ts → import-C8whCC7_.d.ts} +6 -0
- package/dist/index.d.ts +7 -7
- package/dist/index.js +28 -26
- package/dist/infer/index.d.ts +3 -3
- package/dist/infer/index.js +7 -9
- package/dist/{layouts-BHrgZ5FS.d.ts → layouts-CTdPlB-u.d.ts} +1 -1
- package/dist/layouts-DRWZGSPD.js +10 -0
- package/dist/{mapTheme-IR27S6IV.js → mapTheme-4TWH25FT.js} +1 -2
- package/dist/ooxml/index.d.ts +3 -3
- package/dist/ooxml/index.js +14 -13
- package/dist/pdf/index.d.ts +18 -0
- package/dist/pdf/index.js +2 -3
- package/dist/pptx/index.d.ts +4 -4
- package/dist/pptx/index.js +11 -13
- package/dist/{reader-B9L8Ucbj.d.ts → reader-B_m1aKZC.d.ts} +30 -1
- package/dist/registry/index.d.ts +21 -5
- package/dist/registry/index.js +9 -6
- package/dist/{themeReader-DJKErl_j.d.ts → themeReader-DCtwC83Q.d.ts} +1 -1
- package/dist/xlsx/index.d.ts +3 -3
- package/dist/xlsx/index.js +6 -7
- package/package.json +6 -3
- package/dist/chunk-2KPARF2P.js.map +0 -1
- package/dist/chunk-4VUWTSGM.js.map +0 -1
- package/dist/chunk-6M7Z25LA.js +0 -46
- package/dist/chunk-6M7Z25LA.js.map +0 -1
- package/dist/chunk-ABVI556T.js.map +0 -1
- package/dist/chunk-CRAVSMPZ.js.map +0 -1
- package/dist/chunk-FE6OJV6O.js.map +0 -1
- package/dist/chunk-GVS2XXV6.js.map +0 -1
- package/dist/chunk-HTW2M27H.js.map +0 -1
- package/dist/chunk-LXYLOOST.js.map +0 -1
- package/dist/chunk-MLX2BOJC.js.map +0 -1
- package/dist/chunk-NKAJPJ4G.js.map +0 -1
- package/dist/chunk-O3GVVND4.js.map +0 -1
- package/dist/chunk-ODL3SSPT.js.map +0 -1
- package/dist/chunk-PN52A5AA.js.map +0 -1
- package/dist/chunk-QRVN6A6E.js.map +0 -1
- package/dist/chunk-RFAPOKHJ.js.map +0 -1
- package/dist/chunk-SSUPBUF5.js.map +0 -1
- package/dist/chunk-U32AG3G3.js.map +0 -1
- package/dist/chunk-U4MRIFKL.js.map +0 -1
- package/dist/chunk-VJJM2SSH.js +0 -275
- package/dist/chunk-VJJM2SSH.js.map +0 -1
- package/dist/chunk-VSYHZECT.js.map +0 -1
- package/dist/chunk-WC7WULGV.js.map +0 -1
- package/dist/chunk-XKUMNGBW.js.map +0 -1
- package/dist/chunk-YRT7GQ5Y.js +0 -28
- package/dist/chunk-YRT7GQ5Y.js.map +0 -1
- package/dist/container/index.js.map +0 -1
- package/dist/csv/index.js.map +0 -1
- package/dist/docx/index.js.map +0 -1
- package/dist/epub/index.js.map +0 -1
- package/dist/extract-H6RXJMHP.js +0 -15
- package/dist/extract-H6RXJMHP.js.map +0 -1
- package/dist/html/index.js.map +0 -1
- package/dist/images-7FBWPKE3.js +0 -7
- package/dist/images-7FBWPKE3.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/infer/index.js.map +0 -1
- package/dist/layouts-QVPK3ZCU.js +0 -12
- package/dist/layouts-QVPK3ZCU.js.map +0 -1
- package/dist/mapTheme-IR27S6IV.js.map +0 -1
- package/dist/ooxml/index.js.map +0 -1
- package/dist/pdf/index.js.map +0 -1
- package/dist/pptx/index.js.map +0 -1
- package/dist/registry/index.js.map +0 -1
- package/dist/xlsx/index.js.map +0 -1
- package/src/__tests__/container.test.ts +0 -230
- package/src/__tests__/convert.test.ts +0 -495
- package/src/__tests__/csvImport.test.ts +0 -84
- package/src/__tests__/docxExport.test.ts +0 -457
- package/src/__tests__/docxImport.test.ts +0 -410
- package/src/__tests__/epub.test.ts +0 -649
- package/src/__tests__/exportThemeReconciliation.test.ts +0 -87
- package/src/__tests__/formatRegistry.test.ts +0 -174
- package/src/__tests__/html.test.ts +0 -435
- package/src/__tests__/htmlImport.test.ts +0 -57
- package/src/__tests__/inferTheme.test.ts +0 -135
- package/src/__tests__/lossyWarnings.test.ts +0 -146
- package/src/__tests__/ooxml.test.ts +0 -271
- package/src/__tests__/ooxmlCancellation.test.ts +0 -113
- package/src/__tests__/ooxmlThemeReader.test.ts +0 -92
- package/src/__tests__/pdfExport.test.ts +0 -322
- package/src/__tests__/pdfImport.test.ts +0 -384
- package/src/__tests__/plainHtml.test.ts +0 -417
- package/src/__tests__/plainHtmlBundle.test.ts +0 -253
- package/src/__tests__/pptxExport.test.ts +0 -138
- package/src/__tests__/pptxImport.test.ts +0 -145
- package/src/__tests__/pptxInferFixtures.ts +0 -314
- package/src/__tests__/pptxLayoutInfer.test.ts +0 -395
- package/src/__tests__/roundTrip.test.ts +0 -201
- package/src/__tests__/roundTripAssets.test.ts +0 -50
- package/src/__tests__/roundTripMatrix.fixtures.ts +0 -86
- package/src/__tests__/roundTripMatrix.helpers.ts +0 -154
- package/src/__tests__/roundTripMatrix.test.ts +0 -142
- package/src/__tests__/sharedContainer.test.ts +0 -41
- package/src/__tests__/sharedImages.test.ts +0 -61
- package/src/__tests__/xlsxExport.test.ts +0 -164
- package/src/__tests__/xlsxImport.test.ts +0 -80
- package/src/__tests__/zipSafety.test.ts +0 -317
- package/src/container/index.ts +0 -94
- package/src/csv/index.ts +0 -188
- package/src/docx/export.ts +0 -1267
- package/src/docx/import.ts +0 -995
- package/src/docx/index.ts +0 -26
- package/src/docx/styles.ts +0 -145
- package/src/epub/export.ts +0 -968
- package/src/epub/index.ts +0 -20
- package/src/html/docsHtmlBundle.ts +0 -373
- package/src/html/htmlTemplate.ts +0 -385
- package/src/html/imageUtils.ts +0 -61
- package/src/html/import.ts +0 -297
- package/src/html/index.ts +0 -212
- package/src/html/plainHtml.ts +0 -790
- package/src/html/plainHtmlBundle.ts +0 -421
- package/src/index.ts +0 -109
- package/src/infer/extract.ts +0 -127
- package/src/infer/index.ts +0 -199
- package/src/infer/mapTheme.ts +0 -176
- package/src/infer/types.ts +0 -27
- package/src/ooxml/index.ts +0 -111
- package/src/ooxml/namespaces.ts +0 -196
- package/src/ooxml/readUtils.ts +0 -44
- package/src/ooxml/reader.ts +0 -318
- package/src/ooxml/themeReader.ts +0 -197
- package/src/ooxml/types.ts +0 -103
- package/src/ooxml/writer.ts +0 -339
- package/src/ooxml/xmlUtils.ts +0 -123
- package/src/pdf/export.ts +0 -1084
- package/src/pdf/import.ts +0 -1164
- package/src/pdf/index.ts +0 -29
- package/src/pdf/styles.ts +0 -180
- package/src/pptx/export.ts +0 -1184
- package/src/pptx/import.ts +0 -455
- package/src/pptx/index.ts +0 -52
- package/src/pptx/layouts.ts +0 -1222
- package/src/pptx/styles.ts +0 -96
- package/src/pptx/templates.ts +0 -187
- package/src/registry/convert.ts +0 -433
- package/src/registry/defaultFormats.ts +0 -413
- package/src/registry/errors.ts +0 -46
- package/src/registry/index.ts +0 -43
- package/src/registry/registry.ts +0 -48
- package/src/registry/types.ts +0 -170
- package/src/shared/boundedZipArchive.ts +0 -383
- package/src/shared/container.ts +0 -28
- package/src/shared/fidelity.ts +0 -130
- package/src/shared/images.ts +0 -44
- package/src/shared/inlineRuns.ts +0 -99
- package/src/shared/text.ts +0 -41
- package/src/shared/zipEntryCount.ts +0 -151
- package/src/shared/zipLimits.ts +0 -296
- package/src/shared/zipSafety.ts +0 -19
- package/src/xlsx/export.ts +0 -253
- package/src/xlsx/import.ts +0 -160
- package/src/xlsx/index.ts +0 -35
package/src/xlsx/import.ts
DELETED
|
@@ -1,160 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* XLSX import — SpreadsheetML (.xlsx) → MarkdownDocument.
|
|
3
|
-
*
|
|
4
|
-
* Reuses the shared ooxml/ reader (zip + DOMParser). Reads the workbook's
|
|
5
|
-
* sheet list, resolves each sheet part via relationships, pulls shared strings,
|
|
6
|
-
* and turns each worksheet's cell grid into a markdown table (first row treated
|
|
7
|
-
* as the header). By default every sheet is imported, each preceded by an H1 of
|
|
8
|
-
* the sheet name; pass `options.sheet` (index or name) to import just one.
|
|
9
|
-
*/
|
|
10
|
-
|
|
11
|
-
import type {
|
|
12
|
-
MarkdownBlockNode,
|
|
13
|
-
MarkdownDocument,
|
|
14
|
-
MarkdownTable,
|
|
15
|
-
MarkdownTableCell,
|
|
16
|
-
MarkdownTableRow,
|
|
17
|
-
} from '@bendyline/squisq/markdown';
|
|
18
|
-
import { getPartXml, getPartRelationships, openPackage } from '../ooxml/reader.js';
|
|
19
|
-
import type { OoxmlOpenOptions } from '../ooxml/reader.js';
|
|
20
|
-
import type { OoxmlPackage } from '../ooxml/types.js';
|
|
21
|
-
import { NS_R, NS_SML } from '../ooxml/namespaces.js';
|
|
22
|
-
|
|
23
|
-
export interface XlsxImportOptions extends OoxmlOpenOptions {
|
|
24
|
-
/** Which sheet to import (0-based index or sheet name). Default: all sheets. */
|
|
25
|
-
sheet?: number | string;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
interface SheetRef {
|
|
29
|
-
name: string;
|
|
30
|
-
path: string;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
function attrNS(el: Element, ns: string, local: string, fallback: string): string | null {
|
|
34
|
-
return el.getAttributeNS(ns, local) ?? el.getAttribute(fallback);
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
/** Resolve a relationship target (relative to its part's dir) to a zip path. */
|
|
38
|
-
function resolveTarget(baseDir: string, target: string): string {
|
|
39
|
-
if (target.startsWith('/')) return target.replace(/^\//, '');
|
|
40
|
-
const stack = baseDir ? baseDir.split('/') : [];
|
|
41
|
-
for (const seg of target.split('/')) {
|
|
42
|
-
if (seg === '..') stack.pop();
|
|
43
|
-
else if (seg !== '.') stack.push(seg);
|
|
44
|
-
}
|
|
45
|
-
return stack.join('/');
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
async function readSheets(pkg: OoxmlPackage): Promise<SheetRef[]> {
|
|
49
|
-
const wb = await getPartXml(pkg, 'xl/workbook.xml');
|
|
50
|
-
if (!wb) return [];
|
|
51
|
-
const rels = await getPartRelationships(pkg, 'xl/workbook.xml');
|
|
52
|
-
const relById = new Map(rels.map((r) => [r.id, r.target]));
|
|
53
|
-
const out: SheetRef[] = [];
|
|
54
|
-
const sheetEls = wb.getElementsByTagNameNS(NS_SML, 'sheet');
|
|
55
|
-
for (let i = 0; i < sheetEls.length; i++) {
|
|
56
|
-
const el = sheetEls[i]!;
|
|
57
|
-
const name = el.getAttribute('name') ?? `Sheet${i + 1}`;
|
|
58
|
-
const rid = attrNS(el, NS_R, 'id', 'r:id');
|
|
59
|
-
const target = rid ? relById.get(rid) : undefined;
|
|
60
|
-
if (target) out.push({ name, path: resolveTarget('xl', target) });
|
|
61
|
-
}
|
|
62
|
-
return out;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
async function readSharedStrings(pkg: OoxmlPackage): Promise<string[]> {
|
|
66
|
-
const doc = await getPartXml(pkg, 'xl/sharedStrings.xml');
|
|
67
|
-
if (!doc) return [];
|
|
68
|
-
const siEls = doc.getElementsByTagNameNS(NS_SML, 'si');
|
|
69
|
-
const out: string[] = [];
|
|
70
|
-
for (let i = 0; i < siEls.length; i++) out.push(siEls[i]!.textContent ?? '');
|
|
71
|
-
return out;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
/** Column letters of a cell ref ("B7" → 1, "AA1" → 26). */
|
|
75
|
-
function colIndex(ref: string): number {
|
|
76
|
-
const m = /^([A-Za-z]+)/.exec(ref);
|
|
77
|
-
if (!m) return 0;
|
|
78
|
-
let n = 0;
|
|
79
|
-
for (const ch of m[1]!.toUpperCase()) n = n * 26 + (ch.charCodeAt(0) - 64);
|
|
80
|
-
return n - 1;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
function cellText(cell: Element, shared: string[]): string {
|
|
84
|
-
const t = cell.getAttribute('t');
|
|
85
|
-
if (t === 'inlineStr') {
|
|
86
|
-
const is = cell.getElementsByTagNameNS(NS_SML, 't');
|
|
87
|
-
return is.length ? (is[0]!.textContent ?? '') : '';
|
|
88
|
-
}
|
|
89
|
-
const vEls = cell.getElementsByTagNameNS(NS_SML, 'v');
|
|
90
|
-
const v = vEls.length ? (vEls[0]!.textContent ?? '') : '';
|
|
91
|
-
if (t === 's') return shared[Number.parseInt(v, 10)] ?? '';
|
|
92
|
-
if (t === 'b') return v === '1' ? 'TRUE' : 'FALSE';
|
|
93
|
-
return v;
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
async function sheetToGrid(pkg: OoxmlPackage, path: string, shared: string[]): Promise<string[][]> {
|
|
97
|
-
const doc = await getPartXml(pkg, path);
|
|
98
|
-
if (!doc) return [];
|
|
99
|
-
const rowEls = doc.getElementsByTagNameNS(NS_SML, 'row');
|
|
100
|
-
const grid: string[][] = [];
|
|
101
|
-
for (let r = 0; r < rowEls.length; r++) {
|
|
102
|
-
const cells = rowEls[r]!.getElementsByTagNameNS(NS_SML, 'c');
|
|
103
|
-
const rowArr: string[] = [];
|
|
104
|
-
for (let c = 0; c < cells.length; c++) {
|
|
105
|
-
const cell = cells[c]!;
|
|
106
|
-
const ref = cell.getAttribute('r');
|
|
107
|
-
const idx = ref ? colIndex(ref) : rowArr.length;
|
|
108
|
-
while (rowArr.length < idx) rowArr.push('');
|
|
109
|
-
rowArr[idx] = cellText(cell, shared);
|
|
110
|
-
}
|
|
111
|
-
grid.push(rowArr);
|
|
112
|
-
}
|
|
113
|
-
return grid;
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
function gridToTable(grid: string[][]): MarkdownTable {
|
|
117
|
-
const maxCols = grid.reduce((m, r) => Math.max(m, r.length), 1);
|
|
118
|
-
const rows: MarkdownTableRow[] = grid.map((cells, rowIdx) => {
|
|
119
|
-
const children: MarkdownTableCell[] = [];
|
|
120
|
-
for (let c = 0; c < maxCols; c++) {
|
|
121
|
-
const value = cells[c] ?? '';
|
|
122
|
-
children.push({
|
|
123
|
-
type: 'tableCell',
|
|
124
|
-
...(rowIdx === 0 ? { isHeader: true } : {}),
|
|
125
|
-
children: value ? [{ type: 'text', value }] : [],
|
|
126
|
-
});
|
|
127
|
-
}
|
|
128
|
-
return { type: 'tableRow', children };
|
|
129
|
-
});
|
|
130
|
-
return { type: 'table', children: rows };
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
export async function xlsxToMarkdownDoc(
|
|
134
|
-
data: ArrayBuffer | Blob,
|
|
135
|
-
options: XlsxImportOptions = {},
|
|
136
|
-
): Promise<MarkdownDocument> {
|
|
137
|
-
const pkg = await openPackage(data, options);
|
|
138
|
-
const sheets = await readSheets(pkg);
|
|
139
|
-
const shared = await readSharedStrings(pkg);
|
|
140
|
-
|
|
141
|
-
let selected = sheets;
|
|
142
|
-
if (options.sheet !== undefined) {
|
|
143
|
-
const picked =
|
|
144
|
-
typeof options.sheet === 'number'
|
|
145
|
-
? sheets[options.sheet]
|
|
146
|
-
: sheets.find((s) => s.name === options.sheet);
|
|
147
|
-
selected = picked ? [picked] : [];
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
const children: MarkdownBlockNode[] = [];
|
|
151
|
-
const single = selected.length === 1 && options.sheet !== undefined;
|
|
152
|
-
for (const sheet of selected) {
|
|
153
|
-
const grid = await sheetToGrid(pkg, sheet.path, shared);
|
|
154
|
-
if (!single) {
|
|
155
|
-
children.push({ type: 'heading', depth: 1, children: [{ type: 'text', value: sheet.name }] });
|
|
156
|
-
}
|
|
157
|
-
if (grid.length > 0) children.push(gridToTable(grid));
|
|
158
|
-
}
|
|
159
|
-
return { type: 'document', children };
|
|
160
|
-
}
|
package/src/xlsx/index.ts
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @bendyline/squisq-formats XLSX Module
|
|
3
|
-
*
|
|
4
|
-
* Excel .xlsx support via SpreadsheetML and the shared ooxml/ infrastructure.
|
|
5
|
-
* Both directions are implemented: import (`xlsxToMarkdownDoc` / `xlsxToDoc`)
|
|
6
|
-
* turns each worksheet grid into a markdown table; export (`markdownDocToXlsx`
|
|
7
|
-
* / `docToXlsx`) turns each markdown table into a worksheet. Export is
|
|
8
|
-
* tables-only fidelity — non-table content is dropped (headings only survive
|
|
9
|
-
* as sheet names). See export.ts for details.
|
|
10
|
-
*
|
|
11
|
-
* @example
|
|
12
|
-
* ```ts
|
|
13
|
-
* import { xlsxToMarkdownDoc, markdownDocToXlsx } from '@bendyline/squisq-formats/xlsx';
|
|
14
|
-
* ```
|
|
15
|
-
*/
|
|
16
|
-
|
|
17
|
-
import { markdownToDoc } from '@bendyline/squisq/doc';
|
|
18
|
-
import type { Doc } from '@bendyline/squisq/schemas';
|
|
19
|
-
import { type XlsxImportOptions, xlsxToMarkdownDoc } from './import.js';
|
|
20
|
-
|
|
21
|
-
export type { XlsxImportOptions } from './import.js';
|
|
22
|
-
export { xlsxToMarkdownDoc } from './import.js';
|
|
23
|
-
|
|
24
|
-
export type { XlsxExportOptions } from './export.js';
|
|
25
|
-
export { markdownDocToXlsx, docToXlsx } from './export.js';
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* Convert a .xlsx file to a squisq Doc (via the markdown table model).
|
|
29
|
-
*/
|
|
30
|
-
export async function xlsxToDoc(
|
|
31
|
-
data: ArrayBuffer | Blob,
|
|
32
|
-
options?: XlsxImportOptions,
|
|
33
|
-
): Promise<Doc> {
|
|
34
|
-
return markdownToDoc(await xlsxToMarkdownDoc(data, options));
|
|
35
|
-
}
|