@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
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { clamp, BasePlugin, createScopedEmitter, createBehaviorEmitter } from "@embedpdf/core";
2
- import { PdfAnnotationSubtype, PdfAnnotationReplyType, expandRect, rectFromPoints, uuidV4, PdfAnnotationLineEnding, getRectCenter, inferRotationCenterFromRects, calculateRotatedRectAABBAroundPoint, rotateAndTranslatePoint, calculateRotatedRectAABB, rotatePointAround, rotateVertices, PdfAnnotationIcon, PdfVerticalAlignment, PdfTextAlignment, PdfStandardFont, PdfAnnotationBorderStyle, PdfBlendMode, PdfPermissionFlag, ignore, PdfTaskHelper, PdfErrorCode, Task, PdfActionType, PdfZoomMode, TaskStage } from "@embedpdf/models";
2
+ import { PdfAnnotationSubtype, PdfAnnotationReplyType, expandRect, rectFromPoints, uuidV4, PdfAnnotationLineEnding, getRectCenter, inferRotationCenterFromRects, calculateRotatedRectAABBAroundPoint, rotateAndTranslatePoint, calculateRotatedRectAABB, rotatePointAround, rotateVertices, PdfAnnotationName, PdfVerticalAlignment, PdfTextAlignment, PdfStandardFont, PdfAnnotationBorderStyle, PdfBlendMode, PdfPermissionFlag, ignore, PdfTaskHelper, PdfErrorCode, Task, PdfActionType, PdfZoomMode, TaskStage } from "@embedpdf/models";
3
3
  import { calculateRotatedRectAABB as calculateRotatedRectAABB2, calculateRotatedRectAABBAroundPoint as calculateRotatedRectAABBAroundPoint2, getRectCenter as getRectCenter2, inferRotationCenterFromRects as inferRotationCenterFromRects2, rotatePointAround as rotatePointAround2, rotateVertices as rotateVertices2 } from "@embedpdf/models";
4
4
  const ANNOTATION_PLUGIN_ID = "annotation";
5
5
  const manifest = {
@@ -68,9 +68,9 @@ const setSelection = (documentId, ids) => ({
68
68
  type: SET_SELECTION,
69
69
  payload: { documentId, ids }
70
70
  });
71
- const setActiveToolId = (documentId, toolId) => ({
71
+ const setActiveToolId = (documentId, toolId, context) => ({
72
72
  type: SET_ACTIVE_TOOL_ID,
73
- payload: { documentId, toolId }
73
+ payload: { documentId, toolId, context }
74
74
  });
75
75
  const createAnnotation = (documentId, pageIndex, annotation) => ({
76
76
  type: CREATE_ANNOTATION,
@@ -930,7 +930,7 @@ const textHandlerFactory = {
930
930
  ...tool.defaults,
931
931
  rect,
932
932
  type: PdfAnnotationSubtype.TEXT,
933
- icon: tool.defaults.icon ?? PdfAnnotationIcon.Comment,
933
+ name: tool.defaults.name ?? PdfAnnotationName.Comment,
934
934
  contents: tool.defaults.contents ?? "",
935
935
  flags: tool.defaults.flags ?? ["print", "noRotate", "noZoom"],
936
936
  pageIndex: context.pageIndex,
@@ -2220,7 +2220,7 @@ const stampHandlerFactory = {
2220
2220
  ...tool.defaults,
2221
2221
  rect,
2222
2222
  type: PdfAnnotationSubtype.STAMP,
2223
- icon: tool.defaults.icon ?? PdfAnnotationIcon.Draft,
2223
+ name: tool.defaults.name ?? PdfAnnotationName.Image,
2224
2224
  subject: tool.defaults.subject ?? "Stamp",
2225
2225
  flags: tool.defaults.flags ?? ["print"],
2226
2226
  pageIndex: context.pageIndex,
@@ -3938,14 +3938,14 @@ const reducer = (state, action) => {
3938
3938
  };
3939
3939
  }
3940
3940
  case SET_ACTIVE_TOOL_ID: {
3941
- const { documentId, toolId } = action.payload;
3941
+ const { documentId, toolId, context } = action.payload;
3942
3942
  const docState = state.documents[documentId];
3943
3943
  if (!docState) return state;
3944
3944
  return {
3945
3945
  ...state,
3946
3946
  documents: {
3947
3947
  ...state.documents,
3948
- [documentId]: { ...docState, activeToolId: toolId }
3948
+ [documentId]: { ...docState, activeToolId: toolId, activeToolContext: context }
3949
3949
  }
3950
3950
  };
3951
3951
  }
@@ -4288,7 +4288,7 @@ const _AnnotationPlugin = class _AnnotationPlugin extends BasePlugin {
4288
4288
  return {
4289
4289
  // Active document operations
4290
4290
  getActiveTool: () => this.getActiveTool(),
4291
- setActiveTool: (toolId) => this.setActiveTool(toolId),
4291
+ setActiveTool: (toolId, context) => this.setActiveTool(toolId, void 0, context),
4292
4292
  getState: () => this.getDocumentState(),
4293
4293
  getPageAnnotations: (options) => this.getPageAnnotations(options),
4294
4294
  getSelectedAnnotation: () => this.getSelectedAnnotation(),
@@ -4372,7 +4372,7 @@ const _AnnotationPlugin = class _AnnotationPlugin extends BasePlugin {
4372
4372
  setSelection: (ids) => this.setSelectionMethod(ids, documentId),
4373
4373
  deselectAnnotation: () => this.deselectAnnotation(documentId),
4374
4374
  getActiveTool: () => this.getActiveTool(documentId),
4375
- setActiveTool: (toolId) => this.setActiveTool(toolId, documentId),
4375
+ setActiveTool: (toolId, context) => this.setActiveTool(toolId, documentId, context),
4376
4376
  findToolForAnnotation: (anno) => this.findToolForAnnotation(anno),
4377
4377
  importAnnotations: (items) => this.importAnnotations(items, documentId),
4378
4378
  createAnnotation: (pageIndex, anno, ctx) => this.createAnnotation(pageIndex, anno, ctx, documentId),
@@ -4443,7 +4443,7 @@ const _AnnotationPlugin = class _AnnotationPlugin extends BasePlugin {
4443
4443
  return context.changes;
4444
4444
  }
4445
4445
  registerPageHandlers(documentId, pageIndex, scale, callbacks) {
4446
- var _a;
4446
+ var _a, _b;
4447
4447
  const docState = this.getCoreDocument(documentId);
4448
4448
  const page = (_a = docState == null ? void 0 : docState.document) == null ? void 0 : _a.pages[pageIndex];
4449
4449
  if (!page) return () => {
@@ -4453,7 +4453,7 @@ const _AnnotationPlugin = class _AnnotationPlugin extends BasePlugin {
4453
4453
  const unregisterFns = [];
4454
4454
  const effectivePageRotation = ((page.rotation ?? 0) + ((docState == null ? void 0 : docState.rotation) ?? 0)) % 4;
4455
4455
  for (const tool of this.state.tools) {
4456
- const factory = tool.pointerHandler;
4456
+ const factory = tool.pointerHandler ?? (((_b = tool.defaults) == null ? void 0 : _b.type) ? _AnnotationPlugin.defaultHandlerFactories.get(tool.defaults.type) : void 0);
4457
4457
  if (!factory) continue;
4458
4458
  const context = {
4459
4459
  pageIndex,
@@ -4461,20 +4461,23 @@ const _AnnotationPlugin = class _AnnotationPlugin extends BasePlugin {
4461
4461
  pageRotation: effectivePageRotation,
4462
4462
  scale,
4463
4463
  services: callbacks.services,
4464
- // Pass through services
4465
4464
  onPreview: (state) => callbacks.onPreview(tool.id, state),
4466
4465
  onCommit: (annotation, ctx) => {
4467
- var _a2, _b, _c;
4466
+ var _a2, _b2, _c;
4468
4467
  const editAfterCreate = ((_a2 = tool.behavior) == null ? void 0 : _a2.editAfterCreate) ?? false;
4469
4468
  this.createAnnotation(pageIndex, annotation, ctx, documentId, { editAfterCreate });
4470
- if ((_b = tool.behavior) == null ? void 0 : _b.deactivateToolAfterCreate) {
4469
+ if ((_b2 = tool.behavior) == null ? void 0 : _b2.deactivateToolAfterCreate) {
4471
4470
  this.setActiveTool(null, documentId);
4472
4471
  }
4473
4472
  if (((_c = tool.behavior) == null ? void 0 : _c.selectAfterCreate) || editAfterCreate) {
4474
4473
  this.selectAnnotation(pageIndex, annotation.id, documentId);
4475
4474
  }
4476
4475
  },
4477
- getTool: () => this.state.tools.find((t) => t.id === tool.id)
4476
+ getTool: () => this.state.tools.find((t) => t.id === tool.id),
4477
+ getToolContext: () => {
4478
+ var _a2;
4479
+ return (_a2 = this.state.documents[documentId]) == null ? void 0 : _a2.activeToolContext;
4480
+ }
4478
4481
  };
4479
4482
  const unregister = this.interactionManager.registerHandlers({
4480
4483
  documentId,
@@ -5865,7 +5868,7 @@ const _AnnotationPlugin = class _AnnotationPlugin extends BasePlugin {
5865
5868
  if (!docState.activeToolId) return null;
5866
5869
  return this.state.tools.find((t) => t.id === docState.activeToolId) ?? null;
5867
5870
  }
5868
- setActiveTool(toolId, documentId) {
5871
+ setActiveTool(toolId, documentId, context) {
5869
5872
  var _a, _b;
5870
5873
  const docId = documentId ?? this.getActiveDocumentId();
5871
5874
  if (toolId !== null && !this.checkPermission(docId, PdfPermissionFlag.ModifyAnnotations)) {
@@ -5877,8 +5880,8 @@ const _AnnotationPlugin = class _AnnotationPlugin extends BasePlugin {
5877
5880
  return;
5878
5881
  }
5879
5882
  const docState = this.getDocumentState(docId);
5880
- if (toolId === docState.activeToolId) return;
5881
- this.dispatch(setActiveToolId(docId, toolId));
5883
+ if (toolId === docState.activeToolId && !context) return;
5884
+ this.dispatch(setActiveToolId(docId, toolId, context));
5882
5885
  const tool = this.state.tools.find((t) => t.id === toolId);
5883
5886
  if (tool) {
5884
5887
  (_a = this.interactionManager) == null ? void 0 : _a.forDocument(docId).activate(tool.interaction.mode ?? tool.id);
@@ -6178,6 +6181,18 @@ const _AnnotationPlugin = class _AnnotationPlugin extends BasePlugin {
6178
6181
  }
6179
6182
  };
6180
6183
  _AnnotationPlugin.id = "annotation";
6184
+ _AnnotationPlugin.defaultHandlerFactories = /* @__PURE__ */ new Map([
6185
+ [PdfAnnotationSubtype.CIRCLE, circleHandlerFactory],
6186
+ [PdfAnnotationSubtype.SQUARE, squareHandlerFactory],
6187
+ [PdfAnnotationSubtype.STAMP, stampHandlerFactory],
6188
+ [PdfAnnotationSubtype.POLYGON, polygonHandlerFactory],
6189
+ [PdfAnnotationSubtype.POLYLINE, polylineHandlerFactory],
6190
+ [PdfAnnotationSubtype.LINE, lineHandlerFactory],
6191
+ [PdfAnnotationSubtype.INK, inkHandlerFactory],
6192
+ [PdfAnnotationSubtype.FREETEXT, freeTextHandlerFactory],
6193
+ [PdfAnnotationSubtype.TEXT, textHandlerFactory],
6194
+ [PdfAnnotationSubtype.LINK, linkHandlerFactory]
6195
+ ]);
6181
6196
  let AnnotationPlugin = _AnnotationPlugin;
6182
6197
  function resolveInteractionProp(prop, annotation, defaultValue) {
6183
6198
  if (prop === void 0) return defaultValue;
@@ -6216,8 +6231,10 @@ export {
6216
6231
  AnnotationPlugin,
6217
6232
  AnnotationPluginPackage,
6218
6233
  LockModeType,
6234
+ applyInsertUpright,
6219
6235
  calculateRotatedRectAABB2 as calculateRotatedRectAABB,
6220
6236
  calculateRotatedRectAABBAroundPoint2 as calculateRotatedRectAABBAroundPoint,
6237
+ clampAnnotationToPage,
6221
6238
  convertAABBRectToUnrotatedSpace,
6222
6239
  createToolPredicate,
6223
6240
  defineAnnotationTool,