import { default as React, ComponentType, ReactNode, LazyExoticComponent } from 'react';
/**
* Network quality tiers for adaptive loading
*/
export type NetworkTier = 'high' | 'medium' | 'low' | 'offline';
/**
* Loading priority levels
*/
export type LoadingPriority = 'critical' | 'high' | 'normal' | 'low' | 'idle';
/**
* Lazy loading strategy
*/
export type LazyStrategy = 'viewport' | 'interaction' | 'idle' | 'immediate' | 'network-aware';
/**
* Lazy component configuration
*/
export interface LazyComponentConfig
{
/** Import function */
loader: () => Promise<{
default: ComponentType
;
}>;
/** Loading priority */
priority?: LoadingPriority;
/** Loading strategy */
strategy?: LazyStrategy;
/** Preload on hover/focus */
preloadOnInteraction?: boolean;
/** SSR fallback */
ssrFallback?: ReactNode;
/** Error fallback */
errorFallback?: ReactNode | ((error: Error, retry: () => void) => ReactNode);
/** Loading fallback */
loadingFallback?: ReactNode;
/** Minimum loading time for UX */
minLoadingTime?: number;
/** Retry count on failure */
retryCount?: number;
/** Retry delay in ms */
retryDelay?: number;
/** Chunk name for webpack */
chunkName?: string;
}
/**
* Lazy image configuration
*/
export interface LazyImageConfig {
/** Image source */
src: string;
/** Placeholder image (LQIP) */
placeholder?: string;
/** Alt text */
alt: string;
/** Width */
width?: number;
/** Height */
height?: number;
/** Srcset for responsive images */
srcSet?: string;
/** Sizes attribute */
sizes?: string;
/** Loading strategy */
strategy?: LazyStrategy;
/** Root margin for early loading */
rootMargin?: string;
/** Enable blur-up effect */
blurUp?: boolean;
/** Blur radius for placeholder */
blurRadius?: number;
/** Decode async */
decodeAsync?: boolean;
/** onLoad callback */
onLoad?: () => void;
/** onError callback */
onError?: (error: Error) => void;
}
/**
* Module preload configuration
*/
export interface ModulePreloadConfig {
/** Module path or import function */
module: string | (() => Promise);
/** Preload priority */
priority?: LoadingPriority;
/** Trigger condition */
trigger?: 'immediate' | 'idle' | 'viewport' | 'route';
/** Associated route pattern */
routePattern?: string;
}
/**
* Pooled IntersectionObserver manager for efficient DOM observation
* Reduces observer instances by grouping elements with same config
*
* Memory Optimization: Includes periodic cleanup of orphaned entries
* to prevent memory leaks from disconnected DOM elements.
*/
declare class ObserverPool {
private static instance;
private static readonly CLEANUP_INTERVAL;
private observers;
private entries;
private callbacks;
private cleanupIntervalId;
private constructor();
static getInstance(): ObserverPool;
/**
* Reset singleton instance (for testing and HMR)
*/
static reset(): void;
/**
* Observe an element
*/
observe(element: Element, callback: (isIntersecting: boolean) => void, options?: {
threshold?: number;
rootMargin?: string;
}): () => void;
/**
* Unobserve an element
*/
unobserve(element: Element, threshold: number, rootMargin: string): void;
/**
* Disconnect all observers and clean up resources
*/
disconnectAll(): void;
/**
* Get current entry count (for debugging/monitoring)
*/
getEntryCount(): number;
/**
* Start periodic cleanup of orphaned entries
* Memory leak prevention: Removes entries for elements no longer in DOM
*/
private startCleanupInterval;
/**
* Stop cleanup interval
*/
private stopCleanupInterval;
/**
* Remove entries for elements that are no longer connected to the DOM
* This prevents memory leaks from strong references to disconnected elements
*/
private cleanupOrphanedEntries;
/**
* Generate cache key for observer config
*/
private getKey;
/**
* Get or create observer for config
*/
private getObserver;
}
/**
* Get current network quality tier
*/
export declare function getNetworkTier(): NetworkTier;
/**
* Check if network allows loading
*/
export declare function shouldLoadOnNetwork(priority: LoadingPriority, tier?: NetworkTier): boolean;
/**
* Intelligent module preloader with priority queue
*/
declare class ModulePreloader {
private static instance;
private preloadQueue;
private loadedModules;
private loadingModules;
private isProcessing;
static getInstance(): ModulePreloader;
/**
* Queue module for preloading
*/
queue(config: ModulePreloadConfig): void;
/**
* Check if module is loaded
*/
isLoaded(moduleId: string): boolean;
/**
* Clear all preloaded modules (for testing)
*/
reset(): void;
/**
* Process preload queue during idle time
*/
private processQueue;
/**
* Load a module
*/
private loadModule;
}
/**
* Create a lazy component with advanced features
*/
export declare function createLazyComponent(config: LazyComponentConfig
): LazyExoticComponent> & {
preload: () => Promise;
};
/**
* Higher-order component for lazy loading with full configuration
*/
export declare function withLazyLoading(config: LazyComponentConfig
): React.FC
void) => ReactNode);
}>;
/**
* Lazy image with blur-up placeholder and network awareness
*/
export declare function LazyImage({ src, placeholder, alt, width, height, srcSet, sizes, strategy, rootMargin, blurUp, blurRadius, decodeAsync, onLoad, onError, ...props }: LazyImageConfig & React.ImgHTMLAttributes): React.JSX.Element;
/**
* Hook for lazy loading any element on viewport intersection
*/
export declare function useLazyVisible(options?: {
rootMargin?: string;
threshold?: number;
triggerOnce?: boolean;
}): {
ref: React.RefObject;
isVisible: boolean;
hasBeenVisible: boolean;
};
/**
* Hook for preloading modules
*/
export declare function useModulePreload(configs: ModulePreloadConfig[]): void;
/**
* Hook for network-aware loading decisions
*/
export declare function useNetworkAwareLoading(priority?: LoadingPriority): {
networkTier: NetworkTier;
shouldLoad: boolean;
isOnline: boolean;
};
/**
* Preload a component imperatively
*/
export declare function preloadComponent(config: LazyComponentConfig
): Promise;
/**
* Preload multiple components in parallel
*/
export declare function preloadComponents(configs: Array): Promise;
/**
* Queue module for preloading
*/
export declare function queueModulePreload(config: ModulePreloadConfig): void;
/**
* Reset observer pool (for testing and HMR)
*/
export declare function resetObserverPool(): void;
/**
* Reset module preloader (for testing)
*/
export declare function resetModulePreloader(): void;
export { ObserverPool, ModulePreloader, };
declare const _default: {
createLazyComponent: typeof createLazyComponent;
withLazyLoading: typeof withLazyLoading;
LazyImage: typeof LazyImage;
useLazyVisible: typeof useLazyVisible;
useModulePreload: typeof useModulePreload;
useNetworkAwareLoading: typeof useNetworkAwareLoading;
preloadComponent: typeof preloadComponent;
preloadComponents: typeof preloadComponents;
queueModulePreload: typeof queueModulePreload;
getNetworkTier: typeof getNetworkTier;
shouldLoadOnNetwork: typeof shouldLoadOnNetwork;
};
export default _default;