import { ComputedBounds, ContextTrackingConfig, LayoutAncestor, LayoutConstraints, LayoutType, PositionType } from './types'; /** * Tracks DOM context for elements including layout ancestry, * constraints, and computed dimensions. * * @remarks * Uses WeakMap for caching to prevent memory leaks when elements * are removed from the DOM. All DOM reads are batched for performance. * * @example * ```typescript * const tracker = DOMContextTracker.getInstance(); * const ancestry = tracker.getAncestry(element); * const constraints = tracker.getConstraints(element); * ``` */ export declare class DOMContextTracker { private static instance; /** WeakMap cache for element IDs */ private readonly elementIds; /** WeakMap cache for computed ancestors */ private readonly ancestorCache; /** WeakMap cache for computed constraints */ private readonly constraintCache; /** WeakMap cache for computed bounds */ private readonly boundsCache; /** Set of elements pending updates */ private readonly pendingUpdates; /** Configuration for tracking behavior */ private readonly config; /** RAF handle for batched updates */ private rafHandle; /** Callbacks to invoke after batch update */ private updateCallbacks; /** Whether we're in SSR mode */ private readonly isSSR; /** * Creates a new DOMContextTracker instance. * * @param config - Optional configuration override */ private constructor(); /** * Gets the singleton instance of DOMContextTracker. * * @param config - Optional configuration override * @returns The singleton instance */ static getInstance(config?: Partial): DOMContextTracker; /** * Resets the singleton instance (useful for testing). */ static resetInstance(): void; /** * Gets or generates a unique ID for an element. * * @param element - The DOM element * @returns Unique identifier string */ getElementId(element: Element): string; /** * Gets the layout ancestry chain for an element. * * @param element - The DOM element to get ancestry for * @param forceRefresh - Whether to bypass cache * @returns Array of LayoutAncestor from closest to farthest */ getAncestry(element: Element, forceRefresh?: boolean): LayoutAncestor[]; /** * Gets the layout constraints for an element based on its ancestry. * * @param element - The DOM element * @param forceRefresh - Whether to bypass cache * @returns Computed layout constraints */ getConstraints(element: Element, forceRefresh?: boolean): LayoutConstraints; /** * Gets the computed bounds for an element. * * @param element - The DOM element * @param forceRefresh - Whether to bypass cache * @returns Computed bounds including content/padding/border boxes */ getBounds(element: Element, forceRefresh?: boolean): ComputedBounds; /** * Detects the layout type of an element. * * @param element - The DOM element * @returns The detected LayoutType */ getLayoutType(element: Element): LayoutType; /** * Detects the position type of an element. * * @param element - The DOM element * @returns The detected PositionType */ getPositionType(element: Element): PositionType; /** * Schedules a cache invalidation for an element. * * @param element - The DOM element to invalidate * @param callback - Optional callback after invalidation */ invalidate(element: Element, callback?: () => void): void; /** * Invalidates cache for an element and all its descendants. * * @param element - The root element to invalidate */ invalidateTree(element: Element): void; /** * Clears all caches. Use sparingly. */ clearAllCaches(): void; /** * Destroys the tracker and cleans up resources. */ destroy(): void; /** * Builds the complete ancestry chain for an element. * * @param element - Starting element * @returns Array of LayoutAncestor objects */ private buildAncestry; /** * Creates a LayoutAncestor object for an element. * * @param element - The DOM element * @param depth - Depth in ancestry chain * @returns LayoutAncestor object */ private createLayoutAncestor; /** * Parses CSS display value to LayoutType. * * @param display - CSS display value * @returns Corresponding LayoutType */ private parseLayoutType; /** * Extracts flex container properties from computed style. * * @param style - Computed style object * @returns FlexContainerProperties */ private extractFlexProperties; /** * Extracts grid container properties from computed style. * * @param style - Computed style object * @returns GridContainerProperties */ private extractGridProperties; /** * Determines if an element creates a containing block. * * @param style - Computed style * @param position - Position type * @returns Whether element is a containing block */ private isContainingBlock; /** * Computes layout constraints for an element. * * @param element - The DOM element * @returns Computed LayoutConstraints */ private computeConstraints; /** * Parses dimension constraint values. * * @param min - CSS min value * @param max - CSS max value * @param current - Current dimension * @returns DimensionBounds object */ private parseDimensionBounds; /** * Determines if an element creates a stacking context. * * @param style - Computed style * @param position - Position type * @returns Whether element creates stacking context */ private createsStackingContext; /** * Computes comprehensive bounds for an element. * * @param element - The DOM element * @returns ComputedBounds object */ private computeBounds; /** * Creates default constraints for SSR. */ private createDefaultConstraints; /** * Creates default bounds for SSR. */ private createDefaultBounds; /** * Schedules a batched update for pending elements. */ private scheduleUpdate; /** * Processes all pending element updates. */ private processPendingUpdates; } /** * Gets the singleton DOMContextTracker instance. * * @param config - Optional configuration * @returns DOMContextTracker instance */ export declare function getDOMContextTracker(config?: Partial): DOMContextTracker; /** * Finds the nearest ancestor of a specific layout type. * * @param ancestry - Array of layout ancestors * @param type - Layout type to find * @returns Matching ancestor or undefined */ export declare function findAncestorByType(ancestry: LayoutAncestor[], type: LayoutType): LayoutAncestor | undefined; /** * Finds the nearest scroll container in ancestry. * * @param ancestry - Array of layout ancestors * @returns Scroll container ancestor or undefined */ export declare function findScrollContainerAncestor(ancestry: LayoutAncestor[]): LayoutAncestor | undefined; /** * Finds the nearest containing block in ancestry. * * @param ancestry - Array of layout ancestors * @returns Containing block ancestor or undefined */ export declare function findContainingBlockAncestor(ancestry: LayoutAncestor[]): LayoutAncestor | undefined; /** * Computes inherited constraints from ancestry chain. * * @param ancestry - Array of layout ancestors * @returns Merged constraints or null */ export declare function computeInheritedConstraints(ancestry: LayoutAncestor[]): LayoutConstraints | null; /** * Checks if an element is within a specific layout type. * * @param ancestry - Array of layout ancestors * @param type - Layout type to check for * @returns Whether element is within the layout type */ export declare function isWithinLayoutType(ancestry: LayoutAncestor[], type: LayoutType): boolean; /** * Gets the layout depth (number of layout-significant ancestors). * * @param ancestry - Array of layout ancestors * @returns Layout depth */ export declare function getLayoutDepth(ancestry: LayoutAncestor[]): number;