javascript-excel 1.0.3 → 2.0.0-alpha.2
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/README.md +69 -2
- package/dist/auto-width-2oBzjeNG.d.cts +11 -0
- package/dist/auto-width-CT-BihTW.d.ts +10 -0
- package/dist/csv-DyVH9y7S.cjs +647 -0
- package/dist/csv-pXfaputs.js +618 -0
- package/dist/csv.cjs +7 -0
- package/dist/csv.d.cts +89 -0
- package/dist/csv.d.ts +89 -0
- package/dist/csv.js +1 -0
- package/dist/dom.cjs +440 -0
- package/dist/dom.d.cts +78 -0
- package/dist/dom.d.ts +78 -0
- package/dist/dom.js +437 -0
- package/dist/errors-CvGlfw0E.js +28 -0
- package/dist/errors-DOPrrGS4.cjs +69 -0
- package/dist/index.cjs +627 -0
- package/dist/index.d.cts +255 -0
- package/dist/index.d.ts +255 -0
- package/dist/index.js +597 -0
- package/dist/infer-BR-J9BZa.js +88 -0
- package/dist/infer-D9EC9vJ-.cjs +105 -0
- package/dist/iso-date-3TY1OlGd.cjs +57 -0
- package/dist/iso-date-CXnn-9mT.js +46 -0
- package/dist/numfmt-BBgB7iQA.js +429 -0
- package/dist/numfmt-Dv6AjopS.cjs +512 -0
- package/dist/read-C6L7Nyy3.d.cts +78 -0
- package/dist/read-DDN5ZsPe.js +2909 -0
- package/dist/read-Ddkks7qC.d.ts +78 -0
- package/dist/read-Ym1voUct.cjs +2932 -0
- package/dist/read.cjs +6 -0
- package/dist/read.d.cts +15 -0
- package/dist/read.d.ts +15 -0
- package/dist/read.js +1 -0
- package/dist/sheet-names-qpXsvMpM.cjs +1005 -0
- package/dist/sheet-names-uT2EH5Ui.js +832 -0
- package/dist/signal-Dz0ZYe6d.d.cts +13 -0
- package/dist/signal-Dz0ZYe6d.d.ts +13 -0
- package/dist/warnings-C_12PT4t.d.cts +410 -0
- package/dist/warnings-DXJKe1lx.d.ts +410 -0
- package/dist/worker.cjs +240 -0
- package/dist/worker.d.cts +65 -0
- package/dist/worker.d.ts +65 -0
- package/dist/worker.js +238 -0
- package/dist/write-BOh9jfu1.cjs +1487 -0
- package/dist/write-C5JgeIar.d.cts +29 -0
- package/dist/write-CYpLGuzl.d.ts +29 -0
- package/dist/write-DubvcG-x.js +1470 -0
- package/package.json +101 -51
- package/.babelrc +0 -10
- package/.circleci/config.yml +0 -39
- package/lib/index.d.ts +0 -1
- package/lib/index.js +0 -22
- package/lib/javascript-excel.js +0 -17703
- package/src/index.tsx +0 -11
- package/test/unit/sample.spec.js +0 -5
- package/tsconfig.json +0 -54
- package/webpack.config.js +0 -19
- /package/{LICENSE.md → LICENSE} +0 -0
|
@@ -0,0 +1,410 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Binary input and Blob types shared by the reader and the CSV entry.
|
|
3
|
+
*
|
|
4
|
+
* The package compiles without DOM types, so `Blob` cannot be named directly
|
|
5
|
+
* in a published signature. `BlobType` resolves to the platform's own `Blob`
|
|
6
|
+
* whenever the consumer's TypeScript setup declares one (lib "dom", or
|
|
7
|
+
* @types/node), and to the structural `BlobLike` otherwise.
|
|
8
|
+
*/
|
|
9
|
+
/** The members of `Blob` the library uses. */
|
|
10
|
+
interface BlobLike {
|
|
11
|
+
readonly size: number;
|
|
12
|
+
readonly type: string;
|
|
13
|
+
arrayBuffer(): Promise<ArrayBuffer>;
|
|
14
|
+
}
|
|
15
|
+
/** The platform `Blob` type when the consumer has one, else `BlobLike`. */
|
|
16
|
+
type BlobType = typeof globalThis extends {
|
|
17
|
+
Blob: {
|
|
18
|
+
prototype: infer B;
|
|
19
|
+
};
|
|
20
|
+
} ? B : BlobLike;
|
|
21
|
+
/** Bytes the library can read. A Node `Buffer` is a `Uint8Array`. */
|
|
22
|
+
type BinaryInput = Uint8Array | ArrayBuffer | BlobType;
|
|
23
|
+
/**
|
|
24
|
+
* The workbook model (docs/api.md §3).
|
|
25
|
+
*
|
|
26
|
+
* Plain data only: objects, arrays, strings, numbers, booleans and `Date`s, so
|
|
27
|
+
* a workbook can be `structuredClone`d and posted to a worker. The writer
|
|
28
|
+
* accepts loose `CellInput`; the reader returns normalised `Cell`s.
|
|
29
|
+
* Indices are zero-based; references and ranges are A1 strings.
|
|
30
|
+
*/
|
|
31
|
+
/** A workbook. `C` is the cell type: `CellInput` for writer input, `Cell` for reader output. */
|
|
32
|
+
interface Workbook<C = CellInput> {
|
|
33
|
+
/** At least one sheet (`NO_SHEETS` otherwise). */
|
|
34
|
+
sheets: Sheet<C>[];
|
|
35
|
+
/** Index into `sheets` of the sheet shown when the file opens. Default 0. Must not be hidden. */
|
|
36
|
+
activeSheet?: number | undefined;
|
|
37
|
+
/** Use the 1904 date system (`workbookPr/@date1904`). Default false (1900 system). */
|
|
38
|
+
date1904?: boolean | undefined;
|
|
39
|
+
properties?: DocProperties | undefined;
|
|
40
|
+
definedNames?: DefinedName[] | undefined;
|
|
41
|
+
/** Workbook default font, used for `fonts[0]` in styles.xml and for width maths. Default Calibri 11. */
|
|
42
|
+
defaultFont?: Font | undefined;
|
|
43
|
+
/** Reader output only: theme colours and fonts, for resolving theme colours (§3.5.6). Ignored on write in 2.0. */
|
|
44
|
+
theme?: Theme | undefined;
|
|
45
|
+
/** Reader output only: a custom indexed palette (ARGB, index 0..63) from styles.xml, if the file has one. */
|
|
46
|
+
indexedColors?: string[] | undefined;
|
|
47
|
+
/** Calculation flags (`calcPr`). `fullCalcOnLoad` write default: `'auto'`. */
|
|
48
|
+
calc?: {
|
|
49
|
+
fullCalcOnLoad?: boolean | "auto" | undefined;
|
|
50
|
+
} | undefined;
|
|
51
|
+
}
|
|
52
|
+
/** Document properties from docProps/core.xml, app.xml and custom.xml. */
|
|
53
|
+
interface DocProperties {
|
|
54
|
+
title?: string | undefined;
|
|
55
|
+
subject?: string | undefined;
|
|
56
|
+
creator?: string | undefined;
|
|
57
|
+
keywords?: string | undefined;
|
|
58
|
+
description?: string | undefined;
|
|
59
|
+
lastModifiedBy?: string | undefined;
|
|
60
|
+
category?: string | undefined;
|
|
61
|
+
/** Write default: now. */
|
|
62
|
+
created?: Date | undefined;
|
|
63
|
+
/** Write default: now. Also used for zip entry timestamps. */
|
|
64
|
+
modified?: Date | undefined;
|
|
65
|
+
company?: string | undefined;
|
|
66
|
+
manager?: string | undefined;
|
|
67
|
+
/** Write default: `'javascript-excel'`. */
|
|
68
|
+
application?: string | undefined;
|
|
69
|
+
/** docProps/custom.xml. An array, not an object keyed by name, so file-supplied names are never object keys. */
|
|
70
|
+
custom?: Array<{
|
|
71
|
+
name: string;
|
|
72
|
+
value: string | number | boolean | Date;
|
|
73
|
+
}> | undefined;
|
|
74
|
+
}
|
|
75
|
+
/** A workbook- or sheet-level defined name. */
|
|
76
|
+
interface DefinedName {
|
|
77
|
+
/** For example `'TaxRate'`. */
|
|
78
|
+
name: string;
|
|
79
|
+
/** Formula text without `=`: `"'Sheet 1'!$A$1:$B$4"`. */
|
|
80
|
+
ref: string;
|
|
81
|
+
/** Sheet index when the name is local to a sheet (`localSheetId`). */
|
|
82
|
+
sheet?: number | undefined;
|
|
83
|
+
hidden?: boolean | undefined;
|
|
84
|
+
comment?: string | undefined;
|
|
85
|
+
}
|
|
86
|
+
/** A worksheet. */
|
|
87
|
+
interface Sheet<C = CellInput> {
|
|
88
|
+
/** 1–31 characters, none of `\ / ? * [ ] :`, no leading or trailing `'`, unique case-insensitively. */
|
|
89
|
+
name: string;
|
|
90
|
+
/** `rows[r][c]`; both levels may be sparse. Max 1,048,576 rows x 16,384 columns. */
|
|
91
|
+
rows: Array<Array<C | undefined> | undefined>;
|
|
92
|
+
/** Per-row properties, indexed like `rows`. */
|
|
93
|
+
rowProps?: Array<RowProps | undefined> | undefined;
|
|
94
|
+
/** Per-column properties, index 0 = column A. */
|
|
95
|
+
colProps?: Array<ColumnProps | undefined> | undefined;
|
|
96
|
+
/** Merged ranges as A1 strings, e.g. `['A1:C1']`. Must not overlap. */
|
|
97
|
+
merges?: string[] | undefined;
|
|
98
|
+
/** Autofilter range, e.g. `'A1:F1'`. */
|
|
99
|
+
autoFilter?: string | undefined;
|
|
100
|
+
view?: SheetView | undefined;
|
|
101
|
+
print?: PrintSetup | undefined;
|
|
102
|
+
/** Default `'visible'`. */
|
|
103
|
+
state?: "visible" | "hidden" | "veryHidden" | undefined;
|
|
104
|
+
tabColor?: Color | undefined;
|
|
105
|
+
/** Default column width in characters (`sheetFormatPr/@defaultColWidth`). */
|
|
106
|
+
defaultColWidth?: number | undefined;
|
|
107
|
+
/** Default row height in points (`sheetFormatPr/@defaultRowHeight`). */
|
|
108
|
+
defaultRowHeight?: number | undefined;
|
|
109
|
+
/** Style applied under column, row and cell styles on write (§3.5.7). Not produced by the reader. */
|
|
110
|
+
defaultStyle?: Style | undefined;
|
|
111
|
+
/** Reader output only: the used range computed from the cells read, e.g. `'A1:F120'`. */
|
|
112
|
+
dimension?: string | undefined;
|
|
113
|
+
}
|
|
114
|
+
/** Row properties. */
|
|
115
|
+
interface RowProps {
|
|
116
|
+
/** Points, 0..409. */
|
|
117
|
+
height?: number | undefined;
|
|
118
|
+
hidden?: boolean | undefined;
|
|
119
|
+
style?: Style | undefined;
|
|
120
|
+
/** 0..7. */
|
|
121
|
+
outlineLevel?: number | undefined;
|
|
122
|
+
collapsed?: boolean | undefined;
|
|
123
|
+
}
|
|
124
|
+
/** Column properties. */
|
|
125
|
+
interface ColumnProps {
|
|
126
|
+
width?: ColumnWidth | undefined;
|
|
127
|
+
hidden?: boolean | undefined;
|
|
128
|
+
style?: Style | undefined;
|
|
129
|
+
/** 0..7. */
|
|
130
|
+
outlineLevel?: number | undefined;
|
|
131
|
+
collapsed?: boolean | undefined;
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Column width.
|
|
135
|
+
* - number or `{ wch }`: width in characters, as Excel's UI shows it (8.43 is the Calibri 11 default).
|
|
136
|
+
* - `{ wpx }`: width in pixels at 96 dpi.
|
|
137
|
+
* - `'auto'`: estimated by the writer from the column's text (no font metrics).
|
|
138
|
+
*
|
|
139
|
+
* Reader output is always a number in characters.
|
|
140
|
+
*/
|
|
141
|
+
type ColumnWidth = number | {
|
|
142
|
+
wch: number;
|
|
143
|
+
} | {
|
|
144
|
+
wpx: number;
|
|
145
|
+
} | "auto";
|
|
146
|
+
/** Sheet view settings. */
|
|
147
|
+
interface SheetView {
|
|
148
|
+
/** Frozen panes: rows above and columns left of the split stay visible. */
|
|
149
|
+
freeze?: {
|
|
150
|
+
rows?: number | undefined;
|
|
151
|
+
cols?: number | undefined;
|
|
152
|
+
} | undefined;
|
|
153
|
+
/** `sheetView/@rightToLeft`: column A on the right. */
|
|
154
|
+
rightToLeft?: boolean | undefined;
|
|
155
|
+
/** Default true. */
|
|
156
|
+
showGridLines?: boolean | undefined;
|
|
157
|
+
/** Default true. */
|
|
158
|
+
showRowColHeaders?: boolean | undefined;
|
|
159
|
+
/** Percent, 10..400. */
|
|
160
|
+
zoom?: number | undefined;
|
|
161
|
+
/** For example `'B2'`. */
|
|
162
|
+
activeCell?: string | undefined;
|
|
163
|
+
/** For example `'B2:D5'`. */
|
|
164
|
+
selection?: string | undefined;
|
|
165
|
+
}
|
|
166
|
+
/** Print setup. */
|
|
167
|
+
interface PrintSetup {
|
|
168
|
+
orientation?: "portrait" | "landscape" | undefined;
|
|
169
|
+
/** Paper size code, e.g. 1 = Letter, 9 = A4. */
|
|
170
|
+
paperSize?: number | undefined;
|
|
171
|
+
/** Fit to N pages wide / tall; 0 = automatic. Sets `sheetPr/pageSetUpPr/@fitToPage`. */
|
|
172
|
+
fitTo?: {
|
|
173
|
+
width?: number | undefined;
|
|
174
|
+
height?: number | undefined;
|
|
175
|
+
} | undefined;
|
|
176
|
+
/** Percent, 10..400; ignored when `fitTo` is set. */
|
|
177
|
+
scale?: number | undefined;
|
|
178
|
+
/** Inches. */
|
|
179
|
+
margins?: {
|
|
180
|
+
left?: number | undefined;
|
|
181
|
+
right?: number | undefined;
|
|
182
|
+
top?: number | undefined;
|
|
183
|
+
bottom?: number | undefined;
|
|
184
|
+
header?: number | undefined;
|
|
185
|
+
footer?: number | undefined;
|
|
186
|
+
} | undefined;
|
|
187
|
+
center?: {
|
|
188
|
+
horizontal?: boolean | undefined;
|
|
189
|
+
vertical?: boolean | undefined;
|
|
190
|
+
} | undefined;
|
|
191
|
+
gridLines?: boolean | undefined;
|
|
192
|
+
headings?: boolean | undefined;
|
|
193
|
+
/** Written as the `_xlnm.Print_Area` defined name, e.g. `'A1:F40'`. */
|
|
194
|
+
printArea?: string | undefined;
|
|
195
|
+
/** Written as `_xlnm.Print_Titles`. Rows `'1:2'`, columns `'A:B'`. */
|
|
196
|
+
printTitles?: {
|
|
197
|
+
rows?: string | undefined;
|
|
198
|
+
cols?: string | undefined;
|
|
199
|
+
} | undefined;
|
|
200
|
+
/** Raw header strings with Excel's &-codes, e.g. `'&CPage &P of &N'`. */
|
|
201
|
+
header?: {
|
|
202
|
+
odd?: string | undefined;
|
|
203
|
+
even?: string | undefined;
|
|
204
|
+
first?: string | undefined;
|
|
205
|
+
} | undefined;
|
|
206
|
+
/** Raw footer strings with Excel's &-codes. */
|
|
207
|
+
footer?: {
|
|
208
|
+
odd?: string | undefined;
|
|
209
|
+
even?: string | undefined;
|
|
210
|
+
first?: string | undefined;
|
|
211
|
+
} | undefined;
|
|
212
|
+
}
|
|
213
|
+
/** What the writer accepts in a cell slot. */
|
|
214
|
+
type CellInput = CellValue | Cell | null | undefined;
|
|
215
|
+
/** Bare values. A string is always text, even when it starts with `=`. Only `Cell.formula` makes a formula. */
|
|
216
|
+
type CellValue = string | number | boolean | Date | CellErrorValue | RichText;
|
|
217
|
+
/** An error value such as `#N/A`. */
|
|
218
|
+
interface CellErrorValue {
|
|
219
|
+
error: ErrorCode;
|
|
220
|
+
}
|
|
221
|
+
/** Rich text: a sequence of runs, each with its own font. */
|
|
222
|
+
interface RichText {
|
|
223
|
+
richText: RichTextRun[];
|
|
224
|
+
}
|
|
225
|
+
/** One run of rich text. */
|
|
226
|
+
interface RichTextRun {
|
|
227
|
+
text: string;
|
|
228
|
+
font?: Font | undefined;
|
|
229
|
+
}
|
|
230
|
+
/** The seven error values defined by ECMA-376. */
|
|
231
|
+
type ErrorCode = "#NULL!" | "#DIV/0!" | "#VALUE!" | "#REF!" | "#NAME?" | "#NUM!" | "#N/A";
|
|
232
|
+
/** The type of a cell's value (for formulas, of the cached value). */
|
|
233
|
+
type CellType = "string" | "number" | "boolean" | "date" | "error" | "richText" | "empty";
|
|
234
|
+
/** A cell with value, formula, style and hyperlink. */
|
|
235
|
+
interface Cell {
|
|
236
|
+
/** Literal value, or the cached result when `formula` is set. null/undefined = empty (styled if `style` is set). */
|
|
237
|
+
value?: CellValue | null | undefined;
|
|
238
|
+
/** Formula text without the leading `=`. A leading `=` is accepted on write and stripped. */
|
|
239
|
+
formula?: string | undefined;
|
|
240
|
+
/** Array formula (CSE) range, e.g. `'D1:D3'`; set on the anchor cell only. */
|
|
241
|
+
arrayRef?: string | undefined;
|
|
242
|
+
/**
|
|
243
|
+
* Reader: always set; describes `value` (for formulas, the cached value).
|
|
244
|
+
* Writer: optional. If set, it must match `value` (`INVALID_CELL` otherwise). It is a check, not a coercion.
|
|
245
|
+
*/
|
|
246
|
+
type?: CellType | undefined;
|
|
247
|
+
style?: Style | undefined;
|
|
248
|
+
hyperlink?: Hyperlink | undefined;
|
|
249
|
+
}
|
|
250
|
+
/**
|
|
251
|
+
* A cell hyperlink.
|
|
252
|
+
* - string: external URL, shorthand for `{ target }`.
|
|
253
|
+
* - `{ target }`: external (http, https, mailto, ...).
|
|
254
|
+
* - `{ location }`: internal, `"'Sheet 2'!A1"` or a defined name.
|
|
255
|
+
*/
|
|
256
|
+
type Hyperlink = string | {
|
|
257
|
+
target: string;
|
|
258
|
+
tooltip?: string | undefined;
|
|
259
|
+
} | {
|
|
260
|
+
location: string;
|
|
261
|
+
tooltip?: string | undefined;
|
|
262
|
+
};
|
|
263
|
+
/** A cell, row, column or default style. Every field is optional. */
|
|
264
|
+
interface Style {
|
|
265
|
+
font?: Font | undefined;
|
|
266
|
+
fill?: Fill | undefined;
|
|
267
|
+
border?: Border | undefined;
|
|
268
|
+
alignment?: Alignment | undefined;
|
|
269
|
+
numFmt?: NumFmt | undefined;
|
|
270
|
+
/** Only takes effect once sheet protection exists (later release). */
|
|
271
|
+
protection?: {
|
|
272
|
+
locked?: boolean | undefined;
|
|
273
|
+
hidden?: boolean | undefined;
|
|
274
|
+
} | undefined;
|
|
275
|
+
}
|
|
276
|
+
/** Font. */
|
|
277
|
+
interface Font {
|
|
278
|
+
/** For example `'Calibri'`. */
|
|
279
|
+
name?: string | undefined;
|
|
280
|
+
/** Points. */
|
|
281
|
+
size?: number | undefined;
|
|
282
|
+
color?: Color | undefined;
|
|
283
|
+
bold?: boolean | undefined;
|
|
284
|
+
italic?: boolean | undefined;
|
|
285
|
+
/** `true` = `'single'`. */
|
|
286
|
+
underline?: boolean | "single" | "double" | "singleAccounting" | "doubleAccounting" | undefined;
|
|
287
|
+
strike?: boolean | undefined;
|
|
288
|
+
vertAlign?: "superscript" | "subscript" | "baseline" | undefined;
|
|
289
|
+
/** Font family class: 0 n/a, 1 Roman, 2 Swiss, 3 Modern, 4 Script, 5 Decorative. */
|
|
290
|
+
family?: number | undefined;
|
|
291
|
+
charset?: number | undefined;
|
|
292
|
+
scheme?: "major" | "minor" | "none" | undefined;
|
|
293
|
+
/** Mac-only rendering. */
|
|
294
|
+
outline?: boolean | undefined;
|
|
295
|
+
/** Mac-only rendering. */
|
|
296
|
+
shadow?: boolean | undefined;
|
|
297
|
+
condense?: boolean | undefined;
|
|
298
|
+
extend?: boolean | undefined;
|
|
299
|
+
}
|
|
300
|
+
/** A fill. A string is shorthand for a solid fill in that colour: `fill: 'FFFF00'`. */
|
|
301
|
+
type Fill = string | PatternFill | GradientFill;
|
|
302
|
+
/** Pattern fill. */
|
|
303
|
+
interface PatternFill {
|
|
304
|
+
type?: "pattern" | undefined;
|
|
305
|
+
pattern: PatternType;
|
|
306
|
+
/** Pattern colour. For `'solid'` this is the cell colour (OOXML puts a solid fill in fgColor). */
|
|
307
|
+
fgColor?: Color | undefined;
|
|
308
|
+
bgColor?: Color | undefined;
|
|
309
|
+
}
|
|
310
|
+
/** `ST_PatternType`, all 19 values. */
|
|
311
|
+
type PatternType = "none" | "solid" | "mediumGray" | "darkGray" | "lightGray" | "darkHorizontal" | "darkVertical" | "darkDown" | "darkUp" | "darkGrid" | "darkTrellis" | "lightHorizontal" | "lightVertical" | "lightDown" | "lightUp" | "lightGrid" | "lightTrellis" | "gray125" | "gray0625";
|
|
312
|
+
/** Gradient fill. */
|
|
313
|
+
interface GradientFill {
|
|
314
|
+
type: "gradient";
|
|
315
|
+
gradient: "linear" | "path";
|
|
316
|
+
/** Linear only. */
|
|
317
|
+
degree?: number | undefined;
|
|
318
|
+
/** Path only, 0..1. */
|
|
319
|
+
left?: number | undefined;
|
|
320
|
+
/** Path only, 0..1. */
|
|
321
|
+
right?: number | undefined;
|
|
322
|
+
/** Path only, 0..1. */
|
|
323
|
+
top?: number | undefined;
|
|
324
|
+
/** Path only, 0..1. */
|
|
325
|
+
bottom?: number | undefined;
|
|
326
|
+
/** Positions 0..1. */
|
|
327
|
+
stops: Array<{
|
|
328
|
+
position: number;
|
|
329
|
+
color: Color;
|
|
330
|
+
}>;
|
|
331
|
+
}
|
|
332
|
+
/** Cell border; each side is independent. */
|
|
333
|
+
interface Border {
|
|
334
|
+
left?: BorderSide | undefined;
|
|
335
|
+
right?: BorderSide | undefined;
|
|
336
|
+
top?: BorderSide | undefined;
|
|
337
|
+
bottom?: BorderSide | undefined;
|
|
338
|
+
diagonal?: BorderSide | undefined;
|
|
339
|
+
diagonalUp?: boolean | undefined;
|
|
340
|
+
diagonalDown?: boolean | undefined;
|
|
341
|
+
}
|
|
342
|
+
/** One border side. */
|
|
343
|
+
interface BorderSide {
|
|
344
|
+
style: BorderStyle;
|
|
345
|
+
/** Default: automatic (black). */
|
|
346
|
+
color?: Color | undefined;
|
|
347
|
+
}
|
|
348
|
+
/** `ST_BorderStyle`, all 14 values. */
|
|
349
|
+
type BorderStyle = "none" | "thin" | "medium" | "thick" | "double" | "hair" | "dotted" | "dashed" | "dashDot" | "dashDotDot" | "mediumDashed" | "mediumDashDot" | "mediumDashDotDot" | "slantDashDot";
|
|
350
|
+
/** Cell alignment. */
|
|
351
|
+
interface Alignment {
|
|
352
|
+
horizontal?: "general" | "left" | "center" | "right" | "fill" | "justify" | "centerContinuous" | "distributed" | undefined;
|
|
353
|
+
vertical?: "top" | "center" | "bottom" | "justify" | "distributed" | undefined;
|
|
354
|
+
wrapText?: boolean | undefined;
|
|
355
|
+
shrinkToFit?: boolean | undefined;
|
|
356
|
+
/** Indent level, in steps of about three character widths. Excel shows it for left, right and distributed. */
|
|
357
|
+
indent?: number | undefined;
|
|
358
|
+
/** Degrees, -90..90, positive = counter-clockwise; or `'vertical'` for stacked text. */
|
|
359
|
+
rotation?: number | "vertical" | undefined;
|
|
360
|
+
readingOrder?: "context" | "ltr" | "rtl" | undefined;
|
|
361
|
+
justifyLastLine?: boolean | undefined;
|
|
362
|
+
}
|
|
363
|
+
/** Number format: a number is a built-in format id (0..163), a string is a format code. */
|
|
364
|
+
type NumFmt = number | string;
|
|
365
|
+
/**
|
|
366
|
+
* A colour.
|
|
367
|
+
* - string: `'RRGGBB'`, `'AARRGGBB'`, `'#RRGGBB'` or `'#AARRGGBB'` (case-insensitive), same as `{ rgb }`.
|
|
368
|
+
* - `{ rgb }`: ARGB, e.g. `'FF336699'`.
|
|
369
|
+
* - `{ theme, tint }`: theme colour index 0..11, tint -1..1.
|
|
370
|
+
* - `{ indexed }`: legacy palette 0..63; 64 = system foreground, 65 = system background.
|
|
371
|
+
* - `{ auto: true }`: automatic colour.
|
|
372
|
+
*/
|
|
373
|
+
type Color = string | {
|
|
374
|
+
rgb: string;
|
|
375
|
+
} | {
|
|
376
|
+
theme: number;
|
|
377
|
+
tint?: number | undefined;
|
|
378
|
+
} | {
|
|
379
|
+
indexed: number;
|
|
380
|
+
} | {
|
|
381
|
+
auto: true;
|
|
382
|
+
};
|
|
383
|
+
/** Theme colours and fonts read from xl/theme/theme1.xml. */
|
|
384
|
+
interface Theme {
|
|
385
|
+
/** ARGB in clrScheme order: dk1, lt1, dk2, lt2, accent1..6, hlink, folHlink. */
|
|
386
|
+
colors: string[];
|
|
387
|
+
/** Major (headings) latin typeface. */
|
|
388
|
+
majorFont?: string | undefined;
|
|
389
|
+
/** Minor (body) latin typeface. */
|
|
390
|
+
minorFont?: string | undefined;
|
|
391
|
+
}
|
|
392
|
+
/**
|
|
393
|
+
* Warnings (docs/api.md §7.3).
|
|
394
|
+
*
|
|
395
|
+
* The reader and the CSV parser collect warnings for damage they can recover
|
|
396
|
+
* from, instead of throwing. Each warning is plain data.
|
|
397
|
+
*/
|
|
398
|
+
/** Every warning code the library reports. */
|
|
399
|
+
type ExcelWarningCode = "UNSUPPORTED_PART" | "INVALID_STYLE_INDEX" | "INVALID_SHARED_STRING" | "CELL_OUT_OF_BOUNDS" | "INVALID_CELL_REF" | "DUPLICATE_CELL" | "INVALID_DATE_SERIAL" | "SHARED_FORMULA_UNRESOLVED" | "MISSING_PART" | "BROKEN_OPTIONAL_PART" | "HYPERLINK_RANGE_REDUCED" | "SPLIT_PANE_IGNORED" | "COERCION_FAILED" | "NON_FINITE_NUMBER" | "HYPERLINK_DROPPED" | "CSV_UNTERMINATED_QUOTE" | "CSV_STRAY_QUOTE" | "CSV_FIELD_COUNT" | "CSV_INVALID_ENCODING" | "CSV_ROWS_TRUNCATED" | "WARNINGS_TRUNCATED";
|
|
400
|
+
/** A recoverable problem found while reading or building. */
|
|
401
|
+
interface ExcelWarning {
|
|
402
|
+
code: ExcelWarningCode;
|
|
403
|
+
message: string;
|
|
404
|
+
/** Zip part, e.g. `'xl/worksheets/sheet2.xml'`. */
|
|
405
|
+
part?: string | undefined;
|
|
406
|
+
sheet?: string | undefined;
|
|
407
|
+
/** Cell or range, e.g. `'B3'`. For CSV, the cell the record and field map to. */
|
|
408
|
+
ref?: string | undefined;
|
|
409
|
+
}
|
|
410
|
+
export { SheetView as A, PatternFill as C, RichTextRun as D, RichText as E, BlobLike as F, BlobType as I, Theme as M, Workbook as N, RowProps as O, BinaryInput as P, NumFmt as S, PrintSetup as T, ErrorCode as _, BorderSide as a, GradientFill as b, CellErrorValue as c, CellValue as d, Color as f, DocProperties as g, DefinedName as h, Border as i, Style as j, Sheet as k, CellInput as l, ColumnWidth as m, ExcelWarningCode as n, BorderStyle as o, ColumnProps as p, Alignment as r, Cell as s, ExcelWarning as t, CellType as u, Fill as v, PatternType as w, Hyperlink as x, Font as y };
|
package/dist/worker.cjs
ADDED
|
@@ -0,0 +1,240 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_csv = require("./csv-DyVH9y7S.cjs");
|
|
3
|
+
const require_errors = require("./errors-DOPrrGS4.cjs");
|
|
4
|
+
const require_read = require("./read-Ym1voUct.cjs");
|
|
5
|
+
const require_write = require("./write-BOh9jfu1.cjs");
|
|
6
|
+
// src/worker.ts
|
|
7
|
+
/** Marks the library's messages, so an app can use the same worker for its own messages too. */
|
|
8
|
+
const TAG = "javascript-excel/worker@1";
|
|
9
|
+
function isTagged(v) {
|
|
10
|
+
return typeof v === "object" && v !== null && v.tag === TAG && typeof v.id === "number";
|
|
11
|
+
}
|
|
12
|
+
function abortError(message) {
|
|
13
|
+
const err = new Error(message);
|
|
14
|
+
err.name = "AbortError";
|
|
15
|
+
return err;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Serves requests from `createWorkerClient` on `scope` (default: the worker's
|
|
19
|
+
* global scope, `self`). Call it once at the top of the worker file.
|
|
20
|
+
*/
|
|
21
|
+
function exposeWorker(scope) {
|
|
22
|
+
const ep = scope ?? globalThis;
|
|
23
|
+
if (typeof ep.postMessage !== "function" || typeof ep.addEventListener !== "function") throw new require_errors.EnvironmentError("ENVIRONMENT_UNSUPPORTED", "exposeWorker() must run inside a worker (no postMessage/addEventListener here).", { details: { api: "postMessage" } });
|
|
24
|
+
const endpoint = ep;
|
|
25
|
+
const controllers = /* @__PURE__ */ new Map();
|
|
26
|
+
let queue = Promise.resolve();
|
|
27
|
+
endpoint.addEventListener("message", (event) => {
|
|
28
|
+
const msg = event.data;
|
|
29
|
+
if (!isTagged(msg)) return;
|
|
30
|
+
const req = msg;
|
|
31
|
+
if (req.cancel) {
|
|
32
|
+
const c = controllers.get(req.id);
|
|
33
|
+
if (c) {
|
|
34
|
+
c.aborted = true;
|
|
35
|
+
c.reason = abortError("The operation was aborted.");
|
|
36
|
+
}
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
const state = {
|
|
40
|
+
aborted: false,
|
|
41
|
+
reason: void 0
|
|
42
|
+
};
|
|
43
|
+
controllers.set(req.id, state);
|
|
44
|
+
queue = queue.then(() => run(endpoint, req, state)).finally(() => controllers.delete(req.id));
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
async function run(ep, req, signal) {
|
|
48
|
+
const post = (r, transfer) => ep.postMessage({
|
|
49
|
+
tag: TAG,
|
|
50
|
+
id: req.id,
|
|
51
|
+
...r
|
|
52
|
+
}, transfer);
|
|
53
|
+
try {
|
|
54
|
+
if (signal.aborted) throw signal.reason;
|
|
55
|
+
const options = {
|
|
56
|
+
...req.options ?? {},
|
|
57
|
+
signal
|
|
58
|
+
};
|
|
59
|
+
if (req.progress) options["onProgress"] = (p) => post({ progress: p });
|
|
60
|
+
if (req.warnings) options["onWarning"] = (w) => post({ warning: w });
|
|
61
|
+
switch (req.op) {
|
|
62
|
+
case "write": {
|
|
63
|
+
const bytes = await require_write.toUint8Array(req.input, options);
|
|
64
|
+
post({
|
|
65
|
+
done: true,
|
|
66
|
+
result: bytes
|
|
67
|
+
}, [bytes.buffer]);
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
case "read":
|
|
71
|
+
post({
|
|
72
|
+
done: true,
|
|
73
|
+
result: await require_read.read(req.input, options)
|
|
74
|
+
});
|
|
75
|
+
return;
|
|
76
|
+
case "toCsv":
|
|
77
|
+
delete options["signal"];
|
|
78
|
+
post({
|
|
79
|
+
done: true,
|
|
80
|
+
result: require_csv.toCsv(req.input, options)
|
|
81
|
+
});
|
|
82
|
+
return;
|
|
83
|
+
case "parseCsv":
|
|
84
|
+
post({
|
|
85
|
+
done: true,
|
|
86
|
+
result: await require_csv.readCsv(req.input, options)
|
|
87
|
+
});
|
|
88
|
+
return;
|
|
89
|
+
default: throw new TypeError(`Unknown worker operation ${JSON.stringify(req.op)}`);
|
|
90
|
+
}
|
|
91
|
+
} catch (err) {
|
|
92
|
+
post({
|
|
93
|
+
done: true,
|
|
94
|
+
error: serializeError(err)
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
function serializeError(err) {
|
|
99
|
+
if (require_errors.isExcelError(err)) {
|
|
100
|
+
const out = {
|
|
101
|
+
name: err.name,
|
|
102
|
+
message: err.message,
|
|
103
|
+
code: err.code,
|
|
104
|
+
excel: true
|
|
105
|
+
};
|
|
106
|
+
if (err.details !== void 0) out.details = err.details;
|
|
107
|
+
return out;
|
|
108
|
+
}
|
|
109
|
+
if (err instanceof Error) return {
|
|
110
|
+
name: err.name,
|
|
111
|
+
message: err.message,
|
|
112
|
+
excel: false
|
|
113
|
+
};
|
|
114
|
+
return {
|
|
115
|
+
name: "Error",
|
|
116
|
+
message: String(err),
|
|
117
|
+
excel: false
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
const EXCEL_CLASSES = {
|
|
121
|
+
ValidationError: require_errors.ValidationError,
|
|
122
|
+
FormatError: require_errors.FormatError,
|
|
123
|
+
LimitError: require_errors.LimitError,
|
|
124
|
+
CsvError: require_errors.CsvError,
|
|
125
|
+
EnvironmentError: require_errors.EnvironmentError,
|
|
126
|
+
ExcelError: require_errors.ExcelError
|
|
127
|
+
};
|
|
128
|
+
function deserializeError(e) {
|
|
129
|
+
if (e.excel) return new (Object.prototype.hasOwnProperty.call(EXCEL_CLASSES, e.name) ? EXCEL_CLASSES[e.name] : require_errors.ExcelError)(e.code, e.message, e.details === void 0 ? void 0 : { details: e.details });
|
|
130
|
+
const Std = {
|
|
131
|
+
TypeError,
|
|
132
|
+
RangeError,
|
|
133
|
+
SyntaxError,
|
|
134
|
+
ReferenceError
|
|
135
|
+
};
|
|
136
|
+
const err = new (Object.prototype.hasOwnProperty.call(Std, e.name) ? Std[e.name] : Error)(e.message);
|
|
137
|
+
if (err.name !== e.name) err.name = e.name;
|
|
138
|
+
return err;
|
|
139
|
+
}
|
|
140
|
+
/** Wraps a worker that runs `exposeWorker()`. */
|
|
141
|
+
function createWorkerClient(worker) {
|
|
142
|
+
let nextId = 1;
|
|
143
|
+
const pending = /* @__PURE__ */ new Map();
|
|
144
|
+
worker.addEventListener("message", (event) => {
|
|
145
|
+
const msg = event.data;
|
|
146
|
+
if (!isTagged(msg)) return;
|
|
147
|
+
const res = msg;
|
|
148
|
+
const p = pending.get(res.id);
|
|
149
|
+
if (!p) return;
|
|
150
|
+
if (res.progress) p.onProgress?.(res.progress);
|
|
151
|
+
if (res.warning) p.onWarning?.(res.warning);
|
|
152
|
+
if (!res.done) return;
|
|
153
|
+
pending.delete(res.id);
|
|
154
|
+
p.cleanup();
|
|
155
|
+
if (res.error) p.reject(deserializeError(res.error));
|
|
156
|
+
else p.resolve(res.result);
|
|
157
|
+
});
|
|
158
|
+
worker.addEventListener("error", (event) => {
|
|
159
|
+
const reason = new require_errors.EnvironmentError("ENVIRONMENT_UNSUPPORTED", "The worker failed (see the worker's console for details).", { details: {
|
|
160
|
+
api: "Worker",
|
|
161
|
+
event: String(event.message ?? "")
|
|
162
|
+
} });
|
|
163
|
+
for (const [id, p] of pending) {
|
|
164
|
+
pending.delete(id);
|
|
165
|
+
p.cleanup();
|
|
166
|
+
p.reject(reason);
|
|
167
|
+
}
|
|
168
|
+
});
|
|
169
|
+
function call(op, input, options) {
|
|
170
|
+
const o = { ...options ?? {} };
|
|
171
|
+
const signal = o["signal"];
|
|
172
|
+
const onProgress = o["onProgress"];
|
|
173
|
+
const onWarning = o["onWarning"];
|
|
174
|
+
const transfer = o["transfer"] === true;
|
|
175
|
+
delete o["signal"];
|
|
176
|
+
delete o["onProgress"];
|
|
177
|
+
delete o["onWarning"];
|
|
178
|
+
delete o["transfer"];
|
|
179
|
+
for (const [k, v] of Object.entries(o)) if (typeof v === "function") return Promise.reject(/* @__PURE__ */ new TypeError(`options.${k} is a function, which cannot be sent to a worker`));
|
|
180
|
+
if (signal?.aborted) return Promise.reject(signal.reason ?? abortError("The operation was aborted."));
|
|
181
|
+
const id = nextId++;
|
|
182
|
+
return new Promise((resolve, reject) => {
|
|
183
|
+
const onAbort = () => {
|
|
184
|
+
if (!pending.has(id)) return;
|
|
185
|
+
pending.delete(id);
|
|
186
|
+
worker.postMessage({
|
|
187
|
+
tag: TAG,
|
|
188
|
+
id,
|
|
189
|
+
cancel: true
|
|
190
|
+
});
|
|
191
|
+
reject(signal?.reason ?? abortError("The operation was aborted."));
|
|
192
|
+
};
|
|
193
|
+
signal?.addEventListener?.("abort", onAbort, { once: true });
|
|
194
|
+
pending.set(id, {
|
|
195
|
+
resolve,
|
|
196
|
+
reject,
|
|
197
|
+
onProgress,
|
|
198
|
+
onWarning,
|
|
199
|
+
cleanup: () => signal?.removeEventListener?.("abort", onAbort)
|
|
200
|
+
});
|
|
201
|
+
const req = {
|
|
202
|
+
tag: TAG,
|
|
203
|
+
id,
|
|
204
|
+
op,
|
|
205
|
+
input,
|
|
206
|
+
options: o,
|
|
207
|
+
progress: onProgress !== void 0,
|
|
208
|
+
warnings: onWarning !== void 0
|
|
209
|
+
};
|
|
210
|
+
const list = [];
|
|
211
|
+
if (transfer) {
|
|
212
|
+
if (input instanceof ArrayBuffer) list.push(input);
|
|
213
|
+
else if (input instanceof Uint8Array) list.push(input.buffer);
|
|
214
|
+
}
|
|
215
|
+
try {
|
|
216
|
+
worker.postMessage(req, list);
|
|
217
|
+
} catch (err) {
|
|
218
|
+
pending.delete(id);
|
|
219
|
+
signal?.removeEventListener?.("abort", onAbort);
|
|
220
|
+
reject(err);
|
|
221
|
+
}
|
|
222
|
+
});
|
|
223
|
+
}
|
|
224
|
+
return {
|
|
225
|
+
write: (wb, options) => call("write", wb, options),
|
|
226
|
+
read: (input, options) => call("read", input, options),
|
|
227
|
+
toCsv: (source, options) => call("toCsv", source, options),
|
|
228
|
+
parseCsv: (input, options) => call("parseCsv", input, options),
|
|
229
|
+
terminate: () => {
|
|
230
|
+
worker.terminate();
|
|
231
|
+
for (const [id, p] of pending) {
|
|
232
|
+
pending.delete(id);
|
|
233
|
+
p.cleanup();
|
|
234
|
+
p.reject(abortError("The worker was terminated."));
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
};
|
|
238
|
+
}
|
|
239
|
+
exports.createWorkerClient = createWorkerClient;
|
|
240
|
+
exports.exposeWorker = exposeWorker;
|