javascript-excel 2.0.0-alpha.1 → 2.0.0-alpha.3
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 +164 -15
- package/dist/address-DUn7-5OS.js +75 -0
- package/dist/address-DZBHchLv.cjs +122 -0
- package/dist/{auto-width-2oBzjeNG.d.cts → auto-width-DRHsPKNk.d.cts} +1 -1
- package/dist/cells-CPXU722t.cjs +33 -0
- package/dist/cells-CrMF8h_t.js +28 -0
- package/dist/colors-B8Nf_xTx.js +114 -0
- package/dist/colors-oBpjx97l.cjs +119 -0
- package/dist/csv-DyVH9y7S.cjs +647 -0
- package/dist/csv-pXfaputs.js +618 -0
- package/dist/csv.cjs +6 -622
- package/dist/csv.d.cts +4 -1
- package/dist/csv.d.ts +4 -1
- package/dist/csv.js +1 -618
- package/dist/dataset-KeMzHCGl.js +664 -0
- package/dist/dataset-UUZCzsi3.cjs +687 -0
- package/dist/dates-BXcSWf9_.js +64 -0
- package/dist/dates-CA1dCizp.cjs +75 -0
- package/dist/dom.cjs +7 -28
- package/dist/dom.d.cts +5 -2
- package/dist/dom.d.ts +4 -1
- package/dist/dom.js +6 -27
- package/dist/{numfmt-B-TlCgr7.cjs → dos-time-FZ7-1tot.cjs} +36 -199
- package/dist/{numfmt-DEm0sYBJ.js → dos-time-dD0z1YWU.js} +36 -181
- package/dist/format.cjs +1264 -0
- package/dist/format.d.cts +59 -0
- package/dist/format.d.ts +59 -0
- package/dist/format.js +1262 -0
- package/dist/import.cjs +10 -0
- package/dist/import.d.cts +10 -0
- package/dist/import.d.ts +10 -0
- package/dist/import.js +1 -0
- package/dist/index.cjs +28 -1408
- package/dist/index.d.cts +149 -8
- package/dist/index.d.ts +148 -7
- package/dist/index.js +11 -1395
- package/dist/iso-date-3TY1OlGd.cjs +57 -0
- package/dist/iso-date-CXnn-9mT.js +46 -0
- package/dist/{warnings-C_12PT4t.d.cts → model-0JikLfuM.d.cts} +1 -41
- package/dist/{warnings-DXJKe1lx.d.ts → model-0JikLfuM.d.ts} +1 -41
- package/dist/numfmt-BmEbm78Y.cjs +125 -0
- package/dist/numfmt-DCDrX9P1.js +114 -0
- package/dist/pipeline-BAJtzBdW.js +1085 -0
- package/dist/pipeline-Bnf7EU3X.cjs +1132 -0
- package/dist/pipeline-CctEa86r.d.cts +186 -0
- package/dist/pipeline-I8SLmV9S.d.ts +186 -0
- package/dist/read-CZEWV4rK.cjs +3096 -0
- package/dist/read-LWti17lz.js +3073 -0
- package/dist/read.cjs +5 -2898
- package/dist/read.d.cts +13 -12
- package/dist/read.d.ts +13 -12
- package/dist/read.js +1 -2895
- package/dist/render.cjs +751 -0
- package/dist/render.d.cts +215 -0
- package/dist/render.d.ts +215 -0
- package/dist/render.js +732 -0
- package/dist/{sheet-names-CDsVK15c.js → sheet-names-7p-joVsG.js} +4 -102
- package/dist/{sheet-names-Cm-IhbBk.cjs → sheet-names-B8U5RAW0.cjs} +16 -168
- package/dist/warnings-B1v58nCZ.d.cts +41 -0
- package/dist/warnings-B1v58nCZ.d.ts +41 -0
- package/dist/worker.cjs +244 -7
- package/dist/worker.d.cts +68 -5
- package/dist/worker.d.ts +68 -5
- package/dist/worker.js +243 -7
- package/dist/{write-CYpLGuzl.d.ts → write-DM6ieuQY.d.ts} +2 -1
- package/dist/write-DjgWy1PK.js +1473 -0
- package/dist/{write-C5JgeIar.d.cts → write-DtjfdIFm.d.cts} +2 -1
- package/dist/write-f9kcYf5K.cjs +1490 -0
- package/package.json +77 -12
- package/dist/iso-date-B22IvwL1.js +0 -21
- package/dist/iso-date-BSUsPSWO.cjs +0 -26
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as LimitError, i as FormatError, n as EnvironmentError
|
|
1
|
+
import { a as LimitError, i as FormatError, n as EnvironmentError } from "./errors-CvGlfw0E.js";
|
|
2
2
|
// src/internal/zip/bytes.ts
|
|
3
3
|
/** Rejects with `signal.reason`, the same as fetch. */
|
|
4
4
|
function throwIfAborted(signal) {
|
|
@@ -38,6 +38,32 @@ var ByteWriter = class {
|
|
|
38
38
|
this.pos += b.length;
|
|
39
39
|
}
|
|
40
40
|
};
|
|
41
|
+
const clock = (() => {
|
|
42
|
+
const perf = globalThis.performance;
|
|
43
|
+
return perf && typeof perf.now === "function" ? () => perf.now() : () => Date.now();
|
|
44
|
+
})();
|
|
45
|
+
/** Wraps a progress callback: monotonic ratio, throttled. Returns undefined when there is no callback. */
|
|
46
|
+
function throttleProgress(cb, intervalMs = 50) {
|
|
47
|
+
if (!cb) return void 0;
|
|
48
|
+
let last = -1e400;
|
|
49
|
+
let lastPhase;
|
|
50
|
+
let lastSheet;
|
|
51
|
+
let ratio = 0;
|
|
52
|
+
return (p) => {
|
|
53
|
+
ratio = Math.min(1, Math.max(ratio, p.ratio));
|
|
54
|
+
const now = clock();
|
|
55
|
+
if (!(p.phase !== lastPhase || p.sheet !== lastSheet) && ratio < 1 && now - last < intervalMs) return;
|
|
56
|
+
last = now;
|
|
57
|
+
lastPhase = p.phase;
|
|
58
|
+
lastSheet = p.sheet;
|
|
59
|
+
const out = {
|
|
60
|
+
phase: p.phase,
|
|
61
|
+
ratio
|
|
62
|
+
};
|
|
63
|
+
if (p.sheet !== void 0) out.sheet = p.sheet;
|
|
64
|
+
cb(out);
|
|
65
|
+
};
|
|
66
|
+
}
|
|
41
67
|
// src/internal/platform.ts
|
|
42
68
|
/**
|
|
43
69
|
* Minimal structural types for the web platform APIs the engine uses.
|
|
@@ -168,12 +194,13 @@ const nativeCodec = {
|
|
|
168
194
|
* CRC-32 as used by zip (ISO 3309 / ITU-T V.42): reflected polynomial
|
|
169
195
|
* 0xEDB88320, initial value and final XOR 0xFFFFFFFF.
|
|
170
196
|
*
|
|
171
|
-
* Slicing-by-
|
|
172
|
-
* module costs nothing.
|
|
197
|
+
* Slicing-by-8 tables: 8 KiB, built lazily on first use so importing the
|
|
198
|
+
* module costs nothing. Slicing-by-8 measured 1,150–1,270 MB/s against
|
|
199
|
+
* 850–940 MB/s for slicing-by-4 on Node 24 (JSE-8).
|
|
173
200
|
*/
|
|
174
201
|
let tables;
|
|
175
202
|
function buildTables() {
|
|
176
|
-
const t = /* @__PURE__ */ new Uint32Array(
|
|
203
|
+
const t = /* @__PURE__ */ new Uint32Array(2048);
|
|
177
204
|
for (let n = 0; n < 256; n++) {
|
|
178
205
|
let c = n;
|
|
179
206
|
for (let k = 0; k < 8; k++) c = c & 1 ? 3988292384 ^ c >>> 1 : c >>> 1;
|
|
@@ -181,7 +208,7 @@ function buildTables() {
|
|
|
181
208
|
}
|
|
182
209
|
for (let n = 0; n < 256; n++) {
|
|
183
210
|
let c = t[n];
|
|
184
|
-
for (let k = 1; k <
|
|
211
|
+
for (let k = 1; k < 8; k++) {
|
|
185
212
|
c = t[c & 255] ^ c >>> 8;
|
|
186
213
|
t[k * 256 + n] = c >>> 0;
|
|
187
214
|
}
|
|
@@ -197,9 +224,10 @@ function crc32(data, crc = 0) {
|
|
|
197
224
|
let c = ~crc >>> 0;
|
|
198
225
|
const n = data.length;
|
|
199
226
|
let i = 0;
|
|
200
|
-
for (const end = n - n %
|
|
227
|
+
for (const end = n - n % 8; i < end; i += 8) {
|
|
201
228
|
c ^= data[i] | data[i + 1] << 8 | data[i + 2] << 16 | data[i + 3] << 24;
|
|
202
|
-
|
|
229
|
+
const hi = data[i + 4] | data[i + 5] << 8 | data[i + 6] << 16 | data[i + 7] << 24;
|
|
230
|
+
c = t[1792 + (c & 255)] ^ t[1536 + (c >>> 8 & 255)] ^ t[1280 + (c >>> 16 & 255)] ^ t[1024 + (c >>> 24)] ^ t[768 + (hi & 255)] ^ t[512 + (hi >>> 8 & 255)] ^ t[256 + (hi >>> 16 & 255)] ^ t[hi >>> 24];
|
|
203
231
|
}
|
|
204
232
|
for (; i < n; i++) c = t[(c ^ data[i]) & 255] ^ c >>> 8;
|
|
205
233
|
return ~c >>> 0;
|
|
@@ -223,177 +251,4 @@ function fromDosDateTime(date, time) {
|
|
|
223
251
|
const day = Math.max(1, date & 31);
|
|
224
252
|
return new Date(Date.UTC(year, month, day, time >>> 11, time >>> 5 & 63, (time & 31) * 2));
|
|
225
253
|
}
|
|
226
|
-
|
|
227
|
-
/**
|
|
228
|
-
* Date ↔ serial conversion (docs/api.md §3.4.1, §4.5).
|
|
229
|
-
*
|
|
230
|
-
* 1900 system: serial 1 = 1900-01-01. Excel treats 1900 as a leap year, so
|
|
231
|
-
* serial 60 is the non-existent 1900-02-29: dates before 1900-03-01 use the
|
|
232
|
-
* epoch 1899-12-31, later dates 1899-12-30.
|
|
233
|
-
* 1904 system: serial 0 = 1904-01-01.
|
|
234
|
-
*
|
|
235
|
-
* `dateZone: 'local'` (default) reads and builds dates from their local
|
|
236
|
-
* calendar fields, so `new Date(2024, 0, 15)` is serial 45306 in every zone.
|
|
237
|
-
* `'utc'` uses the UTC fields.
|
|
238
|
-
*/
|
|
239
|
-
const DAY_MS = 864e5;
|
|
240
|
-
const EPOCH_1900 = Date.UTC(1899, 11, 30);
|
|
241
|
-
const EPOCH_1900_EARLY = Date.UTC(1899, 11, 31);
|
|
242
|
-
const LEAP_BUG_START = Date.UTC(1900, 2, 1);
|
|
243
|
-
const EPOCH_1904 = Date.UTC(1904, 0, 1);
|
|
244
|
-
const MIN_1900 = Date.UTC(1900, 0, 1);
|
|
245
|
-
const MAX = Date.UTC(9999, 11, 31, 23, 59, 59, 999);
|
|
246
|
-
/** Wall-clock time of `d` in the chosen zone, as UTC milliseconds. */
|
|
247
|
-
function wallClock(d, zone) {
|
|
248
|
-
if (zone === "utc") return d.getTime();
|
|
249
|
-
const year = d.getFullYear();
|
|
250
|
-
if (year < 1e3) return NaN;
|
|
251
|
-
return Date.UTC(year, d.getMonth(), d.getDate(), d.getHours(), d.getMinutes(), d.getSeconds(), d.getMilliseconds());
|
|
252
|
-
}
|
|
253
|
-
/**
|
|
254
|
-
* Converts a Date to an Excel serial number.
|
|
255
|
-
* Throws `INVALID_DATE` for an invalid Date or one outside the date system's
|
|
256
|
-
* range (1900-01-01 or 1904-01-01 to 9999-12-31).
|
|
257
|
-
*/
|
|
258
|
-
function dateToSerial(d, options) {
|
|
259
|
-
const ms = Number.isFinite(d.getTime()) ? wallClock(d, options?.dateZone ?? "local") : NaN;
|
|
260
|
-
const min = options?.date1904 ? EPOCH_1904 : MIN_1900;
|
|
261
|
-
if (!Number.isFinite(ms) || ms < min || ms > MAX) throw new ValidationError("INVALID_DATE", `Date ${String(d)} is outside the range Excel can store.`, { details: { value: Number.isFinite(d.getTime()) ? d.toISOString() : "Invalid Date" } });
|
|
262
|
-
if (options?.date1904) return (ms - EPOCH_1904) / DAY_MS;
|
|
263
|
-
return (ms - (ms < LEAP_BUG_START ? EPOCH_1900_EARLY : EPOCH_1900)) / DAY_MS;
|
|
264
|
-
}
|
|
265
|
-
/**
|
|
266
|
-
* Converts an Excel serial number to a Date (inverse of `dateToSerial`).
|
|
267
|
-
* - 1900 system: serials 0 to <1 are Excel's day 0 ("1900-01-00", i.e.
|
|
268
|
-
* 1899-12-31), which is how time-only values such as 0.5 (12:00) are
|
|
269
|
-
* stored. Serial 60 (the fictitious 1900-02-29) has no real date and gives
|
|
270
|
-
* 1900-03-01; callers that must flag it (the reader) check for it themselves.
|
|
271
|
-
* - 1904 system: serial 0 = 1904-01-01.
|
|
272
|
-
* Throws `INVALID_DATE` for negative, non-finite or out-of-range serials.
|
|
273
|
-
*/
|
|
274
|
-
function serialToDate(serial, options) {
|
|
275
|
-
const max = options?.date1904 ? (MAX - EPOCH_1904) / DAY_MS : (MAX - EPOCH_1900) / DAY_MS;
|
|
276
|
-
if (!Number.isFinite(serial) || serial < 0 || serial > max) throw new ValidationError("INVALID_DATE", `Serial ${serial} is not a valid date.`, { details: { value: serial } });
|
|
277
|
-
let ms;
|
|
278
|
-
if (options?.date1904) ms = EPOCH_1904 + Math.round(serial * DAY_MS);
|
|
279
|
-
else if (serial < 60) ms = EPOCH_1900_EARLY + Math.round(serial * DAY_MS);
|
|
280
|
-
else if (serial < 61) ms = EPOCH_1900 + Math.round((serial + 1) * DAY_MS);
|
|
281
|
-
else ms = EPOCH_1900 + Math.round(serial * DAY_MS);
|
|
282
|
-
if ((options?.dateZone ?? "local") === "utc") return new Date(ms);
|
|
283
|
-
const u = new Date(ms);
|
|
284
|
-
return new Date(u.getUTCFullYear(), u.getUTCMonth(), u.getUTCDate(), u.getUTCHours(), u.getUTCMinutes(), u.getUTCSeconds(), u.getUTCMilliseconds());
|
|
285
|
-
}
|
|
286
|
-
// src/numfmt.ts
|
|
287
|
-
/** The built-in number formats ECMA-376 §18.8.30 defines (§11.2). Ids 14–17 and 22 render in the user's locale in Excel. */
|
|
288
|
-
const BUILTIN_NUM_FMTS = Object.freeze({
|
|
289
|
-
0: "General",
|
|
290
|
-
1: "0",
|
|
291
|
-
2: "0.00",
|
|
292
|
-
3: "#,##0",
|
|
293
|
-
4: "#,##0.00",
|
|
294
|
-
9: "0%",
|
|
295
|
-
10: "0.00%",
|
|
296
|
-
11: "0.00E+00",
|
|
297
|
-
12: "# ?/?",
|
|
298
|
-
13: "# ??/??",
|
|
299
|
-
14: "mm-dd-yy",
|
|
300
|
-
15: "d-mmm-yy",
|
|
301
|
-
16: "d-mmm",
|
|
302
|
-
17: "mmm-yy",
|
|
303
|
-
18: "h:mm AM/PM",
|
|
304
|
-
19: "h:mm:ss AM/PM",
|
|
305
|
-
20: "h:mm",
|
|
306
|
-
21: "h:mm:ss",
|
|
307
|
-
22: "m/d/yy h:mm",
|
|
308
|
-
37: "#,##0 ;(#,##0)",
|
|
309
|
-
38: "#,##0 ;[Red](#,##0)",
|
|
310
|
-
39: "#,##0.00;(#,##0.00)",
|
|
311
|
-
40: "#,##0.00;[Red](#,##0.00)",
|
|
312
|
-
45: "mm:ss",
|
|
313
|
-
46: "[h]:mm:ss",
|
|
314
|
-
47: "mmss.0",
|
|
315
|
-
48: "##0.0E+0",
|
|
316
|
-
49: "@"
|
|
317
|
-
});
|
|
318
|
-
/** Built-in ids that are dates or times: 14–22, 45 and 47, and the East Asian locale ids 27–36 and 50–58. 46 is `[h]:mm:ss`, a duration. */
|
|
319
|
-
const DATE_IDS = /* @__PURE__ */ new Set([
|
|
320
|
-
14,
|
|
321
|
-
15,
|
|
322
|
-
16,
|
|
323
|
-
17,
|
|
324
|
-
18,
|
|
325
|
-
19,
|
|
326
|
-
20,
|
|
327
|
-
21,
|
|
328
|
-
22,
|
|
329
|
-
27,
|
|
330
|
-
28,
|
|
331
|
-
29,
|
|
332
|
-
30,
|
|
333
|
-
31,
|
|
334
|
-
32,
|
|
335
|
-
33,
|
|
336
|
-
34,
|
|
337
|
-
35,
|
|
338
|
-
36,
|
|
339
|
-
45,
|
|
340
|
-
47,
|
|
341
|
-
50,
|
|
342
|
-
51,
|
|
343
|
-
52,
|
|
344
|
-
53,
|
|
345
|
-
54,
|
|
346
|
-
55,
|
|
347
|
-
56,
|
|
348
|
-
57,
|
|
349
|
-
58
|
|
350
|
-
]);
|
|
351
|
-
const cache = /* @__PURE__ */ new Map();
|
|
352
|
-
/**
|
|
353
|
-
* True when a number format shows a date or a time of day (§3.4.1): built-in
|
|
354
|
-
* ids 14–22, 45, 47, 27–36 and 50–58, or a custom code that contains a date or
|
|
355
|
-
* time token outside quoted text, escapes and brackets. Elapsed-time formats
|
|
356
|
-
* (`[h]:mm:ss`, built-in 46) are durations and return false.
|
|
357
|
-
*/
|
|
358
|
-
function isDateFormat(fmt) {
|
|
359
|
-
if (fmt === void 0) return false;
|
|
360
|
-
if (typeof fmt === "number") return DATE_IDS.has(fmt);
|
|
361
|
-
let hit = cache.get(fmt);
|
|
362
|
-
if (hit === void 0) {
|
|
363
|
-
hit = detect(fmt);
|
|
364
|
-
if (cache.size < 1e3) cache.set(fmt, hit);
|
|
365
|
-
}
|
|
366
|
-
return hit;
|
|
367
|
-
}
|
|
368
|
-
function detect(code) {
|
|
369
|
-
let s = "";
|
|
370
|
-
let inQuote = false;
|
|
371
|
-
for (let i = 0; i < code.length; i++) {
|
|
372
|
-
const ch = code[i];
|
|
373
|
-
if (inQuote) {
|
|
374
|
-
if (ch === "\"") inQuote = false;
|
|
375
|
-
continue;
|
|
376
|
-
}
|
|
377
|
-
if (ch === "\"") {
|
|
378
|
-
inQuote = true;
|
|
379
|
-
continue;
|
|
380
|
-
}
|
|
381
|
-
if (ch === "\\" || ch === "_" || ch === "*") {
|
|
382
|
-
i++;
|
|
383
|
-
continue;
|
|
384
|
-
}
|
|
385
|
-
if (ch === ";") break;
|
|
386
|
-
if (ch === "[") {
|
|
387
|
-
const end = code.indexOf("]", i + 1);
|
|
388
|
-
if (end === -1) break;
|
|
389
|
-
const inner = code.slice(i + 1, end).toLowerCase();
|
|
390
|
-
if (/^(h+|m+|s+)$/.test(inner)) return false;
|
|
391
|
-
i = end;
|
|
392
|
-
continue;
|
|
393
|
-
}
|
|
394
|
-
s += ch;
|
|
395
|
-
}
|
|
396
|
-
s = s.replace(/general/gi, "").replace(/e[+-]/gi, "");
|
|
397
|
-
return /[ymdhs]|am\/pm|a\/p|[egb]/i.test(s);
|
|
398
|
-
}
|
|
399
|
-
export { fromDosDateTime as a, nativeCodec as c, ByteWriter as d, concatBytes as f, serialToDate as i, decodeUtf8Strict as l, isDateFormat as n, toDosDateTime as o, throwIfAborted as p, dateToSerial as r, crc32 as s, BUILTIN_NUM_FMTS as t, encodeUtf8 as u };
|
|
254
|
+
export { decodeUtf8Strict as a, ByteWriter as c, nativeCodec as i, concatBytes as l, toDosDateTime as n, encodeUtf8 as o, crc32 as r, throttleProgress as s, fromDosDateTime as t, throwIfAborted as u };
|