/** * Image Loading Module * Handles loading images from MD5 hashes or URLs with caching support */ import type { ImageLoadCallback, ImageErrorCallback, RigData, SvgParallaxPartConfig } from '../types.js'; /** * ImageLoader class - Handles loading and caching images for character rigs */ export declare class ImageLoader { private baseHost; protected imageCache: Map; protected pendingRasterUpgrades: Map>; /** Incremented when viewport zoom resets — stale async raster completions are ignored. */ protected rasterApplyGeneration: number; /** * Creates a new ImageLoader instance * @param baseHost - The base URL for the API (default: https://orchestrator.distark.com) */ constructor(baseHost?: string); /** * Cancel in-flight SVG raster upgrades/downgrades and ignore their completion callbacks. * Call when editor viewport zoom returns to 1× so late zoom-era promises cannot * overwrite freshly downgraded 1× rasters. */ invalidatePendingRasterUpgrades(): void; /** * Set the base host for image loading * @param host - The base URL for the API */ setBaseHost(host: string): void; /** * Get the current base host * @returns The current base host URL */ getBaseHost(): string; /** * Resolve an image source (hash or URL) to a full URL * @param imageData - Image hash, URL, or data URL * @returns Full URL or null if invalid */ resolveImageSource(imageData: string | null | undefined): string | null; /** * Load an image from a URL/hash and invoke callbacks * @param key - Unique key for the image * @param imageData - Image hash or URL * @param onLoad - Callback when image loads successfully * @param onError - Callback when image fails to load (optional) */ loadImage(key: string, imageData: string | null | undefined, onLoad?: ImageLoadCallback, onError?: ImageErrorCallback): void; /** * Load multiple images in parallel * @param imagesToLoad - Array of {key, hash} objects * @param onProgress - Optional callback for progress updates * @returns Promise that resolves with loaded images map */ loadImages(imagesToLoad: Array<{ key: string; hash: string; }>, onProgress?: (loaded: number, total: number, failed: number) => void): Promise>; /** * Get the image cache * @returns The image cache Map */ getImageCache(): Map; /** * Clear the image cache */ clearImageCache(): void; /** * Get image from cache or return undefined * @param key - Image key */ getCachedImage(key: string): any; /** * Manually add image to cache * @param key - Image key * @param image - Image element */ cacheImage(key: string, image: any): void; requestImageForSize(key: string, desiredWidth: number, desiredHeight: number, loadedImages?: Record, options?: { cacheKey?: string; allowDowngrade?: boolean; }): any; requestSvgParallaxImageForSize(baseKey: string, config: SvgParallaxPartConfig | undefined, angleDegrees: number, desiredWidth: number, desiredHeight: number, loadedImages?: Record): any; waitForPendingImageUpgrades(): Promise; /** * Pre-rasterize SVG parts at intrinsic aspect × uniform scale (≥ layout × pixelDensity). * Stretch to layout dimensions happens at drawImage time, matching barebones distark. */ prepareSvgCanvases(rigData: RigData, loadedImages: Record, options?: { pixelDensity?: number; maxRasterSide?: number; }): Promise; /** * Pre-rasterize arbitrary part → URL / dimension maps (supports expanded mouth/eye keys). */ prepareSvgCanvasesForParts(imagePaths: Record, dimensionValues: Record, loadedImages: Record, options?: { pixelDensity?: number; maxRasterSide?: number; }): Promise; /** * Adds preserveAspectRatio="none" to the SVG root element. * Replaces any existing preserveAspectRatio attribute value. */ static injectPreserveAspectRatioNone(svgSource: string): string; /** * Load image with caching support * Checks cache first, only loads if not cached */ loadImageWithCache(key: string, imageData: string | null | undefined, onLoad?: ImageLoadCallback, onError?: ImageErrorCallback): void; /** * Collect all unique image hashes from rig data (imagePaths, part swap images, eyes, mouth). */ protected collectImageHashes(rigData: RigData, useCache: boolean): string[]; /** * Load all images for a character rig and populate the cache. * Uses createImageBitmap for off-main-thread parallel decoding when available. * Images are cached by their ACTUAL PATH (hash/URL), not semantic keys. * * Strategy: batch all sync work (resolve URLs, convert data URIs to Blobs) up front, * then fire all async createImageBitmap calls at once for maximum parallelism. */ loadAllRigImages(rigData: RigData, useCache?: boolean, onProgress?: (loaded: number, total: number, failed: number) => void): Promise>; private static decodeSvgDataUrl; private static parseDimension; private static parseViewBox; private static parseSvgDimensions; private static formatNumber; private static setSvgRootAttribute; /** * Prepares an SVG for one raster target without changing its source geometry. * The browser applies non-uniform scaling through preserveAspectRatio="none". */ static prepareSvgForRasterPixels(svgSource: string, targetWidth?: number, targetHeight?: number): string; /** * Compatibility alias. The previous fit-matrix path was removed; this only * sets pixel dimensions and preserveAspectRatio="none". */ static normalizeSvgToVisibleBounds(svgSource: string, targetWidth?: number, targetHeight?: number): string; protected prepareResolvedAsset(imageUrl: string): Promise<{ kind: 'svg'; svgSource: string; intrinsicWidth: number; intrinsicHeight: number; } | { kind: 'blob'; objectUrl: string; } | null>; protected createSvgCanvas(svgSource: string, targetWidth: number, targetHeight: number): Promise; protected attachSvgMetadata(image: any, svgSource: string, intrinsicWidth: number, intrinsicHeight: number, rasterWidth: number, rasterHeight: number): void; protected loadDomImage(url: string): Promise; } export declare const defaultImageLoader: ImageLoader; //# sourceMappingURL=imageLoad.d.ts.map