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
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { o as ValidationError } from "./errors-CvGlfw0E.js";
|
|
2
|
+
// src/dates.ts
|
|
3
|
+
/**
|
|
4
|
+
* Date ↔ serial conversion (docs/api.md §3.4.1, §4.5).
|
|
5
|
+
*
|
|
6
|
+
* 1900 system: serial 1 = 1900-01-01. Excel treats 1900 as a leap year, so
|
|
7
|
+
* serial 60 is the non-existent 1900-02-29: dates before 1900-03-01 use the
|
|
8
|
+
* epoch 1899-12-31, later dates 1899-12-30.
|
|
9
|
+
* 1904 system: serial 0 = 1904-01-01.
|
|
10
|
+
*
|
|
11
|
+
* `dateZone: 'local'` (default) reads and builds dates from their local
|
|
12
|
+
* calendar fields, so `new Date(2024, 0, 15)` is serial 45306 in every zone.
|
|
13
|
+
* `'utc'` uses the UTC fields.
|
|
14
|
+
*/
|
|
15
|
+
const DAY_MS = 864e5;
|
|
16
|
+
const EPOCH_1900 = Date.UTC(1899, 11, 30);
|
|
17
|
+
const EPOCH_1900_EARLY = Date.UTC(1899, 11, 31);
|
|
18
|
+
const LEAP_BUG_START = Date.UTC(1900, 2, 1);
|
|
19
|
+
const EPOCH_1904 = Date.UTC(1904, 0, 1);
|
|
20
|
+
/** Excel's day 0 ("1900-01-00", 1899-12-31): time-only values live there, serials 0 to <1. */
|
|
21
|
+
const MIN_1900 = Date.UTC(1899, 11, 31);
|
|
22
|
+
const MAX = Date.UTC(9999, 11, 31, 23, 59, 59, 999);
|
|
23
|
+
/** Wall-clock time of `d` in the chosen zone, as UTC milliseconds. */
|
|
24
|
+
function wallClock(d, zone) {
|
|
25
|
+
if (zone === "utc") return d.getTime();
|
|
26
|
+
const year = d.getFullYear();
|
|
27
|
+
if (year < 1e3) return NaN;
|
|
28
|
+
return Date.UTC(year, d.getMonth(), d.getDate(), d.getHours(), d.getMinutes(), d.getSeconds(), d.getMilliseconds());
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Converts a Date to an Excel serial number.
|
|
32
|
+
* Throws `INVALID_DATE` for an invalid Date or one outside the date system's
|
|
33
|
+
* range: 1899-12-31 (Excel's day 0, where time-only values live, as serials
|
|
34
|
+
* 0 to <1; serialToDate returns those) or 1904-01-01, to 9999-12-31.
|
|
35
|
+
*/
|
|
36
|
+
function dateToSerial(d, options) {
|
|
37
|
+
const ms = Number.isFinite(d.getTime()) ? wallClock(d, options?.dateZone ?? "local") : NaN;
|
|
38
|
+
const min = options?.date1904 ? EPOCH_1904 : MIN_1900;
|
|
39
|
+
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" } });
|
|
40
|
+
if (options?.date1904) return (ms - EPOCH_1904) / DAY_MS;
|
|
41
|
+
return (ms - (ms < LEAP_BUG_START ? EPOCH_1900_EARLY : EPOCH_1900)) / DAY_MS;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Converts an Excel serial number to a Date (inverse of `dateToSerial`).
|
|
45
|
+
* - 1900 system: serials 0 to <1 are Excel's day 0 ("1900-01-00", i.e.
|
|
46
|
+
* 1899-12-31), which is how time-only values such as 0.5 (12:00) are
|
|
47
|
+
* stored. Serial 60 (the fictitious 1900-02-29) has no real date and gives
|
|
48
|
+
* 1900-03-01; callers that must flag it (the reader) check for it themselves.
|
|
49
|
+
* - 1904 system: serial 0 = 1904-01-01.
|
|
50
|
+
* Throws `INVALID_DATE` for negative, non-finite or out-of-range serials.
|
|
51
|
+
*/
|
|
52
|
+
function serialToDate(serial, options) {
|
|
53
|
+
const max = options?.date1904 ? (MAX - EPOCH_1904) / DAY_MS : (MAX - EPOCH_1900) / DAY_MS;
|
|
54
|
+
if (!Number.isFinite(serial) || serial < 0 || serial > max) throw new ValidationError("INVALID_DATE", `Serial ${serial} is not a valid date.`, { details: { value: serial } });
|
|
55
|
+
let ms;
|
|
56
|
+
if (options?.date1904) ms = EPOCH_1904 + Math.round(serial * DAY_MS);
|
|
57
|
+
else if (serial < 60) ms = EPOCH_1900_EARLY + Math.round(serial * DAY_MS);
|
|
58
|
+
else if (serial < 61) ms = EPOCH_1900 + Math.round((serial + 1) * DAY_MS);
|
|
59
|
+
else ms = EPOCH_1900 + Math.round(serial * DAY_MS);
|
|
60
|
+
if ((options?.dateZone ?? "local") === "utc") return new Date(ms);
|
|
61
|
+
const u = new Date(ms);
|
|
62
|
+
return new Date(u.getUTCFullYear(), u.getUTCMonth(), u.getUTCDate(), u.getUTCHours(), u.getUTCMinutes(), u.getUTCSeconds(), u.getUTCMilliseconds());
|
|
63
|
+
}
|
|
64
|
+
export { serialToDate as n, dateToSerial as t };
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
const require_errors = require("./errors-DOPrrGS4.cjs");
|
|
2
|
+
// src/dates.ts
|
|
3
|
+
/**
|
|
4
|
+
* Date ↔ serial conversion (docs/api.md §3.4.1, §4.5).
|
|
5
|
+
*
|
|
6
|
+
* 1900 system: serial 1 = 1900-01-01. Excel treats 1900 as a leap year, so
|
|
7
|
+
* serial 60 is the non-existent 1900-02-29: dates before 1900-03-01 use the
|
|
8
|
+
* epoch 1899-12-31, later dates 1899-12-30.
|
|
9
|
+
* 1904 system: serial 0 = 1904-01-01.
|
|
10
|
+
*
|
|
11
|
+
* `dateZone: 'local'` (default) reads and builds dates from their local
|
|
12
|
+
* calendar fields, so `new Date(2024, 0, 15)` is serial 45306 in every zone.
|
|
13
|
+
* `'utc'` uses the UTC fields.
|
|
14
|
+
*/
|
|
15
|
+
const DAY_MS = 864e5;
|
|
16
|
+
const EPOCH_1900 = Date.UTC(1899, 11, 30);
|
|
17
|
+
const EPOCH_1900_EARLY = Date.UTC(1899, 11, 31);
|
|
18
|
+
const LEAP_BUG_START = Date.UTC(1900, 2, 1);
|
|
19
|
+
const EPOCH_1904 = Date.UTC(1904, 0, 1);
|
|
20
|
+
/** Excel's day 0 ("1900-01-00", 1899-12-31): time-only values live there, serials 0 to <1. */
|
|
21
|
+
const MIN_1900 = Date.UTC(1899, 11, 31);
|
|
22
|
+
const MAX = Date.UTC(9999, 11, 31, 23, 59, 59, 999);
|
|
23
|
+
/** Wall-clock time of `d` in the chosen zone, as UTC milliseconds. */
|
|
24
|
+
function wallClock(d, zone) {
|
|
25
|
+
if (zone === "utc") return d.getTime();
|
|
26
|
+
const year = d.getFullYear();
|
|
27
|
+
if (year < 1e3) return NaN;
|
|
28
|
+
return Date.UTC(year, d.getMonth(), d.getDate(), d.getHours(), d.getMinutes(), d.getSeconds(), d.getMilliseconds());
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Converts a Date to an Excel serial number.
|
|
32
|
+
* Throws `INVALID_DATE` for an invalid Date or one outside the date system's
|
|
33
|
+
* range: 1899-12-31 (Excel's day 0, where time-only values live, as serials
|
|
34
|
+
* 0 to <1; serialToDate returns those) or 1904-01-01, to 9999-12-31.
|
|
35
|
+
*/
|
|
36
|
+
function dateToSerial(d, options) {
|
|
37
|
+
const ms = Number.isFinite(d.getTime()) ? wallClock(d, options?.dateZone ?? "local") : NaN;
|
|
38
|
+
const min = options?.date1904 ? EPOCH_1904 : MIN_1900;
|
|
39
|
+
if (!Number.isFinite(ms) || ms < min || ms > MAX) throw new require_errors.ValidationError("INVALID_DATE", `Date ${String(d)} is outside the range Excel can store.`, { details: { value: Number.isFinite(d.getTime()) ? d.toISOString() : "Invalid Date" } });
|
|
40
|
+
if (options?.date1904) return (ms - EPOCH_1904) / DAY_MS;
|
|
41
|
+
return (ms - (ms < LEAP_BUG_START ? EPOCH_1900_EARLY : EPOCH_1900)) / DAY_MS;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Converts an Excel serial number to a Date (inverse of `dateToSerial`).
|
|
45
|
+
* - 1900 system: serials 0 to <1 are Excel's day 0 ("1900-01-00", i.e.
|
|
46
|
+
* 1899-12-31), which is how time-only values such as 0.5 (12:00) are
|
|
47
|
+
* stored. Serial 60 (the fictitious 1900-02-29) has no real date and gives
|
|
48
|
+
* 1900-03-01; callers that must flag it (the reader) check for it themselves.
|
|
49
|
+
* - 1904 system: serial 0 = 1904-01-01.
|
|
50
|
+
* Throws `INVALID_DATE` for negative, non-finite or out-of-range serials.
|
|
51
|
+
*/
|
|
52
|
+
function serialToDate(serial, options) {
|
|
53
|
+
const max = options?.date1904 ? (MAX - EPOCH_1904) / DAY_MS : (MAX - EPOCH_1900) / DAY_MS;
|
|
54
|
+
if (!Number.isFinite(serial) || serial < 0 || serial > max) throw new require_errors.ValidationError("INVALID_DATE", `Serial ${serial} is not a valid date.`, { details: { value: serial } });
|
|
55
|
+
let ms;
|
|
56
|
+
if (options?.date1904) ms = EPOCH_1904 + Math.round(serial * DAY_MS);
|
|
57
|
+
else if (serial < 60) ms = EPOCH_1900_EARLY + Math.round(serial * DAY_MS);
|
|
58
|
+
else if (serial < 61) ms = EPOCH_1900 + Math.round((serial + 1) * DAY_MS);
|
|
59
|
+
else ms = EPOCH_1900 + Math.round(serial * DAY_MS);
|
|
60
|
+
if ((options?.dateZone ?? "local") === "utc") return new Date(ms);
|
|
61
|
+
const u = new Date(ms);
|
|
62
|
+
return new Date(u.getUTCFullYear(), u.getUTCMonth(), u.getUTCDate(), u.getUTCHours(), u.getUTCMinutes(), u.getUTCSeconds(), u.getUTCMilliseconds());
|
|
63
|
+
}
|
|
64
|
+
Object.defineProperty(exports, "dateToSerial", {
|
|
65
|
+
enumerable: true,
|
|
66
|
+
get: function() {
|
|
67
|
+
return dateToSerial;
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
Object.defineProperty(exports, "serialToDate", {
|
|
71
|
+
enumerable: true,
|
|
72
|
+
get: function() {
|
|
73
|
+
return serialToDate;
|
|
74
|
+
}
|
|
75
|
+
});
|
package/dist/dom.cjs
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const
|
|
2
|
+
const require_cells = require("./cells-CPXU722t.cjs");
|
|
3
|
+
const require_sheet_names = require("./sheet-names-B8U5RAW0.cjs");
|
|
3
4
|
const require_errors = require("./errors-DOPrrGS4.cjs");
|
|
5
|
+
const require_iso_date = require("./iso-date-3TY1OlGd.cjs");
|
|
4
6
|
// src/auto-width.ts
|
|
5
7
|
/**
|
|
6
8
|
* Auto column widths for builders (docs/api.md §4.3, §5.4).
|
|
@@ -15,7 +17,7 @@ function autoWidths(rows, options = {}) {
|
|
|
15
17
|
const row = rows[r];
|
|
16
18
|
if (!row) continue;
|
|
17
19
|
for (let c = 0; c < row.length; c++) {
|
|
18
|
-
const w = require_sheet_names.textWidth(
|
|
20
|
+
const w = require_sheet_names.textWidth(require_cells.cellText(row[c]));
|
|
19
21
|
if (w > (widest[c] ?? 0)) widest[c] = w;
|
|
20
22
|
}
|
|
21
23
|
}
|
|
@@ -83,6 +85,8 @@ function isElement(n) {
|
|
|
83
85
|
* The only module that touches the DOM. Importing it never reads a global, so
|
|
84
86
|
* it is safe during server-side rendering; the DOM is used only inside the
|
|
85
87
|
* functions, and a table is read through its own window (iframes work).
|
|
88
|
+
*
|
|
89
|
+
* @module javascript-excel/dom
|
|
86
90
|
*/
|
|
87
91
|
const DEFAULT_IGNORE = "[data-export-ignore]";
|
|
88
92
|
const XLSX_MIME = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
|
|
@@ -185,7 +189,6 @@ function cellTextOf(el) {
|
|
|
185
189
|
}
|
|
186
190
|
const PLAIN_NUMBER = /^[+-]?(?:\d+\.?\d*|\.\d+)(?:[eE][+-]?\d+)?$/;
|
|
187
191
|
const GROUPED_NUMBER = /^[+-]?\d{1,3}(?:,\d{3})+(?:\.\d+)?$/;
|
|
188
|
-
const ISO_DATE = /^(\d{4})-(\d{2})-(\d{2})(?:[T ](\d{2}):(\d{2})(?::(\d{2})(?:\.(\d{1,3})\d*)?)?(Z|[+-]\d{2}:?\d{2})?)?$/;
|
|
189
192
|
function parseNumber(s) {
|
|
190
193
|
const t = s.trim();
|
|
191
194
|
if (PLAIN_NUMBER.test(t)) return Number(t);
|
|
@@ -196,30 +199,6 @@ function parseBoolean(s) {
|
|
|
196
199
|
if (t === "true" || t === "yes" || t === "1") return true;
|
|
197
200
|
if (t === "false" || t === "no" || t === "0") return false;
|
|
198
201
|
}
|
|
199
|
-
/** ISO 8601 date or date-time. Without a zone, the local wall-clock time (dateZone 'local'). */
|
|
200
|
-
function parseDate(s) {
|
|
201
|
-
const m = ISO_DATE.exec(s.trim());
|
|
202
|
-
if (!m) return void 0;
|
|
203
|
-
const [y, mo, d, h = "0", mi = "0", sec = "0", ms = "0", zone] = m.slice(1);
|
|
204
|
-
const parts = [
|
|
205
|
-
Number(y),
|
|
206
|
-
Number(mo) - 1,
|
|
207
|
-
Number(d),
|
|
208
|
-
Number(h),
|
|
209
|
-
Number(mi),
|
|
210
|
-
Number(sec),
|
|
211
|
-
Number(ms.padEnd(3, "0"))
|
|
212
|
-
];
|
|
213
|
-
let date;
|
|
214
|
-
if (zone) {
|
|
215
|
-
const off = zone === "Z" ? 0 : (zone[0] === "-" ? -1 : 1) * (Number(zone.slice(1, 3)) * 60 + Number(zone.slice(-2)));
|
|
216
|
-
date = /* @__PURE__ */ new Date(Date.UTC(...parts) - off * 6e4);
|
|
217
|
-
} else date = new Date(...parts);
|
|
218
|
-
const wall = zone ? new Date(Date.UTC(...parts)) : date;
|
|
219
|
-
const [month, day] = zone ? [wall.getUTCMonth(), wall.getUTCDate()] : [wall.getMonth(), wall.getDate()];
|
|
220
|
-
if (month !== parts[1] || day !== parts[2]) return void 0;
|
|
221
|
-
return Number.isFinite(date.getTime()) ? date : void 0;
|
|
222
|
-
}
|
|
223
202
|
function coerce(ctx, raw, type, ref) {
|
|
224
203
|
if (type === null || type === "" || type === "string") {
|
|
225
204
|
if (ctx.inferTypes) {
|
|
@@ -246,7 +225,7 @@ function coerce(ctx, raw, type, ref) {
|
|
|
246
225
|
return n !== void 0 && Number.isFinite(n) ? n : fail();
|
|
247
226
|
}
|
|
248
227
|
case "boolean": return parseBoolean(raw) ?? fail();
|
|
249
|
-
case "date": return
|
|
228
|
+
case "date": return require_iso_date.parseIsoDate(raw) ?? fail();
|
|
250
229
|
default:
|
|
251
230
|
ctx.warn({
|
|
252
231
|
code: "COERCION_FAILED",
|
package/dist/dom.d.cts
CHANGED
|
@@ -4,9 +4,12 @@
|
|
|
4
4
|
* The only module that touches the DOM. Importing it never reads a global, so
|
|
5
5
|
* it is safe during server-side rendering; the DOM is used only inside the
|
|
6
6
|
* functions, and a table is read through its own window (iframes work).
|
|
7
|
+
*
|
|
8
|
+
* @module javascript-excel/dom
|
|
7
9
|
*/
|
|
8
|
-
import { t as AutoWidthOptions } from "./auto-width-
|
|
9
|
-
import {
|
|
10
|
+
import { t as AutoWidthOptions } from "./auto-width-DRHsPKNk.cjs";
|
|
11
|
+
import { a as BlobType, n as ExcelWarningCode, t as ExcelWarning } from "./warnings-B1v58nCZ.cjs";
|
|
12
|
+
import { D as Sheet, k as Style, s as CellInput } from "./model-0JikLfuM.cjs";
|
|
10
13
|
/** `HTMLTableElement` when the consumer has DOM types, else `object`. */
|
|
11
14
|
export type TableElement = typeof globalThis extends {
|
|
12
15
|
HTMLTableElement: {
|
package/dist/dom.d.ts
CHANGED
|
@@ -4,9 +4,12 @@
|
|
|
4
4
|
* The only module that touches the DOM. Importing it never reads a global, so
|
|
5
5
|
* it is safe during server-side rendering; the DOM is used only inside the
|
|
6
6
|
* functions, and a table is read through its own window (iframes work).
|
|
7
|
+
*
|
|
8
|
+
* @module javascript-excel/dom
|
|
7
9
|
*/
|
|
8
10
|
import { t as AutoWidthOptions } from "./auto-width-CT-BihTW.js";
|
|
9
|
-
import {
|
|
11
|
+
import { a as BlobType, n as ExcelWarningCode, t as ExcelWarning } from "./warnings-B1v58nCZ.js";
|
|
12
|
+
import { D as Sheet, k as Style, s as CellInput } from "./model-0JikLfuM.js";
|
|
10
13
|
/** `HTMLTableElement` when the consumer has DOM types, else `object`. */
|
|
11
14
|
export type TableElement = typeof globalThis extends {
|
|
12
15
|
HTMLTableElement: {
|
package/dist/dom.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { t as cellText } from "./cells-CrMF8h_t.js";
|
|
2
|
+
import { c as hyperlinkSchemes, i as DEFAULT_HYPERLINK_SCHEMES, l as textWidth, m as mergeStyles, n as validateSheetName, r as AUTO_WIDTH } from "./sheet-names-7p-joVsG.js";
|
|
2
3
|
import { n as EnvironmentError, o as ValidationError } from "./errors-CvGlfw0E.js";
|
|
4
|
+
import { n as parseIsoDate } from "./iso-date-CXnn-9mT.js";
|
|
3
5
|
// src/auto-width.ts
|
|
4
6
|
/**
|
|
5
7
|
* Auto column widths for builders (docs/api.md §4.3, §5.4).
|
|
@@ -82,6 +84,8 @@ function isElement(n) {
|
|
|
82
84
|
* The only module that touches the DOM. Importing it never reads a global, so
|
|
83
85
|
* it is safe during server-side rendering; the DOM is used only inside the
|
|
84
86
|
* functions, and a table is read through its own window (iframes work).
|
|
87
|
+
*
|
|
88
|
+
* @module javascript-excel/dom
|
|
85
89
|
*/
|
|
86
90
|
const DEFAULT_IGNORE = "[data-export-ignore]";
|
|
87
91
|
const XLSX_MIME = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
|
|
@@ -184,7 +188,6 @@ function cellTextOf(el) {
|
|
|
184
188
|
}
|
|
185
189
|
const PLAIN_NUMBER = /^[+-]?(?:\d+\.?\d*|\.\d+)(?:[eE][+-]?\d+)?$/;
|
|
186
190
|
const GROUPED_NUMBER = /^[+-]?\d{1,3}(?:,\d{3})+(?:\.\d+)?$/;
|
|
187
|
-
const ISO_DATE = /^(\d{4})-(\d{2})-(\d{2})(?:[T ](\d{2}):(\d{2})(?::(\d{2})(?:\.(\d{1,3})\d*)?)?(Z|[+-]\d{2}:?\d{2})?)?$/;
|
|
188
191
|
function parseNumber(s) {
|
|
189
192
|
const t = s.trim();
|
|
190
193
|
if (PLAIN_NUMBER.test(t)) return Number(t);
|
|
@@ -195,30 +198,6 @@ function parseBoolean(s) {
|
|
|
195
198
|
if (t === "true" || t === "yes" || t === "1") return true;
|
|
196
199
|
if (t === "false" || t === "no" || t === "0") return false;
|
|
197
200
|
}
|
|
198
|
-
/** ISO 8601 date or date-time. Without a zone, the local wall-clock time (dateZone 'local'). */
|
|
199
|
-
function parseDate(s) {
|
|
200
|
-
const m = ISO_DATE.exec(s.trim());
|
|
201
|
-
if (!m) return void 0;
|
|
202
|
-
const [y, mo, d, h = "0", mi = "0", sec = "0", ms = "0", zone] = m.slice(1);
|
|
203
|
-
const parts = [
|
|
204
|
-
Number(y),
|
|
205
|
-
Number(mo) - 1,
|
|
206
|
-
Number(d),
|
|
207
|
-
Number(h),
|
|
208
|
-
Number(mi),
|
|
209
|
-
Number(sec),
|
|
210
|
-
Number(ms.padEnd(3, "0"))
|
|
211
|
-
];
|
|
212
|
-
let date;
|
|
213
|
-
if (zone) {
|
|
214
|
-
const off = zone === "Z" ? 0 : (zone[0] === "-" ? -1 : 1) * (Number(zone.slice(1, 3)) * 60 + Number(zone.slice(-2)));
|
|
215
|
-
date = /* @__PURE__ */ new Date(Date.UTC(...parts) - off * 6e4);
|
|
216
|
-
} else date = new Date(...parts);
|
|
217
|
-
const wall = zone ? new Date(Date.UTC(...parts)) : date;
|
|
218
|
-
const [month, day] = zone ? [wall.getUTCMonth(), wall.getUTCDate()] : [wall.getMonth(), wall.getDate()];
|
|
219
|
-
if (month !== parts[1] || day !== parts[2]) return void 0;
|
|
220
|
-
return Number.isFinite(date.getTime()) ? date : void 0;
|
|
221
|
-
}
|
|
222
201
|
function coerce(ctx, raw, type, ref) {
|
|
223
202
|
if (type === null || type === "" || type === "string") {
|
|
224
203
|
if (ctx.inferTypes) {
|
|
@@ -245,7 +224,7 @@ function coerce(ctx, raw, type, ref) {
|
|
|
245
224
|
return n !== void 0 && Number.isFinite(n) ? n : fail();
|
|
246
225
|
}
|
|
247
226
|
case "boolean": return parseBoolean(raw) ?? fail();
|
|
248
|
-
case "date": return
|
|
227
|
+
case "date": return parseIsoDate(raw) ?? fail();
|
|
249
228
|
default:
|
|
250
229
|
ctx.warn({
|
|
251
230
|
code: "COERCION_FAILED",
|
|
@@ -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,185 +251,6 @@ 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
|
-
// src/dates.ts
|
|
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 require_errors.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 require_errors.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
|
-
Object.defineProperty(exports, "BUILTIN_NUM_FMTS", {
|
|
400
|
-
enumerable: true,
|
|
401
|
-
get: function() {
|
|
402
|
-
return BUILTIN_NUM_FMTS;
|
|
403
|
-
}
|
|
404
|
-
});
|
|
405
254
|
Object.defineProperty(exports, "ByteWriter", {
|
|
406
255
|
enumerable: true,
|
|
407
256
|
get: function() {
|
|
@@ -420,12 +269,6 @@ Object.defineProperty(exports, "crc32", {
|
|
|
420
269
|
return crc32;
|
|
421
270
|
}
|
|
422
271
|
});
|
|
423
|
-
Object.defineProperty(exports, "dateToSerial", {
|
|
424
|
-
enumerable: true,
|
|
425
|
-
get: function() {
|
|
426
|
-
return dateToSerial;
|
|
427
|
-
}
|
|
428
|
-
});
|
|
429
272
|
Object.defineProperty(exports, "decodeUtf8Strict", {
|
|
430
273
|
enumerable: true,
|
|
431
274
|
get: function() {
|
|
@@ -444,22 +287,16 @@ Object.defineProperty(exports, "fromDosDateTime", {
|
|
|
444
287
|
return fromDosDateTime;
|
|
445
288
|
}
|
|
446
289
|
});
|
|
447
|
-
Object.defineProperty(exports, "isDateFormat", {
|
|
448
|
-
enumerable: true,
|
|
449
|
-
get: function() {
|
|
450
|
-
return isDateFormat;
|
|
451
|
-
}
|
|
452
|
-
});
|
|
453
290
|
Object.defineProperty(exports, "nativeCodec", {
|
|
454
291
|
enumerable: true,
|
|
455
292
|
get: function() {
|
|
456
293
|
return nativeCodec;
|
|
457
294
|
}
|
|
458
295
|
});
|
|
459
|
-
Object.defineProperty(exports, "
|
|
296
|
+
Object.defineProperty(exports, "throttleProgress", {
|
|
460
297
|
enumerable: true,
|
|
461
298
|
get: function() {
|
|
462
|
-
return
|
|
299
|
+
return throttleProgress;
|
|
463
300
|
}
|
|
464
301
|
});
|
|
465
302
|
Object.defineProperty(exports, "throwIfAborted", {
|