TypeScript Types
Complete TypeScript type definitions for Annota.
Core Types
Section titled “Core Types”Annotation
Section titled “Annotation”interface Annotation { id: string; shape: Shape; properties?: Record<string, unknown>; style?: AnnotationStyle; layerId?: string;}type Shape = PointShape | RectangleShape | PolygonShape;
interface PointShape { type: "point"; geometry: PointGeometry; bounds: Bounds;}
interface RectangleShape { type: "rectangle"; geometry: RectangleGeometry; bounds: Bounds;}
interface PolygonShape { type: "polygon"; geometry: PolygonGeometry; bounds: Bounds;}Geometry Types
Section titled “Geometry Types”interface PointGeometry { x: number; y: number;}
interface RectangleGeometry { x: number; y: number; width: number; height: number;}
interface PolygonGeometry { points: Array<{ x: number; y: number }>;}
interface Bounds { x: number; y: number; width: number; height: number;}AnnotationStyle
Section titled “AnnotationStyle”interface AnnotationStyle { fill?: string; fillOpacity?: number; stroke?: string; strokeWidth?: number; strokeOpacity?: number;}Layer Types
Section titled “Layer Types”interface Layer { id: string; name: string; visible: boolean; opacity?: number; locked?: boolean; style?: AnnotationStyle; zIndex?: number;}LayerManager
Section titled “LayerManager”interface LayerManager { layers: Layer[]; createLayer(layer: Layer): void; updateLayer(id: string, updates: Partial<Layer>): void; deleteLayer(id: string, deleteAnnotations?: boolean): void; getLayer(id: string): Layer | undefined;}Tool Types
Section titled “Tool Types”interface Tool { name: string; cursor?: string; onActivate?(): void; onDeactivate?(): void; onPointerDown?(event: PointerEvent): void; onPointerMove?(event: PointerEvent): void; onPointerUp?(event: PointerEvent): void; onKeyDown?(event: KeyboardEvent): void;}Tool Options
Section titled “Tool Options”interface ToolOptions { style?: AnnotationStyle; layer?: string; properties?: Record<string, unknown>;}
interface PushToolOptions extends ToolOptions { radius?: number; strength?: number; showCursor?: boolean;}
interface ContourToolOptions extends ToolOptions { threshold?: number; minArea?: number; maxContours?: number;}Event Types
Section titled “Event Types”AnnotatorEvents
Section titled “AnnotatorEvents”interface AnnotatorEvents { createAnnotation: (annotation: Annotation) => void; updateAnnotation: (annotation: Annotation) => void; deleteAnnotation: (annotation: Annotation) => void; selectionChanged: (data: SelectionChangedData) => void; hoverChanged: (annotation: Annotation | null) => void; toolChanged: (tool: Tool | null) => void;}
interface SelectionChangedData { selected: string[]; added?: string[]; removed?: string[];}Hook Return Types
Section titled “Hook Return Types”useAnnotator
Section titled “useAnnotator”function useAnnotator(): Annotator | null;useAnnotations
Section titled “useAnnotations”function useAnnotations(): Annotation[];useSelection
Section titled “useSelection”function useSelection(): Annotation[];useTool
Section titled “useTool”interface UseToolOptions { viewer: OpenSeadragon.Viewer | null; handler: Tool | null; enabled?: boolean;}
function useTool(options: UseToolOptions): void;useLayers
Section titled “useLayers”function useLayers(): Layer[];useLayerManager
Section titled “useLayerManager”function useLayerManager(): LayerManager;Component Props
Section titled “Component Props”AnnotaProviderProps
Section titled “AnnotaProviderProps”interface AnnotaProviderProps { slideId: string; children: ReactNode;}AnnotaViewerProps
Section titled “AnnotaViewerProps”interface AnnotaViewerProps { options: OpenSeadragon.Options; onViewerReady?: (viewer: OpenSeadragon.Viewer) => void; className?: string; style?: CSSProperties;}AnnotatorProps
Section titled “AnnotatorProps”interface AnnotatorProps { viewer: OpenSeadragon.Viewer | null; style?: StyleFunction; children?: ReactNode;}
type StyleFunction = (annotation: Annotation) => AnnotationStyle;Utility Types
Section titled “Utility Types”DeepPartial
Section titled “DeepPartial”type DeepPartial<T> = { [P in keyof T]?: T[P] extends object ? DeepPartial<T[P]> : T[P];};interface Point { x: number; y: number;}import type { Annotation, Shape, Layer, AnnotationStyle } from "annota";