/** * VARIABLE RESOLUTION SYSTEM * TASKSET 8.4: Shared variable resolution utility for unified documents * * Provides: * - Variable interpolation in text ({{variableName}}) * - Variable resolution for formulas (=VAR("name")) * - Type coercion and formatting * - Cross-view variable access */ /** Variable types supported in unified documents */ export type VariableType = 'string' | 'number' | 'boolean' | 'date' | 'cellref' | 'formula'; /** Source view for a variable */ export type ViewType = 'editor' | 'calc' | 'slides'; /** Variable source location */ export interface VariableSource { view: ViewType; location?: Record; } /** Shared variable definition */ export interface SharedVariable { name: string; type: VariableType; value: unknown; source?: VariableSource; } /** Variable resolver function type */ export type VariableResolver = (name: string) => SharedVariable | undefined; /** Variable setter function type (for SETVAR in calc) */ export type VariableSetter = (name: string, value: unknown, type?: VariableType) => void; /** Interpolation options */ export interface InterpolationOptions { /** Whether to return placeholder for missing variables */ keepMissingPlaceholders?: boolean; /** Custom placeholder for missing variables */ missingPlaceholder?: string; /** Format functions for different types */ formatters?: Partial string>>; } /** Pattern to match variable references: {{variableName}} */ export declare const VARIABLE_PATTERN: RegExp; /** Pattern to match variable names (validation) */ export declare const VARIABLE_NAME_PATTERN: RegExp; /** * Validate a variable name */ export declare function isValidVariableName(name: string): boolean; /** * Format a variable value as string based on its type */ export declare function formatVariableValue(variable: SharedVariable, customFormatters?: Partial string>>): string; /** * Coerce a value to match the expected variable type */ export declare function coerceVariableValue(value: unknown, type: VariableType): unknown; /** * Extract all variable names from text containing {{variable}} placeholders */ export declare function extractVariableNames(text: string): string[]; /** * Interpolate variables in text, replacing {{variableName}} with values */ export declare function interpolateVariables(text: string, resolver: VariableResolver, options?: InterpolationOptions): string; /** * Resolve a single variable by name */ export declare function resolveVariable(name: string, resolver: VariableResolver): unknown; /** * Check if text contains any variable references */ export declare function containsVariables(text: string): boolean; /** * Configuration for rich text variable rendering */ export interface VariableRenderConfig { /** CSS class for variable spans */ className?: string; /** Whether to show variable name on hover */ showTooltip?: boolean; /** Style for unresolved variables */ unresolvedStyle?: 'highlight' | 'strikethrough' | 'dimmed'; } /** * Render text with variables as HTML with styling */ export declare function renderVariablesAsHTML(text: string, resolver: VariableResolver, config?: VariableRenderConfig): string; /** * Result of a VAR() function call */ export interface VarFunctionResult { value: unknown; type: VariableType; found: boolean; } /** * Evaluate VAR("variableName") function for spreadsheets * Returns the value of a shared variable */ export declare function evaluateVarFunction(variableName: string, resolver: VariableResolver): VarFunctionResult; /** * Result of a SETVAR() function call */ export interface SetVarFunctionResult { success: boolean; variableName: string; value: unknown; type: VariableType; error?: string; } /** * Evaluate SETVAR("variableName", value) function for spreadsheets * Sets a shared variable and returns the value (for display in cell) * * Usage in spreadsheet: * =SETVAR("revenue", A1) - Creates/updates 'revenue' variable with value from A1 * =SETVAR("total", SUM(A1:A10)) - Creates/updates 'total' with sum result */ export declare function evaluateSetVarFunction(variableName: string, value: unknown, setter: VariableSetter, existingResolver?: VariableResolver): SetVarFunctionResult; /** * Parse VAR function from formula string * Returns variable name if this is a VAR() call, null otherwise */ export declare function parseVarFunction(formula: string): string | null; /** * Parse SETVAR function from formula string * Returns {name, expression} if this is a SETVAR() call, null otherwise */ export declare function parseSetVarFunction(formula: string): { name: string; expression: string; } | null; /** * Detect which variables in text have changed values */ export declare function detectChangedVariables(text: string, oldResolver: VariableResolver, newResolver: VariableResolver): string[]; /** * Create a variable map from an array of variables */ export declare function createVariableMap(variables: SharedVariable[]): Map; /** * Create a resolver function from a variable map */ export declare function createResolver(variableMap: Map): VariableResolver; declare const _default: { isValidVariableName: typeof isValidVariableName; VARIABLE_PATTERN: RegExp; VARIABLE_NAME_PATTERN: RegExp; formatVariableValue: typeof formatVariableValue; coerceVariableValue: typeof coerceVariableValue; extractVariableNames: typeof extractVariableNames; interpolateVariables: typeof interpolateVariables; resolveVariable: typeof resolveVariable; containsVariables: typeof containsVariables; renderVariablesAsHTML: typeof renderVariablesAsHTML; evaluateVarFunction: typeof evaluateVarFunction; evaluateSetVarFunction: typeof evaluateSetVarFunction; parseVarFunction: typeof parseVarFunction; parseSetVarFunction: typeof parseSetVarFunction; detectChangedVariables: typeof detectChangedVariables; createVariableMap: typeof createVariableMap; createResolver: typeof createResolver; }; export default _default; //# sourceMappingURL=index.d.ts.map