@ember-lattice/formula-ironcalc 0.0.0-stage → 1.0.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/CHANGELOG.md +16 -0
- package/LICENSE.md +21 -0
- package/NOTICE +30 -0
- package/README.md +49 -2
- package/dist/engine.d.ts +25 -0
- package/dist/functions.d.ts +3 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +610 -0
- package/dist/index.js.map +1 -0
- package/dist/worker.d.ts +39 -0
- package/package.json +50 -3
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# @ember-lattice/formula-ironcalc
|
|
2
|
+
|
|
3
|
+
## 1.0.0
|
|
4
|
+
|
|
5
|
+
### Major Changes
|
|
6
|
+
|
|
7
|
+
- 7ce4af2: Lattice 1.0: one grid for every collection in Ember. Lists, feeds, tables, boards and
|
|
8
|
+
spreadsheets come from one headless engine, a port of TanStack Table. It has 80 of the 81
|
|
9
|
+
AG Grid features in the parity matrix; the external filter runs after grouping. The release has the client row models, the Lattice wire protocol with servers for Node,
|
|
10
|
+
Rails and Python, an IronCalc spreadsheet with live collaboration, themes, test harnesses, Jig
|
|
11
|
+
stories and Marquetry catalog entries.
|
|
12
|
+
|
|
13
|
+
### Patch Changes
|
|
14
|
+
|
|
15
|
+
- Updated dependencies [7ce4af2]
|
|
16
|
+
- @ember-lattice/formula@1.0.0
|
package/LICENSE.md
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Joe Gaudet
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/NOTICE
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
Lattice
|
|
2
|
+
Copyright (c) 2026 Joe Gaudet. MIT licensed; see LICENSE.md.
|
|
3
|
+
|
|
4
|
+
Lattice ports code from two MIT-licensed TanStack projects into Ember-native code. Lattice does
|
|
5
|
+
not depend on either package. PORT_MAP.md names each ported file and its source.
|
|
6
|
+
|
|
7
|
+
TanStack Table (@tanstack/table-core 9.3.1)
|
|
8
|
+
https://github.com/TanStack/table
|
|
9
|
+
Copyright (c) 2016 Tanner Linsley
|
|
10
|
+
|
|
11
|
+
TanStack Virtual (@tanstack/virtual-core 3.19.16)
|
|
12
|
+
https://github.com/TanStack/virtual
|
|
13
|
+
Copyright (c) 2021-present Tanner Linsley
|
|
14
|
+
|
|
15
|
+
Both are licensed under the MIT License:
|
|
16
|
+
|
|
17
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software
|
|
18
|
+
and associated documentation files (the "Software"), to deal in the Software without
|
|
19
|
+
restriction, including without limitation the rights to use, copy, modify, merge, publish,
|
|
20
|
+
distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
|
|
21
|
+
Software is furnished to do so, subject to the following conditions:
|
|
22
|
+
|
|
23
|
+
The above copyright notice and this permission notice shall be included in all copies or
|
|
24
|
+
substantial portions of the Software.
|
|
25
|
+
|
|
26
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
|
|
27
|
+
BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
28
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
|
29
|
+
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
30
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,50 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @ember-lattice/formula-ironcalc
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
A Lattice `FormulaEngine` on IronCalc 0.9.1 (WASM), for a browser worker and for Node.
|
|
4
|
+
|
|
5
|
+
Part of [Lattice](https://joegaudet.com/ember-lattice/). Not released yet.
|
|
6
|
+
|
|
7
|
+
## Use
|
|
8
|
+
|
|
9
|
+
In the worker:
|
|
10
|
+
|
|
11
|
+
```ts
|
|
12
|
+
import { createIronCalcEngine, serveEngine } from '@ember-lattice/formula-ironcalc'
|
|
13
|
+
|
|
14
|
+
serveEngine(self, () => createIronCalcEngine())
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
On the page:
|
|
18
|
+
|
|
19
|
+
```ts
|
|
20
|
+
import { createWorkerEngine } from '@ember-lattice/formula-ironcalc'
|
|
21
|
+
|
|
22
|
+
const engine = createWorkerEngine(new Worker(new URL('./engine-worker.js', import.meta.url)))
|
|
23
|
+
await engine.load(doc)
|
|
24
|
+
await engine.watch([{ sheet: 's1', rows: visibleRows, cols: visibleCols }])
|
|
25
|
+
const changes = await engine.apply([
|
|
26
|
+
{ type: 'setCell', sheet: 's1', row: 'r1', col: 'c1', value: 4 },
|
|
27
|
+
])
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
- In Node, give the `.wasm` bytes: `createIronCalcEngine({ wasm: readFileSync(path) })`.
|
|
31
|
+
- IronCalc gives no list of changed cells. The engine reads the watched cells again after each
|
|
32
|
+
recalc. Without `watch`, it reads all cells with content. For large sheets, watch the
|
|
33
|
+
viewport, and call `watch` again when the viewport moves.
|
|
34
|
+
|
|
35
|
+
## Limits
|
|
36
|
+
|
|
37
|
+
- Numbers come back with 15 significant digits.
|
|
38
|
+
- Each edit recalculates the full workbook. Each `evaluate` call costs one recalc.
|
|
39
|
+
- See `docs/adr/0015-sheet-model.md` for the sheet gate numbers and the IronCalc bugs.
|
|
40
|
+
|
|
41
|
+
## Tests
|
|
42
|
+
|
|
43
|
+
Build `formula` and this package first. The worker test loads `dist`.
|
|
44
|
+
|
|
45
|
+
```sh
|
|
46
|
+
volta run --node 24.11.1 npx tsc --build packages/formula packages/formula-ironcalc
|
|
47
|
+
(cd packages/formula && npx tsup) && (cd packages/formula-ironcalc && npx tsup)
|
|
48
|
+
volta run --node 24.11.1 npx vitest run packages/formula-ironcalc
|
|
49
|
+
volta run --node 24.11.1 node packages/formula-ironcalc/tests/sheet-gate.ts
|
|
50
|
+
```
|
package/dist/engine.d.ts
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { CellChange, CellValue, FormulaEngine, FunctionInfo, SheetDoc, SheetOp, WatchRange } from '@ember-lattice/formula';
|
|
2
|
+
export interface IronCalcOptions {
|
|
3
|
+
/** The `.wasm` bytes or a compiled module. Without it, the browser fetches the file by URL. */
|
|
4
|
+
wasm?: BufferSource | WebAssembly.Module;
|
|
5
|
+
locale?: string;
|
|
6
|
+
timezone?: string;
|
|
7
|
+
}
|
|
8
|
+
/** Loads the IronCalc WASM module and gives a new engine. */
|
|
9
|
+
export declare function createIronCalcEngine(options?: IronCalcOptions): Promise<IronCalcEngine>;
|
|
10
|
+
/**
|
|
11
|
+
* A `FormulaEngine` on IronCalc. IronCalc stores A1 formulas, so the engine converts the
|
|
12
|
+
* stored ID refs to A1 when a formula is set. IronCalc moves its own refs on insert and
|
|
13
|
+
* delete. IronCalc recalculates the full workbook and does not list the changed cells, so
|
|
14
|
+
* `apply` reads the watched cells again and gives the values that changed.
|
|
15
|
+
*/
|
|
16
|
+
export declare class IronCalcEngine implements FormulaEngine {
|
|
17
|
+
#private;
|
|
18
|
+
constructor(options?: IronCalcOptions);
|
|
19
|
+
load(doc: SheetDoc): Promise<void>;
|
|
20
|
+
apply(ops: SheetOp[]): Promise<CellChange[]>;
|
|
21
|
+
evaluate(sheet: string, formula: string): Promise<CellValue>;
|
|
22
|
+
functions(): FunctionInfo[];
|
|
23
|
+
watch(ranges: WatchRange[] | null): Promise<CellChange[]>;
|
|
24
|
+
dispose(): void;
|
|
25
|
+
}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { createIronCalcEngine, IronCalcEngine } from './engine';
|
|
2
|
+
export type { IronCalcOptions } from './engine';
|
|
3
|
+
export { createWorkerEngine, serveEngine } from './worker';
|
|
4
|
+
export type { EngineRequest, EngineResponse, PortLike } from './worker';
|
|
5
|
+
export { FUNCTION_NAMES } from './functions';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,610 @@
|
|
|
1
|
+
import is from '@sindresorhus/is';
|
|
2
|
+
import init, { Model, initSync } from '@ironcalc/wasm';
|
|
3
|
+
import { scanStored, printStored, toA1, createRefContext, storedRefs, shrinkDeleted } from '@ember-lattice/formula';
|
|
4
|
+
|
|
5
|
+
// src/engine.ts
|
|
6
|
+
|
|
7
|
+
// src/functions.ts
|
|
8
|
+
var ARGS = {
|
|
9
|
+
ABS: "number",
|
|
10
|
+
ADDRESS: "row_num, column_num, [abs_num], [a1], [sheet_text]",
|
|
11
|
+
AND: "logical1, [logical2], ...",
|
|
12
|
+
AVERAGE: "number1, [number2], ...",
|
|
13
|
+
AVERAGEIF: "range, criteria, [average_range]",
|
|
14
|
+
AVERAGEIFS: "average_range, criteria_range1, criteria1, ...",
|
|
15
|
+
CEILING: "number, significance",
|
|
16
|
+
"CEILING.MATH": "number, [significance], [mode]",
|
|
17
|
+
CELL: "info_type, [reference]",
|
|
18
|
+
CHAR: "number",
|
|
19
|
+
CHOOSE: "index_num, value1, [value2], ...",
|
|
20
|
+
CHOOSECOLS: "array, col_num1, [col_num2], ...",
|
|
21
|
+
CLEAN: "text",
|
|
22
|
+
CODE: "text",
|
|
23
|
+
COLUMN: "[reference]",
|
|
24
|
+
COLUMNS: "array",
|
|
25
|
+
CONCAT: "text1, [text2], ...",
|
|
26
|
+
CONCATENATE: "text1, [text2], ...",
|
|
27
|
+
CONVERT: "number, from_unit, to_unit",
|
|
28
|
+
CORREL: "array1, array2",
|
|
29
|
+
COUNT: "value1, [value2], ...",
|
|
30
|
+
COUNTA: "value1, [value2], ...",
|
|
31
|
+
COUNTBLANK: "range",
|
|
32
|
+
COUNTIF: "range, criteria",
|
|
33
|
+
COUNTIFS: "criteria_range1, criteria1, ...",
|
|
34
|
+
DATE: "year, month, day",
|
|
35
|
+
DATEDIF: "start_date, end_date, unit",
|
|
36
|
+
DATEVALUE: "date_text",
|
|
37
|
+
DAY: "serial_number",
|
|
38
|
+
DAYS: "end_date, start_date",
|
|
39
|
+
DROP: "array, rows, [columns]",
|
|
40
|
+
EDATE: "start_date, months",
|
|
41
|
+
EOMONTH: "start_date, months",
|
|
42
|
+
EXACT: "text1, text2",
|
|
43
|
+
EXP: "number",
|
|
44
|
+
FILTER: "array, include, [if_empty]",
|
|
45
|
+
FIND: "find_text, within_text, [start_num]",
|
|
46
|
+
FIXED: "number, [decimals], [no_commas]",
|
|
47
|
+
FLOOR: "number, significance",
|
|
48
|
+
"FLOOR.MATH": "number, [significance], [mode]",
|
|
49
|
+
"FORECAST.LINEAR": "x, known_y's, known_x's",
|
|
50
|
+
FV: "rate, nper, pmt, [pv], [type]",
|
|
51
|
+
HLOOKUP: "lookup_value, table_array, row_index_num, [range_lookup]",
|
|
52
|
+
HOUR: "serial_number",
|
|
53
|
+
HSTACK: "array1, [array2], ...",
|
|
54
|
+
HYPERLINK: "link_location, [friendly_name]",
|
|
55
|
+
IF: "logical_test, [value_if_true], [value_if_false]",
|
|
56
|
+
IFERROR: "value, value_if_error",
|
|
57
|
+
IFNA: "value, value_if_na",
|
|
58
|
+
IFS: "logical_test1, value_if_true1, ...",
|
|
59
|
+
INDEX: "array, row_num, [column_num]",
|
|
60
|
+
INDIRECT: "ref_text, [a1]",
|
|
61
|
+
INT: "number",
|
|
62
|
+
IPMT: "rate, per, nper, pv, [fv], [type]",
|
|
63
|
+
IRR: "values, [guess]",
|
|
64
|
+
ISBLANK: "value",
|
|
65
|
+
ISERR: "value",
|
|
66
|
+
ISERROR: "value",
|
|
67
|
+
ISEVEN: "number",
|
|
68
|
+
ISFORMULA: "reference",
|
|
69
|
+
ISLOGICAL: "value",
|
|
70
|
+
ISNA: "value",
|
|
71
|
+
ISNUMBER: "value",
|
|
72
|
+
ISODD: "number",
|
|
73
|
+
ISOWEEKNUM: "date",
|
|
74
|
+
ISTEXT: "value",
|
|
75
|
+
LAMBDA: "[parameter1, ...], calculation",
|
|
76
|
+
LARGE: "array, k",
|
|
77
|
+
LEFT: "text, [num_chars]",
|
|
78
|
+
LEN: "text",
|
|
79
|
+
LET: "name1, name_value1, calculation_or_name2, ...",
|
|
80
|
+
LN: "number",
|
|
81
|
+
LOG: "number, [base]",
|
|
82
|
+
LOG10: "number",
|
|
83
|
+
LOOKUP: "lookup_value, lookup_vector, [result_vector]",
|
|
84
|
+
LOWER: "text",
|
|
85
|
+
MATCH: "lookup_value, lookup_array, [match_type]",
|
|
86
|
+
MAX: "number1, [number2], ...",
|
|
87
|
+
MAXIFS: "max_range, criteria_range1, criteria1, ...",
|
|
88
|
+
MEDIAN: "number1, [number2], ...",
|
|
89
|
+
MID: "text, start_num, num_chars",
|
|
90
|
+
MIN: "number1, [number2], ...",
|
|
91
|
+
MINIFS: "min_range, criteria_range1, criteria1, ...",
|
|
92
|
+
MINUTE: "serial_number",
|
|
93
|
+
MOD: "number, divisor",
|
|
94
|
+
MODE: "number1, [number2], ...",
|
|
95
|
+
"MODE.SNGL": "number1, [number2], ...",
|
|
96
|
+
MONTH: "serial_number",
|
|
97
|
+
MROUND: "number, multiple",
|
|
98
|
+
N: "value",
|
|
99
|
+
NA: "",
|
|
100
|
+
NETWORKDAYS: "start_date, end_date, [holidays]",
|
|
101
|
+
"NETWORKDAYS.INTL": "start_date, end_date, [weekend], [holidays]",
|
|
102
|
+
NOT: "logical",
|
|
103
|
+
NOW: "",
|
|
104
|
+
NPER: "rate, pmt, pv, [fv], [type]",
|
|
105
|
+
NPV: "rate, value1, [value2], ...",
|
|
106
|
+
NUMBERVALUE: "text, [decimal_separator], [group_separator]",
|
|
107
|
+
OFFSET: "reference, rows, cols, [height], [width]",
|
|
108
|
+
OR: "logical1, [logical2], ...",
|
|
109
|
+
PERCENTILE: "array, k",
|
|
110
|
+
"PERCENTILE.INC": "array, k",
|
|
111
|
+
PI: "",
|
|
112
|
+
PMT: "rate, nper, pv, [fv], [type]",
|
|
113
|
+
POWER: "number, power",
|
|
114
|
+
PPMT: "rate, per, nper, pv, [fv], [type]",
|
|
115
|
+
PRODUCT: "number1, [number2], ...",
|
|
116
|
+
PROPER: "text",
|
|
117
|
+
PV: "rate, nper, pmt, [fv], [type]",
|
|
118
|
+
QUARTILE: "array, quart",
|
|
119
|
+
RAND: "",
|
|
120
|
+
RANDARRAY: "[rows], [columns], [min], [max], [whole_number]",
|
|
121
|
+
RANDBETWEEN: "bottom, top",
|
|
122
|
+
RANK: "number, ref, [order]",
|
|
123
|
+
"RANK.EQ": "number, ref, [order]",
|
|
124
|
+
RATE: "nper, pmt, pv, [fv], [type], [guess]",
|
|
125
|
+
REPLACE: "old_text, start_num, num_chars, new_text",
|
|
126
|
+
REPT: "text, number_times",
|
|
127
|
+
RIGHT: "text, [num_chars]",
|
|
128
|
+
ROUND: "number, num_digits",
|
|
129
|
+
ROUNDDOWN: "number, num_digits",
|
|
130
|
+
ROUNDUP: "number, num_digits",
|
|
131
|
+
ROW: "[reference]",
|
|
132
|
+
ROWS: "array",
|
|
133
|
+
SEARCH: "find_text, within_text, [start_num]",
|
|
134
|
+
SECOND: "serial_number",
|
|
135
|
+
SEQUENCE: "rows, [columns], [start], [step]",
|
|
136
|
+
SIGN: "number",
|
|
137
|
+
SMALL: "array, k",
|
|
138
|
+
SORT: "array, [sort_index], [sort_order], [by_col]",
|
|
139
|
+
SORTBY: "array, by_array1, [sort_order1], ...",
|
|
140
|
+
SQRT: "number",
|
|
141
|
+
STDEV: "number1, [number2], ...",
|
|
142
|
+
"STDEV.P": "number1, [number2], ...",
|
|
143
|
+
"STDEV.S": "number1, [number2], ...",
|
|
144
|
+
SUBSTITUTE: "text, old_text, new_text, [instance_num]",
|
|
145
|
+
SUBTOTAL: "function_num, ref1, [ref2], ...",
|
|
146
|
+
SUM: "number1, [number2], ...",
|
|
147
|
+
SUMIF: "range, criteria, [sum_range]",
|
|
148
|
+
SUMIFS: "sum_range, criteria_range1, criteria1, ...",
|
|
149
|
+
SUMPRODUCT: "array1, [array2], ...",
|
|
150
|
+
SWITCH: "expression, value1, result1, [default_or_value2], ...",
|
|
151
|
+
T: "value",
|
|
152
|
+
TAKE: "array, rows, [columns]",
|
|
153
|
+
TEXT: "value, format_text",
|
|
154
|
+
TEXTAFTER: "text, delimiter, [instance_num], [match_mode], [match_end], [if_not_found]",
|
|
155
|
+
TEXTBEFORE: "text, delimiter, [instance_num], [match_mode], [match_end], [if_not_found]",
|
|
156
|
+
TEXTJOIN: "delimiter, ignore_empty, text1, [text2], ...",
|
|
157
|
+
TEXTSPLIT: "text, col_delimiter, [row_delimiter], [ignore_empty], [match_mode], [pad_with]",
|
|
158
|
+
TIME: "hour, minute, second",
|
|
159
|
+
TIMEVALUE: "time_text",
|
|
160
|
+
TODAY: "",
|
|
161
|
+
TRANSPOSE: "array",
|
|
162
|
+
TRIM: "text",
|
|
163
|
+
TRUNC: "number, [num_digits]",
|
|
164
|
+
UNICHAR: "number",
|
|
165
|
+
UNIQUE: "array, [by_col], [exactly_once]",
|
|
166
|
+
UPPER: "text",
|
|
167
|
+
VALUE: "text",
|
|
168
|
+
VAR: "number1, [number2], ...",
|
|
169
|
+
"VAR.S": "number1, [number2], ...",
|
|
170
|
+
VLOOKUP: "lookup_value, table_array, col_index_num, [range_lookup]",
|
|
171
|
+
VSTACK: "array1, [array2], ...",
|
|
172
|
+
WEEKDAY: "serial_number, [return_type]",
|
|
173
|
+
WEEKNUM: "serial_number, [return_type]",
|
|
174
|
+
WORKDAY: "start_date, days, [holidays]",
|
|
175
|
+
"WORKDAY.INTL": "start_date, days, [weekend], [holidays]",
|
|
176
|
+
XIRR: "values, dates, [guess]",
|
|
177
|
+
XLOOKUP: "lookup_value, lookup_array, return_array, [if_not_found], [match_mode], [search_mode]",
|
|
178
|
+
XMATCH: "lookup_value, lookup_array, [match_mode], [search_mode]",
|
|
179
|
+
XNPV: "rate, values, dates",
|
|
180
|
+
XOR: "logical1, [logical2], ...",
|
|
181
|
+
YEAR: "serial_number",
|
|
182
|
+
YEARFRAC: "start_date, end_date, [basis]"
|
|
183
|
+
};
|
|
184
|
+
var FUNCTION_NAMES = Object.keys(ARGS);
|
|
185
|
+
var signatureOf = (name) => `${name}(${ARGS[name] ?? ""})`;
|
|
186
|
+
|
|
187
|
+
// src/engine.ts
|
|
188
|
+
var READ_FORMAT = "0.00000000000000E+0";
|
|
189
|
+
var EVAL_SHEET = "__lattice_eval__";
|
|
190
|
+
var TEXT = 2;
|
|
191
|
+
var BOOLEAN = 4;
|
|
192
|
+
var ERROR = 16;
|
|
193
|
+
function gridSet(grid, sheet, row, col, value) {
|
|
194
|
+
let rows = grid.get(sheet);
|
|
195
|
+
if (!rows) grid.set(sheet, rows = /* @__PURE__ */ new Map());
|
|
196
|
+
let cols = rows.get(row);
|
|
197
|
+
if (!cols) rows.set(row, cols = /* @__PURE__ */ new Map());
|
|
198
|
+
cols.set(col, value);
|
|
199
|
+
}
|
|
200
|
+
var indexOf = (ids) => new Map(ids.map((id, i) => [id, i]));
|
|
201
|
+
var loaded;
|
|
202
|
+
function loadWasm(wasm) {
|
|
203
|
+
if (wasm) {
|
|
204
|
+
initSync({ module: wasm });
|
|
205
|
+
return Promise.resolve();
|
|
206
|
+
}
|
|
207
|
+
return loaded ??= init().then(() => void 0);
|
|
208
|
+
}
|
|
209
|
+
async function createIronCalcEngine(options = {}) {
|
|
210
|
+
await loadWasm(options.wasm);
|
|
211
|
+
return new IronCalcEngine(options);
|
|
212
|
+
}
|
|
213
|
+
var IronCalcEngine = class {
|
|
214
|
+
#options;
|
|
215
|
+
#model;
|
|
216
|
+
#sheets = [];
|
|
217
|
+
#ctx;
|
|
218
|
+
/** The cells with content. */
|
|
219
|
+
#content = /* @__PURE__ */ new Map();
|
|
220
|
+
/** The stored formulas that hold a range, for the range shrink on delete. */
|
|
221
|
+
#ranges = /* @__PURE__ */ new Map();
|
|
222
|
+
/** The last values read for the watched cells. */
|
|
223
|
+
#values = /* @__PURE__ */ new Map();
|
|
224
|
+
#watch = null;
|
|
225
|
+
constructor(options = {}) {
|
|
226
|
+
this.#options = options;
|
|
227
|
+
}
|
|
228
|
+
get #m() {
|
|
229
|
+
if (!this.#model) throw new Error("Lattice: call load() before you use the engine");
|
|
230
|
+
return this.#model;
|
|
231
|
+
}
|
|
232
|
+
async load(doc) {
|
|
233
|
+
this.#model?.free();
|
|
234
|
+
const { locale = "en", timezone = "UTC" } = this.#options;
|
|
235
|
+
const m = this.#model = new Model("lattice", locale, timezone, "en");
|
|
236
|
+
this.#sheets = [];
|
|
237
|
+
this.#content = /* @__PURE__ */ new Map();
|
|
238
|
+
this.#ranges = /* @__PURE__ */ new Map();
|
|
239
|
+
this.#values = /* @__PURE__ */ new Map();
|
|
240
|
+
this.#ctx = void 0;
|
|
241
|
+
m.pauseEvaluation();
|
|
242
|
+
doc.sheets.forEach(
|
|
243
|
+
(sheet, i) => this.#addSheet(sheet.id, sheet.name, sheet.rows, sheet.cols, i)
|
|
244
|
+
);
|
|
245
|
+
for (const { name, ref } of doc.names ?? []) m.newDefinedName(name, null, this.#a1Name(ref));
|
|
246
|
+
for (const sheet of doc.sheets) {
|
|
247
|
+
for (const cell of sheet.cells) {
|
|
248
|
+
this.#setCell(sheet.id, cell.row, cell.col, cell.value, cell.formula);
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
m.resumeEvaluation();
|
|
252
|
+
m.evaluate();
|
|
253
|
+
this.#diff();
|
|
254
|
+
}
|
|
255
|
+
async apply(ops) {
|
|
256
|
+
const m = this.#m;
|
|
257
|
+
const touched = /* @__PURE__ */ new Map();
|
|
258
|
+
m.pauseEvaluation();
|
|
259
|
+
try {
|
|
260
|
+
for (const op of ops) this.#apply(op, touched);
|
|
261
|
+
} finally {
|
|
262
|
+
m.resumeEvaluation();
|
|
263
|
+
}
|
|
264
|
+
m.evaluate();
|
|
265
|
+
const changes = this.#diff(touched);
|
|
266
|
+
for (const [sheet, rows] of touched) {
|
|
267
|
+
for (const [row, cols] of rows) {
|
|
268
|
+
for (const col of cols.keys()) {
|
|
269
|
+
if (this.#values.get(sheet)?.get(row)?.get(col) === null) {
|
|
270
|
+
this.#content.get(sheet)?.get(row)?.delete(col);
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
return changes;
|
|
276
|
+
}
|
|
277
|
+
async evaluate(sheet, formula) {
|
|
278
|
+
const m = this.#m;
|
|
279
|
+
this.#sheetState(sheet);
|
|
280
|
+
const qualified = scanStored(formula).map((t) => t.kind === "ref" ? printStored({ sheet, ...t.ref }) : t.text).join("");
|
|
281
|
+
const a1 = toA1(qualified, sheet, this.#refs());
|
|
282
|
+
m.newSheet();
|
|
283
|
+
const index = this.#sheets.length;
|
|
284
|
+
m.renameSheet(index, EVAL_SHEET);
|
|
285
|
+
try {
|
|
286
|
+
m.setUserInput(index, 1, 1, a1);
|
|
287
|
+
this.#readFormat(index, 1, 1);
|
|
288
|
+
m.evaluate();
|
|
289
|
+
return readCell(m, index, 1, 1);
|
|
290
|
+
} finally {
|
|
291
|
+
m.deleteSheet(index);
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
functions() {
|
|
295
|
+
return FUNCTION_NAMES.map((name) => ({ name, signature: signatureOf(name) }));
|
|
296
|
+
}
|
|
297
|
+
async watch(ranges) {
|
|
298
|
+
this.#watch = ranges;
|
|
299
|
+
this.#values = /* @__PURE__ */ new Map();
|
|
300
|
+
this.#diff();
|
|
301
|
+
const out = [];
|
|
302
|
+
this.#eachWatched(/* @__PURE__ */ new Map(), (sheet, row, col) => {
|
|
303
|
+
const value = this.#values.get(sheet)?.get(row)?.get(col);
|
|
304
|
+
if (value !== void 0) out.push({ sheet, row, col, value });
|
|
305
|
+
});
|
|
306
|
+
return out;
|
|
307
|
+
}
|
|
308
|
+
dispose() {
|
|
309
|
+
this.#model?.free();
|
|
310
|
+
this.#model = void 0;
|
|
311
|
+
}
|
|
312
|
+
#refs() {
|
|
313
|
+
return this.#ctx ??= createRefContext({ sheets: this.#sheets });
|
|
314
|
+
}
|
|
315
|
+
#sheetState(id) {
|
|
316
|
+
const sheet = this.#sheets.find((s) => s.id === id);
|
|
317
|
+
if (!sheet) throw new Error(`Lattice: no sheet with the ID "${id}"`);
|
|
318
|
+
return sheet;
|
|
319
|
+
}
|
|
320
|
+
#sheetIndex(id) {
|
|
321
|
+
return this.#sheets.indexOf(this.#sheetState(id));
|
|
322
|
+
}
|
|
323
|
+
#a1Name(ref) {
|
|
324
|
+
const first = this.#sheets[0]?.id ?? "";
|
|
325
|
+
return toA1(ref, first, this.#refs());
|
|
326
|
+
}
|
|
327
|
+
#addSheet(id, name, rows, cols, index) {
|
|
328
|
+
const m = this.#m;
|
|
329
|
+
if (index > 0) m.newSheet();
|
|
330
|
+
m.renameSheet(index, name);
|
|
331
|
+
this.#sheets.push({
|
|
332
|
+
id,
|
|
333
|
+
name,
|
|
334
|
+
rows: [...rows],
|
|
335
|
+
cols: [...cols],
|
|
336
|
+
rowIndex: indexOf(rows),
|
|
337
|
+
colIndex: indexOf(cols)
|
|
338
|
+
});
|
|
339
|
+
this.#ctx = void 0;
|
|
340
|
+
}
|
|
341
|
+
#readFormat(sheet, row, column) {
|
|
342
|
+
this.#m.updateRangeStyle({ sheet, row, column, width: 1, height: 1 }, "num_fmt", READ_FORMAT);
|
|
343
|
+
}
|
|
344
|
+
#position(sheetId, row, col) {
|
|
345
|
+
const sheet = this.#sheetState(sheetId);
|
|
346
|
+
const r = sheet.rowIndex.get(row);
|
|
347
|
+
const c = sheet.colIndex.get(col);
|
|
348
|
+
if (r === void 0 || c === void 0) {
|
|
349
|
+
throw new Error(`Lattice: no cell at row "${row}", column "${col}" on sheet "${sheetId}"`);
|
|
350
|
+
}
|
|
351
|
+
return { sheet: this.#sheets.indexOf(sheet), row: r + 1, col: c + 1 };
|
|
352
|
+
}
|
|
353
|
+
#setCell(sheet, row, col, value, formula) {
|
|
354
|
+
const m = this.#m;
|
|
355
|
+
const at = this.#position(sheet, row, col);
|
|
356
|
+
const input = formula ? toA1(formula, sheet, this.#refs()) : toInput(value);
|
|
357
|
+
if (formula && storedRefs(formula).some((ref) => ref.end)) {
|
|
358
|
+
gridSet(this.#ranges, sheet, row, col, formula);
|
|
359
|
+
} else this.#ranges.get(sheet)?.get(row)?.delete(col);
|
|
360
|
+
if (input === "") m.rangeClearContents(at.sheet, at.row, at.col, at.row, at.col);
|
|
361
|
+
else {
|
|
362
|
+
m.setUserInput(at.sheet, at.row, at.col, input);
|
|
363
|
+
this.#readFormat(at.sheet, at.row, at.col);
|
|
364
|
+
gridSet(this.#content, sheet, row, col, true);
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
#apply(op, touched) {
|
|
368
|
+
const m = this.#m;
|
|
369
|
+
switch (op.type) {
|
|
370
|
+
case "setCell":
|
|
371
|
+
this.#setCell(op.sheet, op.row, op.col, op.value, op.formula);
|
|
372
|
+
gridSet(touched, op.sheet, op.row, op.col, true);
|
|
373
|
+
return;
|
|
374
|
+
case "insertRows":
|
|
375
|
+
case "insertCols": {
|
|
376
|
+
const sheet = this.#sheetState(op.sheet);
|
|
377
|
+
const rows = op.type === "insertRows";
|
|
378
|
+
const ids = rows ? sheet.rows : sheet.cols;
|
|
379
|
+
const at = op.before === null ? ids.length : (rows ? sheet.rowIndex : sheet.colIndex).get(op.before);
|
|
380
|
+
if (at === void 0) throw new Error(`Lattice: no row or column "${op.before}"`);
|
|
381
|
+
const index = this.#sheets.indexOf(sheet);
|
|
382
|
+
if (rows) m.insertRows(index, at + 1, op.ids.length);
|
|
383
|
+
else m.insertColumns(index, at + 1, op.ids.length);
|
|
384
|
+
ids.splice(at, 0, ...op.ids);
|
|
385
|
+
this.#reindex(sheet);
|
|
386
|
+
return;
|
|
387
|
+
}
|
|
388
|
+
case "deleteRows":
|
|
389
|
+
case "deleteCols": {
|
|
390
|
+
const sheet = this.#sheetState(op.sheet);
|
|
391
|
+
const rows = op.type === "deleteRows";
|
|
392
|
+
const map = rows ? sheet.rowIndex : sheet.colIndex;
|
|
393
|
+
const index = this.#sheets.indexOf(sheet);
|
|
394
|
+
const positions = op.ids.map((id) => map.get(id)).filter((i) => i !== void 0);
|
|
395
|
+
const shrunk = this.#shrink({ sheet: op.sheet, [rows ? "rows" : "cols"]: op.ids });
|
|
396
|
+
for (const [start, count] of runs(positions)) {
|
|
397
|
+
if (rows) m.deleteRows(index, start + 1, count);
|
|
398
|
+
else m.deleteColumns(index, start + 1, count);
|
|
399
|
+
}
|
|
400
|
+
const gone = new Set(op.ids);
|
|
401
|
+
if (rows) sheet.rows = sheet.rows.filter((id) => !gone.has(id));
|
|
402
|
+
else sheet.cols = sheet.cols.filter((id) => !gone.has(id));
|
|
403
|
+
for (const grid of [this.#content, this.#values]) {
|
|
404
|
+
const sheetRows = grid.get(op.sheet);
|
|
405
|
+
if (!sheetRows) continue;
|
|
406
|
+
if (rows) for (const id of gone) sheetRows.delete(id);
|
|
407
|
+
else for (const cols of sheetRows.values()) for (const id of gone) cols.delete(id);
|
|
408
|
+
}
|
|
409
|
+
this.#reindex(sheet);
|
|
410
|
+
for (const cell of shrunk)
|
|
411
|
+
this.#setCell(cell.sheet, cell.row, cell.col, void 0, cell.formula);
|
|
412
|
+
return;
|
|
413
|
+
}
|
|
414
|
+
case "setName": {
|
|
415
|
+
const exists = m.getDefinedNameList().some((n) => n.name.toUpperCase() === op.name.toUpperCase());
|
|
416
|
+
if (op.ref === null) {
|
|
417
|
+
if (exists) m.deleteDefinedName(op.name, null);
|
|
418
|
+
} else if (exists) m.updateDefinedName(op.name, null, op.name, null, this.#a1Name(op.ref));
|
|
419
|
+
else m.newDefinedName(op.name, null, this.#a1Name(op.ref));
|
|
420
|
+
return;
|
|
421
|
+
}
|
|
422
|
+
case "addSheet":
|
|
423
|
+
this.#addSheet(op.id, op.name, op.rows, op.cols, this.#sheets.length);
|
|
424
|
+
return;
|
|
425
|
+
case "removeSheet": {
|
|
426
|
+
m.deleteSheet(this.#sheetIndex(op.id));
|
|
427
|
+
this.#sheets = this.#sheets.filter((s) => s.id !== op.id);
|
|
428
|
+
this.#content.delete(op.id);
|
|
429
|
+
this.#values.delete(op.id);
|
|
430
|
+
this.#ctx = void 0;
|
|
431
|
+
return;
|
|
432
|
+
}
|
|
433
|
+
case "renameSheet":
|
|
434
|
+
m.renameSheet(this.#sheetIndex(op.id), op.name);
|
|
435
|
+
this.#sheetState(op.id).name = op.name;
|
|
436
|
+
this.#ctx = void 0;
|
|
437
|
+
return;
|
|
438
|
+
// Formats, styles and merges are Lattice state. They do not change a computed value.
|
|
439
|
+
case "setFormat":
|
|
440
|
+
case "setStyle":
|
|
441
|
+
case "merge":
|
|
442
|
+
case "unmerge":
|
|
443
|
+
return;
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
/**
|
|
447
|
+
* IronCalc 0.9.1 turns a range end that a delete removes into `#REF!`. Excel moves the end
|
|
448
|
+
* inward. Gives the range formulas to set again after the delete, with the ends moved. A range
|
|
449
|
+
* that loses all its rows or columns is set again as it is: it prints as `#REF!`, as on a fresh
|
|
450
|
+
* load (IronCalc gives `#VALUE!` for it after its own delete).
|
|
451
|
+
*/
|
|
452
|
+
#shrink(deletion) {
|
|
453
|
+
const out = [];
|
|
454
|
+
const gone = /* @__PURE__ */ new Set([...deletion.rows ?? [], ...deletion.cols ?? []]);
|
|
455
|
+
for (const [sheet, rows] of this.#ranges) {
|
|
456
|
+
for (const [row, cols] of rows) {
|
|
457
|
+
if (sheet === deletion.sheet && deletion.rows && gone.has(row)) continue;
|
|
458
|
+
for (const [col, formula] of cols) {
|
|
459
|
+
if (sheet === deletion.sheet && gone.has(col)) continue;
|
|
460
|
+
const next = shrinkDeleted(formula, sheet, this.#refs(), deletion);
|
|
461
|
+
const lost = storedRefs(next).some(
|
|
462
|
+
(ref) => (ref.sheet ?? sheet) === deletion.sheet && [ref.start, ref.end].some((p) => gone.has(p?.row ?? "") || gone.has(p?.col ?? ""))
|
|
463
|
+
);
|
|
464
|
+
if (next !== formula || lost) out.push({ sheet, row, col, formula: next });
|
|
465
|
+
}
|
|
466
|
+
}
|
|
467
|
+
}
|
|
468
|
+
return out;
|
|
469
|
+
}
|
|
470
|
+
#reindex(sheet) {
|
|
471
|
+
sheet.rowIndex = indexOf(sheet.rows);
|
|
472
|
+
sheet.colIndex = indexOf(sheet.cols);
|
|
473
|
+
this.#ctx = void 0;
|
|
474
|
+
}
|
|
475
|
+
#eachWatched(touched, fn) {
|
|
476
|
+
if (this.#watch) {
|
|
477
|
+
for (const range of this.#watch) {
|
|
478
|
+
for (const row of range.rows) for (const col of range.cols) fn(range.sheet, row, col);
|
|
479
|
+
}
|
|
480
|
+
return;
|
|
481
|
+
}
|
|
482
|
+
for (const grid of [this.#content, touched]) {
|
|
483
|
+
for (const [sheet, rows] of grid) {
|
|
484
|
+
for (const [row, cols] of rows) {
|
|
485
|
+
for (const col of cols.keys()) {
|
|
486
|
+
if (grid === touched && this.#content.get(sheet)?.get(row)?.has(col)) continue;
|
|
487
|
+
fn(sheet, row, col);
|
|
488
|
+
}
|
|
489
|
+
}
|
|
490
|
+
}
|
|
491
|
+
}
|
|
492
|
+
}
|
|
493
|
+
/** Reads the watched cells and gives the values that differ from the last read. */
|
|
494
|
+
#diff(touched = /* @__PURE__ */ new Map()) {
|
|
495
|
+
const changes = [];
|
|
496
|
+
const m = this.#m;
|
|
497
|
+
const sheets = new Map(this.#sheets.map((sheet, index) => [sheet.id, { sheet, index }]));
|
|
498
|
+
this.#eachWatched(touched, (sheetId, row, col) => {
|
|
499
|
+
const at = sheets.get(sheetId);
|
|
500
|
+
const r = at?.sheet.rowIndex.get(row);
|
|
501
|
+
const c = at?.sheet.colIndex.get(col);
|
|
502
|
+
if (!at || r === void 0 || c === void 0) return;
|
|
503
|
+
const value = readCell(m, at.index, r + 1, c + 1);
|
|
504
|
+
const prev = this.#values.get(sheetId)?.get(row)?.get(col);
|
|
505
|
+
if (prev === void 0 ? value !== null : !sameValue(prev, value)) {
|
|
506
|
+
changes.push({ sheet: sheetId, row, col, value });
|
|
507
|
+
}
|
|
508
|
+
gridSet(this.#values, sheetId, row, col, value);
|
|
509
|
+
});
|
|
510
|
+
return changes;
|
|
511
|
+
}
|
|
512
|
+
};
|
|
513
|
+
function sameValue(a, b) {
|
|
514
|
+
if (is.plainObject(a) && is.plainObject(b)) {
|
|
515
|
+
return a.error === b.error;
|
|
516
|
+
}
|
|
517
|
+
return a === b;
|
|
518
|
+
}
|
|
519
|
+
function runs(positions) {
|
|
520
|
+
const sorted = [...new Set(positions)].sort((a, b) => b - a);
|
|
521
|
+
const out = [];
|
|
522
|
+
for (const p of sorted) {
|
|
523
|
+
const last = out[out.length - 1];
|
|
524
|
+
if (last && last[0] - 1 === p) {
|
|
525
|
+
last[0] = p;
|
|
526
|
+
last[1]++;
|
|
527
|
+
} else out.push([p, 1]);
|
|
528
|
+
}
|
|
529
|
+
return out;
|
|
530
|
+
}
|
|
531
|
+
function toInput(value) {
|
|
532
|
+
if (value === null || value === void 0) return "";
|
|
533
|
+
if (value === true) return "TRUE";
|
|
534
|
+
if (value === false) return "FALSE";
|
|
535
|
+
if (is.number(value)) return String(value);
|
|
536
|
+
if (is.string(value)) return value === "" ? "" : `'${value}`;
|
|
537
|
+
return value.error;
|
|
538
|
+
}
|
|
539
|
+
function readCell(m, sheet, row, col) {
|
|
540
|
+
const type = m.getCellType(sheet, row, col);
|
|
541
|
+
const text = m.getFormattedCellValue(sheet, row, col);
|
|
542
|
+
if (type === TEXT) return text;
|
|
543
|
+
if (type === BOOLEAN) return text === "TRUE";
|
|
544
|
+
if (type === ERROR) return { error: text };
|
|
545
|
+
if (text === "") return null;
|
|
546
|
+
const n = Number(text);
|
|
547
|
+
return Number.isNaN(n) ? text : n;
|
|
548
|
+
}
|
|
549
|
+
|
|
550
|
+
// src/worker.ts
|
|
551
|
+
function serveEngine(port, create) {
|
|
552
|
+
const engine = create();
|
|
553
|
+
port.addEventListener("message", async (event) => {
|
|
554
|
+
const request = event.data;
|
|
555
|
+
try {
|
|
556
|
+
const e = await engine;
|
|
557
|
+
let result;
|
|
558
|
+
switch (request.method) {
|
|
559
|
+
case "load":
|
|
560
|
+
await e.load(...request.args);
|
|
561
|
+
result = e.functions();
|
|
562
|
+
break;
|
|
563
|
+
case "apply":
|
|
564
|
+
result = await e.apply(...request.args);
|
|
565
|
+
break;
|
|
566
|
+
case "evaluate":
|
|
567
|
+
result = await e.evaluate(...request.args);
|
|
568
|
+
break;
|
|
569
|
+
case "watch":
|
|
570
|
+
result = e.watch ? await e.watch(...request.args) : [];
|
|
571
|
+
break;
|
|
572
|
+
}
|
|
573
|
+
port.postMessage({ id: request.id, ok: true, result });
|
|
574
|
+
} catch (error) {
|
|
575
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
576
|
+
port.postMessage({ id: request.id, ok: false, error: message });
|
|
577
|
+
}
|
|
578
|
+
});
|
|
579
|
+
}
|
|
580
|
+
function createWorkerEngine(port) {
|
|
581
|
+
let next = 0;
|
|
582
|
+
let functions = [];
|
|
583
|
+
const pending = /* @__PURE__ */ new Map();
|
|
584
|
+
port.addEventListener("message", (event) => {
|
|
585
|
+
const response = event.data;
|
|
586
|
+
const call = pending.get(response.id);
|
|
587
|
+
if (!call) return;
|
|
588
|
+
pending.delete(response.id);
|
|
589
|
+
if (response.ok) call.resolve(response.result);
|
|
590
|
+
else call.reject(new Error(response.error));
|
|
591
|
+
});
|
|
592
|
+
const send = (method, args) => new Promise((resolve, reject) => {
|
|
593
|
+
const id = next++;
|
|
594
|
+
pending.set(id, { resolve, reject });
|
|
595
|
+
port.postMessage({ id, method, args });
|
|
596
|
+
});
|
|
597
|
+
return {
|
|
598
|
+
async load(doc) {
|
|
599
|
+
functions = await send("load", [doc]);
|
|
600
|
+
},
|
|
601
|
+
apply: (ops) => send("apply", [ops]),
|
|
602
|
+
evaluate: (sheet, formula) => send("evaluate", [sheet, formula]),
|
|
603
|
+
watch: (ranges) => send("watch", [ranges]),
|
|
604
|
+
functions: () => functions
|
|
605
|
+
};
|
|
606
|
+
}
|
|
607
|
+
|
|
608
|
+
export { FUNCTION_NAMES, IronCalcEngine, createIronCalcEngine, createWorkerEngine, serveEngine };
|
|
609
|
+
//# sourceMappingURL=index.js.map
|
|
610
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/functions.ts","../src/engine.ts","../src/worker.ts"],"names":[],"mappings":";;;;;;;AAIA,IAAM,IAAA,GAAyC;AAAA,EAC7C,GAAA,EAAK,QAAA;AAAA,EACL,OAAA,EAAS,oDAAA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AAA,IAAI,CAAC,IAAA,EAAM;AACX,IAAA,OAAA,CAAQ,MAAA,CAAO,SAAS,EAAE,CAAA;AAC1B,IAAA,IAAI,QAAA,CAAS,EAAA,EAAI,IAAA,CAAK,OAAA,CAAQ,SAAS,MAAM,CAAA;AAAA,cACnC,MAAA,CAAO,IAAI,KAAA,CAAM,QAAA,CAAS,KAAK,CAAC,CAAA;AAAA,EAC5C,CAAC,CAAA;AACD,EAAA,MAAM,IAAA,GAAO,CAAI,MAAA,EAAiC,IAAA,KAChD,IAAI,OAAA,CAAW,CAAC,SAAS,MAAA,KAAW;AAClC,IAAA,MAAM,EAAA,GAAK,IAAA,EAAA;AACX,IAAA,OAAA,CAAQ,GAAA,CAAI,EAAA,EAAI,EAAE,OAAA,EAA0C,QAAQ,CAAA;AACpE,IAAA,IAAA,CAAK,WAAA,CAAY,EAAE,EAAA,EAAI,MAAA,EAAQ,MAAM,CAAA;AAAA,EACvC,CAAC,CAAA;AACH,EAAA,OAAO;AAAA,IACL,MAAM,KAAK,GAAA,EAAK;AACd,MAAA,SAAA,GAAY,MAAM,IAAA,CAAqB,MAAA,EAAQ,CAAC,GAAG,CAAC,CAAA;AAAA,IACtD,CAAA;AAAA,IACA,OAAO,CAAA,GAAA,KAAO,IAAA,CAAmB,OAAA,EAAS,CAAC,GAAG,CAAC,CAAA;AAAA,IAC/C,QAAA,EAAU,CAAC,KAAA,EAAO,OAAA,KAAY,KAAgB,UAAA,EAAY,CAAC,KAAA,EAAO,OAAO,CAAC,CAAA;AAAA,IAC1E,OAAO,CAAA,MAAA,KAAU,IAAA,CAAmB,OAAA,EAAS,CAAC,MAAM,CAAC,CAAA;AAAA,IACrD,WAAW,MAAM;AAAA,GACnB;AACF","file":"index.js","sourcesContent":["// Function names and arguments for the formula bar help. IronCalc 0.9.1 has no API that lists its\n// functions, so this list is the set that spike S5 checked (docs/adr/0006), less the 2 that\n// IronCalc lacks. IronCalc has 497 functions in all. shortcut: a fixed list, add names when the\n// help needs them. The arguments use the Excel help form: `[x]` is optional, `...` repeats.\nconst ARGS: Readonly<Record<string, string>> = {\n ABS: 'number',\n ADDRESS: 'row_num, column_num, [abs_num], [a1], [sheet_text]',\n AND: 'logical1, [logical2], ...',\n AVERAGE: 'number1, [number2], ...',\n AVERAGEIF: 'range, criteria, [average_range]',\n AVERAGEIFS: 'average_range, criteria_range1, criteria1, ...',\n CEILING: 'number, significance',\n 'CEILING.MATH': 'number, [significance], [mode]',\n CELL: 'info_type, [reference]',\n CHAR: 'number',\n CHOOSE: 'index_num, value1, [value2], ...',\n CHOOSECOLS: 'array, col_num1, [col_num2], ...',\n CLEAN: 'text',\n CODE: 'text',\n COLUMN: '[reference]',\n COLUMNS: 'array',\n CONCAT: 'text1, [text2], ...',\n CONCATENATE: 'text1, [text2], ...',\n CONVERT: 'number, from_unit, to_unit',\n CORREL: 'array1, array2',\n COUNT: 'value1, [value2], ...',\n COUNTA: 'value1, [value2], ...',\n COUNTBLANK: 'range',\n COUNTIF: 'range, criteria',\n COUNTIFS: 'criteria_range1, criteria1, ...',\n DATE: 'year, month, day',\n DATEDIF: 'start_date, end_date, unit',\n DATEVALUE: 'date_text',\n DAY: 'serial_number',\n DAYS: 'end_date, start_date',\n DROP: 'array, rows, [columns]',\n EDATE: 'start_date, months',\n EOMONTH: 'start_date, months',\n EXACT: 'text1, text2',\n EXP: 'number',\n FILTER: 'array, include, [if_empty]',\n FIND: 'find_text, within_text, [start_num]',\n FIXED: 'number, [decimals], [no_commas]',\n FLOOR: 'number, significance',\n 'FLOOR.MATH': 'number, [significance], [mode]',\n 'FORECAST.LINEAR': \"x, known_y's, known_x's\",\n FV: 'rate, nper, pmt, [pv], [type]',\n HLOOKUP: 'lookup_value, table_array, row_index_num, [range_lookup]',\n HOUR: 'serial_number',\n HSTACK: 'array1, [array2], ...',\n HYPERLINK: 'link_location, [friendly_name]',\n IF: 'logical_test, [value_if_true], [value_if_false]',\n IFERROR: 'value, value_if_error',\n IFNA: 'value, value_if_na',\n IFS: 'logical_test1, value_if_true1, ...',\n INDEX: 'array, row_num, [column_num]',\n INDIRECT: 'ref_text, [a1]',\n INT: 'number',\n IPMT: 'rate, per, nper, pv, [fv], [type]',\n IRR: 'values, [guess]',\n ISBLANK: 'value',\n ISERR: 'value',\n ISERROR: 'value',\n ISEVEN: 'number',\n ISFORMULA: 'reference',\n ISLOGICAL: 'value',\n ISNA: 'value',\n ISNUMBER: 'value',\n ISODD: 'number',\n ISOWEEKNUM: 'date',\n ISTEXT: 'value',\n LAMBDA: '[parameter1, ...], calculation',\n LARGE: 'array, k',\n LEFT: 'text, [num_chars]',\n LEN: 'text',\n LET: 'name1, name_value1, calculation_or_name2, ...',\n LN: 'number',\n LOG: 'number, [base]',\n LOG10: 'number',\n LOOKUP: 'lookup_value, lookup_vector, [result_vector]',\n LOWER: 'text',\n MATCH: 'lookup_value, lookup_array, [match_type]',\n MAX: 'number1, [number2], ...',\n MAXIFS: 'max_range, criteria_range1, criteria1, ...',\n MEDIAN: 'number1, [number2], ...',\n MID: 'text, start_num, num_chars',\n MIN: 'number1, [number2], ...',\n MINIFS: 'min_range, criteria_range1, criteria1, ...',\n MINUTE: 'serial_number',\n MOD: 'number, divisor',\n MODE: 'number1, [number2], ...',\n 'MODE.SNGL': 'number1, [number2], ...',\n MONTH: 'serial_number',\n MROUND: 'number, multiple',\n N: 'value',\n NA: '',\n NETWORKDAYS: 'start_date, end_date, [holidays]',\n 'NETWORKDAYS.INTL': 'start_date, end_date, [weekend], [holidays]',\n NOT: 'logical',\n NOW: '',\n NPER: 'rate, pmt, pv, [fv], [type]',\n NPV: 'rate, value1, [value2], ...',\n NUMBERVALUE: 'text, [decimal_separator], [group_separator]',\n OFFSET: 'reference, rows, cols, [height], [width]',\n OR: 'logical1, [logical2], ...',\n PERCENTILE: 'array, k',\n 'PERCENTILE.INC': 'array, k',\n PI: '',\n PMT: 'rate, nper, pv, [fv], [type]',\n POWER: 'number, power',\n PPMT: 'rate, per, nper, pv, [fv], [type]',\n PRODUCT: 'number1, [number2], ...',\n PROPER: 'text',\n PV: 'rate, nper, pmt, [fv], [type]',\n QUARTILE: 'array, quart',\n RAND: '',\n RANDARRAY: '[rows], [columns], [min], [max], [whole_number]',\n RANDBETWEEN: 'bottom, top',\n RANK: 'number, ref, [order]',\n 'RANK.EQ': 'number, ref, [order]',\n RATE: 'nper, pmt, pv, [fv], [type], [guess]',\n REPLACE: 'old_text, start_num, num_chars, new_text',\n REPT: 'text, number_times',\n RIGHT: 'text, [num_chars]',\n ROUND: 'number, num_digits',\n ROUNDDOWN: 'number, num_digits',\n ROUNDUP: 'number, num_digits',\n ROW: '[reference]',\n ROWS: 'array',\n SEARCH: 'find_text, within_text, [start_num]',\n SECOND: 'serial_number',\n SEQUENCE: 'rows, [columns], [start], [step]',\n SIGN: 'number',\n SMALL: 'array, k',\n SORT: 'array, [sort_index], [sort_order], [by_col]',\n SORTBY: 'array, by_array1, [sort_order1], ...',\n SQRT: 'number',\n STDEV: 'number1, [number2], ...',\n 'STDEV.P': 'number1, [number2], ...',\n 'STDEV.S': 'number1, [number2], ...',\n SUBSTITUTE: 'text, old_text, new_text, [instance_num]',\n SUBTOTAL: 'function_num, ref1, [ref2], ...',\n SUM: 'number1, [number2], ...',\n SUMIF: 'range, criteria, [sum_range]',\n SUMIFS: 'sum_range, criteria_range1, criteria1, ...',\n SUMPRODUCT: 'array1, [array2], ...',\n SWITCH: 'expression, value1, result1, [default_or_value2], ...',\n T: 'value',\n TAKE: 'array, rows, [columns]',\n TEXT: 'value, format_text',\n TEXTAFTER: 'text, delimiter, [instance_num], [match_mode], [match_end], [if_not_found]',\n TEXTBEFORE: 'text, delimiter, [instance_num], [match_mode], [match_end], [if_not_found]',\n TEXTJOIN: 'delimiter, ignore_empty, text1, [text2], ...',\n TEXTSPLIT: 'text, col_delimiter, [row_delimiter], [ignore_empty], [match_mode], [pad_with]',\n TIME: 'hour, minute, second',\n TIMEVALUE: 'time_text',\n TODAY: '',\n TRANSPOSE: 'array',\n TRIM: 'text',\n TRUNC: 'number, [num_digits]',\n UNICHAR: 'number',\n UNIQUE: 'array, [by_col], [exactly_once]',\n UPPER: 'text',\n VALUE: 'text',\n VAR: 'number1, [number2], ...',\n 'VAR.S': 'number1, [number2], ...',\n VLOOKUP: 'lookup_value, table_array, col_index_num, [range_lookup]',\n VSTACK: 'array1, [array2], ...',\n WEEKDAY: 'serial_number, [return_type]',\n WEEKNUM: 'serial_number, [return_type]',\n WORKDAY: 'start_date, days, [holidays]',\n 'WORKDAY.INTL': 'start_date, days, [weekend], [holidays]',\n XIRR: 'values, dates, [guess]',\n XLOOKUP: 'lookup_value, lookup_array, return_array, [if_not_found], [match_mode], [search_mode]',\n XMATCH: 'lookup_value, lookup_array, [match_mode], [search_mode]',\n XNPV: 'rate, values, dates',\n XOR: 'logical1, [logical2], ...',\n YEAR: 'serial_number',\n YEARFRAC: 'start_date, end_date, [basis]',\n}\n\nexport const FUNCTION_NAMES: readonly string[] = Object.keys(ARGS)\n\n/** The help form of a function, for example `ROUND(number, num_digits)`. */\nexport const signatureOf = (name: string): string => `${name}(${ARGS[name] ?? ''})`\n","import is from '@sindresorhus/is'\nimport init, { initSync, Model } from '@ironcalc/wasm'\nimport {\n createRefContext,\n printStored,\n scanStored,\n shrinkDeleted,\n storedRefs,\n toA1,\n} from '@ember-lattice/formula'\nimport type {\n CellChange,\n Deletion,\n CellValue,\n FormulaEngine,\n FunctionInfo,\n RefContext,\n SheetDoc,\n SheetOp,\n WatchRange,\n} from '@ember-lattice/formula'\nimport { FUNCTION_NAMES, signatureOf } from './functions'\n\nexport interface IronCalcOptions {\n /** The `.wasm` bytes or a compiled module. Without it, the browser fetches the file by URL. */\n wasm?: BufferSource | WebAssembly.Module\n locale?: string\n timezone?: string\n}\n\n// Lattice owns the display formats; IronCalc only computes. This format makes IronCalc print\n// each number in a form `Number()` reads: dates as serials, 15 significant digits. The\n// one-digit exponent avoids an IronCalc bug with 3-digit exponents (`E+30300` for `E+300`).\nconst READ_FORMAT = '0.00000000000000E+0'\nconst EVAL_SHEET = '__lattice_eval__'\n\n// `getCellType` codes in IronCalc 0.9.1.\nconst TEXT = 2\nconst BOOLEAN = 4\nconst ERROR = 16\n\ninterface SheetState {\n id: string\n name: string\n rows: string[]\n cols: string[]\n rowIndex: Map<string, number>\n colIndex: Map<string, number>\n}\n\ntype Grid<T> = Map<string, Map<string, Map<string, T>>>\n\nfunction gridSet<T>(grid: Grid<T>, sheet: string, row: string, col: string, value: T) {\n let rows = grid.get(sheet)\n if (!rows) grid.set(sheet, (rows = new Map()))\n let cols = rows.get(row)\n if (!cols) rows.set(row, (cols = new Map()))\n cols.set(col, value)\n}\n\nconst indexOf = (ids: string[]) => new Map(ids.map((id, i) => [id, i]))\n\nlet loaded: Promise<void> | undefined\n\nfunction loadWasm(wasm: IronCalcOptions['wasm']): Promise<void> {\n if (wasm) {\n initSync({ module: wasm })\n return Promise.resolve()\n }\n return (loaded ??= init().then(() => undefined))\n}\n\n/** Loads the IronCalc WASM module and gives a new engine. */\nexport async function createIronCalcEngine(options: IronCalcOptions = {}) {\n await loadWasm(options.wasm)\n return new IronCalcEngine(options)\n}\n\n/**\n * A `FormulaEngine` on IronCalc. IronCalc stores A1 formulas, so the engine converts the\n * stored ID refs to A1 when a formula is set. IronCalc moves its own refs on insert and\n * delete. IronCalc recalculates the full workbook and does not list the changed cells, so\n * `apply` reads the watched cells again and gives the values that changed.\n */\nexport class IronCalcEngine implements FormulaEngine {\n #options: IronCalcOptions\n #model: Model | undefined\n #sheets: SheetState[] = []\n #ctx: RefContext | undefined\n /** The cells with content. */\n #content: Grid<true> = new Map()\n /** The stored formulas that hold a range, for the range shrink on delete. */\n #ranges: Grid<string> = new Map()\n /** The last values read for the watched cells. */\n #values: Grid<CellValue> = new Map()\n #watch: WatchRange[] | null = null\n\n constructor(options: IronCalcOptions = {}) {\n this.#options = options\n }\n\n get #m(): Model {\n if (!this.#model) throw new Error('Lattice: call load() before you use the engine')\n return this.#model\n }\n\n async load(doc: SheetDoc): Promise<void> {\n this.#model?.free()\n const { locale = 'en', timezone = 'UTC' } = this.#options\n const m = (this.#model = new Model('lattice', locale, timezone, 'en'))\n this.#sheets = []\n this.#content = new Map()\n this.#ranges = new Map()\n this.#values = new Map()\n this.#ctx = undefined\n m.pauseEvaluation()\n doc.sheets.forEach((sheet, i) =>\n this.#addSheet(sheet.id, sheet.name, sheet.rows, sheet.cols, i),\n )\n for (const { name, ref } of doc.names ?? []) m.newDefinedName(name, null, this.#a1Name(ref))\n for (const sheet of doc.sheets) {\n for (const cell of sheet.cells) {\n this.#setCell(sheet.id, cell.row, cell.col, cell.value, cell.formula)\n }\n }\n m.resumeEvaluation()\n m.evaluate()\n this.#diff()\n }\n\n async apply(ops: SheetOp[]): Promise<CellChange[]> {\n const m = this.#m\n const touched: Grid<true> = new Map()\n m.pauseEvaluation()\n try {\n for (const op of ops) this.#apply(op, touched)\n } finally {\n m.resumeEvaluation()\n }\n m.evaluate()\n const changes = this.#diff(touched)\n // A cleared cell has no content after its change is out. A cell that a later op in the\n // batch deleted has no value here, so it is skipped.\n for (const [sheet, rows] of touched) {\n for (const [row, cols] of rows) {\n for (const col of cols.keys()) {\n if (this.#values.get(sheet)?.get(row)?.get(col) === null) {\n this.#content.get(sheet)?.get(row)?.delete(col)\n }\n }\n }\n }\n return changes\n }\n\n async evaluate(sheet: string, formula: string): Promise<CellValue> {\n const m = this.#m\n this.#sheetState(sheet)\n // A ref with no sheet is on `sheet`, not on the scratch sheet.\n const qualified = scanStored(formula)\n .map(t => (t.kind === 'ref' ? printStored({ sheet, ...t.ref }) : t.text))\n .join('')\n const a1 = toA1(qualified, sheet, this.#refs())\n m.newSheet()\n const index = this.#sheets.length\n m.renameSheet(index, EVAL_SHEET)\n try {\n m.setUserInput(index, 1, 1, a1)\n this.#readFormat(index, 1, 1)\n m.evaluate()\n return readCell(m, index, 1, 1)\n } finally {\n m.deleteSheet(index)\n }\n }\n\n functions(): FunctionInfo[] {\n return FUNCTION_NAMES.map(name => ({ name, signature: signatureOf(name) }))\n }\n\n async watch(ranges: WatchRange[] | null): Promise<CellChange[]> {\n this.#watch = ranges\n this.#values = new Map()\n this.#diff()\n const out: CellChange[] = []\n this.#eachWatched(new Map(), (sheet, row, col) => {\n const value = this.#values.get(sheet)?.get(row)?.get(col)\n if (value !== undefined) out.push({ sheet, row, col, value })\n })\n return out\n }\n\n dispose(): void {\n this.#model?.free()\n this.#model = undefined\n }\n\n #refs(): RefContext {\n return (this.#ctx ??= createRefContext({ sheets: this.#sheets }))\n }\n\n #sheetState(id: string): SheetState {\n const sheet = this.#sheets.find(s => s.id === id)\n if (!sheet) throw new Error(`Lattice: no sheet with the ID \"${id}\"`)\n return sheet\n }\n\n #sheetIndex(id: string): number {\n return this.#sheets.indexOf(this.#sheetState(id))\n }\n\n #a1Name(ref: string): string {\n const first = this.#sheets[0]?.id ?? ''\n return toA1(ref, first, this.#refs())\n }\n\n #addSheet(id: string, name: string, rows: string[], cols: string[], index: number) {\n const m = this.#m\n if (index > 0) m.newSheet()\n m.renameSheet(index, name)\n this.#sheets.push({\n id,\n name,\n rows: [...rows],\n cols: [...cols],\n rowIndex: indexOf(rows),\n colIndex: indexOf(cols),\n })\n this.#ctx = undefined\n }\n\n #readFormat(sheet: number, row: number, column: number) {\n this.#m.updateRangeStyle({ sheet, row, column, width: 1, height: 1 }, 'num_fmt', READ_FORMAT)\n }\n\n #position(sheetId: string, row: string, col: string) {\n const sheet = this.#sheetState(sheetId)\n const r = sheet.rowIndex.get(row)\n const c = sheet.colIndex.get(col)\n if (r === undefined || c === undefined) {\n throw new Error(`Lattice: no cell at row \"${row}\", column \"${col}\" on sheet \"${sheetId}\"`)\n }\n return { sheet: this.#sheets.indexOf(sheet), row: r + 1, col: c + 1 }\n }\n\n #setCell(sheet: string, row: string, col: string, value?: CellValue, formula?: string) {\n const m = this.#m\n const at = this.#position(sheet, row, col)\n const input = formula ? toA1(formula, sheet, this.#refs()) : toInput(value)\n if (formula && storedRefs(formula).some(ref => ref.end)) {\n gridSet(this.#ranges, sheet, row, col, formula)\n } else this.#ranges.get(sheet)?.get(row)?.delete(col)\n if (input === '') m.rangeClearContents(at.sheet, at.row, at.col, at.row, at.col)\n else {\n m.setUserInput(at.sheet, at.row, at.col, input)\n // After the input: IronCalc gives a formula such as `=DATE()` its own format on input.\n this.#readFormat(at.sheet, at.row, at.col)\n gridSet(this.#content, sheet, row, col, true)\n }\n }\n\n #apply(op: SheetOp, touched: Grid<true>) {\n const m = this.#m\n switch (op.type) {\n case 'setCell':\n this.#setCell(op.sheet, op.row, op.col, op.value, op.formula)\n gridSet(touched, op.sheet, op.row, op.col, true)\n return\n case 'insertRows':\n case 'insertCols': {\n const sheet = this.#sheetState(op.sheet)\n const rows = op.type === 'insertRows'\n const ids = rows ? sheet.rows : sheet.cols\n const at =\n op.before === null ? ids.length : (rows ? sheet.rowIndex : sheet.colIndex).get(op.before)\n if (at === undefined) throw new Error(`Lattice: no row or column \"${op.before}\"`)\n const index = this.#sheets.indexOf(sheet)\n if (rows) m.insertRows(index, at + 1, op.ids.length)\n else m.insertColumns(index, at + 1, op.ids.length)\n ids.splice(at, 0, ...op.ids)\n this.#reindex(sheet)\n return\n }\n case 'deleteRows':\n case 'deleteCols': {\n const sheet = this.#sheetState(op.sheet)\n const rows = op.type === 'deleteRows'\n const map = rows ? sheet.rowIndex : sheet.colIndex\n const index = this.#sheets.indexOf(sheet)\n const positions = op.ids.map(id => map.get(id)).filter(i => i !== undefined)\n const shrunk = this.#shrink({ sheet: op.sheet, [rows ? 'rows' : 'cols']: op.ids })\n // Delete runs from the bottom, so the earlier positions stay correct.\n for (const [start, count] of runs(positions)) {\n if (rows) m.deleteRows(index, start + 1, count)\n else m.deleteColumns(index, start + 1, count)\n }\n const gone = new Set(op.ids)\n if (rows) sheet.rows = sheet.rows.filter(id => !gone.has(id))\n else sheet.cols = sheet.cols.filter(id => !gone.has(id))\n for (const grid of [this.#content, this.#values]) {\n const sheetRows = grid.get(op.sheet)\n if (!sheetRows) continue\n if (rows) for (const id of gone) sheetRows.delete(id)\n else for (const cols of sheetRows.values()) for (const id of gone) cols.delete(id)\n }\n this.#reindex(sheet)\n for (const cell of shrunk)\n this.#setCell(cell.sheet, cell.row, cell.col, undefined, cell.formula)\n return\n }\n case 'setName': {\n const exists = m\n .getDefinedNameList()\n .some(n => n.name.toUpperCase() === op.name.toUpperCase())\n if (op.ref === null) {\n if (exists) m.deleteDefinedName(op.name, null)\n } else if (exists) m.updateDefinedName(op.name, null, op.name, null, this.#a1Name(op.ref))\n else m.newDefinedName(op.name, null, this.#a1Name(op.ref))\n return\n }\n case 'addSheet':\n this.#addSheet(op.id, op.name, op.rows, op.cols, this.#sheets.length)\n return\n case 'removeSheet': {\n m.deleteSheet(this.#sheetIndex(op.id))\n this.#sheets = this.#sheets.filter(s => s.id !== op.id)\n this.#content.delete(op.id)\n this.#values.delete(op.id)\n this.#ctx = undefined\n return\n }\n case 'renameSheet':\n m.renameSheet(this.#sheetIndex(op.id), op.name)\n this.#sheetState(op.id).name = op.name\n this.#ctx = undefined\n return\n // Formats, styles and merges are Lattice state. They do not change a computed value.\n case 'setFormat':\n case 'setStyle':\n case 'merge':\n case 'unmerge':\n return\n }\n }\n\n /**\n * IronCalc 0.9.1 turns a range end that a delete removes into `#REF!`. Excel moves the end\n * inward. Gives the range formulas to set again after the delete, with the ends moved. A range\n * that loses all its rows or columns is set again as it is: it prints as `#REF!`, as on a fresh\n * load (IronCalc gives `#VALUE!` for it after its own delete).\n */\n #shrink(deletion: Deletion) {\n const out: { sheet: string; row: string; col: string; formula: string }[] = []\n const gone = new Set([...(deletion.rows ?? []), ...(deletion.cols ?? [])])\n for (const [sheet, rows] of this.#ranges) {\n for (const [row, cols] of rows) {\n if (sheet === deletion.sheet && deletion.rows && gone.has(row)) continue\n for (const [col, formula] of cols) {\n if (sheet === deletion.sheet && gone.has(col)) continue\n const next = shrinkDeleted(formula, sheet, this.#refs(), deletion)\n const lost = storedRefs(next).some(\n ref =>\n (ref.sheet ?? sheet) === deletion.sheet &&\n [ref.start, ref.end].some(p => gone.has(p?.row ?? '') || gone.has(p?.col ?? '')),\n )\n if (next !== formula || lost) out.push({ sheet, row, col, formula: next })\n }\n }\n }\n return out\n }\n\n #reindex(sheet: SheetState) {\n sheet.rowIndex = indexOf(sheet.rows)\n sheet.colIndex = indexOf(sheet.cols)\n this.#ctx = undefined\n }\n\n #eachWatched(touched: Grid<true>, fn: (sheet: string, row: string, col: string) => void) {\n if (this.#watch) {\n for (const range of this.#watch) {\n for (const row of range.rows) for (const col of range.cols) fn(range.sheet, row, col)\n }\n return\n }\n for (const grid of [this.#content, touched]) {\n for (const [sheet, rows] of grid) {\n for (const [row, cols] of rows) {\n for (const col of cols.keys()) {\n if (grid === touched && this.#content.get(sheet)?.get(row)?.has(col)) continue\n fn(sheet, row, col)\n }\n }\n }\n }\n }\n\n /** Reads the watched cells and gives the values that differ from the last read. */\n #diff(touched: Grid<true> = new Map()): CellChange[] {\n const changes: CellChange[] = []\n const m = this.#m\n const sheets = new Map(this.#sheets.map((sheet, index) => [sheet.id, { sheet, index }]))\n this.#eachWatched(touched, (sheetId, row, col) => {\n const at = sheets.get(sheetId)\n const r = at?.sheet.rowIndex.get(row)\n const c = at?.sheet.colIndex.get(col)\n if (!at || r === undefined || c === undefined) return\n const value = readCell(m, at.index, r + 1, c + 1)\n const prev = this.#values.get(sheetId)?.get(row)?.get(col)\n if (prev === undefined ? value !== null : !sameValue(prev, value)) {\n changes.push({ sheet: sheetId, row, col, value })\n }\n gridSet(this.#values, sheetId, row, col, value)\n })\n return changes\n }\n}\n\nfunction sameValue(a: CellValue, b: CellValue): boolean {\n if (is.plainObject(a) && is.plainObject(b)) {\n return a.error === b.error\n }\n return a === b\n}\n\n/** Groups positions into runs of `[start, count]`, from the last run to the first. */\nfunction runs(positions: number[]): [number, number][] {\n const sorted = [...new Set(positions)].sort((a, b) => b - a)\n const out: [number, number][] = []\n for (const p of sorted) {\n const last = out[out.length - 1]\n if (last && last[0] - 1 === p) {\n last[0] = p\n last[1]++\n } else out.push([p, 1])\n }\n return out\n}\n\nfunction toInput(value: CellValue | undefined): string {\n if (value === null || value === undefined) return ''\n if (value === true) return 'TRUE'\n if (value === false) return 'FALSE'\n if (is.number(value)) return String(value)\n if (is.string(value)) return value === '' ? '' : `'${value}`\n return value.error\n}\n\nfunction readCell(m: Model, sheet: number, row: number, col: number): CellValue {\n const type = m.getCellType(sheet, row, col)\n const text = m.getFormattedCellValue(sheet, row, col)\n if (type === TEXT) return text\n if (type === BOOLEAN) return text === 'TRUE'\n if (type === ERROR) return { error: text }\n if (text === '') return null\n const n = Number(text)\n return Number.isNaN(n) ? text : n\n}\n","// A message protocol that runs a `FormulaEngine` in a worker, so the UI thread never waits on\n// a recalc. The page side is `createWorkerEngine(worker)`; the worker side is\n// `serveEngine(self, () => createIronCalcEngine())`. Both sides take a small port, so the same\n// code runs on a browser `Worker`, a `MessagePort` and Node `worker_threads` (with an adapter).\nimport type {\n CellChange,\n CellValue,\n FormulaEngine,\n FunctionInfo,\n SheetDoc,\n SheetOp,\n WatchRange,\n} from '@ember-lattice/formula'\n\nexport interface PortLike {\n postMessage(message: unknown): void\n addEventListener(type: 'message', listener: (event: { data: unknown }) => void): void\n}\n\nexport type EngineRequest =\n | { id: number; method: 'load'; args: [SheetDoc] }\n | { id: number; method: 'apply'; args: [SheetOp[]] }\n | { id: number; method: 'evaluate'; args: [string, string] }\n | { id: number; method: 'watch'; args: [WatchRange[] | null] }\n\nexport type EngineResponse =\n { id: number; ok: true; result: unknown } | { id: number; ok: false; error: string }\n\n/** The worker side: answers each request with the result or the error message. */\nexport function serveEngine(port: PortLike, create: () => Promise<FormulaEngine>): void {\n const engine = create()\n port.addEventListener('message', async event => {\n const request = event.data as EngineRequest\n try {\n const e = await engine\n let result: unknown\n switch (request.method) {\n case 'load':\n await e.load(...request.args)\n result = e.functions()\n break\n case 'apply':\n result = await e.apply(...request.args)\n break\n case 'evaluate':\n result = await e.evaluate(...request.args)\n break\n case 'watch':\n result = e.watch ? await e.watch(...request.args) : []\n break\n }\n port.postMessage({ id: request.id, ok: true, result } satisfies EngineResponse)\n } catch (error) {\n const message = error instanceof Error ? error.message : String(error)\n port.postMessage({ id: request.id, ok: false, error: message } satisfies EngineResponse)\n }\n })\n}\n\n/** The page side: a `FormulaEngine` whose calls go to the engine in the worker. */\nexport function createWorkerEngine(port: PortLike): FormulaEngine & {\n watch(ranges: WatchRange[] | null): Promise<CellChange[]>\n} {\n let next = 0\n let functions: FunctionInfo[] = []\n const pending = new Map<number, { resolve: (v: unknown) => void; reject: (e: Error) => void }>()\n port.addEventListener('message', event => {\n const response = event.data as EngineResponse\n const call = pending.get(response.id)\n if (!call) return\n pending.delete(response.id)\n if (response.ok) call.resolve(response.result)\n else call.reject(new Error(response.error))\n })\n const send = <T>(method: EngineRequest['method'], args: unknown[]) =>\n new Promise<T>((resolve, reject) => {\n const id = next++\n pending.set(id, { resolve: resolve as (v: unknown) => void, reject })\n port.postMessage({ id, method, args })\n })\n return {\n async load(doc) {\n functions = await send<FunctionInfo[]>('load', [doc])\n },\n apply: ops => send<CellChange[]>('apply', [ops]),\n evaluate: (sheet, formula) => send<CellValue>('evaluate', [sheet, formula]),\n watch: ranges => send<CellChange[]>('watch', [ranges]),\n functions: () => functions,\n }\n}\n"]}
|
package/dist/worker.d.ts
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { CellChange, FormulaEngine, SheetDoc, SheetOp, WatchRange } from '@ember-lattice/formula';
|
|
2
|
+
export interface PortLike {
|
|
3
|
+
postMessage(message: unknown): void;
|
|
4
|
+
addEventListener(type: 'message', listener: (event: {
|
|
5
|
+
data: unknown;
|
|
6
|
+
}) => void): void;
|
|
7
|
+
}
|
|
8
|
+
export type EngineRequest = {
|
|
9
|
+
id: number;
|
|
10
|
+
method: 'load';
|
|
11
|
+
args: [SheetDoc];
|
|
12
|
+
} | {
|
|
13
|
+
id: number;
|
|
14
|
+
method: 'apply';
|
|
15
|
+
args: [SheetOp[]];
|
|
16
|
+
} | {
|
|
17
|
+
id: number;
|
|
18
|
+
method: 'evaluate';
|
|
19
|
+
args: [string, string];
|
|
20
|
+
} | {
|
|
21
|
+
id: number;
|
|
22
|
+
method: 'watch';
|
|
23
|
+
args: [WatchRange[] | null];
|
|
24
|
+
};
|
|
25
|
+
export type EngineResponse = {
|
|
26
|
+
id: number;
|
|
27
|
+
ok: true;
|
|
28
|
+
result: unknown;
|
|
29
|
+
} | {
|
|
30
|
+
id: number;
|
|
31
|
+
ok: false;
|
|
32
|
+
error: string;
|
|
33
|
+
};
|
|
34
|
+
/** The worker side: answers each request with the result or the error message. */
|
|
35
|
+
export declare function serveEngine(port: PortLike, create: () => Promise<FormulaEngine>): void;
|
|
36
|
+
/** The page side: a `FormulaEngine` whose calls go to the engine in the worker. */
|
|
37
|
+
export declare function createWorkerEngine(port: PortLike): FormulaEngine & {
|
|
38
|
+
watch(ranges: WatchRange[] | null): Promise<CellChange[]>;
|
|
39
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,53 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ember-lattice/formula-ironcalc",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "A Lattice FormulaEngine on IronCalc (WASM), for the browser worker and for Node.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"data-grid",
|
|
7
|
+
"server-side-row-model",
|
|
8
|
+
"protocol"
|
|
9
|
+
],
|
|
10
|
+
"license": "MIT",
|
|
11
|
+
"author": "Joe Gaudet <joe@joegaudet.com>",
|
|
12
|
+
"repository": {
|
|
13
|
+
"type": "git",
|
|
14
|
+
"url": "git+https://github.com/joegaudet/ember-lattice.git",
|
|
15
|
+
"directory": "packages/formula-ironcalc"
|
|
16
|
+
},
|
|
17
|
+
"homepage": "https://joegaudet.com/ember-lattice/",
|
|
18
|
+
"bugs": "https://github.com/joegaudet/ember-lattice/issues",
|
|
19
|
+
"type": "module",
|
|
20
|
+
"types": "./dist/index.d.ts",
|
|
21
|
+
"exports": {
|
|
22
|
+
".": {
|
|
23
|
+
"types": "./dist/index.d.ts",
|
|
24
|
+
"default": "./dist/index.js"
|
|
25
|
+
},
|
|
26
|
+
"./package.json": "./package.json"
|
|
27
|
+
},
|
|
28
|
+
"files": [
|
|
29
|
+
"dist",
|
|
30
|
+
"CHANGELOG.md",
|
|
31
|
+
"README.md",
|
|
32
|
+
"LICENSE.md",
|
|
33
|
+
"NOTICE"
|
|
34
|
+
],
|
|
35
|
+
"sideEffects": false,
|
|
36
|
+
"devDependencies": {
|
|
37
|
+
"tsup": "^8.5.1"
|
|
38
|
+
},
|
|
39
|
+
"publishConfig": {
|
|
40
|
+
"access": "public"
|
|
41
|
+
},
|
|
42
|
+
"engines": {
|
|
43
|
+
"node": ">=22.12.0"
|
|
44
|
+
},
|
|
45
|
+
"dependencies": {
|
|
46
|
+
"@ember-lattice/formula": "1.0.0",
|
|
47
|
+
"@ironcalc/wasm": "0.9.1",
|
|
48
|
+
"@sindresorhus/is": "^7.2.0"
|
|
49
|
+
},
|
|
50
|
+
"scripts": {
|
|
51
|
+
"build": "tsc --build --force && tsup"
|
|
52
|
+
}
|
|
6
53
|
}
|