@gridsheet/engine 3.3.0
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/LICENSE +190 -0
- package/README.md +50 -0
- package/dist/constants.d.ts +21 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/formula/evaluator.d.ts +135 -0
- package/dist/formula/evaluator.d.ts.map +1 -0
- package/dist/formula/formula-error.d.ts +10 -0
- package/dist/formula/formula-error.d.ts.map +1 -0
- package/dist/formula/functions/__async.d.ts +67 -0
- package/dist/formula/functions/__async.d.ts.map +1 -0
- package/dist/formula/functions/__base.d.ts +120 -0
- package/dist/formula/functions/__base.d.ts.map +1 -0
- package/dist/formula/functions/__utils.d.ts +30 -0
- package/dist/formula/functions/__utils.d.ts.map +1 -0
- package/dist/formula/functions/abs.d.ts +9 -0
- package/dist/formula/functions/abs.d.ts.map +1 -0
- package/dist/formula/functions/add.d.ts +10 -0
- package/dist/formula/functions/add.d.ts.map +1 -0
- package/dist/formula/functions/and.d.ts +9 -0
- package/dist/formula/functions/and.d.ts.map +1 -0
- package/dist/formula/functions/arrayformula.d.ts +12 -0
- package/dist/formula/functions/arrayformula.d.ts.map +1 -0
- package/dist/formula/functions/average.d.ts +9 -0
- package/dist/formula/functions/average.d.ts.map +1 -0
- package/dist/formula/functions/concat.d.ts +9 -0
- package/dist/formula/functions/concat.d.ts.map +1 -0
- package/dist/formula/functions/count.d.ts +9 -0
- package/dist/formula/functions/count.d.ts.map +1 -0
- package/dist/formula/functions/counta.d.ts +9 -0
- package/dist/formula/functions/counta.d.ts.map +1 -0
- package/dist/formula/functions/divide.d.ts +10 -0
- package/dist/formula/functions/divide.d.ts.map +1 -0
- package/dist/formula/functions/eq.d.ts +9 -0
- package/dist/formula/functions/eq.d.ts.map +1 -0
- package/dist/formula/functions/gt.d.ts +9 -0
- package/dist/formula/functions/gt.d.ts.map +1 -0
- package/dist/formula/functions/gte.d.ts +9 -0
- package/dist/formula/functions/gte.d.ts.map +1 -0
- package/dist/formula/functions/if.d.ts +9 -0
- package/dist/formula/functions/if.d.ts.map +1 -0
- package/dist/formula/functions/iferror.d.ts +10 -0
- package/dist/formula/functions/iferror.d.ts.map +1 -0
- package/dist/formula/functions/len.d.ts +9 -0
- package/dist/formula/functions/len.d.ts.map +1 -0
- package/dist/formula/functions/lt.d.ts +9 -0
- package/dist/formula/functions/lt.d.ts.map +1 -0
- package/dist/formula/functions/lte.d.ts +9 -0
- package/dist/formula/functions/lte.d.ts.map +1 -0
- package/dist/formula/functions/max.d.ts +9 -0
- package/dist/formula/functions/max.d.ts.map +1 -0
- package/dist/formula/functions/min.d.ts +9 -0
- package/dist/formula/functions/min.d.ts.map +1 -0
- package/dist/formula/functions/minus.d.ts +10 -0
- package/dist/formula/functions/minus.d.ts.map +1 -0
- package/dist/formula/functions/multiply.d.ts +9 -0
- package/dist/formula/functions/multiply.d.ts.map +1 -0
- package/dist/formula/functions/ne.d.ts +9 -0
- package/dist/formula/functions/ne.d.ts.map +1 -0
- package/dist/formula/functions/not.d.ts +9 -0
- package/dist/formula/functions/not.d.ts.map +1 -0
- package/dist/formula/functions/now.d.ts +9 -0
- package/dist/formula/functions/now.d.ts.map +1 -0
- package/dist/formula/functions/or.d.ts +9 -0
- package/dist/formula/functions/or.d.ts.map +1 -0
- package/dist/formula/functions/power.d.ts +9 -0
- package/dist/formula/functions/power.d.ts.map +1 -0
- package/dist/formula/functions/sum.d.ts +9 -0
- package/dist/formula/functions/sum.d.ts.map +1 -0
- package/dist/formula/functions/uminus.d.ts +9 -0
- package/dist/formula/functions/uminus.d.ts.map +1 -0
- package/dist/formula/mapping.d.ts +11 -0
- package/dist/formula/mapping.d.ts.map +1 -0
- package/dist/formula/solver.d.ts +39 -0
- package/dist/formula/solver.d.ts.map +1 -0
- package/dist/index.d.ts +31 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +4888 -0
- package/dist/index.js.map +1 -0
- package/dist/lib/autofill.d.ts +22 -0
- package/dist/lib/autofill.d.ts.map +1 -0
- package/dist/lib/book.d.ts +141 -0
- package/dist/lib/book.d.ts.map +1 -0
- package/dist/lib/cell.d.ts +17 -0
- package/dist/lib/cell.d.ts.map +1 -0
- package/dist/lib/coords.d.ts +22 -0
- package/dist/lib/coords.d.ts.map +1 -0
- package/dist/lib/date.d.ts +2 -0
- package/dist/lib/date.d.ts.map +1 -0
- package/dist/lib/filter.d.ts +7 -0
- package/dist/lib/filter.d.ts.map +1 -0
- package/dist/lib/label.d.ts +4 -0
- package/dist/lib/label.d.ts.map +1 -0
- package/dist/lib/operation.d.ts +31 -0
- package/dist/lib/operation.d.ts.map +1 -0
- package/dist/lib/palette.d.ts +2 -0
- package/dist/lib/palette.d.ts.map +1 -0
- package/dist/lib/reference.d.ts +19 -0
- package/dist/lib/reference.d.ts.map +1 -0
- package/dist/lib/sheet.d.ts +626 -0
- package/dist/lib/sheet.d.ts.map +1 -0
- package/dist/lib/sheet_utils.d.ts +52 -0
- package/dist/lib/sheet_utils.d.ts.map +1 -0
- package/dist/lib/spatial.d.ts +79 -0
- package/dist/lib/spatial.d.ts.map +1 -0
- package/dist/lib/time.d.ts +29 -0
- package/dist/lib/time.d.ts.map +1 -0
- package/dist/policy/core.d.ts +161 -0
- package/dist/policy/core.d.ts.map +1 -0
- package/dist/policy/percentage.d.ts +3 -0
- package/dist/policy/percentage.d.ts.map +1 -0
- package/dist/policy/thousand_separator.d.ts +4 -0
- package/dist/policy/thousand_separator.d.ts.map +1 -0
- package/dist/sentinels.d.ts +41 -0
- package/dist/sentinels.d.ts.map +1 -0
- package/dist/types.d.ts +313 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/utils.d.ts +2 -0
- package/dist/utils.d.ts.map +1 -0
- package/package.json +63 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,4888 @@
|
|
|
1
|
+
import H from "dayjs";
|
|
2
|
+
import ds from "dayjs/plugin/utc.js";
|
|
3
|
+
import fs from "dayjs/plugin/timezone.js";
|
|
4
|
+
const ps = 20, J = 24, jt = 90, Dr = 500, vr = 1e3, Re = 24, _e = 50, kr = 5, Pr = 5, $r = 5, Lr = 10, $e = 1e3, Zt = 86400, ms = "YYYY-MM-DDTHH:mm:ss.SSSZ", gs = {
|
|
5
|
+
startY: -1,
|
|
6
|
+
startX: -1,
|
|
7
|
+
endY: -1,
|
|
8
|
+
endX: -1
|
|
9
|
+
}, ys = new Date(1900, 0, 1), Ft = "default", Dt = "defaultCol", vt = "defaultRow", qt = "ABCDEFGHIJKLMNOPQRSTUVWXYZ", gt = /* @__PURE__ */ new Map(), yt = /* @__PURE__ */ new Map(), ws = (r, t = $e) => {
|
|
10
|
+
const e = gt.get(--r);
|
|
11
|
+
if (e != null)
|
|
12
|
+
return e;
|
|
13
|
+
if (r === 0)
|
|
14
|
+
return "";
|
|
15
|
+
let s = r, i = "";
|
|
16
|
+
do
|
|
17
|
+
i = qt[--s % 26] + i, s = Math.floor(s / 26);
|
|
18
|
+
while (s > 0);
|
|
19
|
+
gt.set(r, i);
|
|
20
|
+
const n = gt.keys();
|
|
21
|
+
for (let o = n.next(); gt.size > t; o = n.next())
|
|
22
|
+
gt.delete(o.value);
|
|
23
|
+
return i;
|
|
24
|
+
}, xs = (r, t = $e) => {
|
|
25
|
+
const e = yt.get(r);
|
|
26
|
+
if (e != null)
|
|
27
|
+
return e;
|
|
28
|
+
if (r === "")
|
|
29
|
+
return 0;
|
|
30
|
+
const s = r;
|
|
31
|
+
let i = 0;
|
|
32
|
+
for (let o = 0; o < s.length; o++) {
|
|
33
|
+
const a = s[s.length - o - 1], l = qt.indexOf(a) + 1;
|
|
34
|
+
i += qt.length ** o * l;
|
|
35
|
+
}
|
|
36
|
+
yt.set(r, i);
|
|
37
|
+
const n = yt.keys();
|
|
38
|
+
for (let o = n.next(); yt.size > t; o = n.next())
|
|
39
|
+
yt.delete(o.value);
|
|
40
|
+
return i;
|
|
41
|
+
}, W = (r) => {
|
|
42
|
+
if (r === 0)
|
|
43
|
+
return "";
|
|
44
|
+
const t = ws(r + 1);
|
|
45
|
+
return r < 0 ? `$${t}` : t;
|
|
46
|
+
}, _t = (r, t = !1) => {
|
|
47
|
+
const e = xs(r.toUpperCase());
|
|
48
|
+
return t ? -e : e;
|
|
49
|
+
}, Et = (r) => r === 0 ? "" : r < 0 ? `$${r}` : String(r), bs = (r, t = !1) => (typeof r == "string" && (r = parseInt(r, 10)), t ? -r : r), D = ({ y: r, x: t, absX: e, absY: s }) => {
|
|
50
|
+
if (t === -1 && r === -1)
|
|
51
|
+
return "?";
|
|
52
|
+
const i = t === void 0 ? "" : t === 0 ? "0" : `${e ? "$" : ""}${W(t)}`, n = r === void 0 ? "" : r === 0 ? "0" : `${s ? "$" : ""}${Et(r)}`;
|
|
53
|
+
return `${i}${n}`;
|
|
54
|
+
}, N = (r) => {
|
|
55
|
+
const t = r.match(/(\$)?([a-zA-Z]*)(\$)?([0-9]*)/);
|
|
56
|
+
if (t == null)
|
|
57
|
+
return { y: -1, x: -1 };
|
|
58
|
+
const [, e, s, i, n] = t.slice(), [o, a] = [e != null, i != null];
|
|
59
|
+
return s === "" && n === "" ? { y: -1, x: -1, absX: !1, absY: !1 } : { y: bs(n) || 0, x: _t(s) || 0, absX: o, absY: a };
|
|
60
|
+
}, Le = (r, t, e) => {
|
|
61
|
+
const s = r.match(/([A-Z]*)([0-9]*)/);
|
|
62
|
+
if (s == null)
|
|
63
|
+
return r;
|
|
64
|
+
const [, i, n] = s.slice();
|
|
65
|
+
return `${t ? "$" : ""}${i.toUpperCase()}${e ? "$" : ""}${n}`;
|
|
66
|
+
}, Hr = (r) => `0${r}`, Yr = (r) => typeof r == "number" ? `${W(r)}0` : `${r.toUpperCase()}0`, Br = (r) => r.replace(/\$/g, ""), He = (r, t = !1, e = !1) => `${t ? "$" : ""}#${r}${e ? "$" : ""}`, Ur = (r, t) => {
|
|
67
|
+
const { rows: e, cols: s } = Ae(r), { rows: i, cols: n } = Ae(t);
|
|
68
|
+
return {
|
|
69
|
+
rows: e > i ? e : i,
|
|
70
|
+
cols: s > n ? s : n
|
|
71
|
+
};
|
|
72
|
+
}, Ss = (r, t) => {
|
|
73
|
+
const e = { ...r };
|
|
74
|
+
return t.left < r.left && (e.left = t.left), t.right > r.right && (e.right = t.right), t.top < r.top && (e.top = t.top), t.bottom > r.bottom && (e.bottom = t.bottom), e;
|
|
75
|
+
}, Rs = (r) => {
|
|
76
|
+
if (r.endY === -1 || r.endX === -1)
|
|
77
|
+
return { top: -1, left: -1, bottom: -1, right: -1 };
|
|
78
|
+
const [t, e] = r.startY < r.endY ? [r.startY, r.endY] : [r.endY, r.startY], [s, i] = r.startX < r.endX ? [r.startX, r.endX] : [r.endX, r.startX];
|
|
79
|
+
return { top: t, left: s, bottom: e, right: i };
|
|
80
|
+
}, Ee = (r) => ({
|
|
81
|
+
startY: r.top,
|
|
82
|
+
startX: r.left,
|
|
83
|
+
endY: r.bottom,
|
|
84
|
+
endX: r.right
|
|
85
|
+
}), zr = (r) => {
|
|
86
|
+
const { top: t, left: e, bottom: s, right: i } = r;
|
|
87
|
+
if (t === s && e === i)
|
|
88
|
+
return D({ y: t, x: e });
|
|
89
|
+
const n = D({ y: t, x: e }), o = D({ y: s, x: i });
|
|
90
|
+
return `${n}:${o}`;
|
|
91
|
+
}, Vr = (r, t) => r.start === -1 || r.end === -1 ? !1 : r.start <= t && t <= r.end || r.end <= t && t <= r.start, Wr = (r, t) => {
|
|
92
|
+
if (r.top === -1 || r.left === -1 || r.bottom === -1 || r.right === -1)
|
|
93
|
+
return !1;
|
|
94
|
+
const { y: e, x: s } = t, { top: i, left: n, bottom: o, right: a } = r;
|
|
95
|
+
return i <= e && e <= o && n <= s && s <= a;
|
|
96
|
+
}, _s = (r) => r.endY === -1 || r.endX === -1 ? { rows: 0, cols: 0 } : {
|
|
97
|
+
rows: Math.abs(r.startY - r.endY),
|
|
98
|
+
cols: Math.abs(r.startX - r.endX)
|
|
99
|
+
}, Xr = (r) => r.endY === -1 || r.endX === -1 ? { rows: 1, cols: 1 } : {
|
|
100
|
+
rows: 1 + Math.abs(r.startY - r.endY),
|
|
101
|
+
cols: 1 + Math.abs(r.startX - r.endX)
|
|
102
|
+
}, Ae = (r) => ({
|
|
103
|
+
rows: Math.abs(r.top - r.bottom),
|
|
104
|
+
cols: Math.abs(r.left - r.right)
|
|
105
|
+
}), Kt = (r) => ({
|
|
106
|
+
rows: 1 + Math.abs(r.top - r.bottom),
|
|
107
|
+
cols: 1 + Math.abs(r.left - r.right)
|
|
108
|
+
}), Nt = ({ base: r = 0, matrix: t }) => {
|
|
109
|
+
const e = t.length;
|
|
110
|
+
return e === 0 ? { rows: 0, cols: 0 } : { rows: r + e, cols: r + t[0].length };
|
|
111
|
+
}, jr = (r, t, e = 1) => Array.from({ length: (t - r - 1) / e + 1 }, (s, i) => r + i * e), Gr = (r, t) => {
|
|
112
|
+
const e = [];
|
|
113
|
+
return r.forEach((s) => {
|
|
114
|
+
const i = [];
|
|
115
|
+
t.forEach((n) => {
|
|
116
|
+
i.push(s[n]);
|
|
117
|
+
}), e.push(i);
|
|
118
|
+
}), e;
|
|
119
|
+
}, Zr = (r, t) => {
|
|
120
|
+
const e = [];
|
|
121
|
+
return r.forEach((s) => {
|
|
122
|
+
const i = {};
|
|
123
|
+
s.forEach((n, o) => {
|
|
124
|
+
if (o >= t.length)
|
|
125
|
+
return;
|
|
126
|
+
const a = t[o];
|
|
127
|
+
i[a] = n;
|
|
128
|
+
}), e.push(i);
|
|
129
|
+
}), e;
|
|
130
|
+
}, se = (r, t, e) => [...Array(r)].map(() => Array(t).fill(e)), qr = ({
|
|
131
|
+
cells: r = {},
|
|
132
|
+
ensured: t = {},
|
|
133
|
+
matrix: e = [],
|
|
134
|
+
flattenAs: s = "value",
|
|
135
|
+
origin: i = "A1"
|
|
136
|
+
}) => Es({
|
|
137
|
+
cells: r,
|
|
138
|
+
ensured: t,
|
|
139
|
+
matrices: { [i]: e },
|
|
140
|
+
flattenAs: s
|
|
141
|
+
}), Es = ({
|
|
142
|
+
cells: r = {},
|
|
143
|
+
ensured: t = {},
|
|
144
|
+
matrices: e = {},
|
|
145
|
+
flattenAs: s = "value"
|
|
146
|
+
} = {}) => {
|
|
147
|
+
const i = Object.keys(r), a = Object.values(e).reduce((c, f) => {
|
|
148
|
+
var d;
|
|
149
|
+
return c + f.length * (((d = f[0]) == null ? void 0 : d.length) ?? 0);
|
|
150
|
+
}, 0) > 1e5;
|
|
151
|
+
a ? (Object.defineProperty(r, "__matrices", { value: e, configurable: !0 }), Object.defineProperty(r, "__flattenAs", { value: s, configurable: !0 })) : As({ cells: r, flattenAs: s, matrices: e });
|
|
152
|
+
const { numRows: l, numCols: u } = Object.assign({ numRows: 1, numCols: 1 }, t), h = D({ y: l, x: u });
|
|
153
|
+
return r[h] == null && (r[h] = {}), a && (i.push(h), Object.defineProperty(r, "__userKeys", { value: i, configurable: !0 })), r;
|
|
154
|
+
}, As = ({
|
|
155
|
+
cells: r = {},
|
|
156
|
+
matrices: t = {},
|
|
157
|
+
flattenAs: e
|
|
158
|
+
}) => (Object.keys(t).forEach((s) => {
|
|
159
|
+
const i = t[s], { y: n, x: o } = N(s), a = [];
|
|
160
|
+
for (let l = 0; l < i.length; l++) {
|
|
161
|
+
const u = i[l], h = String(n + l);
|
|
162
|
+
for (let c = 0; c < u.length; c++) {
|
|
163
|
+
a[c] == null && (a[c] = W(o + c));
|
|
164
|
+
const f = a[c] + h;
|
|
165
|
+
if (e) {
|
|
166
|
+
const d = r[f];
|
|
167
|
+
d ? e in d || (d[e] = u[c]) : r[f] = { [e]: u[c] };
|
|
168
|
+
} else
|
|
169
|
+
r[f] = u[c];
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
}), r), Cs = (r = {}, t) => {
|
|
173
|
+
let [e, s] = [0, 0];
|
|
174
|
+
return (t ?? Object.keys(r)).forEach((i) => {
|
|
175
|
+
if (i === Ft || i === Dt || i === vt)
|
|
176
|
+
return;
|
|
177
|
+
const { y: n, x: o } = N(i);
|
|
178
|
+
e < n && (e = n), s < o && (s = o);
|
|
179
|
+
}), { numRows: e, numCols: s };
|
|
180
|
+
}, Kr = (r, t) => {
|
|
181
|
+
const e = [];
|
|
182
|
+
for (let s = r; s <= t; s++)
|
|
183
|
+
e.push(s);
|
|
184
|
+
return e;
|
|
185
|
+
}, Is = (r, t) => (r.left === -1 && (r = {
|
|
186
|
+
left: t.x,
|
|
187
|
+
top: t.y,
|
|
188
|
+
right: t.x,
|
|
189
|
+
bottom: t.y
|
|
190
|
+
}), r), Ts = (r) => {
|
|
191
|
+
if (r.indexOf(":") === -1)
|
|
192
|
+
return [r];
|
|
193
|
+
const t = [];
|
|
194
|
+
if (/^\d+\:\d+$/.test(r)) {
|
|
195
|
+
const [h, c] = r.split(":").map(Number);
|
|
196
|
+
for (let f = h; f <= c; f++)
|
|
197
|
+
t.push(`${f}`);
|
|
198
|
+
return t;
|
|
199
|
+
}
|
|
200
|
+
const s = r.match(/^([A-Z]*)(\d+)?\:([A-Z]*)(\d+)?$/);
|
|
201
|
+
if (!s)
|
|
202
|
+
return console.error("Invalid range format", r), [r];
|
|
203
|
+
const [, i, n, o, a] = s, l = i ? _t(i) : 1, u = o ? _t(o) : 1;
|
|
204
|
+
for (let h = l; h <= u; h++) {
|
|
205
|
+
const c = i || o ? W(h) : "";
|
|
206
|
+
if (n && a)
|
|
207
|
+
for (let f = Number(n); f <= Number(a); f++)
|
|
208
|
+
t.push(`${c}${f}`);
|
|
209
|
+
else !n && !a && t.push(c);
|
|
210
|
+
}
|
|
211
|
+
return t;
|
|
212
|
+
}, Jr = (r) => {
|
|
213
|
+
const t = _s(r);
|
|
214
|
+
return t.rows + t.cols === 0 ? { startY: -1, startX: -1, endY: -1, endX: -1 } : { ...r };
|
|
215
|
+
}, Qr = (r, t, e, s) => {
|
|
216
|
+
for (; r <= t; ) {
|
|
217
|
+
const i = Math.floor((r + t) / 2);
|
|
218
|
+
e(i) ? s ? t = i - 1 : r = i + 1 : s ? r = i + 1 : t = i - 1;
|
|
219
|
+
}
|
|
220
|
+
return s ? r : t;
|
|
221
|
+
}, tn = (r) => {
|
|
222
|
+
if (r.length === 0)
|
|
223
|
+
return [];
|
|
224
|
+
const t = r.map((o) => {
|
|
225
|
+
const { y: a, x: l } = N(o);
|
|
226
|
+
return { y: a, x: l };
|
|
227
|
+
}), e = (o, a) => `${o},${a}`, s = new Set(t.map((o) => e(o.y, o.x))), i = /* @__PURE__ */ new Set(), n = [];
|
|
228
|
+
for (const o of t) {
|
|
229
|
+
const a = e(o.y, o.x);
|
|
230
|
+
if (i.has(a))
|
|
231
|
+
continue;
|
|
232
|
+
let l = o.y, u = o.x, h = o.y, c = o.x;
|
|
233
|
+
const f = [o];
|
|
234
|
+
for (i.add(a); f.length > 0; ) {
|
|
235
|
+
const { y: d, x: p } = f.shift();
|
|
236
|
+
d < l && (l = d), d > h && (h = d), p < u && (u = p), p > c && (c = p);
|
|
237
|
+
for (const [m, g] of [
|
|
238
|
+
[0, 1],
|
|
239
|
+
[0, -1],
|
|
240
|
+
[1, 0],
|
|
241
|
+
[-1, 0]
|
|
242
|
+
]) {
|
|
243
|
+
const y = e(d + m, p + g);
|
|
244
|
+
s.has(y) && !i.has(y) && (i.add(y), f.push({ y: d + m, x: p + g }));
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
n.push({ top: l, left: u, bottom: h, right: c });
|
|
248
|
+
}
|
|
249
|
+
return n;
|
|
250
|
+
}, en = (r, t = !0) => {
|
|
251
|
+
const e = /* @__PURE__ */ new Set(), s = [];
|
|
252
|
+
for (const i of r) {
|
|
253
|
+
const { x: n } = N(i);
|
|
254
|
+
e.has(n) || (e.add(n), s.push(n));
|
|
255
|
+
}
|
|
256
|
+
return t === !0 ? s.sort((i, n) => i - n) : t === !1 && s.sort((i, n) => n - i), s;
|
|
257
|
+
}, sn = (r, t = !0) => {
|
|
258
|
+
const e = /* @__PURE__ */ new Set(), s = [];
|
|
259
|
+
for (const i of r) {
|
|
260
|
+
const { y: n } = N(i);
|
|
261
|
+
e.has(n) || (e.add(n), s.push(n));
|
|
262
|
+
}
|
|
263
|
+
return t === !0 ? s.sort((i, n) => i - n) : t === !1 && s.sort((i, n) => n - i), s;
|
|
264
|
+
}, rn = (r) => r.startY === -1 || r.startX === -1 || r.endY === -1 || r.endX === -1, et = 864e5;
|
|
265
|
+
class b {
|
|
266
|
+
constructor(t, e = "HH:mm:ss") {
|
|
267
|
+
this.__gsType = "Time", this.days = t, this.format = e;
|
|
268
|
+
}
|
|
269
|
+
add(t) {
|
|
270
|
+
return new Date(t.getTime() + this.days * et);
|
|
271
|
+
}
|
|
272
|
+
sub(t) {
|
|
273
|
+
return new Date(t.getTime() - this.days * et);
|
|
274
|
+
}
|
|
275
|
+
stringify(t) {
|
|
276
|
+
const e = this.toMilliseconds(), s = Math.abs(e), i = e < 0 ? "-" : "", n = s % 1e3;
|
|
277
|
+
let o = Math.floor(s / 1e3);
|
|
278
|
+
const a = o % 60;
|
|
279
|
+
o = Math.floor(o / 60);
|
|
280
|
+
const l = o % 60, u = Math.floor(o / 60);
|
|
281
|
+
let c = t ?? (n === 0 ? "HH:mm:ss" : "HH:mm:ss.SSS");
|
|
282
|
+
return c = c.replace("HH", i + String(u).padStart(2, "0")), c = c.replace("H", i + String(u)), c = c.replace("mm", String(l).padStart(2, "0")), c = c.replace("ss", String(a).padStart(2, "0")), c = c.replace("SSS", String(n).padStart(3, "0")), c = c.replace("SS", String(n).padStart(3, "0").substring(0, 2)), c = c.replace("S", String(n).padStart(3, "0").substring(0, 1)), c;
|
|
283
|
+
}
|
|
284
|
+
toMilliseconds() {
|
|
285
|
+
return this.days * et;
|
|
286
|
+
}
|
|
287
|
+
toDate() {
|
|
288
|
+
return new Date(ys.getTime() + this.days * et);
|
|
289
|
+
}
|
|
290
|
+
toJSON() {
|
|
291
|
+
return { __gsType: "Time", days: this.days, format: this.format };
|
|
292
|
+
}
|
|
293
|
+
toString() {
|
|
294
|
+
return this.stringify();
|
|
295
|
+
}
|
|
296
|
+
static create(t = 0, e = 0, s = 0, i = 0) {
|
|
297
|
+
const n = t * 36e5 + e * 6e4 + s * 1e3 + i;
|
|
298
|
+
return new b(n / et);
|
|
299
|
+
}
|
|
300
|
+
static fromDate(t) {
|
|
301
|
+
const e = t.getHours() * 36e5 + t.getMinutes() * 6e4 + t.getSeconds() * 1e3 + t.getMilliseconds();
|
|
302
|
+
return new b(e / et);
|
|
303
|
+
}
|
|
304
|
+
static fromDates(t, e) {
|
|
305
|
+
return new b((t.getTime() - e.getTime()) / et);
|
|
306
|
+
}
|
|
307
|
+
static fromObject(t) {
|
|
308
|
+
return new b(t.days, t.format);
|
|
309
|
+
}
|
|
310
|
+
static is(t) {
|
|
311
|
+
return t instanceof b || (t == null ? void 0 : t.__gsType) === "Time";
|
|
312
|
+
}
|
|
313
|
+
static ensure(t) {
|
|
314
|
+
return t instanceof b ? t : (t == null ? void 0 : t.__gsType) === "Time" ? b.fromObject(t) : b.create();
|
|
315
|
+
}
|
|
316
|
+
static parse(t, e, s = !1) {
|
|
317
|
+
if (e != null) {
|
|
318
|
+
const i = Ms(e), n = t.match(i);
|
|
319
|
+
if (n != null && n.groups)
|
|
320
|
+
return b.create(
|
|
321
|
+
Number(n.groups.HH || n.groups.H || 0),
|
|
322
|
+
Number(n.groups.mm || n.groups.m || 0),
|
|
323
|
+
Number(n.groups.ss || n.groups.s || 0),
|
|
324
|
+
Number(n.groups.SSS || n.groups.SS || n.groups.S || 0)
|
|
325
|
+
);
|
|
326
|
+
}
|
|
327
|
+
if (!s) {
|
|
328
|
+
{
|
|
329
|
+
const i = t.match(/^([+-]?)(\d+):(\d{2})$/);
|
|
330
|
+
if (i) {
|
|
331
|
+
const [, n, o, a] = i, l = n === "-" ? -1 : 1;
|
|
332
|
+
return b.create(l * Number(o), l * Number(a));
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
{
|
|
336
|
+
const i = t.match(/^([+-]?)(\d+):(\d{2}):(\d{2})$/);
|
|
337
|
+
if (i) {
|
|
338
|
+
const [, n, o, a, l] = i, u = n === "-" ? -1 : 1;
|
|
339
|
+
return b.create(u * Number(o), u * Number(a), u * Number(l));
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
{
|
|
343
|
+
const i = t.match(/^([+-]?)(\d+):(\d{2}):(\d{2})\.(\d+)$/);
|
|
344
|
+
if (i) {
|
|
345
|
+
const [, n, o, a, l, u] = i, h = n === "-" ? -1 : 1;
|
|
346
|
+
return b.create(h * Number(o), h * Number(a), h * Number(l), h * Number(u));
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
const Ce = {
|
|
353
|
+
HH: { group: "HH", pattern: "(?<HH>\\d+)" },
|
|
354
|
+
H: { group: "H", pattern: "(?<HH>\\d+)" },
|
|
355
|
+
mm: { group: "mm", pattern: "(?<mm>[0-5]\\d)" },
|
|
356
|
+
m: { group: "m", pattern: "(?<m>\\d|[1-5]\\d)" },
|
|
357
|
+
ss: { group: "ss", pattern: "(?<ss>[0-5]\\d)" },
|
|
358
|
+
s: { group: "s", pattern: "(?<s>\\d|[1-5]\\d)" },
|
|
359
|
+
SSS: { group: "SSS", pattern: "(?<SSS>\\d{3})" },
|
|
360
|
+
SS: { group: "SS", pattern: "(?<SS>\\d{2})" },
|
|
361
|
+
S: { group: "S", pattern: "(?<S>\\d)" }
|
|
362
|
+
};
|
|
363
|
+
function Ms(r) {
|
|
364
|
+
const t = Object.keys(Ce).sort((n, o) => o.length - n.length), e = new RegExp(t.join("|"), "g"), i = r.replace(/[-\/\\^$*+?.()|[\]{}]/g, "\\$&").replace(e, (n) => {
|
|
365
|
+
var o;
|
|
366
|
+
return ((o = Ce[n]) == null ? void 0 : o.pattern) ?? n;
|
|
367
|
+
});
|
|
368
|
+
return new RegExp(`^${i}$`);
|
|
369
|
+
}
|
|
370
|
+
class x {
|
|
371
|
+
constructor(t, e, s) {
|
|
372
|
+
this.__gsType = "FormulaError", this.code = t, this.message = e, this.error = s;
|
|
373
|
+
}
|
|
374
|
+
static is(t) {
|
|
375
|
+
return t instanceof x || (t == null ? void 0 : t.__gsType) === "FormulaError";
|
|
376
|
+
}
|
|
377
|
+
toString() {
|
|
378
|
+
return this.code;
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
class ut {
|
|
382
|
+
constructor(t) {
|
|
383
|
+
this.code = t, this.__gsType = "Sentinel";
|
|
384
|
+
}
|
|
385
|
+
is(t) {
|
|
386
|
+
return ut.is(t, this.code);
|
|
387
|
+
}
|
|
388
|
+
static is(t, e) {
|
|
389
|
+
return t instanceof ut || (t == null ? void 0 : t.__gsType) === "Sentinel" ? e == null || t.code === e : !1;
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
const At = new ut("solving"), wt = new ut("none");
|
|
393
|
+
class k {
|
|
394
|
+
constructor(t) {
|
|
395
|
+
this.__gsType = "Pending", this.promise = t, this.timestamp = Date.now();
|
|
396
|
+
}
|
|
397
|
+
static is(t) {
|
|
398
|
+
return t instanceof k || (t == null ? void 0 : t.__gsType) === "Pending";
|
|
399
|
+
}
|
|
400
|
+
toString() {
|
|
401
|
+
return `<Pending #${this.timestamp}>`;
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
class B {
|
|
405
|
+
constructor(t) {
|
|
406
|
+
this.__gsType = "Spilling", this.matrix = this.ensure2D(t);
|
|
407
|
+
}
|
|
408
|
+
ensure2D(t) {
|
|
409
|
+
return t.length === 0 ? [] : Array.isArray(t[0]) ? t : [t];
|
|
410
|
+
}
|
|
411
|
+
static is(t) {
|
|
412
|
+
return t instanceof B || (t == null ? void 0 : t.__gsType) === "Spilling";
|
|
413
|
+
}
|
|
414
|
+
}
|
|
415
|
+
const Pt = (r, t = !0) => {
|
|
416
|
+
let e = r;
|
|
417
|
+
return t && e.startsWith("$") && (e = e.slice(1)), t && e.endsWith("$") && (e = e.slice(0, -1)), e.replace("#", "");
|
|
418
|
+
};
|
|
419
|
+
class rt {
|
|
420
|
+
constructor(t) {
|
|
421
|
+
this.ids = [], this.value = t;
|
|
422
|
+
}
|
|
423
|
+
}
|
|
424
|
+
class ie extends rt {
|
|
425
|
+
evaluate() {
|
|
426
|
+
return this.value;
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
class Os extends rt {
|
|
430
|
+
evaluate() {
|
|
431
|
+
throw new x("#REF!", "Reference does not exist.");
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
class Ns extends rt {
|
|
435
|
+
evaluate() {
|
|
436
|
+
throw new x("#NAME?", `Invalid ref: ${this.value}`);
|
|
437
|
+
}
|
|
438
|
+
}
|
|
439
|
+
class Ye extends rt {
|
|
440
|
+
constructor(t) {
|
|
441
|
+
super(t);
|
|
442
|
+
}
|
|
443
|
+
stringify() {
|
|
444
|
+
return this.value.toUpperCase();
|
|
445
|
+
}
|
|
446
|
+
evaluate({ sheet: t }) {
|
|
447
|
+
const e = dt(this.value, { sheet: t, dependency: "" });
|
|
448
|
+
if (e.sheet == null)
|
|
449
|
+
throw new x("#REF!", `Unknown sheet: ${e.sheetName}`);
|
|
450
|
+
if (e.addresses.length === 0)
|
|
451
|
+
throw new x("#REF!", `Invalid address: ${this.value}`);
|
|
452
|
+
const { y: s, x: i } = N(e.addresses[0]);
|
|
453
|
+
return e.sheet.trim({ top: s, left: i, bottom: s, right: i });
|
|
454
|
+
}
|
|
455
|
+
identify(t) {
|
|
456
|
+
const { slideY: e = 0, slideX: s = 0 } = t, i = dt(this.value, t);
|
|
457
|
+
if (i.sheet == null)
|
|
458
|
+
return this.value;
|
|
459
|
+
const n = i.addresses[0], { y: o, x: a, absX: l, absY: u } = N(n), h = {
|
|
460
|
+
y: o + e,
|
|
461
|
+
x: a + s,
|
|
462
|
+
absX: l,
|
|
463
|
+
absY: u
|
|
464
|
+
}, c = i.sheet.getId(h);
|
|
465
|
+
return c == null ? this.value : (this.ids = [c], `#${i.sheet.id}!${He(c, l, u)}`);
|
|
466
|
+
}
|
|
467
|
+
}
|
|
468
|
+
class Be extends rt {
|
|
469
|
+
stringify() {
|
|
470
|
+
return this.value.toUpperCase();
|
|
471
|
+
}
|
|
472
|
+
evaluate({ sheet: t }) {
|
|
473
|
+
const e = dt(this.value, { sheet: t, dependency: "" });
|
|
474
|
+
if (e.sheet == null)
|
|
475
|
+
throw new x("#REF!", `Unknown sheet: ${e.sheetName}`);
|
|
476
|
+
if (e.addresses.length === 0)
|
|
477
|
+
throw new x("#REF!", `Invalid address: ${this.value}`);
|
|
478
|
+
const s = e.sheet.rangeToArea(e.addresses.join(":"));
|
|
479
|
+
return e.sheet.trim(s);
|
|
480
|
+
}
|
|
481
|
+
identify(t) {
|
|
482
|
+
const { slideY: e = 0, slideX: s = 0 } = t, i = dt(this.value, t);
|
|
483
|
+
if (i.sheet == null)
|
|
484
|
+
return this.value;
|
|
485
|
+
const n = [];
|
|
486
|
+
for (let o = 0; o < i.addresses.length; o++) {
|
|
487
|
+
const a = i.addresses[o], { y: l, x: u, absX: h, absY: c } = N(a), f = {
|
|
488
|
+
y: l + e,
|
|
489
|
+
x: u + s,
|
|
490
|
+
absX: h,
|
|
491
|
+
absY: c
|
|
492
|
+
}, d = i.sheet.getId(f);
|
|
493
|
+
if (d == null)
|
|
494
|
+
return this.value;
|
|
495
|
+
this.ids.push(d), n.push(He(d, h, c));
|
|
496
|
+
}
|
|
497
|
+
return `#${i.sheet.id}!${n.join(":")}`;
|
|
498
|
+
}
|
|
499
|
+
}
|
|
500
|
+
class Jt extends rt {
|
|
501
|
+
parse(t) {
|
|
502
|
+
if (this.value.indexOf("!") !== -1) {
|
|
503
|
+
const [e, s] = this.value.split("!"), i = Number(e.slice(1));
|
|
504
|
+
return { sheet: t.getSheetBySheetId(i), id: Pt(s, !1) };
|
|
505
|
+
}
|
|
506
|
+
return { sheet: t, id: Pt(this.value, !1) };
|
|
507
|
+
}
|
|
508
|
+
evaluate({ sheet: t }) {
|
|
509
|
+
const e = this.parse(t);
|
|
510
|
+
if (e.id === "?")
|
|
511
|
+
throw new x("#REF!", "Reference does not exist");
|
|
512
|
+
const { y: s, x: i } = e.sheet.getPointById(e.id), [n, o] = [Math.abs(s), Math.abs(i)];
|
|
513
|
+
return e.sheet.trim({
|
|
514
|
+
top: n,
|
|
515
|
+
left: o,
|
|
516
|
+
bottom: n,
|
|
517
|
+
right: o
|
|
518
|
+
});
|
|
519
|
+
}
|
|
520
|
+
display({ sheet: t, slideY: e = 0, slideX: s = 0 }) {
|
|
521
|
+
const i = this.parse(t), n = i.sheet.getAddressById(i.id, e, s);
|
|
522
|
+
return n ? i.sheet.id === t.id ? n : `${i.sheet.sheetPrefix()}${n}` : "#REF!";
|
|
523
|
+
}
|
|
524
|
+
identify(t) {
|
|
525
|
+
const { sheet: e, slideY: s = 0, slideX: i = 0 } = t, n = this.display({ sheet: e, slideY: s, slideX: i });
|
|
526
|
+
if (n == null || n.length < 2)
|
|
527
|
+
return "#?";
|
|
528
|
+
const { formula: o, ids: a } = dt(n, t);
|
|
529
|
+
return this.ids = a, o || "#?";
|
|
530
|
+
}
|
|
531
|
+
}
|
|
532
|
+
class Qt extends rt {
|
|
533
|
+
parse(t) {
|
|
534
|
+
const e = this.value;
|
|
535
|
+
if (e.indexOf("!") !== -1) {
|
|
536
|
+
const [s, i] = e.split("!"), n = Number(s.slice(1));
|
|
537
|
+
return { sheet: t.getSheetBySheetId(n), ids: i.split(":") };
|
|
538
|
+
}
|
|
539
|
+
return { sheet: t, ids: e.split(":") };
|
|
540
|
+
}
|
|
541
|
+
evaluate({ sheet: t }) {
|
|
542
|
+
const e = this.parse(t), s = e.ids.map((c) => Pt(c)), i = [];
|
|
543
|
+
for (let c = 0; c < s.length; c++) {
|
|
544
|
+
const f = s[c];
|
|
545
|
+
if (f === "?")
|
|
546
|
+
throw new x("#REF!", "Reference does not exist");
|
|
547
|
+
const d = e.sheet.getPointById(f);
|
|
548
|
+
i.push(d);
|
|
549
|
+
}
|
|
550
|
+
const [n, o] = i, [a, l, u, h] = [n.y, n.x, o.y || e.sheet.numRows, o.x || e.sheet.numCols];
|
|
551
|
+
return e.sheet.trim({ top: a, left: l, bottom: u, right: h });
|
|
552
|
+
}
|
|
553
|
+
display({ sheet: t, slideY: e = 0, slideX: s = 0 }) {
|
|
554
|
+
const i = this.parse(t), n = i.ids.map((o) => Pt(o, !1)).map((o) => i.sheet.getAddressById(o, e, s) || "#REF!").join(":");
|
|
555
|
+
return i.sheet.id === t.id ? n : `${i.sheet.sheetPrefix()}${n}`;
|
|
556
|
+
}
|
|
557
|
+
identify(t) {
|
|
558
|
+
const { sheet: e, slideY: s = 0, slideX: i = 0 } = t, n = this.display({ sheet: e, slideY: s, slideX: i }), { formula: o, ids: a } = dt(n, t);
|
|
559
|
+
return this.ids = a, o ?? "";
|
|
560
|
+
}
|
|
561
|
+
}
|
|
562
|
+
class kt {
|
|
563
|
+
constructor(t, e = 0, s = [], i) {
|
|
564
|
+
this.name = t, this.precedence = e, this.args = s, this.at = i;
|
|
565
|
+
}
|
|
566
|
+
evaluate({ sheet: t }) {
|
|
567
|
+
const e = this.name.toLowerCase(), s = t.getFunctionByName(e);
|
|
568
|
+
if (s == null)
|
|
569
|
+
throw new x("#NAME?", `Unknown function: ${e}`);
|
|
570
|
+
return new s({ args: this.args, sheet: t, at: this.at }).call();
|
|
571
|
+
}
|
|
572
|
+
}
|
|
573
|
+
const Fs = new ie(0), Ds = {
|
|
574
|
+
"+": "add",
|
|
575
|
+
"-": "minus",
|
|
576
|
+
"/": "divide",
|
|
577
|
+
"*": "multiply",
|
|
578
|
+
"^": "power",
|
|
579
|
+
"&": "concat",
|
|
580
|
+
"=": "eq",
|
|
581
|
+
"<>": "ne",
|
|
582
|
+
">": "gt",
|
|
583
|
+
">=": "gte",
|
|
584
|
+
"<": "lt",
|
|
585
|
+
"<=": "lte"
|
|
586
|
+
}, vs = {
|
|
587
|
+
"-": "uminus"
|
|
588
|
+
}, Ue = /* @__PURE__ */ new Set([" ", `
|
|
589
|
+
`, "\r", " ", "\f"]), ks = /* @__PURE__ */ new Set([...Ue, "+", "-", "/", "*", "^", "&", "=", "<", ">", ")", ",", "%"]);
|
|
590
|
+
class I {
|
|
591
|
+
constructor(t, e, s = 0, i, n = !0) {
|
|
592
|
+
this.type = t, this.entity = e, this.precedence = s, this.at = i, this.closed = n;
|
|
593
|
+
}
|
|
594
|
+
length() {
|
|
595
|
+
return this.type === "VALUE" && typeof this.entity == "string" ? this.entity.length + (this.closed ? 2 : 1) : new String(this.entity).length;
|
|
596
|
+
}
|
|
597
|
+
stringify() {
|
|
598
|
+
if (this.type === "VALUE") {
|
|
599
|
+
if (typeof this.entity == "string")
|
|
600
|
+
return this.closed ? `"${this.entity}"` : `"${this.entity}`;
|
|
601
|
+
if (typeof this.entity == "boolean")
|
|
602
|
+
return this.entity ? "TRUE" : "FALSE";
|
|
603
|
+
if (this.raw != null)
|
|
604
|
+
return this.raw;
|
|
605
|
+
}
|
|
606
|
+
return this.entity;
|
|
607
|
+
}
|
|
608
|
+
convert() {
|
|
609
|
+
switch (this.type) {
|
|
610
|
+
case "VALUE":
|
|
611
|
+
return new ie(this.entity);
|
|
612
|
+
case "ID":
|
|
613
|
+
return new Jt(this.entity);
|
|
614
|
+
case "ID_RANGE":
|
|
615
|
+
return new Qt(this.entity);
|
|
616
|
+
case "REF":
|
|
617
|
+
return new Ye(this.entity);
|
|
618
|
+
case "RANGE":
|
|
619
|
+
return new Be(this.entity);
|
|
620
|
+
case "INFIX_OPERATOR": {
|
|
621
|
+
const t = Ds[this.entity];
|
|
622
|
+
return new kt(t, this.precedence, void 0, this.at);
|
|
623
|
+
}
|
|
624
|
+
case "PREFIX_OPERATOR": {
|
|
625
|
+
const t = vs[this.entity];
|
|
626
|
+
return new kt(t, this.precedence, void 0, this.at);
|
|
627
|
+
}
|
|
628
|
+
case "FUNCTION":
|
|
629
|
+
return new kt(this.entity, 0, [], this.at);
|
|
630
|
+
case "UNREFERENCED":
|
|
631
|
+
return new Os(this.entity);
|
|
632
|
+
case "INVALID_REF":
|
|
633
|
+
return new Ns(this.entity);
|
|
634
|
+
}
|
|
635
|
+
}
|
|
636
|
+
}
|
|
637
|
+
const Ps = (r) => Ue.has(r), $s = { true: !0, false: !1 }, Ie = new I("OPEN", "("), Ls = new I("CLOSE", ")"), Hs = new I("COMMA", ","), L = "INFIX_OPERATOR", Ys = "PREFIX_OPERATOR", Bs = "POSTFIX_OPERATOR";
|
|
638
|
+
class $t {
|
|
639
|
+
constructor(t, e) {
|
|
640
|
+
this.tokens = [], this.foreign = !1, this.identifiedFormula = "", this.dependencyIds = [], this.formula = t, this.index = 0, this.tokens = [], this.at = e == null ? void 0 : e.at;
|
|
641
|
+
}
|
|
642
|
+
isWhiteSpace() {
|
|
643
|
+
return Ps(this.formula[this.index]);
|
|
644
|
+
}
|
|
645
|
+
next(t = 1) {
|
|
646
|
+
this.index += t;
|
|
647
|
+
}
|
|
648
|
+
get(t = 0) {
|
|
649
|
+
return this.formula[this.index + t];
|
|
650
|
+
}
|
|
651
|
+
getToken(t = 0) {
|
|
652
|
+
return this.tokens[this.tokens.length + t];
|
|
653
|
+
}
|
|
654
|
+
getTokenIndexByCharPosition(t) {
|
|
655
|
+
let e = 0, s = 0;
|
|
656
|
+
for (let i = 0; i < this.tokens.length; i++) {
|
|
657
|
+
const n = this.tokens[i];
|
|
658
|
+
if (s = e + n.length(), e <= t && t <= s)
|
|
659
|
+
return [i, t === e || t === s];
|
|
660
|
+
e = s;
|
|
661
|
+
}
|
|
662
|
+
return [-1, !1];
|
|
663
|
+
}
|
|
664
|
+
getTokenPositionRange(t, e = 1) {
|
|
665
|
+
let s = 0, i = 0;
|
|
666
|
+
for (let n = 0; n < t; n++)
|
|
667
|
+
s = i, i += this.tokens[n].length();
|
|
668
|
+
return [s + e, i + e];
|
|
669
|
+
}
|
|
670
|
+
stringify() {
|
|
671
|
+
return this.tokens.map((t) => t.stringify()).join("");
|
|
672
|
+
}
|
|
673
|
+
identify(t) {
|
|
674
|
+
const e = [], s = [];
|
|
675
|
+
for (const i of this.tokens)
|
|
676
|
+
switch (i.type) {
|
|
677
|
+
case "VALUE":
|
|
678
|
+
typeof i.entity == "number" || typeof i.entity == "boolean" ? e.push(String(i.entity)) : e.push(i.closed ? `"${i.entity}"` : `"${i.entity}`);
|
|
679
|
+
break;
|
|
680
|
+
case "ID": {
|
|
681
|
+
const n = new Jt(i.entity);
|
|
682
|
+
e.push(n.identify(t)), s.push(...n.ids);
|
|
683
|
+
break;
|
|
684
|
+
}
|
|
685
|
+
case "ID_RANGE": {
|
|
686
|
+
const n = new Qt(i.entity);
|
|
687
|
+
e.push(n.identify(t)), s.push(...n.ids);
|
|
688
|
+
break;
|
|
689
|
+
}
|
|
690
|
+
case "REF": {
|
|
691
|
+
const n = new Ye(i.entity);
|
|
692
|
+
e.push(n.identify(t)), s.push(...n.ids);
|
|
693
|
+
break;
|
|
694
|
+
}
|
|
695
|
+
case "RANGE": {
|
|
696
|
+
const n = new Be(i.entity);
|
|
697
|
+
e.push(n.identify(t)), s.push(...n.ids);
|
|
698
|
+
break;
|
|
699
|
+
}
|
|
700
|
+
default:
|
|
701
|
+
e.push(i.entity);
|
|
702
|
+
break;
|
|
703
|
+
}
|
|
704
|
+
this.identifiedFormula = e.join(""), this.dependencyIds = s;
|
|
705
|
+
}
|
|
706
|
+
display({ sheet: t }) {
|
|
707
|
+
return this.tokens.map((e) => {
|
|
708
|
+
switch (e.type) {
|
|
709
|
+
case "VALUE":
|
|
710
|
+
return typeof e.entity == "number" || typeof e.entity == "boolean" ? e.raw ?? e.entity : e.closed ? `"${e.entity}"` : `"${e.entity}`;
|
|
711
|
+
case "ID":
|
|
712
|
+
return new Jt(e.entity).display({ sheet: t });
|
|
713
|
+
case "ID_RANGE":
|
|
714
|
+
return new Qt(e.entity).display({ sheet: t });
|
|
715
|
+
}
|
|
716
|
+
return e.entity;
|
|
717
|
+
}).join("");
|
|
718
|
+
}
|
|
719
|
+
tokenize(t = {}) {
|
|
720
|
+
var e, s;
|
|
721
|
+
for (; this.index <= this.formula.length; ) {
|
|
722
|
+
this.skipSpaces();
|
|
723
|
+
let i = this.get();
|
|
724
|
+
switch (this.next(), i) {
|
|
725
|
+
case void 0:
|
|
726
|
+
return;
|
|
727
|
+
case "(":
|
|
728
|
+
this.tokens.push(Ie);
|
|
729
|
+
continue;
|
|
730
|
+
case ")":
|
|
731
|
+
this.tokens.push(Ls);
|
|
732
|
+
continue;
|
|
733
|
+
case ",":
|
|
734
|
+
this.tokens.push(Hs);
|
|
735
|
+
continue;
|
|
736
|
+
case "+":
|
|
737
|
+
this.tokens.push(new I(L, "+", 3, this.at));
|
|
738
|
+
continue;
|
|
739
|
+
case "-": {
|
|
740
|
+
const o = (e = this.getToken(-1)) == null ? void 0 : e.type, a = (s = this.getToken(-2)) == null ? void 0 : s.type;
|
|
741
|
+
o === L || o === "SPACE" && a === L ? this.tokens.push(new I(Ys, "-", 6, this.at)) : this.tokens.push(new I(L, "-", 3, this.at));
|
|
742
|
+
continue;
|
|
743
|
+
}
|
|
744
|
+
case "/":
|
|
745
|
+
this.tokens.push(new I(L, "/", 4, this.at));
|
|
746
|
+
continue;
|
|
747
|
+
case "*":
|
|
748
|
+
this.tokens.push(new I(L, "*", 4, this.at));
|
|
749
|
+
continue;
|
|
750
|
+
case "^":
|
|
751
|
+
this.tokens.push(new I(L, "^", 5, this.at));
|
|
752
|
+
continue;
|
|
753
|
+
case "&":
|
|
754
|
+
this.tokens.push(new I(L, "&", 4, this.at));
|
|
755
|
+
continue;
|
|
756
|
+
case "=":
|
|
757
|
+
this.tokens.push(new I(L, "=", 1, this.at));
|
|
758
|
+
continue;
|
|
759
|
+
case ">":
|
|
760
|
+
if (this.get() === "=") {
|
|
761
|
+
this.next(), this.tokens.push(new I(L, ">=", 2, this.at));
|
|
762
|
+
continue;
|
|
763
|
+
}
|
|
764
|
+
this.tokens.push(new I(L, ">", 2, this.at));
|
|
765
|
+
continue;
|
|
766
|
+
case "<":
|
|
767
|
+
if (this.get() === "=") {
|
|
768
|
+
this.next(), this.tokens.push(new I(L, "<=", 2, this.at));
|
|
769
|
+
continue;
|
|
770
|
+
}
|
|
771
|
+
if (this.get() === ">") {
|
|
772
|
+
this.next(), this.tokens.push(new I(L, "<>", 1, this.at));
|
|
773
|
+
continue;
|
|
774
|
+
}
|
|
775
|
+
this.tokens.push(new I(L, "<", 2, this.at));
|
|
776
|
+
continue;
|
|
777
|
+
case '"': {
|
|
778
|
+
const { buf: o, closed: a } = this.getString('"');
|
|
779
|
+
this.tokens.push(new I("VALUE", o, 0, this.at, a));
|
|
780
|
+
continue;
|
|
781
|
+
}
|
|
782
|
+
case "'": {
|
|
783
|
+
const { buf: o } = this.getString("'");
|
|
784
|
+
i = `'${o}'`;
|
|
785
|
+
break;
|
|
786
|
+
}
|
|
787
|
+
case "!": {
|
|
788
|
+
this.foreign = !0;
|
|
789
|
+
break;
|
|
790
|
+
}
|
|
791
|
+
case "%": {
|
|
792
|
+
this.tokens.push(new I(Bs, "%", 4, this.at));
|
|
793
|
+
continue;
|
|
794
|
+
}
|
|
795
|
+
}
|
|
796
|
+
let n = i;
|
|
797
|
+
for (; ; ) {
|
|
798
|
+
const o = this.get();
|
|
799
|
+
if (o === "(") {
|
|
800
|
+
this.tokens.push(new I("FUNCTION", n, 0, this.at), Ie), this.next();
|
|
801
|
+
break;
|
|
802
|
+
}
|
|
803
|
+
if (o == null || ks.has(o)) {
|
|
804
|
+
if (n.length === 0)
|
|
805
|
+
break;
|
|
806
|
+
if (n.match(/^[+-]?(\d*[.])?\d+$/)) {
|
|
807
|
+
const a = new I("VALUE", parseFloat(n), 0, this.at);
|
|
808
|
+
a.raw = n, this.tokens.push(a);
|
|
809
|
+
} else {
|
|
810
|
+
const a = $s[n.toLowerCase()];
|
|
811
|
+
a != null ? this.tokens.push(new I("VALUE", a, 0, this.at)) : n.startsWith("#") ? n.indexOf("#REF!") !== -1 ? this.tokens.push(new I("UNREFERENCED", n, 0, this.at)) : n.indexOf(":") !== -1 ? this.tokens.push(new I("ID_RANGE", Us(n, t), 0, this.at)) : this.tokens.push(new I("ID", n, 0, this.at)) : n.indexOf(":") !== -1 ? this.tokens.push(new I("RANGE", n, 0, this.at)) : !n.startsWith("'") && n.indexOf("!") === -1 && n.includes(".") && /[a-zA-Z]/.test(n) || isNaN(n[n.length - 1]) ? this.tokens.push(new I("INVALID_REF", n, 0, this.at)) : this.tokens.push(new I("REF", n, 0, this.at));
|
|
812
|
+
}
|
|
813
|
+
break;
|
|
814
|
+
}
|
|
815
|
+
n += o, this.next();
|
|
816
|
+
}
|
|
817
|
+
}
|
|
818
|
+
}
|
|
819
|
+
skipSpaces() {
|
|
820
|
+
let t = "";
|
|
821
|
+
for (; this.isWhiteSpace(); )
|
|
822
|
+
t += this.formula[this.index++];
|
|
823
|
+
t !== "" && this.tokens.push(new I("SPACE", t, 0, this.at));
|
|
824
|
+
}
|
|
825
|
+
getString(t = '"') {
|
|
826
|
+
let e = "";
|
|
827
|
+
for (; ; ) {
|
|
828
|
+
const s = this.get();
|
|
829
|
+
if (this.next(), s == null)
|
|
830
|
+
return { buf: e, closed: !1 };
|
|
831
|
+
if (s === t)
|
|
832
|
+
if (t === '"' && this.get() === t) {
|
|
833
|
+
e += t, this.next();
|
|
834
|
+
continue;
|
|
835
|
+
} else if (t === "'" && this.get() === t) {
|
|
836
|
+
e += s;
|
|
837
|
+
continue;
|
|
838
|
+
} else
|
|
839
|
+
return { buf: e, closed: !0 };
|
|
840
|
+
else
|
|
841
|
+
e += s;
|
|
842
|
+
}
|
|
843
|
+
}
|
|
844
|
+
}
|
|
845
|
+
const Us = (r, t) => {
|
|
846
|
+
const [e, s] = r.split("!"), i = s.split(":"), n = /* @__PURE__ */ new Set();
|
|
847
|
+
return Object.keys(t).forEach((o) => {
|
|
848
|
+
const a = t[o], l = new RegExp(`(\\$)?#${o}\\b(\\$)?`);
|
|
849
|
+
for (let u = 0; u < i.length; u++) {
|
|
850
|
+
if (n.has(u))
|
|
851
|
+
continue;
|
|
852
|
+
const h = i[u], c = h.replace(l, (f, d, p) => `${d || ""}#${a}${p || ""}`);
|
|
853
|
+
c !== h && (i[u] = c, n.add(u));
|
|
854
|
+
}
|
|
855
|
+
}), `${e}!${i.join(":")}`;
|
|
856
|
+
};
|
|
857
|
+
class ze {
|
|
858
|
+
constructor(t) {
|
|
859
|
+
this.index = 0, this.depth = 0, this.tokens = t;
|
|
860
|
+
}
|
|
861
|
+
build() {
|
|
862
|
+
const { expr: t } = this.parse(!1);
|
|
863
|
+
return t;
|
|
864
|
+
}
|
|
865
|
+
parse(t) {
|
|
866
|
+
const e = [];
|
|
867
|
+
let s;
|
|
868
|
+
const i = (n = !1) => {
|
|
869
|
+
if (s) {
|
|
870
|
+
const o = e.pop();
|
|
871
|
+
s.args.push(o);
|
|
872
|
+
}
|
|
873
|
+
return { hasNext: n, expr: e.shift() };
|
|
874
|
+
};
|
|
875
|
+
for (; this.tokens.length > this.index; ) {
|
|
876
|
+
const n = this.tokens[this.index++];
|
|
877
|
+
if (n.type !== "SPACE") {
|
|
878
|
+
if (n.type === "COMMA") {
|
|
879
|
+
if (!t)
|
|
880
|
+
throw new x("#ERROR!", "Invalid comma");
|
|
881
|
+
return i(!0);
|
|
882
|
+
} else if (n.type === "VALUE" || n.type === "ID" || n.type === "ID_RANGE" || n.type === "REF" || n.type === "RANGE" || n.type === "UNREFERENCED" || n.type === "INVALID_REF") {
|
|
883
|
+
const o = n.convert();
|
|
884
|
+
e.push(o);
|
|
885
|
+
} else if (n.type === "POSTFIX_OPERATOR" && n.entity === "%") {
|
|
886
|
+
const o = e.pop();
|
|
887
|
+
if (!o)
|
|
888
|
+
throw new x("#ERROR!", "Missing expression before %");
|
|
889
|
+
const a = new kt("divide", 4, [o, new ie(100)]);
|
|
890
|
+
e.push(a);
|
|
891
|
+
} else if (n.type === "FUNCTION") {
|
|
892
|
+
this.index++, this.depth++;
|
|
893
|
+
const o = n.convert();
|
|
894
|
+
for (e.push(o); ; ) {
|
|
895
|
+
const { expr: a, hasNext: l } = this.parse(!0);
|
|
896
|
+
if (a && o.args.push(a), !l)
|
|
897
|
+
break;
|
|
898
|
+
}
|
|
899
|
+
} else if (n.type === "OPEN") {
|
|
900
|
+
this.depth++;
|
|
901
|
+
const { expr: o } = this.parse(!1);
|
|
902
|
+
e.push(o);
|
|
903
|
+
} else if (n.type === "CLOSE") {
|
|
904
|
+
if (this.depth-- === 0)
|
|
905
|
+
throw new x("#ERROR!", "Unexpected end paren");
|
|
906
|
+
return i();
|
|
907
|
+
} else if (n.type === "INFIX_OPERATOR") {
|
|
908
|
+
const o = n.convert();
|
|
909
|
+
let a = e.pop();
|
|
910
|
+
if (a == null)
|
|
911
|
+
if (o.name === "minus" || o.name === "add")
|
|
912
|
+
a = Fs;
|
|
913
|
+
else
|
|
914
|
+
throw new x("#ERROR!", "Missing left expression");
|
|
915
|
+
if (s == null)
|
|
916
|
+
o.args.push(a), e.unshift(o);
|
|
917
|
+
else if (o.precedence > s.precedence)
|
|
918
|
+
o.args.push(a), s.args.push(o), e.unshift(s);
|
|
919
|
+
else {
|
|
920
|
+
const l = e.shift();
|
|
921
|
+
o.args.push(l), s.args.push(a), e.unshift(o);
|
|
922
|
+
}
|
|
923
|
+
s = o;
|
|
924
|
+
} else if (n.type === "PREFIX_OPERATOR") {
|
|
925
|
+
const o = n.convert();
|
|
926
|
+
s ? s.args.push(o) : e.unshift(o), s = o;
|
|
927
|
+
}
|
|
928
|
+
}
|
|
929
|
+
}
|
|
930
|
+
return i();
|
|
931
|
+
}
|
|
932
|
+
}
|
|
933
|
+
const nn = ze, on = (r) => (r.charAt(0) === "'" && (r = r.slice(1)), r.charAt(r.length - 1) === "'" && (r = r.slice(0, -1)), r);
|
|
934
|
+
function zs(r) {
|
|
935
|
+
let t, e = [];
|
|
936
|
+
if (r.startsWith("'")) {
|
|
937
|
+
let s = 1, i = "";
|
|
938
|
+
for (; s < r.length; ) {
|
|
939
|
+
const o = r[s], a = r[s + 1];
|
|
940
|
+
if (o === "'")
|
|
941
|
+
if (a === "'")
|
|
942
|
+
i += "'", s += 2;
|
|
943
|
+
else if (a === "!") {
|
|
944
|
+
s += 2;
|
|
945
|
+
break;
|
|
946
|
+
} else
|
|
947
|
+
return { sheetName: void 0, addresses: [] };
|
|
948
|
+
else
|
|
949
|
+
i += o, s++;
|
|
950
|
+
}
|
|
951
|
+
t = i, e = r.slice(s).trim().split(":");
|
|
952
|
+
} else {
|
|
953
|
+
const s = r.indexOf("!");
|
|
954
|
+
s !== -1 ? (t = r.slice(0, s), e = r.slice(s + 1).trim().split(":")) : e = r.trim().split(":");
|
|
955
|
+
}
|
|
956
|
+
return { sheetName: t, addresses: e };
|
|
957
|
+
}
|
|
958
|
+
const dt = (r, { sheet: t, operation: e, dependency: s }) => {
|
|
959
|
+
const { sheetName: i, addresses: n } = zs(r), o = [];
|
|
960
|
+
if (i && (t = t.getSheetBySheetName(i), t == null))
|
|
961
|
+
return { sheet: t, sheetName: i, addresses: n, ids: o };
|
|
962
|
+
if (n.length === 0)
|
|
963
|
+
return { sheet: t, sheetName: i, addresses: n, ids: o };
|
|
964
|
+
const a = [];
|
|
965
|
+
for (let u = 0; u < n.length; u++) {
|
|
966
|
+
const h = n[u], { y: c, x: f, absX: d, absY: p } = N(h);
|
|
967
|
+
let m = t.getId({ y: c, x: f });
|
|
968
|
+
if (m === s && (e === "removeRows" ? m = t.getId({ y: c - 1, x: f }) : e === "removeCols" && (m = t.getId({ y: c, x: f - 1 }))), m == null) {
|
|
969
|
+
a.push(Le(h, !!d, !!p) || "?");
|
|
970
|
+
continue;
|
|
971
|
+
}
|
|
972
|
+
o.push(m), a.push(`${d ? "$" : ""}#${m}${p ? "$" : ""}`);
|
|
973
|
+
}
|
|
974
|
+
let l = `#${t.id}!${a.join(":")}`;
|
|
975
|
+
return {
|
|
976
|
+
sheet: t,
|
|
977
|
+
sheetName: i,
|
|
978
|
+
addresses: n,
|
|
979
|
+
ids: o,
|
|
980
|
+
formula: l
|
|
981
|
+
};
|
|
982
|
+
}, Ct = (r, t) => t.length === 0 ? r : Object.fromEntries(
|
|
983
|
+
Object.entries(r).filter(([e]) => !t.includes(e))
|
|
984
|
+
), bt = (r, t, e = {}) => {
|
|
985
|
+
r.systems[t] == null && (r.systems[t] = {});
|
|
986
|
+
const s = r.systems[t];
|
|
987
|
+
for (const i of Object.keys(e))
|
|
988
|
+
s[i] ?? (s[i] = e[i]);
|
|
989
|
+
return s;
|
|
990
|
+
}, Lt = (r, t, e) => {
|
|
991
|
+
r.asyncCaches || (r.asyncCaches = {}), r.asyncCaches[t] = e;
|
|
992
|
+
}, tt = () => !0, Ve = (r, t, e = {}) => {
|
|
993
|
+
const s = N(t);
|
|
994
|
+
return r.getCell(s, e);
|
|
995
|
+
}, Vs = (r, { area: t, resolution: e = "RESOLVED", raise: s = !1, filter: i = tt, asScalar: n = !1 } = {}) => r.__raw__._toValueMatrix({ area: t, resolution: e, raise: s, filter: i, asScalar: n }), an = (r, {
|
|
996
|
+
resolution: t = "RESOLVED",
|
|
997
|
+
raise: e = !1,
|
|
998
|
+
filter: s = tt,
|
|
999
|
+
addresses: i,
|
|
1000
|
+
area: n,
|
|
1001
|
+
asScalar: o = !1
|
|
1002
|
+
} = {}) => {
|
|
1003
|
+
const a = {};
|
|
1004
|
+
if (i) {
|
|
1005
|
+
for (const f of i) {
|
|
1006
|
+
const d = N(f), p = Ve(r, f, { resolution: t, raise: e }) ?? {};
|
|
1007
|
+
if (s(p)) {
|
|
1008
|
+
let m = p.value;
|
|
1009
|
+
o && (m = r.getPolicy(d).toScalar({ value: p.value, cell: p, sheet: r.__raw__, point: d })), a[f] = m;
|
|
1010
|
+
}
|
|
1011
|
+
}
|
|
1012
|
+
return a;
|
|
1013
|
+
}
|
|
1014
|
+
const { top: l, left: u, bottom: h, right: c } = n ?? r.area;
|
|
1015
|
+
for (let f = l; f <= h; f++)
|
|
1016
|
+
for (let d = u; d <= c; d++) {
|
|
1017
|
+
const p = r.getCell({ y: f, x: d }, { resolution: t, raise: e }) ?? {};
|
|
1018
|
+
if (s(p)) {
|
|
1019
|
+
let m = p.value;
|
|
1020
|
+
o && (m = r.getPolicy({ y: f, x: d }).toScalar({ value: p.value, cell: p, sheet: r.__raw__, point: { y: f, x: d } })), a[D({ y: f, x: d })] = m;
|
|
1021
|
+
}
|
|
1022
|
+
}
|
|
1023
|
+
return a;
|
|
1024
|
+
}, cn = (r, { resolution: t = "RESOLVED", raise: e = !1, filter: s = tt, rows: i, area: n, asScalar: o = !1 } = {}) => {
|
|
1025
|
+
const a = [], { top: l, left: u, bottom: h, right: c } = n ?? r.area, f = i ?? Array.from({ length: r.numRows }, (d, p) => l + p);
|
|
1026
|
+
for (const d of f) {
|
|
1027
|
+
const p = {};
|
|
1028
|
+
a.push(p);
|
|
1029
|
+
for (let m = u; m <= c; m++) {
|
|
1030
|
+
const g = r.getCell({ y: d, x: m }, { resolution: t, raise: e }) ?? {};
|
|
1031
|
+
if (s(g)) {
|
|
1032
|
+
let y = g.value;
|
|
1033
|
+
o && (y = r.getPolicy({ y: d, x: m }).toScalar({ value: g.value, cell: g, sheet: r.__raw__, point: { y: d, x: m } })), p[W(m)] = y;
|
|
1034
|
+
}
|
|
1035
|
+
}
|
|
1036
|
+
}
|
|
1037
|
+
return a;
|
|
1038
|
+
}, ln = (r, { resolution: t = "RESOLVED", raise: e = !1, filter: s = tt, cols: i, area: n, asScalar: o = !1 } = {}) => {
|
|
1039
|
+
const a = [], { top: l, left: u, bottom: h, right: c } = n ?? r.area, f = i ? i.map((d) => typeof d == "string" ? _t(d) : d) : Array.from({ length: r.numCols }, (d, p) => u + p);
|
|
1040
|
+
for (const d of f) {
|
|
1041
|
+
const p = {};
|
|
1042
|
+
a.push(p);
|
|
1043
|
+
for (let m = l; m <= h; m++) {
|
|
1044
|
+
const g = r.getCell({ y: m, x: d }, { resolution: t, raise: e }) ?? {};
|
|
1045
|
+
if (s(g)) {
|
|
1046
|
+
let y = g.value;
|
|
1047
|
+
o && (y = r.getPolicy({ y: m, x: d }).toScalar({ value: g.value, cell: g, sheet: r.__raw__, point: { y: m, x: d } })), p[Et(m)] = y;
|
|
1048
|
+
}
|
|
1049
|
+
}
|
|
1050
|
+
}
|
|
1051
|
+
return a;
|
|
1052
|
+
}, hn = (r, { area: t, resolution: e = "RESOLVED", raise: s = !1, filter: i = tt, ignoreFields: n = [] } = {}) => {
|
|
1053
|
+
const { top: o, left: a, bottom: l, right: u } = t ?? r.area, h = se(l - o + 1, u - a + 1);
|
|
1054
|
+
for (let c = o; c <= l; c++)
|
|
1055
|
+
for (let f = a; f <= u; f++) {
|
|
1056
|
+
const d = r.getCell({ y: c, x: f }, { resolution: e, raise: s }) ?? {};
|
|
1057
|
+
if (i(d)) {
|
|
1058
|
+
const p = Ct(d, n);
|
|
1059
|
+
h[c - o][f - a] = p;
|
|
1060
|
+
}
|
|
1061
|
+
}
|
|
1062
|
+
return h;
|
|
1063
|
+
}, un = (r, {
|
|
1064
|
+
resolution: t = "RESOLVED",
|
|
1065
|
+
raise: e = !1,
|
|
1066
|
+
filter: s = tt,
|
|
1067
|
+
addresses: i,
|
|
1068
|
+
area: n,
|
|
1069
|
+
ignoreFields: o = []
|
|
1070
|
+
} = {}) => {
|
|
1071
|
+
const a = {};
|
|
1072
|
+
if (i) {
|
|
1073
|
+
for (const f of i) {
|
|
1074
|
+
const d = Ve(r, f, { resolution: t, raise: e }) ?? {};
|
|
1075
|
+
s(d) && (a[f] = Ct(d, o));
|
|
1076
|
+
}
|
|
1077
|
+
return a;
|
|
1078
|
+
}
|
|
1079
|
+
const { top: l, left: u, bottom: h, right: c } = n ?? r.area;
|
|
1080
|
+
for (let f = l; f <= h; f++)
|
|
1081
|
+
for (let d = u; d <= c; d++) {
|
|
1082
|
+
const p = r.getCell({ y: f, x: d }, { resolution: t, raise: e }) ?? {};
|
|
1083
|
+
s(p) && (a[D({ y: f, x: d })] = Ct(p, o));
|
|
1084
|
+
}
|
|
1085
|
+
return a;
|
|
1086
|
+
}, dn = (r, { resolution: t = "RESOLVED", raise: e = !1, filter: s = tt, rows: i, area: n, ignoreFields: o = [] } = {}) => {
|
|
1087
|
+
const a = [], { top: l, left: u, bottom: h, right: c } = n ?? r.area, f = i ?? Array.from({ length: r.numRows }, (d, p) => l + p);
|
|
1088
|
+
for (const d of f) {
|
|
1089
|
+
const p = {};
|
|
1090
|
+
a.push(p);
|
|
1091
|
+
for (let m = u; m <= c; m++) {
|
|
1092
|
+
const g = r.getCell({ y: d, x: m }, { resolution: t, raise: e }) ?? {};
|
|
1093
|
+
s(g) && (p[W(m)] = Ct(g, o));
|
|
1094
|
+
}
|
|
1095
|
+
}
|
|
1096
|
+
return a;
|
|
1097
|
+
}, We = (r) => `'${r.replace(/'/g, "''")}'`, Ws = (r) => r ? `${We(r)}!` : "", fn = (r, { resolution: t = "RESOLVED", raise: e = !1, filter: s = tt, cols: i, area: n, ignoreFields: o = [] } = {}) => {
|
|
1098
|
+
const a = [], { top: l, left: u, bottom: h, right: c } = n ?? r.area, f = i ? i.map((d) => typeof d == "string" ? _t(d) : d) : Array.from({ length: r.numCols }, (d, p) => u + p);
|
|
1099
|
+
for (const d of f) {
|
|
1100
|
+
const p = {};
|
|
1101
|
+
a.push(p);
|
|
1102
|
+
for (let m = l; m <= h; m++) {
|
|
1103
|
+
const g = r.getCell({ y: m, x: d }, { resolution: t, raise: e }) ?? {};
|
|
1104
|
+
s(g) && (p[Et(m)] = Ct(g, o));
|
|
1105
|
+
}
|
|
1106
|
+
}
|
|
1107
|
+
return a;
|
|
1108
|
+
}, Bt = 1, Ut = 2, re = 4, ne = 8, oe = 16, ae = 32, It = 64, Tt = 128, ht = 256, zt = 512, ce = 8192, Vt = 1024, le = 16384, he = 32768, ue = 65536, Wt = 131072, Xs = 0, Xe = It | Tt, St = ht | zt | ce | Vt | le | Wt, je = re | ne, Ge = oe | ae, Ze = je | Ge, qe = Bt | Ut, Ke = St | qe | Ze | Xe, Je = ue | he | Wt, js = 524288, Gs = Ke | Je, O = (r, t) => r === void 0 ? !1 : (r & t) === t, Zs = (r) => {
|
|
1109
|
+
const t = [];
|
|
1110
|
+
return O(r, Bt) && t.push("RemoveRow"), O(r, Ut) && t.push("RemoveCol"), O(r, re) && t.push("InsertRowAbove"), O(r, ne) && t.push("InsertRowBelow"), O(r, oe) && t.push("InsertColLeft"), O(r, ae) && t.push("InsertColRight"), O(r, It) && t.push("MoveFrom"), O(r, Tt) && t.push("MoveTo"), O(r, ht) && t.push("Write"), O(r, zt) && t.push("Style"), O(r, Vt) && t.push("Resize"), O(r, le) && t.push("SetPolicy"), O(r, Wt) && t.push("SetLabel"), O(r, he) && t.push("Sort"), O(r, ue) && t.push("Filter"), t;
|
|
1111
|
+
}, pn = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
1112
|
+
__proto__: null,
|
|
1113
|
+
Add: Ze,
|
|
1114
|
+
ColumnMenu: Je,
|
|
1115
|
+
Copy: ce,
|
|
1116
|
+
Delete: qe,
|
|
1117
|
+
Filter: ue,
|
|
1118
|
+
InsertCols: Ge,
|
|
1119
|
+
InsertColsLeft: oe,
|
|
1120
|
+
InsertColsRight: ae,
|
|
1121
|
+
InsertRows: je,
|
|
1122
|
+
InsertRowsAbove: re,
|
|
1123
|
+
InsertRowsBelow: ne,
|
|
1124
|
+
Move: Xe,
|
|
1125
|
+
MoveFrom: It,
|
|
1126
|
+
MoveTo: Tt,
|
|
1127
|
+
NoOperation: Xs,
|
|
1128
|
+
ReadOnly: Ke,
|
|
1129
|
+
RemoveCols: Ut,
|
|
1130
|
+
RemoveRows: Bt,
|
|
1131
|
+
Resize: Vt,
|
|
1132
|
+
RowMenu: js,
|
|
1133
|
+
SetLabel: Wt,
|
|
1134
|
+
SetPolicy: le,
|
|
1135
|
+
Sort: he,
|
|
1136
|
+
Style: zt,
|
|
1137
|
+
Update: St,
|
|
1138
|
+
ViewOnly: Gs,
|
|
1139
|
+
Write: ht,
|
|
1140
|
+
debugOperations: Zs,
|
|
1141
|
+
hasOperation: O
|
|
1142
|
+
}, Symbol.toStringTag, { value: "Module" }));
|
|
1143
|
+
H.extend(fs);
|
|
1144
|
+
H.extend(ds);
|
|
1145
|
+
const Qe = /* @__PURE__ */ new Set(["0", "1", "2", "3", "4", "5", "6", "7", "8", "9"]), qs = /* @__PURE__ */ new Set([...Qe, "Z", "z"]), Ks = /* @__PURE__ */ new Set(["J", "F", "M", "A", "S", "O", "N", "D", ...Qe]), Js = /* @__PURE__ */ new Set(["N", "B", "R", "Y", "N", "L", "G", "P", "T", "V", "C", ...qs]), Qs = /* @__PURE__ */ new Set([
|
|
1146
|
+
"jan",
|
|
1147
|
+
"feb",
|
|
1148
|
+
"mar",
|
|
1149
|
+
"apr",
|
|
1150
|
+
"may",
|
|
1151
|
+
"jun",
|
|
1152
|
+
"jul",
|
|
1153
|
+
"aug",
|
|
1154
|
+
"sep",
|
|
1155
|
+
"oct",
|
|
1156
|
+
"nov",
|
|
1157
|
+
"dec",
|
|
1158
|
+
"january",
|
|
1159
|
+
"february",
|
|
1160
|
+
"march",
|
|
1161
|
+
"april",
|
|
1162
|
+
"june",
|
|
1163
|
+
"july",
|
|
1164
|
+
"august",
|
|
1165
|
+
"september",
|
|
1166
|
+
"october",
|
|
1167
|
+
"november",
|
|
1168
|
+
"december",
|
|
1169
|
+
"mon",
|
|
1170
|
+
"tue",
|
|
1171
|
+
"wed",
|
|
1172
|
+
"thu",
|
|
1173
|
+
"fri",
|
|
1174
|
+
"sat",
|
|
1175
|
+
"sun",
|
|
1176
|
+
"monday",
|
|
1177
|
+
"tuesday",
|
|
1178
|
+
"wednesday",
|
|
1179
|
+
"thursday",
|
|
1180
|
+
"friday",
|
|
1181
|
+
"saturday",
|
|
1182
|
+
"sunday",
|
|
1183
|
+
"am",
|
|
1184
|
+
"pm",
|
|
1185
|
+
"utc",
|
|
1186
|
+
"gmt",
|
|
1187
|
+
"est",
|
|
1188
|
+
"cst",
|
|
1189
|
+
"mst",
|
|
1190
|
+
"pst",
|
|
1191
|
+
"jst",
|
|
1192
|
+
"cet",
|
|
1193
|
+
"eet",
|
|
1194
|
+
"ist",
|
|
1195
|
+
"aest",
|
|
1196
|
+
"edt",
|
|
1197
|
+
"cdt",
|
|
1198
|
+
"mdt",
|
|
1199
|
+
"pdt",
|
|
1200
|
+
"bst",
|
|
1201
|
+
"hst",
|
|
1202
|
+
"akst",
|
|
1203
|
+
"akdt",
|
|
1204
|
+
"nzst",
|
|
1205
|
+
"nzdt",
|
|
1206
|
+
"t",
|
|
1207
|
+
"z"
|
|
1208
|
+
]);
|
|
1209
|
+
function ts(r) {
|
|
1210
|
+
const t = r[0];
|
|
1211
|
+
if (t == null || !Ks.has(t.toUpperCase()) || !Js.has(r[r.length - 1].toUpperCase()) || r.match(/[=*&#@!?[\]{}"'()|%\\<>~+\r\n]/))
|
|
1212
|
+
return;
|
|
1213
|
+
const e = r.split(/[\s,/\-:.]+/).filter(Boolean);
|
|
1214
|
+
for (const i of e)
|
|
1215
|
+
if (/^[a-zA-Z]+$/.test(i) && !Qs.has(i.toLowerCase()))
|
|
1216
|
+
return;
|
|
1217
|
+
let s = "UTC";
|
|
1218
|
+
try {
|
|
1219
|
+
s = Intl.DateTimeFormat().resolvedOptions().timeZone;
|
|
1220
|
+
} catch {
|
|
1221
|
+
}
|
|
1222
|
+
try {
|
|
1223
|
+
return H.tz(r, s).toDate();
|
|
1224
|
+
} catch {
|
|
1225
|
+
}
|
|
1226
|
+
}
|
|
1227
|
+
const ti = { true: !0, false: !1 };
|
|
1228
|
+
class de {
|
|
1229
|
+
constructor(t) {
|
|
1230
|
+
this.priority = 0, this.datetimeFormat = "YYYY-MM-DD HH:mm:ss", this.dateFormat = "YYYY-MM-DD", this.timeFormat = "HH:mm:ss", this.decimalPrecision = 14, this.deserializeFunctions = [], this.priority = (t == null ? void 0 : t.priority) ?? 1, this.applyMixins(t == null ? void 0 : t.mixins), this.registerDeserializeFunctions();
|
|
1231
|
+
}
|
|
1232
|
+
registerDeserializeFunctions() {
|
|
1233
|
+
this.deserializeFunctions = [
|
|
1234
|
+
...this.deserializeFirst ? [this.deserializeFirst.bind(this)] : [],
|
|
1235
|
+
this.deserializeNumber.bind(this),
|
|
1236
|
+
this.deserializeTime.bind(this),
|
|
1237
|
+
this.deserializeDate.bind(this),
|
|
1238
|
+
this.deserializeBool.bind(this),
|
|
1239
|
+
this.deserializeAny.bind(this)
|
|
1240
|
+
];
|
|
1241
|
+
}
|
|
1242
|
+
applyMixins(t) {
|
|
1243
|
+
if (t == null)
|
|
1244
|
+
return;
|
|
1245
|
+
const e = Object.getPrototypeOf(this);
|
|
1246
|
+
for (const s of t)
|
|
1247
|
+
for (const i in s)
|
|
1248
|
+
e !== de.prototype && Object.prototype.hasOwnProperty.call(e, i) || (this[i] = s[i]);
|
|
1249
|
+
}
|
|
1250
|
+
// --- RENDER ---
|
|
1251
|
+
render(t) {
|
|
1252
|
+
let { value: e, cell: s } = t;
|
|
1253
|
+
const { sheet: i, point: n } = t;
|
|
1254
|
+
s == null && (s = i.getCell(n, { resolution: "EVALUATED", raise: !0 }) ?? {}, e = s.value);
|
|
1255
|
+
let o;
|
|
1256
|
+
if (k.is(e))
|
|
1257
|
+
o = "";
|
|
1258
|
+
else if (e == null)
|
|
1259
|
+
o = this.renderNull({ ...t, value: e, cell: s });
|
|
1260
|
+
else
|
|
1261
|
+
switch (typeof e) {
|
|
1262
|
+
case "object":
|
|
1263
|
+
if (e instanceof Date)
|
|
1264
|
+
o = this.renderDate({ ...t, value: e, cell: s });
|
|
1265
|
+
else if (b.is(e))
|
|
1266
|
+
o = this.renderTime({ value: b.ensure(e), cell: s, sheet: i, point: n });
|
|
1267
|
+
else if (Array.isArray(e))
|
|
1268
|
+
o = this.renderArray({ ...t, value: e, cell: s });
|
|
1269
|
+
else {
|
|
1270
|
+
if (x.is(e))
|
|
1271
|
+
throw e;
|
|
1272
|
+
Q(e) ? o = this.renderSheet({ ...t, value: e, cell: s }) : o = this.renderObject({ ...t, value: e, cell: s });
|
|
1273
|
+
}
|
|
1274
|
+
break;
|
|
1275
|
+
case "string":
|
|
1276
|
+
o = this.renderString({ ...t, value: e, cell: s });
|
|
1277
|
+
break;
|
|
1278
|
+
case "number":
|
|
1279
|
+
o = this.renderNumber({ ...t, value: e, cell: s });
|
|
1280
|
+
break;
|
|
1281
|
+
case "boolean":
|
|
1282
|
+
o = this.renderBool({ ...t, value: e, cell: s });
|
|
1283
|
+
break;
|
|
1284
|
+
case "function":
|
|
1285
|
+
o = e();
|
|
1286
|
+
break;
|
|
1287
|
+
default:
|
|
1288
|
+
o = "";
|
|
1289
|
+
}
|
|
1290
|
+
return this.renderCallback ? this.renderCallback(o, { ...t, value: e, cell: s }) : o;
|
|
1291
|
+
}
|
|
1292
|
+
renderString({ value: t }) {
|
|
1293
|
+
return t;
|
|
1294
|
+
}
|
|
1295
|
+
renderBool({ value: t }) {
|
|
1296
|
+
return t ? "TRUE" : "FALSE";
|
|
1297
|
+
}
|
|
1298
|
+
renderNumber({ value: t }) {
|
|
1299
|
+
return isNaN(t) ? "NaN" : parseFloat(t.toPrecision(this.decimalPrecision));
|
|
1300
|
+
}
|
|
1301
|
+
renderDate({ value: t }) {
|
|
1302
|
+
return t.getHours() + t.getMinutes() + t.getSeconds() === 0 ? H(t).format(this.dateFormat) : H(t).format(this.datetimeFormat);
|
|
1303
|
+
}
|
|
1304
|
+
renderTime({ value: t }) {
|
|
1305
|
+
return t.stringify(this.timeFormat);
|
|
1306
|
+
}
|
|
1307
|
+
renderArray(t) {
|
|
1308
|
+
let { value: e, cell: s } = t;
|
|
1309
|
+
return e = e == null ? void 0 : e[0], Array.isArray(e) && (e = e[0]), this.render({ ...t, value: e, cell: s });
|
|
1310
|
+
}
|
|
1311
|
+
renderObject({ value: t }) {
|
|
1312
|
+
return JSON.stringify(t);
|
|
1313
|
+
}
|
|
1314
|
+
renderNull(t) {
|
|
1315
|
+
return "";
|
|
1316
|
+
}
|
|
1317
|
+
renderSheet({ value: t, ...e }) {
|
|
1318
|
+
const s = e.sheet.getId(e.point), i = t.__raw__.strip({ raise: !0, at: s });
|
|
1319
|
+
return this.render({ ...e, value: i });
|
|
1320
|
+
}
|
|
1321
|
+
renderRowHeaderLabel(t) {
|
|
1322
|
+
return null;
|
|
1323
|
+
}
|
|
1324
|
+
renderColHeaderLabel(t) {
|
|
1325
|
+
return null;
|
|
1326
|
+
}
|
|
1327
|
+
// --- TO SCALAR ---
|
|
1328
|
+
toScalar(t) {
|
|
1329
|
+
const { value: e, cell: s, sheet: i, point: n } = t;
|
|
1330
|
+
if (!k.is(e)) {
|
|
1331
|
+
if (e == null)
|
|
1332
|
+
return this.toScalarNull({ value: e, cell: s, sheet: i, point: n });
|
|
1333
|
+
switch (typeof e) {
|
|
1334
|
+
case "string":
|
|
1335
|
+
return this.toScalarString({ value: e, cell: s, sheet: i, point: n });
|
|
1336
|
+
case "number":
|
|
1337
|
+
return this.toScalarNumber({ value: e, cell: s, sheet: i, point: n });
|
|
1338
|
+
case "boolean":
|
|
1339
|
+
return this.toScalarBool({ value: e, cell: s, sheet: i, point: n });
|
|
1340
|
+
case "object":
|
|
1341
|
+
if (e instanceof Date)
|
|
1342
|
+
return this.toScalarDate({ value: e, cell: s, sheet: i, point: n });
|
|
1343
|
+
if (b.is(e))
|
|
1344
|
+
return this.toScalarTime({ value: b.ensure(e), cell: s, sheet: i, point: n });
|
|
1345
|
+
if (Array.isArray(e))
|
|
1346
|
+
return this.toScalarArray({ value: e, cell: s, sheet: i, point: n });
|
|
1347
|
+
if (x.is(e))
|
|
1348
|
+
throw e;
|
|
1349
|
+
return;
|
|
1350
|
+
default:
|
|
1351
|
+
return;
|
|
1352
|
+
}
|
|
1353
|
+
}
|
|
1354
|
+
}
|
|
1355
|
+
toScalarString({ value: t }) {
|
|
1356
|
+
return t;
|
|
1357
|
+
}
|
|
1358
|
+
toScalarNumber({ value: t }) {
|
|
1359
|
+
return t == null ? void 0 : t.toPrecision(this.decimalPrecision);
|
|
1360
|
+
}
|
|
1361
|
+
toScalarBool({ value: t }) {
|
|
1362
|
+
return t;
|
|
1363
|
+
}
|
|
1364
|
+
toScalarDate({ value: t }) {
|
|
1365
|
+
return t.getHours() + t.getMinutes() + t.getSeconds() === 0 ? H(t).format(this.dateFormat) : H(t).format(this.datetimeFormat);
|
|
1366
|
+
}
|
|
1367
|
+
toScalarTime({ value: t }) {
|
|
1368
|
+
return t.stringify(this.timeFormat);
|
|
1369
|
+
}
|
|
1370
|
+
toScalarArray({ value: t, cell: e, sheet: s, point: i }) {
|
|
1371
|
+
let n = t == null ? void 0 : t[0];
|
|
1372
|
+
return Array.isArray(n) && (n = n[0]), this.toScalar({ value: n, cell: e, sheet: s, point: i });
|
|
1373
|
+
}
|
|
1374
|
+
toScalarNull(t) {
|
|
1375
|
+
return null;
|
|
1376
|
+
}
|
|
1377
|
+
// --- SERIALIZE ---
|
|
1378
|
+
serialize({ value: t, cell: e, sheet: s, point: i }) {
|
|
1379
|
+
return t === void 0 && (t = e == null ? void 0 : e.value), k.is(t) ? "" : t instanceof Date ? this.serializeDate({ value: t, cell: e, sheet: s, point: i }) : b.is(t) ? this.serializeTime({ value: b.ensure(t), cell: e, sheet: s, point: i }) : t == null ? this.serializeNull({ cell: e, sheet: s, point: i }) : Array.isArray(t) ? this.serializeArray({ value: t, cell: e, sheet: s, point: i }) : t instanceof x ? this.serializeFormulaError({ value: t, cell: e, sheet: s, point: i }) : t instanceof Error ? this.serializeError({ value: t, cell: e, sheet: s, point: i }) : t.toString();
|
|
1380
|
+
}
|
|
1381
|
+
serializeString({ value: t }) {
|
|
1382
|
+
return t;
|
|
1383
|
+
}
|
|
1384
|
+
serializeBool({ value: t }) {
|
|
1385
|
+
return t ? "true" : "false";
|
|
1386
|
+
}
|
|
1387
|
+
serializeNumber({ value: t }) {
|
|
1388
|
+
return isNaN(t) ? "NaN" : parseFloat(t.toPrecision(this.decimalPrecision)).toString();
|
|
1389
|
+
}
|
|
1390
|
+
serializeDate({ value: t }) {
|
|
1391
|
+
return t.getHours() + t.getMinutes() + t.getSeconds() === 0 ? H(t).format(this.dateFormat) : H(t).format(this.datetimeFormat);
|
|
1392
|
+
}
|
|
1393
|
+
serializeTime({ value: t }) {
|
|
1394
|
+
return t.stringify(this.timeFormat);
|
|
1395
|
+
}
|
|
1396
|
+
serializeArray(t) {
|
|
1397
|
+
let { value: e } = t;
|
|
1398
|
+
return e = e == null ? void 0 : e[0], Array.isArray(e) && (e = e[0]), this.serialize({ ...t, value: e });
|
|
1399
|
+
}
|
|
1400
|
+
serializeNull(t) {
|
|
1401
|
+
return "";
|
|
1402
|
+
}
|
|
1403
|
+
serializeFormulaError({ value: t }) {
|
|
1404
|
+
return t.code;
|
|
1405
|
+
}
|
|
1406
|
+
serializeError(t) {
|
|
1407
|
+
return "";
|
|
1408
|
+
}
|
|
1409
|
+
serializeForClipboard(t) {
|
|
1410
|
+
const { point: e, sheet: s } = t;
|
|
1411
|
+
return s.getSerializedValue({ point: e }) ?? "";
|
|
1412
|
+
}
|
|
1413
|
+
// --- DESERIALIZE ---
|
|
1414
|
+
deserializeValue(t, e) {
|
|
1415
|
+
try {
|
|
1416
|
+
const s = typeof t != "string" ? this.deserializeRaw(t, e) : this.deserialize(t, e);
|
|
1417
|
+
return this.deserializeCallback ? this.deserializeCallback(s, e) : s;
|
|
1418
|
+
} catch (s) {
|
|
1419
|
+
return { ...e, value: String(s) };
|
|
1420
|
+
}
|
|
1421
|
+
}
|
|
1422
|
+
deserializeRaw(t, e) {
|
|
1423
|
+
return b.is(t) && (t = b.ensure(t)), { ...e, value: t };
|
|
1424
|
+
}
|
|
1425
|
+
deserialize(t, e) {
|
|
1426
|
+
if (t[0] === "'")
|
|
1427
|
+
return { ...e, value: t };
|
|
1428
|
+
for (let s = 0; s < this.deserializeFunctions.length; s++) {
|
|
1429
|
+
const i = this.deserializeFunctions[s](t, e);
|
|
1430
|
+
if ((i == null ? void 0 : i.value) !== void 0)
|
|
1431
|
+
return { ...e, ...i };
|
|
1432
|
+
}
|
|
1433
|
+
return t === "" ? { ...e, value: void 0 } : { ...e, value: t };
|
|
1434
|
+
}
|
|
1435
|
+
deserializeAny(t, e) {
|
|
1436
|
+
return t == null || t === "" ? { value: void 0 } : { value: t };
|
|
1437
|
+
}
|
|
1438
|
+
deserializeBool(t, e) {
|
|
1439
|
+
return { value: ti[t.toLowerCase()] };
|
|
1440
|
+
}
|
|
1441
|
+
deserializeNumber(t, e) {
|
|
1442
|
+
return t.match(/^-?[\d.]+$/) != null && t.match(/\.$/) == null && (t.match(/\./g) || []).length <= 1 ? { value: parseFloat(t) } : { value: void 0 };
|
|
1443
|
+
}
|
|
1444
|
+
deserializeTime(t, e) {
|
|
1445
|
+
return t.length < 3 || isNaN(t[t.length - 1]) ? { value: void 0 } : { value: b.parse(t) };
|
|
1446
|
+
}
|
|
1447
|
+
deserializeDate(t, e) {
|
|
1448
|
+
return { value: ts(t) };
|
|
1449
|
+
}
|
|
1450
|
+
// --- SELECT ---
|
|
1451
|
+
getSelectFallback(t) {
|
|
1452
|
+
return { value: null };
|
|
1453
|
+
}
|
|
1454
|
+
getSelectOptions() {
|
|
1455
|
+
return [];
|
|
1456
|
+
}
|
|
1457
|
+
select(t) {
|
|
1458
|
+
const { next: e, sheet: s, point: i } = t, n = this.getSelectOptions();
|
|
1459
|
+
return n.length === 0 || n.some((a) => a.value === (e == null ? void 0 : e.value)) ? e : { ...e, ...this.getSelectFallback({ sheet: s, point: i, value: e == null ? void 0 : e.value }) };
|
|
1460
|
+
}
|
|
1461
|
+
}
|
|
1462
|
+
const xt = "default", ei = new de({ priority: 0 }), j = (r) => r == null ? "" : String(r);
|
|
1463
|
+
function ft(r) {
|
|
1464
|
+
return typeof r == "number" ? "number" : r instanceof Date ? "date" : b.is(r) ? "time" : typeof r == "boolean" ? "boolean" : "string";
|
|
1465
|
+
}
|
|
1466
|
+
function pt(r, t) {
|
|
1467
|
+
switch (t) {
|
|
1468
|
+
case "number": {
|
|
1469
|
+
let e = r.replace(/[,_]/g, ""), s = 1;
|
|
1470
|
+
e.endsWith("%") && (e = e.slice(0, -1), s = 0.01);
|
|
1471
|
+
const i = Number(e);
|
|
1472
|
+
return { ok: !isNaN(i), num: i * s };
|
|
1473
|
+
}
|
|
1474
|
+
case "date": {
|
|
1475
|
+
const e = ts(r);
|
|
1476
|
+
return e ? { ok: !0, num: e.getTime() } : { ok: !1, num: NaN };
|
|
1477
|
+
}
|
|
1478
|
+
case "time": {
|
|
1479
|
+
const e = b.parse(r);
|
|
1480
|
+
return e ? { ok: !0, num: e.toMilliseconds() } : { ok: !1, num: NaN };
|
|
1481
|
+
}
|
|
1482
|
+
case "boolean": {
|
|
1483
|
+
const e = r.toLowerCase();
|
|
1484
|
+
return e === "true" ? { ok: !0, num: 1 } : e === "false" ? { ok: !0, num: 0 } : { ok: !1, num: NaN };
|
|
1485
|
+
}
|
|
1486
|
+
default:
|
|
1487
|
+
return { ok: !1, num: NaN };
|
|
1488
|
+
}
|
|
1489
|
+
}
|
|
1490
|
+
function mt(r, t) {
|
|
1491
|
+
switch (t) {
|
|
1492
|
+
case "number":
|
|
1493
|
+
return r;
|
|
1494
|
+
case "date":
|
|
1495
|
+
return r.getTime();
|
|
1496
|
+
case "time":
|
|
1497
|
+
return b.ensure(r).toMilliseconds();
|
|
1498
|
+
case "boolean":
|
|
1499
|
+
return r ? 1 : 0;
|
|
1500
|
+
default:
|
|
1501
|
+
return NaN;
|
|
1502
|
+
}
|
|
1503
|
+
}
|
|
1504
|
+
const si = (r, t) => {
|
|
1505
|
+
const e = ft(t);
|
|
1506
|
+
if (e === "string") {
|
|
1507
|
+
const i = j(t);
|
|
1508
|
+
return r.value.some((n) => i === n);
|
|
1509
|
+
}
|
|
1510
|
+
const s = mt(t, e);
|
|
1511
|
+
return r.value.some((i) => {
|
|
1512
|
+
const n = pt(i, e);
|
|
1513
|
+
return n.ok && s === n.num;
|
|
1514
|
+
});
|
|
1515
|
+
}, ii = (r, t) => {
|
|
1516
|
+
const e = ft(t);
|
|
1517
|
+
if (e === "string") {
|
|
1518
|
+
const i = j(t);
|
|
1519
|
+
return !r.value.some((n) => i === n);
|
|
1520
|
+
}
|
|
1521
|
+
const s = mt(t, e);
|
|
1522
|
+
return !r.value.some((i) => {
|
|
1523
|
+
const n = pt(i, e);
|
|
1524
|
+
return n.ok && s === n.num;
|
|
1525
|
+
});
|
|
1526
|
+
}, ri = (r, t) => {
|
|
1527
|
+
const e = ft(t);
|
|
1528
|
+
if (e === "string")
|
|
1529
|
+
return j(t) > r.value[0];
|
|
1530
|
+
const s = mt(t, e), i = pt(r.value[0], e);
|
|
1531
|
+
return i.ok && s > i.num;
|
|
1532
|
+
}, ni = (r, t) => {
|
|
1533
|
+
const e = ft(t);
|
|
1534
|
+
if (e === "string")
|
|
1535
|
+
return j(t) >= r.value[0];
|
|
1536
|
+
const s = mt(t, e), i = pt(r.value[0], e);
|
|
1537
|
+
return i.ok && s >= i.num;
|
|
1538
|
+
}, oi = (r, t) => {
|
|
1539
|
+
const e = ft(t);
|
|
1540
|
+
if (e === "string")
|
|
1541
|
+
return j(t) < r.value[0];
|
|
1542
|
+
const s = mt(t, e), i = pt(r.value[0], e);
|
|
1543
|
+
return i.ok && s < i.num;
|
|
1544
|
+
}, ai = (r, t) => {
|
|
1545
|
+
const e = ft(t);
|
|
1546
|
+
if (e === "string")
|
|
1547
|
+
return j(t) <= r.value[0];
|
|
1548
|
+
const s = mt(t, e), i = pt(r.value[0], e);
|
|
1549
|
+
return i.ok && s <= i.num;
|
|
1550
|
+
}, ci = (r, t) => t == null || j(t) === "", li = (r, t) => t != null && j(t) !== "", hi = (r, t) => {
|
|
1551
|
+
const e = j(t).toLowerCase();
|
|
1552
|
+
return r.value.some((s) => e.includes(s.toLowerCase()));
|
|
1553
|
+
}, ui = (r, t) => {
|
|
1554
|
+
const e = j(t).toLowerCase();
|
|
1555
|
+
return !r.value.some((s) => e.includes(s.toLowerCase()));
|
|
1556
|
+
}, di = {
|
|
1557
|
+
eq: si,
|
|
1558
|
+
ne: ii,
|
|
1559
|
+
gt: ri,
|
|
1560
|
+
gte: ni,
|
|
1561
|
+
lt: oi,
|
|
1562
|
+
lte: ai,
|
|
1563
|
+
blank: ci,
|
|
1564
|
+
nonblank: li,
|
|
1565
|
+
includes: hi,
|
|
1566
|
+
excludes: ui
|
|
1567
|
+
};
|
|
1568
|
+
function Te(r, t) {
|
|
1569
|
+
const e = di[r.method];
|
|
1570
|
+
return e ? e(r, t) : !0;
|
|
1571
|
+
}
|
|
1572
|
+
function fi(r, t) {
|
|
1573
|
+
const e = r.mode ?? "or";
|
|
1574
|
+
return r.conditions.length === 0 ? !0 : e === "and" ? r.conditions.every((s) => Te(s, t)) : r.conditions.some((s) => Te(s, t));
|
|
1575
|
+
}
|
|
1576
|
+
class lt {
|
|
1577
|
+
constructor(t) {
|
|
1578
|
+
this.map = {}, this.dependentIds = /* @__PURE__ */ new Set(), this.sheet = t;
|
|
1579
|
+
}
|
|
1580
|
+
collectDependents(...t) {
|
|
1581
|
+
t.forEach((e) => {
|
|
1582
|
+
var s, i;
|
|
1583
|
+
(i = (s = this.sheet.registry.systems[e]) == null ? void 0 : s.dependents) == null || i.forEach((n) => {
|
|
1584
|
+
this.dependentIds.add(n);
|
|
1585
|
+
});
|
|
1586
|
+
});
|
|
1587
|
+
}
|
|
1588
|
+
/**
|
|
1589
|
+
* Compare two idMatrix snapshots (`before` and `after`) and populate
|
|
1590
|
+
* `this.map` and collect dependents for every position where the occupying
|
|
1591
|
+
* cell ID changed. Works for any rearrangement (sort, move, etc.).
|
|
1592
|
+
*/
|
|
1593
|
+
buildMap(t, e) {
|
|
1594
|
+
for (let s = 0; s < t.length; s++) {
|
|
1595
|
+
const i = t[s], n = e[s];
|
|
1596
|
+
i != null && n != null && i !== n && (this.collectDependents(i, n), this.map[i] = n);
|
|
1597
|
+
}
|
|
1598
|
+
}
|
|
1599
|
+
resolveDependents(t) {
|
|
1600
|
+
this.sheet.clearAddressCaches();
|
|
1601
|
+
const e = {};
|
|
1602
|
+
return this.dependentIds.forEach((s) => {
|
|
1603
|
+
const i = this.sheet.registry.data[s];
|
|
1604
|
+
i != null && (e[s] = { ...i }, this.sheet.clearDependencies(s), i.value = this.sheet.processFormula(i.value, {
|
|
1605
|
+
dependency: s,
|
|
1606
|
+
idMap: this.map,
|
|
1607
|
+
operation: t
|
|
1608
|
+
}));
|
|
1609
|
+
}), e;
|
|
1610
|
+
}
|
|
1611
|
+
}
|
|
1612
|
+
const Me = (r) => {
|
|
1613
|
+
switch (r) {
|
|
1614
|
+
case "INSERT_ROWS":
|
|
1615
|
+
case "INSERT_COLS":
|
|
1616
|
+
case "REMOVE_ROWS":
|
|
1617
|
+
case "REMOVE_COLS":
|
|
1618
|
+
case "MOVE":
|
|
1619
|
+
case "SORT_ROWS":
|
|
1620
|
+
return !0;
|
|
1621
|
+
}
|
|
1622
|
+
return !1;
|
|
1623
|
+
}, pi = () => !0;
|
|
1624
|
+
class $ {
|
|
1625
|
+
constructor({ limits: t = {}, name: e, registry: s = ye({}), eager: i = !1 }) {
|
|
1626
|
+
this.__gsType = "Sheet", this._stripped = wt, this.area = { top: 0, left: 0, bottom: 0, right: 0 }, this.id = 0, this.name = "", this.eager = !1, this.prevName = "", this.status = 0, this.idsToBeIdentified = [], this.totalWidth = 0, this.totalHeight = 0, this.fullHeight = 0, this.defaultColWidth = jt, this.defaultRowHeight = J, this.version = 0, this.addressCaches = /* @__PURE__ */ new Map(), this.lastChangedAddresses = [], this._initCells = null, this._initMatrices = null, this._matrixBases = [], this._matrixByBase = [], this._colLetters = [], this._rowHeightOverrides = /* @__PURE__ */ new Map(), this._filteredRows = /* @__PURE__ */ new Set(), this.idMatrix = [], this.changedTime = Date.now(), this.eager = i, this._limits = {
|
|
1627
|
+
minRows: t.minRows ?? 1,
|
|
1628
|
+
maxRows: t.maxRows ?? -1,
|
|
1629
|
+
minCols: t.minCols ?? 1,
|
|
1630
|
+
maxCols: t.maxCols ?? -1
|
|
1631
|
+
}, this.name = e || "", this.prevName = this.name, this.registry = s;
|
|
1632
|
+
}
|
|
1633
|
+
get minNumRows() {
|
|
1634
|
+
return this._limits.minRows;
|
|
1635
|
+
}
|
|
1636
|
+
get maxNumRows() {
|
|
1637
|
+
return this._limits.maxRows;
|
|
1638
|
+
}
|
|
1639
|
+
get minNumCols() {
|
|
1640
|
+
return this._limits.minCols;
|
|
1641
|
+
}
|
|
1642
|
+
get maxNumCols() {
|
|
1643
|
+
return this._limits.maxCols;
|
|
1644
|
+
}
|
|
1645
|
+
static is(t) {
|
|
1646
|
+
return (t == null ? void 0 : t.__gsType) === "Sheet";
|
|
1647
|
+
}
|
|
1648
|
+
toString() {
|
|
1649
|
+
return `Sheet(name=${We(this.name)}, top=${this.top}, left=${this.left}, bottom=${this.bottom}, right=${this.right})`;
|
|
1650
|
+
}
|
|
1651
|
+
get headerHeight() {
|
|
1652
|
+
var t;
|
|
1653
|
+
return ((t = this.getCell({ y: 0, x: 0 }, { resolution: "SYSTEM" })) == null ? void 0 : t.height) || Re;
|
|
1654
|
+
}
|
|
1655
|
+
setHeaderHeight(t, e = !0) {
|
|
1656
|
+
return this.update({
|
|
1657
|
+
diff: { 0: { height: t } },
|
|
1658
|
+
partial: !0,
|
|
1659
|
+
historicize: e
|
|
1660
|
+
});
|
|
1661
|
+
}
|
|
1662
|
+
get headerWidth() {
|
|
1663
|
+
var t;
|
|
1664
|
+
return ((t = this.getCell({ y: 0, x: 0 }, { resolution: "SYSTEM" })) == null ? void 0 : t.width) || _e;
|
|
1665
|
+
}
|
|
1666
|
+
setHeaderWidth(t, e = !0) {
|
|
1667
|
+
return this.update({
|
|
1668
|
+
diff: { 0: { width: t } },
|
|
1669
|
+
partial: !0,
|
|
1670
|
+
historicize: e
|
|
1671
|
+
});
|
|
1672
|
+
}
|
|
1673
|
+
/**
|
|
1674
|
+
* Get the raw (mutable) cell data for a point. Unlike getCell, this returns the actual registry.data reference.
|
|
1675
|
+
* @internal
|
|
1676
|
+
*/
|
|
1677
|
+
_pointToRawCell({ y: t, x: e }) {
|
|
1678
|
+
const s = this.getId({ y: t, x: e });
|
|
1679
|
+
if (s != null)
|
|
1680
|
+
return this._ensureCellPopulated(t, e, s), this.registry.data[s];
|
|
1681
|
+
}
|
|
1682
|
+
isRowFiltered(t) {
|
|
1683
|
+
var e;
|
|
1684
|
+
return !!((e = this._pointToRawCell({ y: t, x: 0 })) != null && e.filtered);
|
|
1685
|
+
}
|
|
1686
|
+
hasActiveFilters() {
|
|
1687
|
+
const t = this.numCols;
|
|
1688
|
+
for (let e = 1; e <= t; e++) {
|
|
1689
|
+
const s = this._pointToRawCell({ y: 0, x: e });
|
|
1690
|
+
if (s != null && s.filter && s.filter.conditions.length > 0)
|
|
1691
|
+
return !0;
|
|
1692
|
+
}
|
|
1693
|
+
return !1;
|
|
1694
|
+
}
|
|
1695
|
+
/**
|
|
1696
|
+
* Returns true if any data cell in this sheet currently holds a Pending value
|
|
1697
|
+
* (i.e. an async formula that hasn't resolved yet).
|
|
1698
|
+
*/
|
|
1699
|
+
hasPendingCells() {
|
|
1700
|
+
for (const t of Object.keys(this.registry.data)) {
|
|
1701
|
+
const e = this.registry.data[t];
|
|
1702
|
+
if (k.is(e == null ? void 0 : e.value))
|
|
1703
|
+
return !0;
|
|
1704
|
+
}
|
|
1705
|
+
return !1;
|
|
1706
|
+
}
|
|
1707
|
+
/**
|
|
1708
|
+
* Returns a Promise that resolves when all in-flight async formula computations
|
|
1709
|
+
* have completed and no data cells hold Pending values.
|
|
1710
|
+
* If nothing is pending, resolves immediately.
|
|
1711
|
+
* Useful for waiting before sort/filter so that cell values are fully resolved.
|
|
1712
|
+
*/
|
|
1713
|
+
waitForPending() {
|
|
1714
|
+
const t = this.registry.asyncPending;
|
|
1715
|
+
if (t.size > 0) {
|
|
1716
|
+
const e = Array.from(t.values()).map((s) => s.promise);
|
|
1717
|
+
return Promise.all(e).then(() => this.waitForPending());
|
|
1718
|
+
}
|
|
1719
|
+
return this.hasPendingCells() ? new Promise((e) => {
|
|
1720
|
+
const s = () => {
|
|
1721
|
+
if (this.registry.asyncPending.size > 0) {
|
|
1722
|
+
const i = Array.from(this.registry.asyncPending.values()).map((n) => n.promise);
|
|
1723
|
+
Promise.all(i).then(s);
|
|
1724
|
+
} else this.hasPendingCells() ? setTimeout(s, 50) : e();
|
|
1725
|
+
};
|
|
1726
|
+
s();
|
|
1727
|
+
}) : Promise.resolve();
|
|
1728
|
+
}
|
|
1729
|
+
/**
|
|
1730
|
+
* Returns the addresses that were changed in the most recent `_update()` call.
|
|
1731
|
+
* Useful inside `onChange` to know which cells were modified.
|
|
1732
|
+
*/
|
|
1733
|
+
getLastChangedAddresses() {
|
|
1734
|
+
return this.lastChangedAddresses;
|
|
1735
|
+
}
|
|
1736
|
+
/**
|
|
1737
|
+
* Eagerly fire every async formula cell in this sheet, ignoring the visible
|
|
1738
|
+
* range.
|
|
1739
|
+
*
|
|
1740
|
+
* GridSheet is virtualized: normally only cells the UI renders get solved, so
|
|
1741
|
+
* an off-screen `=…` formula that calls an async function never fires. Only
|
|
1742
|
+
* async cells need this — sync formulas have no side effects and resolve when
|
|
1743
|
+
* read (e.g. by serialization), whereas an async cell must be *fired* and given
|
|
1744
|
+
* time to settle before its value can be read. `resolveAll()` therefore walks
|
|
1745
|
+
* the async-formula index ({@link Registry.asyncFormulaCells}) and solves each
|
|
1746
|
+
* one, which fires it through the usual machinery: it resolves, populates the
|
|
1747
|
+
* per-cell async cache, and triggers a re-render via `transmit()`. Sync cells
|
|
1748
|
+
* that depend on those results resolve normally on the next read.
|
|
1749
|
+
*
|
|
1750
|
+
* Cells already resolved (async-cache hit) or in flight (Pending) are not
|
|
1751
|
+
* re-fired — solving is a cache hit for them — so repeated calls converge and
|
|
1752
|
+
* are cheap. After awaiting {@link waitForPending}, serialization helpers such
|
|
1753
|
+
* as `toValueMatrix` return resolved values for off-screen cells too.
|
|
1754
|
+
*
|
|
1755
|
+
* This is the building block behind the opt-in `eager` sheet option; call it
|
|
1756
|
+
* directly to resolve on demand without enabling eager mode.
|
|
1757
|
+
*
|
|
1758
|
+
* @returns the number of async formula cells visited (for diagnostics/tests).
|
|
1759
|
+
*/
|
|
1760
|
+
resolveAll() {
|
|
1761
|
+
var s;
|
|
1762
|
+
const t = this.registry;
|
|
1763
|
+
let e = 0;
|
|
1764
|
+
for (const i of Array.from(t.asyncFormulaCells)) {
|
|
1765
|
+
const n = t.data[i];
|
|
1766
|
+
if (n == null || typeof n.value != "string" || n.value.charAt(0) !== "=") {
|
|
1767
|
+
t.asyncFormulaCells.delete(i);
|
|
1768
|
+
continue;
|
|
1769
|
+
}
|
|
1770
|
+
if (((s = t.systems[i]) == null ? void 0 : s.sheetId) !== this.id)
|
|
1771
|
+
continue;
|
|
1772
|
+
const { y: o, x: a } = this.getPointById(i);
|
|
1773
|
+
if (o < 0 || a < 0) {
|
|
1774
|
+
t.asyncFormulaCells.delete(i);
|
|
1775
|
+
continue;
|
|
1776
|
+
}
|
|
1777
|
+
this.getCell({ y: o, x: a }, { resolution: "RESOLVED", raise: !1 }), e++;
|
|
1778
|
+
}
|
|
1779
|
+
return e;
|
|
1780
|
+
}
|
|
1781
|
+
/**
|
|
1782
|
+
* Capture the full cell state of all filter-related header cells as a CellsByIdType snapshot.
|
|
1783
|
+
* @internal
|
|
1784
|
+
*/
|
|
1785
|
+
_captureFilterCellStates() {
|
|
1786
|
+
var i, n;
|
|
1787
|
+
const t = {}, e = this.numCols, s = this.numRows;
|
|
1788
|
+
for (let o = 1; o <= e; o++) {
|
|
1789
|
+
const a = this.getId({ y: 0, x: o });
|
|
1790
|
+
a != null && (t[a] = { filter: ((i = this.registry.data[a]) == null ? void 0 : i.filter) ?? null });
|
|
1791
|
+
}
|
|
1792
|
+
for (let o = 1; o <= s; o++) {
|
|
1793
|
+
const a = this.getId({ y: o, x: 0 });
|
|
1794
|
+
a != null && (t[a] = { filtered: ((n = this.registry.data[a]) == null ? void 0 : n.filtered) ?? !1 });
|
|
1795
|
+
}
|
|
1796
|
+
return t;
|
|
1797
|
+
}
|
|
1798
|
+
filterRows({
|
|
1799
|
+
x: t,
|
|
1800
|
+
filter: e
|
|
1801
|
+
} = {}) {
|
|
1802
|
+
const s = this._captureFilterCellStates();
|
|
1803
|
+
if (t == null) {
|
|
1804
|
+
const o = this.numCols;
|
|
1805
|
+
for (let a = 1; a <= o; a++) {
|
|
1806
|
+
const l = this._pointToRawCell({ y: 0, x: a });
|
|
1807
|
+
l == null || delete l.filter;
|
|
1808
|
+
}
|
|
1809
|
+
} else {
|
|
1810
|
+
const o = this._pointToRawCell({ y: 0, x: t });
|
|
1811
|
+
o && (e ? o.filter = e : delete o.filter);
|
|
1812
|
+
}
|
|
1813
|
+
this._reapplyFilters();
|
|
1814
|
+
const i = this._captureFilterCellStates(), n = Object.keys(s).filter(
|
|
1815
|
+
(o) => JSON.stringify(s[o]) !== JSON.stringify(i[o])
|
|
1816
|
+
);
|
|
1817
|
+
if (n.length > 0) {
|
|
1818
|
+
const o = {}, a = {};
|
|
1819
|
+
for (const l of n)
|
|
1820
|
+
o[l] = s[l], a[l] = i[l];
|
|
1821
|
+
this._pushHistory({
|
|
1822
|
+
applyed: !0,
|
|
1823
|
+
operation: "UPDATE",
|
|
1824
|
+
srcSheetId: this.id,
|
|
1825
|
+
dstSheetId: this.id,
|
|
1826
|
+
diffBefore: o,
|
|
1827
|
+
diffAfter: a,
|
|
1828
|
+
partial: !0
|
|
1829
|
+
});
|
|
1830
|
+
}
|
|
1831
|
+
return this.refresh(!1, !0);
|
|
1832
|
+
}
|
|
1833
|
+
/** @internal */
|
|
1834
|
+
_reapplyFilters() {
|
|
1835
|
+
const t = this.numCols, e = [], s = [];
|
|
1836
|
+
for (let n = 1; n <= t; n++) {
|
|
1837
|
+
const o = this._pointToRawCell({ y: 0, x: n });
|
|
1838
|
+
o != null && o.filter && o.filter.conditions.length > 0 && e.push({ x: n, filter: o.filter }), s.push(D({ y: 0, x: n }));
|
|
1839
|
+
}
|
|
1840
|
+
const i = this.numRows;
|
|
1841
|
+
for (let n = 1; n <= i; n++) {
|
|
1842
|
+
const o = this._pointToRawCell({ y: n, x: 0 });
|
|
1843
|
+
if (!o || o.filterFixed)
|
|
1844
|
+
continue;
|
|
1845
|
+
let a = !1;
|
|
1846
|
+
for (const { x: u, filter: h } of e) {
|
|
1847
|
+
const c = this.getCell({ y: n, x: u }, { resolution: "RESOLVED" });
|
|
1848
|
+
if (!fi(h, c == null ? void 0 : c.value)) {
|
|
1849
|
+
a = !0;
|
|
1850
|
+
break;
|
|
1851
|
+
}
|
|
1852
|
+
}
|
|
1853
|
+
const l = !!o.filtered;
|
|
1854
|
+
a ? (o.filtered = !0, this._filteredRows.add(n)) : (delete o.filtered, this._filteredRows.delete(n)), l !== a && s.push(D({ y: n, x: 0 }));
|
|
1855
|
+
}
|
|
1856
|
+
this.lastChangedAddresses = s;
|
|
1857
|
+
}
|
|
1858
|
+
sortRows({ x: t, direction: e }) {
|
|
1859
|
+
const s = this.numRows;
|
|
1860
|
+
if (s <= 1)
|
|
1861
|
+
return this;
|
|
1862
|
+
const i = /* @__PURE__ */ new Set(), n = [];
|
|
1863
|
+
for (let c = 1; c <= s; c++) {
|
|
1864
|
+
const f = this._pointToRawCell({ y: c, x: 0 });
|
|
1865
|
+
f != null && f.sortFixed ? i.add(c) : n.push(c);
|
|
1866
|
+
}
|
|
1867
|
+
n.sort((c, f) => {
|
|
1868
|
+
const d = this.getCell({ y: c, x: t }, { resolution: "RESOLVED" }), p = this.getCell({ y: f, x: t }, { resolution: "RESOLVED" }), m = d == null ? void 0 : d.value, g = p == null ? void 0 : p.value;
|
|
1869
|
+
if (m == null && g == null)
|
|
1870
|
+
return 0;
|
|
1871
|
+
if (m == null)
|
|
1872
|
+
return 1;
|
|
1873
|
+
if (g == null)
|
|
1874
|
+
return -1;
|
|
1875
|
+
let y = 0;
|
|
1876
|
+
return typeof m == "number" && typeof g == "number" ? y = m - g : m instanceof Date && g instanceof Date ? y = m.getTime() - g.getTime() : y = String(m).localeCompare(String(g)), e === "asc" ? y : -y;
|
|
1877
|
+
});
|
|
1878
|
+
const o = [];
|
|
1879
|
+
for (let c = 1; c <= s; c++)
|
|
1880
|
+
i.has(c) || o.push(c);
|
|
1881
|
+
let a = !1;
|
|
1882
|
+
for (let c = 0; c < n.length; c++)
|
|
1883
|
+
if (n[c] !== o[c]) {
|
|
1884
|
+
a = !0;
|
|
1885
|
+
break;
|
|
1886
|
+
}
|
|
1887
|
+
if (!a)
|
|
1888
|
+
return this;
|
|
1889
|
+
const l = {};
|
|
1890
|
+
for (const c of i)
|
|
1891
|
+
l[c] = c;
|
|
1892
|
+
for (let c = 0; c < n.length; c++)
|
|
1893
|
+
l[n[c]] = o[c];
|
|
1894
|
+
this._materializeIdMatrix();
|
|
1895
|
+
const u = this.idMatrix.slice();
|
|
1896
|
+
for (const [c, f] of Object.entries(l))
|
|
1897
|
+
this.idMatrix[Number(f)] = u[Number(c)];
|
|
1898
|
+
this.addressCaches.clear();
|
|
1899
|
+
const h = new lt(this);
|
|
1900
|
+
return h.buildMap(u.flat(), this.idMatrix.flat()), h.resolveDependents(), this._pushHistory({
|
|
1901
|
+
applyed: !0,
|
|
1902
|
+
operation: "SORT_ROWS",
|
|
1903
|
+
srcSheetId: this.id,
|
|
1904
|
+
dstSheetId: this.id,
|
|
1905
|
+
sortedRowMapping: l
|
|
1906
|
+
}), this.refresh(!0, !0);
|
|
1907
|
+
}
|
|
1908
|
+
/** @internal */
|
|
1909
|
+
_sortRowMapping(t, e = !1) {
|
|
1910
|
+
const s = new Array(this.numRows);
|
|
1911
|
+
if (e)
|
|
1912
|
+
for (const [n, o] of Object.entries(t)) {
|
|
1913
|
+
const a = Number(n);
|
|
1914
|
+
s[a - 1] = o;
|
|
1915
|
+
}
|
|
1916
|
+
else
|
|
1917
|
+
for (const [n, o] of Object.entries(t)) {
|
|
1918
|
+
const a = Number(n);
|
|
1919
|
+
s[o - 1] = a;
|
|
1920
|
+
}
|
|
1921
|
+
this._materializeIdMatrix();
|
|
1922
|
+
const i = [];
|
|
1923
|
+
for (let n = 0; n < s.length; n++)
|
|
1924
|
+
i.push(this.idMatrix[s[n]]);
|
|
1925
|
+
for (let n = 0; n < s.length; n++)
|
|
1926
|
+
this.idMatrix[n + 1] = i[n];
|
|
1927
|
+
this.addressCaches.clear();
|
|
1928
|
+
}
|
|
1929
|
+
get isInitialized() {
|
|
1930
|
+
return this.status === 2;
|
|
1931
|
+
}
|
|
1932
|
+
get policies() {
|
|
1933
|
+
return this.registry.policies;
|
|
1934
|
+
}
|
|
1935
|
+
/** @internal */
|
|
1936
|
+
getSystem(t) {
|
|
1937
|
+
const e = this.getId(t);
|
|
1938
|
+
if (e != null)
|
|
1939
|
+
return this.registry.systems[e];
|
|
1940
|
+
}
|
|
1941
|
+
/** @internal */
|
|
1942
|
+
processFormula(t, { idMap: e, ...s }) {
|
|
1943
|
+
if ((typeof t == "string" || t instanceof String) && t.charAt(0) === "=") {
|
|
1944
|
+
const i = new $t(t.substring(1));
|
|
1945
|
+
return i.tokenize(e), i.identify({ ...s, sheet: this }), i.dependencyIds.forEach((n) => this.addDependency(n, s.dependency)), s.dependency != null && (this._formulaHasAsync(i) ? this.registry.asyncFormulaCells.add(s.dependency) : this.registry.asyncFormulaCells.delete(s.dependency)), "=" + i.identifiedFormula;
|
|
1946
|
+
}
|
|
1947
|
+
return s.dependency != null && this.registry.asyncFormulaCells.delete(s.dependency), t;
|
|
1948
|
+
}
|
|
1949
|
+
/**
|
|
1950
|
+
* Whether a tokenized formula calls at least one async function, decided via
|
|
1951
|
+
* the function class's static `isAsync` flag (no instantiation). Drives the
|
|
1952
|
+
* async-formula index that {@link resolveAll} walks.
|
|
1953
|
+
* @internal
|
|
1954
|
+
*/
|
|
1955
|
+
_formulaHasAsync(t) {
|
|
1956
|
+
for (const e of t.tokens)
|
|
1957
|
+
if (e.type === "FUNCTION") {
|
|
1958
|
+
const s = this.registry.functions[String(e.entity).toLowerCase()];
|
|
1959
|
+
if (s != null && s.isAsync)
|
|
1960
|
+
return !0;
|
|
1961
|
+
}
|
|
1962
|
+
return !1;
|
|
1963
|
+
}
|
|
1964
|
+
/** @internal */
|
|
1965
|
+
resolveFormulas() {
|
|
1966
|
+
this.idsToBeIdentified.forEach((t) => {
|
|
1967
|
+
var s;
|
|
1968
|
+
const e = this.registry.data[t];
|
|
1969
|
+
((s = this.registry.systems[t]) == null ? void 0 : s.sheetId) != null && e != null && (this.clearDependencies(t), e.value = this.processFormula(e == null ? void 0 : e.value, { dependency: t }));
|
|
1970
|
+
}), this.idsToBeIdentified = [], this.status = 2;
|
|
1971
|
+
}
|
|
1972
|
+
/** @internal */
|
|
1973
|
+
getSheetBySheetName(t) {
|
|
1974
|
+
const e = this.registry.sheetIdsByName[t];
|
|
1975
|
+
return this.getSheetBySheetId(e);
|
|
1976
|
+
}
|
|
1977
|
+
/** @internal */
|
|
1978
|
+
getSheetBySheetId(t) {
|
|
1979
|
+
var e, s, i;
|
|
1980
|
+
return (i = (s = (e = this.registry.contextsBySheetId[t]) == null ? void 0 : e.store) == null ? void 0 : s.sheetReactive) == null ? void 0 : i.current;
|
|
1981
|
+
}
|
|
1982
|
+
/** @internal */
|
|
1983
|
+
static _stack(...t) {
|
|
1984
|
+
const e = {};
|
|
1985
|
+
return t.forEach((s) => {
|
|
1986
|
+
s != null && s.style && (e.style = { ...e.style, ...s.style }), s != null && s.prevention && (e.prevention = (e.prevention || 0) | s.prevention);
|
|
1987
|
+
}), e;
|
|
1988
|
+
}
|
|
1989
|
+
/** @internal */
|
|
1990
|
+
initialize(t) {
|
|
1991
|
+
var o, a;
|
|
1992
|
+
if (this.status > 1)
|
|
1993
|
+
return;
|
|
1994
|
+
t[0] == null && (t[0] = { width: _e, height: Re });
|
|
1995
|
+
const e = Cs(t, t.__userKeys);
|
|
1996
|
+
this.area = {
|
|
1997
|
+
top: 1,
|
|
1998
|
+
left: 1,
|
|
1999
|
+
bottom: e.numRows,
|
|
2000
|
+
right: e.numCols
|
|
2001
|
+
}, this.idMatrix = new Array(e.numRows + 1), this._colLetters = [];
|
|
2002
|
+
for (let l = 0; l <= e.numCols; l++)
|
|
2003
|
+
this._colLetters[l] = W(l);
|
|
2004
|
+
const s = t.__userKeys ?? Object.keys(t);
|
|
2005
|
+
s.forEach((l) => {
|
|
2006
|
+
if (l === Ft || l === Dt || l === vt)
|
|
2007
|
+
return;
|
|
2008
|
+
const u = Ts(l), h = t[l];
|
|
2009
|
+
u.forEach((c) => {
|
|
2010
|
+
const f = t[c];
|
|
2011
|
+
t[c] = {
|
|
2012
|
+
...f,
|
|
2013
|
+
...h,
|
|
2014
|
+
...$._stack(f, h)
|
|
2015
|
+
};
|
|
2016
|
+
});
|
|
2017
|
+
}), this._common = t == null ? void 0 : t[Ft], this._commonCol = t == null ? void 0 : t[Dt], this._commonRow = t == null ? void 0 : t[vt], this._initCells = t;
|
|
2018
|
+
const i = t.__matrices;
|
|
2019
|
+
if (i) {
|
|
2020
|
+
this._initMatrices = i, this._initFlattenAs = t.__flattenAs, this._matrixByBase = [];
|
|
2021
|
+
for (const l of Object.keys(i)) {
|
|
2022
|
+
const { y: u, x: h } = N(l);
|
|
2023
|
+
this._matrixByBase.push({ baseY: u, baseX: h, matrix: i[l] });
|
|
2024
|
+
}
|
|
2025
|
+
}
|
|
2026
|
+
((o = this._commonCol) == null ? void 0 : o.width) != null && (this.defaultColWidth = this._commonCol.width), ((a = this._commonRow) == null ? void 0 : a.height) != null && (this.defaultRowHeight = this._commonRow.height), this._ensureIdRow(0);
|
|
2027
|
+
for (let l = 0; l <= e.numCols; l++) {
|
|
2028
|
+
const u = this.idMatrix[0][l];
|
|
2029
|
+
this._ensureCellPopulated(0, l, u);
|
|
2030
|
+
}
|
|
2031
|
+
const n = s;
|
|
2032
|
+
for (const l of n) {
|
|
2033
|
+
if (l === Ft || l === Dt || l === vt)
|
|
2034
|
+
continue;
|
|
2035
|
+
const u = N(l), { y: h, x: c } = u;
|
|
2036
|
+
if (h === 0 && c === 0 || h === 0 || c === 0 || h <= 0 || c <= 0 || h > e.numRows || c > e.numCols)
|
|
2037
|
+
continue;
|
|
2038
|
+
const d = this._ensureIdRow(h)[c];
|
|
2039
|
+
d != null && this._ensureCellPopulated(h, c, d);
|
|
2040
|
+
}
|
|
2041
|
+
this.status = 1, this.registry.sheetIdsByName[this.name] = this.id;
|
|
2042
|
+
}
|
|
2043
|
+
/** @internal */
|
|
2044
|
+
_incrementVersion() {
|
|
2045
|
+
this.version++, this.version >= Number.MAX_SAFE_INTEGER && (this.version = 1);
|
|
2046
|
+
}
|
|
2047
|
+
/** @internal */
|
|
2048
|
+
_xsheetDispatch(t) {
|
|
2049
|
+
if (t === this)
|
|
2050
|
+
return;
|
|
2051
|
+
t.refresh(!0);
|
|
2052
|
+
const e = this.registry.contextsBySheetId[t.id];
|
|
2053
|
+
if (e !== null) {
|
|
2054
|
+
const { dispatch: s } = e;
|
|
2055
|
+
requestAnimationFrame(() => {
|
|
2056
|
+
s(this.registry.updateSheet(t));
|
|
2057
|
+
});
|
|
2058
|
+
}
|
|
2059
|
+
}
|
|
2060
|
+
/** @internal */
|
|
2061
|
+
_generateId() {
|
|
2062
|
+
return (this.registry.cellHead++).toString();
|
|
2063
|
+
}
|
|
2064
|
+
/**
|
|
2065
|
+
* Lazily generate the ID row for the given y-coordinate.
|
|
2066
|
+
* If the row already exists, returns it immediately.
|
|
2067
|
+
* @internal
|
|
2068
|
+
*/
|
|
2069
|
+
_ensureIdRow(t) {
|
|
2070
|
+
let e = this.idMatrix[t];
|
|
2071
|
+
if (e != null)
|
|
2072
|
+
return e;
|
|
2073
|
+
const s = this.area.right;
|
|
2074
|
+
e = [];
|
|
2075
|
+
for (let i = 0; i <= s; i++) {
|
|
2076
|
+
const n = this._generateId();
|
|
2077
|
+
e.push(n);
|
|
2078
|
+
const o = this._colLetters[i] || W(i);
|
|
2079
|
+
this.addressCaches.set(n, t === 0 ? `${o}0` : i === 0 ? `0${t}` : `${o}${t}`);
|
|
2080
|
+
}
|
|
2081
|
+
return this.idMatrix[t] = e, e;
|
|
2082
|
+
}
|
|
2083
|
+
/**
|
|
2084
|
+
* Ensure that registry.data and registry.systems exist for a given cell.
|
|
2085
|
+
* Performs lazy cell stacking using stored initialization defaults.
|
|
2086
|
+
* @internal
|
|
2087
|
+
*/
|
|
2088
|
+
_ensureCellPopulated(t, e, s) {
|
|
2089
|
+
var l, u;
|
|
2090
|
+
if (this.registry.data[s] != null)
|
|
2091
|
+
return;
|
|
2092
|
+
const i = this._initCells, n = Date.now();
|
|
2093
|
+
let o;
|
|
2094
|
+
if (t === 0 && e > 0) {
|
|
2095
|
+
const h = this._colLetters[e] || W(e), c = i == null ? void 0 : i[h], { style: f, ...d } = c ?? {}, p = i == null ? void 0 : i[h + "0"];
|
|
2096
|
+
o = {
|
|
2097
|
+
...this._commonCol,
|
|
2098
|
+
...d,
|
|
2099
|
+
...p,
|
|
2100
|
+
...$._stack(this._commonCol, p)
|
|
2101
|
+
};
|
|
2102
|
+
} else if (e === 0 && t > 0) {
|
|
2103
|
+
const h = Et(t), c = i == null ? void 0 : i[h], { style: f, ...d } = c ?? {}, p = i == null ? void 0 : i["0" + h];
|
|
2104
|
+
o = {
|
|
2105
|
+
...this._commonRow,
|
|
2106
|
+
...d,
|
|
2107
|
+
...p,
|
|
2108
|
+
...$._stack(this._commonRow, p)
|
|
2109
|
+
};
|
|
2110
|
+
} else if (t === 0 && e === 0) {
|
|
2111
|
+
const h = i == null ? void 0 : i["0"];
|
|
2112
|
+
o = { ...h, ...$._stack(h) };
|
|
2113
|
+
} else {
|
|
2114
|
+
const h = this._colLetters[e] || W(e), c = Et(t), f = `${h}${c}`, d = i == null ? void 0 : i[c], p = i == null ? void 0 : i[h];
|
|
2115
|
+
let m = i == null ? void 0 : i[f];
|
|
2116
|
+
if ((m == null || !("value" in m)) && this._matrixByBase.length > 0)
|
|
2117
|
+
for (const { baseY: g, baseX: y, matrix: R } of this._matrixByBase) {
|
|
2118
|
+
const A = t - g, w = e - y;
|
|
2119
|
+
if (A >= 0 && A < R.length && w >= 0 && w < R[A].length) {
|
|
2120
|
+
const S = R[A][w];
|
|
2121
|
+
let _;
|
|
2122
|
+
this._initFlattenAs ? _ = { [this._initFlattenAs]: S } : _ = S, m = m ? { ..._, ...m } : _;
|
|
2123
|
+
break;
|
|
2124
|
+
}
|
|
2125
|
+
}
|
|
2126
|
+
o = {
|
|
2127
|
+
...this._common,
|
|
2128
|
+
...d,
|
|
2129
|
+
...p,
|
|
2130
|
+
...m,
|
|
2131
|
+
...$._stack(this._common, d, p, m)
|
|
2132
|
+
};
|
|
2133
|
+
}
|
|
2134
|
+
(u = (l = o == null ? void 0 : o.value) == null ? void 0 : l.startsWith) != null && u.call(l, "=") && ((o == null ? void 0 : o.formulaEnabled) ?? !0) && this.idsToBeIdentified.push(s), t === 0 ? o.width == null && (o.width = jt) : e === 0 ? (o.height == null && (o.height = J), o.height !== (this.defaultRowHeight || J) && this._rowHeightOverrides.set(t, o.height), o.filtered && this._filteredRows.add(t)) : (delete o.height, delete o.width, delete o.label), o = (this.policies[o.policy ?? ""] ?? this.defaultPolicy).deserializeValue(o.value, o) ?? {}, this.registry.systems[s] = { ...this.registry.systems[s], id: s, changedTime: n, sheetId: this.id }, this.registry.data[s] = o;
|
|
2135
|
+
}
|
|
2136
|
+
/**
|
|
2137
|
+
* Materialize all lazy ID rows. Call this before operations that need the full
|
|
2138
|
+
* idMatrix (e.g. .flat(), .map(), .slice() for sort/move/undo/redo).
|
|
2139
|
+
* @internal
|
|
2140
|
+
*/
|
|
2141
|
+
_materializeIdMatrix() {
|
|
2142
|
+
for (let t = 0; t < this.idMatrix.length; t++)
|
|
2143
|
+
this.idMatrix[t] == null && this._ensureIdRow(t);
|
|
2144
|
+
}
|
|
2145
|
+
/**
|
|
2146
|
+
* Compute the absolute top offset for a given row using arithmetic + overrides.
|
|
2147
|
+
* Avoids iterating all rows — O(overrides) instead of O(numRows).
|
|
2148
|
+
* @internal
|
|
2149
|
+
*/
|
|
2150
|
+
getOffsetTop(t) {
|
|
2151
|
+
const e = this.headerHeight, s = this.defaultRowHeight || J;
|
|
2152
|
+
let i = e + (t - 1) * s;
|
|
2153
|
+
for (const [n, o] of this._rowHeightOverrides)
|
|
2154
|
+
n < t && (i += o - s);
|
|
2155
|
+
for (const n of this._filteredRows)
|
|
2156
|
+
if (n < t) {
|
|
2157
|
+
const o = this._rowHeightOverrides.get(n) ?? s;
|
|
2158
|
+
i -= o;
|
|
2159
|
+
}
|
|
2160
|
+
return i;
|
|
2161
|
+
}
|
|
2162
|
+
/**
|
|
2163
|
+
* Re-key the row-metadata caches after rows are removed at [y, y+numRows).
|
|
2164
|
+
* These maps are keyed by absolute row number, so deletions must drop the removed
|
|
2165
|
+
* keys and shift later keys down — otherwise stale entries corrupt getOffsetTop().
|
|
2166
|
+
* @internal
|
|
2167
|
+
*/
|
|
2168
|
+
_shiftRowMetaForRemove(t, e) {
|
|
2169
|
+
const s = /* @__PURE__ */ new Map();
|
|
2170
|
+
for (const [n, o] of this._rowHeightOverrides)
|
|
2171
|
+
n < t ? s.set(n, o) : n >= t + e && s.set(n - e, o);
|
|
2172
|
+
this._rowHeightOverrides = s;
|
|
2173
|
+
const i = /* @__PURE__ */ new Set();
|
|
2174
|
+
for (const n of this._filteredRows)
|
|
2175
|
+
n < t ? i.add(n) : n >= t + e && i.add(n - e);
|
|
2176
|
+
this._filteredRows = i;
|
|
2177
|
+
}
|
|
2178
|
+
/**
|
|
2179
|
+
* Re-key the row-metadata caches after numRows are inserted at y, shifting keys >= y up.
|
|
2180
|
+
* @internal
|
|
2181
|
+
*/
|
|
2182
|
+
_shiftRowMetaForInsert(t, e) {
|
|
2183
|
+
const s = /* @__PURE__ */ new Map();
|
|
2184
|
+
for (const [n, o] of this._rowHeightOverrides)
|
|
2185
|
+
s.set(n < t ? n : n + e, o);
|
|
2186
|
+
this._rowHeightOverrides = s;
|
|
2187
|
+
const i = /* @__PURE__ */ new Set();
|
|
2188
|
+
for (const n of this._filteredRows)
|
|
2189
|
+
i.add(n < t ? n : n + e);
|
|
2190
|
+
this._filteredRows = i;
|
|
2191
|
+
}
|
|
2192
|
+
/**
|
|
2193
|
+
* (Re)seed row-metadata for the rows at [y, y+numRows) from their current header cells.
|
|
2194
|
+
* Used after rows are added (insert / undo-remove / redo-insert) so non-default heights
|
|
2195
|
+
* and filtered state are reflected immediately rather than only on the next lazy read.
|
|
2196
|
+
* @internal
|
|
2197
|
+
*/
|
|
2198
|
+
_seedRowMeta(t, e) {
|
|
2199
|
+
const s = this.defaultRowHeight || J;
|
|
2200
|
+
for (let i = 0; i < e; i++) {
|
|
2201
|
+
const n = t + i, o = this.getId({ y: n, x: 0 }), a = o ? this.registry.data[o] : void 0;
|
|
2202
|
+
(a == null ? void 0 : a.height) != null && a.height !== s ? this._rowHeightOverrides.set(n, a.height) : this._rowHeightOverrides.delete(n), a != null && a.filtered ? this._filteredRows.add(n) : this._filteredRows.delete(n);
|
|
2203
|
+
}
|
|
2204
|
+
}
|
|
2205
|
+
getRectSize({ top: t, left: e, bottom: s, right: i }) {
|
|
2206
|
+
var d, p;
|
|
2207
|
+
const n = e || 1, o = t || 1, a = ((d = this.registry.systems[this.getId({ y: 0, x: i })]) == null ? void 0 : d.offsetLeft) ?? 0, l = ((p = this.registry.systems[this.getId({ y: 0, x: n })]) == null ? void 0 : p.offsetLeft) ?? 0, u = this.getOffsetTop(s), h = this.getOffsetTop(o), c = Math.max(0, a - l), f = Math.max(0, u - h);
|
|
2208
|
+
return { y: o, x: n, height: f, width: c };
|
|
2209
|
+
}
|
|
2210
|
+
/** @internal */
|
|
2211
|
+
setTotalSize() {
|
|
2212
|
+
const t = this.numCols, e = this.numRows, s = this.headerWidth, i = this.headerHeight, n = this.defaultRowHeight || J;
|
|
2213
|
+
let o = 0;
|
|
2214
|
+
for (let h = 1; h <= t; h++) {
|
|
2215
|
+
const c = this.getCell({ y: 0, x: h }, { resolution: "SYSTEM" }), f = (c == null ? void 0 : c.width) || this.defaultColWidth || jt, d = this.registry.systems[this.getId({ y: 0, x: h })];
|
|
2216
|
+
d != null && (d.offsetLeft = s + o), o += f;
|
|
2217
|
+
}
|
|
2218
|
+
this.totalWidth = s + o;
|
|
2219
|
+
let a = 0, l = 0;
|
|
2220
|
+
for (const [h, c] of this._rowHeightOverrides)
|
|
2221
|
+
h >= 1 && h <= e && (a += c - n);
|
|
2222
|
+
for (const h of this._filteredRows)
|
|
2223
|
+
if (h >= 1 && h <= e) {
|
|
2224
|
+
const c = this._rowHeightOverrides.get(h) ?? n;
|
|
2225
|
+
l += c;
|
|
2226
|
+
}
|
|
2227
|
+
const u = e * n + a;
|
|
2228
|
+
this.totalHeight = i + u - l, this.fullHeight = i + u;
|
|
2229
|
+
}
|
|
2230
|
+
/** @internal */
|
|
2231
|
+
refresh(t = !1, e = !1) {
|
|
2232
|
+
return this._incrementVersion(), this.lastChangedTime = this.changedTime, this.changedTime = Date.now(), this.clearSolvedCaches(), this._stripped = wt, t && this.addressCaches.clear(), e && this.setTotalSize(), this;
|
|
2233
|
+
}
|
|
2234
|
+
/** @internal */
|
|
2235
|
+
clone(t = !1) {
|
|
2236
|
+
const e = Object.assign(Object.create(Object.getPrototypeOf(this)), this);
|
|
2237
|
+
return e._stripped = wt, e.refresh(t);
|
|
2238
|
+
}
|
|
2239
|
+
/** @internal */
|
|
2240
|
+
getPointById(t, e = 0, s = 0) {
|
|
2241
|
+
const i = t.startsWith("$");
|
|
2242
|
+
i && (t = t.slice(1), s = 0);
|
|
2243
|
+
const n = t.endsWith("$");
|
|
2244
|
+
n && (t = t.slice(0, -1), e = 0);
|
|
2245
|
+
const o = this.addressCaches.get(t);
|
|
2246
|
+
if (o) {
|
|
2247
|
+
const a = N(o);
|
|
2248
|
+
return { y: a.y + e, x: a.x + s, absCol: i, absRow: n };
|
|
2249
|
+
}
|
|
2250
|
+
this._materializeIdMatrix();
|
|
2251
|
+
for (let a = 0; a < this.idMatrix.length; a++) {
|
|
2252
|
+
const l = this.idMatrix[a];
|
|
2253
|
+
for (let u = 0; u < l.length; u++) {
|
|
2254
|
+
const h = l[u], c = D({ y: a, x: u });
|
|
2255
|
+
if (this.addressCaches.set(h, c), h === t)
|
|
2256
|
+
return {
|
|
2257
|
+
y: a + e,
|
|
2258
|
+
x: u + s,
|
|
2259
|
+
absCol: i,
|
|
2260
|
+
absRow: n
|
|
2261
|
+
};
|
|
2262
|
+
}
|
|
2263
|
+
}
|
|
2264
|
+
return { y: -1, x: -1, absCol: i, absRow: n };
|
|
2265
|
+
}
|
|
2266
|
+
/** @internal */
|
|
2267
|
+
getAddressById(t, e = 0, s = 0) {
|
|
2268
|
+
const { y: i, x: n, absCol: o, absRow: a } = this.getPointById(t, e, s);
|
|
2269
|
+
return Le(D({ y: i, x: n }), o, a);
|
|
2270
|
+
}
|
|
2271
|
+
/** @internal */
|
|
2272
|
+
clearAddressCaches() {
|
|
2273
|
+
this.addressCaches.clear();
|
|
2274
|
+
}
|
|
2275
|
+
/** @internal */
|
|
2276
|
+
_warmAddressCaches() {
|
|
2277
|
+
this._materializeIdMatrix();
|
|
2278
|
+
for (let t = 0; t < this.idMatrix.length; t++) {
|
|
2279
|
+
const e = this.idMatrix[t];
|
|
2280
|
+
for (let s = 0; s < e.length; s++)
|
|
2281
|
+
this.addressCaches.set(e[s], D({ y: t, x: s }));
|
|
2282
|
+
}
|
|
2283
|
+
}
|
|
2284
|
+
/** @internal */
|
|
2285
|
+
getId(t) {
|
|
2286
|
+
var i;
|
|
2287
|
+
const { y: e, x: s } = t;
|
|
2288
|
+
return e >= 0 && s >= 0 && e <= this.area.bottom && s <= this.area.right ? this._ensureIdRow(e)[s] : (i = this.idMatrix[e]) == null ? void 0 : i[s];
|
|
2289
|
+
}
|
|
2290
|
+
/** @internal */
|
|
2291
|
+
getCell(t, { resolution: e = "RESOLVED", raise: s = !1 } = {}) {
|
|
2292
|
+
const { y: i, x: n } = t;
|
|
2293
|
+
if (i === -1 || n === -1)
|
|
2294
|
+
return;
|
|
2295
|
+
const o = this.getId(t);
|
|
2296
|
+
if (o == null)
|
|
2297
|
+
return;
|
|
2298
|
+
this._ensureCellPopulated(i, n, o);
|
|
2299
|
+
const a = this.registry.data[o];
|
|
2300
|
+
if (a == null)
|
|
2301
|
+
return;
|
|
2302
|
+
let l = a.value;
|
|
2303
|
+
return e !== "SYSTEM" && (a.formulaEnabled ?? !0) && (l = te({ value: l, sheet: this, point: t, raise: s, resolution: e, at: o })), { ...a, value: l };
|
|
2304
|
+
}
|
|
2305
|
+
/** @internal */
|
|
2306
|
+
get numRows() {
|
|
2307
|
+
const { top: t, bottom: e } = this.area;
|
|
2308
|
+
return 1 + e - t;
|
|
2309
|
+
}
|
|
2310
|
+
get numCols() {
|
|
2311
|
+
const { left: t, right: e } = this.area;
|
|
2312
|
+
return 1 + e - t;
|
|
2313
|
+
}
|
|
2314
|
+
get top() {
|
|
2315
|
+
return this.area.top;
|
|
2316
|
+
}
|
|
2317
|
+
get left() {
|
|
2318
|
+
return this.area.left;
|
|
2319
|
+
}
|
|
2320
|
+
get bottom() {
|
|
2321
|
+
return this.area.bottom;
|
|
2322
|
+
}
|
|
2323
|
+
get right() {
|
|
2324
|
+
return this.area.right;
|
|
2325
|
+
}
|
|
2326
|
+
/** @internal */
|
|
2327
|
+
_toValueMatrix({
|
|
2328
|
+
area: t,
|
|
2329
|
+
at: e,
|
|
2330
|
+
resolution: s = "RESOLVED",
|
|
2331
|
+
raise: i = !1,
|
|
2332
|
+
filter: n = pi,
|
|
2333
|
+
asScalar: o = !1
|
|
2334
|
+
} = {}) {
|
|
2335
|
+
const { top: a, left: l, bottom: u, right: h } = t ?? this.area, c = se(u - a + 1, h - l + 1);
|
|
2336
|
+
for (let f = a; f <= u; f++)
|
|
2337
|
+
for (let d = l; d <= h; d++) {
|
|
2338
|
+
const p = this.getId({ y: f, x: d });
|
|
2339
|
+
if (e === p)
|
|
2340
|
+
throw new x("#REF!", "References are circulating.");
|
|
2341
|
+
const m = this.getCell({ y: f, x: d }, { resolution: s, raise: i }) ?? {};
|
|
2342
|
+
if (n(m)) {
|
|
2343
|
+
let g = m.value;
|
|
2344
|
+
o && (g = this.getPolicy({ y: f, x: d }).toScalar({ value: m.value, cell: m, sheet: this, point: { y: f, x: d } })), c[f - a][d - l] = g;
|
|
2345
|
+
}
|
|
2346
|
+
}
|
|
2347
|
+
return c;
|
|
2348
|
+
}
|
|
2349
|
+
/** @internal */
|
|
2350
|
+
_pushHistory(t) {
|
|
2351
|
+
const e = this.registry;
|
|
2352
|
+
if (e.histories.splice(e.historyIndex + 1, e.histories.length).forEach(this._cleanStrayed.bind(this)), e.histories.push(t), e.lastHistory = e.currentHistory = t, e.histories.length > e.historyLimit) {
|
|
2353
|
+
const i = e.histories.splice(0, 1)[0];
|
|
2354
|
+
this._cleanObsolete(i);
|
|
2355
|
+
} else
|
|
2356
|
+
e.historyIndex++;
|
|
2357
|
+
}
|
|
2358
|
+
/** @internal */
|
|
2359
|
+
_cleanObsolete(t) {
|
|
2360
|
+
(t.operation === "REMOVE_ROWS" || t.operation === "REMOVE_COLS") && t.deleted.forEach((e) => {
|
|
2361
|
+
e.forEach((s) => {
|
|
2362
|
+
this._deleteOrphanedId(s);
|
|
2363
|
+
});
|
|
2364
|
+
}), t.operation === "MOVE" && t.moveRelations.forEach((e) => {
|
|
2365
|
+
e.new != null && this._deleteOrphanedId(e.new), e.lost != null && this._deleteOrphanedId(e.lost);
|
|
2366
|
+
});
|
|
2367
|
+
}
|
|
2368
|
+
/** @internal */
|
|
2369
|
+
_cleanStrayed(t) {
|
|
2370
|
+
(t.operation === "INSERT_ROWS" || t.operation === "INSERT_COLS") && t.idMatrix.forEach((e) => {
|
|
2371
|
+
e.forEach((s) => {
|
|
2372
|
+
this._deleteOrphanedId(s);
|
|
2373
|
+
});
|
|
2374
|
+
});
|
|
2375
|
+
}
|
|
2376
|
+
/**
|
|
2377
|
+
* Remove an id from registry.data and registry.dependents entirely.
|
|
2378
|
+
* @internal
|
|
2379
|
+
*/
|
|
2380
|
+
_deleteOrphanedId(t) {
|
|
2381
|
+
var s;
|
|
2382
|
+
const e = this.registry.systems[t];
|
|
2383
|
+
(s = e == null ? void 0 : e.dependencies) == null || s.forEach((i) => {
|
|
2384
|
+
var n, o;
|
|
2385
|
+
(o = (n = this.registry.systems[i]) == null ? void 0 : n.dependents) == null || o.delete(t);
|
|
2386
|
+
}), delete this.registry.data[t], delete this.registry.systems[t];
|
|
2387
|
+
}
|
|
2388
|
+
/** @internal */
|
|
2389
|
+
_copyCellLayout(t) {
|
|
2390
|
+
if (t == null)
|
|
2391
|
+
return;
|
|
2392
|
+
const e = {};
|
|
2393
|
+
return t.style != null && (e.style = t.style), t.justifyContent != null && (e.justifyContent = t.justifyContent), t.alignItems != null && (e.alignItems = t.alignItems), t.policy != null && (e.policy = t.policy), t.width != null && (e.width = t.width), t.height != null && (e.height = t.height), e;
|
|
2394
|
+
}
|
|
2395
|
+
move({
|
|
2396
|
+
srcSheet: t = this,
|
|
2397
|
+
src: e,
|
|
2398
|
+
dst: s,
|
|
2399
|
+
historicize: i = !0,
|
|
2400
|
+
operator: n = "SYSTEM",
|
|
2401
|
+
undoReflection: o,
|
|
2402
|
+
redoReflection: a
|
|
2403
|
+
}) {
|
|
2404
|
+
const l = t.__raw__, u = this._createMoveRelations(l, e, this, s), { diffBefore: h, diffAfter: c } = this._moveCells(l, this, u, !1, n);
|
|
2405
|
+
return this._xsheetDispatch(l), i && this._pushHistory({
|
|
2406
|
+
applyed: !0,
|
|
2407
|
+
operation: "MOVE",
|
|
2408
|
+
srcSheetId: l.id,
|
|
2409
|
+
dstSheetId: this.id,
|
|
2410
|
+
undoReflection: o,
|
|
2411
|
+
redoReflection: a,
|
|
2412
|
+
diffBefore: h,
|
|
2413
|
+
diffAfter: c,
|
|
2414
|
+
moveRelations: u
|
|
2415
|
+
}), this.refresh(!0);
|
|
2416
|
+
}
|
|
2417
|
+
/**
|
|
2418
|
+
* Build MoveRelations from src area to dst area, skipping filtered rows.
|
|
2419
|
+
*
|
|
2420
|
+
* Layout of the returned array (processed in this order by _moveCells):
|
|
2421
|
+
* 1. Entries where [0] is a newly-generated ID — these fill the vacated src cells (processed last in forward order)
|
|
2422
|
+
* 2. Entries where [0] is a src address and [1] is a dst address — the actual moves (processed first in forward order, descending)
|
|
2423
|
+
* Entries whose [1] is an existing ID mean the destination cell is displaced/overflowed and
|
|
2424
|
+
* is no longer addressable; on forward pass they are skipped; on reverse pass the ID is written back.
|
|
2425
|
+
*/
|
|
2426
|
+
/** @internal */
|
|
2427
|
+
_createMoveRelations(t, e, s, i) {
|
|
2428
|
+
const { top: n, left: o, bottom: a, right: l } = e, { top: u, left: h } = i, c = s.numRows, f = s.numCols, d = [];
|
|
2429
|
+
for (let w = n; w <= a; w++)
|
|
2430
|
+
t.isRowFiltered(w) || d.push(w);
|
|
2431
|
+
const p = l - o + 1, m = d.length, g = [];
|
|
2432
|
+
{
|
|
2433
|
+
let w = 0, S = u;
|
|
2434
|
+
for (; w < m; )
|
|
2435
|
+
s.isRowFiltered(S) || (g.push(S), w++), S++;
|
|
2436
|
+
}
|
|
2437
|
+
const y = /* @__PURE__ */ new Set();
|
|
2438
|
+
for (let w = 0; w < m; w++)
|
|
2439
|
+
for (let S = 0; S < p; S++)
|
|
2440
|
+
y.add(D({ y: d[w], x: o + S }));
|
|
2441
|
+
const R = /* @__PURE__ */ new Set();
|
|
2442
|
+
for (let w = 0; w < m; w++) {
|
|
2443
|
+
const S = g[w];
|
|
2444
|
+
for (let _ = 0; _ < p; _++) {
|
|
2445
|
+
const M = h + _;
|
|
2446
|
+
S <= c && M <= f && R.add(D({ y: S, x: M }));
|
|
2447
|
+
}
|
|
2448
|
+
}
|
|
2449
|
+
const A = [];
|
|
2450
|
+
for (let w = 0; w < m; w++) {
|
|
2451
|
+
const S = d[w], _ = g[w];
|
|
2452
|
+
for (let M = 0; M < p; M++) {
|
|
2453
|
+
const T = o + M, C = h + M, Y = D({ y: S, x: T }), U = _ <= c && C <= f, G = U ? D({ y: _, x: C }) : void 0;
|
|
2454
|
+
let V;
|
|
2455
|
+
t === s && R.has(Y) || (V = t._generateId());
|
|
2456
|
+
let q;
|
|
2457
|
+
if (U) {
|
|
2458
|
+
if (!(t === s && y.has(G))) {
|
|
2459
|
+
const P = s.getId({ y: _, x: C });
|
|
2460
|
+
P != null && (q = P);
|
|
2461
|
+
}
|
|
2462
|
+
} else {
|
|
2463
|
+
const P = t.getId({ y: S, x: T });
|
|
2464
|
+
P != null && (q = P);
|
|
2465
|
+
}
|
|
2466
|
+
const K = t.getCell({ y: S, x: T }, { resolution: "SYSTEM" }), v = U ? s.getCell({ y: _, x: C }, { resolution: "SYSTEM" }) : void 0;
|
|
2467
|
+
A.push({
|
|
2468
|
+
before: K == null ? void 0 : K.policy,
|
|
2469
|
+
after: v == null ? void 0 : v.policy,
|
|
2470
|
+
src: Y,
|
|
2471
|
+
dst: G,
|
|
2472
|
+
new: V,
|
|
2473
|
+
lost: q
|
|
2474
|
+
});
|
|
2475
|
+
}
|
|
2476
|
+
}
|
|
2477
|
+
return A;
|
|
2478
|
+
}
|
|
2479
|
+
get defaultPolicy() {
|
|
2480
|
+
return this.policies[xt] ?? ei;
|
|
2481
|
+
}
|
|
2482
|
+
/**
|
|
2483
|
+
* Apply (or reverse) a MoveRelations list.
|
|
2484
|
+
*
|
|
2485
|
+
* Forward (reverse=false): process descending — actual ID moves happen bottom-up so
|
|
2486
|
+
* earlier entries don't clobber later ones; vacate entries (at front of array) are
|
|
2487
|
+
* applied last.
|
|
2488
|
+
* Reverse (reverse=true): process ascending — restores IDs in the natural order.
|
|
2489
|
+
*
|
|
2490
|
+
* On forward pass: applies policy, collects diffBefore, runs ReferencePreserver.
|
|
2491
|
+
* On reverse pass: only moves IDs (caller is responsible for applyDiff(diffBefore)).
|
|
2492
|
+
*/
|
|
2493
|
+
/** @internal */
|
|
2494
|
+
_moveCells(t, e, s, i, n = "SYSTEM") {
|
|
2495
|
+
const o = {}, a = new lt(e), l = {}, u = [], h = [];
|
|
2496
|
+
if (i)
|
|
2497
|
+
for (const {
|
|
2498
|
+
before: m,
|
|
2499
|
+
after: g,
|
|
2500
|
+
src: y,
|
|
2501
|
+
dst: R,
|
|
2502
|
+
new: A,
|
|
2503
|
+
lost: w
|
|
2504
|
+
} of s) {
|
|
2505
|
+
if (R != null) {
|
|
2506
|
+
const S = N(R), _ = e.getId(S);
|
|
2507
|
+
if (_ != null) {
|
|
2508
|
+
const M = N(y);
|
|
2509
|
+
u.push({ y: M.y, x: M.x, id: _ });
|
|
2510
|
+
}
|
|
2511
|
+
}
|
|
2512
|
+
if (w != null)
|
|
2513
|
+
if (R != null) {
|
|
2514
|
+
const S = N(R);
|
|
2515
|
+
h.push({ y: S.y, x: S.x, id: w });
|
|
2516
|
+
} else {
|
|
2517
|
+
const S = N(y);
|
|
2518
|
+
u.push({ y: S.y, x: S.x, id: w });
|
|
2519
|
+
}
|
|
2520
|
+
}
|
|
2521
|
+
else
|
|
2522
|
+
for (const {
|
|
2523
|
+
before: m,
|
|
2524
|
+
after: g,
|
|
2525
|
+
src: y,
|
|
2526
|
+
dst: R,
|
|
2527
|
+
new: A,
|
|
2528
|
+
lost: w
|
|
2529
|
+
} of s) {
|
|
2530
|
+
const S = N(y), _ = t.getId(S), M = R != null ? N(R) : void 0, T = M != null ? e.getId(M) : void 0, C = _ != null ? t.registry.data[_] : void 0, Y = T != null ? e.registry.data[T] : void 0;
|
|
2531
|
+
if (!(n === "USER" && (O(C == null ? void 0 : C.prevention, It) || O(Y == null ? void 0 : Y.prevention, Tt)))) {
|
|
2532
|
+
if (A != null) {
|
|
2533
|
+
const U = m || xt, V = (t.policies[U] ?? t.defaultPolicy).select({
|
|
2534
|
+
sheet: t,
|
|
2535
|
+
point: S,
|
|
2536
|
+
next: { value: null },
|
|
2537
|
+
current: C,
|
|
2538
|
+
operation: It
|
|
2539
|
+
});
|
|
2540
|
+
l[A] = {
|
|
2541
|
+
...V,
|
|
2542
|
+
policy: m
|
|
2543
|
+
}, this.registry.systems[A] = { id: A, sheetId: t.id, changedTime: Date.now() }, u.push({ y: S.y, x: S.x, id: A });
|
|
2544
|
+
}
|
|
2545
|
+
if (T != null && M != null && R != null) {
|
|
2546
|
+
const U = g || xt, G = m || xt, V = e.policies[U] ?? e.defaultPolicy, q = t.policies[G] ?? t.defaultPolicy, K = q.priority > V.priority, P = (K ? q : V).select({
|
|
2547
|
+
sheet: e,
|
|
2548
|
+
point: M,
|
|
2549
|
+
next: C,
|
|
2550
|
+
current: Y,
|
|
2551
|
+
operation: Tt
|
|
2552
|
+
});
|
|
2553
|
+
if (P && (o[_] = C ?? {}, l[_] = {
|
|
2554
|
+
...C,
|
|
2555
|
+
...P,
|
|
2556
|
+
policy: K ? m : g
|
|
2557
|
+
}), C != null) {
|
|
2558
|
+
const ct = this.registry.systems[_];
|
|
2559
|
+
ct && (ct.changedTime = Date.now());
|
|
2560
|
+
}
|
|
2561
|
+
h.push({ y: M.y, x: M.x, id: _ });
|
|
2562
|
+
}
|
|
2563
|
+
}
|
|
2564
|
+
}
|
|
2565
|
+
i || (t._materializeIdMatrix(), t !== e && e._materializeIdMatrix());
|
|
2566
|
+
const c = i ? null : t.idMatrix.flat(), f = !i && t !== e ? e.idMatrix.flat() : null;
|
|
2567
|
+
Object.assign(this.registry.data, l);
|
|
2568
|
+
for (const { y: m, x: g, id: y } of u)
|
|
2569
|
+
t._ensureIdRow(m)[g] = y;
|
|
2570
|
+
for (const { y: m, x: g, id: y } of h)
|
|
2571
|
+
e._ensureIdRow(m)[g] = y;
|
|
2572
|
+
const d = s.filter((m) => m.dst != null).map((m) => m.dst), p = s.map((m) => m.src);
|
|
2573
|
+
if (t === e ? e.lastChangedAddresses = [.../* @__PURE__ */ new Set([...p, ...d])] : (e.lastChangedAddresses = d, t.lastChangedAddresses = p), !i) {
|
|
2574
|
+
a.buildMap(c.flat(), t.idMatrix.flat()), t !== e && a.buildMap(f.flat(), e.idMatrix.flat());
|
|
2575
|
+
const m = a.resolveDependents("move");
|
|
2576
|
+
Object.assign(o, m);
|
|
2577
|
+
}
|
|
2578
|
+
return { diffBefore: o, diffAfter: {} };
|
|
2579
|
+
}
|
|
2580
|
+
copy({
|
|
2581
|
+
srcSheet: t = this,
|
|
2582
|
+
src: e,
|
|
2583
|
+
dst: s,
|
|
2584
|
+
onlyValue: i = !1,
|
|
2585
|
+
operator: n = "SYSTEM",
|
|
2586
|
+
undoReflection: o,
|
|
2587
|
+
redoReflection: a
|
|
2588
|
+
}) {
|
|
2589
|
+
const l = t !== this, { top: u, left: h, bottom: c, right: f } = e, { top: d, left: p, bottom: m, right: g } = s, y = {}, R = Date.now(), A = [];
|
|
2590
|
+
for (let T = u; T <= c; T++)
|
|
2591
|
+
t.isRowFiltered(T) || A.push(T);
|
|
2592
|
+
const w = [];
|
|
2593
|
+
for (let T = d; T <= m; T++)
|
|
2594
|
+
T > this.numRows || this.isRowFiltered(T) || w.push(T);
|
|
2595
|
+
const S = A.length, _ = f - h + 1, M = g - p + 1;
|
|
2596
|
+
for (let T = 0; T < w.length; T++) {
|
|
2597
|
+
const C = w[T], Y = A[T % S];
|
|
2598
|
+
for (let U = 0; U <= M - 1; U++) {
|
|
2599
|
+
const G = p + U;
|
|
2600
|
+
if (G > this.numCols)
|
|
2601
|
+
continue;
|
|
2602
|
+
const V = h + U % _, q = l ? 0 : C - Y, K = l ? 0 : G - V, v = {
|
|
2603
|
+
...t.getCell({ y: Y, x: V }, { resolution: "SYSTEM" })
|
|
2604
|
+
}, P = { y: C, x: G }, ct = this.getCell(P, { resolution: "SYSTEM" }), os = this.getPolicy(P), xe = { y: Y, x: V }, as = t.getPolicy(xe), Xt = t.getCell(xe, { resolution: "SYSTEM" }), cs = as.priority > os.priority;
|
|
2605
|
+
v.policy = cs ? Xt == null ? void 0 : Xt.policy : ct == null ? void 0 : ct.policy;
|
|
2606
|
+
const be = this.getId(P);
|
|
2607
|
+
this.clearDependencies(be);
|
|
2608
|
+
const ls = (v == null ? void 0 : v.formulaEnabled) ?? !0 ? this.processFormula(v == null ? void 0 : v.value, {
|
|
2609
|
+
dependency: be,
|
|
2610
|
+
slideY: q,
|
|
2611
|
+
slideX: K
|
|
2612
|
+
}) : v == null ? void 0 : v.value, hs = this.getId(P), Se = this.registry.systems[hs];
|
|
2613
|
+
Se != null && (Se.changedTime = R);
|
|
2614
|
+
const us = D(P);
|
|
2615
|
+
if (i) {
|
|
2616
|
+
const Z = this.getCell(P, { resolution: "SYSTEM" });
|
|
2617
|
+
v.style = Z == null ? void 0 : Z.style, v.justifyContent = Z == null ? void 0 : Z.justifyContent, v.alignItems = Z == null ? void 0 : Z.alignItems;
|
|
2618
|
+
}
|
|
2619
|
+
y[us] = { ...v, value: ls };
|
|
2620
|
+
}
|
|
2621
|
+
}
|
|
2622
|
+
return this.update({
|
|
2623
|
+
diff: y,
|
|
2624
|
+
partial: !1,
|
|
2625
|
+
operator: n,
|
|
2626
|
+
operation: ce,
|
|
2627
|
+
undoReflection: o,
|
|
2628
|
+
redoReflection: a
|
|
2629
|
+
});
|
|
2630
|
+
}
|
|
2631
|
+
getPolicy(t) {
|
|
2632
|
+
const e = this.getCell(t, { resolution: "SYSTEM" });
|
|
2633
|
+
return (e == null ? void 0 : e.policy) == null ? this.defaultPolicy : this.policies[e.policy] ?? this.defaultPolicy;
|
|
2634
|
+
}
|
|
2635
|
+
/** @internal */
|
|
2636
|
+
_update({
|
|
2637
|
+
diff: t,
|
|
2638
|
+
partial: e = !0,
|
|
2639
|
+
updateChangedTime: s = !0,
|
|
2640
|
+
ignoreFields: i = ["label"],
|
|
2641
|
+
operator: n = "SYSTEM",
|
|
2642
|
+
operation: o = St,
|
|
2643
|
+
formulaIdentify: a = !0
|
|
2644
|
+
}) {
|
|
2645
|
+
const l = {}, u = {}, h = [], c = Date.now();
|
|
2646
|
+
let f = !1;
|
|
2647
|
+
return Object.keys(t).forEach((d) => {
|
|
2648
|
+
var w, S, _, M, T;
|
|
2649
|
+
const p = N(d), m = this.getId(p), g = this.registry.data[m];
|
|
2650
|
+
if (n === "USER" && O(g == null ? void 0 : g.prevention, St))
|
|
2651
|
+
return;
|
|
2652
|
+
let y = { ...t[d] };
|
|
2653
|
+
if (a && "value" in y && (y.formulaEnabled ?? (g == null ? void 0 : g.formulaEnabled) ?? !0) && (this.clearDependencies(m), y.value = this.processFormula(y.value, { dependency: m })), i.forEach((C) => {
|
|
2654
|
+
y[C] = g == null ? void 0 : g[C];
|
|
2655
|
+
}), n === "USER" && O(g == null ? void 0 : g.prevention, ht) && delete y.value, n === "USER" && O(g == null ? void 0 : g.prevention, zt) && ((w = y == null ? void 0 : y.style) == null || delete w.justifyContent, (S = y == null ? void 0 : y.style) == null || delete S.alignItems), n === "USER" && O(g == null ? void 0 : g.prevention, Vt) && ((_ = y == null ? void 0 : y.style) == null || delete _.width, (M = y == null ? void 0 : y.style) == null || delete M.height), (y.width != null || y.height != null) && (f = !0), l[m] = g ?? {}, y = { ...(this.policies[(g == null ? void 0 : g.policy) || xt] ?? this.defaultPolicy).select({
|
|
2656
|
+
sheet: this,
|
|
2657
|
+
point: p,
|
|
2658
|
+
next: y,
|
|
2659
|
+
current: g,
|
|
2660
|
+
operation: o
|
|
2661
|
+
}) }, s) {
|
|
2662
|
+
const C = this.registry.systems[m];
|
|
2663
|
+
C != null && (C.changedTime = c);
|
|
2664
|
+
}
|
|
2665
|
+
if (e) {
|
|
2666
|
+
const C = { ...g, ...y };
|
|
2667
|
+
this.registry.data[m] = C, u[m] = C;
|
|
2668
|
+
} else
|
|
2669
|
+
this.registry.data[m] = y, u[m] = y;
|
|
2670
|
+
if (p.x === 0 && p.y >= 1) {
|
|
2671
|
+
const C = (T = this.registry.data[m]) == null ? void 0 : T.height, Y = this.defaultRowHeight || J;
|
|
2672
|
+
C != null && C !== Y ? this._rowHeightOverrides.set(p.y, C) : this._rowHeightOverrides.delete(p.y);
|
|
2673
|
+
}
|
|
2674
|
+
h.push(d);
|
|
2675
|
+
}), this.lastChangedAddresses = h, {
|
|
2676
|
+
diffBefore: l,
|
|
2677
|
+
diffAfter: u,
|
|
2678
|
+
resized: f
|
|
2679
|
+
};
|
|
2680
|
+
}
|
|
2681
|
+
update({
|
|
2682
|
+
diff: t,
|
|
2683
|
+
partial: e = !0,
|
|
2684
|
+
updateChangedTime: s = !0,
|
|
2685
|
+
historicize: i = !0,
|
|
2686
|
+
operator: n = "SYSTEM",
|
|
2687
|
+
operation: o = St,
|
|
2688
|
+
ignoreFields: a,
|
|
2689
|
+
undoReflection: l,
|
|
2690
|
+
redoReflection: u
|
|
2691
|
+
}) {
|
|
2692
|
+
const { diffBefore: h, diffAfter: c, resized: f } = this._update({
|
|
2693
|
+
diff: t,
|
|
2694
|
+
partial: e,
|
|
2695
|
+
operator: n,
|
|
2696
|
+
operation: o,
|
|
2697
|
+
updateChangedTime: s,
|
|
2698
|
+
...a != null ? { ignoreFields: a } : {}
|
|
2699
|
+
});
|
|
2700
|
+
return i && this._pushHistory({
|
|
2701
|
+
applyed: !0,
|
|
2702
|
+
operation: "UPDATE",
|
|
2703
|
+
srcSheetId: this.id,
|
|
2704
|
+
dstSheetId: this.id,
|
|
2705
|
+
undoReflection: l,
|
|
2706
|
+
redoReflection: u,
|
|
2707
|
+
diffBefore: h,
|
|
2708
|
+
diffAfter: c,
|
|
2709
|
+
partial: e
|
|
2710
|
+
}), this.refresh(!1, f);
|
|
2711
|
+
}
|
|
2712
|
+
/** @internal */
|
|
2713
|
+
writeRawCellMatrix({
|
|
2714
|
+
point: t,
|
|
2715
|
+
matrix: e,
|
|
2716
|
+
updateChangedTime: s = !0,
|
|
2717
|
+
historicize: i = !0,
|
|
2718
|
+
onlyValue: n = !1,
|
|
2719
|
+
operator: o = "SYSTEM",
|
|
2720
|
+
undoReflection: a,
|
|
2721
|
+
redoReflection: l
|
|
2722
|
+
}) {
|
|
2723
|
+
const { y: u, x: h } = t, c = {};
|
|
2724
|
+
let f = 0, d = u;
|
|
2725
|
+
for (; f < e.length && !(d > this.bottom); ) {
|
|
2726
|
+
if (this.isRowFiltered(d)) {
|
|
2727
|
+
d++;
|
|
2728
|
+
continue;
|
|
2729
|
+
}
|
|
2730
|
+
e[f].forEach((m, g) => {
|
|
2731
|
+
const y = h + g;
|
|
2732
|
+
if (y > this.right)
|
|
2733
|
+
return;
|
|
2734
|
+
const R = { y: d, x: y }, A = this.parse(R, m.value ?? "");
|
|
2735
|
+
if (A.style = { ...m.style, ...A.style }, n) {
|
|
2736
|
+
const w = this.getCell(R, { resolution: "SYSTEM" });
|
|
2737
|
+
A.style = w == null ? void 0 : w.style, A.justifyContent = w == null ? void 0 : w.justifyContent, A.alignItems = w == null ? void 0 : w.alignItems;
|
|
2738
|
+
}
|
|
2739
|
+
c[D(R)] = A;
|
|
2740
|
+
}), f++, d++;
|
|
2741
|
+
}
|
|
2742
|
+
return this.update({
|
|
2743
|
+
diff: c,
|
|
2744
|
+
partial: !0,
|
|
2745
|
+
updateChangedTime: s,
|
|
2746
|
+
historicize: i,
|
|
2747
|
+
operator: o,
|
|
2748
|
+
operation: ht,
|
|
2749
|
+
undoReflection: a,
|
|
2750
|
+
redoReflection: l
|
|
2751
|
+
});
|
|
2752
|
+
}
|
|
2753
|
+
writeMatrix(t) {
|
|
2754
|
+
const e = t.matrix.map((s) => s.map((i) => ({ value: i })));
|
|
2755
|
+
return this.writeRawCellMatrix({ ...t, matrix: e });
|
|
2756
|
+
}
|
|
2757
|
+
write(t) {
|
|
2758
|
+
const { point: e, value: s } = t, i = this.parse(e, s ?? ""), n = this.getCell(e, { resolution: "RAW" });
|
|
2759
|
+
if (((n == null ? void 0 : n.value) ?? null) === i.value)
|
|
2760
|
+
return this;
|
|
2761
|
+
const o = { [D(e)]: i };
|
|
2762
|
+
return this.update({
|
|
2763
|
+
...t,
|
|
2764
|
+
diff: o,
|
|
2765
|
+
partial: !0,
|
|
2766
|
+
operation: ht
|
|
2767
|
+
});
|
|
2768
|
+
}
|
|
2769
|
+
insertRows({
|
|
2770
|
+
y: t,
|
|
2771
|
+
numRows: e,
|
|
2772
|
+
baseY: s,
|
|
2773
|
+
diff: i,
|
|
2774
|
+
partial: n,
|
|
2775
|
+
updateChangedTime: o,
|
|
2776
|
+
operator: a = "SYSTEM",
|
|
2777
|
+
undoReflection: l,
|
|
2778
|
+
redoReflection: u
|
|
2779
|
+
}) {
|
|
2780
|
+
if (this.maxNumRows !== -1 && this.numRows + e > this.maxNumRows)
|
|
2781
|
+
return console.error(`Rows are limited to ${this.maxNumRows}.`), this;
|
|
2782
|
+
const h = this.numCols, c = [], f = Date.now();
|
|
2783
|
+
for (let d = 0; d < e; d++) {
|
|
2784
|
+
const p = [];
|
|
2785
|
+
for (let m = 0; m <= h; m++) {
|
|
2786
|
+
const g = this._generateId();
|
|
2787
|
+
p.push(g);
|
|
2788
|
+
const y = this.getCell({ y: s, x: m }, { resolution: "SYSTEM" }), R = this._copyCellLayout(y);
|
|
2789
|
+
this.registry.data[g] = { ...R }, this.registry.systems[g] = { id: g, sheetId: this.id, changedTime: f };
|
|
2790
|
+
}
|
|
2791
|
+
c.push(p);
|
|
2792
|
+
}
|
|
2793
|
+
if (this.idMatrix.splice(t, 0, ...c), this.area.bottom += e, this._shiftRowMetaForInsert(t, e), this._seedRowMeta(t, e), this._pushHistory({
|
|
2794
|
+
applyed: !0,
|
|
2795
|
+
operation: "INSERT_ROWS",
|
|
2796
|
+
srcSheetId: this.id,
|
|
2797
|
+
dstSheetId: this.id,
|
|
2798
|
+
undoReflection: l,
|
|
2799
|
+
redoReflection: u,
|
|
2800
|
+
y: t,
|
|
2801
|
+
numRows: e,
|
|
2802
|
+
idMatrix: c
|
|
2803
|
+
}), i && Object.assign(this.registry.lastHistory, this._update({ diff: i, partial: n, updateChangedTime: o, operator: a }), {
|
|
2804
|
+
partial: n
|
|
2805
|
+
}), this.registry.onInsertRows) {
|
|
2806
|
+
const d = this.clone();
|
|
2807
|
+
d.area = {
|
|
2808
|
+
top: t,
|
|
2809
|
+
bottom: t + e - 1,
|
|
2810
|
+
left: this.area.left,
|
|
2811
|
+
right: this.area.right
|
|
2812
|
+
}, d.addressCaches = /* @__PURE__ */ new Map(), this.registry.onInsertRows({ sheet: d, y: t, numRows: e });
|
|
2813
|
+
}
|
|
2814
|
+
return this.refresh(!0, !0);
|
|
2815
|
+
}
|
|
2816
|
+
removeRows({
|
|
2817
|
+
y: t,
|
|
2818
|
+
numRows: e,
|
|
2819
|
+
operator: s = "SYSTEM",
|
|
2820
|
+
undoReflection: i,
|
|
2821
|
+
redoReflection: n
|
|
2822
|
+
}) {
|
|
2823
|
+
if (this.minNumRows !== -1 && this.numRows - e < this.minNumRows)
|
|
2824
|
+
return console.error(`At least ${this.minNumRows} row(s) are required.`), this;
|
|
2825
|
+
const o = new lt(this), a = [];
|
|
2826
|
+
this._materializeIdMatrix();
|
|
2827
|
+
const l = this.idMatrix.map((c) => [...c]);
|
|
2828
|
+
for (let c = t; c < t + e; c++) {
|
|
2829
|
+
const f = this.getCell({ y: c, x: 0 }, { resolution: "SYSTEM" });
|
|
2830
|
+
if (s === "USER" && O(f == null ? void 0 : f.prevention, Bt))
|
|
2831
|
+
return console.warn(`Cannot delete row ${c}.`), this;
|
|
2832
|
+
for (let d = 1; d <= this.numCols; d++) {
|
|
2833
|
+
const p = this.getId({ y: c, x: d });
|
|
2834
|
+
p != null && (o.collectDependents(p), o.map[p] = this.getId({ y: c + e, x: d }));
|
|
2835
|
+
}
|
|
2836
|
+
a.unshift(c);
|
|
2837
|
+
}
|
|
2838
|
+
const u = [];
|
|
2839
|
+
a.forEach((c) => {
|
|
2840
|
+
const f = this.idMatrix.splice(c, 1);
|
|
2841
|
+
u.unshift(f[0]);
|
|
2842
|
+
}), this.area.bottom -= a.length, this._shiftRowMetaForRemove(t, e);
|
|
2843
|
+
const h = o.resolveDependents("removeRows");
|
|
2844
|
+
if (this._pushHistory({
|
|
2845
|
+
applyed: !0,
|
|
2846
|
+
operation: "REMOVE_ROWS",
|
|
2847
|
+
srcSheetId: this.id,
|
|
2848
|
+
dstSheetId: this.id,
|
|
2849
|
+
undoReflection: i,
|
|
2850
|
+
redoReflection: n,
|
|
2851
|
+
ys: a.reverse(),
|
|
2852
|
+
diffBefore: h,
|
|
2853
|
+
deleted: u
|
|
2854
|
+
}), this.registry.onRemoveRows) {
|
|
2855
|
+
const c = this.clone();
|
|
2856
|
+
c.idMatrix = l, c.area = {
|
|
2857
|
+
top: t,
|
|
2858
|
+
bottom: t + e - 1,
|
|
2859
|
+
left: this.area.left,
|
|
2860
|
+
right: this.area.right
|
|
2861
|
+
}, c.addressCaches = /* @__PURE__ */ new Map(), this.registry.onRemoveRows({ sheet: c, ys: a.reverse() });
|
|
2862
|
+
}
|
|
2863
|
+
return this.refresh(!0, !0);
|
|
2864
|
+
}
|
|
2865
|
+
insertCols({
|
|
2866
|
+
x: t,
|
|
2867
|
+
numCols: e,
|
|
2868
|
+
baseX: s,
|
|
2869
|
+
diff: i,
|
|
2870
|
+
partial: n,
|
|
2871
|
+
updateChangedTime: o,
|
|
2872
|
+
operator: a = "SYSTEM",
|
|
2873
|
+
undoReflection: l,
|
|
2874
|
+
redoReflection: u
|
|
2875
|
+
}) {
|
|
2876
|
+
if (this.maxNumCols !== -1 && this.numCols + e > this.maxNumCols)
|
|
2877
|
+
return console.error(`Columns are limited to ${this.maxNumCols}.`), this;
|
|
2878
|
+
const h = this.numRows, c = [], f = Date.now();
|
|
2879
|
+
for (let d = 0; d <= h; d++) {
|
|
2880
|
+
const p = [];
|
|
2881
|
+
for (let m = 0; m < e; m++) {
|
|
2882
|
+
const g = this._generateId();
|
|
2883
|
+
p.push(g);
|
|
2884
|
+
const y = this.getCell({ y: d, x: s }, { resolution: "SYSTEM" }), R = this._copyCellLayout(y);
|
|
2885
|
+
this._ensureIdRow(d).splice(t, 0, g), this.registry.data[g] = { ...R }, this.registry.systems[g] = { id: g, sheetId: this.id, changedTime: f };
|
|
2886
|
+
}
|
|
2887
|
+
c.push(p);
|
|
2888
|
+
}
|
|
2889
|
+
if (this.area.right += e, this._pushHistory({
|
|
2890
|
+
applyed: !0,
|
|
2891
|
+
operation: "INSERT_COLS",
|
|
2892
|
+
srcSheetId: this.id,
|
|
2893
|
+
dstSheetId: this.id,
|
|
2894
|
+
undoReflection: l,
|
|
2895
|
+
redoReflection: u,
|
|
2896
|
+
x: t,
|
|
2897
|
+
numCols: e,
|
|
2898
|
+
idMatrix: c
|
|
2899
|
+
}), i && Object.assign(this.registry.lastHistory, this._update({ diff: i, partial: n, updateChangedTime: o, operator: a }), {
|
|
2900
|
+
partial: n
|
|
2901
|
+
}), this.registry.onInsertCols) {
|
|
2902
|
+
const d = this.clone();
|
|
2903
|
+
d.area = {
|
|
2904
|
+
top: this.area.top,
|
|
2905
|
+
bottom: this.area.bottom,
|
|
2906
|
+
left: t,
|
|
2907
|
+
right: t + e - 1
|
|
2908
|
+
}, d.addressCaches = /* @__PURE__ */ new Map(), this.registry.onInsertCols({ sheet: d, x: t, numCols: e });
|
|
2909
|
+
}
|
|
2910
|
+
return this.refresh(!0, !0);
|
|
2911
|
+
}
|
|
2912
|
+
removeCols({
|
|
2913
|
+
x: t,
|
|
2914
|
+
numCols: e,
|
|
2915
|
+
operator: s = "SYSTEM",
|
|
2916
|
+
undoReflection: i,
|
|
2917
|
+
redoReflection: n
|
|
2918
|
+
}) {
|
|
2919
|
+
if (this.minNumCols !== -1 && this.numCols - e < this.minNumCols)
|
|
2920
|
+
return console.error(`At least ${this.minNumCols} column(s) are required.`), this;
|
|
2921
|
+
const o = new lt(this), a = [];
|
|
2922
|
+
this._materializeIdMatrix();
|
|
2923
|
+
const l = this.idMatrix.map((c) => [...c]);
|
|
2924
|
+
for (let c = t; c < t + e; c++) {
|
|
2925
|
+
const f = this.getCell({ y: 0, x: c }, { resolution: "SYSTEM" });
|
|
2926
|
+
if (s === "USER" && O(f == null ? void 0 : f.prevention, Ut)) {
|
|
2927
|
+
console.warn(`Cannot delete col ${c}.`);
|
|
2928
|
+
continue;
|
|
2929
|
+
}
|
|
2930
|
+
for (let d = 1; d <= this.numRows; d++) {
|
|
2931
|
+
const p = this.getId({ y: d, x: c });
|
|
2932
|
+
p != null && (o.collectDependents(p), o.map[p] = this.getId({ y: d, x: c + e }));
|
|
2933
|
+
}
|
|
2934
|
+
a.unshift(c);
|
|
2935
|
+
}
|
|
2936
|
+
const u = [];
|
|
2937
|
+
this.idMatrix.forEach((c) => {
|
|
2938
|
+
const f = [];
|
|
2939
|
+
u.push(f), a.forEach((d) => {
|
|
2940
|
+
f.unshift(...c.splice(d, 1));
|
|
2941
|
+
});
|
|
2942
|
+
}), this.area.right -= a.length;
|
|
2943
|
+
const h = o.resolveDependents("removeCols");
|
|
2944
|
+
if (this._pushHistory({
|
|
2945
|
+
applyed: !0,
|
|
2946
|
+
operation: "REMOVE_COLS",
|
|
2947
|
+
srcSheetId: this.id,
|
|
2948
|
+
dstSheetId: this.id,
|
|
2949
|
+
undoReflection: i,
|
|
2950
|
+
redoReflection: n,
|
|
2951
|
+
xs: a.reverse(),
|
|
2952
|
+
diffBefore: h,
|
|
2953
|
+
deleted: u
|
|
2954
|
+
}), this.registry.onRemoveCols) {
|
|
2955
|
+
const c = this.clone();
|
|
2956
|
+
c.idMatrix = l, c.area = {
|
|
2957
|
+
top: this.area.top,
|
|
2958
|
+
bottom: this.area.bottom,
|
|
2959
|
+
left: t,
|
|
2960
|
+
right: t + e - 1
|
|
2961
|
+
}, c.addressCaches = /* @__PURE__ */ new Map(), this.registry.onRemoveCols({ sheet: c, xs: a.reverse() });
|
|
2962
|
+
}
|
|
2963
|
+
return this.refresh(!0, !0);
|
|
2964
|
+
}
|
|
2965
|
+
/** @internal */
|
|
2966
|
+
histories() {
|
|
2967
|
+
return [...this.registry.histories];
|
|
2968
|
+
}
|
|
2969
|
+
/** @internal */
|
|
2970
|
+
historyIndex() {
|
|
2971
|
+
return this.registry.historyIndex;
|
|
2972
|
+
}
|
|
2973
|
+
/** @internal */
|
|
2974
|
+
historySize() {
|
|
2975
|
+
return this.registry.histories.length;
|
|
2976
|
+
}
|
|
2977
|
+
/** @internal */
|
|
2978
|
+
getHistoryLimit() {
|
|
2979
|
+
return this.registry.historyLimit;
|
|
2980
|
+
}
|
|
2981
|
+
/** @internal */
|
|
2982
|
+
parse(t, e) {
|
|
2983
|
+
const s = this.getCell(t, { resolution: "SYSTEM" }) ?? {};
|
|
2984
|
+
return this.getPolicy(t).deserializeValue(e, s);
|
|
2985
|
+
}
|
|
2986
|
+
/** @internal */
|
|
2987
|
+
render(t) {
|
|
2988
|
+
const { point: e, apply: s } = t;
|
|
2989
|
+
return this.getId(e), this.getPolicy(e).render({ sheet: this, point: e, apply: s, value: void 0 });
|
|
2990
|
+
}
|
|
2991
|
+
getSerializedValue({
|
|
2992
|
+
point: t,
|
|
2993
|
+
cell: e,
|
|
2994
|
+
resolution: s = "RESOLVED"
|
|
2995
|
+
}) {
|
|
2996
|
+
if (e == null) {
|
|
2997
|
+
const o = this.getId(t);
|
|
2998
|
+
e = o != null ? this.registry.data[o] : void 0;
|
|
2999
|
+
}
|
|
3000
|
+
if (e == null)
|
|
3001
|
+
return "";
|
|
3002
|
+
const i = this.getPolicy(t), n = e.value;
|
|
3003
|
+
if (typeof n == "string" && n[0] === "=") {
|
|
3004
|
+
if (s === "SYSTEM")
|
|
3005
|
+
return n;
|
|
3006
|
+
if (s === "RAW" || (e == null ? void 0 : e.formulaEnabled) === !1) {
|
|
3007
|
+
const o = new $t(n.substring(1));
|
|
3008
|
+
return o.tokenize(), "=" + o.display({ sheet: this });
|
|
3009
|
+
}
|
|
3010
|
+
try {
|
|
3011
|
+
const o = this.getId(t), a = te({ value: n, sheet: this, point: t, raise: !0, resolution: s, at: o }), l = nt({ value: a, raise: !1 });
|
|
3012
|
+
return i.serialize({ value: l, cell: e, sheet: this, point: t });
|
|
3013
|
+
} catch (o) {
|
|
3014
|
+
return i.serialize({ value: o, cell: e, sheet: this, point: t });
|
|
3015
|
+
}
|
|
3016
|
+
}
|
|
3017
|
+
return i.serialize({ value: n, cell: e, sheet: this, point: t });
|
|
3018
|
+
}
|
|
3019
|
+
/** @internal */
|
|
3020
|
+
trim(t) {
|
|
3021
|
+
const e = Object.assign(Object.create(Object.getPrototypeOf(this)), this);
|
|
3022
|
+
return e.area = t, e._stripped = wt, e;
|
|
3023
|
+
}
|
|
3024
|
+
/**
|
|
3025
|
+
* Solve all formulas in this sheet and return a 2D matrix of resolved values.
|
|
3026
|
+
* @internal
|
|
3027
|
+
*/
|
|
3028
|
+
solve({ raise: t = !1, at: e }) {
|
|
3029
|
+
return Oe({ sheet: this, raise: t, at: e });
|
|
3030
|
+
}
|
|
3031
|
+
/**
|
|
3032
|
+
* Collapse this sheet to a scalar (top-left cell value).
|
|
3033
|
+
* @internal
|
|
3034
|
+
*/
|
|
3035
|
+
strip({ raise: t = !1, at: e }) {
|
|
3036
|
+
var i;
|
|
3037
|
+
if (!wt.is(this._stripped))
|
|
3038
|
+
return this._stripped;
|
|
3039
|
+
let s = this;
|
|
3040
|
+
for (; s instanceof $; )
|
|
3041
|
+
s = (i = Oe({ sheet: s, raise: t, at: e })[0]) == null ? void 0 : i[0];
|
|
3042
|
+
return this._stripped = s, this._stripped;
|
|
3043
|
+
}
|
|
3044
|
+
/** @internal */
|
|
3045
|
+
_applyDiff(t = {}, e = !0) {
|
|
3046
|
+
const s = Object.keys(t);
|
|
3047
|
+
s.forEach((n) => {
|
|
3048
|
+
const o = t[n] ?? {};
|
|
3049
|
+
let a;
|
|
3050
|
+
e ? (a = { ...this.registry.data[n] }, Object.keys(o).forEach((h) => {
|
|
3051
|
+
o[h] === void 0 ? delete a[h] : a[h] = o[h];
|
|
3052
|
+
})) : a = { ...o };
|
|
3053
|
+
const l = this.registry.systems[n];
|
|
3054
|
+
l != null && (l.changedTime = Date.now()), this.registry.data[n] = a, this.clearDependencies(n), this.processFormula(a.value, { dependency: n });
|
|
3055
|
+
const u = this.addressCaches.get(n);
|
|
3056
|
+
if (u) {
|
|
3057
|
+
const h = N(u);
|
|
3058
|
+
if (h.x === 0 && h.y > 0) {
|
|
3059
|
+
const c = this.defaultRowHeight || J, f = a.height ?? c;
|
|
3060
|
+
f !== c ? this._rowHeightOverrides.set(h.y, f) : this._rowHeightOverrides.delete(h.y), a.filtered ? this._filteredRows.add(h.y) : this._filteredRows.delete(h.y);
|
|
3061
|
+
}
|
|
3062
|
+
}
|
|
3063
|
+
}), this._warmAddressCaches();
|
|
3064
|
+
const i = [];
|
|
3065
|
+
for (const n of s) {
|
|
3066
|
+
const o = this.getAddressById(n);
|
|
3067
|
+
o && i.push(o);
|
|
3068
|
+
}
|
|
3069
|
+
this.lastChangedAddresses = i;
|
|
3070
|
+
}
|
|
3071
|
+
undo() {
|
|
3072
|
+
if (this.registry.historyIndex < 0)
|
|
3073
|
+
return { history: null, newSheet: this.__raw__ };
|
|
3074
|
+
const t = this.registry.histories[this.registry.historyIndex--];
|
|
3075
|
+
t.applyed = !1, this.registry.currentHistory = this.registry.histories[this.registry.historyIndex];
|
|
3076
|
+
const e = this.getSheetBySheetId(t.srcSheetId), s = this.getSheetBySheetId(t.dstSheetId);
|
|
3077
|
+
if (!s)
|
|
3078
|
+
return { history: null, newSheet: this.__raw__ };
|
|
3079
|
+
switch (t.operation) {
|
|
3080
|
+
case "UPDATE":
|
|
3081
|
+
s._applyDiff(t.diffBefore, t.partial ?? !1);
|
|
3082
|
+
break;
|
|
3083
|
+
case "INSERT_ROWS": {
|
|
3084
|
+
t.diffBefore && s._applyDiff(t.diffBefore, !1);
|
|
3085
|
+
const { rows: i } = Nt({ matrix: t.idMatrix });
|
|
3086
|
+
s._materializeIdMatrix(), s.idMatrix.splice(t.y, i), s.area.bottom -= i, s._shiftRowMetaForRemove(t.y, i);
|
|
3087
|
+
break;
|
|
3088
|
+
}
|
|
3089
|
+
case "INSERT_COLS": {
|
|
3090
|
+
t.diffBefore && s._applyDiff(t.diffBefore, !1);
|
|
3091
|
+
const { cols: i } = Nt({ matrix: t.idMatrix });
|
|
3092
|
+
s._materializeIdMatrix(), s.idMatrix.forEach((n) => {
|
|
3093
|
+
n.splice(t.x, i);
|
|
3094
|
+
}), s.area.right -= i;
|
|
3095
|
+
break;
|
|
3096
|
+
}
|
|
3097
|
+
case "REMOVE_ROWS": {
|
|
3098
|
+
const { ys: i, deleted: n } = t;
|
|
3099
|
+
s._materializeIdMatrix(), i.forEach((a, l) => {
|
|
3100
|
+
s.idMatrix.splice(a, 0, n[l]);
|
|
3101
|
+
}), s.area.bottom += i.length;
|
|
3102
|
+
const o = Math.min(...i);
|
|
3103
|
+
s._shiftRowMetaForInsert(o, i.length), s._seedRowMeta(o, i.length), this._applyDiff(t.diffBefore, !1);
|
|
3104
|
+
break;
|
|
3105
|
+
}
|
|
3106
|
+
case "REMOVE_COLS": {
|
|
3107
|
+
const { xs: i, deleted: n } = t;
|
|
3108
|
+
s._materializeIdMatrix(), s.idMatrix.forEach((o, a) => {
|
|
3109
|
+
for (let l = 0; l < i.length; l++)
|
|
3110
|
+
o.splice(i[l], 0, n[a][l]);
|
|
3111
|
+
}), s.area.right += i.length, this._applyDiff(t.diffBefore, !1);
|
|
3112
|
+
break;
|
|
3113
|
+
}
|
|
3114
|
+
case "MOVE": {
|
|
3115
|
+
e && this._moveCells(e, s, t.moveRelations, !0);
|
|
3116
|
+
const i = s.lastChangedAddresses;
|
|
3117
|
+
s._applyDiff(t.diffBefore, !1), s.lastChangedAddresses = [.../* @__PURE__ */ new Set([...i, ...s.lastChangedAddresses])];
|
|
3118
|
+
break;
|
|
3119
|
+
}
|
|
3120
|
+
case "SORT_ROWS": {
|
|
3121
|
+
s._materializeIdMatrix();
|
|
3122
|
+
const i = s.idMatrix.flat();
|
|
3123
|
+
s._sortRowMapping(t.sortedRowMapping, !0);
|
|
3124
|
+
const n = new lt(s);
|
|
3125
|
+
n.buildMap(i, s.idMatrix.flat()), n.resolveDependents(), s._reapplyFilters();
|
|
3126
|
+
break;
|
|
3127
|
+
}
|
|
3128
|
+
}
|
|
3129
|
+
return this.refresh(Me(t.operation), !0), s !== this && (s.addressCaches.clear(), s.setTotalSize()), t.operation === "MOVE" && e && e !== s && this._xsheetDispatch(e), {
|
|
3130
|
+
history: t,
|
|
3131
|
+
callback: ({ sheetReactive: i }) => {
|
|
3132
|
+
var n, o;
|
|
3133
|
+
(o = i.current) == null || o.registry.transmit((n = t.undoReflection) == null ? void 0 : n.transmit);
|
|
3134
|
+
}
|
|
3135
|
+
};
|
|
3136
|
+
}
|
|
3137
|
+
redo() {
|
|
3138
|
+
if (this.registry.historyIndex + 1 >= this.registry.histories.length)
|
|
3139
|
+
return { history: null, newSheet: this.__raw__ };
|
|
3140
|
+
const t = this.registry.histories[++this.registry.historyIndex];
|
|
3141
|
+
t.applyed = !0, this.registry.currentHistory = t;
|
|
3142
|
+
const e = this.getSheetBySheetId(t.srcSheetId), s = this.getSheetBySheetId(t.dstSheetId);
|
|
3143
|
+
if (!s)
|
|
3144
|
+
return { history: null, newSheet: this.__raw__ };
|
|
3145
|
+
switch (t.operation) {
|
|
3146
|
+
case "UPDATE":
|
|
3147
|
+
s._applyDiff(t.diffAfter, t.partial ?? !1);
|
|
3148
|
+
break;
|
|
3149
|
+
case "INSERT_ROWS": {
|
|
3150
|
+
t.diffAfter && s._applyDiff(t.diffAfter, !1);
|
|
3151
|
+
const { rows: i } = Nt({ matrix: t.idMatrix });
|
|
3152
|
+
s._materializeIdMatrix(), s.idMatrix.splice(t.y, 0, ...t.idMatrix), s.area.bottom += i, s._shiftRowMetaForInsert(t.y, i), s._seedRowMeta(t.y, i);
|
|
3153
|
+
break;
|
|
3154
|
+
}
|
|
3155
|
+
case "INSERT_COLS": {
|
|
3156
|
+
t.diffAfter && s._applyDiff(t.diffAfter, !1);
|
|
3157
|
+
const { cols: i } = Nt({ matrix: t.idMatrix });
|
|
3158
|
+
s._materializeIdMatrix(), s.idMatrix.map((n, o) => {
|
|
3159
|
+
n.splice(t.x, 0, ...t.idMatrix[o]);
|
|
3160
|
+
}), s.area.right += i;
|
|
3161
|
+
break;
|
|
3162
|
+
}
|
|
3163
|
+
case "REMOVE_ROWS": {
|
|
3164
|
+
s.removeRows({
|
|
3165
|
+
y: t.ys[0],
|
|
3166
|
+
numRows: t.ys.length,
|
|
3167
|
+
operator: "SYSTEM",
|
|
3168
|
+
undoReflection: t.undoReflection,
|
|
3169
|
+
redoReflection: t.redoReflection
|
|
3170
|
+
});
|
|
3171
|
+
break;
|
|
3172
|
+
}
|
|
3173
|
+
case "REMOVE_COLS": {
|
|
3174
|
+
s.removeCols({
|
|
3175
|
+
x: t.xs[0],
|
|
3176
|
+
numCols: t.xs.length,
|
|
3177
|
+
operator: "SYSTEM",
|
|
3178
|
+
undoReflection: t.undoReflection,
|
|
3179
|
+
redoReflection: t.redoReflection
|
|
3180
|
+
});
|
|
3181
|
+
break;
|
|
3182
|
+
}
|
|
3183
|
+
case "MOVE": {
|
|
3184
|
+
e && this._moveCells(e, s, t.moveRelations, !1);
|
|
3185
|
+
break;
|
|
3186
|
+
}
|
|
3187
|
+
case "SORT_ROWS": {
|
|
3188
|
+
s._materializeIdMatrix();
|
|
3189
|
+
const i = s.idMatrix.flat();
|
|
3190
|
+
s._sortRowMapping(t.sortedRowMapping, !1);
|
|
3191
|
+
const n = new lt(s);
|
|
3192
|
+
n.buildMap(i, s.idMatrix.flat()), n.resolveDependents(), s._reapplyFilters();
|
|
3193
|
+
break;
|
|
3194
|
+
}
|
|
3195
|
+
}
|
|
3196
|
+
return this.refresh(Me(t.operation), !0), s !== this && (s.addressCaches.clear(), s.setTotalSize()), t.operation === "MOVE" && e && e !== s && this._xsheetDispatch(e), {
|
|
3197
|
+
history: t,
|
|
3198
|
+
callback: ({ sheetReactive: i }) => {
|
|
3199
|
+
var n, o;
|
|
3200
|
+
(o = i.current) == null || o.registry.transmit((n = t.redoReflection) == null ? void 0 : n.transmit);
|
|
3201
|
+
}
|
|
3202
|
+
};
|
|
3203
|
+
}
|
|
3204
|
+
/** @internal */
|
|
3205
|
+
getFunctionByName(t) {
|
|
3206
|
+
return this.registry.functions[t];
|
|
3207
|
+
}
|
|
3208
|
+
/** @internal */
|
|
3209
|
+
clearDependencies(t) {
|
|
3210
|
+
var s;
|
|
3211
|
+
const e = this.registry.systems[t];
|
|
3212
|
+
(s = e == null ? void 0 : e.dependencies) == null || s.forEach((i) => {
|
|
3213
|
+
var n, o;
|
|
3214
|
+
(o = (n = this.registry.systems[i]) == null ? void 0 : n.dependents) == null || o.delete(t);
|
|
3215
|
+
}), e != null && (e.dependencies = /* @__PURE__ */ new Set());
|
|
3216
|
+
}
|
|
3217
|
+
/** @internal */
|
|
3218
|
+
addDependency(t, e) {
|
|
3219
|
+
const s = bt(this.registry, t);
|
|
3220
|
+
s.dependents == null && (s.dependents = /* @__PURE__ */ new Set()), s.dependents.add(e);
|
|
3221
|
+
const i = bt(this.registry, e);
|
|
3222
|
+
i.dependencies == null && (i.dependencies = /* @__PURE__ */ new Set()), i.dependencies.add(t);
|
|
3223
|
+
}
|
|
3224
|
+
/** @internal */
|
|
3225
|
+
getSolvedCache(t) {
|
|
3226
|
+
const e = this.getId(t);
|
|
3227
|
+
return [this.registry.solvedCaches.has(e), this.registry.solvedCaches.get(e)];
|
|
3228
|
+
}
|
|
3229
|
+
/** @internal */
|
|
3230
|
+
setSolvingCache(t) {
|
|
3231
|
+
const e = this.getId(t);
|
|
3232
|
+
this.registry.solvedCaches.set(e, At), bt(this.registry, e, { tmpAsyncCaches: {} });
|
|
3233
|
+
}
|
|
3234
|
+
/** @internal */
|
|
3235
|
+
finishSolvedCache(t, e) {
|
|
3236
|
+
if (At.is(e))
|
|
3237
|
+
return;
|
|
3238
|
+
const s = this.getId(t);
|
|
3239
|
+
this.registry.solvedCaches.set(s, e);
|
|
3240
|
+
const i = this.registry.data[s];
|
|
3241
|
+
if (i == null)
|
|
3242
|
+
return;
|
|
3243
|
+
const n = this.registry.systems[s], o = n == null ? void 0 : n.tmpAsyncCaches;
|
|
3244
|
+
o != null && (Object.keys(o).length > 0 ? i.asyncCaches = o : delete i.asyncCaches, delete n.tmpAsyncCaches);
|
|
3245
|
+
}
|
|
3246
|
+
/** @internal */
|
|
3247
|
+
clearSolvedCaches() {
|
|
3248
|
+
this.registry.solvedCaches.clear();
|
|
3249
|
+
for (const t of this.registry.lastSpilledTargetIds) {
|
|
3250
|
+
const e = this.registry.systems[t];
|
|
3251
|
+
(e == null ? void 0 : e.spilledFrom) != null && delete e.spilledFrom;
|
|
3252
|
+
}
|
|
3253
|
+
this.registry.lastSpilledTargetIds.clear();
|
|
3254
|
+
}
|
|
3255
|
+
/**
|
|
3256
|
+
* Spill a 2D matrix of values starting from the origin cell.
|
|
3257
|
+
* The origin cell receives matrix[0][0] and adjacent cells receive spill values in solvedCaches.
|
|
3258
|
+
* For a 1×1 matrix, no spill occurs — the single value is cached directly.
|
|
3259
|
+
* Throws FormulaError('#REF!') if the spill range is obstructed.
|
|
3260
|
+
*
|
|
3261
|
+
* @param origin The anchor cell that produced the spill.
|
|
3262
|
+
* @param matrix The 2D array of resolved scalar values.
|
|
3263
|
+
* @returns The top-left value (matrix[0][0]).
|
|
3264
|
+
* @internal
|
|
3265
|
+
*/
|
|
3266
|
+
spill(t, e) {
|
|
3267
|
+
var a;
|
|
3268
|
+
const s = e.length, i = s > 0 ? e[0].length : 0;
|
|
3269
|
+
if (s <= 1 && i <= 1)
|
|
3270
|
+
return (a = e[0]) == null ? void 0 : a[0];
|
|
3271
|
+
for (let l = 0; l < s; l++)
|
|
3272
|
+
for (let u = 0; u < i; u++) {
|
|
3273
|
+
if (l === 0 && u === 0)
|
|
3274
|
+
continue;
|
|
3275
|
+
const h = { y: t.y + l, x: t.x + u }, c = this.getId(h), f = D(h);
|
|
3276
|
+
if (c == null) {
|
|
3277
|
+
console.warn(`Spill target ${f} is out of bounds.`);
|
|
3278
|
+
continue;
|
|
3279
|
+
}
|
|
3280
|
+
const d = this.registry.data[c];
|
|
3281
|
+
if ((d == null ? void 0 : d.value) != null && d.value !== "")
|
|
3282
|
+
throw new x(
|
|
3283
|
+
"#REF!",
|
|
3284
|
+
`Array result was not expanded because it would overwrite data in ${f}.`
|
|
3285
|
+
);
|
|
3286
|
+
if (this.registry.solvedCaches.has(c))
|
|
3287
|
+
throw new x(
|
|
3288
|
+
"#REF!",
|
|
3289
|
+
`Array result was not expanded because ${f} is already occupied by another formula.`
|
|
3290
|
+
);
|
|
3291
|
+
}
|
|
3292
|
+
const n = this.getId(t), o = [];
|
|
3293
|
+
for (let l = 0; l < s; l++)
|
|
3294
|
+
for (let u = 0; u < i; u++) {
|
|
3295
|
+
const h = { y: t.y + l, x: t.x + u }, c = this.getId(h);
|
|
3296
|
+
if (c != null && (this.finishSolvedCache(h, e[l][u]), (l !== 0 || u !== 0) && (o.push(D(h)), n != null))) {
|
|
3297
|
+
const f = bt(this.registry, c, {});
|
|
3298
|
+
f.spilledFrom = D(t), this.registry.lastSpilledTargetIds.add(c);
|
|
3299
|
+
}
|
|
3300
|
+
}
|
|
3301
|
+
return e[0][0];
|
|
3302
|
+
}
|
|
3303
|
+
/** @internal */
|
|
3304
|
+
sheetPrefix(t = !1) {
|
|
3305
|
+
return t ? "" : Ws(this.name);
|
|
3306
|
+
}
|
|
3307
|
+
/** @internal */
|
|
3308
|
+
rangeToArea(t) {
|
|
3309
|
+
const e = t.split(":");
|
|
3310
|
+
let [s, i] = e;
|
|
3311
|
+
s.match(/[a-zA-Z]$/) && (s += "1"), s.match(/^[1-9]/) && (s = `A${s}`), i != null && i.match(/[a-zA-Z]$/) && (i += this.bottom), i != null && i.match(/^[1-9]/) && (i = `${W(this.right)}${i}`);
|
|
3312
|
+
const { y: n, x: o } = N(s), { y: a, x: l } = N(i || s);
|
|
3313
|
+
return {
|
|
3314
|
+
top: Math.abs(n),
|
|
3315
|
+
left: Math.abs(o),
|
|
3316
|
+
bottom: Math.abs(a),
|
|
3317
|
+
right: Math.abs(l)
|
|
3318
|
+
};
|
|
3319
|
+
}
|
|
3320
|
+
get __raw__() {
|
|
3321
|
+
return this;
|
|
3322
|
+
}
|
|
3323
|
+
get shape() {
|
|
3324
|
+
return Kt(this.area);
|
|
3325
|
+
}
|
|
3326
|
+
get hasSingleCell() {
|
|
3327
|
+
const t = this.shape;
|
|
3328
|
+
return t.rows === 1 && t.cols === 1;
|
|
3329
|
+
}
|
|
3330
|
+
get currentVersion() {
|
|
3331
|
+
return this.version;
|
|
3332
|
+
}
|
|
3333
|
+
}
|
|
3334
|
+
const te = ({ value: r, sheet: t, point: e, raise: s = !0, resolution: i = "RESOLVED", at: n }) => {
|
|
3335
|
+
var u;
|
|
3336
|
+
const [o, a] = t.getSolvedCache(e);
|
|
3337
|
+
if (o && r == null && !At.is(a))
|
|
3338
|
+
return a;
|
|
3339
|
+
if (typeof r != "string" || i === "SYSTEM")
|
|
3340
|
+
return r;
|
|
3341
|
+
if (r.charAt(0) === "'")
|
|
3342
|
+
return i === "RAW" ? r : r.substring(1);
|
|
3343
|
+
if (r.charAt(0) !== "=")
|
|
3344
|
+
return r;
|
|
3345
|
+
if (i === "RAW") {
|
|
3346
|
+
const h = new $t(r.substring(1), { at: n });
|
|
3347
|
+
return h.tokenize(), "=" + h.display({ sheet: t });
|
|
3348
|
+
}
|
|
3349
|
+
let l = r;
|
|
3350
|
+
if (o && !At.is(a))
|
|
3351
|
+
l = a;
|
|
3352
|
+
else
|
|
3353
|
+
try {
|
|
3354
|
+
const h = new $t(r.substring(1), { at: n });
|
|
3355
|
+
h.tokenize();
|
|
3356
|
+
const f = new ze(h.tokens).build();
|
|
3357
|
+
l = (u = f == null ? void 0 : f.evaluate) == null ? void 0 : u.call(f, { sheet: t });
|
|
3358
|
+
} catch (h) {
|
|
3359
|
+
if (s)
|
|
3360
|
+
throw t.finishSolvedCache(e, h), h;
|
|
3361
|
+
return h;
|
|
3362
|
+
}
|
|
3363
|
+
return B.is(l) ? l = t.spill(e, l.matrix) : t.finishSolvedCache(e, l), i === "RESOLVED" && l instanceof $ && (l = nt({ value: l, raise: s, at: n })), k.is(l) && t.finishSolvedCache(e, l), l;
|
|
3364
|
+
}, Oe = ({ sheet: r, raise: t = !0, at: e }) => {
|
|
3365
|
+
const s = r.area;
|
|
3366
|
+
return r._toValueMatrix({ area: s, at: e, resolution: "SYSTEM" }).map((n, o) => {
|
|
3367
|
+
const a = s.top + o;
|
|
3368
|
+
return n.map((l, u) => {
|
|
3369
|
+
const h = s.left + u, c = { y: a, x: h }, [f, d] = r.getSolvedCache(c);
|
|
3370
|
+
try {
|
|
3371
|
+
if (At.is(d))
|
|
3372
|
+
throw new x("#REF!", "References are circulating.", new Error(l));
|
|
3373
|
+
if (k.is(d))
|
|
3374
|
+
return d;
|
|
3375
|
+
if (x.is(d))
|
|
3376
|
+
throw d;
|
|
3377
|
+
if (d != null)
|
|
3378
|
+
return d;
|
|
3379
|
+
r.setSolvingCache(c);
|
|
3380
|
+
const p = te({ value: l, sheet: r, point: c, raise: t, at: e, resolution: "RESOLVED" });
|
|
3381
|
+
return r.finishSolvedCache(c, p), p;
|
|
3382
|
+
} catch (p) {
|
|
3383
|
+
if (r.finishSolvedCache(c, p), t)
|
|
3384
|
+
throw p;
|
|
3385
|
+
return p;
|
|
3386
|
+
}
|
|
3387
|
+
});
|
|
3388
|
+
});
|
|
3389
|
+
}, nt = ({ value: r, at: t, raise: e = !0 }) => r instanceof $ ? r.strip({ raise: e, at: t }) : r, ee = new ut("asyncCacheMiss"), mi = (r) => r.some((t) => k.is(t)), es = (r) => (r == null ? void 0 : r.__gsType) === "Sheet", Rt = (r, t) => {
|
|
3390
|
+
for (const e of r)
|
|
3391
|
+
if (k.is(e) || Array.isArray(e) && Rt(e, t) || B.is(e) && Rt(e.matrix, t) || es(e) && Rt(e._toValueMatrix({ at: t }), t))
|
|
3392
|
+
return !0;
|
|
3393
|
+
return !1;
|
|
3394
|
+
}, gi = (r, t = 0) => {
|
|
3395
|
+
let e = 3735928559 ^ t, s = 1103547991 ^ t;
|
|
3396
|
+
for (let i = 0; i < r.length; i++) {
|
|
3397
|
+
const n = r.charCodeAt(i);
|
|
3398
|
+
e = Math.imul(e ^ n, 2654435761), s = Math.imul(s ^ n, 1597334677);
|
|
3399
|
+
}
|
|
3400
|
+
return e = Math.imul(e ^ e >>> 16, 2246822507), e ^= Math.imul(s ^ s >>> 13, 3266489909), s = Math.imul(s ^ s >>> 16, 2246822507), s ^= Math.imul(e ^ e >>> 13, 3266489909), 4294967296 * (2097151 & s) + (e >>> 0);
|
|
3401
|
+
}, yi = (r, t, e = 1) => {
|
|
3402
|
+
const s = JSON.stringify(t, (n, o) => es(o) ? Vs(o) : k.is(o) ? null : o), i = Array.from({ length: e }, (n, o) => gi(s, o).toString(36));
|
|
3403
|
+
return `${r}:${s.length}:${i.join("-")}`;
|
|
3404
|
+
}, wi = (r, t, e, s = !1) => {
|
|
3405
|
+
var l;
|
|
3406
|
+
const i = r.registry, n = i.data[t];
|
|
3407
|
+
if (n == null)
|
|
3408
|
+
return ee;
|
|
3409
|
+
const o = bt(i, t, { tmpAsyncCaches: {} });
|
|
3410
|
+
if (n.asyncCaches != null) {
|
|
3411
|
+
const u = n.asyncCaches[e];
|
|
3412
|
+
if (u != null && (u.expireTime == null || Date.now() < u.expireTime))
|
|
3413
|
+
return o.tmpAsyncCaches[e] = u, u.value;
|
|
3414
|
+
}
|
|
3415
|
+
const a = `${t}:${e}`;
|
|
3416
|
+
if (i.asyncPending.has(a))
|
|
3417
|
+
return i.asyncPending.get(a);
|
|
3418
|
+
if (s && ((l = i.asyncInflight) != null && l.has(e))) {
|
|
3419
|
+
const u = i.asyncInflight.get(e);
|
|
3420
|
+
return i.asyncPending.set(a, u.pending), u.pending.promise.then((h) => {
|
|
3421
|
+
const c = i.data[t];
|
|
3422
|
+
c != null && Lt(c, e, { value: h, expireTime: u.expireTime });
|
|
3423
|
+
}).catch((h) => {
|
|
3424
|
+
x.is(h) || (h = new x("#ASYNC!", (h == null ? void 0 : h.message) ?? String(h), h instanceof Error ? h : void 0));
|
|
3425
|
+
const c = i.data[t];
|
|
3426
|
+
c != null && Lt(c, e, { value: h, expireTime: u.expireTime });
|
|
3427
|
+
}).finally(() => {
|
|
3428
|
+
i.asyncPending.delete(a);
|
|
3429
|
+
}), u.pending;
|
|
3430
|
+
}
|
|
3431
|
+
return ee;
|
|
3432
|
+
}, xi = (r, t, e, s, i, n = !1) => {
|
|
3433
|
+
const o = t.registry, a = i != null ? Date.now() + i : void 0, l = `${e}:${s}`, u = new k(r);
|
|
3434
|
+
return o.asyncPending.set(l, u), n && (o.asyncInflight || (o.asyncInflight = /* @__PURE__ */ new Map()), o.asyncInflight.set(s, { pending: u, expireTime: a })), r.then((h) => {
|
|
3435
|
+
const c = o.data[e];
|
|
3436
|
+
c != null && Lt(c, s, { value: h, expireTime: a });
|
|
3437
|
+
}).catch((h) => {
|
|
3438
|
+
x.is(h) || (h = new x("#ASYNC!", (h == null ? void 0 : h.message) ?? String(h), h instanceof Error ? h : void 0));
|
|
3439
|
+
const c = o.data[e];
|
|
3440
|
+
c != null && Lt(c, s, { value: h, expireTime: a });
|
|
3441
|
+
}).finally(() => {
|
|
3442
|
+
o.asyncPending.delete(l), n && o.asyncInflight && o.asyncInflight.delete(s), o.solvedCaches.clear(), o.transmit();
|
|
3443
|
+
}), u;
|
|
3444
|
+
}, Gt = () => new k(Promise.resolve()), fe = (r, t) => {
|
|
3445
|
+
if (typeof r == "string" || typeof t == "string")
|
|
3446
|
+
return X(r) > X(t);
|
|
3447
|
+
try {
|
|
3448
|
+
return F(r) > F(t);
|
|
3449
|
+
} catch {
|
|
3450
|
+
return !1;
|
|
3451
|
+
}
|
|
3452
|
+
}, pe = (r, t) => {
|
|
3453
|
+
if (typeof r == "string" || typeof t == "string")
|
|
3454
|
+
return X(r) >= X(t);
|
|
3455
|
+
try {
|
|
3456
|
+
return F(r) >= F(t);
|
|
3457
|
+
} catch {
|
|
3458
|
+
return !1;
|
|
3459
|
+
}
|
|
3460
|
+
}, ss = (r, t) => !pe(r, t), is = (r, t) => !fe(r, t), me = (r, t) => X(r).toLowerCase() === X(t).toLowerCase(), bi = (r, t) => !me(r, t), ge = (r) => typeof r != "string" || !r.endsWith("%") ? !1 : !isNaN(parseFloat(r.slice(0, -1))), Mt = (r) => typeof r == "number" || ge(r) ? !0 : typeof r == "string" ? !isNaN(parseFloat(r)) && isFinite(Number(r)) : !1, F = (r, t) => {
|
|
3461
|
+
const { alternative: e, ignore: s } = t || {};
|
|
3462
|
+
if (k.is(r))
|
|
3463
|
+
return r;
|
|
3464
|
+
if (typeof r > "u" && typeof e < "u")
|
|
3465
|
+
return e;
|
|
3466
|
+
if (!r)
|
|
3467
|
+
return 0;
|
|
3468
|
+
if (r instanceof $) {
|
|
3469
|
+
const n = nt({ value: r });
|
|
3470
|
+
return F(n, { alternative: e });
|
|
3471
|
+
}
|
|
3472
|
+
if (r instanceof Date)
|
|
3473
|
+
return r.getTime();
|
|
3474
|
+
if (b.is(r))
|
|
3475
|
+
return r.days;
|
|
3476
|
+
if (ge(r))
|
|
3477
|
+
return parseFloat(r.slice(0, -1)) / 100;
|
|
3478
|
+
const i = parseFloat(r);
|
|
3479
|
+
if (isNaN(i)) {
|
|
3480
|
+
if (s)
|
|
3481
|
+
return e ?? 0;
|
|
3482
|
+
throw new x("#VALUE!", `${r} cannot be converted to a number`);
|
|
3483
|
+
}
|
|
3484
|
+
return i;
|
|
3485
|
+
}, X = (r) => {
|
|
3486
|
+
if (k.is(r))
|
|
3487
|
+
return r;
|
|
3488
|
+
if (r === 0)
|
|
3489
|
+
return "0";
|
|
3490
|
+
if (!r)
|
|
3491
|
+
return "";
|
|
3492
|
+
if (r instanceof $) {
|
|
3493
|
+
const t = nt({ value: r });
|
|
3494
|
+
return X(t);
|
|
3495
|
+
}
|
|
3496
|
+
switch (r.constructor.name) {
|
|
3497
|
+
case "Date":
|
|
3498
|
+
return H(r).format(ms);
|
|
3499
|
+
default:
|
|
3500
|
+
return String(r);
|
|
3501
|
+
}
|
|
3502
|
+
}, Ot = (r, t) => {
|
|
3503
|
+
const { alternative: e, ignore: s } = t ?? {};
|
|
3504
|
+
if (k.is(r))
|
|
3505
|
+
return r;
|
|
3506
|
+
if (typeof r > "u" && typeof e < "u")
|
|
3507
|
+
return e;
|
|
3508
|
+
if (r === null)
|
|
3509
|
+
return !1;
|
|
3510
|
+
if (r instanceof $) {
|
|
3511
|
+
const i = nt({ value: r });
|
|
3512
|
+
return Ot(i, t);
|
|
3513
|
+
}
|
|
3514
|
+
if (typeof r == "string" || r instanceof String) {
|
|
3515
|
+
const i = { true: !0, false: !1 }[r.toLowerCase()];
|
|
3516
|
+
if (i == null) {
|
|
3517
|
+
if (s)
|
|
3518
|
+
return !1;
|
|
3519
|
+
throw new x("#VALUE!", `text '${r}' cannot be converted to a boolean`);
|
|
3520
|
+
}
|
|
3521
|
+
return i;
|
|
3522
|
+
}
|
|
3523
|
+
return !!r;
|
|
3524
|
+
};
|
|
3525
|
+
function Si(r) {
|
|
3526
|
+
if (k.is(r) || r instanceof Date)
|
|
3527
|
+
return r;
|
|
3528
|
+
if (r instanceof $) {
|
|
3529
|
+
const t = nt({ value: r });
|
|
3530
|
+
return Si(t);
|
|
3531
|
+
}
|
|
3532
|
+
if (typeof r == "number")
|
|
3533
|
+
return new Date(r);
|
|
3534
|
+
if (typeof r == "string") {
|
|
3535
|
+
const t = new Date(r);
|
|
3536
|
+
if (!isNaN(t.getTime()))
|
|
3537
|
+
return t;
|
|
3538
|
+
}
|
|
3539
|
+
throw new x("#VALUE!", `${r} cannot be converted to a date`);
|
|
3540
|
+
}
|
|
3541
|
+
const Ri = /^(<=|>=|<>|>|<|=)?(.*)$/, _i = (r, t) => {
|
|
3542
|
+
const e = t.match(Ri), [, s = "", i = ""] = e || [];
|
|
3543
|
+
let n = i;
|
|
3544
|
+
if (s === ">" || s === "<" || s === ">=" || s === "<=")
|
|
3545
|
+
switch (typeof r == "number" && (n = parseFloat(i)), s) {
|
|
3546
|
+
case ">":
|
|
3547
|
+
return fe(r, n);
|
|
3548
|
+
case ">=":
|
|
3549
|
+
return pe(r, n);
|
|
3550
|
+
case "<":
|
|
3551
|
+
return ss(r, n);
|
|
3552
|
+
case "<=":
|
|
3553
|
+
return is(r, n);
|
|
3554
|
+
}
|
|
3555
|
+
const o = s === "" || s === "=";
|
|
3556
|
+
if (i === "")
|
|
3557
|
+
return (r == null || r === "") === o;
|
|
3558
|
+
if (typeof r == "string" || r instanceof String) {
|
|
3559
|
+
const a = i.replace(/~\*/g, "(\\*)").replace(/~\?/g, "(\\?)").replace(/\*/g, "(.*)").replace(/\?/g, "(.)");
|
|
3560
|
+
return RegExp(`^${a}$`, "i").test(r) === o;
|
|
3561
|
+
}
|
|
3562
|
+
return me(r, n) === o;
|
|
3563
|
+
}, ot = (r, t, e) => {
|
|
3564
|
+
if (r instanceof $) {
|
|
3565
|
+
const s = r.solve({ at: e });
|
|
3566
|
+
for (let i = 0; i < s.length; i++)
|
|
3567
|
+
for (let n = 0; n < s[i].length; n++)
|
|
3568
|
+
t(s[i][n], { y: i, x: n });
|
|
3569
|
+
} else if (B.is(r)) {
|
|
3570
|
+
const s = r.matrix;
|
|
3571
|
+
for (let i = 0; i < s.length; i++)
|
|
3572
|
+
for (let n = 0; n < s[i].length; n++)
|
|
3573
|
+
t(s[i][n], { y: i, x: n });
|
|
3574
|
+
} else if (Array.isArray(r) && Array.isArray(r[0]))
|
|
3575
|
+
for (let s = 0; s < r.length; s++)
|
|
3576
|
+
for (let i = 0; i < r[s].length; i++)
|
|
3577
|
+
t(r[s][i], { y: s, x: i });
|
|
3578
|
+
else
|
|
3579
|
+
t(r, { y: 0, x: 0 });
|
|
3580
|
+
}, mn = (r, t, e) => {
|
|
3581
|
+
if (r.length === 0)
|
|
3582
|
+
return [];
|
|
3583
|
+
const s = r[0], i = s.numRows, n = s.numCols, o = Array.from({ length: i }, () => Array(n).fill(!0));
|
|
3584
|
+
for (let a = 0; a < r.length; a++) {
|
|
3585
|
+
const l = r[a], u = t[a];
|
|
3586
|
+
ot(
|
|
3587
|
+
l,
|
|
3588
|
+
(h, c) => {
|
|
3589
|
+
var f, d;
|
|
3590
|
+
(f = o[c.y])[d = c.x] && (f[d] = _i(h, u));
|
|
3591
|
+
},
|
|
3592
|
+
e
|
|
3593
|
+
);
|
|
3594
|
+
}
|
|
3595
|
+
return o;
|
|
3596
|
+
}, Q = (r) => (r == null ? void 0 : r.__gsType) === "Sheet", gn = {
|
|
3597
|
+
name: "condition",
|
|
3598
|
+
description: 'The condition to evaluate. Use "=" for equal, "<" for less than, ">" for greater than, "<=" for less than or equal, ">=" for greater than or equal, "<>" for not equal.',
|
|
3599
|
+
acceptedTypes: ["any"]
|
|
3600
|
+
}, Ei = (r, { nullable: t = !0, errorTolerant: e = !1, acceptedTypes: s }) => {
|
|
3601
|
+
if (!s || s.length === 0)
|
|
3602
|
+
return !0;
|
|
3603
|
+
if (r == null)
|
|
3604
|
+
return t;
|
|
3605
|
+
if (x.is(r) || r instanceof Error) {
|
|
3606
|
+
if (e)
|
|
3607
|
+
return !0;
|
|
3608
|
+
throw r;
|
|
3609
|
+
}
|
|
3610
|
+
for (const i of s)
|
|
3611
|
+
switch (i) {
|
|
3612
|
+
case "any":
|
|
3613
|
+
return !0;
|
|
3614
|
+
case "number":
|
|
3615
|
+
if (Mt(r))
|
|
3616
|
+
return !0;
|
|
3617
|
+
break;
|
|
3618
|
+
case "string":
|
|
3619
|
+
if (typeof r == "string")
|
|
3620
|
+
return !0;
|
|
3621
|
+
break;
|
|
3622
|
+
case "boolean":
|
|
3623
|
+
if (typeof r == "boolean")
|
|
3624
|
+
return !0;
|
|
3625
|
+
break;
|
|
3626
|
+
case "date":
|
|
3627
|
+
if (r instanceof Date)
|
|
3628
|
+
return !0;
|
|
3629
|
+
break;
|
|
3630
|
+
case "time":
|
|
3631
|
+
if (b.is(r))
|
|
3632
|
+
return !0;
|
|
3633
|
+
break;
|
|
3634
|
+
case "matrix":
|
|
3635
|
+
if (at(r))
|
|
3636
|
+
return !0;
|
|
3637
|
+
break;
|
|
3638
|
+
case "reference":
|
|
3639
|
+
if (Q(r))
|
|
3640
|
+
return !0;
|
|
3641
|
+
break;
|
|
3642
|
+
}
|
|
3643
|
+
return !1;
|
|
3644
|
+
}, at = (r) => Q(r) || B.is(r) || Array.isArray(r) && Array.isArray(r[0]), Ai = (r, t) => {
|
|
3645
|
+
var i;
|
|
3646
|
+
if (!at(r))
|
|
3647
|
+
return r;
|
|
3648
|
+
if (Q(r))
|
|
3649
|
+
return nt({ value: r, raise: !1, at: t });
|
|
3650
|
+
const e = B.is(r) ? r.matrix : r;
|
|
3651
|
+
return (i = e == null ? void 0 : e[0]) == null ? void 0 : i[0];
|
|
3652
|
+
}, Ne = (r) => {
|
|
3653
|
+
if (Q(r))
|
|
3654
|
+
return !r.hasSingleCell;
|
|
3655
|
+
if (B.is(r)) {
|
|
3656
|
+
const t = r.matrix;
|
|
3657
|
+
return t.length > 1 || t.length === 1 && t[0].length > 1;
|
|
3658
|
+
}
|
|
3659
|
+
return Array.isArray(r) && Array.isArray(r[0]) ? r.length > 1 || r[0].length > 1 : !1;
|
|
3660
|
+
}, Fe = (r, t) => {
|
|
3661
|
+
const e = [];
|
|
3662
|
+
let s = -1, i = 0;
|
|
3663
|
+
for (let n = 0; n < r.length; n++)
|
|
3664
|
+
r[n].variadic && (s < 0 && (s = n), i++);
|
|
3665
|
+
for (let n = 0; n < t; n++)
|
|
3666
|
+
if (s >= 0 && n >= s) {
|
|
3667
|
+
const o = (n - s) % i;
|
|
3668
|
+
e.push(s + o);
|
|
3669
|
+
} else n < r.length ? e.push(n) : e.push(r.length - 1);
|
|
3670
|
+
return e;
|
|
3671
|
+
}, Yt = class Yt {
|
|
3672
|
+
constructor({ args: t, sheet: e, at: s }) {
|
|
3673
|
+
this.defs = [], this.description = "", this.category = "other", this.isAsync = !1, this.hashPrecision = 1, this.useInflight = !0, this.broadcastDisabled = !1, this.autoSpilling = !1, this.eachMatrix = (i, n) => {
|
|
3674
|
+
if (Q(i)) {
|
|
3675
|
+
const o = i.solve({ at: this.at, raise: !0 });
|
|
3676
|
+
for (let a = 0; a < o.length; a++)
|
|
3677
|
+
for (let l = 0; l < o[a].length; l++)
|
|
3678
|
+
n(o[a][l]);
|
|
3679
|
+
} else if (B.is(i)) {
|
|
3680
|
+
const o = i.matrix;
|
|
3681
|
+
for (let a = 0; a < o.length; a++)
|
|
3682
|
+
for (let l = 0; l < o[a].length; l++)
|
|
3683
|
+
n(o[a][l]);
|
|
3684
|
+
} else if (Array.isArray(i) && Array.isArray(i[0]))
|
|
3685
|
+
for (let o = 0; o < i.length; o++)
|
|
3686
|
+
for (let a = 0; a < i[o].length; a++)
|
|
3687
|
+
n(i[o][a]);
|
|
3688
|
+
else
|
|
3689
|
+
n(i);
|
|
3690
|
+
}, this.args = t.map((i) => {
|
|
3691
|
+
try {
|
|
3692
|
+
return i.evaluate({ sheet: e });
|
|
3693
|
+
} catch (n) {
|
|
3694
|
+
return n;
|
|
3695
|
+
}
|
|
3696
|
+
}), this.sheet = e, this.at = s ?? "?";
|
|
3697
|
+
}
|
|
3698
|
+
_main(...t) {
|
|
3699
|
+
return this.autoSpilling ? new B(this.main(...t)) : this.main(...t);
|
|
3700
|
+
}
|
|
3701
|
+
/**
|
|
3702
|
+
* Validate and normalise arguments before `main()` is called.
|
|
3703
|
+
*
|
|
3704
|
+
* Checks:
|
|
3705
|
+
* 1. Argument count satisfies defs (respecting optional / variadic).
|
|
3706
|
+
* 2. Each argument's runtime type matches the corresponding def's `type` list.
|
|
3707
|
+
*
|
|
3708
|
+
* Subclasses may override for additional coercion / spreading.
|
|
3709
|
+
*/
|
|
3710
|
+
validate(t) {
|
|
3711
|
+
const e = [...t], s = this.defs;
|
|
3712
|
+
if (s.length === 0) {
|
|
3713
|
+
if (t.length !== 0)
|
|
3714
|
+
throw new x("#N/A", "Too many arguments: expected 0, got " + t.length + ".");
|
|
3715
|
+
return e;
|
|
3716
|
+
}
|
|
3717
|
+
let i = 0, n = !1;
|
|
3718
|
+
for (const a of s)
|
|
3719
|
+
a.variadic && (n = !0), a.optional || i++;
|
|
3720
|
+
if (t.length < i)
|
|
3721
|
+
throw new x("#N/A", `Too few arguments: expected at least ${i}, got ${t.length}.`);
|
|
3722
|
+
if (!n && t.length > s.length)
|
|
3723
|
+
throw new x("#N/A", `Too many arguments: expected at most ${s.length}, got ${t.length}.`);
|
|
3724
|
+
const o = Fe(s, t.length);
|
|
3725
|
+
for (let a = 0; a < t.length; a++) {
|
|
3726
|
+
const l = s[o[a]];
|
|
3727
|
+
if (!l)
|
|
3728
|
+
continue;
|
|
3729
|
+
let u = t[a];
|
|
3730
|
+
if (!(!l.acceptedTypes || l.acceptedTypes.length === 0)) {
|
|
3731
|
+
if (Ne(u)) {
|
|
3732
|
+
if (!l.takesMatrix)
|
|
3733
|
+
continue;
|
|
3734
|
+
} else at(u) && (l.takesMatrix || (u = Ai(u, this.at)));
|
|
3735
|
+
if (ge(u) && (u = parseFloat(u.slice(0, -1)) / 100), !Ei(u, l))
|
|
3736
|
+
throw new x(
|
|
3737
|
+
"#VALUE!",
|
|
3738
|
+
`Argument "${l.name}" (position ${a + 1}) expected ${l.acceptedTypes.join(" | ")}, got ${typeof u}.`
|
|
3739
|
+
);
|
|
3740
|
+
e[a] = u;
|
|
3741
|
+
}
|
|
3742
|
+
}
|
|
3743
|
+
return e;
|
|
3744
|
+
}
|
|
3745
|
+
/**
|
|
3746
|
+
* Extract a 2D array from a matrix value (Spilling, Sheet, or nested array).
|
|
3747
|
+
* Default behavior for Sheet is value.solve(). Functions like COL can override
|
|
3748
|
+
* this to preserve Sheet metadata per cell.
|
|
3749
|
+
*/
|
|
3750
|
+
toMatrix(t) {
|
|
3751
|
+
return B.is(t) ? t.matrix : Q(t) ? t.solve({ at: this.at }) : Array.isArray(t) && Array.isArray(t[0]) ? t : [[t]];
|
|
3752
|
+
}
|
|
3753
|
+
/**
|
|
3754
|
+
* Collapse a 1×1 matrix value (Sheet, Spilling, or 2D array) to a scalar.
|
|
3755
|
+
* Non-matrix values pass through unchanged.
|
|
3756
|
+
*
|
|
3757
|
+
* Override in sub-classes that need the original Sheet / reference
|
|
3758
|
+
* metadata (e.g. COL, ROW) — for instance, to extract position
|
|
3759
|
+
* information before collapsing.
|
|
3760
|
+
*/
|
|
3761
|
+
toScalar(t) {
|
|
3762
|
+
var e, s, i;
|
|
3763
|
+
if (Q(t)) {
|
|
3764
|
+
const { rows: n, cols: o } = t.shape;
|
|
3765
|
+
return n === 1 && o === 1 ? t.strip({}) : t;
|
|
3766
|
+
}
|
|
3767
|
+
return B.is(t) ? (s = (e = t.matrix) == null ? void 0 : e[0]) == null ? void 0 : s[0] : Array.isArray(t) ? Array.isArray(t[0]) ? (i = t[0]) == null ? void 0 : i[0] : t[0] : t;
|
|
3768
|
+
}
|
|
3769
|
+
call() {
|
|
3770
|
+
const t = this.broadcast();
|
|
3771
|
+
if (t !== void 0)
|
|
3772
|
+
return t;
|
|
3773
|
+
if (Rt(this.args, this.at))
|
|
3774
|
+
return Gt();
|
|
3775
|
+
if (this.args = this.validate(this.args), this.isAsync) {
|
|
3776
|
+
const e = yi(this.constructor.name, this.args, this.hashPrecision), s = wi(this.sheet, this.at, e, this.useInflight);
|
|
3777
|
+
if (s !== ee)
|
|
3778
|
+
return s;
|
|
3779
|
+
const i = this._main(...this.args);
|
|
3780
|
+
return xi(i, this.sheet, this.at, e, this.ttlMilliseconds, this.useInflight);
|
|
3781
|
+
}
|
|
3782
|
+
return this._main(...this.args);
|
|
3783
|
+
}
|
|
3784
|
+
/**
|
|
3785
|
+
* If any broadcastable argument is a matrix (multi-cell), expand the call
|
|
3786
|
+
* across all element positions and return a Spilling.
|
|
3787
|
+
* Returns `undefined` when no broadcast is necessary.
|
|
3788
|
+
*
|
|
3789
|
+
* Rules:
|
|
3790
|
+
* - broadcastDisabled = true → never broadcast
|
|
3791
|
+
* - An arg is broadcastable when its corresponding args[].takesMatrix is not true
|
|
3792
|
+
* - A Sheet/Spilling/2D-array whose size is (1,1) is treated as a scalar
|
|
3793
|
+
* (not broadcast); only multi-cell matrices trigger broadcast
|
|
3794
|
+
* - For variadic args, extra args are assigned round-robin
|
|
3795
|
+
* across the variadic helpArg positions
|
|
3796
|
+
*/
|
|
3797
|
+
broadcast() {
|
|
3798
|
+
if (this.broadcastDisabled)
|
|
3799
|
+
return;
|
|
3800
|
+
const t = Fe(this.defs, this.args.length), e = this.args.map((u, h) => {
|
|
3801
|
+
var f;
|
|
3802
|
+
const c = t[h];
|
|
3803
|
+
return !((f = this.defs[c]) != null && f.takesMatrix);
|
|
3804
|
+
}), s = this.args.map((u, h) => e[h] && Ne(u) ? this.toMatrix(u) : null);
|
|
3805
|
+
if (s.every((u) => u === null))
|
|
3806
|
+
return;
|
|
3807
|
+
const i = this.args.map((u, h) => s[h] !== null ? u : this.toScalar(u));
|
|
3808
|
+
let n = 1, o = 1;
|
|
3809
|
+
for (const u of s)
|
|
3810
|
+
u && (n = Math.max(n, u.length), o = Math.max(
|
|
3811
|
+
o,
|
|
3812
|
+
u.reduce((h, c) => Math.max(h, c.length), 0)
|
|
3813
|
+
));
|
|
3814
|
+
const a = this.args, l = [];
|
|
3815
|
+
for (let u = 0; u < n; u++) {
|
|
3816
|
+
const h = [];
|
|
3817
|
+
for (let c = 0; c < o; c++) {
|
|
3818
|
+
const f = i.map((d, p) => {
|
|
3819
|
+
var g;
|
|
3820
|
+
const m = s[p];
|
|
3821
|
+
return m ? ((g = m == null ? void 0 : m[u]) == null ? void 0 : g[c]) ?? null : d;
|
|
3822
|
+
});
|
|
3823
|
+
try {
|
|
3824
|
+
if (mi(f))
|
|
3825
|
+
h.push(Gt());
|
|
3826
|
+
else {
|
|
3827
|
+
const d = this.validate(f);
|
|
3828
|
+
Rt(d, this.at) ? h.push(Gt()) : h.push(this._main(...d));
|
|
3829
|
+
}
|
|
3830
|
+
} catch (d) {
|
|
3831
|
+
h.push(d);
|
|
3832
|
+
}
|
|
3833
|
+
}
|
|
3834
|
+
l.push(h);
|
|
3835
|
+
}
|
|
3836
|
+
return this.args = a, l;
|
|
3837
|
+
}
|
|
3838
|
+
};
|
|
3839
|
+
Yt.__name = "", Yt.isAsync = !1;
|
|
3840
|
+
let E = Yt;
|
|
3841
|
+
const we = class we extends E {
|
|
3842
|
+
constructor() {
|
|
3843
|
+
super(...arguments), this.isAsync = !0;
|
|
3844
|
+
}
|
|
3845
|
+
};
|
|
3846
|
+
we.isAsync = !0;
|
|
3847
|
+
let De = we;
|
|
3848
|
+
const Ci = `Returns the sum of two numbers.
|
|
3849
|
+
This is the same as the '+' operator.`;
|
|
3850
|
+
class Ii extends E {
|
|
3851
|
+
constructor() {
|
|
3852
|
+
super(...arguments), this.example = "ADD(2, 3)", this.description = Ci, this.defs = [
|
|
3853
|
+
{ name: "value1", description: "First additive.", acceptedTypes: ["number", "date", "time"] },
|
|
3854
|
+
{ name: "value2", description: "Second additive.", acceptedTypes: ["number", "date", "time"] }
|
|
3855
|
+
], this.category = "math";
|
|
3856
|
+
}
|
|
3857
|
+
main(t, e) {
|
|
3858
|
+
if (typeof t == "number" && typeof e == "number")
|
|
3859
|
+
return t + e;
|
|
3860
|
+
if (t instanceof Date && b.is(e))
|
|
3861
|
+
return b.ensure(e).add(t);
|
|
3862
|
+
if (b.is(t) && e instanceof Date)
|
|
3863
|
+
return b.ensure(t).add(e);
|
|
3864
|
+
if (t instanceof Date && typeof e == "number")
|
|
3865
|
+
return H(t).add(e * Zt, "second").toDate();
|
|
3866
|
+
if (typeof t == "number" && e instanceof Date)
|
|
3867
|
+
return H(e).add(t * Zt, "second").toDate();
|
|
3868
|
+
try {
|
|
3869
|
+
return F(t, { alternative: 0 }) + F(e, { alternative: 0 });
|
|
3870
|
+
} catch {
|
|
3871
|
+
throw new x("#VALUE!", "Mismatched types for augend or addend.");
|
|
3872
|
+
}
|
|
3873
|
+
}
|
|
3874
|
+
}
|
|
3875
|
+
const Ti = `Returns the difference of two numbers.
|
|
3876
|
+
This is the same as the '-' operator.`;
|
|
3877
|
+
class Mi extends E {
|
|
3878
|
+
constructor() {
|
|
3879
|
+
super(...arguments), this.example = "MINUS(8, 3)", this.description = Ti, this.defs = [
|
|
3880
|
+
{ name: "value1", description: "A number that will be subtracted.", acceptedTypes: ["number", "date", "time"] },
|
|
3881
|
+
{
|
|
3882
|
+
name: "value2",
|
|
3883
|
+
description: "A number that will subtract from value1.",
|
|
3884
|
+
acceptedTypes: ["number", "date", "time"]
|
|
3885
|
+
}
|
|
3886
|
+
], this.category = "math";
|
|
3887
|
+
}
|
|
3888
|
+
main(t, e) {
|
|
3889
|
+
if (typeof t == "number" && typeof e == "number")
|
|
3890
|
+
return t - e;
|
|
3891
|
+
if (t instanceof Date && e instanceof Date)
|
|
3892
|
+
return b.fromDates(t, e);
|
|
3893
|
+
if (t instanceof Date && b.is(e))
|
|
3894
|
+
return b.ensure(e).sub(t);
|
|
3895
|
+
if (b.is(t) && e instanceof Date)
|
|
3896
|
+
return b.ensure(t).sub(e);
|
|
3897
|
+
if (t instanceof Date && typeof e == "number")
|
|
3898
|
+
return H(t).subtract(e * Zt, "second").toDate();
|
|
3899
|
+
try {
|
|
3900
|
+
return F(t, { alternative: 0 }) - F(e, { alternative: 0 });
|
|
3901
|
+
} catch {
|
|
3902
|
+
throw new x("#VALUE!", "Mismatched types for minuend or subtrahend.");
|
|
3903
|
+
}
|
|
3904
|
+
}
|
|
3905
|
+
}
|
|
3906
|
+
const Oi = `Returns the product of two numbers.
|
|
3907
|
+
This is the same as the '*' operator.`;
|
|
3908
|
+
class Ni extends E {
|
|
3909
|
+
constructor() {
|
|
3910
|
+
super(...arguments), this.example = "MULTIPLY(6, 7)", this.description = Oi, this.defs = [
|
|
3911
|
+
{ name: "factor1", description: "First factor.", acceptedTypes: ["number"] },
|
|
3912
|
+
{ name: "factor2", description: "Second factor.", acceptedTypes: ["number"] }
|
|
3913
|
+
], this.category = "math";
|
|
3914
|
+
}
|
|
3915
|
+
main(t, e) {
|
|
3916
|
+
return F(t) * F(e);
|
|
3917
|
+
}
|
|
3918
|
+
}
|
|
3919
|
+
const Fi = `Returns the result of dividing one number by another.
|
|
3920
|
+
This is the same as the '/' operator.`;
|
|
3921
|
+
class Di extends E {
|
|
3922
|
+
constructor() {
|
|
3923
|
+
super(...arguments), this.example = "DIVIDE(4, 2)", this.description = Fi, this.defs = [
|
|
3924
|
+
{
|
|
3925
|
+
name: "dividend",
|
|
3926
|
+
description: "A number that will be divided by divisor.",
|
|
3927
|
+
acceptedTypes: ["number"]
|
|
3928
|
+
},
|
|
3929
|
+
{
|
|
3930
|
+
name: "divisor",
|
|
3931
|
+
description: "A number that will divide a dividend. Must be non-zero.",
|
|
3932
|
+
acceptedTypes: ["number"]
|
|
3933
|
+
}
|
|
3934
|
+
], this.category = "math";
|
|
3935
|
+
}
|
|
3936
|
+
validate(t) {
|
|
3937
|
+
const e = super.validate(t).map((s) => F(s));
|
|
3938
|
+
if (e[1] === 0)
|
|
3939
|
+
throw new x("#DIV/0!", "The second argument must be non-zero.");
|
|
3940
|
+
return e;
|
|
3941
|
+
}
|
|
3942
|
+
main(t, e) {
|
|
3943
|
+
return t / e;
|
|
3944
|
+
}
|
|
3945
|
+
}
|
|
3946
|
+
const vi = "Returns the sum of a series of numbers or cells.";
|
|
3947
|
+
class ki extends E {
|
|
3948
|
+
constructor() {
|
|
3949
|
+
super(...arguments), this.example = "SUM(A2:A100, 101)", this.description = vi, this.defs = [
|
|
3950
|
+
{
|
|
3951
|
+
name: "value",
|
|
3952
|
+
description: "Numbers or ranges to sum.",
|
|
3953
|
+
takesMatrix: !0,
|
|
3954
|
+
acceptedTypes: ["number", "matrix"],
|
|
3955
|
+
variadic: !0
|
|
3956
|
+
}
|
|
3957
|
+
], this.category = "math";
|
|
3958
|
+
}
|
|
3959
|
+
main(...t) {
|
|
3960
|
+
if (t.length === 0)
|
|
3961
|
+
return 0;
|
|
3962
|
+
let e = 0;
|
|
3963
|
+
return t.forEach((s) => {
|
|
3964
|
+
ot(
|
|
3965
|
+
s,
|
|
3966
|
+
(i) => {
|
|
3967
|
+
e += F(i, { ignore: !0 });
|
|
3968
|
+
},
|
|
3969
|
+
this.at
|
|
3970
|
+
);
|
|
3971
|
+
}), e;
|
|
3972
|
+
}
|
|
3973
|
+
}
|
|
3974
|
+
const Pi = `Returns the concatenation of two values.
|
|
3975
|
+
This is the same as the '&' operator.`;
|
|
3976
|
+
class $i extends E {
|
|
3977
|
+
constructor() {
|
|
3978
|
+
super(...arguments), this.example = 'CONCAT("Hello", "World")', this.description = Pi, this.defs = [
|
|
3979
|
+
{
|
|
3980
|
+
name: "value1",
|
|
3981
|
+
description: "A value to be concatenated with value2.",
|
|
3982
|
+
acceptedTypes: ["string", "number", "boolean"]
|
|
3983
|
+
},
|
|
3984
|
+
{
|
|
3985
|
+
name: "value2",
|
|
3986
|
+
description: "A value to be concatenated with value1",
|
|
3987
|
+
acceptedTypes: ["string", "number", "boolean"]
|
|
3988
|
+
}
|
|
3989
|
+
], this.category = "text";
|
|
3990
|
+
}
|
|
3991
|
+
main(t, e) {
|
|
3992
|
+
return X(t) + X(e);
|
|
3993
|
+
}
|
|
3994
|
+
}
|
|
3995
|
+
const Li = `Returns TRUE if the two specified values are equal, FALSE if they are not.
|
|
3996
|
+
This is the same as the '=' operator.`;
|
|
3997
|
+
class Hi extends E {
|
|
3998
|
+
constructor() {
|
|
3999
|
+
super(...arguments), this.example = "EQ(6, 7)", this.description = Li, this.defs = [
|
|
4000
|
+
{ name: "value1", description: "First value.", acceptedTypes: ["any"] },
|
|
4001
|
+
{ name: "value2", description: "A value to be compared with value1.", acceptedTypes: ["any"] }
|
|
4002
|
+
], this.category = "logical";
|
|
4003
|
+
}
|
|
4004
|
+
main(t, e) {
|
|
4005
|
+
return me(t, e);
|
|
4006
|
+
}
|
|
4007
|
+
}
|
|
4008
|
+
const Yi = `Returns TRUE if the two specified values are not equal, FALSE if they are.
|
|
4009
|
+
This is the same as the '<>' operator.`;
|
|
4010
|
+
class Bi extends E {
|
|
4011
|
+
constructor() {
|
|
4012
|
+
super(...arguments), this.example = "NE(6, 7)", this.description = Yi, this.defs = [
|
|
4013
|
+
{ name: "value1", description: "First value.", acceptedTypes: ["any"] },
|
|
4014
|
+
{ name: "value2", description: "A value to be compared with value1.", acceptedTypes: ["any"] }
|
|
4015
|
+
], this.category = "logical";
|
|
4016
|
+
}
|
|
4017
|
+
main(t, e) {
|
|
4018
|
+
return bi(t, e);
|
|
4019
|
+
}
|
|
4020
|
+
}
|
|
4021
|
+
const Ui = `Returns TRUE if the first argument is truly greater than the second, FALSE otherwise.
|
|
4022
|
+
This is the same as the '>' operator.`;
|
|
4023
|
+
class zi extends E {
|
|
4024
|
+
constructor() {
|
|
4025
|
+
super(...arguments), this.example = "GT(5, 3)", this.description = Ui, this.defs = [
|
|
4026
|
+
{ name: "value1", description: "First value.", acceptedTypes: ["any"] },
|
|
4027
|
+
{ name: "value2", description: "A value to be compared with value1.", acceptedTypes: ["any"] }
|
|
4028
|
+
], this.category = "logical";
|
|
4029
|
+
}
|
|
4030
|
+
main(t, e) {
|
|
4031
|
+
return fe(t, e);
|
|
4032
|
+
}
|
|
4033
|
+
}
|
|
4034
|
+
const Vi = `Returns TRUE if the first argument is greater than the second, FALSE otherwise.
|
|
4035
|
+
This is the same as the '>=' operator.`;
|
|
4036
|
+
class Wi extends E {
|
|
4037
|
+
constructor() {
|
|
4038
|
+
super(...arguments), this.example = "GTE(5, 3)", this.description = Vi, this.defs = [
|
|
4039
|
+
{ name: "value1", description: "First value.", acceptedTypes: ["any"] },
|
|
4040
|
+
{ name: "value2", description: "A value to be compared with value1.", acceptedTypes: ["any"] }
|
|
4041
|
+
], this.category = "logical";
|
|
4042
|
+
}
|
|
4043
|
+
main(t, e) {
|
|
4044
|
+
return pe(t, e);
|
|
4045
|
+
}
|
|
4046
|
+
}
|
|
4047
|
+
const Xi = `Returns TRUE if the first argument is truely less than the second argument, FALSE otherwise.
|
|
4048
|
+
This is the same as the '<' operator.`;
|
|
4049
|
+
class ji extends E {
|
|
4050
|
+
constructor() {
|
|
4051
|
+
super(...arguments), this.example = "LT(3, 6)", this.description = Xi, this.defs = [
|
|
4052
|
+
{ name: "value1", description: "First value.", acceptedTypes: ["any"] },
|
|
4053
|
+
{ name: "value2", description: "A value to be compared with value1.", acceptedTypes: ["any"] }
|
|
4054
|
+
], this.category = "logical";
|
|
4055
|
+
}
|
|
4056
|
+
main(t, e) {
|
|
4057
|
+
return ss(t, e);
|
|
4058
|
+
}
|
|
4059
|
+
}
|
|
4060
|
+
const Gi = `Returns TRUE if the first argument is less than the second argument, FALSE otherwise.
|
|
4061
|
+
This is the same as the '<=' operator.`;
|
|
4062
|
+
class Zi extends E {
|
|
4063
|
+
constructor() {
|
|
4064
|
+
super(...arguments), this.example = "LTE(3, 6)", this.description = Gi, this.defs = [
|
|
4065
|
+
{ name: "value1", description: "First value.", acceptedTypes: ["any"] },
|
|
4066
|
+
{ name: "value2", description: "A value to be compared with value1.", acceptedTypes: ["any"] }
|
|
4067
|
+
], this.category = "logical";
|
|
4068
|
+
}
|
|
4069
|
+
main(t, e) {
|
|
4070
|
+
return is(t, e);
|
|
4071
|
+
}
|
|
4072
|
+
}
|
|
4073
|
+
const qi = "Returns a serial value corresponding to the current date and time.";
|
|
4074
|
+
class Ki extends E {
|
|
4075
|
+
constructor() {
|
|
4076
|
+
super(...arguments), this.example = "NOW()", this.description = qi, this.defs = [], this.category = "time";
|
|
4077
|
+
}
|
|
4078
|
+
main() {
|
|
4079
|
+
return /* @__PURE__ */ new Date();
|
|
4080
|
+
}
|
|
4081
|
+
}
|
|
4082
|
+
const Ji = `Returns TRUE if all arguments are logically TRUE.
|
|
4083
|
+
Returns FALSE if any argument is logically FALSE.`;
|
|
4084
|
+
class Qi extends E {
|
|
4085
|
+
constructor() {
|
|
4086
|
+
super(...arguments), this.example = "AND(A1=1, A2=2)", this.description = Ji, this.defs = [
|
|
4087
|
+
{
|
|
4088
|
+
name: "expression",
|
|
4089
|
+
description: "Logical expressions to evaluate.",
|
|
4090
|
+
acceptedTypes: ["boolean", "number"],
|
|
4091
|
+
variadic: !0
|
|
4092
|
+
}
|
|
4093
|
+
], this.category = "logical";
|
|
4094
|
+
}
|
|
4095
|
+
main(...t) {
|
|
4096
|
+
return t.map((e) => Ot(e)).reduce((e, s) => e && s);
|
|
4097
|
+
}
|
|
4098
|
+
}
|
|
4099
|
+
const tr = `Returns TRUE if any argument is logically true.
|
|
4100
|
+
Returns FALSE if all arguments are logically false.`;
|
|
4101
|
+
class er extends E {
|
|
4102
|
+
constructor() {
|
|
4103
|
+
super(...arguments), this.example = "OR(A1=1, A2=2)", this.description = tr, this.defs = [
|
|
4104
|
+
{
|
|
4105
|
+
name: "expression",
|
|
4106
|
+
description: "Logical expressions to evaluate.",
|
|
4107
|
+
acceptedTypes: ["boolean", "number"],
|
|
4108
|
+
variadic: !0
|
|
4109
|
+
}
|
|
4110
|
+
], this.category = "logical";
|
|
4111
|
+
}
|
|
4112
|
+
main(...t) {
|
|
4113
|
+
return t.map((e) => Ot(e)).reduce((e, s) => e || s);
|
|
4114
|
+
}
|
|
4115
|
+
}
|
|
4116
|
+
const sr = `If the logical expression is TRUE, the second argument is returned.
|
|
4117
|
+
If FALSE, the third argument is returned.`;
|
|
4118
|
+
class ir extends E {
|
|
4119
|
+
constructor() {
|
|
4120
|
+
super(...arguments), this.example = 'IF(A2 = "Human", "Hello", "World")', this.description = sr, this.defs = [
|
|
4121
|
+
{ name: "condition", description: "An expression as a condition", acceptedTypes: ["any"] },
|
|
4122
|
+
{
|
|
4123
|
+
name: "value1",
|
|
4124
|
+
description: "value to be returned if the condition is true.",
|
|
4125
|
+
acceptedTypes: ["any"]
|
|
4126
|
+
},
|
|
4127
|
+
{
|
|
4128
|
+
name: "value2",
|
|
4129
|
+
description: "value to be returned if the condition is false.",
|
|
4130
|
+
optional: !0,
|
|
4131
|
+
acceptedTypes: ["any"]
|
|
4132
|
+
}
|
|
4133
|
+
], this.category = "logical";
|
|
4134
|
+
}
|
|
4135
|
+
main(t, e, s = !1) {
|
|
4136
|
+
return Ot(t) ? e : s;
|
|
4137
|
+
}
|
|
4138
|
+
}
|
|
4139
|
+
const rr = "Returns the first argument if it is not an error value, otherwise returns the second argument if present, or a blank if the second argument is absent.";
|
|
4140
|
+
class nr extends E {
|
|
4141
|
+
constructor() {
|
|
4142
|
+
super(...arguments), this.example = 'IFERROR(A1, "Error in cell A1")', this.description = rr, this.defs = [
|
|
4143
|
+
{
|
|
4144
|
+
name: "value",
|
|
4145
|
+
description: "The value to return if value itself is not an error.",
|
|
4146
|
+
acceptedTypes: ["any"],
|
|
4147
|
+
errorTolerant: !0
|
|
4148
|
+
},
|
|
4149
|
+
{
|
|
4150
|
+
name: "value_if_error",
|
|
4151
|
+
description: "The value the function returns if value is an error.",
|
|
4152
|
+
optional: !0,
|
|
4153
|
+
acceptedTypes: ["any"]
|
|
4154
|
+
}
|
|
4155
|
+
], this.category = "logical", this.broadcastDisabled = !0;
|
|
4156
|
+
}
|
|
4157
|
+
main(t, e) {
|
|
4158
|
+
return x.is(t) || t instanceof Error ? e : t;
|
|
4159
|
+
}
|
|
4160
|
+
}
|
|
4161
|
+
const or = `Returns the inverse of the Boolean; if TRUE, NOT returns FALSE.
|
|
4162
|
+
If FALSE, NOT returns TRUE.`;
|
|
4163
|
+
class ar extends E {
|
|
4164
|
+
constructor() {
|
|
4165
|
+
super(...arguments), this.example = "NOT(TRUE)", this.description = or, this.defs = [
|
|
4166
|
+
{
|
|
4167
|
+
name: "logical expression",
|
|
4168
|
+
description: "A logical expression as a boolean.",
|
|
4169
|
+
acceptedTypes: ["boolean", "number"]
|
|
4170
|
+
}
|
|
4171
|
+
], this.category = "logical";
|
|
4172
|
+
}
|
|
4173
|
+
main(t) {
|
|
4174
|
+
return !Ot(t);
|
|
4175
|
+
}
|
|
4176
|
+
}
|
|
4177
|
+
const cr = "Returns the count of a series of numbers or cells.";
|
|
4178
|
+
class lr extends E {
|
|
4179
|
+
constructor() {
|
|
4180
|
+
super(...arguments), this.example = "COUNT(A2:A100,B2:B100,4,26)", this.description = cr, this.defs = [
|
|
4181
|
+
{
|
|
4182
|
+
name: "value",
|
|
4183
|
+
description: "Numbers or ranges to count.",
|
|
4184
|
+
takesMatrix: !0,
|
|
4185
|
+
acceptedTypes: ["number", "matrix"],
|
|
4186
|
+
variadic: !0
|
|
4187
|
+
}
|
|
4188
|
+
], this.category = "math";
|
|
4189
|
+
}
|
|
4190
|
+
main(...t) {
|
|
4191
|
+
let e = 0;
|
|
4192
|
+
return t.forEach((s) => {
|
|
4193
|
+
at(s) ? ot(
|
|
4194
|
+
s,
|
|
4195
|
+
(i) => {
|
|
4196
|
+
Mt(i) && e++;
|
|
4197
|
+
},
|
|
4198
|
+
this.at
|
|
4199
|
+
) : (F(s), e++);
|
|
4200
|
+
}), e;
|
|
4201
|
+
}
|
|
4202
|
+
}
|
|
4203
|
+
const hr = "Returns the absolute value of a number";
|
|
4204
|
+
class ur extends E {
|
|
4205
|
+
constructor() {
|
|
4206
|
+
super(...arguments), this.example = "ABS(-2)", this.description = hr, this.defs = [{ name: "value", description: "target number", acceptedTypes: ["number"] }], this.category = "math";
|
|
4207
|
+
}
|
|
4208
|
+
main(t) {
|
|
4209
|
+
return Math.abs(F(t));
|
|
4210
|
+
}
|
|
4211
|
+
}
|
|
4212
|
+
const dr = "Returns a number multiplied by an exponent.";
|
|
4213
|
+
class ve extends E {
|
|
4214
|
+
constructor() {
|
|
4215
|
+
super(...arguments), this.example = "POWER(4,0.5)", this.description = dr, this.defs = [
|
|
4216
|
+
{ name: "base", description: "A number to be multiplied by an exponent.", acceptedTypes: ["number"] },
|
|
4217
|
+
{ name: "exponent", description: "An exponent to power the base.", acceptedTypes: ["number"] }
|
|
4218
|
+
], this.category = "math";
|
|
4219
|
+
}
|
|
4220
|
+
main(t, e) {
|
|
4221
|
+
return Math.pow(F(t), F(e));
|
|
4222
|
+
}
|
|
4223
|
+
}
|
|
4224
|
+
const fr = "Returns the number of values in the data set.";
|
|
4225
|
+
class pr extends E {
|
|
4226
|
+
constructor() {
|
|
4227
|
+
super(...arguments), this.example = "COUNTA(A2:A100,B2:B100,4,26)", this.description = fr, this.defs = [
|
|
4228
|
+
{
|
|
4229
|
+
name: "value",
|
|
4230
|
+
description: "Values or ranges to count.",
|
|
4231
|
+
takesMatrix: !0,
|
|
4232
|
+
acceptedTypes: ["number", "matrix"],
|
|
4233
|
+
variadic: !0
|
|
4234
|
+
}
|
|
4235
|
+
], this.category = "math";
|
|
4236
|
+
}
|
|
4237
|
+
main(...t) {
|
|
4238
|
+
let e = 0;
|
|
4239
|
+
return t.forEach((s) => {
|
|
4240
|
+
ot(
|
|
4241
|
+
s,
|
|
4242
|
+
(i) => {
|
|
4243
|
+
i != null && i !== "" && e++;
|
|
4244
|
+
},
|
|
4245
|
+
this.at
|
|
4246
|
+
);
|
|
4247
|
+
}), e;
|
|
4248
|
+
}
|
|
4249
|
+
}
|
|
4250
|
+
const mr = "Returns the average of a series of numbers or cells.";
|
|
4251
|
+
class gr extends E {
|
|
4252
|
+
constructor() {
|
|
4253
|
+
super(...arguments), this.example = "AVERAGE(A2:A100, 101)", this.description = mr, this.defs = [
|
|
4254
|
+
{
|
|
4255
|
+
name: "value",
|
|
4256
|
+
description: "Numbers or ranges to average.",
|
|
4257
|
+
takesMatrix: !0,
|
|
4258
|
+
acceptedTypes: ["number", "matrix"],
|
|
4259
|
+
variadic: !0
|
|
4260
|
+
}
|
|
4261
|
+
], this.category = "statistics";
|
|
4262
|
+
}
|
|
4263
|
+
main(...t) {
|
|
4264
|
+
let e = 0, s = 0;
|
|
4265
|
+
if (t.forEach((i) => {
|
|
4266
|
+
if (at(i))
|
|
4267
|
+
ot(
|
|
4268
|
+
i,
|
|
4269
|
+
(n) => {
|
|
4270
|
+
Mt(n) && (e += F(n), s++);
|
|
4271
|
+
},
|
|
4272
|
+
this.at
|
|
4273
|
+
);
|
|
4274
|
+
else {
|
|
4275
|
+
const n = F(i);
|
|
4276
|
+
e += n, s++;
|
|
4277
|
+
}
|
|
4278
|
+
}), s === 0)
|
|
4279
|
+
throw new x("#DIV/0!", "Evaluation of function AVERAGE caused a divide by zero error.");
|
|
4280
|
+
return e / s;
|
|
4281
|
+
}
|
|
4282
|
+
}
|
|
4283
|
+
const yr = "Returns the max in a series of numbers or cells.";
|
|
4284
|
+
class wr extends E {
|
|
4285
|
+
constructor() {
|
|
4286
|
+
super(...arguments), this.example = "MAX(A2:A100, 101)", this.description = yr, this.defs = [
|
|
4287
|
+
{
|
|
4288
|
+
name: "value",
|
|
4289
|
+
description: "Numbers or ranges to find max from.",
|
|
4290
|
+
acceptedTypes: ["number", "matrix"],
|
|
4291
|
+
takesMatrix: !0,
|
|
4292
|
+
variadic: !0
|
|
4293
|
+
}
|
|
4294
|
+
], this.category = "statistics";
|
|
4295
|
+
}
|
|
4296
|
+
main(...t) {
|
|
4297
|
+
let e = -1 / 0, s = !1;
|
|
4298
|
+
return t.forEach((i) => {
|
|
4299
|
+
if (at(i))
|
|
4300
|
+
ot(
|
|
4301
|
+
i,
|
|
4302
|
+
(n) => {
|
|
4303
|
+
if (Mt(n)) {
|
|
4304
|
+
const o = F(n);
|
|
4305
|
+
o > e && (e = o), s = !0;
|
|
4306
|
+
}
|
|
4307
|
+
},
|
|
4308
|
+
this.at
|
|
4309
|
+
);
|
|
4310
|
+
else {
|
|
4311
|
+
const n = F(i);
|
|
4312
|
+
n > e && (e = n), s = !0;
|
|
4313
|
+
}
|
|
4314
|
+
}), s ? e : 0;
|
|
4315
|
+
}
|
|
4316
|
+
}
|
|
4317
|
+
const xr = "Returns the min in a series of numbers or cells.";
|
|
4318
|
+
class br extends E {
|
|
4319
|
+
constructor() {
|
|
4320
|
+
super(...arguments), this.example = "MIN(A2:A100, 101)", this.description = xr, this.defs = [
|
|
4321
|
+
{
|
|
4322
|
+
name: "value",
|
|
4323
|
+
description: "Numbers or ranges to find min from.",
|
|
4324
|
+
acceptedTypes: ["number", "matrix"],
|
|
4325
|
+
takesMatrix: !0,
|
|
4326
|
+
variadic: !0
|
|
4327
|
+
}
|
|
4328
|
+
], this.category = "statistics";
|
|
4329
|
+
}
|
|
4330
|
+
main(...t) {
|
|
4331
|
+
let e = 1 / 0, s = !1;
|
|
4332
|
+
return t.forEach((i) => {
|
|
4333
|
+
if (at(i))
|
|
4334
|
+
ot(
|
|
4335
|
+
i,
|
|
4336
|
+
(n) => {
|
|
4337
|
+
if (Mt(n)) {
|
|
4338
|
+
const o = F(n);
|
|
4339
|
+
o < e && (e = o), s = !0;
|
|
4340
|
+
}
|
|
4341
|
+
},
|
|
4342
|
+
this.at
|
|
4343
|
+
);
|
|
4344
|
+
else {
|
|
4345
|
+
const n = F(i);
|
|
4346
|
+
n < e && (e = n), s = !0;
|
|
4347
|
+
}
|
|
4348
|
+
}), s ? e : 0;
|
|
4349
|
+
}
|
|
4350
|
+
}
|
|
4351
|
+
const Sr = "Returns the length of a string.";
|
|
4352
|
+
class Rr extends E {
|
|
4353
|
+
constructor() {
|
|
4354
|
+
super(...arguments), this.example = "LEN(A2)", this.description = Sr, this.defs = [
|
|
4355
|
+
{
|
|
4356
|
+
name: "text",
|
|
4357
|
+
description: "A text to be returned the length.",
|
|
4358
|
+
acceptedTypes: ["string", "number"]
|
|
4359
|
+
}
|
|
4360
|
+
], this.category = "text";
|
|
4361
|
+
}
|
|
4362
|
+
main(t) {
|
|
4363
|
+
return X(t).length;
|
|
4364
|
+
}
|
|
4365
|
+
}
|
|
4366
|
+
const _r = "Returns a number with positive and negative values reversed.";
|
|
4367
|
+
class Er extends E {
|
|
4368
|
+
constructor() {
|
|
4369
|
+
super(...arguments), this.example = "UMINUS(4)", this.description = _r, this.defs = [
|
|
4370
|
+
{ name: "value1", description: "A number that will be subtracted.", acceptedTypes: ["number"] }
|
|
4371
|
+
], this.category = "math";
|
|
4372
|
+
}
|
|
4373
|
+
main(t) {
|
|
4374
|
+
return -F(t);
|
|
4375
|
+
}
|
|
4376
|
+
}
|
|
4377
|
+
const Ar = `Enables the display of values returned from an array formula into multiple rows and/or columns.
|
|
4378
|
+
If the argument is already a Spilling, it is returned as-is. If it is a Sheet (range reference), the field matrix is extracted and wrapped in a Spilling. Otherwise the value is wrapped as a single-element Spilling.`;
|
|
4379
|
+
class Cr extends E {
|
|
4380
|
+
constructor() {
|
|
4381
|
+
super(...arguments), this.autoSpilling = !0, this.example = "ARRAYFORMULA(A1:A10 * B1:B10)", this.description = Ar, this.defs = [
|
|
4382
|
+
{
|
|
4383
|
+
name: "value",
|
|
4384
|
+
description: "The array expression or value to evaluate.",
|
|
4385
|
+
takesMatrix: !0,
|
|
4386
|
+
acceptedTypes: ["matrix", "any"]
|
|
4387
|
+
}
|
|
4388
|
+
], this.category = "logical", this.broadcastDisabled = !0;
|
|
4389
|
+
}
|
|
4390
|
+
main(t) {
|
|
4391
|
+
return B.is(t) ? t : t instanceof $ ? t._toValueMatrix() : Array.isArray(t) ? t : [[t]];
|
|
4392
|
+
}
|
|
4393
|
+
}
|
|
4394
|
+
const rs = {
|
|
4395
|
+
// Arithmetic & Comparison
|
|
4396
|
+
add: Ii,
|
|
4397
|
+
minus: Mi,
|
|
4398
|
+
uminus: Er,
|
|
4399
|
+
multiply: Ni,
|
|
4400
|
+
divide: Di,
|
|
4401
|
+
pow: ve,
|
|
4402
|
+
power: ve,
|
|
4403
|
+
concat: $i,
|
|
4404
|
+
eq: Hi,
|
|
4405
|
+
ne: Bi,
|
|
4406
|
+
gt: zi,
|
|
4407
|
+
gte: Wi,
|
|
4408
|
+
lt: ji,
|
|
4409
|
+
lte: Zi,
|
|
4410
|
+
// Logical
|
|
4411
|
+
if: ir,
|
|
4412
|
+
iferror: nr,
|
|
4413
|
+
and: Qi,
|
|
4414
|
+
or: er,
|
|
4415
|
+
not: ar,
|
|
4416
|
+
arrayformula: Cr,
|
|
4417
|
+
// Statistics & Aggregation
|
|
4418
|
+
sum: ki,
|
|
4419
|
+
max: wr,
|
|
4420
|
+
min: br,
|
|
4421
|
+
average: gr,
|
|
4422
|
+
count: lr,
|
|
4423
|
+
counta: pr,
|
|
4424
|
+
// Text
|
|
4425
|
+
len: Rr,
|
|
4426
|
+
// Math
|
|
4427
|
+
abs: ur,
|
|
4428
|
+
// Time
|
|
4429
|
+
now: Ki
|
|
4430
|
+
}, ke = /* @__PURE__ */ new Map(), yn = (r = rs) => {
|
|
4431
|
+
let t = ke.get(r);
|
|
4432
|
+
return t || (t = Object.keys(r).map((e) => {
|
|
4433
|
+
const s = r[e], i = new s({ args: [], sheet: {} });
|
|
4434
|
+
return {
|
|
4435
|
+
name: e.toUpperCase(),
|
|
4436
|
+
category: i.category,
|
|
4437
|
+
example: i.example ?? (s == null ? void 0 : s.__name) ?? "Unknown",
|
|
4438
|
+
description: i.description ?? "",
|
|
4439
|
+
defs: i.defs || []
|
|
4440
|
+
};
|
|
4441
|
+
}), ke.set(r, t)), t;
|
|
4442
|
+
};
|
|
4443
|
+
class Ir {
|
|
4444
|
+
constructor({
|
|
4445
|
+
historyLimit: t,
|
|
4446
|
+
additionalFunctions: e,
|
|
4447
|
+
policies: s = {},
|
|
4448
|
+
onSave: i,
|
|
4449
|
+
onChange: n,
|
|
4450
|
+
onRemoveRows: o,
|
|
4451
|
+
onRemoveCols: a,
|
|
4452
|
+
onInsertRows: l,
|
|
4453
|
+
onInsertCols: u,
|
|
4454
|
+
onSelect: h,
|
|
4455
|
+
onKeyUp: c,
|
|
4456
|
+
onInit: f
|
|
4457
|
+
} = {}) {
|
|
4458
|
+
this.sheetHead = 0, this.cellHead = 0, this.data = {}, this.systems = {}, this.sheetIdsByName = {}, this.contextsBySheetId = {}, this.choosingSheetId = 0, this.choosingAddress = "", this.editingSheetId = 0, this.editingAddress = "", this.paletteBySheetName = {}, this.lastFocused = null, this.solvedCaches = /* @__PURE__ */ new Map(), this.lastSpilledTargetIds = /* @__PURE__ */ new Set(), this.asyncFormulaCells = /* @__PURE__ */ new Set(), this.asyncPending = /* @__PURE__ */ new Map(), this.copyingSheetId = 0, this.copyingZone = gs, this.cutting = !1, this.histories = [], this.historyIndex = -1, this.historyLimit = ps, this._componentSheetIds = /* @__PURE__ */ new Map(), this.ready = !1, this.functions = {}, this.policies = {}, this.transmit = (d) => {
|
|
4459
|
+
}, this.updateSheet = (d) => ({ type: 0, value: d }), t != null && (this.historyLimit = t), this.functions = {
|
|
4460
|
+
...rs,
|
|
4461
|
+
...e
|
|
4462
|
+
};
|
|
4463
|
+
for (const d in this.functions) {
|
|
4464
|
+
const p = this.functions[d];
|
|
4465
|
+
p.__name = d;
|
|
4466
|
+
}
|
|
4467
|
+
this.policies = s, this.onSave = i, this.onChange = n, this.onRemoveRows = o, this.onRemoveCols = a, this.onInsertRows = l, this.onInsertCols = u, this.onSelect = h, this.onKeyUp = c, this.onInit = f;
|
|
4468
|
+
}
|
|
4469
|
+
boot() {
|
|
4470
|
+
if (this.ready || Object.keys(this.contextsBySheetId).length === 0)
|
|
4471
|
+
return;
|
|
4472
|
+
const t = Object.keys(this.contextsBySheetId), e = [];
|
|
4473
|
+
for (let s = 0; s < t.length; s++) {
|
|
4474
|
+
const i = t[s], n = this.contextsBySheetId[i], o = n.store.sheetReactive.current;
|
|
4475
|
+
if (!o || o.status === 0)
|
|
4476
|
+
return;
|
|
4477
|
+
e.push(n);
|
|
4478
|
+
}
|
|
4479
|
+
for (let s = 0; s < e.length; s++) {
|
|
4480
|
+
const { store: i, dispatch: n } = e[s], o = i.sheetReactive.current;
|
|
4481
|
+
o && (o.resolveFormulas(), n(this.updateSheet(o)));
|
|
4482
|
+
}
|
|
4483
|
+
this.ready = !0;
|
|
4484
|
+
}
|
|
4485
|
+
}
|
|
4486
|
+
const ye = (r = {}) => new Ir(r), wn = ye, xn = (r = {}) => ({ registry: ye(r) }), Tr = (r) => ({
|
|
4487
|
+
renderNumber({ value: t }) {
|
|
4488
|
+
if (t == null || isNaN(t))
|
|
4489
|
+
return "NaN";
|
|
4490
|
+
const [e, s] = String(parseFloat(t.toPrecision(this.decimalPrecision))).split("."), i = e.replace(/(\d)(?=(\d\d\d)+(?!\d))/g, `$1${r}`);
|
|
4491
|
+
return s == null ? i : `${i}.${s}`;
|
|
4492
|
+
}
|
|
4493
|
+
}), bn = Tr(","), Sn = {
|
|
4494
|
+
renderNumber({ value: r }) {
|
|
4495
|
+
return r == null || isNaN(r) ? "0%" : `${parseFloat((r * 100).toPrecision(this.decimalPrecision))}%`;
|
|
4496
|
+
}
|
|
4497
|
+
}, Rn = (r, t, e, s) => {
|
|
4498
|
+
if (t != null)
|
|
4499
|
+
return t;
|
|
4500
|
+
const i = r.getPolicy(e);
|
|
4501
|
+
return (e.x === 0 ? i.renderRowHeaderLabel(s) : i.renderColHeaderLabel(s)) ?? null;
|
|
4502
|
+
}, _n = [
|
|
4503
|
+
// orange
|
|
4504
|
+
"#FF6600",
|
|
4505
|
+
// purple
|
|
4506
|
+
"#AA44FF",
|
|
4507
|
+
// emeraldblue
|
|
4508
|
+
"#00CCCC",
|
|
4509
|
+
// peach
|
|
4510
|
+
"#EEAAEE",
|
|
4511
|
+
// yellow
|
|
4512
|
+
"#DDDD00",
|
|
4513
|
+
// winered
|
|
4514
|
+
"#AA4444",
|
|
4515
|
+
// lightgreen
|
|
4516
|
+
"#00FF00",
|
|
4517
|
+
// pink
|
|
4518
|
+
"#FF00FF",
|
|
4519
|
+
// navy
|
|
4520
|
+
"#3366FF",
|
|
4521
|
+
// cyan
|
|
4522
|
+
"#008888"
|
|
4523
|
+
], z = "dashed 1px #888888", Pe = {
|
|
4524
|
+
left: ["horizontal", -1],
|
|
4525
|
+
right: ["horizontal", 1],
|
|
4526
|
+
up: ["vertical", -1],
|
|
4527
|
+
down: ["vertical", 1],
|
|
4528
|
+
none: ["none", 0]
|
|
4529
|
+
};
|
|
4530
|
+
class En {
|
|
4531
|
+
constructor(t, e) {
|
|
4532
|
+
const { sheetReactive: s, choosing: i, selectingZone: n } = t, o = s.current;
|
|
4533
|
+
if (!o)
|
|
4534
|
+
throw new Error("Sheet is not available");
|
|
4535
|
+
this.src = Is(Rs(n), i), this.direction = this.suggestDirection(e), this.dst = this.getDestinationArea(e), this.sheet = o;
|
|
4536
|
+
}
|
|
4537
|
+
get applied() {
|
|
4538
|
+
var f, d;
|
|
4539
|
+
const [t, e] = Pe[this.direction], { top: s, left: i, bottom: n, right: o } = this.src, a = se(n - s + 1, o - i + 1);
|
|
4540
|
+
for (let p = s; p <= n; p++)
|
|
4541
|
+
for (let m = i; m <= o; m++)
|
|
4542
|
+
a[p - s][m - i] = this.sheet.getCell({ y: p, x: m }, { resolution: "SYSTEM" }) ?? null;
|
|
4543
|
+
const l = Kt(this.src), u = Kt(this.dst), h = {};
|
|
4544
|
+
if (t === "horizontal")
|
|
4545
|
+
for (let p = 0; p < u.rows; p++) {
|
|
4546
|
+
const m = this.getChangePatterns(a[p], "");
|
|
4547
|
+
for (let g = 0; g < u.cols; g++) {
|
|
4548
|
+
const y = (f = a[p % l.rows]) == null ? void 0 : f[g % l.cols], R = e > 0 ? this.dst.left + g : this.dst.right - g, A = e > 0 ? g % l.cols : (l.cols - 1 - g % l.cols) % l.cols, w = { y: this.dst.top + p, x: R }, S = this.sheet.getId(w), _ = m[A].next().value, M = (y == null ? void 0 : y.formulaEnabled) ?? !0 ? this.sheet.processFormula(_, {
|
|
4549
|
+
dependency: S
|
|
4550
|
+
}) : _;
|
|
4551
|
+
h[D(w)] = {
|
|
4552
|
+
...y,
|
|
4553
|
+
value: M
|
|
4554
|
+
};
|
|
4555
|
+
}
|
|
4556
|
+
}
|
|
4557
|
+
else if (t === "vertical")
|
|
4558
|
+
for (let p = 0; p < u.cols; p++) {
|
|
4559
|
+
const m = this.getChangePatterns(
|
|
4560
|
+
a.map((g) => g[p]),
|
|
4561
|
+
""
|
|
4562
|
+
);
|
|
4563
|
+
for (let g = 0; g < u.rows; g++) {
|
|
4564
|
+
const y = (d = a[g % l.rows]) == null ? void 0 : d[p % l.cols], R = e > 0 ? this.dst.top + g : this.dst.bottom - g, A = e > 0 ? g % l.rows : (l.rows - 1 - g % l.rows) % l.rows, w = m[A].next().value;
|
|
4565
|
+
h[D({ y: R, x: this.dst.left + p })] = { ...y, value: w };
|
|
4566
|
+
}
|
|
4567
|
+
}
|
|
4568
|
+
return this.sheet.update({
|
|
4569
|
+
diff: h,
|
|
4570
|
+
operator: "USER",
|
|
4571
|
+
undoReflection: {
|
|
4572
|
+
sheetId: this.sheet.id,
|
|
4573
|
+
selectingZone: Ee(this.src)
|
|
4574
|
+
},
|
|
4575
|
+
redoReflection: {
|
|
4576
|
+
sheetId: this.sheet.id,
|
|
4577
|
+
selectingZone: Ee(this.dst)
|
|
4578
|
+
}
|
|
4579
|
+
});
|
|
4580
|
+
}
|
|
4581
|
+
get wholeArea() {
|
|
4582
|
+
return Ss(this.src, this.dst);
|
|
4583
|
+
}
|
|
4584
|
+
getCellStyle(t) {
|
|
4585
|
+
const { x: e, y: s } = t, i = {}, { top: n, left: o, bottom: a, right: l } = this.src;
|
|
4586
|
+
switch (this.direction) {
|
|
4587
|
+
case "left": {
|
|
4588
|
+
this.dst.left <= e && e <= this.dst.right && (n === s && (i.borderTop = z), a === s - 1 && (i.borderTop = z)), this.dst.left === e && n <= s && s <= a && (i.borderLeft = z);
|
|
4589
|
+
break;
|
|
4590
|
+
}
|
|
4591
|
+
case "right": {
|
|
4592
|
+
this.dst.left <= e && e <= this.dst.right && (n === s && (i.borderTop = z), a === s - 1 && (i.borderTop = z)), this.dst.right === e - 1 && n <= s && s <= a && (i.borderLeft = z);
|
|
4593
|
+
break;
|
|
4594
|
+
}
|
|
4595
|
+
case "up": {
|
|
4596
|
+
this.dst.top <= s && s <= this.dst.bottom && (o === e && (i.borderLeft = z), l === e - 1 && (i.borderLeft = z)), this.dst.top === s && o <= e && e <= l && (i.borderTop = z);
|
|
4597
|
+
break;
|
|
4598
|
+
}
|
|
4599
|
+
case "down": {
|
|
4600
|
+
this.dst.top <= s && s <= this.dst.bottom && (o === e && (i.borderLeft = z), l === e - 1 && (i.borderLeft = z)), this.dst.bottom === s - 1 && o <= e && e <= l && (i.borderTop = z);
|
|
4601
|
+
break;
|
|
4602
|
+
}
|
|
4603
|
+
}
|
|
4604
|
+
return i;
|
|
4605
|
+
}
|
|
4606
|
+
getDestinationArea(t) {
|
|
4607
|
+
const { x: e, y: s } = t, { top: i, left: n, bottom: o, right: a } = this.src;
|
|
4608
|
+
switch (this.direction) {
|
|
4609
|
+
case "left":
|
|
4610
|
+
return { top: i, bottom: o, left: e, right: n - 1 };
|
|
4611
|
+
case "right":
|
|
4612
|
+
return { top: i, bottom: o, left: a + 1, right: e };
|
|
4613
|
+
case "up":
|
|
4614
|
+
return { left: n, right: a, top: s, bottom: i - 1 };
|
|
4615
|
+
case "down":
|
|
4616
|
+
return { left: n, right: a, top: o + 1, bottom: s };
|
|
4617
|
+
}
|
|
4618
|
+
return this.src;
|
|
4619
|
+
}
|
|
4620
|
+
suggestDirection(t) {
|
|
4621
|
+
const { top: e, left: s, bottom: i, right: n } = this.src;
|
|
4622
|
+
let o = 0, a = 0;
|
|
4623
|
+
return t.x < s ? o = t.x - s : t.x > n && (o = t.x - n), t.y < e ? a = t.y - e : t.y > i && (a = t.y - i), Math.abs(o) > 0 && Math.abs(a) > 0 ? Math.abs(o) > Math.abs(a) ? o < 0 ? "left" : "right" : a < 0 ? "up" : "down" : o !== 0 ? o < 0 ? "left" : "right" : a !== 0 ? a < 0 ? "up" : "down" : "none";
|
|
4624
|
+
}
|
|
4625
|
+
getChangePatterns(t, e) {
|
|
4626
|
+
const s = [], i = Mr(t), [n, o] = Pe[this.direction];
|
|
4627
|
+
return i.forEach((a) => {
|
|
4628
|
+
const l = o > 0 ? a.last : a.first;
|
|
4629
|
+
switch (a.kind) {
|
|
4630
|
+
case "other": {
|
|
4631
|
+
s.push(st(a.first));
|
|
4632
|
+
return;
|
|
4633
|
+
}
|
|
4634
|
+
case "formula": {
|
|
4635
|
+
const u = a.first, h = this.sheet;
|
|
4636
|
+
function* c() {
|
|
4637
|
+
let f = 0;
|
|
4638
|
+
const d = t.length * o;
|
|
4639
|
+
for (; ; )
|
|
4640
|
+
f += d, yield h.processFormula(u, {
|
|
4641
|
+
dependency: e,
|
|
4642
|
+
slideY: n === "vertical" ? f : 0,
|
|
4643
|
+
slideX: n === "horizontal" ? f : 0
|
|
4644
|
+
});
|
|
4645
|
+
}
|
|
4646
|
+
s.push(c());
|
|
4647
|
+
return;
|
|
4648
|
+
}
|
|
4649
|
+
case "number": {
|
|
4650
|
+
if (!a.equidistant) {
|
|
4651
|
+
s.push(st(a.first), ...a.nexts.map((c) => st(c)));
|
|
4652
|
+
return;
|
|
4653
|
+
}
|
|
4654
|
+
function* u() {
|
|
4655
|
+
let c = l;
|
|
4656
|
+
const f = a.numericDelta * o;
|
|
4657
|
+
for (; ; )
|
|
4658
|
+
c += f, yield c;
|
|
4659
|
+
}
|
|
4660
|
+
const h = u();
|
|
4661
|
+
s.push(h, ...a.nexts.map(() => h));
|
|
4662
|
+
return;
|
|
4663
|
+
}
|
|
4664
|
+
case "date": {
|
|
4665
|
+
const u = (f) => o > 0 ? a.time.add(f) : a.time.sub(f);
|
|
4666
|
+
if (!a.equidistant) {
|
|
4667
|
+
s.push(st(a.first), ...a.nexts.map((f) => st(f)));
|
|
4668
|
+
return;
|
|
4669
|
+
}
|
|
4670
|
+
function* h() {
|
|
4671
|
+
let f = l;
|
|
4672
|
+
for (; ; )
|
|
4673
|
+
f = u(f), yield new Date(f);
|
|
4674
|
+
}
|
|
4675
|
+
const c = h();
|
|
4676
|
+
s.push(c, ...a.nexts.map(() => c));
|
|
4677
|
+
return;
|
|
4678
|
+
}
|
|
4679
|
+
case "string+number": {
|
|
4680
|
+
if (!a.equidistant) {
|
|
4681
|
+
s.push(st(a.first), ...a.nexts.map((c) => st(c)));
|
|
4682
|
+
return;
|
|
4683
|
+
}
|
|
4684
|
+
function* u() {
|
|
4685
|
+
const { prefix: c } = it(a.first), { number: f } = it(l);
|
|
4686
|
+
let d = f;
|
|
4687
|
+
const p = a.numericDelta * o;
|
|
4688
|
+
for (; ; )
|
|
4689
|
+
d += p, yield `${c}${Math.abs(d)}`;
|
|
4690
|
+
}
|
|
4691
|
+
const h = u();
|
|
4692
|
+
s.push(h, ...a.nexts.map(() => h));
|
|
4693
|
+
return;
|
|
4694
|
+
}
|
|
4695
|
+
}
|
|
4696
|
+
}), s;
|
|
4697
|
+
}
|
|
4698
|
+
}
|
|
4699
|
+
function* st(r) {
|
|
4700
|
+
for (; ; )
|
|
4701
|
+
yield r;
|
|
4702
|
+
}
|
|
4703
|
+
const ns = new RegExp("(.+?)(\\d+)$"), it = (r) => {
|
|
4704
|
+
const t = r.match(ns);
|
|
4705
|
+
if (t) {
|
|
4706
|
+
const [, e, s] = t;
|
|
4707
|
+
return { prefix: e, number: Number(s) };
|
|
4708
|
+
}
|
|
4709
|
+
return { prefix: "", number: 0 };
|
|
4710
|
+
};
|
|
4711
|
+
class Ht {
|
|
4712
|
+
constructor(t) {
|
|
4713
|
+
this.time = b.create(), this.numericDelta = 0, this.equidistant = !0, this.first = t, this.nexts = [], this.kind = this.discriminate(t);
|
|
4714
|
+
}
|
|
4715
|
+
discriminate(t) {
|
|
4716
|
+
const e = t instanceof Date ? "date" : typeof t;
|
|
4717
|
+
return e === "number" || e === "date" ? e : e === "string" && t[0] === "=" ? "formula" : e === "string" && t.match(ns) ? "string+number" : "other";
|
|
4718
|
+
}
|
|
4719
|
+
get last() {
|
|
4720
|
+
return this.nexts.length === 0 ? this.first : this.nexts[this.nexts.length - 1];
|
|
4721
|
+
}
|
|
4722
|
+
add(t) {
|
|
4723
|
+
const e = this.discriminate(t);
|
|
4724
|
+
if (this.kind !== e || e === "other" || e === "formula")
|
|
4725
|
+
return new Ht(t);
|
|
4726
|
+
if (this.nexts.length === 0)
|
|
4727
|
+
switch (e) {
|
|
4728
|
+
case "date": {
|
|
4729
|
+
this.time = b.fromDates(t, this.first);
|
|
4730
|
+
break;
|
|
4731
|
+
}
|
|
4732
|
+
case "number": {
|
|
4733
|
+
this.numericDelta = t - this.first;
|
|
4734
|
+
break;
|
|
4735
|
+
}
|
|
4736
|
+
case "string+number": {
|
|
4737
|
+
const { prefix: s, number: i } = it(this.first), { prefix: n, number: o } = it(t);
|
|
4738
|
+
s === n && (this.numericDelta = o - i);
|
|
4739
|
+
break;
|
|
4740
|
+
}
|
|
4741
|
+
}
|
|
4742
|
+
this.nexts.push(t);
|
|
4743
|
+
}
|
|
4744
|
+
subdivide() {
|
|
4745
|
+
if (this.nexts.length === 0)
|
|
4746
|
+
return [];
|
|
4747
|
+
const t = [];
|
|
4748
|
+
let e = this;
|
|
4749
|
+
switch (this.kind) {
|
|
4750
|
+
case "date": {
|
|
4751
|
+
const s = this.nexts.every((i, n) => n === 0 || H(i).isSame(this.time.add(this.nexts[n - 1])));
|
|
4752
|
+
return this.equidistant = s, [];
|
|
4753
|
+
}
|
|
4754
|
+
case "number": {
|
|
4755
|
+
const s = this.nexts.every((i, n) => n === 0 || i === this.first + this.numericDelta * (n + 1));
|
|
4756
|
+
return this.equidistant = s, [];
|
|
4757
|
+
}
|
|
4758
|
+
case "string+number": {
|
|
4759
|
+
const { prefix: s } = it(this.first);
|
|
4760
|
+
for (let i = 0; i < e.nexts.length; i++) {
|
|
4761
|
+
const n = e.nexts[i], { prefix: o, number: a } = it(n);
|
|
4762
|
+
if (s !== o) {
|
|
4763
|
+
const l = this.nexts.splice(i, this.nexts.length);
|
|
4764
|
+
e = new Ht(l.splice(0, 1)[0]), l.forEach(e.add.bind(e)), t.push(e, ...e.subdivide());
|
|
4765
|
+
break;
|
|
4766
|
+
} else {
|
|
4767
|
+
const { number: l } = it(e.first);
|
|
4768
|
+
a !== l + (i + 1) * e.numericDelta && (e.equidistant = !1);
|
|
4769
|
+
}
|
|
4770
|
+
}
|
|
4771
|
+
break;
|
|
4772
|
+
}
|
|
4773
|
+
}
|
|
4774
|
+
return t;
|
|
4775
|
+
}
|
|
4776
|
+
}
|
|
4777
|
+
function Mr(r) {
|
|
4778
|
+
var s, i;
|
|
4779
|
+
let t = new Ht((s = r[0]) == null ? void 0 : s.value);
|
|
4780
|
+
const e = [t];
|
|
4781
|
+
for (let n = 1; n < r.length; n++) {
|
|
4782
|
+
const o = (i = r[n]) == null ? void 0 : i.value, a = t.add(o);
|
|
4783
|
+
a && (e.push(a), t = a);
|
|
4784
|
+
}
|
|
4785
|
+
for (let n = e.length - 1; n >= 0; n--) {
|
|
4786
|
+
const o = e[n];
|
|
4787
|
+
e.splice(n + 1, 0, ...o.subdivide());
|
|
4788
|
+
}
|
|
4789
|
+
return e;
|
|
4790
|
+
}
|
|
4791
|
+
export {
|
|
4792
|
+
En as Autofill,
|
|
4793
|
+
E as BaseFunction,
|
|
4794
|
+
De as BaseFunctionAsync,
|
|
4795
|
+
_n as COLOR_PALETTE,
|
|
4796
|
+
Dt as DEFAULT_COL_KEY,
|
|
4797
|
+
J as DEFAULT_HEIGHT,
|
|
4798
|
+
ps as DEFAULT_HISTORY_LIMIT,
|
|
4799
|
+
vt as DEFAULT_ROW_KEY,
|
|
4800
|
+
jt as DEFAULT_WIDTH,
|
|
4801
|
+
x as FormulaError,
|
|
4802
|
+
nn as FormulaParser,
|
|
4803
|
+
Re as HEADER_HEIGHT,
|
|
4804
|
+
_e as HEADER_WIDTH,
|
|
4805
|
+
$t as Lexer,
|
|
4806
|
+
Pr as MIN_HEIGHT,
|
|
4807
|
+
kr as MIN_WIDTH,
|
|
4808
|
+
$r as OVERSCAN_X,
|
|
4809
|
+
Lr as OVERSCAN_Y,
|
|
4810
|
+
k as Pending,
|
|
4811
|
+
Sn as PercentagePolicyMixin,
|
|
4812
|
+
de as Policy,
|
|
4813
|
+
Be as RangeEntity,
|
|
4814
|
+
Ye as RefEntity,
|
|
4815
|
+
Ir as Registry,
|
|
4816
|
+
Dr as SHEET_HEIGHT,
|
|
4817
|
+
vr as SHEET_WIDTH,
|
|
4818
|
+
$ as Sheet,
|
|
4819
|
+
B as Spilling,
|
|
4820
|
+
bn as ThousandSeparatorPolicyMixin,
|
|
4821
|
+
b as Time,
|
|
4822
|
+
ie as ValueEntity,
|
|
4823
|
+
N as a2p,
|
|
4824
|
+
Zr as aa2oa,
|
|
4825
|
+
tn as addressesToAreas,
|
|
4826
|
+
en as addressesToCols,
|
|
4827
|
+
sn as addressesToRows,
|
|
4828
|
+
Wr as among,
|
|
4829
|
+
Ae as areaDiff,
|
|
4830
|
+
Kt as areaShape,
|
|
4831
|
+
zr as areaToRange,
|
|
4832
|
+
Ee as areaToZone,
|
|
4833
|
+
Vr as between,
|
|
4834
|
+
Qr as binarySearch,
|
|
4835
|
+
Es as buildInitialCells,
|
|
4836
|
+
qr as buildInitialCellsFromOrigin,
|
|
4837
|
+
_t as c2x,
|
|
4838
|
+
Yr as ch,
|
|
4839
|
+
_i as check,
|
|
4840
|
+
Is as complementSelectingArea,
|
|
4841
|
+
Ss as concatAreas,
|
|
4842
|
+
gn as conditionArg,
|
|
4843
|
+
wn as createBinding,
|
|
4844
|
+
xn as createBook,
|
|
4845
|
+
mn as createBooleanMask,
|
|
4846
|
+
se as createMatrix,
|
|
4847
|
+
ye as createRegistry,
|
|
4848
|
+
ot as eachMatrix,
|
|
4849
|
+
Ot as ensureBoolean,
|
|
4850
|
+
Si as ensureDate,
|
|
4851
|
+
F as ensureNumber,
|
|
4852
|
+
X as ensureString,
|
|
4853
|
+
yn as getFunctionHelps,
|
|
4854
|
+
Rn as getLabel,
|
|
4855
|
+
Cs as getMaxSizesFromCells,
|
|
4856
|
+
Le as grantAddressAbsolute,
|
|
4857
|
+
Mt as isNumeric,
|
|
4858
|
+
ge as isPercentage,
|
|
4859
|
+
rn as isZoneNotSelected,
|
|
4860
|
+
jr as makeSequence,
|
|
4861
|
+
Nt as matrixShape,
|
|
4862
|
+
Gr as oa2aa,
|
|
4863
|
+
pn as operations,
|
|
4864
|
+
D as p2a,
|
|
4865
|
+
bs as r2y,
|
|
4866
|
+
Kr as range,
|
|
4867
|
+
Jr as restrictZone,
|
|
4868
|
+
Hr as rh,
|
|
4869
|
+
zs as splitRef,
|
|
4870
|
+
Br as stripAddressAbsolute,
|
|
4871
|
+
Ai as stripMatrix,
|
|
4872
|
+
on as stripSheetName,
|
|
4873
|
+
Ur as superposeArea,
|
|
4874
|
+
fn as toCellCols,
|
|
4875
|
+
hn as toCellMatrix,
|
|
4876
|
+
un as toCellObject,
|
|
4877
|
+
dn as toCellRows,
|
|
4878
|
+
Ws as toSheetPrefix,
|
|
4879
|
+
ln as toValueCols,
|
|
4880
|
+
Vs as toValueMatrix,
|
|
4881
|
+
an as toValueObject,
|
|
4882
|
+
cn as toValueRows,
|
|
4883
|
+
W as x2c,
|
|
4884
|
+
Et as y2r,
|
|
4885
|
+
Xr as zoneShape,
|
|
4886
|
+
Rs as zoneToArea
|
|
4887
|
+
};
|
|
4888
|
+
//# sourceMappingURL=index.js.map
|