@borgar/fx 2.1.0 → 3.0.0-rc.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/README.md +139 -24
- package/References.md +39 -0
- package/dist/fx.js +1 -1
- package/lib/a1.js +152 -87
- package/lib/a1.spec.js +264 -0
- package/lib/addMeta.js +72 -13
- package/lib/{addMeta-test.js → addMeta.spec.js} +39 -6
- package/lib/constants.js +7 -89
- package/lib/fixRanges.js +41 -0
- package/lib/fixRanges.spec.js +111 -0
- package/lib/index.js +9 -6
- package/lib/isType.js +18 -0
- package/lib/lexer.js +99 -70
- package/lib/{lexer-test.js → lexer.spec.js} +449 -138
- package/lib/lexerParts.js +153 -0
- package/lib/mergeRefTokens.js +77 -0
- package/lib/mergeRefTokens.spec.js +118 -0
- package/lib/parseRef.js +44 -40
- package/lib/rc.js +154 -49
- package/lib/rc.spec.js +220 -0
- package/lib/stringifyPrefix.js +21 -0
- package/lib/{translate-toA1-test.js → translate-toA1.spec.js} +20 -2
- package/lib/{translate-toRC-test.js → translate-toRC.spec.js} +18 -1
- package/lib/translate.js +20 -32
- package/package.json +12 -10
- package/lib/a1-test.js +0 -158
- package/lib/quickVerify.js +0 -35
- package/lib/rc-test.js +0 -111
package/README.md
CHANGED
|
@@ -16,13 +16,14 @@ The library is also provided as an ES6 module in an NPM package:
|
|
|
16
16
|
|
|
17
17
|
* `formula` should be a string (an Excel formula).
|
|
18
18
|
|
|
19
|
-
* `options` are set as an object of keys: `
|
|
19
|
+
* `options` are set as an object of keys: `tokenize(formula, { option: true })`. Supported options are:
|
|
20
20
|
|
|
21
21
|
| name | default | effect |
|
|
22
|
-
|-
|
|
22
|
+
|- |- |-
|
|
23
|
+
| `allowTernary` | `false` | Enables the recognition of ternary ranges in the style of `A1:A` or `A1:1`. These are supported by Google Sheets but not Excel. See: References.md.
|
|
23
24
|
| `emitRanges` | `false` | Adds offset ranges on the tokens: `{ range: [ start, end ] }`
|
|
24
|
-
| `mergeRanges` | `true` | Should ranges be returned as whole references (`Sheet1!A1:B2`) or as separate tokens for each part: (`Sheet1`,`!`,`A1`,`:`,`B2`).
|
|
25
|
-
| `negativeNumbers` | `
|
|
25
|
+
| `mergeRanges` | `true` | Should ranges be returned as whole references (`Sheet1!A1:B2`) or as separate tokens for each part: (`Sheet1`,`!`,`A1`,`:`,`B2`). This is the same as calling [`mergeRanges`](#mergeRanges)
|
|
26
|
+
| `negativeNumbers` | `true` | Merges unary minuses with their immediately following number tokens (`-`,`1`) => `-1`
|
|
26
27
|
| `r1c1` | `false` | Ranges are expected to be in the R1C1 style format rather than the more popular A1 style.
|
|
27
28
|
|
|
28
29
|
The returned output will be an array of objects representing the tokens:
|
|
@@ -45,22 +46,22 @@ tokenTypes = {
|
|
|
45
46
|
BOOLEAN: "bool",
|
|
46
47
|
ERROR: "error",
|
|
47
48
|
NUMBER: "number",
|
|
48
|
-
FUNCTION: "
|
|
49
|
+
FUNCTION: "func",
|
|
49
50
|
NEWLINE: "newline",
|
|
50
51
|
WHITESPACE: "whitespace",
|
|
51
52
|
STRING: "string",
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
PATH_PREFIX: "path-prefix",
|
|
53
|
+
CONTEXT_QUOTE: "context_quote",
|
|
54
|
+
CONTEXT: "context",
|
|
55
55
|
RANGE: "range",
|
|
56
|
-
RANGE_BEAM: "
|
|
57
|
-
RANGE_NAMED: "
|
|
58
|
-
|
|
56
|
+
RANGE_BEAM: "range_beam",
|
|
57
|
+
RANGE_NAMED: "range_named",
|
|
58
|
+
RANGE_TERNARY: "range_ternary",
|
|
59
|
+
FX_PREFIX: "fx_prefix",
|
|
59
60
|
UNKNOWN: "unknown"
|
|
60
61
|
}
|
|
61
62
|
```
|
|
62
63
|
|
|
63
|
-
To support syntax highlighting as you type, `STRING
|
|
64
|
+
To support syntax highlighting as you type, `STRING` tokens are allowed to be "unterminated". For example, the incomplete formula `="Hello world` would be tokenized as:
|
|
64
65
|
|
|
65
66
|
```js
|
|
66
67
|
[
|
|
@@ -71,7 +72,7 @@ To support syntax highlighting as you type, `STRING`, `PATH_BRACE`, and `PATH_QU
|
|
|
71
72
|
|
|
72
73
|
### <a name="translateToA1" href="#translateToA1">#</a> **translateToA1**( _formula, anchorCell_ )
|
|
73
74
|
|
|
74
|
-
Translates ranges in a formula from relative R1C1 syntax to absolute A1 syntax.
|
|
75
|
+
Translates ranges in a formula or list of tokens from relative R1C1 syntax to absolute A1 syntax.
|
|
75
76
|
|
|
76
77
|
* `formula` should be a string (an Excel formula) or a token list.
|
|
77
78
|
|
|
@@ -87,7 +88,7 @@ translateToA1("=SUM(RC[1],R2C5,Sheet!R3C5)", "D10");
|
|
|
87
88
|
|
|
88
89
|
### <a name="translateToRC" href="#translateToRC">#</a> **translateToRC**( _formula, anchorCell_ )
|
|
89
90
|
|
|
90
|
-
Translates ranges in a formula from absolute A1 syntax to relative R1C1 syntax.
|
|
91
|
+
Translates ranges in a formula or list of tokens from absolute A1 syntax to relative R1C1 syntax.
|
|
91
92
|
|
|
92
93
|
* `formula` should be a string (an Excel formula) or a token list.
|
|
93
94
|
|
|
@@ -107,10 +108,11 @@ Runs through a list of tokens and adds extra attributes such as matching parens
|
|
|
107
108
|
|
|
108
109
|
* `tokenlist` should be a token list (from `tokenize()`).
|
|
109
110
|
|
|
110
|
-
* `context` should be an object containing default reference attributes: `{ workbookName: 'report.xlsx', sheetName: 'Sheet1' }
|
|
111
|
+
* `context` should be an object containing default reference attributes: `{ workbookName: 'report.xlsx', sheetName: 'Sheet1' }`. If supplied, these are used to match `A1` to `Sheet1!A1`)
|
|
111
112
|
|
|
112
|
-
|
|
113
|
+
All tokens will be tagged with a `.depth` number value to indicating the level of nesting in parentheses as well as an `.index` number indicating their zero based position in the list.
|
|
113
114
|
|
|
115
|
+
The returned output will be the same array of tokens but the following properties will added to tokens (as applicable):
|
|
114
116
|
|
|
115
117
|
#### Parentheses ( )
|
|
116
118
|
|
|
@@ -133,12 +135,48 @@ All ranges will be tagged with `.groupId` string identifier regardless of the nu
|
|
|
133
135
|
All will be tagged with `.error` (boolean `true`).
|
|
134
136
|
|
|
135
137
|
|
|
138
|
+
### <a name="mergeRanges" href="#mergeRanges">#</a> **mergeRanges**( _tokenlist_ )
|
|
139
|
+
|
|
140
|
+
Given a tokenlist, returns a new list with ranges returned as whole references (`Sheet1!A1:B2`) rather than separate tokens for each part: (`Sheet1`,`!`,`A1`,`:`,`B2`).
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+
### <a name="fixRanges" href="#fixRanges">#</a> **fixRanges**( _formula[, { addBounds: true } ]_ )
|
|
144
|
+
|
|
145
|
+
Normalizes A1 style ranges in a formula or list of tokens so that the top and left coordinates of the range are on the left-hand side of a colon operator:
|
|
146
|
+
|
|
147
|
+
* `B2:A1` → `A1:B2`
|
|
148
|
+
* `1:A1` → `A1:1`
|
|
149
|
+
* `A:A1` → `A1:A`
|
|
150
|
+
* `B:A` → `A:B`
|
|
151
|
+
* `2:1` → `1:2`
|
|
152
|
+
* `A1:A1` → `A1`
|
|
153
|
+
|
|
154
|
+
When `{ addBounds: true }` is passed as an option, the missing bounds are also added. This can be done to ensure Excel compatible ranges. The fixes then additionally include:
|
|
155
|
+
|
|
156
|
+
* `1:A1` → `A1:1` → `1:1`
|
|
157
|
+
* `A:A1` → `A1:A` → `A:A`
|
|
158
|
+
* `A1:A` → `A:A`
|
|
159
|
+
* `A1:1` → `A:1`
|
|
160
|
+
* `B2:B` → `B2:1048576`
|
|
161
|
+
* `B2:2` → `B2:XFD2`
|
|
162
|
+
|
|
163
|
+
Returns the same formula with the ranges updated. If an array of tokens was supplied, then a new array is returned.
|
|
164
|
+
|
|
165
|
+
### <a name="isRange" href="#isRange">#</a> **isRange**( _token_ )
|
|
166
|
+
|
|
167
|
+
Returns `true` if the input is a token that has a type of either RANGE (`A1` or `A1:B2`), RANGE_TERNARY (`A1:A`, `A1:1`, `1:A1`, or `A:A1`), or RANGE_BEAM (`A:A` or `1:1`). In all other cases `false` is returned.
|
|
168
|
+
|
|
169
|
+
|
|
170
|
+
### <a name="isReference" href="#isReference">#</a> **isReference**( _token_ )
|
|
171
|
+
|
|
172
|
+
Returns `true` if the input is a token of type RANGE (`A1` or `A1:B2`), RANGE_TERNARY (`A1:A`, `A1:1`, `1:A1`, or `A:A1`), RANGE_BEAM (`A:A` or `1:1`), or RANGE_NAMED (`myrange`). In all other cases `false` is returned.
|
|
173
|
+
|
|
136
174
|
|
|
137
175
|
### .a1:
|
|
138
176
|
|
|
139
177
|
An object of methods to interpret and manipulate A1 style references.
|
|
140
178
|
|
|
141
|
-
#### <a name="a1.parse" href="#a1.parse">#</a> **.parse**( _refString[,
|
|
179
|
+
#### <a name="a1.parse" href="#a1.parse">#</a> **.parse**( _refString[, { allowNamed: true, allowTernary: true } ]_ )
|
|
142
180
|
|
|
143
181
|
Parse a string reference into an object representing it.
|
|
144
182
|
|
|
@@ -146,8 +184,7 @@ Parse a string reference into an object representing it.
|
|
|
146
184
|
import { a1 } from '@borgar/fx';
|
|
147
185
|
a1.parse('Sheet1!A$1:$B2');
|
|
148
186
|
// => {
|
|
149
|
-
//
|
|
150
|
-
// sheetName: 'Sheet1',
|
|
187
|
+
// context: [ 'Sheet1' ],
|
|
151
188
|
// range: {
|
|
152
189
|
// top: 0,
|
|
153
190
|
// left: 0,
|
|
@@ -161,6 +198,62 @@ a1.parse('Sheet1!A$1:$B2');
|
|
|
161
198
|
// }
|
|
162
199
|
```
|
|
163
200
|
|
|
201
|
+
For A:A or A1:A style ranges, null will be used for any dimensions that the syntax does not specify:
|
|
202
|
+
|
|
203
|
+
#### <a name="a1.stringify" href="#a1.stringify">#</a> **.stringify**( _refObject_ )
|
|
204
|
+
|
|
205
|
+
Get a string representation of a reference object.
|
|
206
|
+
|
|
207
|
+
```js
|
|
208
|
+
import { a1 } from '@borgar/fx';
|
|
209
|
+
a1.stringify({
|
|
210
|
+
context: [ 'Sheet1' ],
|
|
211
|
+
range: {
|
|
212
|
+
top: 0,
|
|
213
|
+
left: 0,
|
|
214
|
+
bottom: 1,
|
|
215
|
+
right: 1
|
|
216
|
+
$top: true,
|
|
217
|
+
$left: false,
|
|
218
|
+
$bottom: false,
|
|
219
|
+
$right: true
|
|
220
|
+
}
|
|
221
|
+
});
|
|
222
|
+
// => 'Sheet1!A$1:$B2'
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
#### <a name="a1.addBounds" href="#a1.addBounds">#</a> **.addBounds**( _refObject_ )
|
|
226
|
+
|
|
227
|
+
Fill the any missing bounds in range objects. Top will be set to 0, bottom to 1048575, left to 0, and right to 16383, if they are `null` or `undefined`.
|
|
228
|
+
|
|
229
|
+
```js
|
|
230
|
+
import { a1 } from '@borgar/fx';
|
|
231
|
+
a1.addBounds({
|
|
232
|
+
context: [ 'Sheet1' ],
|
|
233
|
+
range: {
|
|
234
|
+
top: 0,
|
|
235
|
+
left: 0,
|
|
236
|
+
bottom: 1,
|
|
237
|
+
$top: true,
|
|
238
|
+
$left: false,
|
|
239
|
+
$bottom: false,
|
|
240
|
+
}
|
|
241
|
+
});
|
|
242
|
+
// => {
|
|
243
|
+
// context: [ 'Sheet1' ],
|
|
244
|
+
// range: {
|
|
245
|
+
// top: 0,
|
|
246
|
+
// left: 0,
|
|
247
|
+
// bottom: 1,
|
|
248
|
+
// right: 16383,
|
|
249
|
+
// $top: true,
|
|
250
|
+
// $left: false,
|
|
251
|
+
// $bottom: false,
|
|
252
|
+
// $right: false
|
|
253
|
+
// }
|
|
254
|
+
// }
|
|
255
|
+
```
|
|
256
|
+
|
|
164
257
|
#### <a name="a1.to" href="#a1.to">#</a> **.to**( _columnString_ )
|
|
165
258
|
|
|
166
259
|
Parse a simple string reference to an A1 range into a range object ([see above](#a1.parse)). Will accept `A1`, `A2`, `A:A`, or `1:1`.
|
|
@@ -171,17 +264,17 @@ Stringify a range object ([see above](#a1.parse)) into A1 syntax.
|
|
|
171
264
|
|
|
172
265
|
#### <a name="a1.fromCol" href="#a1.fromCol">#</a> **.fromCol**( _columnString_ )
|
|
173
266
|
|
|
174
|
-
Convert a column string representation to a 0 based offset number (`"C"` = `2`).
|
|
267
|
+
Convert a column string representation to a 0 based offset number (`"C"` = `2`). The method expects a valid column identifier made up of _only_ A-Z letters, which may be either upper or lower case. Other input will return garbage.
|
|
175
268
|
|
|
176
269
|
#### <a name="a1.toCol" href="#a1.toCol">#</a> **.toCol**( _columnNumber_ )
|
|
177
270
|
|
|
178
|
-
Convert a 0 based offset number to a column string representation (`2` = `"C"`).
|
|
271
|
+
Convert a 0 based offset number to a column string representation (`2` = `"C"`). The method expects a number between 0 and 16383. Other input will return garbage.
|
|
179
272
|
|
|
180
273
|
### .rc:
|
|
181
274
|
|
|
182
275
|
An object of methods to interpret and manipulate R1C1 style references.
|
|
183
276
|
|
|
184
|
-
#### <a name="rc.parse" href="#rc.parse">#</a> **.parse**( _refString[,
|
|
277
|
+
#### <a name="rc.parse" href="#rc.parse">#</a> **.parse**( _refString[, { allowNamed: true, allowTernary: true } ]_ )
|
|
185
278
|
|
|
186
279
|
Parse a string reference into an object representing it.
|
|
187
280
|
|
|
@@ -189,8 +282,7 @@ Parse a string reference into an object representing it.
|
|
|
189
282
|
import { rc } from '@borgar/fx';
|
|
190
283
|
rc.parse('Sheet1!R[9]C9:R[9]C9');
|
|
191
284
|
// => {
|
|
192
|
-
//
|
|
193
|
-
// sheetName: 'Sheet1',
|
|
285
|
+
// context: [ 'Sheet1' ],
|
|
194
286
|
// range: {
|
|
195
287
|
// r0: 9,
|
|
196
288
|
// c0: 8,
|
|
@@ -204,6 +296,29 @@ rc.parse('Sheet1!R[9]C9:R[9]C9');
|
|
|
204
296
|
// }
|
|
205
297
|
```
|
|
206
298
|
|
|
299
|
+
#### <a name="rc.stringify" href="#rc.stringify">#</a> **.stringify**( _refObject_ )
|
|
300
|
+
|
|
301
|
+
Get a string representation of a reference object.
|
|
302
|
+
|
|
303
|
+
```js
|
|
304
|
+
import { a1 } from '@borgar/fx';
|
|
305
|
+
a1.stringify({
|
|
306
|
+
context: [ 'Sheet1' ],
|
|
307
|
+
range: {
|
|
308
|
+
r0: 9,
|
|
309
|
+
c0: 8,
|
|
310
|
+
r1: 9,
|
|
311
|
+
c1: 8,
|
|
312
|
+
$c0: true,
|
|
313
|
+
$c1: true
|
|
314
|
+
$r0: false,
|
|
315
|
+
$r1: false
|
|
316
|
+
}
|
|
317
|
+
});
|
|
318
|
+
// => 'Sheet1!R[9]C9:R[9]C9'
|
|
319
|
+
```
|
|
320
|
+
|
|
321
|
+
|
|
207
322
|
#### <a name="rc.from" href="#rc.from">#</a> **.from**( _rangeObject_ )
|
|
208
323
|
|
|
209
324
|
Stringify a range object ([see above](#rc.parse)) into R1C1 syntax.
|
package/References.md
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
# References and Ranges
|
|
2
|
+
|
|
3
|
+
In Excels spreadsheet formula language terminology, a reference is similar to what is in most programming is called a variable. Spreadsheets do not have variables though, they have cells. The cells can be referenced in formulas, either directly (such as `=SUM(A1)`), or through aliases (such as `=SUM(someName)`).
|
|
4
|
+
|
|
5
|
+
A range is when a cell, or a set of cells, is referenced directly. Ranges in formulas can come in one of two syntax styles: The commonly known A1 style, as well as R1C1 style where both axes are numerical. Only one style can be used at a time in a formula.
|
|
6
|
+
|
|
7
|
+
This tokenizer considers there to be three "types" of ranges:
|
|
8
|
+
|
|
9
|
+
## Ranges (`RANGE`)
|
|
10
|
+
|
|
11
|
+
The basic type of range will be referencing either:
|
|
12
|
+
|
|
13
|
+
* A single cell, like `A1` or `AF31`.
|
|
14
|
+
* A bounded rectangle of cells, like `A1:B2` or `AF17:AF31`.
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
## Range ternary (`RANGE_TERNARY`)
|
|
18
|
+
|
|
19
|
+
Ternary ranges are rectangles of cells defined by only three of the four possible sides. They are are unbounded in either bottom or right dimension:
|
|
20
|
+
|
|
21
|
+
* A rectangle of cells that is unbounded to the bottom, like `A1:A` or `C3:D`.
|
|
22
|
+
* A rectangle of cells that is unbounded to the right, like `A1:1` or `F2:5`.
|
|
23
|
+
|
|
24
|
+
This type of range is not supported in Excel, so it is an opt-in for the tokenizer (see README.md).
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
## Range beams (`RANGE_BEAM`)
|
|
28
|
+
|
|
29
|
+
Range beams are rectangles of cells that are unbounded in either left and right, or top and bottom dimensions.
|
|
30
|
+
|
|
31
|
+
* A rectangle of cells that is unbounded to the top and bottom, like `A:A` or `C:D`.
|
|
32
|
+
* A rectangle of cells that is unbounded to the left and right, like `1:1` or `2:5`.
|
|
33
|
+
|
|
34
|
+
---
|
|
35
|
+
|
|
36
|
+
Spreadsheet applications will normalize all of these types when you enter a formula, flipping the left/right and top/bottom coordinates as needed to keep the range top to bottom and left to right.
|
|
37
|
+
|
|
38
|
+
The library has tools to both normalize the ranges, as well as filling in the missing boundaries (see README.md).
|
|
39
|
+
|
package/dist/fx.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";function t(t){return t.split(/(\d+|[a-zA-Z]+)/).every((t=>{const e=parseInt(t,36);return!!isNaN(e)||(isFinite(t)?e<=2183880786:e<=43321)}))}const e={R:1048577,"R[":1048576,C:16385,"C[":16384};function r(t){const r=/([RC]\[?)(-?\d+)/gi;let n;for(;null!==(n=r.exec(t));){const t=e[n[1]],r=parseInt(n[2],10);if(r>=t||r<=-t)return!1}return!0}const n="range",o="range-beam",a=/^#(NAME\?|FIELD!|CALC!|VALUE!|REF!|DIV\/0!|NULL!|NUM!|N\/A|GETTING_DATA\b|SPILL!|UNKNOWN!|FIELD\b|CALC\b|SYNTAX\?|ERROR!)/i,i=/^(<=|>=|<>|[-+/*^%&<>=]|[{},;]|[()]|@|:|!|#)/,l=/^(TRUE|FALSE)\b/i,u=/^[A-Z_]+[A-Z\d_.]+(?=\s*\()/i,c=/^\n+/,p=/^[ \f\r\t\v\u00a0\u1680\u2000-\u200a\u2028\u2029\u202f\u205f\u3000\ufeff]+/,s=/^"(?:""|[^"])*("|$)/,f=/^'(?:''|[^'])*('|$)/,$=/^\[(?:[^\]])+(\]|$)/,h=/^([^ \t\n$!"`'#%&(){}<>,;:^@|~=*+-]+)(?=!)/,g=/^\$?[A-Z]{1,3}:\$?[A-Z]{1,3}/i,m=/^\$?[1-9][0-9]{0,6}:\$?[1-9][0-9]{0,6}/i,b=/^\$?[A-Z]{1,3}\$?[1-9][0-9]{0,6}/i,d="(?:R(?:\\[[+-]?\\d+\\]|[1-9][0-9]{0,6})?)",v="(?:C(?:\\[[+-]?\\d+\\]|[1-9][0-9]{0,4})?)",R=new RegExp(`^${v}(:${v})?(?=\\W|$)`,"i"),x=new RegExp(`^${d}(:${d})?(?=\\W|$)`,"i"),N=new RegExp(`^(?:(?=[RC])${d}${v})`,"i"),A=/^(?:\d+(\.\d+)?(?:[eE][+-]?\d+)?|\d+)/,E=/^[A-Z\d\\_.?]+/i,C=[["error",a],["operator",i],["bool",l],["function",u],["newline",c],["whitespace",p],["string",s],["path-quote",f],["path-brace",$],["path-prefix",h],[n,b,t],[o,g,t],[o,m,t],["number",A],["range-named",E]],y=[["error",a],["operator",i],["bool",l],["function",u],["newline",c],["whitespace",p],["string",s],["path-quote",f],["path-brace",$],["path-prefix",h],[n,N,r],[o,x,r],[o,R,r],["number",A],["range-named",E]],I=[["operator",/^[!:]/],["path-quote",f],["path-brace",$],["path-prefix",h],[n,b,t],[o,g,t],[o,m,t],["range-named",E]],w=[["operator",/^!/],["path-quote",f],["path-brace",$],["path-prefix",h],[n,N,r],[o,x,r],[o,R,r],["range-named",E]],k=(t,e)=>t&&t.type===e,T=t=>t&&":"===t.value,L=t=>t&&"!"===t.value,O={emitRanges:!1,mergeRanges:!0,negativeNumbers:!1,r1c1:!1};function M(t,e){let r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};const{emitRanges:a,mergeRanges:i,negativeNumbers:l}=Object.assign({},O,r),u=[];let c=0;const p=t=>u[u.length-t],s=t=>{const e=u.filter((t=>!k(t,"whitespace")&&!k(t,"newline")));return e[e.length-t]};if(/^=/.test(t)){const t={type:"fx-prefix",value:"=",...a?{range:[0,1]}:{}};c++,u.push(t)}for(;c<t.length;){const r=c,f=t.slice(c);let $="",h="";for(let t=0;t<e.length;t++){const[r,n,o]=e[t],a=n.exec(f);if(a&&(!o||o(a[0]))){$=r,h=a[0],c+=a[0].length;break}}$||($="unknown",h=t[c],c++);let g={type:$,value:h,...a?{range:[r,c]}:{}};if(("string"!==$||h.endsWith('"'))&&("path-brace"!==$||h.endsWith("]"))&&("path-quote"!==$||h.endsWith("'"))||(g.unterminated=!0),l&&"number"===$){const t=p(1);if(t&&k(t,"operator")&&"-"===t.value){const t=s(2);(!t||k(t,"fx-prefix")||k(t,"operator")&&!["%","}",")","#"].includes(t.value))&&(u.pop(),g.value="-"+h)}}if(i&&($===n||"range-named"===$||$===o)){const t=[];if(T(p(1))&&k(p(2),n)&&$===n&&t.unshift(...u.splice(-2,2)),L(p(1)))if(k(p(2),"path-quote")||k(p(2),"path-brace"))t.unshift(...u.splice(-2,2));else if(k(p(2),"path-prefix")){const e=k(p(3),"path-brace")?3:2;t.unshift(...u.splice(-e,e))}t.length&&(g={type:$,value:t.map((t=>t.value)).join("")+h,...a?{range:[t[0].range[0],c]}:{}})}u.push(g)}return u}function _(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};const r=e.r1c1?y:C;return M(t,r,e)}const Z=t=>t.slice(1,-1).replace(/''/g,"'"),S=t=>t&&":"===t.value&&{},U=t=>t&&t.type===n&&{r0:t.value},W=t=>t&&t.type===n&&{r1:t.value},q=t=>t&&"!"===t.value&&{},F=t=>t&&t.type===o&&{r0:t.value},P=t=>t&&"path-prefix"===t.type&&/^[^:\\/?*[\]]{0,31}$/.test(t.value)&&{sheetName:t.value},G=t=>t&&"path-brace"===t.type&&{workbookName:t.value.slice(1,-1)},X=t=>t&&"range-named"===t.type&&{name:t.value},j=t=>{if(t&&"path-quote"===t.type){const e=/(?:\[(.+?)\])?([^[\]]+?)$/.exec(Z(t.value));if(e){const[,t,r]=e;if(!r||/^[^:\\/?*[\]]{0,31}$/.test(r))return{workbookName:t||"",sheetName:r||""}}}},D=[[U],[U,S,W],[F],[j,q,U],[j,q,U,S,W],[j,q,F],[P,q,U],[P,q,U,S,W],[P,q,F],[G,P,q,U],[G,P,q,U,S,W],[G,P,q,F]],B=D.concat([[X],[t=>t&&"path-prefix"===t.type&&{workbookName:t.value},q,X],[t=>t&&"path-quote"===t.type&&{workbookName:Z(t.value)},q,X]]);function H(t){let e=!(arguments.length>1&&void 0!==arguments[1])||arguments[1],r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:[];const n=M(t,r,{emitRanges:!1,mergeRanges:!1}),o={sheetName:"",workbookName:"",r0:"",r1:"",name:""};n.length&&"fx-prefix"===n[0].type&&n.shift();const a=e?B:D;for(let t=0;t<a.length;t++){const e={...o};if(a[t].length===n.length){if(a[t].every(((t,r)=>{const o=t(n[r]);return Object.assign(e,o),o})))return e}}return null}function z(t){const e=(t||"").toUpperCase();let r=0,n=0;for(;n!==e.length;++n){const t=e.charCodeAt(n);t>=65&&t<=90&&(r=26*r+t-64)}return r-1}function K(t){let e=t,r="";for(;e>=0;)r=String.fromCharCode(e%26+65)+r,e=Math.floor(e/26)-1;return r}function V(t){return+t-1}function Q(t){return String(t+1)}function Y(t){const{top:e,left:r,bottom:n,right:o}=t;return{top:e,left:r,bottom:n,right:o,$left:!1,$right:!1,$top:!1,$bottom:!1}}function J(t){const e=t=>t?"$":"",{top:r,left:n,bottom:o,right:a,$left:i,$right:l,$top:u,$bottom:c}=t;return 0===r&&1048575===o?e(i)+K(n)+":"+e(l)+K(a):0===n&&16383===a?e(u)+Q(r)+":"+e(c)+Q(o):null==a||null==o||a===n&&o===r?e(i)+K(n)+e(u)+Q(r):e(i)+K(n)+e(u)+Q(r)+":"+e(l)+K(a)+e(c)+Q(o)}function tt(t){let e,r=0,n=0,o=1048575,a=16383,i=!1,l=!1,u=!1,c=!1;if(e=/^(\$?)([A-Z]{1,3}):(\$?)([A-Z]{1,3})$/.exec(t)){const t=z(e[2]),p=z(e[4]);return n=Math.min(t,p),a=Math.max(t,p),l=!!e[t<=p?1:3],c=!!e[t<=p?3:1],i=!0,u=!0,{top:r,left:n,bottom:o,right:a,$top:i,$left:l,$bottom:u,$right:c}}if(e=/^(\$?)([1-9]\d{0,6}):(\$?)([1-9]\d{0,6})$/.exec(t)){const t=V(e[2]),p=V(e[4]);return r=Math.min(t,p),o=Math.max(t,p),i=!!e[t<=p?1:3],u=!!e[t<=p?3:1],l=!0,c=!0,{top:r,left:n,bottom:o,right:a,$top:i,$left:l,$bottom:u,$right:c}}{const[p,s]=t.split(":");if(e=/^(\$?)([A-Z]{1,3})(\$?)([1-9]\d{0,6})$/i.exec(p))return n=z(e[2]),r=V(e[4]),l=!!e[1],i=!!e[3],s&&(e=/^(\$?)([A-Z]{1,3})(\$?)([1-9]\d{0,6})$/i.exec(s))?(a=z(e[2]),o=V(e[4]),c=!!e[1],u=!!e[3],o<r&&([r,o,i,u]=[o,r,u,i]),a<n&&([n,a,l,c]=[a,n,c,l])):(o=r,a=n,u=i,c=l),{top:r,left:n,bottom:o,right:a,$top:i,$left:l,$bottom:u,$right:c}}return null}function et(t){let e=!(arguments.length>1&&void 0!==arguments[1])||arguments[1];const r=H(t,e,I);if(r&&(r.r0||r.name)){let t=null;return r.r0&&(t=r.r1?tt(r.r0+":"+r.r1):tt(r.r0)),r.name||t?(r.range=t,delete r.r0,delete r.r1,r):null}return null}var rt={fromCol:z,toCol:K,toRelative:Y,toAbsolute:function(t){const{top:e,left:r,bottom:n,right:o}=t;return{top:e,left:r,bottom:n,right:o,$left:!0,$right:!0,$top:!0,$bottom:!0}},to:J,from:tt,parse:et};function nt(){let t=1;return()=>"fxg"+t++}function ot(t,e){return e?String(t+1):t?"["+t+"]":""}function at(t){const{r0:e,c0:r,r1:n,c1:o,$c0:a,$c1:i,$r0:l,$r1:u}=t;if(0===e&&1048575===n){const t=ot(r,a),e=ot(o,i);return"C"+(t===e?t:t+":C"+e)}if(0===r&&16383===o){const t=ot(e,l),r=ot(n,u);return"R"+(t===r?t:t+":R"+r)}const c=ot(e,l),p=ot(n,u),s=ot(r,a),f=ot(o,i);return c!==p||s!==f?"R"+c+"C"+s+":R"+p+"C"+f:"R"+c+"C"+s}function it(t){let e=0,r=0,n=1048575,o=16383,a=!1,i=!1,l=!1,u=!1;const c=/^R(?:\[([+-]?\d+)\]|(\d+))?/.exec(t);c?(c[1]?e=parseInt(c[1],10):c[2]&&(e=parseInt(c[2],10)-1,a=!0),n=e,l=a,t=t.slice(c[0].length)):(a=!0,l=!0);const p=/^C(?:\[([+-]?\d+)\]|(\d+))?/.exec(t);return p?(p[1]?r=parseInt(p[1],10):p[2]&&(r=parseInt(p[2],10)-1,i=!0),o=r,u=i,t=t.slice(p[0].length)):(i=!0,u=!0),!c&&!p||t.length?null:{r0:e,c0:r,r1:n,c1:o,$r0:a,$c0:i,$r1:l,$c1:u}}function lt(t){const[e,r]=t.split(":",2),n=it(e);if(!n)return null;if(n&&r){const t=it(r);if(!t)return null;n.r1=t.r1,n.c1=t.c1,n.$r1=t.$r1,n.$c1=t.$c1}return n}var ut={to:at,from:lt,parse:function(t){let e=!(arguments.length>1&&void 0!==arguments[1])||arguments[1];const r=H(t,e,w);if(r&&(r.r0||r.name)){const t=r.r1?lt(r.r0+":"+r.r1):lt(r.r0);return r.name||t?(r.range=t,delete r.r0,delete r.r1,r):null}return null}};function ct(t,e,r,n){let o=t;return e||(o=r+t,o<0&&(o=n+o+1),o>n&&(o-=n+1)),o}const pt={OPERATOR:"operator",BOOLEAN:"bool",ERROR:"error",NUMBER:"number",FUNCTION:"function",NEWLINE:"newline",WHITESPACE:"whitespace",STRING:"string",PATH_QUOTE:"path-quote",PATH_BRACE:"path-brace",PATH_PREFIX:"path-prefix",RANGE:n,RANGE_BEAM:o,RANGE_NAMED:"range-named",FX_PREFIX:"fx-prefix",UNKNOWN:"unknown"};exports.MAX_COLS=16383,exports.MAX_ROWS=1048575,exports.a1=rt,exports.addMeta=function(t){let{sheetName:e="",workbookName:r=""}=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};const a=[];let i=null;const l={},u=nt();return t.forEach(((t,c)=>{if(t.index=c,t.depth=a.length,"("===t.value)t.depth=a.length+1,a.push(t);else if(")"===t.value){const e=a.pop();if(e){const r=u();t.groupId=r,t.depth=e.depth,e.groupId=r}else t.error=!0}else if("{"===t.value)i?t.error=!0:i=t;else if("}"===t.value){if(i){const e=u();t.groupId=e,i.groupId=e}else t.error=!0;i=null}else if(t.type===n||t.type===o){const n=et(t.value,!1),o=n&&`[${n.workbookName||r}]${n.sheetName||e}!${n.range?J(Y(n.range)):n.name}`.toLowerCase();o&&(o in l?t.groupId=l[o]:(t.groupId=u(),l[o]=t.groupId))}else"unknown"===t.type&&(t.error=!0)})),t},exports.rc=ut,exports.tokenTypes=pt,exports.tokenize=_,exports.translateToA1=function(t,e){const r=tt(e),a="string"==typeof t,i=a?_(t,{emitRanges:!1,mergeRanges:!1,r1c1:!0}):t;return i.forEach((t=>{if(t.type===n||t.type===o){const e={},n=lt(t.value),o=ct(n.r0,n.$r0,r.top,1048575),a=ct(n.r1,n.$r1,r.top,1048575);o>a?(e.top=a,e.$top=n.$r1,e.bottom=o,e.$bottom=n.$r0):(e.top=o,e.$top=n.$r0,e.bottom=a,e.$bottom=n.$r1);const i=ct(n.c0,n.$c0,r.left,16383),l=ct(n.c1,n.$c1,r.left,16383);i>l?(e.left=l,e.$left=n.$c1,e.right=i,e.$right=n.$c0):(e.left=i,e.$left=n.$c0,e.right=l,e.$right=n.$c1),t.value=J(e)}})),a?i.map((t=>t.value)).join(""):i},exports.translateToRC=function(t,e){const{top:r,left:a}=tt(e),i="string"==typeof t,l=i?_(t,{emitRanges:!1,mergeRanges:!1,r1c2:!1}):t;return l.forEach((t=>{if(t.type===n){const e={},n=tt(t.value);e.r0=n.$top?n.top:n.top-r,e.$r0=n.$top,e.r1=n.$bottom?n.bottom:n.bottom-r,e.$r1=n.$bottom,e.c0=n.$left?n.left:n.left-a,e.$c0=n.$left,e.c1=n.$right?n.right:n.right-a,e.$c1=n.$right,t.value=at(e)}else if(t.type===o){const e={},n=tt(t.value);e.r0=n.$top?n.top:n.top-r,e.$r0=n.$top,e.r1=n.$bottom?n.bottom:n.bottom-r,e.$r1=n.$bottom,e.c0=n.$left?n.left:n.left-a,e.$c0=n.$left,e.c1=n.$right?n.right:n.right-a,e.$c1=n.$right,t.value=at(e)}})),i?l.map((t=>t.value)).join(""):l};
|
|
1
|
+
"use strict";const e="range",t="unknown";function n(e){const t=/(?:\[(.+?)\])?([^[\]]+?)$/.exec(e);if(t){const[,e,n]=t;return{context:[e,n].filter(Boolean)}}}const r=e=>e&&":"===e.value&&{},l=t=>t&&t.type===e&&{r0:t.value},o=e=>e&&"range_ternary"===e.type&&{r0:e.value},u=t=>t&&t.type===e&&{r1:t.value},a=e=>e&&"operator"===e.type&&"!"===e.value&&{},c=e=>e&&"range_beam"===e.type&&{r0:e.value},i=e=>e&&"context"===e.type?n(e.value):e&&"context_quote"===e.type?n(e.value.slice(1,-1).replace(/''/g,"'")):void 0,f=e=>e&&"range_named"===e.type&&{name:e.value},s=[[o],[l,r,u],[l],[c],[i,a,o],[i,a,l,r,u],[i,a,l],[i,a,c]],g=s.concat([[f],[i,a,f]]);function p(e,t){const n={emitRanges:!1,mergeRanges:!1,allowTernary:!1,allowNamed:!0,r1c1:!1,...t},r=re(e,K,n),l={context:[],r0:"",r1:"",name:""};r.length&&"fx_prefix"===r[0].type&&r.shift();const o=n.allowNamed?g:s;for(let e=0;e<o.length;e++){const t={...l};if(o[e].length===r.length){if(o[e].every(((e,n)=>{const l=e(r[n]);return Object.assign(t,l),l})))return t}}return null}const $=/[^0-9A-Za-z._¡¤§¨ª\u00ad¯-\uffff]/;function m(e){let t="",n=0,r=0;const l=e.context||[];for(let e=l.length;e>-1;e--){const o=l[e];if(o){t=(r%2?"["+o+"]":o)+t,n+=$.test(o),r++}}return n&&(t="'"+t.replace(/'/g,"''")+"'"),t?t+"!":t}function d(e){const t=e||"",n=t.length;let r=0;if(n>2){const e=t.charCodeAt(n-3);r+=676*(1+e-(e>95?32:0)-65)}if(n>1){const e=t.charCodeAt(n-2);r+=26*(1+e-(e>95?32:0)-65)}if(n){const e=t.charCodeAt(n-1);r+=e-(e>95?32:0)-65}return r}function x(e){return(e>=702?String.fromCharCode(((e-702)/676-0)%26+65):"")+(e>=26?String.fromCharCode(Math.floor((e/26-1)%26+65)):"")+String.fromCharCode(e%26+65)}const h=(e,t)=>(t?"$":"")+x(e),y=(e,t)=>(t?"$":"")+String(e+1);function v(e){const{top:t,left:n,bottom:r,right:l,$left:o,$right:u,$top:a,$bottom:c}=e,i=null==n,f=null==l,s=null==t,g=null==r;return 0===t&&r>=1048575||s&&g?h(n,o)+":"+h(l,u):0===n&&l>=16383||i&&f?y(t,a)+":"+y(r,c):i||s||f||!g?i||!s||f||g?i||s||!f||g?!i||s||f||g?l!==n||r!==t||u!==o||c!==a?h(n,o)+y(t,a)+":"+h(l,u)+y(r,c):h(n,o)+y(t,a):h(l,u)+y(t,a)+":"+y(r,c):h(n,o)+y(t,a)+":"+y(r,c):h(n,o)+y(r,c)+":"+h(l,u):h(n,o)+y(t,a)+":"+h(l,u)}function R(e){const t=/^(?=.)(\$(?=\D))?([A-Za-z]{0,3})?(\$)?([1-9][0-9]{0,6})?$/.exec(e);return t&&(t[2]||t[4])?[t[4]?(n=t[4],+n-1):null,t[2]?d(t[2]):null,!!t[3],!!t[1]]:null;var n}function _(e){let t=null,n=null,r=null,l=null,o=!1,u=!1,a=!1,c=!1;const[i,f,s]=e.split(":");if(s)return null;const g=R(i),p=f?R(f):null;if(!g||f&&!p)return null;if(null!=g[0]&&null!=g[1]?[t,n,o,u]=g:null==g[0]&&null!=g[1]?[,n,,u]=g:null!=g[0]&&null==g[1]&&([t,,o]=g),f)null!=p[0]&&null!=p[1]?[r,l,a,c]=p:null==p[0]&&null!=p[1]?[,l,,c]=p:null!=p[0]&&null==p[1]&&([r,,a]=p);else{if(null==t||null==n)return null;r=t,l=n,a=o,c=u}return null!=l&&(null==n||null!=n&&l<n)&&([n,l,u,c]=[l,n,c,u]),null!=r&&(null==t||null!=t&&r<t)&&([t,r,o,a]=[r,t,a,o]),{top:t,left:n,bottom:r,right:l,$top:o,$left:u,$bottom:a,$right:c}}function b(e){let{allowNamed:t=!0,allowTernary:n=!1}=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};const r=p(e,{allowNamed:t,allowTernary:n,r1c1:!1});if(r&&(r.r0||r.name)){let e=null;return r.r0&&(e=_(r.r1?r.r0+":"+r.r1:r.r0)),r.name||e?(r.range=e,delete r.r0,delete r.r1,r):null}return null}function E(e){return m(e)+(e.name?e.name:v(e.range))}function w(e){return null==e.top&&(e.top=0,e.$top=!1),null==e.bottom&&(e.bottom=1048575,e.$bottom=!1),null==e.left&&(e.left=0,e.$left=!1),null==e.right&&(e.right=16383,e.$right=!1),e}var A={fromCol:d,toCol:x,toRelative:function(e){const{top:t,left:n,bottom:r,right:l}=e;return{top:t,left:n,bottom:r,right:l,$left:!1,$right:!1,$top:!1,$bottom:!1}},toAbsolute:function(e){const{top:t,left:n,bottom:r,right:l}=e;return{top:t,left:n,bottom:r,right:l,$left:!0,$right:!0,$top:!0,$bottom:!0}},to:v,from:_,parse:b,addBounds:w,stringify:E};const N=/^(\[(?:[^\]])+\])?([0-9A-Za-z._¡¤§¨ª\u00ad¯-\uffff]+)(?=!)/,C=/^'(?:''|[^'])*('|$)(?=!)/,T="\\$?[A-Z]{1,3}\\$?[1-9][0-9]{0,6}",I="\\$?[A-Z]{1,3}",O="\\$?[1-9][0-9]{0,6}",L=new RegExp(`^${I}:${I}`,"i"),S=new RegExp(`^${O}:${O}`,"i"),M=new RegExp(`^${T}`,"i"),Z=new RegExp(`^((${I}|${O}):${T}|${T}:(${I}|${O}))(?![\\w($.])`,"i"),q="(?:R(?:\\[[+-]?\\d+\\]|[1-9][0-9]{0,6})?)",U="(?:C(?:\\[[+-]?\\d+\\]|[1-9][0-9]{0,4})?)",W=new RegExp(`^${U}(:${U})?(?=\\W|$)`,"i"),k=new RegExp(`^${q}(:${q})?(?=\\W|$)`,"i"),z=new RegExp(`^(?:(?=[RC])${q}${U})`,"i"),B=new RegExp(`^(${q}${U}(:${U}|:${q})(?![[\\d])|(${q}|${U})(:${q}${U}))(?=\\W|$)`,"i"),F=/^[a-zA-Z\\_\u00a1-\uffff][a-zA-Z0-9\\_.?\u00a1-\uffff]{0,254}/i;function G(e,t){return n=>{const r=t.exec(n);if(r)return{type:e,value:r[0]}}}const X=/([RC])(\[?)(-?\d+)/gi,j=/(\d+|[a-zA-Z]+)/gi;function D(t,n){let r,l;if(n.r1c1){if(n.allowTernary&&(r=B.exec(t))?l={type:"range_ternary",value:r[0]}:(r=z.exec(t))?l={type:e,value:r[0]}:((r=k.exec(t))||(r=W.exec(t)))&&(l={type:"range_beam",value:r[0]}),l){for(X.lastIndex=0;null!==(r=X.exec(l.value));){const e=("R"===r[1]?1048575:16383)+(r[2]?1:0),t=parseInt(r[3],10);if(t>=e||t<=-e)return null}return l}}else if(n.allowTernary&&(r=Z.exec(t))?l={type:"range_ternary",value:r[0]}:(r=L.exec(t))||(r=S.exec(t))?l={type:"range_beam",value:r[0]}:(r=M.exec(t))&&(l={type:e,value:r[0]}),l){for(j.lastIndex=0;null!==(r=j.exec(l.value));)if(/^\d/.test(r[1])){if(parseInt(r[1],10)-1>1048575)return null}else if(d(r[1])>16383)return null;return l}}const P=[G("error",/^#(NAME\?|FIELD!|CALC!|VALUE!|REF!|DIV\/0!|NULL!|NUM!|N\/A|GETTING_DATA\b|SPILL!|UNKNOWN!|FIELD\b|CALC\b|SYNTAX\?|ERROR!)/i),G("operator",/^(<=|>=|<>|[-+/*^%&<>=]|[{},;]|[()]|@|:|!|#)/),G("bool",/^(TRUE|FALSE)\b/i),G("func",/^[A-Z_]+[A-Z\d_.]*(?=\()/i),G("newline",/^\n+/),G("whitespace",/^[ \f\r\t\v\u00a0\u1680\u2000-\u200a\u2028\u2029\u202f\u205f\u3000\ufeff]+/),G("string",/^"(?:""|[^"])*("|$)/),G("context_quote",C),G("context",N),D,G("number",/^(?:\d+(\.\d+)?(?:[eE][+-]?\d+)?|\d+)/),G("range_named",F)],K=[function(e,t){return t.r1c1?"!"===e[0]?{type:"operator",value:e[0]}:null:"!"===e[0]||":"===e[0]?{type:"operator",value:e[0]}:null},G("context_quote",C),G("context",N),D,G("range_named",F)],V={};function Y(e,t){if(e.length){const n=e[0];t[n]=t[n]||{},Y(e.slice(1),t[n])}else t.$=!0}[[e,":",e],[e],["range_beam"],["range_ternary"],["context","!",e,":",e],["context","!",e],["context","!","range_beam"],["context","!","range_ternary"],["context_quote","!",e,":",e],["context_quote","!",e],["context_quote","!","range_beam"],["context_quote","!","range_ternary"],["range_named"],["context","!","range_named"],["context_quote","!","range_named"]].forEach((e=>Y(e.concat().reverse(),V)));const H=function(e,t,n){let r=arguments.length>3&&void 0!==arguments[3]?arguments[3]:0;const l=e[n-r];if(l){const o="operator"===l.type?l.value:l.type;if(o in t)return H(e,t[o],n,r+1)}return t.$?r:0};function Q(e){const t=[];for(let n=e.length-1;n>=0;n--){let r=e[n];const l=H(e,V,n);if(l){const t=e.slice(n-l+1,n+1);r={...r},r.value=t.map((e=>e.value)).join(""),r.range&&t[0].range&&(r.range[0]=t[0].range[0]),n-=l-1}t.unshift(r)}return t}const J=(e,t)=>e&&e.type===t,ee={emitRanges:!1,mergeRanges:!0,allowTernary:!1,negativeNumbers:!0,r1c1:!1},te=e=>"range_named"===e.type||"func"===e.type,ne=e=>!J(e,"operator")||"%"===e.value||"}"===e.value||")"===e.value||"#"===e.value;function re(e,n){let r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};const l=Object.assign({},ee,r),{emitRanges:o,mergeRanges:u,negativeNumbers:a}=l,c=[];let i=0,f=null,s=null,g=null;const p=e=>{const n=e.type===t,r=g&&g.type===t;g&&(n&&r||n&&te(g)||r&&te(e))?(g.value+=e.value,g.type=t,o&&(g.range[1]=e.range[1])):(c.push(e),g=e,"whitespace"!==e.type&&"newline"!==e.type&&(s=f,f=e))};if(/^=/.test(e)){i++,p({type:"fx_prefix",value:"=",...o?{range:[0,1]}:{}})}for(;i<e.length;){const r=i,u=e.slice(i);let $="",m="";for(let e=0;e<n.length;e++){const t=n[e](u,l);if(t){$=t.type,m=t.value,i+=m.length;break}}$||($=t,m=e[i],i++);const d={type:$,value:m,...o?{range:[r,i]}:{}};if("string"===$){const e=m.length;if('""'===m);else if('"'===m||'"'!==m[e-1])d.unterminated=!0;else if('""'!==m&&'"'===m[e-2]){let t=e-1;for(;'"'===m[t];)t--;!(t+1)^(e-t+1)%2==0&&(d.unterminated=!0)}}if(a&&"number"===$){const e=g;if(e&&J(e,"operator")&&"-"===e.value&&(!s||J(s,"fx_prefix")||!ne(s))){const e=c.pop();d.value="-"+m,o&&(d.range[0]=e.range[0]),f=s,g=c[c.length-1]}}p(d)}return u?Q(c):c}function le(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return re(e,P,t)}function oe(){let e=1;return()=>"fxg"+e++}function ue(e,t){return null==e&&null==t||e===t}function ae(e,t){return!e&&!t||String(e).toLowerCase()===String(t).toLowerCase()}function ce(e,t){return(!e.name&&!t.name||e.name===t.name)&&(!!(!e.range&&!t.range||ue(e.range.top,t.range.top)&&ue(e.range.bottom,t.range.bottom)&&ue(e.range.left,t.range.left)&&ue(e.range.right,t.range.right))&&!(!ae(e.context[0],t.context[0])||!ae(e.context[1],t.context[1])))}function ie(e,t){return t?String(e+1):e?"["+e+"]":""}function fe(e){const{r0:t,c0:n,r1:r,c1:l,$c0:o,$c1:u,$r0:a,$r1:c}=e,i=null==t,f=null==r,s=null==n,g=null==l;if(0===t&&r>=1048575||i&&f){const e=ie(n,o),t=ie(l,u);return"C"+(e===t?e:e+":C"+t)}if(0===n&&l>=16383||s&&g){const e=ie(t,a),n=ie(r,c);return"R"+(e===n?e:e+":R"+n)}const p=ie(t,a),$=ie(r,c),m=ie(n,o),d=ie(l,u);return i||f||s||g?(i?"":"R"+p)+(s?"":"C"+m)+":"+(f?"":"R"+$)+(g?"":"C"+d):p!==$||m!==d?"R"+p+"C"+m+":R"+$+"C"+d:"R"+p+"C"+m}function se(e){let t=null,n=null,r=null,l=null;const o=/^R(?:\[([+-]?\d+)\]|(\d+))?/.exec(e);o&&(o[1]?(t=parseInt(o[1],10),r=!1):o[2]?(t=parseInt(o[2],10)-1,r=!0):(t=0,r=!1),e=e.slice(o[0].length));const u=/^C(?:\[([+-]?\d+)\]|(\d+))?/.exec(e);return u&&(u[1]?(n=parseInt(u[1],10),l=!1):u[2]?(n=parseInt(u[2],10)-1,l=!0):(n=0,l=!1),e=e.slice(u[0].length)),!o&&!u||e.length?null:[t,n,r,l]}function ge(e){let t=null;const[n,r]=e.split(":",2),l=se(n);if(l){const[e,n,o,u]=l;if(!r)return null!=e&&null==n?{r0:e,c0:null,r1:e,c1:null,$r0:o,$c0:!1,$r1:o,$c1:!1}:null==e&&null!=n?{r0:null,c0:n,r1:null,c1:n,$r0:!1,$c0:u,$r1:!1,$c1:u}:{r0:e||0,c0:n||0,r1:e||0,c1:n||0,$r0:o||!1,$c0:u||!1,$r1:o||!1,$c1:u||!1};{const l=se(r);if(!l)return null;{t={};const[r,a,c,i]=l;null!=e&&null!=r?(t.r0=o===c?Math.min(e,r):e,t.$r0=o,t.r1=o===c?Math.max(e,r):r,t.$r1=c):null!=e&&null==r?(t.r0=e,t.$r0=o,t.r1=null,t.$r1=o):null==e&&null!=r?(t.r0=r,t.$r0=c,t.r1=null,t.$r1=c):null==e&&null==r&&(t.r0=null,t.$r0=!1,t.r1=null,t.$r1=!1),null!=n&&null!=a?(t.c0=u===i?Math.min(n,a):n,t.$c0=u,t.c1=u===i?Math.max(n,a):a,t.$c1=i):null!=n&&null==a?(t.c0=n,t.$c0=u,t.c1=null,t.$c1=u):null==n&&null!=a?(t.c0=a,t.$c0=i,t.c1=null,t.$c1=i):null==n&&null==a&&(t.c0=null,t.$c0=!1,t.c1=null,t.$c1=!1)}}}return t}var pe={to:fe,from:ge,parse:function(e){let{allowNamed:t=!0,allowTernary:n=!1}=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};const r=p(e,{allowNamed:t,allowTernary:n,r1c1:!0});if(r&&(r.r0||r.name)){const e=r.r1?ge(r.r0+":"+r.r1):ge(r.r0);return r.name||e?(r.range=e,delete r.r0,delete r.r1,r):null}return null},stringify:function(e){return m(e)+(e.name?e.name:fe(e.range))}};function $e(t){return!!t&&(t.type===e||"range_beam"===t.type||"range_ternary"===t.type)}const me=(e,t,n)=>null==t?null:e?t:t-n;function de(e,t,n,r){let l=e;return null==l||t||(l=n+e,l<0&&(l=r+l+1),l>r&&(l-=r+1)),l}const xe={OPERATOR:"operator",BOOLEAN:"bool",ERROR:"error",NUMBER:"number",FUNCTION:"func",NEWLINE:"newline",WHITESPACE:"whitespace",STRING:"string",CONTEXT:"context",CONTEXT_QUOTE:"context_quote",RANGE:e,RANGE_BEAM:"range_beam",RANGE_TERNARY:"range_ternary",RANGE_NAMED:"range_named",FX_PREFIX:"fx_prefix",UNKNOWN:t};exports.MAX_COLS=16383,exports.MAX_ROWS=1048575,exports.a1=A,exports.addMeta=function(n){let{sheetName:r="",workbookName:l=""}=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};const o=[];let u=null;const a=oe(),c=[],i=()=>o.length+(u?1:0);return n.forEach(((n,f)=>{if(n.index=f,n.depth=i(),"("===n.value)o.push(n),n.depth=i();else if(")"===n.value){const e=o.pop();if(e){const t=a();n.groupId=t,n.depth=e.depth,e.groupId=t}else n.error=!0}else if("{"===n.value)u?n.error=!0:(u=n,n.depth=i());else if("}"===n.value){if(u){const e=a();n.groupId=e,n.depth=u.depth,u.groupId=e}else n.error=!0;u=null}else if(n.type===e||"range_beam"===n.type||"range_ternary"===n.type){const e=b(n.value,{allowNamed:!1,allowTernary:!0});if(e&&e.range){if(e.source=n.value,e.context.length){if(1===e.context.length){const t=e.context[0];e.context=t===r||t===l?[l,r]:[l,t]}}else e.context=[l,r];const t=c.find((t=>ce(t,e)));t?n.groupId=t.groupId:(e.groupId=a(),n.groupId=e.groupId,c.push(e))}}else n.type===t&&(n.error=!0)})),n},exports.fixRanges=function e(t){let n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{addBounds:!1};if("string"==typeof t)return e(le(t,n),n).map((e=>e.value)).join("");if(!Array.isArray(t))throw new Error("fixRanges expects an array of tokens");const{addBounds:r,r1c1:l}=n;if(l)throw new Error("fixRanges does not have an R1C1 mode");return t.map((e=>{if($e(e)){const t=b(e.value,n),l=t.range;r&&w(l);const o={...e};return o.value=E(t),o.range&&(o.range=l),o}return e}))},exports.isRange=$e,exports.isReference=function(t){return!!t&&(t.type===e||"range_beam"===t.type||"range_ternary"===t.type||"range_named"===t.type)},exports.mergeRanges=Q,exports.rc=pe,exports.tokenTypes=xe,exports.tokenize=le,exports.translateToA1=function(e,t){const n=_(t),r="string"==typeof e,l=r?le(e,{emitRanges:!1,mergeRanges:!1,allowTernary:!0,r1c1:!0}):e;return l.forEach((e=>{if($e(e)){const t={},r=ge(e.value),l=de(r.r0,r.$r0,n.top,1048575),o=de(r.r1,r.$r1,n.top,1048575);l>o?(t.top=o,t.$top=r.$r1,t.bottom=l,t.$bottom=r.$r0):(t.top=l,t.$top=r.$r0,t.bottom=o,t.$bottom=r.$r1);const u=de(r.c0,r.$c0,n.left,16383),a=de(r.c1,r.$c1,n.left,16383);u>a?(t.left=a,t.$left=r.$c1,t.right=u,t.$right=r.$c0):(t.left=u,t.$left=r.$c0,t.right=a,t.$right=r.$c1),e.value=v(t)}})),r?l.map((e=>e.value)).join(""):l},exports.translateToRC=function(e,t){const{top:n,left:r}=_(t),l="string"==typeof e,o=l?le(e,{emitRanges:!1,mergeRanges:!1,allowTernary:!0,r1c2:!1}):e;return o.forEach((e=>{if($e(e)){const t={},l=_(e.value);t.r0=me(l.$top,l.top,n),t.$r0=l.$top,t.r1=me(l.$bottom,l.bottom,n),t.$r1=l.$bottom,t.c0=me(l.$left,l.left,r),t.$c0=l.$left,t.c1=me(l.$right,l.right,r),t.$c1=l.$right,e.value=fe(t)}})),l?o.map((e=>e.value)).join(""):o};
|
|
2
2
|
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZnguanMiLCJzb3VyY2VzIjpbXSwic291cmNlc0NvbnRlbnQiOltdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiIn0=
|