import { PriorityQueueStats } from './priority-queue'; import { HydrationBoundaryId, HydrationEventListener, HydrationEventType, HydrationMetricsSnapshot, HydrationPriority, HydrationSchedulerConfig, HydrationStatus, HydrationTask } from './types'; /** * Scheduler state for external observation. */ export interface SchedulerState { readonly isRunning: boolean; readonly isPaused: boolean; readonly isProcessing: boolean; readonly queueSize: number; readonly hydratedCount: number; readonly pendingCount: number; readonly failedCount: number; } /** * Core scheduler for auto-prioritized hydration. * * @example * ```typescript * const scheduler = new HydrationScheduler({ debug: true }); * * scheduler.register({ * id: 'hero-section', * priority: 'critical', * trigger: 'immediate', * hydrate: async () => { ... }, * }); * * scheduler.start(); * ``` */ export declare class HydrationScheduler { /** Configuration */ private readonly config; /** Priority queue for pending tasks */ private readonly queue; /** Registered boundaries */ private readonly boundaries; /** Visibility observer */ private visibilityObserver; /** Media query listeners */ private readonly mediaListeners; /** Interaction replay manager */ private readonly replayManager; /** Event listeners */ private readonly eventListeners; /** Metrics storage */ private readonly metrics; /** State */ private isRunning; private isPaused; private isProcessing; private idleCallbackHandle; private animationFrameHandle; private startTime; private aboveFoldHydrationTime; private fullHydrationTime; /** * Creates a new HydrationScheduler. * * @param config - Scheduler configuration */ constructor(config?: Partial); /** * Starts the hydration scheduler. * Begins processing queued tasks according to their priority and triggers. */ start(): void; /** * Stops the hydration scheduler. * Pending tasks remain in queue but processing stops. */ stop(): void; /** * Pauses the scheduler without clearing the queue. */ pause(): void; /** * Resumes a paused scheduler. */ resume(): void; /** * Disposes of all resources. * Call when unmounting the hydration system. */ dispose(): void; /** * Registers a hydration task. * * @param task - The hydration task to register */ register(task: HydrationTask): void; /** * Unregisters a hydration task. * * @param id - ID of the task to unregister */ unregister(id: HydrationBoundaryId): void; /** * Updates the priority of a registered boundary. * * @param id - ID of the boundary * @param priority - New priority level */ updatePriority(id: HydrationBoundaryId, priority: HydrationPriority): void; /** * Forces immediate hydration of a specific boundary. * * @param id - ID of the boundary to hydrate */ forceHydrate(id: HydrationBoundaryId): Promise; /** * Forces hydration of all registered boundaries. */ forceHydrateAll(): Promise; /** * Gets the status of a specific boundary. * * @param id - ID of the boundary * @returns The hydration status, or undefined if not found */ getStatus(id: HydrationBoundaryId): HydrationStatus | undefined; /** * Gets the current scheduler state. */ getState(): SchedulerState; /** * Gets queue statistics. */ getQueueStats(): PriorityQueueStats; /** * Gets aggregated metrics snapshot. */ getMetrics(): HydrationMetricsSnapshot; /** * Gets the scheduler configuration. */ getConfig(): HydrationSchedulerConfig; /** * Adds an event listener. * * @param type - Event type to listen for * @param listener - Callback function * @returns Unsubscribe function */ on(type: HydrationEventType, listener: HydrationEventListener): () => void; /** * Removes an event listener. */ off(type: HydrationEventType, listener: HydrationEventListener): void; /** * Sets up trigger-specific behavior for a boundary. */ private setupTrigger; /** * Observes visibility for a boundary. */ private observeVisibility; /** * Sets up interaction trigger for a boundary. */ private setupInteractionTrigger; /** * Sets up media query trigger for a boundary. */ private setupMediaTrigger; /** * Enqueues a boundary for hydration. */ private enqueue; /** * Schedules processing using appropriate callback. */ private scheduleProcessing; /** * Cancels any scheduled processing. */ private cancelScheduledProcessing; /** * Processes the queue with a deadline (for idle callback). */ private processQueueWithDeadline; /** * Processes the queue with frame budget. */ private processQueue; /** * Hydrates a single task. */ private hydrateTask; /** * Records a hydration metric. */ private recordMetric; /** * Checks if all boundaries are hydrated. */ private checkFullHydration; /** * Initializes the IntersectionObserver for visibility-based hydration. */ private initializeVisibilityObserver; /** * Handles visibility change for an element. */ private handleVisibilityChange; /** * Emits an event to all listeners. */ private emitEvent; /** * Debug logging helper. */ private log; } /** * Gets or creates the global HydrationScheduler instance. * * @param config - Scheduler configuration (only used if creating new instance) * @returns The global HydrationScheduler instance */ export declare function getHydrationScheduler(config?: Partial): HydrationScheduler; /** * Resets the global HydrationScheduler instance. * Primarily useful for testing. */ export declare function resetHydrationScheduler(): void;