@nubisco/ui 5.59.1 → 5.60.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/dist/{Blueprint-CQxC02e5.cjs → Blueprint-B1vqK1QL.cjs} +1 -1
- package/dist/{Blueprint-Dnliv-77.js → Blueprint-CRTuGw8u.js} +1 -1
- package/dist/Spreadsheet-DD0OS-sF.cjs +4 -0
- package/dist/Spreadsheet-DN8_9s4Q.js +2215 -0
- package/dist/all.cjs +1 -1
- package/dist/all.mjs +15 -14
- package/dist/components/Blueprint.cjs +1 -1
- package/dist/components/Blueprint.mjs +1 -1
- package/dist/components/Spreadsheet.cjs +1 -1
- package/dist/components/Spreadsheet.d.ts +98 -2
- package/dist/components/Spreadsheet.mjs +1 -1
- package/dist/components/Spreadsheet.vue.d.ts +23 -2
- package/dist/components/Spreadsheet.vue.d.ts.map +1 -1
- package/dist/components/spreadsheet/sheetLook.d.ts +39 -0
- package/dist/components/spreadsheet/sheetLook.d.ts.map +1 -0
- package/dist/composables/useNbStrings.composable.cjs +1 -1
- package/dist/composables/useNbStrings.composable.d.ts +6 -0
- package/dist/composables/useNbStrings.composable.d.ts.map +1 -1
- package/dist/composables/useNbStrings.composable.mjs +4 -0
- package/dist/formula/criteria.d.ts +15 -0
- package/dist/formula/criteria.d.ts.map +1 -0
- package/dist/formula/evaluator.d.ts +11 -0
- package/dist/formula/evaluator.d.ts.map +1 -0
- package/dist/formula/functions/define.d.ts +16 -0
- package/dist/formula/functions/define.d.ts.map +1 -0
- package/dist/formula/functions/index.d.ts +9 -0
- package/dist/formula/functions/index.d.ts.map +1 -0
- package/dist/formula/functions/information.d.ts +3 -0
- package/dist/formula/functions/information.d.ts.map +1 -0
- package/dist/formula/functions/logical.d.ts +3 -0
- package/dist/formula/functions/logical.d.ts.map +1 -0
- package/dist/formula/functions/lookup.d.ts +3 -0
- package/dist/formula/functions/lookup.d.ts.map +1 -0
- package/dist/formula/functions/math.d.ts +13 -0
- package/dist/formula/functions/math.d.ts.map +1 -0
- package/dist/formula/functions/statistical.d.ts +3 -0
- package/dist/formula/functions/statistical.d.ts.map +1 -0
- package/dist/formula/functions/text.d.ts +3 -0
- package/dist/formula/functions/text.d.ts.map +1 -0
- package/dist/formula/index.cjs +1 -0
- package/dist/formula/index.d.ts +13 -0
- package/dist/formula/index.d.ts.map +1 -0
- package/dist/formula/index.mjs +2 -0
- package/dist/formula/parser.d.ts +10 -0
- package/dist/formula/parser.d.ts.map +1 -0
- package/dist/formula/references.d.ts +14 -0
- package/dist/formula/references.d.ts.map +1 -0
- package/dist/formula/refs.d.ts +20 -0
- package/dist/formula/refs.d.ts.map +1 -0
- package/dist/formula/sheet.d.ts +10 -0
- package/dist/formula/sheet.d.ts.map +1 -0
- package/dist/formula/syntax.d.ts +14 -0
- package/dist/formula/syntax.d.ts.map +1 -0
- package/dist/formula/tokenizer.d.ts +11 -0
- package/dist/formula/tokenizer.d.ts.map +1 -0
- package/dist/formula/types.d.ts +150 -0
- package/dist/formula/types.d.ts.map +1 -0
- package/dist/formula/values.d.ts +46 -0
- package/dist/formula/values.d.ts.map +1 -0
- package/dist/formula-Bic1LaPK.js +1969 -0
- package/dist/formula-CoCixvl3.cjs +1 -0
- package/dist/index.cjs +1 -1
- package/dist/index.mjs +9 -8
- package/dist/{main-I6bzKhGk.cjs → main-vJqUlyCN.cjs} +1 -1
- package/dist/{main-zCF9LQQU.js → main-wtHGDDYS.js} +1 -1
- package/dist/main.d.ts +2 -1
- package/dist/main.d.ts.map +1 -1
- package/dist/styles/Spreadsheet.css +1 -1
- package/dist/ui.css +1 -1
- package/dist/utils/csv.helper.cjs +5 -0
- package/dist/utils/csv.helper.d.ts +22 -0
- package/dist/utils/csv.helper.d.ts.map +1 -0
- package/dist/utils/csv.helper.mjs +46 -0
- package/package.json +7 -1
- package/src/utils/csv.helper.ts +96 -0
- package/dist/Spreadsheet-BwGhq9vm.cjs +0 -4
- package/dist/Spreadsheet-C9MeO5MD.js +0 -1455
- /package/dist/{pixi-scene-D1jzgzHL.js → pixi-scene-CShpsLDx.js} +0 -0
- /package/dist/{pixi-scene-BGTSD1-G.cjs → pixi-scene-OJo1IXN4.cjs} +0 -0
|
@@ -0,0 +1,1969 @@
|
|
|
1
|
+
//#region src/formula/refs.ts
|
|
2
|
+
function e(e) {
|
|
3
|
+
let t = "", n = Math.floor(e) + 1;
|
|
4
|
+
for (; n > 0;) {
|
|
5
|
+
let e = (n - 1) % 26;
|
|
6
|
+
t = String.fromCharCode(65 + e) + t, n = Math.floor((n - 1) / 26);
|
|
7
|
+
}
|
|
8
|
+
return t;
|
|
9
|
+
}
|
|
10
|
+
function t(e) {
|
|
11
|
+
if (!/^[A-Za-z]+$/.test(e)) return -1;
|
|
12
|
+
let t = 0;
|
|
13
|
+
for (let n of e.toUpperCase()) t = t * 26 + (n.charCodeAt(0) - 64);
|
|
14
|
+
return t - 1;
|
|
15
|
+
}
|
|
16
|
+
var n = /^\$?([A-Za-z]{1,3})\$?([1-9][0-9]*)$/;
|
|
17
|
+
function r(e) {
|
|
18
|
+
let r = n.exec(e);
|
|
19
|
+
return r ? {
|
|
20
|
+
row: Number(r[2]) - 1,
|
|
21
|
+
col: t(r[1])
|
|
22
|
+
} : null;
|
|
23
|
+
}
|
|
24
|
+
function i(t, n) {
|
|
25
|
+
return e(n) + String(t + 1);
|
|
26
|
+
}
|
|
27
|
+
function a(e) {
|
|
28
|
+
let n = e.split(":");
|
|
29
|
+
if (n.length !== 2) return null;
|
|
30
|
+
let [i, a] = n, s = r(i), c = r(a);
|
|
31
|
+
if (s && c) return o(s.row, s.col, c.row, c.col);
|
|
32
|
+
let l = /^\$?([A-Za-z]{1,3})$/.exec(i), u = /^\$?([A-Za-z]{1,3})$/.exec(a);
|
|
33
|
+
if (l && u) {
|
|
34
|
+
let e = t(l[1]), n = t(u[1]);
|
|
35
|
+
return {
|
|
36
|
+
r1: 0,
|
|
37
|
+
r2: Infinity,
|
|
38
|
+
c1: Math.min(e, n),
|
|
39
|
+
c2: Math.max(e, n)
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
let d = /^\$?([1-9][0-9]*)$/.exec(i), f = /^\$?([1-9][0-9]*)$/.exec(a);
|
|
43
|
+
if (d && f) {
|
|
44
|
+
let e = Number(d[1]) - 1, t = Number(f[1]) - 1;
|
|
45
|
+
return {
|
|
46
|
+
r1: Math.min(e, t),
|
|
47
|
+
r2: Math.max(e, t),
|
|
48
|
+
c1: 0,
|
|
49
|
+
c2: Infinity
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
return null;
|
|
53
|
+
}
|
|
54
|
+
function o(e, t, n, r) {
|
|
55
|
+
return {
|
|
56
|
+
r1: Math.min(e, n),
|
|
57
|
+
r2: Math.max(e, n),
|
|
58
|
+
c1: Math.min(t, r),
|
|
59
|
+
c2: Math.max(t, r)
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
//#endregion
|
|
63
|
+
//#region src/formula/tokenizer.ts
|
|
64
|
+
var s = Object.freeze({
|
|
65
|
+
decimal: ".",
|
|
66
|
+
separator: ","
|
|
67
|
+
}), c = [
|
|
68
|
+
"#DIV/0!",
|
|
69
|
+
"#VALUE!",
|
|
70
|
+
"#REF!",
|
|
71
|
+
"#NAME?",
|
|
72
|
+
"#N/A",
|
|
73
|
+
"#NUM!",
|
|
74
|
+
"#NULL!",
|
|
75
|
+
"#ERROR!"
|
|
76
|
+
], l = "(?![A-Za-z0-9_.$(])", u = RegExp(`^\\$?[A-Za-z]{1,3}\\$?[1-9][0-9]*:\\$?[A-Za-z]{1,3}\\$?[1-9][0-9]*${l}`), d = RegExp(`^\\$?[A-Za-z]{1,3}:\\$?[A-Za-z]{1,3}${l}`), f = RegExp(`^\\$?[1-9][0-9]*:\\$?[1-9][0-9]*${l}`), p = RegExp(`^\\$?[A-Za-z]{1,3}\\$?[1-9][0-9]*${l}`), m = /^[A-Za-z_][A-Za-z0-9_.]*/, h = /^\s+/, ee = [
|
|
77
|
+
"<>",
|
|
78
|
+
"<=",
|
|
79
|
+
">=",
|
|
80
|
+
"+",
|
|
81
|
+
"-",
|
|
82
|
+
"*",
|
|
83
|
+
"/",
|
|
84
|
+
"^",
|
|
85
|
+
"&",
|
|
86
|
+
"%",
|
|
87
|
+
"=",
|
|
88
|
+
"<",
|
|
89
|
+
">",
|
|
90
|
+
":"
|
|
91
|
+
];
|
|
92
|
+
function te(e) {
|
|
93
|
+
let t = e === "." ? "\\." : ",";
|
|
94
|
+
return RegExp(`^(?:[0-9]+(?:${t}[0-9]*)?|${t}[0-9]+)(?:[eE][+-]?[0-9]+)?`);
|
|
95
|
+
}
|
|
96
|
+
var ne = {
|
|
97
|
+
".": te("."),
|
|
98
|
+
",": te(",")
|
|
99
|
+
};
|
|
100
|
+
function g(e, t = s) {
|
|
101
|
+
let n = [], r = ne[t.decimal] ?? ne["."], i = 0, a = (t, r) => {
|
|
102
|
+
n.push({
|
|
103
|
+
type: t,
|
|
104
|
+
text: e.slice(i, i + r),
|
|
105
|
+
start: i,
|
|
106
|
+
end: i + r
|
|
107
|
+
}), i += r;
|
|
108
|
+
};
|
|
109
|
+
for (; i < e.length;) {
|
|
110
|
+
let n = e.slice(i), o = n[0], s;
|
|
111
|
+
if (s = h.exec(n)) a("whitespace", s[0].length);
|
|
112
|
+
else if (o === "\"") {
|
|
113
|
+
let e = 1, t = !1;
|
|
114
|
+
for (; e < n.length;) if (n[e] === "\"") if (n[e + 1] === "\"") e += 2;
|
|
115
|
+
else {
|
|
116
|
+
t = !0, e++;
|
|
117
|
+
break;
|
|
118
|
+
}
|
|
119
|
+
else e++;
|
|
120
|
+
a(t ? "string" : "invalid", e);
|
|
121
|
+
} else if (o === "#") {
|
|
122
|
+
let e = n.toUpperCase(), t = c.find((t) => e.startsWith(t));
|
|
123
|
+
a(t ? "error" : "invalid", t ? t.length : 1);
|
|
124
|
+
} else if (s = f.exec(n)) a("range", s[0].length);
|
|
125
|
+
else if (s = r.exec(n)) a("number", s[0].length);
|
|
126
|
+
else if ((s = u.exec(n)) || (s = d.exec(n))) a("range", s[0].length);
|
|
127
|
+
else if (s = p.exec(n)) a("reference", s[0].length);
|
|
128
|
+
else if (s = m.exec(n)) {
|
|
129
|
+
let t = s[0], n = e[i + t.length], r = t.toUpperCase();
|
|
130
|
+
a(n === "(" ? "function" : r === "TRUE" || r === "FALSE" ? "boolean" : "name", t.length);
|
|
131
|
+
} else if (o === "(" || o === ")") a("paren", 1);
|
|
132
|
+
else if (o === t.separator) a("separator", 1);
|
|
133
|
+
else {
|
|
134
|
+
let e = ee.find((e) => n.startsWith(e));
|
|
135
|
+
a(e ? "operator" : "invalid", e ? e.length : 1);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
return n;
|
|
139
|
+
}
|
|
140
|
+
//#endregion
|
|
141
|
+
//#region src/formula/values.ts
|
|
142
|
+
var re = {
|
|
143
|
+
"#DIV/0!": "Division by zero",
|
|
144
|
+
"#VALUE!": "Wrong type of value",
|
|
145
|
+
"#REF!": "Invalid reference",
|
|
146
|
+
"#NAME?": "Unknown name",
|
|
147
|
+
"#N/A": "Value not available",
|
|
148
|
+
"#NUM!": "Invalid number",
|
|
149
|
+
"#NULL!": "Empty intersection",
|
|
150
|
+
"#ERROR!": "Formula could not be read"
|
|
151
|
+
};
|
|
152
|
+
function _(e, t) {
|
|
153
|
+
return {
|
|
154
|
+
error: e,
|
|
155
|
+
message: t ?? re[e]
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
function ie(e) {
|
|
159
|
+
return typeof e == "string" && e.length > 1 && e[0] === "=";
|
|
160
|
+
}
|
|
161
|
+
function v(e) {
|
|
162
|
+
return typeof e == "object" && !!e && "error" in e && c.includes(e.error);
|
|
163
|
+
}
|
|
164
|
+
function y(e) {
|
|
165
|
+
return typeof e == "object" && !!e && e.kind === "matrix";
|
|
166
|
+
}
|
|
167
|
+
function b(e, t, n) {
|
|
168
|
+
return {
|
|
169
|
+
kind: "matrix",
|
|
170
|
+
rows: e,
|
|
171
|
+
cols: t,
|
|
172
|
+
get: (e, r) => n[e * t + r] ?? null
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
function ae(e, t) {
|
|
176
|
+
let n = t.r2 === Infinity ? e.extent.rows - 1 : t.r2, r = t.c2 === Infinity ? e.extent.cols - 1 : t.c2, { r1: i, c1: a } = t;
|
|
177
|
+
return {
|
|
178
|
+
kind: "matrix",
|
|
179
|
+
rows: Math.max(0, n - i + 1),
|
|
180
|
+
cols: Math.max(0, r - a + 1),
|
|
181
|
+
get: (t, n) => e.cell(i + t, a + n),
|
|
182
|
+
origin: {
|
|
183
|
+
row: i,
|
|
184
|
+
col: a
|
|
185
|
+
}
|
|
186
|
+
};
|
|
187
|
+
}
|
|
188
|
+
function x(e) {
|
|
189
|
+
return y(e) ? e : b(1, 1, [e]);
|
|
190
|
+
}
|
|
191
|
+
function S(e, t) {
|
|
192
|
+
for (let n = 0; n < e.rows; n++) for (let r = 0; r < e.cols; r++) if (t(e.get(n, r), n, r) === !0) return;
|
|
193
|
+
}
|
|
194
|
+
function C(e) {
|
|
195
|
+
return y(e) ? e.rows === 1 && e.cols === 1 ? e.get(0, 0) : _("#VALUE!", "A range cannot be used as a single value") : e;
|
|
196
|
+
}
|
|
197
|
+
var oe = /^[+-]?(?:[0-9]+(?:\.[0-9]*)?|\.[0-9]+)(?:[eE][+-]?[0-9]+)?%?$/;
|
|
198
|
+
function w(e) {
|
|
199
|
+
let t = e.trim();
|
|
200
|
+
return oe.test(t) ? t.endsWith("%") ? Number(t.slice(0, -1)) / 100 : Number(t) : null;
|
|
201
|
+
}
|
|
202
|
+
function T(e) {
|
|
203
|
+
if (e === null) return 0;
|
|
204
|
+
if (typeof e == "number") return e;
|
|
205
|
+
if (typeof e == "boolean") return e ? 1 : 0;
|
|
206
|
+
if (typeof e == "string") {
|
|
207
|
+
let t = w(e);
|
|
208
|
+
return t === null ? _("#VALUE!", "Text cannot be used as a number") : t;
|
|
209
|
+
}
|
|
210
|
+
return e;
|
|
211
|
+
}
|
|
212
|
+
function se(e) {
|
|
213
|
+
return Number.isInteger(e) && Math.abs(e) < 1e21 ? String(e) : String(Number(e.toPrecision(15))).toUpperCase();
|
|
214
|
+
}
|
|
215
|
+
function E(e) {
|
|
216
|
+
return e === null ? "" : typeof e == "string" ? e : typeof e == "number" ? se(e) : typeof e == "boolean" ? e ? "TRUE" : "FALSE" : e;
|
|
217
|
+
}
|
|
218
|
+
function D(e) {
|
|
219
|
+
if (e === null) return !1;
|
|
220
|
+
if (typeof e == "boolean") return e;
|
|
221
|
+
if (typeof e == "number") return e !== 0;
|
|
222
|
+
if (typeof e == "string") {
|
|
223
|
+
let t = e.toUpperCase();
|
|
224
|
+
return t === "TRUE" ? !0 : t === "FALSE" ? !1 : _("#VALUE!", "Text cannot be used as TRUE or FALSE");
|
|
225
|
+
}
|
|
226
|
+
return e;
|
|
227
|
+
}
|
|
228
|
+
var O = (e) => T(C(e)), k = (e) => E(C(e)), A = (e) => D(C(e));
|
|
229
|
+
function j(e, t, n) {
|
|
230
|
+
let r = e[t];
|
|
231
|
+
return r == null ? n : O(r);
|
|
232
|
+
}
|
|
233
|
+
function ce(e) {
|
|
234
|
+
return typeof e == "number" ? 0 : typeof e == "string" ? 1 : 2;
|
|
235
|
+
}
|
|
236
|
+
function M(e, t) {
|
|
237
|
+
if (e === null && t === null) return 0;
|
|
238
|
+
let n = (e) => typeof e == "number" ? 0 : typeof e == "string" ? "" : !1, r = e === null ? n(t) : e, i = t === null ? n(r) : t, a = ce(r) - ce(i);
|
|
239
|
+
if (a !== 0) return Math.sign(a);
|
|
240
|
+
if (typeof r == "string") {
|
|
241
|
+
let e = r.toLowerCase(), t = i.toLowerCase();
|
|
242
|
+
return e < t ? -1 : e > t ? 1 : 0;
|
|
243
|
+
}
|
|
244
|
+
return Math.sign(Number(r) - Number(i));
|
|
245
|
+
}
|
|
246
|
+
function N(e) {
|
|
247
|
+
let t = [];
|
|
248
|
+
for (let n of e) if (y(n)) {
|
|
249
|
+
let e = null;
|
|
250
|
+
if (S(n, (n) => {
|
|
251
|
+
if (typeof n == "number") t.push(n);
|
|
252
|
+
else if (v(n)) return e = n, !0;
|
|
253
|
+
}), e) return e;
|
|
254
|
+
} else if (n !== null) {
|
|
255
|
+
let e = T(n);
|
|
256
|
+
if (v(e)) return e;
|
|
257
|
+
t.push(e);
|
|
258
|
+
}
|
|
259
|
+
return t;
|
|
260
|
+
}
|
|
261
|
+
function le(e) {
|
|
262
|
+
return typeof e == "number" && !Number.isFinite(e) ? _("#NUM!", "The result is not a finite number") : e;
|
|
263
|
+
}
|
|
264
|
+
//#endregion
|
|
265
|
+
//#region src/formula/syntax.ts
|
|
266
|
+
function ue(e) {
|
|
267
|
+
try {
|
|
268
|
+
if (new Intl.NumberFormat(e).formatToParts(1.5).find((e) => e.type === "decimal")?.value === ",") return {
|
|
269
|
+
decimal: ",",
|
|
270
|
+
separator: ";"
|
|
271
|
+
};
|
|
272
|
+
} catch {}
|
|
273
|
+
return { ...s };
|
|
274
|
+
}
|
|
275
|
+
function de(e, t, n) {
|
|
276
|
+
return t.decimal === n.decimal && t.separator === n.separator ? e : g(e, t).map((e) => e.type === "number" ? e.text.replace(t.decimal, n.decimal) : e.type === "separator" ? n.separator : e.text).join("");
|
|
277
|
+
}
|
|
278
|
+
function fe(e, t) {
|
|
279
|
+
return de(e, t, s);
|
|
280
|
+
}
|
|
281
|
+
function pe(e, t) {
|
|
282
|
+
return de(e, s, t);
|
|
283
|
+
}
|
|
284
|
+
//#endregion
|
|
285
|
+
//#region src/formula/references.ts
|
|
286
|
+
function me(e, t = s) {
|
|
287
|
+
let n = [];
|
|
288
|
+
for (let i of g(e, t)) if (i.type === "reference") {
|
|
289
|
+
let e = r(i.text);
|
|
290
|
+
if (!e) continue;
|
|
291
|
+
n.push({
|
|
292
|
+
start: i.start,
|
|
293
|
+
end: i.end,
|
|
294
|
+
text: i.text,
|
|
295
|
+
range: {
|
|
296
|
+
r1: e.row,
|
|
297
|
+
c1: e.col,
|
|
298
|
+
r2: e.row,
|
|
299
|
+
c2: e.col
|
|
300
|
+
}
|
|
301
|
+
});
|
|
302
|
+
} else if (i.type === "range") {
|
|
303
|
+
let e = a(i.text);
|
|
304
|
+
e && n.push({
|
|
305
|
+
start: i.start,
|
|
306
|
+
end: i.end,
|
|
307
|
+
text: i.text,
|
|
308
|
+
range: e
|
|
309
|
+
});
|
|
310
|
+
}
|
|
311
|
+
return n;
|
|
312
|
+
}
|
|
313
|
+
var he = /^(\$?)([A-Za-z]{1,3})?(\$?)([1-9][0-9]*)?$/;
|
|
314
|
+
function ge(e) {
|
|
315
|
+
let n = he.exec(e);
|
|
316
|
+
if (!n || !n[2] && !n[4]) return null;
|
|
317
|
+
let r = {};
|
|
318
|
+
if (n[2] && (r.col = {
|
|
319
|
+
index: t(n[2]),
|
|
320
|
+
absolute: n[1] === "$"
|
|
321
|
+
}), n[4]) {
|
|
322
|
+
let e = n[2] ? n[3] === "$" : n[1] === "$" || n[3] === "$";
|
|
323
|
+
r.row = {
|
|
324
|
+
index: Number(n[4]) - 1,
|
|
325
|
+
absolute: e
|
|
326
|
+
};
|
|
327
|
+
}
|
|
328
|
+
return r;
|
|
329
|
+
}
|
|
330
|
+
function _e(t) {
|
|
331
|
+
let n = "";
|
|
332
|
+
return t.col && (n += (t.col.absolute ? "$" : "") + e(t.col.index)), t.row && (n += (t.row.absolute ? "$" : "") + String(t.row.index + 1)), n;
|
|
333
|
+
}
|
|
334
|
+
function ve(e, t, n) {
|
|
335
|
+
return e.col && !e.col.absolute && (e.col.index += n), e.row && !e.row.absolute && (e.row.index += t), (!e.col || e.col.index >= 0) && (!e.row || e.row.index >= 0);
|
|
336
|
+
}
|
|
337
|
+
function ye(e, t, n) {
|
|
338
|
+
let r = e.split(":").map(ge);
|
|
339
|
+
if (r.some((e) => e === null)) return e;
|
|
340
|
+
let i = r;
|
|
341
|
+
for (let e of i) if (!ve(e, t, n)) return "#REF!";
|
|
342
|
+
if (i.length === 2) {
|
|
343
|
+
let [e, t] = i;
|
|
344
|
+
e.row && t.row && e.row.index > t.row.index && ([e.row, t.row] = [t.row, e.row]), e.col && t.col && e.col.index > t.col.index && ([e.col, t.col] = [t.col, e.col]);
|
|
345
|
+
}
|
|
346
|
+
return i.map(_e).join(":");
|
|
347
|
+
}
|
|
348
|
+
function be(e, t, n) {
|
|
349
|
+
return t === 0 && n === 0 ? e : g(e).map((e) => e.type === "reference" || e.type === "range" ? ye(e.text, t, n) : e.text).join("");
|
|
350
|
+
}
|
|
351
|
+
//#endregion
|
|
352
|
+
//#region src/formula/functions/information.ts
|
|
353
|
+
var P = (e) => (t) => {
|
|
354
|
+
let n = t[0];
|
|
355
|
+
return y(n) && n.rows * n.cols !== 1 ? _("#VALUE!", "A range cannot be used as a single value") : e(C(n));
|
|
356
|
+
}, xe = [
|
|
357
|
+
{
|
|
358
|
+
name: "ISBLANK",
|
|
359
|
+
category: "information",
|
|
360
|
+
syntax: "ISBLANK(value)",
|
|
361
|
+
description: "Returns TRUE when a cell is empty.",
|
|
362
|
+
minArgs: 1,
|
|
363
|
+
maxArgs: 1,
|
|
364
|
+
call: P((e) => e === null)
|
|
365
|
+
},
|
|
366
|
+
{
|
|
367
|
+
name: "ISNUMBER",
|
|
368
|
+
category: "information",
|
|
369
|
+
syntax: "ISNUMBER(value)",
|
|
370
|
+
description: "Returns TRUE when a value is a number.",
|
|
371
|
+
minArgs: 1,
|
|
372
|
+
maxArgs: 1,
|
|
373
|
+
call: P((e) => typeof e == "number")
|
|
374
|
+
},
|
|
375
|
+
{
|
|
376
|
+
name: "ISTEXT",
|
|
377
|
+
category: "information",
|
|
378
|
+
syntax: "ISTEXT(value)",
|
|
379
|
+
description: "Returns TRUE when a value is text.",
|
|
380
|
+
minArgs: 1,
|
|
381
|
+
maxArgs: 1,
|
|
382
|
+
call: P((e) => typeof e == "string")
|
|
383
|
+
},
|
|
384
|
+
{
|
|
385
|
+
name: "ISLOGICAL",
|
|
386
|
+
category: "information",
|
|
387
|
+
syntax: "ISLOGICAL(value)",
|
|
388
|
+
description: "Returns TRUE when a value is TRUE or FALSE.",
|
|
389
|
+
minArgs: 1,
|
|
390
|
+
maxArgs: 1,
|
|
391
|
+
call: P((e) => typeof e == "boolean")
|
|
392
|
+
},
|
|
393
|
+
{
|
|
394
|
+
name: "ISERROR",
|
|
395
|
+
category: "information",
|
|
396
|
+
syntax: "ISERROR(value)",
|
|
397
|
+
description: "Returns TRUE when a value is any error.",
|
|
398
|
+
minArgs: 1,
|
|
399
|
+
maxArgs: 1,
|
|
400
|
+
call: P((e) => v(e))
|
|
401
|
+
},
|
|
402
|
+
{
|
|
403
|
+
name: "ISNA",
|
|
404
|
+
category: "information",
|
|
405
|
+
syntax: "ISNA(value)",
|
|
406
|
+
description: "Returns TRUE when a value is the #N/A error.",
|
|
407
|
+
minArgs: 1,
|
|
408
|
+
maxArgs: 1,
|
|
409
|
+
call: P((e) => v(e) && e.error === "#N/A")
|
|
410
|
+
},
|
|
411
|
+
{
|
|
412
|
+
name: "NA",
|
|
413
|
+
category: "information",
|
|
414
|
+
syntax: "NA()",
|
|
415
|
+
description: "Returns the #N/A error, for a value that is not available.",
|
|
416
|
+
minArgs: 0,
|
|
417
|
+
maxArgs: 0,
|
|
418
|
+
call: () => _("#N/A")
|
|
419
|
+
}
|
|
420
|
+
];
|
|
421
|
+
//#endregion
|
|
422
|
+
//#region src/formula/functions/logical.ts
|
|
423
|
+
function Se(e) {
|
|
424
|
+
let t = [];
|
|
425
|
+
for (let n of e) if (y(n)) {
|
|
426
|
+
let e = null;
|
|
427
|
+
if (S(n, (n) => {
|
|
428
|
+
if (v(n)) return e = n, !0;
|
|
429
|
+
(typeof n == "boolean" || typeof n == "number") && t.push(D(n));
|
|
430
|
+
}), e) return e;
|
|
431
|
+
} else if (n !== null) {
|
|
432
|
+
let e = D(n);
|
|
433
|
+
if (v(e)) return e;
|
|
434
|
+
t.push(e);
|
|
435
|
+
}
|
|
436
|
+
return t.length === 0 ? _("#VALUE!", "There are no logical values") : t;
|
|
437
|
+
}
|
|
438
|
+
var F = (e) => (t) => {
|
|
439
|
+
let n = Se(t);
|
|
440
|
+
return v(n) ? n : e(n);
|
|
441
|
+
};
|
|
442
|
+
function Ce(e) {
|
|
443
|
+
let t = y(e) && e.rows * e.cols === 1 ? e.get(0, 0) : e;
|
|
444
|
+
return v(t) ? t : null;
|
|
445
|
+
}
|
|
446
|
+
var we = [
|
|
447
|
+
{
|
|
448
|
+
name: "IF",
|
|
449
|
+
category: "logical",
|
|
450
|
+
syntax: "IF(condition, [value_if_true], [value_if_false])",
|
|
451
|
+
description: "Returns one value when a condition is true and another when it is false.",
|
|
452
|
+
minArgs: 2,
|
|
453
|
+
maxArgs: 3,
|
|
454
|
+
lazy: (e, t, n) => {
|
|
455
|
+
let r = A(n(e[0]));
|
|
456
|
+
return v(r) ? r : r ? n(e[1]) : e[2] === void 0 ? !1 : n(e[2]);
|
|
457
|
+
}
|
|
458
|
+
},
|
|
459
|
+
{
|
|
460
|
+
name: "IFS",
|
|
461
|
+
category: "logical",
|
|
462
|
+
syntax: "IFS(condition1, value1, [condition2, value2, ...])",
|
|
463
|
+
description: "Returns the value paired with the first condition that is true.",
|
|
464
|
+
minArgs: 2,
|
|
465
|
+
maxArgs: Infinity,
|
|
466
|
+
lazy: (e, t, n) => {
|
|
467
|
+
if (e.length % 2 != 0) return _("#N/A", "IFS expects conditions and values in pairs");
|
|
468
|
+
for (let t = 0; t < e.length; t += 2) {
|
|
469
|
+
let r = A(n(e[t]));
|
|
470
|
+
if (v(r)) return r;
|
|
471
|
+
if (r) return n(e[t + 1]);
|
|
472
|
+
}
|
|
473
|
+
return _("#N/A", "No condition was true");
|
|
474
|
+
}
|
|
475
|
+
},
|
|
476
|
+
{
|
|
477
|
+
name: "IFERROR",
|
|
478
|
+
category: "logical",
|
|
479
|
+
syntax: "IFERROR(value, value_if_error)",
|
|
480
|
+
description: "Returns a value, or a fallback when the value is any error.",
|
|
481
|
+
minArgs: 2,
|
|
482
|
+
maxArgs: 2,
|
|
483
|
+
lazy: (e, t, n) => {
|
|
484
|
+
let r = n(e[0]);
|
|
485
|
+
return Ce(r) ? n(e[1]) : r;
|
|
486
|
+
}
|
|
487
|
+
},
|
|
488
|
+
{
|
|
489
|
+
name: "IFNA",
|
|
490
|
+
category: "logical",
|
|
491
|
+
syntax: "IFNA(value, value_if_na)",
|
|
492
|
+
description: "Returns a value, or a fallback when the value is #N/A.",
|
|
493
|
+
minArgs: 2,
|
|
494
|
+
maxArgs: 2,
|
|
495
|
+
lazy: (e, t, n) => {
|
|
496
|
+
let r = n(e[0]);
|
|
497
|
+
return Ce(r)?.error === "#N/A" ? n(e[1]) : r;
|
|
498
|
+
}
|
|
499
|
+
},
|
|
500
|
+
{
|
|
501
|
+
name: "AND",
|
|
502
|
+
category: "logical",
|
|
503
|
+
syntax: "AND(value1, [value2, ...])",
|
|
504
|
+
description: "Returns TRUE when every value is true.",
|
|
505
|
+
minArgs: 1,
|
|
506
|
+
maxArgs: Infinity,
|
|
507
|
+
call: F((e) => e.every(Boolean))
|
|
508
|
+
},
|
|
509
|
+
{
|
|
510
|
+
name: "OR",
|
|
511
|
+
category: "logical",
|
|
512
|
+
syntax: "OR(value1, [value2, ...])",
|
|
513
|
+
description: "Returns TRUE when at least one value is true.",
|
|
514
|
+
minArgs: 1,
|
|
515
|
+
maxArgs: Infinity,
|
|
516
|
+
call: F((e) => e.some(Boolean))
|
|
517
|
+
},
|
|
518
|
+
{
|
|
519
|
+
name: "XOR",
|
|
520
|
+
category: "logical",
|
|
521
|
+
syntax: "XOR(value1, [value2, ...])",
|
|
522
|
+
description: "Returns TRUE when an odd number of values are true.",
|
|
523
|
+
minArgs: 1,
|
|
524
|
+
maxArgs: Infinity,
|
|
525
|
+
call: F((e) => e.filter(Boolean).length % 2 == 1)
|
|
526
|
+
},
|
|
527
|
+
{
|
|
528
|
+
name: "NOT",
|
|
529
|
+
category: "logical",
|
|
530
|
+
syntax: "NOT(value)",
|
|
531
|
+
description: "Returns the opposite of a logical value.",
|
|
532
|
+
minArgs: 1,
|
|
533
|
+
maxArgs: 1,
|
|
534
|
+
call: (e) => {
|
|
535
|
+
let t = A(e[0]);
|
|
536
|
+
return v(t) ? t : !t;
|
|
537
|
+
}
|
|
538
|
+
},
|
|
539
|
+
{
|
|
540
|
+
name: "SWITCH",
|
|
541
|
+
category: "logical",
|
|
542
|
+
syntax: "SWITCH(expression, case1, value1, [case2, value2, ...], [default])",
|
|
543
|
+
description: "Compares a value with a list of cases and returns the value of the first match.",
|
|
544
|
+
minArgs: 3,
|
|
545
|
+
maxArgs: Infinity,
|
|
546
|
+
lazy: (e, t, n) => {
|
|
547
|
+
let r = C(n(e[0]));
|
|
548
|
+
if (v(r)) return r;
|
|
549
|
+
let i = Math.floor((e.length - 1) / 2);
|
|
550
|
+
for (let t = 0; t < i; t++) {
|
|
551
|
+
let i = C(n(e[1 + t * 2]));
|
|
552
|
+
if (v(i)) return i;
|
|
553
|
+
if (typeof i == typeof r && M(r, i) === 0) return n(e[2 + t * 2]);
|
|
554
|
+
}
|
|
555
|
+
return (e.length - 1) % 2 == 1 ? n(e[e.length - 1]) : _("#N/A", "No case matched");
|
|
556
|
+
}
|
|
557
|
+
},
|
|
558
|
+
{
|
|
559
|
+
name: "TRUE",
|
|
560
|
+
category: "logical",
|
|
561
|
+
syntax: "TRUE()",
|
|
562
|
+
description: "Returns the logical value TRUE.",
|
|
563
|
+
minArgs: 0,
|
|
564
|
+
maxArgs: 0,
|
|
565
|
+
call: () => !0
|
|
566
|
+
},
|
|
567
|
+
{
|
|
568
|
+
name: "FALSE",
|
|
569
|
+
category: "logical",
|
|
570
|
+
syntax: "FALSE()",
|
|
571
|
+
description: "Returns the logical value FALSE.",
|
|
572
|
+
minArgs: 0,
|
|
573
|
+
maxArgs: 0,
|
|
574
|
+
call: () => !1
|
|
575
|
+
}
|
|
576
|
+
];
|
|
577
|
+
//#endregion
|
|
578
|
+
//#region src/formula/criteria.ts
|
|
579
|
+
function I(e, t = !0) {
|
|
580
|
+
let n = "";
|
|
581
|
+
for (let t = 0; t < e.length; t++) {
|
|
582
|
+
let r = e[t];
|
|
583
|
+
r === "~" && t + 1 < e.length ? n += Te(e[++t]) : r === "*" ? n += "[\\s\\S]*" : r === "?" ? n += "[\\s\\S]" : n += Te(r);
|
|
584
|
+
}
|
|
585
|
+
return new RegExp(t ? `^${n}$` : n, "i");
|
|
586
|
+
}
|
|
587
|
+
function Te(e) {
|
|
588
|
+
return e.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
589
|
+
}
|
|
590
|
+
var L = (e) => e === null || e === "";
|
|
591
|
+
function R(e) {
|
|
592
|
+
if (e === null) return L;
|
|
593
|
+
if (typeof e == "number" || typeof e == "boolean") return (t) => typeof t == typeof e && t === e;
|
|
594
|
+
if (v(e)) return (t) => v(t) && t.error === e.error;
|
|
595
|
+
let t = /^(<=|>=|<>|<|>|=)?([\s\S]*)$/.exec(e), n = t?.[1] ?? "", r = t?.[2] ?? "";
|
|
596
|
+
if (r === "") return n === "" || n === "=" ? L : n === "<>" ? (e) => !L(e) : () => !1;
|
|
597
|
+
let i = w(r), a = r.toUpperCase(), o = i === null ? a === "TRUE" ? !0 : a === "FALSE" ? !1 : r : i;
|
|
598
|
+
if (n === "" || n === "=" || n === "<>") {
|
|
599
|
+
let e = typeof o == "string" ? (() => {
|
|
600
|
+
let e = I(o);
|
|
601
|
+
return (t) => typeof t == "string" && e.test(t);
|
|
602
|
+
})() : (e) => typeof e == typeof o && e === o;
|
|
603
|
+
return n === "<>" ? (t) => !e(t) : e;
|
|
604
|
+
}
|
|
605
|
+
return (e) => {
|
|
606
|
+
if (e === null || v(e) || typeof e != typeof o) return !1;
|
|
607
|
+
let t = M(e, o);
|
|
608
|
+
switch (n) {
|
|
609
|
+
case "<": return t < 0;
|
|
610
|
+
case ">": return t > 0;
|
|
611
|
+
case "<=": return t <= 0;
|
|
612
|
+
default: return t >= 0;
|
|
613
|
+
}
|
|
614
|
+
};
|
|
615
|
+
}
|
|
616
|
+
//#endregion
|
|
617
|
+
//#region src/formula/functions/define.ts
|
|
618
|
+
function z(e) {
|
|
619
|
+
return (t) => {
|
|
620
|
+
let n = [];
|
|
621
|
+
for (let e of t) {
|
|
622
|
+
let t = O(e);
|
|
623
|
+
if (v(t)) return t;
|
|
624
|
+
n.push(t);
|
|
625
|
+
}
|
|
626
|
+
return e(...n);
|
|
627
|
+
};
|
|
628
|
+
}
|
|
629
|
+
function B(...e) {
|
|
630
|
+
for (let t of e) if (v(t)) return t;
|
|
631
|
+
return null;
|
|
632
|
+
}
|
|
633
|
+
//#endregion
|
|
634
|
+
//#region src/formula/functions/lookup.ts
|
|
635
|
+
var V = () => _("#N/A", "The value was not found");
|
|
636
|
+
function Ee(e) {
|
|
637
|
+
return e.cols === 1 ? {
|
|
638
|
+
length: e.rows,
|
|
639
|
+
at: (t) => e.get(t, 0)
|
|
640
|
+
} : e.rows === 1 ? {
|
|
641
|
+
length: e.cols,
|
|
642
|
+
at: (t) => e.get(0, t)
|
|
643
|
+
} : null;
|
|
644
|
+
}
|
|
645
|
+
function De(e, t) {
|
|
646
|
+
if (typeof e == "string" && t && /[*?~]/.test(e)) {
|
|
647
|
+
let t = I(e);
|
|
648
|
+
return (e) => typeof e == "string" && t.test(e);
|
|
649
|
+
}
|
|
650
|
+
return (t) => t !== null && !v(t) && typeof t == typeof e && M(t, e) === 0;
|
|
651
|
+
}
|
|
652
|
+
function Oe(e, t, n, r) {
|
|
653
|
+
if (n === 0) {
|
|
654
|
+
let n = De(t, r);
|
|
655
|
+
for (let t = 0; t < e.length; t++) if (n(e.at(t))) return t;
|
|
656
|
+
return -1;
|
|
657
|
+
}
|
|
658
|
+
let i = -1;
|
|
659
|
+
for (let r = 0; r < e.length; r++) {
|
|
660
|
+
let a = e.at(r);
|
|
661
|
+
if (a === null || v(a) || typeof a != typeof t) continue;
|
|
662
|
+
let o = M(a, t);
|
|
663
|
+
if (o === 0) return r;
|
|
664
|
+
if (n === 1 && o < 0 || n === -1 && o > 0) i = r;
|
|
665
|
+
else break;
|
|
666
|
+
}
|
|
667
|
+
return i;
|
|
668
|
+
}
|
|
669
|
+
function ke(e, t) {
|
|
670
|
+
let n = C(e[0]), r = x(e[1]), i = O(e[2]), a = e[3] === void 0 || e[3] === null ? !0 : A(e[3]), o = B(n, i, a);
|
|
671
|
+
if (o) return o;
|
|
672
|
+
let s = Math.trunc(i), c = t ? r.cols : r.rows;
|
|
673
|
+
if (s < 1) return _("#VALUE!", "The index must be at least 1");
|
|
674
|
+
if (s > c) return _("#REF!", "The index is outside the table");
|
|
675
|
+
let l = Oe(t ? {
|
|
676
|
+
length: r.rows,
|
|
677
|
+
at: (e) => r.get(e, 0)
|
|
678
|
+
} : {
|
|
679
|
+
length: r.cols,
|
|
680
|
+
at: (e) => r.get(0, e)
|
|
681
|
+
}, n, a ? 1 : 0, !0);
|
|
682
|
+
return l < 0 ? V() : t ? r.get(l, s - 1) : r.get(s - 1, l);
|
|
683
|
+
}
|
|
684
|
+
function H(e, t, n, r, i) {
|
|
685
|
+
return {
|
|
686
|
+
kind: "matrix",
|
|
687
|
+
rows: r,
|
|
688
|
+
cols: i,
|
|
689
|
+
get: (r, i) => e.get(t + r, n + i),
|
|
690
|
+
origin: e.origin ? {
|
|
691
|
+
row: e.origin.row + t,
|
|
692
|
+
col: e.origin.col + n
|
|
693
|
+
} : void 0
|
|
694
|
+
};
|
|
695
|
+
}
|
|
696
|
+
function Ae(e, t, n) {
|
|
697
|
+
return e == null ? t.at ? t.at[n] + 1 : _("#VALUE!", "There is no current cell") : y(e) && e.origin ? e.origin[n] + 1 : _("#VALUE!", "A reference is needed");
|
|
698
|
+
}
|
|
699
|
+
var je = [
|
|
700
|
+
{
|
|
701
|
+
name: "VLOOKUP",
|
|
702
|
+
category: "lookup",
|
|
703
|
+
syntax: "VLOOKUP(key, table, column, [approximate])",
|
|
704
|
+
description: "Finds a key in the first column of a table and returns the value in another column of that row.",
|
|
705
|
+
minArgs: 3,
|
|
706
|
+
maxArgs: 4,
|
|
707
|
+
call: (e) => ke(e, !0)
|
|
708
|
+
},
|
|
709
|
+
{
|
|
710
|
+
name: "HLOOKUP",
|
|
711
|
+
category: "lookup",
|
|
712
|
+
syntax: "HLOOKUP(key, table, row, [approximate])",
|
|
713
|
+
description: "Finds a key in the first row of a table and returns the value in another row of that column.",
|
|
714
|
+
minArgs: 3,
|
|
715
|
+
maxArgs: 4,
|
|
716
|
+
call: (e) => ke(e, !1)
|
|
717
|
+
},
|
|
718
|
+
{
|
|
719
|
+
name: "INDEX",
|
|
720
|
+
category: "lookup",
|
|
721
|
+
syntax: "INDEX(range, row, [column])",
|
|
722
|
+
description: "Returns the value at a row and column of a range, counting from 1.",
|
|
723
|
+
minArgs: 2,
|
|
724
|
+
maxArgs: 3,
|
|
725
|
+
call: (e) => {
|
|
726
|
+
let t = x(e[0]), n = O(e[1]), r = j(e, 2, 0), i = B(n, r);
|
|
727
|
+
if (i) return i;
|
|
728
|
+
t.rows === 1 && (e[2] === void 0 || e[2] === null) && (r = n, n = 1);
|
|
729
|
+
let a = Math.trunc(n), o = Math.trunc(r);
|
|
730
|
+
return a < 0 || o < 0 || a > t.rows || o > t.cols ? _("#REF!", "The position is outside the range") : a === 0 && o === 0 ? t : a === 0 ? H(t, 0, o - 1, t.rows, 1) : o === 0 ? t.cols === 1 ? H(t, a - 1, 0, 1, 1) : H(t, a - 1, 0, 1, t.cols) : H(t, a - 1, o - 1, 1, 1);
|
|
731
|
+
}
|
|
732
|
+
},
|
|
733
|
+
{
|
|
734
|
+
name: "MATCH",
|
|
735
|
+
category: "lookup",
|
|
736
|
+
syntax: "MATCH(key, range, [match_type])",
|
|
737
|
+
description: "Returns the position of a key in a row or column: 1 for sorted ascending, 0 for exact, -1 for sorted descending.",
|
|
738
|
+
minArgs: 2,
|
|
739
|
+
maxArgs: 3,
|
|
740
|
+
call: (e) => {
|
|
741
|
+
let t = C(e[0]), n = j(e, 2, 1), r = B(t, n);
|
|
742
|
+
if (r) return r;
|
|
743
|
+
let i = Ee(x(e[1]));
|
|
744
|
+
if (!i) return _("#N/A", "The range must be one row or one column");
|
|
745
|
+
let a = Oe(i, t, Math.sign(n), !0);
|
|
746
|
+
return a < 0 ? V() : a + 1;
|
|
747
|
+
}
|
|
748
|
+
},
|
|
749
|
+
{
|
|
750
|
+
name: "XLOOKUP",
|
|
751
|
+
category: "lookup",
|
|
752
|
+
syntax: "XLOOKUP(key, lookup_range, return_range, [if_not_found], [match_mode], [search_mode])",
|
|
753
|
+
description: "Finds a key in a range and returns the matching item of another range, with a fallback when nothing matches.",
|
|
754
|
+
minArgs: 3,
|
|
755
|
+
maxArgs: 6,
|
|
756
|
+
lazy: (e, t, n) => {
|
|
757
|
+
let r = C(n(e[0])), i = x(n(e[1])), a = x(n(e[2])), o = e[4] ? O(n(e[4])) : 0, s = e[5] ? O(n(e[5])) : 1, c = B(r, o, s);
|
|
758
|
+
if (c) return c;
|
|
759
|
+
let l = Ee(i);
|
|
760
|
+
if (!l) return _("#VALUE!", "The lookup range must be one row or one column");
|
|
761
|
+
let u = i.cols === 1;
|
|
762
|
+
if (u ? a.rows !== l.length : a.cols !== l.length) return _("#VALUE!", "The ranges differ in size");
|
|
763
|
+
let d = o, f = [];
|
|
764
|
+
for (let e = 0; e < l.length; e++) f.push(e);
|
|
765
|
+
s < 0 && f.reverse();
|
|
766
|
+
let p = De(r, d === 2), m = -1, h = -1;
|
|
767
|
+
for (let e of f) {
|
|
768
|
+
let t = l.at(e);
|
|
769
|
+
if (p(t)) {
|
|
770
|
+
m = e;
|
|
771
|
+
break;
|
|
772
|
+
}
|
|
773
|
+
if (d !== -1 && d !== 1 || t === null || v(t) || typeof t != typeof r || M(t, r) !== d) continue;
|
|
774
|
+
let n = h < 0 ? null : l.at(h);
|
|
775
|
+
(n === null || M(t, n) === -d) && (h = e);
|
|
776
|
+
}
|
|
777
|
+
return m < 0 && (m = h), m < 0 ? e[3] && e[3].type !== "missing" ? n(e[3]) : V() : u ? H(a, m, 0, 1, a.cols) : H(a, 0, m, a.rows, 1);
|
|
778
|
+
}
|
|
779
|
+
},
|
|
780
|
+
{
|
|
781
|
+
name: "CHOOSE",
|
|
782
|
+
category: "lookup",
|
|
783
|
+
syntax: "CHOOSE(index, value1, [value2, ...])",
|
|
784
|
+
description: "Returns the value at a position in a list of values, counting from 1.",
|
|
785
|
+
minArgs: 2,
|
|
786
|
+
maxArgs: Infinity,
|
|
787
|
+
lazy: (e, t, n) => {
|
|
788
|
+
let r = O(n(e[0]));
|
|
789
|
+
if (v(r)) return r;
|
|
790
|
+
let i = Math.trunc(r);
|
|
791
|
+
return i < 1 || i >= e.length ? _("#VALUE!", "The index is outside the list") : n(e[i]);
|
|
792
|
+
}
|
|
793
|
+
},
|
|
794
|
+
{
|
|
795
|
+
name: "ROWS",
|
|
796
|
+
category: "lookup",
|
|
797
|
+
syntax: "ROWS(range)",
|
|
798
|
+
description: "Returns the number of rows in a range.",
|
|
799
|
+
minArgs: 1,
|
|
800
|
+
maxArgs: 1,
|
|
801
|
+
call: (e) => x(e[0]).rows
|
|
802
|
+
},
|
|
803
|
+
{
|
|
804
|
+
name: "COLUMNS",
|
|
805
|
+
category: "lookup",
|
|
806
|
+
syntax: "COLUMNS(range)",
|
|
807
|
+
description: "Returns the number of columns in a range.",
|
|
808
|
+
minArgs: 1,
|
|
809
|
+
maxArgs: 1,
|
|
810
|
+
call: (e) => x(e[0]).cols
|
|
811
|
+
},
|
|
812
|
+
{
|
|
813
|
+
name: "ROW",
|
|
814
|
+
category: "lookup",
|
|
815
|
+
syntax: "ROW([reference])",
|
|
816
|
+
description: "Returns the row number of a reference, or of the current cell.",
|
|
817
|
+
minArgs: 0,
|
|
818
|
+
maxArgs: 1,
|
|
819
|
+
call: (e, t) => Ae(e[0], t, "row")
|
|
820
|
+
},
|
|
821
|
+
{
|
|
822
|
+
name: "COLUMN",
|
|
823
|
+
category: "lookup",
|
|
824
|
+
syntax: "COLUMN([reference])",
|
|
825
|
+
description: "Returns the column number of a reference, or of the current cell.",
|
|
826
|
+
minArgs: 0,
|
|
827
|
+
maxArgs: 1,
|
|
828
|
+
call: (e, t) => Ae(e[0], t, "col")
|
|
829
|
+
}
|
|
830
|
+
], U = (e) => Number(e.toPrecision(15));
|
|
831
|
+
function W(e, t, n) {
|
|
832
|
+
let r = Math.trunc(n), i = 10 ** Math.abs(r), a = Math.sign(t);
|
|
833
|
+
return r >= 0 ? a * e(U(Math.abs(t) * i)) / i : a * e(U(Math.abs(t) / i)) * i;
|
|
834
|
+
}
|
|
835
|
+
var Me = (e) => Math.floor(e + .5);
|
|
836
|
+
function Ne(e, t) {
|
|
837
|
+
let n = [];
|
|
838
|
+
if (e.length % 2 != 0) return _("#N/A", "Each criteria range needs a criterion");
|
|
839
|
+
let r = t?.rows, i = t?.cols;
|
|
840
|
+
for (let t = 0; t < e.length; t += 2) {
|
|
841
|
+
let a = x(e[t]), o = x(e[t + 1]);
|
|
842
|
+
if (r === void 0 || i === void 0) r = a.rows, i = a.cols;
|
|
843
|
+
else if (a.rows !== r || a.cols !== i) return _("#VALUE!", "The ranges differ in size");
|
|
844
|
+
n.push({
|
|
845
|
+
range: a,
|
|
846
|
+
test: R(o.get(0, 0))
|
|
847
|
+
});
|
|
848
|
+
}
|
|
849
|
+
return (e, t) => n.every(({ range: n, test: r }) => r(n.get(e, t)));
|
|
850
|
+
}
|
|
851
|
+
function Pe(e, t, n, r) {
|
|
852
|
+
let i = x(e), a = [];
|
|
853
|
+
for (let e = 0; e < n; e++) for (let n = 0; n < r; n++) {
|
|
854
|
+
if (!t(e, n)) continue;
|
|
855
|
+
let r = e < i.rows && n < i.cols ? i.get(e, n) : null;
|
|
856
|
+
if (v(r)) return r;
|
|
857
|
+
typeof r == "number" && a.push(r);
|
|
858
|
+
}
|
|
859
|
+
return a;
|
|
860
|
+
}
|
|
861
|
+
var G = (e) => e.reduce((e, t) => e + t, 0);
|
|
862
|
+
function Fe(e) {
|
|
863
|
+
let t = x(e[0]), n = R(x(e[1]).get(0, 0));
|
|
864
|
+
return Pe(e[2] === void 0 || e[2] === null ? e[0] : e[2], (e, r) => n(t.get(e, r)), t.rows, t.cols);
|
|
865
|
+
}
|
|
866
|
+
function Ie(e) {
|
|
867
|
+
let t = x(e[0]), n = Ne(e.slice(1), t);
|
|
868
|
+
return v(n) ? n : Pe(t, n, t.rows, t.cols);
|
|
869
|
+
}
|
|
870
|
+
function Le(e, t, n) {
|
|
871
|
+
let r = O(e[0]), i = j(e, 1, 1), a = B(r, i);
|
|
872
|
+
if (a) return a;
|
|
873
|
+
let o = r, s = i;
|
|
874
|
+
return s === 0 ? n === "FLOOR" ? _("#DIV/0!", "Division by zero") : 0 : o > 0 && s < 0 ? _("#NUM!", "A positive number needs a positive significance") : t(U(o / s)) * s;
|
|
875
|
+
}
|
|
876
|
+
var Re = [
|
|
877
|
+
{
|
|
878
|
+
name: "SUM",
|
|
879
|
+
category: "math",
|
|
880
|
+
syntax: "SUM(value1, [value2, ...])",
|
|
881
|
+
description: "Adds numbers and the numbers in ranges.",
|
|
882
|
+
minArgs: 1,
|
|
883
|
+
maxArgs: Infinity,
|
|
884
|
+
call: (e) => {
|
|
885
|
+
let t = N(e);
|
|
886
|
+
return v(t) ? t : G(t);
|
|
887
|
+
}
|
|
888
|
+
},
|
|
889
|
+
{
|
|
890
|
+
name: "SUMIF",
|
|
891
|
+
category: "math",
|
|
892
|
+
syntax: "SUMIF(range, criterion, [sum_range])",
|
|
893
|
+
description: "Adds the cells that meet a criterion.",
|
|
894
|
+
minArgs: 2,
|
|
895
|
+
maxArgs: 3,
|
|
896
|
+
call: (e) => {
|
|
897
|
+
let t = Fe(e);
|
|
898
|
+
return v(t) ? t : G(t);
|
|
899
|
+
}
|
|
900
|
+
},
|
|
901
|
+
{
|
|
902
|
+
name: "SUMIFS",
|
|
903
|
+
category: "math",
|
|
904
|
+
syntax: "SUMIFS(sum_range, criteria_range1, criterion1, [criteria_range2, criterion2, ...])",
|
|
905
|
+
description: "Adds the cells that meet every criterion.",
|
|
906
|
+
minArgs: 3,
|
|
907
|
+
maxArgs: Infinity,
|
|
908
|
+
call: (e) => {
|
|
909
|
+
let t = Ie(e);
|
|
910
|
+
return v(t) ? t : G(t);
|
|
911
|
+
}
|
|
912
|
+
},
|
|
913
|
+
{
|
|
914
|
+
name: "SUMPRODUCT",
|
|
915
|
+
category: "math",
|
|
916
|
+
syntax: "SUMPRODUCT(array1, [array2, ...])",
|
|
917
|
+
description: "Multiplies matching cells of ranges of the same size and adds the products.",
|
|
918
|
+
minArgs: 1,
|
|
919
|
+
maxArgs: Infinity,
|
|
920
|
+
call: (e) => {
|
|
921
|
+
let t = e.map(x), { rows: n, cols: r } = t[0];
|
|
922
|
+
if (t.some((e) => e.rows !== n || e.cols !== r)) return _("#VALUE!", "The ranges differ in size");
|
|
923
|
+
let i = 0;
|
|
924
|
+
for (let e = 0; e < n; e++) for (let n = 0; n < r; n++) {
|
|
925
|
+
let r = 1;
|
|
926
|
+
for (let i of t) {
|
|
927
|
+
let t = i.get(e, n);
|
|
928
|
+
if (v(t)) return t;
|
|
929
|
+
r *= typeof t == "number" ? t : 0;
|
|
930
|
+
}
|
|
931
|
+
i += r;
|
|
932
|
+
}
|
|
933
|
+
return i;
|
|
934
|
+
}
|
|
935
|
+
},
|
|
936
|
+
{
|
|
937
|
+
name: "PRODUCT",
|
|
938
|
+
category: "math",
|
|
939
|
+
syntax: "PRODUCT(value1, [value2, ...])",
|
|
940
|
+
description: "Multiplies numbers and the numbers in ranges.",
|
|
941
|
+
minArgs: 1,
|
|
942
|
+
maxArgs: Infinity,
|
|
943
|
+
call: (e) => {
|
|
944
|
+
let t = N(e);
|
|
945
|
+
return v(t) ? t : t.length === 0 ? 0 : t.reduce((e, t) => e * t, 1);
|
|
946
|
+
}
|
|
947
|
+
},
|
|
948
|
+
{
|
|
949
|
+
name: "ROUND",
|
|
950
|
+
category: "math",
|
|
951
|
+
syntax: "ROUND(value, [digits])",
|
|
952
|
+
description: "Rounds a number to a number of digits, halves away from zero.",
|
|
953
|
+
minArgs: 1,
|
|
954
|
+
maxArgs: 2,
|
|
955
|
+
call: (e) => {
|
|
956
|
+
let t = j(e, 1, 0), n = O(e[0]);
|
|
957
|
+
return B(n, t) ?? W(Me, n, t);
|
|
958
|
+
}
|
|
959
|
+
},
|
|
960
|
+
{
|
|
961
|
+
name: "ROUNDUP",
|
|
962
|
+
category: "math",
|
|
963
|
+
syntax: "ROUNDUP(value, [digits])",
|
|
964
|
+
description: "Rounds a number away from zero to a number of digits.",
|
|
965
|
+
minArgs: 1,
|
|
966
|
+
maxArgs: 2,
|
|
967
|
+
call: (e) => {
|
|
968
|
+
let t = j(e, 1, 0), n = O(e[0]);
|
|
969
|
+
return B(n, t) ?? W(Math.ceil, n, t);
|
|
970
|
+
}
|
|
971
|
+
},
|
|
972
|
+
{
|
|
973
|
+
name: "ROUNDDOWN",
|
|
974
|
+
category: "math",
|
|
975
|
+
syntax: "ROUNDDOWN(value, [digits])",
|
|
976
|
+
description: "Rounds a number toward zero to a number of digits.",
|
|
977
|
+
minArgs: 1,
|
|
978
|
+
maxArgs: 2,
|
|
979
|
+
call: (e) => {
|
|
980
|
+
let t = j(e, 1, 0), n = O(e[0]);
|
|
981
|
+
return B(n, t) ?? W(Math.floor, n, t);
|
|
982
|
+
}
|
|
983
|
+
},
|
|
984
|
+
{
|
|
985
|
+
name: "INT",
|
|
986
|
+
category: "math",
|
|
987
|
+
syntax: "INT(value)",
|
|
988
|
+
description: "Rounds a number down to the nearest integer.",
|
|
989
|
+
minArgs: 1,
|
|
990
|
+
maxArgs: 1,
|
|
991
|
+
call: z((e) => Math.floor(e))
|
|
992
|
+
},
|
|
993
|
+
{
|
|
994
|
+
name: "TRUNC",
|
|
995
|
+
category: "math",
|
|
996
|
+
syntax: "TRUNC(value, [digits])",
|
|
997
|
+
description: "Cuts a number to a number of digits without rounding.",
|
|
998
|
+
minArgs: 1,
|
|
999
|
+
maxArgs: 2,
|
|
1000
|
+
call: (e) => {
|
|
1001
|
+
let t = j(e, 1, 0), n = O(e[0]);
|
|
1002
|
+
return B(n, t) ?? W(Math.floor, n, t);
|
|
1003
|
+
}
|
|
1004
|
+
},
|
|
1005
|
+
{
|
|
1006
|
+
name: "ABS",
|
|
1007
|
+
category: "math",
|
|
1008
|
+
syntax: "ABS(value)",
|
|
1009
|
+
description: "Returns a number without its sign.",
|
|
1010
|
+
minArgs: 1,
|
|
1011
|
+
maxArgs: 1,
|
|
1012
|
+
call: z((e) => Math.abs(e))
|
|
1013
|
+
},
|
|
1014
|
+
{
|
|
1015
|
+
name: "MOD",
|
|
1016
|
+
category: "math",
|
|
1017
|
+
syntax: "MOD(dividend, divisor)",
|
|
1018
|
+
description: "Returns the remainder of a division, with the sign of the divisor.",
|
|
1019
|
+
minArgs: 2,
|
|
1020
|
+
maxArgs: 2,
|
|
1021
|
+
call: z((e, t) => t === 0 ? _("#DIV/0!", "Division by zero") : e - t * Math.floor(e / t))
|
|
1022
|
+
},
|
|
1023
|
+
{
|
|
1024
|
+
name: "POWER",
|
|
1025
|
+
category: "math",
|
|
1026
|
+
syntax: "POWER(base, exponent)",
|
|
1027
|
+
description: "Raises a number to a power.",
|
|
1028
|
+
minArgs: 2,
|
|
1029
|
+
maxArgs: 2,
|
|
1030
|
+
call: z((e, t) => e === 0 && t === 0 ? _("#NUM!", "Zero to the power of zero") : e === 0 && t < 0 ? _("#DIV/0!", "Division by zero") : e ** +t)
|
|
1031
|
+
},
|
|
1032
|
+
{
|
|
1033
|
+
name: "SQRT",
|
|
1034
|
+
category: "math",
|
|
1035
|
+
syntax: "SQRT(value)",
|
|
1036
|
+
description: "Returns the square root of a number.",
|
|
1037
|
+
minArgs: 1,
|
|
1038
|
+
maxArgs: 1,
|
|
1039
|
+
call: z((e) => e < 0 ? _("#NUM!", "Square root of a negative number") : Math.sqrt(e))
|
|
1040
|
+
},
|
|
1041
|
+
{
|
|
1042
|
+
name: "EXP",
|
|
1043
|
+
category: "math",
|
|
1044
|
+
syntax: "EXP(value)",
|
|
1045
|
+
description: "Returns e raised to a power.",
|
|
1046
|
+
minArgs: 1,
|
|
1047
|
+
maxArgs: 1,
|
|
1048
|
+
call: z((e) => Math.exp(e))
|
|
1049
|
+
},
|
|
1050
|
+
{
|
|
1051
|
+
name: "LN",
|
|
1052
|
+
category: "math",
|
|
1053
|
+
syntax: "LN(value)",
|
|
1054
|
+
description: "Returns the natural logarithm of a number.",
|
|
1055
|
+
minArgs: 1,
|
|
1056
|
+
maxArgs: 1,
|
|
1057
|
+
call: z((e) => e <= 0 ? _("#NUM!", "Logarithm of a number that is not positive") : Math.log(e))
|
|
1058
|
+
},
|
|
1059
|
+
{
|
|
1060
|
+
name: "LOG",
|
|
1061
|
+
category: "math",
|
|
1062
|
+
syntax: "LOG(value, [base])",
|
|
1063
|
+
description: "Returns the logarithm of a number in a base, 10 when left out.",
|
|
1064
|
+
minArgs: 1,
|
|
1065
|
+
maxArgs: 2,
|
|
1066
|
+
call: (e) => {
|
|
1067
|
+
let t = j(e, 1, 10), n = O(e[0]), r = B(n, t);
|
|
1068
|
+
if (r) return r;
|
|
1069
|
+
let i = n, a = t;
|
|
1070
|
+
return i <= 0 || a <= 0 ? _("#NUM!", "Logarithm of a number that is not positive") : a === 1 ? _("#DIV/0!", "Division by zero") : Math.log(i) / Math.log(a);
|
|
1071
|
+
}
|
|
1072
|
+
},
|
|
1073
|
+
{
|
|
1074
|
+
name: "LOG10",
|
|
1075
|
+
category: "math",
|
|
1076
|
+
syntax: "LOG10(value)",
|
|
1077
|
+
description: "Returns the base 10 logarithm of a number.",
|
|
1078
|
+
minArgs: 1,
|
|
1079
|
+
maxArgs: 1,
|
|
1080
|
+
call: z((e) => e <= 0 ? _("#NUM!", "Logarithm of a number that is not positive") : Math.log10(e))
|
|
1081
|
+
},
|
|
1082
|
+
{
|
|
1083
|
+
name: "PI",
|
|
1084
|
+
category: "math",
|
|
1085
|
+
syntax: "PI()",
|
|
1086
|
+
description: "Returns the number pi.",
|
|
1087
|
+
minArgs: 0,
|
|
1088
|
+
maxArgs: 0,
|
|
1089
|
+
call: () => Math.PI
|
|
1090
|
+
},
|
|
1091
|
+
{
|
|
1092
|
+
name: "SIGN",
|
|
1093
|
+
category: "math",
|
|
1094
|
+
syntax: "SIGN(value)",
|
|
1095
|
+
description: "Returns 1 for a positive number, -1 for a negative one and 0 for zero.",
|
|
1096
|
+
minArgs: 1,
|
|
1097
|
+
maxArgs: 1,
|
|
1098
|
+
call: z((e) => Math.sign(e))
|
|
1099
|
+
},
|
|
1100
|
+
{
|
|
1101
|
+
name: "CEILING",
|
|
1102
|
+
category: "math",
|
|
1103
|
+
syntax: "CEILING(value, [significance])",
|
|
1104
|
+
description: "Rounds a number up to the nearest multiple of a significance, 1 when left out.",
|
|
1105
|
+
minArgs: 1,
|
|
1106
|
+
maxArgs: 2,
|
|
1107
|
+
call: (e) => Le(e, Math.ceil, "CEILING")
|
|
1108
|
+
},
|
|
1109
|
+
{
|
|
1110
|
+
name: "FLOOR",
|
|
1111
|
+
category: "math",
|
|
1112
|
+
syntax: "FLOOR(value, [significance])",
|
|
1113
|
+
description: "Rounds a number down to the nearest multiple of a significance, 1 when left out.",
|
|
1114
|
+
minArgs: 1,
|
|
1115
|
+
maxArgs: 2,
|
|
1116
|
+
call: (e) => Le(e, Math.floor, "FLOOR")
|
|
1117
|
+
}
|
|
1118
|
+
], K = (e) => e.length === 0 ? _("#DIV/0!", "There are no numbers to average") : e.reduce((e, t) => e + t, 0) / e.length;
|
|
1119
|
+
function ze(e) {
|
|
1120
|
+
if (e.length < 2) return _("#DIV/0!", "At least two numbers are needed");
|
|
1121
|
+
let t = e.reduce((e, t) => e + t, 0) / e.length;
|
|
1122
|
+
return e.reduce((e, n) => e + (n - t) ** 2, 0) / (e.length - 1);
|
|
1123
|
+
}
|
|
1124
|
+
var q = (e) => (t) => {
|
|
1125
|
+
let n = N(t);
|
|
1126
|
+
return v(n) ? n : e(n);
|
|
1127
|
+
};
|
|
1128
|
+
function Be(e, t) {
|
|
1129
|
+
let n = N([x(e[0])]), r = O(e[1]), i = B(n, r);
|
|
1130
|
+
if (i) return i;
|
|
1131
|
+
let a = n.slice().sort((e, n) => t ? n - e : e - n), o = Math.ceil(r) - 1;
|
|
1132
|
+
return o < 0 || o >= a.length ? _("#NUM!", "The position is outside the list") : a[o];
|
|
1133
|
+
}
|
|
1134
|
+
var Ve = [
|
|
1135
|
+
{
|
|
1136
|
+
name: "AVERAGE",
|
|
1137
|
+
category: "statistical",
|
|
1138
|
+
syntax: "AVERAGE(value1, [value2, ...])",
|
|
1139
|
+
description: "Returns the arithmetic mean of numbers and the numbers in ranges.",
|
|
1140
|
+
minArgs: 1,
|
|
1141
|
+
maxArgs: Infinity,
|
|
1142
|
+
call: q(K)
|
|
1143
|
+
},
|
|
1144
|
+
{
|
|
1145
|
+
name: "AVERAGEIF",
|
|
1146
|
+
category: "statistical",
|
|
1147
|
+
syntax: "AVERAGEIF(range, criterion, [average_range])",
|
|
1148
|
+
description: "Returns the mean of the cells that meet a criterion.",
|
|
1149
|
+
minArgs: 2,
|
|
1150
|
+
maxArgs: 3,
|
|
1151
|
+
call: (e) => {
|
|
1152
|
+
let t = Fe(e);
|
|
1153
|
+
return v(t) ? t : K(t);
|
|
1154
|
+
}
|
|
1155
|
+
},
|
|
1156
|
+
{
|
|
1157
|
+
name: "AVERAGEIFS",
|
|
1158
|
+
category: "statistical",
|
|
1159
|
+
syntax: "AVERAGEIFS(average_range, criteria_range1, criterion1, [criteria_range2, criterion2, ...])",
|
|
1160
|
+
description: "Returns the mean of the cells that meet every criterion.",
|
|
1161
|
+
minArgs: 3,
|
|
1162
|
+
maxArgs: Infinity,
|
|
1163
|
+
call: (e) => {
|
|
1164
|
+
let t = Ie(e);
|
|
1165
|
+
return v(t) ? t : K(t);
|
|
1166
|
+
}
|
|
1167
|
+
},
|
|
1168
|
+
{
|
|
1169
|
+
name: "COUNT",
|
|
1170
|
+
category: "statistical",
|
|
1171
|
+
syntax: "COUNT(value1, [value2, ...])",
|
|
1172
|
+
description: "Counts the numbers among the values and in ranges.",
|
|
1173
|
+
minArgs: 1,
|
|
1174
|
+
maxArgs: Infinity,
|
|
1175
|
+
call: (e) => {
|
|
1176
|
+
let t = 0;
|
|
1177
|
+
for (let n of e) y(n) ? S(n, (e) => {
|
|
1178
|
+
typeof e == "number" && t++;
|
|
1179
|
+
}) : (typeof n == "number" || typeof n == "boolean" || typeof n == "string" && w(n) !== null) && t++;
|
|
1180
|
+
return t;
|
|
1181
|
+
}
|
|
1182
|
+
},
|
|
1183
|
+
{
|
|
1184
|
+
name: "COUNTA",
|
|
1185
|
+
category: "statistical",
|
|
1186
|
+
syntax: "COUNTA(value1, [value2, ...])",
|
|
1187
|
+
description: "Counts the values and the cells in ranges that are not empty.",
|
|
1188
|
+
minArgs: 1,
|
|
1189
|
+
maxArgs: Infinity,
|
|
1190
|
+
call: (e) => {
|
|
1191
|
+
let t = 0;
|
|
1192
|
+
for (let n of e) y(n) ? S(n, (e) => {
|
|
1193
|
+
e !== null && t++;
|
|
1194
|
+
}) : n !== null && t++;
|
|
1195
|
+
return t;
|
|
1196
|
+
}
|
|
1197
|
+
},
|
|
1198
|
+
{
|
|
1199
|
+
name: "COUNTBLANK",
|
|
1200
|
+
category: "statistical",
|
|
1201
|
+
syntax: "COUNTBLANK(range)",
|
|
1202
|
+
description: "Counts the empty cells in a range, including cells with empty text.",
|
|
1203
|
+
minArgs: 1,
|
|
1204
|
+
maxArgs: 1,
|
|
1205
|
+
call: (e) => {
|
|
1206
|
+
let t = 0;
|
|
1207
|
+
return S(x(e[0]), (e) => {
|
|
1208
|
+
(e === null || e === "") && t++;
|
|
1209
|
+
}), t;
|
|
1210
|
+
}
|
|
1211
|
+
},
|
|
1212
|
+
{
|
|
1213
|
+
name: "COUNTIF",
|
|
1214
|
+
category: "statistical",
|
|
1215
|
+
syntax: "COUNTIF(range, criterion)",
|
|
1216
|
+
description: "Counts the cells in a range that meet a criterion.",
|
|
1217
|
+
minArgs: 2,
|
|
1218
|
+
maxArgs: 2,
|
|
1219
|
+
call: (e) => {
|
|
1220
|
+
let t = R(x(e[1]).get(0, 0)), n = 0;
|
|
1221
|
+
return S(x(e[0]), (e) => {
|
|
1222
|
+
t(e) && n++;
|
|
1223
|
+
}), n;
|
|
1224
|
+
}
|
|
1225
|
+
},
|
|
1226
|
+
{
|
|
1227
|
+
name: "COUNTIFS",
|
|
1228
|
+
category: "statistical",
|
|
1229
|
+
syntax: "COUNTIFS(criteria_range1, criterion1, [criteria_range2, criterion2, ...])",
|
|
1230
|
+
description: "Counts the positions where every criterion is met.",
|
|
1231
|
+
minArgs: 2,
|
|
1232
|
+
maxArgs: Infinity,
|
|
1233
|
+
call: (e) => {
|
|
1234
|
+
let t = x(e[0]), n = Ne(e);
|
|
1235
|
+
if (v(n)) return n;
|
|
1236
|
+
let r = 0;
|
|
1237
|
+
for (let e = 0; e < t.rows; e++) for (let i = 0; i < t.cols; i++) n(e, i) && r++;
|
|
1238
|
+
return r;
|
|
1239
|
+
}
|
|
1240
|
+
},
|
|
1241
|
+
{
|
|
1242
|
+
name: "MIN",
|
|
1243
|
+
category: "statistical",
|
|
1244
|
+
syntax: "MIN(value1, [value2, ...])",
|
|
1245
|
+
description: "Returns the smallest number, or 0 when there are none.",
|
|
1246
|
+
minArgs: 1,
|
|
1247
|
+
maxArgs: Infinity,
|
|
1248
|
+
call: q((e) => e.length === 0 ? 0 : e.reduce((e, t) => Math.min(e, t)))
|
|
1249
|
+
},
|
|
1250
|
+
{
|
|
1251
|
+
name: "MAX",
|
|
1252
|
+
category: "statistical",
|
|
1253
|
+
syntax: "MAX(value1, [value2, ...])",
|
|
1254
|
+
description: "Returns the largest number, or 0 when there are none.",
|
|
1255
|
+
minArgs: 1,
|
|
1256
|
+
maxArgs: Infinity,
|
|
1257
|
+
call: q((e) => e.length === 0 ? 0 : e.reduce((e, t) => Math.max(e, t)))
|
|
1258
|
+
},
|
|
1259
|
+
{
|
|
1260
|
+
name: "MEDIAN",
|
|
1261
|
+
category: "statistical",
|
|
1262
|
+
syntax: "MEDIAN(value1, [value2, ...])",
|
|
1263
|
+
description: "Returns the middle number, or the mean of the two middle numbers.",
|
|
1264
|
+
minArgs: 1,
|
|
1265
|
+
maxArgs: Infinity,
|
|
1266
|
+
call: q((e) => {
|
|
1267
|
+
if (e.length === 0) return _("#NUM!", "There are no numbers");
|
|
1268
|
+
let t = e.slice().sort((e, t) => e - t), n = Math.floor(t.length / 2);
|
|
1269
|
+
return t.length % 2 == 1 ? t[n] : (t[n - 1] + t[n]) / 2;
|
|
1270
|
+
})
|
|
1271
|
+
},
|
|
1272
|
+
{
|
|
1273
|
+
name: "LARGE",
|
|
1274
|
+
category: "statistical",
|
|
1275
|
+
syntax: "LARGE(range, k)",
|
|
1276
|
+
description: "Returns the k-th largest number in a range.",
|
|
1277
|
+
minArgs: 2,
|
|
1278
|
+
maxArgs: 2,
|
|
1279
|
+
call: (e) => Be(e, !0)
|
|
1280
|
+
},
|
|
1281
|
+
{
|
|
1282
|
+
name: "SMALL",
|
|
1283
|
+
category: "statistical",
|
|
1284
|
+
syntax: "SMALL(range, k)",
|
|
1285
|
+
description: "Returns the k-th smallest number in a range.",
|
|
1286
|
+
minArgs: 2,
|
|
1287
|
+
maxArgs: 2,
|
|
1288
|
+
call: (e) => Be(e, !1)
|
|
1289
|
+
},
|
|
1290
|
+
{
|
|
1291
|
+
name: "STDEV",
|
|
1292
|
+
category: "statistical",
|
|
1293
|
+
syntax: "STDEV(value1, [value2, ...])",
|
|
1294
|
+
description: "Returns the standard deviation of a sample.",
|
|
1295
|
+
minArgs: 1,
|
|
1296
|
+
maxArgs: Infinity,
|
|
1297
|
+
call: q((e) => {
|
|
1298
|
+
let t = ze(e);
|
|
1299
|
+
return v(t) ? t : Math.sqrt(t);
|
|
1300
|
+
})
|
|
1301
|
+
},
|
|
1302
|
+
{
|
|
1303
|
+
name: "VAR",
|
|
1304
|
+
category: "statistical",
|
|
1305
|
+
syntax: "VAR(value1, [value2, ...])",
|
|
1306
|
+
description: "Returns the variance of a sample.",
|
|
1307
|
+
minArgs: 1,
|
|
1308
|
+
maxArgs: Infinity,
|
|
1309
|
+
call: q(ze)
|
|
1310
|
+
}
|
|
1311
|
+
], He = 32767;
|
|
1312
|
+
function J(e) {
|
|
1313
|
+
let t = [];
|
|
1314
|
+
for (let n of e) if (y(n)) {
|
|
1315
|
+
let e = null;
|
|
1316
|
+
if (S(n, (n) => {
|
|
1317
|
+
let r = E(n);
|
|
1318
|
+
if (v(r)) return e = r, !0;
|
|
1319
|
+
t.push(r);
|
|
1320
|
+
}), e) return e;
|
|
1321
|
+
} else {
|
|
1322
|
+
let e = E(n);
|
|
1323
|
+
if (v(e)) return e;
|
|
1324
|
+
t.push(e);
|
|
1325
|
+
}
|
|
1326
|
+
return t;
|
|
1327
|
+
}
|
|
1328
|
+
var Y = (e) => (t) => {
|
|
1329
|
+
let n = k(t[0]);
|
|
1330
|
+
return v(n) ? n : e(n);
|
|
1331
|
+
};
|
|
1332
|
+
function Ue(e, t) {
|
|
1333
|
+
let n = k(e[0]), r = j(e, 1, 1), i = B(n, r);
|
|
1334
|
+
if (i) return i;
|
|
1335
|
+
let a = Math.trunc(r);
|
|
1336
|
+
if (a < 0) return _("#VALUE!", "The count cannot be negative");
|
|
1337
|
+
let o = n;
|
|
1338
|
+
return t ? o.slice(Math.max(0, o.length - a)) : o.slice(0, a);
|
|
1339
|
+
}
|
|
1340
|
+
function We(e, t) {
|
|
1341
|
+
let n = k(e[0]), r = k(e[1]), i = j(e, 2, 1), a = B(n, r, i);
|
|
1342
|
+
if (a) return a;
|
|
1343
|
+
let o = Math.trunc(i), s = r;
|
|
1344
|
+
if (o < 1 || o > s.length + 1) return _("#VALUE!", "The start position is outside the text");
|
|
1345
|
+
if (t) {
|
|
1346
|
+
let e = s.indexOf(n, o - 1);
|
|
1347
|
+
return e < 0 ? _("#VALUE!", "The text was not found") : e + 1;
|
|
1348
|
+
}
|
|
1349
|
+
let c = I(n, !1).exec(s.slice(o - 1));
|
|
1350
|
+
return c ? c.index + o : _("#VALUE!", "The text was not found");
|
|
1351
|
+
}
|
|
1352
|
+
var Ge = [
|
|
1353
|
+
{
|
|
1354
|
+
name: "CONCAT",
|
|
1355
|
+
category: "text",
|
|
1356
|
+
syntax: "CONCAT(value1, [value2, ...])",
|
|
1357
|
+
description: "Joins values and the cells of ranges into one text.",
|
|
1358
|
+
minArgs: 1,
|
|
1359
|
+
maxArgs: Infinity,
|
|
1360
|
+
call: (e) => {
|
|
1361
|
+
let t = J(e);
|
|
1362
|
+
return v(t) ? t : t.join("");
|
|
1363
|
+
}
|
|
1364
|
+
},
|
|
1365
|
+
{
|
|
1366
|
+
name: "CONCATENATE",
|
|
1367
|
+
category: "text",
|
|
1368
|
+
syntax: "CONCATENATE(value1, [value2, ...])",
|
|
1369
|
+
description: "Joins values into one text.",
|
|
1370
|
+
minArgs: 1,
|
|
1371
|
+
maxArgs: Infinity,
|
|
1372
|
+
call: (e) => {
|
|
1373
|
+
let t = J(e);
|
|
1374
|
+
return v(t) ? t : t.join("");
|
|
1375
|
+
}
|
|
1376
|
+
},
|
|
1377
|
+
{
|
|
1378
|
+
name: "TEXTJOIN",
|
|
1379
|
+
category: "text",
|
|
1380
|
+
syntax: "TEXTJOIN(delimiter, ignore_empty, value1, [value2, ...])",
|
|
1381
|
+
description: "Joins values with a delimiter, optionally leaving out empty ones.",
|
|
1382
|
+
minArgs: 3,
|
|
1383
|
+
maxArgs: Infinity,
|
|
1384
|
+
call: (e) => {
|
|
1385
|
+
let t = k(e[0]), n = A(e[1]), r = J(e.slice(2));
|
|
1386
|
+
return B(t, n, r) || (n ? r.filter((e) => e !== "") : r).join(t);
|
|
1387
|
+
}
|
|
1388
|
+
},
|
|
1389
|
+
{
|
|
1390
|
+
name: "LEN",
|
|
1391
|
+
category: "text",
|
|
1392
|
+
syntax: "LEN(text)",
|
|
1393
|
+
description: "Returns the number of characters in a text.",
|
|
1394
|
+
minArgs: 1,
|
|
1395
|
+
maxArgs: 1,
|
|
1396
|
+
call: Y((e) => e.length)
|
|
1397
|
+
},
|
|
1398
|
+
{
|
|
1399
|
+
name: "LEFT",
|
|
1400
|
+
category: "text",
|
|
1401
|
+
syntax: "LEFT(text, [count])",
|
|
1402
|
+
description: "Returns the first characters of a text, one when the count is left out.",
|
|
1403
|
+
minArgs: 1,
|
|
1404
|
+
maxArgs: 2,
|
|
1405
|
+
call: (e) => Ue(e, !1)
|
|
1406
|
+
},
|
|
1407
|
+
{
|
|
1408
|
+
name: "RIGHT",
|
|
1409
|
+
category: "text",
|
|
1410
|
+
syntax: "RIGHT(text, [count])",
|
|
1411
|
+
description: "Returns the last characters of a text, one when the count is left out.",
|
|
1412
|
+
minArgs: 1,
|
|
1413
|
+
maxArgs: 2,
|
|
1414
|
+
call: (e) => Ue(e, !0)
|
|
1415
|
+
},
|
|
1416
|
+
{
|
|
1417
|
+
name: "MID",
|
|
1418
|
+
category: "text",
|
|
1419
|
+
syntax: "MID(text, start, count)",
|
|
1420
|
+
description: "Returns characters from the middle of a text, counting from 1.",
|
|
1421
|
+
minArgs: 3,
|
|
1422
|
+
maxArgs: 3,
|
|
1423
|
+
call: (e) => {
|
|
1424
|
+
let t = k(e[0]), n = O(e[1]), r = O(e[2]), i = B(t, n, r);
|
|
1425
|
+
if (i) return i;
|
|
1426
|
+
let a = Math.trunc(n), o = Math.trunc(r);
|
|
1427
|
+
return a < 1 ? _("#VALUE!", "The start position must be at least 1") : o < 0 ? _("#VALUE!", "The count cannot be negative") : t.slice(a - 1, a - 1 + o);
|
|
1428
|
+
}
|
|
1429
|
+
},
|
|
1430
|
+
{
|
|
1431
|
+
name: "UPPER",
|
|
1432
|
+
category: "text",
|
|
1433
|
+
syntax: "UPPER(text)",
|
|
1434
|
+
description: "Converts a text to upper case.",
|
|
1435
|
+
minArgs: 1,
|
|
1436
|
+
maxArgs: 1,
|
|
1437
|
+
call: Y((e) => e.toUpperCase())
|
|
1438
|
+
},
|
|
1439
|
+
{
|
|
1440
|
+
name: "LOWER",
|
|
1441
|
+
category: "text",
|
|
1442
|
+
syntax: "LOWER(text)",
|
|
1443
|
+
description: "Converts a text to lower case.",
|
|
1444
|
+
minArgs: 1,
|
|
1445
|
+
maxArgs: 1,
|
|
1446
|
+
call: Y((e) => e.toLowerCase())
|
|
1447
|
+
},
|
|
1448
|
+
{
|
|
1449
|
+
name: "PROPER",
|
|
1450
|
+
category: "text",
|
|
1451
|
+
syntax: "PROPER(text)",
|
|
1452
|
+
description: "Capitalises the first letter of each word and lowers the rest.",
|
|
1453
|
+
minArgs: 1,
|
|
1454
|
+
maxArgs: 1,
|
|
1455
|
+
call: Y((e) => e.toLowerCase().replace(/(^|[^\p{L}])(\p{L})/gu, (e, t, n) => t + n.toUpperCase()))
|
|
1456
|
+
},
|
|
1457
|
+
{
|
|
1458
|
+
name: "TRIM",
|
|
1459
|
+
category: "text",
|
|
1460
|
+
syntax: "TRIM(text)",
|
|
1461
|
+
description: "Removes spaces from both ends and collapses runs of spaces inside.",
|
|
1462
|
+
minArgs: 1,
|
|
1463
|
+
maxArgs: 1,
|
|
1464
|
+
call: Y((e) => e.replace(/ +/g, " ").trim())
|
|
1465
|
+
},
|
|
1466
|
+
{
|
|
1467
|
+
name: "SUBSTITUTE",
|
|
1468
|
+
category: "text",
|
|
1469
|
+
syntax: "SUBSTITUTE(text, old_text, new_text, [instance])",
|
|
1470
|
+
description: "Replaces occurrences of a text, or only the given occurrence.",
|
|
1471
|
+
minArgs: 3,
|
|
1472
|
+
maxArgs: 4,
|
|
1473
|
+
call: (e) => {
|
|
1474
|
+
let t = k(e[0]), n = k(e[1]), r = k(e[2]), i = e[3] === void 0 || e[3] === null ? null : O(e[3]), a = B(t, n, r, i);
|
|
1475
|
+
if (a) return a;
|
|
1476
|
+
let o = t, s = n;
|
|
1477
|
+
if (s === "") return o;
|
|
1478
|
+
if (i === null) return o.split(s).join(r);
|
|
1479
|
+
let c = Math.trunc(i);
|
|
1480
|
+
if (c < 1) return _("#VALUE!", "The instance must be at least 1");
|
|
1481
|
+
let l = -1;
|
|
1482
|
+
for (let e = 0; e < c; e++) if (l = o.indexOf(s, l + 1), l < 0) return o;
|
|
1483
|
+
return o.slice(0, l) + r + o.slice(l + s.length);
|
|
1484
|
+
}
|
|
1485
|
+
},
|
|
1486
|
+
{
|
|
1487
|
+
name: "REPLACE",
|
|
1488
|
+
category: "text",
|
|
1489
|
+
syntax: "REPLACE(text, start, count, new_text)",
|
|
1490
|
+
description: "Replaces a number of characters at a position, counting from 1.",
|
|
1491
|
+
minArgs: 4,
|
|
1492
|
+
maxArgs: 4,
|
|
1493
|
+
call: (e) => {
|
|
1494
|
+
let t = k(e[0]), n = O(e[1]), r = O(e[2]), i = k(e[3]), a = B(t, n, r, i);
|
|
1495
|
+
if (a) return a;
|
|
1496
|
+
let o = Math.trunc(n), s = Math.trunc(r);
|
|
1497
|
+
if (o < 1) return _("#VALUE!", "The start position must be at least 1");
|
|
1498
|
+
if (s < 0) return _("#VALUE!", "The count cannot be negative");
|
|
1499
|
+
let c = t;
|
|
1500
|
+
return c.slice(0, o - 1) + i + c.slice(o - 1 + s);
|
|
1501
|
+
}
|
|
1502
|
+
},
|
|
1503
|
+
{
|
|
1504
|
+
name: "FIND",
|
|
1505
|
+
category: "text",
|
|
1506
|
+
syntax: "FIND(search_for, text, [start])",
|
|
1507
|
+
description: "Returns the position of a text inside another, matching case.",
|
|
1508
|
+
minArgs: 2,
|
|
1509
|
+
maxArgs: 3,
|
|
1510
|
+
call: (e) => We(e, !0)
|
|
1511
|
+
},
|
|
1512
|
+
{
|
|
1513
|
+
name: "SEARCH",
|
|
1514
|
+
category: "text",
|
|
1515
|
+
syntax: "SEARCH(search_for, text, [start])",
|
|
1516
|
+
description: "Returns the position of a text inside another, ignoring case and allowing wildcards.",
|
|
1517
|
+
minArgs: 2,
|
|
1518
|
+
maxArgs: 3,
|
|
1519
|
+
call: (e) => We(e, !1)
|
|
1520
|
+
},
|
|
1521
|
+
{
|
|
1522
|
+
name: "REPT",
|
|
1523
|
+
category: "text",
|
|
1524
|
+
syntax: "REPT(text, times)",
|
|
1525
|
+
description: "Repeats a text a number of times.",
|
|
1526
|
+
minArgs: 2,
|
|
1527
|
+
maxArgs: 2,
|
|
1528
|
+
call: (e) => {
|
|
1529
|
+
let t = k(e[0]), n = O(e[1]), r = B(t, n);
|
|
1530
|
+
if (r) return r;
|
|
1531
|
+
let i = Math.trunc(n);
|
|
1532
|
+
return i < 0 ? _("#VALUE!", "The count cannot be negative") : t.length * i > He ? _("#VALUE!", "The text would be too long") : t.repeat(i);
|
|
1533
|
+
}
|
|
1534
|
+
},
|
|
1535
|
+
{
|
|
1536
|
+
name: "EXACT",
|
|
1537
|
+
category: "text",
|
|
1538
|
+
syntax: "EXACT(text1, text2)",
|
|
1539
|
+
description: "Returns TRUE when two texts are the same, including case.",
|
|
1540
|
+
minArgs: 2,
|
|
1541
|
+
maxArgs: 2,
|
|
1542
|
+
call: (e) => {
|
|
1543
|
+
let t = k(e[0]), n = k(e[1]);
|
|
1544
|
+
return B(t, n) ?? t === n;
|
|
1545
|
+
}
|
|
1546
|
+
},
|
|
1547
|
+
{
|
|
1548
|
+
name: "VALUE",
|
|
1549
|
+
category: "text",
|
|
1550
|
+
syntax: "VALUE(text)",
|
|
1551
|
+
description: "Converts a text that looks like a number into the number.",
|
|
1552
|
+
minArgs: 1,
|
|
1553
|
+
maxArgs: 1,
|
|
1554
|
+
call: (e) => {
|
|
1555
|
+
let t = C(e[0]);
|
|
1556
|
+
if (typeof t == "number" || v(t)) return t;
|
|
1557
|
+
let n = typeof t == "string" ? w(t) : null;
|
|
1558
|
+
return n === null ? _("#VALUE!", "The text is not a number") : n;
|
|
1559
|
+
}
|
|
1560
|
+
}
|
|
1561
|
+
], Ke = [
|
|
1562
|
+
...Re,
|
|
1563
|
+
...Ve,
|
|
1564
|
+
...we,
|
|
1565
|
+
...Ge,
|
|
1566
|
+
...je,
|
|
1567
|
+
...xe
|
|
1568
|
+
].sort((e, t) => e.name < t.name ? -1 : e.name > t.name ? 1 : 0), qe = new Map(Ke.map((e) => [e.name, e])), Je = Object.freeze(Ke.map(({ name: e, category: t, syntax: n, description: r, minArgs: i, maxArgs: a }) => Object.freeze({
|
|
1569
|
+
name: e,
|
|
1570
|
+
category: t,
|
|
1571
|
+
syntax: n,
|
|
1572
|
+
description: r,
|
|
1573
|
+
minArgs: i,
|
|
1574
|
+
maxArgs: a
|
|
1575
|
+
})));
|
|
1576
|
+
function Ye(e) {
|
|
1577
|
+
let t = e.trim().toUpperCase();
|
|
1578
|
+
return Je.filter((e) => e.name.startsWith(t));
|
|
1579
|
+
}
|
|
1580
|
+
//#endregion
|
|
1581
|
+
//#region src/formula/evaluator.ts
|
|
1582
|
+
function X(e, t, n) {
|
|
1583
|
+
if (v(t)) return t;
|
|
1584
|
+
if (v(n)) return n;
|
|
1585
|
+
if (e === "&") {
|
|
1586
|
+
let e = E(t);
|
|
1587
|
+
if (v(e)) return e;
|
|
1588
|
+
let r = E(n);
|
|
1589
|
+
return v(r) ? r : e + r;
|
|
1590
|
+
}
|
|
1591
|
+
if (e === "=" || e === "<>" || e === "<" || e === ">" || e === "<=" || e === ">=") {
|
|
1592
|
+
let r = M(t, n);
|
|
1593
|
+
switch (e) {
|
|
1594
|
+
case "=": return r === 0;
|
|
1595
|
+
case "<>": return r !== 0;
|
|
1596
|
+
case "<": return r < 0;
|
|
1597
|
+
case ">": return r > 0;
|
|
1598
|
+
case "<=": return r <= 0;
|
|
1599
|
+
default: return r >= 0;
|
|
1600
|
+
}
|
|
1601
|
+
}
|
|
1602
|
+
let r = T(t);
|
|
1603
|
+
if (v(r)) return r;
|
|
1604
|
+
let i = T(n);
|
|
1605
|
+
if (v(i)) return i;
|
|
1606
|
+
let a;
|
|
1607
|
+
switch (e) {
|
|
1608
|
+
case "+":
|
|
1609
|
+
a = r + i;
|
|
1610
|
+
break;
|
|
1611
|
+
case "-":
|
|
1612
|
+
a = r - i;
|
|
1613
|
+
break;
|
|
1614
|
+
case "*":
|
|
1615
|
+
a = r * i;
|
|
1616
|
+
break;
|
|
1617
|
+
case "/":
|
|
1618
|
+
if (i === 0) return _("#DIV/0!", "Division by zero");
|
|
1619
|
+
a = r / i;
|
|
1620
|
+
break;
|
|
1621
|
+
default:
|
|
1622
|
+
if (r === 0 && i === 0) return _("#NUM!", "Zero to the power of zero");
|
|
1623
|
+
if (r === 0 && i < 0) return _("#DIV/0!", "Division by zero");
|
|
1624
|
+
a = r ** +i;
|
|
1625
|
+
}
|
|
1626
|
+
return le(a);
|
|
1627
|
+
}
|
|
1628
|
+
var Xe = (e) => !y(e) || e.rows === 1 && e.cols === 1;
|
|
1629
|
+
function Ze(e, t, n) {
|
|
1630
|
+
if (Xe(e) && Xe(t)) return n(C(e), C(t));
|
|
1631
|
+
let r = y(e) ? e : b(1, 1, [e]), i = y(t) ? t : b(1, 1, [t]), a = Math.max(r.rows, i.rows), o = Math.max(r.cols, i.cols), s = (e, t, n) => {
|
|
1632
|
+
let r = e.rows === 1 ? 0 : t, i = e.cols === 1 ? 0 : n;
|
|
1633
|
+
return r >= e.rows || i >= e.cols ? _("#N/A", "The ranges differ in size") : e.get(r, i);
|
|
1634
|
+
}, c = [];
|
|
1635
|
+
for (let e = 0; e < a; e++) for (let t = 0; t < o; t++) c.push(n(s(r, e, t), s(i, e, t)));
|
|
1636
|
+
return b(a, o, c);
|
|
1637
|
+
}
|
|
1638
|
+
function Qe(e, t) {
|
|
1639
|
+
let n = (e) => e === 1 ? "argument" : "arguments";
|
|
1640
|
+
return e === t ? `${e} ${n(e)}` : t === Infinity ? `at least ${e} ${n(e)}` : `between ${e} and ${t} arguments`;
|
|
1641
|
+
}
|
|
1642
|
+
function Z(e, t) {
|
|
1643
|
+
switch (e.type) {
|
|
1644
|
+
case "number":
|
|
1645
|
+
case "string":
|
|
1646
|
+
case "boolean": return e.value;
|
|
1647
|
+
case "error": return e.error;
|
|
1648
|
+
case "missing": return null;
|
|
1649
|
+
case "name": return _("#NAME?", `Unknown name ${e.name}`);
|
|
1650
|
+
case "ref": return ae(t, {
|
|
1651
|
+
r1: e.row,
|
|
1652
|
+
c1: e.col,
|
|
1653
|
+
r2: e.row,
|
|
1654
|
+
c2: e.col
|
|
1655
|
+
});
|
|
1656
|
+
case "range": return ae(t, e.range);
|
|
1657
|
+
case "unary": return Ze(Z(e.operand, t), 0, (t) => e.op === "-" ? X("-", 0, t) : X("+", 0, t));
|
|
1658
|
+
case "percent": return Ze(Z(e.operand, t), 100, (e, t) => X("/", e, t));
|
|
1659
|
+
case "binary": return Ze(Z(e.left, t), Z(e.right, t), (t, n) => X(e.op, t, n));
|
|
1660
|
+
case "call": {
|
|
1661
|
+
let n = qe.get(e.name);
|
|
1662
|
+
if (!n) return _("#NAME?", `Unknown function ${e.name}`);
|
|
1663
|
+
let r = e.args.length;
|
|
1664
|
+
if (r < n.minArgs || r > n.maxArgs) return _("#N/A", `${e.name} expects ${Qe(n.minArgs, n.maxArgs)}`);
|
|
1665
|
+
let i = (e) => Z(e, t);
|
|
1666
|
+
return le(n.lazy ? n.lazy(e.args, t, i) : n.call ? n.call(e.args.map(i), t) : _("#NAME?", `Unknown function ${e.name}`));
|
|
1667
|
+
}
|
|
1668
|
+
}
|
|
1669
|
+
}
|
|
1670
|
+
function $e(e) {
|
|
1671
|
+
let t = C(e);
|
|
1672
|
+
return t === null ? 0 : le(t);
|
|
1673
|
+
}
|
|
1674
|
+
function et(e, t) {
|
|
1675
|
+
try {
|
|
1676
|
+
return $e(Z(e, t));
|
|
1677
|
+
} catch (e) {
|
|
1678
|
+
if (e instanceof RangeError) return _("#ERROR!", "The formula is nested too deeply");
|
|
1679
|
+
throw e;
|
|
1680
|
+
}
|
|
1681
|
+
}
|
|
1682
|
+
//#endregion
|
|
1683
|
+
//#region src/formula/parser.ts
|
|
1684
|
+
var tt = class extends Error {}, nt = {
|
|
1685
|
+
"=": 10,
|
|
1686
|
+
"<>": 10,
|
|
1687
|
+
"<": 10,
|
|
1688
|
+
">": 10,
|
|
1689
|
+
"<=": 10,
|
|
1690
|
+
">=": 10,
|
|
1691
|
+
"&": 20,
|
|
1692
|
+
"+": 30,
|
|
1693
|
+
"-": 30,
|
|
1694
|
+
"*": 40,
|
|
1695
|
+
"/": 40,
|
|
1696
|
+
"^": 50,
|
|
1697
|
+
":": 80
|
|
1698
|
+
}, rt = 60, it = 70;
|
|
1699
|
+
function at(e, t = s) {
|
|
1700
|
+
let n = g(e, t).filter((e) => e.type !== "whitespace");
|
|
1701
|
+
n.length > 0 && n[0].type === "operator" && n[0].text === "=" && n.shift();
|
|
1702
|
+
let i = 0, c = () => n[i], l = () => n[i++], u = (e) => {
|
|
1703
|
+
throw new tt(e);
|
|
1704
|
+
}, d = (e) => e ? `Unexpected "${e.text}"` : "The formula ends too early", f = (e) => {
|
|
1705
|
+
let t = h();
|
|
1706
|
+
for (;;) {
|
|
1707
|
+
let n = c();
|
|
1708
|
+
if (!n || n.type !== "operator") break;
|
|
1709
|
+
if (n.text === "%") {
|
|
1710
|
+
if (rt <= e) break;
|
|
1711
|
+
i++, t = {
|
|
1712
|
+
type: "percent",
|
|
1713
|
+
operand: t
|
|
1714
|
+
};
|
|
1715
|
+
continue;
|
|
1716
|
+
}
|
|
1717
|
+
let r = nt[n.text];
|
|
1718
|
+
if (r === void 0 || r <= e) break;
|
|
1719
|
+
i++;
|
|
1720
|
+
let a = f(r);
|
|
1721
|
+
t = n.text === ":" ? m(t, a) : p(n.text, t, a);
|
|
1722
|
+
}
|
|
1723
|
+
return t;
|
|
1724
|
+
}, p = (e, t, n) => ({
|
|
1725
|
+
type: "binary",
|
|
1726
|
+
op: e,
|
|
1727
|
+
left: t,
|
|
1728
|
+
right: n
|
|
1729
|
+
}), m = (e, t) => {
|
|
1730
|
+
let n = (e) => e.type === "ref" ? {
|
|
1731
|
+
r1: e.row,
|
|
1732
|
+
c1: e.col,
|
|
1733
|
+
r2: e.row,
|
|
1734
|
+
c2: e.col
|
|
1735
|
+
} : e.type === "range" ? e.range : null, r = n(e), i = n(t);
|
|
1736
|
+
return !r || !i ? u("A range needs a reference on each side of \":\"") : {
|
|
1737
|
+
type: "range",
|
|
1738
|
+
range: o(Math.min(r.r1, i.r1), Math.min(r.c1, i.c1), Math.max(r.r2, i.r2), Math.max(r.c2, i.c2))
|
|
1739
|
+
};
|
|
1740
|
+
}, h = () => {
|
|
1741
|
+
let e = l();
|
|
1742
|
+
if (!e) return u(d(e));
|
|
1743
|
+
switch (e.type) {
|
|
1744
|
+
case "number": return {
|
|
1745
|
+
type: "number",
|
|
1746
|
+
value: Number(e.text.replace(t.decimal, "."))
|
|
1747
|
+
};
|
|
1748
|
+
case "string": return {
|
|
1749
|
+
type: "string",
|
|
1750
|
+
value: e.text.slice(1, -1).replace(/""/g, "\"")
|
|
1751
|
+
};
|
|
1752
|
+
case "boolean": return {
|
|
1753
|
+
type: "boolean",
|
|
1754
|
+
value: e.text.toUpperCase() === "TRUE"
|
|
1755
|
+
};
|
|
1756
|
+
case "error": return {
|
|
1757
|
+
type: "error",
|
|
1758
|
+
error: _(e.text.toUpperCase())
|
|
1759
|
+
};
|
|
1760
|
+
case "reference": {
|
|
1761
|
+
let t = r(e.text);
|
|
1762
|
+
return t ? {
|
|
1763
|
+
type: "ref",
|
|
1764
|
+
...t
|
|
1765
|
+
} : u(`"${e.text}" is not a reference`);
|
|
1766
|
+
}
|
|
1767
|
+
case "range": {
|
|
1768
|
+
let t = a(e.text);
|
|
1769
|
+
return t ? {
|
|
1770
|
+
type: "range",
|
|
1771
|
+
range: t
|
|
1772
|
+
} : u(`"${e.text}" is not a range`);
|
|
1773
|
+
}
|
|
1774
|
+
case "name": return {
|
|
1775
|
+
type: "name",
|
|
1776
|
+
name: e.text
|
|
1777
|
+
};
|
|
1778
|
+
case "function": return te(e.text);
|
|
1779
|
+
case "paren":
|
|
1780
|
+
if (e.text === "(") {
|
|
1781
|
+
let e = f(0), t = l();
|
|
1782
|
+
return (!t || t.text !== ")") && u("A parenthesis is not closed"), e;
|
|
1783
|
+
}
|
|
1784
|
+
return u(d(e));
|
|
1785
|
+
case "operator": return e.text === "-" || e.text === "+" ? {
|
|
1786
|
+
type: "unary",
|
|
1787
|
+
op: e.text,
|
|
1788
|
+
operand: f(it)
|
|
1789
|
+
} : u(d(e));
|
|
1790
|
+
default: return e.text.startsWith("\"") ? u("A text value is missing its closing quote") : u(d(e));
|
|
1791
|
+
}
|
|
1792
|
+
}, ee = (e) => !!e && (e.type === "separator" || e.type === "paren" && e.text === ")"), te = (e) => {
|
|
1793
|
+
l();
|
|
1794
|
+
let t = [];
|
|
1795
|
+
if (c()?.type === "paren" && c()?.text === ")") return i++, {
|
|
1796
|
+
type: "call",
|
|
1797
|
+
name: e.toUpperCase(),
|
|
1798
|
+
args: t
|
|
1799
|
+
};
|
|
1800
|
+
for (;;) {
|
|
1801
|
+
t.push(ee(c()) ? { type: "missing" } : f(0));
|
|
1802
|
+
let n = l();
|
|
1803
|
+
if (n?.type !== "separator") {
|
|
1804
|
+
if (n?.type === "paren" && n.text === ")") break;
|
|
1805
|
+
u(n ? d(n) : `${e.toUpperCase()} is missing a ")"`);
|
|
1806
|
+
}
|
|
1807
|
+
}
|
|
1808
|
+
return {
|
|
1809
|
+
type: "call",
|
|
1810
|
+
name: e.toUpperCase(),
|
|
1811
|
+
args: t
|
|
1812
|
+
};
|
|
1813
|
+
};
|
|
1814
|
+
try {
|
|
1815
|
+
n.length === 0 && u("The formula is empty");
|
|
1816
|
+
let e = f(0);
|
|
1817
|
+
return i < n.length && u(d(n[i])), e;
|
|
1818
|
+
} catch (e) {
|
|
1819
|
+
return {
|
|
1820
|
+
type: "error",
|
|
1821
|
+
error: _("#ERROR!", e instanceof tt ? e.message : e instanceof RangeError ? "The formula is nested too deeply" : "The formula could not be read")
|
|
1822
|
+
};
|
|
1823
|
+
}
|
|
1824
|
+
}
|
|
1825
|
+
function ot(e, t = []) {
|
|
1826
|
+
let n = [e];
|
|
1827
|
+
for (; n.length > 0;) {
|
|
1828
|
+
let e = n.pop();
|
|
1829
|
+
switch (e.type) {
|
|
1830
|
+
case "ref":
|
|
1831
|
+
case "range":
|
|
1832
|
+
t.push(e);
|
|
1833
|
+
break;
|
|
1834
|
+
case "call":
|
|
1835
|
+
for (let t of e.args) n.push(t);
|
|
1836
|
+
break;
|
|
1837
|
+
case "unary":
|
|
1838
|
+
case "percent":
|
|
1839
|
+
n.push(e.operand);
|
|
1840
|
+
break;
|
|
1841
|
+
case "binary":
|
|
1842
|
+
n.push(e.left, e.right);
|
|
1843
|
+
break;
|
|
1844
|
+
}
|
|
1845
|
+
}
|
|
1846
|
+
return t;
|
|
1847
|
+
}
|
|
1848
|
+
//#endregion
|
|
1849
|
+
//#region src/formula/sheet.ts
|
|
1850
|
+
var st = 2e4, Q = (e, t) => e * st + t, $ = () => _("#REF!", "Circular reference");
|
|
1851
|
+
function ct(e) {
|
|
1852
|
+
return e === void 0 || e === "" ? null : typeof e == "number" && !Number.isFinite(e) ? _("#NUM!", "The value is not a finite number") : e;
|
|
1853
|
+
}
|
|
1854
|
+
function lt(e) {
|
|
1855
|
+
let t = at(e);
|
|
1856
|
+
return {
|
|
1857
|
+
tree: t,
|
|
1858
|
+
reads: ot(t)
|
|
1859
|
+
};
|
|
1860
|
+
}
|
|
1861
|
+
function ut() {
|
|
1862
|
+
let e = /* @__PURE__ */ new Map(), t = /* @__PURE__ */ new Map(), n = /* @__PURE__ */ new Map(), a = /* @__PURE__ */ new Map(), o = {
|
|
1863
|
+
rows: 0,
|
|
1864
|
+
cols: 0
|
|
1865
|
+
}, s = (e) => ({
|
|
1866
|
+
cell(e, t) {
|
|
1867
|
+
let r = Q(e, t), i = n.get(r);
|
|
1868
|
+
return ie(i) ? a.get(r) ?? $() : ct(i);
|
|
1869
|
+
},
|
|
1870
|
+
extent: o,
|
|
1871
|
+
at: e
|
|
1872
|
+
});
|
|
1873
|
+
function c(t) {
|
|
1874
|
+
let c = /* @__PURE__ */ new Map();
|
|
1875
|
+
n = /* @__PURE__ */ new Map(), a = /* @__PURE__ */ new Map(), o = {
|
|
1876
|
+
rows: 0,
|
|
1877
|
+
cols: 0
|
|
1878
|
+
};
|
|
1879
|
+
let l = [], u = /* @__PURE__ */ new Map();
|
|
1880
|
+
for (let a of Object.keys(t)) {
|
|
1881
|
+
let s = r(a);
|
|
1882
|
+
if (!s) continue;
|
|
1883
|
+
let d = t[a];
|
|
1884
|
+
if (d == null || d === "") continue;
|
|
1885
|
+
let f = Q(s.row, s.col);
|
|
1886
|
+
if (n.set(f, d), o.rows = Math.max(o.rows, s.row + 1), o.cols = Math.max(o.cols, s.col + 1), ie(d)) {
|
|
1887
|
+
let t = c.get(d) ?? e.get(d) ?? lt(d);
|
|
1888
|
+
c.set(d, t), u.set(f, l.length), l.push({
|
|
1889
|
+
key: f,
|
|
1890
|
+
ref: i(s.row, s.col),
|
|
1891
|
+
...s,
|
|
1892
|
+
parsed: t
|
|
1893
|
+
});
|
|
1894
|
+
}
|
|
1895
|
+
}
|
|
1896
|
+
e = c;
|
|
1897
|
+
let d = l.map((e) => {
|
|
1898
|
+
let t = [];
|
|
1899
|
+
for (let n of e.parsed.reads) if (n.type === "ref") {
|
|
1900
|
+
let e = u.get(Q(n.row, n.col));
|
|
1901
|
+
e !== void 0 && t.push(e);
|
|
1902
|
+
} else if (n.type === "range") {
|
|
1903
|
+
let e = Math.min(n.range.r2, o.rows - 1), r = Math.min(n.range.c2, o.cols - 1), { r1: i, c1: a } = n.range;
|
|
1904
|
+
if (Math.max(0, e - i + 1) * Math.max(0, r - a + 1) <= l.length) for (let n = i; n <= e; n++) for (let e = a; e <= r; e++) {
|
|
1905
|
+
let r = u.get(Q(n, e));
|
|
1906
|
+
r !== void 0 && t.push(r);
|
|
1907
|
+
}
|
|
1908
|
+
else l.forEach((n, o) => {
|
|
1909
|
+
n.row >= i && n.row <= e && n.col >= a && n.col <= r && t.push(o);
|
|
1910
|
+
});
|
|
1911
|
+
}
|
|
1912
|
+
return t;
|
|
1913
|
+
});
|
|
1914
|
+
for (let e of dt(d)) {
|
|
1915
|
+
let t = e[0];
|
|
1916
|
+
if (e.length > 1 || d[t].includes(t)) {
|
|
1917
|
+
for (let t of e) a.set(l[t].key, $());
|
|
1918
|
+
continue;
|
|
1919
|
+
}
|
|
1920
|
+
let n = l[t];
|
|
1921
|
+
a.set(n.key, et(n.parsed.tree, s({
|
|
1922
|
+
row: n.row,
|
|
1923
|
+
col: n.col
|
|
1924
|
+
})));
|
|
1925
|
+
}
|
|
1926
|
+
let f = /* @__PURE__ */ new Map();
|
|
1927
|
+
for (let e of l) f.set(e.ref, a.get(e.key) ?? $());
|
|
1928
|
+
return f;
|
|
1929
|
+
}
|
|
1930
|
+
function l(e) {
|
|
1931
|
+
let n = t.get(e);
|
|
1932
|
+
return n || (t.size > 500 && t.clear(), n = lt(e), t.set(e, n)), et(n.tree, s());
|
|
1933
|
+
}
|
|
1934
|
+
return {
|
|
1935
|
+
compute: c,
|
|
1936
|
+
evaluate: l,
|
|
1937
|
+
get cacheSize() {
|
|
1938
|
+
return e.size;
|
|
1939
|
+
}
|
|
1940
|
+
};
|
|
1941
|
+
}
|
|
1942
|
+
function dt(e) {
|
|
1943
|
+
let t = e.length, n = new Int32Array(t).fill(-1), r = new Int32Array(t), i = new Uint8Array(t), a = [], o = [], s = 0;
|
|
1944
|
+
for (let c = 0; c < t; c++) {
|
|
1945
|
+
if (n[c] !== -1) continue;
|
|
1946
|
+
let t = [c], l = [0];
|
|
1947
|
+
for (n[c] = r[c] = s++, a.push(c), i[c] = 1; t.length > 0;) {
|
|
1948
|
+
let c = t.length - 1, u = t[c], d = e[u][l[c]];
|
|
1949
|
+
if (d !== void 0) {
|
|
1950
|
+
l[c]++, n[d] === -1 ? (n[d] = r[d] = s++, a.push(d), i[d] = 1, t.push(d), l.push(0)) : i[d] && (r[u] = Math.min(r[u], n[d]));
|
|
1951
|
+
continue;
|
|
1952
|
+
}
|
|
1953
|
+
if (t.pop(), l.pop(), t.length > 0) {
|
|
1954
|
+
let e = t[t.length - 1];
|
|
1955
|
+
r[e] = Math.min(r[e], r[u]);
|
|
1956
|
+
}
|
|
1957
|
+
if (r[u] === n[u]) {
|
|
1958
|
+
let e = [], t;
|
|
1959
|
+
do
|
|
1960
|
+
t = a.pop(), i[t] = 0, e.push(t);
|
|
1961
|
+
while (t !== u);
|
|
1962
|
+
o.push(e);
|
|
1963
|
+
}
|
|
1964
|
+
}
|
|
1965
|
+
}
|
|
1966
|
+
return o;
|
|
1967
|
+
}
|
|
1968
|
+
//#endregion
|
|
1969
|
+
export { r as _, be as a, pe as c, s as d, g as f, a as g, t as h, me as i, ie as l, i as m, Je as n, ue as o, e as p, Ye as r, fe as s, ut as t, v as u };
|