@ricsam/formula-engine 0.0.4 → 0.0.6
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/evaluator/formula-evaluator.cjs +3 -3
- package/dist/cjs/evaluator/formula-evaluator.cjs.map +3 -3
- package/dist/cjs/functions/{index.cjs → function-registry.cjs} +5 -5
- package/dist/cjs/functions/{index.cjs.map → function-registry.cjs.map} +2 -2
- 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/evaluator/formula-evaluator.mjs +2 -2
- package/dist/mjs/evaluator/formula-evaluator.mjs.map +2 -2
- package/dist/mjs/functions/{index.mjs → function-registry.mjs} +2 -2
- package/dist/mjs/functions/{index.mjs.map → function-registry.mjs.map} +2 -2
- 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/package.json +1 -1
- /package/dist/types/functions/{index.d.ts → function-registry.d.ts} +0 -0
|
@@ -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.mjs\";\nimport type { WorkbookManager } from \"./workbook-manager.mjs\";\nimport type { EvaluationManager } from \"./evaluation-manager.mjs\";\nimport { isCellInRange } from \"../utils.mjs\";\nimport {\n calculateGradientFactor,\n interpolateLCH,\n lchToHex,\n} from \"../utils/color-utils.mjs\";\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": ";AAcA;AACA;AAAA;AAAA;AAAA;AAAA;AAAA;AAMO,MAAM,aAAa;AAAA,EAKd;AAAA,EACA;AAAA,EALF,oBAAwC,CAAC;AAAA,EACzC,aAAgC,CAAC;AAAA,EAEzC,WAAW,CACD,iBACA,mBACR;AAAA,IAFQ;AAAA,IACA;AAAA;AAAA,EAMV,mBAAmB,CAAC,OAA+B;AAAA,IACjD,KAAK,kBAAkB,KAAK,KAAK;AAAA;AAAA,EAMnC,sBAAsB,CAAC,cAAsB,OAAwB;AAAA,IACnE,MAAM,iBAAiB,KAAK,kBAAkB,OAC5C,CAAC,UAAU,MAAM,KAAK,iBAAiB,YACzC;AAAA,IACA,IAAI,QAAQ,KAAK,SAAS,eAAe,QAAQ;AAAA,MAC/C,OAAO;AAAA,IACT;AAAA,IAEA,IAAI,eAAe;AAAA,IACnB,SAAS,IAAI,EAAG,IAAI,KAAK,kBAAkB,QAAQ,KAAK;AAAA,MACtD,MAAM,QAAQ,KAAK,k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|
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.mjs\";\nimport type { FormulaEvaluator } from \"../evaluator/formula-evaluator.mjs\";\nimport type { FunctionNode } from \"../parser/ast.mjs\";\nimport type { DependencyNode } from \"./managers/dependency-node.mjs\";\nimport type { LookupOrder } from \"./managers/range-eval-order-builder.mjs\";\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.mjs\";\nimport type { FormulaEvaluator } from \"../evaluator/formula-evaluator.mjs\";\nimport type { FunctionNode } from \"../parser/ast.mjs\";\nimport type { DependencyNode } from \"./managers/dependency-node.mjs\";\nimport type { LookupOrder } from \"./managers/range-eval-order-builder.mjs\";\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": "0E7C5AF634572D3964756E2164756E21",
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
// src/core/utils/color-utils.ts
|
|
2
|
+
function lchToHex(color) {
|
|
3
|
+
const { l, c, h } = color;
|
|
4
|
+
const hRad = h * Math.PI / 180;
|
|
5
|
+
const a = c * Math.cos(hRad);
|
|
6
|
+
const b = c * Math.sin(hRad);
|
|
7
|
+
let y = (l + 16) / 116;
|
|
8
|
+
let x = a / 500 + y;
|
|
9
|
+
let z = y - b / 200;
|
|
10
|
+
const delta = 6 / 29;
|
|
11
|
+
const deltaCubed = delta * delta * delta;
|
|
12
|
+
x = x > delta ? x * x * x : 3 * delta * delta * (x - 4 / 29);
|
|
13
|
+
y = y > delta ? y * y * y : 3 * delta * delta * (y - 4 / 29);
|
|
14
|
+
z = z > delta ? z * z * z : 3 * delta * delta * (z - 4 / 29);
|
|
15
|
+
x *= 0.95047;
|
|
16
|
+
y *= 1;
|
|
17
|
+
z *= 1.08883;
|
|
18
|
+
let r = x * 3.2406 + y * -1.5372 + z * -0.4986;
|
|
19
|
+
let g = x * -0.9689 + y * 1.8758 + z * 0.0415;
|
|
20
|
+
let bVal = x * 0.0557 + y * -0.204 + z * 1.057;
|
|
21
|
+
const gammaCorrect = (val) => {
|
|
22
|
+
return val > 0.0031308 ? 1.055 * Math.pow(val, 1 / 2.4) - 0.055 : 12.92 * val;
|
|
23
|
+
};
|
|
24
|
+
r = gammaCorrect(r);
|
|
25
|
+
g = gammaCorrect(g);
|
|
26
|
+
bVal = gammaCorrect(bVal);
|
|
27
|
+
r = Math.max(0, Math.min(1, r)) * 255;
|
|
28
|
+
g = Math.max(0, Math.min(1, g)) * 255;
|
|
29
|
+
bVal = Math.max(0, Math.min(1, bVal)) * 255;
|
|
30
|
+
const toHex = (n) => {
|
|
31
|
+
const hex = Math.round(n).toString(16);
|
|
32
|
+
return hex.length === 1 ? "0" + hex : hex;
|
|
33
|
+
};
|
|
34
|
+
return `#${toHex(r)}${toHex(g)}${toHex(bVal)}`;
|
|
35
|
+
}
|
|
36
|
+
function hexToLch(hex) {
|
|
37
|
+
const normalizedHex = hex.startsWith("#") ? hex.slice(1) : hex;
|
|
38
|
+
const r = parseInt(normalizedHex.slice(0, 2), 16) / 255;
|
|
39
|
+
const g = parseInt(normalizedHex.slice(2, 4), 16) / 255;
|
|
40
|
+
const b = parseInt(normalizedHex.slice(4, 6), 16) / 255;
|
|
41
|
+
const inverseGamma = (val) => {
|
|
42
|
+
return val > 0.04045 ? Math.pow((val + 0.055) / 1.055, 2.4) : val / 12.92;
|
|
43
|
+
};
|
|
44
|
+
let rLinear = inverseGamma(r);
|
|
45
|
+
let gLinear = inverseGamma(g);
|
|
46
|
+
let bLinear = inverseGamma(b);
|
|
47
|
+
let x = rLinear * 0.4124564 + gLinear * 0.3575761 + bLinear * 0.1804375;
|
|
48
|
+
let y = rLinear * 0.2126729 + gLinear * 0.7151522 + bLinear * 0.072175;
|
|
49
|
+
let z = rLinear * 0.0193339 + gLinear * 0.119192 + bLinear * 0.9503041;
|
|
50
|
+
x /= 0.95047;
|
|
51
|
+
y /= 1;
|
|
52
|
+
z /= 1.08883;
|
|
53
|
+
const f = (t) => {
|
|
54
|
+
const delta = 6 / 29;
|
|
55
|
+
if (t > delta * delta * delta) {
|
|
56
|
+
return Math.cbrt(t);
|
|
57
|
+
}
|
|
58
|
+
return t / (3 * delta * delta) + 4 / 29;
|
|
59
|
+
};
|
|
60
|
+
const fx = f(x);
|
|
61
|
+
const fy = f(y);
|
|
62
|
+
const fz = f(z);
|
|
63
|
+
const l = 116 * fy - 16;
|
|
64
|
+
const a = 500 * (fx - fy);
|
|
65
|
+
const bLab = 200 * (fy - fz);
|
|
66
|
+
const c = Math.sqrt(a * a + bLab * bLab);
|
|
67
|
+
let h = Math.atan2(bLab, a) * (180 / Math.PI);
|
|
68
|
+
if (h < 0) {
|
|
69
|
+
h += 360;
|
|
70
|
+
}
|
|
71
|
+
return {
|
|
72
|
+
l: Math.max(0, Math.min(100, l)),
|
|
73
|
+
c: Math.max(0, c),
|
|
74
|
+
h
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
function interpolateLCH(color1, color2, t) {
|
|
78
|
+
t = Math.max(0, Math.min(1, t));
|
|
79
|
+
const l = color1.l + (color2.l - color1.l) * t;
|
|
80
|
+
const c = color1.c + (color2.c - color1.c) * t;
|
|
81
|
+
let h1 = color1.h;
|
|
82
|
+
let h2 = color2.h;
|
|
83
|
+
const diff = h2 - h1;
|
|
84
|
+
if (diff > 180) {
|
|
85
|
+
h1 += 360;
|
|
86
|
+
} else if (diff < -180) {
|
|
87
|
+
h2 += 360;
|
|
88
|
+
}
|
|
89
|
+
let h = h1 + (h2 - h1) * t;
|
|
90
|
+
h = (h % 360 + 360) % 360;
|
|
91
|
+
return { l, c, h };
|
|
92
|
+
}
|
|
93
|
+
function calculateGradientFactor(value, min, max) {
|
|
94
|
+
if (max === min) {
|
|
95
|
+
return 0.5;
|
|
96
|
+
}
|
|
97
|
+
const factor = (value - min) / (max - min);
|
|
98
|
+
return Math.max(0, Math.min(1, factor));
|
|
99
|
+
}
|
|
100
|
+
export {
|
|
101
|
+
lchToHex,
|
|
102
|
+
interpolateLCH,
|
|
103
|
+
hexToLch,
|
|
104
|
+
calculateGradientFactor
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
//# debugId=EA53CA37A5EEE72764756E2164756E21
|
|
@@ -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.mjs\";\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,IAAI,QAAQ,IAAI,IAAI,IAAI,IAAI,QAAQ,SAAS,IAAI,IAAI;AAAA,EACzD,IAAI,IAAI,QAAQ,IAAI,IAAI,IAAI,IAAI,QAAQ,SAAS,IAAI,IAAI;AAAA,EACzD,IAAI,IAAI,QAAQ,IAAI,IAAI,IAAI,IAAI,QAAQ,SAAS,IAAI,IAAI;AAAA,EAGzD,KAAK;AAAA,EACL,KAAK;AAAA,EACL,KAAK;AAAA,EAGL,IAAI,IAAI,IAAI,SAAS,IAAI,UAAU,IAAI;AAAA,EACvC,IAAI,IAAI,IAAI,UAAU,IAAI,SAAS,IAAI;AAAA,EACvC,IAAI,OAAO,IAA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I,OAAO,KAAK;AAAA,EAG7C,IAAI,KAAK,OAAO;AAAA,EAChB,IAAI,KAAK,OAAO;AAAA,EAGhB,MAAM,OAAO,KAAK;AAAA,EAClB,IAAI,OAAO,KAAK;AAAA,IACd,MAAM;AAAA,EACR,EAAO,SAAI,OAAO,MAAM;AAAA,IACtB,MAAM;AAAA,EACR;AAAA,EAEA,IAAI,IAAI,MAAM,KAAK,MAAM;AAAA,EAGzB,KAAM,IAAI,MAAO,OAAO;AAAA,EAExB,OAAO,EAAE,GAAG,GAAG,EAAE;AAAA;AAUZ,SAAS,uBAAuB,CACrC,OACA,KACA,KACQ;AAAA,EAER,IAAI,QAAQ,KAAK;AAAA,IACf,OAAO;AAAA,EACT;AAAA,EAGA,MAAM,UAAU,QAAQ,QAAQ,MAAM;AAAA,EACtC,OAAO,KAAK,IAAI,GAAG,KAAK,IAAI,GAAG,MAAM,CAAC;AAAA;",
|
|
8
|
+
"debugId": "EA53CA37A5EEE72764756E2164756E21",
|
|
9
|
+
"names": []
|
|
10
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
// src/evaluator/dependency-nodes/virtual-cell-value-node.ts
|
|
2
|
+
import { getCellReference } from "../../core/utils.mjs";
|
|
3
|
+
import { BaseEvalNode } from "./base-eval-node.mjs";
|
|
4
|
+
|
|
5
|
+
class VirtualCellValueNode extends BaseEvalNode {
|
|
6
|
+
cellAddress;
|
|
7
|
+
cellValue;
|
|
8
|
+
constructor(key, cellAddress, cellValue) {
|
|
9
|
+
super(key);
|
|
10
|
+
this.cellAddress = cellAddress;
|
|
11
|
+
this.cellValue = cellValue;
|
|
12
|
+
}
|
|
13
|
+
toString() {
|
|
14
|
+
return "virtual:" + getCellReference(this.cellAddress);
|
|
15
|
+
}
|
|
16
|
+
spillMeta;
|
|
17
|
+
setSpillMetaNode(node) {
|
|
18
|
+
this.spillMeta = node;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
export {
|
|
22
|
+
VirtualCellValueNode
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
//# debugId=8F8ADB0C7DD1C28D64756E2164756E21
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../src/evaluator/dependency-nodes/virtual-cell-value-node.ts"],
|
|
4
|
+
"sourcesContent": [
|
|
5
|
+
"import type {\n CellAddress,\n SerializedCellValue,\n SingleEvaluationResult,\n} from \"../../core/types.mjs\";\nimport { getCellReference } from \"../../core/utils.mjs\";\nimport { BaseEvalNode } from \"./base-eval-node.mjs\";\nimport type { SpillMetaNode } from \"./spill-meta-node.mjs\";\n\nexport class VirtualCellValueNode extends BaseEvalNode<SingleEvaluationResult> {\n public readonly cellAddress: CellAddress;\n public readonly cellValue: SerializedCellValue;\n\n constructor(\n key: string,\n cellAddress: CellAddress,\n cellValue: SerializedCellValue\n ) {\n super(key);\n\n this.cellAddress = cellAddress;\n this.cellValue = cellValue;\n }\n\n public override toString(): string {\n return \"virtual:\" + getCellReference(this.cellAddress);\n }\n\n spillMeta: SpillMetaNode | undefined;\n\n setSpillMetaNode(node: SpillMetaNode) {\n this.spillMeta = node;\n }\n}\n"
|
|
6
|
+
],
|
|
7
|
+
"mappings": ";AAKA;AACA;AAAA;AAGO,MAAM,6BAA6B,aAAqC;AAAA,EAC7D;AAAA,EACA;AAAA,EAEhB,WAAW,CACT,KACA,aACA,WACA;AAAA,IACA,MAAM,GAAG;AAAA,IAET,KAAK,cAAc;AAAA,IACnB,KAAK,YAAY;AAAA;AAAA,EAGH,QAAQ,GAAW;AAAA,IACjC,OAAO,aAAa,iBAAiB,KAAK,WAAW;AAAA;AAAA,EAGvD;AAAA,EAEA,gBAAgB,CAAC,MAAqB;AAAA,IACpC,KAAK,YAAY;AAAA;AAErB;",
|
|
8
|
+
"debugId": "8F8ADB0C7DD1C28D64756E2164756E21",
|
|
9
|
+
"names": []
|
|
10
|
+
}
|
|
@@ -16,7 +16,7 @@ import {
|
|
|
16
16
|
import {
|
|
17
17
|
evaluateScalarOperator
|
|
18
18
|
} from "../evaluator/evaluate-scalar-operator.mjs";
|
|
19
|
-
import { functions } from "../functions.mjs";
|
|
19
|
+
import { functions } from "../functions/function-registry.mjs";
|
|
20
20
|
import { add } from "./arithmetic/add/add.mjs";
|
|
21
21
|
import { divide } from "./arithmetic/divide/divide.mjs";
|
|
22
22
|
import { multiply } from "./arithmetic/multiply/multiply.mjs";
|
|
@@ -777,4 +777,4 @@ export {
|
|
|
777
777
|
FormulaEvaluator
|
|
778
778
|
};
|
|
779
779
|
|
|
780
|
-
//# debugId=
|
|
780
|
+
//# debugId=D0163067F1378BC864756E2164756E21
|
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/evaluator/formula-evaluator.ts"],
|
|
4
4
|
"sourcesContent": [
|
|
5
|
-
"import type {\n LocalCellAddress,\n RangeAddress,\n SingleEvaluationResult,\n} from \"../core/types.mjs\";\nimport {\n FormulaError,\n type CellAddress,\n type CellValue,\n type FunctionEvaluationResult,\n type SpreadsheetRange,\n type SpreadsheetRangeEnd,\n type TableDefinition,\n} from \"../core/types.mjs\";\nimport { parseFormula } from \"../parser/parser.mjs\";\n\nimport type { DependencyManager } from \"../core/managers/dependency-manager.mjs\";\nimport type { NamedExpressionManager } from \"../core/managers/named-expression-manager.mjs\";\nimport type { TableManager } from \"../core/managers/table-manager.mjs\";\nimport {\n captureEvaluationErrors,\n cellAddressToKey,\n getAbsoluteRange,\n getRangeIntersection,\n getRangeKey,\n getRelativeRange,\n isRangeOneCell,\n rangeAddressToKey,\n} from \"../core/utils.mjs\";\nimport {\n evaluateScalarOperator,\n type EvaluateScalarOperatorOptions,\n} from \"../evaluator/evaluate-scalar-operator.mjs\";\nimport { functions } from \"../functions.mjs\";\nimport type {\n ArrayNode,\n ASTNode,\n BinaryOpNode,\n FunctionNode,\n NamedExpressionNode,\n RangeNode,\n ReferenceNode,\n StructuredReferenceNode,\n ThreeDRangeNode,\n UnaryOpNode,\n ValueNode,\n} from \"../parser/ast.mjs\";\nimport { add } from \"./arithmetic/add/add.mjs\";\nimport { divide } from \"./arithmetic/divide/divide.mjs\";\nimport { multiply } from \"./arithmetic/multiply/multiply.mjs\";\nimport { power } from \"./arithmetic/power/power.mjs\";\nimport { subtract } from \"./arithmetic/subtract/subtract.mjs\";\nimport { equals } from \"./comparison/equals.mjs\";\nimport { greaterThan } from \"./comparison/greater-than.mjs\";\nimport { greaterThanOrEqual } from \"./comparison/greater-than-or-equal.mjs\";\nimport { lessThan } from \"./comparison/less-than.mjs\";\nimport { lessThanOrEqual } from \"./comparison/less-than-or-equal.mjs\";\nimport { notEquals } from \"./comparison/not-equals.mjs\";\nimport { concatenate } from \"./concatenation/concatenate.mjs\";\nimport { CellValueNode } from \"./dependency-nodes/cell-value-node.mjs\";\nimport { EvaluationContext } from \"./evaluation-context.mjs\";\n\nexport class FormulaEvaluator {\n constructor(\n private tableManager: TableManager,\n private dependencyManager: DependencyManager,\n private namedExpressionManager: NamedExpressionManager\n ) {}\n\n // evaluator methods\n evaluateFormula(\n /**\n * formula is the formula to evaluate, without the leading =\n */\n formula: string,\n context: EvaluationContext\n ): FunctionEvaluationResult {\n const ast = parseFormula(formula);\n\n return captureEvaluationErrors(context.dependencyNode, () => {\n const result = this.evaluateNode(ast, context);\n return result;\n });\n }\n\n evaluateNode(\n node: ASTNode,\n context: EvaluationContext\n ): FunctionEvaluationResult {\n const currentContext = {\n ...context.cellAddress,\n tableName: context.tableName,\n };\n\n const astNode = this.dependencyManager.getAstNode(node, currentContext);\n context.dependencyNode.addDependency(astNode);\n\n // if (astNode.evaluationResult.type !== \"awaiting-evaluation\") {\n // return astNode.evaluationResult;\n // }\n\n if (astNode.resolved) {\n const astContextDependency = astNode.getContextDependency();\n context.appendContextDependency(astContextDependency);\n return astNode.evaluationResult;\n }\n\n astNode.resetDirectDepsUpdated();\n\n function runEvaluation(\n this: FormulaEvaluator,\n context: EvaluationContext\n ): FunctionEvaluationResult {\n switch (node.type) {\n case \"value\":\n return {\n type: \"value\",\n result: this.evaluateValue(node),\n };\n case \"infinity\":\n return {\n type: \"value\",\n result: {\n type: \"infinity\",\n sign: \"positive\",\n },\n };\n case \"binary-op\":\n return this.evaluateBinaryOp(node, context);\n\n case \"reference\":\n return this.evaluateReference(node, context);\n\n case \"named-expression\":\n return this.evaluateNamedExpression(node, context);\n\n case \"structured-reference\":\n return this.evaluateStructuredReference(node, context);\n\n case \"function\":\n return this.evaluateFunction(node, context);\n\n case \"range\":\n return this.evaluateRange(node, context);\n\n case \"unary-op\":\n return this.evaluateUnaryOp(node, context);\n\n case \"3d-range\":\n return this.evaluate3DRange(node, context);\n\n case \"array\":\n return this.evaluateArray(node, context);\n\n default:\n return {\n type: \"error\",\n err: FormulaError.ERROR,\n message: \"WIP: unimplemented support for \" + node.type,\n errAddress: context.dependencyNode,\n };\n }\n }\n const newContext = new EvaluationContext(\n this.tableManager,\n astNode,\n context.cellAddress\n );\n const result = captureEvaluationErrors(astNode, () =>\n runEvaluation.call(this, newContext)\n );\n astNode.setEvaluationResult(result);\n const astContextDependency = newContext.getContextDependency();\n\n astNode.setContextDependency(astContextDependency);\n\n context.appendContextDependency(astContextDependency);\n\n return result;\n }\n\n evaluateStructuredReference(\n node: StructuredReferenceNode,\n context: EvaluationContext\n ): FunctionEvaluationResult {\n // the tables are never dependent on the sheet, interesetingly enough\n let table: TableDefinition | undefined;\n if (node.tableName && node.workbookName) {\n // this expression will evaluate to the same value regardless of where in the workbooks we are evaluating it in\n table = this.tableManager\n .getTables(node.workbookName)\n .get(node.tableName);\n } else if (node.tableName) {\n // different workbooks could have different tables with the same name\n // so it can differ based on the workbook we are evaluating it in\n context.addContextDependency(\"workbook\");\n table = this.tableManager\n .getTables(context.cellAddress.workbookName)\n .get(node.tableName);\n } else {\n // if no table nor workbook name is provided, we need to find the table in the current workbook\n // and the formula will be evaluated differently based on the table (and workbook) we are evaluating it in\n context.addContextDependency(\"workbook\", \"table\");\n table = this.tableManager.isCellInTable(context.cellAddress);\n }\n\n if (node.isCurrentRow) {\n context.addContextDependency(\"row\");\n }\n\n if (!table) {\n return {\n type: \"error\",\n err: FormulaError.REF,\n message: `Table ${node.tableName} not found`,\n errAddress: context.dependencyNode,\n };\n }\n\n const rowIndex = context.cellAddress.rowIndex;\n const tableStart = table.start;\n\n // Handle selector-based references\n if (node.selector) {\n let startRow: number;\n let endRow: SpreadsheetRangeEnd;\n\n switch (node.selector) {\n case \"#Headers\":\n startRow = table.start.rowIndex;\n endRow = { type: \"number\", value: table.start.rowIndex };\n break;\n case \"#Data\":\n startRow = table.start.rowIndex + 1;\n endRow = table.endRow;\n break;\n case \"#All\":\n startRow = table.start.rowIndex;\n endRow = table.endRow;\n break;\n default:\n return {\n type: \"error\",\n err: FormulaError.REF,\n message: `Unknown table selector: ${node.selector}`,\n errAddress: context.dependencyNode,\n };\n }\n\n // If we also have column specification, use those columns\n if (node.cols) {\n const startCol = table.headers.get(node.cols.startCol);\n const endCol = table.headers.get(node.cols.endCol);\n if (!startCol || !endCol) {\n return {\n type: \"error\",\n err: FormulaError.REF,\n message: `Column ${node.cols.startCol} or ${node.cols.endCol} not found in table ${table.name}`,\n errAddress: context.dependencyNode,\n };\n }\n const startColIndex = tableStart.colIndex + startCol.index;\n const endColIndex = tableStart.colIndex + endCol.index;\n\n const range: SpreadsheetRange = {\n start: {\n row: startRow,\n col: startColIndex,\n },\n end: {\n row: endRow,\n col: { type: \"number\", value: endColIndex },\n },\n };\n\n return this.evaluateRange(\n {\n type: \"range\",\n range,\n isAbsolute: {\n start: {\n col: true,\n row: true,\n },\n end: {\n col: true,\n row: true,\n },\n },\n sheetName: table.sheetName,\n },\n context\n );\n } else {\n // No column specification, return entire row(s) for the selector\n const range: SpreadsheetRange = {\n start: {\n row: startRow,\n col: tableStart.colIndex,\n },\n end: {\n row: endRow,\n col: {\n type: \"number\",\n value: tableStart.colIndex + table.headers.size - 1,\n },\n },\n };\n\n return this.evaluateRange(\n {\n type: \"range\",\n range,\n isAbsolute: {\n start: {\n col: true,\n row: true,\n },\n end: {\n col: true,\n row: true,\n },\n },\n sheetName: table.sheetName,\n },\n context\n );\n }\n }\n\n // Handle column-only references (no selector)\n if (node.cols) {\n const startCol = table.headers.get(node.cols.startCol);\n const endCol = table.headers.get(node.cols.endCol);\n if (!startCol || !endCol) {\n return {\n type: \"error\",\n err: FormulaError.REF,\n message: `Column ${node.cols.startCol} or ${node.cols.endCol} not found in table ${table.name}`,\n errAddress: context.dependencyNode,\n };\n }\n const startColIndex = tableStart.colIndex + startCol.index;\n const endColIndex = tableStart.colIndex + endCol.index;\n const range: SpreadsheetRange = {\n start: {\n row: node.isCurrentRow ? rowIndex : table.start.rowIndex + 1,\n col: startColIndex,\n },\n end: {\n row: node.isCurrentRow\n ? { type: \"number\", value: rowIndex }\n : table.endRow,\n col: { type: \"number\", value: endColIndex },\n },\n };\n\n return this.evaluateRange(\n {\n type: \"range\",\n range,\n isAbsolute: {\n start: {\n col: true,\n row: true,\n },\n end: {\n col: true,\n row: true,\n },\n },\n sheetName: table.sheetName,\n },\n context\n );\n }\n\n return {\n type: \"error\",\n err: FormulaError.REF,\n message: \"Structured reference must specify either a selector or columns\",\n errAddress: context.dependencyNode,\n };\n }\n\n /**\n * Evaluates a value node\n */\n evaluateValue(node: ValueNode): CellValue {\n return node.value;\n }\n\n evaluate3DRange(\n node: ThreeDRangeNode,\n context: EvaluationContext\n ): FunctionEvaluationResult {\n throw new Error(\"WIP: 3d range is not implemented\");\n /*\n const startSheet = this.sheets.get(node.startSheet);\n const endSheet = this.sheets.get(node.endSheet);\n if (!startSheet || !endSheet) {\n return {\n type: \"error\",\n err: FormulaError.REF,\n message: `Sheet ${node.startSheet} or ${node.endSheet} not found`,\n };\n }\n\n let numCols = 0;\n let numRows = 0;\n for (let i = startSheet.index; i <= endSheet.index; i++) {\n if (node.reference.type === \"reference\") {\n numCols += 1;\n } else {\n numCols += node.reference.range.end.col.value - node.reference.range.start.col.value + 1;\n }\n\n return {\n type: \"error\",\n err: FormulaError.REF,\n message: `Sheet ${i} not found`,\n };\n }\n\n return {\n type: \"spilled-values\",\n spillArea: (origin: CellAddress) => ({\n start: {\n col: origin.colIndex,\n row: origin.rowIndex,\n },\n end: {\n col: { type: \"number\", value: origin.colIndex },\n row: {\n type: \"number\",\n value: origin.rowIndex + numSheets - 1,\n },\n },\n }),\n source: `range`,\n originResult:\n originResult.type === \"value\"\n ? originResult.result\n : originResult.originResult,\n evaluate: (spilledCell, context) => {\n const colIndex = range.start.col + spilledCell.spillOffset.x;\n const rowIndex = range.start.row + spilledCell.spillOffset.y;\n const sheetName = node.sheetName ?? context.currentSheet;\n return this.evalTimeSafeEvaluateCell(\n {\n colIndex,\n rowIndex,\n sheetName,\n },\n context\n );\n },\n };\n */\n }\n\n evaluateRange(\n node: RangeNode,\n context: EvaluationContext\n ): FunctionEvaluationResult {\n if (isRangeOneCell(node.range)) {\n return this.evaluateReference(\n {\n type: \"reference\",\n address: {\n colIndex: node.range.start.col,\n rowIndex: node.range.start.row,\n },\n isAbsolute: {\n col: node.isAbsolute.start.col || node.isAbsolute.end.col,\n row: node.isAbsolute.start.row || node.isAbsolute.end.row,\n },\n sheetName: node.sheetName,\n },\n context\n );\n }\n\n const debugRange = getRangeKey(node.range);\n\n const rangeAddress: RangeAddress = {\n sheetName: node.sheetName ?? context.cellAddress.sheetName,\n workbookName: node.workbookName ?? context.cellAddress.workbookName,\n range: node.range,\n };\n\n return {\n type: \"spilled-values\",\n spillArea: (origin) => this.projectRange(node.range, origin),\n source: `range ${debugRange}`,\n sourceRange: rangeAddress,\n evaluate: (spillOffset, context) => {\n if (!node.sheetName && !node.workbookName) {\n // e.g. the result from A4:A9 will depend in which sheet and workbook we are evaluating it in\n context.addContextDependency(\"workbook\", \"sheet\");\n } else if (!node.sheetName) {\n // e.g. the result from [Workbook1]A4:A9 will depend in which sheet we are evaluating it in\n context.addContextDependency(\"sheet\");\n } else if (!node.workbookName) {\n // e.g. the result from Sheet1!A4:A9 will depend in which workbook we are evaluating it in\n context.addContextDependency(\"workbook\");\n } else {\n // if we have both sheetName and workbookName, we don't need to add any context dependencies\n }\n\n const originSheetName = node.sheetName ?? context.cellAddress.sheetName;\n const originWorkbookName =\n node.workbookName ?? context.cellAddress.workbookName;\n const colIndex = node.range.start.col + spillOffset.x;\n const rowIndex = node.range.start.row + spillOffset.y;\n\n const cellAddress: CellAddress = {\n colIndex,\n rowIndex,\n sheetName: originSheetName,\n workbookName: originWorkbookName,\n };\n\n const evalNode = this.dependencyManager.getCellValueOrEmptyCellNode(\n cellAddressToKey(cellAddress)\n );\n context.dependencyNode.addDependency(evalNode);\n\n const result = evalNode.evaluationResult;\n\n return result;\n },\n evaluateAllCells: function ({\n evaluate,\n intersection,\n context,\n origin,\n lookupOrder,\n }) {\n let range = node.range;\n if (intersection) {\n // When we have an intersection, it's defined relative to where the spilled range\n // will appear (the origin). However, we need to evaluate cells from the source\n // range (node.range). So we must translate the intersection coordinates back\n // to the source range's coordinate system.\n //\n // Example: If source range A1:C3 spills to D5:F7, and we want intersection E6:F7,\n // we need to translate E6:F7 (relative to D5) to B2:C3 (relative to A1).\n\n // Calculate the offset of the intersection from the spill origin\n const relativeRange = getRelativeRange(intersection, origin);\n const start: LocalCellAddress = {\n colIndex: node.range.start.col,\n rowIndex: node.range.start.row,\n };\n const projectedIntersection = getAbsoluteRange(relativeRange, start);\n const calculateIntersection = getRangeIntersection(\n node.range,\n projectedIntersection\n );\n if (calculateIntersection) {\n range = calculateIntersection;\n }\n }\n\n const address: RangeAddress = {\n range,\n sheetName: node.sheetName ?? context.cellAddress.sheetName,\n workbookName: node.workbookName ?? context.cellAddress.workbookName,\n };\n\n const rangeNode = this.dependencyManager.getRangeNode(\n rangeAddressToKey(address)\n );\n\n context.dependencyNode.addDependency(rangeNode);\n\n return this.dependencyManager.getRangeNode(rangeAddressToKey(address))\n .result;\n },\n };\n }\n\n evaluateArray(\n node: ArrayNode,\n context: EvaluationContext\n ): FunctionEvaluationResult {\n const firstRow = node.elements[0];\n if (!firstRow) {\n return {\n type: \"error\",\n err: FormulaError.REF,\n message: \"Array is empty\",\n errAddress: context.dependencyNode,\n };\n }\n const firstCell = firstRow[0];\n if (!firstCell) {\n return {\n type: \"error\",\n err: FormulaError.REF,\n message: \"Array is empty\",\n errAddress: context.dependencyNode,\n };\n }\n const originResult = this.evaluateNode(firstCell, context);\n if (\n originResult.type === \"error\" ||\n originResult.type === \"awaiting-evaluation\"\n ) {\n return originResult;\n }\n return {\n type: \"spilled-values\",\n spillArea: (origin) => ({\n start: {\n col: origin.colIndex,\n row: origin.rowIndex,\n },\n end: {\n col: {\n type: \"number\",\n value: origin.colIndex + firstRow.length - 1,\n },\n row: {\n type: \"number\",\n value: origin.rowIndex + node.elements.length - 1,\n },\n },\n }),\n source: `array`,\n evaluate: (spillOffset, context) => {\n const row = node.elements[spillOffset.y];\n if (!row) {\n return {\n type: \"error\",\n err: FormulaError.REF,\n message: \"Array is empty\",\n errAddress: context.dependencyNode,\n };\n }\n const cell = row[spillOffset.x];\n if (!cell) {\n return {\n type: \"error\",\n err: FormulaError.REF,\n message: \"Array is empty\",\n errAddress: context.dependencyNode,\n };\n }\n const result = this.evaluateNode(cell, context);\n if (result.type === \"spilled-values\") {\n return {\n type: \"error\",\n err: FormulaError.VALUE,\n message: \"Arrays cannot contain spilled values\",\n errAddress: context.dependencyNode,\n };\n }\n return result;\n },\n evaluateAllCells: (intersectingRange) => {\n throw new Error(\"WIP: evaluateAllCells for array is not implemented\");\n },\n };\n }\n\n /**\n * Evaluates a unary operation\n */\n evaluateUnaryOp(\n node: UnaryOpNode,\n context: EvaluationContext\n ): FunctionEvaluationResult {\n const operandResult = this.evaluateNode(node.operand, context);\n\n if (\n operandResult.type === \"error\" ||\n operandResult.type === \"awaiting-evaluation\"\n ) {\n return operandResult;\n }\n\n if (operandResult.type === \"spilled-values\") {\n return {\n type: \"spilled-values\",\n spillArea: (origin) => operandResult.spillArea(origin),\n source: `unary ${node.operator} operation`,\n evaluate: (spilledCell, context) => {\n const spillResult = operandResult.evaluate(spilledCell, context);\n if (\n !spillResult ||\n spillResult.type === \"error\" ||\n spillResult.type === \"awaiting-evaluation\"\n ) {\n return spillResult;\n }\n if (spillResult.type !== \"value\") {\n return {\n type: \"error\",\n err: FormulaError.VALUE,\n message: \"Invalid spilled result for unary operation\",\n errAddress: context.dependencyNode,\n };\n }\n return this.evaluateUnaryScalar(\n node.operator,\n spillResult.result,\n context\n );\n },\n evaluateAllCells: function (options) {\n const cellValues = operandResult.evaluateAllCells.call(this, options);\n if (cellValues.type !== \"values\") {\n return cellValues;\n }\n return {\n type: \"values\",\n values: cellValues.values.map((cellValue) => {\n if (\n cellValue.result.type === \"error\" ||\n cellValue.result.type === \"awaiting-evaluation\"\n ) {\n return cellValue;\n } else {\n return {\n result: this.evaluateUnaryScalar(\n node.operator,\n cellValue.result.result,\n context\n ),\n relativePos: cellValue.relativePos,\n };\n }\n }),\n };\n },\n };\n }\n\n if (operandResult.type === \"value\") {\n return this.evaluateUnaryScalar(\n node.operator,\n operandResult.result,\n context\n );\n }\n\n return {\n type: \"error\",\n err: FormulaError.VALUE,\n message: \"Invalid operand for unary operation\",\n errAddress: context.dependencyNode,\n };\n }\n\n /**\n * Evaluates a unary scalar operation\n */\n private evaluateUnaryScalar(\n operator: \"+\" | \"-\" | \"%\",\n operand: CellValue,\n context: EvaluationContext\n ): SingleEvaluationResult {\n if (operand.type !== \"number\" && operand.type !== \"infinity\") {\n return {\n type: \"error\",\n err: FormulaError.VALUE,\n message: `Cannot apply unary ${operator} to non-number`,\n errAddress: context.dependencyNode,\n };\n }\n if (operand.type === \"infinity\") {\n if (operator === \"%\") {\n return {\n type: \"error\",\n err: FormulaError.NUM,\n message: \"Cannot apply % to infinity\",\n errAddress: context.dependencyNode,\n };\n }\n return {\n type: \"value\",\n result: {\n type: \"infinity\",\n sign: operator === \"+\" ? \"positive\" : \"negative\",\n },\n };\n }\n switch (operator) {\n case \"+\":\n return { type: \"value\", result: operand };\n\n case \"-\":\n return {\n type: \"value\",\n result: {\n type: \"number\",\n value: -operand.value,\n },\n };\n\n case \"%\":\n return {\n type: \"value\",\n result: { type: \"number\", value: operand.value / 100 },\n };\n\n default:\n return {\n type: \"error\",\n err: FormulaError.VALUE,\n message: `Unknown unary operator: ${operator}`,\n errAddress: context.dependencyNode,\n };\n }\n }\n\n /**\n * Evaluates a binary operation\n */\n evaluateBinaryOp(\n node: BinaryOpNode,\n context: EvaluationContext\n ): FunctionEvaluationResult {\n const left = this.evaluateNode(node.left, context);\n const right = this.evaluateNode(node.right, context);\n\n if (left.type === \"error\" || left.type === \"awaiting-evaluation\") {\n return left;\n }\n if (right.type === \"error\" || right.type === \"awaiting-evaluation\") {\n return right;\n }\n\n // Scalar operation\n return this.evaluateBinaryScalar(node.operator, left, right, context);\n }\n\n /**\n * Evaluates a reference node\n */\n evaluateReference(\n node: ReferenceNode,\n context: EvaluationContext\n ): FunctionEvaluationResult {\n const cellAddress: CellAddress = {\n ...node.address,\n sheetName: node.sheetName ?? context.cellAddress.sheetName,\n workbookName: node.workbookName ?? context.cellAddress.workbookName,\n };\n\n const key = cellAddressToKey(cellAddress);\n const evalNode = this.dependencyManager.getCellValueOrEmptyCellNode(key);\n context.dependencyNode.addDependency(evalNode);\n\n if (!node.sheetName && !node.workbookName) {\n // e.g. the result from A4:A9 will depend in which sheet and workbook we are evaluating it in\n context.addContextDependency(\"workbook\", \"sheet\");\n } else if (!node.sheetName) {\n // e.g. the result from [Workbook1]A4:A9 will depend in which sheet we are evaluating it in\n context.addContextDependency(\"sheet\");\n } else if (!node.workbookName) {\n // e.g. the result from Sheet1!A4:A9 will depend in which workbook we are evaluating it in\n context.addContextDependency(\"workbook\");\n } else {\n // if we have both sheetName and workbookName, we don't need to add any context dependencies\n }\n\n if (evalNode instanceof CellValueNode && evalNode.spillMeta) {\n if (evalNode.spillMeta.evaluationResult.type === \"spilled-values\") {\n return {\n ...evalNode.spillMeta.evaluationResult,\n sourceCell: cellAddress,\n sourceRange: undefined,\n };\n }\n }\n\n return { ...evalNode.evaluationResult, sourceCell: cellAddress };\n }\n\n /**\n * Evaluates a named expression node\n */\n evaluateNamedExpression(\n node: NamedExpressionNode,\n context: EvaluationContext\n ): FunctionEvaluationResult {\n const expression = this.namedExpressionManager.resolveNamedExpression(\n node,\n context\n );\n\n if (!expression) {\n return {\n type: \"error\",\n err: FormulaError.NAME,\n message: `Named expression ${node.name} not found`,\n errAddress: context.dependencyNode,\n };\n }\n\n return this.evaluateFormula(expression, context);\n }\n\n /**\n * Binary scalar operations\n */\n evaluateBinaryScalar(\n operator: string,\n left: FunctionEvaluationResult,\n right: FunctionEvaluationResult,\n context: EvaluationContext\n ): FunctionEvaluationResult {\n switch (operator) {\n case \"+\":\n return this.add(left, right, context);\n case \"-\":\n return this.subtract(left, right, context);\n case \"*\":\n return this.multiply(left, right, context);\n case \"/\":\n return this.divide(left, right, context);\n case \"^\":\n return this.power(left, right, context);\n\n case \"&\":\n return this.concatenateOp(left, right, context);\n case \"=\":\n return this.equalsOp(left, right, context);\n case \"<>\":\n return this.notEqualsOp(left, right, context);\n case \"<\":\n return this.lessThanOp(left, right, context);\n case \"<=\":\n return this.lessThanOrEqualOp(left, right, context);\n case \">\":\n return this.greaterThanOp(left, right, context);\n case \">=\":\n return this.greaterThanOrEqualOp(left, right, context);\n default:\n return {\n type: \"error\",\n err: FormulaError.ERROR,\n message: `Unknown binary operator: ${operator}`,\n errAddress: context.dependencyNode,\n };\n }\n }\n\n evaluateFunction(\n node: FunctionNode,\n context: EvaluationContext\n ): FunctionEvaluationResult {\n const func = functions[node.name];\n if (!func) {\n return {\n type: \"error\",\n err: FormulaError.NAME,\n message: `Function ${node.name} not found`,\n errAddress: context.dependencyNode,\n };\n }\n return func.evaluate.call(this, node, context);\n }\n\n // Arithmetic operations\n add(\n left: FunctionEvaluationResult,\n right: FunctionEvaluationResult,\n context: EvaluationContext\n ): FunctionEvaluationResult {\n return this.evaluateScalarOperator(left, right, {\n evaluateScalar: add,\n context,\n name: \"add\",\n });\n }\n\n multiply(\n left: FunctionEvaluationResult,\n right: FunctionEvaluationResult,\n context: EvaluationContext\n ): FunctionEvaluationResult {\n return this.evaluateScalarOperator(left, right, {\n evaluateScalar: multiply,\n context,\n name: \"multiply\",\n });\n }\n\n divide(\n left: FunctionEvaluationResult,\n right: FunctionEvaluationResult,\n context: EvaluationContext\n ): FunctionEvaluationResult {\n return this.evaluateScalarOperator(left, right, {\n evaluateScalar: divide,\n context,\n name: \"divide\",\n });\n }\n\n evaluateScalarOperator(\n left: FunctionEvaluationResult,\n right: FunctionEvaluationResult,\n options: EvaluateScalarOperatorOptions\n ): FunctionEvaluationResult {\n return evaluateScalarOperator.call(this, left, right, options);\n }\n\n subtract(\n left: FunctionEvaluationResult,\n right: FunctionEvaluationResult,\n context: EvaluationContext\n ): FunctionEvaluationResult {\n return this.evaluateScalarOperator(left, right, {\n evaluateScalar: subtract,\n context,\n name: \"subtract\",\n });\n }\n\n power(\n left: FunctionEvaluationResult,\n right: FunctionEvaluationResult,\n context: EvaluationContext\n ): FunctionEvaluationResult {\n return this.evaluateScalarOperator(left, right, {\n evaluateScalar: power,\n context,\n name: \"power\",\n });\n }\n\n // Comparison operations\n equalsOp(\n left: FunctionEvaluationResult,\n right: FunctionEvaluationResult,\n context: EvaluationContext\n ): FunctionEvaluationResult {\n return this.evaluateScalarOperator(left, right, {\n evaluateScalar: equals,\n context,\n name: \"equals\",\n });\n }\n\n notEqualsOp(\n left: FunctionEvaluationResult,\n right: FunctionEvaluationResult,\n context: EvaluationContext\n ): FunctionEvaluationResult {\n return this.evaluateScalarOperator(left, right, {\n evaluateScalar: notEquals,\n context,\n name: \"notEquals\",\n });\n }\n\n lessThanOp(\n left: FunctionEvaluationResult,\n right: FunctionEvaluationResult,\n context: EvaluationContext\n ): FunctionEvaluationResult {\n return this.evaluateScalarOperator(left, right, {\n evaluateScalar: lessThan,\n context,\n name: \"lessThan\",\n });\n }\n\n lessThanOrEqualOp(\n left: FunctionEvaluationResult,\n right: FunctionEvaluationResult,\n context: EvaluationContext\n ): FunctionEvaluationResult {\n return this.evaluateScalarOperator(left, right, {\n evaluateScalar: lessThanOrEqual,\n context,\n name: \"lessThanOrEqual\",\n });\n }\n\n greaterThanOp(\n left: FunctionEvaluationResult,\n right: FunctionEvaluationResult,\n context: EvaluationContext\n ): FunctionEvaluationResult {\n return this.evaluateScalarOperator(left, right, {\n evaluateScalar: greaterThan,\n context,\n name: \"greaterThan\",\n });\n }\n\n greaterThanOrEqualOp(\n left: FunctionEvaluationResult,\n right: FunctionEvaluationResult,\n context: EvaluationContext\n ): FunctionEvaluationResult {\n return this.evaluateScalarOperator(left, right, {\n evaluateScalar: greaterThanOrEqual,\n context,\n name: \"greaterThanOrEqual\",\n });\n }\n\n // Concatenation operation\n concatenateOp(\n left: FunctionEvaluationResult,\n right: FunctionEvaluationResult,\n context: EvaluationContext\n ): FunctionEvaluationResult {\n return this.evaluateScalarOperator(left, right, {\n evaluateScalar: concatenate,\n context,\n name: \"concatenate\",\n });\n }\n\n projectRange(\n range: SpreadsheetRange,\n originCellAddress: CellAddress\n ): SpreadsheetRange {\n const offsetLeft = originCellAddress.colIndex - range.start.col;\n const offsetTop = originCellAddress.rowIndex - range.start.row;\n return {\n start: {\n col: range.start.col + offsetLeft,\n row: range.start.row + offsetTop,\n },\n end: {\n col:\n range.end.col.type === \"number\"\n ? { type: \"number\", value: range.end.col.value + offsetLeft }\n : range.end.col,\n row:\n range.end.row.type === \"number\"\n ? { type: \"number\", value: range.end.row.value + offsetTop }\n : range.end.row,\n },\n };\n }\n\n unionRanges(\n range1: SpreadsheetRange,\n range2: SpreadsheetRange\n ): SpreadsheetRange {\n const endCol = ((): SpreadsheetRangeEnd => {\n if (\n range1.end.col.type === \"infinity\" ||\n range2.end.col.type === \"infinity\"\n ) {\n return { type: \"infinity\", sign: \"positive\" };\n }\n return {\n type: \"number\",\n value: Math.max(range1.end.col.value, range2.end.col.value),\n };\n })();\n\n const endRow = ((): SpreadsheetRangeEnd => {\n if (\n range1.end.row.type === \"infinity\" ||\n range2.end.row.type === \"infinity\"\n ) {\n return { type: \"infinity\", sign: \"positive\" };\n }\n return {\n type: \"number\",\n value: Math.max(range1.end.row.value, range2.end.row.value),\n };\n })();\n\n return {\n start: {\n col: Math.min(range1.start.col, range2.start.col),\n row: Math.min(range1.start.row, range2.start.row),\n },\n end: {\n col: endCol,\n row: endRow,\n },\n };\n }\n}\n"
|
|
5
|
+
"import type {\n LocalCellAddress,\n RangeAddress,\n SingleEvaluationResult,\n} from \"../core/types.mjs\";\nimport {\n FormulaError,\n type CellAddress,\n type CellValue,\n type FunctionEvaluationResult,\n type SpreadsheetRange,\n type SpreadsheetRangeEnd,\n type TableDefinition,\n} from \"../core/types.mjs\";\nimport { parseFormula } from \"../parser/parser.mjs\";\n\nimport type { DependencyManager } from \"../core/managers/dependency-manager.mjs\";\nimport type { NamedExpressionManager } from \"../core/managers/named-expression-manager.mjs\";\nimport type { TableManager } from \"../core/managers/table-manager.mjs\";\nimport {\n captureEvaluationErrors,\n cellAddressToKey,\n getAbsoluteRange,\n getRangeIntersection,\n getRangeKey,\n getRelativeRange,\n isRangeOneCell,\n rangeAddressToKey,\n} from \"../core/utils.mjs\";\nimport {\n evaluateScalarOperator,\n type EvaluateScalarOperatorOptions,\n} from \"../evaluator/evaluate-scalar-operator.mjs\";\nimport { functions } from \"../functions/function-registry.mjs\";\nimport type {\n ArrayNode,\n ASTNode,\n BinaryOpNode,\n FunctionNode,\n NamedExpressionNode,\n RangeNode,\n ReferenceNode,\n StructuredReferenceNode,\n ThreeDRangeNode,\n UnaryOpNode,\n ValueNode,\n} from \"../parser/ast.mjs\";\nimport { add } from \"./arithmetic/add/add.mjs\";\nimport { divide } from \"./arithmetic/divide/divide.mjs\";\nimport { multiply } from \"./arithmetic/multiply/multiply.mjs\";\nimport { power } from \"./arithmetic/power/power.mjs\";\nimport { subtract } from \"./arithmetic/subtract/subtract.mjs\";\nimport { equals } from \"./comparison/equals.mjs\";\nimport { greaterThan } from \"./comparison/greater-than.mjs\";\nimport { greaterThanOrEqual } from \"./comparison/greater-than-or-equal.mjs\";\nimport { lessThan } from \"./comparison/less-than.mjs\";\nimport { lessThanOrEqual } from \"./comparison/less-than-or-equal.mjs\";\nimport { notEquals } from \"./comparison/not-equals.mjs\";\nimport { concatenate } from \"./concatenation/concatenate.mjs\";\nimport { CellValueNode } from \"./dependency-nodes/cell-value-node.mjs\";\nimport { EvaluationContext } from \"./evaluation-context.mjs\";\n\nexport class FormulaEvaluator {\n constructor(\n private tableManager: TableManager,\n private dependencyManager: DependencyManager,\n private namedExpressionManager: NamedExpressionManager\n ) {}\n\n // evaluator methods\n evaluateFormula(\n /**\n * formula is the formula to evaluate, without the leading =\n */\n formula: string,\n context: EvaluationContext\n ): FunctionEvaluationResult {\n const ast = parseFormula(formula);\n\n return captureEvaluationErrors(context.dependencyNode, () => {\n const result = this.evaluateNode(ast, context);\n return result;\n });\n }\n\n evaluateNode(\n node: ASTNode,\n context: EvaluationContext\n ): FunctionEvaluationResult {\n const currentContext = {\n ...context.cellAddress,\n tableName: context.tableName,\n };\n\n const astNode = this.dependencyManager.getAstNode(node, currentContext);\n context.dependencyNode.addDependency(astNode);\n\n // if (astNode.evaluationResult.type !== \"awaiting-evaluation\") {\n // return astNode.evaluationResult;\n // }\n\n if (astNode.resolved) {\n const astContextDependency = astNode.getContextDependency();\n context.appendContextDependency(astContextDependency);\n return astNode.evaluationResult;\n }\n\n astNode.resetDirectDepsUpdated();\n\n function runEvaluation(\n this: FormulaEvaluator,\n context: EvaluationContext\n ): FunctionEvaluationResult {\n switch (node.type) {\n case \"value\":\n return {\n type: \"value\",\n result: this.evaluateValue(node),\n };\n case \"infinity\":\n return {\n type: \"value\",\n result: {\n type: \"infinity\",\n sign: \"positive\",\n },\n };\n case \"binary-op\":\n return this.evaluateBinaryOp(node, context);\n\n case \"reference\":\n return this.evaluateReference(node, context);\n\n case \"named-expression\":\n return this.evaluateNamedExpression(node, context);\n\n case \"structured-reference\":\n return this.evaluateStructuredReference(node, context);\n\n case \"function\":\n return this.evaluateFunction(node, context);\n\n case \"range\":\n return this.evaluateRange(node, context);\n\n case \"unary-op\":\n return this.evaluateUnaryOp(node, context);\n\n case \"3d-range\":\n return this.evaluate3DRange(node, context);\n\n case \"array\":\n return this.evaluateArray(node, context);\n\n default:\n return {\n type: \"error\",\n err: FormulaError.ERROR,\n message: \"WIP: unimplemented support for \" + node.type,\n errAddress: context.dependencyNode,\n };\n }\n }\n const newContext = new EvaluationContext(\n this.tableManager,\n astNode,\n context.cellAddress\n );\n const result = captureEvaluationErrors(astNode, () =>\n runEvaluation.call(this, newContext)\n );\n astNode.setEvaluationResult(result);\n const astContextDependency = newContext.getContextDependency();\n\n astNode.setContextDependency(astContextDependency);\n\n context.appendContextDependency(astContextDependency);\n\n return result;\n }\n\n evaluateStructuredReference(\n node: StructuredReferenceNode,\n context: EvaluationContext\n ): FunctionEvaluationResult {\n // the tables are never dependent on the sheet, interesetingly enough\n let table: TableDefinition | undefined;\n if (node.tableName && node.workbookName) {\n // this expression will evaluate to the same value regardless of where in the workbooks we are evaluating it in\n table = this.tableManager\n .getTables(node.workbookName)\n .get(node.tableName);\n } else if (node.tableName) {\n // different workbooks could have different tables with the same name\n // so it can differ based on the workbook we are evaluating it in\n context.addContextDependency(\"workbook\");\n table = this.tableManager\n .getTables(context.cellAddress.workbookName)\n .get(node.tableName);\n } else {\n // if no table nor workbook name is provided, we need to find the table in the current workbook\n // and the formula will be evaluated differently based on the table (and workbook) we are evaluating it in\n context.addContextDependency(\"workbook\", \"table\");\n table = this.tableManager.isCellInTable(context.cellAddress);\n }\n\n if (node.isCurrentRow) {\n context.addContextDependency(\"row\");\n }\n\n if (!table) {\n return {\n type: \"error\",\n err: FormulaError.REF,\n message: `Table ${node.tableName} not found`,\n errAddress: context.dependencyNode,\n };\n }\n\n const rowIndex = context.cellAddress.rowIndex;\n const tableStart = table.start;\n\n // Handle selector-based references\n if (node.selector) {\n let startRow: number;\n let endRow: SpreadsheetRangeEnd;\n\n switch (node.selector) {\n case \"#Headers\":\n startRow = table.start.rowIndex;\n endRow = { type: \"number\", value: table.start.rowIndex };\n break;\n case \"#Data\":\n startRow = table.start.rowIndex + 1;\n endRow = table.endRow;\n break;\n case \"#All\":\n startRow = table.start.rowIndex;\n endRow = table.endRow;\n break;\n default:\n return {\n type: \"error\",\n err: FormulaError.REF,\n message: `Unknown table selector: ${node.selector}`,\n errAddress: context.dependencyNode,\n };\n }\n\n // If we also have column specification, use those columns\n if (node.cols) {\n const startCol = table.headers.get(node.cols.startCol);\n const endCol = table.headers.get(node.cols.endCol);\n if (!startCol || !endCol) {\n return {\n type: \"error\",\n err: FormulaError.REF,\n message: `Column ${node.cols.startCol} or ${node.cols.endCol} not found in table ${table.name}`,\n errAddress: context.dependencyNode,\n };\n }\n const startColIndex = tableStart.colIndex + startCol.index;\n const endColIndex = tableStart.colIndex + endCol.index;\n\n const range: SpreadsheetRange = {\n start: {\n row: startRow,\n col: startColIndex,\n },\n end: {\n row: endRow,\n col: { type: \"number\", value: endColIndex },\n },\n };\n\n return this.evaluateRange(\n {\n type: \"range\",\n range,\n isAbsolute: {\n start: {\n col: true,\n row: true,\n },\n end: {\n col: true,\n row: true,\n },\n },\n sheetName: table.sheetName,\n },\n context\n );\n } else {\n // No column specification, return entire row(s) for the selector\n const range: SpreadsheetRange = {\n start: {\n row: startRow,\n col: tableStart.colIndex,\n },\n end: {\n row: endRow,\n col: {\n type: \"number\",\n value: tableStart.colIndex + table.headers.size - 1,\n },\n },\n };\n\n return this.evaluateRange(\n {\n type: \"range\",\n range,\n isAbsolute: {\n start: {\n col: true,\n row: true,\n },\n end: {\n col: true,\n row: true,\n },\n },\n sheetName: table.sheetName,\n },\n context\n );\n }\n }\n\n // Handle column-only references (no selector)\n if (node.cols) {\n const startCol = table.headers.get(node.cols.startCol);\n const endCol = table.headers.get(node.cols.endCol);\n if (!startCol || !endCol) {\n return {\n type: \"error\",\n err: FormulaError.REF,\n message: `Column ${node.cols.startCol} or ${node.cols.endCol} not found in table ${table.name}`,\n errAddress: context.dependencyNode,\n };\n }\n const startColIndex = tableStart.colIndex + startCol.index;\n const endColIndex = tableStart.colIndex + endCol.index;\n const range: SpreadsheetRange = {\n start: {\n row: node.isCurrentRow ? rowIndex : table.start.rowIndex + 1,\n col: startColIndex,\n },\n end: {\n row: node.isCurrentRow\n ? { type: \"number\", value: rowIndex }\n : table.endRow,\n col: { type: \"number\", value: endColIndex },\n },\n };\n\n return this.evaluateRange(\n {\n type: \"range\",\n range,\n isAbsolute: {\n start: {\n col: true,\n row: true,\n },\n end: {\n col: true,\n row: true,\n },\n },\n sheetName: table.sheetName,\n },\n context\n );\n }\n\n return {\n type: \"error\",\n err: FormulaError.REF,\n message: \"Structured reference must specify either a selector or columns\",\n errAddress: context.dependencyNode,\n };\n }\n\n /**\n * Evaluates a value node\n */\n evaluateValue(node: ValueNode): CellValue {\n return node.value;\n }\n\n evaluate3DRange(\n node: ThreeDRangeNode,\n context: EvaluationContext\n ): FunctionEvaluationResult {\n throw new Error(\"WIP: 3d range is not implemented\");\n /*\n const startSheet = this.sheets.get(node.startSheet);\n const endSheet = this.sheets.get(node.endSheet);\n if (!startSheet || !endSheet) {\n return {\n type: \"error\",\n err: FormulaError.REF,\n message: `Sheet ${node.startSheet} or ${node.endSheet} not found`,\n };\n }\n\n let numCols = 0;\n let numRows = 0;\n for (let i = startSheet.index; i <= endSheet.index; i++) {\n if (node.reference.type === \"reference\") {\n numCols += 1;\n } else {\n numCols += node.reference.range.end.col.value - node.reference.range.start.col.value + 1;\n }\n\n return {\n type: \"error\",\n err: FormulaError.REF,\n message: `Sheet ${i} not found`,\n };\n }\n\n return {\n type: \"spilled-values\",\n spillArea: (origin: CellAddress) => ({\n start: {\n col: origin.colIndex,\n row: origin.rowIndex,\n },\n end: {\n col: { type: \"number\", value: origin.colIndex },\n row: {\n type: \"number\",\n value: origin.rowIndex + numSheets - 1,\n },\n },\n }),\n source: `range`,\n originResult:\n originResult.type === \"value\"\n ? originResult.result\n : originResult.originResult,\n evaluate: (spilledCell, context) => {\n const colIndex = range.start.col + spilledCell.spillOffset.x;\n const rowIndex = range.start.row + spilledCell.spillOffset.y;\n const sheetName = node.sheetName ?? context.currentSheet;\n return this.evalTimeSafeEvaluateCell(\n {\n colIndex,\n rowIndex,\n sheetName,\n },\n context\n );\n },\n };\n */\n }\n\n evaluateRange(\n node: RangeNode,\n context: EvaluationContext\n ): FunctionEvaluationResult {\n if (isRangeOneCell(node.range)) {\n return this.evaluateReference(\n {\n type: \"reference\",\n address: {\n colIndex: node.range.start.col,\n rowIndex: node.range.start.row,\n },\n isAbsolute: {\n col: node.isAbsolute.start.col || node.isAbsolute.end.col,\n row: node.isAbsolute.start.row || node.isAbsolute.end.row,\n },\n sheetName: node.sheetName,\n },\n context\n );\n }\n\n const debugRange = getRangeKey(node.range);\n\n const rangeAddress: RangeAddress = {\n sheetName: node.sheetName ?? context.cellAddress.sheetName,\n workbookName: node.workbookName ?? context.cellAddress.workbookName,\n range: node.range,\n };\n\n return {\n type: \"spilled-values\",\n spillArea: (origin) => this.projectRange(node.range, origin),\n source: `range ${debugRange}`,\n sourceRange: rangeAddress,\n evaluate: (spillOffset, context) => {\n if (!node.sheetName && !node.workbookName) {\n // e.g. the result from A4:A9 will depend in which sheet and workbook we are evaluating it in\n context.addContextDependency(\"workbook\", \"sheet\");\n } else if (!node.sheetName) {\n // e.g. the result from [Workbook1]A4:A9 will depend in which sheet we are evaluating it in\n context.addContextDependency(\"sheet\");\n } else if (!node.workbookName) {\n // e.g. the result from Sheet1!A4:A9 will depend in which workbook we are evaluating it in\n context.addContextDependency(\"workbook\");\n } else {\n // if we have both sheetName and workbookName, we don't need to add any context dependencies\n }\n\n const originSheetName = node.sheetName ?? context.cellAddress.sheetName;\n const originWorkbookName =\n node.workbookName ?? context.cellAddress.workbookName;\n const colIndex = node.range.start.col + spillOffset.x;\n const rowIndex = node.range.start.row + spillOffset.y;\n\n const cellAddress: CellAddress = {\n colIndex,\n rowIndex,\n sheetName: originSheetName,\n workbookName: originWorkbookName,\n };\n\n const evalNode = this.dependencyManager.getCellValueOrEmptyCellNode(\n cellAddressToKey(cellAddress)\n );\n context.dependencyNode.addDependency(evalNode);\n\n const result = evalNode.evaluationResult;\n\n return result;\n },\n evaluateAllCells: function ({\n evaluate,\n intersection,\n context,\n origin,\n lookupOrder,\n }) {\n let range = node.range;\n if (intersection) {\n // When we have an intersection, it's defined relative to where the spilled range\n // will appear (the origin). However, we need to evaluate cells from the source\n // range (node.range). So we must translate the intersection coordinates back\n // to the source range's coordinate system.\n //\n // Example: If source range A1:C3 spills to D5:F7, and we want intersection E6:F7,\n // we need to translate E6:F7 (relative to D5) to B2:C3 (relative to A1).\n\n // Calculate the offset of the intersection from the spill origin\n const relativeRange = getRelativeRange(intersection, origin);\n const start: LocalCellAddress = {\n colIndex: node.range.start.col,\n rowIndex: node.range.start.row,\n };\n const projectedIntersection = getAbsoluteRange(relativeRange, start);\n const calculateIntersection = getRangeIntersection(\n node.range,\n projectedIntersection\n );\n if (calculateIntersection) {\n range = calculateIntersection;\n }\n }\n\n const address: RangeAddress = {\n range,\n sheetName: node.sheetName ?? context.cellAddress.sheetName,\n workbookName: node.workbookName ?? context.cellAddress.workbookName,\n };\n\n const rangeNode = this.dependencyManager.getRangeNode(\n rangeAddressToKey(address)\n );\n\n context.dependencyNode.addDependency(rangeNode);\n\n return this.dependencyManager.getRangeNode(rangeAddressToKey(address))\n .result;\n },\n };\n }\n\n evaluateArray(\n node: ArrayNode,\n context: EvaluationContext\n ): FunctionEvaluationResult {\n const firstRow = node.elements[0];\n if (!firstRow) {\n return {\n type: \"error\",\n err: FormulaError.REF,\n message: \"Array is empty\",\n errAddress: context.dependencyNode,\n };\n }\n const firstCell = firstRow[0];\n if (!firstCell) {\n return {\n type: \"error\",\n err: FormulaError.REF,\n message: \"Array is empty\",\n errAddress: context.dependencyNode,\n };\n }\n const originResult = this.evaluateNode(firstCell, context);\n if (\n originResult.type === \"error\" ||\n originResult.type === \"awaiting-evaluation\"\n ) {\n return originResult;\n }\n return {\n type: \"spilled-values\",\n spillArea: (origin) => ({\n start: {\n col: origin.colIndex,\n row: origin.rowIndex,\n },\n end: {\n col: {\n type: \"number\",\n value: origin.colIndex + firstRow.length - 1,\n },\n row: {\n type: \"number\",\n value: origin.rowIndex + node.elements.length - 1,\n },\n },\n }),\n source: `array`,\n evaluate: (spillOffset, context) => {\n const row = node.elements[spillOffset.y];\n if (!row) {\n return {\n type: \"error\",\n err: FormulaError.REF,\n message: \"Array is empty\",\n errAddress: context.dependencyNode,\n };\n }\n const cell = row[spillOffset.x];\n if (!cell) {\n return {\n type: \"error\",\n err: FormulaError.REF,\n message: \"Array is empty\",\n errAddress: context.dependencyNode,\n };\n }\n const result = this.evaluateNode(cell, context);\n if (result.type === \"spilled-values\") {\n return {\n type: \"error\",\n err: FormulaError.VALUE,\n message: \"Arrays cannot contain spilled values\",\n errAddress: context.dependencyNode,\n };\n }\n return result;\n },\n evaluateAllCells: (intersectingRange) => {\n throw new Error(\"WIP: evaluateAllCells for array is not implemented\");\n },\n };\n }\n\n /**\n * Evaluates a unary operation\n */\n evaluateUnaryOp(\n node: UnaryOpNode,\n context: EvaluationContext\n ): FunctionEvaluationResult {\n const operandResult = this.evaluateNode(node.operand, context);\n\n if (\n operandResult.type === \"error\" ||\n operandResult.type === \"awaiting-evaluation\"\n ) {\n return operandResult;\n }\n\n if (operandResult.type === \"spilled-values\") {\n return {\n type: \"spilled-values\",\n spillArea: (origin) => operandResult.spillArea(origin),\n source: `unary ${node.operator} operation`,\n evaluate: (spilledCell, context) => {\n const spillResult = operandResult.evaluate(spilledCell, context);\n if (\n !spillResult ||\n spillResult.type === \"error\" ||\n spillResult.type === \"awaiting-evaluation\"\n ) {\n return spillResult;\n }\n if (spillResult.type !== \"value\") {\n return {\n type: \"error\",\n err: FormulaError.VALUE,\n message: \"Invalid spilled result for unary operation\",\n errAddress: context.dependencyNode,\n };\n }\n return this.evaluateUnaryScalar(\n node.operator,\n spillResult.result,\n context\n );\n },\n evaluateAllCells: function (options) {\n const cellValues = operandResult.evaluateAllCells.call(this, options);\n if (cellValues.type !== \"values\") {\n return cellValues;\n }\n return {\n type: \"values\",\n values: cellValues.values.map((cellValue) => {\n if (\n cellValue.result.type === \"error\" ||\n cellValue.result.type === \"awaiting-evaluation\"\n ) {\n return cellValue;\n } else {\n return {\n result: this.evaluateUnaryScalar(\n node.operator,\n cellValue.result.result,\n context\n ),\n relativePos: cellValue.relativePos,\n };\n }\n }),\n };\n },\n };\n }\n\n if (operandResult.type === \"value\") {\n return this.evaluateUnaryScalar(\n node.operator,\n operandResult.result,\n context\n );\n }\n\n return {\n type: \"error\",\n err: FormulaError.VALUE,\n message: \"Invalid operand for unary operation\",\n errAddress: context.dependencyNode,\n };\n }\n\n /**\n * Evaluates a unary scalar operation\n */\n private evaluateUnaryScalar(\n operator: \"+\" | \"-\" | \"%\",\n operand: CellValue,\n context: EvaluationContext\n ): SingleEvaluationResult {\n if (operand.type !== \"number\" && operand.type !== \"infinity\") {\n return {\n type: \"error\",\n err: FormulaError.VALUE,\n message: `Cannot apply unary ${operator} to non-number`,\n errAddress: context.dependencyNode,\n };\n }\n if (operand.type === \"infinity\") {\n if (operator === \"%\") {\n return {\n type: \"error\",\n err: FormulaError.NUM,\n message: \"Cannot apply % to infinity\",\n errAddress: context.dependencyNode,\n };\n }\n return {\n type: \"value\",\n result: {\n type: \"infinity\",\n sign: operator === \"+\" ? \"positive\" : \"negative\",\n },\n };\n }\n switch (operator) {\n case \"+\":\n return { type: \"value\", result: operand };\n\n case \"-\":\n return {\n type: \"value\",\n result: {\n type: \"number\",\n value: -operand.value,\n },\n };\n\n case \"%\":\n return {\n type: \"value\",\n result: { type: \"number\", value: operand.value / 100 },\n };\n\n default:\n return {\n type: \"error\",\n err: FormulaError.VALUE,\n message: `Unknown unary operator: ${operator}`,\n errAddress: context.dependencyNode,\n };\n }\n }\n\n /**\n * Evaluates a binary operation\n */\n evaluateBinaryOp(\n node: BinaryOpNode,\n context: EvaluationContext\n ): FunctionEvaluationResult {\n const left = this.evaluateNode(node.left, context);\n const right = this.evaluateNode(node.right, context);\n\n if (left.type === \"error\" || left.type === \"awaiting-evaluation\") {\n return left;\n }\n if (right.type === \"error\" || right.type === \"awaiting-evaluation\") {\n return right;\n }\n\n // Scalar operation\n return this.evaluateBinaryScalar(node.operator, left, right, context);\n }\n\n /**\n * Evaluates a reference node\n */\n evaluateReference(\n node: ReferenceNode,\n context: EvaluationContext\n ): FunctionEvaluationResult {\n const cellAddress: CellAddress = {\n ...node.address,\n sheetName: node.sheetName ?? context.cellAddress.sheetName,\n workbookName: node.workbookName ?? context.cellAddress.workbookName,\n };\n\n const key = cellAddressToKey(cellAddress);\n const evalNode = this.dependencyManager.getCellValueOrEmptyCellNode(key);\n context.dependencyNode.addDependency(evalNode);\n\n if (!node.sheetName && !node.workbookName) {\n // e.g. the result from A4:A9 will depend in which sheet and workbook we are evaluating it in\n context.addContextDependency(\"workbook\", \"sheet\");\n } else if (!node.sheetName) {\n // e.g. the result from [Workbook1]A4:A9 will depend in which sheet we are evaluating it in\n context.addContextDependency(\"sheet\");\n } else if (!node.workbookName) {\n // e.g. the result from Sheet1!A4:A9 will depend in which workbook we are evaluating it in\n context.addContextDependency(\"workbook\");\n } else {\n // if we have both sheetName and workbookName, we don't need to add any context dependencies\n }\n\n if (evalNode instanceof CellValueNode && evalNode.spillMeta) {\n if (evalNode.spillMeta.evaluationResult.type === \"spilled-values\") {\n return {\n ...evalNode.spillMeta.evaluationResult,\n sourceCell: cellAddress,\n sourceRange: undefined,\n };\n }\n }\n\n return { ...evalNode.evaluationResult, sourceCell: cellAddress };\n }\n\n /**\n * Evaluates a named expression node\n */\n evaluateNamedExpression(\n node: NamedExpressionNode,\n context: EvaluationContext\n ): FunctionEvaluationResult {\n const expression = this.namedExpressionManager.resolveNamedExpression(\n node,\n context\n );\n\n if (!expression) {\n return {\n type: \"error\",\n err: FormulaError.NAME,\n message: `Named expression ${node.name} not found`,\n errAddress: context.dependencyNode,\n };\n }\n\n return this.evaluateFormula(expression, context);\n }\n\n /**\n * Binary scalar operations\n */\n evaluateBinaryScalar(\n operator: string,\n left: FunctionEvaluationResult,\n right: FunctionEvaluationResult,\n context: EvaluationContext\n ): FunctionEvaluationResult {\n switch (operator) {\n case \"+\":\n return this.add(left, right, context);\n case \"-\":\n return this.subtract(left, right, context);\n case \"*\":\n return this.multiply(left, right, context);\n case \"/\":\n return this.divide(left, right, context);\n case \"^\":\n return this.power(left, right, context);\n\n case \"&\":\n return this.concatenateOp(left, right, context);\n case \"=\":\n return this.equalsOp(left, right, context);\n case \"<>\":\n return this.notEqualsOp(left, right, context);\n case \"<\":\n return this.lessThanOp(left, right, context);\n case \"<=\":\n return this.lessThanOrEqualOp(left, right, context);\n case \">\":\n return this.greaterThanOp(left, right, context);\n case \">=\":\n return this.greaterThanOrEqualOp(left, right, context);\n default:\n return {\n type: \"error\",\n err: FormulaError.ERROR,\n message: `Unknown binary operator: ${operator}`,\n errAddress: context.dependencyNode,\n };\n }\n }\n\n evaluateFunction(\n node: FunctionNode,\n context: EvaluationContext\n ): FunctionEvaluationResult {\n const func = functions[node.name];\n if (!func) {\n return {\n type: \"error\",\n err: FormulaError.NAME,\n message: `Function ${node.name} not found`,\n errAddress: context.dependencyNode,\n };\n }\n return func.evaluate.call(this, node, context);\n }\n\n // Arithmetic operations\n add(\n left: FunctionEvaluationResult,\n right: FunctionEvaluationResult,\n context: EvaluationContext\n ): FunctionEvaluationResult {\n return this.evaluateScalarOperator(left, right, {\n evaluateScalar: add,\n context,\n name: \"add\",\n });\n }\n\n multiply(\n left: FunctionEvaluationResult,\n right: FunctionEvaluationResult,\n context: EvaluationContext\n ): FunctionEvaluationResult {\n return this.evaluateScalarOperator(left, right, {\n evaluateScalar: multiply,\n context,\n name: \"multiply\",\n });\n }\n\n divide(\n left: FunctionEvaluationResult,\n right: FunctionEvaluationResult,\n context: EvaluationContext\n ): FunctionEvaluationResult {\n return this.evaluateScalarOperator(left, right, {\n evaluateScalar: divide,\n context,\n name: \"divide\",\n });\n }\n\n evaluateScalarOperator(\n left: FunctionEvaluationResult,\n right: FunctionEvaluationResult,\n options: EvaluateScalarOperatorOptions\n ): FunctionEvaluationResult {\n return evaluateScalarOperator.call(this, left, right, options);\n }\n\n subtract(\n left: FunctionEvaluationResult,\n right: FunctionEvaluationResult,\n context: EvaluationContext\n ): FunctionEvaluationResult {\n return this.evaluateScalarOperator(left, right, {\n evaluateScalar: subtract,\n context,\n name: \"subtract\",\n });\n }\n\n power(\n left: FunctionEvaluationResult,\n right: FunctionEvaluationResult,\n context: EvaluationContext\n ): FunctionEvaluationResult {\n return this.evaluateScalarOperator(left, right, {\n evaluateScalar: power,\n context,\n name: \"power\",\n });\n }\n\n // Comparison operations\n equalsOp(\n left: FunctionEvaluationResult,\n right: FunctionEvaluationResult,\n context: EvaluationContext\n ): FunctionEvaluationResult {\n return this.evaluateScalarOperator(left, right, {\n evaluateScalar: equals,\n context,\n name: \"equals\",\n });\n }\n\n notEqualsOp(\n left: FunctionEvaluationResult,\n right: FunctionEvaluationResult,\n context: EvaluationContext\n ): FunctionEvaluationResult {\n return this.evaluateScalarOperator(left, right, {\n evaluateScalar: notEquals,\n context,\n name: \"notEquals\",\n });\n }\n\n lessThanOp(\n left: FunctionEvaluationResult,\n right: FunctionEvaluationResult,\n context: EvaluationContext\n ): FunctionEvaluationResult {\n return this.evaluateScalarOperator(left, right, {\n evaluateScalar: lessThan,\n context,\n name: \"lessThan\",\n });\n }\n\n lessThanOrEqualOp(\n left: FunctionEvaluationResult,\n right: FunctionEvaluationResult,\n context: EvaluationContext\n ): FunctionEvaluationResult {\n return this.evaluateScalarOperator(left, right, {\n evaluateScalar: lessThanOrEqual,\n context,\n name: \"lessThanOrEqual\",\n });\n }\n\n greaterThanOp(\n left: FunctionEvaluationResult,\n right: FunctionEvaluationResult,\n context: EvaluationContext\n ): FunctionEvaluationResult {\n return this.evaluateScalarOperator(left, right, {\n evaluateScalar: greaterThan,\n context,\n name: \"greaterThan\",\n });\n }\n\n greaterThanOrEqualOp(\n left: FunctionEvaluationResult,\n right: FunctionEvaluationResult,\n context: EvaluationContext\n ): FunctionEvaluationResult {\n return this.evaluateScalarOperator(left, right, {\n evaluateScalar: greaterThanOrEqual,\n context,\n name: \"greaterThanOrEqual\",\n });\n }\n\n // Concatenation operation\n concatenateOp(\n left: FunctionEvaluationResult,\n right: FunctionEvaluationResult,\n context: EvaluationContext\n ): FunctionEvaluationResult {\n return this.evaluateScalarOperator(left, right, {\n evaluateScalar: concatenate,\n context,\n name: \"concatenate\",\n });\n }\n\n projectRange(\n range: SpreadsheetRange,\n originCellAddress: CellAddress\n ): SpreadsheetRange {\n const offsetLeft = originCellAddress.colIndex - range.start.col;\n const offsetTop = originCellAddress.rowIndex - range.start.row;\n return {\n start: {\n col: range.start.col + offsetLeft,\n row: range.start.row + offsetTop,\n },\n end: {\n col:\n range.end.col.type === \"number\"\n ? { type: \"number\", value: range.end.col.value + offsetLeft }\n : range.end.col,\n row:\n range.end.row.type === \"number\"\n ? { type: \"number\", value: range.end.row.value + offsetTop }\n : range.end.row,\n },\n };\n }\n\n unionRanges(\n range1: SpreadsheetRange,\n range2: SpreadsheetRange\n ): SpreadsheetRange {\n const endCol = ((): SpreadsheetRangeEnd => {\n if (\n range1.end.col.type === \"infinity\" ||\n range2.end.col.type === \"infinity\"\n ) {\n return { type: \"infinity\", sign: \"positive\" };\n }\n return {\n type: \"number\",\n value: Math.max(range1.end.col.value, range2.end.col.value),\n };\n })();\n\n const endRow = ((): SpreadsheetRangeEnd => {\n if (\n range1.end.row.type === \"infinity\" ||\n range2.end.row.type === \"infinity\"\n ) {\n return { type: \"infinity\", sign: \"positive\" };\n }\n return {\n type: \"number\",\n value: Math.max(range1.end.row.value, range2.end.row.value),\n };\n })();\n\n return {\n start: {\n col: Math.min(range1.start.col, range2.start.col),\n row: Math.min(range1.start.row, range2.start.row),\n },\n end: {\n col: endCol,\n row: endRow,\n },\n };\n }\n}\n"
|
|
6
6
|
],
|
|
7
7
|
"mappings": ";AAKA;AAAA;AAAA;AASA;AAKA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAUA;AAAA;AAAA;AAIA;AAcA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAAA;AAEO,MAAM,iBAAiB;AAAA,EAElB;AAAA,EACA;AAAA,EACA;AAAA,EAHV,WAAW,CACD,cACA,mBACA,wBACR;AAAA,IAHQ;AAAA,IACA;AAAA,IACA;AAAA;AAAA,EAIV,eAAe,CAIb,SACA,SAC0B;AAAA,IAC1B,MAAM,MAAM,aAAa,OAAO;AAAA,IAEhC,OAAO,wBAAwB,QAAQ,gBAAgB,MAAM;AAAA,MAC3D,MAAM,SAAS,KAAK,aAAa,KAAK,OAAO;AAAA,MAC7C,OAAO;AAAA,KACR;AAAA;AAAA,EAGH,YAAY,CACV,MACA,SAC0B;AAAA,IAC1B,MAAM,iBAAiB;AAAA,SAClB,QAAQ;AAAA,MACX,WAAW,QAAQ;AAAA,IACrB;AAAA,IAEA,MAAM,UAAU,KAAK,kBAAkB,WAAW,MAAM,cAAc;AAAA,IACtE,QAAQ,eAAe,cAAc,OAAO;AAAA,IAM5C,IAAI,QAAQ,UAAU;AAAA,MACpB,MAAM,wBAAuB,QAAQ,qBAAqB;AAAA,MAC1D,QAAQ,wBAAwB,qBAAoB;AAAA,MACpD,OAAO,QAAQ;AAAA,IACjB;AAAA,IAEA,QAAQ,uBAAuB;AAAA,IAE/B,SAAS,aAAa,CAEpB,UAC0B;AAAA,MAC1B,QAAQ,KAAK;AAAA,aACN;AAAA,UACH,OAAO;AAAA,YACL,MAAM;AAAA,YACN,QAAQ,KAAK,cAAc,IAAI;AAAA,UACjC;AAAA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zC,IACE,OAAO,IAAI,IAAI,SAAS,cACxB,OAAO,IAAI,IAAI,SAAS,YACxB;AAAA,QACA,OAAO,EAAE,MAAM,YAAY,MAAM,WAAW;AAAA,MAC9C;AAAA,MACA,OAAO;AAAA,QACL,MAAM;AAAA,QACN,OAAO,KAAK,IAAI,OAAO,IAAI,IAAI,OAAO,OAAO,IAAI,IAAI,KAAK;AAAA,MAC5D;AAAA,OACC;AAAA,IAEH,OAAO;AAAA,MACL,OAAO;AAAA,QACL,KAAK,KAAK,IAAI,OAAO,MAAM,KAAK,OAAO,MAAM,GAAG;AAAA,QAChD,KAAK,KAAK,IAAI,OAAO,MAAM,KAAK,OAAO,MAAM,GAAG;AAAA,MAClD;AAAA,MACA,KAAK;AAAA,QACH,KAAK;AAAA,QACL,KAAK;AAAA,MACP;AAAA,IACF;AAAA;AAEJ;",
|
|
8
|
-
"debugId": "
|
|
8
|
+
"debugId": "D0163067F1378BC864756E2164756E21",
|
|
9
9
|
"names": []
|
|
10
10
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// src/functions/
|
|
1
|
+
// src/functions/function-registry.ts
|
|
2
2
|
import { SEQUENCE } from "./array/sequence/sequence.mjs";
|
|
3
3
|
import { INDEX } from "./lookup/index-lookup/index-lookup.mjs";
|
|
4
4
|
import { MATCH } from "./lookup/match/match.mjs";
|
|
@@ -92,4 +92,4 @@ export {
|
|
|
92
92
|
functions
|
|
93
93
|
};
|
|
94
94
|
|
|
95
|
-
//# debugId=
|
|
95
|
+
//# debugId=412AE470DB80B9DF64756E2164756E21
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["../../../src/functions/
|
|
3
|
+
"sources": ["../../../src/functions/function-registry.ts"],
|
|
4
4
|
"sourcesContent": [
|
|
5
5
|
"import type { FunctionDefinition } from \"../core/types.mjs\";\n// import { arrayFunctions } from \"./array/array-functions.mjs\";\n// import { infoFunctions } from \"./info/info-functions.mjs\";\n// import { logicalComparisonFunctions } from \"./logical/comparisons.mjs\";\n// import { logicalConditionFunctions } from \"./logical/conditions.mjs\";\n// import { lookupFunctions } from \"./lookup/lookup-functions.mjs\";\n// import { advancedMathFunctions } from \"./math/advanced.mjs\";\n// import { basicMathFunctions } from \"./math/basic.mjs\";\n// import { textFunctions } from \"./text/string-functions.mjs\";\nimport { SEQUENCE } from \"./array/sequence/sequence.mjs\";\nimport { INDEX } from \"./lookup/index-lookup/index-lookup.mjs\"; // Fixed import path\nimport { MATCH } from \"./lookup/match/match.mjs\";\nimport { COUNT } from \"./lookup/count/count.mjs\";\nimport { COUNTIF } from \"./lookup/count/countif.mjs\";\nimport { AVERAGE } from \"./math/average/average.mjs\";\nimport { AVERAGEIF } from \"./math/average/averageif.mjs\";\nimport { AVERAGEIFS } from \"./math/average/averageifs.mjs\";\nimport { MAX } from \"./math/max/max.mjs\";\nimport { MAXIFS } from \"./math/max/maxifs.mjs\";\nimport { MIN } from \"./math/min/min.mjs\";\nimport { MINIFS } from \"./math/min/minifs.mjs\";\nimport { SUM } from \"./math/sum/sum.mjs\";\nimport { SUMIF } from \"./math/sum/sumif.mjs\";\nimport { SUMIFS } from \"./math/sum/sumifs.mjs\";\nimport { COUNTIFS } from \"./lookup/count/countifs.mjs\";\nimport { MAXIF } from \"./math/max/maxif.mjs\";\nimport { MINIF } from \"./math/min/minif.mjs\";\nimport { CEILING } from \"./math/ceiling/ceiling.mjs\";\nimport { EXACT } from \"./text/exact/exact.mjs\";\nimport { FIND } from \"./text/find/find.mjs\";\nimport { LEFT } from \"./text/left/left.mjs\";\nimport { MID } from \"./text/mid/mid.mjs\";\nimport { LEN } from \"./text/len/len.mjs\";\nimport { RIGHT } from \"./text/right/right.mjs\";\nimport { CONCATENATE } from \"./text/concatenate/concatenate.mjs\";\nimport { AND } from \"./logical/and/and.mjs\";\nimport { IF } from \"./logical/if/if.mjs\";\nimport { IFERROR } from \"./logical/iferror/iferror.mjs\";\nimport { XLOOKUP } from \"./lookup/xlookup/xlookup.mjs\";\nimport { OR } from \"./logical/or/or.mjs\";\nimport { TEXTJOIN } from \"./text/textjoin/textjoin.mjs\";\nimport { ROW } from \"./information/row/row.mjs\";\nimport { COLUMN } from \"./information/column/column.mjs\";\nimport { CELL } from \"./information/cell/cell.mjs\";\nimport { ADDRESS } from \"./reference/address/address.mjs\";\nimport { INDIRECT } from \"./reference/indirect/indirect.mjs\";\nimport { OFFSET } from \"./reference/offset/offset.mjs\";\n\nconst buildFunctionIndex = (functions: Record<string, FunctionDefinition>) => {\n return Object.fromEntries(\n Object.entries(functions).flatMap(([name, func]) => {\n const base: [string, FunctionDefinition][] = [[name, func]];\n if (func.aliases) {\n func.aliases.forEach((alias) => {\n base.push([alias, func]);\n });\n }\n return base;\n })\n );\n};\n\nexport const functions: Record<string, FunctionDefinition> = buildFunctionIndex(\n {\n ADDRESS,\n AND,\n AVERAGE,\n AVERAGEIF,\n AVERAGEIFS,\n CEILING,\n CELL,\n COLUMN,\n CONCATENATE,\n COUNT,\n COUNTIF,\n COUNTIFS,\n EXACT,\n FIND,\n IF,\n IFERROR,\n INDEX,\n INDIRECT,\n LEFT,\n LEN,\n MATCH,\n MAX,\n MAXIF,\n MAXIFS,\n MID,\n MIN,\n MINIF,\n MINIFS,\n OFFSET,\n OR,\n RIGHT,\n ROW,\n SEQUENCE,\n SUM,\n SUMIF,\n SUMIFS,\n TEXTJOIN,\n XLOOKUP,\n }\n);\n"
|
|
6
6
|
],
|
|
7
7
|
"mappings": ";AASA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA,IAAM,qBAAqB,CAAC,cAAkD;AAAA,EAC5E,OAAO,OAAO,YACZ,OAAO,QAAQ,SAAS,EAAE,QAAQ,EAAE,MAAM,UAAU;AAAA,IAClD,MAAM,OAAuC,CAAC,CAAC,MAAM,IAAI,CAAC;AAAA,IAC1D,IAAI,KAAK,SAAS;AAAA,MAChB,KAAK,QAAQ,QAAQ,CAAC,UAAU;AAAA,QAC9B,KAAK,KAAK,CAAC,OAAO,IAAI,CAAC;AAAA,OACxB;AAAA,IACH;AAAA,IACA,OAAO;AAAA,GACR,CACH;AAAA;AAGK,IAAM,YAAgD,mBAC3D;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,CACF;",
|
|
8
|
-
"debugId": "
|
|
8
|
+
"debugId": "412AE470DB80B9DF64756E2164756E21",
|
|
9
9
|
"names": []
|
|
10
10
|
}
|
package/dist/mjs/package.json
CHANGED