import type { InterpreterContext } from "@hylimo/core"; import { FullObject, type LabeledValue } from "@hylimo/core"; import type { LayoutElement } from "../layoutElement.js"; /** * Different types of selectors */ declare enum SelectorType { /** * Class selector, matches class */ CLASS = "class", /** * Type selector, matches type */ TYPE = "type", /** * Any selector, maches any element */ ANY = "any" } /** * A selector which is part of the selector chain */ interface Selector { /** * The type of the selector */ type: SelectorType; /** * The value of the selector */ value: string; } /** * Represents a single style context with its selector, variables, and child contexts. * Each StyleContext can match against layout elements based on its selector and provides * style values and variables when matched. */ export declare class StyleContext { private readonly styleObject; /** * Flag indicating whether this context has been initialized */ private isInitialized; /** * Flag indicating whether this context is currently active (matched) */ isActive: boolean; /** * Child style contexts that are nested within this context */ children: StyleContext[]; /** * Cache for variable lookups to avoid repeated property access */ variablesLookup: Map; /** * Cache for value lookups to avoid repeated property access */ valuesLookup: Map; /** * Variables object containing all variables defined in this context */ variables?: FullObject; /** * The selector used to match elements against this style context */ selector: Selector; /** * Creates a new StyleContext from a style object. * Extracts the selector type and value from the style object. * * @param styleObject The full object containing style definition with selector information */ constructor(styleObject: FullObject); /** * Initializes the style context by loading child styles and variables. * This is called lazily when the context becomes active for the first time. * Sets up child StyleContext instances and extracts variables object. */ initialize(): void; /** * Gets the value of a variable defined in this style context. * Uses caching to avoid repeated lookups of the same variable. * * @param name The name of the variable to retrieve * @returns The labeled value of the variable, or null if not found */ getVariable(name: string): LabeledValue | null; /** * Gets a style property value from this style context. * Uses caching to avoid repeated lookups of the same property. * * @param name The name of the style property to retrieve * @returns The labeled value of the property, or null if not found */ getValue(name: string): LabeledValue | null; /** * Checks if a layout element matches this style context's selector. * Supports class selectors (matching element classes), type selectors * (matching element types), and the universal selector (matching any element). * * @param element The layout element to check against the selector * @returns true if the element matches the selector, otherwise false */ matchesSelector(element: LayoutElement): boolean; } /** * Evaluates and manages style contexts for layout elements. * Handles matching elements against style selectors and maintains * an active style stack for nested style application. */ export declare class StyleEvaluator { /** * All available style contexts */ contexts: StyleContext[]; /** * Stack of currently active style contexts */ activeStyleStack: StyleContext[]; /** * Stack tracking the number of active styles at each nesting level */ activeStyleCountStack: number[]; /** * Creates a new StyleEvaluator with the given styles object. * Extracts all top-level style contexts from the styles object. * * @param styles The full object containing all style definitions */ constructor(styles: FullObject); /** * Begins style matching for a layout element. * Finds all style contexts that match the element and updates the active style stack. * The returned contexts are in reverse order (most specific first). * * @param layoutElement The layout element to match styles against * @returns Array of matching style contexts in reverse order (most specific first) */ beginMatchStyles(layoutElement: LayoutElement): StyleContext[]; /** * Ends style matching for the current element. * Removes the styles that were added during the last beginMatchStyles call * from the active style stack. */ endMatchStyles(): void; /** * Recursively matches a layout element against a style context and its children. * If the context matches, it's added to the matched contexts and activated. * Child contexts are only processed if the parent context was already active. * * @param layoutElement The layout element to match against * @param context The style context to check for matching * @param matchedContexts Array to collect all matching contexts */ private matchStylesRecursive; } /** * Helper class to get style values from a set of matching style objects */ export declare class StyleValueParser { readonly matchingStyles: StyleContext[]; readonly context: InterpreterContext; /** * Cached variable values * During computation, a variable value is set to null to detect circular dependencies */ private readonly variableValues; /** * Creates a new style value parser * * @param matchingStyles all matching styles * @param context the context to use for variable resolution */ constructor(matchingStyles: StyleContext[], context: InterpreterContext); /** * Gets the value of a style attribute * * @param name the name of the attribute * @returns the value of the attribute, undefined if none of the matching styles provides the attribute */ getValue(name: string): LabeledValue | undefined; /** * Parses a labeled value, resolving calc, var and unset special values * * @param labeledValue the labeled value to parse * @returns the parsed labeled value */ private parse; /** * Gets the value of a variable * * @param name the name of the variable * @returns the value of the variable */ private getVariableValue; } export {}; //# sourceMappingURL=styles.d.ts.map