beautiful-grid 1.0.11 → 1.0.13

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.
@@ -0,0 +1,129 @@
1
+ "use strict";
2
+ var __values = (this && this.__values) || function(o) {
3
+ var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
4
+ if (m) return m.call(o);
5
+ if (o && typeof o.length === "number") return {
6
+ next: function () {
7
+ if (o && i >= o.length) o = void 0;
8
+ return { value: o && o[i++], done: !o };
9
+ }
10
+ };
11
+ throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
12
+ };
13
+ Object.defineProperty(exports, "__esModule", { value: true });
14
+ exports.formatCsvCellValue = formatCsvCellValue;
15
+ exports.escapeCsvCell = escapeCsvCell;
16
+ exports.serializeGridExportDataToCsv = serializeGridExportDataToCsv;
17
+ exports.downloadCsv = downloadCsv;
18
+ function formatCsvCellValue(value, preventFormulaInjection) {
19
+ if (preventFormulaInjection === void 0) { preventFormulaInjection = true; }
20
+ if (value === null || value === undefined) {
21
+ return '';
22
+ }
23
+ var formatted;
24
+ if (typeof value === 'string') {
25
+ formatted = value;
26
+ var startsWithFormula = /^[=+\-@]/.test(formatted);
27
+ var startsWithDangerousControl = /^[\t\r\n]/.test(formatted);
28
+ var hasFormulaAfterLeadingWhitespace = /^\s+[=+\-@]/.test(formatted);
29
+ if (preventFormulaInjection &&
30
+ (startsWithFormula || startsWithDangerousControl || hasFormulaAfterLeadingWhitespace)) {
31
+ formatted = "'".concat(formatted);
32
+ }
33
+ return formatted;
34
+ }
35
+ if (typeof value === 'number') {
36
+ return String(value);
37
+ }
38
+ if (typeof value === 'boolean') {
39
+ return value ? 'true' : 'false';
40
+ }
41
+ if (typeof value === 'bigint') {
42
+ return value.toString();
43
+ }
44
+ if (value instanceof Date) {
45
+ return isNaN(value.getTime()) ? 'Invalid Date' : value.toISOString();
46
+ }
47
+ if (typeof value === 'object') {
48
+ try {
49
+ formatted = JSON.stringify(value);
50
+ }
51
+ catch (_a) {
52
+ formatted = String(value);
53
+ }
54
+ return formatted;
55
+ }
56
+ return String(value);
57
+ }
58
+ function escapeCsvCell(cell, delimiter) {
59
+ if (delimiter === void 0) { delimiter = ','; }
60
+ var needsQuotes = cell.includes(delimiter) ||
61
+ cell.includes('"') ||
62
+ cell.includes('\r') ||
63
+ cell.includes('\n');
64
+ if (needsQuotes) {
65
+ return "\"".concat(cell.replace(/"/g, '""'), "\"");
66
+ }
67
+ return cell;
68
+ }
69
+ function serializeGridExportDataToCsv(data, options) {
70
+ var e_1, _a;
71
+ var _b, _c, _d, _e, _f;
72
+ var delimiter = (_b = options === null || options === void 0 ? void 0 : options.delimiter) !== null && _b !== void 0 ? _b : ',';
73
+ var newline = (_c = options === null || options === void 0 ? void 0 : options.newline) !== null && _c !== void 0 ? _c : '\r\n';
74
+ var includeHeader = (_d = options === null || options === void 0 ? void 0 : options.includeHeader) !== null && _d !== void 0 ? _d : true;
75
+ var bom = (_e = options === null || options === void 0 ? void 0 : options.bom) !== null && _e !== void 0 ? _e : true;
76
+ var preventFormulaInjection = (_f = options === null || options === void 0 ? void 0 : options.preventFormulaInjection) !== null && _f !== void 0 ? _f : true;
77
+ var lines = [];
78
+ if (includeHeader) {
79
+ var headerLine = data.columns
80
+ .map(function (col) { return escapeCsvCell(formatCsvCellValue(col.header, preventFormulaInjection), delimiter); })
81
+ .join(delimiter);
82
+ lines.push(headerLine);
83
+ }
84
+ try {
85
+ for (var _g = __values(data.rows), _h = _g.next(); !_h.done; _h = _g.next()) {
86
+ var row = _h.value;
87
+ var rowLine = row.cells
88
+ .map(function (cell) { return escapeCsvCell(formatCsvCellValue(cell, preventFormulaInjection), delimiter); })
89
+ .join(delimiter);
90
+ lines.push(rowLine);
91
+ }
92
+ }
93
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
94
+ finally {
95
+ try {
96
+ if (_h && !_h.done && (_a = _g.return)) _a.call(_g);
97
+ }
98
+ finally { if (e_1) throw e_1.error; }
99
+ }
100
+ var csvText = lines.join(newline);
101
+ return (bom ? '\uFEFF' : '') + csvText;
102
+ }
103
+ function downloadCsv(csv, fileName) {
104
+ if (fileName === void 0) { fileName = 'export.csv'; }
105
+ if (typeof window === 'undefined' || typeof document === 'undefined') {
106
+ return;
107
+ }
108
+ var resolvedName = (fileName || '').trim();
109
+ if (!resolvedName) {
110
+ resolvedName = 'export.csv';
111
+ }
112
+ else if (!resolvedName.toLowerCase().endsWith('.csv')) {
113
+ resolvedName += '.csv';
114
+ }
115
+ var blob = new Blob([csv], { type: 'text/csv;charset=utf-8;' });
116
+ if (typeof URL !== 'undefined' && typeof URL.createObjectURL === 'function') {
117
+ var url = URL.createObjectURL(blob);
118
+ var link = document.createElement('a');
119
+ link.href = url;
120
+ link.setAttribute('download', resolvedName);
121
+ link.style.display = 'none';
122
+ document.body.appendChild(link);
123
+ link.click();
124
+ document.body.removeChild(link);
125
+ if (typeof URL.revokeObjectURL === 'function') {
126
+ URL.revokeObjectURL(url);
127
+ }
128
+ }
129
+ }
@@ -0,0 +1,230 @@
1
+ "use strict";
2
+ var __values = (this && this.__values) || function(o) {
3
+ var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
4
+ if (m) return m.call(o);
5
+ if (o && typeof o.length === "number") return {
6
+ next: function () {
7
+ if (o && i >= o.length) o = void 0;
8
+ return { value: o && o[i++], done: !o };
9
+ }
10
+ };
11
+ throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
12
+ };
13
+ var __read = (this && this.__read) || function (o, n) {
14
+ var m = typeof Symbol === "function" && o[Symbol.iterator];
15
+ if (!m) return o;
16
+ var i = m.call(o), r, ar = [], e;
17
+ try {
18
+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
19
+ }
20
+ catch (error) { e = { error: error }; }
21
+ finally {
22
+ try {
23
+ if (r && !r.done && (m = i["return"])) m.call(i);
24
+ }
25
+ finally { if (e) throw e.error; }
26
+ }
27
+ return ar;
28
+ };
29
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
30
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
31
+ if (ar || !(i in from)) {
32
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
33
+ ar[i] = from[i];
34
+ }
35
+ }
36
+ return to.concat(ar || Array.prototype.slice.call(from));
37
+ };
38
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ exports.resolveExportColumns = resolveExportColumns;
40
+ exports.resolveExportRows = resolveExportRows;
41
+ exports.createGridExportData = createGridExportData;
42
+ var getColumnId_1 = require("./getColumnId");
43
+ var getCellValue_1 = require("./getCellValue");
44
+ function resolveExportColumns(columns, sourceColumns, scope) {
45
+ var e_1, _a, e_2, _b;
46
+ if (scope === void 0) { scope = 'visible'; }
47
+ var selectedColumns;
48
+ if (Array.isArray(scope)) {
49
+ var candidatePool = sourceColumns && sourceColumns.length > 0 ? sourceColumns : columns;
50
+ var columnMap = new Map();
51
+ try {
52
+ for (var candidatePool_1 = __values(candidatePool), candidatePool_1_1 = candidatePool_1.next(); !candidatePool_1_1.done; candidatePool_1_1 = candidatePool_1.next()) {
53
+ var col = candidatePool_1_1.value;
54
+ columnMap.set((0, getColumnId_1.getColumnId)(col), col);
55
+ }
56
+ }
57
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
58
+ finally {
59
+ try {
60
+ if (candidatePool_1_1 && !candidatePool_1_1.done && (_a = candidatePool_1.return)) _a.call(candidatePool_1);
61
+ }
62
+ finally { if (e_1) throw e_1.error; }
63
+ }
64
+ selectedColumns = [];
65
+ try {
66
+ for (var scope_1 = __values(scope), scope_1_1 = scope_1.next(); !scope_1_1.done; scope_1_1 = scope_1.next()) {
67
+ var id = scope_1_1.value;
68
+ var col = columnMap.get(id);
69
+ if (col) {
70
+ selectedColumns.push(col);
71
+ }
72
+ }
73
+ }
74
+ catch (e_2_1) { e_2 = { error: e_2_1 }; }
75
+ finally {
76
+ try {
77
+ if (scope_1_1 && !scope_1_1.done && (_b = scope_1.return)) _b.call(scope_1);
78
+ }
79
+ finally { if (e_2) throw e_2.error; }
80
+ }
81
+ }
82
+ else if (scope === 'all') {
83
+ selectedColumns = sourceColumns && sourceColumns.length > 0 ? __spreadArray([], __read(sourceColumns), false) : __spreadArray([], __read(columns), false);
84
+ }
85
+ else {
86
+ // 'visible'
87
+ selectedColumns = __spreadArray([], __read(columns), false);
88
+ }
89
+ var exportableColumns = selectedColumns.filter(function (col) { return col.exportable !== false; });
90
+ return exportableColumns.map(function (column, columnIndex) {
91
+ var columnId = (0, getColumnId_1.getColumnId)(column);
92
+ var header;
93
+ if (typeof column.exportHeader === 'function') {
94
+ header = column.exportHeader(column);
95
+ }
96
+ else if (typeof column.exportHeader === 'string') {
97
+ header = column.exportHeader;
98
+ }
99
+ else if (typeof column.label === 'string' || typeof column.label === 'number') {
100
+ header = String(column.label);
101
+ }
102
+ else {
103
+ header = columnId;
104
+ }
105
+ return {
106
+ columnId: columnId,
107
+ header: header,
108
+ column: column,
109
+ columnIndex: columnIndex,
110
+ };
111
+ });
112
+ }
113
+ function resolveExportRows(exportColumns, params) {
114
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
115
+ var rowScope = (_b = (_a = params.options) === null || _a === void 0 ? void 0 : _a.rows) !== null && _b !== void 0 ? _b : 'displayed';
116
+ var rows = [];
117
+ var sourcePool = params.sourceData && params.sourceData.length > 0 ? params.sourceData : params.data;
118
+ var buildCells = function (item, values, sourceIndex, visibleIndex) {
119
+ var e_3, _a;
120
+ var cells = [];
121
+ try {
122
+ for (var exportColumns_1 = __values(exportColumns), exportColumns_1_1 = exportColumns_1.next(); !exportColumns_1_1.done; exportColumns_1_1 = exportColumns_1.next()) {
123
+ var expCol = exportColumns_1_1.value;
124
+ var rawValue = (0, getCellValue_1.getCellValueByRowKey)(expCol.column.key, values);
125
+ if (expCol.column.getExportValue) {
126
+ cells.push(expCol.column.getExportValue({
127
+ column: expCol.column,
128
+ columnId: expCol.columnId,
129
+ visibleIndex: visibleIndex,
130
+ sourceIndex: sourceIndex,
131
+ item: item,
132
+ values: values,
133
+ value: rawValue,
134
+ }));
135
+ }
136
+ else {
137
+ cells.push(rawValue);
138
+ }
139
+ }
140
+ }
141
+ catch (e_3_1) { e_3 = { error: e_3_1 }; }
142
+ finally {
143
+ try {
144
+ if (exportColumns_1_1 && !exportColumns_1_1.done && (_a = exportColumns_1.return)) _a.call(exportColumns_1);
145
+ }
146
+ finally { if (e_3) throw e_3.error; }
147
+ }
148
+ return cells;
149
+ };
150
+ var resolveRowKey = function (item, values) {
151
+ var rowKey;
152
+ if (params.rowKey !== undefined && values) {
153
+ var rawKey = (0, getCellValue_1.getCellValueByRowKey)(params.rowKey, values);
154
+ if (rawKey !== undefined && rawKey !== null) {
155
+ rowKey = rawKey;
156
+ }
157
+ }
158
+ if (rowKey === undefined && (item === null || item === void 0 ? void 0 : item.key) !== undefined) {
159
+ rowKey = item.key;
160
+ }
161
+ return rowKey;
162
+ };
163
+ if (rowScope === 'displayed') {
164
+ var displayData = params.data;
165
+ for (var visibleIndex = 0; visibleIndex < displayData.length; visibleIndex++) {
166
+ var item = (_c = displayData[visibleIndex]) !== null && _c !== void 0 ? _c : { values: {} };
167
+ var sourceIndex = (_e = (_d = params.sourceIndexByVisibleIndex) === null || _d === void 0 ? void 0 : _d[visibleIndex]) !== null && _e !== void 0 ? _e : visibleIndex;
168
+ var values = (_f = item.values) !== null && _f !== void 0 ? _f : {};
169
+ var rowKey = resolveRowKey(item, values);
170
+ var cells = buildCells(item, values, sourceIndex, visibleIndex);
171
+ rows.push({
172
+ visibleIndex: visibleIndex,
173
+ sourceIndex: sourceIndex,
174
+ rowKey: rowKey,
175
+ item: item,
176
+ values: values,
177
+ cells: cells,
178
+ });
179
+ }
180
+ }
181
+ else if (rowScope === 'checked') {
182
+ var checkedMap = params.checkedIndexesMap;
183
+ for (var sourceIndex = 0; sourceIndex < sourcePool.length; sourceIndex++) {
184
+ if (!(checkedMap === null || checkedMap === void 0 ? void 0 : checkedMap.has(sourceIndex)))
185
+ continue;
186
+ var item = (_g = sourcePool[sourceIndex]) !== null && _g !== void 0 ? _g : { values: {} };
187
+ var visibleIndex = (_h = params.visibleIndexBySourceIndex) === null || _h === void 0 ? void 0 : _h.get(sourceIndex);
188
+ var values = (_j = item.values) !== null && _j !== void 0 ? _j : {};
189
+ var rowKey = resolveRowKey(item, values);
190
+ var cells = buildCells(item, values, sourceIndex, visibleIndex);
191
+ rows.push({
192
+ visibleIndex: visibleIndex,
193
+ sourceIndex: sourceIndex,
194
+ rowKey: rowKey,
195
+ item: item,
196
+ values: values,
197
+ cells: cells,
198
+ });
199
+ }
200
+ }
201
+ else {
202
+ // 'source'
203
+ for (var sourceIndex = 0; sourceIndex < sourcePool.length; sourceIndex++) {
204
+ var item = (_k = sourcePool[sourceIndex]) !== null && _k !== void 0 ? _k : { values: {} };
205
+ var visibleIndex = (_l = params.visibleIndexBySourceIndex) === null || _l === void 0 ? void 0 : _l.get(sourceIndex);
206
+ var values = (_m = item.values) !== null && _m !== void 0 ? _m : {};
207
+ var rowKey = resolveRowKey(item, values);
208
+ var cells = buildCells(item, values, sourceIndex, visibleIndex);
209
+ rows.push({
210
+ visibleIndex: visibleIndex,
211
+ sourceIndex: sourceIndex,
212
+ rowKey: rowKey,
213
+ item: item,
214
+ values: values,
215
+ cells: cells,
216
+ });
217
+ }
218
+ }
219
+ return rows;
220
+ }
221
+ function createGridExportData(params) {
222
+ var _a, _b;
223
+ var columnScope = (_b = (_a = params.options) === null || _a === void 0 ? void 0 : _a.columns) !== null && _b !== void 0 ? _b : 'visible';
224
+ var columns = resolveExportColumns(params.columns, params.sourceColumns, columnScope);
225
+ var rows = resolveExportRows(columns, params);
226
+ return {
227
+ columns: columns,
228
+ rows: rows,
229
+ };
230
+ }
@@ -0,0 +1,317 @@
1
+ "use strict";
2
+ var __values = (this && this.__values) || function(o) {
3
+ var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
4
+ if (m) return m.call(o);
5
+ if (o && typeof o.length === "number") return {
6
+ next: function () {
7
+ if (o && i >= o.length) o = void 0;
8
+ return { value: o && o[i++], done: !o };
9
+ }
10
+ };
11
+ throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
12
+ };
13
+ Object.defineProperty(exports, "__esModule", { value: true });
14
+ exports.escapeXml = escapeXml;
15
+ exports.colIndexToExcelColumn = colIndexToExcelColumn;
16
+ exports.serializeGridExportDataToExcel = serializeGridExportDataToExcel;
17
+ exports.downloadExcel = downloadExcel;
18
+ function makeCrc32Table() {
19
+ var table = new Uint32Array(256);
20
+ for (var i = 0; i < 256; i++) {
21
+ var c = i;
22
+ for (var k = 0; k < 8; k++) {
23
+ c = (c & 1) ? (0xedb88320 ^ (c >>> 1)) : (c >>> 1);
24
+ }
25
+ table[i] = c;
26
+ }
27
+ return table;
28
+ }
29
+ var crcTable = makeCrc32Table();
30
+ function calculateCrc32(bytes) {
31
+ var crc = 0xffffffff;
32
+ for (var i = 0; i < bytes.length; i++) {
33
+ crc = (crc >>> 8) ^ crcTable[(crc ^ bytes[i]) & 0xff];
34
+ }
35
+ return (crc ^ 0xffffffff) >>> 0;
36
+ }
37
+ function escapeXml(value) {
38
+ return value
39
+ .replace(/&/g, '&amp;')
40
+ .replace(/</g, '&lt;')
41
+ .replace(/>/g, '&gt;')
42
+ .replace(/"/g, '&quot;')
43
+ .replace(/'/g, '&apos;')
44
+ .replace(/[\x00-\x08\x0b\x0c\x0e-\x1f]/g, '');
45
+ }
46
+ function colIndexToExcelColumn(colIndex) {
47
+ var name = '';
48
+ var n = colIndex;
49
+ while (n >= 0) {
50
+ name = String.fromCharCode((n % 26) + 65) + name;
51
+ n = Math.floor(n / 26) - 1;
52
+ }
53
+ return name;
54
+ }
55
+ function createZipArchive(files) {
56
+ var e_1, _a, e_2, _b, e_3, _c, e_4, _d;
57
+ var encoder = new TextEncoder();
58
+ var fileEntries = [];
59
+ var offset = 0;
60
+ try {
61
+ for (var files_1 = __values(files), files_1_1 = files_1.next(); !files_1_1.done; files_1_1 = files_1.next()) {
62
+ var file = files_1_1.value;
63
+ var nameBytes = encoder.encode(file.name);
64
+ var dataBytes = typeof file.data === 'string' ? encoder.encode(file.data) : file.data;
65
+ var crc = calculateCrc32(dataBytes);
66
+ var localHeader = new Uint8Array(30 + nameBytes.length);
67
+ var dv = new DataView(localHeader.buffer);
68
+ dv.setUint32(0, 0x04034b50, true); // Local file header signature
69
+ dv.setUint16(4, 20, true); // Version needed to extract (2.0)
70
+ dv.setUint16(6, 0x0800, true); // Bit flag: UTF-8 filename (bit 11)
71
+ dv.setUint16(8, 0, true); // Compression method: STORE (0)
72
+ dv.setUint16(10, 0, true); // File last mod time
73
+ dv.setUint16(12, 0, true); // File last mod date
74
+ dv.setUint32(14, crc, true); // CRC-32
75
+ dv.setUint32(18, dataBytes.length, true); // Compressed size
76
+ dv.setUint32(22, dataBytes.length, true); // Uncompressed size
77
+ dv.setUint16(26, nameBytes.length, true); // Filename length
78
+ dv.setUint16(28, 0, true); // Extra field length
79
+ localHeader.set(nameBytes, 30);
80
+ fileEntries.push({
81
+ nameBytes: nameBytes,
82
+ dataBytes: dataBytes,
83
+ crc: crc,
84
+ localHeader: localHeader,
85
+ offset: offset,
86
+ });
87
+ offset += localHeader.length + dataBytes.length;
88
+ }
89
+ }
90
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
91
+ finally {
92
+ try {
93
+ if (files_1_1 && !files_1_1.done && (_a = files_1.return)) _a.call(files_1);
94
+ }
95
+ finally { if (e_1) throw e_1.error; }
96
+ }
97
+ var centralDirEntries = [];
98
+ var centralDirSize = 0;
99
+ try {
100
+ for (var fileEntries_1 = __values(fileEntries), fileEntries_1_1 = fileEntries_1.next(); !fileEntries_1_1.done; fileEntries_1_1 = fileEntries_1.next()) {
101
+ var entry = fileEntries_1_1.value;
102
+ var cd = new Uint8Array(46 + entry.nameBytes.length);
103
+ var dv = new DataView(cd.buffer);
104
+ dv.setUint32(0, 0x02014b50, true); // Central file header signature
105
+ dv.setUint16(4, 20, true); // Version made by
106
+ dv.setUint16(6, 20, true); // Version needed to extract
107
+ dv.setUint16(8, 0x0800, true); // Bit flag: UTF-8
108
+ dv.setUint16(10, 0, true); // Compression method: STORE
109
+ dv.setUint16(12, 0, true); // File last mod time
110
+ dv.setUint16(14, 0, true); // File last mod date
111
+ dv.setUint32(16, entry.crc, true); // CRC-32
112
+ dv.setUint32(20, entry.dataBytes.length, true); // Compressed size
113
+ dv.setUint32(24, entry.dataBytes.length, true); // Uncompressed size
114
+ dv.setUint16(28, entry.nameBytes.length, true); // Filename length
115
+ dv.setUint16(30, 0, true); // Extra field length
116
+ dv.setUint16(32, 0, true); // File comment length
117
+ dv.setUint16(34, 0, true); // Disk number start
118
+ dv.setUint16(36, 0, true); // Internal file attributes
119
+ dv.setUint32(38, 0, true); // External file attributes
120
+ dv.setUint32(42, entry.offset, true); // Relative offset of local header
121
+ cd.set(entry.nameBytes, 46);
122
+ centralDirEntries.push(cd);
123
+ centralDirSize += cd.length;
124
+ }
125
+ }
126
+ catch (e_2_1) { e_2 = { error: e_2_1 }; }
127
+ finally {
128
+ try {
129
+ if (fileEntries_1_1 && !fileEntries_1_1.done && (_b = fileEntries_1.return)) _b.call(fileEntries_1);
130
+ }
131
+ finally { if (e_2) throw e_2.error; }
132
+ }
133
+ var eocd = new Uint8Array(22);
134
+ var dvEocd = new DataView(eocd.buffer);
135
+ dvEocd.setUint32(0, 0x06054b50, true); // End of central dir signature
136
+ dvEocd.setUint16(4, 0, true); // Number of this disk
137
+ dvEocd.setUint16(6, 0, true); // Number of disk with start of central directory
138
+ dvEocd.setUint16(8, fileEntries.length, true); // Total entries in this disk
139
+ dvEocd.setUint16(10, fileEntries.length, true); // Total entries
140
+ dvEocd.setUint32(12, centralDirSize, true); // Size of the central directory
141
+ dvEocd.setUint32(16, offset, true); // Offset of start of central directory
142
+ dvEocd.setUint16(20, 0, true); // ZIP file comment length
143
+ var totalLength = offset + centralDirSize + 22;
144
+ var result = new Uint8Array(totalLength);
145
+ var pos = 0;
146
+ try {
147
+ for (var fileEntries_2 = __values(fileEntries), fileEntries_2_1 = fileEntries_2.next(); !fileEntries_2_1.done; fileEntries_2_1 = fileEntries_2.next()) {
148
+ var entry = fileEntries_2_1.value;
149
+ result.set(entry.localHeader, pos);
150
+ pos += entry.localHeader.length;
151
+ result.set(entry.dataBytes, pos);
152
+ pos += entry.dataBytes.length;
153
+ }
154
+ }
155
+ catch (e_3_1) { e_3 = { error: e_3_1 }; }
156
+ finally {
157
+ try {
158
+ if (fileEntries_2_1 && !fileEntries_2_1.done && (_c = fileEntries_2.return)) _c.call(fileEntries_2);
159
+ }
160
+ finally { if (e_3) throw e_3.error; }
161
+ }
162
+ try {
163
+ for (var centralDirEntries_1 = __values(centralDirEntries), centralDirEntries_1_1 = centralDirEntries_1.next(); !centralDirEntries_1_1.done; centralDirEntries_1_1 = centralDirEntries_1.next()) {
164
+ var cd = centralDirEntries_1_1.value;
165
+ result.set(cd, pos);
166
+ pos += cd.length;
167
+ }
168
+ }
169
+ catch (e_4_1) { e_4 = { error: e_4_1 }; }
170
+ finally {
171
+ try {
172
+ if (centralDirEntries_1_1 && !centralDirEntries_1_1.done && (_d = centralDirEntries_1.return)) _d.call(centralDirEntries_1);
173
+ }
174
+ finally { if (e_4) throw e_4.error; }
175
+ }
176
+ result.set(eocd, pos);
177
+ return result;
178
+ }
179
+ function formatCellValueAsXml(cellValue, cellRef) {
180
+ if (cellValue === null || cellValue === undefined || cellValue === '') {
181
+ return "<c r=\"".concat(cellRef, "\"/>");
182
+ }
183
+ if (typeof cellValue === 'number') {
184
+ if (Number.isFinite(cellValue)) {
185
+ return "<c r=\"".concat(cellRef, "\"><v>").concat(cellValue, "</v></c>");
186
+ }
187
+ return "<c r=\"".concat(cellRef, "\" t=\"inlineStr\"><is><t>").concat(escapeXml(String(cellValue)), "</t></is></c>");
188
+ }
189
+ if (typeof cellValue === 'boolean') {
190
+ return "<c r=\"".concat(cellRef, "\" t=\"b\"><v>").concat(cellValue ? 1 : 0, "</v></c>");
191
+ }
192
+ if (typeof cellValue === 'bigint') {
193
+ return "<c r=\"".concat(cellRef, "\" t=\"inlineStr\"><is><t>").concat(cellValue.toString(), "</t></is></c>");
194
+ }
195
+ if (cellValue instanceof Date) {
196
+ var dateStr = Number.isNaN(cellValue.getTime()) ? 'Invalid Date' : cellValue.toISOString();
197
+ return "<c r=\"".concat(cellRef, "\" t=\"inlineStr\"><is><t>").concat(escapeXml(dateStr), "</t></is></c>");
198
+ }
199
+ var text;
200
+ if (typeof cellValue === 'object') {
201
+ try {
202
+ text = JSON.stringify(cellValue);
203
+ }
204
+ catch (_a) {
205
+ text = String(cellValue);
206
+ }
207
+ }
208
+ else {
209
+ text = String(cellValue);
210
+ }
211
+ return "<c r=\"".concat(cellRef, "\" t=\"inlineStr\"><is><t xml:space=\"preserve\">").concat(escapeXml(text), "</t></is></c>");
212
+ }
213
+ function serializeGridExportDataToExcel(data, options) {
214
+ var e_5, _a;
215
+ var _b;
216
+ var includeHeader = (_b = options === null || options === void 0 ? void 0 : options.includeHeader) !== null && _b !== void 0 ? _b : true;
217
+ var rawSheetName = ((options === null || options === void 0 ? void 0 : options.sheetName) || 'Sheet1').trim().replace(/[:\\/?*\[\]]/g, '');
218
+ if (!rawSheetName) {
219
+ rawSheetName = 'Sheet1';
220
+ }
221
+ else if (rawSheetName.length > 31) {
222
+ rawSheetName = rawSheetName.slice(0, 31);
223
+ }
224
+ var sheetRows = [];
225
+ var rowIndex = 1;
226
+ if (includeHeader) {
227
+ var headerCells = data.columns
228
+ .map(function (col, colIdx) {
229
+ var cellRef = "".concat(colIndexToExcelColumn(colIdx)).concat(rowIndex);
230
+ return formatCellValueAsXml(col.header, cellRef);
231
+ })
232
+ .join('');
233
+ sheetRows.push("<row r=\"".concat(rowIndex, "\">").concat(headerCells, "</row>"));
234
+ rowIndex++;
235
+ }
236
+ try {
237
+ for (var _c = __values(data.rows), _d = _c.next(); !_d.done; _d = _c.next()) {
238
+ var row = _d.value;
239
+ var rowCells = row.cells
240
+ .map(function (cell, colIdx) {
241
+ var cellRef = "".concat(colIndexToExcelColumn(colIdx)).concat(rowIndex);
242
+ return formatCellValueAsXml(cell, cellRef);
243
+ })
244
+ .join('');
245
+ sheetRows.push("<row r=\"".concat(rowIndex, "\">").concat(rowCells, "</row>"));
246
+ rowIndex++;
247
+ }
248
+ }
249
+ catch (e_5_1) { e_5 = { error: e_5_1 }; }
250
+ finally {
251
+ try {
252
+ if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
253
+ }
254
+ finally { if (e_5) throw e_5.error; }
255
+ }
256
+ var contentTypesXml = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>\n' +
257
+ '<Types xmlns="http://schemas.openxmlformats.org/package/2006/content-types">' +
258
+ '<Default Extension="rels" ContentType="application/vnd.openxmlformats-package.relationships+xml"/>' +
259
+ '<Default Extension="xml" ContentType="application/xml"/>' +
260
+ '<Override PartName="/xl/workbook.xml" ContentType="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet.main+xml"/>' +
261
+ '<Override PartName="/xl/worksheets/sheet1.xml" ContentType="application/vnd.openxmlformats-officedocument.spreadsheetml.worksheet+xml"/>' +
262
+ '</Types>';
263
+ var rootRelsXml = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>\n' +
264
+ '<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">' +
265
+ '<Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument" Target="xl/workbook.xml"/>' +
266
+ '</Relationships>';
267
+ var workbookRelsXml = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>\n' +
268
+ '<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">' +
269
+ '<Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/worksheet" Target="worksheets/sheet1.xml"/>' +
270
+ '</Relationships>';
271
+ var workbookXml = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>\n' +
272
+ '<workbook xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships">' +
273
+ "<sheets><sheet name=\"".concat(escapeXml(rawSheetName), "\" sheetId=\"1\" r:id=\"rId1\"/></sheets>") +
274
+ '</workbook>';
275
+ var worksheetXml = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>\n' +
276
+ '<worksheet xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main">' +
277
+ "<sheetData>".concat(sheetRows.join(''), "</sheetData>") +
278
+ '</worksheet>';
279
+ return createZipArchive([
280
+ { name: '[Content_Types].xml', data: contentTypesXml },
281
+ { name: '_rels/.rels', data: rootRelsXml },
282
+ { name: 'xl/_rels/workbook.xml.rels', data: workbookRelsXml },
283
+ { name: 'xl/workbook.xml', data: workbookXml },
284
+ { name: 'xl/worksheets/sheet1.xml', data: worksheetXml },
285
+ ]);
286
+ }
287
+ function downloadExcel(blobOrBytes, fileName) {
288
+ if (fileName === void 0) { fileName = 'export.xlsx'; }
289
+ if (typeof window === 'undefined' || typeof document === 'undefined') {
290
+ return;
291
+ }
292
+ var resolvedName = (fileName || '').trim();
293
+ if (!resolvedName) {
294
+ resolvedName = 'export.xlsx';
295
+ }
296
+ else if (!resolvedName.toLowerCase().endsWith('.xlsx')) {
297
+ resolvedName += '.xlsx';
298
+ }
299
+ var blob = blobOrBytes instanceof Blob
300
+ ? blobOrBytes
301
+ : new Blob([blobOrBytes], {
302
+ type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
303
+ });
304
+ if (typeof URL !== 'undefined' && typeof URL.createObjectURL === 'function') {
305
+ var url = URL.createObjectURL(blob);
306
+ var link = document.createElement('a');
307
+ link.href = url;
308
+ link.setAttribute('download', resolvedName);
309
+ link.style.display = 'none';
310
+ document.body.appendChild(link);
311
+ link.click();
312
+ document.body.removeChild(link);
313
+ if (typeof URL.revokeObjectURL === 'function') {
314
+ URL.revokeObjectURL(url);
315
+ }
316
+ }
317
+ }