@fileverse-dev/dsheet 4.1.8 → 4.1.9-cmt

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 (34) hide show
  1. package/dist/editor/components/export-menu-section.d.ts +2 -1
  2. package/dist/editor/components/import-button-ui.d.ts +3 -1
  3. package/dist/editor/components/read-only-export-button.d.ts +1 -1
  4. package/dist/editor/hooks/use-homepage-redirect.d.ts +2 -1
  5. package/dist/editor/hooks/use-xlsx-import.d.ts +4 -2
  6. package/dist/editor/utils/custom-toolbar-item.d.ts +5 -2
  7. package/dist/editor/utils/ods-export-sanitize.d.ts +9 -0
  8. package/dist/editor/utils/ods-export-sanitize.test.d.ts +1 -0
  9. package/dist/editor/utils/ods-to-xlsx.d.ts +6 -0
  10. package/dist/editor/utils/spreadsheet-import.d.ts +1 -1
  11. package/dist/editor/utils/xlsx-export-impl.d.ts +1 -0
  12. package/dist/editor/utils/xlsx-export.d.ts +1 -0
  13. package/dist/{es-BonrkVxY.js → es-yR2JIXsz.js} +8 -2
  14. package/dist/{executeStringFunction-V_hu5VRM.js → executeStringFunction-DMMvpc-I.js} +1385 -1374
  15. package/dist/formula.js +1 -1
  16. package/dist/{hi-Ca55EZ4A.js → hi-DRcLnrnZ.js} +8 -2
  17. package/dist/{index-GBqDuF2T.js → index-D-LWXwhT.js} +9657 -9505
  18. package/dist/index.d.ts +1 -1
  19. package/dist/index.es.js +44 -43
  20. package/dist/ods-to-xlsx-DeJAYBkD.js +19 -0
  21. package/dist/sheet-engine/core/locale/en.d.ts +1 -0
  22. package/dist/sheet-engine/core/locale/es.d.ts +1 -0
  23. package/dist/sheet-engine/core/locale/hi.d.ts +1 -0
  24. package/dist/sheet-engine/core/locale/zh.d.ts +1 -0
  25. package/dist/sheet-engine/core/locale/zh_tw.d.ts +1 -0
  26. package/dist/style.css +1 -1
  27. package/dist/{use-xlsx-import-impl-CkHRRbtb.js → use-xlsx-import-impl-D5I9O2H5.js} +4 -4
  28. package/dist/{xlsx-defined-names-CBoWA_1s.js → xlsx-defined-names--Q1w2nN5.js} +2 -2
  29. package/dist/xlsx-export-impl-s13TyH01.js +880 -0
  30. package/dist/{xlsx-hyperlink-inline-CY7B4A0C.js → xlsx-hyperlink-inline-lfx1jg1v.js} +2 -2
  31. package/dist/{zh-BfQYzoDQ.js → zh-B1KUs68q.js} +4 -2
  32. package/dist/{zh_tw-CINWHD2H.js → zh_tw-B9_7WgLO.js} +4 -2
  33. package/package.json +3 -2
  34. package/dist/xlsx-export-impl-YSSLVP-V.js +0 -835
@@ -1,835 +0,0 @@
1
- import { utils as F, write as it } from "xlsx-js-style";
2
- import { Workbook as ct } from "exceljs";
3
- import { toast as nt } from "@fileverse/ui";
4
- import { J as ft, c as X, g as ut, a as pt } from "./xlsx-hyperlink-inline-CY7B4A0C.js";
5
- import { b as dt } from "./executeStringFunction-V_hu5VRM.js";
6
- import { e as ht } from "./index-GBqDuF2T.js";
7
- const mt = {
8
- 1: "thin",
9
- 2: "hair",
10
- 3: "dotted",
11
- 4: "dashed",
12
- 5: "dashDot",
13
- 6: "dashDotDot",
14
- 7: "double",
15
- 8: "medium",
16
- 9: "mediumDashed",
17
- 10: "mediumDashDot",
18
- 11: "mediumDashDotDot",
19
- 12: "slantDashDot",
20
- 13: "thick"
21
- }, gt = (e) => {
22
- if (typeof e != "string") return "000000";
23
- const o = e.replace("#", "").toUpperCase();
24
- return o.length === 3 ? o.replace(/(.)/g, "$1$1") : o.length === 6 ? o : "000000";
25
- }, q = (e, o) => {
26
- const t = Number(e);
27
- if (t)
28
- return {
29
- style: mt[t] ?? "thin",
30
- color: { rgb: gt(o) }
31
- };
32
- }, I = (e, o, t, r, n) => {
33
- if (!n || !r.l && !r.r && !r.t && !r.b) return;
34
- const l = F.encode_cell({ r: o, c: t }), i = {
35
- ...e[l] || { t: "z" }
36
- }, u = { ...i.s || {} }, d = { ...u.border || {} };
37
- r.l && (d.left = n), r.r && (d.right = n), r.t && (d.top = n), r.b && (d.bottom = n), u.border = d, i.s = u, e[l] = i;
38
- }, xt = (e, o) => {
39
- o.forEach((t) => {
40
- if (t.rangeType === "cell") {
41
- if (!t.value) return;
42
- const { row_index: r, col_index: n } = t.value;
43
- if (r == null || n == null) return;
44
- const l = t.value, i = F.encode_cell({ r, c: n }), u = {
45
- ...e[i] || { t: "z" }
46
- }, d = { ...u.s || {} }, a = { ...d.border || {} };
47
- l.l && (a.left = q(l.l.style, l.l.color)), l.r && (a.right = q(l.r.style, l.r.color)), l.t && (a.top = q(l.t.style, l.t.color)), l.b && (a.bottom = q(l.b.style, l.b.color)), d.border = a, u.s = d, e[i] = u;
48
- } else if (t.rangeType === "range") {
49
- const { borderType: r, style: n, color: l, range: i } = t;
50
- if (r === "border-none" || !Array.isArray(i) || !n)
51
- return;
52
- const u = q(n, l);
53
- if (!u) return;
54
- i.forEach((d) => {
55
- const [a, T] = d.row, [w, k] = d.column;
56
- for (let C = a; C <= T; C++)
57
- for (let x = w; x <= k; x++)
58
- switch (r) {
59
- case "border-all":
60
- I(
61
- e,
62
- C,
63
- x,
64
- { l: !0, r: !0, t: !0, b: !0 },
65
- u
66
- );
67
- break;
68
- case "border-outside":
69
- I(
70
- e,
71
- C,
72
- x,
73
- { l: x === w, r: x === k, t: C === a, b: C === T },
74
- u
75
- );
76
- break;
77
- case "border-inside":
78
- I(
79
- e,
80
- C,
81
- x,
82
- { r: x < k, b: C < T },
83
- u
84
- );
85
- break;
86
- case "border-horizontal":
87
- I(e, C, x, { b: C < T }, u);
88
- break;
89
- case "border-vertical":
90
- I(e, C, x, { r: x < k }, u);
91
- break;
92
- case "border-left":
93
- x === w && I(e, C, x, { l: !0 }, u);
94
- break;
95
- case "border-right":
96
- x === k && I(e, C, x, { r: !0 }, u);
97
- break;
98
- case "border-top":
99
- C === a && I(e, C, x, { t: !0 }, u);
100
- break;
101
- case "border-bottom":
102
- C === T && I(e, C, x, { b: !0 }, u);
103
- break;
104
- }
105
- });
106
- }
107
- });
108
- };
109
- function G(e) {
110
- if (!e || typeof e != "string") return null;
111
- const o = e.trim();
112
- if (o.startsWith("#")) {
113
- const r = o.replace("#", "").toUpperCase();
114
- return r.length === 3 ? "FF" + r.split("").map((n) => n + n).join("") : r.length === 6 ? "FF" + r : null;
115
- }
116
- const t = o.match(/rgba?\s*\(\s*([\d.]+)[,\s]+([\d.]+)[,\s]+([\d.]+)/i);
117
- if (t) {
118
- const r = (n) => Math.min(255, Math.max(0, Math.round(n))).toString(16).padStart(2, "0").toUpperCase();
119
- return "FF" + r(parseFloat(t[1])) + r(parseFloat(t[2])) + r(parseFloat(t[3]));
120
- }
121
- return null;
122
- }
123
- function bt(e) {
124
- const o = {}, t = {};
125
- if (e.textColor && e.textColor.toLowerCase() !== "#000000") {
126
- const n = G(e.textColor);
127
- n && (t.color = { argb: n });
128
- }
129
- e.bold && (t.bold = !0), e.italic && (t.italic = !0), e.underline && (t.underline = !0), e.strikethrough && (t.strike = !0), Object.keys(t).length > 0 && (o.font = t);
130
- const r = e.cellColor;
131
- if (r && r.toLowerCase() !== "#ffffff") {
132
- const n = G(r);
133
- n && (o.fill = { type: "pattern", pattern: "solid", fgColor: { argb: n } });
134
- }
135
- return o;
136
- }
137
- function yt(e) {
138
- return !Array.isArray(e) || e.length === 0 ? "" : e.map((t) => {
139
- const [r, n] = t.row, [l, i] = t.column, u = F.encode_cell({ r, c: l }), d = F.encode_cell({ r: n, c: i });
140
- return u === d ? u : `${u}:${d}`;
141
- }).filter(Boolean).join(" ");
142
- }
143
- function Ct(e, o, t) {
144
- const { conditionName: r, conditionValue: n = [], format: l = {} } = e, i = bt(l), u = (a) => a.replace(/"/g, '""'), d = o.split(/[\s:]/)[0];
145
- switch (r) {
146
- case "greaterThan":
147
- case "greaterThanOrEqual":
148
- case "lessThan":
149
- case "lessThanOrEqual":
150
- case "equal":
151
- return n[0] ? {
152
- type: "cellIs",
153
- operator: r,
154
- formulae: [n[0]],
155
- priority: t,
156
- style: i
157
- } : null;
158
- case "notEqual":
159
- return n[0] ? {
160
- type: "cellIs",
161
- operator: "notEqual",
162
- formulae: [n[0]],
163
- priority: t,
164
- style: i
165
- } : null;
166
- case "between":
167
- return n.length < 2 ? null : {
168
- type: "cellIs",
169
- operator: "between",
170
- formulae: [n[0], n[1]],
171
- priority: t,
172
- style: i
173
- };
174
- case "notBetween":
175
- return n.length < 2 ? null : {
176
- type: "cellIs",
177
- operator: "notBetween",
178
- formulae: [n[0], n[1]],
179
- priority: t,
180
- style: i
181
- };
182
- case "textContains": {
183
- if (!n[0]) return null;
184
- const a = n[0];
185
- return {
186
- type: "containsText",
187
- operator: "containsText",
188
- text: a,
189
- formulae: [
190
- `NOT(ISERROR(SEARCH("${u(a)}",${d})))`
191
- ],
192
- priority: t,
193
- style: i
194
- };
195
- }
196
- case "containsText": {
197
- if (!n[0]) return null;
198
- const a = n[0];
199
- return {
200
- type: "containsText",
201
- operator: "containsText",
202
- text: a,
203
- formulae: [
204
- `NOT(ISERROR(SEARCH("${u(a)}",${d})))`
205
- ],
206
- priority: t,
207
- style: i
208
- };
209
- }
210
- case "textDoesNotContain": {
211
- if (!n[0]) return null;
212
- const a = n[0];
213
- return {
214
- type: "notContainsText",
215
- operator: "notContainsText",
216
- text: a,
217
- formulae: [`ISERROR(SEARCH("${u(a)}",${d}))`],
218
- priority: t,
219
- style: i
220
- };
221
- }
222
- case "notContainsText":
223
- case "notContains": {
224
- if (!n[0]) return null;
225
- const a = n[0];
226
- return {
227
- type: "notContainsText",
228
- operator: "notContainsText",
229
- text: a,
230
- formulae: [`ISERROR(SEARCH("${u(a)}",${d}))`],
231
- priority: t,
232
- style: i
233
- };
234
- }
235
- case "textStartsWith": {
236
- if (!n[0]) return null;
237
- const a = n[0];
238
- return {
239
- type: "beginsWith",
240
- operator: "beginsWith",
241
- text: a,
242
- formulae: [
243
- `LEFT(${d},${a.length})="${u(a)}"`
244
- ],
245
- priority: t,
246
- style: i
247
- };
248
- }
249
- case "beginsWith": {
250
- if (!n[0]) return null;
251
- const a = n[0];
252
- return {
253
- type: "beginsWith",
254
- operator: "beginsWith",
255
- text: a,
256
- formulae: [
257
- `LEFT(${d},${a.length})="${u(a)}"`
258
- ],
259
- priority: t,
260
- style: i
261
- };
262
- }
263
- case "textEndsWith": {
264
- if (!n[0]) return null;
265
- const a = n[0];
266
- return {
267
- type: "endsWith",
268
- operator: "endsWith",
269
- text: a,
270
- formulae: [
271
- `RIGHT(${d},${a.length})="${u(a)}"`
272
- ],
273
- priority: t,
274
- style: i
275
- };
276
- }
277
- case "endsWith": {
278
- if (!n[0]) return null;
279
- const a = n[0];
280
- return {
281
- type: "endsWith",
282
- operator: "endsWith",
283
- text: a,
284
- formulae: [
285
- `RIGHT(${d},${a.length})="${u(a)}"`
286
- ],
287
- priority: t,
288
- style: i
289
- };
290
- }
291
- case "textExactly": {
292
- if (!n[0]) return null;
293
- const a = n[0];
294
- return {
295
- // Keep this in the text-rule family so Google/OOXML readers preserve it
296
- // similarly to other text CF rules.
297
- type: "containsText",
298
- operator: "equal",
299
- text: a,
300
- formulae: [`EXACT(${d},"${u(a)}")`],
301
- priority: t,
302
- style: i
303
- };
304
- }
305
- case "empty":
306
- return {
307
- type: "containsText",
308
- operator: "containsBlanks",
309
- formulae: [`LEN(TRIM(${d}))=0`],
310
- priority: t,
311
- style: i
312
- };
313
- case "containsBlanks":
314
- return {
315
- type: "containsText",
316
- operator: "containsBlanks",
317
- formulae: [`LEN(TRIM(${d}))=0`],
318
- priority: t,
319
- style: i
320
- };
321
- case "notEmpty":
322
- return {
323
- type: "containsText",
324
- operator: "notContainsBlanks",
325
- formulae: [`LEN(TRIM(${d}))>0`],
326
- priority: t,
327
- style: i
328
- };
329
- case "notContainsBlanks":
330
- return {
331
- type: "containsText",
332
- operator: "notContainsBlanks",
333
- formulae: [`LEN(TRIM(${d}))>0`],
334
- priority: t,
335
- style: i
336
- };
337
- case "top10":
338
- return {
339
- type: "top10",
340
- rank: parseInt(n[0] || "10", 10) || 10,
341
- percent: !1,
342
- bottom: !1,
343
- priority: t,
344
- style: i
345
- };
346
- case "top10Percent":
347
- case "top10_percent":
348
- return {
349
- type: "top10",
350
- rank: parseInt(n[0] || "10", 10) || 10,
351
- percent: !0,
352
- bottom: !1,
353
- priority: t,
354
- style: i
355
- };
356
- case "last10":
357
- return {
358
- type: "top10",
359
- rank: parseInt(n[0] || "10", 10) || 10,
360
- percent: !1,
361
- bottom: !0,
362
- priority: t,
363
- style: i
364
- };
365
- case "last10Percent":
366
- case "last10_percent":
367
- return {
368
- type: "top10",
369
- rank: parseInt(n[0] || "10", 10) || 10,
370
- percent: !0,
371
- bottom: !0,
372
- priority: t,
373
- style: i
374
- };
375
- case "aboveAverage":
376
- return { type: "aboveAverage", aboveAverage: !0, priority: t, style: i };
377
- case "belowAverage":
378
- return { type: "aboveAverage", aboveAverage: !1, priority: t, style: i };
379
- case "date":
380
- case "dateIs":
381
- case "dateBefore":
382
- case "dateAfter": {
383
- const a = String(n[0] ?? ""), T = a.startsWith("preset:") ? a.slice(7) : a.toLowerCase();
384
- return T === "today" || T === "tomorrow" || T === "yesterday" ? { type: "timePeriod", timePeriod: T, priority: t, style: i } : T === "pastWeek" ? { type: "timePeriod", timePeriod: "last7Days", priority: t, style: i } : T === "pastMonth" ? { type: "timePeriod", timePeriod: "lastMonth", priority: t, style: i } : T === "pastYear" ? { type: "timePeriod", timePeriod: "lastYear", priority: t, style: i } : null;
385
- }
386
- default:
387
- return null;
388
- }
389
- }
390
- function Tt(e, o, t) {
391
- var i;
392
- const r = o.luckysheet_conditionformat_save, n = [];
393
- if (!Array.isArray(r) || r.length === 0)
394
- return { nextPriority: t, pendingDuplicateValues: n };
395
- let l = t;
396
- for (const u of r) {
397
- if (u.type !== "default") continue;
398
- const d = yt(u.cellrange);
399
- if (!d) continue;
400
- if (u.conditionName === "duplicateValue") {
401
- const T = String(((i = u.conditionValue) == null ? void 0 : i[0]) ?? "0") === "1" ? "uniqueValues" : "duplicateValues";
402
- n.push({
403
- ref: d,
404
- format: u.format || {},
405
- priority: l,
406
- type: T
407
- }), l++;
408
- continue;
409
- }
410
- const a = Ct(u, d, l);
411
- a && (e.addConditionalFormatting({ ref: d, rules: [a] }), l++);
412
- }
413
- return { nextPriority: l, pendingDuplicateValues: n };
414
- }
415
- function wt(e) {
416
- let o = "";
417
- const t = [];
418
- if (e.bold && t.push("<b/>"), e.italic && t.push("<i/>"), e.underline && t.push("<u/>"), e.strikethrough && t.push("<strike/>"), e.textColor && e.textColor.toLowerCase() !== "#000000") {
419
- const n = G(e.textColor);
420
- n && t.push(`<color rgb="${n}"/>`);
421
- }
422
- t.length > 0 && (o += `<font>${t.join("")}</font>`);
423
- const r = e.cellColor;
424
- if (r && r.toLowerCase() !== "#ffffff") {
425
- const n = G(r);
426
- n && (o += `<fill><patternFill patternType="solid"><fgColor rgb="${n}"/></patternFill></fill>`);
427
- }
428
- return `<dxf>${o}</dxf>`;
429
- }
430
- function Et(e, o) {
431
- const t = e.match(/<dxfs count="(\d+)"/);
432
- if (t) {
433
- const r = parseInt(t[1], 10);
434
- return {
435
- xml: e.replace(/<dxfs count="\d+"/, `<dxfs count="${r + 1}"`).replace("</dxfs>", o + "</dxfs>"),
436
- dxfId: r
437
- };
438
- }
439
- return e.includes("<dxfs/>") ? {
440
- xml: e.replace("<dxfs/>", `<dxfs count="1">${o}</dxfs>`),
441
- dxfId: 0
442
- } : {
443
- xml: e.replace(
444
- "</styleSheet>",
445
- `<dxfs count="1">${o}</dxfs></styleSheet>`
446
- ),
447
- dxfId: 0
448
- };
449
- }
450
- function $t(e) {
451
- return e.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
452
- }
453
- function At(e, o, t) {
454
- const r = new RegExp(
455
- `(<conditionalFormatting[^>]*\\bsqref="${$t(o)}"[^>]*>)`
456
- );
457
- if (r.test(e))
458
- return e.replace(r, `$1${t}`);
459
- const n = `<conditionalFormatting sqref="${o}">${t}</conditionalFormatting>`;
460
- for (const l of [
461
- "<pageMargins",
462
- "<pageSetup",
463
- "<headerFooter",
464
- "<drawing",
465
- "</worksheet>"
466
- ])
467
- if (e.includes(l))
468
- return e.replace(l, n + l);
469
- return e + n;
470
- }
471
- function kt(e) {
472
- return e.replace(
473
- /<cfRule([^>]*)type="containsText"([^>]*?)>([\s\S]*?)<\/cfRule>/g,
474
- (o, t, r, n) => {
475
- if (/\btext=/.test(t) || /\btext=/.test(r)) return o;
476
- const l = n.match(/<formula[^>]*>([\s\S]*?)<\/formula>/);
477
- if (!l) return o;
478
- const u = l[1].replace(/&quot;/g, '"').replace(/&amp;/g, "&").replace(/&lt;/g, "<").replace(/&gt;/g, ">").match(/SEARCH\s*\(\s*"([^"]*)"/i);
479
- if (!u) return o;
480
- const d = u[1].replace(/&/g, "&amp;").replace(/"/g, "&quot;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
481
- return `<cfRule${t}type="containsText"${r} text="${d}">${n}</cfRule>`;
482
- }
483
- );
484
- }
485
- async function Rt(e, o) {
486
- var i;
487
- const t = await ft.loadAsync(e), r = t.file("xl/styles.xml");
488
- let n = r ? await r.async("text") : "", l = !1;
489
- for (const [u, d] of Object.entries(t.files)) {
490
- if (d.dir) continue;
491
- const a = u.match(/^xl\/worksheets\/sheet(\d+)\.xml$/);
492
- if (!a) continue;
493
- const T = parseInt(a[1], 10) - 1;
494
- let w = await d.async("text"), k = !1;
495
- const C = kt(w);
496
- C !== w && (w = C, k = !0);
497
- const x = ((i = o[T]) == null ? void 0 : i.duplicateValues) ?? [];
498
- for (const B of x) {
499
- const V = wt(B.format), { xml: z, dxfId: Z } = Et(n, V);
500
- n = z, l = !0;
501
- const K = `<cfRule type="${B.type}" dxfId="${Z}" priority="${B.priority}"/>`;
502
- w = At(w, B.ref, K), k = !0;
503
- }
504
- k && t.file(u, w);
505
- }
506
- return l && r && t.file("xl/styles.xml", n), t.generateAsync({ type: "arraybuffer", compression: "DEFLATE" });
507
- }
508
- const Ft = (e) => {
509
- if (!e || typeof e != "string") return null;
510
- const o = e.trim().toLowerCase();
511
- if (o.startsWith("#")) {
512
- const n = o.replace("#", "").toUpperCase();
513
- return n.length === 3 ? n.split("").map((l) => l + l).join("").toUpperCase() : n.length === 6 ? n : null;
514
- }
515
- const t = /rgba?\s*\(\s*([\d.]+)[,\s]+([\d.]+)[,\s]+([\d.]+)(?:[,\s/]+[\d.]+)?\s*\)/i, r = o.match(t);
516
- if (r) {
517
- const n = Math.min(255, Math.max(0, parseFloat(r[1]))), l = Math.min(255, Math.max(0, parseFloat(r[2]))), i = Math.min(255, Math.max(0, parseFloat(r[3])));
518
- return ((1 << 24) + (n << 16) + (l << 8) + i).toString(16).slice(1).toUpperCase();
519
- }
520
- return null;
521
- };
522
- function St(e) {
523
- const o = {};
524
- if (e.bl === 1 && (o.bold = !0), e.it === 1 && (o.italic = !0), e.un === 1 && (o.underline = !0), e.cl === 1 && (o.strike = !0), e.fs && (o.size = Number(e.fs)), typeof e.ff == "string" && e.ff && (o.name = e.ff), e.fc) {
525
- const t = Ft(e.fc);
526
- t && (o.color = { argb: `FF${t}` });
527
- }
528
- return Object.keys(o).length > 0 ? o : void 0;
529
- }
530
- function rt(e) {
531
- if (!Array.isArray(e) || e.length === 0) return null;
532
- const o = [];
533
- for (const t of e) {
534
- const r = String(t.v ?? "");
535
- if (r === "" && !t.bl && !t.it && !t.un && !t.cl) continue;
536
- const n = St(t), l = { text: r };
537
- n && (l.font = n), o.push(l);
538
- }
539
- return o.length === 0 || !o.some((t) => t.text !== "") ? null : { richText: o };
540
- }
541
- function vt(e, o) {
542
- o.forEach((t, r) => {
543
- const n = e.getCell(r);
544
- n.value = t;
545
- });
546
- }
547
- function Mt(e) {
548
- const o = e == null ? void 0 : e.filter, t = e == null ? void 0 : e.filter_select, r = !!(o && Object.keys(o).length > 0), n = !!t && (Array.isArray(t.row) || Array.isArray(t.column));
549
- return r || n;
550
- }
551
- const Y = (e) => {
552
- if (!e || typeof e != "string") return null;
553
- const o = e.trim().toLowerCase();
554
- if (o.startsWith("#")) {
555
- const n = o.replace("#", "").toUpperCase();
556
- return n.length === 3 ? n.split("").map((l) => l + l).join("").toUpperCase() : n.length === 6 ? n : null;
557
- }
558
- const t = /rgba?\s*\(\s*([\d.]+)[,\s]+([\d.]+)[,\s]+([\d.]+)(?:[,\s/]+[\d.]+)?\s*\)/i, r = o.match(t);
559
- if (r) {
560
- const n = Math.min(255, Math.max(0, parseFloat(r[1]))), l = Math.min(255, Math.max(0, parseFloat(r[2]))), i = Math.min(255, Math.max(0, parseFloat(r[3])));
561
- return ((1 << 24) + (n << 16) + (l << 8) + i).toString(16).slice(1).toUpperCase();
562
- }
563
- return null;
564
- }, Pt = async (e, o, t, r) => {
565
- var n, l, i, u, d, a, T;
566
- if (!(!e.current || !o.current))
567
- try {
568
- const w = (l = (n = e.current).getWorkbookContext) == null ? void 0 : l.call(n), k = w == null ? void 0 : w.luckysheetfile;
569
- Array.isArray(k) && k.some(Mt) && nt({
570
- title: "Filters are not supported in Export",
571
- variant: "warning",
572
- showCloseButton: !0,
573
- duration: 30 * 1e3
574
- }), o.current.getArray(t);
575
- const x = e.current.getAllSheets();
576
- x.forEach((m) => ht(m));
577
- const B = F.book_new(), V = x.map(() => /* @__PURE__ */ new Map()), z = /* @__PURE__ */ new Set();
578
- x.forEach((m, W) => {
579
- var J, N, U, L, O;
580
- const R = dt(m), g = F.aoa_to_sheet(R);
581
- Object.keys(g).forEach((c) => {
582
- if (c.startsWith("!")) return;
583
- const h = g[c];
584
- h && (h.t === "s" || h.t === void 0) && h.v !== "" && !isNaN(Number(h.v)) && (g[c] = { ...h, v: Number(h.v), t: "n" });
585
- }), g["!merges"] = [], (J = m.config) != null && J.merge && Object.values(m.config.merge).forEach((c) => {
586
- g["!merges"].push({
587
- s: { r: c.r, c: c.c },
588
- e: { r: c.r + c.rs - 1, c: c.c + c.cs - 1 }
589
- });
590
- });
591
- {
592
- const h = Math.round(3437.714285714286) / 256, f = m.column || 36;
593
- g["!cols"] = [];
594
- for (let s = 0; s < f; s++) {
595
- const b = (U = (N = m.config) == null ? void 0 : N.columnlen) == null ? void 0 : U[s];
596
- if (b !== void 0) {
597
- const p = Math.max(
598
- 0,
599
- Math.round((Number(b) - 5) / 7 * 256) / 256
600
- );
601
- g["!cols"][s] = { wch: p };
602
- } else
603
- g["!cols"][s] = { wch: h };
604
- }
605
- }
606
- {
607
- const c = Math.round(60.48) / 4;
608
- g.sheetFormat = {
609
- ...g.sheetFormat || {},
610
- defaultRowHeight: String(c)
611
- }, (L = m.config) != null && L.rowlen && (g["!rows"] = [], Object.entries(m.config.rowlen).forEach(([h, f]) => {
612
- const s = Math.round(Number(f) * 0.72 * 4) / 4;
613
- g["!rows"][Number(h)] = { hpt: s };
614
- }));
615
- }
616
- const D = /* @__PURE__ */ new Set();
617
- (m.celldata ?? []).forEach((c) => {
618
- var A, S, $, _, P;
619
- const h = c.r, f = c.c, s = c.v || {}, b = F.encode_cell({ r: h, c: f });
620
- let p = g[b] || {};
621
- if (p = { ...p }, s.f && (p.f = s.f.replace(/^=/, "")), !s.f && ((A = s.ct) == null ? void 0 : A.t) === "inlineStr" && Array.isArray(s.ct.s) ? (p.v = X(s.ct.s), p.t = "s") : p.v = s.v ?? ((_ = ($ = (S = s == null ? void 0 : s.ct) == null ? void 0 : S.s) == null ? void 0 : $[0]) == null ? void 0 : _.v), s.m && (p.w = s.m), !s.f && ((P = s.ct) == null ? void 0 : P.t) === "inlineStr" && Array.isArray(s.ct.s)) {
622
- const M = rt(s.ct.s);
623
- M && V[W].set(b, M);
624
- }
625
- if (s.ct && (s.ct.fa && (p.z = s.ct.fa), s.ct.t && s.ct.t !== "inlineStr" && (p.t = s.ct.t === "d" ? "n" : s.ct.t)), typeof p.v == "number" && !p.t && (p.t = "n"), p.s = p.s || {}, s.bg) {
626
- const M = Y(s.bg);
627
- M && (p.s.fill = {
628
- patternType: "solid",
629
- fgColor: { rgb: M }
630
- });
631
- }
632
- p.s.font = {
633
- ...p.s.font || {},
634
- bold: s.bl === 1 || void 0,
635
- italic: s.it === 1 || void 0,
636
- strike: s.cl === 1 || void 0,
637
- underline: s.un === 1 || void 0,
638
- sz: s.fs ?? 10,
639
- name: s.ff ?? void 0,
640
- color: (() => {
641
- const M = Y(s.fc);
642
- return M ? { rgb: M } : void 0;
643
- })()
644
- };
645
- const E = { 0: "center", 1: "left", 2: "right" }, y = { 0: "center", 1: "top", 2: "bottom" };
646
- p.s.alignment = {
647
- ...p.s.alignment || {},
648
- wrapText: s.tb === "1" || s.tb === "2" ? !0 : void 0,
649
- textRotation: s.tr !== void 0 ? s.tr : void 0
650
- }, p.s.alignment.horizontal = E[s.ht] || void 0, p.s.alignment.vertical = y[s.vt] || void 0, s.tb !== void 0 && (p.s.alignment = p.s.alignment || {}, s.tb === "1" ? p.s.alignment.wrapText = !0 : s.tb === "2" && (p.s.alignment.shrinkToFit = !0)), D.add(b), g[b] = p;
651
- }), R.forEach((c, h) => {
652
- Array.isArray(c) && c.forEach((f, s) => {
653
- if (!f || typeof f != "object") return;
654
- const b = F.encode_cell({ r: h, c: s });
655
- if (D.has(b)) return;
656
- const p = !!f.f, E = f.bg || f.bl || f.it || f.cl || f.un || f.fs || f.ff || f.fc || f.ht !== void 0 || f.vt !== void 0 || f.tb !== void 0 || f.tr !== void 0;
657
- if (!p && !E) return;
658
- const y = { ...g[b] || {} };
659
- if (y.s = y.s || {}, p && (y.f = f.f.replace(/^=/, "")), f.bg) {
660
- const $ = Y(f.bg);
661
- $ && (y.s.fill = { patternType: "solid", fgColor: { rgb: $ } });
662
- }
663
- y.s.font = {
664
- ...y.s.font || {},
665
- bold: f.bl === 1 || void 0,
666
- italic: f.it === 1 || void 0,
667
- strike: f.cl === 1 || void 0,
668
- underline: f.un === 1 || void 0,
669
- sz: f.fs ?? 10,
670
- name: f.ff ?? void 0,
671
- color: (() => {
672
- const $ = Y(f.fc);
673
- return $ ? { rgb: $ } : void 0;
674
- })()
675
- };
676
- const A = { 0: "center", 1: "left", 2: "right" }, S = { 0: "center", 1: "top", 2: "bottom" };
677
- y.s.alignment = {
678
- ...y.s.alignment || {},
679
- horizontal: A[f.ht] || void 0,
680
- vertical: S[f.vt] || void 0,
681
- textRotation: f.tr !== void 0 ? f.tr : void 0
682
- }, f.tb === "1" ? y.s.alignment.wrapText = !0 : f.tb === "2" && (y.s.alignment.shrinkToFit = !0), g[b] = y;
683
- });
684
- }), R.forEach((c, h) => {
685
- Array.isArray(c) && c.forEach((f, s) => {
686
- var y;
687
- if (!f || ((y = f.ct) == null ? void 0 : y.t) !== "inlineStr" || !Array.isArray(f.ct.s)) return;
688
- const b = F.encode_cell({ r: h, c: s }), p = X(f.ct.s);
689
- g[b] = {
690
- ...g[b] || {},
691
- v: p,
692
- t: "s"
693
- };
694
- const E = rt(f.ct.s);
695
- E && V[W].set(b, E);
696
- });
697
- }), (O = m.config) != null && O.borderInfo && xt(g, m.config.borderInfo), Object.keys(g).forEach((c) => {
698
- if (c.startsWith("!")) return;
699
- const h = g[c];
700
- h && h.s && h.t == null && h.v == null && h.f == null && (h.t = "s", h.v = "");
701
- });
702
- const v = m.name.length > 30 ? m.name.slice(0, 30) : m.name;
703
- if (z.has(v)) {
704
- const c = v !== m.name ? `"${m.name}" is too long and collides with another sheet after being shortened to "${v}"` : `Two sheets share the name "${m.name}"`;
705
- throw new Error(
706
- `${c}. Sheet names must be unique. Rename one and try again.`
707
- );
708
- }
709
- z.add(v), F.book_append_sheet(B, g, v);
710
- });
711
- const Z = await (r == null ? void 0 : r(t)) || "Untitled", K = it(B, {
712
- bookType: "xlsx",
713
- type: "array",
714
- compression: !0
715
- }), j = new ct();
716
- await j.xlsx.load(K);
717
- const H = j.model;
718
- (u = (i = H == null ? void 0 : H.styles) == null ? void 0 : i.fonts) != null && u[0] && (H.styles.fonts[0] = { ...H.styles.fonts[0], size: 10 });
719
- const tt = x.map(() => ({
720
- duplicateValues: []
721
- }));
722
- x.forEach((m, W) => {
723
- const R = j.worksheets[W];
724
- if (!R) return;
725
- vt(R, V[W]);
726
- const g = m.data;
727
- Object.entries(m.hyperlink || {}).forEach(([L, O]) => {
728
- var A, S, $, _;
729
- const c = ut(O);
730
- if (!(c != null && c.linkAddress)) return;
731
- const [h, f] = L.split("_").map(Number);
732
- if (Number.isNaN(h) || Number.isNaN(f)) return;
733
- const s = F.encode_cell({ r: h, c: f }), b = R.getCell(s), p = (A = g == null ? void 0 : g[h]) == null ? void 0 : A[f];
734
- let E = "";
735
- p && typeof p == "object" && ((S = p.ct) == null ? void 0 : S.t) === "inlineStr" && Array.isArray(p.ct.s) && (E = X(p.ct.s));
736
- const y = E || (typeof b.text == "string" && b.text.length > 0 ? b.text : (($ = b.value) == null ? void 0 : $.text) || (Array.isArray((_ = b.value) == null ? void 0 : _.richText) ? b.value.richText.map((P) => P.text || "").join("") : "") || "");
737
- b.value = {
738
- text: y || c.linkAddress,
739
- hyperlink: c.linkAddress
740
- };
741
- });
742
- const { nextPriority: D, pendingDuplicateValues: v } = Tt(R, m, 1);
743
- tt[W] = { duplicateValues: v };
744
- let J = D;
745
- if (!m.dataVerification) return;
746
- const N = R;
747
- N.dataValidations || (N.dataValidations = { model: {} }), N.dataValidations.model || (N.dataValidations.model = {});
748
- const U = N.dataValidations.model;
749
- Object.entries(m.dataVerification).forEach(([L, O]) => {
750
- const c = O;
751
- if (c.type !== "dropdown" && c.type !== "checkbox") return;
752
- const [h, f] = L.split("_").map(Number), s = F.encode_cell({ r: h, c: f });
753
- if (c.type === "checkbox") {
754
- const p = (c.value1 || "TRUE").trim(), E = (c.value2 || "FALSE").trim(), y = [p, E].filter(Boolean);
755
- U[s] = {
756
- type: "list",
757
- allowBlank: !0,
758
- formulae: [`"${y.join(",")}"`],
759
- showInputMessage: !!c.hintShow,
760
- prompt: c.hintValue || "",
761
- showErrorMessage: !!c.prohibitInput
762
- };
763
- return;
764
- }
765
- const b = (c.value1 || "").split(",").map((p) => p.trim()).filter(Boolean);
766
- if (b.length !== 0 && (U[s] = {
767
- type: "list",
768
- allowBlank: !0,
769
- formulae: [`"${b.join(",")}"`],
770
- showInputMessage: !!c.hintShow,
771
- prompt: c.hintValue || "",
772
- showErrorMessage: !!c.prohibitInput
773
- }, c.color)) {
774
- const p = c.color.split(",").map((A) => parseInt(A.trim(), 10)), E = (A) => Math.max(0, Math.min(255, A)).toString(16).padStart(2, "0").toUpperCase(), y = b.map((A, S) => {
775
- const $ = p[S * 3], _ = p[S * 3 + 1], P = p[S * 3 + 2];
776
- if (isNaN($) || isNaN(_) || isNaN(P)) return null;
777
- const M = `FF${E($)}${E(_)}${E(P)}`;
778
- return {
779
- type: "cellIs",
780
- operator: "equal",
781
- formulae: [`"${A}"`],
782
- priority: J++,
783
- style: {
784
- fill: {
785
- type: "pattern",
786
- pattern: "solid",
787
- fgColor: { argb: M }
788
- }
789
- }
790
- };
791
- }).filter(Boolean);
792
- y.length > 0 && N.addConditionalFormatting({
793
- ref: s,
794
- rules: y
795
- });
796
- }
797
- });
798
- }), x.forEach((m, W) => {
799
- var v;
800
- if (!((v = m.images) != null && v.length)) return;
801
- const R = j.worksheets[W];
802
- if (!R) return;
803
- const g = Number(m.defaultColWidth) || 99, D = Number(m.defaultRowHeight) || 21;
804
- pt(
805
- R,
806
- j,
807
- m.images,
808
- m,
809
- g,
810
- D
811
- );
812
- });
813
- const { applyDefinedNamesToExcelWorkbook: ot } = await import("./xlsx-defined-names-CBoWA_1s.js");
814
- ot(
815
- j,
816
- (T = (a = (d = e.current).getWorkbookContext) == null ? void 0 : a.call(d)) == null ? void 0 : T.definedNames,
817
- x
818
- );
819
- const at = await j.xlsx.writeBuffer(), st = await Rt(at, tt), lt = new Blob([st], {
820
- type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
821
- }), et = URL.createObjectURL(lt), Q = document.createElement("a");
822
- Q.href = et, Q.download = `${Z}.xlsx`, Q.click(), URL.revokeObjectURL(et);
823
- } catch (w) {
824
- console.error("Export failed:", w), nt({
825
- title: "Export failed",
826
- description: w instanceof Error && w.message ? w.message : "Something went wrong while exporting to .xlsx. Please try again.",
827
- variant: "error",
828
- showCloseButton: !0,
829
- duration: 10 * 1e3
830
- });
831
- }
832
- };
833
- export {
834
- Pt as handleExportToXLSX
835
- };