import { CLSGuardConfig, CLSGuardInterface, CLSMeasurement, Dimensions, LayoutReservation, ReservationStrategy } from './types'; /** * CLS Guard implementation that prevents layout shifts through * reservations and monitors actual CLS scores. * * @example * ```typescript * const guard = createCLSGuard({ maxCLS: 0.05 }); * * // Reserve space for an image * const reservation = guard.createReservation('hero-image', { * width: 1200, * height: 600 * }, 'skeleton'); * * // Monitor CLS * const unsubscribe = guard.observeCLS((measurement) => { * if (measurement.thresholdExceeded) { * console.warn('CLS threshold exceeded:', measurement.score); * } * }); * ``` */ export declare class CLSGuard implements CLSGuardInterface { private readonly _reservations; private readonly _reservationElements; private readonly _measurements; private readonly _callbacks; private _observer; private _sessionEntries; private _sessionStart; private _destroyed; constructor(config?: Partial); private _config; /** * Current configuration. */ get config(): CLSGuardConfig; private _currentScore; /** * Current CLS score. */ get currentScore(): number; /** * Updates the guard configuration. */ configure(config: Partial): void; /** * Creates a layout reservation to prevent CLS. * * @param id - Unique identifier for the reservation * @param dimensions - Dimensions to reserve * @param strategy - Reservation strategy (defaults to config) * @returns The created reservation */ createReservation(id: string, dimensions: Dimensions, strategy?: ReservationStrategy): LayoutReservation; /** * Releases a layout reservation. * * @param id - The reservation ID to release */ releaseReservation(id: string): void; /** * Measures the current CLS score. * * @returns CLS measurement result */ measureCLS(): CLSMeasurement; /** * Subscribes to CLS updates. * * @param callback - Callback for CLS measurements * @returns Unsubscribe function */ observeCLS(callback: (measurement: CLSMeasurement) => void): () => void; /** * Cleans up all resources. */ destroy(): void; /** * Gets the reservation element for a given ID. * * @param id - Reservation ID * @returns The reservation element or undefined */ getReservationElement(id: string): HTMLElement | undefined; /** * Inserts a reservation element at a specific location. * * @param id - Reservation ID * @param container - Container element to insert into * @param position - Insert position */ insertReservationElement(id: string, container: HTMLElement, position?: 'prepend' | 'append' | 'before' | 'after'): void; /** * Initializes the Performance Observer for CLS tracking. */ private _initializeObserver; /** * Processes a layout shift entry. */ private _processLayoutShift; /** * Extracts element ID from layout shift sources. */ private _extractElementId; /** * Creates a reservation element in the DOM. */ private _createReservationElement; /** * Asserts that the guard has not been destroyed. */ private _assertNotDestroyed; } /** * Creates a new CLSGuard instance. * * @param config - Optional configuration overrides * @returns A new CLSGuard instance */ export declare function createCLSGuard(config?: Partial): CLSGuardInterface; /** * Calculates the predicted CLS impact of a layout change. * * @param beforeRects - Element positions before change * @param afterRects - Element positions after change * @param viewportDimensions - Viewport dimensions * @returns Predicted CLS score */ export declare function predictCLSImpact(beforeRects: ReadonlyMap, afterRects: ReadonlyMap, viewportDimensions: Dimensions): number; /** * Creates optimized dimension reservations based on content hints. * * @param contentHints - Array of content hints with expected dimensions * @returns Array of optimized reservations */ export declare function createOptimizedReservations(contentHints: Array<{ id: string; type: 'image' | 'video' | 'text' | 'custom'; expectedDimensions?: Dimensions; aspectRatio?: number; }>): Array<{ id: string; dimensions: Dimensions; strategy: ReservationStrategy; }>;