@embedpdf/plugin-annotation 2.9.0 → 2.10.0

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.
Files changed (77) hide show
  1. package/dist/index.cjs +1 -1
  2. package/dist/index.cjs.map +1 -1
  3. package/dist/index.js +3082 -2656
  4. package/dist/index.js.map +1 -1
  5. package/dist/lib/actions.d.ts +25 -6
  6. package/dist/lib/annotation-plugin.d.ts +15 -12
  7. package/dist/lib/handlers/index.d.ts +1 -0
  8. package/dist/lib/handlers/link.handler.d.ts +3 -0
  9. package/dist/lib/handlers/types.d.ts +9 -1
  10. package/dist/lib/helpers.d.ts +12 -5
  11. package/dist/lib/index.d.ts +4 -0
  12. package/dist/lib/reducer.d.ts +1 -1
  13. package/dist/lib/tools/default-tools.d.ts +149 -299
  14. package/dist/lib/tools/tools-utils.d.ts +448 -22
  15. package/dist/lib/tools/types.d.ts +37 -2
  16. package/dist/lib/types.d.ts +108 -24
  17. package/dist/preact/index.cjs +1 -1
  18. package/dist/preact/index.cjs.map +1 -1
  19. package/dist/preact/index.js +213 -92
  20. package/dist/preact/index.js.map +1 -1
  21. package/dist/react/index.cjs +1 -1
  22. package/dist/react/index.cjs.map +1 -1
  23. package/dist/react/index.js +213 -92
  24. package/dist/react/index.js.map +1 -1
  25. package/dist/shared/components/annotation-navigation-handler.d.ts +1 -0
  26. package/dist/shared/components/annotations/link-locked.d.ts +3 -0
  27. package/dist/shared/components/annotations/stamp.d.ts +1 -1
  28. package/dist/shared/components/preview-renderer.d.ts +4 -3
  29. package/dist/shared/components/types.d.ts +21 -4
  30. package/dist/shared/hooks/index.d.ts +1 -0
  31. package/dist/shared/hooks/use-annotation.d.ts +2 -2
  32. package/dist/shared/hooks/use-ios-zoom-prevention.d.ts +16 -0
  33. package/dist/shared-preact/components/annotation-navigation-handler.d.ts +1 -0
  34. package/dist/shared-preact/components/annotations/link-locked.d.ts +3 -0
  35. package/dist/shared-preact/components/annotations/stamp.d.ts +1 -1
  36. package/dist/shared-preact/components/preview-renderer.d.ts +4 -3
  37. package/dist/shared-preact/components/types.d.ts +21 -4
  38. package/dist/shared-preact/hooks/index.d.ts +1 -0
  39. package/dist/shared-preact/hooks/use-annotation.d.ts +2 -2
  40. package/dist/shared-preact/hooks/use-ios-zoom-prevention.d.ts +15 -0
  41. package/dist/shared-react/components/annotation-navigation-handler.d.ts +1 -0
  42. package/dist/shared-react/components/annotations/link-locked.d.ts +3 -0
  43. package/dist/shared-react/components/annotations/stamp.d.ts +1 -1
  44. package/dist/shared-react/components/preview-renderer.d.ts +4 -3
  45. package/dist/shared-react/components/types.d.ts +21 -4
  46. package/dist/shared-react/hooks/index.d.ts +1 -0
  47. package/dist/shared-react/hooks/use-annotation.d.ts +2 -2
  48. package/dist/shared-react/hooks/use-ios-zoom-prevention.d.ts +16 -0
  49. package/dist/svelte/components/AnnotationNavigationHandler.svelte.d.ts +3 -0
  50. package/dist/svelte/components/PreviewRenderer.svelte.d.ts +3 -2
  51. package/dist/svelte/components/annotations/LinkLockedMode.svelte.d.ts +5 -0
  52. package/dist/svelte/components/annotations/LinkPreview.svelte.d.ts +10 -0
  53. package/dist/svelte/components/annotations/Stamp.svelte.d.ts +1 -1
  54. package/dist/svelte/context/renderer-registry.svelte.d.ts +1 -1
  55. package/dist/svelte/context/types.d.ts +20 -3
  56. package/dist/svelte/hooks/index.d.ts +1 -0
  57. package/dist/svelte/hooks/use-annotation.svelte.d.ts +1 -1
  58. package/dist/svelte/hooks/use-ios-zoom-prevention.svelte.d.ts +6 -0
  59. package/dist/svelte/index.cjs +1 -1
  60. package/dist/svelte/index.cjs.map +1 -1
  61. package/dist/svelte/index.js +422 -234
  62. package/dist/svelte/index.js.map +1 -1
  63. package/dist/vue/components/annotation-navigation-handler.vue.d.ts +3 -0
  64. package/dist/vue/components/annotations/link-locked.vue.d.ts +5 -0
  65. package/dist/vue/components/annotations/link-preview.vue.d.ts +10 -0
  66. package/dist/vue/components/annotations/stamp.vue.d.ts +2 -2
  67. package/dist/vue/components/preview-renderer.vue.d.ts +3 -2
  68. package/dist/vue/context/renderer-registry.d.ts +1 -1
  69. package/dist/vue/context/types.d.ts +20 -3
  70. package/dist/vue/hooks/index.d.ts +1 -0
  71. package/dist/vue/hooks/use-annotation.d.ts +24 -2
  72. package/dist/vue/hooks/use-ios-zoom-prevention.d.ts +7 -0
  73. package/dist/vue/index.cjs +1 -1
  74. package/dist/vue/index.cjs.map +1 -1
  75. package/dist/vue/index.js +433 -277
  76. package/dist/vue/index.js.map +1 -1
  77. package/package.json +12 -10
@@ -1,7 +1,7 @@
1
1
  import { Action } from '@embedpdf/core';
2
2
  import { PdfAnnotationObject } from '@embedpdf/models';
3
3
  import { AnnotationTool } from './tools/types';
4
- import { AnnotationDocumentState } from './types';
4
+ import { AnnotationDocumentState, LockMode } from './types';
5
5
  export declare const INIT_ANNOTATION_STATE = "ANNOTATION/INIT_STATE";
6
6
  export declare const CLEANUP_ANNOTATION_STATE = "ANNOTATION/CLEANUP_STATE";
7
7
  export declare const SET_ACTIVE_DOCUMENT = "ANNOTATION/SET_ACTIVE_DOCUMENT";
@@ -18,6 +18,8 @@ export declare const MOVE_ANNOTATION = "ANNOTATION/MOVE_ANNOTATION";
18
18
  export declare const DELETE_ANNOTATION = "ANNOTATION/DELETE_ANNOTATION";
19
19
  export declare const COMMIT_PENDING_CHANGES = "ANNOTATION/COMMIT";
20
20
  export declare const PURGE_ANNOTATION = "ANNOTATION/PURGE_ANNOTATION";
21
+ export declare const SET_LOCKED = "ANNOTATION/SET_LOCKED";
22
+ export declare const SYNC_ANNOTATION_OBJECT = "ANNOTATION/SYNC_OBJECT";
21
23
  export declare const ADD_COLOR_PRESET = "ANNOTATION/ADD_COLOR_PRESET";
22
24
  export declare const SET_TOOL_DEFAULTS = "ANNOTATION/SET_TOOL_DEFAULTS";
23
25
  export declare const ADD_TOOL = "ANNOTATION/ADD_TOOL";
@@ -135,6 +137,21 @@ export interface PurgeAnnotationAction extends Action {
135
137
  uid: string;
136
138
  };
137
139
  }
140
+ export interface SetLockedAction extends Action {
141
+ type: typeof SET_LOCKED;
142
+ payload: {
143
+ documentId: string;
144
+ mode: LockMode;
145
+ };
146
+ }
147
+ export interface SyncAnnotationObjectAction extends Action {
148
+ type: typeof SYNC_ANNOTATION_OBJECT;
149
+ payload: {
150
+ documentId: string;
151
+ id: string;
152
+ patch: Partial<PdfAnnotationObject>;
153
+ };
154
+ }
138
155
  export interface AddColorPresetAction extends Action {
139
156
  type: typeof ADD_COLOR_PRESET;
140
157
  payload: string;
@@ -143,14 +160,14 @@ export interface SetToolDefaultsAction extends Action {
143
160
  type: typeof SET_TOOL_DEFAULTS;
144
161
  payload: {
145
162
  toolId: string;
146
- patch: Partial<any>;
163
+ patch: Partial<PdfAnnotationObject> & Record<string, unknown>;
147
164
  };
148
165
  }
149
166
  export interface AddToolAction extends Action {
150
167
  type: typeof ADD_TOOL;
151
- payload: AnnotationTool;
168
+ payload: AnnotationTool<any>;
152
169
  }
153
- export type AnnotationAction = InitAnnotationStateAction | CleanupAnnotationStateAction | SetActiveDocumentAction | SetAnnotationsAction | SelectAnnotationAction | DeselectAnnotationAction | AddToSelectionAction | RemoveFromSelectionAction | SetSelectionAction | SetActiveToolIdAction | CreateAnnotationAction | PatchAnnotationAction | MoveAnnotationAction | DeleteAnnotationAction | CommitAction | PurgeAnnotationAction | AddColorPresetAction | SetToolDefaultsAction | AddToolAction;
170
+ export type AnnotationAction = InitAnnotationStateAction | CleanupAnnotationStateAction | SetActiveDocumentAction | SetAnnotationsAction | SelectAnnotationAction | DeselectAnnotationAction | AddToSelectionAction | RemoveFromSelectionAction | SetSelectionAction | SetActiveToolIdAction | CreateAnnotationAction | PatchAnnotationAction | MoveAnnotationAction | DeleteAnnotationAction | CommitAction | PurgeAnnotationAction | SetLockedAction | SyncAnnotationObjectAction | AddColorPresetAction | SetToolDefaultsAction | AddToolAction;
154
171
  export declare function initAnnotationState(documentId: string, state: AnnotationDocumentState): InitAnnotationStateAction;
155
172
  export declare function cleanupAnnotationState(documentId: string): CleanupAnnotationStateAction;
156
173
  export declare function setActiveDocument(documentId: string | null): SetActiveDocumentAction;
@@ -167,6 +184,8 @@ export declare const moveAnnotation: (documentId: string, pageIndex: number, id:
167
184
  export declare const deleteAnnotation: (documentId: string, pageIndex: number, id: string) => DeleteAnnotationAction;
168
185
  export declare const commitPendingChanges: (documentId: string, committedUids: string[]) => CommitAction;
169
186
  export declare const purgeAnnotation: (documentId: string, pageIndex: number, uid: string) => PurgeAnnotationAction;
187
+ export declare const setLockedAction: (documentId: string, mode: LockMode) => SetLockedAction;
188
+ export declare const syncAnnotationObject: (documentId: string, id: string, patch: Partial<PdfAnnotationObject>) => SyncAnnotationObjectAction;
170
189
  export declare const addColorPreset: (c: string) => AddColorPresetAction;
171
- export declare const setToolDefaults: (toolId: string, patch: Partial<any>) => SetToolDefaultsAction;
172
- export declare const addTool: (tool: AnnotationTool) => AddToolAction;
190
+ export declare const setToolDefaults: (toolId: string, patch: Partial<PdfAnnotationObject> & Record<string, unknown>) => SetToolDefaultsAction;
191
+ export declare const addTool: (tool: AnnotationTool<any>) => AddToolAction;
@@ -1,9 +1,9 @@
1
1
  import { BasePlugin, PluginRegistry } from '@embedpdf/core';
2
2
  import { PdfAnnotationObject, Position, Rect } from '@embedpdf/models';
3
- import { AnnotationCapability, AnnotationPluginConfig, AnnotationState, UnifiedDragOptions, UnifiedDragState, UnifiedDragEvent, UnifiedResizeOptions, UnifiedResizeState, UnifiedResizeEvent, UnifiedRotateOptions, UnifiedRotateState, UnifiedRotateEvent } from './types';
3
+ import { AnnotationCapability, AnnotationPluginConfig, AnnotationState, UnifiedDragOptions, UnifiedDragState, UnifiedDragEvent, UnifiedResizeOptions, UnifiedResizeState, UnifiedResizeEvent, UnifiedRotateOptions, UnifiedRotateState, UnifiedRotateEvent, LockMode } from './types';
4
4
  import { AnnotationAction } from './actions';
5
- import { AnnotationTool } from './tools/types';
6
- import { AnyPreviewState, HandlerServices } from './handlers/types';
5
+ import { AnnotationTool, AnnotationToolMap, ToolById, ToolId } from './tools/types';
6
+ import { PreviewState, HandlerServices } from './handlers/types';
7
7
  export declare class AnnotationPlugin extends BasePlugin<AnnotationPluginConfig, AnnotationCapability, AnnotationState, AnnotationAction> {
8
8
  static readonly id: "annotation";
9
9
  private readonly ANNOTATION_HISTORY_TOPIC;
@@ -12,16 +12,14 @@ export declare class AnnotationPlugin extends BasePlugin<AnnotationPluginConfig,
12
12
  private readonly interactionManager;
13
13
  private readonly selection;
14
14
  private readonly history;
15
+ private readonly scroll;
15
16
  private pendingContexts;
16
17
  private isInitialLoadComplete;
17
18
  private importQueue;
18
19
  private commitInProgress;
19
- private handlerFactories;
20
- private selectionHandlerFactories;
21
20
  private readonly activeTool$;
22
21
  private readonly events$;
23
22
  private readonly toolsChange$;
24
- private readonly patchRegistry;
25
23
  private readonly appearanceCache;
26
24
  private readonly unifiedDragStates;
27
25
  private readonly unifiedDrag$;
@@ -29,23 +27,20 @@ export declare class AnnotationPlugin extends BasePlugin<AnnotationPluginConfig,
29
27
  private readonly unifiedResize$;
30
28
  private readonly unifiedRotateStates;
31
29
  private readonly unifiedRotate$;
30
+ private readonly navigate$;
32
31
  constructor(id: string, registry: PluginRegistry, config: AnnotationPluginConfig);
33
32
  protected onDocumentLoadingStarted(documentId: string): void;
34
33
  protected onDocumentLoaded(documentId: string): void;
35
34
  protected onDocumentClosed(documentId: string): void;
36
- private registerHandlerFactories;
37
- private registerSelectionHandlerFactories;
38
- private registerBuiltInPatches;
39
35
  initialize(): Promise<void>;
40
36
  private registerInteractionForTool;
41
37
  protected buildCapability(): AnnotationCapability;
42
38
  private createAnnotationScope;
43
39
  onStoreUpdated(prev: AnnotationState, next: AnnotationState): void;
44
- private registerPatchFunction;
45
40
  private transformAnnotation;
46
41
  registerPageHandlers(documentId: string, pageIndex: number, scale: number, callbacks: {
47
42
  services: HandlerServices;
48
- onPreview: (toolId: string, state: AnyPreviewState | null) => void;
43
+ onPreview: (toolId: string, state: PreviewState | null) => void;
49
44
  }): () => void;
50
45
  private getDocumentState;
51
46
  private getAllAnnotations;
@@ -248,8 +243,16 @@ export declare class AnnotationPlugin extends BasePlugin<AnnotationPluginConfig,
248
243
  private moveAnnotationMethod;
249
244
  getActiveTool(documentId?: string): AnnotationTool | null;
250
245
  setActiveTool(toolId: string | null, documentId?: string): void;
251
- getTool<T extends AnnotationTool>(toolId: string): T | undefined;
246
+ getTool<TId extends ToolId<AnnotationToolMap>>(toolId: TId): (ToolById<AnnotationToolMap, TId> & AnnotationTool) | undefined;
247
+ getTool(toolId: string): AnnotationTool | undefined;
252
248
  findToolForAnnotation(annotation: PdfAnnotationObject): AnnotationTool | null;
249
+ setLocked(mode: LockMode, documentId?: string): void;
250
+ getLocked(documentId?: string): LockMode;
251
+ isAnnotationLocked(annotation: PdfAnnotationObject, documentId?: string): boolean;
252
+ isCategoryLockedMethod(category: string, documentId?: string): boolean;
253
+ isToolLockedMethod(toolId: string, documentId?: string): boolean;
254
+ syncAnnotationObject(id: string, patch: Partial<PdfAnnotationObject>, documentId?: string): void;
255
+ private navigateTargetMethod;
253
256
  /**
254
257
  * Collects all pending annotation changes for a document into a batch.
255
258
  * This separates the "what to commit" from "how to commit" for cleaner code.
@@ -7,6 +7,7 @@ export * from './polygon.handler';
7
7
  export * from './square.handler';
8
8
  export * from './stamp.handler';
9
9
  export * from './circle.handler';
10
+ export * from './link.handler';
10
11
  export * from './text-markup.handler';
11
12
  export * from './insert-text.handler';
12
13
  export * from './replace-text.handler';
@@ -0,0 +1,3 @@
1
+ import { PdfLinkAnnoObject } from '@embedpdf/models';
2
+ import { HandlerFactory } from './types';
3
+ export declare const linkHandlerFactory: HandlerFactory<PdfLinkAnnoObject>;
@@ -67,6 +67,13 @@ export interface FreeTextPreviewData {
67
67
  verticalAlign?: PdfVerticalAlignment;
68
68
  contents?: string;
69
69
  }
70
+ export interface LinkPreviewData {
71
+ rect: Rect;
72
+ strokeColor: string;
73
+ strokeWidth: number;
74
+ strokeStyle: PdfAnnotationBorderStyle;
75
+ strokeDashArray: number[];
76
+ }
70
77
  /**
71
78
  * Map types to their preview data
72
79
  */
@@ -78,6 +85,7 @@ export interface PreviewDataMap {
78
85
  [PdfAnnotationSubtype.LINE]: LinePreviewData;
79
86
  [PdfAnnotationSubtype.INK]: InkPreviewData;
80
87
  [PdfAnnotationSubtype.FREETEXT]: FreeTextPreviewData;
88
+ [PdfAnnotationSubtype.LINK]: LinkPreviewData;
81
89
  }
82
90
  /**
83
91
  * Typed preview state - constrain T to keys that exist in PreviewDataMap
@@ -137,7 +145,7 @@ export interface HandlerContext<A extends PdfAnnotationObject> {
137
145
  pageRotation: Rotation;
138
146
  scale: number;
139
147
  services: HandlerServices;
140
- onPreview: (state: AnyPreviewState | null) => void;
148
+ onPreview: (state: PreviewState<A['type']> | null) => void;
141
149
  onCommit: (annotation: A, context?: AnnotationCreateContext<A>) => void;
142
150
  }
143
151
  export interface SelectionHandlerContext<A extends PdfAnnotationObject = PdfAnnotationObject> {
@@ -1,12 +1,11 @@
1
- import { PdfAnnotationSubtype, PdfAnnotationObject, Rect } from '@embedpdf/models';
2
- import { TrackedAnnotation } from './types';
1
+ import { PdfAnnotationSubtype, PdfAnnotationObject, PdfAnnotationOf, Rect } from '@embedpdf/models';
2
+ import { LockMode, TrackedAnnotation } from './types';
3
+ import { AnnotationTool } from './tools/types';
3
4
  /**
4
5
  * Check if two rectangles intersect
5
6
  */
6
7
  export declare function rectsIntersect(a: Rect, b: Rect): boolean;
7
- export type AnnoOf<S extends PdfAnnotationSubtype> = Extract<PdfAnnotationObject, {
8
- type: S;
9
- }>;
8
+ export type AnnoOf<S extends PdfAnnotationSubtype> = PdfAnnotationOf<S>;
10
9
  export type TextMarkupSubtype = PdfAnnotationSubtype.HIGHLIGHT | PdfAnnotationSubtype.UNDERLINE | PdfAnnotationSubtype.STRIKEOUT | PdfAnnotationSubtype.SQUIGGLY;
11
10
  export type SidebarSubtype = TextMarkupSubtype | PdfAnnotationSubtype.TEXT | PdfAnnotationSubtype.INK | PdfAnnotationSubtype.SQUARE | PdfAnnotationSubtype.CIRCLE | PdfAnnotationSubtype.POLYGON | PdfAnnotationSubtype.LINE | PdfAnnotationSubtype.POLYLINE | PdfAnnotationSubtype.FREETEXT | PdfAnnotationSubtype.STAMP | PdfAnnotationSubtype.REDACT | PdfAnnotationSubtype.CARET;
12
11
  /** True when `a.object.type === INK` – and narrows the generic. */
@@ -28,4 +27,12 @@ export declare function isText(a: TrackedAnnotation): a is TrackedAnnotation<Ann
28
27
  export declare function isLink(a: TrackedAnnotation): a is TrackedAnnotation<AnnoOf<PdfAnnotationSubtype.LINK>>;
29
28
  export declare function isRedact(a: TrackedAnnotation): a is TrackedAnnotation<AnnoOf<PdfAnnotationSubtype.REDACT>>;
30
29
  export declare function isCaret(a: TrackedAnnotation): a is TrackedAnnotation<AnnoOf<PdfAnnotationSubtype.CARET>>;
30
+ export declare function isWidget(a: TrackedAnnotation): a is TrackedAnnotation<AnnoOf<PdfAnnotationSubtype.WIDGET>>;
31
31
  export declare function isSidebarAnnotation(a: TrackedAnnotation): a is TrackedAnnotation<AnnoOf<SidebarSubtype>>;
32
+ export declare function isSelectableAnnotation(a: TrackedAnnotation): boolean;
33
+ /** Extract the category tags from a tool (returns `[]` for uncategorized). */
34
+ export declare function getAnnotationCategories(tool: AnnotationTool | null): string[];
35
+ /** Check if the category-based LockMode locks annotations with these categories. */
36
+ export declare function isCategoryLocked(categories: string[], mode: LockMode): boolean;
37
+ /** Check if the annotation itself has the PDF 'locked' flag (bit 7). */
38
+ export declare function hasLockedFlag(annotation: PdfAnnotationObject): boolean;
@@ -10,7 +10,11 @@ export * from './selectors';
10
10
  export * from './helpers';
11
11
  export * from './handlers/types';
12
12
  export * from './tools/types';
13
+ export type { DefaultAnnotationTool, DefaultAnnotationToolMap } from './tools/default-tools';
13
14
  export * from './tools/tools-utils';
14
15
  export * from './geometry';
15
16
  export * as patching from './patching';
17
+ export type { PatchFunction, TransformContext } from './patching/patch-registry';
16
18
  export { initialState, initialDocumentState } from './reducer';
19
+ export { useState } from './utils/use-state';
20
+ export { useClickDetector } from './handlers/click-detector';
@@ -1,6 +1,6 @@
1
1
  import { Reducer } from '@embedpdf/core';
2
2
  import { AnnotationAction } from './actions';
3
3
  import { AnnotationPluginConfig, AnnotationState, AnnotationDocumentState } from './types';
4
- export declare const initialDocumentState: () => AnnotationDocumentState;
4
+ export declare const initialDocumentState: (cfg?: AnnotationPluginConfig) => AnnotationDocumentState;
5
5
  export declare const initialState: (cfg: AnnotationPluginConfig) => AnnotationState;
6
6
  export declare const reducer: Reducer<AnnotationState, AnnotationAction>;