@embedpdf/plugin-annotation 2.10.0 → 2.11.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 (49) hide show
  1. package/dist/index.cjs +1 -1
  2. package/dist/index.cjs.map +1 -1
  3. package/dist/index.js +35 -18
  4. package/dist/index.js.map +1 -1
  5. package/dist/lib/actions.d.ts +2 -1
  6. package/dist/lib/annotation-plugin.d.ts +2 -1
  7. package/dist/lib/handlers/types.d.ts +17 -5
  8. package/dist/lib/index.d.ts +1 -0
  9. package/dist/lib/tools/default-tools.d.ts +12 -12
  10. package/dist/lib/tools/tools-utils.d.ts +9 -9
  11. package/dist/lib/tools/types.d.ts +1 -1
  12. package/dist/lib/types.d.ts +5 -4
  13. package/dist/preact/index.cjs +1 -1
  14. package/dist/preact/index.cjs.map +1 -1
  15. package/dist/preact/index.js +48 -45
  16. package/dist/preact/index.js.map +1 -1
  17. package/dist/react/index.cjs +1 -1
  18. package/dist/react/index.cjs.map +1 -1
  19. package/dist/react/index.js +48 -45
  20. package/dist/react/index.js.map +1 -1
  21. package/dist/shared/components/types.d.ts +19 -5
  22. package/dist/shared-preact/components/types.d.ts +19 -5
  23. package/dist/shared-react/components/types.d.ts +19 -5
  24. package/dist/svelte/components/annotations/CirclePreview.svelte.d.ts +10 -0
  25. package/dist/svelte/components/annotations/FreeTextPreview.svelte.d.ts +10 -0
  26. package/dist/svelte/components/annotations/InkPreview.svelte.d.ts +10 -0
  27. package/dist/svelte/components/annotations/LinePreview.svelte.d.ts +10 -0
  28. package/dist/svelte/components/annotations/PolygonPreview.svelte.d.ts +10 -0
  29. package/dist/svelte/components/annotations/PolylinePreview.svelte.d.ts +10 -0
  30. package/dist/svelte/components/annotations/SquarePreview.svelte.d.ts +10 -0
  31. package/dist/svelte/context/types.d.ts +19 -5
  32. package/dist/svelte/index.cjs +1 -1
  33. package/dist/svelte/index.cjs.map +1 -1
  34. package/dist/svelte/index.js +247 -425
  35. package/dist/svelte/index.js.map +1 -1
  36. package/dist/vue/components/annotations/circle-preview.vue.d.ts +10 -0
  37. package/dist/vue/components/annotations/free-text-preview.vue.d.ts +10 -0
  38. package/dist/vue/components/annotations/ink-preview.vue.d.ts +10 -0
  39. package/dist/vue/components/annotations/line-preview.vue.d.ts +10 -0
  40. package/dist/vue/components/annotations/polygon-preview.vue.d.ts +10 -0
  41. package/dist/vue/components/annotations/polyline-preview.vue.d.ts +10 -0
  42. package/dist/vue/components/annotations/square-preview.vue.d.ts +10 -0
  43. package/dist/vue/context/types.d.ts +19 -5
  44. package/dist/vue/hooks/use-annotation.d.ts +2 -0
  45. package/dist/vue/index.cjs +1 -1
  46. package/dist/vue/index.cjs.map +1 -1
  47. package/dist/vue/index.js +279 -163
  48. package/dist/vue/index.js.map +1 -1
  49. package/package.json +12 -12
@@ -86,6 +86,7 @@ export interface SetActiveToolIdAction extends Action {
86
86
  payload: {
87
87
  documentId: string;
88
88
  toolId: string | null;
89
+ context?: Record<string, unknown>;
89
90
  };
90
91
  }
91
92
  export interface CreateAnnotationAction extends Action {
@@ -177,7 +178,7 @@ export declare const deselectAnnotation: (documentId: string) => DeselectAnnotat
177
178
  export declare const addToSelection: (documentId: string, pageIndex: number, id: string) => AddToSelectionAction;
178
179
  export declare const removeFromSelection: (documentId: string, id: string) => RemoveFromSelectionAction;
179
180
  export declare const setSelection: (documentId: string, ids: string[]) => SetSelectionAction;
180
- export declare const setActiveToolId: (documentId: string, toolId: string | null) => SetActiveToolIdAction;
181
+ export declare const setActiveToolId: (documentId: string, toolId: string | null, context?: Record<string, unknown>) => SetActiveToolIdAction;
181
182
  export declare const createAnnotation: (documentId: string, pageIndex: number, annotation: PdfAnnotationObject) => CreateAnnotationAction;
182
183
  export declare const patchAnnotation: (documentId: string, pageIndex: number, id: string, patch: Partial<PdfAnnotationObject>) => PatchAnnotationAction;
183
184
  export declare const moveAnnotation: (documentId: string, pageIndex: number, id: string, patch: Partial<PdfAnnotationObject>) => MoveAnnotationAction;
@@ -7,6 +7,7 @@ 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;
10
+ private static readonly defaultHandlerFactories;
10
11
  readonly config: AnnotationPluginConfig;
11
12
  private readonly state$;
12
13
  private readonly interactionManager;
@@ -242,7 +243,7 @@ export declare class AnnotationPlugin extends BasePlugin<AnnotationPluginConfig,
242
243
  private moveAnnotationsMethod;
243
244
  private moveAnnotationMethod;
244
245
  getActiveTool(documentId?: string): AnnotationTool | null;
245
- setActiveTool(toolId: string | null, documentId?: string): void;
246
+ setActiveTool(toolId: string | null, documentId?: string, context?: Record<string, unknown>): void;
246
247
  getTool<TId extends ToolId<AnnotationToolMap>>(toolId: TId): (ToolById<AnnotationToolMap, TId> & AnnotationTool) | undefined;
247
248
  getTool(toolId: string): AnnotationTool | undefined;
248
249
  findToolForAnnotation(annotation: PdfAnnotationObject): AnnotationTool | null;
@@ -11,7 +11,7 @@ export interface CirclePreviewData {
11
11
  strokeStyle: PdfAnnotationBorderStyle;
12
12
  strokeDashArray: number[];
13
13
  }
14
- interface SquarePreviewData extends CirclePreviewData {
14
+ export interface SquarePreviewData extends CirclePreviewData {
15
15
  }
16
16
  export interface PolygonPreviewData {
17
17
  rect: Rect;
@@ -129,16 +129,29 @@ export interface HandlerServices {
129
129
  }) => void;
130
130
  }): void;
131
131
  }
132
+ /**
133
+ * Extensible map from tool ID to per-activation context data.
134
+ * Plugins extend this via declaration merging to provide typed context
135
+ * for their custom tools (e.g. stamp appearance data, ghost image URL).
136
+ */
137
+ export interface ToolContextMap {
138
+ }
139
+ /**
140
+ * Resolves the tool context type for a given tool ID.
141
+ * Returns the mapped type if known, otherwise a generic record.
142
+ */
143
+ export type ResolvedToolContext<TId extends string> = TId extends keyof ToolContextMap ? ToolContextMap[TId] : Record<string, unknown>;
132
144
  /**
133
145
  * The context object passed to a handler factory when creating a handler.
134
146
  * It contains all the necessary information and callbacks.
135
147
  */
136
- export interface HandlerFactory<A extends PdfAnnotationObject> {
148
+ export interface HandlerFactory<A extends PdfAnnotationObject, TId extends string = string> {
137
149
  annotationType: PdfAnnotationSubtype;
138
- create(context: HandlerContext<A>): PointerEventHandlersWithLifecycle;
150
+ create(context: HandlerContext<A, TId>): PointerEventHandlersWithLifecycle;
139
151
  }
140
- export interface HandlerContext<A extends PdfAnnotationObject> {
152
+ export interface HandlerContext<A extends PdfAnnotationObject, TId extends string = string> {
141
153
  getTool: () => AnnotationTool<A> | undefined;
154
+ getToolContext: () => ResolvedToolContext<TId> | undefined;
142
155
  pageIndex: number;
143
156
  pageSize: Size;
144
157
  /** Effective page rotation (page intrinsic + document rotation), as a quarter-turn value (0-3). */
@@ -159,4 +172,3 @@ export interface SelectionHandlerFactory<A extends PdfAnnotationObject = PdfAnno
159
172
  toolId: string;
160
173
  handle(context: SelectionHandlerContext<A>, selections: FormattedSelection[], getText: () => Promise<string | undefined>): void;
161
174
  }
162
- export {};
@@ -15,6 +15,7 @@ export * from './tools/tools-utils';
15
15
  export * from './geometry';
16
16
  export * as patching from './patching';
17
17
  export type { PatchFunction, TransformContext } from './patching/patch-registry';
18
+ export * from './patching/insert-upright';
18
19
  export { initialState, initialDocumentState } from './reducer';
19
20
  export { useState } from './utils/use-state';
20
21
  export { useClickDetector } from './handlers/click-detector';
@@ -162,7 +162,7 @@ export declare const defaultTools: ({
162
162
  smartLineThreshold?: undefined;
163
163
  };
164
164
  transform: import('..').PatchFunction<import('@embedpdf/models').PdfInkAnnoObject>;
165
- pointerHandler: import('..').HandlerFactory<import('@embedpdf/models').PdfInkAnnoObject>;
165
+ pointerHandler: import('..').HandlerFactory<import('@embedpdf/models').PdfInkAnnoObject, string>;
166
166
  } | {
167
167
  id: "inkHighlighter";
168
168
  name: string;
@@ -192,7 +192,7 @@ export declare const defaultTools: ({
192
192
  smartLineThreshold: number;
193
193
  };
194
194
  transform: import('..').PatchFunction<import('@embedpdf/models').PdfInkAnnoObject>;
195
- pointerHandler: import('..').HandlerFactory<import('@embedpdf/models').PdfInkAnnoObject>;
195
+ pointerHandler: import('..').HandlerFactory<import('@embedpdf/models').PdfInkAnnoObject, string>;
196
196
  } | {
197
197
  id: "circle";
198
198
  name: string;
@@ -223,7 +223,7 @@ export declare const defaultTools: ({
223
223
  };
224
224
  };
225
225
  transform: import('..').PatchFunction<import('@embedpdf/models').PdfCircleAnnoObject>;
226
- pointerHandler: import('..').HandlerFactory<import('@embedpdf/models').PdfCircleAnnoObject>;
226
+ pointerHandler: import('..').HandlerFactory<import('@embedpdf/models').PdfCircleAnnoObject, string>;
227
227
  } | {
228
228
  id: "square";
229
229
  name: string;
@@ -254,7 +254,7 @@ export declare const defaultTools: ({
254
254
  };
255
255
  };
256
256
  transform: import('..').PatchFunction<import('@embedpdf/models').PdfSquareAnnoObject>;
257
- pointerHandler: import('..').HandlerFactory<import('@embedpdf/models').PdfSquareAnnoObject>;
257
+ pointerHandler: import('..').HandlerFactory<import('@embedpdf/models').PdfSquareAnnoObject, string>;
258
258
  } | {
259
259
  id: "line";
260
260
  name: string;
@@ -285,7 +285,7 @@ export declare const defaultTools: ({
285
285
  defaultAngle: number;
286
286
  };
287
287
  transform: import('..').PatchFunction<import('@embedpdf/models').PdfLineAnnoObject>;
288
- pointerHandler: import('..').HandlerFactory<import('@embedpdf/models').PdfLineAnnoObject>;
288
+ pointerHandler: import('..').HandlerFactory<import('@embedpdf/models').PdfLineAnnoObject, string>;
289
289
  } | {
290
290
  id: "lineArrow";
291
291
  name: string;
@@ -319,7 +319,7 @@ export declare const defaultTools: ({
319
319
  defaultAngle: number;
320
320
  };
321
321
  transform: import('..').PatchFunction<import('@embedpdf/models').PdfLineAnnoObject>;
322
- pointerHandler: import('..').HandlerFactory<import('@embedpdf/models').PdfLineAnnoObject>;
322
+ pointerHandler: import('..').HandlerFactory<import('@embedpdf/models').PdfLineAnnoObject, string>;
323
323
  } | {
324
324
  id: "polyline";
325
325
  name: string;
@@ -343,7 +343,7 @@ export declare const defaultTools: ({
343
343
  strokeColor: string;
344
344
  };
345
345
  transform: import('..').PatchFunction<import('@embedpdf/models').PdfPolylineAnnoObject>;
346
- pointerHandler: import('..').HandlerFactory<import('@embedpdf/models').PdfPolylineAnnoObject>;
346
+ pointerHandler: import('..').HandlerFactory<import('@embedpdf/models').PdfPolylineAnnoObject, string>;
347
347
  } | {
348
348
  id: "polygon";
349
349
  name: string;
@@ -367,7 +367,7 @@ export declare const defaultTools: ({
367
367
  strokeColor: string;
368
368
  };
369
369
  transform: import('..').PatchFunction<import('@embedpdf/models').PdfPolygonAnnoObject>;
370
- pointerHandler: import('..').HandlerFactory<import('@embedpdf/models').PdfPolygonAnnoObject>;
370
+ pointerHandler: import('..').HandlerFactory<import('@embedpdf/models').PdfPolygonAnnoObject, string>;
371
371
  } | {
372
372
  id: "textComment";
373
373
  name: string;
@@ -389,7 +389,7 @@ export declare const defaultTools: ({
389
389
  behavior: {
390
390
  selectAfterCreate: true;
391
391
  };
392
- pointerHandler: import('..').HandlerFactory<import('@embedpdf/models').PdfTextAnnoObject>;
392
+ pointerHandler: import('..').HandlerFactory<import('@embedpdf/models').PdfTextAnnoObject, string>;
393
393
  } | {
394
394
  id: "freeText";
395
395
  name: string;
@@ -430,7 +430,7 @@ export declare const defaultTools: ({
430
430
  selectAfterCreate: true;
431
431
  };
432
432
  transform: import('..').PatchFunction<import('@embedpdf/models').PdfFreeTextAnnoObject>;
433
- pointerHandler: import('..').HandlerFactory<import('@embedpdf/models').PdfFreeTextAnnoObject>;
433
+ pointerHandler: import('..').HandlerFactory<import('@embedpdf/models').PdfFreeTextAnnoObject, string>;
434
434
  } | {
435
435
  id: "stamp";
436
436
  name: string;
@@ -453,7 +453,7 @@ export declare const defaultTools: ({
453
453
  useAppearanceStream: false;
454
454
  };
455
455
  transform: import('..').PatchFunction<import('@embedpdf/models').PdfStampAnnoObject>;
456
- pointerHandler: import('..').HandlerFactory<import('@embedpdf/models').PdfStampAnnoObject>;
456
+ pointerHandler: import('..').HandlerFactory<import('@embedpdf/models').PdfStampAnnoObject, string>;
457
457
  } | {
458
458
  id: "link";
459
459
  name: string;
@@ -480,7 +480,7 @@ export declare const defaultTools: ({
480
480
  height: number;
481
481
  };
482
482
  };
483
- pointerHandler: import('..').HandlerFactory<import('@embedpdf/models').PdfLinkAnnoObject>;
483
+ pointerHandler: import('..').HandlerFactory<import('@embedpdf/models').PdfLinkAnnoObject, string>;
484
484
  })[];
485
485
  export type DefaultAnnotationTool = (typeof defaultTools)[number];
486
486
  export type DefaultAnnotationToolMap = ToolMapFromList<typeof defaultTools>;
@@ -139,7 +139,7 @@ export declare const isInkTool: (tool: {
139
139
  smartLineThreshold?: undefined;
140
140
  };
141
141
  transform: import('..').PatchFunction<import('@embedpdf/models').PdfInkAnnoObject>;
142
- pointerHandler: import('..').HandlerFactory<import('@embedpdf/models').PdfInkAnnoObject>;
142
+ pointerHandler: import('..').HandlerFactory<import('@embedpdf/models').PdfInkAnnoObject, string>;
143
143
  };
144
144
  export declare const isInkHighlighterTool: (tool: {
145
145
  id: string;
@@ -172,7 +172,7 @@ export declare const isInkHighlighterTool: (tool: {
172
172
  smartLineThreshold: number;
173
173
  };
174
174
  transform: import('..').PatchFunction<import('@embedpdf/models').PdfInkAnnoObject>;
175
- pointerHandler: import('..').HandlerFactory<import('@embedpdf/models').PdfInkAnnoObject>;
175
+ pointerHandler: import('..').HandlerFactory<import('@embedpdf/models').PdfInkAnnoObject, string>;
176
176
  };
177
177
  export declare const isSquareTool: (tool: {
178
178
  id: string;
@@ -206,7 +206,7 @@ export declare const isSquareTool: (tool: {
206
206
  };
207
207
  };
208
208
  transform: import('..').PatchFunction<import('@embedpdf/models').PdfSquareAnnoObject>;
209
- pointerHandler: import('..').HandlerFactory<import('@embedpdf/models').PdfSquareAnnoObject>;
209
+ pointerHandler: import('..').HandlerFactory<import('@embedpdf/models').PdfSquareAnnoObject, string>;
210
210
  };
211
211
  export declare const isCircleTool: (tool: {
212
212
  id: string;
@@ -240,7 +240,7 @@ export declare const isCircleTool: (tool: {
240
240
  };
241
241
  };
242
242
  transform: import('..').PatchFunction<import('@embedpdf/models').PdfCircleAnnoObject>;
243
- pointerHandler: import('..').HandlerFactory<import('@embedpdf/models').PdfCircleAnnoObject>;
243
+ pointerHandler: import('..').HandlerFactory<import('@embedpdf/models').PdfCircleAnnoObject, string>;
244
244
  };
245
245
  export declare const isLineTool: (tool: {
246
246
  id: string;
@@ -274,7 +274,7 @@ export declare const isLineTool: (tool: {
274
274
  defaultAngle: number;
275
275
  };
276
276
  transform: import('..').PatchFunction<import('@embedpdf/models').PdfLineAnnoObject>;
277
- pointerHandler: import('..').HandlerFactory<import('@embedpdf/models').PdfLineAnnoObject>;
277
+ pointerHandler: import('..').HandlerFactory<import('@embedpdf/models').PdfLineAnnoObject, string>;
278
278
  };
279
279
  export declare const isPolylineTool: (tool: {
280
280
  id: string;
@@ -301,7 +301,7 @@ export declare const isPolylineTool: (tool: {
301
301
  strokeColor: string;
302
302
  };
303
303
  transform: import('..').PatchFunction<import('@embedpdf/models').PdfPolylineAnnoObject>;
304
- pointerHandler: import('..').HandlerFactory<import('@embedpdf/models').PdfPolylineAnnoObject>;
304
+ pointerHandler: import('..').HandlerFactory<import('@embedpdf/models').PdfPolylineAnnoObject, string>;
305
305
  };
306
306
  export declare const isPolygonTool: (tool: {
307
307
  id: string;
@@ -328,7 +328,7 @@ export declare const isPolygonTool: (tool: {
328
328
  strokeColor: string;
329
329
  };
330
330
  transform: import('..').PatchFunction<import('@embedpdf/models').PdfPolygonAnnoObject>;
331
- pointerHandler: import('..').HandlerFactory<import('@embedpdf/models').PdfPolygonAnnoObject>;
331
+ pointerHandler: import('..').HandlerFactory<import('@embedpdf/models').PdfPolygonAnnoObject, string>;
332
332
  };
333
333
  export declare const isFreeTextTool: (tool: {
334
334
  id: string;
@@ -372,7 +372,7 @@ export declare const isFreeTextTool: (tool: {
372
372
  selectAfterCreate: true;
373
373
  };
374
374
  transform: import('..').PatchFunction<import('@embedpdf/models').PdfFreeTextAnnoObject>;
375
- pointerHandler: import('..').HandlerFactory<import('@embedpdf/models').PdfFreeTextAnnoObject>;
375
+ pointerHandler: import('..').HandlerFactory<import('@embedpdf/models').PdfFreeTextAnnoObject, string>;
376
376
  };
377
377
  export declare const isStampTool: (tool: {
378
378
  id: string;
@@ -398,7 +398,7 @@ export declare const isStampTool: (tool: {
398
398
  useAppearanceStream: false;
399
399
  };
400
400
  transform: import('..').PatchFunction<import('@embedpdf/models').PdfStampAnnoObject>;
401
- pointerHandler: import('..').HandlerFactory<import('@embedpdf/models').PdfStampAnnoObject>;
401
+ pointerHandler: import('..').HandlerFactory<import('@embedpdf/models').PdfStampAnnoObject, string>;
402
402
  };
403
403
  export declare const isInsertTextTool: (tool: {
404
404
  id: string;
@@ -179,7 +179,7 @@ export type AnnotationTool<T extends PdfAnnotationObject = PdfAnnotationObject,
179
179
  useAppearanceStream?: boolean;
180
180
  } & InsertUprightBehaviorFor<T> & InkBehaviorFor<T>;
181
181
  /** Pointer-based creation handler (drag-to-create, click-to-place). */
182
- pointerHandler?: HandlerFactory<T>;
182
+ pointerHandler?: HandlerFactory<T, TId>;
183
183
  /** Text-selection-based creation handler. */
184
184
  selectionHandler?: SelectionHandlerFactory<T>;
185
185
  /** Transform function for move, resize, rotate, and property-update operations. */
@@ -117,6 +117,7 @@ export interface AnnotationDocumentState {
117
117
  */
118
118
  selectedUid: string | null;
119
119
  activeToolId: string | null;
120
+ activeToolContext?: Record<string, unknown>;
120
121
  hasPendingChanges: boolean;
121
122
  locked: LockMode;
122
123
  }
@@ -245,8 +246,8 @@ export interface AnnotationScope<TTools extends AnnotationToolMap = AnnotationTo
245
246
  /** Clear all selection */
246
247
  deselectAnnotation(): void;
247
248
  getActiveTool(): ToolUnion<TTools> | null;
248
- setActiveTool<TId extends ToolId<TTools>>(toolId: TId | null): void;
249
- setActiveTool(toolId: string | null): void;
249
+ setActiveTool<TId extends ToolId<TTools>>(toolId: TId | null, context?: Record<string, unknown>): void;
250
+ setActiveTool(toolId: string | null, context?: Record<string, unknown>): void;
250
251
  findToolForAnnotation(annotation: PdfAnnotationObject): ToolUnion<TTools> | null;
251
252
  importAnnotations(items: ImportAnnotationItem<PdfAnnotationObject>[]): void;
252
253
  createAnnotation<A extends PdfAnnotationObject>(pageIndex: number, annotation: A, context?: AnnotationCreateContext<A>): void;
@@ -386,8 +387,8 @@ export interface AnnotationCapability<TTools extends AnnotationToolMap = Annotat
386
387
  forDocument: (documentId: string) => AnnotationScope<TTools>;
387
388
  getActiveTool: () => ToolUnion<TTools> | null;
388
389
  setActiveTool: {
389
- <TId extends ToolId<TTools>>(toolId: TId | null): void;
390
- (toolId: string | null): void;
390
+ <TId extends ToolId<TTools>>(toolId: TId | null, context?: Record<string, unknown>): void;
391
+ (toolId: string | null, context?: Record<string, unknown>): void;
391
392
  };
392
393
  getTools: () => Array<ToolUnion<TTools>>;
393
394
  getTool: {