import { type VectorItem } from "./vectorUtils"; /** * VectorManager: Singleton class that manages SVG vector loading and caching * * * Key responsibilities: * - Fetches and caches the SVG vectors list * - Manages vector loading states to prevent duplicate loading * - Optimizes loading through intersection observers * - Handles scroll-based lazy loading of vectors * * Usage: * const vectorManager = VectorManager.getInstance(); * await vectorManager.getVectorList(); * vectorManager.loadVector('Vector Name'); * * Implements multiple caching strategies: * 1. Browser cache for vector files * 2. localStorage for vector list * 3. Memory cache for runtime performance */ export interface VectorData { name: string; category: VectorItem['category']; url: string; isCustom?: boolean; } declare class VectorManager { private static readonly DEBUG_MODE; private static readonly WAIT_TIME; private static instance; private loadedVectors; private observers; private scrollTimeout; private vectorListPromise; private initialVectorsLoaded; private allVectorsLoaded; private cachedVectorList; private static readonly CACHE_KEY; private static readonly CACHE_DURATION; private static readonly LOADED_VECTORS_KEY; private static readonly CACHE_CONTROL; private visibleVectors; private static initialPreloadComplete; private static preloadPromise; private completeVectorList; static isInitialized: boolean; static initialVectorNumber: number; private static initializationPromise; private remainingTime; private preInitializedObservers; static readonly BATCH_SIZE = 100; private currentBatchIndex; private batchIndices; private categoryVectors; private customVectors; /** * Private constructor to enforce singleton pattern */ private constructor(); /** * Gets or creates the singleton instance and initializes it */ static getInstance(): Promise; /** * Initializes the VectorManager with initial vectors and setup */ private initialize; /** * Pre-initializes observers during VectorManager initialization */ private preInitializeObservers; /** * Loads custom vectors from custom-svgs.json */ loadCustomVectors(): Promise; /** * Gets list of vectors cached in browser */ private getBrowserCachedVectors; /** * Saves the current state of loaded vectors to localStorage */ private saveLoadedVectors; /** * Gets initial vector list (initial number of vectors + recent vectors) */ getInitialVectorList(): Promise; /** * Saves vector list to localStorage cache */ private saveVectorListToCache; /** * Verifies if a vector is actually cached in the browser */ private verifyVectorCache; /** * Loads a vector by name * Simpler than font loading since we just need to verify the URL exists */ loadVector(name: string): Promise; /** * Loads initial visible vectors */ private loadInitialVisibleVectors; /** * Handles scroll optimization for vector loading * Implements debouncing to prevent excessive loading * @param callback - Optional callback after vectors are loaded */ handleScroll(callback?: () => void): void; /** * Checks if scrolling is currently active */ isScrolling(): boolean; /** * Adds a vector to the visible set */ addVisibleVector(name: string): void; /** * Removes a vector from the visible set */ removeVisibleVector(name: string): void; /** * Gets the cached vector list without making an API call */ getCachedVectorList(): VectorData[]; /** * Gets the next batch of vectors */ getNextBatch(controllerId: string, category?: string): VectorData[]; /** * Checks if there are more vectors to load */ hasMoreVectors(controllerId: string, category?: string): boolean; /** * Resets the batch index to initial number * This allows each vector input controller to start from the beginning */ resetBatchIndex(controllerId: string): void; /** * Gets preloaded vectors for a category */ getPreloadedVectors(category: VectorItem['category']): VectorData[]; /** * Gets the complete list of vectors */ getCompleteVectorList(force?: boolean): Promise; /** * Checks if a vector is a custom vector */ isCustomVector(name: string): boolean; /** * Gets custom vector data if available */ getCustomVector(name: string): VectorData | undefined; /** * Removes a custom vector */ removeCustomVector(name: string): Promise; /** * Gets observer for a container */ getObserver(container: HTMLElement | null): IntersectionObserver | null; /** * Gets a pre-initialized observer */ getPreInitializedObserver(): IntersectionObserver | null; /** * Gets stats about loaded vectors */ getLoadedVectorsStats(): { total: number; vectors: string[]; }; /** * Cleans up resources when a vector container is removed * Prevents memory leaks from orphaned observers */ cleanup(containerId: string): void; /** * Checks if a vector is already loaded */ isVectorLoaded(name: string): boolean; /** * Gets the vector list from cache without making an API call * Returns null if cache is invalid or expired */ private getVectorListFromCache; } export default VectorManager;