import { ComponentType } from 'react'; import { ModuleId, ModuleLoadOptions, ModuleLoadingState } from './types'; import { ModuleRegistry } from './module-registry'; /** * Prefetch hint configuration. */ export interface PrefetchHint { /** Module ID to prefetch */ moduleId: ModuleId; /** Likelihood of being needed (0-1) */ probability: number; /** When to trigger prefetch */ trigger: 'immediate' | 'idle' | 'visible' | 'hover'; /** Element to observe for visibility/hover */ element?: Element; } /** * Loading performance metrics. */ export interface LoadingMetrics { /** Total modules loaded */ totalLoaded: number; /** Total load time (ms) */ totalLoadTime: number; /** Average load time (ms) */ averageLoadTime: number; /** Failed loads */ failedLoads: number; /** Cache hits */ cacheHits: number; /** Prefetch hits */ prefetchHits: number; } /** * Orchestrates module loading with intelligent strategies. * Supports priority-based loading, prefetching, and performance monitoring. * * @example * ```typescript * const loader = new ModuleLoader(); * * // Load a module with high priority * const component = await loader.load(moduleId, { * priority: LoadingPriority.HIGH, * timeout: 5000, * }); * * // Add prefetch hint * loader.addPrefetchHint({ * moduleId: otherModuleId, * probability: 0.8, * trigger: 'idle', * }); * ``` */ export declare class ModuleLoader { /** Module registry reference */ private readonly registry; /** Priority queues for loading tasks */ private readonly queues; /** Currently loading modules */ private readonly loading; /** Loading states by module */ private readonly loadingStates; /** Prefetch hints */ private readonly prefetchHints; /** Intersection observers for visibility-based prefetch */ private readonly visibilityObservers; /** Loading metrics */ private metrics; /** Whether loader is processing queue */ private isProcessing; /** Idle callback ID */ private idleCallbackId; /** * Creates a new ModuleLoader. * @param registry - Module registry (defaults to global) */ constructor(registry?: ModuleRegistry); /** * Gets the number of pending loads. */ get pendingCount(): number; /** * Gets the number of currently loading modules. */ get loadingCount(): number; /** * Loads a module with the given options. * @param moduleId - Module to load * @param options - Loading options * @returns Loaded component */ load(moduleId: ModuleId, options?: ModuleLoadOptions): Promise>; /** * Loads multiple modules in parallel. * @param moduleIds - Modules to load * @param options - Loading options * @returns Loaded components */ loadMany(moduleIds: ModuleId[], options?: ModuleLoadOptions): Promise>>; /** * Gets the loading state of a module. * @param moduleId - Module ID * @returns Loading state or null */ getLoadingState(moduleId: ModuleId): ModuleLoadingState | null; /** * Cancels a pending load. * @param moduleId - Module to cancel * @returns Whether cancellation was successful */ cancel(moduleId: ModuleId): boolean; /** * Adds a prefetch hint for a module. * @param hint - Prefetch hint configuration */ addPrefetchHint(hint: PrefetchHint): void; /** * Removes a prefetch hint. * @param moduleId - Module ID */ removePrefetchHint(moduleId: ModuleId): void; /** * Gets loading metrics. * @returns Loading metrics */ getMetrics(): LoadingMetrics; /** * Resets loading metrics. */ resetMetrics(): void; /** * Clears all queues and cancels pending loads. */ clearQueues(): void; /** * Disposes the loader and cleans up resources. */ dispose(): void; /** * Triggers prefetch for a module. * @param moduleId - Module to prefetch */ private triggerPrefetch; /** * Schedules prefetch for idle time. * @param moduleId - Module to prefetch */ private schedulePrefetchOnIdle; /** * Sets up visibility observation for prefetch. * @param moduleId - Module ID * @param element - Element to observe */ private observeForVisibility; /** * Sets up hover observation for prefetch. * @param moduleId - Module ID * @param element - Element to observe */ private observeForHover; /** * Processes the loading queue. */ private processQueue; /** * Checks if there are any tasks in queues. */ private hasQueuedTasks; /** * Gets the next task from queues (highest priority first). * @returns Next task or null */ private getNextTask; /** * Executes a loading task. * @param task - Task to execute */ private executeTask; /** * Loads dependencies for a module. * @param moduleId - Module ID * @param options - Loading options */ private loadDependencies; /** * Updates loading state for a module. * @param moduleId - Module ID * @param state - New state */ private updateLoadingState; } /** * Gets the default global module loader. * @returns Default ModuleLoader instance */ export declare function getDefaultLoader(): ModuleLoader; /** * Sets the default global module loader. * @param loader - Loader to set as default */ export declare function setDefaultLoader(loader: ModuleLoader): void; /** * Resets the default global module loader. */ export declare function resetDefaultLoader(): void; /** * Loads a module using the default loader. * @param moduleId - Module to load * @param options - Loading options * @returns Loaded component */ export declare function loadModule(moduleId: ModuleId, options?: ModuleLoadOptions): Promise>; /** * Prefetches a module using the default loader. * @param moduleId - Module to prefetch * @param probability - Likelihood of needing the module */ export declare function prefetchModule(moduleId: ModuleId, probability?: number): void; /** * Creates a lazy loader wrapper for React.lazy() compatibility. * * @example * ```typescript * const LazyModule = createLazyLoader(moduleId); * * // Use in JSX * }> * * * ``` */ export declare function createLazyLoader(moduleId: ModuleId, options?: ModuleLoadOptions): () => Promise<{ default: ComponentType; }>;