javascript-excel 2.0.0-alpha.2 → 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.
Files changed (65) hide show
  1. package/README.md +151 -21
  2. package/dist/address-DUn7-5OS.js +75 -0
  3. package/dist/address-DZBHchLv.cjs +122 -0
  4. package/dist/{auto-width-2oBzjeNG.d.cts → auto-width-DRHsPKNk.d.cts} +1 -1
  5. package/dist/cells-CPXU722t.cjs +33 -0
  6. package/dist/cells-CrMF8h_t.js +28 -0
  7. package/dist/colors-B8Nf_xTx.js +114 -0
  8. package/dist/colors-oBpjx97l.cjs +119 -0
  9. package/dist/csv.d.cts +4 -1
  10. package/dist/csv.d.ts +4 -1
  11. package/dist/dataset-KeMzHCGl.js +664 -0
  12. package/dist/dataset-UUZCzsi3.cjs +687 -0
  13. package/dist/dates-BXcSWf9_.js +64 -0
  14. package/dist/dates-CA1dCizp.cjs +75 -0
  15. package/dist/dom.cjs +5 -2
  16. package/dist/dom.d.cts +5 -2
  17. package/dist/dom.d.ts +4 -1
  18. package/dist/dom.js +4 -1
  19. package/dist/{numfmt-Dv6AjopS.cjs → dos-time-FZ7-1tot.cjs} +0 -199
  20. package/dist/{numfmt-BBgB7iQA.js → dos-time-dD0z1YWU.js} +2 -177
  21. package/dist/format.cjs +1264 -0
  22. package/dist/format.d.cts +59 -0
  23. package/dist/format.d.ts +59 -0
  24. package/dist/format.js +1262 -0
  25. package/dist/import.cjs +10 -0
  26. package/dist/import.d.cts +10 -0
  27. package/dist/import.d.ts +10 -0
  28. package/dist/import.js +1 -0
  29. package/dist/index.cjs +24 -607
  30. package/dist/index.d.cts +32 -6
  31. package/dist/index.d.ts +31 -5
  32. package/dist/index.js +10 -594
  33. package/dist/{warnings-C_12PT4t.d.cts → model-0JikLfuM.d.cts} +1 -41
  34. package/dist/{warnings-DXJKe1lx.d.ts → model-0JikLfuM.d.ts} +1 -41
  35. package/dist/numfmt-BmEbm78Y.cjs +125 -0
  36. package/dist/numfmt-DCDrX9P1.js +114 -0
  37. package/dist/pipeline-BAJtzBdW.js +1085 -0
  38. package/dist/pipeline-Bnf7EU3X.cjs +1132 -0
  39. package/dist/pipeline-CctEa86r.d.cts +186 -0
  40. package/dist/pipeline-I8SLmV9S.d.ts +186 -0
  41. package/dist/{read-Ym1voUct.cjs → read-CZEWV4rK.cjs} +181 -17
  42. package/dist/{read-DDN5ZsPe.js → read-LWti17lz.js} +169 -5
  43. package/dist/read.cjs +1 -1
  44. package/dist/read.d.cts +78 -4
  45. package/dist/read.d.ts +78 -4
  46. package/dist/read.js +1 -1
  47. package/dist/render.cjs +751 -0
  48. package/dist/render.d.cts +215 -0
  49. package/dist/render.d.ts +215 -0
  50. package/dist/render.js +732 -0
  51. package/dist/{sheet-names-uT2EH5Ui.js → sheet-names-7p-joVsG.js} +2 -101
  52. package/dist/{sheet-names-qpXsvMpM.cjs → sheet-names-B8U5RAW0.cjs} +14 -167
  53. package/dist/warnings-B1v58nCZ.d.cts +41 -0
  54. package/dist/warnings-B1v58nCZ.d.ts +41 -0
  55. package/dist/worker.cjs +10 -2
  56. package/dist/worker.d.cts +10 -4
  57. package/dist/worker.d.ts +10 -4
  58. package/dist/worker.js +10 -2
  59. package/dist/{write-CYpLGuzl.d.ts → write-DM6ieuQY.d.ts} +2 -1
  60. package/dist/{write-DubvcG-x.js → write-DjgWy1PK.js} +5 -2
  61. package/dist/{write-C5JgeIar.d.cts → write-DtjfdIFm.d.cts} +2 -1
  62. package/dist/{write-BOh9jfu1.cjs → write-f9kcYf5K.cjs} +31 -28
  63. package/package.json +32 -1
  64. package/dist/read-C6L7Nyy3.d.cts +0 -78
  65. package/dist/read-Ddkks7qC.d.ts +0 -78
@@ -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,5 +1,6 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_sheet_names = require("./sheet-names-qpXsvMpM.cjs");
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");
4
5
  const require_iso_date = require("./iso-date-3TY1OlGd.cjs");
5
6
  // src/auto-width.ts
@@ -16,7 +17,7 @@ function autoWidths(rows, options = {}) {
16
17
  const row = rows[r];
17
18
  if (!row) continue;
18
19
  for (let c = 0; c < row.length; c++) {
19
- const w = require_sheet_names.textWidth(require_sheet_names.cellText(row[c]));
20
+ const w = require_sheet_names.textWidth(require_cells.cellText(row[c]));
20
21
  if (w > (widest[c] ?? 0)) widest[c] = w;
21
22
  }
22
23
  }
@@ -84,6 +85,8 @@ function isElement(n) {
84
85
  * The only module that touches the DOM. Importing it never reads a global, so
85
86
  * it is safe during server-side rendering; the DOM is used only inside the
86
87
  * functions, and a table is read through its own window (iframes work).
88
+ *
89
+ * @module javascript-excel/dom
87
90
  */
88
91
  const DEFAULT_IGNORE = "[data-export-ignore]";
89
92
  const XLSX_MIME = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
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-2oBzjeNG.cjs";
9
- import { M as Sheet, P as Style, a as BlobType, f as CellInput, n as ExcelWarningCode, t as ExcelWarning } from "./warnings-C_12PT4t.cjs";
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 { I as BlobType, j as Style, k as Sheet, l as CellInput, n as ExcelWarningCode, t as ExcelWarning } from "./warnings-DXJKe1lx.js";
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,4 +1,5 @@
1
- import { c as hyperlinkSchemes, h as mergeStyles, i as DEFAULT_HYPERLINK_SCHEMES, l as textWidth, m as cellText, n as validateSheetName, r as AUTO_WIDTH } from "./sheet-names-uT2EH5Ui.js";
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";
3
4
  import { n as parseIsoDate } from "./iso-date-CXnn-9mT.js";
4
5
  // src/auto-width.ts
@@ -83,6 +84,8 @@ function isElement(n) {
83
84
  * The only module that touches the DOM. Importing it never reads a global, so
84
85
  * it is safe during server-side rendering; the DOM is used only inside the
85
86
  * functions, and a table is read through its own window (iframes work).
87
+ *
88
+ * @module javascript-excel/dom
86
89
  */
87
90
  const DEFAULT_IGNORE = "[data-export-ignore]";
88
91
  const XLSX_MIME = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
@@ -251,187 +251,6 @@ function fromDosDateTime(date, time) {
251
251
  const day = Math.max(1, date & 31);
252
252
  return new Date(Date.UTC(year, month, day, time >>> 11, time >>> 5 & 63, (time & 31) * 2));
253
253
  }
254
- // src/dates.ts
255
- /**
256
- * Date ↔ serial conversion (docs/api.md §3.4.1, §4.5).
257
- *
258
- * 1900 system: serial 1 = 1900-01-01. Excel treats 1900 as a leap year, so
259
- * serial 60 is the non-existent 1900-02-29: dates before 1900-03-01 use the
260
- * epoch 1899-12-31, later dates 1899-12-30.
261
- * 1904 system: serial 0 = 1904-01-01.
262
- *
263
- * `dateZone: 'local'` (default) reads and builds dates from their local
264
- * calendar fields, so `new Date(2024, 0, 15)` is serial 45306 in every zone.
265
- * `'utc'` uses the UTC fields.
266
- */
267
- const DAY_MS = 864e5;
268
- const EPOCH_1900 = Date.UTC(1899, 11, 30);
269
- const EPOCH_1900_EARLY = Date.UTC(1899, 11, 31);
270
- const LEAP_BUG_START = Date.UTC(1900, 2, 1);
271
- const EPOCH_1904 = Date.UTC(1904, 0, 1);
272
- /** Excel's day 0 ("1900-01-00", 1899-12-31): time-only values live there, serials 0 to <1. */
273
- const MIN_1900 = Date.UTC(1899, 11, 31);
274
- const MAX = Date.UTC(9999, 11, 31, 23, 59, 59, 999);
275
- /** Wall-clock time of `d` in the chosen zone, as UTC milliseconds. */
276
- function wallClock(d, zone) {
277
- if (zone === "utc") return d.getTime();
278
- const year = d.getFullYear();
279
- if (year < 1e3) return NaN;
280
- return Date.UTC(year, d.getMonth(), d.getDate(), d.getHours(), d.getMinutes(), d.getSeconds(), d.getMilliseconds());
281
- }
282
- /**
283
- * Converts a Date to an Excel serial number.
284
- * Throws `INVALID_DATE` for an invalid Date or one outside the date system's
285
- * range: 1899-12-31 (Excel's day 0, where time-only values live, as serials
286
- * 0 to <1; serialToDate returns those) or 1904-01-01, to 9999-12-31.
287
- */
288
- function dateToSerial(d, options) {
289
- const ms = Number.isFinite(d.getTime()) ? wallClock(d, options?.dateZone ?? "local") : NaN;
290
- const min = options?.date1904 ? EPOCH_1904 : MIN_1900;
291
- 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" } });
292
- if (options?.date1904) return (ms - EPOCH_1904) / DAY_MS;
293
- return (ms - (ms < LEAP_BUG_START ? EPOCH_1900_EARLY : EPOCH_1900)) / DAY_MS;
294
- }
295
- /**
296
- * Converts an Excel serial number to a Date (inverse of `dateToSerial`).
297
- * - 1900 system: serials 0 to <1 are Excel's day 0 ("1900-01-00", i.e.
298
- * 1899-12-31), which is how time-only values such as 0.5 (12:00) are
299
- * stored. Serial 60 (the fictitious 1900-02-29) has no real date and gives
300
- * 1900-03-01; callers that must flag it (the reader) check for it themselves.
301
- * - 1904 system: serial 0 = 1904-01-01.
302
- * Throws `INVALID_DATE` for negative, non-finite or out-of-range serials.
303
- */
304
- function serialToDate(serial, options) {
305
- const max = options?.date1904 ? (MAX - EPOCH_1904) / DAY_MS : (MAX - EPOCH_1900) / DAY_MS;
306
- 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 } });
307
- let ms;
308
- if (options?.date1904) ms = EPOCH_1904 + Math.round(serial * DAY_MS);
309
- else if (serial < 60) ms = EPOCH_1900_EARLY + Math.round(serial * DAY_MS);
310
- else if (serial < 61) ms = EPOCH_1900 + Math.round((serial + 1) * DAY_MS);
311
- else ms = EPOCH_1900 + Math.round(serial * DAY_MS);
312
- if ((options?.dateZone ?? "local") === "utc") return new Date(ms);
313
- const u = new Date(ms);
314
- return new Date(u.getUTCFullYear(), u.getUTCMonth(), u.getUTCDate(), u.getUTCHours(), u.getUTCMinutes(), u.getUTCSeconds(), u.getUTCMilliseconds());
315
- }
316
- // src/numfmt.ts
317
- /** 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. */
318
- const BUILTIN_NUM_FMTS = Object.freeze({
319
- 0: "General",
320
- 1: "0",
321
- 2: "0.00",
322
- 3: "#,##0",
323
- 4: "#,##0.00",
324
- 9: "0%",
325
- 10: "0.00%",
326
- 11: "0.00E+00",
327
- 12: "# ?/?",
328
- 13: "# ??/??",
329
- 14: "mm-dd-yy",
330
- 15: "d-mmm-yy",
331
- 16: "d-mmm",
332
- 17: "mmm-yy",
333
- 18: "h:mm AM/PM",
334
- 19: "h:mm:ss AM/PM",
335
- 20: "h:mm",
336
- 21: "h:mm:ss",
337
- 22: "m/d/yy h:mm",
338
- 37: "#,##0 ;(#,##0)",
339
- 38: "#,##0 ;[Red](#,##0)",
340
- 39: "#,##0.00;(#,##0.00)",
341
- 40: "#,##0.00;[Red](#,##0.00)",
342
- 45: "mm:ss",
343
- 46: "[h]:mm:ss",
344
- 47: "mmss.0",
345
- 48: "##0.0E+0",
346
- 49: "@"
347
- });
348
- /** 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. */
349
- const DATE_IDS = /* @__PURE__ */ new Set([
350
- 14,
351
- 15,
352
- 16,
353
- 17,
354
- 18,
355
- 19,
356
- 20,
357
- 21,
358
- 22,
359
- 27,
360
- 28,
361
- 29,
362
- 30,
363
- 31,
364
- 32,
365
- 33,
366
- 34,
367
- 35,
368
- 36,
369
- 45,
370
- 47,
371
- 50,
372
- 51,
373
- 52,
374
- 53,
375
- 54,
376
- 55,
377
- 56,
378
- 57,
379
- 58
380
- ]);
381
- const cache = /* @__PURE__ */ new Map();
382
- /**
383
- * True when a number format shows a date or a time of day (§3.4.1): built-in
384
- * ids 14–22, 45, 47, 27–36 and 50–58, or a custom code that contains a date or
385
- * time token outside quoted text, escapes and brackets. Elapsed-time formats
386
- * (`[h]:mm:ss`, built-in 46) are durations and return false.
387
- */
388
- function isDateFormat(fmt) {
389
- if (fmt === void 0) return false;
390
- if (typeof fmt === "number") return DATE_IDS.has(fmt);
391
- let hit = cache.get(fmt);
392
- if (hit === void 0) {
393
- hit = detect(fmt);
394
- if (cache.size < 1e3) cache.set(fmt, hit);
395
- }
396
- return hit;
397
- }
398
- function detect(code) {
399
- let s = "";
400
- let inQuote = false;
401
- for (let i = 0; i < code.length; i++) {
402
- const ch = code[i];
403
- if (inQuote) {
404
- if (ch === "\"") inQuote = false;
405
- continue;
406
- }
407
- if (ch === "\"") {
408
- inQuote = true;
409
- continue;
410
- }
411
- if (ch === "\\" || ch === "_" || ch === "*") {
412
- i++;
413
- continue;
414
- }
415
- if (ch === ";") break;
416
- if (ch === "[") {
417
- const end = code.indexOf("]", i + 1);
418
- if (end === -1) break;
419
- const inner = code.slice(i + 1, end).toLowerCase();
420
- if (/^(h+|m+|s+)$/.test(inner)) return false;
421
- i = end;
422
- continue;
423
- }
424
- s += ch;
425
- }
426
- s = s.replace(/general/gi, "").replace(/e[+-]/gi, "");
427
- return /[ymdhs]|am\/pm|a\/p|[egb]/i.test(s);
428
- }
429
- Object.defineProperty(exports, "BUILTIN_NUM_FMTS", {
430
- enumerable: true,
431
- get: function() {
432
- return BUILTIN_NUM_FMTS;
433
- }
434
- });
435
254
  Object.defineProperty(exports, "ByteWriter", {
436
255
  enumerable: true,
437
256
  get: function() {
@@ -450,12 +269,6 @@ Object.defineProperty(exports, "crc32", {
450
269
  return crc32;
451
270
  }
452
271
  });
453
- Object.defineProperty(exports, "dateToSerial", {
454
- enumerable: true,
455
- get: function() {
456
- return dateToSerial;
457
- }
458
- });
459
272
  Object.defineProperty(exports, "decodeUtf8Strict", {
460
273
  enumerable: true,
461
274
  get: function() {
@@ -474,24 +287,12 @@ Object.defineProperty(exports, "fromDosDateTime", {
474
287
  return fromDosDateTime;
475
288
  }
476
289
  });
477
- Object.defineProperty(exports, "isDateFormat", {
478
- enumerable: true,
479
- get: function() {
480
- return isDateFormat;
481
- }
482
- });
483
290
  Object.defineProperty(exports, "nativeCodec", {
484
291
  enumerable: true,
485
292
  get: function() {
486
293
  return nativeCodec;
487
294
  }
488
295
  });
489
- Object.defineProperty(exports, "serialToDate", {
490
- enumerable: true,
491
- get: function() {
492
- return serialToDate;
493
- }
494
- });
495
296
  Object.defineProperty(exports, "throttleProgress", {
496
297
  enumerable: true,
497
298
  get: function() {
@@ -1,4 +1,4 @@
1
- import { a as LimitError, i as FormatError, n as EnvironmentError, o as ValidationError } from "./errors-CvGlfw0E.js";
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) {
@@ -251,179 +251,4 @@ function fromDosDateTime(date, time) {
251
251
  const day = Math.max(1, date & 31);
252
252
  return new Date(Date.UTC(year, month, day, time >>> 11, time >>> 5 & 63, (time & 31) * 2));
253
253
  }
254
- // src/dates.ts
255
- /**
256
- * Date ↔ serial conversion (docs/api.md §3.4.1, §4.5).
257
- *
258
- * 1900 system: serial 1 = 1900-01-01. Excel treats 1900 as a leap year, so
259
- * serial 60 is the non-existent 1900-02-29: dates before 1900-03-01 use the
260
- * epoch 1899-12-31, later dates 1899-12-30.
261
- * 1904 system: serial 0 = 1904-01-01.
262
- *
263
- * `dateZone: 'local'` (default) reads and builds dates from their local
264
- * calendar fields, so `new Date(2024, 0, 15)` is serial 45306 in every zone.
265
- * `'utc'` uses the UTC fields.
266
- */
267
- const DAY_MS = 864e5;
268
- const EPOCH_1900 = Date.UTC(1899, 11, 30);
269
- const EPOCH_1900_EARLY = Date.UTC(1899, 11, 31);
270
- const LEAP_BUG_START = Date.UTC(1900, 2, 1);
271
- const EPOCH_1904 = Date.UTC(1904, 0, 1);
272
- /** Excel's day 0 ("1900-01-00", 1899-12-31): time-only values live there, serials 0 to <1. */
273
- const MIN_1900 = Date.UTC(1899, 11, 31);
274
- const MAX = Date.UTC(9999, 11, 31, 23, 59, 59, 999);
275
- /** Wall-clock time of `d` in the chosen zone, as UTC milliseconds. */
276
- function wallClock(d, zone) {
277
- if (zone === "utc") return d.getTime();
278
- const year = d.getFullYear();
279
- if (year < 1e3) return NaN;
280
- return Date.UTC(year, d.getMonth(), d.getDate(), d.getHours(), d.getMinutes(), d.getSeconds(), d.getMilliseconds());
281
- }
282
- /**
283
- * Converts a Date to an Excel serial number.
284
- * Throws `INVALID_DATE` for an invalid Date or one outside the date system's
285
- * range: 1899-12-31 (Excel's day 0, where time-only values live, as serials
286
- * 0 to <1; serialToDate returns those) or 1904-01-01, to 9999-12-31.
287
- */
288
- function dateToSerial(d, options) {
289
- const ms = Number.isFinite(d.getTime()) ? wallClock(d, options?.dateZone ?? "local") : NaN;
290
- const min = options?.date1904 ? EPOCH_1904 : MIN_1900;
291
- 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" } });
292
- if (options?.date1904) return (ms - EPOCH_1904) / DAY_MS;
293
- return (ms - (ms < LEAP_BUG_START ? EPOCH_1900_EARLY : EPOCH_1900)) / DAY_MS;
294
- }
295
- /**
296
- * Converts an Excel serial number to a Date (inverse of `dateToSerial`).
297
- * - 1900 system: serials 0 to <1 are Excel's day 0 ("1900-01-00", i.e.
298
- * 1899-12-31), which is how time-only values such as 0.5 (12:00) are
299
- * stored. Serial 60 (the fictitious 1900-02-29) has no real date and gives
300
- * 1900-03-01; callers that must flag it (the reader) check for it themselves.
301
- * - 1904 system: serial 0 = 1904-01-01.
302
- * Throws `INVALID_DATE` for negative, non-finite or out-of-range serials.
303
- */
304
- function serialToDate(serial, options) {
305
- const max = options?.date1904 ? (MAX - EPOCH_1904) / DAY_MS : (MAX - EPOCH_1900) / DAY_MS;
306
- if (!Number.isFinite(serial) || serial < 0 || serial > max) throw new ValidationError("INVALID_DATE", `Serial ${serial} is not a valid date.`, { details: { value: serial } });
307
- let ms;
308
- if (options?.date1904) ms = EPOCH_1904 + Math.round(serial * DAY_MS);
309
- else if (serial < 60) ms = EPOCH_1900_EARLY + Math.round(serial * DAY_MS);
310
- else if (serial < 61) ms = EPOCH_1900 + Math.round((serial + 1) * DAY_MS);
311
- else ms = EPOCH_1900 + Math.round(serial * DAY_MS);
312
- if ((options?.dateZone ?? "local") === "utc") return new Date(ms);
313
- const u = new Date(ms);
314
- return new Date(u.getUTCFullYear(), u.getUTCMonth(), u.getUTCDate(), u.getUTCHours(), u.getUTCMinutes(), u.getUTCSeconds(), u.getUTCMilliseconds());
315
- }
316
- // src/numfmt.ts
317
- /** 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. */
318
- const BUILTIN_NUM_FMTS = Object.freeze({
319
- 0: "General",
320
- 1: "0",
321
- 2: "0.00",
322
- 3: "#,##0",
323
- 4: "#,##0.00",
324
- 9: "0%",
325
- 10: "0.00%",
326
- 11: "0.00E+00",
327
- 12: "# ?/?",
328
- 13: "# ??/??",
329
- 14: "mm-dd-yy",
330
- 15: "d-mmm-yy",
331
- 16: "d-mmm",
332
- 17: "mmm-yy",
333
- 18: "h:mm AM/PM",
334
- 19: "h:mm:ss AM/PM",
335
- 20: "h:mm",
336
- 21: "h:mm:ss",
337
- 22: "m/d/yy h:mm",
338
- 37: "#,##0 ;(#,##0)",
339
- 38: "#,##0 ;[Red](#,##0)",
340
- 39: "#,##0.00;(#,##0.00)",
341
- 40: "#,##0.00;[Red](#,##0.00)",
342
- 45: "mm:ss",
343
- 46: "[h]:mm:ss",
344
- 47: "mmss.0",
345
- 48: "##0.0E+0",
346
- 49: "@"
347
- });
348
- /** 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. */
349
- const DATE_IDS = /* @__PURE__ */ new Set([
350
- 14,
351
- 15,
352
- 16,
353
- 17,
354
- 18,
355
- 19,
356
- 20,
357
- 21,
358
- 22,
359
- 27,
360
- 28,
361
- 29,
362
- 30,
363
- 31,
364
- 32,
365
- 33,
366
- 34,
367
- 35,
368
- 36,
369
- 45,
370
- 47,
371
- 50,
372
- 51,
373
- 52,
374
- 53,
375
- 54,
376
- 55,
377
- 56,
378
- 57,
379
- 58
380
- ]);
381
- const cache = /* @__PURE__ */ new Map();
382
- /**
383
- * True when a number format shows a date or a time of day (§3.4.1): built-in
384
- * ids 14–22, 45, 47, 27–36 and 50–58, or a custom code that contains a date or
385
- * time token outside quoted text, escapes and brackets. Elapsed-time formats
386
- * (`[h]:mm:ss`, built-in 46) are durations and return false.
387
- */
388
- function isDateFormat(fmt) {
389
- if (fmt === void 0) return false;
390
- if (typeof fmt === "number") return DATE_IDS.has(fmt);
391
- let hit = cache.get(fmt);
392
- if (hit === void 0) {
393
- hit = detect(fmt);
394
- if (cache.size < 1e3) cache.set(fmt, hit);
395
- }
396
- return hit;
397
- }
398
- function detect(code) {
399
- let s = "";
400
- let inQuote = false;
401
- for (let i = 0; i < code.length; i++) {
402
- const ch = code[i];
403
- if (inQuote) {
404
- if (ch === "\"") inQuote = false;
405
- continue;
406
- }
407
- if (ch === "\"") {
408
- inQuote = true;
409
- continue;
410
- }
411
- if (ch === "\\" || ch === "_" || ch === "*") {
412
- i++;
413
- continue;
414
- }
415
- if (ch === ";") break;
416
- if (ch === "[") {
417
- const end = code.indexOf("]", i + 1);
418
- if (end === -1) break;
419
- const inner = code.slice(i + 1, end).toLowerCase();
420
- if (/^(h+|m+|s+)$/.test(inner)) return false;
421
- i = end;
422
- continue;
423
- }
424
- s += ch;
425
- }
426
- s = s.replace(/general/gi, "").replace(/e[+-]/gi, "");
427
- return /[ymdhs]|am\/pm|a\/p|[egb]/i.test(s);
428
- }
429
- export { fromDosDateTime as a, nativeCodec as c, throttleProgress as d, ByteWriter as f, serialToDate as i, decodeUtf8Strict as l, throwIfAborted as m, isDateFormat as n, toDosDateTime as o, concatBytes 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 };