@vue-pdf-viewer/viewer
Version:
A vue-pdf-viewer component for Vue and Nuxt. Suitable for vue-pdf document.
72 lines (71 loc) • 2.69 kB
TypeScript
import { type Ref } from 'vue';
import type { PDFDocumentProxy } from 'pdfjs-dist/types/src/display/api';
/**
* Annotation Storage Composable with Automatic Save Support
*
* This composable provides a centralized way to manage PDF annotations with automatic
* saving capabilities. It tracks modifications and can automatically save annotations
* to the PDF document before operations like print and download.
*
* Key Features:
* - Tracks annotation modifications automatically
* - Provides methods to save annotations before print/download
* - Supports batch updates for better performance
* - Maintains reactivity across components
* - Returns updated PDF data for download operations
*
* Usage:
* ```typescript
* const {
* annotationStorage,
* hasModifications,
* saveAnnotationsToDocument,
* setAnnotationValue,
* batchUpdate
* } = useAnnotationStorage()
*
* // Set individual annotation
* setAnnotationValue('annotationId', { color: [255, 0, 0], noView: true })
*
* // Batch update multiple annotations
* batchUpdate([
* { key: 'id1', value: { color: [255, 0, 0] } },
* { key: 'id2', value: { noView: true } }
* ])
*
* // Save before print/download (returns updated PDF data)
* if (hasModifications()) {
* const updatedPdfData = await saveAnnotationsToDocument(pdfDocument)
* // Use updatedPdfData for download operations
* }
* ```
*/
export interface UseAnnotationStorageReturn {
annotationStorage: Ref<any>;
annotationEditorStorageMap: Ref<Map<string, any>>;
setStorage: (documentProxy: PDFDocumentProxy) => any;
batchUpdate: (updates: Array<{
key: string;
value: any;
}>) => void;
setAnnotationValue: (key: string, value: any, serialized?: boolean) => void;
hasModifications: () => boolean;
saveAnnotationsToDocument: (documentProxy: PDFDocumentProxy) => Promise<Uint8Array | null>;
cleanAnnotationStorage: () => void;
validateAnnotationData: (annotationData: any) => boolean;
renderTrigger: Ref<number>;
canvasRenderTrigger: Ref<number>;
cancelBatchUpdate: () => void;
ensureStorageInitialized: () => boolean;
getEditorKey: () => string;
getAnnotationById: (id: string) => any;
findEditorAnnotationKey: (annotationId: string) => string | undefined;
}
export declare const getGlobalStorageEntries: () => unknown[];
/**
* Creates a serializable version of the annotation data
* @param value - The annotation data to serialize
* @returns A serializable version of the annotation data
*/
export declare function createSerializableAnnotation(value: any): Promise<any>;
export default function useAnnotationStorage(): UseAnnotationStorageReturn;