@vue-pdf-viewer/viewer
Version:
A vue-pdf-viewer component for Vue and Nuxt. Suitable for vue-pdf document.
55 lines (54 loc) • 2.06 kB
TypeScript
import { Ref } from 'vue';
import type { AnnotationLayer, PDFPageProxy } from 'pdfjs-dist';
import { AnnotationType } from '@vue-pdf-viewer/shared';
import { UnifiedAnnotation, AnnotationEventType, AnnotationEvent, AnnotationEventListener, annotationEventEmitter } from '@/utils/annotation-event';
export type { UnifiedAnnotation, AnnotationEventType, AnnotationEvent, AnnotationEventListener };
export { annotationEventEmitter };
/**
* Props for useAnnotation composable
*/
export interface UseAnnotationProps {
page: Ref<PDFPageProxy>;
annotationLayer: Ref<AnnotationLayer | undefined>;
}
/**
* Return type for useAnnotation composable
*/
export interface UseAnnotationReturn {
annotations: Ref<Map<AnnotationType, UnifiedAnnotation[]>>;
isInitialized: Ref<boolean>;
addAnnotation: <T extends UnifiedAnnotation>(annotation: T) => void;
updateAnnotation: <T extends UnifiedAnnotation>(annotation: T) => void;
removeAnnotation: <T extends UnifiedAnnotation>(annotation: T) => void;
getAnnotationsByType: <T extends UnifiedAnnotation>(type: AnnotationType) => T[];
syncAnnotationsFromPage: () => Promise<void>;
}
/**
* useAnnotation - Unified composable for managing all annotation types
*
* This composable provides a centralized way to:
* 1. Store annotations in the singleton useAnnotationStorage
* 2. Handle add/update/remove operations for all annotation types
* 3. Sync annotations from PDF pages to storage
* 4. Emit events for annotation changes
*
* @example
* ```typescript
* const { annotations, addAnnotation, updateAnnotation, removeAnnotation } = useAnnotation({
* page: pageRef,
* annotationLayer: annotationLayerRef
* })
*
* // Add a new highlight annotation
* addAnnotation({
* id: 'highlight-1',
* annotationType: AnnotationType.Highlight,
* pageIndex: 0,
* rect: [100, 100, 200, 200],
* hexColor: '#FFFF00',
* // ... other properties
* })
* ```
*/
export declare function useAnnotation(props: UseAnnotationProps): UseAnnotationReturn;
export default useAnnotation;