javascript-excel 1.0.3 → 2.0.0-alpha.1

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 (50) hide show
  1. package/README.md +50 -2
  2. package/dist/auto-width-2oBzjeNG.d.cts +11 -0
  3. package/dist/auto-width-CT-BihTW.d.ts +10 -0
  4. package/dist/csv.cjs +623 -0
  5. package/dist/csv.d.cts +89 -0
  6. package/dist/csv.d.ts +89 -0
  7. package/dist/csv.js +618 -0
  8. package/dist/dom.cjs +464 -0
  9. package/dist/dom.d.cts +78 -0
  10. package/dist/dom.d.ts +78 -0
  11. package/dist/dom.js +461 -0
  12. package/dist/errors-CvGlfw0E.js +28 -0
  13. package/dist/errors-DOPrrGS4.cjs +69 -0
  14. package/dist/index.cjs +1424 -0
  15. package/dist/index.d.cts +140 -0
  16. package/dist/index.d.ts +140 -0
  17. package/dist/index.js +1397 -0
  18. package/dist/infer-BR-J9BZa.js +88 -0
  19. package/dist/infer-D9EC9vJ-.cjs +105 -0
  20. package/dist/iso-date-B22IvwL1.js +21 -0
  21. package/dist/iso-date-BSUsPSWO.cjs +26 -0
  22. package/dist/numfmt-B-TlCgr7.cjs +476 -0
  23. package/dist/numfmt-DEm0sYBJ.js +399 -0
  24. package/dist/read.cjs +2899 -0
  25. package/dist/read.d.cts +88 -0
  26. package/dist/read.d.ts +88 -0
  27. package/dist/read.js +2895 -0
  28. package/dist/sheet-names-CDsVK15c.js +831 -0
  29. package/dist/sheet-names-Cm-IhbBk.cjs +1004 -0
  30. package/dist/signal-Dz0ZYe6d.d.cts +13 -0
  31. package/dist/signal-Dz0ZYe6d.d.ts +13 -0
  32. package/dist/warnings-C_12PT4t.d.cts +410 -0
  33. package/dist/warnings-DXJKe1lx.d.ts +410 -0
  34. package/dist/worker.cjs +11 -0
  35. package/dist/worker.d.cts +8 -0
  36. package/dist/worker.d.ts +8 -0
  37. package/dist/worker.js +10 -0
  38. package/dist/write-C5JgeIar.d.cts +29 -0
  39. package/dist/write-CYpLGuzl.d.ts +29 -0
  40. package/package.json +67 -51
  41. package/.babelrc +0 -10
  42. package/.circleci/config.yml +0 -39
  43. package/lib/index.d.ts +0 -1
  44. package/lib/index.js +0 -22
  45. package/lib/javascript-excel.js +0 -17703
  46. package/src/index.tsx +0 -11
  47. package/test/unit/sample.spec.js +0 -5
  48. package/tsconfig.json +0 -54
  49. package/webpack.config.js +0 -19
  50. /package/{LICENSE.md → LICENSE} +0 -0
package/dist/dom.js ADDED
@@ -0,0 +1,461 @@
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-CDsVK15c.js";
2
+ import { n as EnvironmentError, o as ValidationError } from "./errors-CvGlfw0E.js";
3
+ // src/auto-width.ts
4
+ /**
5
+ * Auto column widths for builders (docs/api.md §4.3, §5.4).
6
+ */
7
+ /** Estimated width in characters per column: widest `cellText` + 2 padding, clamped to [min, max]. */
8
+ function autoWidths(rows, options = {}) {
9
+ const min = options.min ?? AUTO_WIDTH.min;
10
+ const max = Math.min(255, options.max ?? AUTO_WIDTH.max);
11
+ const limit = Math.min(rows.length, options.sampleRows ?? rows.length);
12
+ const widest = [];
13
+ for (let r = 0; r < limit; r++) {
14
+ const row = rows[r];
15
+ if (!row) continue;
16
+ for (let c = 0; c < row.length; c++) {
17
+ const w = textWidth(cellText(row[c]));
18
+ if (w > (widest[c] ?? 0)) widest[c] = w;
19
+ }
20
+ }
21
+ return Array.from(widest, (w) => Math.min(max, Math.max(min, (w ?? 0) + AUTO_WIDTH.padding)));
22
+ }
23
+ // src/internal/css-color.ts
24
+ /** CSS colour values to RRGGBB, for computed-style mapping in javascript-excel/dom. */
25
+ const NAMED = {
26
+ black: "000000",
27
+ white: "FFFFFF",
28
+ red: "FF0000",
29
+ lime: "00FF00",
30
+ green: "008000",
31
+ blue: "0000FF",
32
+ yellow: "FFFF00",
33
+ cyan: "00FFFF",
34
+ aqua: "00FFFF",
35
+ magenta: "FF00FF",
36
+ fuchsia: "FF00FF",
37
+ silver: "C0C0C0",
38
+ gray: "808080",
39
+ grey: "808080",
40
+ maroon: "800000",
41
+ olive: "808000",
42
+ purple: "800080",
43
+ teal: "008080",
44
+ navy: "000080",
45
+ orange: "FFA500"
46
+ };
47
+ /** A CSS colour as RRGGBB, or undefined for transparent or unparseable values. */
48
+ function cssColor(value) {
49
+ const v = value.trim().toLowerCase();
50
+ if (!v || v === "transparent" || v === "currentcolor" || v === "inherit" || v === "initial") return void 0;
51
+ const hex = /^#([0-9a-f]{3,8})$/.exec(v)?.[1];
52
+ if (hex) {
53
+ if (hex.length === 3 || hex.length === 4) {
54
+ if (hex.length === 4 && hex[3] === "0") return void 0;
55
+ return hex.slice(0, 3).split("").map((c) => c + c).join("").toUpperCase();
56
+ }
57
+ if (hex.length === 6) return hex.toUpperCase();
58
+ if (hex.length === 8) return hex.slice(6) === "00" ? void 0 : hex.slice(0, 6).toUpperCase();
59
+ return;
60
+ }
61
+ const m = /^rgba?\(\s*([\d.]+%?)[\s,]+([\d.]+%?)[\s,]+([\d.]+%?)(?:\s*[,/]\s*([\d.]+%?))?\s*\)$/.exec(v);
62
+ if (m) {
63
+ const ch = (s) => Math.round(Math.min(255, Math.max(0, s.endsWith("%") ? parseFloat(s) * 255 / 100 : parseFloat(s))));
64
+ if (m[4] !== void 0) {
65
+ if (!((m[4].endsWith("%") ? parseFloat(m[4]) / 100 : parseFloat(m[4])) > 0)) return void 0;
66
+ }
67
+ return [
68
+ m[1],
69
+ m[2],
70
+ m[3]
71
+ ].map((s) => ch(s).toString(16).padStart(2, "0")).join("").toUpperCase();
72
+ }
73
+ return NAMED[v];
74
+ }
75
+ function isElement(n) {
76
+ return n.nodeType === 1;
77
+ }
78
+ // src/dom.ts
79
+ /**
80
+ * javascript-excel/dom: HTML table input and file download (docs/api.md §5.4).
81
+ *
82
+ * The only module that touches the DOM. Importing it never reads a global, so
83
+ * it is safe during server-side rendering; the DOM is used only inside the
84
+ * functions, and a table is read through its own window (iframes work).
85
+ */
86
+ const DEFAULT_IGNORE = "[data-export-ignore]";
87
+ const XLSX_MIME = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
88
+ /** HTML's limits on colspan and rowspan. */
89
+ const MAX_COLSPAN = 1e3;
90
+ const MAX_ROWSPAN = 65534;
91
+ /**
92
+ * How long the object URL stays valid after the click. Browsers start the
93
+ * download asynchronously, and Safari needs the URL for a while; 40 s is the
94
+ * delay FileSaver.js uses. Not measured here.
95
+ */
96
+ const DOWNLOAD_REVOKE_DELAY_MS = 4e4;
97
+ function mimeFor(filename, data) {
98
+ const ext = /\.([A-Za-z0-9]+)$/.exec(filename)?.[1]?.toLowerCase();
99
+ if (ext === "xlsx") return XLSX_MIME;
100
+ if (ext === "csv") return "text/csv;charset=utf-8";
101
+ return typeof data === "string" ? "text/plain;charset=utf-8" : "application/octet-stream";
102
+ }
103
+ /**
104
+ * Saves data as a file in the browser: creates an object URL, clicks a
105
+ * temporary `<a download>` and revokes the URL after DOWNLOAD_REVOKE_DELAY_MS.
106
+ * A string is encoded as UTF-8. Throws ENVIRONMENT_UNSUPPORTED without a DOM.
107
+ */
108
+ function download(data, filename, options) {
109
+ const g = globalThis;
110
+ const doc = g.document;
111
+ if (!doc?.body || typeof g.URL?.createObjectURL !== "function" || typeof g.Blob !== "function") throw new EnvironmentError("ENVIRONMENT_UNSUPPORTED", "download() needs a browser DOM (document, URL.createObjectURL, Blob).", { details: { api: "document" } });
112
+ if (typeof filename !== "string" || filename.length === 0) throw new TypeError("download(): filename must be a non-empty string");
113
+ const Blob = g.Blob;
114
+ const isBlob = typeof data === "object" && data !== null && !(data instanceof Uint8Array);
115
+ let blob;
116
+ if (isBlob) {
117
+ const b = data;
118
+ blob = options?.mimeType && b.type !== options.mimeType ? new Blob([b], { type: options.mimeType }) : b;
119
+ } else blob = new Blob([data], { type: options?.mimeType ?? mimeFor(filename, data) });
120
+ const url = g.URL.createObjectURL(blob);
121
+ const a = doc.createElement("a");
122
+ a.href = url;
123
+ a.download = filename;
124
+ a.rel = "noopener";
125
+ a.style.display = "none";
126
+ doc.body.appendChild(a);
127
+ try {
128
+ a.click();
129
+ } finally {
130
+ a.remove();
131
+ const revoke = () => g.URL.revokeObjectURL(url);
132
+ if (typeof g.setTimeout === "function") g.setTimeout(revoke, DOWNLOAD_REVOKE_DELAY_MS);
133
+ else revoke();
134
+ }
135
+ }
136
+ function css(ctx, el, prop) {
137
+ if (!ctx.view) return "";
138
+ try {
139
+ return ctx.view.getComputedStyle(el).getPropertyValue(prop).trim();
140
+ } catch {
141
+ return "";
142
+ }
143
+ }
144
+ function inlineDisplayNone(el) {
145
+ const style = el.getAttribute("style");
146
+ return style !== null && /(?:^|;)\s*display\s*:\s*none\s*(?:!important\s*)?(?:;|$)/i.test(style);
147
+ }
148
+ function skipped(ctx, el) {
149
+ if (el.matches(ctx.ignore)) return true;
150
+ if (!ctx.skipHidden) return false;
151
+ if (el.hasAttribute("hidden") || inlineDisplayNone(el)) return true;
152
+ return ctx.computed && css(ctx, el, "display") === "none";
153
+ }
154
+ const SKIP_TEXT = /* @__PURE__ */ new Set([
155
+ "SCRIPT",
156
+ "STYLE",
157
+ "TEMPLATE",
158
+ "NOSCRIPT"
159
+ ]);
160
+ /** Text of a cell: whitespace collapsed per line, <br> as a newline. */
161
+ function cellTextOf(el) {
162
+ const lines = [""];
163
+ let hasBreak = false;
164
+ const walk = (n) => {
165
+ if (n.nodeType === 3) {
166
+ lines[lines.length - 1] += n.textContent ?? "";
167
+ return;
168
+ }
169
+ if (!isElement(n)) return;
170
+ const tag = n.tagName.toUpperCase();
171
+ if (SKIP_TEXT.has(tag)) return;
172
+ if (tag === "BR") {
173
+ lines.push("");
174
+ hasBreak = true;
175
+ return;
176
+ }
177
+ for (let i = 0; i < n.childNodes.length; i++) walk(n.childNodes[i]);
178
+ };
179
+ for (let i = 0; i < el.childNodes.length; i++) walk(el.childNodes[i]);
180
+ return {
181
+ text: lines.map((l) => l.replace(/[ \t\n\r\f ]+/g, " ").trim()).join("\n").replace(/^\n+|\n+$/g, ""),
182
+ hasBreak
183
+ };
184
+ }
185
+ const PLAIN_NUMBER = /^[+-]?(?:\d+\.?\d*|\.\d+)(?:[eE][+-]?\d+)?$/;
186
+ 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
+ function parseNumber(s) {
189
+ const t = s.trim();
190
+ if (PLAIN_NUMBER.test(t)) return Number(t);
191
+ if (GROUPED_NUMBER.test(t)) return Number(t.replace(/,/g, ""));
192
+ }
193
+ function parseBoolean(s) {
194
+ const t = s.trim().toLowerCase();
195
+ if (t === "true" || t === "yes" || t === "1") return true;
196
+ if (t === "false" || t === "no" || t === "0") return false;
197
+ }
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
+ function coerce(ctx, raw, type, ref) {
223
+ if (type === null || type === "" || type === "string") {
224
+ if (ctx.inferTypes) {
225
+ const n = PLAIN_NUMBER.test(raw.trim()) ? Number(raw.trim()) : void 0;
226
+ if (n !== void 0 && Number.isFinite(n)) return n;
227
+ const t = raw.trim().toLowerCase();
228
+ if (t === "true") return true;
229
+ if (t === "false") return false;
230
+ }
231
+ return raw;
232
+ }
233
+ const fail = () => {
234
+ ctx.warn({
235
+ code: "COERCION_FAILED",
236
+ message: `${ctx.sheet}!${ref}: ${JSON.stringify(raw)} is not a valid ${type}; kept as text.`,
237
+ sheet: ctx.sheet,
238
+ ref
239
+ });
240
+ return raw;
241
+ };
242
+ switch (type) {
243
+ case "number": {
244
+ const n = parseNumber(raw);
245
+ return n !== void 0 && Number.isFinite(n) ? n : fail();
246
+ }
247
+ case "boolean": return parseBoolean(raw) ?? fail();
248
+ case "date": return parseDate(raw) ?? fail();
249
+ default:
250
+ ctx.warn({
251
+ code: "COERCION_FAILED",
252
+ message: `${ctx.sheet}!${ref}: unknown data-type ${JSON.stringify(type)}; kept as text.`,
253
+ sheet: ctx.sheet,
254
+ ref
255
+ });
256
+ return raw;
257
+ }
258
+ }
259
+ /** The first non-transparent background of the cell, its row, section or table (what a reader sees). */
260
+ function backgroundOf(ctx, cell, table) {
261
+ for (let el = cell; el; el = el.parentElement) {
262
+ const c = cssColor(css(ctx, el, "background-color"));
263
+ if (c) return c;
264
+ if (el === table) break;
265
+ }
266
+ }
267
+ function computedStyle(ctx, el, table) {
268
+ const style = {};
269
+ const font = {};
270
+ const weight = css(ctx, el, "font-weight");
271
+ if (weight === "bold" || weight === "bolder" || Number(weight) >= 600) font.bold = true;
272
+ const fs = css(ctx, el, "font-style");
273
+ if (fs === "italic" || fs.startsWith("oblique")) font.italic = true;
274
+ const deco = `${css(ctx, el, "text-decoration-line")} ${css(ctx, el, "text-decoration")}`;
275
+ if (/\bunderline\b/.test(deco)) font.underline = true;
276
+ if (/\bline-through\b/.test(deco)) font.strike = true;
277
+ const color = cssColor(css(ctx, el, "color"));
278
+ if (color && color !== "000000") font.color = color;
279
+ if (Object.keys(font).length) style.font = font;
280
+ const bg = backgroundOf(ctx, el, table);
281
+ if (bg) style.fill = bg;
282
+ const alignment = {};
283
+ const ta = css(ctx, el, "text-align");
284
+ const h = /^(?:-webkit-|-internal-|-moz-)?center$/.test(ta) ? "center" : ta;
285
+ if (h === "left" || h === "right" || h === "center" || h === "justify") alignment.horizontal = h;
286
+ const va = css(ctx, el, "vertical-align");
287
+ if (va === "top" || va === "bottom") alignment.vertical = va;
288
+ const ws = css(ctx, el, "white-space");
289
+ if (ws === "pre-wrap" || ws === "pre-line" || ws === "break-spaces") alignment.wrapText = true;
290
+ if (Object.keys(alignment).length) style.alignment = alignment;
291
+ return Object.keys(style).length ? style : void 0;
292
+ }
293
+ function linkOf(ctx, cell, ref) {
294
+ const find = (n) => {
295
+ for (let i = 0; i < n.children.length; i++) {
296
+ const c = n.children[i];
297
+ if (c.tagName.toUpperCase() === "A" && c.hasAttribute("href")) return c;
298
+ const deeper = find(c);
299
+ if (deeper) return deeper;
300
+ }
301
+ };
302
+ const a = find(cell);
303
+ if (!a) return void 0;
304
+ const raw = a.getAttribute("href") ?? "";
305
+ if (raw.startsWith("#") || raw.trim() === "") return void 0;
306
+ const url = typeof a.href === "string" && a.href ? a.href : raw;
307
+ const scheme = /^([A-Za-z][A-Za-z0-9+.-]*):/.exec(url)?.[1]?.toLowerCase();
308
+ if (!scheme || !ctx.schemes.has(scheme)) {
309
+ ctx.warn({
310
+ code: "HYPERLINK_DROPPED",
311
+ message: `${ctx.sheet}!${ref}: link ${JSON.stringify(url)} dropped (scheme not allowed).`,
312
+ sheet: ctx.sheet,
313
+ ref
314
+ });
315
+ return;
316
+ }
317
+ return url;
318
+ }
319
+ /** Rows in reading order: <thead> rows, then <tbody> and bare <tr> rows, then <tfoot> rows. */
320
+ function collectRows(table, includeFooter) {
321
+ const head = [];
322
+ const body = [];
323
+ const foot = [];
324
+ const bare = [];
325
+ const trs = (section) => Array.from(section.children).filter((c) => c.tagName.toUpperCase() === "TR");
326
+ for (const child of Array.from(table.children)) {
327
+ const tag = child.tagName.toUpperCase();
328
+ if (tag === "THEAD") head.push(trs(child));
329
+ else if (tag === "TBODY") {
330
+ if (bare.length) body.push(bare.splice(0));
331
+ body.push(trs(child));
332
+ } else if (tag === "TFOOT") {
333
+ if (includeFooter) foot.push(trs(child));
334
+ } else if (tag === "TR") bare.push(child);
335
+ }
336
+ if (bare.length) body.push(bare);
337
+ const groups = [
338
+ ...head,
339
+ ...body,
340
+ ...foot
341
+ ];
342
+ const rows = groups.flat();
343
+ const sections = [];
344
+ groups.forEach((g, i) => g.forEach(() => sections.push(i)));
345
+ return {
346
+ rows,
347
+ sections
348
+ };
349
+ }
350
+ function intAttr(el, name, fallback, min, max) {
351
+ const v = el.getAttribute(name);
352
+ if (v === null) return fallback;
353
+ const n = Number.parseInt(v, 10);
354
+ if (!Number.isFinite(n)) return fallback;
355
+ return Math.min(max, Math.max(min, n));
356
+ }
357
+ /** Reads an HTML table into a Sheet: values, merges from colspan/rowspan, hints, links and (optionally) styles. */
358
+ function fromTable(table, options = {}) {
359
+ const t = table;
360
+ if (typeof t !== "object" || t === null || typeof t.tagName !== "string" || typeof t.matches !== "function") throw new EnvironmentError("ENVIRONMENT_UNSUPPORTED", "fromTable() needs a DOM <table> element.", { details: { api: "HTMLTableElement" } });
361
+ if (t.tagName.toUpperCase() !== "TABLE") throw new TypeError(`fromTable(): expected a <table> element, got <${t.tagName.toLowerCase()}>`);
362
+ const name = options.name ?? "Sheet1";
363
+ const problem = validateSheetName(name);
364
+ if (problem) throw new ValidationError("INVALID_SHEET_NAME", `fromTable(): sheet name ${JSON.stringify(name)} is invalid (${problem}).`, { details: {
365
+ sheet: name,
366
+ problem
367
+ } });
368
+ const ctx = {
369
+ view: t.ownerDocument?.defaultView ?? null,
370
+ computed: options.styles === "computed",
371
+ skipHidden: options.skipHidden !== false,
372
+ ignore: options.ignore ?? DEFAULT_IGNORE,
373
+ inferTypes: options.inferTypes === true,
374
+ links: options.links !== false,
375
+ schemes: options.hyperlinkSchemes === void 0 ? new Set(DEFAULT_HYPERLINK_SCHEMES) : hyperlinkSchemes(options.hyperlinkSchemes),
376
+ sheet: name,
377
+ warn: options.onWarning ?? (() => {})
378
+ };
379
+ const rtl = t.closest("[dir]")?.getAttribute("dir")?.toLowerCase() === "rtl" || ctx.computed && css(ctx, t, "direction") === "rtl";
380
+ const { rows: allRows, sections: allSections } = collectRows(t, options.includeFooter !== false);
381
+ const header = options.header ?? "thead";
382
+ const headerStyle = options.headerStyle ?? { font: { bold: true } };
383
+ const out = [];
384
+ const merges = [];
385
+ const occupied = [];
386
+ const occupy = (r, c) => {
387
+ (occupied[r] ??= [])[c] = true;
388
+ };
389
+ const kept = allRows.map((tr, i) => ({
390
+ tr,
391
+ section: allSections[i]
392
+ })).filter(({ tr }) => !skipped(ctx, tr));
393
+ const headerCount = header === "thead" ? kept.filter(({ tr }) => tr.parentElement?.tagName.toUpperCase() === "THEAD").length : header === false ? 0 : Math.max(0, Math.trunc(header));
394
+ let maxCol = -1;
395
+ kept.forEach(({ tr, section }, r) => {
396
+ const row = out[r] ??= [];
397
+ let c = 0;
398
+ for (const cell of Array.from(tr.children)) {
399
+ const tag = cell.tagName.toUpperCase();
400
+ if (tag !== "TD" && tag !== "TH") continue;
401
+ if (skipped(ctx, cell)) continue;
402
+ while (occupied[r]?.[c]) c++;
403
+ const colspan = intAttr(cell, "colspan", 1, 1, MAX_COLSPAN);
404
+ let rowspan = intAttr(cell, "rowspan", 1, 0, MAX_ROWSPAN);
405
+ if (rowspan === 0) {
406
+ let end = r;
407
+ while (end + 1 < kept.length && kept[end + 1].section === section) end++;
408
+ rowspan = end - r + 1;
409
+ }
410
+ rowspan = Math.min(rowspan, kept.length - r);
411
+ for (let dr = 0; dr < rowspan; dr++) for (let dc = 0; dc < colspan; dc++) occupy(r + dr, c + dc);
412
+ const ref = `${colName(c)}${r + 1}`;
413
+ if (colspan > 1 || rowspan > 1) merges.push(`${ref}:${colName(c + colspan - 1)}${r + rowspan}`);
414
+ const isHeader = r < headerCount;
415
+ const hooked = options.cell?.(cell, {
416
+ row: r,
417
+ col: c,
418
+ header: isHeader
419
+ });
420
+ if (hooked !== void 0) row[c] = hooked;
421
+ else {
422
+ const dataValue = cell.getAttribute("data-value");
423
+ const { text, hasBreak } = cellTextOf(cell);
424
+ const value = coerce(ctx, dataValue ?? text, cell.getAttribute("data-type"), ref);
425
+ const layers = [];
426
+ if (isHeader) layers.push(headerStyle);
427
+ if (ctx.computed) layers.push(computedStyle(ctx, cell, t));
428
+ if (hasBreak) layers.push({ alignment: { wrapText: true } });
429
+ const numFmt = cell.getAttribute("data-numfmt");
430
+ if (numFmt) layers.push({ numFmt: /^\d+$/.test(numFmt) ? Number(numFmt) : numFmt });
431
+ const style = layers.some(Boolean) ? mergeStyles(...layers) : void 0;
432
+ const hyperlink = ctx.links ? linkOf(ctx, cell, ref) : void 0;
433
+ row[c] = style === void 0 && hyperlink === void 0 ? value : {
434
+ value,
435
+ ...style ? { style } : {},
436
+ ...hyperlink ? { hyperlink } : {}
437
+ };
438
+ }
439
+ maxCol = Math.max(maxCol, c + colspan - 1);
440
+ c += colspan;
441
+ }
442
+ });
443
+ const sheet = {
444
+ name,
445
+ rows: out
446
+ };
447
+ if (merges.length) sheet.merges = merges;
448
+ const view = {};
449
+ if (rtl) view.rightToLeft = true;
450
+ if (options.freezeHeader && headerCount > 0) view.freeze = { rows: headerCount };
451
+ if (Object.keys(view).length) sheet.view = view;
452
+ if (options.autoFilter && headerCount > 0 && maxCol >= 0) sheet.autoFilter = `A${headerCount}:${colName(maxCol)}${Math.max(headerCount, out.length)}`;
453
+ if (options.autoWidth) sheet.colProps = autoWidths(out, typeof options.autoWidth === "object" ? options.autoWidth : {}).map((width) => ({ width }));
454
+ return sheet;
455
+ }
456
+ function colName(c) {
457
+ let s = "";
458
+ for (let n = c + 1; n > 0; n = Math.floor((n - 1) / 26)) s = String.fromCharCode(65 + (n - 1) % 26) + s;
459
+ return s;
460
+ }
461
+ export { DOWNLOAD_REVOKE_DELAY_MS, download, fromTable };
@@ -0,0 +1,28 @@
1
+ // src/errors.ts
2
+ const BRAND = Symbol.for("javascript-excel.error");
3
+ /** Base class of every error the library throws. */
4
+ var ExcelError = class extends Error {
5
+ code;
6
+ constructor(code, message, options) {
7
+ super(message, options?.cause === void 0 ? void 0 : { cause: options.cause });
8
+ this.name = new.target.name;
9
+ this.code = code;
10
+ if (options?.details !== void 0) this.details = options.details;
11
+ Object.defineProperty(this, BRAND, { value: true });
12
+ }
13
+ };
14
+ /** The model or options cannot be written. */
15
+ var ValidationError = class extends ExcelError {};
16
+ /** The input is not a readable xlsx or zip file. */
17
+ var FormatError = class extends ExcelError {};
18
+ /** A read limit was exceeded; `details.limit` names it. */
19
+ var LimitError = class extends ExcelError {};
20
+ /** Malformed CSV in strict mode. */
21
+ var CsvError = class extends ExcelError {};
22
+ /** A required platform API is missing. */
23
+ var EnvironmentError = class extends ExcelError {};
24
+ /** True for any error thrown by this library, across ESM/CJS copies and realms. */
25
+ function isExcelError(e) {
26
+ return typeof e === "object" && e !== null && e[BRAND] === true;
27
+ }
28
+ export { LimitError as a, FormatError as i, EnvironmentError as n, ValidationError as o, ExcelError as r, isExcelError as s, CsvError as t };
@@ -0,0 +1,69 @@
1
+ // src/errors.ts
2
+ const BRAND = Symbol.for("javascript-excel.error");
3
+ /** Base class of every error the library throws. */
4
+ var ExcelError = class extends Error {
5
+ code;
6
+ constructor(code, message, options) {
7
+ super(message, options?.cause === void 0 ? void 0 : { cause: options.cause });
8
+ this.name = new.target.name;
9
+ this.code = code;
10
+ if (options?.details !== void 0) this.details = options.details;
11
+ Object.defineProperty(this, BRAND, { value: true });
12
+ }
13
+ };
14
+ /** The model or options cannot be written. */
15
+ var ValidationError = class extends ExcelError {};
16
+ /** The input is not a readable xlsx or zip file. */
17
+ var FormatError = class extends ExcelError {};
18
+ /** A read limit was exceeded; `details.limit` names it. */
19
+ var LimitError = class extends ExcelError {};
20
+ /** Malformed CSV in strict mode. */
21
+ var CsvError = class extends ExcelError {};
22
+ /** A required platform API is missing. */
23
+ var EnvironmentError = class extends ExcelError {};
24
+ /** True for any error thrown by this library, across ESM/CJS copies and realms. */
25
+ function isExcelError(e) {
26
+ return typeof e === "object" && e !== null && e[BRAND] === true;
27
+ }
28
+ Object.defineProperty(exports, "CsvError", {
29
+ enumerable: true,
30
+ get: function() {
31
+ return CsvError;
32
+ }
33
+ });
34
+ Object.defineProperty(exports, "EnvironmentError", {
35
+ enumerable: true,
36
+ get: function() {
37
+ return EnvironmentError;
38
+ }
39
+ });
40
+ Object.defineProperty(exports, "ExcelError", {
41
+ enumerable: true,
42
+ get: function() {
43
+ return ExcelError;
44
+ }
45
+ });
46
+ Object.defineProperty(exports, "FormatError", {
47
+ enumerable: true,
48
+ get: function() {
49
+ return FormatError;
50
+ }
51
+ });
52
+ Object.defineProperty(exports, "LimitError", {
53
+ enumerable: true,
54
+ get: function() {
55
+ return LimitError;
56
+ }
57
+ });
58
+ Object.defineProperty(exports, "ValidationError", {
59
+ enumerable: true,
60
+ get: function() {
61
+ return ValidationError;
62
+ }
63
+ });
64
+ Object.defineProperty(exports, "isExcelError", {
65
+ enumerable: true,
66
+ get: function() {
67
+ return isExcelError;
68
+ }
69
+ });