@codefast/image-loader
Version:
Flexible image loader for Next.js supporting multiple CDN providers
93 lines • 2.84 kB
TypeScript
import type { ImageLoaderProps } from "next/image";
import type { ImageLoader, ImageLoaderFactoryConfig } from "./types";
/**
* Factory class for managing and selecting image loaders
* Implements the Factory pattern and follows the Dependency Inversion Principle
* Optimized for high performance with caching and memoization
*/
export declare class ImageLoaderFactory {
private readonly loaders;
private readonly config;
private readonly loaderCache;
private readonly transformCache;
private readonly maxCacheSize;
constructor(config?: ImageLoaderFactoryConfig);
/**
* Registers a new image loader
* Follows the Open/Closed Principle - new loaders can be added without modifying existing code
*/
registerLoader(loader: ImageLoader): void;
/**
* Registers multiple image loaders at once
*/
registerLoaders(loaders: ImageLoader[]): void;
/**
* Unregisters an image loader by name
*/
unregisterLoader(name: string): boolean;
/**
* Gets all registered loaders
*/
getLoaders(): readonly ImageLoader[];
/**
* Finds the appropriate loader for a given source URL
* Returns the first loader that can handle the URL
* Uses caching for improved performance on repeated lookups
*/
findLoader(source: string): ImageLoader | null;
/**
* Loads an image using the appropriate loader
* Main entry point for image loading
* Uses memoization for improved performance on repeated transformations
*/
load(config: ImageLoaderProps): string;
/**
* Creates a Next.js compatible image loader function
* This function can be used directly in Next.js configuration
*/
createNextImageLoader(): (params: ImageLoaderProps) => string;
/**
* Gets loader statistics
* Useful for debugging and monitoring
*/
getStats(): {
totalLoaders: number;
loaderNames: string[];
domainMappings: Record<string, string>;
};
/**
* Clears all registered loaders and caches
* Useful for testing or reconfiguration
*/
clear(): void;
/**
* Utility method to extract domain from URL
*/
private extractDomain;
/**
* Caches a loader for a specific domain
*/
private cacheLoader;
/**
* Clears the loader cache
*/
private clearLoaderCache;
/**
* Creates a cache key for URL transformation
*/
private createTransformCacheKey;
/**
* Caches a transformed URL
*/
private cacheTransform;
/**
* Clears the transform cache
*/
private clearTransformCache;
}
/**
* Default factory instance
* Singleton pattern for convenience
*/
export declare const defaultImageLoaderFactory: ImageLoaderFactory;
//# sourceMappingURL=loader-factory.d.ts.map