@ricsam/formula-engine 0.0.5 → 0.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/core/engine.cjs +62 -2
- package/dist/cjs/core/engine.cjs.map +3 -3
- package/dist/cjs/core/managers/dependency-manager.cjs +32 -39
- package/dist/cjs/core/managers/dependency-manager.cjs.map +3 -3
- package/dist/cjs/core/managers/evaluation-manager.cjs +31 -34
- package/dist/cjs/core/managers/evaluation-manager.cjs.map +3 -3
- package/dist/cjs/core/managers/style-manager.cjs +341 -0
- package/dist/cjs/core/managers/style-manager.cjs.map +10 -0
- package/dist/cjs/core/types.cjs.map +1 -1
- package/dist/cjs/core/utils/color-utils.cjs +137 -0
- package/dist/cjs/core/utils/color-utils.cjs.map +10 -0
- package/dist/cjs/evaluator/dependency-nodes/virtual-cell-value-node.cjs +55 -0
- package/dist/cjs/evaluator/dependency-nodes/virtual-cell-value-node.cjs.map +10 -0
- package/dist/cjs/lib.cjs +2 -1
- package/dist/cjs/lib.cjs.map +3 -3
- package/dist/cjs/package.json +1 -1
- package/dist/mjs/core/engine.mjs +62 -2
- package/dist/mjs/core/engine.mjs.map +3 -3
- package/dist/mjs/core/managers/dependency-manager.mjs +37 -41
- package/dist/mjs/core/managers/dependency-manager.mjs.map +3 -3
- package/dist/mjs/core/managers/evaluation-manager.mjs +31 -34
- package/dist/mjs/core/managers/evaluation-manager.mjs.map +3 -3
- package/dist/mjs/core/managers/style-manager.mjs +315 -0
- package/dist/mjs/core/managers/style-manager.mjs.map +10 -0
- package/dist/mjs/core/types.mjs.map +1 -1
- package/dist/mjs/core/utils/color-utils.mjs +107 -0
- package/dist/mjs/core/utils/color-utils.mjs.map +10 -0
- package/dist/mjs/evaluator/dependency-nodes/virtual-cell-value-node.mjs +25 -0
- package/dist/mjs/evaluator/dependency-nodes/virtual-cell-value-node.mjs.map +10 -0
- package/dist/mjs/lib.mjs +2 -1
- package/dist/mjs/lib.mjs.map +3 -3
- package/dist/mjs/package.json +1 -1
- package/dist/types/core/engine.d.ts +39 -1
- package/dist/types/core/managers/dependency-manager.d.ts +8 -7
- package/dist/types/core/managers/evaluation-manager.d.ts +13 -3
- package/dist/types/core/managers/style-manager.d.ts +92 -0
- package/dist/types/core/types.d.ts +42 -0
- package/dist/types/core/utils/color-utils.d.ts +32 -0
- package/dist/types/evaluator/dependency-nodes/virtual-cell-value-node.d.ts +11 -0
- package/dist/types/lib.d.ts +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,341 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __moduleCache = /* @__PURE__ */ new WeakMap;
|
|
6
|
+
var __toCommonJS = (from) => {
|
|
7
|
+
var entry = __moduleCache.get(from), desc;
|
|
8
|
+
if (entry)
|
|
9
|
+
return entry;
|
|
10
|
+
entry = __defProp({}, "__esModule", { value: true });
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function")
|
|
12
|
+
__getOwnPropNames(from).map((key) => !__hasOwnProp.call(entry, key) && __defProp(entry, key, {
|
|
13
|
+
get: () => from[key],
|
|
14
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
15
|
+
}));
|
|
16
|
+
__moduleCache.set(from, entry);
|
|
17
|
+
return entry;
|
|
18
|
+
};
|
|
19
|
+
var __export = (target, all) => {
|
|
20
|
+
for (var name in all)
|
|
21
|
+
__defProp(target, name, {
|
|
22
|
+
get: all[name],
|
|
23
|
+
enumerable: true,
|
|
24
|
+
configurable: true,
|
|
25
|
+
set: (newValue) => all[name] = () => newValue
|
|
26
|
+
});
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
// src/core/managers/style-manager.ts
|
|
30
|
+
var exports_style_manager = {};
|
|
31
|
+
__export(exports_style_manager, {
|
|
32
|
+
StyleManager: () => StyleManager
|
|
33
|
+
});
|
|
34
|
+
module.exports = __toCommonJS(exports_style_manager);
|
|
35
|
+
var import_utils = require("../utils.cjs");
|
|
36
|
+
var import_color_utils = require("../utils/color-utils.cjs");
|
|
37
|
+
|
|
38
|
+
class StyleManager {
|
|
39
|
+
workbookManager;
|
|
40
|
+
evaluationManager;
|
|
41
|
+
conditionalStyles = [];
|
|
42
|
+
cellStyles = [];
|
|
43
|
+
constructor(workbookManager, evaluationManager) {
|
|
44
|
+
this.workbookManager = workbookManager;
|
|
45
|
+
this.evaluationManager = evaluationManager;
|
|
46
|
+
}
|
|
47
|
+
addConditionalStyle(style) {
|
|
48
|
+
this.conditionalStyles.push(style);
|
|
49
|
+
}
|
|
50
|
+
removeConditionalStyle(workbookName, index) {
|
|
51
|
+
const workbookStyles = this.conditionalStyles.filter((style) => style.area.workbookName === workbookName);
|
|
52
|
+
if (index < 0 || index >= workbookStyles.length) {
|
|
53
|
+
return false;
|
|
54
|
+
}
|
|
55
|
+
let currentIndex = 0;
|
|
56
|
+
for (let i = 0;i < this.conditionalStyles.length; i++) {
|
|
57
|
+
const style = this.conditionalStyles[i];
|
|
58
|
+
if (style && style.area.workbookName === workbookName) {
|
|
59
|
+
if (currentIndex === index) {
|
|
60
|
+
this.conditionalStyles.splice(i, 1);
|
|
61
|
+
return true;
|
|
62
|
+
}
|
|
63
|
+
currentIndex++;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
return false;
|
|
67
|
+
}
|
|
68
|
+
getConditionalStyles(workbookName) {
|
|
69
|
+
return this.conditionalStyles.filter((style) => style && style.area && style.area.workbookName === workbookName);
|
|
70
|
+
}
|
|
71
|
+
addCellStyle(style) {
|
|
72
|
+
this.cellStyles.push(style);
|
|
73
|
+
}
|
|
74
|
+
removeCellStyle(workbookName, index) {
|
|
75
|
+
const workbookStyles = this.cellStyles.filter((style) => style && style.area && style.area.workbookName === workbookName);
|
|
76
|
+
if (index < 0 || index >= workbookStyles.length) {
|
|
77
|
+
return false;
|
|
78
|
+
}
|
|
79
|
+
let currentIndex = 0;
|
|
80
|
+
for (let i = 0;i < this.cellStyles.length; i++) {
|
|
81
|
+
const style = this.cellStyles[i];
|
|
82
|
+
if (style && style.area && style.area.workbookName === workbookName) {
|
|
83
|
+
if (currentIndex === index) {
|
|
84
|
+
this.cellStyles.splice(i, 1);
|
|
85
|
+
return true;
|
|
86
|
+
}
|
|
87
|
+
currentIndex++;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
return false;
|
|
91
|
+
}
|
|
92
|
+
getCellStyles(workbookName) {
|
|
93
|
+
return this.cellStyles.filter((style) => style && style.area && style.area.workbookName === workbookName);
|
|
94
|
+
}
|
|
95
|
+
getAllConditionalStyles() {
|
|
96
|
+
return [...this.conditionalStyles];
|
|
97
|
+
}
|
|
98
|
+
getAllCellStyles() {
|
|
99
|
+
return [...this.cellStyles];
|
|
100
|
+
}
|
|
101
|
+
resetStyles(conditionalStyles, cellStyles) {
|
|
102
|
+
this.conditionalStyles = conditionalStyles ? [...conditionalStyles] : [];
|
|
103
|
+
this.cellStyles = cellStyles ? [...cellStyles] : [];
|
|
104
|
+
}
|
|
105
|
+
removeWorkbookStyles(workbookName) {
|
|
106
|
+
this.conditionalStyles = this.conditionalStyles.filter((style) => style.area.workbookName !== workbookName);
|
|
107
|
+
this.cellStyles = this.cellStyles.filter((style) => style.area.workbookName !== workbookName);
|
|
108
|
+
}
|
|
109
|
+
updateWorkbookName(oldName, newName) {
|
|
110
|
+
this.conditionalStyles = this.conditionalStyles.map((style) => {
|
|
111
|
+
if (style.area.workbookName === oldName) {
|
|
112
|
+
return {
|
|
113
|
+
...style,
|
|
114
|
+
area: {
|
|
115
|
+
...style.area,
|
|
116
|
+
workbookName: newName
|
|
117
|
+
}
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
return style;
|
|
121
|
+
});
|
|
122
|
+
this.cellStyles = this.cellStyles.map((style) => {
|
|
123
|
+
if (style.area.workbookName === oldName) {
|
|
124
|
+
return {
|
|
125
|
+
...style,
|
|
126
|
+
area: {
|
|
127
|
+
...style.area,
|
|
128
|
+
workbookName: newName
|
|
129
|
+
}
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
return style;
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
updateSheetName(workbookName, oldSheetName, newSheetName) {
|
|
136
|
+
this.conditionalStyles = this.conditionalStyles.map((style) => {
|
|
137
|
+
if (style.area.workbookName === workbookName && style.area.sheetName === oldSheetName) {
|
|
138
|
+
return {
|
|
139
|
+
...style,
|
|
140
|
+
area: {
|
|
141
|
+
...style.area,
|
|
142
|
+
sheetName: newSheetName
|
|
143
|
+
}
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
return style;
|
|
147
|
+
});
|
|
148
|
+
this.cellStyles = this.cellStyles.map((style) => {
|
|
149
|
+
if (style.area.workbookName === workbookName && style.area.sheetName === oldSheetName) {
|
|
150
|
+
return {
|
|
151
|
+
...style,
|
|
152
|
+
area: {
|
|
153
|
+
...style.area,
|
|
154
|
+
sheetName: newSheetName
|
|
155
|
+
}
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
return style;
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
removeSheetStyles(workbookName, sheetName) {
|
|
162
|
+
this.conditionalStyles = this.conditionalStyles.filter((style) => !(style.area.workbookName === workbookName && style.area.sheetName === sheetName));
|
|
163
|
+
this.cellStyles = this.cellStyles.filter((style) => !(style.area.workbookName === workbookName && style.area.sheetName === sheetName));
|
|
164
|
+
}
|
|
165
|
+
getCellStyle(cellAddress) {
|
|
166
|
+
for (const cellStyle of this.cellStyles) {
|
|
167
|
+
if (!cellStyle || !cellStyle.area) {
|
|
168
|
+
continue;
|
|
169
|
+
}
|
|
170
|
+
if (cellStyle.area.workbookName === cellAddress.workbookName && cellStyle.area.sheetName === cellAddress.sheetName && import_utils.isCellInRange(cellAddress, cellStyle.area.range)) {
|
|
171
|
+
return {
|
|
172
|
+
backgroundColor: cellStyle.style.backgroundColor,
|
|
173
|
+
color: cellStyle.style.color
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
for (const style of this.conditionalStyles) {
|
|
178
|
+
if (!style || !style.area) {
|
|
179
|
+
continue;
|
|
180
|
+
}
|
|
181
|
+
if (style.area.sheetName !== cellAddress.sheetName || style.area.workbookName !== cellAddress.workbookName) {
|
|
182
|
+
continue;
|
|
183
|
+
}
|
|
184
|
+
if (!import_utils.isCellInRange(cellAddress, style.area.range)) {
|
|
185
|
+
continue;
|
|
186
|
+
}
|
|
187
|
+
if (style.condition.type === "formula") {
|
|
188
|
+
const result = this.evaluateFormulaCondition(cellAddress, style);
|
|
189
|
+
if (result)
|
|
190
|
+
return result;
|
|
191
|
+
} else {
|
|
192
|
+
const result = this.evaluateGradientCondition(cellAddress, style);
|
|
193
|
+
if (result)
|
|
194
|
+
return result;
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
return;
|
|
198
|
+
}
|
|
199
|
+
evaluateFormulaCondition(cellAddress, style) {
|
|
200
|
+
if (style.condition.type !== "formula") {
|
|
201
|
+
return;
|
|
202
|
+
}
|
|
203
|
+
try {
|
|
204
|
+
const formula = style.condition.formula.startsWith("=") ? style.condition.formula : `=${style.condition.formula}`;
|
|
205
|
+
const result = this.evaluationManager.evaluateFormula(formula, cellAddress);
|
|
206
|
+
const isTruthy = result === true || result === "TRUE" || typeof result === "number" && result !== 0;
|
|
207
|
+
if (isTruthy) {
|
|
208
|
+
return {
|
|
209
|
+
backgroundColor: import_color_utils.lchToHex(style.condition.color)
|
|
210
|
+
};
|
|
211
|
+
}
|
|
212
|
+
} catch (error) {
|
|
213
|
+
console.warn("Failed to evaluate formula condition:", error);
|
|
214
|
+
}
|
|
215
|
+
return;
|
|
216
|
+
}
|
|
217
|
+
evaluateGradientCondition(cellAddress, style) {
|
|
218
|
+
if (style.condition.type !== "gradient") {
|
|
219
|
+
return;
|
|
220
|
+
}
|
|
221
|
+
try {
|
|
222
|
+
const evalResult = this.evaluationManager.getCellEvaluationResult(cellAddress);
|
|
223
|
+
if (!evalResult || evalResult.type !== "value") {
|
|
224
|
+
return;
|
|
225
|
+
}
|
|
226
|
+
if (evalResult.result.type !== "number") {
|
|
227
|
+
return;
|
|
228
|
+
}
|
|
229
|
+
const cellValue = evalResult.result.value;
|
|
230
|
+
const { min: minValue, max: maxValue } = this.calculateGradientBounds(style, cellAddress);
|
|
231
|
+
if (minValue === null || maxValue === null) {
|
|
232
|
+
return;
|
|
233
|
+
}
|
|
234
|
+
const factor = import_color_utils.calculateGradientFactor(cellValue, minValue, maxValue);
|
|
235
|
+
const minColor = style.condition.min.color;
|
|
236
|
+
const maxColor = style.condition.max.color;
|
|
237
|
+
const interpolatedColor = import_color_utils.interpolateLCH(minColor, maxColor, factor);
|
|
238
|
+
return {
|
|
239
|
+
backgroundColor: import_color_utils.lchToHex(interpolatedColor)
|
|
240
|
+
};
|
|
241
|
+
} catch (error) {
|
|
242
|
+
console.warn("Failed to evaluate gradient condition:", error);
|
|
243
|
+
return;
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
calculateGradientBounds(style, cellAddress) {
|
|
247
|
+
if (style.condition.type !== "gradient") {
|
|
248
|
+
return { min: null, max: null };
|
|
249
|
+
}
|
|
250
|
+
const { min: minConfig, max: maxConfig } = style.condition;
|
|
251
|
+
const topLeftCell = {
|
|
252
|
+
workbookName: style.area.workbookName,
|
|
253
|
+
sheetName: style.area.sheetName,
|
|
254
|
+
colIndex: style.area.range.start.col,
|
|
255
|
+
rowIndex: style.area.range.start.row
|
|
256
|
+
};
|
|
257
|
+
let minValue = null;
|
|
258
|
+
if (minConfig.type === "lowest_value") {
|
|
259
|
+
try {
|
|
260
|
+
const rangeRef = this.getRangeReference(style.area);
|
|
261
|
+
const result = this.evaluationManager.evaluateFormula(`=MIN(${rangeRef})`, topLeftCell);
|
|
262
|
+
if (typeof result === "number") {
|
|
263
|
+
minValue = result;
|
|
264
|
+
}
|
|
265
|
+
} catch (error) {
|
|
266
|
+
console.warn("Failed to calculate MIN:", error);
|
|
267
|
+
}
|
|
268
|
+
} else {
|
|
269
|
+
const formula = minConfig.valueFormula.startsWith("=") ? minConfig.valueFormula : `=${minConfig.valueFormula}`;
|
|
270
|
+
const result = this.evaluationManager.evaluateFormula(formula, topLeftCell);
|
|
271
|
+
if (typeof result === "number") {
|
|
272
|
+
minValue = result;
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
let maxValue = null;
|
|
276
|
+
if (maxConfig.type === "highest_value") {
|
|
277
|
+
try {
|
|
278
|
+
const rangeRef = this.getRangeReference(style.area);
|
|
279
|
+
const result = this.evaluationManager.evaluateFormula(`=MAX(${rangeRef})`, topLeftCell);
|
|
280
|
+
if (typeof result === "number") {
|
|
281
|
+
maxValue = result;
|
|
282
|
+
}
|
|
283
|
+
} catch (error) {
|
|
284
|
+
console.warn("Failed to calculate MAX:", error);
|
|
285
|
+
}
|
|
286
|
+
} else {
|
|
287
|
+
const formula = maxConfig.valueFormula.startsWith("=") ? maxConfig.valueFormula : `=${maxConfig.valueFormula}`;
|
|
288
|
+
const result = this.evaluationManager.evaluateFormula(formula, topLeftCell);
|
|
289
|
+
if (typeof result === "number") {
|
|
290
|
+
maxValue = result;
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
return { min: minValue, max: maxValue };
|
|
294
|
+
}
|
|
295
|
+
getRangeReference(area) {
|
|
296
|
+
const colToLetter = (col) => {
|
|
297
|
+
let result = "";
|
|
298
|
+
let c = col;
|
|
299
|
+
while (c >= 0) {
|
|
300
|
+
result = String.fromCharCode(65 + c % 26) + result;
|
|
301
|
+
c = Math.floor(c / 26) - 1;
|
|
302
|
+
}
|
|
303
|
+
return result;
|
|
304
|
+
};
|
|
305
|
+
const startCol = colToLetter(area.range.start.col);
|
|
306
|
+
const startRow = area.range.start.row + 1;
|
|
307
|
+
const isColInfinity = area.range.end.col.type === "infinity";
|
|
308
|
+
const isRowInfinity = area.range.end.row.type === "infinity";
|
|
309
|
+
let rangeStr;
|
|
310
|
+
if (isColInfinity && isRowInfinity) {
|
|
311
|
+
rangeStr = `${startCol}${startRow}:INFINITY`;
|
|
312
|
+
} else if (isColInfinity) {
|
|
313
|
+
if (area.range.end.row.type === "number") {
|
|
314
|
+
const endRow = area.range.end.row.value + 1;
|
|
315
|
+
rangeStr = `${startCol}${startRow}:${endRow}`;
|
|
316
|
+
} else {
|
|
317
|
+
rangeStr = `${startCol}${startRow}:INFINITY`;
|
|
318
|
+
}
|
|
319
|
+
} else if (isRowInfinity) {
|
|
320
|
+
if (area.range.end.col.type === "number") {
|
|
321
|
+
const endCol = colToLetter(area.range.end.col.value);
|
|
322
|
+
rangeStr = `${startCol}${startRow}:${endCol}`;
|
|
323
|
+
} else {
|
|
324
|
+
rangeStr = `${startCol}${startRow}:INFINITY`;
|
|
325
|
+
}
|
|
326
|
+
} else {
|
|
327
|
+
if (area.range.end.col.type === "number" && area.range.end.row.type === "number") {
|
|
328
|
+
const endCol = colToLetter(area.range.end.col.value);
|
|
329
|
+
const endRow = area.range.end.row.value + 1;
|
|
330
|
+
rangeStr = `${startCol}${startRow}:${endCol}${endRow}`;
|
|
331
|
+
} else {
|
|
332
|
+
rangeStr = `${startCol}${startRow}:INFINITY`;
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
const needsQuotes = /[ '!]/.test(area.sheetName);
|
|
336
|
+
const sheetRef = needsQuotes ? `'${area.sheetName.replace(/'/g, "''")}'` : area.sheetName;
|
|
337
|
+
return `[${area.workbookName}]${sheetRef}!${rangeStr}`;
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
//# debugId=2984643D5EF61FCB64756E2164756E21
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../src/core/managers/style-manager.ts"],
|
|
4
|
+
"sourcesContent": [
|
|
5
|
+
"/**\n * StyleManager - Manages conditional styling for cells\n */\n\nimport type {\n CellAddress,\n CellStyle,\n ConditionalStyle,\n DirectCellStyle,\n RangeAddress,\n SerializedCellValue,\n} from \"../types.cjs\";\nimport type { WorkbookManager } from \"./workbook-manager.cjs\";\nimport type { EvaluationManager } from \"./evaluation-manager.cjs\";\nimport { isCellInRange } from \"../utils.cjs\";\nimport {\n calculateGradientFactor,\n interpolateLCH,\n lchToHex,\n} from \"../utils/color-utils.cjs\";\n\nexport class StyleManager {\n private conditionalStyles: ConditionalStyle[] = [];\n private cellStyles: DirectCellStyle[] = [];\n\n constructor(\n private workbookManager: WorkbookManager,\n private evaluationManager: EvaluationManager\n ) {}\n\n /**\n * Add a conditional style rule\n */\n addConditionalStyle(style: ConditionalStyle): void {\n this.conditionalStyles.push(style);\n }\n\n /**\n * Remove a conditional style rule by index for a specific workbook\n */\n removeConditionalStyle(workbookName: string, index: number): boolean {\n const workbookStyles = this.conditionalStyles.filter(\n (style) => style.area.workbookName === workbookName\n );\n if (index < 0 || index >= workbookStyles.length) {\n return false;\n }\n // Find the actual index in the full array\n let currentIndex = 0;\n for (let i = 0; i < this.conditionalStyles.length; i++) {\n const style = this.conditionalStyles[i];\n if (style && style.area.workbookName === workbookName) {\n if (currentIndex === index) {\n this.conditionalStyles.splice(i, 1);\n return true;\n }\n currentIndex++;\n }\n }\n return false;\n }\n\n /**\n * Get all conditional styles for a workbook\n */\n getConditionalStyles(workbookName: string): ConditionalStyle[] {\n return this.conditionalStyles.filter(\n (style) => style && style.area && style.area.workbookName === workbookName\n );\n }\n\n /**\n * Add a direct cell style rule\n */\n addCellStyle(style: DirectCellStyle): void {\n this.cellStyles.push(style);\n }\n\n /**\n * Remove a direct cell style rule by index for a specific workbook\n */\n removeCellStyle(workbookName: string, index: number): boolean {\n const workbookStyles = this.cellStyles.filter(\n (style) => style && style.area && style.area.workbookName === workbookName\n );\n if (index < 0 || index >= workbookStyles.length) {\n return false;\n }\n // Find the actual index in the full array\n let currentIndex = 0;\n for (let i = 0; i < this.cellStyles.length; i++) {\n const style = this.cellStyles[i];\n if (style && style.area && style.area.workbookName === workbookName) {\n if (currentIndex === index) {\n this.cellStyles.splice(i, 1);\n return true;\n }\n currentIndex++;\n }\n }\n return false;\n }\n\n /**\n * Get all direct cell styles for a workbook\n */\n getCellStyles(workbookName: string): DirectCellStyle[] {\n return this.cellStyles.filter(\n (style) => style && style.area && style.area.workbookName === workbookName\n );\n }\n\n /**\n * Get all conditional styles across all workbooks (for serialization)\n */\n getAllConditionalStyles(): ConditionalStyle[] {\n return [...this.conditionalStyles];\n }\n\n /**\n * Get all cell styles (for serialization)\n */\n getAllCellStyles(): DirectCellStyle[] {\n return [...this.cellStyles];\n }\n\n /**\n * Reset all styles (for deserialization)\n */\n resetStyles(conditionalStyles?: ConditionalStyle[], cellStyles?: DirectCellStyle[]): void {\n this.conditionalStyles = conditionalStyles ? [...conditionalStyles] : [];\n this.cellStyles = cellStyles ? [...cellStyles] : [];\n }\n\n /**\n * Remove all styles for a workbook\n */\n removeWorkbookStyles(workbookName: string): void {\n this.conditionalStyles = this.conditionalStyles.filter(\n (style) => style.area.workbookName !== workbookName\n );\n this.cellStyles = this.cellStyles.filter(\n (style) => style.area.workbookName !== workbookName\n );\n }\n\n /**\n * Update workbook name in all style references\n */\n updateWorkbookName(oldName: string, newName: string): void {\n // Update conditional styles\n this.conditionalStyles = this.conditionalStyles.map((style) => {\n if (style.area.workbookName === oldName) {\n return {\n ...style,\n area: {\n ...style.area,\n workbookName: newName,\n },\n };\n }\n return style;\n });\n // Update cell styles\n this.cellStyles = this.cellStyles.map((style) => {\n if (style.area.workbookName === oldName) {\n return {\n ...style,\n area: {\n ...style.area,\n workbookName: newName,\n },\n };\n }\n return style;\n });\n }\n\n /**\n * Update sheet name in style references\n */\n updateSheetName(\n workbookName: string,\n oldSheetName: string,\n newSheetName: string\n ): void {\n // Update conditional styles\n this.conditionalStyles = this.conditionalStyles.map((style) => {\n if (\n style.area.workbookName === workbookName &&\n style.area.sheetName === oldSheetName\n ) {\n return {\n ...style,\n area: {\n ...style.area,\n sheetName: newSheetName,\n },\n };\n }\n return style;\n });\n // Update cell styles\n this.cellStyles = this.cellStyles.map((style) => {\n if (\n style.area.workbookName === workbookName &&\n style.area.sheetName === oldSheetName\n ) {\n return {\n ...style,\n area: {\n ...style.area,\n sheetName: newSheetName,\n },\n };\n }\n return style;\n });\n }\n\n /**\n * Remove styles that reference a deleted sheet\n */\n removeSheetStyles(workbookName: string, sheetName: string): void {\n this.conditionalStyles = this.conditionalStyles.filter(\n (style) =>\n !(\n style.area.workbookName === workbookName &&\n style.area.sheetName === sheetName\n )\n );\n this.cellStyles = this.cellStyles.filter(\n (style) =>\n !(\n style.area.workbookName === workbookName &&\n style.area.sheetName === sheetName\n )\n );\n }\n\n /**\n * Get the style for a specific cell\n * Returns the first matching style (first match wins)\n * Checks cellStyles first, then conditionalStyles\n */\n getCellStyle(cellAddress: CellAddress): CellStyle | undefined {\n // First check direct cell styles\n for (const cellStyle of this.cellStyles) {\n if (!cellStyle || !cellStyle.area) {\n continue;\n }\n if (\n cellStyle.area.workbookName === cellAddress.workbookName &&\n cellStyle.area.sheetName === cellAddress.sheetName &&\n isCellInRange(cellAddress, cellStyle.area.range)\n ) {\n return {\n backgroundColor: cellStyle.style.backgroundColor,\n color: cellStyle.style.color,\n };\n }\n }\n\n // Then check conditional styles\n for (const style of this.conditionalStyles) {\n if (!style || !style.area) {\n continue;\n }\n // Check if cell is in the style's area\n if (\n style.area.sheetName !== cellAddress.sheetName ||\n style.area.workbookName !== cellAddress.workbookName\n ) {\n continue;\n }\n\n if (!isCellInRange(cellAddress, style.area.range)) {\n continue;\n }\n\n // Cell is in area, evaluate condition\n if (style.condition.type === \"formula\") {\n const result = this.evaluateFormulaCondition(cellAddress, style);\n if (result) return result;\n } else {\n const result = this.evaluateGradientCondition(cellAddress, style);\n if (result) return result;\n }\n }\n\n return undefined;\n }\n\n /**\n * Evaluate a formula-based style condition\n */\n private evaluateFormulaCondition(\n cellAddress: CellAddress,\n style: ConditionalStyle\n ): CellStyle | undefined {\n if (style.condition.type !== \"formula\") {\n return undefined;\n }\n\n try {\n // Evaluate formula in context of the cell\n // evaluateFormula expects a full cell value (with = prefix for formulas)\n const formula = style.condition.formula.startsWith(\"=\")\n ? style.condition.formula\n : `=${style.condition.formula}`;\n \n const result = this.evaluationManager.evaluateFormula(\n formula,\n cellAddress\n );\n\n // Check if result is truthy\n const isTruthy =\n result === true ||\n result === \"TRUE\" ||\n (typeof result === \"number\" && result !== 0);\n\n if (isTruthy) {\n return {\n backgroundColor: lchToHex(style.condition.color),\n };\n }\n } catch (error) {\n // If formula evaluation fails, don't apply style\n console.warn(\"Failed to evaluate formula condition:\", error);\n }\n\n return undefined;\n }\n\n /**\n * Evaluate a gradient-based style condition\n */\n private evaluateGradientCondition(\n cellAddress: CellAddress,\n style: ConditionalStyle\n ): CellStyle | undefined {\n if (style.condition.type !== \"gradient\") {\n return undefined;\n }\n\n try {\n // Get the cell's evaluation result\n const evalResult = this.evaluationManager.getCellEvaluationResult(cellAddress);\n if (!evalResult || evalResult.type !== \"value\") {\n return undefined;\n }\n if (evalResult.result.type !== \"number\") {\n return undefined;\n }\n const cellValue = evalResult.result.value;\n\n // Calculate min and max values for the gradient\n const { min: minValue, max: maxValue } = this.calculateGradientBounds(\n style,\n cellAddress\n );\n\n if (minValue === null || maxValue === null) {\n return undefined;\n }\n\n // Calculate interpolation factor\n const factor = calculateGradientFactor(cellValue, minValue, maxValue);\n\n // Interpolate between min and max colors\n const minColor = style.condition.min.color;\n const maxColor = style.condition.max.color;\n const interpolatedColor = interpolateLCH(minColor, maxColor, factor);\n\n return {\n backgroundColor: lchToHex(interpolatedColor),\n };\n } catch (error) {\n console.warn(\"Failed to evaluate gradient condition:\", error);\n return undefined;\n }\n }\n\n /**\n * Calculate min and max bounds for a gradient\n */\n private calculateGradientBounds(\n style: ConditionalStyle,\n cellAddress: CellAddress\n ): { min: number | null; max: number | null } {\n if (style.condition.type !== \"gradient\") {\n return { min: null, max: null };\n }\n\n const { min: minConfig, max: maxConfig } = style.condition;\n const topLeftCell: CellAddress = {\n workbookName: style.area.workbookName,\n sheetName: style.area.sheetName,\n colIndex: style.area.range.start.col,\n rowIndex: style.area.range.start.row,\n };\n\n // Calculate min value\n let minValue: number | null = null;\n if (minConfig.type === \"lowest_value\") {\n // Evaluate MIN(range) formula directly\n try {\n const rangeRef = this.getRangeReference(style.area);\n const result = this.evaluationManager.evaluateFormula(\n `=MIN(${rangeRef})`,\n topLeftCell\n );\n if (typeof result === \"number\") {\n minValue = result;\n }\n } catch (error) {\n console.warn(\"Failed to calculate MIN:\", error);\n }\n } else {\n // Evaluate valueFormula in context of area's top-left cell\n const formula = minConfig.valueFormula.startsWith(\"=\")\n ? minConfig.valueFormula\n : `=${minConfig.valueFormula}`;\n const result = this.evaluationManager.evaluateFormula(\n formula,\n topLeftCell\n );\n if (typeof result === \"number\") {\n minValue = result;\n }\n }\n\n // Calculate max value\n let maxValue: number | null = null;\n if (maxConfig.type === \"highest_value\") {\n // Evaluate MAX(range) formula directly\n try {\n const rangeRef = this.getRangeReference(style.area);\n const result = this.evaluationManager.evaluateFormula(\n `=MAX(${rangeRef})`,\n topLeftCell\n );\n if (typeof result === \"number\") {\n maxValue = result;\n }\n } catch (error) {\n console.warn(\"Failed to calculate MAX:\", error);\n }\n } else {\n // Evaluate valueFormula in context of area's top-left cell\n const formula = maxConfig.valueFormula.startsWith(\"=\")\n ? maxConfig.valueFormula\n : `=${maxConfig.valueFormula}`;\n const result = this.evaluationManager.evaluateFormula(\n formula,\n topLeftCell\n );\n if (typeof result === \"number\") {\n maxValue = result;\n }\n }\n\n return { min: minValue, max: maxValue };\n }\n\n /**\n * Get a range reference string from a RangeAddress\n * Follows CANONICAL_RANGES.md format:\n * - Closed: A5:D10\n * - Row-bounded (col-open): A5:10\n * - Col-bounded (row-open): A5:D\n * - Open both: A5:INFINITY\n */\n private getRangeReference(area: RangeAddress): string {\n const colToLetter = (col: number): string => {\n let result = \"\";\n let c = col;\n while (c >= 0) {\n result = String.fromCharCode(65 + (c % 26)) + result;\n c = Math.floor(c / 26) - 1;\n }\n return result;\n };\n\n const startCol = colToLetter(area.range.start.col);\n const startRow = area.range.start.row + 1; // Convert to 1-based\n\n const isColInfinity = area.range.end.col.type === \"infinity\";\n const isRowInfinity = area.range.end.row.type === \"infinity\";\n\n let rangeStr: string;\n\n if (isColInfinity && isRowInfinity) {\n // Open both: A5:INFINITY\n rangeStr = `${startCol}${startRow}:INFINITY`;\n } else if (isColInfinity) {\n // Row-bounded (col-open): A5:10\n if (area.range.end.row.type === \"number\") {\n const endRow = area.range.end.row.value + 1; // Convert to 1-based\n rangeStr = `${startCol}${startRow}:${endRow}`;\n } else {\n rangeStr = `${startCol}${startRow}:INFINITY`;\n }\n } else if (isRowInfinity) {\n // Col-bounded (row-open): A5:D\n if (area.range.end.col.type === \"number\") {\n const endCol = colToLetter(area.range.end.col.value);\n rangeStr = `${startCol}${startRow}:${endCol}`;\n } else {\n rangeStr = `${startCol}${startRow}:INFINITY`;\n }\n } else {\n // Closed rectangle: A5:D10\n if (area.range.end.col.type === \"number\" && area.range.end.row.type === \"number\") {\n const endCol = colToLetter(area.range.end.col.value);\n const endRow = area.range.end.row.value + 1; // Convert to 1-based\n rangeStr = `${startCol}${startRow}:${endCol}${endRow}`;\n } else {\n // Fallback to INFINITY if types don't match\n rangeStr = `${startCol}${startRow}:INFINITY`;\n }\n }\n\n // Quote sheet name if it contains spaces or special characters\n const needsQuotes = /[ '!]/.test(area.sheetName);\n const sheetRef = needsQuotes ? `'${area.sheetName.replace(/'/g, \"''\")}'` : area.sheetName;\n\n // Construct the full reference: [workbook]'sheet'!range\n return `[${area.workbookName}]${sheetRef}!${rangeStr}`;\n }\n}\n\n"
|
|
6
|
+
],
|
|
7
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;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AY,KAAK,MAAM,IAAI,IAAI,SAAS,UAAU;AAAA,QAChF,MAAM,SAAS,YAAY,KAAK,MAAM,IAAI,IAAI,KAAK;AAAA,QACnD,MAAM,SAAS,KAAK,MAAM,IAAI,IAAI,QAAQ;AAAA,QAC1C,WAAW,GAAG,WAAW,YAAY,SAAS;AAAA,MAChD,EAAO;AAAA,QAEL,WAAW,GAAG,WAAW;AAAA;AAAA;AAAA,IAK7B,MAAM,cAAc,QAAQ,KAAK,KAAK,SAAS;AAAA,IAC/C,MAAM,WAAW,cAAc,IAAI,KAAK,UAAU,QAAQ,MAAM,IAAI,OAAO,KAAK;AAAA,IAGhF,OAAO,IAAI,KAAK,gBAAgB,YAAY;AAAA;AAEhD;",
|
|
8
|
+
"debugId": "2984643D5EF61FCB64756E2164756E21",
|
|
9
|
+
"names": []
|
|
10
|
+
}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/core/types.ts"],
|
|
4
4
|
"sourcesContent": [
|
|
5
|
-
"/**\n * Core type definitions for FormulaEngine\n * This file contains all fundamental types used throughout the engine\n */\n\nimport type { EvaluationContext } from \"../evaluator/evaluation-context.cjs\";\nimport type { FormulaEvaluator } from \"../evaluator/formula-evaluator.cjs\";\nimport type { FunctionNode } from \"../parser/ast.cjs\";\nimport type { DependencyNode } from \"./managers/dependency-node.cjs\";\nimport type { LookupOrder } from \"./managers/range-eval-order-builder.cjs\";\n\n// Cell addressing types\nexport interface CellAddress {\n sheetName: string;\n workbookName: string;\n colIndex: number;\n rowIndex: number;\n}\n\nexport interface RangeAddress {\n sheetName: string;\n workbookName: string;\n range: SpreadsheetRange;\n}\n\nexport interface LocalCellAddress {\n colIndex: number;\n rowIndex: number;\n}\n\nexport type ArethmeticEvaluator = (\n left: CellValue,\n right: CellValue,\n context: EvaluationContext\n) => CellValue | ErrorEvaluationResult;\n\nexport type PositiveInfinity = {\n type: \"infinity\";\n sign: \"positive\";\n};\n\nexport type CellInfinity = {\n type: \"infinity\";\n sign: \"positive\" | \"negative\";\n};\n\nexport type CellNumber = {\n type: \"number\";\n value: number;\n};\n\nexport type SpreadsheetRangeEnd = CellNumber | PositiveInfinity;\n\nexport type SpreadsheetRange = {\n start: {\n col: number;\n row: number;\n };\n end: {\n col: SpreadsheetRangeEnd;\n row: SpreadsheetRangeEnd;\n };\n};\n\nexport type RelativeRange = {\n start: {\n col: number;\n row: number;\n };\n width: SpreadsheetRangeEnd;\n height: SpreadsheetRangeEnd;\n};\n\nexport type FiniteSpreadsheetRange = {\n start: {\n col: number;\n row: number;\n };\n end: {\n col: number;\n row: number;\n };\n};\n\nexport type CellString = {\n type: \"string\";\n value: string;\n};\n\nexport type CellBoolean = {\n type: \"boolean\";\n value: boolean;\n};\n\n// Cell value types\nexport type CellValue = CellNumber | CellString | CellBoolean | CellInfinity;\n/**\n * undefined and \"\" are considered empty values\n * undefineds are converted to \"\" in the engine\n *\n * any empty values are deleted from the sheet content\n */\nexport type SerializedCellValue = string | number | boolean | undefined;\n\n// Named expressions\nexport interface NamedExpression {\n name: string;\n expression: string;\n}\n\nexport interface TableDefinition {\n name: string;\n start: {\n rowIndex: number;\n colIndex: number;\n };\n headers: Map<string, { name: string; index: number }>;\n endRow: SpreadsheetRangeEnd;\n sheetName: string;\n workbookName: string;\n}\n\n// Formula errors\nexport enum FormulaError {\n DIV0 = \"#DIV/0!\",\n NA = \"#N/A\",\n NAME = \"#NAME?\",\n NUM = \"#NUM!\",\n REF = \"#REF!\",\n VALUE = \"#VALUE!\",\n CYCLE = \"#CYCLE!\",\n ERROR = \"#ERROR!\",\n SPILL = \"#SPILL!\",\n}\n\n// Sheet structure\nexport interface Sheet {\n name: string;\n index: number; // 0-based index of the sheet\n content: Map<string, SerializedCellValue>;\n}\n\nexport interface Workbook {\n name: string;\n sheets: Map<string, Sheet>;\n}\n\nexport type ValueEvaluationResult = {\n type: \"value\";\n result: CellValue;\n /**\n * If the terminating evaluation result is a reference (see evaluateReference)\n * then we store information about the source cell for context dependent functions like CELL\n */\n sourceCell?: CellAddress;\n};\n\nexport type AwaitingEvaluationResult = {\n type: \"awaiting-evaluation\";\n waitingFor: DependencyNode;\n errAddress: DependencyNode;\n /**\n * If the terminating evaluation result is a reference (see evaluateReference)\n * then we store information about the source cell for context dependent functions like CELL\n */\n sourceCell?: CellAddress;\n};\n\nexport type DoesNotSpillResult = {\n type: \"does-not-spill\";\n};\n\nexport type ErrorEvaluationResult =\n | {\n type: \"error\";\n err: FormulaError;\n errAddress: DependencyNode;\n message: string;\n /**\n * If the terminating evaluation result is a reference (see evaluateReference)\n * then we store information about the source cell for context dependent functions like CELL\n */\n sourceCell?: CellAddress;\n }\n | AwaitingEvaluationResult;\n\nexport type SingleEvaluationResult =\n | ValueEvaluationResult\n | ErrorEvaluationResult;\n\nexport type SpilledValuesEvaluator = (\n spillOffset: { x: number; y: number },\n context: EvaluationContext\n) => SingleEvaluationResult;\n\nexport type SpilledValuesEvaluationResult = {\n type: \"spilled-values\";\n\n /**\n * When a raw range is evaluated, we will add it to the sourceRange so it can be used e.g. for context dependent functions\n */\n sourceRange?: RangeAddress;\n\n /**\n * If the terminating evaluation result is a reference (see evaluateReference)\n * then we store information about the source cell for context dependent functions like CELL\n * sourceCell will only be defined on a spilledValue when a single value is looked up,\n */\n sourceCell?: CellAddress;\n\n spillArea: (origin: CellAddress) => SpreadsheetRange;\n /**\n * for debugging we add a source string to denote where the spilled values were created\n */\n source: string;\n evaluate: SpilledValuesEvaluator;\n /**\n * evaluateAllCells evaluates all non-empty cells in the spilled range.\n * Because a spilled range can be open-ended, we need to have logic for which cells we should evaluate.\n * e.g. when evaluating a range such as D:D only the cells in the current sheet residing in\n * column D should be evaluated and cells producing spilled values that spill onto D:D.\n *\n * In order to evaluate spilled cells in D:D the range evaluateAllCells need to get all cells in the\n * the intersection of the spilled range and D:D, for that reason evaluateAllCells gets an intersection parameter,\n * where the intersection is relative to the origin.\n *\n * #### Producers:\n * In e.g. SEQUENCE and evaluateRange we have logic for which cells in a spilled range we should evaluate,\n *\n * #### Nesting:\n * e.g. evaluation of scalar operators where we want to nest e.g. `5 * right.evaluate()`\n * can be implemented by calling\n * ```ts\n * const vals = child.evaluateAllCells.call(this, options);\n * return vals.map(val => ({ ...val, result: 5 * val.result }));\n * ```\n *\n * #### Consumers:\n * Only functions that need access to all spilled values in a range end up calling evaluateAllCells, e.g.\n * SUM, MIN, MAX, MATCH. Other types of functions like INDEX doesn't need to evaluate all cells in a range,\n * but does a lookup into a spilled range using the evaluate method.\n *\n */\n evaluateAllCells: (\n this: FormulaEvaluator,\n options: {\n /**\n * an intersection relative to the origin\n */\n intersection?: SpreadsheetRange;\n evaluate: SpilledValuesEvaluator;\n context: EvaluationContext;\n /**\n * origin is the cell address that the spilled range is spilled from\n * e.g. in A3=B2:B4 the origin is A3\n */\n origin: CellAddress;\n\n lookupOrder: LookupOrder;\n }\n ) => EvaluateAllCellsResult;\n};\n\nexport type EvaluateAllCellsResult =\n | ErrorEvaluationResult\n | {\n type: \"values\";\n values: CellInRangeResult[];\n };\n\nexport type CellInRangeResult = {\n result: SingleEvaluationResult;\n relativePos: { x: number; y: number };\n};\n\nexport type FunctionEvaluationResult =\n | SingleEvaluationResult\n | SpilledValuesEvaluationResult;\n\nexport type SpilledValue = {\n /**\n * spillOnto is the range that the spilled value is spilled onto\n */\n spillOnto: SpreadsheetRange;\n /**\n * origin is the cell address that the spilled value is spilled from\n */\n origin: CellAddress;\n};\n\n/**\n * Function definition\n */\nexport interface FunctionDefinition {\n name: string;\n evaluate: (\n this: FormulaEvaluator,\n node: FunctionNode,\n context: EvaluationContext\n ) => FunctionEvaluationResult;\n aliases?: string[];\n}\n\n/**\n * Evaluation result\n */\nexport type EvaluationResult = {\n dependencies: Set<string>;\n} & FunctionEvaluationResult;\n\nexport type SCC = {\n id: number;\n nodes: Set<DependencyNode>; // All nodes considering soft + hard edges\n evaluationOrder: DependencyNode[]; // Flat topologically ordered list\n resolved: boolean;\n hardEdgeSCCs: Set<DependencyNode>[]; // SCCs formed by only hard edges (regular dependencies)\n};\n\nexport type SCCDAG = {\n sccList: SCC[];\n sccGraph: Map<number, Set<number>>; // Adjacency list of SCC dependencies\n};\n\nexport type EvaluationOrder = {\n evaluationOrder: Set<DependencyNode>;\n hasCycle: boolean;\n cycleNodes?: Set<DependencyNode>;\n hash: string;\n sccDAG?: SCCDAG;\n};\n"
|
|
5
|
+
"/**\n * Core type definitions for FormulaEngine\n * This file contains all fundamental types used throughout the engine\n */\n\nimport type { EvaluationContext } from \"../evaluator/evaluation-context.cjs\";\nimport type { FormulaEvaluator } from \"../evaluator/formula-evaluator.cjs\";\nimport type { FunctionNode } from \"../parser/ast.cjs\";\nimport type { DependencyNode } from \"./managers/dependency-node.cjs\";\nimport type { LookupOrder } from \"./managers/range-eval-order-builder.cjs\";\n\n// Cell addressing types\nexport interface CellAddress {\n sheetName: string;\n workbookName: string;\n colIndex: number;\n rowIndex: number;\n}\n\nexport interface RangeAddress {\n sheetName: string;\n workbookName: string;\n range: SpreadsheetRange;\n}\n\nexport interface LocalCellAddress {\n colIndex: number;\n rowIndex: number;\n}\n\nexport type ArethmeticEvaluator = (\n left: CellValue,\n right: CellValue,\n context: EvaluationContext\n) => CellValue | ErrorEvaluationResult;\n\nexport type PositiveInfinity = {\n type: \"infinity\";\n sign: \"positive\";\n};\n\nexport type CellInfinity = {\n type: \"infinity\";\n sign: \"positive\" | \"negative\";\n};\n\nexport type CellNumber = {\n type: \"number\";\n value: number;\n};\n\nexport type SpreadsheetRangeEnd = CellNumber | PositiveInfinity;\n\nexport type SpreadsheetRange = {\n start: {\n col: number;\n row: number;\n };\n end: {\n col: SpreadsheetRangeEnd;\n row: SpreadsheetRangeEnd;\n };\n};\n\nexport type RelativeRange = {\n start: {\n col: number;\n row: number;\n };\n width: SpreadsheetRangeEnd;\n height: SpreadsheetRangeEnd;\n};\n\nexport type FiniteSpreadsheetRange = {\n start: {\n col: number;\n row: number;\n };\n end: {\n col: number;\n row: number;\n };\n};\n\nexport type CellString = {\n type: \"string\";\n value: string;\n};\n\nexport type CellBoolean = {\n type: \"boolean\";\n value: boolean;\n};\n\n// Cell value types\nexport type CellValue = CellNumber | CellString | CellBoolean | CellInfinity;\n/**\n * undefined and \"\" are considered empty values\n * undefineds are converted to \"\" in the engine\n *\n * any empty values are deleted from the sheet content\n */\nexport type SerializedCellValue = string | number | boolean | undefined;\n\n// Named expressions\nexport interface NamedExpression {\n name: string;\n expression: string;\n}\n\nexport interface TableDefinition {\n name: string;\n start: {\n rowIndex: number;\n colIndex: number;\n };\n headers: Map<string, { name: string; index: number }>;\n endRow: SpreadsheetRangeEnd;\n sheetName: string;\n workbookName: string;\n}\n\n// Formula errors\nexport enum FormulaError {\n DIV0 = \"#DIV/0!\",\n NA = \"#N/A\",\n NAME = \"#NAME?\",\n NUM = \"#NUM!\",\n REF = \"#REF!\",\n VALUE = \"#VALUE!\",\n CYCLE = \"#CYCLE!\",\n ERROR = \"#ERROR!\",\n SPILL = \"#SPILL!\",\n}\n\n// Sheet structure\nexport interface Sheet {\n name: string;\n index: number; // 0-based index of the sheet\n content: Map<string, SerializedCellValue>;\n}\n\nexport interface Workbook {\n name: string;\n sheets: Map<string, Sheet>;\n}\n\nexport type ValueEvaluationResult = {\n type: \"value\";\n result: CellValue;\n /**\n * If the terminating evaluation result is a reference (see evaluateReference)\n * then we store information about the source cell for context dependent functions like CELL\n */\n sourceCell?: CellAddress;\n};\n\nexport type AwaitingEvaluationResult = {\n type: \"awaiting-evaluation\";\n waitingFor: DependencyNode;\n errAddress: DependencyNode;\n /**\n * If the terminating evaluation result is a reference (see evaluateReference)\n * then we store information about the source cell for context dependent functions like CELL\n */\n sourceCell?: CellAddress;\n};\n\nexport type DoesNotSpillResult = {\n type: \"does-not-spill\";\n};\n\nexport type ErrorEvaluationResult =\n | {\n type: \"error\";\n err: FormulaError;\n errAddress: DependencyNode;\n message: string;\n /**\n * If the terminating evaluation result is a reference (see evaluateReference)\n * then we store information about the source cell for context dependent functions like CELL\n */\n sourceCell?: CellAddress;\n }\n | AwaitingEvaluationResult;\n\nexport type SingleEvaluationResult =\n | ValueEvaluationResult\n | ErrorEvaluationResult;\n\nexport type SpilledValuesEvaluator = (\n spillOffset: { x: number; y: number },\n context: EvaluationContext\n) => SingleEvaluationResult;\n\nexport type SpilledValuesEvaluationResult = {\n type: \"spilled-values\";\n\n /**\n * When a raw range is evaluated, we will add it to the sourceRange so it can be used e.g. for context dependent functions\n */\n sourceRange?: RangeAddress;\n\n /**\n * If the terminating evaluation result is a reference (see evaluateReference)\n * then we store information about the source cell for context dependent functions like CELL\n * sourceCell will only be defined on a spilledValue when a single value is looked up,\n */\n sourceCell?: CellAddress;\n\n spillArea: (origin: CellAddress) => SpreadsheetRange;\n /**\n * for debugging we add a source string to denote where the spilled values were created\n */\n source: string;\n evaluate: SpilledValuesEvaluator;\n /**\n * evaluateAllCells evaluates all non-empty cells in the spilled range.\n * Because a spilled range can be open-ended, we need to have logic for which cells we should evaluate.\n * e.g. when evaluating a range such as D:D only the cells in the current sheet residing in\n * column D should be evaluated and cells producing spilled values that spill onto D:D.\n *\n * In order to evaluate spilled cells in D:D the range evaluateAllCells need to get all cells in the\n * the intersection of the spilled range and D:D, for that reason evaluateAllCells gets an intersection parameter,\n * where the intersection is relative to the origin.\n *\n * #### Producers:\n * In e.g. SEQUENCE and evaluateRange we have logic for which cells in a spilled range we should evaluate,\n *\n * #### Nesting:\n * e.g. evaluation of scalar operators where we want to nest e.g. `5 * right.evaluate()`\n * can be implemented by calling\n * ```ts\n * const vals = child.evaluateAllCells.call(this, options);\n * return vals.map(val => ({ ...val, result: 5 * val.result }));\n * ```\n *\n * #### Consumers:\n * Only functions that need access to all spilled values in a range end up calling evaluateAllCells, e.g.\n * SUM, MIN, MAX, MATCH. Other types of functions like INDEX doesn't need to evaluate all cells in a range,\n * but does a lookup into a spilled range using the evaluate method.\n *\n */\n evaluateAllCells: (\n this: FormulaEvaluator,\n options: {\n /**\n * an intersection relative to the origin\n */\n intersection?: SpreadsheetRange;\n evaluate: SpilledValuesEvaluator;\n context: EvaluationContext;\n /**\n * origin is the cell address that the spilled range is spilled from\n * e.g. in A3=B2:B4 the origin is A3\n */\n origin: CellAddress;\n\n lookupOrder: LookupOrder;\n }\n ) => EvaluateAllCellsResult;\n};\n\nexport type EvaluateAllCellsResult =\n | ErrorEvaluationResult\n | {\n type: \"values\";\n values: CellInRangeResult[];\n };\n\nexport type CellInRangeResult = {\n result: SingleEvaluationResult;\n relativePos: { x: number; y: number };\n};\n\nexport type FunctionEvaluationResult =\n | SingleEvaluationResult\n | SpilledValuesEvaluationResult;\n\nexport type SpilledValue = {\n /**\n * spillOnto is the range that the spilled value is spilled onto\n */\n spillOnto: SpreadsheetRange;\n /**\n * origin is the cell address that the spilled value is spilled from\n */\n origin: CellAddress;\n};\n\n/**\n * Function definition\n */\nexport interface FunctionDefinition {\n name: string;\n evaluate: (\n this: FormulaEvaluator,\n node: FunctionNode,\n context: EvaluationContext\n ) => FunctionEvaluationResult;\n aliases?: string[];\n}\n\n/**\n * Evaluation result\n */\nexport type EvaluationResult = {\n dependencies: Set<string>;\n} & FunctionEvaluationResult;\n\nexport type SCC = {\n id: number;\n nodes: Set<DependencyNode>; // All nodes considering soft + hard edges\n evaluationOrder: DependencyNode[]; // Flat topologically ordered list\n resolved: boolean;\n hardEdgeSCCs: Set<DependencyNode>[]; // SCCs formed by only hard edges (regular dependencies)\n};\n\nexport type SCCDAG = {\n sccList: SCC[];\n sccGraph: Map<number, Set<number>>; // Adjacency list of SCC dependencies\n};\n\nexport type EvaluationOrder = {\n evaluationOrder: Set<DependencyNode>;\n hasCycle: boolean;\n cycleNodes?: Set<DependencyNode>;\n hash: string;\n sccDAG?: SCCDAG;\n};\n\n// Conditional Styling types\nexport interface LCHColor {\n l: number; // Lightness: 0-100\n c: number; // Chroma: 0-150+\n h: number; // Hue: 0-360\n}\n\nexport interface FormulaStyleCondition {\n type: \"formula\";\n formula: string;\n color: LCHColor;\n}\n\nexport interface GradientStyleCondition {\n type: \"gradient\";\n min:\n | { type: \"lowest_value\"; color: LCHColor }\n | { type: \"number\"; color: LCHColor; valueFormula: string };\n max:\n | { type: \"highest_value\"; color: LCHColor }\n | { type: \"number\"; color: LCHColor; valueFormula: string };\n}\n\nexport type StyleCondition = FormulaStyleCondition | GradientStyleCondition;\n\nexport interface ConditionalStyle {\n area: RangeAddress;\n condition: StyleCondition;\n}\n\nexport interface DirectCellStyle {\n area: RangeAddress;\n style: CellStyle\n}\n\nexport interface CellStyle {\n backgroundColor?: string; // Hex color format\n color?: string; // Text color in hex format\n}\n"
|
|
6
6
|
],
|
|
7
7
|
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2HO,IAAK;AAAA,CAAL,CAAK,kBAAL;AAAA,EACL,wBAAO;AAAA,EACP,sBAAK;AAAA,EACL,wBAAO;AAAA,EACP,uBAAM;AAAA,EACN,uBAAM;AAAA,EACN,yBAAQ;AAAA,EACR,yBAAQ;AAAA,EACR,yBAAQ;AAAA,EACR,yBAAQ;AAAA,GATE;",
|
|
8
8
|
"debugId": "F54C7C141D21E24164756E2164756E21",
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __moduleCache = /* @__PURE__ */ new WeakMap;
|
|
6
|
+
var __toCommonJS = (from) => {
|
|
7
|
+
var entry = __moduleCache.get(from), desc;
|
|
8
|
+
if (entry)
|
|
9
|
+
return entry;
|
|
10
|
+
entry = __defProp({}, "__esModule", { value: true });
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function")
|
|
12
|
+
__getOwnPropNames(from).map((key) => !__hasOwnProp.call(entry, key) && __defProp(entry, key, {
|
|
13
|
+
get: () => from[key],
|
|
14
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
15
|
+
}));
|
|
16
|
+
__moduleCache.set(from, entry);
|
|
17
|
+
return entry;
|
|
18
|
+
};
|
|
19
|
+
var __export = (target, all) => {
|
|
20
|
+
for (var name in all)
|
|
21
|
+
__defProp(target, name, {
|
|
22
|
+
get: all[name],
|
|
23
|
+
enumerable: true,
|
|
24
|
+
configurable: true,
|
|
25
|
+
set: (newValue) => all[name] = () => newValue
|
|
26
|
+
});
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
// src/core/utils/color-utils.ts
|
|
30
|
+
var exports_color_utils = {};
|
|
31
|
+
__export(exports_color_utils, {
|
|
32
|
+
lchToHex: () => lchToHex,
|
|
33
|
+
interpolateLCH: () => interpolateLCH,
|
|
34
|
+
hexToLch: () => hexToLch,
|
|
35
|
+
calculateGradientFactor: () => calculateGradientFactor
|
|
36
|
+
});
|
|
37
|
+
module.exports = __toCommonJS(exports_color_utils);
|
|
38
|
+
function lchToHex(color) {
|
|
39
|
+
const { l, c, h } = color;
|
|
40
|
+
const hRad = h * Math.PI / 180;
|
|
41
|
+
const a = c * Math.cos(hRad);
|
|
42
|
+
const b = c * Math.sin(hRad);
|
|
43
|
+
let y = (l + 16) / 116;
|
|
44
|
+
let x = a / 500 + y;
|
|
45
|
+
let z = y - b / 200;
|
|
46
|
+
const delta = 6 / 29;
|
|
47
|
+
const deltaCubed = delta * delta * delta;
|
|
48
|
+
x = x > delta ? x * x * x : 3 * delta * delta * (x - 4 / 29);
|
|
49
|
+
y = y > delta ? y * y * y : 3 * delta * delta * (y - 4 / 29);
|
|
50
|
+
z = z > delta ? z * z * z : 3 * delta * delta * (z - 4 / 29);
|
|
51
|
+
x *= 0.95047;
|
|
52
|
+
y *= 1;
|
|
53
|
+
z *= 1.08883;
|
|
54
|
+
let r = x * 3.2406 + y * -1.5372 + z * -0.4986;
|
|
55
|
+
let g = x * -0.9689 + y * 1.8758 + z * 0.0415;
|
|
56
|
+
let bVal = x * 0.0557 + y * -0.204 + z * 1.057;
|
|
57
|
+
const gammaCorrect = (val) => {
|
|
58
|
+
return val > 0.0031308 ? 1.055 * Math.pow(val, 1 / 2.4) - 0.055 : 12.92 * val;
|
|
59
|
+
};
|
|
60
|
+
r = gammaCorrect(r);
|
|
61
|
+
g = gammaCorrect(g);
|
|
62
|
+
bVal = gammaCorrect(bVal);
|
|
63
|
+
r = Math.max(0, Math.min(1, r)) * 255;
|
|
64
|
+
g = Math.max(0, Math.min(1, g)) * 255;
|
|
65
|
+
bVal = Math.max(0, Math.min(1, bVal)) * 255;
|
|
66
|
+
const toHex = (n) => {
|
|
67
|
+
const hex = Math.round(n).toString(16);
|
|
68
|
+
return hex.length === 1 ? "0" + hex : hex;
|
|
69
|
+
};
|
|
70
|
+
return `#${toHex(r)}${toHex(g)}${toHex(bVal)}`;
|
|
71
|
+
}
|
|
72
|
+
function hexToLch(hex) {
|
|
73
|
+
const normalizedHex = hex.startsWith("#") ? hex.slice(1) : hex;
|
|
74
|
+
const r = parseInt(normalizedHex.slice(0, 2), 16) / 255;
|
|
75
|
+
const g = parseInt(normalizedHex.slice(2, 4), 16) / 255;
|
|
76
|
+
const b = parseInt(normalizedHex.slice(4, 6), 16) / 255;
|
|
77
|
+
const inverseGamma = (val) => {
|
|
78
|
+
return val > 0.04045 ? Math.pow((val + 0.055) / 1.055, 2.4) : val / 12.92;
|
|
79
|
+
};
|
|
80
|
+
let rLinear = inverseGamma(r);
|
|
81
|
+
let gLinear = inverseGamma(g);
|
|
82
|
+
let bLinear = inverseGamma(b);
|
|
83
|
+
let x = rLinear * 0.4124564 + gLinear * 0.3575761 + bLinear * 0.1804375;
|
|
84
|
+
let y = rLinear * 0.2126729 + gLinear * 0.7151522 + bLinear * 0.072175;
|
|
85
|
+
let z = rLinear * 0.0193339 + gLinear * 0.119192 + bLinear * 0.9503041;
|
|
86
|
+
x /= 0.95047;
|
|
87
|
+
y /= 1;
|
|
88
|
+
z /= 1.08883;
|
|
89
|
+
const f = (t) => {
|
|
90
|
+
const delta = 6 / 29;
|
|
91
|
+
if (t > delta * delta * delta) {
|
|
92
|
+
return Math.cbrt(t);
|
|
93
|
+
}
|
|
94
|
+
return t / (3 * delta * delta) + 4 / 29;
|
|
95
|
+
};
|
|
96
|
+
const fx = f(x);
|
|
97
|
+
const fy = f(y);
|
|
98
|
+
const fz = f(z);
|
|
99
|
+
const l = 116 * fy - 16;
|
|
100
|
+
const a = 500 * (fx - fy);
|
|
101
|
+
const bLab = 200 * (fy - fz);
|
|
102
|
+
const c = Math.sqrt(a * a + bLab * bLab);
|
|
103
|
+
let h = Math.atan2(bLab, a) * (180 / Math.PI);
|
|
104
|
+
if (h < 0) {
|
|
105
|
+
h += 360;
|
|
106
|
+
}
|
|
107
|
+
return {
|
|
108
|
+
l: Math.max(0, Math.min(100, l)),
|
|
109
|
+
c: Math.max(0, c),
|
|
110
|
+
h
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
function interpolateLCH(color1, color2, t) {
|
|
114
|
+
t = Math.max(0, Math.min(1, t));
|
|
115
|
+
const l = color1.l + (color2.l - color1.l) * t;
|
|
116
|
+
const c = color1.c + (color2.c - color1.c) * t;
|
|
117
|
+
let h1 = color1.h;
|
|
118
|
+
let h2 = color2.h;
|
|
119
|
+
const diff = h2 - h1;
|
|
120
|
+
if (diff > 180) {
|
|
121
|
+
h1 += 360;
|
|
122
|
+
} else if (diff < -180) {
|
|
123
|
+
h2 += 360;
|
|
124
|
+
}
|
|
125
|
+
let h = h1 + (h2 - h1) * t;
|
|
126
|
+
h = (h % 360 + 360) % 360;
|
|
127
|
+
return { l, c, h };
|
|
128
|
+
}
|
|
129
|
+
function calculateGradientFactor(value, min, max) {
|
|
130
|
+
if (max === min) {
|
|
131
|
+
return 0.5;
|
|
132
|
+
}
|
|
133
|
+
const factor = (value - min) / (max - min);
|
|
134
|
+
return Math.max(0, Math.min(1, factor));
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
//# debugId=D8283E7787ACB0EE64756E2164756E21
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../src/core/utils/color-utils.ts"],
|
|
4
|
+
"sourcesContent": [
|
|
5
|
+
"/**\n * Color utilities for conditional styling\n * Handles LCH color space conversions and interpolation\n */\n\nimport type { LCHColor } from \"../types.cjs\";\n\n/**\n * Convert LCH color to hex string\n * LCH uses the CIELCH color space which provides perceptually uniform colors\n */\nexport function lchToHex(color: LCHColor): string {\n // First convert LCH to LAB\n const { l, c, h } = color;\n const hRad = (h * Math.PI) / 180;\n const a = c * Math.cos(hRad);\n const b = c * Math.sin(hRad);\n\n // Then convert LAB to XYZ (using D65 illuminant)\n let y = (l + 16) / 116;\n let x = a / 500 + y;\n let z = y - b / 200;\n\n // Apply inverse f function\n const delta = 6 / 29;\n const deltaCubed = delta * delta * delta;\n \n x = x > delta ? x * x * x : 3 * delta * delta * (x - 4 / 29);\n y = y > delta ? y * y * y : 3 * delta * delta * (y - 4 / 29);\n z = z > delta ? z * z * z : 3 * delta * delta * (z - 4 / 29);\n\n // Scale by D65 white point\n x *= 0.95047;\n y *= 1.0;\n z *= 1.08883;\n\n // Convert XYZ to RGB\n let r = x * 3.2406 + y * -1.5372 + z * -0.4986;\n let g = x * -0.9689 + y * 1.8758 + z * 0.0415;\n let bVal = x * 0.0557 + y * -0.204 + z * 1.057;\n\n // Apply gamma correction\n const gammaCorrect = (val: number) => {\n return val > 0.0031308\n ? 1.055 * Math.pow(val, 1 / 2.4) - 0.055\n : 12.92 * val;\n };\n\n r = gammaCorrect(r);\n g = gammaCorrect(g);\n bVal = gammaCorrect(bVal);\n\n // Clamp to [0, 1] and convert to 0-255\n r = Math.max(0, Math.min(1, r)) * 255;\n g = Math.max(0, Math.min(1, g)) * 255;\n bVal = Math.max(0, Math.min(1, bVal)) * 255;\n\n // Convert to hex\n const toHex = (n: number) => {\n const hex = Math.round(n).toString(16);\n return hex.length === 1 ? \"0\" + hex : hex;\n };\n\n return `#${toHex(r)}${toHex(g)}${toHex(bVal)}`;\n}\n\n/**\n * Convert hex color string to LCH color\n * @param hex Hex color string (e.g., \"#FF0000\" or \"FF0000\")\n * @returns LCH color\n */\nexport function hexToLch(hex: string): LCHColor {\n // Remove # if present and normalize\n const normalizedHex = hex.startsWith(\"#\") ? hex.slice(1) : hex;\n \n // Parse RGB values\n const r = parseInt(normalizedHex.slice(0, 2), 16) / 255;\n const g = parseInt(normalizedHex.slice(2, 4), 16) / 255;\n const b = parseInt(normalizedHex.slice(4, 6), 16) / 255;\n\n // Apply inverse gamma correction\n const inverseGamma = (val: number) => {\n return val > 0.04045\n ? Math.pow((val + 0.055) / 1.055, 2.4)\n : val / 12.92;\n };\n\n let rLinear = inverseGamma(r);\n let gLinear = inverseGamma(g);\n let bLinear = inverseGamma(b);\n\n // Convert RGB to XYZ (using sRGB matrix)\n let x = rLinear * 0.4124564 + gLinear * 0.3575761 + bLinear * 0.1804375;\n let y = rLinear * 0.2126729 + gLinear * 0.7151522 + bLinear * 0.0721750;\n let z = rLinear * 0.0193339 + gLinear * 0.1191920 + bLinear * 0.9503041;\n\n // Normalize by D65 white point\n x /= 0.95047;\n y /= 1.0;\n z /= 1.08883;\n\n // Convert XYZ to LAB\n const f = (t: number) => {\n const delta = 6 / 29;\n if (t > delta * delta * delta) {\n return Math.cbrt(t);\n }\n return t / (3 * delta * delta) + 4 / 29;\n };\n\n const fx = f(x);\n const fy = f(y);\n const fz = f(z);\n\n const l = 116 * fy - 16;\n const a = 500 * (fx - fy);\n const bLab = 200 * (fy - fz);\n\n // Convert LAB to LCH\n const c = Math.sqrt(a * a + bLab * bLab);\n let h = Math.atan2(bLab, a) * (180 / Math.PI);\n \n // Normalize hue to [0, 360)\n if (h < 0) {\n h += 360;\n }\n\n return {\n l: Math.max(0, Math.min(100, l)),\n c: Math.max(0, c),\n h: h,\n };\n}\n\n/**\n * Interpolate between two LCH colors\n * @param color1 Starting color\n * @param color2 Ending color\n * @param t Interpolation factor (0-1)\n * @returns Interpolated LCH color\n */\nexport function interpolateLCH(\n color1: LCHColor,\n color2: LCHColor,\n t: number\n): LCHColor {\n // Clamp t to [0, 1]\n t = Math.max(0, Math.min(1, t));\n\n // Interpolate lightness and chroma linearly\n const l = color1.l + (color2.l - color1.l) * t;\n const c = color1.c + (color2.c - color1.c) * t;\n\n // Interpolate hue taking the shortest path around the circle\n let h1 = color1.h;\n let h2 = color2.h;\n\n // Find shortest path\n const diff = h2 - h1;\n if (diff > 180) {\n h1 += 360;\n } else if (diff < -180) {\n h2 += 360;\n }\n\n let h = h1 + (h2 - h1) * t;\n\n // Normalize hue to [0, 360)\n h = ((h % 360) + 360) % 360;\n\n return { l, c, h };\n}\n\n/**\n * Calculate interpolation factor for a value within a range\n * @param value Current value\n * @param min Minimum value\n * @param max Maximum value\n * @returns Factor between 0 and 1\n */\nexport function calculateGradientFactor(\n value: number,\n min: number,\n max: number\n): number {\n // Handle edge cases\n if (max === min) {\n return 0.5; // If min equals max, return middle value\n }\n\n // Calculate factor and clamp to [0, 1]\n const factor = (value - min) / (max - min);\n return Math.max(0, Math.min(1, factor));\n}\n\n"
|
|
6
|
+
],
|
|
7
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAWO,SAAS,QAAQ,CAAC,OAAyB;AAAA,EAEhD,QAAQ,GAAG,GAAG,MAAM;AAAA,EACpB,MAAM,OAAQ,IAAI,KAAK,KAAM;AAAA,EAC7B,MAAM,IAAI,IAAI,KAAK,IAAI,IAAI;AAAA,EAC3B,MAAM,IAAI,IAAI,KAAK,IAAI,IAAI;AAAA,EAG3B,IAAI,KAAK,IAAI,MAAM;AAAA,EACnB,IAAI,IAAI,IAAI,MAAM;AAAA,EAClB,IAAI,IAAI,IAAI,IAAI;AAAA,EAGhB,MAAM,QAAQ,IAAI;AAAA,EAClB,MAAM,aAAa,QAAQ,QAAQ;AAAA,EAEnC,IAAI,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