@ricsam/formula-engine 0.2.8 → 0.2.10

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.
Files changed (130) hide show
  1. package/README.md +41 -3
  2. package/dist/cjs/core/engine.cjs +551 -166
  3. package/dist/cjs/core/engine.cjs.map +3 -3
  4. package/dist/cjs/core/managers/dependency-manager.cjs +151 -67
  5. package/dist/cjs/core/managers/dependency-manager.cjs.map +3 -3
  6. package/dist/cjs/core/managers/evaluation-manager.cjs.map +1 -1
  7. package/dist/cjs/core/managers/workbook-manager.cjs +197 -1
  8. package/dist/cjs/core/managers/workbook-manager.cjs.map +3 -3
  9. package/dist/cjs/core/mutation-invalidation.cjs +241 -0
  10. package/dist/cjs/core/mutation-invalidation.cjs.map +10 -0
  11. package/dist/cjs/core/types.cjs.map +2 -2
  12. package/dist/cjs/core/workbook-renamer.cjs.map +1 -1
  13. package/dist/cjs/evaluator/formula-evaluator.cjs +22 -48
  14. package/dist/cjs/evaluator/formula-evaluator.cjs.map +3 -3
  15. package/dist/cjs/functions/math/sum/summation-utils.cjs +2 -2
  16. package/dist/cjs/functions/math/sum/summation-utils.cjs.map +2 -2
  17. package/dist/cjs/lib.cjs +2 -13
  18. package/dist/cjs/lib.cjs.map +3 -3
  19. package/dist/cjs/package.json +1 -1
  20. package/dist/cjs/parser/formatter.cjs +3 -4
  21. package/dist/cjs/parser/formatter.cjs.map +3 -3
  22. package/dist/cjs/parser/parser.cjs +24 -216
  23. package/dist/cjs/parser/parser.cjs.map +3 -3
  24. package/dist/mjs/core/engine.mjs +565 -207
  25. package/dist/mjs/core/engine.mjs.map +3 -3
  26. package/dist/mjs/core/managers/dependency-manager.mjs +151 -67
  27. package/dist/mjs/core/managers/dependency-manager.mjs.map +3 -3
  28. package/dist/mjs/core/managers/evaluation-manager.mjs.map +1 -1
  29. package/dist/mjs/core/managers/workbook-manager.mjs +197 -1
  30. package/dist/mjs/core/managers/workbook-manager.mjs.map +3 -3
  31. package/dist/mjs/core/mutation-invalidation.mjs +201 -0
  32. package/dist/mjs/core/mutation-invalidation.mjs.map +10 -0
  33. package/dist/mjs/core/types.mjs.map +2 -2
  34. package/dist/mjs/core/workbook-renamer.mjs.map +1 -1
  35. package/dist/mjs/evaluator/formula-evaluator.mjs +22 -48
  36. package/dist/mjs/evaluator/formula-evaluator.mjs.map +3 -3
  37. package/dist/mjs/functions/math/sum/summation-utils.mjs +2 -2
  38. package/dist/mjs/functions/math/sum/summation-utils.mjs.map +2 -2
  39. package/dist/mjs/lib.mjs +2 -13
  40. package/dist/mjs/lib.mjs.map +3 -3
  41. package/dist/mjs/package.json +1 -1
  42. package/dist/mjs/parser/formatter.mjs +3 -4
  43. package/dist/mjs/parser/formatter.mjs.map +3 -3
  44. package/dist/mjs/parser/parser.mjs +24 -216
  45. package/dist/mjs/parser/parser.mjs.map +3 -3
  46. package/dist/types/core/engine.d.ts +31 -135
  47. package/dist/types/core/managers/dependency-manager.d.ts +5 -1
  48. package/dist/types/core/managers/evaluation-manager.d.ts +1 -1
  49. package/dist/types/core/managers/workbook-manager.d.ts +23 -1
  50. package/dist/types/core/mutation-invalidation.d.ts +46 -0
  51. package/dist/types/core/types.d.ts +35 -0
  52. package/dist/types/lib.d.ts +0 -8
  53. package/dist/types/parser/parser.d.ts +4 -6
  54. package/package.json +1 -1
  55. package/dist/cjs/core/commands/command-executor.cjs +0 -149
  56. package/dist/cjs/core/commands/command-executor.cjs.map +0 -10
  57. package/dist/cjs/core/commands/content-commands.cjs +0 -857
  58. package/dist/cjs/core/commands/content-commands.cjs.map +0 -10
  59. package/dist/cjs/core/commands/metadata-commands.cjs +0 -160
  60. package/dist/cjs/core/commands/metadata-commands.cjs.map +0 -10
  61. package/dist/cjs/core/commands/named-expression-commands.cjs +0 -363
  62. package/dist/cjs/core/commands/named-expression-commands.cjs.map +0 -10
  63. package/dist/cjs/core/commands/structure-commands.cjs +0 -696
  64. package/dist/cjs/core/commands/structure-commands.cjs.map +0 -10
  65. package/dist/cjs/core/commands/style-commands.cjs +0 -229
  66. package/dist/cjs/core/commands/style-commands.cjs.map +0 -10
  67. package/dist/cjs/core/commands/table-commands.cjs +0 -495
  68. package/dist/cjs/core/commands/table-commands.cjs.map +0 -10
  69. package/dist/cjs/core/commands/types.cjs +0 -99
  70. package/dist/cjs/core/commands/types.cjs.map +0 -10
  71. package/dist/cjs/core/managers/schema-manager.cjs +0 -374
  72. package/dist/cjs/core/managers/schema-manager.cjs.map +0 -10
  73. package/dist/cjs/core/schema/cell-orm.cjs +0 -76
  74. package/dist/cjs/core/schema/cell-orm.cjs.map +0 -10
  75. package/dist/cjs/core/schema/grid-orm.cjs +0 -125
  76. package/dist/cjs/core/schema/grid-orm.cjs.map +0 -10
  77. package/dist/cjs/core/schema/schema-builder.cjs +0 -74
  78. package/dist/cjs/core/schema/schema-builder.cjs.map +0 -10
  79. package/dist/cjs/core/schema/schema-helpers.cjs +0 -200
  80. package/dist/cjs/core/schema/schema-helpers.cjs.map +0 -10
  81. package/dist/cjs/core/schema/schema.cjs +0 -91
  82. package/dist/cjs/core/schema/schema.cjs.map +0 -10
  83. package/dist/cjs/core/schema/table-orm.cjs +0 -189
  84. package/dist/cjs/core/schema/table-orm.cjs.map +0 -10
  85. package/dist/mjs/core/commands/command-executor.mjs +0 -109
  86. package/dist/mjs/core/commands/command-executor.mjs.map +0 -10
  87. package/dist/mjs/core/commands/content-commands.mjs +0 -821
  88. package/dist/mjs/core/commands/content-commands.mjs.map +0 -10
  89. package/dist/mjs/core/commands/metadata-commands.mjs +0 -120
  90. package/dist/mjs/core/commands/metadata-commands.mjs.map +0 -10
  91. package/dist/mjs/core/commands/named-expression-commands.mjs +0 -323
  92. package/dist/mjs/core/commands/named-expression-commands.mjs.map +0 -10
  93. package/dist/mjs/core/commands/structure-commands.mjs +0 -661
  94. package/dist/mjs/core/commands/structure-commands.mjs.map +0 -10
  95. package/dist/mjs/core/commands/style-commands.mjs +0 -189
  96. package/dist/mjs/core/commands/style-commands.mjs.map +0 -10
  97. package/dist/mjs/core/commands/table-commands.mjs +0 -459
  98. package/dist/mjs/core/commands/table-commands.mjs.map +0 -10
  99. package/dist/mjs/core/commands/types.mjs +0 -59
  100. package/dist/mjs/core/commands/types.mjs.map +0 -10
  101. package/dist/mjs/core/managers/schema-manager.mjs +0 -334
  102. package/dist/mjs/core/managers/schema-manager.mjs.map +0 -10
  103. package/dist/mjs/core/schema/cell-orm.mjs +0 -35
  104. package/dist/mjs/core/schema/cell-orm.mjs.map +0 -10
  105. package/dist/mjs/core/schema/grid-orm.mjs +0 -84
  106. package/dist/mjs/core/schema/grid-orm.mjs.map +0 -10
  107. package/dist/mjs/core/schema/schema-builder.mjs +0 -34
  108. package/dist/mjs/core/schema/schema-builder.mjs.map +0 -10
  109. package/dist/mjs/core/schema/schema-helpers.mjs +0 -160
  110. package/dist/mjs/core/schema/schema-helpers.mjs.map +0 -10
  111. package/dist/mjs/core/schema/schema.mjs +0 -51
  112. package/dist/mjs/core/schema/schema.mjs.map +0 -10
  113. package/dist/mjs/core/schema/table-orm.mjs +0 -156
  114. package/dist/mjs/core/schema/table-orm.mjs.map +0 -10
  115. package/dist/types/core/commands/command-executor.d.ts +0 -81
  116. package/dist/types/core/commands/content-commands.d.ts +0 -172
  117. package/dist/types/core/commands/metadata-commands.d.ts +0 -55
  118. package/dist/types/core/commands/named-expression-commands.d.ts +0 -130
  119. package/dist/types/core/commands/structure-commands.d.ts +0 -155
  120. package/dist/types/core/commands/style-commands.d.ts +0 -76
  121. package/dist/types/core/commands/table-commands.d.ts +0 -119
  122. package/dist/types/core/commands/types.d.ts +0 -143
  123. package/dist/types/core/managers/schema-manager.d.ts +0 -142
  124. package/dist/types/core/schema/cell-orm.d.ts +0 -33
  125. package/dist/types/core/schema/grid-orm.d.ts +0 -63
  126. package/dist/types/core/schema/schema-builder.d.ts +0 -16
  127. package/dist/types/core/schema/schema-helpers.d.ts +0 -49
  128. package/dist/types/core/schema/schema.d.ts +0 -167
  129. package/dist/types/core/schema/schema.type-test.d.ts +0 -1
  130. package/dist/types/core/schema/table-orm.d.ts +0 -46
@@ -2,9 +2,9 @@
2
2
  "version": 3,
3
3
  "sources": ["../../../../src/core/managers/workbook-manager.ts"],
4
4
  "sourcesContent": [
5
- "import {\n FormulaError,\n type CellAddress,\n type FiniteSpreadsheetRange,\n type LocalCellAddress,\n type SerializedCellValue,\n type Sheet,\n type SpreadsheetRange,\n type Workbook,\n} from \"../types.mjs\";\nimport type { WorkbookManagerSnapshot } from \"../engine-snapshot.mjs\";\nimport { getCellReference, parseCellReference } from \"../utils.mjs\";\n\nimport type { RangeAddress } from \"../types.mjs\";\nimport { buildRangeEvalOrder } from \"./range-eval-order-builder.mjs\";\nimport {\n EvaluationError,\n SheetNotFoundError,\n WorkbookNotFoundError,\n} from \"../../evaluator/evaluation-error.mjs\";\nimport { normalizeSerializedCellValue } from \"../../parser/formatter.mjs\";\n\ninterface IndexEntry {\n number: number;\n key: string;\n}\n\nexport interface SheetIndexes {\n // lookup maps - cells grouped by row/column\n rowGroups: Map<number, IndexEntry[]>; // row number -> cells in that row (sorted by col)\n colGroups: Map<number, IndexEntry[]>; // col number -> cells in that col (sorted by row)\n\n // Sorted flat indexes - for finding cells before a given row/col\n cellsSortedByRow: IndexEntry[];\n cellsSortedByCol: IndexEntry[];\n}\n\n/**\n * Utility class for binary search operations on IndexEntry arrays\n */\nexport class IndexEntryBinarySearch {\n /**\n * Find the insertion point for a number in a sorted IndexEntry array\n * Returns the index where the number should be inserted to maintain sort order\n */\n static findInsertionPoint(entries: IndexEntry[], target: number): number {\n let left = 0;\n let right = entries.length;\n\n while (left < right) {\n const mid = Math.floor((left + right) / 2);\n const midEntry = entries[mid];\n if (midEntry && midEntry.number < target) {\n left = mid + 1;\n } else {\n right = mid;\n }\n }\n\n return left;\n }\n\n /**\n * Find the first element >= target\n * Returns the index of the first element, or -1 if not found\n */\n static findFirstGreaterOrEqual(\n entries: IndexEntry[],\n target: number\n ): number {\n if (entries.length === 0) return -1;\n\n let left = 0;\n let right = entries.length - 1;\n let result = -1;\n\n while (left <= right) {\n const mid = Math.floor((left + right) / 2);\n const midEntry = entries[mid];\n if (midEntry && midEntry.number >= target) {\n result = mid;\n right = mid - 1;\n } else {\n left = mid + 1;\n }\n }\n\n return result;\n }\n\n /**\n * Find the rightmost position where we could insert a target value\n * Useful for finding elements that come before a target\n */\n static findRightmostInsertionPoint(\n entries: IndexEntry[],\n target: number\n ): number {\n return IndexEntryBinarySearch.findInsertionPoint(entries, target);\n }\n}\n\nexport class WorkbookManager {\n private workbooks: Map<string, Workbook> = new Map();\n\n // Map from \"workbookName|sheetName\" to indexes\n private sheetIndexes: Map<string, SheetIndexes> = new Map();\n\n /**\n * Generate a key for the sheet indexes map\n */\n private getSheetIndexKey(workbookName: string, sheetName: string): string {\n return `${workbookName}|${sheetName}`;\n }\n\n /**\n * Get or create indexes for a sheet\n */\n public getSheetIndexes(opts: {\n workbookName: string;\n sheetName: string;\n }): SheetIndexes {\n const key = this.getSheetIndexKey(opts.workbookName, opts.sheetName);\n let indexes = this.sheetIndexes.get(key);\n\n if (!indexes) {\n indexes = {\n rowGroups: new Map(),\n colGroups: new Map(),\n cellsSortedByRow: [],\n cellsSortedByCol: [],\n };\n this.sheetIndexes.set(key, indexes);\n }\n\n return indexes;\n }\n\n getSheets(workbookName: string): Map<string, Sheet> {\n const workbook = this.workbooks.get(workbookName);\n if (!workbook) {\n throw new WorkbookNotFoundError(workbookName);\n }\n return workbook.sheets;\n }\n\n getOrderedSheets(workbookName: string): Sheet[] {\n const workbook = this.workbooks.get(workbookName);\n if (!workbook) {\n throw new WorkbookNotFoundError(workbookName);\n }\n\n return Array.from(workbook.sheets.entries())\n .map(([name, sheet], insertionOrder) => ({\n name,\n sheet,\n insertionOrder,\n }))\n .sort((left, right) => {\n if (left.sheet.index !== right.sheet.index) {\n return left.sheet.index - right.sheet.index;\n }\n return left.insertionOrder - right.insertionOrder;\n })\n .map(({ sheet }) => sheet);\n }\n\n getOrderedSheetNames(workbookName: string): string[] {\n return this.getOrderedSheets(workbookName).map((sheet) => sheet.name);\n }\n\n getNextAvailableSheetName(\n workbookName: string,\n baseName: string = \"Sheet\"\n ): string {\n const workbook = this.workbooks.get(workbookName);\n if (!workbook) {\n throw new WorkbookNotFoundError(workbookName);\n }\n\n let suffix = 1;\n while (workbook.sheets.has(`${baseName}${suffix}`)) {\n suffix++;\n }\n\n return `${baseName}${suffix}`;\n }\n\n getWorkbooks(): Map<string, Workbook> {\n return this.workbooks;\n }\n\n addWorkbook(workbookName: string): void {\n if (this.workbooks.has(workbookName)) {\n throw new Error(\"Workbook already exists\");\n }\n this.workbooks.set(workbookName, {\n name: workbookName,\n sheets: new Map(),\n workbookMetadata: undefined,\n });\n }\n\n removeWorkbook(workbookName: string): void {\n const workbook = this.workbooks.get(workbookName);\n if (!workbook) {\n throw new WorkbookNotFoundError(workbookName);\n }\n\n // Clean up indexes for all sheets in this workbook\n for (const sheetName of workbook.sheets.keys()) {\n const key = this.getSheetIndexKey(workbookName, sheetName);\n this.sheetIndexes.delete(key);\n }\n\n this.workbooks.delete(workbookName);\n }\n\n isContentEmpty(content: SerializedCellValue): boolean {\n return content === \"\" || content === undefined;\n }\n\n renameWorkbook(opts: {\n workbookName: string;\n newWorkbookName: string;\n }): void {\n const workbook = this.workbooks.get(opts.workbookName);\n if (!workbook) {\n throw new Error(\"Workbook not found\");\n }\n\n // Update indexes for all sheets in this workbook\n for (const sheetName of workbook.sheets.keys()) {\n const oldKey = this.getSheetIndexKey(opts.workbookName, sheetName);\n const newKey = this.getSheetIndexKey(opts.newWorkbookName, sheetName);\n const indexes = this.sheetIndexes.get(oldKey);\n if (indexes) {\n this.sheetIndexes.set(newKey, indexes);\n this.sheetIndexes.delete(oldKey);\n }\n }\n\n this.workbooks.set(opts.newWorkbookName, workbook);\n this.workbooks.delete(opts.workbookName);\n workbook.name = opts.newWorkbookName;\n }\n\n resetWorkbooks(workbooks: Map<string, Workbook>): void {\n this.workbooks.clear();\n this.sheetIndexes.clear();\n\n workbooks.forEach((workbook, workbookName) => {\n this.workbooks.set(workbookName, workbook);\n workbook.sheets.forEach((sheet) => {\n // Initialize indexes for this sheet\n const indexes = this.getSheetIndexes({\n workbookName,\n sheetName: sheet.name,\n });\n indexes.rowGroups.clear();\n indexes.colGroups.clear();\n indexes.cellsSortedByRow = [];\n indexes.cellsSortedByCol = [];\n\n sheet.content.forEach((value, key) => {\n this.setCellContent(\n {\n workbookName,\n sheetName: sheet.name,\n colIndex: parseCellReference(key).colIndex,\n rowIndex: parseCellReference(key).rowIndex,\n },\n value,\n {\n sheet,\n buildingFromScratch: true,\n }\n );\n });\n });\n });\n }\n\n toSnapshot(): WorkbookManagerSnapshot {\n return this.getWorkbooks();\n }\n\n restoreFromSnapshot(snapshot: WorkbookManagerSnapshot): void {\n this.resetWorkbooks(snapshot);\n }\n\n getSheet({\n workbookName,\n sheetName,\n }: {\n workbookName: string;\n sheetName: string;\n }): Sheet | undefined {\n const workbook = this.workbooks.get(workbookName);\n const sheet = workbook?.sheets.get(sheetName);\n return sheet;\n }\n\n addSheet({\n workbookName,\n sheetName,\n }: {\n workbookName: string;\n sheetName: string;\n }): Sheet {\n const workbook = this.workbooks.get(workbookName);\n if (!workbook) {\n throw new WorkbookNotFoundError(workbookName);\n }\n\n let nextSheetIndex = -1;\n for (const existingSheet of workbook.sheets.values()) {\n nextSheetIndex = Math.max(nextSheetIndex, existingSheet.index);\n }\n\n const sheet = {\n name: sheetName,\n index: nextSheetIndex + 1,\n content: new Map(),\n metadata: new Map(),\n sheetMetadata: undefined,\n };\n\n if (workbook.sheets.has(sheet.name)) {\n throw new Error(\"Sheet already exists\");\n }\n\n workbook.sheets.set(sheetName, sheet);\n\n // Initialize empty indexes for this sheet\n this.getSheetIndexes({ workbookName, sheetName });\n\n return sheet;\n }\n\n removeSheet({\n workbookName,\n sheetName,\n }: {\n workbookName: string;\n sheetName: string;\n }): Sheet {\n const workbook = this.workbooks.get(workbookName);\n if (!workbook) {\n throw new WorkbookNotFoundError(workbookName);\n }\n const sheet = workbook.sheets.get(sheetName);\n if (!sheet) {\n throw new Error(\"Sheet not found\");\n }\n\n // Remove the sheet\n workbook.sheets.delete(sheetName);\n\n // Clean up indexes for this sheet\n const key = this.getSheetIndexKey(workbookName, sheetName);\n this.sheetIndexes.delete(key);\n\n return sheet;\n }\n\n renameSheet({\n workbookName,\n sheetName,\n newSheetName,\n }: {\n workbookName: string;\n sheetName: string;\n newSheetName: string;\n }): Sheet {\n const workbook = this.workbooks.get(workbookName);\n if (!workbook) {\n throw new WorkbookNotFoundError(workbookName);\n }\n const sheet = workbook.sheets.get(sheetName);\n if (!sheet) {\n throw new SheetNotFoundError(sheetName);\n }\n\n if (workbook.sheets.has(newSheetName)) {\n throw new Error(\"Sheet with new name already exists\");\n }\n\n // Update sheet name\n sheet.name = newSheetName;\n\n // Rebuild the map so the renamed sheet keeps its original position\n const renamedSheets = new Map<string, Sheet>();\n for (const [existingSheetName, existingSheet] of workbook.sheets.entries()) {\n if (existingSheetName === sheetName) {\n renamedSheets.set(newSheetName, sheet);\n } else {\n renamedSheets.set(existingSheetName, existingSheet);\n }\n }\n workbook.sheets.clear();\n for (const [existingSheetName, existingSheet] of renamedSheets.entries()) {\n workbook.sheets.set(existingSheetName, existingSheet);\n }\n\n // Move indexes to new key\n const oldKey = this.getSheetIndexKey(workbookName, sheetName);\n const newKey = this.getSheetIndexKey(workbookName, newSheetName);\n const indexes = this.sheetIndexes.get(oldKey);\n if (indexes) {\n this.sheetIndexes.set(newKey, indexes);\n this.sheetIndexes.delete(oldKey);\n }\n\n return sheet;\n }\n\n updateAllFormulas(updateCallback: (formula: string) => string): CellAddress[] {\n const changed: CellAddress[] = [];\n\n const update = (workbookName: string, map: Map<string, Sheet>) => {\n map.forEach((sheet, sheetName) => {\n sheet.content.forEach((cell, key) => {\n if (typeof cell === \"string\" && cell.startsWith(\"=\")) {\n const formula = cell.slice(1);\n const updatedFormula = updateCallback(formula);\n\n // Only update if the formula actually changed\n if (updatedFormula !== formula) {\n sheet.content.set(key, `=${updatedFormula}`);\n const { colIndex, rowIndex } = parseCellReference(key);\n changed.push({\n workbookName,\n sheetName,\n colIndex,\n rowIndex,\n });\n }\n }\n });\n });\n };\n\n this.workbooks.forEach((workbook, workbookName) => {\n update(workbookName, workbook.sheets);\n });\n\n return changed;\n }\n\n updateFormulasExcluding(\n excludeCellsSet: Set<string>,\n updateCallback: (formula: string) => string\n ): void {\n this.workbooks.forEach((workbook, workbookName) => {\n workbook.sheets.forEach((sheet, sheetName) => {\n sheet.content.forEach((cell, key) => {\n if (typeof cell === \"string\" && cell.startsWith(\"=\")) {\n const { colIndex, rowIndex } = parseCellReference(key);\n const cellKey = `${workbookName}:${sheetName}:${colIndex}:${rowIndex}`;\n \n // Skip if this cell is in the exclude set\n if (excludeCellsSet.has(cellKey)) {\n return;\n }\n\n const formula = cell.slice(1);\n const updatedFormula = updateCallback(formula);\n\n // Only update if the formula actually changed\n if (updatedFormula !== formula) {\n sheet.content.set(key, `=${updatedFormula}`);\n }\n }\n });\n });\n });\n }\n\n updateFormulasForWorkbook(\n workbookName: string,\n updateCallback: (formula: string) => string\n ): void {\n const workbook = this.workbooks.get(workbookName);\n if (!workbook) {\n throw new WorkbookNotFoundError(workbookName);\n }\n\n workbook.sheets.forEach((sheet) => {\n sheet.content.forEach((cell, key) => {\n if (typeof cell === \"string\" && cell.startsWith(\"=\")) {\n const formula = cell.slice(1);\n const updatedFormula = updateCallback(formula);\n\n // Only update if the formula actually changed\n if (updatedFormula !== formula) {\n sheet.content.set(key, `=${updatedFormula}`);\n }\n }\n });\n });\n }\n\n getSheetSerialized({\n workbookName,\n sheetName,\n }: {\n workbookName: string;\n sheetName: string;\n }): Map<string, SerializedCellValue> {\n const workbook = this.workbooks.get(workbookName);\n if (!workbook) {\n throw new WorkbookNotFoundError(workbookName);\n }\n const sheet = workbook.sheets.get(sheetName);\n if (!sheet) {\n throw new SheetNotFoundError(sheetName);\n }\n\n return sheet.content;\n }\n\n /**\n * Add a cell to the grouped indexes\n */\n private addCellToGroups(\n indexes: SheetIndexes,\n rowIndex: number,\n colIndex: number,\n key: string\n ): void {\n // Add to row group (cells in this row, sorted by column)\n let rowGroup = indexes.rowGroups.get(rowIndex);\n if (!rowGroup) {\n rowGroup = [];\n indexes.rowGroups.set(rowIndex, rowGroup);\n }\n const colEntry: IndexEntry = { number: colIndex, key };\n const colInsertIdx = this.findInsertIndex(rowGroup, colIndex);\n rowGroup.splice(colInsertIdx, 0, colEntry);\n\n // Add to column group (cells in this column, sorted by row)\n let colGroup = indexes.colGroups.get(colIndex);\n if (!colGroup) {\n colGroup = [];\n indexes.colGroups.set(colIndex, colGroup);\n }\n const rowEntry: IndexEntry = { number: rowIndex, key };\n const rowInsertIdx = this.findInsertIndex(colGroup, rowIndex);\n colGroup.splice(rowInsertIdx, 0, rowEntry);\n\n // Add to sorted flat indexes\n this.insertSorted(indexes.cellsSortedByRow, { number: rowIndex, key });\n this.insertSorted(indexes.cellsSortedByCol, { number: colIndex, key });\n }\n\n /**\n * Remove a cell from the grouped indexes\n */\n private removeCellFromGroups(\n indexes: SheetIndexes,\n rowIndex: number,\n colIndex: number,\n key: string\n ): void {\n // Remove from row group\n const rowGroup = indexes.rowGroups.get(rowIndex);\n if (rowGroup) {\n const filteredGroup = rowGroup.filter((e) => e.key !== key);\n if (filteredGroup.length === 0) {\n indexes.rowGroups.delete(rowIndex);\n } else {\n indexes.rowGroups.set(rowIndex, filteredGroup);\n }\n }\n\n // Remove from column group\n const colGroup = indexes.colGroups.get(colIndex);\n if (colGroup) {\n const filteredGroup = colGroup.filter((e) => e.key !== key);\n if (filteredGroup.length === 0) {\n indexes.colGroups.delete(colIndex);\n } else {\n indexes.colGroups.set(colIndex, filteredGroup);\n }\n }\n\n // Remove from sorted flat indexes\n indexes.cellsSortedByRow = indexes.cellsSortedByRow.filter(\n (item) => item.key !== key\n );\n indexes.cellsSortedByCol = indexes.cellsSortedByCol.filter(\n (item) => item.key !== key\n );\n }\n\n /**\n * Find insertion index in sorted array\n */\n private findInsertIndex(entries: IndexEntry[], n: number): number {\n return IndexEntryBinarySearch.findInsertionPoint(entries, n);\n }\n\n /**\n * Inserts an item into a sorted array by number, maintaining sort order.\n * If an item with the same number and key already exists, it won't be added again.\n */\n private insertSorted(array: IndexEntry[], item: IndexEntry): void {\n // Check if item already exists (same number and key)\n const existingIndex = array.findIndex(\n (existing) => existing.number === item.number && existing.key === item.key\n );\n\n if (existingIndex !== -1) {\n // Item already exists, no need to add it again\n return;\n }\n\n // Find the insertion point using binary search for efficiency\n const insertionPoint = IndexEntryBinarySearch.findInsertionPoint(\n array,\n item.number\n );\n\n // Insert at the found position\n array.splice(insertionPoint, 0, item);\n }\n\n setCellContent(\n address: CellAddress,\n content: SerializedCellValue,\n options?: {\n /**\n * for extra performance, if the sheet is already known, it can be passed in\n */\n sheet?: Sheet;\n /**\n * if the sheet is being built from scratch, we can skip some checks\n */\n buildingFromScratch?: boolean;\n }\n ): void {\n const sheet =\n options?.sheet ||\n this.getSheet({\n sheetName: address.sheetName,\n workbookName: address.workbookName,\n });\n\n if (!sheet) {\n throw new SheetNotFoundError(address.sheetName);\n }\n\n const indexes = this.getSheetIndexes({\n workbookName: address.workbookName,\n sheetName: address.sheetName,\n });\n const adr = getCellReference(address);\n\n if (this.isContentEmpty(content)) {\n if (!options?.buildingFromScratch) {\n sheet.content.delete(adr);\n // Remove from all indexes\n this.removeCellFromGroups(\n indexes,\n address.rowIndex,\n address.colIndex,\n adr\n );\n }\n } else {\n sheet.content.set(adr, content);\n // Add to all indexes\n this.addCellToGroups(indexes, address.rowIndex, address.colIndex, adr);\n }\n }\n\n /**\n * Set metadata for a cell\n */\n setCellMetadata<TMetadata = unknown>(address: CellAddress, metadata: TMetadata | undefined): void {\n const sheet = this.getSheet({\n workbookName: address.workbookName,\n sheetName: address.sheetName,\n });\n if (!sheet) {\n throw new SheetNotFoundError(address.sheetName);\n }\n\n const key = getCellReference(address);\n if (metadata === undefined) {\n sheet.metadata.delete(key);\n } else {\n sheet.metadata.set(key, metadata);\n }\n }\n\n /**\n * Get metadata for a cell\n */\n getCellMetadata<TMetadata = unknown>(address: CellAddress): TMetadata | undefined {\n const sheet = this.getSheet({\n workbookName: address.workbookName,\n sheetName: address.sheetName,\n });\n if (!sheet) {\n return undefined;\n }\n\n const key = getCellReference(address);\n return sheet.metadata.get(key) as TMetadata | undefined;\n }\n\n /**\n * Get all metadata for a sheet\n */\n getSheetMetadataSerialized<TMetadata = unknown>(opts: {\n sheetName: string;\n workbookName: string;\n }): Map<string, TMetadata> {\n const sheet = this.getSheet(opts);\n return sheet?.metadata || new Map();\n }\n\n /**\n * Set metadata for a sheet\n */\n setSheetMetadata<TSheetMetadata = unknown>(\n opts: { workbookName: string; sheetName: string },\n metadata: TSheetMetadata\n ): void {\n const sheet = this.getSheet(opts);\n if (!sheet) {\n throw new SheetNotFoundError(opts.sheetName);\n }\n sheet.sheetMetadata = metadata;\n }\n\n /**\n * Get metadata for a sheet\n */\n getSheetMetadata<TSheetMetadata = unknown>(\n opts: { workbookName: string; sheetName: string }\n ): TSheetMetadata | undefined {\n const sheet = this.getSheet(opts);\n if (!sheet) {\n return undefined;\n }\n return sheet.sheetMetadata as TSheetMetadata | undefined;\n }\n\n /**\n * Set metadata for a workbook\n */\n setWorkbookMetadata<TWorkbookMetadata = unknown>(\n workbookName: string,\n metadata: TWorkbookMetadata\n ): void {\n const workbook = this.workbooks.get(workbookName);\n if (!workbook) {\n throw new Error(`Workbook \"${workbookName}\" not found`);\n }\n workbook.workbookMetadata = metadata;\n }\n\n /**\n * Get metadata for a workbook\n */\n getWorkbookMetadata<TWorkbookMetadata = unknown>(\n workbookName: string\n ): TWorkbookMetadata | undefined {\n const workbook = this.workbooks.get(workbookName);\n if (!workbook) {\n return undefined;\n }\n return workbook.workbookMetadata as TWorkbookMetadata | undefined;\n }\n\n /**\n * Replace all content for a sheet (safely, without breaking references)\n * This method clears the existing Map and repopulates it rather than replacing the Map reference\n */\n setSheetContent(\n opts: { sheetName: string; workbookName: string },\n newContent: Map<string, SerializedCellValue>\n ): void {\n const sheet = this.getSheet(opts);\n if (!sheet) {\n throw new SheetNotFoundError(opts.sheetName);\n }\n\n // Clear existing content without breaking the Map reference\n sheet.content.clear();\n\n // Clean up indexes for this sheet\n const key = this.getSheetIndexKey(opts.workbookName, opts.sheetName);\n this.sheetIndexes.delete(key);\n\n // Repopulate with new content\n newContent.forEach((value, key) => {\n this.setCellContent(\n {\n workbookName: opts.workbookName,\n sheetName: opts.sheetName,\n colIndex: parseCellReference(key).colIndex,\n rowIndex: parseCellReference(key).rowIndex,\n },\n value,\n {\n sheet,\n buildingFromScratch: true,\n }\n );\n });\n }\n\n /**\n * Removes the content in the spreadsheet that is inside the range.\n * OPTIMIZED: Uses indexes to only process cells that actually exist.\n * ENHANCED: Now supports infinite ranges.\n */\n clearSpreadsheetRange(address: RangeAddress) {\n const sheet = this.getSheet(address);\n\n if (!sheet) {\n throw new SheetNotFoundError(address.sheetName);\n }\n\n // Get current sheet content and prepare new content with cleared cells\n const newContent = new Map(sheet.content);\n const newMetadata = new Map(sheet.metadata);\n\n // Use iterateCellsInRange to only process cells that actually exist\n // This handles both finite and infinite ranges efficiently\n for (const cellAddress of this.iterateCellsInRange(address)) {\n const cellRef = getCellReference(cellAddress);\n\n // Remove from content and metadata\n newContent.delete(cellRef);\n newMetadata.delete(cellRef);\n }\n\n // Update content\n this.setSheetContent(address, newContent);\n \n // Update metadata\n sheet.metadata = newMetadata;\n }\n\n /**\n * Optimized generator to iterate over cells defined in the content within a range\n * Uses indexes to efficiently find and yield only cells that exist within the range\n */\n *iterateCellsInRange(address: RangeAddress): Generator<CellAddress> {\n // First check if the sheet exists\n const sheet = this.getSheet(address);\n if (!sheet) {\n throw new SheetNotFoundError(address.sheetName);\n }\n\n const indexes = this.getSheetIndexes(address);\n\n const range = address.range;\n\n // Use the sorted index to find only rows that actually contain cells\n // This avoids iterating through empty rows regardless of finite/infinite bounds\n\n if (range.end.row.type === \"number\") {\n // Finite bounds: Use binary search to find the range of cells to check\n const startIndex = IndexEntryBinarySearch.findFirstGreaterOrEqual(\n indexes.cellsSortedByRow,\n range.start.row\n );\n\n if (startIndex === -1) return; // No cells at or after start row\n\n // Process cells from startIndex until we exceed the end row\n for (let i = startIndex; i < indexes.cellsSortedByRow.length; i++) {\n const cellEntry = indexes.cellsSortedByRow[i];\n if (!cellEntry) continue;\n\n const parsed = parseCellReference(cellEntry.key);\n\n // Stop if we've gone beyond the row range\n if (parsed.rowIndex > range.end.row.value) break;\n\n // Check if cell is within column bounds\n if (parsed.colIndex < range.start.col) continue;\n\n if (\n range.end.col.type === \"number\" &&\n parsed.colIndex > range.end.col.value\n ) {\n continue; // Skip this cell but keep checking others in different rows\n }\n\n yield {\n rowIndex: parsed.rowIndex,\n colIndex: parsed.colIndex,\n sheetName: address.sheetName,\n workbookName: address.workbookName,\n };\n }\n } else {\n // Infinite row bounds: Use binary search to find starting point\n const startIndex = IndexEntryBinarySearch.findFirstGreaterOrEqual(\n indexes.cellsSortedByRow,\n range.start.row\n );\n\n if (startIndex === -1) return; // No cells at or after start row\n\n // Process all cells from startIndex to end\n for (let i = startIndex; i < indexes.cellsSortedByRow.length; i++) {\n const cellEntry = indexes.cellsSortedByRow[i];\n if (!cellEntry) continue;\n\n const parsed = parseCellReference(cellEntry.key);\n\n // Check if cell is within column bounds\n if (parsed.colIndex < range.start.col) continue;\n\n if (\n range.end.col.type === \"number\" &&\n parsed.colIndex > range.end.col.value\n ) {\n continue; // Skip this cell but keep checking others in different rows\n }\n\n yield {\n rowIndex: parsed.rowIndex,\n colIndex: parsed.colIndex,\n sheetName: address.sheetName,\n workbookName: address.workbookName,\n };\n }\n }\n }\n\n getCellsInRange(address: RangeAddress): CellAddress[] {\n return Array.from(this.iterateCellsInRange(address));\n }\n\n public getCellContent(cellAddress: CellAddress): SerializedCellValue {\n const sheet = this.getSheet(cellAddress);\n if (!sheet) {\n throw new SheetNotFoundError(cellAddress.sheetName);\n }\n return sheet.content.get(getCellReference(cellAddress));\n }\n\n public getSerializedCellValue(cellAddress: CellAddress): SerializedCellValue {\n const sheet = this.getSheet(cellAddress);\n if (!sheet) {\n throw new SheetNotFoundError(cellAddress.sheetName);\n }\n return normalizeSerializedCellValue(\n sheet.content.get(getCellReference(cellAddress))\n );\n }\n\n public isCellEmpty(cellAddress: CellAddress): boolean {\n const content = this.getCellContent(cellAddress);\n return (\n content === undefined || (typeof content === \"string\" && content === \"\")\n );\n }\n public isFormulaCell(cellAddress: CellAddress): boolean {\n const content = this.getCellContent(cellAddress);\n return typeof content === \"string\" && content.startsWith(\"=\");\n }\n\n /**\n * Build evaluation order for a range\n * Delegates to the buildRangeEvalOrder function\n */\n public buildRangeEvalOrder(\n lookupOrder: \"row-major\" | \"col-major\",\n lookupRange: RangeAddress\n ) {\n // Import and call the function\n return buildRangeEvalOrder.call(this, lookupOrder, lookupRange);\n }\n}\n"
5
+ "import {\n FormulaError,\n type CellAddress,\n type FiniteSpreadsheetRange,\n type LocalCellAddress,\n type ReplaceChange,\n type ReplaceTarget,\n type SearchMatch,\n type SearchOptions,\n type SerializedCellValue,\n type Sheet,\n type SpreadsheetRange,\n type Workbook,\n} from \"../types.mjs\";\nimport type { WorkbookManagerSnapshot } from \"../engine-snapshot.mjs\";\nimport { getCellReference, parseCellReference } from \"../utils.mjs\";\n\nimport type { RangeAddress } from \"../types.mjs\";\nimport { buildRangeEvalOrder } from \"./range-eval-order-builder.mjs\";\nimport {\n EvaluationError,\n SheetNotFoundError,\n WorkbookNotFoundError,\n} from \"../../evaluator/evaluation-error.mjs\";\nimport { normalizeSerializedCellValue } from \"../../parser/formatter.mjs\";\n\ninterface IndexEntry {\n number: number;\n key: string;\n}\n\nexport interface SheetIndexes {\n // lookup maps - cells grouped by row/column\n rowGroups: Map<number, IndexEntry[]>; // row number -> cells in that row (sorted by col)\n colGroups: Map<number, IndexEntry[]>; // col number -> cells in that col (sorted by row)\n\n // Sorted flat indexes - for finding cells before a given row/col\n cellsSortedByRow: IndexEntry[];\n cellsSortedByCol: IndexEntry[];\n}\n\ntype SearchScopeSheet = {\n workbookName: string;\n sheet: Sheet;\n};\n\ntype SortableSearchMatch = SearchMatch & {\n rowIndex: number;\n colIndex: number;\n};\n\ntype StringCellMatch = Pick<\n SearchMatch,\n \"occurrenceIndex\" | \"startIndex\" | \"endIndexExclusive\" | \"matchedText\"\n>;\n\ntype PreparedReplace = {\n address: CellAddress;\n beforeContent: string;\n afterContent: string;\n change: ReplaceChange;\n};\n\ntype PreparedCellReplaceAll = {\n address: CellAddress;\n beforeContent: string;\n afterContent: string;\n changes: ReplaceChange[];\n};\n\n/**\n * Utility class for binary search operations on IndexEntry arrays\n */\nexport class IndexEntryBinarySearch {\n /**\n * Find the insertion point for a number in a sorted IndexEntry array\n * Returns the index where the number should be inserted to maintain sort order\n */\n static findInsertionPoint(entries: IndexEntry[], target: number): number {\n let left = 0;\n let right = entries.length;\n\n while (left < right) {\n const mid = Math.floor((left + right) / 2);\n const midEntry = entries[mid];\n if (midEntry && midEntry.number < target) {\n left = mid + 1;\n } else {\n right = mid;\n }\n }\n\n return left;\n }\n\n /**\n * Find the first element >= target\n * Returns the index of the first element, or -1 if not found\n */\n static findFirstGreaterOrEqual(\n entries: IndexEntry[],\n target: number\n ): number {\n if (entries.length === 0) return -1;\n\n let left = 0;\n let right = entries.length - 1;\n let result = -1;\n\n while (left <= right) {\n const mid = Math.floor((left + right) / 2);\n const midEntry = entries[mid];\n if (midEntry && midEntry.number >= target) {\n result = mid;\n right = mid - 1;\n } else {\n left = mid + 1;\n }\n }\n\n return result;\n }\n\n /**\n * Find the rightmost position where we could insert a target value\n * Useful for finding elements that come before a target\n */\n static findRightmostInsertionPoint(\n entries: IndexEntry[],\n target: number\n ): number {\n return IndexEntryBinarySearch.findInsertionPoint(entries, target);\n }\n}\n\nexport class WorkbookManager {\n private workbooks: Map<string, Workbook> = new Map();\n\n // Map from \"workbookName|sheetName\" to indexes\n private sheetIndexes: Map<string, SheetIndexes> = new Map();\n\n /**\n * Generate a key for the sheet indexes map\n */\n private getSheetIndexKey(workbookName: string, sheetName: string): string {\n return `${workbookName}|${sheetName}`;\n }\n\n /**\n * Get or create indexes for a sheet\n */\n public getSheetIndexes(opts: {\n workbookName: string;\n sheetName: string;\n }): SheetIndexes {\n const key = this.getSheetIndexKey(opts.workbookName, opts.sheetName);\n let indexes = this.sheetIndexes.get(key);\n\n if (!indexes) {\n indexes = {\n rowGroups: new Map(),\n colGroups: new Map(),\n cellsSortedByRow: [],\n cellsSortedByCol: [],\n };\n this.sheetIndexes.set(key, indexes);\n }\n\n return indexes;\n }\n\n getSheets(workbookName: string): Map<string, Sheet> {\n const workbook = this.workbooks.get(workbookName);\n if (!workbook) {\n throw new WorkbookNotFoundError(workbookName);\n }\n return workbook.sheets;\n }\n\n getOrderedSheets(workbookName: string): Sheet[] {\n const workbook = this.workbooks.get(workbookName);\n if (!workbook) {\n throw new WorkbookNotFoundError(workbookName);\n }\n\n return Array.from(workbook.sheets.entries())\n .map(([name, sheet], insertionOrder) => ({\n name,\n sheet,\n insertionOrder,\n }))\n .sort((left, right) => {\n if (left.sheet.index !== right.sheet.index) {\n return left.sheet.index - right.sheet.index;\n }\n return left.insertionOrder - right.insertionOrder;\n })\n .map(({ sheet }) => sheet);\n }\n\n getOrderedSheetNames(workbookName: string): string[] {\n return this.getOrderedSheets(workbookName).map((sheet) => sheet.name);\n }\n\n getNextAvailableSheetName(\n workbookName: string,\n baseName: string = \"Sheet\"\n ): string {\n const workbook = this.workbooks.get(workbookName);\n if (!workbook) {\n throw new WorkbookNotFoundError(workbookName);\n }\n\n let suffix = 1;\n while (workbook.sheets.has(`${baseName}${suffix}`)) {\n suffix++;\n }\n\n return `${baseName}${suffix}`;\n }\n\n getWorkbooks(): Map<string, Workbook> {\n return this.workbooks;\n }\n\n addWorkbook(workbookName: string): void {\n if (this.workbooks.has(workbookName)) {\n throw new Error(\"Workbook already exists\");\n }\n this.workbooks.set(workbookName, {\n name: workbookName,\n sheets: new Map(),\n workbookMetadata: undefined,\n });\n }\n\n removeWorkbook(workbookName: string): void {\n const workbook = this.workbooks.get(workbookName);\n if (!workbook) {\n throw new WorkbookNotFoundError(workbookName);\n }\n\n // Clean up indexes for all sheets in this workbook\n for (const sheetName of workbook.sheets.keys()) {\n const key = this.getSheetIndexKey(workbookName, sheetName);\n this.sheetIndexes.delete(key);\n }\n\n this.workbooks.delete(workbookName);\n }\n\n isContentEmpty(content: SerializedCellValue): boolean {\n return content === \"\" || content === undefined;\n }\n\n renameWorkbook(opts: {\n workbookName: string;\n newWorkbookName: string;\n }): void {\n const workbook = this.workbooks.get(opts.workbookName);\n if (!workbook) {\n throw new Error(\"Workbook not found\");\n }\n\n // Update indexes for all sheets in this workbook\n for (const sheetName of workbook.sheets.keys()) {\n const oldKey = this.getSheetIndexKey(opts.workbookName, sheetName);\n const newKey = this.getSheetIndexKey(opts.newWorkbookName, sheetName);\n const indexes = this.sheetIndexes.get(oldKey);\n if (indexes) {\n this.sheetIndexes.set(newKey, indexes);\n this.sheetIndexes.delete(oldKey);\n }\n }\n\n this.workbooks.set(opts.newWorkbookName, workbook);\n this.workbooks.delete(opts.workbookName);\n workbook.name = opts.newWorkbookName;\n }\n\n resetWorkbooks(workbooks: Map<string, Workbook>): void {\n this.workbooks.clear();\n this.sheetIndexes.clear();\n\n workbooks.forEach((workbook, workbookName) => {\n this.workbooks.set(workbookName, workbook);\n workbook.sheets.forEach((sheet) => {\n // Initialize indexes for this sheet\n const indexes = this.getSheetIndexes({\n workbookName,\n sheetName: sheet.name,\n });\n indexes.rowGroups.clear();\n indexes.colGroups.clear();\n indexes.cellsSortedByRow = [];\n indexes.cellsSortedByCol = [];\n\n sheet.content.forEach((value, key) => {\n this.setCellContent(\n {\n workbookName,\n sheetName: sheet.name,\n colIndex: parseCellReference(key).colIndex,\n rowIndex: parseCellReference(key).rowIndex,\n },\n value,\n {\n sheet,\n buildingFromScratch: true,\n }\n );\n });\n });\n });\n }\n\n toSnapshot(): WorkbookManagerSnapshot {\n return this.getWorkbooks();\n }\n\n restoreFromSnapshot(snapshot: WorkbookManagerSnapshot): void {\n this.resetWorkbooks(snapshot);\n }\n\n getSheet({\n workbookName,\n sheetName,\n }: {\n workbookName: string;\n sheetName: string;\n }): Sheet | undefined {\n const workbook = this.workbooks.get(workbookName);\n const sheet = workbook?.sheets.get(sheetName);\n return sheet;\n }\n\n addSheet({\n workbookName,\n sheetName,\n }: {\n workbookName: string;\n sheetName: string;\n }): Sheet {\n const workbook = this.workbooks.get(workbookName);\n if (!workbook) {\n throw new WorkbookNotFoundError(workbookName);\n }\n\n let nextSheetIndex = -1;\n for (const existingSheet of workbook.sheets.values()) {\n nextSheetIndex = Math.max(nextSheetIndex, existingSheet.index);\n }\n\n const sheet = {\n name: sheetName,\n index: nextSheetIndex + 1,\n content: new Map(),\n metadata: new Map(),\n sheetMetadata: undefined,\n };\n\n if (workbook.sheets.has(sheet.name)) {\n throw new Error(\"Sheet already exists\");\n }\n\n workbook.sheets.set(sheetName, sheet);\n\n // Initialize empty indexes for this sheet\n this.getSheetIndexes({ workbookName, sheetName });\n\n return sheet;\n }\n\n removeSheet({\n workbookName,\n sheetName,\n }: {\n workbookName: string;\n sheetName: string;\n }): Sheet {\n const workbook = this.workbooks.get(workbookName);\n if (!workbook) {\n throw new WorkbookNotFoundError(workbookName);\n }\n const sheet = workbook.sheets.get(sheetName);\n if (!sheet) {\n throw new Error(\"Sheet not found\");\n }\n\n // Remove the sheet\n workbook.sheets.delete(sheetName);\n\n // Clean up indexes for this sheet\n const key = this.getSheetIndexKey(workbookName, sheetName);\n this.sheetIndexes.delete(key);\n\n return sheet;\n }\n\n renameSheet({\n workbookName,\n sheetName,\n newSheetName,\n }: {\n workbookName: string;\n sheetName: string;\n newSheetName: string;\n }): Sheet {\n const workbook = this.workbooks.get(workbookName);\n if (!workbook) {\n throw new WorkbookNotFoundError(workbookName);\n }\n const sheet = workbook.sheets.get(sheetName);\n if (!sheet) {\n throw new SheetNotFoundError(sheetName);\n }\n\n if (workbook.sheets.has(newSheetName)) {\n throw new Error(\"Sheet with new name already exists\");\n }\n\n // Update sheet name\n sheet.name = newSheetName;\n\n // Rebuild the map so the renamed sheet keeps its original position\n const renamedSheets = new Map<string, Sheet>();\n for (const [existingSheetName, existingSheet] of workbook.sheets.entries()) {\n if (existingSheetName === sheetName) {\n renamedSheets.set(newSheetName, sheet);\n } else {\n renamedSheets.set(existingSheetName, existingSheet);\n }\n }\n workbook.sheets.clear();\n for (const [existingSheetName, existingSheet] of renamedSheets.entries()) {\n workbook.sheets.set(existingSheetName, existingSheet);\n }\n\n // Move indexes to new key\n const oldKey = this.getSheetIndexKey(workbookName, sheetName);\n const newKey = this.getSheetIndexKey(workbookName, newSheetName);\n const indexes = this.sheetIndexes.get(oldKey);\n if (indexes) {\n this.sheetIndexes.set(newKey, indexes);\n this.sheetIndexes.delete(oldKey);\n }\n\n return sheet;\n }\n\n updateAllFormulas(updateCallback: (formula: string) => string): CellAddress[] {\n const changed: CellAddress[] = [];\n\n const update = (workbookName: string, map: Map<string, Sheet>) => {\n map.forEach((sheet, sheetName) => {\n sheet.content.forEach((cell, key) => {\n if (typeof cell === \"string\" && cell.startsWith(\"=\")) {\n const formula = cell.slice(1);\n const updatedFormula = updateCallback(formula);\n\n // Only update if the formula actually changed\n if (updatedFormula !== formula) {\n sheet.content.set(key, `=${updatedFormula}`);\n const { colIndex, rowIndex } = parseCellReference(key);\n changed.push({\n workbookName,\n sheetName,\n colIndex,\n rowIndex,\n });\n }\n }\n });\n });\n };\n\n this.workbooks.forEach((workbook, workbookName) => {\n update(workbookName, workbook.sheets);\n });\n\n return changed;\n }\n\n updateFormulasExcluding(\n excludeCellsSet: Set<string>,\n updateCallback: (formula: string) => string\n ): void {\n this.workbooks.forEach((workbook, workbookName) => {\n workbook.sheets.forEach((sheet, sheetName) => {\n sheet.content.forEach((cell, key) => {\n if (typeof cell === \"string\" && cell.startsWith(\"=\")) {\n const { colIndex, rowIndex } = parseCellReference(key);\n const cellKey = `${workbookName}:${sheetName}:${colIndex}:${rowIndex}`;\n \n // Skip if this cell is in the exclude set\n if (excludeCellsSet.has(cellKey)) {\n return;\n }\n\n const formula = cell.slice(1);\n const updatedFormula = updateCallback(formula);\n\n // Only update if the formula actually changed\n if (updatedFormula !== formula) {\n sheet.content.set(key, `=${updatedFormula}`);\n }\n }\n });\n });\n });\n }\n\n updateFormulasForWorkbook(\n workbookName: string,\n updateCallback: (formula: string) => string\n ): void {\n const workbook = this.workbooks.get(workbookName);\n if (!workbook) {\n throw new WorkbookNotFoundError(workbookName);\n }\n\n workbook.sheets.forEach((sheet) => {\n sheet.content.forEach((cell, key) => {\n if (typeof cell === \"string\" && cell.startsWith(\"=\")) {\n const formula = cell.slice(1);\n const updatedFormula = updateCallback(formula);\n\n // Only update if the formula actually changed\n if (updatedFormula !== formula) {\n sheet.content.set(key, `=${updatedFormula}`);\n }\n }\n });\n });\n }\n\n getSheetSerialized({\n workbookName,\n sheetName,\n }: {\n workbookName: string;\n sheetName: string;\n }): Map<string, SerializedCellValue> {\n const workbook = this.workbooks.get(workbookName);\n if (!workbook) {\n throw new WorkbookNotFoundError(workbookName);\n }\n const sheet = workbook.sheets.get(sheetName);\n if (!sheet) {\n throw new SheetNotFoundError(sheetName);\n }\n\n return sheet.content;\n }\n\n private resolveSearchScope(\n options?: SearchOptions\n ): SearchScopeSheet[] {\n if (options?.sheetName && !options.workbookName) {\n throw new Error(\"workbookName is required when sheetName is provided\");\n }\n\n if (!options?.workbookName) {\n const scopedSheets: SearchScopeSheet[] = [];\n for (const workbookName of this.workbooks.keys()) {\n for (const sheet of this.getOrderedSheets(workbookName)) {\n scopedSheets.push({ workbookName, sheet });\n }\n }\n return scopedSheets;\n }\n\n const workbookName = options.workbookName;\n if (!this.workbooks.has(workbookName)) {\n throw new WorkbookNotFoundError(workbookName);\n }\n\n if (!options.sheetName) {\n return this.getOrderedSheets(workbookName).map((sheet) => ({\n workbookName,\n sheet,\n }));\n }\n\n const sheet = this.getSheet({\n workbookName,\n sheetName: options.sheetName,\n });\n\n if (!sheet) {\n throw new SheetNotFoundError(options.sheetName);\n }\n\n return [{ workbookName, sheet }];\n }\n\n private getStringContentKind(cellContent: string): SearchMatch[\"contentKind\"] {\n return cellContent.startsWith(\"=\") ? \"formula\" : \"text\";\n }\n\n private findMatchesInString(\n cellContent: string,\n query: string,\n caseSensitive: boolean\n ): StringCellMatch[] {\n if (query.length === 0) {\n return [];\n }\n\n const normalizedContent = caseSensitive\n ? cellContent\n : cellContent.toLowerCase();\n const normalizedQuery = caseSensitive ? query : query.toLowerCase();\n const matches: StringCellMatch[] = [];\n let searchFromIndex = 0;\n\n while (searchFromIndex <= normalizedContent.length - normalizedQuery.length) {\n const startIndex = normalizedContent.indexOf(normalizedQuery, searchFromIndex);\n if (startIndex === -1) {\n break;\n }\n\n const endIndexExclusive = startIndex + normalizedQuery.length;\n matches.push({\n occurrenceIndex: matches.length,\n startIndex,\n endIndexExclusive,\n matchedText: cellContent.slice(startIndex, endIndexExclusive),\n });\n searchFromIndex = endIndexExclusive;\n }\n\n return matches;\n }\n\n private buildSearchMatchesInScope(\n query: string,\n scopedSheets: SearchScopeSheet[],\n caseSensitive: boolean\n ): SearchMatch[] {\n const results: SearchMatch[] = [];\n\n for (const { workbookName, sheet } of scopedSheets) {\n const sheetMatches: SortableSearchMatch[] = [];\n\n for (const [cellReference, value] of sheet.content.entries()) {\n if (typeof value !== \"string\") {\n continue;\n }\n\n const matches = this.findMatchesInString(value, query, caseSensitive);\n if (matches.length === 0) {\n continue;\n }\n\n const { rowIndex, colIndex } = parseCellReference(cellReference);\n const contentKind = this.getStringContentKind(value);\n\n sheetMatches.push(\n ...matches.map((match) => ({\n workbookName,\n sheetName: sheet.name,\n cellReference,\n cellContent: value,\n contentKind,\n occurrenceIndex: match.occurrenceIndex,\n startIndex: match.startIndex,\n endIndexExclusive: match.endIndexExclusive,\n matchedText: match.matchedText,\n rowIndex,\n colIndex,\n }))\n );\n }\n\n sheetMatches.sort(\n (left, right) =>\n left.rowIndex - right.rowIndex ||\n left.colIndex - right.colIndex ||\n left.occurrenceIndex - right.occurrenceIndex\n );\n\n results.push(\n ...sheetMatches.map(({ rowIndex: _rowIndex, colIndex: _colIndex, ...match }) => match)\n );\n }\n\n return results;\n }\n\n search(\n query: string,\n options?: SearchOptions\n ): SearchMatch[] {\n const scopedSheets = this.resolveSearchScope(options);\n\n if (query.length === 0) {\n return [];\n }\n\n return this.buildSearchMatchesInScope(\n query,\n scopedSheets,\n options?.caseSensitive === true\n );\n }\n\n private buildReplacedContent(\n beforeContent: string,\n matches: Array<Pick<SearchMatch, \"startIndex\" | \"endIndexExclusive\">>,\n replacement: string\n ): string {\n let cursor = 0;\n let replacedContent = \"\";\n\n for (const match of matches) {\n replacedContent += beforeContent.slice(cursor, match.startIndex);\n replacedContent += replacement;\n cursor = match.endIndexExclusive;\n }\n\n replacedContent += beforeContent.slice(cursor);\n return replacedContent;\n }\n\n prepareReplace(\n query: string,\n replacement: string,\n target: ReplaceTarget,\n options?: { caseSensitive?: boolean }\n ): PreparedReplace {\n if (query.length === 0) {\n throw new Error(\"replace requires a non-empty query\");\n }\n\n const address: CellAddress = {\n workbookName: target.workbookName,\n sheetName: target.sheetName,\n ...parseCellReference(target.cellReference),\n };\n const beforeContent = this.getCellContent(address);\n\n if (typeof beforeContent !== \"string\") {\n throw new Error(\n `replace requires target cell ${target.cellReference} to contain a string`\n );\n }\n\n const matches = this.findMatchesInString(\n beforeContent,\n query,\n options?.caseSensitive === true\n );\n const match = matches[target.occurrenceIndex];\n\n if (!match) {\n throw new Error(\n `Occurrence ${target.occurrenceIndex} not found in cell ${target.cellReference}`\n );\n }\n\n const afterContent = this.buildReplacedContent(beforeContent, [match], replacement);\n const contentKind = this.getStringContentKind(beforeContent);\n\n return {\n address,\n beforeContent,\n afterContent,\n change: {\n workbookName: target.workbookName,\n sheetName: target.sheetName,\n cellReference: target.cellReference,\n contentKind,\n occurrenceIndex: match.occurrenceIndex,\n startIndex: match.startIndex,\n endIndexExclusive: match.endIndexExclusive,\n matchedText: match.matchedText,\n replacementText: replacement,\n beforeContent,\n afterContent,\n },\n };\n }\n\n prepareReplaceAll(\n query: string,\n replacement: string,\n options?: SearchOptions\n ): PreparedCellReplaceAll[] {\n const scopedSheets = this.resolveSearchScope(options);\n\n if (query.length === 0) {\n throw new Error(\"replaceAll requires a non-empty query\");\n }\n\n const matches = this.buildSearchMatchesInScope(\n query,\n scopedSheets,\n options?.caseSensitive === true\n );\n const matchesByCell = new Map<string, SearchMatch[]>();\n\n for (const match of matches) {\n const cellKey = `${match.workbookName}:${match.sheetName}:${match.cellReference}`;\n const existing = matchesByCell.get(cellKey);\n if (existing) {\n existing.push(match);\n } else {\n matchesByCell.set(cellKey, [match]);\n }\n }\n\n return Array.from(matchesByCell.values()).map((cellMatches) => {\n const [firstMatch] = cellMatches;\n if (!firstMatch) {\n throw new Error(\"Expected at least one match per cell\");\n }\n\n const address: CellAddress = {\n workbookName: firstMatch.workbookName,\n sheetName: firstMatch.sheetName,\n ...parseCellReference(firstMatch.cellReference),\n };\n const afterContent = this.buildReplacedContent(\n firstMatch.cellContent,\n cellMatches,\n replacement\n );\n\n return {\n address,\n beforeContent: firstMatch.cellContent,\n afterContent,\n changes: cellMatches.map((match) => ({\n workbookName: match.workbookName,\n sheetName: match.sheetName,\n cellReference: match.cellReference,\n contentKind: match.contentKind,\n occurrenceIndex: match.occurrenceIndex,\n startIndex: match.startIndex,\n endIndexExclusive: match.endIndexExclusive,\n matchedText: match.matchedText,\n replacementText: replacement,\n beforeContent: firstMatch.cellContent,\n afterContent,\n })),\n };\n });\n }\n\n /**\n * Add a cell to the grouped indexes\n */\n private addCellToGroups(\n indexes: SheetIndexes,\n rowIndex: number,\n colIndex: number,\n key: string\n ): void {\n // Add to row group (cells in this row, sorted by column)\n let rowGroup = indexes.rowGroups.get(rowIndex);\n if (!rowGroup) {\n rowGroup = [];\n indexes.rowGroups.set(rowIndex, rowGroup);\n }\n const colEntry: IndexEntry = { number: colIndex, key };\n const colInsertIdx = this.findInsertIndex(rowGroup, colIndex);\n rowGroup.splice(colInsertIdx, 0, colEntry);\n\n // Add to column group (cells in this column, sorted by row)\n let colGroup = indexes.colGroups.get(colIndex);\n if (!colGroup) {\n colGroup = [];\n indexes.colGroups.set(colIndex, colGroup);\n }\n const rowEntry: IndexEntry = { number: rowIndex, key };\n const rowInsertIdx = this.findInsertIndex(colGroup, rowIndex);\n colGroup.splice(rowInsertIdx, 0, rowEntry);\n\n // Add to sorted flat indexes\n this.insertSorted(indexes.cellsSortedByRow, { number: rowIndex, key });\n this.insertSorted(indexes.cellsSortedByCol, { number: colIndex, key });\n }\n\n /**\n * Remove a cell from the grouped indexes\n */\n private removeCellFromGroups(\n indexes: SheetIndexes,\n rowIndex: number,\n colIndex: number,\n key: string\n ): void {\n // Remove from row group\n const rowGroup = indexes.rowGroups.get(rowIndex);\n if (rowGroup) {\n const filteredGroup = rowGroup.filter((e) => e.key !== key);\n if (filteredGroup.length === 0) {\n indexes.rowGroups.delete(rowIndex);\n } else {\n indexes.rowGroups.set(rowIndex, filteredGroup);\n }\n }\n\n // Remove from column group\n const colGroup = indexes.colGroups.get(colIndex);\n if (colGroup) {\n const filteredGroup = colGroup.filter((e) => e.key !== key);\n if (filteredGroup.length === 0) {\n indexes.colGroups.delete(colIndex);\n } else {\n indexes.colGroups.set(colIndex, filteredGroup);\n }\n }\n\n // Remove from sorted flat indexes\n indexes.cellsSortedByRow = indexes.cellsSortedByRow.filter(\n (item) => item.key !== key\n );\n indexes.cellsSortedByCol = indexes.cellsSortedByCol.filter(\n (item) => item.key !== key\n );\n }\n\n /**\n * Find insertion index in sorted array\n */\n private findInsertIndex(entries: IndexEntry[], n: number): number {\n return IndexEntryBinarySearch.findInsertionPoint(entries, n);\n }\n\n /**\n * Inserts an item into a sorted array by number, maintaining sort order.\n * If an item with the same number and key already exists, it won't be added again.\n */\n private insertSorted(array: IndexEntry[], item: IndexEntry): void {\n // Check if item already exists (same number and key)\n const existingIndex = array.findIndex(\n (existing) => existing.number === item.number && existing.key === item.key\n );\n\n if (existingIndex !== -1) {\n // Item already exists, no need to add it again\n return;\n }\n\n // Find the insertion point using binary search for efficiency\n const insertionPoint = IndexEntryBinarySearch.findInsertionPoint(\n array,\n item.number\n );\n\n // Insert at the found position\n array.splice(insertionPoint, 0, item);\n }\n\n setCellContent(\n address: CellAddress,\n content: SerializedCellValue,\n options?: {\n /**\n * for extra performance, if the sheet is already known, it can be passed in\n */\n sheet?: Sheet;\n /**\n * if the sheet is being built from scratch, we can skip some checks\n */\n buildingFromScratch?: boolean;\n }\n ): void {\n const sheet =\n options?.sheet ||\n this.getSheet({\n sheetName: address.sheetName,\n workbookName: address.workbookName,\n });\n\n if (!sheet) {\n throw new SheetNotFoundError(address.sheetName);\n }\n\n const indexes = this.getSheetIndexes({\n workbookName: address.workbookName,\n sheetName: address.sheetName,\n });\n const adr = getCellReference(address);\n\n if (this.isContentEmpty(content)) {\n if (!options?.buildingFromScratch) {\n sheet.content.delete(adr);\n // Remove from all indexes\n this.removeCellFromGroups(\n indexes,\n address.rowIndex,\n address.colIndex,\n adr\n );\n }\n } else {\n sheet.content.set(adr, content);\n // Add to all indexes\n this.addCellToGroups(indexes, address.rowIndex, address.colIndex, adr);\n }\n }\n\n /**\n * Set metadata for a cell\n */\n setCellMetadata<TMetadata = unknown>(address: CellAddress, metadata: TMetadata | undefined): void {\n const sheet = this.getSheet({\n workbookName: address.workbookName,\n sheetName: address.sheetName,\n });\n if (!sheet) {\n throw new SheetNotFoundError(address.sheetName);\n }\n\n const key = getCellReference(address);\n if (metadata === undefined) {\n sheet.metadata.delete(key);\n } else {\n sheet.metadata.set(key, metadata);\n }\n }\n\n /**\n * Get metadata for a cell\n */\n getCellMetadata<TMetadata = unknown>(address: CellAddress): TMetadata | undefined {\n const sheet = this.getSheet({\n workbookName: address.workbookName,\n sheetName: address.sheetName,\n });\n if (!sheet) {\n return undefined;\n }\n\n const key = getCellReference(address);\n return sheet.metadata.get(key) as TMetadata | undefined;\n }\n\n /**\n * Get all metadata for a sheet\n */\n getSheetMetadataSerialized<TMetadata = unknown>(opts: {\n sheetName: string;\n workbookName: string;\n }): Map<string, TMetadata> {\n const sheet = this.getSheet(opts);\n return sheet?.metadata || new Map();\n }\n\n /**\n * Set metadata for a sheet\n */\n setSheetMetadata<TSheetMetadata = unknown>(\n opts: { workbookName: string; sheetName: string },\n metadata: TSheetMetadata\n ): void {\n const sheet = this.getSheet(opts);\n if (!sheet) {\n throw new SheetNotFoundError(opts.sheetName);\n }\n sheet.sheetMetadata = metadata;\n }\n\n /**\n * Get metadata for a sheet\n */\n getSheetMetadata<TSheetMetadata = unknown>(\n opts: { workbookName: string; sheetName: string }\n ): TSheetMetadata | undefined {\n const sheet = this.getSheet(opts);\n if (!sheet) {\n return undefined;\n }\n return sheet.sheetMetadata as TSheetMetadata | undefined;\n }\n\n /**\n * Set metadata for a workbook\n */\n setWorkbookMetadata<TWorkbookMetadata = unknown>(\n workbookName: string,\n metadata: TWorkbookMetadata\n ): void {\n const workbook = this.workbooks.get(workbookName);\n if (!workbook) {\n throw new Error(`Workbook \"${workbookName}\" not found`);\n }\n workbook.workbookMetadata = metadata;\n }\n\n /**\n * Get metadata for a workbook\n */\n getWorkbookMetadata<TWorkbookMetadata = unknown>(\n workbookName: string\n ): TWorkbookMetadata | undefined {\n const workbook = this.workbooks.get(workbookName);\n if (!workbook) {\n return undefined;\n }\n return workbook.workbookMetadata as TWorkbookMetadata | undefined;\n }\n\n /**\n * Replace all content for a sheet (safely, without breaking references)\n * This method clears the existing Map and repopulates it rather than replacing the Map reference\n */\n setSheetContent(\n opts: { sheetName: string; workbookName: string },\n newContent: Map<string, SerializedCellValue>\n ): void {\n const sheet = this.getSheet(opts);\n if (!sheet) {\n throw new SheetNotFoundError(opts.sheetName);\n }\n\n // Clear existing content without breaking the Map reference\n sheet.content.clear();\n\n // Clean up indexes for this sheet\n const key = this.getSheetIndexKey(opts.workbookName, opts.sheetName);\n this.sheetIndexes.delete(key);\n\n // Repopulate with new content\n newContent.forEach((value, key) => {\n this.setCellContent(\n {\n workbookName: opts.workbookName,\n sheetName: opts.sheetName,\n colIndex: parseCellReference(key).colIndex,\n rowIndex: parseCellReference(key).rowIndex,\n },\n value,\n {\n sheet,\n buildingFromScratch: true,\n }\n );\n });\n }\n\n /**\n * Removes the content in the spreadsheet that is inside the range.\n * OPTIMIZED: Uses indexes to only process cells that actually exist.\n * ENHANCED: Now supports infinite ranges.\n */\n clearSpreadsheetRange(address: RangeAddress) {\n const sheet = this.getSheet(address);\n\n if (!sheet) {\n throw new SheetNotFoundError(address.sheetName);\n }\n\n // Get current sheet content and prepare new content with cleared cells\n const newContent = new Map(sheet.content);\n const newMetadata = new Map(sheet.metadata);\n\n // Use iterateCellsInRange to only process cells that actually exist\n // This handles both finite and infinite ranges efficiently\n for (const cellAddress of this.iterateCellsInRange(address)) {\n const cellRef = getCellReference(cellAddress);\n\n // Remove from content and metadata\n newContent.delete(cellRef);\n newMetadata.delete(cellRef);\n }\n\n // Update content\n this.setSheetContent(address, newContent);\n \n // Update metadata\n sheet.metadata = newMetadata;\n }\n\n /**\n * Optimized generator to iterate over cells defined in the content within a range\n * Uses indexes to efficiently find and yield only cells that exist within the range\n */\n *iterateCellsInRange(address: RangeAddress): Generator<CellAddress> {\n // First check if the sheet exists\n const sheet = this.getSheet(address);\n if (!sheet) {\n throw new SheetNotFoundError(address.sheetName);\n }\n\n const indexes = this.getSheetIndexes(address);\n\n const range = address.range;\n\n // Use the sorted index to find only rows that actually contain cells\n // This avoids iterating through empty rows regardless of finite/infinite bounds\n\n if (range.end.row.type === \"number\") {\n // Finite bounds: Use binary search to find the range of cells to check\n const startIndex = IndexEntryBinarySearch.findFirstGreaterOrEqual(\n indexes.cellsSortedByRow,\n range.start.row\n );\n\n if (startIndex === -1) return; // No cells at or after start row\n\n // Process cells from startIndex until we exceed the end row\n for (let i = startIndex; i < indexes.cellsSortedByRow.length; i++) {\n const cellEntry = indexes.cellsSortedByRow[i];\n if (!cellEntry) continue;\n\n const parsed = parseCellReference(cellEntry.key);\n\n // Stop if we've gone beyond the row range\n if (parsed.rowIndex > range.end.row.value) break;\n\n // Check if cell is within column bounds\n if (parsed.colIndex < range.start.col) continue;\n\n if (\n range.end.col.type === \"number\" &&\n parsed.colIndex > range.end.col.value\n ) {\n continue; // Skip this cell but keep checking others in different rows\n }\n\n yield {\n rowIndex: parsed.rowIndex,\n colIndex: parsed.colIndex,\n sheetName: address.sheetName,\n workbookName: address.workbookName,\n };\n }\n } else {\n // Infinite row bounds: Use binary search to find starting point\n const startIndex = IndexEntryBinarySearch.findFirstGreaterOrEqual(\n indexes.cellsSortedByRow,\n range.start.row\n );\n\n if (startIndex === -1) return; // No cells at or after start row\n\n // Process all cells from startIndex to end\n for (let i = startIndex; i < indexes.cellsSortedByRow.length; i++) {\n const cellEntry = indexes.cellsSortedByRow[i];\n if (!cellEntry) continue;\n\n const parsed = parseCellReference(cellEntry.key);\n\n // Check if cell is within column bounds\n if (parsed.colIndex < range.start.col) continue;\n\n if (\n range.end.col.type === \"number\" &&\n parsed.colIndex > range.end.col.value\n ) {\n continue; // Skip this cell but keep checking others in different rows\n }\n\n yield {\n rowIndex: parsed.rowIndex,\n colIndex: parsed.colIndex,\n sheetName: address.sheetName,\n workbookName: address.workbookName,\n };\n }\n }\n }\n\n getCellsInRange(address: RangeAddress): CellAddress[] {\n return Array.from(this.iterateCellsInRange(address));\n }\n\n public getCellContent(cellAddress: CellAddress): SerializedCellValue {\n const sheet = this.getSheet(cellAddress);\n if (!sheet) {\n throw new SheetNotFoundError(cellAddress.sheetName);\n }\n return sheet.content.get(getCellReference(cellAddress));\n }\n\n public getSerializedCellValue(cellAddress: CellAddress): SerializedCellValue {\n const sheet = this.getSheet(cellAddress);\n if (!sheet) {\n throw new SheetNotFoundError(cellAddress.sheetName);\n }\n return normalizeSerializedCellValue(\n sheet.content.get(getCellReference(cellAddress))\n );\n }\n\n public isCellEmpty(cellAddress: CellAddress): boolean {\n const content = this.getCellContent(cellAddress);\n return (\n content === undefined || (typeof content === \"string\" && content === \"\")\n );\n }\n public isFormulaCell(cellAddress: CellAddress): boolean {\n const content = this.getCellContent(cellAddress);\n return typeof content === \"string\" && content.startsWith(\"=\");\n }\n\n /**\n * Build evaluation order for a range\n * Delegates to the buildRangeEvalOrder function\n */\n public buildRangeEvalOrder(\n lookupOrder: \"row-major\" | \"col-major\",\n lookupRange: RangeAddress\n ) {\n // Import and call the function\n return buildRangeEvalOrder.call(this, lookupOrder, lookupRange);\n }\n}\n"
6
6
  ],
7
- "mappings": ";AAWA;AAGA;AACA;AAAA;AAAA;AAAA;AAKA;AAAA;AAoBO,MAAM,uBAAuB;AAAA,SAK3B,kBAAkB,CAAC,SAAuB,QAAwB;AAAA,IACvE,IAAI,OAAO;AAAA,IACX,IAAI,QAAQ,QAAQ;AAAA,IAEpB,OAAO,OAAO,OAAO;AAAA,MACnB,MAAM,MAAM,KAAK,OAAO,OAAO,SAAS,CAAC;AAAA,MACzC,MAAM,WAAW,QAAQ;AAAA,MACzB,IAAI,YAAY,SAAS,SAAS,QAAQ;AAAA,QACxC,OAAO,MAAM;AAAA,MACf,EAAO;AAAA,QACL,QAAQ;AAAA;AAAA,IAEZ;AAAA,IAEA,OAAO;AAAA;AAAA,SAOF,uBAAuB,CAC5B,SACA,QACQ;AAAA,IACR,IAAI,QAAQ,WAAW;AAAA,MAAG,OAAO;AAAA,IAEjC,IAAI,OAAO;AAAA,IACX,IAAI,QAAQ,QAAQ,SAAS;AAAA,IAC7B,IAAI,SAAS;AAAA,IAEb,OAAO,QAAQ,OAAO;AAAA,MACpB,MAAM,MAAM,KAAK,OAAO,OAAO,SAAS,CAAC;AAAA,MACzC,MAAM,WAAW,QAAQ;AAAA,MACzB,IAAI,YAAY,SAAS,UAAU,QAAQ;AAAA,QACzC,SAAS;AAAA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D;AAAA;AAAA,EAGK,WAAW,CAAC,aAAmC;AAAA,IACpD,MAAM,UAAU,KAAK,eAAe,WAAW;AAAA,IAC/C,OACE,YAAY,aAAc,OAAO,YAAY,YAAY,YAAY;AAAA;AAAA,EAGlE,aAAa,CAAC,aAAmC;AAAA,IACtD,MAAM,UAAU,KAAK,eAAe,WAAW;AAAA,IAC/C,OAAO,OAAO,YAAY,YAAY,QAAQ,WAAW,GAAG;AAAA;AAAA,EAOvD,mBAAmB,CACxB,aACA,aACA;AAAA,IAEA,OAAO,oBAAoB,KAAK,MAAM,aAAa,WAAW;AAAA;AAElE;",
8
+ "debugId": "30E4B573D7FD281D64756E2164756E21",
9
9
  "names": []
10
10
  }
@@ -0,0 +1,201 @@
1
+ // src/core/mutation-invalidation.ts
2
+ import { getNamedExpressionResourceKey } from "./resource-keys.mjs";
3
+ import { getCellReference, parseCellReference } from "./utils.mjs";
4
+ function getSerializedCellValueKind(value) {
5
+ if (value === undefined || typeof value === "string" && value.length === 0) {
6
+ return "empty";
7
+ }
8
+ if (typeof value === "string" && value.startsWith("=")) {
9
+ return "formula";
10
+ }
11
+ return "scalar";
12
+ }
13
+ function getMutationAddressKey(address) {
14
+ return `${address.workbookName}:${address.sheetName}:${getCellReference(address)}`;
15
+ }
16
+ function buildTouchedCells(cells) {
17
+ const deduped = new Map;
18
+ for (const cell of cells) {
19
+ deduped.set(getMutationAddressKey(cell.address), {
20
+ address: cell.address,
21
+ beforeKind: getSerializedCellValueKind(cell.before),
22
+ afterKind: getSerializedCellValueKind(cell.after)
23
+ });
24
+ }
25
+ return Array.from(deduped.values());
26
+ }
27
+ function buildFormulaTouchedCells(cells) {
28
+ return cells.map((address) => ({
29
+ address,
30
+ beforeKind: "formula",
31
+ afterKind: "formula"
32
+ }));
33
+ }
34
+ function captureCellContents(workbookManager, addresses) {
35
+ const contents = new Map;
36
+ for (const address of addresses) {
37
+ try {
38
+ contents.set(getMutationAddressKey(address), workbookManager.getCellContent(address));
39
+ } catch {
40
+ contents.set(getMutationAddressKey(address), undefined);
41
+ }
42
+ }
43
+ return contents;
44
+ }
45
+ function buildSheetContentTouchedCells(opts, beforeContent, afterContent) {
46
+ const touchedKeys = new Set([
47
+ ...Array.from(beforeContent?.keys() ?? []),
48
+ ...Array.from(afterContent.keys())
49
+ ]);
50
+ return buildTouchedCells(Array.from(touchedKeys, (key) => ({
51
+ address: {
52
+ workbookName: opts.workbookName,
53
+ sheetName: opts.sheetName,
54
+ ...parseCellReference(key)
55
+ },
56
+ before: beforeContent?.get(key),
57
+ after: afterContent.get(key)
58
+ })));
59
+ }
60
+ function getTableCellKey(address) {
61
+ return `${address.workbookName}:${address.sheetName}:${address.rowIndex}:${address.colIndex}`;
62
+ }
63
+ function collectTableFootprintCells(workbookManager, table) {
64
+ const cells = new Map;
65
+ const sheet = workbookManager.getSheet({
66
+ workbookName: table.workbookName,
67
+ sheetName: table.sheetName
68
+ });
69
+ if (!sheet) {
70
+ return [];
71
+ }
72
+ const startColIndex = table.start.colIndex;
73
+ const endColIndex = startColIndex + table.headers.size - 1;
74
+ if (table.endRow.type === "number") {
75
+ for (let rowIndex = table.start.rowIndex;rowIndex <= table.endRow.value; rowIndex++) {
76
+ for (let colIndex = startColIndex;colIndex <= endColIndex; colIndex++) {
77
+ const address = {
78
+ workbookName: table.workbookName,
79
+ sheetName: table.sheetName,
80
+ rowIndex,
81
+ colIndex
82
+ };
83
+ cells.set(getTableCellKey(address), {
84
+ address,
85
+ content: workbookManager.getCellContent(address)
86
+ });
87
+ }
88
+ }
89
+ return Array.from(cells.values());
90
+ }
91
+ for (const [ref, content] of sheet.content.entries()) {
92
+ const { rowIndex, colIndex } = parseCellReference(ref);
93
+ if (rowIndex < table.start.rowIndex) {
94
+ continue;
95
+ }
96
+ if (colIndex < startColIndex || colIndex > endColIndex) {
97
+ continue;
98
+ }
99
+ const address = {
100
+ workbookName: table.workbookName,
101
+ sheetName: table.sheetName,
102
+ rowIndex,
103
+ colIndex
104
+ };
105
+ cells.set(getTableCellKey(address), {
106
+ address,
107
+ content
108
+ });
109
+ }
110
+ return Array.from(cells.values());
111
+ }
112
+ function buildTableTouchedCells(workbookManager, tables) {
113
+ const touchedCells = new Map;
114
+ for (const table of tables) {
115
+ if (!table) {
116
+ continue;
117
+ }
118
+ for (const cell of collectTableFootprintCells(workbookManager, table)) {
119
+ touchedCells.set(getTableCellKey(cell.address), {
120
+ address: cell.address,
121
+ beforeKind: getSerializedCellValueKind(cell.content),
122
+ afterKind: getSerializedCellValueKind(cell.content)
123
+ });
124
+ }
125
+ }
126
+ return Array.from(touchedCells.values());
127
+ }
128
+ function buildTableContextChangedCells(workbookManager, tables) {
129
+ const changedCells = new Map;
130
+ for (const table of tables) {
131
+ if (!table) {
132
+ continue;
133
+ }
134
+ for (const cell of collectTableFootprintCells(workbookManager, table)) {
135
+ changedCells.set(getTableCellKey(cell.address), cell.address);
136
+ }
137
+ }
138
+ return Array.from(changedCells.values());
139
+ }
140
+ function mergeTouchedCells(...groups) {
141
+ const precedence = {
142
+ empty: 0,
143
+ scalar: 1,
144
+ formula: 2
145
+ };
146
+ const merged = new Map;
147
+ for (const group of groups) {
148
+ for (const touchedCell of group) {
149
+ const key = getTableCellKey(touchedCell.address);
150
+ const existing = merged.get(key);
151
+ if (!existing) {
152
+ merged.set(key, touchedCell);
153
+ continue;
154
+ }
155
+ merged.set(key, {
156
+ address: touchedCell.address,
157
+ beforeKind: precedence[touchedCell.beforeKind] >= precedence[existing.beforeKind] ? touchedCell.beforeKind : existing.beforeKind,
158
+ afterKind: precedence[touchedCell.afterKind] >= precedence[existing.afterKind] ? touchedCell.afterKind : existing.afterKind
159
+ });
160
+ }
161
+ }
162
+ return Array.from(merged.values());
163
+ }
164
+ function getNamedExpressionScopeResourceKeys(expressions, opts) {
165
+ return Array.from(new Set(Array.from(expressions, (expressionName) => getNamedExpressionResourceKey({
166
+ expressionName,
167
+ workbookName: opts.workbookName,
168
+ sheetName: opts.sheetName
169
+ }))));
170
+ }
171
+ function getFiniteRangeAddresses(address) {
172
+ if (address.range.end.col.type === "infinity" || address.range.end.row.type === "infinity") {
173
+ return [];
174
+ }
175
+ const cells = [];
176
+ for (let colIndex = address.range.start.col;colIndex <= address.range.end.col.value; colIndex++) {
177
+ for (let rowIndex = address.range.start.row;rowIndex <= address.range.end.row.value; rowIndex++) {
178
+ cells.push({
179
+ workbookName: address.workbookName,
180
+ sheetName: address.sheetName,
181
+ colIndex,
182
+ rowIndex
183
+ });
184
+ }
185
+ }
186
+ return cells;
187
+ }
188
+ export {
189
+ mergeTouchedCells,
190
+ getNamedExpressionScopeResourceKeys,
191
+ getMutationAddressKey,
192
+ getFiniteRangeAddresses,
193
+ captureCellContents,
194
+ buildTouchedCells,
195
+ buildTableTouchedCells,
196
+ buildTableContextChangedCells,
197
+ buildSheetContentTouchedCells,
198
+ buildFormulaTouchedCells
199
+ };
200
+
201
+ //# debugId=94265036334F30FD64756E2164756E21
@@ -0,0 +1,10 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/core/mutation-invalidation.ts"],
4
+ "sourcesContent": [
5
+ "import type { WorkbookManager } from \"./managers/workbook-manager.mjs\";\nimport type {\n CellAddress,\n RangeAddress,\n SerializedCellValue,\n TableDefinition,\n} from \"./types.mjs\";\nimport { getNamedExpressionResourceKey } from \"./resource-keys.mjs\";\nimport { getCellReference, parseCellReference } from \"./utils.mjs\";\n\ntype CellContentKind = \"empty\" | \"scalar\" | \"formula\";\n\nexport type RemovedScope =\n | { type: \"workbook\"; workbookName: string }\n | { type: \"sheet\"; workbookName: string; sheetName: string };\n\nexport type MutationInvalidation = {\n touchedCells: Array<{\n address: CellAddress;\n beforeKind: CellContentKind;\n afterKind: CellContentKind;\n }>;\n /**\n * Cells whose table membership or implicit current-row table context changed\n * without necessarily changing their formula text.\n */\n tableContextChangedCells?: CellAddress[];\n resourceKeys: string[];\n removedScopes?: RemovedScope[];\n};\n\nfunction getSerializedCellValueKind(\n value: SerializedCellValue | undefined\n): CellContentKind {\n if (\n value === undefined ||\n (typeof value === \"string\" && value.length === 0)\n ) {\n return \"empty\";\n }\n if (typeof value === \"string\" && value.startsWith(\"=\")) {\n return \"formula\";\n }\n return \"scalar\";\n}\n\nfunction emptyMutationInvalidation(): MutationInvalidation {\n return {\n touchedCells: [],\n resourceKeys: [],\n };\n}\n\nexport function getMutationAddressKey(address: CellAddress): string {\n return `${address.workbookName}:${address.sheetName}:${getCellReference(\n address\n )}`;\n}\n\nexport function buildTouchedCells(\n cells: Array<{\n address: CellAddress;\n before: SerializedCellValue | undefined;\n after: SerializedCellValue | undefined;\n }>\n): MutationInvalidation[\"touchedCells\"] {\n const deduped = new Map<\n string,\n MutationInvalidation[\"touchedCells\"][number]\n >();\n\n for (const cell of cells) {\n deduped.set(getMutationAddressKey(cell.address), {\n address: cell.address,\n beforeKind: getSerializedCellValueKind(cell.before),\n afterKind: getSerializedCellValueKind(cell.after),\n });\n }\n\n return Array.from(deduped.values());\n}\n\nexport function buildFormulaTouchedCells(\n cells: CellAddress[]\n): MutationInvalidation[\"touchedCells\"] {\n return cells.map((address) => ({\n address,\n beforeKind: \"formula\",\n afterKind: \"formula\",\n }));\n}\n\nexport function captureCellContents(\n workbookManager: WorkbookManager,\n addresses: CellAddress[]\n): Map<string, SerializedCellValue | undefined> {\n const contents = new Map<string, SerializedCellValue | undefined>();\n for (const address of addresses) {\n try {\n contents.set(\n getMutationAddressKey(address),\n workbookManager.getCellContent(address)\n );\n } catch {\n contents.set(getMutationAddressKey(address), undefined);\n }\n }\n return contents;\n}\n\nexport function buildSheetContentTouchedCells(\n opts: { workbookName: string; sheetName: string },\n beforeContent: Map<string, SerializedCellValue> | undefined,\n afterContent: Map<string, SerializedCellValue>\n): MutationInvalidation[\"touchedCells\"] {\n const touchedKeys = new Set<string>([\n ...Array.from(beforeContent?.keys() ?? []),\n ...Array.from(afterContent.keys()),\n ]);\n\n return buildTouchedCells(\n Array.from(touchedKeys, (key) => ({\n address: {\n workbookName: opts.workbookName,\n sheetName: opts.sheetName,\n ...parseCellReference(key),\n },\n before: beforeContent?.get(key),\n after: afterContent.get(key),\n }))\n );\n}\n\nfunction getTableCellKey(address: CellAddress): string {\n return `${address.workbookName}:${address.sheetName}:${address.rowIndex}:${address.colIndex}`;\n}\n\nfunction collectTableFootprintCells(\n workbookManager: WorkbookManager,\n table: TableDefinition\n): Array<{\n address: CellAddress;\n content: SerializedCellValue | undefined;\n}> {\n const cells = new Map<\n string,\n {\n address: CellAddress;\n content: SerializedCellValue | undefined;\n }\n >();\n const sheet = workbookManager.getSheet({\n workbookName: table.workbookName,\n sheetName: table.sheetName,\n });\n if (!sheet) {\n return [];\n }\n\n const startColIndex = table.start.colIndex;\n const endColIndex = startColIndex + table.headers.size - 1;\n\n if (table.endRow.type === \"number\") {\n for (\n let rowIndex = table.start.rowIndex;\n rowIndex <= table.endRow.value;\n rowIndex++\n ) {\n for (\n let colIndex = startColIndex;\n colIndex <= endColIndex;\n colIndex++\n ) {\n const address = {\n workbookName: table.workbookName,\n sheetName: table.sheetName,\n rowIndex,\n colIndex,\n };\n cells.set(getTableCellKey(address), {\n address,\n content: workbookManager.getCellContent(address),\n });\n }\n }\n return Array.from(cells.values());\n }\n\n for (const [ref, content] of sheet.content.entries()) {\n const { rowIndex, colIndex } = parseCellReference(ref);\n if (rowIndex < table.start.rowIndex) {\n continue;\n }\n if (colIndex < startColIndex || colIndex > endColIndex) {\n continue;\n }\n\n const address = {\n workbookName: table.workbookName,\n sheetName: table.sheetName,\n rowIndex,\n colIndex,\n };\n cells.set(getTableCellKey(address), {\n address,\n content,\n });\n }\n\n return Array.from(cells.values());\n}\n\nexport function buildTableTouchedCells(\n workbookManager: WorkbookManager,\n tables: Array<TableDefinition | undefined>\n): MutationInvalidation[\"touchedCells\"] {\n const touchedCells = new Map<\n string,\n MutationInvalidation[\"touchedCells\"][number]\n >();\n\n for (const table of tables) {\n if (!table) {\n continue;\n }\n for (const cell of collectTableFootprintCells(workbookManager, table)) {\n touchedCells.set(getTableCellKey(cell.address), {\n address: cell.address,\n beforeKind: getSerializedCellValueKind(cell.content),\n afterKind: getSerializedCellValueKind(cell.content),\n });\n }\n }\n\n return Array.from(touchedCells.values());\n}\n\nexport function buildTableContextChangedCells(\n workbookManager: WorkbookManager,\n tables: Array<TableDefinition | undefined>\n): CellAddress[] {\n const changedCells = new Map<string, CellAddress>();\n\n for (const table of tables) {\n if (!table) {\n continue;\n }\n for (const cell of collectTableFootprintCells(workbookManager, table)) {\n changedCells.set(getTableCellKey(cell.address), cell.address);\n }\n }\n\n return Array.from(changedCells.values());\n}\n\nexport function mergeTouchedCells(\n ...groups: MutationInvalidation[\"touchedCells\"][]\n): MutationInvalidation[\"touchedCells\"] {\n const precedence = {\n empty: 0,\n scalar: 1,\n formula: 2,\n } as const;\n const merged = new Map<\n string,\n MutationInvalidation[\"touchedCells\"][number]\n >();\n\n for (const group of groups) {\n for (const touchedCell of group) {\n const key = getTableCellKey(touchedCell.address);\n const existing = merged.get(key);\n if (!existing) {\n merged.set(key, touchedCell);\n continue;\n }\n\n merged.set(key, {\n address: touchedCell.address,\n beforeKind:\n precedence[touchedCell.beforeKind] >= precedence[existing.beforeKind]\n ? touchedCell.beforeKind\n : existing.beforeKind,\n afterKind:\n precedence[touchedCell.afterKind] >= precedence[existing.afterKind]\n ? touchedCell.afterKind\n : existing.afterKind,\n });\n }\n }\n\n return Array.from(merged.values());\n}\n\nexport function getNamedExpressionScopeResourceKeys(\n expressions: Iterable<string>,\n opts: {\n workbookName?: string;\n sheetName?: string;\n }\n): string[] {\n return Array.from(\n new Set(\n Array.from(expressions, (expressionName) =>\n getNamedExpressionResourceKey({\n expressionName,\n workbookName: opts.workbookName,\n sheetName: opts.sheetName,\n })\n )\n )\n );\n}\n\nexport function getFiniteRangeAddresses(address: RangeAddress): CellAddress[] {\n if (\n address.range.end.col.type === \"infinity\" ||\n address.range.end.row.type === \"infinity\"\n ) {\n return [];\n }\n\n const cells: CellAddress[] = [];\n for (\n let colIndex = address.range.start.col;\n colIndex <= address.range.end.col.value;\n colIndex++\n ) {\n for (\n let rowIndex = address.range.start.row;\n rowIndex <= address.range.end.row.value;\n rowIndex++\n ) {\n cells.push({\n workbookName: address.workbookName,\n sheetName: address.sheetName,\n colIndex,\n rowIndex,\n });\n }\n }\n return cells;\n}\n"
6
+ ],
7
+ "mappings": ";AAOA;AACA;AAuBA,SAAS,0BAA0B,CACjC,OACiB;AAAA,EACjB,IACE,UAAU,aACT,OAAO,UAAU,YAAY,MAAM,WAAW,GAC/C;AAAA,IACA,OAAO;AAAA,EACT;AAAA,EACA,IAAI,OAAO,UAAU,YAAY,MAAM,WAAW,GAAG,GAAG;AAAA,IACtD,OAAO;AAAA,EACT;AAAA,EACA,OAAO;AAAA;AAUF,SAAS,qBAAqB,CAAC,SAA8B;AAAA,EAClE,OAAO,GAAG,QAAQ,gBAAgB,QAAQ,aAAa,iBACrD,OACF;AAAA;AAGK,SAAS,iBAAiB,CAC/B,OAKsC;AAAA,EACtC,MAAM,UAAU,IAAI;AAAA,EAKpB,WAAW,QAAQ,OAAO;AAAA,IACxB,QAAQ,IAAI,sBAAsB,KAAK,OAAO,GAAG;AAAA,MAC/C,SAAS,KAAK;AAAA,MACd,YAAY,2BAA2B,KAAK,MAAM;AAAA,MAClD,WAAW,2BAA2B,KAAK,KAAK;AAAA,IAClD,CAAC;AAAA,EACH;AAAA,EAEA,OAAO,MAAM,KAAK,QAAQ,OAAO,CAAC;AAAA;AAG7B,SAAS,wBAAwB,CACtC,OACsC;AAAA,EACtC,OAAO,MAAM,IAAI,CAAC,aAAa;AAAA,IAC7B;AAAA,IACA,YAAY;AAAA,IACZ,WAAW;AAAA,EACb,EAAE;AAAA;AAGG,SAAS,mBAAmB,CACjC,iBACA,WAC8C;AAAA,EAC9C,MAAM,WAAW,IAAI;AAAA,EACrB,WAAW,WAAW,WAAW;AAAA,IAC/B,IAAI;AAAA,MACF,SAAS,IACP,sBAAsB,OAAO,GAC7B,gBAAgB,eAAe,OAAO,CACx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AC5E,IACE,QAAQ,MAAM,IAAI,IAAI,SAAS,cAC/B,QAAQ,MAAM,IAAI,IAAI,SAAS,YAC/B;AAAA,IACA,OAAO,CAAC;AAAA,EACV;AAAA,EAEA,MAAM,QAAuB,CAAC;AAAA,EAC9B,SACM,WAAW,QAAQ,MAAM,MAAM,IACnC,YAAY,QAAQ,MAAM,IAAI,IAAI,OAClC,YACA;AAAA,IACA,SACM,WAAW,QAAQ,MAAM,MAAM,IACnC,YAAY,QAAQ,MAAM,IAAI,IAAI,OAClC,YACA;AAAA,MACA,MAAM,KAAK;AAAA,QACT,cAAc,QAAQ;AAAA,QACtB,WAAW,QAAQ;AAAA,QACnB;AAAA,QACA;AAAA,MACF,CAAC;AAAA,IACH;AAAA,EACF;AAAA,EACA,OAAO;AAAA;",
8
+ "debugId": "94265036334F30FD64756E2164756E21",
9
+ "names": []
10
+ }
@@ -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.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<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 CellStyle {\n backgroundColor?: string; // Hex color format\n color?: string; // Text color in hex format\n fontSize?: number; // Font size in pixels\n bold?: boolean;\n italic?: boolean;\n underline?: boolean;\n}\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', 'metadata']\n * - Use array for fine-grained control over what to copy:\n * - ['content'] - copy only values/formulas\n * - ['style'] - copy only formatting\n * - ['metadata'] - copy only metadata (rich text, links, etc.)\n * - ['content', 'style'] - copy content and formatting\n * - ['content', 'metadata'] - copy content and metadata\n * - ['style', 'metadata'] - copy formatting and metadata\n * - ['content', 'style', 'metadata'] - same as 'all'\n * @default 'all'\n */\n include?: \"all\" | (\"content\" | \"style\" | \"metadata\")[];\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.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\nexport interface SearchOptions {\n workbookName?: string;\n sheetName?: string;\n caseSensitive?: boolean;\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 CellStyle {\n backgroundColor?: string; // Hex color format\n color?: string; // Text color in hex format\n fontSize?: number; // Font size in pixels\n bold?: boolean;\n italic?: boolean;\n underline?: boolean;\n}\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', 'metadata']\n * - Use array for fine-grained control over what to copy:\n * - ['content'] - copy only values/formulas\n * - ['style'] - copy only formatting\n * - ['metadata'] - copy only metadata (rich text, links, etc.)\n * - ['content', 'style'] - copy content and formatting\n * - ['content', 'metadata'] - copy content and metadata\n * - ['style', 'metadata'] - copy formatting and metadata\n * - ['content', 'style', 'metadata'] - same as 'all'\n * @default 'all'\n */\n include?: \"all\" | (\"content\" | \"style\" | \"metadata\")[];\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": ";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;",
7
+ "mappings": ";AAkKO,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",
9
9
  "names": []
10
10
  }
@@ -2,7 +2,7 @@
2
2
  "version": 3,
3
3
  "sources": ["../../../src/core/workbook-renamer.ts"],
4
4
  "sourcesContent": [
5
- "/**\n * Workbook renamer utility for updating cross-workbook references in formulas\n */\n\nimport { parseFormula } from \"../parser/parser.mjs\";\nimport { astToString } from \"../parser/formatter.mjs\";\nimport { transformAST } from \"./ast-traverser.mjs\";\nimport type { ASTNode } from \"../parser/ast.mjs\";\n\n/**\n * Renames workbook references in a formula string\n * @param formula The formula string (without the leading =)\n * @param oldWorkbookName The old workbook name to replace\n * @param newWorkbookName The new workbook name to use\n * @returns The updated formula string\n */\nexport function renameWorkbookInFormula(options: {\n formula: string;\n oldWorkbookName: string;\n newWorkbookName: string;\n}): string {\n const { formula, oldWorkbookName, newWorkbookName } = options;\n try {\n const ast = parseFormula(formula);\n \n const updatedAst = transformAST(ast, (node) => {\n // Handle cross-workbook references (e.g., [MyWorkbook]Sheet1!A1)\n if (node.type === \"reference\" && node.workbookName === oldWorkbookName) {\n return {\n ...node,\n workbookName: newWorkbookName,\n };\n }\n \n // Handle range references with workbook names (e.g., [MyWorkbook]Sheet1!A1:B2)\n if (node.type === \"range\" && node.workbookName === oldWorkbookName) {\n return {\n ...node,\n workbookName: newWorkbookName,\n };\n }\n \n // Handle named expressions with workbook names\n if (node.type === \"named-expression\" && node.workbookName === oldWorkbookName) {\n return {\n ...node,\n workbookName: newWorkbookName,\n };\n }\n \n // Handle structured references with workbook names (e.g., [MyWorkbook]Sheet1!Table1[Column1])\n if (node.type === \"structured-reference\" && node.workbookName === oldWorkbookName) {\n return {\n ...node,\n workbookName: newWorkbookName,\n };\n }\n \n // Handle 3D ranges with workbook names (e.g., [MyWorkbook]Sheet1:Sheet3!A1:C5)\n if (node.type === \"3d-range\" && node.workbookName === oldWorkbookName) {\n return {\n ...node,\n workbookName: newWorkbookName,\n };\n }\n \n return node;\n });\n \n return astToString(updatedAst);\n } catch (error) {\n // If parsing fails, return the original formula\n return formula;\n }\n}\n\n/**\n * Checks if a formula references a specific workbook\n * @param formula The formula string (without the leading =)\n * @param workbookName The workbook name to check for\n * @returns True if the formula references the workbook\n */\nexport function formulaReferencesWorkbook(formula: string, workbookName: string): boolean {\n try {\n const referencedWorkbooks = getReferencedWorkbookNames(formula);\n return referencedWorkbooks.includes(workbookName);\n } catch (error) {\n // If parsing fails, assume no reference\n return false;\n }\n}\n\n/**\n * Gets all workbook names referenced in a formula\n * @param formula The formula string (without the leading =)\n * @returns Array of unique workbook names referenced in the formula\n */\nexport function getReferencedWorkbookNames(formula: string): string[] {\n try {\n const ast = parseFormula(formula);\n const workbookNames = new Set<string>();\n\n transformAST(ast, (node) => {\n // Handle cross-workbook references\n if ((node.type === \"reference\" || \n node.type === \"range\" || \n node.type === \"named-expression\" || \n node.type === \"structured-reference\" ||\n node.type === \"3d-range\") && \n node.workbookName) {\n workbookNames.add(node.workbookName);\n }\n \n return node;\n });\n\n return Array.from(workbookNames);\n } catch (error) {\n // If parsing fails, return empty array\n return [];\n }\n}\n"
5
+ "/**\n * Workbook renamer utility for updating cross-workbook references in formulas\n */\n\nimport { parseFormula } from \"../parser/parser.mjs\";\nimport { astToString } from \"../parser/formatter.mjs\";\nimport { transformAST } from \"./ast-traverser.mjs\";\nimport type { ASTNode } from \"../parser/ast.mjs\";\n\n/**\n * Renames workbook references in a formula string\n * @param formula The formula string (without the leading =)\n * @param oldWorkbookName The old workbook name to replace\n * @param newWorkbookName The new workbook name to use\n * @returns The updated formula string\n */\nexport function renameWorkbookInFormula(options: {\n formula: string;\n oldWorkbookName: string;\n newWorkbookName: string;\n}): string {\n const { formula, oldWorkbookName, newWorkbookName } = options;\n try {\n const ast = parseFormula(formula);\n \n const updatedAst = transformAST(ast, (node) => {\n // Handle cross-workbook references (e.g., [MyWorkbook]Sheet1!A1)\n if (node.type === \"reference\" && node.workbookName === oldWorkbookName) {\n return {\n ...node,\n workbookName: newWorkbookName,\n };\n }\n \n // Handle range references with workbook names (e.g., [MyWorkbook]Sheet1!A1:B2)\n if (node.type === \"range\" && node.workbookName === oldWorkbookName) {\n return {\n ...node,\n workbookName: newWorkbookName,\n };\n }\n \n // Handle named expressions with workbook names\n if (node.type === \"named-expression\" && node.workbookName === oldWorkbookName) {\n return {\n ...node,\n workbookName: newWorkbookName,\n };\n }\n \n // Handle structured references with workbook names (e.g., [MyWorkbook]!Table1[Column1])\n if (node.type === \"structured-reference\" && node.workbookName === oldWorkbookName) {\n return {\n ...node,\n workbookName: newWorkbookName,\n };\n }\n \n // Handle 3D ranges with workbook names (e.g., [MyWorkbook]Sheet1:Sheet3!A1:C5)\n if (node.type === \"3d-range\" && node.workbookName === oldWorkbookName) {\n return {\n ...node,\n workbookName: newWorkbookName,\n };\n }\n \n return node;\n });\n \n return astToString(updatedAst);\n } catch (error) {\n // If parsing fails, return the original formula\n return formula;\n }\n}\n\n/**\n * Checks if a formula references a specific workbook\n * @param formula The formula string (without the leading =)\n * @param workbookName The workbook name to check for\n * @returns True if the formula references the workbook\n */\nexport function formulaReferencesWorkbook(formula: string, workbookName: string): boolean {\n try {\n const referencedWorkbooks = getReferencedWorkbookNames(formula);\n return referencedWorkbooks.includes(workbookName);\n } catch (error) {\n // If parsing fails, assume no reference\n return false;\n }\n}\n\n/**\n * Gets all workbook names referenced in a formula\n * @param formula The formula string (without the leading =)\n * @returns Array of unique workbook names referenced in the formula\n */\nexport function getReferencedWorkbookNames(formula: string): string[] {\n try {\n const ast = parseFormula(formula);\n const workbookNames = new Set<string>();\n\n transformAST(ast, (node) => {\n // Handle cross-workbook references\n if ((node.type === \"reference\" || \n node.type === \"range\" || \n node.type === \"named-expression\" || \n node.type === \"structured-reference\" ||\n node.type === \"3d-range\") && \n node.workbookName) {\n workbookNames.add(node.workbookName);\n }\n \n return node;\n });\n\n return Array.from(workbookNames);\n } catch (error) {\n // If parsing fails, return empty array\n return [];\n }\n}\n"
6
6
  ],
7
7
  "mappings": ";AAIA;AACA;AACA;AAUO,SAAS,uBAAuB,CAAC,SAI7B;AAAA,EACT,QAAQ,SAAS,iBAAiB,oBAAoB;AAAA,EACtD,IAAI;AAAA,IACF,MAAM,MAAM,aAAa,OAAO;AAAA,IAEhC,MAAM,aAAa,aAAa,KAAK,CAAC,SAAS;AAAA,MAE7C,IAAI,KAAK,SAAS,eAAe,KAAK,iBAAiB,iBAAiB;AAAA,QACtE,OAAO;AAAA,aACF;AAAA,UACH,cAAc;AAAA,QAChB;AAAA,MACF;AAAA,MAGA,IAAI,KAAK,SAAS,WAAW,KAAK,iBAAiB,iBAAiB;AAAA,QAClE,OAAO;AAAA,aACF;AAAA,UACH,cAAc;AAAA,QAChB;AAAA,MACF;AAAA,MAGA,IAAI,KAAK,SAAS,sBAAsB,KAAK,iBAAiB,iBAAiB;AAAA,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