@fileverse-dev/dsheet 4.0.0 → 4.0.1-ref

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,830 @@
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 { addFortuneImagesToWorksheet as ft } from "./xlsx-image-utils-Cvg0qxRA.js";
5
+ import { J as ut } from "./jszip.min-DHgf03FP.js";
6
+ import { b as pt } from "./executeStringFunction-CCpEDh3D.js";
7
+ import { c as X, g as dt } from "./xlsx-hyperlink-inline-DzewAypN.js";
8
+ const mt = {
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
+ }, ht = (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: mt[t] ?? "thin",
31
+ color: { rgb: ht(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 }), i = {
36
+ ...e[l] || { t: "z" }
37
+ }, f = { ...i.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, i.s = f, e[l] = i;
39
+ }, gt = (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, i = F.encode_cell({ r, c: n }), f = {
46
+ ...e[i] || { 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[i] = f;
49
+ } else if (t.rangeType === "range") {
50
+ const { borderType: r, style: n, color: l, range: i } = t;
51
+ if (r === "border-none" || !Array.isArray(i) || !n)
52
+ return;
53
+ const f = q(n, l);
54
+ if (!f) return;
55
+ i.forEach((d) => {
56
+ const [a, T] = d.row, [w, k] = d.column;
57
+ for (let C = a; C <= T; C++)
58
+ for (let g = w; g <= k; g++)
59
+ switch (r) {
60
+ case "border-all":
61
+ I(
62
+ e,
63
+ C,
64
+ g,
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
+ g,
74
+ { l: g === w, r: g === k, t: C === a, b: C === T },
75
+ f
76
+ );
77
+ break;
78
+ case "border-inside":
79
+ I(
80
+ e,
81
+ C,
82
+ g,
83
+ { r: g < k, b: C < T },
84
+ f
85
+ );
86
+ break;
87
+ case "border-horizontal":
88
+ I(e, C, g, { b: C < T }, f);
89
+ break;
90
+ case "border-vertical":
91
+ I(e, C, g, { r: g < k }, f);
92
+ break;
93
+ case "border-left":
94
+ g === w && I(e, C, g, { l: !0 }, f);
95
+ break;
96
+ case "border-right":
97
+ g === k && I(e, C, g, { r: !0 }, f);
98
+ break;
99
+ case "border-top":
100
+ C === a && I(e, C, g, { t: !0 }, f);
101
+ break;
102
+ case "border-bottom":
103
+ C === T && I(e, C, g, { b: !0 }, f);
104
+ break;
105
+ }
106
+ });
107
+ }
108
+ });
109
+ };
110
+ function G(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 xt(e) {
125
+ const o = {}, t = {};
126
+ if (e.textColor && e.textColor.toLowerCase() !== "#000000") {
127
+ const n = G(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 = G(r);
134
+ n && (o.fill = { type: "pattern", pattern: "solid", fgColor: { argb: n } });
135
+ }
136
+ return o;
137
+ }
138
+ function bt(e) {
139
+ return !Array.isArray(e) || e.length === 0 ? "" : e.map((t) => {
140
+ const [r, n] = t.row, [l, i] = t.column, f = F.encode_cell({ r, c: l }), d = F.encode_cell({ r: n, c: i });
141
+ return f === d ? f : `${f}:${d}`;
142
+ }).filter(Boolean).join(" ");
143
+ }
144
+ function yt(e, o, t) {
145
+ const { conditionName: r, conditionValue: n = [], format: l = {} } = e, i = xt(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: i
158
+ } : null;
159
+ case "notEqual":
160
+ return n[0] ? {
161
+ type: "cellIs",
162
+ operator: "notEqual",
163
+ formulae: [n[0]],
164
+ priority: t,
165
+ style: i
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: i
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: i
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: i
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: i
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: i
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: i
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: i
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: i
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: i
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: i
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: i
304
+ };
305
+ }
306
+ case "empty":
307
+ return {
308
+ type: "containsText",
309
+ operator: "containsBlanks",
310
+ formulae: [`LEN(TRIM(${d}))=0`],
311
+ priority: t,
312
+ style: i
313
+ };
314
+ case "containsBlanks":
315
+ return {
316
+ type: "containsText",
317
+ operator: "containsBlanks",
318
+ formulae: [`LEN(TRIM(${d}))=0`],
319
+ priority: t,
320
+ style: i
321
+ };
322
+ case "notEmpty":
323
+ return {
324
+ type: "containsText",
325
+ operator: "notContainsBlanks",
326
+ formulae: [`LEN(TRIM(${d}))>0`],
327
+ priority: t,
328
+ style: i
329
+ };
330
+ case "notContainsBlanks":
331
+ return {
332
+ type: "containsText",
333
+ operator: "notContainsBlanks",
334
+ formulae: [`LEN(TRIM(${d}))>0`],
335
+ priority: t,
336
+ style: i
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: i
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: i
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: i
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: i
375
+ };
376
+ case "aboveAverage":
377
+ return { type: "aboveAverage", aboveAverage: !0, priority: t, style: i };
378
+ case "belowAverage":
379
+ return { type: "aboveAverage", aboveAverage: !1, priority: t, style: i };
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: 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;
386
+ }
387
+ default:
388
+ return null;
389
+ }
390
+ }
391
+ function Ct(e, o, t) {
392
+ var i;
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 = bt(f.cellrange);
400
+ if (!d) continue;
401
+ if (f.conditionName === "duplicateValue") {
402
+ const T = String(((i = f.conditionValue) == null ? void 0 : i[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 = yt(f, d, l);
412
+ a && (e.addConditionalFormatting({ ref: d, rules: [a] }), l++);
413
+ }
414
+ return { nextPriority: l, pendingDuplicateValues: n };
415
+ }
416
+ function Tt(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 = G(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 = G(r);
427
+ n && (o += `<fill><patternFill patternType="solid"><fgColor rgb="${n}"/></patternFill></fill>`);
428
+ }
429
+ return `<dxf>${o}</dxf>`;
430
+ }
431
+ function wt(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 $t(e) {
452
+ return e.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
453
+ }
454
+ function Et(e, o, t) {
455
+ const r = new RegExp(
456
+ `(<conditionalFormatting[^>]*\\bsqref="${$t(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 At(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 kt(e, o) {
487
+ var i;
488
+ const t = await ut.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 w = await d.async("text"), k = !1;
496
+ const C = At(w);
497
+ C !== w && (w = C, k = !0);
498
+ const g = ((i = o[T]) == null ? void 0 : i.duplicateValues) ?? [];
499
+ for (const B of g) {
500
+ const V = Tt(B.format), { xml: z, dxfId: Z } = wt(n, V);
501
+ n = z, l = !0;
502
+ const K = `<cfRule type="${B.type}" dxfId="${Z}" priority="${B.priority}"/>`;
503
+ w = Et(w, B.ref, K), k = !0;
504
+ }
505
+ k && t.file(f, w);
506
+ }
507
+ return l && r && t.file("xl/styles.xml", n), t.generateAsync({ type: "arraybuffer", compression: "DEFLATE" });
508
+ }
509
+ const Rt = (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]))), i = Math.min(255, Math.max(0, parseFloat(r[3])));
519
+ return ((1 << 24) + (n << 16) + (l << 8) + i).toString(16).slice(1).toUpperCase();
520
+ }
521
+ return null;
522
+ };
523
+ function Ft(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 = Rt(e.fc);
527
+ t && (o.color = { argb: `FF${t}` });
528
+ }
529
+ return Object.keys(o).length > 0 ? o : void 0;
530
+ }
531
+ function rt(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 = Ft(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 St(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 Y = (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]))), i = Math.min(255, Math.max(0, parseFloat(r[3])));
562
+ return ((1 << 24) + (n << 16) + (l << 8) + i).toString(16).slice(1).toUpperCase();
563
+ }
564
+ return null;
565
+ }, jt = async (e, o, t, r) => {
566
+ var n, l, i, f, d, a, T;
567
+ if (!(!e.current || !o.current))
568
+ try {
569
+ const w = (l = (n = e.current).getWorkbookContext) == null ? void 0 : l.call(n), k = w == null ? void 0 : w.luckysheetfile;
570
+ Array.isArray(k) && k.some(vt) && nt({
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 g = e.current.getAllSheets(), B = F.book_new(), V = g.map(() => /* @__PURE__ */ new Map()), z = /* @__PURE__ */ new Set();
577
+ g.forEach((m, W) => {
578
+ var J, N, U, D, O;
579
+ const R = pt(m), x = F.aoa_to_sheet(R);
580
+ Object.keys(x).forEach((p) => {
581
+ if (p.startsWith("!")) return;
582
+ const b = x[p];
583
+ b && (b.t === "s" || b.t === void 0) && b.v !== "" && !isNaN(Number(b.v)) && (x[p] = { ...b, v: Number(b.v), t: "n" });
584
+ }), x["!merges"] = [], (J = m.config) != null && J.merge && Object.values(m.config.merge).forEach((p) => {
585
+ x["!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, c = m.column || 36;
592
+ x["!cols"] = [];
593
+ for (let s = 0; s < c; s++) {
594
+ const h = (U = (N = m.config) == null ? void 0 : N.columnlen) == null ? void 0 : U[s];
595
+ if (h !== void 0) {
596
+ const u = Math.max(
597
+ 0,
598
+ Math.round((Number(h) - 5) / 7 * 256) / 256
599
+ );
600
+ x["!cols"][s] = { wch: u };
601
+ } else
602
+ x["!cols"][s] = { wch: b };
603
+ }
604
+ }
605
+ {
606
+ const p = Math.round(60.48) / 4;
607
+ x.sheetFormat = {
608
+ ...x.sheetFormat || {},
609
+ defaultRowHeight: String(p)
610
+ }, (D = m.config) != null && D.rowlen && (x["!rows"] = [], Object.entries(m.config.rowlen).forEach(([b, c]) => {
611
+ const s = Math.round(Number(c) * 0.72 * 4) / 4;
612
+ x["!rows"][Number(b)] = { hpt: s };
613
+ }));
614
+ }
615
+ const L = /* @__PURE__ */ new Set();
616
+ (m.celldata ?? []).forEach((p) => {
617
+ var A, S, E, _, j;
618
+ const b = p.r, c = p.c, s = p.v || {}, h = F.encode_cell({ r: b, c });
619
+ let u = x[h] || {};
620
+ if (u = { ...u }, s.f && (u.f = s.f.replace(/^=/, "")), !s.f && ((A = s.ct) == null ? void 0 : A.t) === "inlineStr" && Array.isArray(s.ct.s) ? (u.v = X(s.ct.s), u.t = "s") : u.v = s.v ?? ((_ = (E = (S = s == null ? void 0 : s.ct) == null ? void 0 : S.s) == null ? void 0 : E[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 = rt(s.ct.s);
622
+ M && V[W].set(h, 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 = Y(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 = Y(s.fc);
641
+ return M ? { rgb: M } : void 0;
642
+ })()
643
+ };
644
+ const $ = { 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 = $[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(h), x[h] = u;
650
+ }), R.forEach((p, b) => {
651
+ Array.isArray(p) && p.forEach((c, s) => {
652
+ if (!c || typeof c != "object") return;
653
+ const h = F.encode_cell({ r: b, c: s });
654
+ if (L.has(h)) return;
655
+ const u = !!c.f, $ = c.bg || c.bl || c.it || c.cl || c.un || c.fs || c.ff || c.fc || c.ht !== void 0 || c.vt !== void 0 || c.tb !== void 0 || c.tr !== void 0;
656
+ if (!u && !$) return;
657
+ const y = { ...x[h] || {} };
658
+ if (y.s = y.s || {}, u && (y.f = c.f.replace(/^=/, "")), c.bg) {
659
+ const E = Y(c.bg);
660
+ E && (y.s.fill = { patternType: "solid", fgColor: { rgb: E } });
661
+ }
662
+ y.s.font = {
663
+ ...y.s.font || {},
664
+ bold: c.bl === 1 || void 0,
665
+ italic: c.it === 1 || void 0,
666
+ strike: c.cl === 1 || void 0,
667
+ underline: c.un === 1 || void 0,
668
+ sz: c.fs ?? 10,
669
+ name: c.ff ?? void 0,
670
+ color: (() => {
671
+ const E = Y(c.fc);
672
+ return E ? { rgb: E } : void 0;
673
+ })()
674
+ };
675
+ const A = { 0: "center", 1: "left", 2: "right" }, S = { 0: "center", 1: "top", 2: "bottom" };
676
+ y.s.alignment = {
677
+ ...y.s.alignment || {},
678
+ horizontal: A[c.ht] || void 0,
679
+ vertical: S[c.vt] || void 0,
680
+ textRotation: c.tr !== void 0 ? c.tr : void 0
681
+ }, c.tb === "1" ? y.s.alignment.wrapText = !0 : c.tb === "2" && (y.s.alignment.shrinkToFit = !0), x[h] = y;
682
+ });
683
+ }), R.forEach((p, b) => {
684
+ Array.isArray(p) && p.forEach((c, s) => {
685
+ var y;
686
+ if (!c || ((y = c.ct) == null ? void 0 : y.t) !== "inlineStr" || !Array.isArray(c.ct.s)) return;
687
+ const h = F.encode_cell({ r: b, c: s }), u = X(c.ct.s);
688
+ x[h] = {
689
+ ...x[h] || {},
690
+ v: u,
691
+ t: "s"
692
+ };
693
+ const $ = rt(c.ct.s);
694
+ $ && V[W].set(h, $);
695
+ });
696
+ }), (O = m.config) != null && O.borderInfo && gt(x, m.config.borderInfo);
697
+ const v = m.name.length > 30 ? m.name.slice(0, 30) : m.name;
698
+ if (z.has(v)) {
699
+ const p = 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}"`;
700
+ throw new Error(
701
+ `${p}. Sheet names must be unique. Rename one and try again.`
702
+ );
703
+ }
704
+ z.add(v), F.book_append_sheet(B, x, v);
705
+ });
706
+ const Z = await (r == null ? void 0 : r(t)) || "Untitled", K = it(B, {
707
+ bookType: "xlsx",
708
+ type: "array",
709
+ compression: !0
710
+ }), P = new ct();
711
+ await P.xlsx.load(K);
712
+ const H = P.model;
713
+ (f = (i = H == null ? void 0 : H.styles) == null ? void 0 : i.fonts) != null && f[0] && (H.styles.fonts[0] = { ...H.styles.fonts[0], size: 10 });
714
+ const tt = g.map(() => ({
715
+ duplicateValues: []
716
+ }));
717
+ g.forEach((m, W) => {
718
+ const R = P.worksheets[W];
719
+ if (!R) return;
720
+ St(R, V[W]);
721
+ const x = m.data;
722
+ Object.entries(m.hyperlink || {}).forEach(([D, O]) => {
723
+ var A, S, E, _;
724
+ const p = dt(O);
725
+ if (!(p != null && p.linkAddress)) return;
726
+ const [b, c] = D.split("_").map(Number);
727
+ if (Number.isNaN(b) || Number.isNaN(c)) return;
728
+ const s = F.encode_cell({ r: b, c }), h = R.getCell(s), u = (A = x == null ? void 0 : x[b]) == null ? void 0 : A[c];
729
+ let $ = "";
730
+ u && typeof u == "object" && ((S = u.ct) == null ? void 0 : S.t) === "inlineStr" && Array.isArray(u.ct.s) && ($ = X(u.ct.s));
731
+ const y = $ || (typeof h.text == "string" && h.text.length > 0 ? h.text : ((E = h.value) == null ? void 0 : E.text) || (Array.isArray((_ = h.value) == null ? void 0 : _.richText) ? h.value.richText.map((j) => j.text || "").join("") : "") || "");
732
+ h.value = {
733
+ text: y || p.linkAddress,
734
+ hyperlink: p.linkAddress
735
+ };
736
+ });
737
+ const { nextPriority: L, pendingDuplicateValues: v } = Ct(R, m, 1);
738
+ tt[W] = { duplicateValues: v };
739
+ let J = L;
740
+ if (!m.dataVerification) return;
741
+ const N = R;
742
+ N.dataValidations || (N.dataValidations = { model: {} }), N.dataValidations.model || (N.dataValidations.model = {});
743
+ const U = N.dataValidations.model;
744
+ Object.entries(m.dataVerification).forEach(([D, O]) => {
745
+ const p = O;
746
+ if (p.type !== "dropdown" && p.type !== "checkbox") return;
747
+ const [b, c] = D.split("_").map(Number), s = F.encode_cell({ r: b, c });
748
+ if (p.type === "checkbox") {
749
+ const u = (p.value1 || "TRUE").trim(), $ = (p.value2 || "FALSE").trim(), y = [u, $].filter(Boolean);
750
+ U[s] = {
751
+ type: "list",
752
+ allowBlank: !0,
753
+ formulae: [`"${y.join(",")}"`],
754
+ showInputMessage: !!p.hintShow,
755
+ prompt: p.hintValue || "",
756
+ showErrorMessage: !!p.prohibitInput
757
+ };
758
+ return;
759
+ }
760
+ const h = (p.value1 || "").split(",").map((u) => u.trim()).filter(Boolean);
761
+ if (h.length !== 0 && (U[s] = {
762
+ type: "list",
763
+ allowBlank: !0,
764
+ formulae: [`"${h.join(",")}"`],
765
+ showInputMessage: !!p.hintShow,
766
+ prompt: p.hintValue || "",
767
+ showErrorMessage: !!p.prohibitInput
768
+ }, p.color)) {
769
+ const u = p.color.split(",").map((A) => parseInt(A.trim(), 10)), $ = (A) => Math.max(0, Math.min(255, A)).toString(16).padStart(2, "0").toUpperCase(), y = h.map((A, S) => {
770
+ const E = u[S * 3], _ = u[S * 3 + 1], j = u[S * 3 + 2];
771
+ if (isNaN(E) || isNaN(_) || isNaN(j)) return null;
772
+ const M = `FF${$(E)}${$(_)}${$(j)}`;
773
+ return {
774
+ type: "cellIs",
775
+ operator: "equal",
776
+ formulae: [`"${A}"`],
777
+ priority: J++,
778
+ style: {
779
+ fill: {
780
+ type: "pattern",
781
+ pattern: "solid",
782
+ fgColor: { argb: M }
783
+ }
784
+ }
785
+ };
786
+ }).filter(Boolean);
787
+ y.length > 0 && N.addConditionalFormatting({
788
+ ref: s,
789
+ rules: y
790
+ });
791
+ }
792
+ });
793
+ }), g.forEach((m, W) => {
794
+ var v;
795
+ if (!((v = m.images) != null && v.length)) return;
796
+ const R = P.worksheets[W];
797
+ if (!R) return;
798
+ const x = Number(m.defaultColWidth) || 99, L = Number(m.defaultRowHeight) || 21;
799
+ ft(
800
+ R,
801
+ P,
802
+ m.images,
803
+ m,
804
+ x,
805
+ L
806
+ );
807
+ });
808
+ const { applyDefinedNamesToExcelWorkbook: ot } = await import("./xlsx-defined-names-_KUWFAe9.js");
809
+ ot(
810
+ P,
811
+ (T = (a = (d = e.current).getWorkbookContext) == null ? void 0 : a.call(d)) == null ? void 0 : T.definedNames,
812
+ g
813
+ );
814
+ const at = await P.xlsx.writeBuffer(), st = await kt(at, tt), lt = new Blob([st], {
815
+ type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
816
+ }), et = URL.createObjectURL(lt), Q = document.createElement("a");
817
+ Q.href = et, Q.download = `${Z}.xlsx`, Q.click(), URL.revokeObjectURL(et);
818
+ } catch (w) {
819
+ console.error("Export failed:", w), nt({
820
+ title: "Export failed",
821
+ description: w instanceof Error && w.message ? w.message : "Something went wrong while exporting to .xlsx. Please try again.",
822
+ variant: "error",
823
+ showCloseButton: !0,
824
+ duration: 10 * 1e3
825
+ });
826
+ }
827
+ };
828
+ export {
829
+ jt as handleExportToXLSX
830
+ };