@ricsam/formula-engine 0.2.12 → 0.2.14

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/README.md CHANGED
@@ -69,6 +69,10 @@ engine.setSheetContent(
69
69
  );
70
70
 
71
71
  const matches = engine.search("sum", { workbookName: "Workbook1" });
72
+ const firstTenMatches = engine.search("sum", {
73
+ workbookName: "Workbook1",
74
+ maxResults: 10,
75
+ });
72
76
  const oneChange = engine.replace("sum", "avg", {
73
77
  workbookName: "Workbook1",
74
78
  sheetName: "Sheet1",
@@ -80,6 +84,9 @@ const allChanges = engine.replaceAll("draft", "published", {
80
84
  });
81
85
 
82
86
  // Works on any stored string cell, including formulas and plain text
87
+ // search() returns at most 1,000 matches by default to keep large UI searches
88
+ // responsive. Pass maxResults to change the cap, or Number.POSITIVE_INFINITY
89
+ // when a batch workflow really needs an unbounded result set.
83
90
  // [
84
91
  // {
85
92
  // workbookName: "Workbook1",
@@ -164,6 +164,21 @@ class StyleManager {
164
164
  this.cellStyles = this.cellStyles.filter((style) => !style.areas.some((area) => area.workbookName === workbookName && area.sheetName === sheetName));
165
165
  }
166
166
  getCellStyle(cellAddress) {
167
+ let resolvedStyle;
168
+ for (const cellStyle of this.cellStyles) {
169
+ if (!cellStyle || !cellStyle.areas) {
170
+ continue;
171
+ }
172
+ for (const area of cellStyle.areas) {
173
+ if (area.workbookName === cellAddress.workbookName && area.sheetName === cellAddress.sheetName && import_utils.isCellInRange(cellAddress, area.range)) {
174
+ resolvedStyle = {
175
+ ...resolvedStyle,
176
+ ...cellStyle.style
177
+ };
178
+ break;
179
+ }
180
+ }
181
+ }
167
182
  for (const style of this.conditionalStyles) {
168
183
  if (!style || !style.areas) {
169
184
  continue;
@@ -178,25 +193,15 @@ class StyleManager {
178
193
  if (style.condition.type === "formula") {
179
194
  const result = this.evaluateFormulaCondition(cellAddress, style, area);
180
195
  if (result)
181
- return result;
196
+ return { ...resolvedStyle, ...result };
182
197
  } else {
183
198
  const result = this.evaluateGradientCondition(cellAddress, style, area);
184
199
  if (result)
185
- return result;
200
+ return { ...resolvedStyle, ...result };
186
201
  }
187
202
  }
188
203
  }
189
- for (const cellStyle of this.cellStyles) {
190
- if (!cellStyle || !cellStyle.areas) {
191
- continue;
192
- }
193
- for (const area of cellStyle.areas) {
194
- if (area.workbookName === cellAddress.workbookName && area.sheetName === cellAddress.sheetName && import_utils.isCellInRange(cellAddress, area.range)) {
195
- return cellStyle.style;
196
- }
197
- }
198
- }
199
- return;
204
+ return resolvedStyle;
200
205
  }
201
206
  evaluateFormulaCondition(cellAddress, style, area) {
202
207
  if (style.condition.type !== "formula") {
@@ -408,4 +413,4 @@ class StyleManager {
408
413
  }
409
414
  }
410
415
 
411
- //# debugId=753E2EDDA422407C64756E2164756E21
416
+ //# debugId=44B954F309835A6864756E2164756E21
@@ -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.cjs\";\nimport type { StyleManagerSnapshot } from \"../engine-snapshot.cjs\";\nimport type { WorkbookManager } from \"./workbook-manager.cjs\";\nimport type { EvaluationManager } from \"./evaluation-manager.cjs\";\nimport { isCellInRange } from \"../utils.cjs\";\nimport {\n calculateGradientFactor,\n interpolateLCH,\n lchToHex,\n} from \"../utils/color-utils.cjs\";\nimport {\n subtractRange,\n rangesIntersect,\n isRangeContained,\n} from \"../utils/range-utils.cjs\";\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.areas.some(area => 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.areas.some(area => 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.areas.some(area =>\n area.workbookName === range.workbookName &&\n area.sheetName === range.sheetName &&\n rangesIntersect(area.range, range.range)\n )\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.areas && style.areas.some(area => 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.areas && style.areas.some(area => 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.areas.some(area =>\n area.sheetName === range.sheetName &&\n area.workbookName === range.workbookName &&\n rangesIntersect(area.range, range.range)\n )\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 areas\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 any of the single style's areas\n const style = intersectingStyles[0]!;\n const isContained = style.areas.some(area =>\n area.workbookName === range.workbookName &&\n area.sheetName === range.sheetName &&\n isRangeContained(range.range, area.range)\n );\n \n if (isContained) {\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 toSnapshot(): StyleManagerSnapshot {\n return {\n conditionalStyles: this.getAllConditionalStyles(),\n cellStyles: this.getAllCellStyles(),\n };\n }\n\n restoreFromSnapshot(snapshot: StyleManagerSnapshot): void {\n this.resetStyles(snapshot.conditionalStyles, snapshot.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.areas.some(area => area.workbookName === workbookName)\n );\n this.cellStyles = this.cellStyles.filter(\n (style) => !style.areas.some(area => 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 ...style,\n areas: style.areas.map(area =>\n area.workbookName === oldName\n ? { ...area, workbookName: newName }\n : area\n )\n }));\n // Update cell styles\n this.cellStyles = this.cellStyles.map((style) => ({\n ...style,\n areas: style.areas.map(area =>\n area.workbookName === oldName\n ? { ...area, workbookName: newName }\n : area\n )\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 ...style,\n areas: style.areas.map(area =>\n area.workbookName === workbookName && area.sheetName === oldSheetName\n ? { ...area, sheetName: newSheetName }\n : area\n )\n }));\n // Update cell styles\n this.cellStyles = this.cellStyles.map((style) => ({\n ...style,\n areas: style.areas.map(area =>\n area.workbookName === workbookName && area.sheetName === oldSheetName\n ? { ...area, sheetName: newSheetName }\n : area\n )\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 !style.areas.some(area =>\n area.workbookName === workbookName &&\n area.sheetName === sheetName\n )\n );\n this.cellStyles = this.cellStyles.filter(\n (style) =>\n !style.areas.some(area =>\n area.workbookName === workbookName &&\n 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.areas) {\n continue;\n }\n \n // Check if cell is in any of the style's areas\n for (const area of style.areas) {\n if (\n area.sheetName !== cellAddress.sheetName ||\n area.workbookName !== cellAddress.workbookName\n ) {\n continue;\n }\n\n if (!isCellInRange(cellAddress, 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, area);\n if (result) return result;\n } else {\n const result = this.evaluateGradientCondition(cellAddress, style, area);\n if (result) return result;\n }\n }\n }\n\n // Then check direct cell styles\n for (const cellStyle of this.cellStyles) {\n if (!cellStyle || !cellStyle.areas) {\n continue;\n }\n \n for (const area of cellStyle.areas) {\n if (\n area.workbookName === cellAddress.workbookName &&\n area.sheetName === cellAddress.sheetName &&\n isCellInRange(cellAddress, area.range)\n ) {\n return cellStyle.style;\n }\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 area: RangeAddress\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 area: RangeAddress\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 area\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 area: RangeAddress\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: area.workbookName,\n sheetName: area.sheetName,\n colIndex: area.range.start.col,\n rowIndex: 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(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(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 - punch holes in areas\n this.cellStyles = this.cellStyles.map(cellStyle => {\n if (!cellStyle || !cellStyle.areas) {\n return cellStyle;\n }\n\n const newAreas: RangeAddress[] = [];\n \n for (const area of cellStyle.areas) {\n // Check if this area intersects with the clear range\n if (\n area.workbookName === range.workbookName &&\n area.sheetName === range.sheetName &&\n rangesIntersect(area.range, range.range)\n ) {\n // Subtract the clear range from this area\n const remainingRanges = subtractRange(area.range, range.range);\n\n // Add all remaining ranges as new areas\n for (const remainingRange of remainingRanges) {\n newAreas.push({\n workbookName: area.workbookName,\n sheetName: area.sheetName,\n range: remainingRange,\n });\n }\n } else {\n // No intersection, keep the area as-is\n newAreas.push(area);\n }\n }\n \n return { ...cellStyle, areas: newAreas };\n }).filter(style => style.areas.length > 0);\n\n // Process conditionalStyles - punch holes in areas\n this.conditionalStyles = this.conditionalStyles.map(conditionalStyle => {\n if (!conditionalStyle || !conditionalStyle.areas) {\n return conditionalStyle;\n }\n\n const newAreas: RangeAddress[] = [];\n \n for (const area of conditionalStyle.areas) {\n // Check if this area intersects with the clear range\n if (\n area.workbookName === range.workbookName &&\n area.sheetName === range.sheetName &&\n rangesIntersect(area.range, range.range)\n ) {\n // Subtract the clear range from this area\n const remainingRanges = subtractRange(area.range, range.range);\n\n // Add all remaining ranges as new areas\n for (const remainingRange of remainingRanges) {\n newAreas.push({\n workbookName: area.workbookName,\n sheetName: area.sheetName,\n range: remainingRange,\n });\n }\n } else {\n // No intersection, keep the area as-is\n newAreas.push(area);\n }\n }\n \n return { ...conditionalStyle, areas: newAreas };\n }).filter(style => style.areas.length > 0);\n }\n\n /**\n * Clear cell styles in a range using subtraction\n * For each intersecting style, subtract the cleared range from its areas:\n * - If an area is completely contained: remove that area\n * - If an area partially overlaps: split into remaining rectangles (hole punching)\n * - If no intersection: keep area unchanged\n * \n * This matches Excel's behavior where cutting/pasting creates multi-area styles\n */\n clearCellStylesInRange(range: RangeAddress): void {\n this.cellStyles = this.cellStyles.map(style => {\n const newAreas: RangeAddress[] = [];\n \n for (const area of style.areas) {\n // Skip areas from different sheets/workbooks\n if (\n area.workbookName !== range.workbookName ||\n area.sheetName !== range.sheetName\n ) {\n newAreas.push(area);\n continue;\n }\n\n // Check if this area intersects with the range to clear\n if (!rangesIntersect(area.range, range.range)) {\n // No intersection, keep the area unchanged\n newAreas.push(area);\n continue;\n }\n\n // Area intersects - subtract the cleared range (may produce multiple ranges)\n const remainingRanges = subtractRange(area.range, range.range);\n\n // Add all remaining ranges as new areas for this style\n for (const remainingRange of remainingRanges) {\n newAreas.push({\n workbookName: area.workbookName,\n sheetName: area.sheetName,\n range: remainingRange,\n });\n }\n }\n \n return { ...style, areas: newAreas };\n }).filter(style => style.areas.length > 0); // Remove styles with no areas left\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.cjs\";\nimport type { StyleManagerSnapshot } from \"../engine-snapshot.cjs\";\nimport type { WorkbookManager } from \"./workbook-manager.cjs\";\nimport type { EvaluationManager } from \"./evaluation-manager.cjs\";\nimport { isCellInRange } from \"../utils.cjs\";\nimport {\n calculateGradientFactor,\n interpolateLCH,\n lchToHex,\n} from \"../utils/color-utils.cjs\";\nimport {\n subtractRange,\n rangesIntersect,\n isRangeContained,\n} from \"../utils/range-utils.cjs\";\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.areas.some(area => 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.areas.some(area => 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.areas.some(area =>\n area.workbookName === range.workbookName &&\n area.sheetName === range.sheetName &&\n rangesIntersect(area.range, range.range)\n )\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.areas && style.areas.some(area => 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.areas && style.areas.some(area => 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.areas.some(area =>\n area.sheetName === range.sheetName &&\n area.workbookName === range.workbookName &&\n rangesIntersect(area.range, range.range)\n )\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 areas\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 any of the single style's areas\n const style = intersectingStyles[0]!;\n const isContained = style.areas.some(area =>\n area.workbookName === range.workbookName &&\n area.sheetName === range.sheetName &&\n isRangeContained(range.range, area.range)\n );\n \n if (isContained) {\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 toSnapshot(): StyleManagerSnapshot {\n return {\n conditionalStyles: this.getAllConditionalStyles(),\n cellStyles: this.getAllCellStyles(),\n };\n }\n\n restoreFromSnapshot(snapshot: StyleManagerSnapshot): void {\n this.resetStyles(snapshot.conditionalStyles, snapshot.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.areas.some(area => area.workbookName === workbookName)\n );\n this.cellStyles = this.cellStyles.filter(\n (style) => !style.areas.some(area => 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 ...style,\n areas: style.areas.map(area =>\n area.workbookName === oldName\n ? { ...area, workbookName: newName }\n : area\n )\n }));\n // Update cell styles\n this.cellStyles = this.cellStyles.map((style) => ({\n ...style,\n areas: style.areas.map(area =>\n area.workbookName === oldName\n ? { ...area, workbookName: newName }\n : area\n )\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 ...style,\n areas: style.areas.map(area =>\n area.workbookName === workbookName && area.sheetName === oldSheetName\n ? { ...area, sheetName: newSheetName }\n : area\n )\n }));\n // Update cell styles\n this.cellStyles = this.cellStyles.map((style) => ({\n ...style,\n areas: style.areas.map(area =>\n area.workbookName === workbookName && area.sheetName === oldSheetName\n ? { ...area, sheetName: newSheetName }\n : area\n )\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 !style.areas.some(area =>\n area.workbookName === workbookName &&\n area.sheetName === sheetName\n )\n );\n this.cellStyles = this.cellStyles.filter(\n (style) =>\n !style.areas.some(area =>\n area.workbookName === workbookName &&\n area.sheetName === sheetName\n )\n );\n }\n\n /**\n * Get the style for a specific cell.\n * Direct cell styles compose in insertion order, with later styles overriding\n * earlier styles for the same properties. Conditional styles then layer over\n * direct styles for the properties they define.\n */\n getCellStyle(cellAddress: CellAddress): CellStyle | undefined {\n let resolvedStyle: CellStyle | undefined;\n\n for (const cellStyle of this.cellStyles) {\n if (!cellStyle || !cellStyle.areas) {\n continue;\n }\n\n for (const area of cellStyle.areas) {\n if (\n area.workbookName === cellAddress.workbookName &&\n area.sheetName === cellAddress.sheetName &&\n isCellInRange(cellAddress, area.range)\n ) {\n resolvedStyle = {\n ...resolvedStyle,\n ...cellStyle.style,\n };\n break;\n }\n }\n }\n\n for (const style of this.conditionalStyles) {\n if (!style || !style.areas) {\n continue;\n }\n \n // Check if cell is in any of the style's areas\n for (const area of style.areas) {\n if (\n area.sheetName !== cellAddress.sheetName ||\n area.workbookName !== cellAddress.workbookName\n ) {\n continue;\n }\n\n if (!isCellInRange(cellAddress, 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, area);\n if (result) return { ...resolvedStyle, ...result };\n } else {\n const result = this.evaluateGradientCondition(cellAddress, style, area);\n if (result) return { ...resolvedStyle, ...result };\n }\n }\n }\n\n return resolvedStyle;\n }\n\n /**\n * Evaluate a formula-based style condition\n */\n private evaluateFormulaCondition(\n cellAddress: CellAddress,\n style: ConditionalStyle,\n area: RangeAddress\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 area: RangeAddress\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 area\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 area: RangeAddress\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: area.workbookName,\n sheetName: area.sheetName,\n colIndex: area.range.start.col,\n rowIndex: 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(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(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 - punch holes in areas\n this.cellStyles = this.cellStyles.map(cellStyle => {\n if (!cellStyle || !cellStyle.areas) {\n return cellStyle;\n }\n\n const newAreas: RangeAddress[] = [];\n \n for (const area of cellStyle.areas) {\n // Check if this area intersects with the clear range\n if (\n area.workbookName === range.workbookName &&\n area.sheetName === range.sheetName &&\n rangesIntersect(area.range, range.range)\n ) {\n // Subtract the clear range from this area\n const remainingRanges = subtractRange(area.range, range.range);\n\n // Add all remaining ranges as new areas\n for (const remainingRange of remainingRanges) {\n newAreas.push({\n workbookName: area.workbookName,\n sheetName: area.sheetName,\n range: remainingRange,\n });\n }\n } else {\n // No intersection, keep the area as-is\n newAreas.push(area);\n }\n }\n \n return { ...cellStyle, areas: newAreas };\n }).filter(style => style.areas.length > 0);\n\n // Process conditionalStyles - punch holes in areas\n this.conditionalStyles = this.conditionalStyles.map(conditionalStyle => {\n if (!conditionalStyle || !conditionalStyle.areas) {\n return conditionalStyle;\n }\n\n const newAreas: RangeAddress[] = [];\n \n for (const area of conditionalStyle.areas) {\n // Check if this area intersects with the clear range\n if (\n area.workbookName === range.workbookName &&\n area.sheetName === range.sheetName &&\n rangesIntersect(area.range, range.range)\n ) {\n // Subtract the clear range from this area\n const remainingRanges = subtractRange(area.range, range.range);\n\n // Add all remaining ranges as new areas\n for (const remainingRange of remainingRanges) {\n newAreas.push({\n workbookName: area.workbookName,\n sheetName: area.sheetName,\n range: remainingRange,\n });\n }\n } else {\n // No intersection, keep the area as-is\n newAreas.push(area);\n }\n }\n \n return { ...conditionalStyle, areas: newAreas };\n }).filter(style => style.areas.length > 0);\n }\n\n /**\n * Clear cell styles in a range using subtraction\n * For each intersecting style, subtract the cleared range from its areas:\n * - If an area is completely contained: remove that area\n * - If an area partially overlaps: split into remaining rectangles (hole punching)\n * - If no intersection: keep area unchanged\n * \n * This matches Excel's behavior where cutting/pasting creates multi-area styles\n */\n clearCellStylesInRange(range: RangeAddress): void {\n this.cellStyles = this.cellStyles.map(style => {\n const newAreas: RangeAddress[] = [];\n \n for (const area of style.areas) {\n // Skip areas from different sheets/workbooks\n if (\n area.workbookName !== range.workbookName ||\n area.sheetName !== range.sheetName\n ) {\n newAreas.push(area);\n continue;\n }\n\n // Check if this area intersects with the range to clear\n if (!rangesIntersect(area.range, range.range)) {\n // No intersection, keep the area unchanged\n newAreas.push(area);\n continue;\n }\n\n // Area intersects - subtract the cleared range (may produce multiple ranges)\n const remainingRanges = subtractRange(area.range, range.range);\n\n // Add all remaining ranges as new areas for this style\n for (const remainingRange of remainingRanges) {\n newAreas.push({\n workbookName: area.workbookName,\n sheetName: area.sheetName,\n range: remainingRange,\n });\n }\n }\n \n return { ...style, areas: newAreas };\n }).filter(style => style.areas.length > 0); // Remove styles with no areas left\n }\n}\n"
6
6
  ],
7
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAe8B,IAA9B;AAKO,IAJP;AASO,IAJP;AAAA;AAMO,MAA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AS;AAAA,MAC7C,MAAM,WAA2B,CAAC;AAAA,MAElC,WAAW,QAAQ,MAAM,OAAO;AAAA,QAE9B,IACE,KAAK,iBAAiB,MAAM,gBAC5B,KAAK,cAAc,MAAM,WACzB;AAAA,UACA,SAAS,KAAK,IAAI;AAAA,UAClB;AAAA,QACF;AAAA,QAGA,IAAI,CAAC,mCAAgB,KAAK,OAAO,MAAM,KAAK,GAAG;AAAA,UAE7C,SAAS,KAAK,IAAI;AAAA,UAClB;AAAA,QACF;AAAA,QAGA,MAAM,kBAAkB,iCAAc,KAAK,OAAO,MAAM,KAAK;AAAA,QAG7D,WAAW,kBAAkB,iBAAiB;AAAA,UAC5C,SAAS,KAAK;AAAA,YACZ,cAAc,KAAK;AAAA,YACnB,WAAW,KAAK;AAAA,YAChB,OAAO;AAAA,UACT,CAAC;AAAA,QACH;AAAA,MACF;AAAA,MAEA,OAAO,KAAK,OAAO,OAAO,SAAS;AAAA,KACpC,EAAE,OAAO,WAAS,MAAM,MAAM,SAAS,CAAC;AAAA;AAE7C;",
8
+ "debugId": "44B954F309835A6864756E2164756E21",
9
9
  "names": []
10
10
  }
@@ -43,6 +43,7 @@ __export(exports_workbook_manager, {
43
43
  IndexEntryBinarySearch: () => IndexEntryBinarySearch
44
44
  });
45
45
  module.exports = __toCommonJS(exports_workbook_manager);
46
+ var import_types = require("../types.cjs");
46
47
  var import_utils = require("../utils.cjs");
47
48
  var import_range_eval_order_builder = require("./range-eval-order-builder.cjs");
48
49
  var import_evaluation_error = require("../../evaluator/evaluation-error.cjs");
@@ -424,15 +425,15 @@ class WorkbookManager {
424
425
  getStringContentKind(cellContent) {
425
426
  return cellContent.startsWith("=") ? "formula" : "text";
426
427
  }
427
- findMatchesInString(cellContent, query, caseSensitive) {
428
- if (query.length === 0) {
428
+ findMatchesInString(cellContent, query, caseSensitive, maxMatches = Number.POSITIVE_INFINITY) {
429
+ if (query.length === 0 || maxMatches <= 0) {
429
430
  return [];
430
431
  }
431
432
  const normalizedContent = caseSensitive ? cellContent : cellContent.toLowerCase();
432
433
  const normalizedQuery = caseSensitive ? query : query.toLowerCase();
433
434
  const matches = [];
434
435
  let searchFromIndex = 0;
435
- while (searchFromIndex <= normalizedContent.length - normalizedQuery.length) {
436
+ while (matches.length < maxMatches && searchFromIndex <= normalizedContent.length - normalizedQuery.length) {
436
437
  const startIndex = normalizedContent.indexOf(normalizedQuery, searchFromIndex);
437
438
  if (startIndex === -1) {
438
439
  break;
@@ -448,45 +449,84 @@ class WorkbookManager {
448
449
  }
449
450
  return matches;
450
451
  }
451
- buildSearchMatchesInScope(query, scopedSheets, caseSensitive) {
452
- const results = [];
452
+ normalizeSearchMaxResults(maxResults) {
453
+ if (maxResults === undefined) {
454
+ return import_types.DEFAULT_SEARCH_MAX_RESULTS;
455
+ }
456
+ if (maxResults === Number.POSITIVE_INFINITY) {
457
+ return Number.POSITIVE_INFINITY;
458
+ }
459
+ if (!Number.isFinite(maxResults) || maxResults <= 0) {
460
+ return 0;
461
+ }
462
+ return Math.floor(maxResults);
463
+ }
464
+ *iterateStringCellsInSearchOrder(scopedSheets) {
453
465
  for (const { workbookName, sheet } of scopedSheets) {
454
- const sheetMatches = [];
455
- for (const [cellReference, value] of sheet.content.entries()) {
456
- if (typeof value !== "string") {
466
+ const indexes = this.getSheetIndexes({
467
+ workbookName,
468
+ sheetName: sheet.name
469
+ });
470
+ const rowIndexes = Array.from(indexes.rowGroups.keys()).sort((left, right) => left - right);
471
+ for (const rowIndex of rowIndexes) {
472
+ const rowGroup = indexes.rowGroups.get(rowIndex);
473
+ if (!rowGroup) {
457
474
  continue;
458
475
  }
459
- const matches = this.findMatchesInString(value, query, caseSensitive);
460
- if (matches.length === 0) {
461
- continue;
476
+ for (const { number: colIndex, key: cellReference } of rowGroup) {
477
+ const cellContent = sheet.content.get(cellReference);
478
+ if (typeof cellContent !== "string") {
479
+ continue;
480
+ }
481
+ yield {
482
+ workbookName,
483
+ sheetName: sheet.name,
484
+ cellReference,
485
+ cellContent,
486
+ rowIndex,
487
+ colIndex
488
+ };
462
489
  }
463
- const { rowIndex, colIndex } = import_utils.parseCellReference(cellReference);
464
- const contentKind = this.getStringContentKind(value);
465
- sheetMatches.push(...matches.map((match) => ({
466
- workbookName,
467
- sheetName: sheet.name,
468
- cellReference,
469
- cellContent: value,
490
+ }
491
+ }
492
+ }
493
+ buildSearchMatchesInScope(query, scopedSheets, caseSensitive, maxResults) {
494
+ const results = [];
495
+ if (maxResults <= 0) {
496
+ return results;
497
+ }
498
+ for (const cell of this.iterateStringCellsInSearchOrder(scopedSheets)) {
499
+ const matches = this.findMatchesInString(cell.cellContent, query, caseSensitive, maxResults - results.length);
500
+ if (matches.length === 0) {
501
+ continue;
502
+ }
503
+ const contentKind = this.getStringContentKind(cell.cellContent);
504
+ for (const match of matches) {
505
+ results.push({
506
+ workbookName: cell.workbookName,
507
+ sheetName: cell.sheetName,
508
+ cellReference: cell.cellReference,
509
+ cellContent: cell.cellContent,
470
510
  contentKind,
471
511
  occurrenceIndex: match.occurrenceIndex,
472
512
  startIndex: match.startIndex,
473
513
  endIndexExclusive: match.endIndexExclusive,
474
- matchedText: match.matchedText,
475
- rowIndex,
476
- colIndex
477
- })));
514
+ matchedText: match.matchedText
515
+ });
516
+ }
517
+ if (results.length >= maxResults) {
518
+ return results;
478
519
  }
479
- sheetMatches.sort((left, right) => left.rowIndex - right.rowIndex || left.colIndex - right.colIndex || left.occurrenceIndex - right.occurrenceIndex);
480
- results.push(...sheetMatches.map(({ rowIndex: _rowIndex, colIndex: _colIndex, ...match }) => match));
481
520
  }
482
521
  return results;
483
522
  }
484
523
  search(query, options) {
485
524
  const scopedSheets = this.resolveSearchScope(options);
525
+ const maxResults = this.normalizeSearchMaxResults(options?.maxResults);
486
526
  if (query.length === 0) {
487
527
  return [];
488
528
  }
489
- return this.buildSearchMatchesInScope(query, scopedSheets, options?.caseSensitive === true);
529
+ return this.buildSearchMatchesInScope(query, scopedSheets, options?.caseSensitive === true, maxResults);
490
530
  }
491
531
  buildReplacedContent(beforeContent, matches, replacement) {
492
532
  let cursor = 0;
@@ -543,47 +583,41 @@ class WorkbookManager {
543
583
  if (query.length === 0) {
544
584
  throw new Error("replaceAll requires a non-empty query");
545
585
  }
546
- const matches = this.buildSearchMatchesInScope(query, scopedSheets, options?.caseSensitive === true);
547
- const matchesByCell = new Map;
548
- for (const match of matches) {
549
- const cellKey = `${match.workbookName}:${match.sheetName}:${match.cellReference}`;
550
- const existing = matchesByCell.get(cellKey);
551
- if (existing) {
552
- existing.push(match);
553
- } else {
554
- matchesByCell.set(cellKey, [match]);
555
- }
556
- }
557
- return Array.from(matchesByCell.values()).map((cellMatches) => {
558
- const [firstMatch] = cellMatches;
559
- if (!firstMatch) {
560
- throw new Error("Expected at least one match per cell");
586
+ const replacements = [];
587
+ const caseSensitive = options?.caseSensitive === true;
588
+ for (const cell of this.iterateStringCellsInSearchOrder(scopedSheets)) {
589
+ const matches = this.findMatchesInString(cell.cellContent, query, caseSensitive);
590
+ if (matches.length === 0) {
591
+ continue;
561
592
  }
562
593
  const address = {
563
- workbookName: firstMatch.workbookName,
564
- sheetName: firstMatch.sheetName,
565
- ...import_utils.parseCellReference(firstMatch.cellReference)
594
+ workbookName: cell.workbookName,
595
+ sheetName: cell.sheetName,
596
+ rowIndex: cell.rowIndex,
597
+ colIndex: cell.colIndex
566
598
  };
567
- const afterContent = this.buildReplacedContent(firstMatch.cellContent, cellMatches, replacement);
568
- return {
599
+ const afterContent = this.buildReplacedContent(cell.cellContent, matches, replacement);
600
+ const contentKind = this.getStringContentKind(cell.cellContent);
601
+ replacements.push({
569
602
  address,
570
- beforeContent: firstMatch.cellContent,
603
+ beforeContent: cell.cellContent,
571
604
  afterContent,
572
- changes: cellMatches.map((match) => ({
573
- workbookName: match.workbookName,
574
- sheetName: match.sheetName,
575
- cellReference: match.cellReference,
576
- contentKind: match.contentKind,
605
+ changes: matches.map((match) => ({
606
+ workbookName: cell.workbookName,
607
+ sheetName: cell.sheetName,
608
+ cellReference: cell.cellReference,
609
+ contentKind,
577
610
  occurrenceIndex: match.occurrenceIndex,
578
611
  startIndex: match.startIndex,
579
612
  endIndexExclusive: match.endIndexExclusive,
580
613
  matchedText: match.matchedText,
581
614
  replacementText: replacement,
582
- beforeContent: firstMatch.cellContent,
615
+ beforeContent: cell.cellContent,
583
616
  afterContent
584
617
  }))
585
- };
586
- });
618
+ });
619
+ }
620
+ return replacements;
587
621
  }
588
622
  addCellToGroups(indexes, rowIndex, colIndex, key) {
589
623
  let rowGroup = indexes.rowGroups.get(rowIndex);
@@ -837,4 +871,4 @@ class WorkbookManager {
837
871
  }
838
872
  }
839
873
 
840
- //# debugId=483CA8B52CB4833564756E2164756E21
874
+ //# debugId=1447E59A152D66CB64756E2164756E21