@vue-pdf-viewer/viewer
Version:
A vue-pdf-viewer component for Vue and Nuxt. Suitable for vue-pdf document.
112 lines (111 loc) • 3.19 kB
TypeScript
/**
* AnnotationImageManager - Based on PDF.js ImageManager
*
* Manages images used by annotation editors with memory optimization.
* Features:
* - Caching with reference counting
* - Memory management (converts to blob when not in use)
* - Multiple image sources: File, URL, Blob, Canvas
* - SVG support with aspect ratio preservation
* - Unique ID generation and validation
*/
export interface ImageData {
bitmap: ImageBitmap | HTMLImageElement;
id: string;
refCounter: number;
isSvg: boolean;
url?: string;
file?: File;
blobPromise?: Promise<Blob>;
svgUrl?: string;
}
export interface ImageManagerOptions {
baseId?: string;
}
/**
* Utility function to generate unique IDs
*/
declare function generateUuid(): string;
/**
* Utility function to fetch data from URL
*/
declare function fetchImageData(url: string): Promise<Blob>;
declare function validateFileSize(file: File, maxSize?: number): boolean;
declare function validateFileMimeType(file: File, mimeTypes?: string[]): boolean;
declare function isSVGFittingCanvas(): Promise<boolean>;
export declare class AnnotationImageManager {
private readonly baseId;
private idCounter;
private cache;
constructor(options?: ImageManagerOptions);
/**
* Get image data from cache or create new entry
*/
private get;
/**
* Handle SVG image loading with aspect ratio preservation
*/
private handleSvgImage;
/**
* Get image from File object
*/
getFromFile(file: File): Promise<ImageData | null>;
/**
* Get image from URL
*/
getFromUrl(url: string): Promise<ImageData | null>;
/**
* Get image from Blob with custom ID
*/
getFromBlob(id: string, blobPromise: Promise<Blob>): Promise<ImageData | null>;
/**
* Get image by ID (restore from cache)
*/
getFromId(id: string): Promise<ImageData | null>;
/**
* Get image from Canvas element
*/
getFromCanvas(id: string, canvas: HTMLCanvasElement): ImageData;
/**
* Get SVG URL by ID
*/
getSvgUrl(id: string): string | null;
/**
* Delete image by ID (decrement reference counter)
*/
deleteId(id: string): void;
/**
* Check if ID belongs to this manager
*/
isValidId(id: string): boolean;
/**
* Get all cached image IDs
*/
getCachedIds(): string[];
/**
* Get cache statistics
*/
getCacheStats(): {
totalImages: number;
loadedImages: number;
totalMemory: number;
};
/**
* Clear all cached images
*/
clear(): void;
/**
* Convert ImageBitmap to data URL (for export/clipboard)
*/
bitmapToDataUrl(imageData: ImageData): Promise<string>;
/**
* Create ImageBitmap from existing ImageData for serialization
*/
serializeBitmap(imageData: ImageData, options?: {
width?: number;
height?: number;
preserveAspectRatio?: boolean;
}): Promise<ImageBitmap>;
}
export declare const annotationImageManager: AnnotationImageManager;
export { generateUuid, fetchImageData, isSVGFittingCanvas, validateFileSize, validateFileMimeType };