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