@gridsheet/core 3.0.0-rc.8

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.
Files changed (250) hide show
  1. package/README.md +17 -0
  2. package/dist/constants.d.ts +21 -0
  3. package/dist/constants.d.ts.map +1 -0
  4. package/dist/constants.js +28 -0
  5. package/dist/constants.js.map +1 -0
  6. package/dist/formula/evaluator.d.ts +134 -0
  7. package/dist/formula/evaluator.d.ts.map +1 -0
  8. package/dist/formula/evaluator.js +585 -0
  9. package/dist/formula/evaluator.js.map +1 -0
  10. package/dist/formula/formula-error.d.ts +10 -0
  11. package/dist/formula/formula-error.d.ts.map +1 -0
  12. package/dist/formula/formula-error.js +15 -0
  13. package/dist/formula/formula-error.js.map +1 -0
  14. package/dist/formula/functions/__async.d.ts +67 -0
  15. package/dist/formula/functions/__async.d.ts.map +1 -0
  16. package/dist/formula/functions/__async.js +70 -0
  17. package/dist/formula/functions/__async.js.map +1 -0
  18. package/dist/formula/functions/__base.d.ts +112 -0
  19. package/dist/formula/functions/__base.d.ts.map +1 -0
  20. package/dist/formula/functions/__base.js +265 -0
  21. package/dist/formula/functions/__base.js.map +1 -0
  22. package/dist/formula/functions/__utils.d.ts +28 -0
  23. package/dist/formula/functions/__utils.d.ts.map +1 -0
  24. package/dist/formula/functions/__utils.js +179 -0
  25. package/dist/formula/functions/__utils.js.map +1 -0
  26. package/dist/formula/functions/abs.d.ts +9 -0
  27. package/dist/formula/functions/abs.d.ts.map +1 -0
  28. package/dist/formula/functions/abs.js +15 -0
  29. package/dist/formula/functions/abs.js.map +1 -0
  30. package/dist/formula/functions/add.d.ts +10 -0
  31. package/dist/formula/functions/add.d.ts.map +1 -0
  32. package/dist/formula/functions/add.js +37 -0
  33. package/dist/formula/functions/add.js.map +1 -0
  34. package/dist/formula/functions/and.d.ts +9 -0
  35. package/dist/formula/functions/and.d.ts.map +1 -0
  36. package/dist/formula/functions/and.js +23 -0
  37. package/dist/formula/functions/and.js.map +1 -0
  38. package/dist/formula/functions/arrayformula.d.ts +12 -0
  39. package/dist/formula/functions/arrayformula.d.ts.map +1 -0
  40. package/dist/formula/functions/arrayformula.js +24 -0
  41. package/dist/formula/functions/arrayformula.js.map +1 -0
  42. package/dist/formula/functions/average.d.ts +9 -0
  43. package/dist/formula/functions/average.d.ts.map +1 -0
  44. package/dist/formula/functions/average.js +40 -0
  45. package/dist/formula/functions/average.js.map +1 -0
  46. package/dist/formula/functions/concat.d.ts +9 -0
  47. package/dist/formula/functions/concat.d.ts.map +1 -0
  48. package/dist/formula/functions/concat.js +27 -0
  49. package/dist/formula/functions/concat.js.map +1 -0
  50. package/dist/formula/functions/count.d.ts +9 -0
  51. package/dist/formula/functions/count.d.ts.map +1 -0
  52. package/dist/formula/functions/count.js +32 -0
  53. package/dist/formula/functions/count.js.map +1 -0
  54. package/dist/formula/functions/counta.d.ts +9 -0
  55. package/dist/formula/functions/counta.d.ts.map +1 -0
  56. package/dist/formula/functions/counta.js +32 -0
  57. package/dist/formula/functions/counta.js.map +1 -0
  58. package/dist/formula/functions/divide.d.ts +10 -0
  59. package/dist/formula/functions/divide.d.ts.map +1 -0
  60. package/dist/formula/functions/divide.js +34 -0
  61. package/dist/formula/functions/divide.js.map +1 -0
  62. package/dist/formula/functions/eq.d.ts +9 -0
  63. package/dist/formula/functions/eq.d.ts.map +1 -0
  64. package/dist/formula/functions/eq.js +19 -0
  65. package/dist/formula/functions/eq.js.map +1 -0
  66. package/dist/formula/functions/gt.d.ts +9 -0
  67. package/dist/formula/functions/gt.d.ts.map +1 -0
  68. package/dist/formula/functions/gt.js +19 -0
  69. package/dist/formula/functions/gt.js.map +1 -0
  70. package/dist/formula/functions/gte.d.ts +9 -0
  71. package/dist/formula/functions/gte.d.ts.map +1 -0
  72. package/dist/formula/functions/gte.js +19 -0
  73. package/dist/formula/functions/gte.js.map +1 -0
  74. package/dist/formula/functions/if.d.ts +9 -0
  75. package/dist/formula/functions/if.d.ts.map +1 -0
  76. package/dist/formula/functions/if.js +29 -0
  77. package/dist/formula/functions/if.js.map +1 -0
  78. package/dist/formula/functions/iferror.d.ts +10 -0
  79. package/dist/formula/functions/iferror.d.ts.map +1 -0
  80. package/dist/formula/functions/iferror.js +28 -0
  81. package/dist/formula/functions/iferror.js.map +1 -0
  82. package/dist/formula/functions/len.d.ts +9 -0
  83. package/dist/formula/functions/len.d.ts.map +1 -0
  84. package/dist/formula/functions/len.js +21 -0
  85. package/dist/formula/functions/len.js.map +1 -0
  86. package/dist/formula/functions/lt.d.ts +9 -0
  87. package/dist/formula/functions/lt.d.ts.map +1 -0
  88. package/dist/formula/functions/lt.js +19 -0
  89. package/dist/formula/functions/lt.js.map +1 -0
  90. package/dist/formula/functions/lte.d.ts +9 -0
  91. package/dist/formula/functions/lte.d.ts.map +1 -0
  92. package/dist/formula/functions/lte.js +19 -0
  93. package/dist/formula/functions/lte.js.map +1 -0
  94. package/dist/formula/functions/max.d.ts +9 -0
  95. package/dist/formula/functions/max.d.ts.map +1 -0
  96. package/dist/formula/functions/max.js +37 -0
  97. package/dist/formula/functions/max.js.map +1 -0
  98. package/dist/formula/functions/min.d.ts +9 -0
  99. package/dist/formula/functions/min.d.ts.map +1 -0
  100. package/dist/formula/functions/min.js +37 -0
  101. package/dist/formula/functions/min.js.map +1 -0
  102. package/dist/formula/functions/minus.d.ts +10 -0
  103. package/dist/formula/functions/minus.d.ts.map +1 -0
  104. package/dist/formula/functions/minus.js +41 -0
  105. package/dist/formula/functions/minus.js.map +1 -0
  106. package/dist/formula/functions/multiply.d.ts +9 -0
  107. package/dist/formula/functions/multiply.d.ts.map +1 -0
  108. package/dist/formula/functions/multiply.js +19 -0
  109. package/dist/formula/functions/multiply.js.map +1 -0
  110. package/dist/formula/functions/ne.d.ts +9 -0
  111. package/dist/formula/functions/ne.d.ts.map +1 -0
  112. package/dist/formula/functions/ne.js +19 -0
  113. package/dist/formula/functions/ne.js.map +1 -0
  114. package/dist/formula/functions/not.d.ts +9 -0
  115. package/dist/formula/functions/not.d.ts.map +1 -0
  116. package/dist/formula/functions/not.js +22 -0
  117. package/dist/formula/functions/not.js.map +1 -0
  118. package/dist/formula/functions/now.d.ts +9 -0
  119. package/dist/formula/functions/now.d.ts.map +1 -0
  120. package/dist/formula/functions/now.js +14 -0
  121. package/dist/formula/functions/now.js.map +1 -0
  122. package/dist/formula/functions/or.d.ts +9 -0
  123. package/dist/formula/functions/or.d.ts.map +1 -0
  124. package/dist/formula/functions/or.js +23 -0
  125. package/dist/formula/functions/or.js.map +1 -0
  126. package/dist/formula/functions/power.d.ts +9 -0
  127. package/dist/formula/functions/power.d.ts.map +1 -0
  128. package/dist/formula/functions/power.js +18 -0
  129. package/dist/formula/functions/power.js.map +1 -0
  130. package/dist/formula/functions/sum.d.ts +9 -0
  131. package/dist/formula/functions/sum.d.ts.map +1 -0
  132. package/dist/formula/functions/sum.js +34 -0
  133. package/dist/formula/functions/sum.js.map +1 -0
  134. package/dist/formula/functions/uminus.d.ts +9 -0
  135. package/dist/formula/functions/uminus.d.ts.map +1 -0
  136. package/dist/formula/functions/uminus.js +17 -0
  137. package/dist/formula/functions/uminus.js.map +1 -0
  138. package/dist/formula/mapping.d.ts +11 -0
  139. package/dist/formula/mapping.d.ts.map +1 -0
  140. package/dist/formula/mapping.js +82 -0
  141. package/dist/formula/mapping.js.map +1 -0
  142. package/dist/formula/solver.d.ts +39 -0
  143. package/dist/formula/solver.d.ts.map +1 -0
  144. package/dist/formula/solver.js +71 -0
  145. package/dist/formula/solver.js.map +1 -0
  146. package/dist/index.d.ts +22 -0
  147. package/dist/index.d.ts.map +1 -0
  148. package/dist/index.js +74 -0
  149. package/dist/index.js.map +1 -0
  150. package/dist/lib/autofill.d.ts +22 -0
  151. package/dist/lib/autofill.d.ts.map +1 -0
  152. package/dist/lib/autofill.js +276 -0
  153. package/dist/lib/autofill.js.map +1 -0
  154. package/dist/lib/book.d.ts +131 -0
  155. package/dist/lib/book.d.ts.map +1 -0
  156. package/dist/lib/book.js +53 -0
  157. package/dist/lib/book.js.map +1 -0
  158. package/dist/lib/cell.d.ts +17 -0
  159. package/dist/lib/cell.d.ts.map +1 -0
  160. package/dist/lib/cell.js +17 -0
  161. package/dist/lib/cell.js.map +1 -0
  162. package/dist/lib/coords.d.ts +22 -0
  163. package/dist/lib/coords.d.ts.map +1 -0
  164. package/dist/lib/coords.js +73 -0
  165. package/dist/lib/coords.js.map +1 -0
  166. package/dist/lib/date.d.ts +2 -0
  167. package/dist/lib/date.d.ts.map +1 -0
  168. package/dist/lib/date.js +91 -0
  169. package/dist/lib/date.js.map +1 -0
  170. package/dist/lib/dom.d.ts +7 -0
  171. package/dist/lib/dom.d.ts.map +1 -0
  172. package/dist/lib/dom.js +28 -0
  173. package/dist/lib/dom.js.map +1 -0
  174. package/dist/lib/filter.d.ts +7 -0
  175. package/dist/lib/filter.d.ts.map +1 -0
  176. package/dist/lib/filter.js +122 -0
  177. package/dist/lib/filter.js.map +1 -0
  178. package/dist/lib/input.d.ts +28 -0
  179. package/dist/lib/input.d.ts.map +1 -0
  180. package/dist/lib/input.js +73 -0
  181. package/dist/lib/input.js.map +1 -0
  182. package/dist/lib/label.d.ts +4 -0
  183. package/dist/lib/label.d.ts.map +1 -0
  184. package/dist/lib/label.js +10 -0
  185. package/dist/lib/label.js.map +1 -0
  186. package/dist/lib/operation.d.ts +31 -0
  187. package/dist/lib/operation.d.ts.map +1 -0
  188. package/dist/lib/operation.js +36 -0
  189. package/dist/lib/operation.js.map +1 -0
  190. package/dist/lib/palette.d.ts +2 -0
  191. package/dist/lib/palette.d.ts.map +1 -0
  192. package/dist/lib/palette.js +26 -0
  193. package/dist/lib/palette.js.map +1 -0
  194. package/dist/lib/popup.d.ts +24 -0
  195. package/dist/lib/popup.d.ts.map +1 -0
  196. package/dist/lib/popup.js +21 -0
  197. package/dist/lib/popup.js.map +1 -0
  198. package/dist/lib/reference.d.ts +19 -0
  199. package/dist/lib/reference.d.ts.map +1 -0
  200. package/dist/lib/reference.js +40 -0
  201. package/dist/lib/reference.js.map +1 -0
  202. package/dist/lib/sheet.d.ts +512 -0
  203. package/dist/lib/sheet.d.ts.map +1 -0
  204. package/dist/lib/sheet.js +1530 -0
  205. package/dist/lib/sheet.js.map +1 -0
  206. package/dist/lib/sheet_utils.d.ts +55 -0
  207. package/dist/lib/sheet_utils.d.ts.map +1 -0
  208. package/dist/lib/sheet_utils.js +125 -0
  209. package/dist/lib/sheet_utils.js.map +1 -0
  210. package/dist/lib/spatial.d.ts +79 -0
  211. package/dist/lib/spatial.d.ts.map +1 -0
  212. package/dist/lib/spatial.js +227 -0
  213. package/dist/lib/spatial.js.map +1 -0
  214. package/dist/lib/time.d.ts +29 -0
  215. package/dist/lib/time.d.ts.map +1 -0
  216. package/dist/lib/time.js +113 -0
  217. package/dist/lib/time.js.map +1 -0
  218. package/dist/lib/virtualization.d.ts +22 -0
  219. package/dist/lib/virtualization.d.ts.map +1 -0
  220. package/dist/lib/virtualization.js +91 -0
  221. package/dist/lib/virtualization.js.map +1 -0
  222. package/dist/policy/core.d.ts +161 -0
  223. package/dist/policy/core.d.ts.map +1 -0
  224. package/dist/policy/core.js +248 -0
  225. package/dist/policy/core.js.map +1 -0
  226. package/dist/policy/thousand_separator.d.ts +4 -0
  227. package/dist/policy/thousand_separator.d.ts.map +1 -0
  228. package/dist/policy/thousand_separator.js +13 -0
  229. package/dist/policy/thousand_separator.js.map +1 -0
  230. package/dist/sentinels.d.ts +40 -0
  231. package/dist/sentinels.d.ts.map +1 -0
  232. package/dist/sentinels.js +41 -0
  233. package/dist/sentinels.js.map +1 -0
  234. package/dist/styles/embedder.d.ts +2 -0
  235. package/dist/styles/embedder.d.ts.map +1 -0
  236. package/dist/styles/embedder.js +11 -0
  237. package/dist/styles/embedder.js.map +1 -0
  238. package/dist/styles/minified.d.ts +3 -0
  239. package/dist/styles/minified.d.ts.map +1 -0
  240. package/dist/styles/minified.js +6 -0
  241. package/dist/styles/minified.js.map +1 -0
  242. package/dist/types.d.ts +310 -0
  243. package/dist/types.d.ts.map +1 -0
  244. package/dist/types.js +2 -0
  245. package/dist/types.js.map +1 -0
  246. package/dist/utils.d.ts +2 -0
  247. package/dist/utils.d.ts.map +1 -0
  248. package/dist/utils.js +5 -0
  249. package/dist/utils.js.map +1 -0
  250. package/package.json +59 -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