@office-view-suite/viewer-excel 0.2.0 → 0.2.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.
package/dist/index.js CHANGED
@@ -1,47 +1,164 @@
1
- import { createWorkerAdapter as wt, createOfficeViewerError as xt } from "@office-view-suite/viewer-core";
2
- const ut = Date.UTC(1899, 11, 30);
3
- function yt(t) {
4
- return new Date(ut + t * 864e5);
1
+ import { createWorkerAdapter as vt, createOfficeViewerError as $t } from "@office-view-suite/viewer-core";
2
+ const rt = { black: "#000000", blue: "#0000ff", cyan: "#00ffff", green: "#008000", magenta: "#ff00ff", red: "#ff0000", white: "#ffffff", yellow: "#ffff00" }, q = 864e5;
3
+ function ft(t) {
4
+ const e = [{ tokens: [] }];
5
+ for (let o = 0; o < t.length; ) {
6
+ const n = e[e.length - 1], r = t[o++];
7
+ if (r === ";") {
8
+ e.push({ tokens: [] });
9
+ continue;
10
+ }
11
+ if (r === '"') {
12
+ let s = "";
13
+ for (; o < t.length && t[o] !== '"'; ) s += t[o++];
14
+ t[o] === '"' && o++, n.tokens.push({ text: s, literal: !0 });
15
+ } else if (r === "\\") n.tokens.push({ text: t[o++] ?? "", literal: !0 });
16
+ else if (r === "_")
17
+ o++, n.tokens.push({ text: " ", literal: !0 });
18
+ else if (r === "*")
19
+ o++;
20
+ else if (r === "[") {
21
+ const s = t.indexOf("]", o);
22
+ if (s < 0) {
23
+ n.tokens.push({ text: "[", literal: !0 });
24
+ continue;
25
+ }
26
+ const c = t.slice(o, s);
27
+ o = s + 1;
28
+ const a = /^(<=|>=|<>|=|<|>)(-?(?:\d+(?:\.\d*)?|\.\d+)(?:e[+-]?\d+)?)$/i.exec(c);
29
+ a ? n.condition = { op: a[1], value: Number(a[2]) } : rt[c.toLowerCase()] ? n.color = rt[c.toLowerCase()] : /^[hms]+$/i.test(c) ? n.tokens.push({ text: c.toLowerCase(), bracket: !0 }) : c.startsWith("$") && n.tokens.push({ text: c.slice(1).split("-")[0], literal: !0 });
30
+ } else {
31
+ const s = /^(AM\/PM|A\/P)/i.exec(t.slice(o - 1));
32
+ if (s)
33
+ n.tokens.push({ text: s[0] }), o += s[0].length - 1;
34
+ else if (/[ymdhs]/i.test(r)) {
35
+ let c = r;
36
+ for (; t[o]?.toLowerCase() === r.toLowerCase(); ) c += t[o++];
37
+ n.tokens.push({ text: c });
38
+ } else n.tokens.push({ text: r });
39
+ }
40
+ }
41
+ return e;
5
42
  }
6
- function K(t) {
7
- const e = t.split(";")[0].match(/\.([0#]+)/);
8
- return e ? e[1].length : 0;
43
+ function ht(t, e) {
44
+ const o = ft(t);
45
+ if (o.slice(0, 2).some((r) => r.condition))
46
+ return { section: o.slice(0, 3).find((s) => {
47
+ if (!s.condition) return !0;
48
+ const { op: c, value: a } = s.condition;
49
+ return c === "<" ? e < a : c === ">" ? e > a : c === "<=" ? e <= a : c === ">=" ? e >= a : c === "<>" ? e !== a : e === a;
50
+ }) ?? { tokens: [] }, magnitude: !1 };
51
+ const n = e < 0 && o.length > 1 ? 1 : e === 0 && o.length > 2 ? 2 : 0;
52
+ return { section: o[n], magnitude: n === 1 };
9
53
  }
10
- function dt(t, e) {
11
- if (!e) return t;
12
- const n = e.split(";")[0].replace(/\\(.)/g, "$1");
13
- if (n.includes("@")) return t;
14
- const r = Number(t), i = t.trim() !== "" && !Number.isNaN(r);
15
- if (/yyyy|mm|dd|hh|ss/i.test(n) && i) {
16
- const s = yt(r);
17
- if (!Number.isNaN(s.getTime())) {
18
- const f = (w) => String(w).padStart(2, "0");
19
- return n.replace(/yyyy/i, String(s.getUTCFullYear())).replace(/mm/i, f(s.getUTCMonth() + 1)).replace(/dd/i, f(s.getUTCDate())).replace(/hh/i, f(s.getUTCHours())).replace(/ss/i, f(s.getUTCSeconds()));
54
+ function Mt(t, e, o) {
55
+ if (!(!e || o && o !== "number" || !Number.isFinite(Number(t)) || t.trim() === ""))
56
+ return ht(e, Number(t)).section.color;
57
+ }
58
+ function zt(t, e) {
59
+ const o = Math.floor(t), n = e ? o : o - (o >= 60 ? 1 : 0), r = new Date((e ? Date.UTC(1904, 0, 1) : Date.UTC(1899, 11, 31)) + n * q + Math.round((t - o) * q));
60
+ return { date: r, year: !e && o === 60 ? 1900 : r.getUTCFullYear(), month: !e && o === 60 ? 2 : r.getUTCMonth() + 1, day: !e && o === 60 ? 29 : r.getUTCDate() };
61
+ }
62
+ function St(t, e, o) {
63
+ const { date: n, year: r, month: s, day: c } = zt(e, o);
64
+ if (!Number.isFinite(n.getTime())) return String(e);
65
+ const a = t.some((p) => !p.literal && /^a(m)?\//i.test(p.text)), d = (p, $) => String(p).padStart($, "0"), x = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"], v = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"], N = t.map((p, $) => !p.literal && /^[ymdhs]+$/i.test(p.text) ? $ : -1).filter((p) => p >= 0);
66
+ return t.map((p, $) => {
67
+ if (p.literal) return p.text;
68
+ const C = p.text.toLowerCase(), S = p.text.length;
69
+ if (p.bracket) return d(Math.floor(Math.abs(e) * (C[0] === "h" ? 24 : C[0] === "m" ? 1440 : 86400) + 1e-8), S);
70
+ if (/^a(m)?\//i.test(p.text)) return n.getUTCHours() < 12 ? S === 3 ? "A" : "AM" : S === 3 ? "P" : "PM";
71
+ if (/^y+$/.test(C)) return S <= 2 ? d(r % 100, 2) : d(r, S);
72
+ if (/^m+$/.test(C)) {
73
+ const u = N.filter((M) => M < $).at(-1), A = N.find((M) => M > $);
74
+ return u != null && t[u].text[0].toLowerCase() === "h" || A != null && t[A].text[0].toLowerCase() === "s" ? S > 1 ? d(n.getUTCMinutes(), 2) : String(n.getUTCMinutes()) : S === 5 ? x[s - 1][0] : S === 4 ? x[s - 1] : S === 3 ? x[s - 1].slice(0, 3) : S === 2 ? d(s, 2) : String(s);
75
+ }
76
+ if (/^d+$/.test(C)) return S >= 3 ? v[n.getUTCDay()].slice(0, S === 3 ? 3 : void 0) : S === 2 ? d(c, 2) : String(c);
77
+ if (/^h+$/.test(C)) {
78
+ const u = a ? n.getUTCHours() % 12 || 12 : n.getUTCHours();
79
+ return S > 1 ? d(u, 2) : String(u);
80
+ }
81
+ if (/^s+$/.test(C)) return S > 1 ? d(n.getUTCSeconds(), 2) : String(n.getUTCSeconds());
82
+ if (p.text === "0") {
83
+ let u = $;
84
+ for (; u > 0 && t[u - 1].text === "0"; ) u--;
85
+ if (t[u - 1]?.text === "." && /^s+$/i.test(t[u - 2]?.text ?? "")) {
86
+ const A = $ - u;
87
+ return d(n.getUTCMilliseconds(), 3)[A] ?? "0";
88
+ }
20
89
  }
90
+ return p.text;
91
+ }).join("");
92
+ }
93
+ function Lt(t, e, o) {
94
+ const n = t.map((l, T) => !l.literal && /[0#?]/.test(l.text) ? T : -1).filter((l) => l >= 0);
95
+ if (!n.length) return t.map((l) => l.text).join("");
96
+ const r = n[0];
97
+ let s = n.at(-1);
98
+ if (t[s + 1]?.text === "/" && !t[s + 1].literal) {
99
+ let l = s + 2;
100
+ for (; t[l] && !t[l].literal && /^\d$/.test(t[l].text); ) l++;
101
+ l > s + 2 && (s = l - 1);
21
102
  }
22
- if (!i) return t;
23
- if (n.includes("%")) {
24
- const s = K(n);
25
- return (r * 100).toFixed(s) + "%";
103
+ const c = t.slice(0, r).map((l) => l.text).join("");
104
+ let a = s + 1, d = 0;
105
+ for (; t[a]?.text === "," && !t[a].literal; )
106
+ d++, a++;
107
+ const x = t.filter((l) => !l.literal && l.text === "%").length;
108
+ let v = (o ? Math.abs(e) : e) * 100 ** x / 1e3 ** d;
109
+ const N = t.slice(r, s + 1).map((l) => l.literal ? "\0" : l.text).join(""), p = t.slice(a).map((l) => l.text).join(""), $ = /^([0#?]+)(?:\.([0#?]+))?([eE])([+-])([0#?]+)$/.exec(N);
110
+ if ($) {
111
+ const l = Math.min(20, $[2]?.length ?? 0), [T, m] = v.toExponential(l).split("e"), g = Number(m);
112
+ return c + T + $[3] + (g < 0 ? "-" : $[4] === "+" ? "+" : "") + String(Math.abs(g)).padStart($[5].length, "0") + p;
26
113
  }
27
- if (/E\+/i.test(n)) {
28
- const s = K(n);
29
- return r.toExponential(s).toUpperCase();
114
+ const C = /^([#0?]+ )?([#0?]+)\/([#0?]+|\d+)$/.exec(N);
115
+ if (C) {
116
+ let l = C[1] ? Math.floor(Math.abs(v)) : 0;
117
+ const T = Math.abs(v) - l, m = /^\d+$/.test(C[3]) ? Number(C[3]) : 0;
118
+ let g = m || 1, b = Math.round(T * g), W = 1 / 0;
119
+ for (let U = 1; !m && U <= Math.min(9999, 10 ** C[3].length - 1); U++) {
120
+ const V = Math.round(T * U), j = Math.abs(T - V / U);
121
+ if (j < W && (W = j, g = U, b = V), j < 1e-12) break;
122
+ }
123
+ C[1] && b >= g && (l += Math.floor(b / g), b %= g);
124
+ const P = C[1] ? l === 0 && !C[1].includes("0") ? " " : `${l} ` : "", F = b === 0 && C[1] ? " ".repeat(C[2].length + C[3].length + 1) : `${b}/${g}`;
125
+ return c + (v < 0 ? "-" : "") + P + F + p;
30
126
  }
31
- if (n.includes("#,##")) {
32
- const s = K(n);
33
- return r.toLocaleString("en-US", {
34
- minimumFractionDigits: s,
35
- maximumFractionDigits: s
36
- });
127
+ const S = /^([0#?,]+)(?:\.([0#?]+))?$/.exec(N);
128
+ if (!S) {
129
+ const l = String(Math.round(Math.abs(v))).padStart(n.length, "0");
130
+ let T = Math.max(0, l.length - n.length);
131
+ return (v < 0 ? "-" : "") + t.map((m, g) => !m.literal && /[0#?]/.test(m.text) ? (g === r ? l.slice(0, T) : "") + (l[T++] ?? "") : m.text).join("");
37
132
  }
38
- if (/^0(\.0+)?$/.test(n)) {
39
- const s = K(n);
40
- return r.toFixed(s);
133
+ const u = S[2] ?? "", A = u.replace(/[^0]/g, "").length, h = Math.min(20, u.length), M = S[1], y = M.includes(","), z = Math.max(1, M.replace(/[^0]/g, "").length), i = Math.abs(v);
134
+ let f = i.toLocaleString("en-US", { useGrouping: y, minimumIntegerDigits: Math.min(21, z), minimumFractionDigits: Math.min(A, h), maximumFractionDigits: h });
135
+ !M.includes("0") && i < 1 && (f = f.replace(/^0(?=\.|$)/, ""));
136
+ const w = u.includes("?") ? h - (f.split(".")[1]?.length ?? 0) : 0;
137
+ return w > 0 && (f += (f.includes(".") ? "" : ".") + " ".repeat(w)), v < 0 && (f = "-" + f), c + f + p;
138
+ }
139
+ function mt(t, e, o, n = !1) {
140
+ if (o === "empty" || t === "") return "";
141
+ if (o === "error" || o === "boolean") return t;
142
+ if (o === "string" || o == null && (!Number.isFinite(Number(t)) || t.trim() === "")) {
143
+ const a = e ? ft(e)[3] : void 0;
144
+ return a ? a.tokens.map((d) => !d.literal && d.text === "@" ? t : d.text).join("") : t;
41
145
  }
42
- return t;
146
+ if (!e || /^general$/i.test(e)) return t;
147
+ let r = Number(t);
148
+ if (o === "date") {
149
+ const a = Date.parse(t);
150
+ if (!Number.isFinite(a)) return t;
151
+ r = (a - (n ? Date.UTC(1904, 0, 1) : Date.UTC(1899, 11, 31))) / q, !n && a >= Date.UTC(1900, 2, 1) && r++;
152
+ }
153
+ if (!Number.isFinite(r)) return t;
154
+ const { section: s, magnitude: c } = ht(e, r);
155
+ return /^general$/i.test(s.tokens.filter((a) => !a.literal).map((a) => a.text).join("")) && !s.tokens.some((a) => a.literal) ? String(r) : s.tokens.some((a) => !a.literal && (a.bracket || /^[ymdhs]+$/i.test(a.text))) ? St(s.tokens, r, n) : s.tokens.some((a) => !a.literal && a.text === "@") ? t : Lt(s.tokens, r, c);
156
+ }
157
+ const pt = 1.25;
158
+ function ot(t, e) {
159
+ return t ? `${JSON.stringify(t)}, "PingFang SC", "Microsoft YaHei", sans-serif` : e;
43
160
  }
44
- const bt = `
161
+ const Et = `
45
162
  :host { display: block; }
46
163
 
47
164
  .workbook { display: flex; flex-direction: column; gap: 12px; width: 100%; }
@@ -55,14 +172,22 @@ const bt = `
55
172
  .sheet[hidden] { display: none; }
56
173
 
57
174
  .grid-wrap { overflow: auto; max-height: 63vh; max-width: var(--office-viewer-viewport-width, none); box-sizing: border-box; background: #fff; border: 1px solid #d0d7de; border-radius: 0; }
58
- .grid { display: grid; gap: 0; width: max-content; zoom: var(--office-excel-scale, 1);
175
+ .grid { position: relative; display: grid; gap: 0; width: max-content; zoom: var(--office-excel-scale, 1);
59
176
  border-left: 1px solid #e4e8ec; border-top: 1px solid #e4e8ec; }
60
177
 
178
+ .grid--no-lines { border-color: transparent; }
179
+ .grid--no-lines .cell { border-color: transparent; }
180
+ .cell-content { width: 100%; min-width: 0; }
61
181
  .cell {
182
+ display: flex;
183
+ flex-direction: column;
184
+ justify-content: flex-end;
185
+ box-sizing: border-box;
62
186
  border-right: 1px solid #e4e8ec;
63
187
  border-bottom: 1px solid #e4e8ec;
64
188
  padding: 3px 8px;
65
189
  font-size: 14px;
190
+ line-height: ${pt};
66
191
  white-space: nowrap;
67
192
  overflow: hidden;
68
193
  text-overflow: ellipsis;
@@ -103,46 +228,46 @@ const bt = `
103
228
 
104
229
  @media print { .grid-wrap { overflow: visible; } }
105
230
  `;
106
- function vt(t) {
107
- let e = t.highestRow, n = t.highestCol;
108
- const r = (i, s) => {
109
- if (!Number.isInteger(i) || i < 0 || i > 1048576 || !Number.isInteger(s) || s < 0 || s > 16384)
231
+ function Tt(t) {
232
+ let e = t.highestRow, o = t.highestCol;
233
+ const n = (r, s) => {
234
+ if (!Number.isInteger(r) || r < 0 || r > 1048576 || !Number.isInteger(s) || s < 0 || s > 16384)
110
235
  throw new Error("Worksheet dimensions exceed Excel limits");
111
- e = Math.max(e, i), n = Math.max(n, s);
236
+ e = Math.max(e, r), o = Math.max(o, s);
112
237
  };
113
- r(e, n);
114
- for (const i of t.merges) {
115
- const s = et(i);
116
- r(s.r2, s.c2);
238
+ n(e, o);
239
+ for (const r of t.merges) {
240
+ const s = nt(r);
241
+ n(s.r2, s.c2);
117
242
  }
118
- for (const i of t.cells) r(i.row, i.col);
119
- for (const i of [...t.images, ...t.shapes])
120
- r(i.row, i.col), r(i.toRow ?? i.row, i.toCol ?? i.col);
121
- return { rows: e, cols: n };
243
+ for (const r of t.cells) n(r.row, r.col);
244
+ for (const r of [...t.images, ...t.shapes])
245
+ n(r.row, r.col), n(r.toRow ?? r.row, r.toCol ?? r.col);
246
+ return { rows: e, cols: o };
122
247
  }
123
- function et(t) {
248
+ function nt(t) {
124
249
  const e = (s) => {
125
- const f = /^\$?([A-Z]+)\$?([1-9]\d*)$/i.exec(s);
126
- if (!f) throw new Error(`Invalid cell range: ${t}`);
127
- let w = 0;
128
- for (const u of f[1].toUpperCase()) w = w * 26 + u.charCodeAt(0) - 64;
129
- const m = Number(f[2]);
130
- if (w > 16384 || m > 1048576) throw new Error(`Cell range exceeds Excel limits: ${t}`);
131
- return { col: w, row: m };
132
- }, n = t.split(":");
133
- if (n.length > 2) throw new Error(`Invalid cell range: ${t}`);
134
- const r = e(n[0]), i = e(n[1] ?? n[0]);
135
- return { c1: Math.min(r.col, i.col), r1: Math.min(r.row, i.row), c2: Math.max(r.col, i.col), r2: Math.max(r.row, i.row) };
250
+ const c = /^\$?([A-Z]+)\$?([1-9]\d*)$/i.exec(s);
251
+ if (!c) throw new Error(`Invalid cell range: ${t}`);
252
+ let a = 0;
253
+ for (const x of c[1].toUpperCase()) a = a * 26 + x.charCodeAt(0) - 64;
254
+ const d = Number(c[2]);
255
+ if (a > 16384 || d > 1048576) throw new Error(`Cell range exceeds Excel limits: ${t}`);
256
+ return { col: a, row: d };
257
+ }, o = t.split(":");
258
+ if (o.length > 2) throw new Error(`Invalid cell range: ${t}`);
259
+ const n = e(o[0]), r = e(o[1] ?? o[0]);
260
+ return { c1: Math.min(n.col, r.col), r1: Math.min(n.row, r.row), c2: Math.max(n.col, r.col), r2: Math.max(n.row, r.row) };
136
261
  }
137
- class nt {
262
+ class st {
138
263
  offsets;
139
264
  count;
140
265
  total;
141
266
  constructor(e) {
142
267
  this.count = e.length, this.offsets = new Float64Array(e.length + 1);
143
- for (let n = 0; n < e.length; n++) {
144
- if (!Number.isFinite(e[n])) throw new Error("Worksheet dimensions must be finite");
145
- this.offsets[n + 1] = this.offsets[n] + Math.max(1, e[n]);
268
+ for (let o = 0; o < e.length; o++) {
269
+ if (!Number.isFinite(e[o])) throw new Error("Worksheet dimensions must be finite");
270
+ this.offsets[o + 1] = this.offsets[o] + Math.max(0, e[o]);
146
271
  }
147
272
  this.total = this.offsets[e.length];
148
273
  }
@@ -157,204 +282,232 @@ class nt {
157
282
  }
158
283
  at(e) {
159
284
  if (this.count === 0) return 0;
160
- let n = 0, r = this.count;
161
- for (; n < r; ) {
162
- const i = n + r >>> 1;
163
- this.offsets[i + 1] <= e ? n = i + 1 : r = i;
285
+ let o = 0, n = this.count;
286
+ for (; o < n; ) {
287
+ const r = o + n >>> 1;
288
+ this.offsets[r + 1] <= e ? o = r + 1 : n = r;
164
289
  }
165
- return Math.min(this.count, n + 1);
290
+ return Math.min(this.count, o + 1);
166
291
  }
167
292
  }
168
293
  class tt {
169
294
  entries;
170
295
  maxEnd;
171
296
  constructor(e) {
172
- this.entries = [...e].sort((r, i) => r.r1 - i.r1);
173
- let n = 0;
174
- this.maxEnd = this.entries.map((r) => n = Math.max(n, r.r2));
297
+ this.entries = [...e].sort((n, r) => n.r1 - r.r1);
298
+ let o = 0;
299
+ this.maxEnd = this.entries.map((n) => o = Math.max(o, n.r2));
175
300
  }
176
301
  intersect(e) {
177
- let n = 0, r = this.entries.length;
178
- for (; n < r; ) {
179
- const s = n + r >>> 1;
180
- this.entries[s].r1 <= e.r2 ? n = s + 1 : r = s;
302
+ let o = 0, n = this.entries.length;
303
+ for (; o < n; ) {
304
+ const s = o + n >>> 1;
305
+ this.entries[s].r1 <= e.r2 ? o = s + 1 : n = s;
181
306
  }
182
- const i = [];
183
- for (let s = n - 1; s >= 0 && this.maxEnd[s] >= e.r1; s--) {
184
- const f = this.entries[s];
185
- f.r2 >= e.r1 && f.c1 <= e.c2 && f.c2 >= e.c1 && i.push(f);
307
+ const r = [];
308
+ for (let s = o - 1; s >= 0 && this.maxEnd[s] >= e.r1; s--) {
309
+ const c = this.entries[s];
310
+ c.r2 >= e.r1 && c.c1 <= e.c2 && c.c2 >= e.c1 && r.push(c);
186
311
  }
187
- return i;
312
+ return r;
188
313
  }
189
314
  }
190
- function rt(t, e, n, r = 1, i = 2) {
191
- return n <= 0 || t.count < r || e >= t.total ? { first: 1, last: 0 } : {
192
- first: Math.max(r, t.at(Math.max(0, e)) - i),
193
- last: Math.min(t.count, t.at(Math.max(0, e + n - 1e-3)) + i)
315
+ function at(t, e, o, n = 1, r = 2) {
316
+ return o <= 0 || t.count < n || e >= t.total ? { first: 1, last: 0 } : {
317
+ first: Math.max(n, t.at(Math.max(0, e)) - r),
318
+ last: Math.min(t.count, t.at(Math.max(0, e + o - 1e-3)) + r)
194
319
  };
195
320
  }
196
- const Ct = 1e4, it = 2e4;
197
- function st(t, e, n) {
321
+ function gt(t, e, o) {
322
+ const n = "fitCell" in t && t.fitCell, r = e.start(t.col) + (n ? 0 : t.offsetXPx ?? 0), s = o.start(t.row) + (n ? 0 : t.offsetYPx ?? 0), c = t.toCol ? t.toOffsetXPx == null ? e.end(t.toCol) : e.start(t.toCol) + t.toOffsetXPx : void 0, a = t.toRow ? t.toOffsetYPx == null ? o.end(t.toRow) : o.start(t.toRow) + t.toOffsetYPx : void 0, d = n ? e.size(t.col) : c != null ? c - r : t.widthPx ?? e.size(t.col), x = n ? o.size(t.row) : a != null ? a - s : t.heightPx ?? o.size(t.row);
323
+ return { x: r, y: s, width: Math.max(0, d), height: Math.max(0, x) };
324
+ }
325
+ function kt(t, e = 0) {
326
+ if (!Number.isFinite(e) || e % 360 === 0) return t;
327
+ const o = e * Math.PI / 180, n = Math.abs(t.width * Math.cos(o)) + Math.abs(t.height * Math.sin(o)), r = Math.abs(t.width * Math.sin(o)) + Math.abs(t.height * Math.cos(o));
328
+ return { x: t.x + (t.width - n) / 2, y: t.y + (t.height - r) / 2, width: n, height: r };
329
+ }
330
+ const Rt = 1e4, lt = 2e4;
331
+ function et(t, e, o) {
198
332
  if (!Number.isInteger(t.highestRow) || t.highestRow < 0 || t.highestRow > 1048576 || !Number.isInteger(t.highestCol) || t.highestCol < 0 || t.highestCol > 16384)
199
333
  throw new Error("Worksheet dimensions exceed Excel limits");
200
- const r = new Float64Array(t.highestCol).fill(96), i = new Float64Array(t.highestRow).fill(26), s = /* @__PURE__ */ new Set(), f = /* @__PURE__ */ new Set();
201
- for (const o of t.colWidths) o.col >= 1 && o.col <= r.length && o.width > 0 && (r[o.col - 1] = Math.max(1, Math.round(o.width * 7 + 5)), s.add(o.col));
202
- for (const o of t.rowHeights) o.row >= 1 && o.row <= i.length && o.height > 0 && (i[o.row - 1] = Math.max(1, Math.round(o.height * 96 / 72)), f.add(o.row));
203
- const w = t.merges.map(et), m = new Map(w.map((o) => [`${o.c1}:${o.r1}`, o])), u = new Map(t.cells.map((o) => [`${o.col}:${o.row}`, o])), R = new Set(t.cells.filter((o) => o.wrapText).map((o) => o.col)), N = e.createElement("canvas").getContext("2d"), L = (o, c) => {
204
- const d = (c?.fontSize ?? o.fontSize ?? 10.5) * 96 / 72, y = c?.fontName ?? o.fontName;
205
- return N && (N.font = `${c?.italic ?? o.italic ? "italic " : ""}${c?.bold ?? o.bold ? "bold " : ""}${d}px ${y ? `"${y}", ` : ""}${n}`), d;
206
- }, A = (o) => o.richText?.length ? o.richText : [{ text: dt(o.value, o.numfmt) }], S = (o, c) => N?.measureText(o).width ?? o.length * c;
207
- for (const o of t.cells) {
208
- if (o.col < 1 || o.col > r.length || s.has(o.col) || R.has(o.col) || m.has(`${o.col}:${o.row}`)) continue;
209
- let c = 0;
210
- for (const d of A(o)) c += S(d.text.replace(/\s+/g, " "), L(o, d));
211
- r[o.col - 1] = Math.max(r[o.col - 1], Math.ceil(c + 17));
334
+ const n = new Float64Array(t.highestCol).fill(t.defaultColWidth && t.defaultColWidth > 0 ? Math.round(t.defaultColWidth * 7 + 5) : 96), r = new Float64Array(t.highestRow).fill(t.defaultRowHeight && t.defaultRowHeight > 0 ? Math.round(t.defaultRowHeight * 96 / 72) : 26), s = /* @__PURE__ */ new Set(), c = /* @__PURE__ */ new Set();
335
+ for (const i of t.colWidths) i.col >= 1 && i.col <= n.length && i.width > 0 && (n[i.col - 1] = Math.max(1, Math.round(i.width * 7 + 5)), s.add(i.col));
336
+ for (const i of t.rowHeights) i.row >= 1 && i.row <= r.length && i.height > 0 && (r[i.row - 1] = Math.max(1, Math.round(i.height * 96 / 72)), i.customHeight !== !1 && c.add(i.row));
337
+ for (const i of t.colWidths) i.hidden && i.col >= 1 && i.col <= n.length && (n[i.col - 1] = 0, s.add(i.col));
338
+ for (const i of t.rowHeights) i.hidden && i.row >= 1 && i.row <= r.length && (r[i.row - 1] = 0, c.add(i.row));
339
+ const a = t.merges.map(nt), d = new Map(a.map((i) => [`${i.c1}:${i.r1}`, i])), x = new Map(t.cells.map((i) => [`${i.col}:${i.row}`, i])), v = (i) => n[i.col - 1] > 0 && r[i.row - 1] > 0, N = new Set(t.cells.filter((i) => i.wrapText && v(i)).map((i) => i.col)), p = e.createElement("canvas").getContext("2d"), $ = (i, f) => {
340
+ const w = (f?.fontSize ?? i.fontSize ?? 10.5) * 96 / 72, l = f?.fontName ?? i.fontName;
341
+ return p && (p.font = `${f?.italic ?? i.italic ? "italic " : ""}${f?.bold ?? i.bold ? "bold " : ""}${w}px ${ot(l, o)}`), w;
342
+ }, C = (i) => i.richText?.length ? i.richText : [{ text: mt(i.value, i.numfmt, i.valueType, i.date1904 ?? t.date1904) }], S = (i, f) => p?.measureText(i).width ?? i.length * f;
343
+ for (const i of t.cells) {
344
+ if (!v(i) || i.col < 1 || i.col > n.length || s.has(i.col) || N.has(i.col) || d.has(`${i.col}:${i.row}`)) continue;
345
+ let f = 0;
346
+ for (const w of C(i)) f += S(w.text.replace(/\s+/g, " "), $(i, w));
347
+ n[i.col - 1] = Math.max(n[i.col - 1], Math.ceil(f + 17));
212
348
  }
213
- const k = new nt(r);
214
- for (const o of t.cells) {
215
- if (o.row < 1 || o.row > i.length || f.has(o.row)) continue;
216
- const c = m.get(`${o.col}:${o.row}`);
217
- if (c && c.r2 > c.r1) continue;
218
- const d = Math.max(1, k.end(c?.c2 ?? o.col) - k.start(o.col) - 17);
219
- let y = 1, l = 0, h = 14;
220
- for (const g of A(o)) {
221
- const $ = L(o, g);
222
- if (h = Math.max(h, $), !o.wrapText) continue;
223
- const M = g.text.match(/[\u2e80-\u9fff]|[^\s\u2e80-\u9fff]+|\s+/g) ?? [];
224
- for (const F of M) {
225
- const H = /^\s+$/.test(F), X = S(H ? " " : F, $);
226
- !H && l > 0 && l + X > d && (y++, l = 0), (!H || l > 0) && (l += X);
349
+ const u = new st(n);
350
+ for (const i of t.cells) {
351
+ if (!v(i) || i.row < 1 || i.row > r.length || c.has(i.row)) continue;
352
+ const f = d.get(`${i.col}:${i.row}`);
353
+ if (f && f.r2 > f.r1) continue;
354
+ const w = Math.max(1, u.end(f?.c2 ?? i.col) - u.start(i.col) - 17);
355
+ let l = 1, T = 0, m = 14;
356
+ for (const g of C(i)) {
357
+ const b = $(i, g);
358
+ if (m = Math.max(m, b), !i.wrapText) continue;
359
+ const W = g.text.match(/\r\n|[\r\n]|[\u2e80-\u9fff]|[^\s\u2e80-\u9fff]+|[^\S\r\n]+/g) ?? [];
360
+ for (const P of W) {
361
+ if (/^[\r\n]+$/.test(P)) {
362
+ l++, T = 0;
363
+ continue;
364
+ }
365
+ const F = /^\s+$/.test(P), U = S(F ? " " : P, b);
366
+ !F && T > 0 && T + U > w && (l++, T = 0), (!F || T > 0) && (T += U);
227
367
  }
228
368
  }
229
- i[o.row - 1] = Math.max(i[o.row - 1], Math.ceil(y * h * 1.25 + 7));
369
+ r[i.row - 1] = Math.max(r[i.row - 1], Math.ceil(l * m * pt + 7));
230
370
  }
231
- const x = new nt(i), P = (o, c) => {
232
- const d = k.start(o.col) + ("offsetXPx" in o ? o.offsetXPx : 0), y = x.start(o.row) + ("offsetYPx" in o ? o.offsetYPx : 0), l = o.toCol ? k.end(o.toCol) - k.start(o.col) : o.widthPx ?? k.size(o.col), h = o.toRow ? x.end(o.toRow) - x.start(o.row) : o.heightPx ?? x.size(o.row);
371
+ const A = new st(r), h = (i, f) => {
372
+ const { x: w, y: l, width: T, height: m } = gt(i, u, A), g = "data" in i ? kt({ x: w, y: l, width: T, height: m }, i.rotation) : { x: w, y: l, width: T, height: m };
233
373
  return {
234
- key: c,
235
- x: d,
236
- y,
237
- width: Math.max(1, l),
238
- height: Math.max(1, h),
239
- c1: d,
240
- r1: y,
241
- c2: d + Math.max(1, l) - 1e-3,
242
- r2: y + Math.max(1, h) - 1e-3,
243
- ..."data" in o ? { image: o } : { shape: o }
374
+ key: f,
375
+ x: w,
376
+ y: l,
377
+ width: T,
378
+ height: m,
379
+ c1: g.x,
380
+ r1: g.y,
381
+ c2: g.x + g.width - 1e-3,
382
+ r2: g.y + g.height - 1e-3,
383
+ ..."data" in i ? { image: i } : { shape: i }
244
384
  };
245
- }, C = [
246
- ...t.images.map((o, c) => P(o, `image:${c}`)),
247
- ...t.shapes.map((o, c) => P(o, `shape:${c}`))
385
+ }, M = [
386
+ ...t.images.map((i, f) => h(i, `image:${f}`)),
387
+ ...t.shapes.map((i, f) => h(i, `shape:${f}`))
248
388
  ];
249
- let a = k.total, p = x.total;
250
- for (const o of C)
251
- a = Math.max(a, o.x + o.width), p = Math.max(p, o.y + o.height);
252
- return { columns: k, rows: x, width: a, height: p, cells: u, merges: new tt(w), overlays: new tt(C) };
389
+ let y = u.total, z = A.total;
390
+ for (const i of M)
391
+ y = Math.max(y, i.c2 + 1e-3), z = Math.max(z, i.r2 + 1e-3);
392
+ return { columns: u, rows: A, width: y, height: z, cells: x, merges: new tt(a), overlays: new tt(M) };
253
393
  }
254
- function $t(t, e, n, r, i, s, f, w) {
255
- r.classList.add("virtual-grid"), e.dataset.virtual = "true";
256
- const m = e.ownerDocument, u = m.defaultView, R = m.createElement("div");
257
- R.className = "virtual-window", r.append(R);
258
- const N = [[!1, !1], [!0, !1], [!1, !0], [!0, !0]].map(([d, y]) => {
259
- const l = m.createElement("div");
260
- return l.className = "virtual-pane", R.append(l), { element: l, nodes: /* @__PURE__ */ new Map(), frozenX: d, frozenY: y };
394
+ function Nt(t, e, o, n, r, s, c, a) {
395
+ n.classList.add("virtual-grid"), e.dataset.virtual = "true";
396
+ const d = e.ownerDocument, x = d.defaultView, v = d.createElement("div");
397
+ v.className = "virtual-window", n.append(v);
398
+ const N = [[!1, !1], [!0, !1], [!1, !0], [!0, !0]].map(([f, w]) => {
399
+ const l = d.createElement("div");
400
+ return l.className = "virtual-pane", v.append(l), { element: l, nodes: /* @__PURE__ */ new Map(), frozenX: f, frozenY: w };
261
401
  });
262
- let L = !1, A = !1, S, k = !1, x = i.layout, P = 0, C = 0;
263
- const a = () => {
264
- if (S = void 0, L || n.clientWidth <= 0 || n.clientHeight <= 0) return;
265
- x || (x = st(t, m, u.getComputedStyle(e).fontFamily || "sans-serif"), i.layout = x);
266
- const { columns: d, rows: y, cells: l, merges: h, overlays: g } = x;
267
- r.style.width = `${x.width}px`, r.style.height = `${x.height}px`;
268
- const $ = Number.parseFloat(u.getComputedStyle(r).zoom) || 1, M = n.clientWidth / $, F = n.clientHeight / $;
269
- P = n.clientWidth, C = n.clientHeight;
270
- const H = n.scrollLeft / $, X = n.scrollTop / $;
271
- R.style.left = `${H}px`, R.style.top = `${X}px`, R.style.width = `${M}px`, R.style.height = `${F}px`;
272
- const J = Math.max(0, Math.min(d.count, t.frozenColumns)), Q = Math.max(0, Math.min(y.count, t.frozenRows)), V = Math.min(M, d.end(J)), B = Math.min(F, y.end(Q));
273
- let ht = 0;
274
- for (const z of N) {
275
- const mt = z.frozenX ? 0 : V, pt = z.frozenY ? 0 : B, Y = z.frozenX ? V : M - V, O = z.frozenY ? B : F - B;
276
- z.element.style.left = `${mt}px`, z.element.style.top = `${pt}px`, z.element.style.width = `${Y}px`, z.element.style.height = `${O}px`;
277
- const G = z.frozenX ? 0 : H + V, Z = z.frozenY ? 0 : X + B, D = rt(d, G, Y, z.frozenX ? 1 : J + 1), W = rt(y, Z, O, z.frozenY ? 1 : Q + 1);
278
- z.frozenX && (D.last = Math.min(D.last, J)), z.frozenY && (W.last = Math.min(W.last, Q));
279
- const ot = /* @__PURE__ */ new Set(), q = (E, I, j, b, T, U) => {
280
- if (++ht > it) throw new Error(`Worksheet viewport exceeds the preview limit of ${it} visible cells and drawings`);
281
- ot.add(E);
282
- let v = z.nodes.get(E);
283
- v || (v = I(), v.classList.contains("cell") && (v.classList.toggle("frozen-column", z.frozenX), v.classList.toggle("frozen-row", z.frozenY), v.classList.toggle("frozen-corner", z.frozenX && z.frozenY)), z.nodes.set(E, v), z.element.append(v)), v.style.left = `${j - G}px`, v.style.top = `${b - Z}px`, v.style.width = `${T}px`, v.style.height = `${U}px`;
402
+ let p = !1, $ = !1, C, S = !1, u = r.layout, A = 0, h = 0;
403
+ const M = () => {
404
+ if (C = void 0, p || o.clientWidth <= 0 || o.clientHeight <= 0) return;
405
+ u || (u = et(t, d, x.getComputedStyle(e).fontFamily || "sans-serif"), r.layout = u);
406
+ const { columns: f, rows: w, cells: l, merges: T, overlays: m } = u;
407
+ n.style.width = `${u.width}px`, n.style.height = `${u.height}px`;
408
+ const g = Number.parseFloat(x.getComputedStyle(n).zoom) || 1, b = o.clientWidth / g, W = o.clientHeight / g;
409
+ A = o.clientWidth, h = o.clientHeight;
410
+ const P = o.scrollLeft / g, F = o.scrollTop / g;
411
+ v.style.left = `${P}px`, v.style.top = `${F}px`, v.style.width = `${b}px`, v.style.height = `${W}px`;
412
+ const U = Math.max(0, Math.min(f.count, t.frozenColumns)), V = Math.max(0, Math.min(w.count, t.frozenRows)), j = Math.min(b, f.end(U)), J = Math.min(W, w.end(V));
413
+ let xt = 0;
414
+ for (const R of N) {
415
+ const yt = R.frozenX ? 0 : j, bt = R.frozenY ? 0 : J, X = R.frozenX ? j : b - j, B = R.frozenY ? J : W - J;
416
+ R.element.style.left = `${yt}px`, R.element.style.top = `${bt}px`, R.element.style.width = `${X}px`, R.element.style.height = `${B}px`;
417
+ const Z = R.frozenX ? 0 : P + j, K = R.frozenY ? 0 : F + J, _ = at(f, Z, X, R.frozenX ? 1 : U + 1), H = at(w, K, B, R.frozenY ? 1 : V + 1);
418
+ R.frozenX && (_.last = Math.min(_.last, U)), R.frozenY && (H.last = Math.min(H.last, V));
419
+ const it = /* @__PURE__ */ new Set(), Q = (k, O, G, L, D, I) => {
420
+ if (D <= 0 || I <= 0) return;
421
+ if (++xt > lt) throw new Error(`Worksheet viewport exceeds the preview limit of ${lt} visible cells and drawings`);
422
+ it.add(k);
423
+ let E = R.nodes.get(k);
424
+ E || (E = O(), E.classList.contains("cell") && (E.classList.toggle("frozen-column", R.frozenX), E.classList.toggle("frozen-row", R.frozenY), E.classList.toggle("frozen-corner", R.frozenX && R.frozenY)), R.nodes.set(k, E), R.element.append(E)), E.style.left = `${G - Z}px`, E.style.top = `${L - K}px`, E.style.width = `${D}px`, E.style.height = `${I}px`;
284
425
  };
285
- if (Y > 0 && O > 0 && D.last >= D.first && W.last >= W.first) {
286
- const E = { c1: D.first, c2: D.last, r1: W.first, r2: W.last }, I = h.intersect(E), j = /* @__PURE__ */ new Map();
287
- for (const b of I) {
288
- for (let T = Math.max(W.first, b.r1); T <= Math.min(W.last, b.r2); T++) {
289
- const U = j.get(T) ?? [];
290
- U.push(b), j.set(T, U);
426
+ if (X > 0 && B > 0 && _.last >= _.first && H.last >= H.first) {
427
+ const k = { c1: _.first, c2: _.last, r1: H.first, r2: H.last }, O = T.intersect(k), G = /* @__PURE__ */ new Map();
428
+ for (const L of O) {
429
+ for (let D = Math.max(H.first, L.r1); D <= Math.min(H.last, L.r2); D++) {
430
+ if (w.size(D) === 0) {
431
+ D = Math.max(D, w.at(w.start(D)) - 1);
432
+ continue;
433
+ }
434
+ const I = G.get(D) ?? [];
435
+ I.push(L), G.set(D, I);
291
436
  }
292
- q(
293
- `merge:${b.c1}:${b.r1}`,
294
- () => s.cell(l.get(`${b.c1}:${b.r1}`), b.r1, b.c1),
295
- d.start(b.c1),
296
- y.start(b.r1),
297
- d.end(b.c2) - d.start(b.c1),
298
- y.end(b.r2) - y.start(b.r1)
437
+ Q(
438
+ `merge:${L.c1}:${L.r1}`,
439
+ () => s.cell(l.get(`${L.c1}:${L.r1}`), L.r1, L.c1),
440
+ f.start(L.c1),
441
+ w.start(L.r1),
442
+ f.end(L.c2) - f.start(L.c1),
443
+ w.end(L.r2) - w.start(L.r1)
299
444
  );
300
445
  }
301
- for (let b = W.first; b <= W.last; b++) {
302
- const T = (j.get(b) ?? []).sort((v, gt) => v.c1 - gt.c1);
303
- let U = 0;
304
- for (let v = D.first; v <= D.last; v++) {
305
- for (; U < T.length && T[U].c2 < v; ) U++;
306
- if (T[U]?.c1 <= v) {
307
- v = T[U].c2;
446
+ for (let L = H.first; L <= H.last; L++) {
447
+ if (w.size(L) === 0) {
448
+ L = Math.max(L, w.at(w.start(L)) - 1);
449
+ continue;
450
+ }
451
+ const D = (G.get(L) ?? []).sort((E, Ct) => E.c1 - Ct.c1);
452
+ let I = 0;
453
+ for (let E = _.first; E <= _.last; E++) {
454
+ if (f.size(E) === 0) {
455
+ E = Math.max(E, f.at(f.start(E)) - 1);
308
456
  continue;
309
457
  }
310
- q(`cell:${v}:${b}`, () => s.cell(l.get(`${v}:${b}`), b, v), d.start(v), y.start(b), d.size(v), y.size(b));
458
+ for (; I < D.length && D[I].c2 < E; ) I++;
459
+ if (D[I]?.c1 <= E) {
460
+ E = D[I].c2;
461
+ continue;
462
+ }
463
+ Q(`cell:${E}:${L}`, () => s.cell(l.get(`${E}:${L}`), L, E), f.start(E), w.start(L), f.size(E), w.size(L));
311
464
  }
312
465
  }
313
466
  }
314
- if (Y > 0 && O > 0)
315
- for (const E of g.intersect({ c1: G, r1: Z, c2: G + Y - 1e-3, r2: Z + O - 1e-3 }))
316
- q(E.key, () => {
317
- const I = E.image ? s.image(E.image) : s.shape(E.shape);
318
- return I.style.transform = "", I;
319
- }, E.x, E.shape?.geometry === "line" || E.shape?.geometry === "lineInv" ? E.y + E.height / 2 : E.y, E.width, E.height);
320
- for (const [E, I] of z.nodes) ot.has(E) || (I.remove(), z.nodes.delete(E));
467
+ if (X > 0 && B > 0)
468
+ for (const k of m.intersect({ c1: Z, r1: K, c2: Z + X - 1e-3, r2: K + B - 1e-3 }))
469
+ Q(k.key, () => {
470
+ const O = k.image ? s.image(k.image) : s.shape(k.shape);
471
+ return k.shape && (O.style.transform = `${k.shape.rotation ? `rotate(${k.shape.rotation}deg)` : ""} scale(${k.shape.flipH ? -1 : 1}, ${k.shape.flipV ? -1 : 1})`), O;
472
+ }, k.x, k.shape?.geometry === "line" || k.shape?.geometry === "lineInv" ? k.y + k.height / 2 : k.y, k.width, k.height);
473
+ for (const [k, O] of R.nodes) it.has(k) || (O.remove(), R.nodes.delete(k));
321
474
  }
322
- k && (k = !1, w?.());
323
- }, p = () => {
324
- !L && !A && S === void 0 && (S = u.requestAnimationFrame(() => {
475
+ S && (S = !1, a?.());
476
+ }, y = () => {
477
+ !p && !$ && C === void 0 && (C = x.requestAnimationFrame(() => {
325
478
  try {
326
- a();
327
- } catch (d) {
328
- if (A = !0, f) f(d instanceof Error ? d : new Error(String(d)));
329
- else throw d;
479
+ M();
480
+ } catch (f) {
481
+ if ($ = !0, c) c(f instanceof Error ? f : new Error(String(f)));
482
+ else throw f;
330
483
  }
331
484
  }));
332
485
  };
333
- n.addEventListener("scroll", p, { passive: !0 });
334
- const o = typeof ResizeObserver > "u" ? void 0 : new ResizeObserver(() => {
335
- (n.clientWidth !== P || n.clientHeight !== C) && p();
486
+ o.addEventListener("scroll", y, { passive: !0 });
487
+ const z = typeof ResizeObserver > "u" ? void 0 : new ResizeObserver(() => {
488
+ (o.clientWidth !== A || o.clientHeight !== h) && y();
336
489
  });
337
- o?.observe(n);
338
- const c = () => {
339
- x = void 0, i.layout = void 0, k = !0, p();
490
+ z?.observe(o);
491
+ const i = () => {
492
+ u = void 0, r.layout = void 0, S = !0, y();
340
493
  };
341
- return m.fonts?.addEventListener("loadingdone", c), {
494
+ return d.fonts?.addEventListener("loadingdone", i), {
342
495
  element: e,
343
- viewport: n,
496
+ viewport: o,
344
497
  resize() {
345
- !x && !L && (x = st(t, m, u.getComputedStyle(e).fontFamily || "sans-serif"), i.layout = x), x && (r.style.width = `${x.width}px`, r.style.height = `${x.height}px`), S !== void 0 && (u.cancelAnimationFrame(S), S = void 0), a();
498
+ !u && !p && (u = et(t, d, x.getComputedStyle(e).fontFamily || "sans-serif"), r.layout = u), u && (n.style.width = `${u.width}px`, n.style.height = `${u.height}px`), C !== void 0 && (x.cancelAnimationFrame(C), C = void 0), M();
346
499
  },
347
500
  getContentWidth() {
348
- return (x?.width ?? 0) + 1;
501
+ return (u?.width ?? 0) + 1;
349
502
  },
350
503
  dispose() {
351
- L = !0, S !== void 0 && u.cancelAnimationFrame(S), o?.disconnect(), n.removeEventListener("scroll", p), m.fonts?.removeEventListener("loadingdone", c);
352
- for (const d of N) d.nodes.clear();
504
+ p = !0, C !== void 0 && x.cancelAnimationFrame(C), z?.disconnect(), o.removeEventListener("scroll", y), d.fonts?.removeEventListener("loadingdone", i);
505
+ for (const f of N) f.nodes.clear();
353
506
  e.remove();
354
507
  }
355
508
  };
356
509
  }
357
- const zt = 96, Mt = 26, _ = {
510
+ const Y = {
358
511
  thin: "1px solid #9aa3ab",
359
512
  medium: "2px solid #666",
360
513
  thick: "3px solid #444",
@@ -362,168 +515,165 @@ const zt = 96, Mt = 26, _ = {
362
515
  dashed: "1px dashed #888",
363
516
  dotted: "1px dotted #888",
364
517
  double: "3px double #888"
365
- }, Et = { Center: "center", Right: "end", Left: "start" };
366
- function Rt(t, e, n, r) {
367
- const i = t.shadowRoot ?? t.attachShadow({ mode: "open" });
368
- i.replaceChildren();
369
- const s = document.createElement("style");
370
- s.textContent = bt, i.appendChild(s);
371
- const f = document.createElement("div");
372
- f.className = "workbook", i.appendChild(f);
373
- const w = document.createElement("div");
374
- w.className = "sheet-tabs", w.setAttribute("role", "tablist");
375
- const m = document.createElement("div");
376
- m.className = "sheet-pages", f.append(w, m);
377
- let u = 0, R = 0, N = 0, L = 0, A = 0;
378
- const S = [], k = /* @__PURE__ */ new Map(), x = /* @__PURE__ */ new Map();
379
- let P = -1, C, a = !1, p = 1;
380
- const o = () => {
381
- const l = t.ownerDocument.defaultView.getComputedStyle(t), h = Number.parseFloat(l.getPropertyValue("--office-viewer-viewport-height")), g = Number.isFinite(h) && h > 0;
382
- f.classList.toggle("workbook--bounded", g), g ? f.style.setProperty("--office-excel-workbook-height", `${h}px`) : f.style.removeProperty("--office-excel-workbook-height");
383
- }, c = (l) => {
384
- if (a || l === P || !e.sheets[l]) return;
385
- const h = C;
386
- C && k.set(P, { top: C.viewport.scrollTop / p, left: C.viewport.scrollLeft / p });
387
- const g = x.get(l) ?? {};
388
- x.set(l, g);
389
- let $;
518
+ }, At = { Center: "center", Right: "end", Left: "start" };
519
+ function Pt(t, e, o, n) {
520
+ const r = new Map(e.sheets.flatMap((m, g) => (m.state ?? "visible").toLowerCase() === "visible" ? [[g, m]] : [])), s = r.has(e.activeTab ?? 0) ? e.activeTab ?? 0 : r.keys().next().value ?? -1, c = t.shadowRoot ?? t.attachShadow({ mode: "open" });
521
+ c.replaceChildren();
522
+ const a = document.createElement("style");
523
+ a.textContent = Et, c.appendChild(a);
524
+ const d = document.createElement("div");
525
+ d.className = "workbook", c.appendChild(d);
526
+ const x = document.createElement("div");
527
+ x.className = "sheet-tabs", x.setAttribute("role", "tablist");
528
+ const v = document.createElement("div");
529
+ v.className = "sheet-pages", d.append(x, v);
530
+ let N = 0, p = 0, $ = 0, C = 0, S = 0;
531
+ const u = [], A = /* @__PURE__ */ new Map(), h = /* @__PURE__ */ new Map();
532
+ let M = -1, y, z = !1, i = 1;
533
+ const f = () => {
534
+ const m = t.ownerDocument.defaultView.getComputedStyle(t), g = Number.parseFloat(m.getPropertyValue("--office-viewer-viewport-height")), b = Number.isFinite(g) && g > 0;
535
+ d.classList.toggle("workbook--bounded", b), b ? d.style.setProperty("--office-excel-workbook-height", `${g}px`) : d.style.removeProperty("--office-excel-workbook-height");
536
+ }, w = (m) => {
537
+ const g = r.get(m);
538
+ if (z || m === M || !g) return;
539
+ const b = y;
540
+ y && A.set(M, { top: y.viewport.scrollTop / i, left: y.viewport.scrollLeft / i });
541
+ const W = h.get(m) ?? {};
542
+ h.set(m, W);
543
+ let P;
390
544
  try {
391
- $ = kt(e.sheets[l], g, n, r), $.element.dataset.sheetIndex = String(l), m.replaceChildren($.element), o(), $.resize();
392
- const M = k.get(l);
393
- M && ($.viewport.scrollTop = M.top * p, $.viewport.scrollLeft = M.left * p, $.resize());
394
- } catch (M) {
395
- throw $?.dispose(), h && m.replaceChildren(h.element), M;
545
+ P = Ft({ ...g, date1904: e.date1904 ?? g.date1904 }, W, o, n), P.element.dataset.sheetIndex = String(m), v.replaceChildren(P.element), f(), P.resize();
546
+ const F = A.get(m);
547
+ F && (P.viewport.scrollTop = F.top * i, P.viewport.scrollLeft = F.left * i, P.resize());
548
+ } catch (F) {
549
+ throw P?.dispose(), b && v.replaceChildren(b.element), F;
396
550
  }
397
- h?.dispose(), C = $, P = l, S.forEach((M, F) => M.setAttribute("aria-selected", String(F === l))), h && r?.();
551
+ b?.dispose(), y = P, M = m, u.forEach((F) => F.setAttribute("aria-selected", String(Number(F.dataset.sheetIndex) === m))), b && n?.();
398
552
  };
399
- e.sheets.forEach((l, h) => {
400
- const g = document.createElement("button");
401
- g.type = "button", g.className = "sheet-tab", g.textContent = l.name, g.dataset.sheetIndex = String(h), g.setAttribute("role", "tab"), g.setAttribute("aria-selected", h === 0 ? "true" : "false"), S.push(g), w.appendChild(g), u += l.highestRow, R += l.highestCol, N += l.merges.length, L += l.images.length, A += l.shapes.length;
553
+ r.forEach((m, g) => {
554
+ const b = document.createElement("button");
555
+ b.type = "button", b.className = "sheet-tab", b.textContent = m.name, b.dataset.sheetIndex = String(g), b.setAttribute("role", "tab"), b.setAttribute("aria-selected", String(g === s)), u.push(b), x.appendChild(b), N += m.highestRow, p += m.highestCol, $ += m.merges.length, C += m.images.length, S += m.shapes.length;
402
556
  });
403
- const d = (l) => {
404
- const h = l.target.closest(".sheet-tab");
405
- if (h)
557
+ const l = (m) => {
558
+ const g = m.target.closest(".sheet-tab");
559
+ if (g)
406
560
  try {
407
- c(Number(h.dataset.sheetIndex));
408
- } catch (g) {
409
- if (n) n(g instanceof Error ? g : new Error(String(g)));
410
- else throw g;
561
+ w(Number(g.dataset.sheetIndex));
562
+ } catch (b) {
563
+ if (o) o(b instanceof Error ? b : new Error(String(b)));
564
+ else throw b;
411
565
  }
412
- }, y = () => {
413
- for (const l of x.values()) l.layout = void 0;
566
+ }, T = () => {
567
+ for (const m of h.values()) m.layout = void 0;
414
568
  };
415
- w.addEventListener("click", d), t.ownerDocument.fonts?.addEventListener("loadingdone", y);
569
+ x.addEventListener("click", l), t.ownerDocument.fonts?.addEventListener("loadingdone", T);
416
570
  try {
417
- c(0);
418
- } catch (l) {
419
- throw w.removeEventListener("click", d), t.ownerDocument.fonts?.removeEventListener("loadingdone", y), f.remove(), s.remove(), l;
571
+ w(s);
572
+ } catch (m) {
573
+ throw x.removeEventListener("click", l), t.ownerDocument.fonts?.removeEventListener("loadingdone", T), d.remove(), a.remove(), m;
420
574
  }
421
575
  return {
422
- stats: { sheets: e.sheets.length, rows: u, cols: R, merges: N, images: L, shapes: A },
576
+ stats: { sheets: r.size, rows: N, cols: p, merges: $, images: C, shapes: S },
423
577
  resize() {
424
- a || (o(), C?.resize());
578
+ z || (f(), y?.resize());
425
579
  },
426
- setZoom(l) {
427
- if (a || l === p) return;
428
- const h = (C?.viewport.scrollTop ?? 0) / p, g = (C?.viewport.scrollLeft ?? 0) / p;
429
- p = l, f.style.setProperty("--office-excel-scale", String(l)), C && (C.viewport.scrollTop = h * l, C.viewport.scrollLeft = g * l);
580
+ setZoom(m) {
581
+ if (z || m === i) return;
582
+ const g = (y?.viewport.scrollTop ?? 0) / i, b = (y?.viewport.scrollLeft ?? 0) / i;
583
+ i = m, d.style.setProperty("--office-excel-scale", String(m)), y && (y.viewport.scrollTop = g * m, y.viewport.scrollLeft = b * m);
430
584
  },
431
585
  getContentWidth() {
432
- return a ? 0 : C?.getContentWidth() ?? 0;
586
+ return z ? 0 : y?.getContentWidth() ?? 0;
433
587
  },
434
588
  dispose() {
435
- a = !0, C?.dispose(), C = void 0, w.removeEventListener("click", d), t.ownerDocument.fonts?.removeEventListener("loadingdone", y), x.clear(), k.clear(), f.remove(), s.remove();
589
+ z = !0, y?.dispose(), y = void 0, x.removeEventListener("click", l), t.ownerDocument.fonts?.removeEventListener("loadingdone", T), h.clear(), A.clear(), d.remove(), a.remove();
436
590
  }
437
591
  };
438
592
  }
439
- function kt(t, e, n, r) {
440
- const i = vt(t), s = i.rows * i.cols > Ct;
441
- s && (t = { ...t, highestRow: i.rows, highestCol: i.cols });
442
- const f = document.createElement("section");
443
- f.className = "sheet";
444
- const w = document.createElement("div");
445
- w.className = "grid-wrap";
446
- const m = document.createElement("div");
447
- if (m.className = "grid", w.appendChild(m), f.appendChild(w), s)
448
- return $t(t, f, w, m, e, {
449
- cell: at,
450
- image: lt,
451
- shape: ct
452
- }, n, r);
453
- const u = (a) => {
454
- const p = t.colWidths.find((o) => o.col === a);
455
- return p && p.width > 0 ? Math.round(p.width * 7 + 5) : zt;
456
- }, R = (a) => {
457
- const p = t.rowHeights.find((o) => o.row === a);
458
- return p && p.height > 0 ? Math.round(p.height * (96 / 72)) : Mt;
459
- }, N = /* @__PURE__ */ new Set();
460
- for (const a of t.cells)
461
- a.wrapText && N.add(a.col);
462
- m.style.gridTemplateColumns = Array.from({ length: t.highestCol }, (a, p) => {
463
- const o = p + 1;
464
- return N.has(o) ? `${u(o)}px` : `minmax(${u(o)}px, max-content)`;
465
- }).join(" ");
466
- const L = t.merges.map(et), A = new tt(L), S = /* @__PURE__ */ new Map();
467
- for (const { c1: a, r1: p, c2: o, r2: c } of L)
468
- S.set(`${a}:${p}`, { cs: o - a + 1, rs: c - p + 1 });
469
- const k = new Map(t.cells.map((a) => [`${a.col}:${a.row}`, a])), x = /* @__PURE__ */ new Set(), P = /* @__PURE__ */ new Set();
470
- for (let a = 1; a <= t.highestRow; a++) {
471
- const p = A.intersect({ c1: 1, c2: t.highestCol, r1: a, r2: a }).sort((c, d) => c.c1 - d.c1);
472
- let o = 0;
473
- for (let c = 1; c <= t.highestCol; c++) {
474
- for (; o < p.length && p[o].c2 < c; ) o++;
475
- const d = p[o];
476
- if (d?.c1 <= c && !(a === d.r1 && c === d.c1)) {
477
- c = d.c2;
478
- continue;
593
+ function Ft(t, e, o, n) {
594
+ const r = Tt(t);
595
+ t = { ...t, highestRow: r.rows, highestCol: r.cols };
596
+ const s = document.createElement("section");
597
+ s.className = "sheet";
598
+ const c = document.createElement("div");
599
+ c.className = "grid-wrap";
600
+ const a = document.createElement("div");
601
+ a.className = "grid", a.classList.toggle("grid--no-lines", t.showGridLines === !1), c.appendChild(a), s.appendChild(c);
602
+ const d = (N, p, $) => Dt(N, p, $, t.date1904);
603
+ if (r.rows * r.cols > Rt)
604
+ return Nt(t, s, c, a, e, { cell: d, image: ct, shape: dt }, o, n);
605
+ const x = () => {
606
+ const N = et(t, s.ownerDocument, s.ownerDocument.defaultView.getComputedStyle(s).fontFamily || "sans-serif"), { columns: p, rows: $ } = N;
607
+ a.replaceChildren(), a.style.gridTemplateColumns = Array.from({ length: p.count }, (h, M) => `${p.size(M + 1)}px`).join(" "), a.style.gridTemplateRows = Array.from({ length: $.count }, (h, M) => `${$.size(M + 1)}px`).join(" "), a.style.width = `${N.width}px`, a.style.height = `${N.height}px`;
608
+ const C = t.merges.map(nt), S = new tt(C), u = new Map(C.map((h) => [`${h.c1}:${h.r1}`, h])), A = new Map(t.cells.map((h) => [`${h.col}:${h.row}`, h]));
609
+ for (let h = 1; h <= t.highestRow; h++) {
610
+ const M = S.intersect({ c1: 1, c2: t.highestCol, r1: h, r2: h }).sort((z, i) => z.c1 - i.c1);
611
+ let y = 0;
612
+ for (let z = 1; z <= t.highestCol; z++) {
613
+ for (; y < M.length && M[y].c2 < z; ) y++;
614
+ const i = M[y];
615
+ if (i?.c1 <= z && !(h === i.r1 && z === i.c1)) {
616
+ z = i.c2;
617
+ continue;
618
+ }
619
+ const f = `${z}:${h}`, w = u.get(f);
620
+ if (p.end(w?.c2 ?? z) <= p.start(z) || $.end(w?.r2 ?? h) <= $.start(h)) continue;
621
+ const l = d(A.get(f), h, z);
622
+ l.style.gridColumn = w ? `${z} / span ${w.c2 - z + 1}` : `${z}`, l.style.gridRow = w ? `${h} / span ${w.r2 - h + 1}` : `${h}`, h <= t.frozenRows && (l.classList.add("frozen-row"), l.style.top = `${$.start(h)}px`), z <= t.frozenColumns && (l.classList.add("frozen-column"), l.style.left = `${p.start(z)}px`), h <= t.frozenRows && z <= t.frozenColumns && l.classList.add("frozen-corner"), a.appendChild(l);
479
623
  }
480
- const y = `${c}:${a}`, l = k.get(y), h = at(l, a, c);
481
- h.style.gridColumn = `${c}`, h.style.gridRow = `${a}`;
482
- const g = S.get(y);
483
- g && (g.cs > 1 && (h.style.gridColumn = `${c} / span ${g.cs}`), g.rs > 1 && (h.style.gridRow = `${a} / span ${g.rs}`)), l && l.wrapText && (h.style.whiteSpace = "normal", x.add(a)), a <= t.frozenRows && (h.classList.add("frozen-row"), h.style.top = `${Array.from({ length: a - 1 }, ($, M) => R(M + 1)).reduce(($, M) => $ + M, 0)}px`), c <= t.frozenColumns && (h.classList.add("frozen-column"), h.style.left = `${Array.from({ length: c - 1 }, ($, M) => u(M + 1)).reduce(($, M) => $ + M, 0)}px`), a <= t.frozenRows && c <= t.frozenColumns && h.classList.add("frozen-corner"), m.appendChild(h);
484
624
  }
485
- }
486
- for (const a of t.rowHeights)
487
- a.height > 0 && P.add(a.row);
488
- for (let a = 1; a <= t.highestRow; a++)
489
- m.style.gridTemplateRows += ` minmax(${R(a)}px, auto)`;
490
- for (const a of t.images)
491
- m.appendChild(lt(a));
492
- for (const a of t.shapes)
493
- m.appendChild(ct(a));
494
- const C = () => r?.();
495
- return f.ownerDocument.fonts?.addEventListener("loadingdone", C), {
496
- element: f,
497
- viewport: w,
625
+ for (const h of [...t.images, ...t.shapes]) {
626
+ const M = gt(h, p, $);
627
+ if (M.width <= 0 || M.height <= 0) continue;
628
+ const y = "data" in h ? ct(h) : dt(h);
629
+ y.style.position = "absolute", y.style.left = `${M.x}px`, y.style.top = `${!("data" in h) && (h.geometry === "line" || h.geometry === "lineInv") ? M.y + M.height / 2 : M.y}px`, y.style.width = `${M.width}px`, y.style.height = `${M.height}px`, "data" in h || (y.style.transform = ut(h)), a.appendChild(y);
630
+ }
631
+ };
632
+ x();
633
+ const v = () => {
634
+ x(), n?.();
635
+ };
636
+ return s.ownerDocument.fonts?.addEventListener("loadingdone", v), {
637
+ element: s,
638
+ viewport: c,
498
639
  resize() {
499
640
  },
500
- getContentWidth: () => m.scrollWidth + 2,
641
+ getContentWidth: () => a.scrollWidth + 2,
501
642
  dispose() {
502
- f.ownerDocument.fonts?.removeEventListener("loadingdone", C), f.remove();
643
+ s.ownerDocument.fonts?.removeEventListener("loadingdone", v), s.remove();
503
644
  }
504
645
  };
505
646
  }
506
- function at(t, e, n) {
647
+ function Dt(t, e, o, n) {
507
648
  const r = document.createElement("div");
508
- return r.className = "cell", r.dataset.row = String(e), r.dataset.col = String(n), t?.richText?.length ? ft(r, t.richText) : r.textContent = t ? dt(t.value, t.numfmt) : "", t && (Lt(r, t), t.wrapText && (r.style.whiteSpace = "normal")), r;
649
+ r.className = "cell", r.dataset.row = String(e), r.dataset.col = String(o);
650
+ const s = document.createElement("div");
651
+ return s.className = "cell-content", t?.richText?.length ? wt(s, t.richText.map((c) => ({ ...c, underline: c.underline ?? t.underline }))) : s.textContent = t ? mt(t.value, t.numfmt, t.valueType, t.date1904 ?? n) : "", r.appendChild(s), t?.formula && t.cachedValuePresent === !1 && (r.dataset.missingFormulaCache = "true", r.title = "此公式没有保存计算结果"), t && (Wt(r, t), t.wrapText && (r.style.whiteSpace = "pre-wrap")), r;
509
652
  }
510
- function lt(t) {
653
+ function ct(t) {
511
654
  const e = document.createElement("div");
512
- e.className = t.fitCell ? "sheet-image sheet-image-cell" : "sheet-image", e.style.gridColumn = t.toCol ? `${t.col} / span ${Math.max(1, t.toCol - t.col + 1)}` : `${t.col}`, e.style.gridRow = t.toRow ? `${t.row} / span ${Math.max(1, t.toRow - t.row + 1)}` : `${t.row}`, !t.fitCell && !t.toCol && t.widthPx && (e.style.width = `${t.widthPx}px`), !t.fitCell && !t.toRow && t.heightPx && (e.style.height = `${t.heightPx}px`);
513
- const n = document.createElement("img");
514
- return n.src = t.data, n.alt = t.name, n.draggable = !1, e.appendChild(n), e;
655
+ e.className = t.fitCell ? "sheet-image sheet-image-cell" : "sheet-image", e.style.transform = ut(t), !t.fitCell && !t.toCol && t.widthPx && (e.style.width = `${t.widthPx}px`), !t.fitCell && !t.toRow && t.heightPx && (e.style.height = `${t.heightPx}px`);
656
+ const o = document.createElement("img");
657
+ if (o.src = t.data, o.alt = t.name, o.draggable = !1, o.style.objectFit = t.fitCell ? "contain" : "fill", t.crop) {
658
+ const { left: n, top: r, right: s, bottom: c } = t.crop, a = 1 - n - s, d = 1 - r - c;
659
+ ![n, r, s, c, 100 / a, 100 / d].every(Number.isFinite) || a <= 0 || d <= 0 ? (e.dataset.invalidCrop = "true", o.style.display = "none") : (o.style.position = "absolute", o.style.objectFit = "fill", o.style.width = `${100 / a}%`, o.style.height = `${100 / d}%`, o.style.left = `${-n * 100 / a}%`, o.style.top = `${-r * 100 / d}%`);
660
+ }
661
+ return e.appendChild(o), e;
515
662
  }
516
- function ct(t) {
663
+ function ut(t) {
664
+ return `${t.rotation ? `rotate(${t.rotation}deg)` : ""} scale(${t.flipH ? -1 : 1}, ${t.flipV ? -1 : 1})`;
665
+ }
666
+ function dt(t) {
517
667
  const e = document.createElement("div");
518
- e.className = "sheet-shape", e.dataset.geometry = t.geometry, e.setAttribute("aria-label", t.name || "形状"), e.style.gridColumn = t.toCol ? `${t.col} / span ${Math.max(1, t.toCol - t.col + 1)}` : `${t.col}`, e.style.gridRow = t.toRow ? `${t.row} / span ${Math.max(1, t.toRow - t.row + 1)}` : `${t.row}`, !t.toCol && t.widthPx && (e.style.width = `${t.widthPx}px`), !t.toRow && t.heightPx && (e.style.height = `${t.heightPx}px`), (t.offsetXPx || t.offsetYPx) && (e.style.transform = `translate(${t.offsetXPx}px, ${t.offsetYPx}px)`), t.fill && (e.style.backgroundColor = t.fill), (t.lineColor || t.lineWidthPx) && (e.style.borderColor = t.lineColor ?? "#666", e.style.borderWidth = `${Math.max(1, t.lineWidthPx ?? 1)}px`), St(e, t.geometry);
519
- for (const n of t.paragraphs) {
520
- const r = document.createElement("div");
521
- r.className = "sheet-shape-paragraph", ft(r, n.runs), e.appendChild(r);
668
+ e.className = "sheet-shape", e.dataset.geometry = t.geometry, e.setAttribute("aria-label", t.name || "形状"), !t.toCol && t.widthPx && (e.style.width = `${t.widthPx}px`), !t.toRow && t.heightPx && (e.style.height = `${t.heightPx}px`), (t.offsetXPx || t.offsetYPx) && (e.style.transform = `translate(${t.offsetXPx}px, ${t.offsetYPx}px)`), t.fill && (e.style.backgroundColor = t.fill), (t.lineColor || t.lineWidthPx) && (e.style.borderColor = t.lineColor ?? "#666", e.style.borderWidth = `${Math.max(0, t.lineWidthPx ?? 1)}px`), Ut(e, t.geometry);
669
+ for (const o of t.paragraphs) {
670
+ const n = document.createElement("div");
671
+ n.className = "sheet-shape-paragraph", wt(n, o.runs), e.appendChild(n);
522
672
  }
523
673
  return e;
524
674
  }
525
- function St(t, e) {
526
- const n = {
675
+ function Ut(t, e) {
676
+ const o = {
527
677
  diamond: "polygon(50% 0, 100% 50%, 50% 100%, 0 50%)",
528
678
  triangle: "polygon(50% 0, 100% 100%, 0 100%)",
529
679
  rtTriangle: "polygon(0 0, 100% 100%, 0 100%)",
@@ -537,52 +687,51 @@ function St(t, e) {
537
687
  parallelogram: "polygon(25% 0, 100% 0, 75% 100%, 0 100%)",
538
688
  trapezoid: "polygon(20% 0, 80% 0, 100% 100%, 0 100%)"
539
689
  };
540
- e === "ellipse" ? t.style.borderRadius = "50%" : e === "roundRect" || e.startsWith("round") ? t.style.borderRadius = "8px" : n[e] ? t.style.clipPath = n[e] : (e === "line" || e === "lineInv") && t.classList.add("sheet-shape-line");
690
+ e === "ellipse" ? t.style.borderRadius = "50%" : e === "roundRect" || e.startsWith("round") ? t.style.borderRadius = "8px" : o[e] ? t.style.clipPath = o[e] : (e === "line" || e === "lineInv") && t.classList.add("sheet-shape-line");
541
691
  }
542
- function ft(t, e) {
543
- for (const n of e) {
544
- const r = document.createElement("span");
545
- r.textContent = n.text, n.fontName && (r.style.fontFamily = `"${n.fontName}", "PingFang SC", "Microsoft YaHei", sans-serif`), n.fontSize && (r.style.fontSize = `${n.fontSize}pt`), n.bold != null && (r.style.fontWeight = n.bold ? "700" : "400"), n.italic != null && (r.style.fontStyle = n.italic ? "italic" : "normal"), n.underline != null && (r.style.textDecoration = n.underline ? "underline" : "none"), n.fontColor && (r.style.color = n.fontColor), t.appendChild(r);
692
+ function wt(t, e) {
693
+ for (const o of e) {
694
+ const n = document.createElement("span");
695
+ n.textContent = o.text, o.fontName && (n.style.fontFamily = ot(o.fontName, "sans-serif")), o.fontSize && (n.style.fontSize = `${o.fontSize}pt`), o.bold != null && (n.style.fontWeight = o.bold ? "700" : "400"), o.italic != null && (n.style.fontStyle = o.italic ? "italic" : "normal"), o.underline != null && (n.style.textDecoration = o.underline ? "underline" : "none"), o.fontColor && (n.style.color = o.fontColor), t.appendChild(n);
546
696
  }
547
697
  }
548
- function Lt(t, e) {
549
- const n = [];
550
- if (e.fontName && (t.style.fontFamily = `"${e.fontName}", "PingFang SC", "Microsoft YaHei", sans-serif`), e.fontSize && (t.style.fontSize = `${e.fontSize}pt`), e.bold && (t.style.fontWeight = "700"), e.italic && (t.style.fontStyle = "italic"), e.underline && (t.style.textDecoration = "underline"), e.fontColor && (t.style.color = e.fontColor), e.fill && (t.style.background = e.fill), e.hAlign) {
551
- const r = Et[e.hAlign] ?? "start";
552
- e.vAlign === "Center" ? t.style.justifyContent = r === "end" ? "flex-end" : r === "center" ? "center" : "flex-start" : t.style.textAlign = r;
553
- }
554
- e.vAlign === "Center" && (t.style.display = "flex", t.style.alignItems = "center"), e.borderTop && (t.style.borderTop = _[e.borderTop] ?? _.thin), e.borderLeft && (t.style.borderLeft = _[e.borderLeft] ?? _.thin), e.borderRight && (t.style.borderRight = _[e.borderRight] ?? _.thin), e.borderBottom && (t.style.borderBottom = _[e.borderBottom] ?? _.thin), n.length && t.setAttribute("style", (t.getAttribute("style") ?? "") + n.join(";"));
698
+ function Wt(t, e) {
699
+ e.fontName && (t.style.fontFamily = ot(e.fontName, "sans-serif")), e.fontSize && (t.style.fontSize = `${e.fontSize}pt`), e.bold && (t.style.fontWeight = "700"), e.italic && (t.style.fontStyle = "italic"), e.underline && !e.richText?.length && (t.style.textDecoration = "underline"), e.fontColor && (t.style.color = e.fontColor), e.fill && (t.style.background = e.fill);
700
+ const o = e.hAlign ? At[e.hAlign] : void 0;
701
+ t.style.textAlign = o ?? (e.valueType === "number" || e.valueType === "date" ? "end" : e.valueType === "boolean" || e.valueType === "error" ? "center" : "start"), t.style.justifyContent = e.vAlign === "Top" ? "flex-start" : e.vAlign === "Center" ? "center" : "flex-end", (e.hAlign === "Justify" || e.hAlign === "Distributed") && (t.style.textAlign = "justify");
702
+ const n = Mt(e.value, e.numfmt, e.valueType);
703
+ n && (t.style.color = n), e.borderTop && (t.style.borderTop = Y[e.borderTop] ?? Y.thin), e.borderLeft && (t.style.borderLeft = Y[e.borderLeft] ?? Y.thin), e.borderRight && (t.style.borderRight = Y[e.borderRight] ?? Y.thin), e.borderBottom && (t.style.borderBottom = Y[e.borderBottom] ?? Y.thin), e.borderTopColor && (t.style.borderTopColor = e.borderTopColor), e.borderLeftColor && (t.style.borderLeftColor = e.borderLeftColor), e.borderRightColor && (t.style.borderRightColor = e.borderRightColor), e.borderBottomColor && (t.style.borderBottomColor = e.borderBottomColor);
555
704
  }
556
- function At(t = {}) {
557
- const e = new URL("" + new URL("assets/excel/worker.js?no-inline", import.meta.url).href, import.meta.url), n = new URL("" + new URL("assets/excel/excel_view_rs_bg.wasm?no-inline", import.meta.url).href, import.meta.url), r = t.assets?.baseUrl ? new URL(String(t.assets.baseUrl), document.baseURI) : void 0;
558
- r && !r.pathname.endsWith("/") && (r.pathname += "/");
559
- const i = (m, u, R) => m ? new URL(m, document.baseURI) : r ? new URL(u, r) : R, s = i(t.assets?.excel?.workerUrl, "excel/worker.js", e), f = i(t.assets?.excel?.wasmUrl, "excel/excel_view_rs_bg.wasm", n).href, w = wt({
705
+ function Ht(t = {}) {
706
+ const e = new URL("" + new URL("assets/excel/worker.js?no-inline", import.meta.url).href, import.meta.url), o = new URL("" + new URL("assets/excel/excel_view_rs_bg.wasm?no-inline", import.meta.url).href, import.meta.url), n = t.assets?.baseUrl ? new URL(String(t.assets.baseUrl), document.baseURI) : void 0;
707
+ n && !n.pathname.endsWith("/") && (n.pathname += "/");
708
+ const r = (d, x, v) => d ? new URL(d, document.baseURI) : n ? new URL(x, n) : v, s = r(t.assets?.excel?.workerUrl, "excel/worker.js", e), c = r(t.assets?.excel?.wasmUrl, "excel/excel_view_rs_bg.wasm", o).href, a = vt({
560
709
  format: "xlsx",
561
710
  formats: ["xlsx", "xlsm"],
562
- workerData: { wasmUrl: f },
711
+ workerData: { wasmUrl: c },
563
712
  createWorker: () => t.workerFactory ? t.workerFactory(s, { type: "module" }) : new Worker(s, { type: "module" })
564
713
  });
565
714
  return {
566
- async open(m) {
567
- const u = await w.open(m);
715
+ async open(d) {
716
+ const x = await a.open(d);
568
717
  return {
569
- format: m.format ?? "xlsx",
570
- durationMs: u.durationMs,
571
- stats: { sheets: u.document.sheets.length },
572
- itemCount: u.document.sheets.length,
573
- warnings: u.warnings,
574
- document: u.document
718
+ format: d.format ?? "xlsx",
719
+ durationMs: x.durationMs,
720
+ stats: { sheets: x.document.sheets.length },
721
+ itemCount: x.document.sheets.length,
722
+ warnings: x.warnings,
723
+ document: x.document
575
724
  };
576
725
  },
577
- render(m, u, R, N) {
578
- const L = Rt(m, u, R ? (A) => {
579
- R(xt("RENDER_FAILED", A.message));
726
+ render(d, x, v, N) {
727
+ const p = Pt(d, x, v ? ($) => {
728
+ v($t("RENDER_FAILED", $.message));
580
729
  } : void 0, N);
581
- return { ...L, stats: { ...L.stats } };
730
+ return { ...p, stats: { ...p.stats } };
582
731
  },
583
- destroy: w.destroy
732
+ destroy: a.destroy
584
733
  };
585
734
  }
586
735
  export {
587
- At as createExcelAdapter
736
+ Ht as createExcelAdapter
588
737
  };