UNPKG

kinetic-slider

Version:

A WebGL-powered kinetic slider component using PIXI.js

173 lines (172 loc) 4.96 kB
import { Texture } from 'pixi.js'; import ResourceManager from './ResourceManager'; /** * Interface for a frame within an atlas */ export interface AtlasFrame { frame: { x: number; y: number; w: number; h: number; }; rotated: boolean; trimmed: boolean; spriteSourceSize?: { x: number; y: number; w: number; h: number; }; sourceSize?: { w: number; h: number; }; pivot?: { x: number; y: number; }; } /** * Interface for atlas metadata */ export interface AtlasMetadata { app?: string; version?: string; image?: string; format?: string; size?: { w: number; h: number; }; scale?: number; } /** * Interface for a complete texture atlas */ export interface Atlas { frames: Record<string, AtlasFrame>; meta: AtlasMetadata; } /** * Options for the atlas manager */ export interface AtlasManagerOptions { debug?: boolean; preferAtlas?: boolean; cacheFrameTextures?: boolean; basePath?: string; } /** * Status of an atlas or image loading operation */ export declare enum LoadStatus { NotLoaded = "not_loaded", Loading = "loading", Loaded = "loaded", Failed = "failed" } /** * Manager for handling texture atlases in the KineticSlider * * This class provides methods for: * - Loading texture atlases from JSON and image files * - Retrieving textures for individual frames * - Managing the lifecycle of atlas resources * - Providing proper cleanup when an atlas is no longer needed */ export declare class AtlasManager { private atlases; private atlasTextures; private frameTextures; private imageTextures; private atlasStatus; private imageStatus; private resourceManager?; private options; /** * Create a new atlas manager * * @param options - Options for the atlas manager * @param resourceManager - Optional ResourceManager for tracking resources */ constructor(options?: AtlasManagerOptions, resourceManager?: ResourceManager); /** * Extract the filename from a path for atlas frame lookup * * @param imagePath - The full path to the image * @returns The filename part of the path */ private getFilenameFromPath; /** * Load a texture atlas from a JSON file * * @param atlasId - Identifier for the atlas * @param jsonUrl - URL to the atlas JSON file * @param imageUrl - Optional URL to the atlas image file (if not specified in JSON) * @returns Promise resolving when the atlas is loaded */ loadAtlas(atlasId: string, jsonUrl: string, imageUrl?: string): Promise<boolean>; /** * Check if a frame exists in any loaded atlas * * @param frameName - Name of the frame to check * @returns The ID of the atlas containing the frame, or null if not found */ hasFrame(frameName: string): string | null; /** * Get a texture for a frame from an atlas * * @param frameName - Name of the frame * @param atlasId - Optional ID of the atlas to use (if not specified, all atlases will be searched) * @returns The texture for the frame, or null if not found */ getFrameTexture(frameName: string, atlasId?: string): Texture | null; /** * Get a list of all frame names in an atlas * * @param atlasId - ID of the atlas * @returns Array of frame names, or empty array if atlas not found */ getFrameNames(atlasId: string): string[]; /** * Get a texture for an image, either from an atlas or as an individual texture * * @param imagePath - Path to the image * @param atlasId - Optional ID of a specific atlas to check first * @returns Promise resolving to the texture, or null if not found */ getTexture(imagePath: string, atlasId?: string): Promise<Texture | null>; /** * Preload a set of images, preferably from atlas(es) * * @param imagePaths - Array of image paths to preload * @param atlasIds - Optional array of atlas IDs to search for frames * @param progressCallback - Optional callback for loading progress * @returns Promise resolving when all images are loaded */ preloadImages(imagePaths: string[], atlasIds?: string[], progressCallback?: (progress: number) => void): Promise<void>; /** * Unload an atlas and its resources * * @param atlasId - ID of the atlas to unload */ unloadAtlas(atlasId: string): void; /** * Unload an individual image texture * * @param imagePath - Path to the image */ unloadTexture(imagePath: string): void; /** * Clean up all resources */ dispose(): void; /** * Log a message with the appropriate level * * @param message - Message to log * @param level - Log level */ private log; }