@umriss-ui/table 0.42.0 → 0.44.0

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/dist/xlsx.d.ts ADDED
@@ -0,0 +1,37 @@
1
+ import { Formats } from '@umriss-ui/core';
2
+ import { Wording } from '@umriss-ui/core';
3
+
4
+ /** What a spreadsheet cell holds: numbers, booleans and points in time stay
5
+ what they are, an absent value is `undefined`. */
6
+ declare type ExportCell = string | number | boolean | Date | undefined;
7
+
8
+ /** What the language in use hands a format. */
9
+ declare interface ExportContext {
10
+ formats: Formats;
11
+ wording: Wording;
12
+ }
13
+
14
+ /** A way to write the export: the file's extension and MIME type, and the
15
+ function that turns the sheet into `R` - text or bytes. */
16
+ declare interface ExportFormat<R = string> {
17
+ extension: string;
18
+ mime: string;
19
+ write: (sheet: ExportSheet, context: ExportContext) => R;
20
+ }
21
+
22
+ /** What a format writes: the header labels, the widths the table holds, whether
23
+ a column's own `exportValue` made its values (`own`: written as they come),
24
+ and the rows as typed cells. A tree's level is its first column, a number. */
25
+ declare interface ExportSheet {
26
+ columns: readonly {
27
+ label: string;
28
+ width?: number;
29
+ own?: true;
30
+ }[];
31
+ rows: readonly (readonly ExportCell[])[];
32
+ }
33
+
34
+ /** The Excel workbook format for `Export`: one sheet, a header line, numbers, dates, booleans and text as what they are, and the table's column widths. `onExport` gets the bytes. */
35
+ export declare const xlsx: ExportFormat<Uint8Array>;
36
+
37
+ export { }
package/dist/xlsx.js ADDED
@@ -0,0 +1,107 @@
1
+ "use client";
2
+ const h = `<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
3
+ `, y = "http://schemas.openxmlformats.org/", w = `${y}spreadsheetml/2006/main`, I = `${y}package/2006/relationships`, g = `${y}officeDocument/2006/relationships`, E = (t) => t.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;");
4
+ function R(t) {
5
+ return t.replace(/[[\]:*?/\\]/g, "").slice(0, 31) || "Sheet1";
6
+ }
7
+ function C(t, e) {
8
+ return [
9
+ {
10
+ name: "[Content_Types].xml",
11
+ text: `${h}<Types xmlns="${y}package/2006/content-types"><Default Extension="rels" ContentType="application/vnd.openxmlformats-package.relationships+xml"/><Default Extension="xml" ContentType="application/xml"/><Override PartName="/xl/workbook.xml" ContentType="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet.main+xml"/><Override PartName="/xl/worksheets/sheet1.xml" ContentType="application/vnd.openxmlformats-officedocument.spreadsheetml.worksheet+xml"/><Override PartName="/xl/styles.xml" ContentType="application/vnd.openxmlformats-officedocument.spreadsheetml.styles+xml"/></Types>`
12
+ },
13
+ {
14
+ name: "_rels/.rels",
15
+ text: `${h}<Relationships xmlns="${I}"><Relationship Id="rId1" Type="${g}/officeDocument" Target="xl/workbook.xml"/></Relationships>`
16
+ },
17
+ {
18
+ name: "xl/workbook.xml",
19
+ text: `${h}<workbook xmlns="${w}" xmlns:r="${g}"><sheets><sheet name="${E(R(t))}" sheetId="1" r:id="rId1"/></sheets></workbook>`
20
+ },
21
+ {
22
+ name: "xl/_rels/workbook.xml.rels",
23
+ text: `${h}<Relationships xmlns="${I}"><Relationship Id="rId1" Type="${g}/worksheet" Target="worksheets/sheet1.xml"/><Relationship Id="rId2" Type="${g}/styles" Target="styles.xml"/></Relationships>`
24
+ },
25
+ {
26
+ /* Cell format 0 is general, 1 a date, 2 a date with time. */
27
+ name: "xl/styles.xml",
28
+ text: `${h}<styleSheet xmlns="${w}"><numFmts count="2"><numFmt numFmtId="164" formatCode="yyyy-mm-dd"/><numFmt numFmtId="165" formatCode="yyyy-mm-dd hh:mm:ss"/></numFmts><fonts count="1"><font><sz val="11"/><name val="Calibri"/></font></fonts><fills count="2"><fill><patternFill patternType="none"/></fill><fill><patternFill patternType="gray125"/></fill></fills><borders count="1"><border><left/><right/><top/><bottom/><diagonal/></border></borders><cellStyleXfs count="1"><xf numFmtId="0" fontId="0" fillId="0" borderId="0"/></cellStyleXfs><cellXfs count="3"><xf numFmtId="0" fontId="0" fillId="0" borderId="0" xfId="0"/><xf numFmtId="164" fontId="0" fillId="0" borderId="0" xfId="0" applyNumberFormat="1"/><xf numFmtId="165" fontId="0" fillId="0" borderId="0" xfId="0" applyNumberFormat="1"/></cellXfs><cellStyles count="1"><cellStyle name="Normal" xfId="0" builtinId="0"/></cellStyles></styleSheet>`
29
+ },
30
+ { name: "xl/worksheets/sheet1.xml", text: e }
31
+ ];
32
+ }
33
+ const N = (t) => {
34
+ for (const e of t) if (e instanceof Date && e.getHours() + e.getMinutes() + e.getSeconds() + e.getMilliseconds() !== 0) return !1;
35
+ return !0;
36
+ }, b = 1048576, F = 16384, T = 32767, A = 864e5, M = Date.UTC(1899, 11, 30), O = 61, _ = /[^\t\n\r -퟿-�\u{10000}-\u{10FFFF}]/gu;
37
+ function k(t) {
38
+ let e = "";
39
+ for (t += 1; t > 0; t = Math.floor((t - 1) / 26)) e = String.fromCharCode(65 + (t - 1) % 26) + e;
40
+ return e;
41
+ }
42
+ const v = (t) => (Date.UTC(t.getFullYear(), t.getMonth(), t.getDate(), t.getHours(), t.getMinutes(), t.getSeconds(), t.getMilliseconds()) - M) / A;
43
+ function X(t) {
44
+ let e = t.replace(_, "");
45
+ return e.length > T && (e = e.slice(0, T), /[\uD800-\uDBFF]$/.test(e) && (e = e.slice(0, -1))), E(e);
46
+ }
47
+ const $ = (t, e) => `<c r="${t}" t="inlineStr"><is><t xml:space="preserve">${X(e)}</t></is></c>`;
48
+ function L(t) {
49
+ const { columns: e, rows: l } = t;
50
+ if (e.length > F) throw new RangeError(`A worksheet holds at most ${F.toLocaleString("en")} columns.`);
51
+ if (l.length + 1 > b) throw new RangeError(`A worksheet holds at most ${b.toLocaleString("en")} rows.`);
52
+ const i = e.map((n, s) => N(l.map((c) => c[s])) ? 1 : 2), p = e.map((n, s) => n.width === void 0 ? "" : `<col min="${s + 1}" max="${s + 1}" width="${n.width / 7 + 1}" customWidth="1"/>`).join(""), u = `<row r="1">${e.map((n, s) => $(`${k(s)}1`, n.label)).join("")}</row>`, a = l.map((n, s) => {
53
+ const c = s + 2;
54
+ let m = "";
55
+ for (let f = 0; f < n.length; f++) {
56
+ const r = n[f], d = `${k(f)}${c}`;
57
+ typeof r == "number" ? Number.isFinite(r) && (m += `<c r="${d}"><v>${r}</v></c>`) : typeof r == "boolean" ? m += `<c r="${d}" t="b"><v>${r ? 1 : 0}</v></c>` : typeof r == "string" ? m += $(d, r) : r instanceof Date && !Number.isNaN(r.getTime()) && (v(r) >= O ? m += `<c r="${d}" s="${i[f]}"><v>${v(r)}</v></c>` : m += $(d, r.toISOString()));
58
+ }
59
+ return m ? `<row r="${c}">${m}</row>` : `<row r="${c}"/>`;
60
+ });
61
+ return `<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
62
+ <worksheet xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main">` + (p ? `<cols>${p}</cols>` : "") + `<sheetData>${u}${a.join("")}</sheetData></worksheet>`;
63
+ }
64
+ const U = Array.from({ length: 256 }, (t, e) => {
65
+ let l = e;
66
+ for (let i = 0; i < 8; i++) l = l & 1 ? 3988292384 ^ l >>> 1 : l >>> 1;
67
+ return l >>> 0;
68
+ });
69
+ function P(t) {
70
+ let e = 4294967295;
71
+ for (const l of t) e = U[(e ^ l) & 255] ^ e >>> 8;
72
+ return (e ^ 4294967295) >>> 0;
73
+ }
74
+ const S = 33, D = 2048;
75
+ function B(t) {
76
+ if (t.length > 65535) throw new RangeError("A ZIP holds at most 65,535 parts.");
77
+ const e = new TextEncoder(), l = t.map((o) => ({ name: e.encode(o.name), data: e.encode(o.text) }));
78
+ let i = 22;
79
+ for (const o of l) i += 76 + 2 * o.name.length + o.data.length;
80
+ if (i > 4294967295) throw new RangeError("A ZIP without ZIP64 holds at most 4 GB.");
81
+ const p = new Uint8Array(i), u = new DataView(p.buffer);
82
+ let a = 0;
83
+ const n = (o) => {
84
+ u.setUint16(a, o, !0), a += 2;
85
+ }, s = (o) => {
86
+ u.setUint32(a, o, !0), a += 4;
87
+ }, c = (o) => {
88
+ p.set(o, a), a += o.length;
89
+ }, m = [], f = l.map((o) => P(o.data));
90
+ l.forEach((o, x) => {
91
+ m.push(a), s(67324752), n(20), n(D), n(0), n(0), n(S), s(f[x]), s(o.data.length), s(o.data.length), n(o.name.length), n(0), c(o.name), c(o.data);
92
+ });
93
+ const r = a;
94
+ l.forEach((o, x) => {
95
+ s(33639248), n(20), n(20), n(D), n(0), n(0), n(S), s(f[x]), s(o.data.length), s(o.data.length), n(o.name.length), n(0), n(0), n(0), n(0), s(0), s(m[x]), c(o.name);
96
+ });
97
+ const d = a;
98
+ return s(101010256), n(0), n(0), n(l.length), n(l.length), s(d - r), s(r), n(0), p;
99
+ }
100
+ const j = {
101
+ extension: "xlsx",
102
+ mime: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
103
+ write: (t, { wording: e }) => B(C(e.exportSheetName, L(t)))
104
+ };
105
+ export {
106
+ j as xlsx
107
+ };