odf-kit 0.9.8 → 0.10.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/CHANGELOG.md +17 -0
- package/README.md +49 -2
- package/dist/docx/body-reader.d.ts +54 -0
- package/dist/docx/body-reader.d.ts.map +1 -0
- package/dist/docx/body-reader.js +1124 -0
- package/dist/docx/body-reader.js.map +1 -0
- package/dist/docx/converter.d.ts +51 -0
- package/dist/docx/converter.d.ts.map +1 -0
- package/dist/docx/converter.js +799 -0
- package/dist/docx/converter.js.map +1 -0
- package/dist/docx/index.d.ts +81 -0
- package/dist/docx/index.d.ts.map +1 -0
- package/dist/docx/index.js +69 -0
- package/dist/docx/index.js.map +1 -0
- package/dist/docx/numbering.d.ts +42 -0
- package/dist/docx/numbering.d.ts.map +1 -0
- package/dist/docx/numbering.js +236 -0
- package/dist/docx/numbering.js.map +1 -0
- package/dist/docx/reader.d.ts +38 -0
- package/dist/docx/reader.d.ts.map +1 -0
- package/dist/docx/reader.js +512 -0
- package/dist/docx/reader.js.map +1 -0
- package/dist/docx/relationships.d.ts +27 -0
- package/dist/docx/relationships.d.ts.map +1 -0
- package/dist/docx/relationships.js +89 -0
- package/dist/docx/relationships.js.map +1 -0
- package/dist/docx/styles.d.ts +46 -0
- package/dist/docx/styles.d.ts.map +1 -0
- package/dist/docx/styles.js +383 -0
- package/dist/docx/styles.js.map +1 -0
- package/dist/docx/types.d.ts +266 -0
- package/dist/docx/types.d.ts.map +1 -0
- package/dist/docx/types.js +38 -0
- package/dist/docx/types.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/xlsx/converter.d.ts +31 -0
- package/dist/xlsx/converter.d.ts.map +1 -0
- package/dist/xlsx/converter.js +132 -0
- package/dist/xlsx/converter.js.map +1 -0
- package/dist/xlsx/index.d.ts +23 -0
- package/dist/xlsx/index.d.ts.map +1 -0
- package/dist/xlsx/index.js +25 -0
- package/dist/xlsx/index.js.map +1 -0
- package/dist/xlsx/reader.d.ts +82 -0
- package/dist/xlsx/reader.d.ts.map +1 -0
- package/dist/xlsx/reader.js +449 -0
- package/dist/xlsx/reader.js.map +1 -0
- package/package.json +9 -1
|
@@ -0,0 +1,266 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* odf-kit — DOCX internal model types
|
|
3
|
+
*
|
|
4
|
+
* These types represent the parsed state of a .docx file. They are internal
|
|
5
|
+
* to the odf-kit/docx pipeline and are not part of the public API.
|
|
6
|
+
*
|
|
7
|
+
* Flow: .docx bytes → reader.ts → DocxDocument → converter.ts → OdtDocument
|
|
8
|
+
*/
|
|
9
|
+
export interface DocxDocument {
|
|
10
|
+
metadata: DocxMetadata;
|
|
11
|
+
pageLayout: DocxPageLayout;
|
|
12
|
+
body: DocxBodyElement[];
|
|
13
|
+
footnotes: Map<string, DocxNote>;
|
|
14
|
+
endnotes: Map<string, DocxNote>;
|
|
15
|
+
headers: DocxHeaderFooter[];
|
|
16
|
+
footers: DocxHeaderFooter[];
|
|
17
|
+
styles: StyleMap;
|
|
18
|
+
numbering: NumberingMap;
|
|
19
|
+
relationships: RelationshipMap;
|
|
20
|
+
images: ImageMap;
|
|
21
|
+
}
|
|
22
|
+
export interface DocxMetadata {
|
|
23
|
+
title: string | null;
|
|
24
|
+
creator: string | null;
|
|
25
|
+
description: string | null;
|
|
26
|
+
created: string | null;
|
|
27
|
+
modified: string | null;
|
|
28
|
+
}
|
|
29
|
+
export interface DocxPageLayout {
|
|
30
|
+
/** Page width in cm. */
|
|
31
|
+
width: number | null;
|
|
32
|
+
/** Page height in cm. */
|
|
33
|
+
height: number | null;
|
|
34
|
+
/** Margins in cm. */
|
|
35
|
+
marginTop: number | null;
|
|
36
|
+
marginBottom: number | null;
|
|
37
|
+
marginLeft: number | null;
|
|
38
|
+
marginRight: number | null;
|
|
39
|
+
/** "portrait" | "landscape". Derived from width vs height when w:orient absent. */
|
|
40
|
+
orientation: "portrait" | "landscape" | null;
|
|
41
|
+
}
|
|
42
|
+
export type DocxBodyElement = DocxParagraph | DocxTable | DocxPageBreak;
|
|
43
|
+
export interface DocxPageBreak {
|
|
44
|
+
type: "pageBreak";
|
|
45
|
+
}
|
|
46
|
+
export interface DocxParagraph {
|
|
47
|
+
type: "paragraph";
|
|
48
|
+
/** Resolved heading level (1–6), or null for body text. */
|
|
49
|
+
headingLevel: number | null;
|
|
50
|
+
/** Paragraph style ID from styles.xml, e.g. "Heading1", "Normal". */
|
|
51
|
+
styleId: string | null;
|
|
52
|
+
props: ParaProps;
|
|
53
|
+
runs: DocxInlineElement[];
|
|
54
|
+
}
|
|
55
|
+
export type DocxInlineElement = DocxRun | DocxHyperlink | DocxInlineImage | DocxFootnoteReference | DocxEndnoteReference | DocxBookmark | DocxTab | DocxLineBreak;
|
|
56
|
+
export interface DocxRun {
|
|
57
|
+
type: "run";
|
|
58
|
+
text: string;
|
|
59
|
+
props: RunProps;
|
|
60
|
+
}
|
|
61
|
+
export interface DocxHyperlink {
|
|
62
|
+
type: "hyperlink";
|
|
63
|
+
/** Resolved URL for external links; anchor target for internal links. */
|
|
64
|
+
url: string;
|
|
65
|
+
/** True if this is an internal bookmark link (starts with #). */
|
|
66
|
+
internal: boolean;
|
|
67
|
+
runs: DocxRun[];
|
|
68
|
+
}
|
|
69
|
+
export interface DocxInlineImage {
|
|
70
|
+
type: "inlineImage";
|
|
71
|
+
/** Relationship ID — used to look up bytes in DocxDocument.images. */
|
|
72
|
+
rId: string;
|
|
73
|
+
/** Width in cm, derived from EMU value (1 cm = 914400 / 100 EMU). */
|
|
74
|
+
widthCm: number;
|
|
75
|
+
/** Height in cm. */
|
|
76
|
+
heightCm: number;
|
|
77
|
+
/** Alt text from wp:docPr descr attribute. */
|
|
78
|
+
altText: string | null;
|
|
79
|
+
}
|
|
80
|
+
export interface DocxFootnoteReference {
|
|
81
|
+
type: "footnoteReference";
|
|
82
|
+
/** Matches a key in DocxDocument.footnotes. */
|
|
83
|
+
id: string;
|
|
84
|
+
}
|
|
85
|
+
export interface DocxEndnoteReference {
|
|
86
|
+
type: "endnoteReference";
|
|
87
|
+
/** Matches a key in DocxDocument.endnotes. */
|
|
88
|
+
id: string;
|
|
89
|
+
}
|
|
90
|
+
export interface DocxNote {
|
|
91
|
+
id: string;
|
|
92
|
+
/** Full paragraph support — notes may contain multiple paragraphs. */
|
|
93
|
+
body: DocxBodyElement[];
|
|
94
|
+
}
|
|
95
|
+
export interface DocxBookmark {
|
|
96
|
+
type: "bookmark";
|
|
97
|
+
name: string;
|
|
98
|
+
/** "start" | "end" — paired markers in the body. */
|
|
99
|
+
position: "start" | "end";
|
|
100
|
+
}
|
|
101
|
+
export interface DocxTab {
|
|
102
|
+
type: "tab";
|
|
103
|
+
}
|
|
104
|
+
export interface DocxLineBreak {
|
|
105
|
+
type: "lineBreak";
|
|
106
|
+
}
|
|
107
|
+
export interface DocxTable {
|
|
108
|
+
type: "table";
|
|
109
|
+
/** Column widths in cm, one per column. Derived from w:tblGrid / w:gridCol. */
|
|
110
|
+
columnWidths: number[];
|
|
111
|
+
rows: DocxTableRow[];
|
|
112
|
+
}
|
|
113
|
+
export interface DocxTableRow {
|
|
114
|
+
cells: DocxTableCell[];
|
|
115
|
+
}
|
|
116
|
+
export interface DocxTableCell {
|
|
117
|
+
/** Number of columns this cell spans (w:gridSpan). Default: 1. */
|
|
118
|
+
colSpan: number;
|
|
119
|
+
/**
|
|
120
|
+
* Rowspan is inferred from w:vMerge / w:vMerge w:val="restart".
|
|
121
|
+
* "restart" = first cell of a vertical merge group.
|
|
122
|
+
* "continue" = continuation cell (rendered as merged, no output cell).
|
|
123
|
+
* null = not merged vertically.
|
|
124
|
+
*/
|
|
125
|
+
vMerge: "restart" | "continue" | null;
|
|
126
|
+
/** Background color (hex, no #), from w:shd w:fill. */
|
|
127
|
+
backgroundColor: string | null;
|
|
128
|
+
/** Vertical alignment: "top" | "center" | "bottom". */
|
|
129
|
+
verticalAlign: "top" | "center" | "bottom" | null;
|
|
130
|
+
body: DocxBodyElement[];
|
|
131
|
+
}
|
|
132
|
+
export interface DocxHeaderFooter {
|
|
133
|
+
/**
|
|
134
|
+
* "default" | "first" | "even"
|
|
135
|
+
* Corresponds to w:type attribute on w:hdr / w:ftr.
|
|
136
|
+
*/
|
|
137
|
+
headerType: "default" | "first" | "even";
|
|
138
|
+
body: DocxBodyElement[];
|
|
139
|
+
}
|
|
140
|
+
export interface RunProps {
|
|
141
|
+
bold: boolean;
|
|
142
|
+
italic: boolean;
|
|
143
|
+
underline: boolean;
|
|
144
|
+
strikethrough: boolean;
|
|
145
|
+
doubleStrikethrough: boolean;
|
|
146
|
+
superscript: boolean;
|
|
147
|
+
subscript: boolean;
|
|
148
|
+
smallCaps: boolean;
|
|
149
|
+
allCaps: boolean;
|
|
150
|
+
/** Hex color string without #, e.g. "FF0000". Null = auto/default. */
|
|
151
|
+
color: string | null;
|
|
152
|
+
/** Font size in points. Null = inherited. */
|
|
153
|
+
fontSize: number | null;
|
|
154
|
+
/** Highlight color name, e.g. "yellow", "cyan". Null = none. */
|
|
155
|
+
highlight: string | null;
|
|
156
|
+
/** Font family name. Null = inherited. */
|
|
157
|
+
fontFamily: string | null;
|
|
158
|
+
/** BCP 47 language tag, e.g. "en-US". Null = inherited. */
|
|
159
|
+
lang: string | null;
|
|
160
|
+
/** Character style ID reference. Null = none. */
|
|
161
|
+
rStyleId: string | null;
|
|
162
|
+
}
|
|
163
|
+
export declare const DEFAULT_RUN_PROPS: RunProps;
|
|
164
|
+
export interface ParaProps {
|
|
165
|
+
/** "left" | "center" | "right" | "justify". Null = inherited. */
|
|
166
|
+
alignment: "left" | "center" | "right" | "justify" | null;
|
|
167
|
+
/**
|
|
168
|
+
* Force a page break before this paragraph (w:pageBreakBefore).
|
|
169
|
+
* When true the converter emits a page break before the paragraph.
|
|
170
|
+
*/
|
|
171
|
+
pageBreakBefore: boolean;
|
|
172
|
+
/** Space before paragraph in cm. Null = inherited. */
|
|
173
|
+
spaceBefore: number | null;
|
|
174
|
+
/** Space after paragraph in cm. Null = inherited. */
|
|
175
|
+
spaceAfter: number | null;
|
|
176
|
+
/**
|
|
177
|
+
* Line height. Null = auto (single).
|
|
178
|
+
* Expressed as a multiplier, e.g. 1.5 = 150%, 2.0 = double.
|
|
179
|
+
*/
|
|
180
|
+
lineHeight: number | null;
|
|
181
|
+
/** Left indentation in cm. Null = none. */
|
|
182
|
+
indentLeft: number | null;
|
|
183
|
+
/** Right indentation in cm. Null = none. */
|
|
184
|
+
indentRight: number | null;
|
|
185
|
+
/** First-line indentation in cm. Negative = hanging. Null = none. */
|
|
186
|
+
indentFirstLine: number | null;
|
|
187
|
+
/**
|
|
188
|
+
* List membership. Null = not a list item.
|
|
189
|
+
*/
|
|
190
|
+
list: ParaListProps | null;
|
|
191
|
+
/** Paragraph bottom border, for horizontal rule simulation. */
|
|
192
|
+
borderBottom: ParaBorder | null;
|
|
193
|
+
}
|
|
194
|
+
export declare const DEFAULT_PARA_PROPS: ParaProps;
|
|
195
|
+
export interface ParaListProps {
|
|
196
|
+
/** References a key in NumberingMap. */
|
|
197
|
+
numId: string;
|
|
198
|
+
/** Zero-based list level (0 = outermost). */
|
|
199
|
+
level: number;
|
|
200
|
+
}
|
|
201
|
+
export interface ParaBorder {
|
|
202
|
+
/** Border style, e.g. "solid", "dashed". Mapped from w:val. */
|
|
203
|
+
style: string;
|
|
204
|
+
/** Line width in pt. Derived from w:sz (eighths of a point → divide by 8). */
|
|
205
|
+
widthPt: number;
|
|
206
|
+
/** Hex color without #. */
|
|
207
|
+
color: string;
|
|
208
|
+
}
|
|
209
|
+
/** Keyed by styleId (w:styleId attribute), e.g. "Heading1", "Normal". */
|
|
210
|
+
export type StyleMap = Map<string, StyleEntry>;
|
|
211
|
+
export interface StyleEntry {
|
|
212
|
+
styleId: string;
|
|
213
|
+
/** Display name, e.g. "heading 1", "Normal". */
|
|
214
|
+
name: string;
|
|
215
|
+
type: "paragraph" | "character" | "table" | "numbering";
|
|
216
|
+
/** Resolved heading level (1–6). Null if not a heading style. */
|
|
217
|
+
headingLevel: number | null;
|
|
218
|
+
/** Parent style ID (w:basedOn). Null = no parent. */
|
|
219
|
+
basedOn: string | null;
|
|
220
|
+
/** Default character formatting for this style. */
|
|
221
|
+
rPr: Partial<RunProps> | null;
|
|
222
|
+
/** Default paragraph formatting for this style. */
|
|
223
|
+
pPr: Partial<ParaProps> | null;
|
|
224
|
+
}
|
|
225
|
+
/**
|
|
226
|
+
* Keyed by numId (string). Each value is an array of levels (index = level).
|
|
227
|
+
* Level 0 is the outermost list level.
|
|
228
|
+
*/
|
|
229
|
+
export type NumberingMap = Map<string, NumberingLevel[]>;
|
|
230
|
+
export interface NumberingLevel {
|
|
231
|
+
/** Zero-based level index. */
|
|
232
|
+
level: number;
|
|
233
|
+
/** True = ordered (numbered) list. False = unordered (bullet) list. */
|
|
234
|
+
isOrdered: boolean;
|
|
235
|
+
/**
|
|
236
|
+
* DOCX numFmt value: "bullet", "decimal", "lowerRoman", "upperRoman",
|
|
237
|
+
* "lowerLetter", "upperLetter", "ordinal", "none", etc.
|
|
238
|
+
*/
|
|
239
|
+
numFormat: string;
|
|
240
|
+
/** List start value. Default: 1. */
|
|
241
|
+
start: number;
|
|
242
|
+
}
|
|
243
|
+
/**
|
|
244
|
+
* Keyed by relationship ID (rId), value is the resolved file path within
|
|
245
|
+
* the ZIP, e.g. "word/media/image1.png", or an external URL.
|
|
246
|
+
*/
|
|
247
|
+
export type RelationshipMap = Map<string, RelationshipEntry>;
|
|
248
|
+
export interface RelationshipEntry {
|
|
249
|
+
/** Full path within ZIP (for internal rels) or URL (for external rels). */
|
|
250
|
+
target: string;
|
|
251
|
+
/** True if this is an external URL (hyperlink, etc.). */
|
|
252
|
+
external: boolean;
|
|
253
|
+
/** Relationship type URI, e.g. ".../hyperlink", ".../image". */
|
|
254
|
+
type: string;
|
|
255
|
+
}
|
|
256
|
+
export interface ImageEntry {
|
|
257
|
+
/** Raw image bytes. */
|
|
258
|
+
bytes: Uint8Array;
|
|
259
|
+
/** MIME type derived from file extension, e.g. "image/png", "image/jpeg". */
|
|
260
|
+
mimeType: string;
|
|
261
|
+
/** Original filename within the ZIP, e.g. "image1.png". */
|
|
262
|
+
filename: string;
|
|
263
|
+
}
|
|
264
|
+
/** Keyed by rId — same keys as RelationshipMap for image-type relationships. */
|
|
265
|
+
export type ImageMap = Map<string, ImageEntry>;
|
|
266
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/docx/types.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAMH,MAAM,WAAW,YAAY;IAC3B,QAAQ,EAAE,YAAY,CAAC;IACvB,UAAU,EAAE,cAAc,CAAC;IAC3B,IAAI,EAAE,eAAe,EAAE,CAAC;IACxB,SAAS,EAAE,GAAG,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;IACjC,QAAQ,EAAE,GAAG,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;IAChC,OAAO,EAAE,gBAAgB,EAAE,CAAC;IAC5B,OAAO,EAAE,gBAAgB,EAAE,CAAC;IAC5B,MAAM,EAAE,QAAQ,CAAC;IACjB,SAAS,EAAE,YAAY,CAAC;IACxB,aAAa,EAAE,eAAe,CAAC;IAC/B,MAAM,EAAE,QAAQ,CAAC;CAClB;AAMD,MAAM,WAAW,YAAY;IAC3B,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IACrB,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IACvB,WAAW,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3B,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IACvB,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;CACzB;AAMD,MAAM,WAAW,cAAc;IAC7B,wBAAwB;IACxB,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IACrB,yBAAyB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W,cAAc;IAC7B,8BAA8B;IAC9B,KAAK,EAAE,MAAM,CAAC;IACd,uEAAuE;IACvE,SAAS,EAAE,OAAO,CAAC;IACnB;;;OAGG;IACH,SAAS,EAAE,MAAM,CAAC;IAClB,oCAAoC;IACpC,KAAK,EAAE,MAAM,CAAC;CACf;AAMD;;;GAGG;AACH,MAAM,MAAM,eAAe,GAAG,GAAG,CAAC,MAAM,EAAE,iBAAiB,CAAC,CAAC;AAE7D,MAAM,WAAW,iBAAiB;IAChC,2EAA2E;IAC3E,MAAM,EAAE,MAAM,CAAC;IACf,yDAAyD;IACzD,QAAQ,EAAE,OAAO,CAAC;IAClB,gEAAgE;IAChE,IAAI,EAAE,MAAM,CAAC;CACd;AAMD,MAAM,WAAW,UAAU;IACzB,uBAAuB;IACvB,KAAK,EAAE,UAAU,CAAC;IAClB,6EAA6E;IAC7E,QAAQ,EAAE,MAAM,CAAC;IACjB,2DAA2D;IAC3D,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,gFAAgF;AAChF,MAAM,MAAM,QAAQ,GAAG,GAAG,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* odf-kit — DOCX internal model types
|
|
3
|
+
*
|
|
4
|
+
* These types represent the parsed state of a .docx file. They are internal
|
|
5
|
+
* to the odf-kit/docx pipeline and are not part of the public API.
|
|
6
|
+
*
|
|
7
|
+
* Flow: .docx bytes → reader.ts → DocxDocument → converter.ts → OdtDocument
|
|
8
|
+
*/
|
|
9
|
+
export const DEFAULT_RUN_PROPS = {
|
|
10
|
+
bold: false,
|
|
11
|
+
italic: false,
|
|
12
|
+
underline: false,
|
|
13
|
+
strikethrough: false,
|
|
14
|
+
doubleStrikethrough: false,
|
|
15
|
+
superscript: false,
|
|
16
|
+
subscript: false,
|
|
17
|
+
smallCaps: false,
|
|
18
|
+
allCaps: false,
|
|
19
|
+
color: null,
|
|
20
|
+
fontSize: null,
|
|
21
|
+
highlight: null,
|
|
22
|
+
fontFamily: null,
|
|
23
|
+
lang: null,
|
|
24
|
+
rStyleId: null,
|
|
25
|
+
};
|
|
26
|
+
export const DEFAULT_PARA_PROPS = {
|
|
27
|
+
alignment: null,
|
|
28
|
+
pageBreakBefore: false,
|
|
29
|
+
spaceBefore: null,
|
|
30
|
+
spaceAfter: null,
|
|
31
|
+
lineHeight: null,
|
|
32
|
+
indentLeft: null,
|
|
33
|
+
indentRight: null,
|
|
34
|
+
indentFirstLine: null,
|
|
35
|
+
list: null,
|
|
36
|
+
borderBottom: null,
|
|
37
|
+
};
|
|
38
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/docx/types.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAqPH,MAAM,CAAC,MAAM,iBAAiB,GAAa;IACzC,IAAI,EAAE,KAAK;IACX,MAAM,EAAE,KAAK;IACb,SAAS,EAAE,KAAK;IAChB,aAAa,EAAE,KAAK;IACpB,mBAAmB,EAAE,KAAK;IAC1B,WAAW,EAAE,KAAK;IAClB,SAAS,EAAE,KAAK;IAChB,SAAS,EAAE,KAAK;IAChB,OAAO,EAAE,KAAK;IACd,KAAK,EAAE,IAAI;IACX,QAAQ,EAAE,IAAI;IACd,SAAS,EAAE,IAAI;IACf,UAAU,EAAE,IAAI;IAChB,IAAI,EAAE,IAAI;IACV,QAAQ,EAAE,IAAI;CACf,CAAC;AAqCF,MAAM,CAAC,MAAM,kBAAkB,GAAc;IAC3C,SAAS,EAAE,IAAI;IACf,eAAe,EAAE,KAAK;IACtB,WAAW,EAAE,IAAI;IACjB,UAAU,EAAE,IAAI;IAChB,UAAU,EAAE,IAAI;IAChB,UAAU,EAAE,IAAI;IAChB,WAAW,EAAE,IAAI;IACjB,eAAe,EAAE,IAAI;IACrB,IAAI,EAAE,IAAI;IACV,YAAY,EAAE,IAAI;CACnB,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -13,4 +13,6 @@ export type { TemplateData } from "./template/index.js";
|
|
|
13
13
|
export { OdsDocument } from "./ods/index.js";
|
|
14
14
|
export { OdsSheet } from "./ods/index.js";
|
|
15
15
|
export type { OdsCellValue, OdsCellObject, OdsCellOptions, OdsCellType, OdsRowOptions, OdsDateFormat, } from "./ods/index.js";
|
|
16
|
+
export { docxToOdt } from "./docx/index.js";
|
|
17
|
+
export type { DocxToOdtOptions, DocxToOdtResult } from "./docx/index.js";
|
|
16
18
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC7C,OAAO,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAClD,OAAO,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AACrD,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AACvE,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC7C,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC3C,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAC/C,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC7C,YAAY,EACV,cAAc,EACd,cAAc,EACd,OAAO,EACP,YAAY,EACZ,WAAW,EACX,UAAU,EACV,gBAAgB,EAChB,OAAO,EACP,WAAW,EACX,YAAY,EACZ,SAAS,EACT,gBAAgB,EAChB,UAAU,EACV,UAAU,EACV,kBAAkB,GACnB,MAAM,gBAAgB,CAAC;AACxB,YAAY,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AACvD,OAAO,EAAE,YAAY,EAAE,gBAAgB,EAAE,UAAU,EAAE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AC;AAC7C,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC1C,YAAY,EACV,YAAY,EACZ,aAAa,EACb,cAAc,EACd,WAAW,EACX,aAAa,EACb,aAAa,GACd,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,YAAY,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -11,4 +11,5 @@ export { tiptapToOdt } from "./odt/index.js";
|
|
|
11
11
|
export { fillTemplate, healPlaceholders, replaceAll } from "./template/index.js";
|
|
12
12
|
export { OdsDocument } from "./ods/index.js";
|
|
13
13
|
export { OdsSheet } from "./ods/index.js";
|
|
14
|
+
export { docxToOdt } from "./docx/index.js";
|
|
14
15
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,+CAA+C;AAC/C,2CAA2C;AAC3C,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC7C,OAAO,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAClD,OAAO,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AACrD,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AACvE,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC7C,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC3C,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAC/C,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAmB7C,OAAO,EAAE,YAAY,EAAE,gBAAgB,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAEjF,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC7C,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,+CAA+C;AAC/C,2CAA2C;AAC3C,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC7C,OAAO,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAClD,OAAO,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AACrD,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AACvE,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC7C,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC3C,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAC/C,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAmB7C,OAAO,EAAE,YAAY,EAAE,gBAAgB,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAEjF,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC7C,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAS1C,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* XLSX → ODS converter.
|
|
3
|
+
*
|
|
4
|
+
* Maps an XlsxWorkbook intermediate model to an OdsDocument and saves it.
|
|
5
|
+
*/
|
|
6
|
+
import type { OdsDateFormat } from "../ods/types.js";
|
|
7
|
+
import type { XlsxWorkbook } from "./reader.js";
|
|
8
|
+
export interface XlsxToOdsOptions {
|
|
9
|
+
/**
|
|
10
|
+
* Date display format for date cells.
|
|
11
|
+
* Defaults to "YYYY-MM-DD".
|
|
12
|
+
*/
|
|
13
|
+
dateFormat?: OdsDateFormat;
|
|
14
|
+
/**
|
|
15
|
+
* Document metadata for the output ODS file.
|
|
16
|
+
*/
|
|
17
|
+
metadata?: {
|
|
18
|
+
title?: string;
|
|
19
|
+
creator?: string;
|
|
20
|
+
description?: string;
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Convert an XlsxWorkbook model to an ODS file.
|
|
25
|
+
*
|
|
26
|
+
* @param workbook - Parsed XLSX workbook from readXlsx().
|
|
27
|
+
* @param options - Conversion options.
|
|
28
|
+
* @returns Promise resolving to a Uint8Array containing the .ods file.
|
|
29
|
+
*/
|
|
30
|
+
export declare function convertXlsxToOds(workbook: XlsxWorkbook, options?: XlsxToOdsOptions): Promise<Uint8Array>;
|
|
31
|
+
//# sourceMappingURL=converter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"converter.d.ts","sourceRoot":"","sources":["../../src/xlsx/converter.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,KAAK,EAAiB,aAAa,EAAE,MAAM,iBAAiB,CAAC;AACpE,OAAO,KAAK,EAAE,YAAY,EAAuB,MAAM,aAAa,CAAC;AAErE,MAAM,WAAW,gBAAgB;IAC/B;;;OAGG;IACH,UAAU,CAAC,EAAE,aAAa,CAAC;IAE3B;;OAEG;IACH,QAAQ,CAAC,EAAE;QACT,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,OAAO,CAAC,EAAE,MAAM,CAAC;QACjB,WAAW,CAAC,EAAE,MAAM,CAAC;KACtB,CAAC;CACH;AAuHD;;;;;;GAMG;AACH,wBAAsB,gBAAgB,CACpC,QAAQ,EAAE,YAAY,EACtB,OAAO,GAAE,gBAAqB,GAC7B,OAAO,CAAC,UAAU,CAAC,CAYrB"}
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* XLSX → ODS converter.
|
|
3
|
+
*
|
|
4
|
+
* Maps an XlsxWorkbook intermediate model to an OdsDocument and saves it.
|
|
5
|
+
*/
|
|
6
|
+
import { OdsDocument } from "../ods/document.js";
|
|
7
|
+
// ─── Cell Mapping ─────────────────────────────────────────────────────
|
|
8
|
+
function mapCell(cell, options) {
|
|
9
|
+
switch (cell.type) {
|
|
10
|
+
case "string":
|
|
11
|
+
return { value: cell.value, type: "string" };
|
|
12
|
+
case "number":
|
|
13
|
+
return { value: cell.value, type: "float" };
|
|
14
|
+
case "boolean":
|
|
15
|
+
return { value: cell.value, type: "boolean" };
|
|
16
|
+
case "date":
|
|
17
|
+
return {
|
|
18
|
+
value: cell.value,
|
|
19
|
+
type: "date",
|
|
20
|
+
...(options.dateFormat ? { dateFormat: options.dateFormat } : {}),
|
|
21
|
+
};
|
|
22
|
+
case "formula": {
|
|
23
|
+
// Determine the cell type from the cached value
|
|
24
|
+
const val = cell.value;
|
|
25
|
+
let type = "formula";
|
|
26
|
+
if (typeof val === "string")
|
|
27
|
+
type = "formula";
|
|
28
|
+
else if (typeof val === "boolean")
|
|
29
|
+
type = "formula";
|
|
30
|
+
else if (val instanceof Date)
|
|
31
|
+
type = "formula";
|
|
32
|
+
else
|
|
33
|
+
type = "formula";
|
|
34
|
+
return {
|
|
35
|
+
value: val,
|
|
36
|
+
type,
|
|
37
|
+
formula: cell.formula ? `=${cell.formula.replace(/^=/, "")}` : undefined,
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
case "error":
|
|
41
|
+
// Represent errors as strings
|
|
42
|
+
return { value: String(cell.value), type: "string" };
|
|
43
|
+
default:
|
|
44
|
+
return { value: null, type: "string" };
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
// ─── Sheet Conversion ─────────────────────────────────────────────────
|
|
48
|
+
function convertSheet(xlSheet, options, doc) {
|
|
49
|
+
const sheet = doc.addSheet(xlSheet.name);
|
|
50
|
+
if (xlSheet.freezeRows)
|
|
51
|
+
sheet.freezeRows(xlSheet.freezeRows);
|
|
52
|
+
if (xlSheet.freezeColumns)
|
|
53
|
+
sheet.freezeColumns(xlSheet.freezeColumns);
|
|
54
|
+
if (xlSheet.rows.size === 0)
|
|
55
|
+
return;
|
|
56
|
+
// Determine row/column extent
|
|
57
|
+
let maxRow = 0;
|
|
58
|
+
let maxCol = 0;
|
|
59
|
+
for (const [rowIdx, row] of xlSheet.rows) {
|
|
60
|
+
if (rowIdx > maxRow)
|
|
61
|
+
maxRow = rowIdx;
|
|
62
|
+
for (const colIdx of row.cells.keys()) {
|
|
63
|
+
if (colIdx > maxCol)
|
|
64
|
+
maxCol = colIdx;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
// Also account for merge extents
|
|
68
|
+
for (const [key, span] of xlSheet.merges) {
|
|
69
|
+
const [c, r] = key.split(":").map(Number);
|
|
70
|
+
const endRow = r + span.rowSpan - 1;
|
|
71
|
+
const endCol = c + span.colSpan - 1;
|
|
72
|
+
if (endRow > maxRow)
|
|
73
|
+
maxRow = endRow;
|
|
74
|
+
if (endCol > maxCol)
|
|
75
|
+
maxCol = endCol;
|
|
76
|
+
}
|
|
77
|
+
for (let r = 0; r <= maxRow; r++) {
|
|
78
|
+
const xlRow = xlSheet.rows.get(r);
|
|
79
|
+
const cells = [];
|
|
80
|
+
let hasContent = false;
|
|
81
|
+
for (let c = 0; c <= maxCol; c++) {
|
|
82
|
+
const cellKey = `${c}:${r}`;
|
|
83
|
+
// Skip covered cells — OdsDocument handles them automatically via colSpan/rowSpan
|
|
84
|
+
if (xlSheet.coveredCells.has(cellKey)) {
|
|
85
|
+
cells.push(null);
|
|
86
|
+
continue;
|
|
87
|
+
}
|
|
88
|
+
const xlCell = xlRow?.cells.get(c);
|
|
89
|
+
if (!xlCell || xlCell.type === "empty") {
|
|
90
|
+
cells.push(null);
|
|
91
|
+
continue;
|
|
92
|
+
}
|
|
93
|
+
const cellObj = mapCell(xlCell, options);
|
|
94
|
+
// Apply merge spans
|
|
95
|
+
const merge = xlSheet.merges.get(cellKey);
|
|
96
|
+
if (merge) {
|
|
97
|
+
if (merge.colSpan > 1)
|
|
98
|
+
cellObj.colSpan = merge.colSpan;
|
|
99
|
+
if (merge.rowSpan > 1)
|
|
100
|
+
cellObj.rowSpan = merge.rowSpan;
|
|
101
|
+
}
|
|
102
|
+
cells.push(cellObj);
|
|
103
|
+
hasContent = true;
|
|
104
|
+
}
|
|
105
|
+
if (hasContent) {
|
|
106
|
+
sheet.addRow(cells);
|
|
107
|
+
}
|
|
108
|
+
else {
|
|
109
|
+
// Emit an empty row to preserve row positioning
|
|
110
|
+
sheet.addRow([]);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
// ─── Public API ───────────────────────────────────────────────────────
|
|
115
|
+
/**
|
|
116
|
+
* Convert an XlsxWorkbook model to an ODS file.
|
|
117
|
+
*
|
|
118
|
+
* @param workbook - Parsed XLSX workbook from readXlsx().
|
|
119
|
+
* @param options - Conversion options.
|
|
120
|
+
* @returns Promise resolving to a Uint8Array containing the .ods file.
|
|
121
|
+
*/
|
|
122
|
+
export async function convertXlsxToOds(workbook, options = {}) {
|
|
123
|
+
const doc = new OdsDocument();
|
|
124
|
+
if (options.metadata) {
|
|
125
|
+
doc.setMetadata(options.metadata);
|
|
126
|
+
}
|
|
127
|
+
for (const xlSheet of workbook.sheets) {
|
|
128
|
+
convertSheet(xlSheet, options, doc);
|
|
129
|
+
}
|
|
130
|
+
return doc.save();
|
|
131
|
+
}
|
|
132
|
+
//# sourceMappingURL=converter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"converter.js","sourceRoot":"","sources":["../../src/xlsx/converter.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAqBjD,yEAAyE;AAEzE,SAAS,OAAO,CAAC,IAAc,EAAE,OAAyB;IACxD,QAAQ,IAAI,CAAC,IAAI,EAAE,CAAC;QAClB,KAAK,QAAQ;YACX,OAAO,EAAE,KAAK,EAAE,IAAI,CAAC,K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OAAO,GAAG,CAAC;oBAAE,OAAO,CAAC,OAAO,GAAG,KAAK,CAAC,OAAO,CAAC;YACzD,CAAC;YAED,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;YACpB,UAAU,GAAG,IAAI,CAAC;QACpB,CAAC;QAED,IAAI,UAAU,EAAE,CAAC;YACf,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;QACtB,CAAC;aAAM,CAAC;YACN,gDAAgD;YAChD,KAAK,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;QACnB,CAAC;IACH,CAAC;AACH,CAAC;AAED,yEAAyE;AAEzE;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,gBAAgB,CACpC,QAAsB,EACtB,UAA4B,EAAE;IAE9B,MAAM,GAAG,GAAG,IAAI,WAAW,EAAE,CAAC;IAE9B,IAAI,OAAO,CAAC,QAAQ,EAAE,CAAC;QACrB,GAAG,CAAC,WAAW,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;IACpC,CAAC;IAED,KAAK,MAAM,OAAO,IAAI,QAAQ,CAAC,MAAM,EAAE,CAAC;QACtC,YAAY,CAAC,OAAO,EAAE,OAAO,EAAE,GAAG,CAAC,CAAC;IACtC,CAAC;IAED,OAAO,GAAG,CAAC,IAAI,EAAE,CAAC;AACpB,CAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { XlsxToOdsOptions } from "./converter.js";
|
|
2
|
+
export { readXlsx } from "./reader.js";
|
|
3
|
+
export type { XlsxWorkbook, XlsxSheet, XlsxRow, XlsxCell } from "./reader.js";
|
|
4
|
+
export type { XlsxToOdsOptions } from "./converter.js";
|
|
5
|
+
/**
|
|
6
|
+
* Convert an .xlsx file to an .ods file.
|
|
7
|
+
*
|
|
8
|
+
* Parses the XLSX XML directly — no external dependencies beyond fflate.
|
|
9
|
+
* Runs in Node.js and browsers.
|
|
10
|
+
*
|
|
11
|
+
* @param bytes - Raw .xlsx file bytes (Uint8Array or ArrayBuffer).
|
|
12
|
+
* @param options - Optional conversion options.
|
|
13
|
+
* @returns Promise resolving to a Uint8Array containing the .ods file.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* import { xlsxToOds } from "odf-kit/xlsx"
|
|
17
|
+
* import { readFileSync, writeFileSync } from "fs"
|
|
18
|
+
*
|
|
19
|
+
* const bytes = await xlsxToOds(readFileSync("report.xlsx"))
|
|
20
|
+
* writeFileSync("report.ods", bytes)
|
|
21
|
+
*/
|
|
22
|
+
export declare function xlsxToOds(bytes: Uint8Array | ArrayBuffer, options?: XlsxToOdsOptions): Promise<Uint8Array>;
|
|
23
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/xlsx/index.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAEvD,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvC,YAAY,EAAE,YAAY,EAAE,SAAS,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAC9E,YAAY,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAEvD;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAsB,SAAS,CAC7B,KAAK,EAAE,UAAU,GAAG,WAAW,EAC/B,OAAO,CAAC,EAAE,gBAAgB,GACzB,OAAO,CAAC,UAAU,CAAC,CAGrB"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { readXlsx } from "./reader.js";
|
|
2
|
+
import { convertXlsxToOds } from "./converter.js";
|
|
3
|
+
export { readXlsx } from "./reader.js";
|
|
4
|
+
/**
|
|
5
|
+
* Convert an .xlsx file to an .ods file.
|
|
6
|
+
*
|
|
7
|
+
* Parses the XLSX XML directly — no external dependencies beyond fflate.
|
|
8
|
+
* Runs in Node.js and browsers.
|
|
9
|
+
*
|
|
10
|
+
* @param bytes - Raw .xlsx file bytes (Uint8Array or ArrayBuffer).
|
|
11
|
+
* @param options - Optional conversion options.
|
|
12
|
+
* @returns Promise resolving to a Uint8Array containing the .ods file.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* import { xlsxToOds } from "odf-kit/xlsx"
|
|
16
|
+
* import { readFileSync, writeFileSync } from "fs"
|
|
17
|
+
*
|
|
18
|
+
* const bytes = await xlsxToOds(readFileSync("report.xlsx"))
|
|
19
|
+
* writeFileSync("report.ods", bytes)
|
|
20
|
+
*/
|
|
21
|
+
export async function xlsxToOds(bytes, options) {
|
|
22
|
+
const workbook = readXlsx(bytes);
|
|
23
|
+
return convertXlsxToOds(workbook, options);
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/xlsx/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvC,OAAO,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAGlD,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAIvC;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,CAAC,KAAK,UAAU,SAAS,CAC7B,KAA+B,EAC/B,OAA0B;IAE1B,MAAM,QAAQ,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC;IACjC,OAAO,gBAAgB,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;AAC7C,CAAC"}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* XLSX reader — parses an .xlsx file into an intermediate XlsxWorkbook model.
|
|
3
|
+
*
|
|
4
|
+
* Parsing pipeline:
|
|
5
|
+
* 1. Unzip the .xlsx bytes with fflate
|
|
6
|
+
* 2. Parse xl/workbook.xml → sheet names and rIds
|
|
7
|
+
* 3. Parse xl/_rels/workbook.xml.rels → rId → file path map
|
|
8
|
+
* 4. Parse xl/sharedStrings.xml → string lookup array
|
|
9
|
+
* 5. Parse xl/styles.xml → style index → date format detection
|
|
10
|
+
* 6. Parse each xl/worksheets/sheet*.xml → rows, cells, merges, freeze
|
|
11
|
+
* 7. Return XlsxWorkbook
|
|
12
|
+
*
|
|
13
|
+
* No external dependencies — uses fflate for ZIP and our existing xml-parser.
|
|
14
|
+
*/
|
|
15
|
+
export interface XlsxWorkbook {
|
|
16
|
+
sheets: XlsxSheet[];
|
|
17
|
+
}
|
|
18
|
+
export interface XlsxSheet {
|
|
19
|
+
name: string;
|
|
20
|
+
/** rowIndex → row */
|
|
21
|
+
rows: Map<number, XlsxRow>;
|
|
22
|
+
/** "col:row" → merge span for primary cell */
|
|
23
|
+
merges: Map<string, {
|
|
24
|
+
colSpan: number;
|
|
25
|
+
rowSpan: number;
|
|
26
|
+
}>;
|
|
27
|
+
/** Set of "col:row" keys that are covered by a merge (non-primary) */
|
|
28
|
+
coveredCells: Set<string>;
|
|
29
|
+
freezeRows?: number;
|
|
30
|
+
freezeColumns?: number;
|
|
31
|
+
}
|
|
32
|
+
export interface XlsxRow {
|
|
33
|
+
/** colIndex → cell */
|
|
34
|
+
cells: Map<number, XlsxCell>;
|
|
35
|
+
}
|
|
36
|
+
export interface XlsxCell {
|
|
37
|
+
type: "string" | "number" | "boolean" | "date" | "formula" | "error" | "empty";
|
|
38
|
+
value: string | number | boolean | Date | null;
|
|
39
|
+
/** Original formula string, if cell has a formula. */
|
|
40
|
+
formula?: string;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Parse a cell reference like "A1", "Z3", "AA10" into zero-based col/row indices.
|
|
44
|
+
*/
|
|
45
|
+
export declare function parseCellRef(ref: string): {
|
|
46
|
+
col: number;
|
|
47
|
+
row: number;
|
|
48
|
+
};
|
|
49
|
+
/**
|
|
50
|
+
* Parse a merge range like "A1:C2" into start position and span.
|
|
51
|
+
*/
|
|
52
|
+
export declare function parseMergeRef(ref: string): {
|
|
53
|
+
startCol: number;
|
|
54
|
+
startRow: number;
|
|
55
|
+
colSpan: number;
|
|
56
|
+
rowSpan: number;
|
|
57
|
+
};
|
|
58
|
+
/**
|
|
59
|
+
* Returns true if a custom number format code represents a date/time.
|
|
60
|
+
* Strips quoted strings first, then checks for date tokens (y, m, d, h).
|
|
61
|
+
*/
|
|
62
|
+
export declare function isDateFormatCode(code: string): boolean;
|
|
63
|
+
/**
|
|
64
|
+
* Returns true if the given style index refers to a date/time format.
|
|
65
|
+
*/
|
|
66
|
+
export declare function isDateStyle(styleIndex: number, cellXfs: number[], customFormats: Map<number, string>): boolean;
|
|
67
|
+
/**
|
|
68
|
+
* Convert an XLSX serial date number to a JavaScript Date (UTC).
|
|
69
|
+
*
|
|
70
|
+
* Excel stores dates as days since January 0, 1900, with a deliberate
|
|
71
|
+
* off-by-one bug inherited from Lotus 1-2-3 (Excel incorrectly treats
|
|
72
|
+
* 1900 as a leap year). The correct epoch is December 30, 1899 UTC.
|
|
73
|
+
*/
|
|
74
|
+
export declare function xlsxSerialToDate(serial: number): Date;
|
|
75
|
+
/**
|
|
76
|
+
* Parse an XLSX file into an intermediate XlsxWorkbook model.
|
|
77
|
+
*
|
|
78
|
+
* @param bytes - Raw .xlsx file bytes (Uint8Array or ArrayBuffer).
|
|
79
|
+
* @returns XlsxWorkbook with typed cell values.
|
|
80
|
+
*/
|
|
81
|
+
export declare function readXlsx(bytes: Uint8Array | ArrayBuffer): XlsxWorkbook;
|
|
82
|
+
//# sourceMappingURL=reader.d.ts.map
|