/** * DOM Caching System * * A reference-counted cache system for expensive DOM operations like getComputedStyle(). * Based on Playwright's caching pattern from packages/injected/src/domUtils.ts. * * Usage: * ```ts * beginDOMCaches(); * try { * // Multiple calls to getCachedStyle with same element * // will only call getComputedStyle once * const style1 = getCachedStyle(element); * const style2 = getCachedStyle(element); * } finally { * endDOMCaches(); * } * * // Or use the helper: * withCache(() => { * const style = getCachedStyle(element); * }); * ``` */ /** * Begin a caching session. Calls can be nested (reference counted). * Use this before batch DOM operations to improve performance. */ export declare function beginDOMCaches(): void; /** * End a caching session. When counter reaches 0, caches are cleared. */ export declare function endDOMCaches(): void; /** * Get cached computed style for an element. * Returns cached value if in a cache session, otherwise calls getComputedStyle. * * @param element - The element to get computed style for * @param pseudo - Optional pseudo element selector (e.g., '::before', '::after') * @returns The computed style declaration */ export declare function getCachedStyle(element: Element, pseudo?: string | null): CSSStyleDeclaration; /** * Get cached pseudo-element content (::before, ::after). * Returns the 'content' property value. * * @param element - The element to get pseudo content for * @param pseudo - The pseudo element ('::before' or '::after') * @returns The content property value (e.g., '"text"', 'none', 'attr(data-label)') */ export declare function getCachedPseudoContent(element: Element, pseudo: '::before' | '::after'): string; /** * Check if caching is currently active. * * @returns true if we're inside a beginDOMCaches/endDOMCaches block */ export declare function isCachingActive(): boolean; /** * Get cache statistics (for debugging/testing). * * @returns Object with cache state information */ export declare function getCacheStats(): { active: boolean; depth: number; styleEntries: number; pseudoEntries: number; }; /** * Execute a function within a cache session. * Automatically calls beginDOMCaches/endDOMCaches. * * @param fn - The function to execute within the cache session * @returns The return value of the function * @throws Re-throws any error from the function after clearing cache * * @example * ```ts * const result = withCache(() => { * const style1 = getCachedStyle(element1); * const style2 = getCachedStyle(element2); * return style1.display === style2.display; * }); * ``` */ export declare function withCache(fn: () => T): T; /** * Async version of withCache. * Execute an async function within a cache session. * * Note: Be careful with long-running async operations as the cache * will persist until the promise resolves/rejects. This is typically * fine for batch DOM operations but may cause stale data if the DOM * changes during the async operation. * * @param fn - The async function to execute within the cache session * @returns A promise that resolves to the return value of the function * @throws Re-throws any error from the function after clearing cache * * @example * ```ts * const result = await withCacheAsync(async () => { * const elements = document.querySelectorAll('.item'); * const results = []; * for (const el of elements) { * const style = getCachedStyle(el); * results.push(await processStyle(style)); * } * return results; * }); * ``` */ export declare function withCacheAsync(fn: () => Promise): Promise; /** * Clear all caches immediately, regardless of reference count. * Use this for cleanup in error scenarios or tests. * This resets the counter to 0. */ export declare function clearAllCaches(): void; //# sourceMappingURL=cache.d.ts.map