@ricsam/formula-engine 0.0.14 → 0.0.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/core/autofill-utils.cjs +13 -1
- package/dist/cjs/core/autofill-utils.cjs.map +3 -3
- package/dist/cjs/core/engine.cjs +32 -1
- package/dist/cjs/core/engine.cjs.map +3 -3
- package/dist/cjs/core/managers/copy-manager.cjs +23 -2
- package/dist/cjs/core/managers/copy-manager.cjs.map +3 -3
- package/dist/cjs/core/managers/style-manager.cjs +34 -9
- package/dist/cjs/core/managers/style-manager.cjs.map +3 -3
- package/dist/cjs/core/managers/workbook-manager.cjs +18 -1
- package/dist/cjs/core/managers/workbook-manager.cjs.map +3 -3
- package/dist/cjs/package.json +1 -1
- package/dist/mjs/core/autofill-utils.mjs +13 -1
- package/dist/mjs/core/autofill-utils.mjs.map +3 -3
- package/dist/mjs/core/engine.mjs +32 -1
- package/dist/mjs/core/engine.mjs.map +3 -3
- package/dist/mjs/core/managers/copy-manager.mjs +23 -2
- package/dist/mjs/core/managers/copy-manager.mjs.map +3 -3
- package/dist/mjs/core/managers/style-manager.mjs +39 -10
- package/dist/mjs/core/managers/style-manager.mjs.map +3 -3
- package/dist/mjs/core/managers/workbook-manager.mjs +18 -1
- package/dist/mjs/core/managers/workbook-manager.mjs.map +3 -3
- package/dist/mjs/package.json +1 -1
- package/dist/types/core/autofill-utils.d.ts +1 -0
- package/dist/types/core/managers/copy-manager.d.ts +3 -0
- package/dist/types/core/managers/style-manager.d.ts +10 -0
- package/dist/types/core/managers/workbook-manager.d.ts +1 -0
- package/package.json +1 -1
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/core/managers/style-manager.ts"],
|
|
4
4
|
"sourcesContent": [
|
|
5
|
-
"/**\n * StyleManager - Manages conditional styling for cells\n */\n\nimport type {\n CellAddress,\n CellStyle,\n ConditionalStyle,\n DirectCellStyle,\n RangeAddress,\n SerializedCellValue,\n} from \"../types.mjs\";\nimport type { WorkbookManager } from \"./workbook-manager.mjs\";\nimport type { EvaluationManager } from \"./evaluation-manager.mjs\";\nimport { isCellInRange } from \"../utils.mjs\";\nimport {\n calculateGradientFactor,\n interpolateLCH,\n lchToHex,\n} from \"../utils/color-utils.mjs\";\nimport { subtractRange, rangesIntersect, isRangeContained } from \"../utils/range-utils.mjs\";\n\nexport class StyleManager {\n private conditionalStyles: ConditionalStyle[] = [];\n private cellStyles: DirectCellStyle[] = [];\n\n constructor(private evaluationManager: EvaluationManager) {}\n\n /**\n * Add a conditional style rule\n */\n addConditionalStyle(style: ConditionalStyle): void {\n this.conditionalStyles.push(style);\n }\n\n /**\n * Remove a conditional style rule by index for a specific workbook\n */\n removeConditionalStyle(workbookName: string, index: number): boolean {\n const workbookStyles = this.conditionalStyles.filter(\n (style) => style.area.workbookName === workbookName\n );\n if (index < 0 || index >= workbookStyles.length) {\n return false;\n }\n // Find the actual index in the full array\n let currentIndex = 0;\n for (let i = 0; i < this.conditionalStyles.length; i++) {\n const style = this.conditionalStyles[i];\n if (style && style.area.workbookName === workbookName) {\n if (currentIndex === index) {\n this.conditionalStyles.splice(i, 1);\n return true;\n }\n currentIndex++;\n }\n }\n return false;\n }\n\n /**\n * Get all conditional styles intersecting with a range\n */\n getConditionalStylesIntersectingWithRange(range: RangeAddress): ConditionalStyle[] {\n return this.conditionalStyles.filter(\n (style) =>\n style.area.workbookName === range.workbookName &&\n style.area.sheetName === range.sheetName &&\n rangesIntersect(style.area.range, range.range)\n );\n }\n\n /**\n * Add a direct cell style rule\n */\n addCellStyle(style: DirectCellStyle): void {\n this.cellStyles.push(style);\n }\n\n /**\n * Remove a direct cell style rule by index for a specific workbook\n */\n removeCellStyle(workbookName: string, index: number): boolean {\n const workbookStyles = this.cellStyles.filter(\n (style) => style && style.area && style.area.workbookName === workbookName\n );\n if (index < 0 || index >= workbookStyles.length) {\n return false;\n }\n // Find the actual index in the full array\n let currentIndex = 0;\n for (let i = 0; i < this.cellStyles.length; i++) {\n const style = this.cellStyles[i];\n if (style && style.area && style.area.workbookName === workbookName) {\n if (currentIndex === index) {\n this.cellStyles.splice(i, 1);\n return true;\n }\n currentIndex++;\n }\n }\n return false;\n }\n\n /**\n * Get all direct cell styles intersecting with a range\n */\n getStylesIntersectingWithRange(range: RangeAddress): DirectCellStyle[] {\n return this.cellStyles.filter(\n (style) =>\n style &&\n style.area.sheetName === range.sheetName &&\n style.area.workbookName === range.workbookName &&\n rangesIntersect(style.area.range, range.range)\n );\n }\n\n /**\n * Get the style for a range if all cells in the range have the same style\n * Returns the DirectCellStyle if the range is completely contained within a single style's area\n * Returns undefined if multiple styles, partial coverage, or no styles apply\n */\n getStyleForRange(range: RangeAddress): DirectCellStyle | undefined {\n const intersectingStyles = this.getStylesIntersectingWithRange(range);\n \n // If no styles intersect, return undefined\n if (intersectingStyles.length === 0) {\n return undefined;\n }\n \n // If multiple styles intersect, return undefined (range has mixed styles)\n if (intersectingStyles.length > 1) {\n return undefined;\n }\n \n // Check if the range is completely contained within the single style's area\n const style = intersectingStyles[0]!;\n if (isRangeContained(range.range, style.area.range)) {\n return style;\n }\n \n // Range is not completely contained, return undefined\n return undefined;\n }\n\n /**\n * Get all conditional styles across all workbooks (for serialization)\n */\n getAllConditionalStyles(): ConditionalStyle[] {\n return [...this.conditionalStyles];\n }\n\n /**\n * Get all cell styles (for serialization)\n */\n getAllCellStyles(): DirectCellStyle[] {\n return [...this.cellStyles];\n }\n\n /**\n * Reset all styles (for deserialization)\n */\n resetStyles(\n conditionalStyles?: ConditionalStyle[],\n cellStyles?: DirectCellStyle[]\n ): void {\n this.conditionalStyles = conditionalStyles ? [...conditionalStyles] : [];\n this.cellStyles = cellStyles ? [...cellStyles] : [];\n }\n\n /**\n * Remove all styles for a workbook\n */\n removeWorkbookStyles(workbookName: string): void {\n this.conditionalStyles = this.conditionalStyles.filter(\n (style) => style.area.workbookName !== workbookName\n );\n this.cellStyles = this.cellStyles.filter(\n (style) => style.area.workbookName !== workbookName\n );\n }\n\n /**\n * Update workbook name in all style references\n */\n updateWorkbookName(oldName: string, newName: string): void {\n // Update conditional styles\n this.conditionalStyles = this.conditionalStyles.map((style) => {\n if (style.area.workbookName === oldName) {\n return {\n ...style,\n area: {\n ...style.area,\n workbookName: newName,\n },\n };\n }\n return style;\n });\n // Update cell styles\n this.cellStyles = this.cellStyles.map((style) => {\n if (style.area.workbookName === oldName) {\n return {\n ...style,\n area: {\n ...style.area,\n workbookName: newName,\n },\n };\n }\n return style;\n });\n }\n\n /**\n * Update sheet name in style references\n */\n updateSheetName(\n workbookName: string,\n oldSheetName: string,\n newSheetName: string\n ): void {\n // Update conditional styles\n this.conditionalStyles = this.conditionalStyles.map((style) => {\n if (\n style.area.workbookName === workbookName &&\n style.area.sheetName === oldSheetName\n ) {\n return {\n ...style,\n area: {\n ...style.area,\n sheetName: newSheetName,\n },\n };\n }\n return style;\n });\n // Update cell styles\n this.cellStyles = this.cellStyles.map((style) => {\n if (\n style.area.workbookName === workbookName &&\n style.area.sheetName === oldSheetName\n ) {\n return {\n ...style,\n area: {\n ...style.area,\n sheetName: newSheetName,\n },\n };\n }\n return style;\n });\n }\n\n /**\n * Remove styles that reference a deleted sheet\n */\n removeSheetStyles(workbookName: string, sheetName: string): void {\n this.conditionalStyles = this.conditionalStyles.filter(\n (style) =>\n !(\n style.area.workbookName === workbookName &&\n style.area.sheetName === sheetName\n )\n );\n this.cellStyles = this.cellStyles.filter(\n (style) =>\n !(\n style.area.workbookName === workbookName &&\n style.area.sheetName === sheetName\n )\n );\n }\n\n /**\n * Get the style for a specific cell\n * Returns the first matching style (first match wins)\n * Checks cellStyles first, then conditionalStyles\n */\n getCellStyle(cellAddress: CellAddress): CellStyle | undefined {\n // First check direct cell styles\n for (const cellStyle of this.cellStyles) {\n if (!cellStyle || !cellStyle.area) {\n continue;\n }\n if (\n cellStyle.area.workbookName === cellAddress.workbookName &&\n cellStyle.area.sheetName === cellAddress.sheetName &&\n isCellInRange(cellAddress, cellStyle.area.range)\n ) {\n return cellStyle.style;\n }\n }\n\n // Then check conditional styles\n for (const style of this.conditionalStyles) {\n if (!style || !style.area) {\n continue;\n }\n // Check if cell is in the style's area\n if (\n style.area.sheetName !== cellAddress.sheetName ||\n style.area.workbookName !== cellAddress.workbookName\n ) {\n continue;\n }\n\n if (!isCellInRange(cellAddress, style.area.range)) {\n continue;\n }\n\n // Cell is in area, evaluate condition\n if (style.condition.type === \"formula\") {\n const result = this.evaluateFormulaCondition(cellAddress, style);\n if (result) return result;\n } else {\n const result = this.evaluateGradientCondition(cellAddress, style);\n if (result) return result;\n }\n }\n\n return undefined;\n }\n\n /**\n * Evaluate a formula-based style condition\n */\n private evaluateFormulaCondition(\n cellAddress: CellAddress,\n style: ConditionalStyle\n ): CellStyle | undefined {\n if (style.condition.type !== \"formula\") {\n return undefined;\n }\n\n try {\n // Evaluate formula in context of the cell\n // evaluateFormula expects a full cell value (with = prefix for formulas)\n const formula = style.condition.formula.startsWith(\"=\")\n ? style.condition.formula\n : `=${style.condition.formula}`;\n\n const result = this.evaluationManager.evaluateFormula(\n formula,\n cellAddress\n );\n\n // Check if result is truthy\n const isTruthy =\n result === true ||\n result === \"TRUE\" ||\n (typeof result === \"number\" && result !== 0);\n\n if (isTruthy) {\n return {\n backgroundColor: lchToHex(style.condition.color),\n };\n }\n } catch (error) {\n // If formula evaluation fails, don't apply style\n console.warn(\"Failed to evaluate formula condition:\", error);\n }\n\n return undefined;\n }\n\n /**\n * Evaluate a gradient-based style condition\n */\n private evaluateGradientCondition(\n cellAddress: CellAddress,\n style: ConditionalStyle\n ): CellStyle | undefined {\n if (style.condition.type !== \"gradient\") {\n return undefined;\n }\n\n try {\n // Get the cell's evaluation result\n const evalResult =\n this.evaluationManager.getCellEvaluationResult(cellAddress);\n if (!evalResult || evalResult.type !== \"value\") {\n return undefined;\n }\n if (evalResult.result.type !== \"number\") {\n return undefined;\n }\n const cellValue = evalResult.result.value;\n\n // Calculate min and max values for the gradient\n const { min: minValue, max: maxValue } = this.calculateGradientBounds(\n style,\n cellAddress\n );\n\n if (minValue === null || maxValue === null) {\n return undefined;\n }\n\n // Calculate interpolation factor\n const factor = calculateGradientFactor(cellValue, minValue, maxValue);\n\n // Interpolate between min and max colors\n const minColor = style.condition.min.color;\n const maxColor = style.condition.max.color;\n const interpolatedColor = interpolateLCH(minColor, maxColor, factor);\n\n return {\n backgroundColor: lchToHex(interpolatedColor),\n };\n } catch (error) {\n console.warn(\"Failed to evaluate gradient condition:\", error);\n return undefined;\n }\n }\n\n /**\n * Calculate min and max bounds for a gradient\n */\n private calculateGradientBounds(\n style: ConditionalStyle,\n cellAddress: CellAddress\n ): { min: number | null; max: number | null } {\n if (style.condition.type !== \"gradient\") {\n return { min: null, max: null };\n }\n\n const { min: minConfig, max: maxConfig } = style.condition;\n const topLeftCell: CellAddress = {\n workbookName: style.area.workbookName,\n sheetName: style.area.sheetName,\n colIndex: style.area.range.start.col,\n rowIndex: style.area.range.start.row,\n };\n\n // Calculate min value\n let minValue: number | null = null;\n if (minConfig.type === \"lowest_value\") {\n // Evaluate MIN(range) formula directly\n try {\n const rangeRef = this.getRangeReference(style.area);\n const result = this.evaluationManager.evaluateFormula(\n `=MIN(${rangeRef})`,\n topLeftCell\n );\n if (typeof result === \"number\") {\n minValue = result;\n }\n } catch (error) {\n console.warn(\"Failed to calculate MIN:\", error);\n }\n } else {\n // Evaluate valueFormula in context of area's top-left cell\n const formula = minConfig.valueFormula.startsWith(\"=\")\n ? minConfig.valueFormula\n : `=${minConfig.valueFormula}`;\n const result = this.evaluationManager.evaluateFormula(\n formula,\n topLeftCell\n );\n if (typeof result === \"number\") {\n minValue = result;\n }\n }\n\n // Calculate max value\n let maxValue: number | null = null;\n if (maxConfig.type === \"highest_value\") {\n // Evaluate MAX(range) formula directly\n try {\n const rangeRef = this.getRangeReference(style.area);\n const result = this.evaluationManager.evaluateFormula(\n `=MAX(${rangeRef})`,\n topLeftCell\n );\n if (typeof result === \"number\") {\n maxValue = result;\n }\n } catch (error) {\n console.warn(\"Failed to calculate MAX:\", error);\n }\n } else {\n // Evaluate valueFormula in context of area's top-left cell\n const formula = maxConfig.valueFormula.startsWith(\"=\")\n ? maxConfig.valueFormula\n : `=${maxConfig.valueFormula}`;\n const result = this.evaluationManager.evaluateFormula(\n formula,\n topLeftCell\n );\n if (typeof result === \"number\") {\n maxValue = result;\n }\n }\n\n return { min: minValue, max: maxValue };\n }\n\n /**\n * Get a range reference string from a RangeAddress\n * Follows CANONICAL_RANGES.md format:\n * - Closed: A5:D10\n * - Row-bounded (col-open): A5:10\n * - Col-bounded (row-open): A5:D\n * - Open both: A5:INFINITY\n */\n private getRangeReference(area: RangeAddress): string {\n const colToLetter = (col: number): string => {\n let result = \"\";\n let c = col;\n while (c >= 0) {\n result = String.fromCharCode(65 + (c % 26)) + result;\n c = Math.floor(c / 26) - 1;\n }\n return result;\n };\n\n const startCol = colToLetter(area.range.start.col);\n const startRow = area.range.start.row + 1; // Convert to 1-based\n\n const isColInfinity = area.range.end.col.type === \"infinity\";\n const isRowInfinity = area.range.end.row.type === \"infinity\";\n\n let rangeStr: string;\n\n if (isColInfinity && isRowInfinity) {\n // Open both: A5:INFINITY\n rangeStr = `${startCol}${startRow}:INFINITY`;\n } else if (isColInfinity) {\n // Row-bounded (col-open): A5:10\n if (area.range.end.row.type === \"number\") {\n const endRow = area.range.end.row.value + 1; // Convert to 1-based\n rangeStr = `${startCol}${startRow}:${endRow}`;\n } else {\n rangeStr = `${startCol}${startRow}:INFINITY`;\n }\n } else if (isRowInfinity) {\n // Col-bounded (row-open): A5:D\n if (area.range.end.col.type === \"number\") {\n const endCol = colToLetter(area.range.end.col.value);\n rangeStr = `${startCol}${startRow}:${endCol}`;\n } else {\n rangeStr = `${startCol}${startRow}:INFINITY`;\n }\n } else {\n // Closed rectangle: A5:D10\n if (\n area.range.end.col.type === \"number\" &&\n area.range.end.row.type === \"number\"\n ) {\n const endCol = colToLetter(area.range.end.col.value);\n const endRow = area.range.end.row.value + 1; // Convert to 1-based\n rangeStr = `${startCol}${startRow}:${endCol}${endRow}`;\n } else {\n // Fallback to INFINITY if types don't match\n rangeStr = `${startCol}${startRow}:INFINITY`;\n }\n }\n\n // Quote sheet name if it contains spaces or special characters\n const needsQuotes = /[ '!]/.test(area.sheetName);\n const sheetRef = needsQuotes\n ? `'${area.sheetName.replace(/'/g, \"''\")}'`\n : area.sheetName;\n\n // Construct the full reference: [workbook]'sheet'!range\n return `[${area.workbookName}]${sheetRef}!${rangeStr}`;\n }\n\n /**\n * Clear cell styles and conditional styles for a given range\n * Adjusts existing style ranges rather than deleting them entirely\n */\n clearCellStyles(range: RangeAddress): void {\n // Process cellStyles\n const newCellStyles: DirectCellStyle[] = [];\n for (const cellStyle of this.cellStyles) {\n if (!cellStyle || !cellStyle.area) {\n newCellStyles.push(cellStyle);\n continue;\n }\n\n // Check if this style intersects with the clear range\n if (\n cellStyle.area.workbookName === range.workbookName &&\n cellStyle.area.sheetName === range.sheetName &&\n rangesIntersect(cellStyle.area.range, range.range)\n ) {\n // Subtract the clear range from this style's range\n const remainingRanges = subtractRange(\n cellStyle.area.range,\n range.range\n );\n\n // Add new styles for each remaining range\n for (const remainingRange of remainingRanges) {\n newCellStyles.push({\n area: {\n workbookName: cellStyle.area.workbookName,\n sheetName: cellStyle.area.sheetName,\n range: remainingRange,\n },\n style: cellStyle.style,\n });\n }\n } else {\n // No intersection, keep the style as-is\n newCellStyles.push(cellStyle);\n }\n }\n this.cellStyles = newCellStyles;\n\n // Process conditionalStyles\n const newConditionalStyles: ConditionalStyle[] = [];\n for (const conditionalStyle of this.conditionalStyles) {\n if (!conditionalStyle || !conditionalStyle.area) {\n newConditionalStyles.push(conditionalStyle);\n continue;\n }\n\n // Check if this style intersects with the clear range\n if (\n conditionalStyle.area.workbookName === range.workbookName &&\n conditionalStyle.area.sheetName === range.sheetName &&\n rangesIntersect(conditionalStyle.area.range, range.range)\n ) {\n // Subtract the clear range from this style's range\n const remainingRanges = subtractRange(\n conditionalStyle.area.range,\n range.range\n );\n\n // Add new styles for each remaining range\n for (const remainingRange of remainingRanges) {\n newConditionalStyles.push({\n area: {\n workbookName: conditionalStyle.area.workbookName,\n sheetName: conditionalStyle.area.sheetName,\n range: remainingRange,\n },\n condition: conditionalStyle.condition,\n });\n }\n } else {\n // No intersection, keep the style as-is\n newConditionalStyles.push(conditionalStyle);\n }\n }\n this.conditionalStyles = newConditionalStyles;\n }\n}\n"
|
|
5
|
+
"/**\n * StyleManager - Manages conditional styling for cells\n */\n\nimport type {\n CellAddress,\n CellStyle,\n ConditionalStyle,\n DirectCellStyle,\n RangeAddress,\n SerializedCellValue,\n} from \"../types.mjs\";\nimport type { WorkbookManager } from \"./workbook-manager.mjs\";\nimport type { EvaluationManager } from \"./evaluation-manager.mjs\";\nimport { isCellInRange } from \"../utils.mjs\";\nimport {\n calculateGradientFactor,\n interpolateLCH,\n lchToHex,\n} from \"../utils/color-utils.mjs\";\nimport {\n subtractRange,\n rangesIntersect,\n isRangeContained,\n} from \"../utils/range-utils.mjs\";\n\nexport class StyleManager {\n private conditionalStyles: ConditionalStyle[] = [];\n private cellStyles: DirectCellStyle[] = [];\n\n constructor(private evaluationManager: EvaluationManager) {}\n\n /**\n * Add a conditional style rule\n */\n addConditionalStyle(style: ConditionalStyle): void {\n this.conditionalStyles.push(style);\n }\n\n /**\n * Remove a conditional style rule by index for a specific workbook\n */\n removeConditionalStyle(workbookName: string, index: number): boolean {\n const workbookStyles = this.conditionalStyles.filter(\n (style) => style.area.workbookName === workbookName\n );\n if (index < 0 || index >= workbookStyles.length) {\n return false;\n }\n // Find the actual index in the full array\n let currentIndex = 0;\n for (let i = 0; i < this.conditionalStyles.length; i++) {\n const style = this.conditionalStyles[i];\n if (style && style.area.workbookName === workbookName) {\n if (currentIndex === index) {\n this.conditionalStyles.splice(i, 1);\n return true;\n }\n currentIndex++;\n }\n }\n return false;\n }\n\n /**\n * Get all conditional styles intersecting with a range\n */\n getConditionalStylesIntersectingWithRange(\n range: RangeAddress\n ): ConditionalStyle[] {\n return this.conditionalStyles.filter(\n (style) =>\n style.area.workbookName === range.workbookName &&\n style.area.sheetName === range.sheetName &&\n rangesIntersect(style.area.range, range.range)\n );\n }\n\n /**\n * Add a direct cell style rule\n */\n addCellStyle(style: DirectCellStyle): void {\n this.cellStyles.push(style);\n }\n\n /**\n * Remove a direct cell style rule by index for a specific workbook\n */\n removeCellStyle(workbookName: string, index: number): boolean {\n const workbookStyles = this.cellStyles.filter(\n (style) => style && style.area && style.area.workbookName === workbookName\n );\n if (index < 0 || index >= workbookStyles.length) {\n return false;\n }\n // Find the actual index in the full array\n let currentIndex = 0;\n for (let i = 0; i < this.cellStyles.length; i++) {\n const style = this.cellStyles[i];\n if (style && style.area && style.area.workbookName === workbookName) {\n if (currentIndex === index) {\n this.cellStyles.splice(i, 1);\n return true;\n }\n currentIndex++;\n }\n }\n return false;\n }\n\n /**\n * Get all direct cell styles intersecting with a range\n */\n getStylesIntersectingWithRange(range: RangeAddress): DirectCellStyle[] {\n return this.cellStyles.filter(\n (style) =>\n style &&\n style.area.sheetName === range.sheetName &&\n style.area.workbookName === range.workbookName &&\n rangesIntersect(style.area.range, range.range)\n );\n }\n\n /**\n * Get the style for a range if all cells in the range have the same style\n * Returns the DirectCellStyle if the range is completely contained within a single style's area\n * Returns undefined if multiple styles, partial coverage, or no styles apply\n */\n getStyleForRange(range: RangeAddress): DirectCellStyle | undefined {\n const intersectingStyles = this.getStylesIntersectingWithRange(range);\n\n // If no styles intersect, return undefined\n if (intersectingStyles.length === 0) {\n return undefined;\n }\n\n // If multiple styles intersect, return undefined (range has mixed styles)\n if (intersectingStyles.length > 1) {\n return undefined;\n }\n\n // Check if the range is completely contained within the single style's area\n const style = intersectingStyles[0]!;\n if (isRangeContained(range.range, style.area.range)) {\n return style;\n }\n\n // Range is not completely contained, return undefined\n return undefined;\n }\n\n /**\n * Get all conditional styles across all workbooks (for serialization)\n */\n getAllConditionalStyles(): ConditionalStyle[] {\n return [...this.conditionalStyles];\n }\n\n /**\n * Get all cell styles (for serialization)\n */\n getAllCellStyles(): DirectCellStyle[] {\n return [...this.cellStyles];\n }\n\n /**\n * Reset all styles (for deserialization)\n */\n resetStyles(\n conditionalStyles?: ConditionalStyle[],\n cellStyles?: DirectCellStyle[]\n ): void {\n this.conditionalStyles = conditionalStyles ? [...conditionalStyles] : [];\n this.cellStyles = cellStyles ? [...cellStyles] : [];\n }\n\n /**\n * Remove all styles for a workbook\n */\n removeWorkbookStyles(workbookName: string): void {\n this.conditionalStyles = this.conditionalStyles.filter(\n (style) => style.area.workbookName !== workbookName\n );\n this.cellStyles = this.cellStyles.filter(\n (style) => style.area.workbookName !== workbookName\n );\n }\n\n /**\n * Update workbook name in all style references\n */\n updateWorkbookName(oldName: string, newName: string): void {\n // Update conditional styles\n this.conditionalStyles = this.conditionalStyles.map((style) => {\n if (style.area.workbookName === oldName) {\n return {\n ...style,\n area: {\n ...style.area,\n workbookName: newName,\n },\n };\n }\n return style;\n });\n // Update cell styles\n this.cellStyles = this.cellStyles.map((style) => {\n if (style.area.workbookName === oldName) {\n return {\n ...style,\n area: {\n ...style.area,\n workbookName: newName,\n },\n };\n }\n return style;\n });\n }\n\n /**\n * Update sheet name in style references\n */\n updateSheetName(\n workbookName: string,\n oldSheetName: string,\n newSheetName: string\n ): void {\n // Update conditional styles\n this.conditionalStyles = this.conditionalStyles.map((style) => {\n if (\n style.area.workbookName === workbookName &&\n style.area.sheetName === oldSheetName\n ) {\n return {\n ...style,\n area: {\n ...style.area,\n sheetName: newSheetName,\n },\n };\n }\n return style;\n });\n // Update cell styles\n this.cellStyles = this.cellStyles.map((style) => {\n if (\n style.area.workbookName === workbookName &&\n style.area.sheetName === oldSheetName\n ) {\n return {\n ...style,\n area: {\n ...style.area,\n sheetName: newSheetName,\n },\n };\n }\n return style;\n });\n }\n\n /**\n * Remove styles that reference a deleted sheet\n */\n removeSheetStyles(workbookName: string, sheetName: string): void {\n this.conditionalStyles = this.conditionalStyles.filter(\n (style) =>\n !(\n style.area.workbookName === workbookName &&\n style.area.sheetName === sheetName\n )\n );\n this.cellStyles = this.cellStyles.filter(\n (style) =>\n !(\n style.area.workbookName === workbookName &&\n style.area.sheetName === sheetName\n )\n );\n }\n\n /**\n * Get the style for a specific cell\n * Returns the first matching style (first match wins)\n * Checks cellStyles first, then conditionalStyles\n */\n getCellStyle(cellAddress: CellAddress): CellStyle | undefined {\n // First check conditional styles\n for (const style of this.conditionalStyles) {\n if (!style || !style.area) {\n continue;\n }\n // Check if cell is in the style's area\n if (\n style.area.sheetName !== cellAddress.sheetName ||\n style.area.workbookName !== cellAddress.workbookName\n ) {\n continue;\n }\n\n if (!isCellInRange(cellAddress, style.area.range)) {\n continue;\n }\n\n // Cell is in area, evaluate condition\n if (style.condition.type === \"formula\") {\n const result = this.evaluateFormulaCondition(cellAddress, style);\n if (result) return result;\n } else {\n const result = this.evaluateGradientCondition(cellAddress, style);\n if (result) return result;\n }\n }\n\n // Then check direct cell styles\n for (const cellStyle of this.cellStyles) {\n if (!cellStyle || !cellStyle.area) {\n continue;\n }\n if (\n cellStyle.area.workbookName === cellAddress.workbookName &&\n cellStyle.area.sheetName === cellAddress.sheetName &&\n isCellInRange(cellAddress, cellStyle.area.range)\n ) {\n return cellStyle.style;\n }\n }\n\n return undefined;\n }\n\n /**\n * Evaluate a formula-based style condition\n */\n private evaluateFormulaCondition(\n cellAddress: CellAddress,\n style: ConditionalStyle\n ): CellStyle | undefined {\n if (style.condition.type !== \"formula\") {\n return undefined;\n }\n\n try {\n // Evaluate formula in context of the cell\n // evaluateFormula expects a full cell value (with = prefix for formulas)\n const formula = style.condition.formula.startsWith(\"=\")\n ? style.condition.formula\n : `=${style.condition.formula}`;\n\n const result = this.evaluationManager.evaluateFormula(\n formula,\n cellAddress\n );\n\n // Check if result is truthy\n const isTruthy =\n result === true ||\n result === \"TRUE\" ||\n (typeof result === \"number\" && result !== 0);\n\n if (isTruthy) {\n return {\n backgroundColor: lchToHex(style.condition.color),\n };\n }\n } catch (error) {\n // If formula evaluation fails, don't apply style\n console.warn(\"Failed to evaluate formula condition:\", error);\n }\n\n return undefined;\n }\n\n /**\n * Evaluate a gradient-based style condition\n */\n private evaluateGradientCondition(\n cellAddress: CellAddress,\n style: ConditionalStyle\n ): CellStyle | undefined {\n if (style.condition.type !== \"gradient\") {\n return undefined;\n }\n\n try {\n // Get the cell's evaluation result\n const evalResult =\n this.evaluationManager.getCellEvaluationResult(cellAddress);\n if (!evalResult || evalResult.type !== \"value\") {\n return undefined;\n }\n if (evalResult.result.type !== \"number\") {\n return undefined;\n }\n const cellValue = evalResult.result.value;\n\n // Calculate min and max values for the gradient\n const { min: minValue, max: maxValue } = this.calculateGradientBounds(\n style,\n cellAddress\n );\n\n if (minValue === null || maxValue === null) {\n return undefined;\n }\n\n // Calculate interpolation factor\n const factor = calculateGradientFactor(cellValue, minValue, maxValue);\n\n // Interpolate between min and max colors\n const minColor = style.condition.min.color;\n const maxColor = style.condition.max.color;\n const interpolatedColor = interpolateLCH(minColor, maxColor, factor);\n\n return {\n backgroundColor: lchToHex(interpolatedColor),\n };\n } catch (error) {\n console.warn(\"Failed to evaluate gradient condition:\", error);\n return undefined;\n }\n }\n\n /**\n * Calculate min and max bounds for a gradient\n */\n private calculateGradientBounds(\n style: ConditionalStyle,\n cellAddress: CellAddress\n ): { min: number | null; max: number | null } {\n if (style.condition.type !== \"gradient\") {\n return { min: null, max: null };\n }\n\n const { min: minConfig, max: maxConfig } = style.condition;\n const topLeftCell: CellAddress = {\n workbookName: style.area.workbookName,\n sheetName: style.area.sheetName,\n colIndex: style.area.range.start.col,\n rowIndex: style.area.range.start.row,\n };\n\n // Calculate min value\n let minValue: number | null = null;\n if (minConfig.type === \"lowest_value\") {\n // Evaluate MIN(range) formula directly\n try {\n const rangeRef = this.getRangeReference(style.area);\n const result = this.evaluationManager.evaluateFormula(\n `=MIN(${rangeRef})`,\n topLeftCell\n );\n if (typeof result === \"number\") {\n minValue = result;\n }\n } catch (error) {\n console.warn(\"Failed to calculate MIN:\", error);\n }\n } else {\n // Evaluate valueFormula in context of area's top-left cell\n const formula = minConfig.valueFormula.startsWith(\"=\")\n ? minConfig.valueFormula\n : `=${minConfig.valueFormula}`;\n const result = this.evaluationManager.evaluateFormula(\n formula,\n topLeftCell\n );\n if (typeof result === \"number\") {\n minValue = result;\n }\n }\n\n // Calculate max value\n let maxValue: number | null = null;\n if (maxConfig.type === \"highest_value\") {\n // Evaluate MAX(range) formula directly\n try {\n const rangeRef = this.getRangeReference(style.area);\n const result = this.evaluationManager.evaluateFormula(\n `=MAX(${rangeRef})`,\n topLeftCell\n );\n if (typeof result === \"number\") {\n maxValue = result;\n }\n } catch (error) {\n console.warn(\"Failed to calculate MAX:\", error);\n }\n } else {\n // Evaluate valueFormula in context of area's top-left cell\n const formula = maxConfig.valueFormula.startsWith(\"=\")\n ? maxConfig.valueFormula\n : `=${maxConfig.valueFormula}`;\n const result = this.evaluationManager.evaluateFormula(\n formula,\n topLeftCell\n );\n if (typeof result === \"number\") {\n maxValue = result;\n }\n }\n\n return { min: minValue, max: maxValue };\n }\n\n /**\n * Get a range reference string from a RangeAddress\n * Follows CANONICAL_RANGES.md format:\n * - Closed: A5:D10\n * - Row-bounded (col-open): A5:10\n * - Col-bounded (row-open): A5:D\n * - Open both: A5:INFINITY\n */\n private getRangeReference(area: RangeAddress): string {\n const colToLetter = (col: number): string => {\n let result = \"\";\n let c = col;\n while (c >= 0) {\n result = String.fromCharCode(65 + (c % 26)) + result;\n c = Math.floor(c / 26) - 1;\n }\n return result;\n };\n\n const startCol = colToLetter(area.range.start.col);\n const startRow = area.range.start.row + 1; // Convert to 1-based\n\n const isColInfinity = area.range.end.col.type === \"infinity\";\n const isRowInfinity = area.range.end.row.type === \"infinity\";\n\n let rangeStr: string;\n\n if (isColInfinity && isRowInfinity) {\n // Open both: A5:INFINITY\n rangeStr = `${startCol}${startRow}:INFINITY`;\n } else if (isColInfinity) {\n // Row-bounded (col-open): A5:10\n if (area.range.end.row.type === \"number\") {\n const endRow = area.range.end.row.value + 1; // Convert to 1-based\n rangeStr = `${startCol}${startRow}:${endRow}`;\n } else {\n rangeStr = `${startCol}${startRow}:INFINITY`;\n }\n } else if (isRowInfinity) {\n // Col-bounded (row-open): A5:D\n if (area.range.end.col.type === \"number\") {\n const endCol = colToLetter(area.range.end.col.value);\n rangeStr = `${startCol}${startRow}:${endCol}`;\n } else {\n rangeStr = `${startCol}${startRow}:INFINITY`;\n }\n } else {\n // Closed rectangle: A5:D10\n if (\n area.range.end.col.type === \"number\" &&\n area.range.end.row.type === \"number\"\n ) {\n const endCol = colToLetter(area.range.end.col.value);\n const endRow = area.range.end.row.value + 1; // Convert to 1-based\n rangeStr = `${startCol}${startRow}:${endCol}${endRow}`;\n } else {\n // Fallback to INFINITY if types don't match\n rangeStr = `${startCol}${startRow}:INFINITY`;\n }\n }\n\n // Quote sheet name if it contains spaces or special characters\n const needsQuotes = /[ '!]/.test(area.sheetName);\n const sheetRef = needsQuotes\n ? `'${area.sheetName.replace(/'/g, \"''\")}'`\n : area.sheetName;\n\n // Construct the full reference: [workbook]'sheet'!range\n return `[${area.workbookName}]${sheetRef}!${rangeStr}`;\n }\n\n /**\n * Clear cell styles and conditional styles for a given range\n * Adjusts existing style ranges rather than deleting them entirely\n */\n clearCellStyles(range: RangeAddress): void {\n // Process cellStyles\n const newCellStyles: DirectCellStyle[] = [];\n for (const cellStyle of this.cellStyles) {\n if (!cellStyle || !cellStyle.area) {\n newCellStyles.push(cellStyle);\n continue;\n }\n\n // Check if this style intersects with the clear range\n if (\n cellStyle.area.workbookName === range.workbookName &&\n cellStyle.area.sheetName === range.sheetName &&\n rangesIntersect(cellStyle.area.range, range.range)\n ) {\n // Subtract the clear range from this style's range\n const remainingRanges = subtractRange(\n cellStyle.area.range,\n range.range\n );\n\n // Add new styles for each remaining range\n for (const remainingRange of remainingRanges) {\n newCellStyles.push({\n area: {\n workbookName: cellStyle.area.workbookName,\n sheetName: cellStyle.area.sheetName,\n range: remainingRange,\n },\n style: cellStyle.style,\n });\n }\n } else {\n // No intersection, keep the style as-is\n newCellStyles.push(cellStyle);\n }\n }\n this.cellStyles = newCellStyles;\n\n // Process conditionalStyles\n const newConditionalStyles: ConditionalStyle[] = [];\n for (const conditionalStyle of this.conditionalStyles) {\n if (!conditionalStyle || !conditionalStyle.area) {\n newConditionalStyles.push(conditionalStyle);\n continue;\n }\n\n // Check if this style intersects with the clear range\n if (\n conditionalStyle.area.workbookName === range.workbookName &&\n conditionalStyle.area.sheetName === range.sheetName &&\n rangesIntersect(conditionalStyle.area.range, range.range)\n ) {\n // Subtract the clear range from this style's range\n const remainingRanges = subtractRange(\n conditionalStyle.area.range,\n range.range\n );\n\n // Add new styles for each remaining range\n for (const remainingRange of remainingRanges) {\n newConditionalStyles.push({\n area: {\n workbookName: conditionalStyle.area.workbookName,\n sheetName: conditionalStyle.area.sheetName,\n range: remainingRange,\n },\n condition: conditionalStyle.condition,\n });\n }\n } else {\n // No intersection, keep the style as-is\n newConditionalStyles.push(conditionalStyle);\n }\n }\n this.conditionalStyles = newConditionalStyles;\n }\n\n /**\n * Clear cell styles in a range using subtraction\n * For each intersecting style, subtract the cleared range:\n * - If style is completely contained: remove entire style\n * - If style partially overlaps: split into remaining rectangles\n * - If no intersection: keep unchanged\n * \n * This matches Excel's behavior where pasting replaces formatting\n */\n clearCellStylesInRange(range: RangeAddress): void {\n const newCellStyles: DirectCellStyle[] = [];\n\n for (const style of this.cellStyles) {\n // Skip styles from different sheets/workbooks\n if (\n style.area.workbookName !== range.workbookName ||\n style.area.sheetName !== range.sheetName\n ) {\n newCellStyles.push(style);\n continue;\n }\n\n // Check if this style intersects with the range to clear\n if (!rangesIntersect(style.area.range, range.range)) {\n // No intersection, keep the style unchanged\n newCellStyles.push(style);\n continue;\n }\n\n // Style intersects - subtract the cleared range\n const remainingRanges = subtractRange(style.area.range, range.range);\n\n // Create new style entries for each remaining range\n for (const remainingRange of remainingRanges) {\n newCellStyles.push({\n area: {\n workbookName: style.area.workbookName,\n sheetName: style.area.sheetName,\n range: remainingRange,\n },\n style: style.style, // Keep same style properties\n });\n }\n }\n\n this.cellStyles = newCellStyles;\n }\n}\n"
|
|
6
6
|
],
|
|
7
|
-
"mappings": ";AAcA;AACA;AAAA;AAAA;AAAA;AAAA;AAKA;AAAA;
|
|
8
|
-
"debugId": "
|
|
7
|
+
"mappings": ";AAcA;AACA;AAAA;AAAA;AAAA;AAAA;AAKA;AAAA;AAAA;AAAA;AAAA;AAAA;AAMO,MAAM,aAAa;AAAA,EAIJ;AAAA,EAHZ,oBAAwC,CAAC;AAAA,EACzC,aAAgC,CAAC;AAAA,EAEzC,WAAW,CAAS,mBAAsC;AAAA,IAAtC;AAAA;AAAA,EAKpB,mBAAmB,CAAC,OAA+B;AAAA,IACjD,KAAK,kBAAkB,KAAK,KAAK;AAAA;AAAA,EAMnC,sBAAsB,CAAC,cAAsB,OAAwB;AAAA,IACnE,MAAM,iBAAiB,KAAK,kBAAkB,OAC5C,CAAC,UAAU,MAAM,KAAK,iBAAiB,YACzC;AAAA,IACA,IAAI,QAAQ,KAAK,SAAS,eAAe,QAAQ;AAAA,MAC/C,OAAO;AAAA,IACT;AAAA,IAEA,IAAI,eAAe;AAAA,IACnB,SAAS,IAAI,EAAG,IAAI,KAAK,kBAAkB,QAAQ,KAAK;AAAA,MACtD,MAAM,QAAQ,KAAK,kBAAkB;AAAA,MACrC,IAAI,SAAS,MAAM,KAAK,iBAAiB,cAAc;AAAA,QACrD,IAAI,iBAAiB,OAAO;AAAA,UAC1B,KAAK,kBAAkB,OAAO,GAAG,CAAC;AAAA,UAClC,OAAO;AAAA,QACT;AAAA,QACA;AAAA,MACF;AAAA,IACF;AAAA,IACA,OAAO;AAAA;AAAA,EAMT,yCAAyC,CACvC,OACoB;AAAA,IACpB,OAAO,KAAK,kBAAkB,OAC5B,CAAC,UACC,MAAM,KAAK,iBAAiB,MAAM,gBA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A,QAEL,qBAAqB,KAAK,gBAAgB;AAAA;AAAA,IAE9C;AAAA,IACA,KAAK,oBAAoB;AAAA;AAAA,EAY3B,sBAAsB,CAAC,OAA2B;AAAA,IAChD,MAAM,gBAAmC,CAAC;AAAA,IAE1C,WAAW,SAAS,KAAK,YAAY;AAAA,MAEnC,IACE,MAAM,KAAK,iBAAiB,MAAM,gBAClC,MAAM,KAAK,cAAc,MAAM,WAC/B;AAAA,QACA,cAAc,KAAK,KAAK;AAAA,QACxB;AAAA,MACF;AAAA,MAGA,IAAI,CAAC,gBAAgB,MAAM,KAAK,OAAO,MAAM,KAAK,GAAG;AAAA,QAEnD,cAAc,KAAK,KAAK;AAAA,QACxB;AAAA,MACF;AAAA,MAGA,MAAM,kBAAkB,cAAc,MAAM,KAAK,OAAO,MAAM,KAAK;AAAA,MAGnE,WAAW,kBAAkB,iBAAiB;AAAA,QAC5C,cAAc,KAAK;AAAA,UACjB,MAAM;AAAA,YACJ,cAAc,MAAM,KAAK;AAAA,YACzB,WAAW,MAAM,KAAK;AAAA,YACtB,OAAO;AAAA,UACT;AAAA,UACA,OAAO,MAAM;AAAA,QACf,CAAC;AAAA,MACH;AAAA,IACF;AAAA,IAEA,KAAK,aAAa;AAAA;AAEtB;",
|
|
8
|
+
"debugId": "0E37CC199FCD4ED464756E2164756E21",
|
|
9
9
|
"names": []
|
|
10
10
|
}
|
|
@@ -235,6 +235,23 @@ class WorkbookManager {
|
|
|
235
235
|
update(workbook.sheets);
|
|
236
236
|
});
|
|
237
237
|
}
|
|
238
|
+
updateFormulasForWorkbook(workbookName, updateCallback) {
|
|
239
|
+
const workbook = this.workbooks.get(workbookName);
|
|
240
|
+
if (!workbook) {
|
|
241
|
+
throw new WorkbookNotFoundError(workbookName);
|
|
242
|
+
}
|
|
243
|
+
workbook.sheets.forEach((sheet) => {
|
|
244
|
+
sheet.content.forEach((cell, key) => {
|
|
245
|
+
if (typeof cell === "string" && cell.startsWith("=")) {
|
|
246
|
+
const formula = cell.slice(1);
|
|
247
|
+
const updatedFormula = updateCallback(formula);
|
|
248
|
+
if (updatedFormula !== formula) {
|
|
249
|
+
sheet.content.set(key, `=${updatedFormula}`);
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
});
|
|
253
|
+
});
|
|
254
|
+
}
|
|
238
255
|
getSheetSerialized({
|
|
239
256
|
workbookName,
|
|
240
257
|
sheetName
|
|
@@ -444,4 +461,4 @@ export {
|
|
|
444
461
|
IndexEntryBinarySearch
|
|
445
462
|
};
|
|
446
463
|
|
|
447
|
-
//# debugId=
|
|
464
|
+
//# debugId=D632FC8B4BBFB4AF64756E2164756E21
|
|
@@ -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 { 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 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 });\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 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 const sheet = {\n name: sheetName,\n index: workbook.sheets.size,\n content: new Map(),\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 // Update sheets map\n workbook.sheets.set(newSheetName, sheet);\n workbook.sheets.delete(sheetName);\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): void {\n const update = (map: Map<string, Sheet>) => {\n map.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 this.workbooks.forEach((workbook) => {\n update(workbook.sheets);\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 * 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\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\n newContent.delete(cellRef);\n }\n\n // setSheetContent will rebuild indexes from scratch, so no need to manually update them\n this.setSheetContent(address, newContent);\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 private 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 SerializedCellValue,\n type Sheet,\n type SpreadsheetRange,\n type Workbook,\n} from \"../types.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 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 });\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 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 const sheet = {\n name: sheetName,\n index: workbook.sheets.size,\n content: new Map(),\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 // Update sheets map\n workbook.sheets.set(newSheetName, sheet);\n workbook.sheets.delete(sheetName);\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): void {\n const update = (map: Map<string, Sheet>) => {\n map.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 this.workbooks.forEach((workbook) => {\n update(workbook.sheets);\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 * 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\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\n newContent.delete(cellRef);\n }\n\n // setSheetContent will rebuild indexes from scratch, so no need to manually update them\n this.setSheetContent(address, newContent);\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 private 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": ";AAUA;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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mC;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": "D632FC8B4BBFB4AF64756E2164756E21",
|
|
9
9
|
"names": []
|
|
10
10
|
}
|
package/dist/mjs/package.json
CHANGED
|
@@ -29,6 +29,7 @@ export declare class CopyManager {
|
|
|
29
29
|
private adjustFormulaReferences;
|
|
30
30
|
/**
|
|
31
31
|
* Copy formatting (cellStyles and conditionalStyles) from source to target
|
|
32
|
+
* Clears existing cell styles in target range first (Excel behavior)
|
|
32
33
|
*/
|
|
33
34
|
private copyFormatting;
|
|
34
35
|
/**
|
|
@@ -51,6 +52,7 @@ export declare class CopyManager {
|
|
|
51
52
|
fillAreas(seedRange: RangeAddress, targetRanges: RangeAddress[], options: CopyCellsOptions): void;
|
|
52
53
|
/**
|
|
53
54
|
* Fill a target range with a seed range using column-first strategy
|
|
55
|
+
* Step 0: Clear existing cell styles in target (Excel behavior)
|
|
54
56
|
* Step 1: Fill down - extend seed pattern vertically to match target height
|
|
55
57
|
* Step 2: Replicate right - copy filled columns horizontally
|
|
56
58
|
*/
|
|
@@ -78,6 +80,7 @@ export declare class CopyManager {
|
|
|
78
80
|
private adjustFormulaWithOffset;
|
|
79
81
|
/**
|
|
80
82
|
* Copy formatting from one cell to another
|
|
83
|
+
* Clears existing cell styles at target (Excel behavior) before copying new ones
|
|
81
84
|
*/
|
|
82
85
|
private copyCellFormatting;
|
|
83
86
|
}
|
|
@@ -98,4 +98,14 @@ export declare class StyleManager {
|
|
|
98
98
|
* Adjusts existing style ranges rather than deleting them entirely
|
|
99
99
|
*/
|
|
100
100
|
clearCellStyles(range: RangeAddress): void;
|
|
101
|
+
/**
|
|
102
|
+
* Clear cell styles in a range using subtraction
|
|
103
|
+
* For each intersecting style, subtract the cleared range:
|
|
104
|
+
* - If style is completely contained: remove entire style
|
|
105
|
+
* - If style partially overlaps: split into remaining rectangles
|
|
106
|
+
* - If no intersection: keep unchanged
|
|
107
|
+
*
|
|
108
|
+
* This matches Excel's behavior where pasting replaces formatting
|
|
109
|
+
*/
|
|
110
|
+
clearCellStylesInRange(range: RangeAddress): void;
|
|
101
111
|
}
|
|
@@ -72,6 +72,7 @@ export declare class WorkbookManager {
|
|
|
72
72
|
newSheetName: string;
|
|
73
73
|
}): Sheet;
|
|
74
74
|
updateAllFormulas(updateCallback: (formula: string) => string): void;
|
|
75
|
+
updateFormulasForWorkbook(workbookName: string, updateCallback: (formula: string) => string): void;
|
|
75
76
|
getSheetSerialized({ workbookName, sheetName, }: {
|
|
76
77
|
workbookName: string;
|
|
77
78
|
sheetName: string;
|