@gridsheet/core 3.0.0-rc.10
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 +17 -0
- package/dist/constants.d.ts +21 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +28 -0
- package/dist/constants.js.map +1 -0
- package/dist/formula/evaluator.d.ts +134 -0
- package/dist/formula/evaluator.d.ts.map +1 -0
- package/dist/formula/evaluator.js +585 -0
- package/dist/formula/evaluator.js.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/formula-error.js +15 -0
- package/dist/formula/formula-error.js.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/__async.js +70 -0
- package/dist/formula/functions/__async.js.map +1 -0
- package/dist/formula/functions/__base.d.ts +112 -0
- package/dist/formula/functions/__base.d.ts.map +1 -0
- package/dist/formula/functions/__base.js +265 -0
- package/dist/formula/functions/__base.js.map +1 -0
- package/dist/formula/functions/__utils.d.ts +28 -0
- package/dist/formula/functions/__utils.d.ts.map +1 -0
- package/dist/formula/functions/__utils.js +179 -0
- package/dist/formula/functions/__utils.js.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/abs.js +15 -0
- package/dist/formula/functions/abs.js.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/add.js +37 -0
- package/dist/formula/functions/add.js.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/and.js +23 -0
- package/dist/formula/functions/and.js.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/arrayformula.js +24 -0
- package/dist/formula/functions/arrayformula.js.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/average.js +40 -0
- package/dist/formula/functions/average.js.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/concat.js +27 -0
- package/dist/formula/functions/concat.js.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/count.js +32 -0
- package/dist/formula/functions/count.js.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/counta.js +32 -0
- package/dist/formula/functions/counta.js.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/divide.js +34 -0
- package/dist/formula/functions/divide.js.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/eq.js +19 -0
- package/dist/formula/functions/eq.js.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/gt.js +19 -0
- package/dist/formula/functions/gt.js.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/gte.js +19 -0
- package/dist/formula/functions/gte.js.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/if.js +29 -0
- package/dist/formula/functions/if.js.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/iferror.js +28 -0
- package/dist/formula/functions/iferror.js.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/len.js +21 -0
- package/dist/formula/functions/len.js.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/lt.js +19 -0
- package/dist/formula/functions/lt.js.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/lte.js +19 -0
- package/dist/formula/functions/lte.js.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/max.js +37 -0
- package/dist/formula/functions/max.js.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/min.js +37 -0
- package/dist/formula/functions/min.js.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/minus.js +41 -0
- package/dist/formula/functions/minus.js.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/multiply.js +19 -0
- package/dist/formula/functions/multiply.js.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/ne.js +19 -0
- package/dist/formula/functions/ne.js.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/not.js +22 -0
- package/dist/formula/functions/not.js.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/now.js +14 -0
- package/dist/formula/functions/now.js.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/or.js +23 -0
- package/dist/formula/functions/or.js.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/power.js +18 -0
- package/dist/formula/functions/power.js.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/sum.js +34 -0
- package/dist/formula/functions/sum.js.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/functions/uminus.js +17 -0
- package/dist/formula/functions/uminus.js.map +1 -0
- package/dist/formula/mapping.d.ts +11 -0
- package/dist/formula/mapping.d.ts.map +1 -0
- package/dist/formula/mapping.js +82 -0
- package/dist/formula/mapping.js.map +1 -0
- package/dist/formula/solver.d.ts +39 -0
- package/dist/formula/solver.d.ts.map +1 -0
- package/dist/formula/solver.js +71 -0
- package/dist/formula/solver.js.map +1 -0
- package/dist/index.d.ts +32 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +132 -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/autofill.js +276 -0
- package/dist/lib/autofill.js.map +1 -0
- package/dist/lib/book.d.ts +131 -0
- package/dist/lib/book.d.ts.map +1 -0
- package/dist/lib/book.js +53 -0
- package/dist/lib/book.js.map +1 -0
- package/dist/lib/cell.d.ts +17 -0
- package/dist/lib/cell.d.ts.map +1 -0
- package/dist/lib/cell.js +17 -0
- package/dist/lib/cell.js.map +1 -0
- package/dist/lib/coords.d.ts +22 -0
- package/dist/lib/coords.d.ts.map +1 -0
- package/dist/lib/coords.js +73 -0
- package/dist/lib/coords.js.map +1 -0
- package/dist/lib/date.d.ts +2 -0
- package/dist/lib/date.d.ts.map +1 -0
- package/dist/lib/date.js +91 -0
- package/dist/lib/date.js.map +1 -0
- package/dist/lib/dom.d.ts +7 -0
- package/dist/lib/dom.d.ts.map +1 -0
- package/dist/lib/dom.js +28 -0
- package/dist/lib/dom.js.map +1 -0
- package/dist/lib/filter.d.ts +7 -0
- package/dist/lib/filter.d.ts.map +1 -0
- package/dist/lib/filter.js +122 -0
- package/dist/lib/filter.js.map +1 -0
- package/dist/lib/input.d.ts +28 -0
- package/dist/lib/input.d.ts.map +1 -0
- package/dist/lib/input.js +73 -0
- package/dist/lib/input.js.map +1 -0
- package/dist/lib/label.d.ts +4 -0
- package/dist/lib/label.d.ts.map +1 -0
- package/dist/lib/label.js +10 -0
- package/dist/lib/label.js.map +1 -0
- package/dist/lib/operation.d.ts +31 -0
- package/dist/lib/operation.d.ts.map +1 -0
- package/dist/lib/operation.js +36 -0
- package/dist/lib/operation.js.map +1 -0
- package/dist/lib/palette.d.ts +2 -0
- package/dist/lib/palette.d.ts.map +1 -0
- package/dist/lib/palette.js +26 -0
- package/dist/lib/palette.js.map +1 -0
- package/dist/lib/popup.d.ts +24 -0
- package/dist/lib/popup.d.ts.map +1 -0
- package/dist/lib/popup.js +21 -0
- package/dist/lib/popup.js.map +1 -0
- package/dist/lib/reference.d.ts +19 -0
- package/dist/lib/reference.d.ts.map +1 -0
- package/dist/lib/reference.js +40 -0
- package/dist/lib/reference.js.map +1 -0
- package/dist/lib/sheet.d.ts +512 -0
- package/dist/lib/sheet.d.ts.map +1 -0
- package/dist/lib/sheet.js +1530 -0
- package/dist/lib/sheet.js.map +1 -0
- package/dist/lib/sheet_utils.d.ts +55 -0
- package/dist/lib/sheet_utils.d.ts.map +1 -0
- package/dist/lib/sheet_utils.js +125 -0
- package/dist/lib/sheet_utils.js.map +1 -0
- package/dist/lib/spatial.d.ts +79 -0
- package/dist/lib/spatial.d.ts.map +1 -0
- package/dist/lib/spatial.js +227 -0
- package/dist/lib/spatial.js.map +1 -0
- package/dist/lib/time.d.ts +29 -0
- package/dist/lib/time.d.ts.map +1 -0
- package/dist/lib/time.js +113 -0
- package/dist/lib/time.js.map +1 -0
- package/dist/lib/virtualization.d.ts +22 -0
- package/dist/lib/virtualization.d.ts.map +1 -0
- package/dist/lib/virtualization.js +91 -0
- package/dist/lib/virtualization.js.map +1 -0
- package/dist/policy/core.d.ts +161 -0
- package/dist/policy/core.d.ts.map +1 -0
- package/dist/policy/core.js +248 -0
- package/dist/policy/core.js.map +1 -0
- package/dist/policy/thousand_separator.d.ts +4 -0
- package/dist/policy/thousand_separator.d.ts.map +1 -0
- package/dist/policy/thousand_separator.js +13 -0
- package/dist/policy/thousand_separator.js.map +1 -0
- package/dist/sentinels.d.ts +40 -0
- package/dist/sentinels.d.ts.map +1 -0
- package/dist/sentinels.js +41 -0
- package/dist/sentinels.js.map +1 -0
- package/dist/styles/embedder.d.ts +2 -0
- package/dist/styles/embedder.d.ts.map +1 -0
- package/dist/styles/embedder.js +11 -0
- package/dist/styles/embedder.js.map +1 -0
- package/dist/styles/minified.d.ts +3 -0
- package/dist/styles/minified.d.ts.map +1 -0
- package/dist/styles/minified.js +6 -0
- package/dist/styles/minified.js.map +1 -0
- package/dist/types.d.ts +310 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/dist/utils.d.ts +2 -0
- package/dist/utils.d.ts.map +1 -0
- package/dist/utils.js +5 -0
- package/dist/utils.js.map +1 -0
- package/package.json +58 -0
|
@@ -0,0 +1,585 @@
|
|
|
1
|
+
import { a2p as x, buildIdentifiedRef as F, grantAddressAbsolute as S } from "../lib/coords.js";
|
|
2
|
+
import { FormulaError as f } from "./formula-error.js";
|
|
3
|
+
const m = (h, e = !0) => {
|
|
4
|
+
let t = h;
|
|
5
|
+
return e && t.startsWith("$") && (t = t.slice(1)), e && t.endsWith("$") && (t = t.slice(0, -1)), t.replace("#", "");
|
|
6
|
+
};
|
|
7
|
+
class w {
|
|
8
|
+
constructor(e) {
|
|
9
|
+
this.ids = [], this.value = e;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
class N extends w {
|
|
13
|
+
evaluate() {
|
|
14
|
+
return this.value;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
class T extends w {
|
|
18
|
+
evaluate() {
|
|
19
|
+
throw new f("#REF!", "Reference does not exist.");
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
class _ extends w {
|
|
23
|
+
evaluate() {
|
|
24
|
+
throw new f("#NAME?", `Invalid ref: ${this.value}`);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
class b extends w {
|
|
28
|
+
constructor(e) {
|
|
29
|
+
super(e);
|
|
30
|
+
}
|
|
31
|
+
stringify() {
|
|
32
|
+
return this.value.toUpperCase();
|
|
33
|
+
}
|
|
34
|
+
evaluate({ sheet: e }) {
|
|
35
|
+
const t = R(this.value, { sheet: e, dependency: "" });
|
|
36
|
+
if (t.sheet == null)
|
|
37
|
+
throw new f("#REF!", `Unknown sheet: ${t.sheetName}`);
|
|
38
|
+
if (t.addresses.length === 0)
|
|
39
|
+
throw new f("#REF!", `Invalid address: ${this.value}`);
|
|
40
|
+
const { y: i, x: n } = x(t.addresses[0]);
|
|
41
|
+
return t.sheet.trim({ top: i, left: n, bottom: i, right: n });
|
|
42
|
+
}
|
|
43
|
+
identify(e) {
|
|
44
|
+
const { slideY: t = 0, slideX: i = 0 } = e, n = R(this.value, e);
|
|
45
|
+
if (n.sheet == null)
|
|
46
|
+
return this.value;
|
|
47
|
+
const s = n.addresses[0], { y: r, x: o, absX: l, absY: u } = x(s), p = {
|
|
48
|
+
y: r + t,
|
|
49
|
+
x: o + i,
|
|
50
|
+
absX: l,
|
|
51
|
+
absY: u
|
|
52
|
+
}, c = n.sheet.getId(p);
|
|
53
|
+
return c == null ? this.value : (this.ids = [c], `#${n.sheet.id}!${F(c, l, u)}`);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
class P extends w {
|
|
57
|
+
stringify() {
|
|
58
|
+
return this.value.toUpperCase();
|
|
59
|
+
}
|
|
60
|
+
evaluate({ sheet: e }) {
|
|
61
|
+
const t = R(this.value, { sheet: e, dependency: "" });
|
|
62
|
+
if (t.sheet == null)
|
|
63
|
+
throw new f("#REF!", `Unknown sheet: ${t.sheetName}`);
|
|
64
|
+
if (t.addresses.length === 0)
|
|
65
|
+
throw new f("#REF!", `Invalid address: ${this.value}`);
|
|
66
|
+
const i = t.sheet.rangeToArea(t.addresses.join(":"));
|
|
67
|
+
return t.sheet.trim(i);
|
|
68
|
+
}
|
|
69
|
+
identify(e) {
|
|
70
|
+
const { slideY: t = 0, slideX: i = 0 } = e, n = R(this.value, e);
|
|
71
|
+
if (n.sheet == null)
|
|
72
|
+
return this.value;
|
|
73
|
+
const s = [];
|
|
74
|
+
for (let r = 0; r < n.addresses.length; r++) {
|
|
75
|
+
const o = n.addresses[r], { y: l, x: u, absX: p, absY: c } = x(o), E = {
|
|
76
|
+
y: l + t,
|
|
77
|
+
x: u + i,
|
|
78
|
+
absX: p,
|
|
79
|
+
absY: c
|
|
80
|
+
}, y = n.sheet.getId(E);
|
|
81
|
+
if (y == null)
|
|
82
|
+
return this.value;
|
|
83
|
+
this.ids.push(y), s.push(F(y, p, c));
|
|
84
|
+
}
|
|
85
|
+
return `#${n.sheet.id}!${s.join(":")}`;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
class O extends w {
|
|
89
|
+
parse(e) {
|
|
90
|
+
if (this.value.indexOf("!") !== -1) {
|
|
91
|
+
const [t, i] = this.value.split("!"), n = Number(t.slice(1));
|
|
92
|
+
return { sheet: e.getSheetBySheetId(n), id: m(i, !1) };
|
|
93
|
+
}
|
|
94
|
+
return { sheet: e, id: m(this.value, !1) };
|
|
95
|
+
}
|
|
96
|
+
evaluate({ sheet: e }) {
|
|
97
|
+
const t = this.parse(e);
|
|
98
|
+
if (t.id === "?")
|
|
99
|
+
throw new f("#REF!", "Reference does not exist");
|
|
100
|
+
const { y: i, x: n } = t.sheet.getPointById(t.id), [s, r] = [Math.abs(i), Math.abs(n)];
|
|
101
|
+
return t.sheet.trim({
|
|
102
|
+
top: s,
|
|
103
|
+
left: r,
|
|
104
|
+
bottom: s,
|
|
105
|
+
right: r
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
display({ sheet: e, slideY: t = 0, slideX: i = 0 }) {
|
|
109
|
+
const n = this.parse(e), s = n.sheet.getAddressById(n.id, t, i);
|
|
110
|
+
return s ? n.sheet.id === e.id ? s : `${n.sheet.sheetPrefix()}${s}` : "#REF!";
|
|
111
|
+
}
|
|
112
|
+
identify(e) {
|
|
113
|
+
const { sheet: t, slideY: i = 0, slideX: n = 0 } = e, s = this.display({ sheet: t, slideY: i, slideX: n });
|
|
114
|
+
if (s == null || s.length < 2)
|
|
115
|
+
return "#?";
|
|
116
|
+
const { formula: r, ids: o } = R(s, e);
|
|
117
|
+
return this.ids = o, r || "#?";
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
class A extends w {
|
|
121
|
+
parse(e) {
|
|
122
|
+
const t = this.value;
|
|
123
|
+
if (t.indexOf("!") !== -1) {
|
|
124
|
+
const [i, n] = t.split("!"), s = Number(i.slice(1));
|
|
125
|
+
return { sheet: e.getSheetBySheetId(s), ids: n.split(":") };
|
|
126
|
+
}
|
|
127
|
+
return { sheet: e, ids: t.split(":") };
|
|
128
|
+
}
|
|
129
|
+
evaluate({ sheet: e }) {
|
|
130
|
+
const t = this.parse(e), i = t.ids.map((c) => m(c)), n = [];
|
|
131
|
+
for (let c = 0; c < i.length; c++) {
|
|
132
|
+
const E = i[c];
|
|
133
|
+
if (E === "?")
|
|
134
|
+
throw new f("#REF!", "Reference does not exist");
|
|
135
|
+
const y = t.sheet.getPointById(E);
|
|
136
|
+
n.push(y);
|
|
137
|
+
}
|
|
138
|
+
const [s, r] = n, [o, l, u, p] = [s.y, s.x, r.y || t.sheet.numRows, r.x || t.sheet.numCols];
|
|
139
|
+
return t.sheet.trim({ top: o, left: l, bottom: u, right: p });
|
|
140
|
+
}
|
|
141
|
+
display({ sheet: e, slideY: t = 0, slideX: i = 0 }) {
|
|
142
|
+
const n = this.parse(e), s = n.ids.map((r) => m(r, !1)).map((r) => n.sheet.getAddressById(r, t, i) || "#REF!").join(":");
|
|
143
|
+
return n.sheet.id === e.id ? s : `${n.sheet.sheetPrefix()}${s}`;
|
|
144
|
+
}
|
|
145
|
+
identify(e) {
|
|
146
|
+
const { sheet: t, slideY: i = 0, slideX: n = 0 } = e, s = this.display({ sheet: t, slideY: i, slideX: n }), { formula: r, ids: o } = R(s, e);
|
|
147
|
+
return this.ids = o, r ?? "";
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
class I {
|
|
151
|
+
constructor(e, t = 0, i = [], n) {
|
|
152
|
+
this.name = e, this.precedence = t, this.args = i, this.at = n;
|
|
153
|
+
}
|
|
154
|
+
evaluate({ sheet: e }) {
|
|
155
|
+
const t = this.name.toLowerCase(), i = e.getFunctionByName(t);
|
|
156
|
+
if (i == null)
|
|
157
|
+
throw new f("#NAME?", `Unknown function: ${t}`);
|
|
158
|
+
return new i({ args: this.args, sheet: e, at: this.at }).call();
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
const C = new N(0), U = {
|
|
162
|
+
"+": "add",
|
|
163
|
+
"-": "minus",
|
|
164
|
+
"/": "divide",
|
|
165
|
+
"*": "multiply",
|
|
166
|
+
"^": "power",
|
|
167
|
+
"&": "concat",
|
|
168
|
+
"=": "eq",
|
|
169
|
+
"<>": "ne",
|
|
170
|
+
">": "gt",
|
|
171
|
+
">=": "gte",
|
|
172
|
+
"<": "lt",
|
|
173
|
+
"<=": "lte"
|
|
174
|
+
}, L = {
|
|
175
|
+
"-": "uminus"
|
|
176
|
+
}, $ = /* @__PURE__ */ new Set([" ", `
|
|
177
|
+
`, "\r", " ", "\f"]), X = /* @__PURE__ */ new Set([...$, "+", "-", "/", "*", "^", "&", "=", "<", ">", ")", ",", "%"]);
|
|
178
|
+
class a {
|
|
179
|
+
constructor(e, t, i = 0, n, s = !0) {
|
|
180
|
+
this.type = e, this.entity = t, this.precedence = i, this.at = n, this.closed = s;
|
|
181
|
+
}
|
|
182
|
+
length() {
|
|
183
|
+
return this.type === "VALUE" && typeof this.entity == "string" ? this.entity.length + (this.closed ? 2 : 1) : new String(this.entity).length;
|
|
184
|
+
}
|
|
185
|
+
stringify() {
|
|
186
|
+
if (this.type === "VALUE") {
|
|
187
|
+
if (typeof this.entity == "string")
|
|
188
|
+
return this.closed ? `"${this.entity}"` : `"${this.entity}`;
|
|
189
|
+
if (typeof this.entity == "boolean")
|
|
190
|
+
return this.entity ? "TRUE" : "FALSE";
|
|
191
|
+
}
|
|
192
|
+
return this.entity;
|
|
193
|
+
}
|
|
194
|
+
convert() {
|
|
195
|
+
switch (this.type) {
|
|
196
|
+
case "VALUE":
|
|
197
|
+
return new N(this.entity);
|
|
198
|
+
case "ID":
|
|
199
|
+
return new O(this.entity);
|
|
200
|
+
case "ID_RANGE":
|
|
201
|
+
return new A(this.entity);
|
|
202
|
+
case "REF":
|
|
203
|
+
return new b(this.entity);
|
|
204
|
+
case "RANGE":
|
|
205
|
+
return new P(this.entity);
|
|
206
|
+
case "INFIX_OPERATOR": {
|
|
207
|
+
const e = U[this.entity];
|
|
208
|
+
return new I(e, this.precedence, void 0, this.at);
|
|
209
|
+
}
|
|
210
|
+
case "PREFIX_OPERATOR": {
|
|
211
|
+
const e = L[this.entity];
|
|
212
|
+
return new I(e, this.precedence, void 0, this.at);
|
|
213
|
+
}
|
|
214
|
+
case "FUNCTION":
|
|
215
|
+
return new I(this.entity, 0, [], this.at);
|
|
216
|
+
case "UNREFERENCED":
|
|
217
|
+
return new T(this.entity);
|
|
218
|
+
case "INVALID_REF":
|
|
219
|
+
return new _(this.entity);
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
const D = (h) => $.has(h), M = { true: !0, false: !1 }, v = new a("OPEN", "("), V = new a("CLOSE", ")"), B = new a("COMMA", ","), d = "INFIX_OPERATOR", j = "PREFIX_OPERATOR", G = "POSTFIX_OPERATOR";
|
|
224
|
+
class Z {
|
|
225
|
+
constructor(e, t) {
|
|
226
|
+
this.tokens = [], this.foreign = !1, this.identifiedFormula = "", this.dependencyIds = [], this.formula = e, this.index = 0, this.tokens = [], this.at = t == null ? void 0 : t.at;
|
|
227
|
+
}
|
|
228
|
+
isWhiteSpace() {
|
|
229
|
+
return D(this.formula[this.index]);
|
|
230
|
+
}
|
|
231
|
+
next(e = 1) {
|
|
232
|
+
this.index += e;
|
|
233
|
+
}
|
|
234
|
+
get(e = 0) {
|
|
235
|
+
return this.formula[this.index + e];
|
|
236
|
+
}
|
|
237
|
+
getToken(e = 0) {
|
|
238
|
+
return this.tokens[this.tokens.length + e];
|
|
239
|
+
}
|
|
240
|
+
getTokenIndexByCharPosition(e) {
|
|
241
|
+
let t = 0, i = 0;
|
|
242
|
+
for (let n = 0; n < this.tokens.length; n++) {
|
|
243
|
+
const s = this.tokens[n];
|
|
244
|
+
if (i = t + s.length(), t <= e && e <= i)
|
|
245
|
+
return [n, e === t || e === i];
|
|
246
|
+
t = i;
|
|
247
|
+
}
|
|
248
|
+
return [-1, !1];
|
|
249
|
+
}
|
|
250
|
+
getTokenPositionRange(e, t = 1) {
|
|
251
|
+
let i = 0, n = 0;
|
|
252
|
+
for (let s = 0; s < e; s++)
|
|
253
|
+
i = n, n += this.tokens[s].length();
|
|
254
|
+
return [i + t, n + t];
|
|
255
|
+
}
|
|
256
|
+
stringify() {
|
|
257
|
+
return this.tokens.map((e) => e.stringify()).join("");
|
|
258
|
+
}
|
|
259
|
+
identify(e) {
|
|
260
|
+
const t = [], i = [];
|
|
261
|
+
for (const n of this.tokens)
|
|
262
|
+
switch (n.type) {
|
|
263
|
+
case "VALUE":
|
|
264
|
+
typeof n.entity == "number" || typeof n.entity == "boolean" ? t.push(String(n.entity)) : t.push(n.closed ? `"${n.entity}"` : `"${n.entity}`);
|
|
265
|
+
break;
|
|
266
|
+
case "ID": {
|
|
267
|
+
const s = new O(n.entity);
|
|
268
|
+
t.push(s.identify(e)), i.push(...s.ids);
|
|
269
|
+
break;
|
|
270
|
+
}
|
|
271
|
+
case "ID_RANGE": {
|
|
272
|
+
const s = new A(n.entity);
|
|
273
|
+
t.push(s.identify(e)), i.push(...s.ids);
|
|
274
|
+
break;
|
|
275
|
+
}
|
|
276
|
+
case "REF": {
|
|
277
|
+
const s = new b(n.entity);
|
|
278
|
+
t.push(s.identify(e)), i.push(...s.ids);
|
|
279
|
+
break;
|
|
280
|
+
}
|
|
281
|
+
case "RANGE": {
|
|
282
|
+
const s = new P(n.entity);
|
|
283
|
+
t.push(s.identify(e)), i.push(...s.ids);
|
|
284
|
+
break;
|
|
285
|
+
}
|
|
286
|
+
default:
|
|
287
|
+
t.push(n.entity);
|
|
288
|
+
break;
|
|
289
|
+
}
|
|
290
|
+
this.identifiedFormula = t.join(""), this.dependencyIds = i;
|
|
291
|
+
}
|
|
292
|
+
display({ sheet: e }) {
|
|
293
|
+
return this.tokens.map((t) => {
|
|
294
|
+
switch (t.type) {
|
|
295
|
+
case "VALUE":
|
|
296
|
+
return typeof t.entity == "number" || typeof t.entity == "boolean" ? t.entity : t.closed ? `"${t.entity}"` : `"${t.entity}`;
|
|
297
|
+
case "ID":
|
|
298
|
+
return new O(t.entity).display({ sheet: e });
|
|
299
|
+
case "ID_RANGE":
|
|
300
|
+
return new A(t.entity).display({ sheet: e });
|
|
301
|
+
}
|
|
302
|
+
return t.entity;
|
|
303
|
+
}).join("");
|
|
304
|
+
}
|
|
305
|
+
tokenize(e = {}) {
|
|
306
|
+
var t, i;
|
|
307
|
+
for (; this.index <= this.formula.length; ) {
|
|
308
|
+
this.skipSpaces();
|
|
309
|
+
let n = this.get();
|
|
310
|
+
switch (this.next(), n) {
|
|
311
|
+
case void 0:
|
|
312
|
+
return;
|
|
313
|
+
case "(":
|
|
314
|
+
this.tokens.push(v);
|
|
315
|
+
continue;
|
|
316
|
+
case ")":
|
|
317
|
+
this.tokens.push(V);
|
|
318
|
+
continue;
|
|
319
|
+
case ",":
|
|
320
|
+
this.tokens.push(B);
|
|
321
|
+
continue;
|
|
322
|
+
case "+":
|
|
323
|
+
this.tokens.push(new a(d, "+", 3, this.at));
|
|
324
|
+
continue;
|
|
325
|
+
case "-": {
|
|
326
|
+
const r = (t = this.getToken(-1)) == null ? void 0 : t.type, o = (i = this.getToken(-2)) == null ? void 0 : i.type;
|
|
327
|
+
r === d || r === "SPACE" && o === d ? this.tokens.push(new a(j, "-", 6, this.at)) : this.tokens.push(new a(d, "-", 3, this.at));
|
|
328
|
+
continue;
|
|
329
|
+
}
|
|
330
|
+
case "/":
|
|
331
|
+
this.tokens.push(new a(d, "/", 4, this.at));
|
|
332
|
+
continue;
|
|
333
|
+
case "*":
|
|
334
|
+
this.tokens.push(new a(d, "*", 4, this.at));
|
|
335
|
+
continue;
|
|
336
|
+
case "^":
|
|
337
|
+
this.tokens.push(new a(d, "^", 5, this.at));
|
|
338
|
+
continue;
|
|
339
|
+
case "&":
|
|
340
|
+
this.tokens.push(new a(d, "&", 4, this.at));
|
|
341
|
+
continue;
|
|
342
|
+
case "=":
|
|
343
|
+
this.tokens.push(new a(d, "=", 1, this.at));
|
|
344
|
+
continue;
|
|
345
|
+
case ">":
|
|
346
|
+
if (this.get() === "=") {
|
|
347
|
+
this.next(), this.tokens.push(new a(d, ">=", 2, this.at));
|
|
348
|
+
continue;
|
|
349
|
+
}
|
|
350
|
+
this.tokens.push(new a(d, ">", 2, this.at));
|
|
351
|
+
continue;
|
|
352
|
+
case "<":
|
|
353
|
+
if (this.get() === "=") {
|
|
354
|
+
this.next(), this.tokens.push(new a(d, "<=", 2, this.at));
|
|
355
|
+
continue;
|
|
356
|
+
}
|
|
357
|
+
if (this.get() === ">") {
|
|
358
|
+
this.next(), this.tokens.push(new a(d, "<>", 1, this.at));
|
|
359
|
+
continue;
|
|
360
|
+
}
|
|
361
|
+
this.tokens.push(new a(d, "<", 2, this.at));
|
|
362
|
+
continue;
|
|
363
|
+
case '"': {
|
|
364
|
+
const { buf: r, closed: o } = this.getString('"');
|
|
365
|
+
this.tokens.push(new a("VALUE", r, 0, this.at, o));
|
|
366
|
+
continue;
|
|
367
|
+
}
|
|
368
|
+
case "'": {
|
|
369
|
+
const { buf: r } = this.getString("'");
|
|
370
|
+
n = `'${r}'`;
|
|
371
|
+
break;
|
|
372
|
+
}
|
|
373
|
+
case "!": {
|
|
374
|
+
this.foreign = !0;
|
|
375
|
+
break;
|
|
376
|
+
}
|
|
377
|
+
case "%": {
|
|
378
|
+
this.tokens.push(new a(G, "%", 4, this.at));
|
|
379
|
+
continue;
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
let s = n;
|
|
383
|
+
for (; ; ) {
|
|
384
|
+
const r = this.get();
|
|
385
|
+
if (r === "(") {
|
|
386
|
+
this.tokens.push(new a("FUNCTION", s, 0, this.at), v), this.next();
|
|
387
|
+
break;
|
|
388
|
+
}
|
|
389
|
+
if (r == null || X.has(r)) {
|
|
390
|
+
if (s.length === 0)
|
|
391
|
+
break;
|
|
392
|
+
if (s.match(/^[+-]?(\d*[.])?\d+$/))
|
|
393
|
+
this.tokens.push(new a("VALUE", parseFloat(s), 0, this.at));
|
|
394
|
+
else {
|
|
395
|
+
const o = M[s.toLowerCase()];
|
|
396
|
+
o != null ? this.tokens.push(new a("VALUE", o, 0, this.at)) : s.startsWith("#") ? s.indexOf("#REF!") !== -1 ? this.tokens.push(new a("UNREFERENCED", s, 0, this.at)) : s.indexOf(":") !== -1 ? this.tokens.push(new a("ID_RANGE", W(s, e), 0, this.at)) : this.tokens.push(new a("ID", s, 0, this.at)) : s.indexOf(":") !== -1 ? this.tokens.push(new a("RANGE", s, 0, this.at)) : s.includes(".") && /[a-zA-Z]/.test(s) || isNaN(s[s.length - 1]) ? this.tokens.push(new a("INVALID_REF", s, 0, this.at)) : this.tokens.push(new a("REF", s, 0, this.at));
|
|
397
|
+
}
|
|
398
|
+
break;
|
|
399
|
+
}
|
|
400
|
+
s += r, this.next();
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
skipSpaces() {
|
|
405
|
+
let e = "";
|
|
406
|
+
for (; this.isWhiteSpace(); )
|
|
407
|
+
e += this.formula[this.index++];
|
|
408
|
+
e !== "" && this.tokens.push(new a("SPACE", e, 0, this.at));
|
|
409
|
+
}
|
|
410
|
+
getString(e = '"') {
|
|
411
|
+
let t = "";
|
|
412
|
+
for (; ; ) {
|
|
413
|
+
const i = this.get();
|
|
414
|
+
if (this.next(), i == null)
|
|
415
|
+
return { buf: t, closed: !1 };
|
|
416
|
+
if (i === e)
|
|
417
|
+
if (e === '"' && this.get() === e) {
|
|
418
|
+
t += e, this.next();
|
|
419
|
+
continue;
|
|
420
|
+
} else if (e === "'" && this.get() === e) {
|
|
421
|
+
t += i;
|
|
422
|
+
continue;
|
|
423
|
+
} else
|
|
424
|
+
return { buf: t, closed: !0 };
|
|
425
|
+
else
|
|
426
|
+
t += i;
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
const W = (h, e) => {
|
|
431
|
+
const [t, i] = h.split("!"), n = i.split(":"), s = /* @__PURE__ */ new Set();
|
|
432
|
+
return Object.keys(e).forEach((r) => {
|
|
433
|
+
const o = e[r], l = new RegExp(`(\\$)?#${r}\\b(\\$)?`);
|
|
434
|
+
for (let u = 0; u < n.length; u++) {
|
|
435
|
+
if (s.has(u))
|
|
436
|
+
continue;
|
|
437
|
+
const p = n[u], c = p.replace(l, (E, y, k) => `${y || ""}#${o}${k || ""}`);
|
|
438
|
+
c !== p && (n[u] = c, s.add(u));
|
|
439
|
+
}
|
|
440
|
+
}), `${t}!${n.join(":")}`;
|
|
441
|
+
};
|
|
442
|
+
class Y {
|
|
443
|
+
constructor(e) {
|
|
444
|
+
this.index = 0, this.depth = 0, this.tokens = e;
|
|
445
|
+
}
|
|
446
|
+
build() {
|
|
447
|
+
const { expr: e } = this.parse(!1);
|
|
448
|
+
return e;
|
|
449
|
+
}
|
|
450
|
+
parse(e) {
|
|
451
|
+
const t = [];
|
|
452
|
+
let i;
|
|
453
|
+
const n = (s = !1) => {
|
|
454
|
+
if (i) {
|
|
455
|
+
const r = t.pop();
|
|
456
|
+
i.args.push(r);
|
|
457
|
+
}
|
|
458
|
+
return { hasNext: s, expr: t.shift() };
|
|
459
|
+
};
|
|
460
|
+
for (; this.tokens.length > this.index; ) {
|
|
461
|
+
const s = this.tokens[this.index++];
|
|
462
|
+
if (s.type !== "SPACE") {
|
|
463
|
+
if (s.type === "COMMA") {
|
|
464
|
+
if (!e)
|
|
465
|
+
throw new f("#ERROR!", "Invalid comma");
|
|
466
|
+
return n(!0);
|
|
467
|
+
} else if (s.type === "VALUE" || s.type === "ID" || s.type === "ID_RANGE" || s.type === "REF" || s.type === "RANGE" || s.type === "UNREFERENCED" || s.type === "INVALID_REF") {
|
|
468
|
+
const r = s.convert();
|
|
469
|
+
t.push(r);
|
|
470
|
+
} else if (s.type === "POSTFIX_OPERATOR" && s.entity === "%") {
|
|
471
|
+
const r = t.pop();
|
|
472
|
+
if (!r)
|
|
473
|
+
throw new f("#ERROR!", "Missing expression before %");
|
|
474
|
+
const o = new I("divide", 4, [r, new N(100)]);
|
|
475
|
+
t.push(o);
|
|
476
|
+
} else if (s.type === "FUNCTION") {
|
|
477
|
+
this.index++, this.depth++;
|
|
478
|
+
const r = s.convert();
|
|
479
|
+
for (t.push(r); ; ) {
|
|
480
|
+
const { expr: o, hasNext: l } = this.parse(!0);
|
|
481
|
+
if (o && r.args.push(o), !l)
|
|
482
|
+
break;
|
|
483
|
+
}
|
|
484
|
+
} else if (s.type === "OPEN") {
|
|
485
|
+
this.depth++;
|
|
486
|
+
const { expr: r } = this.parse(!1);
|
|
487
|
+
t.push(r);
|
|
488
|
+
} else if (s.type === "CLOSE") {
|
|
489
|
+
if (this.depth-- === 0)
|
|
490
|
+
throw new f("#ERROR!", "Unexpected end paren");
|
|
491
|
+
return n();
|
|
492
|
+
} else if (s.type === "INFIX_OPERATOR") {
|
|
493
|
+
const r = s.convert();
|
|
494
|
+
let o = t.pop();
|
|
495
|
+
if (o == null)
|
|
496
|
+
if (r.name === "minus" || r.name === "add")
|
|
497
|
+
o = C;
|
|
498
|
+
else
|
|
499
|
+
throw new f("#ERROR!", "Missing left expression");
|
|
500
|
+
if (i == null)
|
|
501
|
+
r.args.push(o), t.unshift(r);
|
|
502
|
+
else if (r.precedence > i.precedence)
|
|
503
|
+
r.args.push(o), i.args.push(r), t.unshift(i);
|
|
504
|
+
else {
|
|
505
|
+
const l = t.shift();
|
|
506
|
+
r.args.push(l), i.args.push(o), t.unshift(r);
|
|
507
|
+
}
|
|
508
|
+
i = r;
|
|
509
|
+
} else if (s.type === "PREFIX_OPERATOR") {
|
|
510
|
+
const r = s.convert();
|
|
511
|
+
i ? i.args.push(r) : t.unshift(r), i = r;
|
|
512
|
+
}
|
|
513
|
+
}
|
|
514
|
+
}
|
|
515
|
+
return n();
|
|
516
|
+
}
|
|
517
|
+
}
|
|
518
|
+
const J = Y, Q = (h) => (h.charAt(0) === "'" && (h = h.slice(1)), h.charAt(h.length - 1) === "'" && (h = h.slice(0, -1)), h);
|
|
519
|
+
function H(h) {
|
|
520
|
+
let e, t = [];
|
|
521
|
+
if (h.startsWith("'")) {
|
|
522
|
+
let i = 1, n = "";
|
|
523
|
+
for (; i < h.length; ) {
|
|
524
|
+
const r = h[i], o = h[i + 1];
|
|
525
|
+
if (r === "'")
|
|
526
|
+
if (o === "'")
|
|
527
|
+
n += "'", i += 2;
|
|
528
|
+
else if (o === "!") {
|
|
529
|
+
i += 2;
|
|
530
|
+
break;
|
|
531
|
+
} else
|
|
532
|
+
return { sheetName: void 0, addresses: [] };
|
|
533
|
+
else
|
|
534
|
+
n += r, i++;
|
|
535
|
+
}
|
|
536
|
+
e = n, t = h.slice(i).trim().split(":");
|
|
537
|
+
} else {
|
|
538
|
+
const i = h.indexOf("!");
|
|
539
|
+
i !== -1 ? (e = h.slice(0, i), t = h.slice(i + 1).trim().split(":")) : t = h.trim().split(":");
|
|
540
|
+
}
|
|
541
|
+
return { sheetName: e, addresses: t };
|
|
542
|
+
}
|
|
543
|
+
const R = (h, { sheet: e, operation: t, dependency: i }) => {
|
|
544
|
+
const { sheetName: n, addresses: s } = H(h), r = [];
|
|
545
|
+
if (n && (e = e.getSheetBySheetName(n), e == null))
|
|
546
|
+
return { sheet: e, sheetName: n, addresses: s, ids: r };
|
|
547
|
+
if (s.length === 0)
|
|
548
|
+
return { sheet: e, sheetName: n, addresses: s, ids: r };
|
|
549
|
+
const o = [];
|
|
550
|
+
for (let u = 0; u < s.length; u++) {
|
|
551
|
+
const p = s[u], { y: c, x: E, absX: y, absY: k } = x(p);
|
|
552
|
+
let g = e.getId({ y: c, x: E });
|
|
553
|
+
if (g === i && (t === "removeRows" ? g = e.getId({ y: c - 1, x: E }) : t === "removeCols" && (g = e.getId({ y: c, x: E - 1 }))), g == null) {
|
|
554
|
+
o.push(S(p, !!y, !!k) || "?");
|
|
555
|
+
continue;
|
|
556
|
+
}
|
|
557
|
+
r.push(g), o.push(`${y ? "$" : ""}#${g}${k ? "$" : ""}`);
|
|
558
|
+
}
|
|
559
|
+
let l = `#${e.id}!${o.join(":")}`;
|
|
560
|
+
return {
|
|
561
|
+
sheet: e,
|
|
562
|
+
sheetName: n,
|
|
563
|
+
addresses: s,
|
|
564
|
+
ids: r,
|
|
565
|
+
formula: l
|
|
566
|
+
};
|
|
567
|
+
};
|
|
568
|
+
export {
|
|
569
|
+
J as FormulaParser,
|
|
570
|
+
I as FunctionEntity,
|
|
571
|
+
O as IdEntity,
|
|
572
|
+
A as IdRangeEntity,
|
|
573
|
+
_ as InvalidRefEntity,
|
|
574
|
+
Z as Lexer,
|
|
575
|
+
Y as Parser,
|
|
576
|
+
P as RangeEntity,
|
|
577
|
+
b as RefEntity,
|
|
578
|
+
a as Token,
|
|
579
|
+
T as UnreferencedEntity,
|
|
580
|
+
N as ValueEntity,
|
|
581
|
+
R as parseRef,
|
|
582
|
+
H as splitRef,
|
|
583
|
+
Q as stripSheetName
|
|
584
|
+
};
|
|
585
|
+
//# sourceMappingURL=evaluator.js.map
|