import type { FormulaAstNode, FormulaCellRefNode, FormulaRangeRefNode } from "./formulaAst.mjs"; import type { FormulaCellKey, FormulaCellRef, FormulaPositionContext } from "./formulaTypes.mjs"; import type { FormulaErrorValue } from "./formulaErrors.mjs"; /** * Context-free dependency description, extracted with a pure AST walk. * Positional selectors are reported structurally — they cannot become * concrete cell keys until bound against a position context. */ export interface FormulaStaticDependencies { /** * Same-row field references; they bind to `(ownerRow, field)`. */ fieldRefs: Set; /** * Explicit `REF(...)` nodes, any selector mix. */ cellRefs: FormulaCellRefNode[]; ranges: FormulaRangeRefNode[]; columnValues: Set; /** * `true` when any positional selector, `RANGE_REF` or `COLUMN_VALUES` is * present — the formula must rebind when the position context changes. */ usesPositionContext: boolean; /** * Uppercase function names — used for `#NAME?` analysis and * registry-change invalidation. */ calls: Set; } export declare function extractFormulaDependencies(ast: FormulaAstNode): FormulaStaticDependencies; /** * A bounded single-column slice of a range: rows `fromIndex..toIndex` * (1-based, inclusive) of `field` in the position context's row order. */ export interface FormulaColumnIntervalDependency { field: string; fromIndex: number; toIndex: number; } /** * A `COLUMN_VALUES` dependency on every row of `field` in the position * context. The `whole: true` literal is a discriminant: it keeps interval * records (otherwise structurally assignable to `{ field }`) out of * `wholeColumns`, and lets interval and whole-column records be told apart * when mixed in a single per-field list (the adapter's reverse range map). */ export interface FormulaWholeColumnDependency { field: string; whole: true; } /** * Dependencies resolved against a position-context snapshot. * Ranges bind to interval records, never to exploded per-cell edges. */ export interface FormulaBoundDependencies { cells: Set; columnIntervals: FormulaColumnIntervalDependency[]; wholeColumns: FormulaWholeColumnDependency[]; /** * Unresolvable references found during binding. Binding never throws; * evaluation short-circuits to the first of these errors. */ errors: FormulaErrorValue[]; } /** * The normalized rectangle a `RANGE_REF(...)` node spans in a position context. * All indexes are 1-based and inclusive. An empty window is expressed as * `fromColumn > toColumn` or `fromIndex > toIndex` — never as an error. */ export interface FormulaRangeRectangle { fromColumn: number; toColumn: number; fromIndex: number; toIndex: number; } /** * The owner cell's current view positions — the reference point `anchor` range * axes resolve against. Either index is `undefined` when the owner has no * position on that axis (its row is filtered out, or its column is hidden). */ export interface FormulaRangeAnchor { rowIndex: number | undefined; columnIndex: number | undefined; } /** * Looks up the owner cell's view positions once, for the axis resolution of * every range in the formula. */ export declare function getFormulaRangeAnchor(ownerCell: FormulaCellRef, context: FormulaPositionContext): FormulaRangeAnchor; /** * Resolves a `RANGE_REF` window against a position context and the owner cell's * anchor: `anchor` axes resolve to `ownerPosition + delta` (strict — see * `resolveRangeAxisIndex`), then the endpoints are normalized * (`RANGE_REF(B5..A1)` spans the same rectangle as `A1..B5`) and `position` * endpoints auto-clip to the current view — a window larger than the view * covers whatever is available instead of erroring. Shared by dependency * binding, range materialization, reference highlighting and the Excel export * so the four can never disagree about the rectangle a range covers. */ export declare function resolveFormulaRangeRectangle(range: FormulaRangeRefNode, context: FormulaPositionContext, anchor: FormulaRangeAnchor): FormulaRangeRectangle | FormulaErrorValue; /** * Resolves static dependencies into concrete cell keys and column records * against a position-context snapshot. Stable cell refs (`ROW(id)` + * `COLUMN(field)`) bind without consulting positions — a stable ref to a row * that is currently filtered out still binds (its existence is checked at * evaluation time). Only positional selectors and range windows need the * context. */ export declare function bindFormulaDependencies(ownerCell: FormulaCellRef, dependencies: FormulaStaticDependencies, context: FormulaPositionContext): FormulaBoundDependencies;