@ricsam/formula-engine 0.2.14 → 0.2.15

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.
@@ -2,9 +2,9 @@
2
2
  "version": 3,
3
3
  "sources": ["../../../src/core/types.ts"],
4
4
  "sourcesContent": [
5
- "/**\n * Core type definitions for FormulaEngine\n * This file contains all fundamental types used throughout the engine\n */\n\nimport type { EvaluationContext } from \"../evaluator/evaluation-context.cjs\";\nimport type { FormulaEvaluator } from \"../evaluator/formula-evaluator.cjs\";\nimport type { FunctionNode } from \"../parser/ast.cjs\";\nimport type { DependencyNode } from \"./managers/dependency-node.cjs\";\nimport type { LookupOrder } from \"./managers/range-eval-order-builder.cjs\";\n\n// Cell addressing types\nexport interface CellAddress {\n sheetName: string;\n workbookName: string;\n colIndex: number;\n rowIndex: number;\n}\n\nexport interface RangeAddress {\n sheetName: string;\n workbookName: string;\n range: SpreadsheetRange;\n}\n\nexport interface LocalCellAddress {\n colIndex: number;\n rowIndex: number;\n}\n\nexport type ArethmeticEvaluator = (\n left: CellValue,\n right: CellValue,\n context: EvaluationContext\n) => CellValue | ErrorEvaluationResult;\n\nexport type PositiveInfinity = {\n type: \"infinity\";\n sign: \"positive\";\n};\n\nexport type CellInfinity = {\n type: \"infinity\";\n sign: \"positive\" | \"negative\";\n};\n\nexport type CellNumber = {\n type: \"number\";\n value: number;\n};\n\nexport type SpreadsheetRangeEnd = CellNumber | PositiveInfinity;\n\nexport type SpreadsheetRange = {\n start: {\n col: number;\n row: number;\n };\n end: {\n col: SpreadsheetRangeEnd;\n row: SpreadsheetRangeEnd;\n };\n};\n\nexport type RelativeRange = {\n start: {\n col: number;\n row: number;\n };\n width: SpreadsheetRangeEnd;\n height: SpreadsheetRangeEnd;\n};\n\nexport type FiniteSpreadsheetRange = {\n start: {\n col: number;\n row: number;\n };\n end: {\n col: number;\n row: number;\n };\n};\n\nexport type CellString = {\n type: \"string\";\n value: string;\n};\n\nexport type CellBoolean = {\n type: \"boolean\";\n value: boolean;\n};\n\n// Cell value types\nexport type CellValue = CellNumber | CellString | CellBoolean | CellInfinity;\n/**\n * undefined and \"\" are considered empty values\n * undefineds are converted to \"\" in the engine\n *\n * any empty values are deleted from the sheet content\n */\nexport type SerializedCellValue = string | number | boolean | undefined;\n\nexport const DEFAULT_SEARCH_MAX_RESULTS = 1000;\n\nexport interface SearchOptions {\n workbookName?: string;\n sheetName?: string;\n caseSensitive?: boolean;\n /**\n * Maximum number of matches returned by search(). Defaults to\n * DEFAULT_SEARCH_MAX_RESULTS to keep interactive UIs from materializing\n * enormous result sets. Pass Number.POSITIVE_INFINITY for an unbounded search.\n * replaceAll() ignores this option and always replaces all matches in scope.\n */\n maxResults?: number;\n}\n\nexport interface SearchMatch {\n workbookName: string;\n sheetName: string;\n cellReference: string;\n cellContent: string;\n contentKind: \"formula\" | \"text\";\n occurrenceIndex: number;\n startIndex: number;\n endIndexExclusive: number;\n matchedText: string;\n}\n\nexport interface ReplaceTarget {\n workbookName: string;\n sheetName: string;\n cellReference: string;\n occurrenceIndex: number;\n}\n\nexport interface ReplaceChange {\n workbookName: string;\n sheetName: string;\n cellReference: string;\n contentKind: \"formula\" | \"text\";\n occurrenceIndex: number;\n startIndex: number;\n endIndexExclusive: number;\n matchedText: string;\n replacementText: string;\n beforeContent: string;\n afterContent: string;\n}\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<TCellMetadata = unknown, TSheetMetadata = unknown> {\n name: string;\n index: number; // 0-based index of the sheet\n content: Map<string, SerializedCellValue>;\n /**\n * Cell metadata - arbitrary consumer-defined data per cell\n * Examples: rich text content, links, comments, custom app data\n * The engine stores and copies this data but doesn't interpret it\n * Keyed by cell reference (e.g., \"A1\")\n */\n metadata: Map<string, TCellMetadata>;\n /**\n * Sheet-level metadata - arbitrary consumer-defined data for the entire sheet\n * Examples: text boxes, drawings, frozen panes, print settings\n * The engine stores and copies this data but doesn't interpret it\n */\n sheetMetadata: TSheetMetadata;\n}\n\nexport interface Workbook<\n TCellMetadata = unknown,\n TSheetMetadata = unknown,\n TWorkbookMetadata = unknown\n> {\n name: string;\n sheets: Map<string, Sheet<TCellMetadata, TSheetMetadata>>;\n /**\n * Workbook-level metadata - arbitrary consumer-defined data for the entire workbook\n * Examples: themes, custom ribbons, document properties, workbook settings\n * The engine stores and copies this data but doesn't interpret it\n */\n workbookMetadata: TWorkbookMetadata;\n}\n\n/**\n * Tracked reference - a stable reference to a range that updates automatically\n * when workbooks/sheets are renamed and becomes invalid when they're deleted\n */\nexport interface TrackedReference {\n id: string; // UUID\n address: RangeAddress; // The range being tracked\n isValid: boolean; // False if sheet/workbook deleted\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 areas: RangeAddress[];\n condition: StyleCondition;\n}\n\nexport interface DirectCellStyle {\n areas: RangeAddress[];\n style: CellStyle;\n}\n\nexport interface RangeMetadata<TMetadata = unknown> {\n id: string;\n areas: RangeAddress[];\n metadata: TMetadata;\n}\n\nexport interface RangeMetadataInput<TMetadata = unknown> {\n id?: string;\n areas: RangeAddress[];\n metadata: TMetadata;\n}\n\nexport interface CellStyle {\n backgroundColor?: string; // Hex color format\n color?: string; // Text color in hex format\n borderColor?: string; // Border color in hex format\n borderSides?: {\n top?: boolean;\n right?: boolean;\n bottom?: boolean;\n left?: boolean;\n };\n fontSize?: number; // Font size in pixels\n bold?: boolean;\n italic?: boolean;\n underline?: boolean;\n wrapText?: boolean;\n}\n\nexport type CopyCellsIncludePart =\n | \"content\"\n | \"style\"\n | \"cellMetadata\"\n | \"rangeMetadata\";\n\nexport interface CopyCellsOptions {\n /**\n * Whether this is a cut operation (clears source cells after copying)\n * @default false\n */\n cut?: boolean;\n /**\n * What to include in the copy operation.\n * - Use 'all' as shorthand for ['content', 'style', 'cellMetadata', 'rangeMetadata']\n * - Use array for fine-grained control over what to copy:\n * - ['content'] - copy only values/formulas\n * - ['style'] - copy only formatting\n * - ['cellMetadata'] - copy only cell metadata (rich text, links, etc.)\n * - ['rangeMetadata'] - copy only range metadata\n * - ['content', 'style'] - copy content and formatting\n * - ['content', 'cellMetadata'] - copy content and cell metadata\n * - ['style', 'rangeMetadata'] - copy formatting and range metadata\n * - ['content', 'style', 'cellMetadata', 'rangeMetadata'] - same as 'all'\n * @default 'all'\n */\n include?: \"all\" | CopyCellsIncludePart[];\n /**\n * The type of the content to copy\n * value: Copy the value from the source to the target,\n * e.g. if the cell has the formula =123 + 123 then the value is 246\n * formula: Copy the formula from the source to the target,\n * e.g. if the cell has the formula =123 + 123 then the formula is =123 + 123 is copied\n * @default 'formula'\n */\n type?: \"value\" | \"formula\";\n}\n"
5
+ "/**\n * Core type definitions for FormulaEngine\n * This file contains all fundamental types used throughout the engine\n */\n\nimport type { EvaluationContext } from \"../evaluator/evaluation-context.cjs\";\nimport type { FormulaEvaluator } from \"../evaluator/formula-evaluator.cjs\";\nimport type { FunctionNode } from \"../parser/ast.cjs\";\nimport type { DependencyNode } from \"./managers/dependency-node.cjs\";\nimport type { LookupOrder } from \"./managers/range-eval-order-builder.cjs\";\n\nexport interface UndoRedoOptions {\n /**\n * Maximum number of undo entries retained by the engine.\n * @default 100\n */\n maxDepth?: number;\n}\n\nexport interface FormulaEngineOptions {\n /**\n * Configure engine-level undo/redo history. History is always enabled.\n */\n undoRedo?: UndoRedoOptions;\n}\n\nexport interface UndoRedoState {\n enabled: boolean;\n canUndo: boolean;\n canRedo: boolean;\n undoDepth: number;\n redoDepth: number;\n maxDepth: number;\n}\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\nexport const DEFAULT_SEARCH_MAX_RESULTS = 1000;\n\nexport interface SearchOptions {\n workbookName?: string;\n sheetName?: string;\n caseSensitive?: boolean;\n /**\n * Maximum number of matches returned by search(). Defaults to\n * DEFAULT_SEARCH_MAX_RESULTS to keep interactive UIs from materializing\n * enormous result sets. Pass Number.POSITIVE_INFINITY for an unbounded search.\n * replaceAll() ignores this option and always replaces all matches in scope.\n */\n maxResults?: number;\n}\n\nexport interface SearchMatch {\n workbookName: string;\n sheetName: string;\n cellReference: string;\n cellContent: string;\n contentKind: \"formula\" | \"text\";\n occurrenceIndex: number;\n startIndex: number;\n endIndexExclusive: number;\n matchedText: string;\n}\n\nexport interface ReplaceTarget {\n workbookName: string;\n sheetName: string;\n cellReference: string;\n occurrenceIndex: number;\n}\n\nexport interface ReplaceChange {\n workbookName: string;\n sheetName: string;\n cellReference: string;\n contentKind: \"formula\" | \"text\";\n occurrenceIndex: number;\n startIndex: number;\n endIndexExclusive: number;\n matchedText: string;\n replacementText: string;\n beforeContent: string;\n afterContent: string;\n}\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<TCellMetadata = unknown, TSheetMetadata = unknown> {\n name: string;\n index: number; // 0-based index of the sheet\n content: Map<string, SerializedCellValue>;\n /**\n * Cell metadata - arbitrary consumer-defined data per cell\n * Examples: rich text content, links, comments, custom app data\n * The engine stores and copies this data but doesn't interpret it\n * Keyed by cell reference (e.g., \"A1\")\n */\n metadata: Map<string, TCellMetadata>;\n /**\n * Sheet-level metadata - arbitrary consumer-defined data for the entire sheet\n * Examples: text boxes, drawings, frozen panes, print settings\n * The engine stores and copies this data but doesn't interpret it\n */\n sheetMetadata: TSheetMetadata;\n}\n\nexport interface Workbook<\n TCellMetadata = unknown,\n TSheetMetadata = unknown,\n TWorkbookMetadata = unknown\n> {\n name: string;\n sheets: Map<string, Sheet<TCellMetadata, TSheetMetadata>>;\n /**\n * Workbook-level metadata - arbitrary consumer-defined data for the entire workbook\n * Examples: themes, custom ribbons, document properties, workbook settings\n * The engine stores and copies this data but doesn't interpret it\n */\n workbookMetadata: TWorkbookMetadata;\n}\n\n/**\n * Tracked reference - a stable reference to a range that updates automatically\n * when workbooks/sheets are renamed and becomes invalid when they're deleted\n */\nexport interface TrackedReference {\n id: string; // UUID\n address: RangeAddress; // The range being tracked\n isValid: boolean; // False if sheet/workbook deleted\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 areas: RangeAddress[];\n condition: StyleCondition;\n}\n\nexport interface DirectCellStyle {\n areas: RangeAddress[];\n style: CellStyle;\n}\n\nexport interface RangeMetadata<TMetadata = unknown> {\n id: string;\n areas: RangeAddress[];\n metadata: TMetadata;\n}\n\nexport interface RangeMetadataInput<TMetadata = unknown> {\n id?: string;\n areas: RangeAddress[];\n metadata: TMetadata;\n}\n\nexport interface CellStyle {\n backgroundColor?: string; // Hex color format\n color?: string; // Text color in hex format\n borderColor?: string; // Border color in hex format\n borderSides?: {\n top?: boolean;\n right?: boolean;\n bottom?: boolean;\n left?: boolean;\n };\n fontSize?: number; // Font size in pixels\n bold?: boolean;\n italic?: boolean;\n underline?: boolean;\n wrapText?: boolean;\n}\n\nexport type CopyCellsIncludePart =\n | \"content\"\n | \"style\"\n | \"cellMetadata\"\n | \"rangeMetadata\";\n\nexport interface CopyCellsOptions {\n /**\n * Whether this is a cut operation (clears source cells after copying)\n * @default false\n */\n cut?: boolean;\n /**\n * What to include in the copy operation.\n * - Use 'all' as shorthand for ['content', 'style', 'cellMetadata', 'rangeMetadata']\n * - Use array for fine-grained control over what to copy:\n * - ['content'] - copy only values/formulas\n * - ['style'] - copy only formatting\n * - ['cellMetadata'] - copy only cell metadata (rich text, links, etc.)\n * - ['rangeMetadata'] - copy only range metadata\n * - ['content', 'style'] - copy content and formatting\n * - ['content', 'cellMetadata'] - copy content and cell metadata\n * - ['style', 'rangeMetadata'] - copy formatting and range metadata\n * - ['content', 'style', 'cellMetadata', 'rangeMetadata'] - same as 'all'\n * @default 'all'\n */\n include?: \"all\" | CopyCellsIncludePart[];\n /**\n * The type of the content to copy\n * value: Copy the value from the source to the target,\n * e.g. if the cell has the formula =123 + 123 then the value is 246\n * formula: Copy the formula from the source to the target,\n * e.g. if the cell has the formula =123 + 123 then the formula is =123 + 123 is copied\n * @default 'formula'\n */\n type?: \"value\" | \"formula\";\n}\n"
6
6
  ],
7
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAwGO,IAAM,6BAA6B;AAmEnC,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;",
7
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgIO,IAAM,6BAA6B;AAmEnC,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": "C1CCF1E476C387F864756E2164756E21",
9
9
  "names": []
10
10
  }
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "@ricsam/formula-engine",
3
- "version": "0.2.14",
3
+ "version": "0.2.15",
4
4
  "type": "commonjs"
5
5
  }
@@ -2,9 +2,9 @@
2
2
  "version": 3,
3
3
  "sources": ["../../../src/core/engine-snapshot.ts"],
4
4
  "sourcesContent": [
5
- "import type { ContextDependency } from \"../evaluator/evaluation-context.mjs\";\nimport type { DependencyNode } from \"./managers/dependency-node.mjs\";\nimport type {\n CellAddress,\n CellInRangeResult,\n CellValue,\n ConditionalStyle,\n DirectCellStyle,\n FormulaError,\n NamedExpression,\n RangeAddress,\n RangeMetadata,\n RelativeRange,\n SpreadsheetRange,\n TableDefinition,\n TrackedReference,\n Workbook,\n} from \"./types.mjs\";\n\nexport const ENGINE_SNAPSHOT_VERSION = 5 as const;\n\nexport type NodeSnapshotId = string;\n\nexport type NamedExpressionManagerSnapshot = {\n sheetExpressions: Map<string, Map<string, Map<string, NamedExpression>>>;\n workbookExpressions: Map<string, Map<string, NamedExpression>>;\n globalExpressions: Map<string, NamedExpression>;\n};\n\nexport type WorkbookManagerSnapshot = Map<string, Workbook>;\n\nexport type TableManagerSnapshot = Map<string, Map<string, TableDefinition>>;\n\nexport type StyleManagerSnapshot = {\n conditionalStyles: ConditionalStyle[];\n cellStyles: DirectCellStyle[];\n};\n\nexport type RangeMetadataManagerSnapshot = RangeMetadata[];\n\nexport type ReferenceManagerSnapshot = Map<string, TrackedReference>;\n\nexport type SerializedValueEvaluationResultSnapshot = {\n type: \"value\";\n result: CellValue;\n sourceCell?: CellAddress;\n};\n\nexport type SerializedErrorEvaluationResultSnapshot = {\n type: \"error\";\n err: FormulaError;\n message: string;\n errAddressId: NodeSnapshotId;\n sourceCell?: CellAddress;\n};\n\nexport type SerializedSingleEvaluationResultSnapshot =\n | SerializedValueEvaluationResultSnapshot\n | SerializedErrorEvaluationResultSnapshot;\n\nexport type SerializedCellInRangeResultSnapshot = {\n relativePos: CellInRangeResult[\"relativePos\"];\n result: SerializedSingleEvaluationResultSnapshot;\n};\n\nexport type SerializedEvaluateAllCellsResultSnapshot =\n | SerializedErrorEvaluationResultSnapshot\n | {\n type: \"values\";\n values: SerializedCellInRangeResultSnapshot[];\n };\n\nexport type SerializedMaterializedSpillSnapshot = {\n kind: \"materialized\";\n relativeSpillArea: RelativeRange;\n source: string;\n sourceCell?: CellAddress;\n sourceRange?: RangeAddress;\n values: SerializedCellInRangeResultSnapshot[];\n};\n\nexport type SerializedSourceRangeSpillSnapshot = {\n kind: \"source-range\";\n relativeSpillArea: RelativeRange;\n source: string;\n sourceCell?: CellAddress;\n sourceRange: RangeAddress;\n};\n\nexport type SerializedSpillResultSnapshot =\n | SerializedMaterializedSpillSnapshot\n | SerializedSourceRangeSpillSnapshot;\n\nexport type SerializedSpilledValuesEvaluationResultSnapshot = {\n type: \"spilled-values\";\n spill: SerializedSpillResultSnapshot;\n};\n\nexport type SerializedFunctionEvaluationResultSnapshot =\n | SerializedSingleEvaluationResultSnapshot\n | SerializedSpilledValuesEvaluationResultSnapshot;\n\nexport type SerializedSpillMetaEvaluationResultSnapshot =\n | SerializedErrorEvaluationResultSnapshot\n | SerializedSpilledValuesEvaluationResultSnapshot\n | {\n type: \"does-not-spill\";\n };\n\ntype SerializedBaseNodeSnapshot = {\n snapshotId: NodeSnapshotId;\n key: string;\n dependencies: NodeSnapshotId[];\n};\n\nexport type SerializedCellValueNodeSnapshot = SerializedBaseNodeSnapshot & {\n kind: \"cell-value\";\n evaluationResult: SerializedSingleEvaluationResultSnapshot;\n spillMetaSnapshotId?: NodeSnapshotId;\n};\n\nexport type SerializedSpillMetaNodeSnapshot = SerializedBaseNodeSnapshot & {\n kind: \"spill-meta\";\n evaluationResult: SerializedSpillMetaEvaluationResultSnapshot;\n};\n\nexport type SerializedEmptyCellNodeSnapshot = SerializedBaseNodeSnapshot & {\n kind: \"empty\";\n evaluationResult: SerializedSingleEvaluationResultSnapshot;\n};\n\nexport type SerializedRangeNodeSnapshot = SerializedBaseNodeSnapshot & {\n kind: \"range\";\n result: SerializedEvaluateAllCellsResultSnapshot;\n};\n\nexport type SerializedAstNodeSnapshot = SerializedBaseNodeSnapshot & {\n kind: \"ast\";\n contextDependency: ContextDependency;\n evaluationResult: SerializedFunctionEvaluationResultSnapshot;\n};\n\nexport type SerializedResourceNodeSnapshot = SerializedBaseNodeSnapshot & {\n kind: \"resource\";\n};\n\nexport type SerializedDependencyNodeSnapshot =\n | SerializedCellValueNodeSnapshot\n | SerializedSpillMetaNodeSnapshot\n | SerializedEmptyCellNodeSnapshot\n | SerializedRangeNodeSnapshot\n | SerializedAstNodeSnapshot\n | SerializedResourceNodeSnapshot;\n\nexport type DependencyManagerSnapshot = {\n nodes: SerializedDependencyNodeSnapshot[];\n spilledValues: Array<[string, { origin: CellAddress; spillOnto: SpreadsheetRange }]>;\n};\n\nexport type SerializedSCCSnapshot = {\n id: number;\n nodes: NodeSnapshotId[];\n evaluationOrder: NodeSnapshotId[];\n resolved: boolean;\n hardEdgeSCCs: NodeSnapshotId[][];\n};\n\nexport type SerializedEvaluationOrderSnapshot = {\n nodeKey: string;\n evaluationOrder: NodeSnapshotId[];\n hasCycle: boolean;\n cycleNodes?: NodeSnapshotId[];\n hash: string;\n};\n\nexport type CacheManagerSnapshot = {\n evaluationOrders: SerializedEvaluationOrderSnapshot[];\n sccs: Array<{\n hash: string;\n scc: SerializedSCCSnapshot;\n }>;\n};\n\ntype EngineSnapshotManagers = {\n workbook: WorkbookManagerSnapshot;\n namedExpression: NamedExpressionManagerSnapshot;\n table: TableManagerSnapshot;\n style: StyleManagerSnapshot;\n rangeMetadata: RangeMetadataManagerSnapshot;\n reference: ReferenceManagerSnapshot;\n dependency: DependencyManagerSnapshot;\n cache: CacheManagerSnapshot;\n};\n\nexport type EngineSnapshot = {\n version: typeof ENGINE_SNAPSHOT_VERSION;\n managers: EngineSnapshotManagers;\n};\n\nexport function getAstNodeSnapshotId(\n node: DependencyNode & { getContextDependency(): ContextDependency }\n): NodeSnapshotId {\n return `${node.key}::${JSON.stringify(node.getContextDependency())}`;\n}\n"
5
+ "import type { ContextDependency } from \"../evaluator/evaluation-context.mjs\";\nimport type { DependencyNode } from \"./managers/dependency-node.mjs\";\nimport type {\n CellAddress,\n CellInRangeResult,\n CellValue,\n ConditionalStyle,\n DirectCellStyle,\n FormulaError,\n NamedExpression,\n RangeAddress,\n RangeMetadata,\n RelativeRange,\n SpreadsheetRange,\n TableDefinition,\n TrackedReference,\n Workbook,\n} from \"./types.mjs\";\n\nexport const ENGINE_SNAPSHOT_VERSION = 5 as const;\n\nexport type NodeSnapshotId = string;\n\nexport type NamedExpressionManagerSnapshot = {\n sheetExpressions: Map<string, Map<string, Map<string, NamedExpression>>>;\n workbookExpressions: Map<string, Map<string, NamedExpression>>;\n globalExpressions: Map<string, NamedExpression>;\n};\n\nexport type WorkbookManagerSnapshot = Map<string, Workbook>;\n\nexport type TableManagerSnapshot = Map<string, Map<string, TableDefinition>>;\n\nexport type StyleManagerSnapshot = {\n conditionalStyles: ConditionalStyle[];\n cellStyles: DirectCellStyle[];\n};\n\nexport type RangeMetadataManagerSnapshot = RangeMetadata[];\n\nexport type ReferenceManagerSnapshot = Map<string, TrackedReference>;\n\nexport type EngineHistorySnapshotManagers = {\n workbook: WorkbookManagerSnapshot;\n namedExpression: NamedExpressionManagerSnapshot;\n table: TableManagerSnapshot;\n style: StyleManagerSnapshot;\n rangeMetadata: RangeMetadataManagerSnapshot;\n reference: ReferenceManagerSnapshot;\n};\n\nexport type EngineHistorySnapshot = {\n version: typeof ENGINE_SNAPSHOT_VERSION;\n managers: EngineHistorySnapshotManagers;\n};\n\nexport type SerializedValueEvaluationResultSnapshot = {\n type: \"value\";\n result: CellValue;\n sourceCell?: CellAddress;\n};\n\nexport type SerializedErrorEvaluationResultSnapshot = {\n type: \"error\";\n err: FormulaError;\n message: string;\n errAddressId: NodeSnapshotId;\n sourceCell?: CellAddress;\n};\n\nexport type SerializedSingleEvaluationResultSnapshot =\n | SerializedValueEvaluationResultSnapshot\n | SerializedErrorEvaluationResultSnapshot;\n\nexport type SerializedCellInRangeResultSnapshot = {\n relativePos: CellInRangeResult[\"relativePos\"];\n result: SerializedSingleEvaluationResultSnapshot;\n};\n\nexport type SerializedEvaluateAllCellsResultSnapshot =\n | SerializedErrorEvaluationResultSnapshot\n | {\n type: \"values\";\n values: SerializedCellInRangeResultSnapshot[];\n };\n\nexport type SerializedMaterializedSpillSnapshot = {\n kind: \"materialized\";\n relativeSpillArea: RelativeRange;\n source: string;\n sourceCell?: CellAddress;\n sourceRange?: RangeAddress;\n values: SerializedCellInRangeResultSnapshot[];\n};\n\nexport type SerializedSourceRangeSpillSnapshot = {\n kind: \"source-range\";\n relativeSpillArea: RelativeRange;\n source: string;\n sourceCell?: CellAddress;\n sourceRange: RangeAddress;\n};\n\nexport type SerializedSpillResultSnapshot =\n | SerializedMaterializedSpillSnapshot\n | SerializedSourceRangeSpillSnapshot;\n\nexport type SerializedSpilledValuesEvaluationResultSnapshot = {\n type: \"spilled-values\";\n spill: SerializedSpillResultSnapshot;\n};\n\nexport type SerializedFunctionEvaluationResultSnapshot =\n | SerializedSingleEvaluationResultSnapshot\n | SerializedSpilledValuesEvaluationResultSnapshot;\n\nexport type SerializedSpillMetaEvaluationResultSnapshot =\n | SerializedErrorEvaluationResultSnapshot\n | SerializedSpilledValuesEvaluationResultSnapshot\n | {\n type: \"does-not-spill\";\n };\n\ntype SerializedBaseNodeSnapshot = {\n snapshotId: NodeSnapshotId;\n key: string;\n dependencies: NodeSnapshotId[];\n};\n\nexport type SerializedCellValueNodeSnapshot = SerializedBaseNodeSnapshot & {\n kind: \"cell-value\";\n evaluationResult: SerializedSingleEvaluationResultSnapshot;\n spillMetaSnapshotId?: NodeSnapshotId;\n};\n\nexport type SerializedSpillMetaNodeSnapshot = SerializedBaseNodeSnapshot & {\n kind: \"spill-meta\";\n evaluationResult: SerializedSpillMetaEvaluationResultSnapshot;\n};\n\nexport type SerializedEmptyCellNodeSnapshot = SerializedBaseNodeSnapshot & {\n kind: \"empty\";\n evaluationResult: SerializedSingleEvaluationResultSnapshot;\n};\n\nexport type SerializedRangeNodeSnapshot = SerializedBaseNodeSnapshot & {\n kind: \"range\";\n result: SerializedEvaluateAllCellsResultSnapshot;\n};\n\nexport type SerializedAstNodeSnapshot = SerializedBaseNodeSnapshot & {\n kind: \"ast\";\n contextDependency: ContextDependency;\n evaluationResult: SerializedFunctionEvaluationResultSnapshot;\n};\n\nexport type SerializedResourceNodeSnapshot = SerializedBaseNodeSnapshot & {\n kind: \"resource\";\n};\n\nexport type SerializedDependencyNodeSnapshot =\n | SerializedCellValueNodeSnapshot\n | SerializedSpillMetaNodeSnapshot\n | SerializedEmptyCellNodeSnapshot\n | SerializedRangeNodeSnapshot\n | SerializedAstNodeSnapshot\n | SerializedResourceNodeSnapshot;\n\nexport type DependencyManagerSnapshot = {\n nodes: SerializedDependencyNodeSnapshot[];\n spilledValues: Array<[string, { origin: CellAddress; spillOnto: SpreadsheetRange }]>;\n};\n\nexport type SerializedSCCSnapshot = {\n id: number;\n nodes: NodeSnapshotId[];\n evaluationOrder: NodeSnapshotId[];\n resolved: boolean;\n hardEdgeSCCs: NodeSnapshotId[][];\n};\n\nexport type SerializedEvaluationOrderSnapshot = {\n nodeKey: string;\n evaluationOrder: NodeSnapshotId[];\n hasCycle: boolean;\n cycleNodes?: NodeSnapshotId[];\n hash: string;\n};\n\nexport type CacheManagerSnapshot = {\n evaluationOrders: SerializedEvaluationOrderSnapshot[];\n sccs: Array<{\n hash: string;\n scc: SerializedSCCSnapshot;\n }>;\n};\n\ntype EngineSnapshotManagers = EngineHistorySnapshotManagers & {\n dependency: DependencyManagerSnapshot;\n cache: CacheManagerSnapshot;\n};\n\nexport type EngineSnapshot = {\n version: typeof ENGINE_SNAPSHOT_VERSION;\n managers: EngineSnapshotManagers;\n};\n\nexport function getAstNodeSnapshotId(\n node: DependencyNode & { getContextDependency(): ContextDependency }\n): NodeSnapshotId {\n return `${node.key}::${JSON.stringify(node.getContextDependency())}`;\n}\n"
6
6
  ],
7
- "mappings": ";AAmBO,IAAM,0BAA0B;AAoLhC,SAAS,oBAAoB,CAClC,MACgB;AAAA,EAChB,OAAO,GAAG,KAAK,QAAQ,KAAK,UAAU,KAAK,qBAAqB,CAAC;AAAA;",
7
+ "mappings": ";AAmBO,IAAM,0BAA0B;AA4LhC,SAAS,oBAAoB,CAClC,MACgB;AAAA,EAChB,OAAO,GAAG,KAAK,QAAQ,KAAK,UAAU,KAAK,qBAAqB,CAAC;AAAA;",
8
8
  "debugId": "024E0D4A5B98A79764756E2164756E21",
9
9
  "names": []
10
10
  }