@embedpdf/plugin-annotation 1.0.11 → 1.0.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +2 -693
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1 -266
- package/dist/index.js +509 -164
- package/dist/index.js.map +1 -1
- package/dist/lib/actions.d.ts +104 -0
- package/dist/lib/annotation-plugin.d.ts +34 -0
- package/dist/lib/helpers.d.ts +18 -0
- package/dist/lib/index.d.ts +12 -0
- package/dist/lib/manifest.d.ts +4 -0
- package/dist/lib/patching/derived-rect.d.ts +2 -0
- package/dist/lib/patching/index.d.ts +4 -0
- package/dist/lib/patching/line-ending-handlers.d.ts +20 -0
- package/dist/lib/patching/line-endings.d.ts +13 -0
- package/dist/lib/patching/patch-utils.d.ts +7 -0
- package/dist/lib/reducer.d.ts +5 -0
- package/dist/lib/selectors.d.ts +25 -0
- package/dist/lib/types.d.ts +168 -0
- package/dist/lib/utils.d.ts +11 -0
- package/dist/lib/variant-key.d.ts +8 -0
- package/dist/preact/adapter.d.ts +8 -0
- package/dist/preact/core.d.ts +1 -0
- package/dist/preact/index.cjs +2 -1038
- package/dist/preact/index.cjs.map +1 -1
- package/dist/preact/index.d.ts +1 -28
- package/dist/preact/index.js +2150 -539
- package/dist/preact/index.js.map +1 -1
- package/dist/preact/interaction-manager.d.ts +1 -0
- package/dist/preact/selection.d.ts +1 -0
- package/dist/react/adapter.d.ts +2 -0
- package/dist/react/core.d.ts +1 -0
- package/dist/react/index.cjs +2 -0
- package/dist/react/index.cjs.map +1 -0
- package/dist/react/index.d.ts +1 -0
- package/dist/react/index.js +2624 -0
- package/dist/react/index.js.map +1 -0
- package/dist/react/interaction-manager.d.ts +1 -0
- package/dist/react/selection.d.ts +1 -0
- package/dist/shared-preact/components/annotation-container.d.ts +24 -0
- package/dist/shared-preact/components/annotation-layer.d.ts +13 -0
- package/dist/shared-preact/components/annotations/circle-paint.d.ts +10 -0
- package/dist/shared-preact/components/annotations/circle.d.ts +29 -0
- package/dist/shared-preact/components/annotations/ink-highlight-paint.d.ts +0 -0
- package/dist/shared-preact/components/annotations/ink-paint.d.ts +18 -0
- package/dist/shared-preact/components/annotations/ink.d.ts +25 -0
- package/dist/shared-preact/components/annotations/line-paint.d.ts +10 -0
- package/dist/shared-preact/components/annotations/line.d.ts +33 -0
- package/dist/shared-preact/components/annotations/polygon-paint.d.ts +9 -0
- package/dist/shared-preact/components/annotations/polygon.d.ts +17 -0
- package/dist/shared-preact/components/annotations/polyline-paint.d.ts +10 -0
- package/dist/shared-preact/components/annotations/polyline.d.ts +17 -0
- package/dist/shared-preact/components/annotations/square-paint.d.ts +10 -0
- package/dist/shared-preact/components/annotations/square.d.ts +29 -0
- package/dist/shared-preact/components/annotations.d.ts +11 -0
- package/dist/shared-preact/components/counter-rotate-container.d.ts +32 -0
- package/dist/shared-preact/components/index.d.ts +1 -0
- package/dist/shared-preact/components/render-annotation.d.ts +11 -0
- package/dist/shared-preact/components/resize-handles.d.ts +9 -0
- package/dist/shared-preact/components/text-markup/highlight.d.ts +13 -0
- package/dist/shared-preact/components/text-markup/squiggly.d.ts +13 -0
- package/dist/shared-preact/components/text-markup/strikeout.d.ts +13 -0
- package/dist/shared-preact/components/text-markup/underline.d.ts +13 -0
- package/dist/shared-preact/components/text-markup.d.ts +6 -0
- package/dist/shared-preact/components/vertex-editor.d.ts +19 -0
- package/dist/shared-preact/hooks/index.d.ts +1 -0
- package/dist/shared-preact/hooks/use-annotation.d.ts +11 -0
- package/dist/shared-preact/hooks/use-drag-resize.d.ts +31 -0
- package/dist/shared-preact/index.d.ts +2 -0
- package/dist/shared-preact/patch-ink.d.ts +16 -0
- package/dist/shared-preact/patchers.d.ts +9 -0
- package/dist/shared-preact/types.d.ts +12 -0
- package/dist/shared-preact/vertex-patchers.d.ts +10 -0
- package/dist/shared-react/components/annotation-container.d.ts +24 -0
- package/dist/shared-react/components/annotation-layer.d.ts +13 -0
- package/dist/shared-react/components/annotations/circle-paint.d.ts +10 -0
- package/dist/shared-react/components/annotations/circle.d.ts +29 -0
- package/dist/shared-react/components/annotations/ink-highlight-paint.d.ts +0 -0
- package/dist/shared-react/components/annotations/ink-paint.d.ts +17 -0
- package/dist/shared-react/components/annotations/ink.d.ts +25 -0
- package/dist/shared-react/components/annotations/line-paint.d.ts +10 -0
- package/dist/shared-react/components/annotations/line.d.ts +33 -0
- package/dist/shared-react/components/annotations/polygon-paint.d.ts +9 -0
- package/dist/shared-react/components/annotations/polygon.d.ts +17 -0
- package/dist/shared-react/components/annotations/polyline-paint.d.ts +10 -0
- package/dist/shared-react/components/annotations/polyline.d.ts +17 -0
- package/dist/shared-react/components/annotations/square-paint.d.ts +10 -0
- package/dist/shared-react/components/annotations/square.d.ts +29 -0
- package/dist/shared-react/components/annotations.d.ts +11 -0
- package/dist/shared-react/components/counter-rotate-container.d.ts +32 -0
- package/dist/shared-react/components/index.d.ts +1 -0
- package/dist/shared-react/components/render-annotation.d.ts +11 -0
- package/dist/shared-react/components/resize-handles.d.ts +9 -0
- package/dist/shared-react/components/text-markup/highlight.d.ts +13 -0
- package/dist/shared-react/components/text-markup/squiggly.d.ts +13 -0
- package/dist/shared-react/components/text-markup/strikeout.d.ts +13 -0
- package/dist/shared-react/components/text-markup/underline.d.ts +13 -0
- package/dist/shared-react/components/text-markup.d.ts +6 -0
- package/dist/shared-react/components/vertex-editor.d.ts +19 -0
- package/dist/shared-react/hooks/index.d.ts +1 -0
- package/dist/shared-react/hooks/use-annotation.d.ts +11 -0
- package/dist/shared-react/hooks/use-drag-resize.d.ts +31 -0
- package/dist/shared-react/index.d.ts +2 -0
- package/dist/shared-react/patch-ink.d.ts +16 -0
- package/dist/shared-react/patchers.d.ts +9 -0
- package/dist/shared-react/types.d.ts +12 -0
- package/dist/shared-react/vertex-patchers.d.ts +10 -0
- package/package.json +17 -15
- package/dist/index.d.cts +0 -266
- package/dist/preact/index.d.cts +0 -28
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/lib/manifest.ts","../src/lib/annotation-plugin.ts","../src/lib/actions.ts","../src/lib/utils.ts","../src/lib/selectors.ts","../src/lib/reducer.ts","../src/lib/index.ts"],"sourcesContent":["import { PluginManifest } from '@embedpdf/core';\nimport { AnnotationPluginConfig } from './types';\n\nexport const ANNOTATION_PLUGIN_ID = 'annotation';\n\nexport const manifest: PluginManifest<AnnotationPluginConfig> = {\n id: ANNOTATION_PLUGIN_ID,\n name: 'Annotation Plugin',\n version: '1.0.0',\n provides: ['annotation'],\n requires: ['interaction-manager', 'selection'],\n optional: ['history'],\n defaultConfig: {\n enabled: true,\n autoCommit: true,\n },\n};\n","import {\n BasePlugin,\n createBehaviorEmitter,\n enumEntries,\n PluginRegistry,\n SET_DOCUMENT,\n} from '@embedpdf/core';\nimport {\n ignore,\n PdfAnnotationObject,\n PdfDocumentObject,\n PdfEngine,\n PdfErrorReason,\n Task,\n PdfAnnotationSubtype,\n PdfTaskHelper,\n PdfErrorCode,\n PdfTask,\n Rotation,\n AppearanceMode,\n} from '@embedpdf/models';\nimport {\n ActiveTool,\n AnnotationCapability,\n AnnotationPluginConfig,\n AnnotationState,\n BaseAnnotationDefaults,\n GetPageAnnotationsOptions,\n RenderAnnotationOptions,\n StylableSubtype,\n ToolDefaultsBySubtype,\n TrackedAnnotation,\n} from './types';\nimport {\n setAnnotations,\n selectAnnotation,\n deselectAnnotation,\n setAnnotationMode,\n AnnotationAction,\n updateToolDefaults,\n addColorPreset,\n createAnnotation,\n patchAnnotation,\n deleteAnnotation,\n commitPendingChanges,\n storePdfId,\n purgeAnnotation,\n reindexPageAnnotations,\n} from './actions';\nimport {\n InteractionManagerCapability,\n InteractionManagerPlugin,\n InteractionMode,\n} from '@embedpdf/plugin-interaction-manager';\nimport { SelectionPlugin, SelectionCapability } from '@embedpdf/plugin-selection';\nimport { HistoryPlugin, HistoryCapability, Command } from '@embedpdf/plugin-history';\nimport { getSelectedAnnotation } from './selectors';\nimport { makeUid, parseUid } from './utils';\n\nexport class AnnotationPlugin extends BasePlugin<\n AnnotationPluginConfig,\n AnnotationCapability,\n AnnotationState,\n AnnotationAction\n> {\n static readonly id = 'annotation' as const;\n\n private readonly ANNOTATION_HISTORY_TOPIC = 'annotations';\n\n private readonly config: AnnotationPluginConfig;\n\n private engine: PdfEngine;\n private readonly state$ = createBehaviorEmitter<AnnotationState>();\n private readonly interactionManager: InteractionManagerCapability | null;\n private readonly selection: SelectionCapability | null;\n private readonly history: HistoryCapability | null;\n\n /** Map <subtype> → <modeId>. Filled once in `initialize()`. */\n private readonly modeBySubtype = new Map<StylableSubtype, string>();\n /** The inverse map for quick lookup in onModeChange(). */\n private readonly subtypeByMode = new Map<string, StylableSubtype>();\n private readonly modeChange$ = createBehaviorEmitter<StylableSubtype | null>();\n private readonly activeTool$ = createBehaviorEmitter<ActiveTool>({\n mode: null,\n defaults: null,\n });\n\n constructor(\n id: string,\n registry: PluginRegistry,\n engine: PdfEngine,\n config: AnnotationPluginConfig,\n ) {\n super(id, registry);\n this.engine = engine;\n this.config = config;\n\n const selection = registry.getPlugin<SelectionPlugin>('selection');\n this.selection = selection?.provides() ?? null;\n\n const history = registry.getPlugin<HistoryPlugin>('history');\n this.history = history?.provides() ?? null;\n\n const interactionManager = registry.getPlugin<InteractionManagerPlugin>('interaction-manager');\n this.interactionManager = interactionManager?.provides() ?? null;\n\n this.coreStore.onAction(SET_DOCUMENT, (_action, state) => {\n const doc = state.core.document;\n if (doc) {\n this.getAllAnnotations(doc);\n }\n });\n }\n\n async initialize(): Promise<void> {\n for (const [subtype, defaults] of enumEntries(this.state.toolDefaults)) {\n this.registerTool(subtype, defaults);\n }\n\n this.history?.onHistoryChange((topic) => {\n if (topic === this.ANNOTATION_HISTORY_TOPIC && this.config.autoCommit !== false) {\n this.commit();\n }\n });\n\n this.interactionManager?.onModeChange((s) => {\n const newSubtype = this.subtypeByMode.get(s.activeMode) ?? null;\n if (newSubtype !== this.state.annotationMode) {\n this.dispatch(setAnnotationMode(newSubtype));\n this.modeChange$.emit(newSubtype);\n }\n });\n\n this.selection?.onEndSelection(() => {\n if (!this.state.annotationMode) return;\n\n if (\n !(\n this.state.annotationMode === PdfAnnotationSubtype.HIGHLIGHT ||\n this.state.annotationMode === PdfAnnotationSubtype.UNDERLINE ||\n this.state.annotationMode === PdfAnnotationSubtype.STRIKEOUT ||\n this.state.annotationMode === PdfAnnotationSubtype.SQUIGGLY\n )\n ) {\n return;\n }\n\n const formattedSelection = this.selection?.getFormattedSelection();\n if (!formattedSelection) return;\n\n for (const selection of formattedSelection) {\n const rect = selection.rect;\n const segmentRects = selection.segmentRects;\n const type = this.state.annotationMode;\n const color = this.state.toolDefaults[type].color;\n const opacity = this.state.toolDefaults[type].opacity;\n\n this.createAnnotation(selection.pageIndex, {\n type,\n rect,\n segmentRects,\n color,\n opacity,\n pageIndex: selection.pageIndex,\n id: Date.now() + Math.random(),\n });\n }\n\n this.selection?.clear();\n });\n }\n\n private registerTool(subtype: StylableSubtype, defaults: BaseAnnotationDefaults) {\n const modeId = defaults.interaction.mode;\n const interactionMode: InteractionMode = {\n id: modeId,\n scope: 'page',\n exclusive: defaults.interaction.exclusive,\n cursor: defaults.interaction.cursor,\n };\n\n this.interactionManager?.registerMode(interactionMode);\n\n if (defaults.textSelection) {\n this.selection?.enableForMode(modeId);\n }\n this.modeBySubtype.set(subtype, modeId);\n this.subtypeByMode.set(modeId, subtype);\n }\n\n protected buildCapability(): AnnotationCapability {\n return {\n getPageAnnotations: (options: GetPageAnnotationsOptions) => {\n return this.getPageAnnotations(options);\n },\n getSelectedAnnotation: () => {\n return getSelectedAnnotation(this.state);\n },\n selectAnnotation: (pageIndex: number, annotationId: number) => {\n this.selectAnnotation(pageIndex, annotationId);\n },\n deselectAnnotation: () => {\n this.dispatch(deselectAnnotation());\n },\n getAnnotationMode: () => {\n return this.state.annotationMode;\n },\n setAnnotationMode: (subtype: StylableSubtype | null) => {\n if (subtype === this.state.annotationMode) return;\n if (subtype) {\n const mode = this.modeBySubtype.get(subtype);\n if (!mode) throw new Error(`Mode missing for subtype ${subtype}`);\n this.interactionManager?.activate(mode);\n } else {\n this.interactionManager?.activate('default');\n }\n },\n getToolDefaults: (subtype) => {\n const defaults = this.state.toolDefaults[subtype];\n if (!defaults) {\n throw new Error(`No defaults found for subtype: ${subtype}`);\n }\n return defaults;\n },\n setToolDefaults: (subtype, patch) => {\n this.dispatch(updateToolDefaults(subtype, patch));\n },\n getColorPresets: () => [...this.state.colorPresets],\n addColorPreset: (color) => this.dispatch(addColorPreset(color)),\n createAnnotation: (pageIndex: number, annotation: PdfAnnotationObject) =>\n this.createAnnotation(pageIndex, annotation),\n updateAnnotation: (pageIndex: number, localId: number, patch: Partial<PdfAnnotationObject>) =>\n this.updateAnnotation(pageIndex, localId, patch),\n deleteAnnotation: (pageIndex: number, localId: number) =>\n this.deleteAnnotation(pageIndex, localId),\n renderAnnotation: (options: RenderAnnotationOptions) => this.renderAnnotation(options),\n onStateChange: this.state$.on,\n onModeChange: this.modeChange$.on,\n onActiveToolChange: this.activeTool$.on,\n commit: () => this.commit(),\n };\n }\n\n private createActiveTool(\n mode: StylableSubtype | null,\n toolDefaults: ToolDefaultsBySubtype,\n ): ActiveTool {\n if (mode === null) {\n return { mode: null, defaults: null };\n }\n return { mode, defaults: toolDefaults[mode] } as ActiveTool;\n }\n\n private emitActiveTool(state: AnnotationState) {\n const activeTool = this.createActiveTool(state.annotationMode, state.toolDefaults);\n this.activeTool$.emit(activeTool);\n }\n\n override onStoreUpdated(prev: AnnotationState, next: AnnotationState): void {\n this.state$.emit(next);\n if (\n prev.annotationMode !== next.annotationMode ||\n prev.toolDefaults[prev.annotationMode ?? PdfAnnotationSubtype.HIGHLIGHT] !==\n next.toolDefaults[next.annotationMode ?? PdfAnnotationSubtype.HIGHLIGHT]\n ) {\n this.emitActiveTool(next);\n }\n }\n\n private getAllAnnotations(doc: PdfDocumentObject) {\n const task = this.engine.getAllAnnotations(doc);\n task.wait((annotations) => this.dispatch(setAnnotations(annotations)), ignore);\n }\n\n private getPageAnnotations(\n options: GetPageAnnotationsOptions,\n ): Task<PdfAnnotationObject[], PdfErrorReason> {\n const { pageIndex } = options;\n\n const doc = this.coreState.core.document;\n\n if (!doc) {\n return PdfTaskHelper.reject({ code: PdfErrorCode.NotFound, message: 'Document not found' });\n }\n\n const page = doc.pages.find((p) => p.index === pageIndex);\n\n if (!page) {\n return PdfTaskHelper.reject({ code: PdfErrorCode.NotFound, message: 'Page not found' });\n }\n\n return this.engine.getPageAnnotations(doc, page);\n }\n\n private renderAnnotation({\n pageIndex,\n annotation,\n scaleFactor = 1,\n rotation = Rotation.Degree0,\n dpr = 1,\n mode = AppearanceMode.Normal,\n imageType = 'image/webp',\n }: RenderAnnotationOptions) {\n const coreState = this.coreState.core;\n\n if (!coreState.document) {\n throw new Error('document does not open');\n }\n\n const page = coreState.document.pages.find((page) => page.index === pageIndex);\n if (!page) {\n throw new Error('page does not exist');\n }\n\n return this.engine.renderAnnotation(\n coreState.document,\n page,\n annotation,\n scaleFactor,\n rotation,\n dpr,\n mode,\n imageType,\n );\n }\n\n private selectAnnotation(pageIndex: number, annotationId: number) {\n this.dispatch(selectAnnotation(pageIndex, annotationId));\n }\n\n private createAnnotation(pageIndex: number, annotation: PdfAnnotationObject) {\n const localId = annotation.id;\n const execute = () => this.dispatch(createAnnotation(pageIndex, localId, annotation));\n\n if (!this.history) {\n execute();\n if (this.config.autoCommit) this.commit();\n return;\n }\n const command: Command = {\n execute,\n undo: () => {\n this.dispatch(deselectAnnotation());\n this.dispatch(deleteAnnotation(pageIndex, localId));\n },\n };\n this.history.register(command, this.ANNOTATION_HISTORY_TOPIC);\n }\n\n private updateAnnotation(\n pageIndex: number,\n localId: number,\n patch: Partial<PdfAnnotationObject>,\n ) {\n if (!this.history) {\n this.dispatch(patchAnnotation(pageIndex, localId, patch));\n if (this.config.autoCommit !== false) {\n this.commit();\n }\n return;\n }\n const originalObject = this.state.byUid[makeUid(pageIndex, localId)].object;\n const originalPatch = Object.fromEntries(\n Object.keys(patch).map((key) => [key, originalObject[key as keyof PdfAnnotationObject]]),\n );\n const command: Command = {\n execute: () => this.dispatch(patchAnnotation(pageIndex, localId, patch)),\n undo: () => this.dispatch(patchAnnotation(pageIndex, localId, originalPatch)),\n };\n this.history.register(command, this.ANNOTATION_HISTORY_TOPIC);\n }\n\n private deleteAnnotation(pageIndex: number, localId: number) {\n if (!this.history) {\n this.dispatch(deselectAnnotation());\n this.dispatch(deleteAnnotation(pageIndex, localId));\n if (this.config.autoCommit !== false) {\n this.commit();\n }\n return;\n }\n const originalAnnotation = this.state.byUid[makeUid(pageIndex, localId)].object;\n const command: Command = {\n execute: () => {\n this.dispatch(deselectAnnotation());\n this.dispatch(deleteAnnotation(pageIndex, localId));\n },\n undo: () => this.dispatch(createAnnotation(pageIndex, localId, originalAnnotation)),\n };\n this.history.register(command, this.ANNOTATION_HISTORY_TOPIC);\n }\n\n private commit(): Task<boolean, PdfErrorReason> {\n const task = new Task<boolean, PdfErrorReason>();\n\n if (!this.state.hasPendingChanges) return PdfTaskHelper.resolve(true);\n\n const doc = this.coreState.core.document;\n if (!doc)\n return PdfTaskHelper.reject({ code: PdfErrorCode.NotFound, message: 'Document not found' });\n\n const creations: Task<any, PdfErrorReason>[] = [];\n const updates: Task<any, PdfErrorReason>[] = [];\n const deletionsByPage = new Map<number, { ta: TrackedAnnotation; uid: string }[]>();\n const affectedPages = new Set<number>();\n\n // 1. Group all pending changes by operation type\n for (const [uid, ta] of Object.entries(this.state.byUid)) {\n if (ta.commitState === 'synced') continue;\n\n const { pageIndex } = parseUid(uid);\n const page = doc.pages.find((p) => p.index === pageIndex);\n if (!page) continue;\n\n affectedPages.add(pageIndex);\n\n switch (ta.commitState) {\n case 'new':\n const task = this.engine.createPageAnnotation!(doc, page, ta.object);\n task.wait((annoId) => this.dispatch(storePdfId(uid, annoId)), ignore);\n creations.push(task);\n break;\n case 'dirty':\n updates.push(\n this.engine.updatePageAnnotation!(doc, page, { ...ta.object, id: ta.pdfId! }),\n );\n break;\n case 'deleted':\n if (!deletionsByPage.has(pageIndex)) {\n deletionsByPage.set(pageIndex, []);\n }\n deletionsByPage.get(pageIndex)!.push({ ta, uid });\n break;\n }\n }\n\n // 2. Create deletion tasks, sorted by ID descending\n const deletionTasks: Task<any, PdfErrorReason>[] = [];\n for (const [pageIndex, deletions] of deletionsByPage.entries()) {\n const page = doc.pages.find((p) => p.index === pageIndex)!;\n\n deletions.sort((a, b) => (b.ta.pdfId ?? -1) - (a.ta.pdfId ?? -1));\n\n for (const { ta, uid } of deletions) {\n if (ta.pdfId !== undefined) {\n const task = new Task<any, PdfErrorReason>();\n const removeTask = this.engine.removePageAnnotation!(doc, page, {\n ...ta.object,\n id: ta.pdfId!,\n });\n removeTask.wait(() => {\n this.dispatch(purgeAnnotation(uid));\n task.resolve(true);\n }, task.fail);\n deletionTasks.push(task);\n } else {\n this.dispatch(purgeAnnotation(uid));\n }\n }\n }\n\n // 3. Chain the operations: creations/updates -> deletions -> re-sync\n const allWriteTasks = [...creations, ...updates, ...deletionTasks];\n\n Task.allSettled(allWriteTasks).wait(() => {\n // 4. Client-Side Re-indexing\n // After all engine operations are done, tell the reducer to re-index each affected page.\n for (const pageIndex of affectedPages) {\n this.dispatch(reindexPageAnnotations(pageIndex));\n }\n\n // 5. Finalize the commit by updating the commitState of all items.\n this.dispatch(commitPendingChanges());\n task.resolve(true);\n }, task.fail);\n\n return task;\n }\n}\n","import { Action } from '@embedpdf/core';\nimport { PdfAnnotationObject } from '@embedpdf/models';\nimport { StylableSubtype, ToolDefaultsBySubtype } from './types';\n\n/* ─────────── action constants ─────────── */\nexport const SET_ANNOTATIONS = 'ANNOTATION/SET_ANNOTATIONS';\nexport const REINDEX_PAGE_ANNOTATIONS = 'ANNOTATION/REINDEX_PAGE';\nexport const SELECT_ANNOTATION = 'ANNOTATION/SELECT_ANNOTATION';\nexport const DESELECT_ANNOTATION = 'ANNOTATION/DESELECT_ANNOTATION';\nexport const SET_ANNOTATION_MODE = 'ANNOTATION/SET_ANNOTATION_MODE';\nexport const UPDATE_TOOL_DEFAULTS = 'ANNOTATION/UPDATE_TOOL_DEFAULTS';\nexport const ADD_COLOR_PRESET = 'ANNOTATION/ADD_COLOR_PRESET';\nexport const CREATE_ANNOTATION = 'ANNOTATION/CREATE_ANNOTATION';\nexport const PATCH_ANNOTATION = 'ANNOTATION/PATCH_ANNOTATION';\nexport const DELETE_ANNOTATION = 'ANNOTATION/DELETE_ANNOTATION';\nexport const COMMIT_PENDING_CHANGES = 'ANNOTATION/COMMIT';\nexport const STORE_PDF_ID = 'ANNOTATION/STORE_PDF_ID';\nexport const PURGE_ANNOTATION = 'ANNOTATION/PURGE_ANNOTATION';\n\n/* ─────────── action interfaces ─────────── */\nexport interface SetAnnotationsAction extends Action {\n type: typeof SET_ANNOTATIONS;\n payload: Record<number, PdfAnnotationObject[]>;\n}\nexport interface ReindexPageAnnotationsAction extends Action {\n type: typeof REINDEX_PAGE_ANNOTATIONS;\n payload: { pageIndex: number };\n}\nexport interface SelectAnnotationAction extends Action {\n type: typeof SELECT_ANNOTATION;\n payload: { pageIndex: number; localId: number };\n}\nexport interface DeselectAnnotationAction extends Action {\n type: typeof DESELECT_ANNOTATION;\n}\nexport interface SetAnnotationModeAction extends Action {\n type: typeof SET_ANNOTATION_MODE;\n payload: StylableSubtype | null;\n}\n\nexport interface UpdateToolDefaultsAction extends Action {\n type: typeof UPDATE_TOOL_DEFAULTS;\n payload: { subtype: StylableSubtype; patch: Partial<ToolDefaultsBySubtype[StylableSubtype]> };\n}\n\nexport interface AddColorPresetAction extends Action {\n type: typeof ADD_COLOR_PRESET;\n payload: string;\n}\nexport interface CreateAnnotationAction extends Action {\n type: typeof CREATE_ANNOTATION;\n payload: { pageIndex: number; localId: number; annotation: PdfAnnotationObject };\n}\nexport interface PatchAnnotationAction extends Action {\n type: typeof PATCH_ANNOTATION;\n payload: { pageIndex: number; localId: number; patch: Partial<PdfAnnotationObject> };\n}\nexport interface DeleteAnnotationAction extends Action {\n type: typeof DELETE_ANNOTATION;\n payload: { pageIndex: number; localId: number };\n}\nexport interface CommitAction extends Action {\n type: typeof COMMIT_PENDING_CHANGES;\n}\n\nexport interface StorePdfIdAction extends Action {\n type: typeof STORE_PDF_ID;\n payload: { uid: string; pdfId: number };\n}\n\nexport interface PurgeAnnotationAction extends Action {\n type: typeof PURGE_ANNOTATION;\n payload: { uid: string };\n}\n\nexport type AnnotationAction =\n | SetAnnotationsAction\n | ReindexPageAnnotationsAction\n | SelectAnnotationAction\n | DeselectAnnotationAction\n | SetAnnotationModeAction\n | UpdateToolDefaultsAction\n | AddColorPresetAction\n | CreateAnnotationAction\n | PatchAnnotationAction\n | DeleteAnnotationAction\n | CommitAction\n | StorePdfIdAction\n | PurgeAnnotationAction;\n\n/* ─────────── action creators ─────────── */\nexport const setAnnotations = (p: Record<number, PdfAnnotationObject[]>): SetAnnotationsAction => ({\n type: SET_ANNOTATIONS,\n payload: p,\n});\n\nexport const reindexPageAnnotations = (pageIndex: number): ReindexPageAnnotationsAction => ({\n type: REINDEX_PAGE_ANNOTATIONS,\n payload: { pageIndex },\n});\n\nexport const selectAnnotation = (pageIndex: number, localId: number): SelectAnnotationAction => ({\n type: SELECT_ANNOTATION,\n payload: { pageIndex, localId },\n});\n\nexport const deselectAnnotation = (): DeselectAnnotationAction => ({ type: DESELECT_ANNOTATION });\n\nexport const setAnnotationMode = (m: StylableSubtype | null): SetAnnotationModeAction => ({\n type: SET_ANNOTATION_MODE,\n payload: m,\n});\n\nexport const updateToolDefaults = <S extends StylableSubtype>(\n subtype: S,\n patch: Partial<ToolDefaultsBySubtype[S]>,\n): UpdateToolDefaultsAction => ({ type: UPDATE_TOOL_DEFAULTS, payload: { subtype, patch } });\n\nexport const addColorPreset = (c: string): AddColorPresetAction => ({\n type: ADD_COLOR_PRESET,\n payload: c,\n});\n\nexport const createAnnotation = (\n pageIndex: number,\n localId: number,\n annotation: PdfAnnotationObject,\n): CreateAnnotationAction => ({\n type: CREATE_ANNOTATION,\n payload: { pageIndex, localId, annotation },\n});\n\nexport const patchAnnotation = (\n pageIndex: number,\n localId: number,\n patch: Partial<PdfAnnotationObject>,\n): PatchAnnotationAction => ({\n type: PATCH_ANNOTATION,\n payload: { pageIndex, localId, patch },\n});\n\nexport const deleteAnnotation = (pageIndex: number, localId: number): DeleteAnnotationAction => ({\n type: DELETE_ANNOTATION,\n payload: { pageIndex, localId },\n});\n\nexport const commitPendingChanges = (): CommitAction => ({ type: COMMIT_PENDING_CHANGES });\n\nexport const storePdfId = (uid: string, pdfId: number): StorePdfIdAction => ({\n type: STORE_PDF_ID,\n payload: { uid, pdfId },\n});\n\nexport const purgeAnnotation = (uid: string): PurgeAnnotationAction => ({\n type: PURGE_ANNOTATION,\n payload: { uid },\n});\n","/**\n * Creates a stable, document-wide unique ID from a page index and a stable local ID.\n */\nexport const makeUid = (pageIndex: number, localId: number): string => `p${pageIndex}#${localId}`;\n\n/**\n * Parses a UID string back into its constituent page index and stable local ID.\n */\nexport const parseUid = (uid: string): { pageIndex: number; localId: number } => {\n const [pg, rest] = uid.slice(1).split('#');\n return { pageIndex: Number(pg), localId: Number(rest) };\n};\n","import { AnnotationState, SelectedAnnotation } from './types';\nimport { parseUid } from './utils';\n\n/* helper – mirrors the one in reducer */\nconst makeUid = (page: number, id: number) => `p${page}#${id}`;\n\n/* ─────────── public selectors ─────────── */\n\n/** All annotations _objects_ on a single page (order preserved). */\nexport const getAnnotationsByPageIndex = (s: AnnotationState, page: number) =>\n (s.pages[page] ?? []).map((uid) => s.byUid[uid]);\n\n/** Shortcut: every page → list of annotation objects. */\nexport const getAnnotations = (s: AnnotationState) => {\n const out: Record<number, ReturnType<typeof getAnnotationsByPageIndex>> = {};\n for (const p of Object.keys(s.pages).map(Number)) out[p] = getAnnotationsByPageIndex(s, p);\n return out;\n};\n\n/** The full `TrackedAnnotation` for the current selection. */\nexport const getSelectedAnnotation = (s: AnnotationState) =>\n s.selectedUid ? s.byUid[s.selectedUid] : null;\n\nexport const getSelectedAnnotationWithPageIndex = (\n s: AnnotationState,\n): SelectedAnnotation | null => {\n if (!s.selectedUid) return null;\n const { pageIndex, localId } = parseUid(s.selectedUid);\n return { pageIndex, localId, annotation: s.byUid[s.selectedUid].object };\n};\n\nexport const getSelectedAnnotationByPageIndex = (s: AnnotationState, pageIndex: number) => {\n if (!s.selectedUid) return null;\n\n const pageUids = s.pages[pageIndex] ?? [];\n\n // Check if the selected UID is on the requested page\n if (pageUids.includes(s.selectedUid)) {\n return s.byUid[s.selectedUid];\n }\n\n return null;\n};\n\nexport const isInAnnotationMode = (s: AnnotationState) => s.annotationMode !== null;\nexport const getSelectedAnnotationMode = (s: AnnotationState) => s.annotationMode;\n\n/** Check if a given anno on a page is the current selection. */\nexport const isAnnotationSelected = (s: AnnotationState, page: number, id: number) =>\n s.selectedUid === makeUid(page, id);\n","import { Reducer } from '@embedpdf/core';\nimport { PdfAnnotationSubtype } from '@embedpdf/models';\nimport {\n ADD_COLOR_PRESET,\n COMMIT_PENDING_CHANGES,\n CREATE_ANNOTATION,\n DESELECT_ANNOTATION,\n PATCH_ANNOTATION,\n DELETE_ANNOTATION,\n SELECT_ANNOTATION,\n SET_ANNOTATION_MODE,\n SET_ANNOTATIONS,\n UPDATE_TOOL_DEFAULTS,\n AnnotationAction,\n PURGE_ANNOTATION,\n STORE_PDF_ID,\n REINDEX_PAGE_ANNOTATIONS,\n} from './actions';\nimport { AnnotationPluginConfig, AnnotationState, TrackedAnnotation } from './types';\nimport { makeUid } from './utils';\n\n/* ─────────── util helpers ─────────── */\nconst DEFAULT_COLORS = [\n '#E44234',\n '#FF8D00',\n '#FFCD45',\n '#5CC96E',\n '#25D2D1',\n '#597CE2',\n '#C544CE',\n '#7D2E25',\n];\n\n/* helper to immutably replace one annotation (preserving pdfId) */\nconst patchAnno = (\n state: AnnotationState,\n uid: string,\n patch: Partial<TrackedAnnotation['object']>,\n): AnnotationState => {\n const prev = state.byUid[uid];\n if (!prev) return state;\n return {\n ...state,\n byUid: {\n ...state.byUid,\n [uid]: {\n ...prev,\n commitState: prev.commitState === 'synced' ? 'dirty' : prev.commitState,\n object: { ...prev.object, ...patch },\n } as TrackedAnnotation,\n },\n hasPendingChanges: true,\n };\n};\n\n/* ─────────── initialState ─────────── */\nexport const initialState = (cfg: AnnotationPluginConfig): AnnotationState => ({\n pages: {},\n byUid: {},\n selectedUid: null,\n annotationMode: null,\n\n toolDefaults: {\n [PdfAnnotationSubtype.HIGHLIGHT]: {\n name: 'Highlight',\n color: '#FFCD45',\n opacity: 1,\n interaction: { mode: 'highlight', exclusive: false },\n textSelection: true,\n },\n [PdfAnnotationSubtype.UNDERLINE]: {\n name: 'Underline',\n color: '#E44234',\n opacity: 1,\n interaction: { mode: 'underline', exclusive: false },\n textSelection: true,\n },\n [PdfAnnotationSubtype.STRIKEOUT]: {\n name: 'Strikeout',\n color: '#E44234',\n opacity: 1,\n interaction: { mode: 'strikeout', exclusive: false },\n textSelection: true,\n },\n [PdfAnnotationSubtype.SQUIGGLY]: {\n name: 'Squiggly',\n color: '#E44234',\n opacity: 1,\n interaction: { mode: 'squiggly', exclusive: false },\n textSelection: true,\n },\n [PdfAnnotationSubtype.INK]: {\n name: 'Ink',\n color: '#E44234',\n opacity: 1,\n strokeWidth: 11,\n interaction: { mode: 'ink', exclusive: true, cursor: 'crosshair' },\n textSelection: false,\n },\n ...cfg.toolDefaults,\n },\n colorPresets: cfg.colorPresets ?? DEFAULT_COLORS,\n hasPendingChanges: false,\n});\n\n/* ─────────── reducer ─────────── */\nexport const reducer: Reducer<AnnotationState, AnnotationAction> = (state, action) => {\n switch (action.type) {\n /* ───── bulk load from engine ───── */\n case SET_ANNOTATIONS: {\n const newPages = { ...state.pages };\n const newByUid = { ...state.byUid };\n for (const [pgStr, list] of Object.entries(action.payload)) {\n const pageIndex = Number(pgStr);\n const oldUidsOnPage = state.pages[pageIndex] || [];\n for (const uid of oldUidsOnPage) {\n delete newByUid[uid];\n }\n const newUidsOnPage = list.map((a, index) => {\n const localId = Date.now() + Math.random() + index;\n const uid = makeUid(pageIndex, localId);\n newByUid[uid] = { localId, pdfId: a.id, commitState: 'synced', object: a };\n return uid;\n });\n newPages[pageIndex] = newUidsOnPage;\n }\n return { ...state, pages: newPages, byUid: newByUid };\n }\n\n /* ───── GUI bits ───── */\n case SET_ANNOTATION_MODE:\n return { ...state, annotationMode: action.payload };\n case SELECT_ANNOTATION:\n return {\n ...state,\n selectedUid: makeUid(action.payload.pageIndex, action.payload.localId),\n };\n case DESELECT_ANNOTATION:\n return { ...state, selectedUid: null };\n\n case ADD_COLOR_PRESET:\n return state.colorPresets.includes(action.payload)\n ? state\n : { ...state, colorPresets: [...state.colorPresets, action.payload] };\n\n case UPDATE_TOOL_DEFAULTS: {\n const { subtype, patch } = action.payload;\n return {\n ...state,\n toolDefaults: {\n ...state.toolDefaults,\n [subtype]: { ...state.toolDefaults[subtype], ...patch },\n },\n };\n }\n\n /* ───── create ───── */\n case CREATE_ANNOTATION: {\n const { pageIndex, localId, annotation } = action.payload;\n const uid = makeUid(pageIndex, localId);\n\n return {\n ...state,\n pages: { ...state.pages, [pageIndex]: [...(state.pages[pageIndex] ?? []), uid] },\n byUid: {\n ...state.byUid,\n [uid]: { localId, pdfId: undefined, commitState: 'new', object: annotation },\n },\n hasPendingChanges: true,\n };\n }\n\n /* ───── delete ───── */\n case DELETE_ANNOTATION: {\n const { pageIndex, localId } = action.payload;\n const uid = makeUid(pageIndex, localId);\n if (!state.byUid[uid]) return state;\n\n /* keep the object but mark it as deleted */\n return {\n ...state,\n pages: {\n ...state.pages,\n [pageIndex]: (state.pages[pageIndex] ?? []).filter((u) => u !== uid),\n },\n byUid: {\n ...state.byUid,\n [uid]: { ...state.byUid[uid], commitState: 'deleted' },\n },\n hasPendingChanges: true,\n };\n }\n\n /* ───── field edits ───── */\n case PATCH_ANNOTATION: {\n const uid = makeUid(action.payload.pageIndex, action.payload.localId);\n return patchAnno(state, uid, action.payload.patch);\n }\n\n /* ───── commit bookkeeping ───── */\n case COMMIT_PENDING_CHANGES: {\n const cleaned: AnnotationState['byUid'] = {};\n for (const [uid, ta] of Object.entries(state.byUid)) {\n cleaned[uid] = {\n ...ta,\n commitState:\n ta.commitState === 'dirty' || ta.commitState === 'new' ? 'synced' : ta.commitState,\n };\n }\n return { ...state, byUid: cleaned, hasPendingChanges: false };\n }\n\n case REINDEX_PAGE_ANNOTATIONS: {\n const { pageIndex } = action.payload;\n const newByUid = { ...state.byUid };\n\n const uidsOnPage = state.pages[pageIndex] || [];\n const annosOnPage = uidsOnPage\n .map((uid) => state.byUid[uid])\n .filter((ta) => ta && ta.commitState !== 'deleted'); // Filter out annotations pending deletion\n\n // CORRECTED: Sort by the existing pdfId to maintain relative order.\n annosOnPage.sort((a, b) => (a.pdfId ?? Infinity) - (b.pdfId ?? Infinity));\n\n // Update the pdfId for each annotation based on its new sorted index\n annosOnPage.forEach((ta, newPdfId) => {\n const uid = makeUid(pageIndex, ta.localId);\n newByUid[uid] = { ...newByUid[uid], pdfId: newPdfId };\n });\n\n return { ...state, byUid: newByUid };\n }\n\n case STORE_PDF_ID: {\n const { uid, pdfId } = action.payload;\n\n const ta = state.byUid[uid];\n if (!ta) return state;\n return {\n ...state,\n byUid: {\n ...state.byUid,\n [uid]: { ...ta, pdfId, commitState: 'synced' },\n },\n };\n }\n\n case PURGE_ANNOTATION: {\n const { uid } = action.payload;\n const { [uid]: _gone, ...rest } = state.byUid;\n return { ...state, byUid: rest };\n }\n\n default:\n return state;\n }\n};\n","import { PluginPackage } from '@embedpdf/core';\nimport { manifest, ANNOTATION_PLUGIN_ID } from './manifest';\nimport { AnnotationPluginConfig, AnnotationState } from './types';\nimport { AnnotationPlugin } from './annotation-plugin';\nimport { initialState, reducer } from './reducer';\nimport { AnnotationAction } from './actions';\n\nexport const AnnotationPluginPackage: PluginPackage<\n AnnotationPlugin,\n AnnotationPluginConfig,\n AnnotationState,\n AnnotationAction\n> = {\n manifest,\n create: (registry, engine, config) =>\n new AnnotationPlugin(ANNOTATION_PLUGIN_ID, registry, engine, config),\n reducer,\n initialState: (_, config) => initialState(config),\n};\n\nexport * from './annotation-plugin';\nexport * from './types';\nexport * from './manifest';\nexport * from './selectors';\n"],"mappings":";AAGO,IAAM,uBAAuB;AAE7B,IAAM,WAAmD;AAAA,EAC9D,IAAI;AAAA,EACJ,MAAM;AAAA,EACN,SAAS;AAAA,EACT,UAAU,CAAC,YAAY;AAAA,EACvB,UAAU,CAAC,uBAAuB,WAAW;AAAA,EAC7C,UAAU,CAAC,SAAS;AAAA,EACpB,eAAe;AAAA,IACb,SAAS;AAAA,IACT,YAAY;AAAA,EACd;AACF;;;AChBA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EAEA;AAAA,OACK;AACP;AAAA,EACE;AAAA,EAKA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EAEA;AAAA,EACA;AAAA,OACK;;;ACfA,IAAM,kBAAkB;AACxB,IAAM,2BAA2B;AACjC,IAAM,oBAAoB;AAC1B,IAAM,sBAAsB;AAC5B,IAAM,sBAAsB;AAC5B,IAAM,uBAAuB;AAC7B,IAAM,mBAAmB;AACzB,IAAM,oBAAoB;AAC1B,IAAM,mBAAmB;AACzB,IAAM,oBAAoB;AAC1B,IAAM,yBAAyB;AAC/B,IAAM,eAAe;AACrB,IAAM,mBAAmB;AA0EzB,IAAM,iBAAiB,CAAC,OAAoE;AAAA,EACjG,MAAM;AAAA,EACN,SAAS;AACX;AAEO,IAAM,yBAAyB,CAAC,eAAqD;AAAA,EAC1F,MAAM;AAAA,EACN,SAAS,EAAE,UAAU;AACvB;AAEO,IAAM,mBAAmB,CAAC,WAAmB,aAA6C;AAAA,EAC/F,MAAM;AAAA,EACN,SAAS,EAAE,WAAW,QAAQ;AAChC;AAEO,IAAM,qBAAqB,OAAiC,EAAE,MAAM,oBAAoB;AAExF,IAAM,oBAAoB,CAAC,OA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C,UAAU,QAAQ,WACzB,IAAI,iBAAiB,sBAAsB,UAAU,QAAQ,MAAM;AAAA,EACrE;AAAA,EACA,cAAc,CAAC,GAAG,WAAW,aAAa,MAAM;AAClD;","names":["makeUid","page","task","PdfAnnotationSubtype","PdfAnnotationSubtype"]}
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../src/lib/manifest.ts","../src/lib/actions.ts","../src/lib/utils.ts","../src/lib/variant-key.ts","../src/lib/selectors.ts","../src/lib/patching/line-ending-handlers.ts","../src/lib/patching/patch-utils.ts","../src/lib/patching/derived-rect.ts","../src/lib/patching/line-endings.ts","../src/lib/annotation-plugin.ts","../src/lib/reducer.ts","../src/lib/helpers.ts","../src/lib/index.ts"],"sourcesContent":["import { PluginManifest } from '@embedpdf/core';\nimport { AnnotationPluginConfig } from './types';\n\nexport const ANNOTATION_PLUGIN_ID = 'annotation';\n\nexport const manifest: PluginManifest<AnnotationPluginConfig> = {\n id: ANNOTATION_PLUGIN_ID,\n name: 'Annotation Plugin',\n version: '1.0.0',\n provides: ['annotation'],\n requires: ['interaction-manager', 'selection'],\n optional: ['history'],\n defaultConfig: {\n enabled: true,\n autoCommit: true,\n },\n};\n","import { Action } from '@embedpdf/core';\nimport { PdfAnnotationObject } from '@embedpdf/models';\nimport { AnnotationDefaults, ToolDefaultsByMode } from './types';\n\n/* ─────────── action constants ─────────── */\nexport const SET_ANNOTATIONS = 'ANNOTATION/SET_ANNOTATIONS';\nexport const REINDEX_PAGE_ANNOTATIONS = 'ANNOTATION/REINDEX_PAGE';\nexport const SELECT_ANNOTATION = 'ANNOTATION/SELECT_ANNOTATION';\nexport const DESELECT_ANNOTATION = 'ANNOTATION/DESELECT_ANNOTATION';\nexport const UPDATE_TOOL_DEFAULTS = 'ANNOTATION/UPDATE_TOOL_DEFAULTS';\nexport const ADD_COLOR_PRESET = 'ANNOTATION/ADD_COLOR_PRESET';\nexport const CREATE_ANNOTATION = 'ANNOTATION/CREATE_ANNOTATION';\nexport const PATCH_ANNOTATION = 'ANNOTATION/PATCH_ANNOTATION';\nexport const DELETE_ANNOTATION = 'ANNOTATION/DELETE_ANNOTATION';\nexport const COMMIT_PENDING_CHANGES = 'ANNOTATION/COMMIT';\nexport const STORE_PDF_ID = 'ANNOTATION/STORE_PDF_ID';\nexport const PURGE_ANNOTATION = 'ANNOTATION/PURGE_ANNOTATION';\nexport const SET_ACTIVE_VARIANT = 'ANNOTATION/SET_ACTIVE_VARIANT';\n\n/* ─────────── action interfaces ─────────── */\nexport interface SetAnnotationsAction extends Action {\n type: typeof SET_ANNOTATIONS;\n payload: Record<number, PdfAnnotationObject[]>;\n}\nexport interface ReindexPageAnnotationsAction extends Action {\n type: typeof REINDEX_PAGE_ANNOTATIONS;\n payload: { pageIndex: number };\n}\nexport interface SelectAnnotationAction extends Action {\n type: typeof SELECT_ANNOTATION;\n payload: { pageIndex: number; localId: number };\n}\nexport interface DeselectAnnotationAction extends Action {\n type: typeof DESELECT_ANNOTATION;\n}\n\nexport interface UpdateToolDefaultsAction extends Action {\n type: typeof UPDATE_TOOL_DEFAULTS;\n payload: { variantKey: string; patch: Partial<AnnotationDefaults> };\n}\n\nexport interface AddColorPresetAction extends Action {\n type: typeof ADD_COLOR_PRESET;\n payload: string;\n}\nexport interface CreateAnnotationAction extends Action {\n type: typeof CREATE_ANNOTATION;\n payload: { pageIndex: number; localId: number; annotation: PdfAnnotationObject };\n}\nexport interface PatchAnnotationAction extends Action {\n type: typeof PATCH_ANNOTATION;\n payload: { pageIndex: number; localId: number; patch: Partial<PdfAnnotationObject> };\n}\nexport interface DeleteAnnotationAction extends Action {\n type: typeof DELETE_ANNOTATION;\n payload: { pageIndex: number; localId: number };\n}\nexport interface CommitAction extends Action {\n type: typeof COMMIT_PENDING_CHANGES;\n}\n\nexport interface StorePdfIdAction extends Action {\n type: typeof STORE_PDF_ID;\n payload: { uid: string; pdfId: number };\n}\n\nexport interface PurgeAnnotationAction extends Action {\n type: typeof PURGE_ANNOTATION;\n payload: { uid: string };\n}\n\nexport interface SetActiveVariantAction extends Action {\n type: typeof SET_ACTIVE_VARIANT;\n payload: string | null;\n}\n\nexport type AnnotationAction =\n | SetAnnotationsAction\n | ReindexPageAnnotationsAction\n | SelectAnnotationAction\n | DeselectAnnotationAction\n | UpdateToolDefaultsAction\n | AddColorPresetAction\n | CreateAnnotationAction\n | PatchAnnotationAction\n | DeleteAnnotationAction\n | CommitAction\n | StorePdfIdAction\n | PurgeAnnotationAction\n | SetActiveVariantAction;\n\n/* ─────────── action creators ─────────── */\nexport const setAnnotations = (p: Record<number, PdfAnnotationObject[]>): SetAnnotationsAction => ({\n type: SET_ANNOTATIONS,\n payload: p,\n});\n\nexport const reindexPageAnnotations = (pageIndex: number): ReindexPageAnnotationsAction => ({\n type: REINDEX_PAGE_ANNOTATIONS,\n payload: { pageIndex },\n});\n\nexport const selectAnnotation = (pageIndex: number, localId: number): SelectAnnotationAction => ({\n type: SELECT_ANNOTATION,\n payload: { pageIndex, localId },\n});\n\nexport const deselectAnnotation = (): DeselectAnnotationAction => ({ type: DESELECT_ANNOTATION });\n\nexport const updateToolDefaults = (\n variantKey: string,\n patch: Partial<AnnotationDefaults>,\n): UpdateToolDefaultsAction => ({ type: UPDATE_TOOL_DEFAULTS, payload: { variantKey, patch } });\n\nexport const addColorPreset = (c: string): AddColorPresetAction => ({\n type: ADD_COLOR_PRESET,\n payload: c,\n});\n\nexport const createAnnotation = (\n pageIndex: number,\n localId: number,\n annotation: PdfAnnotationObject,\n): CreateAnnotationAction => ({\n type: CREATE_ANNOTATION,\n payload: { pageIndex, localId, annotation },\n});\n\nexport const patchAnnotation = (\n pageIndex: number,\n localId: number,\n patch: Partial<PdfAnnotationObject>,\n): PatchAnnotationAction => ({\n type: PATCH_ANNOTATION,\n payload: { pageIndex, localId, patch },\n});\n\nexport const deleteAnnotation = (pageIndex: number, localId: number): DeleteAnnotationAction => ({\n type: DELETE_ANNOTATION,\n payload: { pageIndex, localId },\n});\n\nexport const commitPendingChanges = (): CommitAction => ({ type: COMMIT_PENDING_CHANGES });\n\nexport const storePdfId = (uid: string, pdfId: number): StorePdfIdAction => ({\n type: STORE_PDF_ID,\n payload: { uid, pdfId },\n});\n\nexport const purgeAnnotation = (uid: string): PurgeAnnotationAction => ({\n type: PURGE_ANNOTATION,\n payload: { uid },\n});\n\nexport const setActiveVariant = (k: string | null): SetActiveVariantAction => ({\n type: SET_ACTIVE_VARIANT,\n payload: k,\n});\n","/**\n * Creates a stable, document-wide unique ID from a page index and a stable local ID.\n */\nexport const makeUid = (pageIndex: number, localId: number): string => `p${pageIndex}#${localId}`;\n\n/**\n * Parses a UID string back into its constituent page index and stable local ID.\n */\nexport const parseUid = (uid: string): { pageIndex: number; localId: number } => {\n const [pg, rest] = uid.slice(1).split('#');\n return { pageIndex: Number(pg), localId: Number(rest) };\n};\n","import { PdfAnnotationSubtype, PdfAnnotationObject } from '@embedpdf/models';\n\nexport type VariantKey = string;\n\nexport const makeVariantKey = (\n subtype: PdfAnnotationSubtype,\n intent?: string | null | undefined,\n): VariantKey => (intent ? `${subtype}#${intent}` : `${subtype}`);\n\nexport const parseVariantKey = (\n key: VariantKey,\n): { subtype: PdfAnnotationSubtype; intent?: string } => {\n const [subStr, intent] = key.split('#');\n return { subtype: Number(subStr) as PdfAnnotationSubtype, intent };\n};\n\nexport const variantKeyFromAnnotation = (a: PdfAnnotationObject): VariantKey =>\n makeVariantKey(a.type, a.intent);\n","import { AnnotationDefaults, AnnotationState, SelectedAnnotation } from './types';\nimport { parseUid } from './utils';\nimport { makeVariantKey } from './variant-key';\n\n/* helper – mirrors the one in reducer */\nconst makeUid = (page: number, id: number) => `p${page}#${id}`;\n\n/* ─────────── public selectors ─────────── */\n\n/** All annotations _objects_ on a single page (order preserved). */\nexport const getAnnotationsByPageIndex = (s: AnnotationState, page: number) =>\n (s.pages[page] ?? []).map((uid) => s.byUid[uid]);\n\n/** Shortcut: every page → list of annotation objects. */\nexport const getAnnotations = (s: AnnotationState) => {\n const out: Record<number, ReturnType<typeof getAnnotationsByPageIndex>> = {};\n for (const p of Object.keys(s.pages).map(Number)) out[p] = getAnnotationsByPageIndex(s, p);\n return out;\n};\n\n/** The full `TrackedAnnotation` for the current selection. */\nexport const getSelectedAnnotation = (s: AnnotationState) =>\n s.selectedUid ? s.byUid[s.selectedUid] : null;\n\nexport const getSelectedAnnotationWithPageIndex = (\n s: AnnotationState,\n): SelectedAnnotation | null => {\n if (!s.selectedUid) return null;\n const { pageIndex, localId } = parseUid(s.selectedUid);\n return { pageIndex, localId, annotation: s.byUid[s.selectedUid].object };\n};\n\nexport const getSelectedAnnotationByPageIndex = (s: AnnotationState, pageIndex: number) => {\n if (!s.selectedUid) return null;\n\n const pageUids = s.pages[pageIndex] ?? [];\n\n // Check if the selected UID is on the requested page\n if (pageUids.includes(s.selectedUid)) {\n return s.byUid[s.selectedUid];\n }\n\n return null;\n};\n\nexport const isInAnnotationVariant = (s: AnnotationState) => s.activeVariant !== null;\nexport const getSelectedAnnotationVariant = (s: AnnotationState) => s.activeVariant;\n\n/** Check if a given anno on a page is the current selection. */\nexport const isAnnotationSelected = (s: AnnotationState, page: number, id: number) =>\n s.selectedUid === makeUid(page, id);\n\n/**\n * Return the tool-defaults for a given subtype and (optionally) intent.\n * If the exact variant (subtype + intent) is not present, it gracefully\n * falls back to the plain subtype variant.\n *\n * The return type is inferred so that you always get the concrete default\n * interface for the supplied subtype (e.g. `InkDefaults` for `INK`,\n * `CircleDefaults` for `CIRCLE`, …).\n */\nexport function getToolDefaultsBySubtypeAndIntent<\n S extends AnnotationState,\n TSub extends AnnotationDefaults['subtype'],\n>(state: S, subtype: TSub, intent?: string | null): Extract<AnnotationDefaults, { subtype: TSub }> {\n // Build keys\n const variantKey = makeVariantKey(subtype, intent ?? undefined);\n const fallbackKey = makeVariantKey(subtype);\n\n // Try exact match first, otherwise fall back to plain subtype\n const defaults = state.toolDefaults[variantKey] ?? state.toolDefaults[fallbackKey];\n\n if (!defaults) {\n throw new Error(\n `No tool defaults found for subtype ${subtype}${intent ? ` and intent ${intent}` : ''}`,\n );\n }\n\n // Cast is safe because we narrow the union by subtype\n return defaults as Extract<AnnotationDefaults, { subtype: TSub }>;\n}\n","import { PdfAnnotationLineEnding, Position } from '@embedpdf/models';\n\n/**\n * A handler that encapsulates all logic for a specific line ending type,\n * including SVG path generation, geometric vertex calculation, and rotation logic.\n * This is the single source of truth for each ending.\n */\nexport interface LineEndingHandler {\n /** Returns the SVG `d` attribute string for rendering. */\n getSvgPath: (strokeWidth: number) => string;\n /** Returns the vertices used for calculating the geometric bounding box. */\n getLocalPoints: (strokeWidth: number) => Position[];\n /** Returns the final rotation angle in radians based on the line segment's angle. */\n getRotation: (segmentAngle: number) => number;\n /** True if the shape should be filled, false if only stroked. */\n filled: boolean;\n}\n\n/**\n * Factory to create handlers for arrow-like shapes.\n * @param isClosed - If true, creates a closed (filled) arrowhead.\n */\nfunction createArrowHandler(isClosed: boolean): LineEndingHandler {\n const calculateGeometry = (sw: number) => {\n const len = sw * 9;\n const a = Math.PI / 6; // 30 degrees\n return {\n x: -len * Math.cos(a),\n y: len * Math.sin(a),\n };\n };\n\n return {\n getSvgPath: (sw) => {\n const { x, y } = calculateGeometry(sw);\n return isClosed ? `M 0 0 L ${x} ${y} L ${x} ${-y} Z` : `M ${x} ${y} L 0 0 L ${x} ${-y}`;\n },\n getLocalPoints: (sw) => {\n const { x, y } = calculateGeometry(sw);\n return [\n { x: 0, y: 0 },\n { x, y },\n { x, y: -y },\n ];\n },\n getRotation: (segmentAngle) => segmentAngle,\n filled: isClosed,\n };\n}\n\n/**\n * Factory to create handlers for simple line-based shapes like Butt and Slash.\n * @param lengthFactor - Multiplier for strokeWidth to determine length.\n * @param rotationFn - Function to determine rotation from segment angle.\n */\nfunction createLineHandler(\n lengthFactor: number,\n rotationFn: (angle: number) => number,\n): LineEndingHandler {\n const getHalfLength = (sw: number) => (sw * lengthFactor) / 2;\n\n return {\n getSvgPath: (sw) => {\n const l = getHalfLength(sw);\n return `M ${-l} 0 L ${l} 0`;\n },\n getLocalPoints: (sw) => {\n const l = getHalfLength(sw);\n return [\n { x: -l, y: 0 },\n { x: l, y: 0 },\n ];\n },\n getRotation: rotationFn,\n filled: false,\n };\n}\n\nconst OpenArrowHandler = createArrowHandler(false);\nconst ClosedArrowHandler = createArrowHandler(true);\n\n/**\n * A map containing the authoritative handler for each line ending type.\n */\nexport const LINE_ENDING_HANDLERS: Partial<Record<PdfAnnotationLineEnding, LineEndingHandler>> = {\n [PdfAnnotationLineEnding.OpenArrow]: OpenArrowHandler,\n [PdfAnnotationLineEnding.ClosedArrow]: ClosedArrowHandler,\n [PdfAnnotationLineEnding.ROpenArrow]: {\n ...OpenArrowHandler,\n getRotation: (segmentAngle) => segmentAngle + Math.PI,\n },\n [PdfAnnotationLineEnding.RClosedArrow]: {\n ...ClosedArrowHandler,\n getRotation: (segmentAngle) => segmentAngle + Math.PI,\n },\n [PdfAnnotationLineEnding.Circle]: {\n getSvgPath: (sw) => {\n const r = (sw * 5) / 2;\n return `M ${r} 0 A ${r} ${r} 0 1 1 ${-r} 0 A ${r} ${r} 0 1 1 ${r} 0`;\n },\n getLocalPoints: (sw) => {\n const r = (sw * 5) / 2;\n return [\n { x: -r, y: -r },\n { x: r, y: r },\n ];\n },\n getRotation: () => 0,\n filled: true,\n },\n [PdfAnnotationLineEnding.Square]: {\n getSvgPath: (sw) => {\n const h = (sw * 6) / 2;\n return `M ${-h} ${-h} L ${h} ${-h} L ${h} ${h} L ${-h} ${h} Z`;\n },\n getLocalPoints: (sw) => {\n const h = (sw * 6) / 2;\n return [\n { x: -h, y: -h }, // TL\n { x: h, y: -h }, // TR\n { x: h, y: h }, // BR\n { x: -h, y: h }, // BL\n ];\n },\n getRotation: (segmentAngle) => segmentAngle, // keep your new orientation\n filled: true,\n },\n [PdfAnnotationLineEnding.Diamond]: {\n getSvgPath: (sw) => {\n const h = (sw * 6) / 2;\n return `M 0 ${-h} L ${h} 0 L 0 ${h} L ${-h} 0 Z`;\n },\n getLocalPoints: (sw) => {\n const h = (sw * 6) / 2;\n return [\n { x: 0, y: -h },\n { x: h, y: 0 },\n { x: 0, y: h },\n { x: -h, y: 0 },\n ];\n },\n getRotation: (segmentAngle) => segmentAngle,\n filled: true,\n },\n [PdfAnnotationLineEnding.Butt]: createLineHandler(6, (angle) => angle + Math.PI / 2),\n [PdfAnnotationLineEnding.Slash]: createLineHandler(18, (angle) => angle + Math.PI / 1.5),\n};\n","import {\n Rect,\n Position,\n LineEndings,\n PdfAnnotationLineEnding,\n rotateAndTranslatePoint,\n rectFromPoints,\n expandRect,\n} from '@embedpdf/models';\nimport { LINE_ENDING_HANDLERS } from './line-ending-handlers';\n\nconst EXTRA_PADDING = 1.2;\n\n/**\n * Computes the exact bounding box for a line or polyline, including its endings and stroke width.\n * This function uses the central `LINE_ENDING_HANDLERS` to ensure calculations are\n * perfectly in sync with the rendering logic.\n */\nexport function lineRectWithEndings(\n vertices: Position[],\n strokeWidth: number,\n endings: LineEndings | undefined,\n): Rect {\n if (!vertices || vertices.length === 0) {\n return { origin: { x: 0, y: 0 }, size: { width: 0, height: 0 } };\n }\n\n const allPoints: Position[] = [...vertices];\n const toAngle = (a: Position, b: Position) => Math.atan2(b.y - a.y, b.x - a.x);\n\n const processEnding = (\n endingType: PdfAnnotationLineEnding | undefined,\n tipPos: Position,\n segmentAngle: number,\n ) => {\n if (!endingType) return;\n\n const handler = LINE_ENDING_HANDLERS[endingType];\n if (!handler) return;\n\n const localPts = handler.getLocalPoints(strokeWidth);\n const rotationAngle = handler.getRotation(segmentAngle);\n\n const transformedPts = localPts.map((p) => rotateAndTranslatePoint(p, rotationAngle, tipPos));\n allPoints.push(...transformedPts);\n };\n\n if (vertices.length >= 2) {\n // Process start ending. Angle points from the second vertex INTO the first.\n const startAngle = toAngle(vertices[1], vertices[0]);\n processEnding(endings?.start, vertices[0], startAngle);\n\n // Process end ending. Angle points from the second-to-last vertex INTO the last.\n const lastIdx = vertices.length - 1;\n const endAngle = toAngle(vertices[lastIdx - 1], vertices[lastIdx]);\n processEnding(endings?.end, vertices[lastIdx], endAngle);\n }\n\n if (allPoints.length <= 1) {\n const point = vertices[0] || { x: 0, y: 0 };\n const pad = strokeWidth;\n return {\n origin: { x: point.x - pad, y: point.y - pad },\n size: { width: pad * 2, height: pad * 2 },\n };\n }\n\n const baseRect = rectFromPoints(allPoints);\n const pad = strokeWidth / 2 + EXTRA_PADDING * strokeWidth;\n return expandRect(baseRect, pad);\n}\n","import {\n PdfAnnotationSubtype,\n PdfAnnotationObject,\n Rect,\n Position,\n expandRect,\n rectFromPoints,\n} from '@embedpdf/models';\n\nimport { lineRectWithEndings } from './patch-utils';\n\n/* ---------- helpers ---------- */\n\n/** Bounding box for arbitrary vertices (+ stroke). */\nconst vertsRect = (verts: Position[], sw: number): Rect =>\n expandRect(rectFromPoints(verts), sw / 2);\n\n/* ---------- dispatcher ---------- */\n\nexport function deriveRect(a: PdfAnnotationObject): Rect {\n switch (a.type) {\n /* mark‑ups already carry their real rect */\n case PdfAnnotationSubtype.HIGHLIGHT:\n case PdfAnnotationSubtype.UNDERLINE:\n case PdfAnnotationSubtype.STRIKEOUT:\n case PdfAnnotationSubtype.SQUIGGLY:\n case PdfAnnotationSubtype.SQUARE:\n case PdfAnnotationSubtype.CIRCLE:\n return a.rect;\n\n /* ink */\n case PdfAnnotationSubtype.INK: {\n const pts = a.inkList.flatMap((s) => s.points);\n return vertsRect(pts, a.strokeWidth);\n }\n\n /* one‑segment */\n case PdfAnnotationSubtype.LINE:\n return lineRectWithEndings(\n [a.linePoints.start, a.linePoints.end],\n a.strokeWidth,\n a.lineEndings,\n );\n\n /* multi‑segment */\n case PdfAnnotationSubtype.POLYLINE:\n return lineRectWithEndings(a.vertices, a.strokeWidth, a.lineEndings);\n\n case PdfAnnotationSubtype.POLYGON:\n return vertsRect(a.vertices, a.strokeWidth);\n\n default:\n return a.rect; // fallback – unchanged\n }\n}\n","import { PdfAnnotationLineEnding } from '@embedpdf/models';\nimport { LINE_ENDING_HANDLERS } from './line-ending-handlers';\n\nexport interface SvgEnding {\n d: string;\n transform: string;\n filled: boolean;\n}\n\n/**\n * Factory that returns SVG path data and transform attributes for a given line ending.\n * It uses a central handler for each ending type to ensure consistency.\n */\nexport function createEnding(\n ending: PdfAnnotationLineEnding | undefined,\n strokeWidth: number,\n rad: number, // direction angle in radians of the line segment\n px: number, // x-coordinate of the line's endpoint\n py: number, // y-coordinate of the line's endpoint\n): SvgEnding | null {\n if (!ending) return null;\n\n const handler = LINE_ENDING_HANDLERS[ending];\n if (!handler) return null;\n\n const toDeg = (r: number) => (r * 180) / Math.PI;\n const rotationAngle = handler.getRotation(rad);\n\n return {\n d: handler.getSvgPath(strokeWidth),\n transform: `translate(${px} ${py}) rotate(${toDeg(rotationAngle)})`,\n filled: handler.filled,\n };\n}\n","import {\n BasePlugin,\n createBehaviorEmitter,\n enumEntries,\n PluginRegistry,\n SET_DOCUMENT,\n} from '@embedpdf/core';\nimport {\n ignore,\n PdfAnnotationObject,\n PdfDocumentObject,\n PdfEngine,\n PdfErrorReason,\n Task,\n PdfAnnotationSubtype,\n PdfTaskHelper,\n PdfErrorCode,\n PdfTask,\n Rotation,\n AppearanceMode,\n PdfBlendMode,\n} from '@embedpdf/models';\nimport {\n ActiveTool,\n AnnotationCapability,\n AnnotationPluginConfig,\n AnnotationState,\n BaseAnnotationDefaults,\n GetPageAnnotationsOptions,\n RenderAnnotationOptions,\n TextMarkupSubtype,\n ToolDefaultsByMode,\n TrackedAnnotation,\n} from './types';\nimport {\n setAnnotations,\n selectAnnotation,\n deselectAnnotation,\n AnnotationAction,\n updateToolDefaults,\n addColorPreset,\n createAnnotation,\n patchAnnotation,\n deleteAnnotation,\n commitPendingChanges,\n storePdfId,\n purgeAnnotation,\n reindexPageAnnotations,\n setActiveVariant,\n} from './actions';\nimport {\n InteractionManagerCapability,\n InteractionManagerPlugin,\n InteractionMode,\n} from '@embedpdf/plugin-interaction-manager';\nimport { SelectionPlugin, SelectionCapability } from '@embedpdf/plugin-selection';\nimport { HistoryPlugin, HistoryCapability, Command } from '@embedpdf/plugin-history';\nimport { getSelectedAnnotation, getToolDefaultsBySubtypeAndIntent } from './selectors';\nimport { makeUid, parseUid } from './utils';\nimport { makeVariantKey, parseVariantKey } from './variant-key';\nimport { deriveRect } from './patching';\n\nexport class AnnotationPlugin extends BasePlugin<\n AnnotationPluginConfig,\n AnnotationCapability,\n AnnotationState,\n AnnotationAction\n> {\n static readonly id = 'annotation' as const;\n\n private readonly ANNOTATION_HISTORY_TOPIC = 'annotations';\n\n private readonly config: AnnotationPluginConfig;\n\n private engine: PdfEngine;\n private readonly state$ = createBehaviorEmitter<AnnotationState>();\n private readonly interactionManager: InteractionManagerCapability | null;\n private readonly selection: SelectionCapability | null;\n private readonly history: HistoryCapability | null;\n\n private readonly modeByVariant = new Map<string, string>();\n private readonly variantByMode = new Map<string, string>();\n\n private readonly activeVariantChange$ = createBehaviorEmitter<string | null>();\n private readonly activeTool$ = createBehaviorEmitter<ActiveTool>({\n variantKey: null,\n defaults: null,\n });\n\n constructor(\n id: string,\n registry: PluginRegistry,\n engine: PdfEngine,\n config: AnnotationPluginConfig,\n ) {\n super(id, registry);\n this.engine = engine;\n this.config = config;\n\n const selection = registry.getPlugin<SelectionPlugin>('selection');\n this.selection = selection?.provides() ?? null;\n\n const history = registry.getPlugin<HistoryPlugin>('history');\n this.history = history?.provides() ?? null;\n\n const interactionManager = registry.getPlugin<InteractionManagerPlugin>('interaction-manager');\n this.interactionManager = interactionManager?.provides() ?? null;\n\n this.coreStore.onAction(SET_DOCUMENT, (_action, state) => {\n const doc = state.core.document;\n if (doc) {\n this.getAllAnnotations(doc);\n }\n });\n }\n\n async initialize(): Promise<void> {\n for (const [variantKey, defaults] of Object.entries(this.state.toolDefaults)) {\n this.registerTool(variantKey, defaults);\n }\n\n this.history?.onHistoryChange((topic) => {\n if (topic === this.ANNOTATION_HISTORY_TOPIC && this.config.autoCommit !== false) {\n this.commit();\n }\n });\n\n this.interactionManager?.onModeChange((s) => {\n const newVariant = this.variantByMode.get(s.activeMode) ?? null;\n console.log(newVariant, this.state.activeVariant);\n if (newVariant !== this.state.activeVariant) {\n this.dispatch(setActiveVariant(newVariant));\n this.activeVariantChange$.emit(newVariant);\n }\n });\n\n this.selection?.onEndSelection(() => {\n if (!this.state.activeVariant) return;\n\n if (\n !(\n this.state.activeVariant === makeVariantKey(PdfAnnotationSubtype.HIGHLIGHT) ||\n this.state.activeVariant === makeVariantKey(PdfAnnotationSubtype.UNDERLINE) ||\n this.state.activeVariant === makeVariantKey(PdfAnnotationSubtype.STRIKEOUT) ||\n this.state.activeVariant === makeVariantKey(PdfAnnotationSubtype.SQUIGGLY)\n )\n ) {\n return;\n }\n\n const formattedSelection = this.selection?.getFormattedSelection();\n if (!formattedSelection) return;\n\n for (const selection of formattedSelection) {\n const rect = selection.rect;\n const segmentRects = selection.segmentRects;\n const type = this.state.activeVariant;\n const subtype = this.state.toolDefaults[type].subtype;\n const color = this.state.toolDefaults[type].color;\n const opacity = this.state.toolDefaults[type].opacity;\n const blendMode = this.state.toolDefaults[type].blendMode ?? PdfBlendMode.Normal;\n\n this.createAnnotation(selection.pageIndex, {\n type: subtype as TextMarkupSubtype,\n rect,\n segmentRects,\n color,\n opacity,\n blendMode,\n pageIndex: selection.pageIndex,\n id: Date.now() + Math.random(),\n });\n }\n\n this.selection?.clear();\n });\n }\n\n private registerTool(variantKey: string, defaults: BaseAnnotationDefaults) {\n const modeId = defaults.interaction.mode;\n const interactionMode: InteractionMode = {\n id: modeId,\n scope: 'page',\n exclusive: defaults.interaction.exclusive,\n cursor: defaults.interaction.cursor,\n };\n\n this.interactionManager?.registerMode(interactionMode);\n\n if (defaults.textSelection) {\n this.selection?.enableForMode(modeId);\n }\n\n this.modeByVariant.set(variantKey, modeId);\n this.variantByMode.set(modeId, variantKey);\n }\n\n protected buildCapability(): AnnotationCapability {\n return {\n getPageAnnotations: (options: GetPageAnnotationsOptions) => {\n return this.getPageAnnotations(options);\n },\n getSelectedAnnotation: () => {\n return getSelectedAnnotation(this.state);\n },\n selectAnnotation: (pageIndex: number, annotationId: number) => {\n this.selectAnnotation(pageIndex, annotationId);\n },\n deselectAnnotation: () => {\n this.dispatch(deselectAnnotation());\n },\n getActiveVariant: () => {\n return this.state.activeVariant;\n },\n setActiveVariant: (variantKey: string | null) => {\n if (variantKey === this.state.activeVariant) return;\n if (variantKey) {\n const mode = this.modeByVariant.get(variantKey);\n if (!mode) throw new Error(`Mode missing for variant ${variantKey}`);\n this.interactionManager?.activate(mode);\n } else {\n this.interactionManager?.activate('default');\n }\n },\n getSubtypeAndIntentByVariant: (variantKey) => {\n return parseVariantKey(variantKey);\n },\n getToolDefaults: (variantKey) => {\n const defaults = this.state.toolDefaults[variantKey];\n if (!defaults) {\n throw new Error(`No defaults found for variant: ${variantKey}`);\n }\n return defaults;\n },\n getToolDefaultsBySubtypeAndIntent: (subtype, intent) => {\n return getToolDefaultsBySubtypeAndIntent(this.state, subtype, intent);\n },\n getToolDefaultsBySubtype: (subtype) => {\n return getToolDefaultsBySubtypeAndIntent(this.state, subtype);\n },\n setToolDefaults: (variantKey, patch) => {\n this.dispatch(updateToolDefaults(variantKey, patch));\n },\n getColorPresets: () => [...this.state.colorPresets],\n addColorPreset: (color) => this.dispatch(addColorPreset(color)),\n createAnnotation: (pageIndex: number, annotation: PdfAnnotationObject) =>\n this.createAnnotation(pageIndex, annotation),\n updateAnnotation: (pageIndex: number, localId: number, patch: Partial<PdfAnnotationObject>) =>\n this.updateAnnotation(pageIndex, localId, patch),\n deleteAnnotation: (pageIndex: number, localId: number) =>\n this.deleteAnnotation(pageIndex, localId),\n renderAnnotation: (options: RenderAnnotationOptions) => this.renderAnnotation(options),\n onStateChange: this.state$.on,\n onActiveVariantChange: this.activeVariantChange$.on,\n onActiveToolChange: this.activeTool$.on,\n commit: () => this.commit(),\n };\n }\n\n private createActiveTool(mode: string | null, toolDefaults: ToolDefaultsByMode): ActiveTool {\n if (mode === null) {\n return { variantKey: null, defaults: null };\n }\n return { variantKey: mode, defaults: toolDefaults[mode] } as ActiveTool;\n }\n\n private emitActiveTool(state: AnnotationState) {\n const activeTool = this.createActiveTool(state.activeVariant, state.toolDefaults);\n this.activeTool$.emit(activeTool);\n }\n\n override onStoreUpdated(prev: AnnotationState, next: AnnotationState): void {\n this.state$.emit(next);\n if (\n prev.activeVariant !== next.activeVariant ||\n prev.toolDefaults[prev.activeVariant ?? PdfAnnotationSubtype.HIGHLIGHT] !==\n next.toolDefaults[next.activeVariant ?? PdfAnnotationSubtype.HIGHLIGHT]\n ) {\n this.emitActiveTool(next);\n }\n }\n\n private getAllAnnotations(doc: PdfDocumentObject) {\n const task = this.engine.getAllAnnotations(doc);\n task.wait((annotations) => this.dispatch(setAnnotations(annotations)), ignore);\n }\n\n private getPageAnnotations(\n options: GetPageAnnotationsOptions,\n ): Task<PdfAnnotationObject[], PdfErrorReason> {\n const { pageIndex } = options;\n\n const doc = this.coreState.core.document;\n\n if (!doc) {\n return PdfTaskHelper.reject({ code: PdfErrorCode.NotFound, message: 'Document not found' });\n }\n\n const page = doc.pages.find((p) => p.index === pageIndex);\n\n if (!page) {\n return PdfTaskHelper.reject({ code: PdfErrorCode.NotFound, message: 'Page not found' });\n }\n\n return this.engine.getPageAnnotations(doc, page);\n }\n\n private renderAnnotation({\n pageIndex,\n annotation,\n scaleFactor = 1,\n rotation = Rotation.Degree0,\n dpr = 1,\n mode = AppearanceMode.Normal,\n imageType = 'image/webp',\n }: RenderAnnotationOptions) {\n const coreState = this.coreState.core;\n\n if (!coreState.document) {\n throw new Error('document does not open');\n }\n\n const page = coreState.document.pages.find((page) => page.index === pageIndex);\n if (!page) {\n throw new Error('page does not exist');\n }\n\n return this.engine.renderAnnotation(\n coreState.document,\n page,\n annotation,\n scaleFactor,\n rotation,\n dpr,\n mode,\n imageType,\n );\n }\n\n private selectAnnotation(pageIndex: number, annotationId: number) {\n this.dispatch(selectAnnotation(pageIndex, annotationId));\n }\n\n private createAnnotation(pageIndex: number, annotation: PdfAnnotationObject) {\n const localId = annotation.id;\n const execute = () => this.dispatch(createAnnotation(pageIndex, localId, annotation));\n\n if (!this.history) {\n execute();\n if (this.config.autoCommit) this.commit();\n return;\n }\n const command: Command = {\n execute,\n undo: () => {\n this.dispatch(deselectAnnotation());\n this.dispatch(deleteAnnotation(pageIndex, localId));\n },\n };\n this.history.register(command, this.ANNOTATION_HISTORY_TOPIC);\n }\n\n private buildPatch(original: PdfAnnotationObject, patch: Partial<PdfAnnotationObject>) {\n if ('rect' in patch) return patch;\n\n const merged = { ...original, ...patch } as PdfAnnotationObject;\n return { ...patch, rect: deriveRect(merged) };\n }\n\n private updateAnnotation(\n pageIndex: number,\n localId: number,\n patch: Partial<PdfAnnotationObject>,\n ) {\n const originalObject = this.state.byUid[makeUid(pageIndex, localId)].object;\n const finalPatch = this.buildPatch(originalObject, patch);\n\n if (!this.history) {\n this.dispatch(patchAnnotation(pageIndex, localId, finalPatch));\n if (this.config.autoCommit !== false) {\n this.commit();\n }\n return;\n }\n const originalPatch = Object.fromEntries(\n Object.keys(patch).map((key) => [key, originalObject[key as keyof PdfAnnotationObject]]),\n );\n const command: Command = {\n execute: () => this.dispatch(patchAnnotation(pageIndex, localId, finalPatch)),\n undo: () => this.dispatch(patchAnnotation(pageIndex, localId, originalPatch)),\n };\n this.history.register(command, this.ANNOTATION_HISTORY_TOPIC);\n }\n\n private deleteAnnotation(pageIndex: number, localId: number) {\n if (!this.history) {\n this.dispatch(deselectAnnotation());\n this.dispatch(deleteAnnotation(pageIndex, localId));\n if (this.config.autoCommit !== false) {\n this.commit();\n }\n return;\n }\n const originalAnnotation = this.state.byUid[makeUid(pageIndex, localId)].object;\n const command: Command = {\n execute: () => {\n this.dispatch(deselectAnnotation());\n this.dispatch(deleteAnnotation(pageIndex, localId));\n },\n undo: () => this.dispatch(createAnnotation(pageIndex, localId, originalAnnotation)),\n };\n this.history.register(command, this.ANNOTATION_HISTORY_TOPIC);\n }\n\n private commit(): Task<boolean, PdfErrorReason> {\n const task = new Task<boolean, PdfErrorReason>();\n\n if (!this.state.hasPendingChanges) return PdfTaskHelper.resolve(true);\n\n const doc = this.coreState.core.document;\n if (!doc)\n return PdfTaskHelper.reject({ code: PdfErrorCode.NotFound, message: 'Document not found' });\n\n const creations: Task<any, PdfErrorReason>[] = [];\n const updates: Task<any, PdfErrorReason>[] = [];\n const deletionsByPage = new Map<number, { ta: TrackedAnnotation; uid: string }[]>();\n const affectedPages = new Set<number>();\n\n // 1. Group all pending changes by operation type\n for (const [uid, ta] of Object.entries(this.state.byUid)) {\n if (ta.commitState === 'synced') continue;\n\n const { pageIndex } = parseUid(uid);\n const page = doc.pages.find((p) => p.index === pageIndex);\n if (!page) continue;\n\n affectedPages.add(pageIndex);\n\n switch (ta.commitState) {\n case 'new':\n const task = this.engine.createPageAnnotation!(doc, page, ta.object);\n task.wait((annoId) => this.dispatch(storePdfId(uid, annoId)), ignore);\n creations.push(task);\n break;\n case 'dirty':\n updates.push(\n this.engine.updatePageAnnotation!(doc, page, { ...ta.object, id: ta.pdfId! }),\n );\n break;\n case 'deleted':\n if (!deletionsByPage.has(pageIndex)) {\n deletionsByPage.set(pageIndex, []);\n }\n deletionsByPage.get(pageIndex)!.push({ ta, uid });\n break;\n }\n }\n\n // 2. Create deletion tasks, sorted by ID descending\n const deletionTasks: Task<any, PdfErrorReason>[] = [];\n for (const [pageIndex, deletions] of deletionsByPage.entries()) {\n const page = doc.pages.find((p) => p.index === pageIndex)!;\n\n deletions.sort((a, b) => (b.ta.pdfId ?? -1) - (a.ta.pdfId ?? -1));\n\n for (const { ta, uid } of deletions) {\n if (ta.pdfId !== undefined) {\n const task = new Task<any, PdfErrorReason>();\n const removeTask = this.engine.removePageAnnotation!(doc, page, {\n ...ta.object,\n id: ta.pdfId!,\n });\n removeTask.wait(() => {\n this.dispatch(purgeAnnotation(uid));\n task.resolve(true);\n }, task.fail);\n deletionTasks.push(task);\n } else {\n this.dispatch(purgeAnnotation(uid));\n }\n }\n }\n\n // 3. Chain the operations: creations/updates -> deletions -> re-sync\n const allWriteTasks = [...creations, ...updates, ...deletionTasks];\n\n Task.allSettled(allWriteTasks).wait(() => {\n // 4. Client-Side Re-indexing\n // After all engine operations are done, tell the reducer to re-index each affected page.\n for (const pageIndex of affectedPages) {\n this.dispatch(reindexPageAnnotations(pageIndex));\n }\n\n // 5. Finalize the commit by updating the commitState of all items.\n this.dispatch(commitPendingChanges());\n task.resolve(true);\n }, task.fail);\n\n return task;\n }\n}\n","import { Reducer } from '@embedpdf/core';\nimport {\n PdfAnnotationBorderStyle,\n PdfAnnotationLineEnding,\n PdfAnnotationSubtype,\n PdfBlendMode,\n} from '@embedpdf/models';\nimport {\n ADD_COLOR_PRESET,\n COMMIT_PENDING_CHANGES,\n CREATE_ANNOTATION,\n DESELECT_ANNOTATION,\n PATCH_ANNOTATION,\n DELETE_ANNOTATION,\n SELECT_ANNOTATION,\n SET_ANNOTATIONS,\n UPDATE_TOOL_DEFAULTS,\n AnnotationAction,\n PURGE_ANNOTATION,\n STORE_PDF_ID,\n REINDEX_PAGE_ANNOTATIONS,\n SET_ACTIVE_VARIANT,\n} from './actions';\nimport {\n AnnotationDefaults,\n AnnotationPluginConfig,\n AnnotationState,\n TrackedAnnotation,\n} from './types';\nimport { makeUid } from './utils';\nimport { makeVariantKey } from './variant-key';\n\n/* ─────────── util helpers ─────────── */\nconst DEFAULT_COLORS = [\n '#E44234',\n '#FF8D00',\n '#FFCD45',\n '#5CC96E',\n '#25D2D1',\n '#597CE2',\n '#C544CE',\n '#7D2E25',\n];\n\n/* helper to immutably replace one annotation (preserving pdfId) */\nconst patchAnno = (\n state: AnnotationState,\n uid: string,\n patch: Partial<TrackedAnnotation['object']>,\n): AnnotationState => {\n const prev = state.byUid[uid];\n if (!prev) return state;\n return {\n ...state,\n byUid: {\n ...state.byUid,\n [uid]: {\n ...prev,\n commitState: prev.commitState === 'synced' ? 'dirty' : prev.commitState,\n object: { ...prev.object, ...patch },\n } as TrackedAnnotation,\n },\n hasPendingChanges: true,\n };\n};\n\n/* ─────────── initialState ─────────── */\nexport const initialState = (cfg: AnnotationPluginConfig): AnnotationState => ({\n pages: {},\n byUid: {},\n selectedUid: null,\n activeVariant: null,\n\n toolDefaults: {\n [makeVariantKey(PdfAnnotationSubtype.HIGHLIGHT)]: {\n name: 'Highlight',\n subtype: PdfAnnotationSubtype.HIGHLIGHT,\n interaction: { mode: 'highlight', exclusive: false },\n textSelection: true,\n color: '#FFCD45',\n opacity: 1,\n blendMode: PdfBlendMode.Multiply,\n },\n [makeVariantKey(PdfAnnotationSubtype.UNDERLINE)]: {\n name: 'Underline',\n subtype: PdfAnnotationSubtype.UNDERLINE,\n interaction: { mode: 'underline', exclusive: false },\n textSelection: true,\n color: '#E44234',\n opacity: 1,\n blendMode: PdfBlendMode.Normal,\n },\n [makeVariantKey(PdfAnnotationSubtype.STRIKEOUT)]: {\n name: 'Strikeout',\n subtype: PdfAnnotationSubtype.STRIKEOUT,\n interaction: { mode: 'strikeout', exclusive: false },\n textSelection: true,\n color: '#E44234',\n opacity: 1,\n blendMode: PdfBlendMode.Normal,\n },\n [makeVariantKey(PdfAnnotationSubtype.SQUIGGLY)]: {\n name: 'Squiggly',\n subtype: PdfAnnotationSubtype.SQUIGGLY,\n interaction: { mode: 'squiggly', exclusive: false },\n textSelection: true,\n color: '#E44234',\n opacity: 1,\n blendMode: PdfBlendMode.Normal,\n },\n [makeVariantKey(PdfAnnotationSubtype.INK)]: {\n name: 'Ink',\n subtype: PdfAnnotationSubtype.INK,\n interaction: { mode: 'ink', exclusive: true, cursor: 'crosshair' },\n color: '#E44234',\n opacity: 1,\n strokeWidth: 11,\n blendMode: PdfBlendMode.Normal,\n },\n [makeVariantKey(PdfAnnotationSubtype.INK, 'InkHighlight')]: {\n name: 'Ink Highlight',\n subtype: PdfAnnotationSubtype.INK,\n intent: 'InkHighlight',\n interaction: { mode: 'inkHighlight', exclusive: true, cursor: 'crosshair' },\n color: '#E44234',\n opacity: 1,\n strokeWidth: 11,\n blendMode: PdfBlendMode.Multiply,\n },\n [makeVariantKey(PdfAnnotationSubtype.CIRCLE)]: {\n name: 'Circle',\n subtype: PdfAnnotationSubtype.CIRCLE,\n interaction: { mode: 'circle', exclusive: true, cursor: 'crosshair' },\n color: 'transparent',\n opacity: 1,\n strokeWidth: 4,\n strokeColor: '#E44234',\n strokeStyle: PdfAnnotationBorderStyle.SOLID,\n },\n [makeVariantKey(PdfAnnotationSubtype.SQUARE)]: {\n name: 'Square',\n subtype: PdfAnnotationSubtype.SQUARE,\n interaction: { mode: 'square', exclusive: true, cursor: 'crosshair' },\n color: 'transparent',\n opacity: 1,\n strokeWidth: 4,\n strokeColor: '#E44234',\n strokeStyle: PdfAnnotationBorderStyle.SOLID,\n },\n [makeVariantKey(PdfAnnotationSubtype.LINE)]: {\n name: 'Line',\n subtype: PdfAnnotationSubtype.LINE,\n interaction: { mode: 'line', exclusive: true, cursor: 'crosshair' },\n color: 'transparent',\n opacity: 1,\n strokeWidth: 4,\n strokeColor: '#E44234',\n strokeStyle: PdfAnnotationBorderStyle.SOLID,\n },\n [makeVariantKey(PdfAnnotationSubtype.LINE, 'LineArrow')]: {\n name: 'Line Arrow',\n subtype: PdfAnnotationSubtype.LINE,\n interaction: { mode: 'lineArrow', exclusive: true, cursor: 'crosshair' },\n color: 'transparent',\n intent: 'LineArrow',\n opacity: 1,\n strokeWidth: 4,\n strokeColor: '#E44234',\n strokeStyle: PdfAnnotationBorderStyle.SOLID,\n lineEndings: {\n start: PdfAnnotationLineEnding.None,\n end: PdfAnnotationLineEnding.OpenArrow,\n },\n },\n [makeVariantKey(PdfAnnotationSubtype.POLYLINE)]: {\n name: 'Polyline',\n subtype: PdfAnnotationSubtype.POLYLINE,\n interaction: { mode: 'polyline', exclusive: true, cursor: 'crosshair' },\n color: 'transparent',\n opacity: 1,\n strokeWidth: 4,\n strokeColor: '#E44234',\n strokeStyle: PdfAnnotationBorderStyle.SOLID,\n },\n [makeVariantKey(PdfAnnotationSubtype.POLYGON)]: {\n name: 'Polygon',\n subtype: PdfAnnotationSubtype.POLYGON,\n interaction: { mode: 'polygon', exclusive: true, cursor: 'crosshair' },\n color: 'transparent',\n opacity: 1,\n strokeWidth: 4,\n strokeColor: '#E44234',\n strokeStyle: PdfAnnotationBorderStyle.SOLID,\n },\n ...cfg.toolDefaults,\n },\n colorPresets: cfg.colorPresets ?? DEFAULT_COLORS,\n hasPendingChanges: false,\n});\n\n/* ─────────── reducer ─────────── */\nexport const reducer: Reducer<AnnotationState, AnnotationAction> = (state, action) => {\n switch (action.type) {\n /* ───── bulk load from engine ───── */\n case SET_ANNOTATIONS: {\n const newPages = { ...state.pages };\n const newByUid = { ...state.byUid };\n for (const [pgStr, list] of Object.entries(action.payload)) {\n const pageIndex = Number(pgStr);\n const oldUidsOnPage = state.pages[pageIndex] || [];\n for (const uid of oldUidsOnPage) {\n delete newByUid[uid];\n }\n const newUidsOnPage = list.map((a, index) => {\n const localId = Date.now() + Math.random() + index;\n const uid = makeUid(pageIndex, localId);\n newByUid[uid] = { localId, pdfId: a.id, commitState: 'synced', object: a };\n return uid;\n });\n newPages[pageIndex] = newUidsOnPage;\n }\n return { ...state, pages: newPages, byUid: newByUid };\n }\n\n /* ───── GUI bits ───── */\n case SET_ACTIVE_VARIANT:\n return { ...state, activeVariant: action.payload };\n case SELECT_ANNOTATION:\n return {\n ...state,\n selectedUid: makeUid(action.payload.pageIndex, action.payload.localId),\n };\n case DESELECT_ANNOTATION:\n return { ...state, selectedUid: null };\n\n case ADD_COLOR_PRESET:\n return state.colorPresets.includes(action.payload)\n ? state\n : { ...state, colorPresets: [...state.colorPresets, action.payload] };\n\n case UPDATE_TOOL_DEFAULTS: {\n const { variantKey, patch } = action.payload;\n const prev = state.toolDefaults[variantKey];\n if (!prev) return state;\n return {\n ...state,\n toolDefaults: {\n ...state.toolDefaults,\n [variantKey]: { ...prev, ...patch } as AnnotationDefaults,\n },\n };\n }\n\n /* ───── create ───── */\n case CREATE_ANNOTATION: {\n const { pageIndex, localId, annotation } = action.payload;\n const uid = makeUid(pageIndex, localId);\n\n return {\n ...state,\n pages: { ...state.pages, [pageIndex]: [...(state.pages[pageIndex] ?? []), uid] },\n byUid: {\n ...state.byUid,\n [uid]: { localId, pdfId: undefined, commitState: 'new', object: annotation },\n },\n hasPendingChanges: true,\n };\n }\n\n /* ───── delete ───── */\n case DELETE_ANNOTATION: {\n const { pageIndex, localId } = action.payload;\n const uid = makeUid(pageIndex, localId);\n if (!state.byUid[uid]) return state;\n\n /* keep the object but mark it as deleted */\n return {\n ...state,\n pages: {\n ...state.pages,\n [pageIndex]: (state.pages[pageIndex] ?? []).filter((u) => u !== uid),\n },\n byUid: {\n ...state.byUid,\n [uid]: { ...state.byUid[uid], commitState: 'deleted' },\n },\n hasPendingChanges: true,\n };\n }\n\n /* ───── field edits ───── */\n case PATCH_ANNOTATION: {\n const uid = makeUid(action.payload.pageIndex, action.payload.localId);\n return patchAnno(state, uid, action.payload.patch);\n }\n\n /* ───── commit bookkeeping ───── */\n case COMMIT_PENDING_CHANGES: {\n const cleaned: AnnotationState['byUid'] = {};\n for (const [uid, ta] of Object.entries(state.byUid)) {\n cleaned[uid] = {\n ...ta,\n commitState:\n ta.commitState === 'dirty' || ta.commitState === 'new' ? 'synced' : ta.commitState,\n };\n }\n return { ...state, byUid: cleaned, hasPendingChanges: false };\n }\n\n case REINDEX_PAGE_ANNOTATIONS: {\n const { pageIndex } = action.payload;\n const newByUid = { ...state.byUid };\n\n const uidsOnPage = state.pages[pageIndex] || [];\n const annosOnPage = uidsOnPage\n .map((uid) => state.byUid[uid])\n .filter((ta) => ta && ta.commitState !== 'deleted'); // Filter out annotations pending deletion\n\n // CORRECTED: Sort by the existing pdfId to maintain relative order.\n annosOnPage.sort((a, b) => (a.pdfId ?? Infinity) - (b.pdfId ?? Infinity));\n\n // Update the pdfId for each annotation based on its new sorted index\n annosOnPage.forEach((ta, newPdfId) => {\n const uid = makeUid(pageIndex, ta.localId);\n newByUid[uid] = { ...newByUid[uid], pdfId: newPdfId };\n });\n\n return { ...state, byUid: newByUid };\n }\n\n case STORE_PDF_ID: {\n const { uid, pdfId } = action.payload;\n\n const ta = state.byUid[uid];\n if (!ta) return state;\n return {\n ...state,\n byUid: {\n ...state.byUid,\n [uid]: { ...ta, pdfId, commitState: 'synced' },\n },\n };\n }\n\n case PURGE_ANNOTATION: {\n const { uid } = action.payload;\n const { [uid]: _gone, ...rest } = state.byUid;\n return { ...state, byUid: rest };\n }\n\n default:\n return state;\n }\n};\n","import { PdfAnnotationSubtype, PdfAnnotationObject } from '@embedpdf/models';\nimport { TrackedAnnotation } from '@embedpdf/plugin-annotation';\n\n/* ------------------------------------------------------------------ */\n/* 1. Generic “subtype‑to‑object” mapper */\n/* ------------------------------------------------------------------ */\n\nexport type AnnoOf<S extends PdfAnnotationSubtype> = Extract<PdfAnnotationObject, { type: S }>;\n\n/* ------------------------------------------------------------------ */\n/* 2. Narrowing type‑guards (add more as needed) */\n/* ------------------------------------------------------------------ */\n\n/** True when `a.object.type === INK` – and narrows the generic. */\nexport function isInk(\n a: TrackedAnnotation,\n): a is TrackedAnnotation<AnnoOf<PdfAnnotationSubtype.INK>> {\n return a.object.type === PdfAnnotationSubtype.INK;\n}\n\n/** Example for Circle – create similar ones for Square, Line, etc. */\nexport function isCircle(\n a: TrackedAnnotation,\n): a is TrackedAnnotation<AnnoOf<PdfAnnotationSubtype.CIRCLE>> {\n return a.object.type === PdfAnnotationSubtype.CIRCLE;\n}\n\nexport function isPolygon(\n a: TrackedAnnotation,\n): a is TrackedAnnotation<AnnoOf<PdfAnnotationSubtype.POLYGON>> {\n return a.object.type === PdfAnnotationSubtype.POLYGON;\n}\n\nexport function isSquare(\n a: TrackedAnnotation,\n): a is TrackedAnnotation<AnnoOf<PdfAnnotationSubtype.SQUARE>> {\n return a.object.type === PdfAnnotationSubtype.SQUARE;\n}\n\nexport function isLine(\n a: TrackedAnnotation,\n): a is TrackedAnnotation<AnnoOf<PdfAnnotationSubtype.LINE>> {\n return a.object.type === PdfAnnotationSubtype.LINE;\n}\n\nexport function isPolyline(\n a: TrackedAnnotation,\n): a is TrackedAnnotation<AnnoOf<PdfAnnotationSubtype.POLYLINE>> {\n return a.object.type === PdfAnnotationSubtype.POLYLINE;\n}\n\nexport function isTextMarkup(\n a: TrackedAnnotation,\n): a is TrackedAnnotation<\n AnnoOf<\n | PdfAnnotationSubtype.HIGHLIGHT\n | PdfAnnotationSubtype.UNDERLINE\n | PdfAnnotationSubtype.STRIKEOUT\n | PdfAnnotationSubtype.SQUIGGLY\n >\n> {\n return (\n a.object.type === PdfAnnotationSubtype.HIGHLIGHT ||\n a.object.type === PdfAnnotationSubtype.UNDERLINE ||\n a.object.type === PdfAnnotationSubtype.STRIKEOUT ||\n a.object.type === PdfAnnotationSubtype.SQUIGGLY\n );\n}\n\nexport function isHighlight(\n a: TrackedAnnotation,\n): a is TrackedAnnotation<AnnoOf<PdfAnnotationSubtype.HIGHLIGHT>> {\n return a.object.type === PdfAnnotationSubtype.HIGHLIGHT;\n}\n\nexport function isUnderline(\n a: TrackedAnnotation,\n): a is TrackedAnnotation<AnnoOf<PdfAnnotationSubtype.UNDERLINE>> {\n return a.object.type === PdfAnnotationSubtype.UNDERLINE;\n}\n\nexport function isStrikeout(\n a: TrackedAnnotation,\n): a is TrackedAnnotation<AnnoOf<PdfAnnotationSubtype.STRIKEOUT>> {\n return a.object.type === PdfAnnotationSubtype.STRIKEOUT;\n}\n\nexport function isSquiggly(\n a: TrackedAnnotation,\n): a is TrackedAnnotation<AnnoOf<PdfAnnotationSubtype.SQUIGGLY>> {\n return a.object.type === PdfAnnotationSubtype.SQUIGGLY;\n}\n","import { PluginPackage } from '@embedpdf/core';\nimport { manifest, ANNOTATION_PLUGIN_ID } from './manifest';\nimport { AnnotationPluginConfig, AnnotationState } from './types';\nimport { AnnotationPlugin } from './annotation-plugin';\nimport { initialState, reducer } from './reducer';\nimport { AnnotationAction } from './actions';\n\nexport const AnnotationPluginPackage: PluginPackage<\n AnnotationPlugin,\n AnnotationPluginConfig,\n AnnotationState,\n AnnotationAction\n> = {\n manifest,\n create: (registry, engine, config) =>\n new AnnotationPlugin(ANNOTATION_PLUGIN_ID, registry, engine, config),\n reducer,\n initialState: (_, config) => initialState(config),\n};\n\nexport * from './annotation-plugin';\nexport * from './types';\nexport * from './manifest';\nexport * from './selectors';\nexport * from './variant-key';\nexport * from './helpers';\nexport * as patching from './patching';\n"],"names":["makeUid","pad","_a","_b","page","task","index"],"mappings":";;AAGO,MAAM,uBAAuB;AAE7B,MAAM,WAAmD;AAAA,EAC9D,IAAI;AAAA,EACJ,MAAM;AAAA,EACN,SAAS;AAAA,EACT,UAAU,CAAC,YAAY;AAAA,EACvB,UAAU,CAAC,uBAAuB,WAAW;AAAA,EAC7C,UAAU,CAAC,SAAS;AAAA,EACpB,eAAe;AAAA,IACb,SAAS;AAAA,IACT,YAAY;AAAA,EAAA;AAEhB;ACXO,MAAM,kBAAkB;AACxB,MAAM,2BAA2B;AACjC,MAAM,oBAAoB;AAC1B,MAAM,sBAAsB;AAC5B,MAAM,uBAAuB;AAC7B,MAAM,mBAAmB;AACzB,MAAM,oBAAoB;AAC1B,MAAM,mBAAmB;AACzB,MAAM,oBAAoB;AAC1B,MAAM,yBAAyB;AAC/B,MAAM,eAAe;AACrB,MAAM,mBAAmB;AACzB,MAAM,qBAAqB;AA2ErB,MAAA,iBAAiB,CAAC,OAAoE;AAAA,EACjG,MAAM;AAAA,EACN,SAAS;AACX;AAEa,MAAA,yBAAyB,CAAC,eAAqD;AAAA,EAC1F,MAAM;AAAA,EACN,SAAS,EAAE,UAAU;AACvB;AAEa,MAAA,mBAAmB,CAAC,WAAmB,aAA6C;AAAA,EAC/F,MAAM;AAAA,EACN,SAAS,EAAE,WAAW,QAAQ;AAChC;AAEO,MAAM,qBAAqB,OAAiC,EAAE,MAAM;AAE9D,MAAA,qBAAqB,CAChC,YACA,WAC8B,EAAE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E,OAAO,SAAS,qBAAqB,aACvC,EAAE,OAAO,SAAS,qBAAqB,aACvC,EAAE,OAAO,SAAS,qBAAqB,aACvC,EAAE,OAAO,SAAS,qBAAqB;AAE3C;AAEO,SAAS,YACd,GACgE;AACzD,SAAA,EAAE,OAAO,SAAS,qBAAqB;AAChD;AAEO,SAAS,YACd,GACgE;AACzD,SAAA,EAAE,OAAO,SAAS,qBAAqB;AAChD;AAEO,SAAS,YACd,GACgE;AACzD,SAAA,EAAE,OAAO,SAAS,qBAAqB;AAChD;AAEO,SAAS,WACd,GAC+D;AACxD,SAAA,EAAE,OAAO,SAAS,qBAAqB;AAChD;ACpFO,MAAM,0BAKT;AAAA,EACF;AAAA,EACA,QAAQ,CAAC,UAAU,QAAQ,WACzB,IAAI,iBAAiB,sBAAsB,UAAU,QAAQ,MAAM;AAAA,EACrE;AAAA,EACA,cAAc,CAAC,GAAG,WAAW,aAAa,MAAM;AAClD;"}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { Action } from '@embedpdf/core';
|
|
2
|
+
import { PdfAnnotationObject } from '@embedpdf/models';
|
|
3
|
+
import { AnnotationDefaults } from './types';
|
|
4
|
+
export declare const SET_ANNOTATIONS = "ANNOTATION/SET_ANNOTATIONS";
|
|
5
|
+
export declare const REINDEX_PAGE_ANNOTATIONS = "ANNOTATION/REINDEX_PAGE";
|
|
6
|
+
export declare const SELECT_ANNOTATION = "ANNOTATION/SELECT_ANNOTATION";
|
|
7
|
+
export declare const DESELECT_ANNOTATION = "ANNOTATION/DESELECT_ANNOTATION";
|
|
8
|
+
export declare const UPDATE_TOOL_DEFAULTS = "ANNOTATION/UPDATE_TOOL_DEFAULTS";
|
|
9
|
+
export declare const ADD_COLOR_PRESET = "ANNOTATION/ADD_COLOR_PRESET";
|
|
10
|
+
export declare const CREATE_ANNOTATION = "ANNOTATION/CREATE_ANNOTATION";
|
|
11
|
+
export declare const PATCH_ANNOTATION = "ANNOTATION/PATCH_ANNOTATION";
|
|
12
|
+
export declare const DELETE_ANNOTATION = "ANNOTATION/DELETE_ANNOTATION";
|
|
13
|
+
export declare const COMMIT_PENDING_CHANGES = "ANNOTATION/COMMIT";
|
|
14
|
+
export declare const STORE_PDF_ID = "ANNOTATION/STORE_PDF_ID";
|
|
15
|
+
export declare const PURGE_ANNOTATION = "ANNOTATION/PURGE_ANNOTATION";
|
|
16
|
+
export declare const SET_ACTIVE_VARIANT = "ANNOTATION/SET_ACTIVE_VARIANT";
|
|
17
|
+
export interface SetAnnotationsAction extends Action {
|
|
18
|
+
type: typeof SET_ANNOTATIONS;
|
|
19
|
+
payload: Record<number, PdfAnnotationObject[]>;
|
|
20
|
+
}
|
|
21
|
+
export interface ReindexPageAnnotationsAction extends Action {
|
|
22
|
+
type: typeof REINDEX_PAGE_ANNOTATIONS;
|
|
23
|
+
payload: {
|
|
24
|
+
pageIndex: number;
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
export interface SelectAnnotationAction extends Action {
|
|
28
|
+
type: typeof SELECT_ANNOTATION;
|
|
29
|
+
payload: {
|
|
30
|
+
pageIndex: number;
|
|
31
|
+
localId: number;
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
export interface DeselectAnnotationAction extends Action {
|
|
35
|
+
type: typeof DESELECT_ANNOTATION;
|
|
36
|
+
}
|
|
37
|
+
export interface UpdateToolDefaultsAction extends Action {
|
|
38
|
+
type: typeof UPDATE_TOOL_DEFAULTS;
|
|
39
|
+
payload: {
|
|
40
|
+
variantKey: string;
|
|
41
|
+
patch: Partial<AnnotationDefaults>;
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
export interface AddColorPresetAction extends Action {
|
|
45
|
+
type: typeof ADD_COLOR_PRESET;
|
|
46
|
+
payload: string;
|
|
47
|
+
}
|
|
48
|
+
export interface CreateAnnotationAction extends Action {
|
|
49
|
+
type: typeof CREATE_ANNOTATION;
|
|
50
|
+
payload: {
|
|
51
|
+
pageIndex: number;
|
|
52
|
+
localId: number;
|
|
53
|
+
annotation: PdfAnnotationObject;
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
export interface PatchAnnotationAction extends Action {
|
|
57
|
+
type: typeof PATCH_ANNOTATION;
|
|
58
|
+
payload: {
|
|
59
|
+
pageIndex: number;
|
|
60
|
+
localId: number;
|
|
61
|
+
patch: Partial<PdfAnnotationObject>;
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
export interface DeleteAnnotationAction extends Action {
|
|
65
|
+
type: typeof DELETE_ANNOTATION;
|
|
66
|
+
payload: {
|
|
67
|
+
pageIndex: number;
|
|
68
|
+
localId: number;
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
export interface CommitAction extends Action {
|
|
72
|
+
type: typeof COMMIT_PENDING_CHANGES;
|
|
73
|
+
}
|
|
74
|
+
export interface StorePdfIdAction extends Action {
|
|
75
|
+
type: typeof STORE_PDF_ID;
|
|
76
|
+
payload: {
|
|
77
|
+
uid: string;
|
|
78
|
+
pdfId: number;
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
export interface PurgeAnnotationAction extends Action {
|
|
82
|
+
type: typeof PURGE_ANNOTATION;
|
|
83
|
+
payload: {
|
|
84
|
+
uid: string;
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
export interface SetActiveVariantAction extends Action {
|
|
88
|
+
type: typeof SET_ACTIVE_VARIANT;
|
|
89
|
+
payload: string | null;
|
|
90
|
+
}
|
|
91
|
+
export type AnnotationAction = SetAnnotationsAction | ReindexPageAnnotationsAction | SelectAnnotationAction | DeselectAnnotationAction | UpdateToolDefaultsAction | AddColorPresetAction | CreateAnnotationAction | PatchAnnotationAction | DeleteAnnotationAction | CommitAction | StorePdfIdAction | PurgeAnnotationAction | SetActiveVariantAction;
|
|
92
|
+
export declare const setAnnotations: (p: Record<number, PdfAnnotationObject[]>) => SetAnnotationsAction;
|
|
93
|
+
export declare const reindexPageAnnotations: (pageIndex: number) => ReindexPageAnnotationsAction;
|
|
94
|
+
export declare const selectAnnotation: (pageIndex: number, localId: number) => SelectAnnotationAction;
|
|
95
|
+
export declare const deselectAnnotation: () => DeselectAnnotationAction;
|
|
96
|
+
export declare const updateToolDefaults: (variantKey: string, patch: Partial<AnnotationDefaults>) => UpdateToolDefaultsAction;
|
|
97
|
+
export declare const addColorPreset: (c: string) => AddColorPresetAction;
|
|
98
|
+
export declare const createAnnotation: (pageIndex: number, localId: number, annotation: PdfAnnotationObject) => CreateAnnotationAction;
|
|
99
|
+
export declare const patchAnnotation: (pageIndex: number, localId: number, patch: Partial<PdfAnnotationObject>) => PatchAnnotationAction;
|
|
100
|
+
export declare const deleteAnnotation: (pageIndex: number, localId: number) => DeleteAnnotationAction;
|
|
101
|
+
export declare const commitPendingChanges: () => CommitAction;
|
|
102
|
+
export declare const storePdfId: (uid: string, pdfId: number) => StorePdfIdAction;
|
|
103
|
+
export declare const purgeAnnotation: (uid: string) => PurgeAnnotationAction;
|
|
104
|
+
export declare const setActiveVariant: (k: string | null) => SetActiveVariantAction;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { BasePlugin, PluginRegistry } from '@embedpdf/core';
|
|
2
|
+
import { PdfEngine } from '@embedpdf/models';
|
|
3
|
+
import { AnnotationCapability, AnnotationPluginConfig, AnnotationState } from './types';
|
|
4
|
+
import { AnnotationAction } from './actions';
|
|
5
|
+
export declare class AnnotationPlugin extends BasePlugin<AnnotationPluginConfig, AnnotationCapability, AnnotationState, AnnotationAction> {
|
|
6
|
+
static readonly id: "annotation";
|
|
7
|
+
private readonly ANNOTATION_HISTORY_TOPIC;
|
|
8
|
+
private readonly config;
|
|
9
|
+
private engine;
|
|
10
|
+
private readonly state$;
|
|
11
|
+
private readonly interactionManager;
|
|
12
|
+
private readonly selection;
|
|
13
|
+
private readonly history;
|
|
14
|
+
private readonly modeByVariant;
|
|
15
|
+
private readonly variantByMode;
|
|
16
|
+
private readonly activeVariantChange$;
|
|
17
|
+
private readonly activeTool$;
|
|
18
|
+
constructor(id: string, registry: PluginRegistry, engine: PdfEngine, config: AnnotationPluginConfig);
|
|
19
|
+
initialize(): Promise<void>;
|
|
20
|
+
private registerTool;
|
|
21
|
+
protected buildCapability(): AnnotationCapability;
|
|
22
|
+
private createActiveTool;
|
|
23
|
+
private emitActiveTool;
|
|
24
|
+
onStoreUpdated(prev: AnnotationState, next: AnnotationState): void;
|
|
25
|
+
private getAllAnnotations;
|
|
26
|
+
private getPageAnnotations;
|
|
27
|
+
private renderAnnotation;
|
|
28
|
+
private selectAnnotation;
|
|
29
|
+
private createAnnotation;
|
|
30
|
+
private buildPatch;
|
|
31
|
+
private updateAnnotation;
|
|
32
|
+
private deleteAnnotation;
|
|
33
|
+
private commit;
|
|
34
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { PdfAnnotationSubtype, PdfAnnotationObject } from '@embedpdf/models';
|
|
2
|
+
import { TrackedAnnotation } from '../index.ts';
|
|
3
|
+
export type AnnoOf<S extends PdfAnnotationSubtype> = Extract<PdfAnnotationObject, {
|
|
4
|
+
type: S;
|
|
5
|
+
}>;
|
|
6
|
+
/** True when `a.object.type === INK` – and narrows the generic. */
|
|
7
|
+
export declare function isInk(a: TrackedAnnotation): a is TrackedAnnotation<AnnoOf<PdfAnnotationSubtype.INK>>;
|
|
8
|
+
/** Example for Circle – create similar ones for Square, Line, etc. */
|
|
9
|
+
export declare function isCircle(a: TrackedAnnotation): a is TrackedAnnotation<AnnoOf<PdfAnnotationSubtype.CIRCLE>>;
|
|
10
|
+
export declare function isPolygon(a: TrackedAnnotation): a is TrackedAnnotation<AnnoOf<PdfAnnotationSubtype.POLYGON>>;
|
|
11
|
+
export declare function isSquare(a: TrackedAnnotation): a is TrackedAnnotation<AnnoOf<PdfAnnotationSubtype.SQUARE>>;
|
|
12
|
+
export declare function isLine(a: TrackedAnnotation): a is TrackedAnnotation<AnnoOf<PdfAnnotationSubtype.LINE>>;
|
|
13
|
+
export declare function isPolyline(a: TrackedAnnotation): a is TrackedAnnotation<AnnoOf<PdfAnnotationSubtype.POLYLINE>>;
|
|
14
|
+
export declare function isTextMarkup(a: TrackedAnnotation): a is TrackedAnnotation<AnnoOf<PdfAnnotationSubtype.HIGHLIGHT | PdfAnnotationSubtype.UNDERLINE | PdfAnnotationSubtype.STRIKEOUT | PdfAnnotationSubtype.SQUIGGLY>>;
|
|
15
|
+
export declare function isHighlight(a: TrackedAnnotation): a is TrackedAnnotation<AnnoOf<PdfAnnotationSubtype.HIGHLIGHT>>;
|
|
16
|
+
export declare function isUnderline(a: TrackedAnnotation): a is TrackedAnnotation<AnnoOf<PdfAnnotationSubtype.UNDERLINE>>;
|
|
17
|
+
export declare function isStrikeout(a: TrackedAnnotation): a is TrackedAnnotation<AnnoOf<PdfAnnotationSubtype.STRIKEOUT>>;
|
|
18
|
+
export declare function isSquiggly(a: TrackedAnnotation): a is TrackedAnnotation<AnnoOf<PdfAnnotationSubtype.SQUIGGLY>>;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { PluginPackage } from '@embedpdf/core';
|
|
2
|
+
import { AnnotationPluginConfig, AnnotationState } from './types';
|
|
3
|
+
import { AnnotationPlugin } from './annotation-plugin';
|
|
4
|
+
import { AnnotationAction } from './actions';
|
|
5
|
+
export declare const AnnotationPluginPackage: PluginPackage<AnnotationPlugin, AnnotationPluginConfig, AnnotationState, AnnotationAction>;
|
|
6
|
+
export * from './annotation-plugin';
|
|
7
|
+
export * from './types';
|
|
8
|
+
export * from './manifest';
|
|
9
|
+
export * from './selectors';
|
|
10
|
+
export * from './variant-key';
|
|
11
|
+
export * from './helpers';
|
|
12
|
+
export * as patching from './patching';
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { PdfAnnotationLineEnding, Position } from '@embedpdf/models';
|
|
2
|
+
/**
|
|
3
|
+
* A handler that encapsulates all logic for a specific line ending type,
|
|
4
|
+
* including SVG path generation, geometric vertex calculation, and rotation logic.
|
|
5
|
+
* This is the single source of truth for each ending.
|
|
6
|
+
*/
|
|
7
|
+
export interface LineEndingHandler {
|
|
8
|
+
/** Returns the SVG `d` attribute string for rendering. */
|
|
9
|
+
getSvgPath: (strokeWidth: number) => string;
|
|
10
|
+
/** Returns the vertices used for calculating the geometric bounding box. */
|
|
11
|
+
getLocalPoints: (strokeWidth: number) => Position[];
|
|
12
|
+
/** Returns the final rotation angle in radians based on the line segment's angle. */
|
|
13
|
+
getRotation: (segmentAngle: number) => number;
|
|
14
|
+
/** True if the shape should be filled, false if only stroked. */
|
|
15
|
+
filled: boolean;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* A map containing the authoritative handler for each line ending type.
|
|
19
|
+
*/
|
|
20
|
+
export declare const LINE_ENDING_HANDLERS: Partial<Record<PdfAnnotationLineEnding, LineEndingHandler>>;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { PdfAnnotationLineEnding } from '@embedpdf/models';
|
|
2
|
+
export interface SvgEnding {
|
|
3
|
+
d: string;
|
|
4
|
+
transform: string;
|
|
5
|
+
filled: boolean;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Factory that returns SVG path data and transform attributes for a given line ending.
|
|
9
|
+
* It uses a central handler for each ending type to ensure consistency.
|
|
10
|
+
*/
|
|
11
|
+
export declare function createEnding(ending: PdfAnnotationLineEnding | undefined, strokeWidth: number, rad: number, // direction angle in radians of the line segment
|
|
12
|
+
px: number, // x-coordinate of the line's endpoint
|
|
13
|
+
py: number): SvgEnding | null;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { Rect, Position, LineEndings } from '@embedpdf/models';
|
|
2
|
+
/**
|
|
3
|
+
* Computes the exact bounding box for a line or polyline, including its endings and stroke width.
|
|
4
|
+
* This function uses the central `LINE_ENDING_HANDLERS` to ensure calculations are
|
|
5
|
+
* perfectly in sync with the rendering logic.
|
|
6
|
+
*/
|
|
7
|
+
export declare function lineRectWithEndings(vertices: Position[], strokeWidth: number, endings: LineEndings | undefined): Rect;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { Reducer } from '@embedpdf/core';
|
|
2
|
+
import { AnnotationAction } from './actions';
|
|
3
|
+
import { AnnotationPluginConfig, AnnotationState } from './types';
|
|
4
|
+
export declare const initialState: (cfg: AnnotationPluginConfig) => AnnotationState;
|
|
5
|
+
export declare const reducer: Reducer<AnnotationState, AnnotationAction>;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { AnnotationDefaults, AnnotationState, SelectedAnnotation } from './types';
|
|
2
|
+
/** All annotations _objects_ on a single page (order preserved). */
|
|
3
|
+
export declare const getAnnotationsByPageIndex: (s: AnnotationState, page: number) => import('./types').TrackedAnnotation<import('@embedpdf/models').PdfAnnotationObject>[];
|
|
4
|
+
/** Shortcut: every page → list of annotation objects. */
|
|
5
|
+
export declare const getAnnotations: (s: AnnotationState) => Record<number, import('./types').TrackedAnnotation<import('@embedpdf/models').PdfAnnotationObject>[]>;
|
|
6
|
+
/** The full `TrackedAnnotation` for the current selection. */
|
|
7
|
+
export declare const getSelectedAnnotation: (s: AnnotationState) => import('./types').TrackedAnnotation<import('@embedpdf/models').PdfAnnotationObject> | null;
|
|
8
|
+
export declare const getSelectedAnnotationWithPageIndex: (s: AnnotationState) => SelectedAnnotation | null;
|
|
9
|
+
export declare const getSelectedAnnotationByPageIndex: (s: AnnotationState, pageIndex: number) => import('./types').TrackedAnnotation<import('@embedpdf/models').PdfAnnotationObject> | null;
|
|
10
|
+
export declare const isInAnnotationVariant: (s: AnnotationState) => boolean;
|
|
11
|
+
export declare const getSelectedAnnotationVariant: (s: AnnotationState) => string | null;
|
|
12
|
+
/** Check if a given anno on a page is the current selection. */
|
|
13
|
+
export declare const isAnnotationSelected: (s: AnnotationState, page: number, id: number) => boolean;
|
|
14
|
+
/**
|
|
15
|
+
* Return the tool-defaults for a given subtype and (optionally) intent.
|
|
16
|
+
* If the exact variant (subtype + intent) is not present, it gracefully
|
|
17
|
+
* falls back to the plain subtype variant.
|
|
18
|
+
*
|
|
19
|
+
* The return type is inferred so that you always get the concrete default
|
|
20
|
+
* interface for the supplied subtype (e.g. `InkDefaults` for `INK`,
|
|
21
|
+
* `CircleDefaults` for `CIRCLE`, …).
|
|
22
|
+
*/
|
|
23
|
+
export declare function getToolDefaultsBySubtypeAndIntent<S extends AnnotationState, TSub extends AnnotationDefaults['subtype']>(state: S, subtype: TSub, intent?: string | null): Extract<AnnotationDefaults, {
|
|
24
|
+
subtype: TSub;
|
|
25
|
+
}>;
|