@embedpdf/plugin-annotation 2.6.2 → 2.8.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 (176) hide show
  1. package/dist/index.cjs +1 -1
  2. package/dist/index.cjs.map +1 -1
  3. package/dist/index.js +538 -90
  4. package/dist/index.js.map +1 -1
  5. package/dist/lib/actions.d.ts +12 -1
  6. package/dist/lib/annotation-plugin.d.ts +19 -0
  7. package/dist/lib/handlers/index.d.ts +4 -0
  8. package/dist/lib/handlers/insert-text.handler.d.ts +8 -0
  9. package/dist/lib/handlers/replace-text.handler.d.ts +9 -0
  10. package/dist/lib/handlers/selection-utils.d.ts +7 -0
  11. package/dist/lib/handlers/text-markup.handler.d.ts +7 -0
  12. package/dist/lib/handlers/text.handler.d.ts +3 -0
  13. package/dist/lib/handlers/types.d.ts +12 -0
  14. package/dist/lib/helpers.d.ts +2 -1
  15. package/dist/lib/selectors.d.ts +6 -1
  16. package/dist/lib/tools/default-tools.d.ts +153 -6
  17. package/dist/lib/tools/tools-utils.d.ts +2 -0
  18. package/dist/lib/tools/types.d.ts +4 -0
  19. package/dist/lib/types.d.ts +19 -2
  20. package/dist/preact/index.cjs +1 -1
  21. package/dist/preact/index.cjs.map +1 -1
  22. package/dist/preact/index.js +1258 -1074
  23. package/dist/preact/index.js.map +1 -1
  24. package/dist/react/index.cjs +1 -1
  25. package/dist/react/index.cjs.map +1 -1
  26. package/dist/react/index.js +1258 -1074
  27. package/dist/react/index.js.map +1 -1
  28. package/dist/shared/annotation-bounds.d.ts +14 -0
  29. package/dist/shared/components/annotation-container.d.ts +11 -5
  30. package/dist/shared/components/annotations/caret.d.ts +24 -0
  31. package/dist/shared/components/annotations/circle.d.ts +6 -4
  32. package/dist/shared/components/annotations/free-text.d.ts +6 -3
  33. package/dist/shared/components/annotations/ink.d.ts +5 -3
  34. package/dist/shared/components/annotations/line.d.ts +5 -3
  35. package/dist/shared/components/annotations/link.d.ts +2 -2
  36. package/dist/shared/components/annotations/polygon.d.ts +5 -4
  37. package/dist/shared/components/annotations/polyline.d.ts +10 -4
  38. package/dist/shared/components/annotations/square.d.ts +6 -4
  39. package/dist/shared/components/annotations/stamp.d.ts +2 -2
  40. package/dist/shared/components/annotations/text.d.ts +14 -0
  41. package/dist/shared/components/annotations.d.ts +0 -1
  42. package/dist/shared/components/appearance-image.d.ts +12 -0
  43. package/dist/shared/components/built-in-renderers.d.ts +2 -0
  44. package/dist/shared/components/text-markup/highlight.d.ts +5 -3
  45. package/dist/shared/components/text-markup/squiggly.d.ts +5 -3
  46. package/dist/shared/components/text-markup/strikeout.d.ts +5 -3
  47. package/dist/shared/components/text-markup/underline.d.ts +5 -3
  48. package/dist/shared/components/types.d.ts +67 -11
  49. package/dist/shared-preact/annotation-bounds.d.ts +14 -0
  50. package/dist/shared-preact/components/annotation-container.d.ts +11 -5
  51. package/dist/shared-preact/components/annotations/caret.d.ts +24 -0
  52. package/dist/shared-preact/components/annotations/circle.d.ts +6 -4
  53. package/dist/shared-preact/components/annotations/free-text.d.ts +6 -3
  54. package/dist/shared-preact/components/annotations/ink.d.ts +5 -3
  55. package/dist/shared-preact/components/annotations/line.d.ts +5 -3
  56. package/dist/shared-preact/components/annotations/link.d.ts +2 -2
  57. package/dist/shared-preact/components/annotations/polygon.d.ts +5 -4
  58. package/dist/shared-preact/components/annotations/polyline.d.ts +10 -4
  59. package/dist/shared-preact/components/annotations/square.d.ts +6 -4
  60. package/dist/shared-preact/components/annotations/stamp.d.ts +2 -2
  61. package/dist/shared-preact/components/annotations/text.d.ts +14 -0
  62. package/dist/shared-preact/components/annotations.d.ts +0 -1
  63. package/dist/shared-preact/components/appearance-image.d.ts +12 -0
  64. package/dist/shared-preact/components/built-in-renderers.d.ts +2 -0
  65. package/dist/shared-preact/components/text-markup/highlight.d.ts +5 -3
  66. package/dist/shared-preact/components/text-markup/squiggly.d.ts +5 -3
  67. package/dist/shared-preact/components/text-markup/strikeout.d.ts +5 -3
  68. package/dist/shared-preact/components/text-markup/underline.d.ts +5 -3
  69. package/dist/shared-preact/components/types.d.ts +67 -11
  70. package/dist/shared-react/annotation-bounds.d.ts +14 -0
  71. package/dist/shared-react/components/annotation-container.d.ts +11 -5
  72. package/dist/shared-react/components/annotations/caret.d.ts +24 -0
  73. package/dist/shared-react/components/annotations/circle.d.ts +6 -4
  74. package/dist/shared-react/components/annotations/free-text.d.ts +6 -3
  75. package/dist/shared-react/components/annotations/ink.d.ts +5 -3
  76. package/dist/shared-react/components/annotations/line.d.ts +5 -3
  77. package/dist/shared-react/components/annotations/link.d.ts +2 -2
  78. package/dist/shared-react/components/annotations/polygon.d.ts +5 -4
  79. package/dist/shared-react/components/annotations/polyline.d.ts +10 -4
  80. package/dist/shared-react/components/annotations/square.d.ts +6 -4
  81. package/dist/shared-react/components/annotations/stamp.d.ts +2 -2
  82. package/dist/shared-react/components/annotations/text.d.ts +14 -0
  83. package/dist/shared-react/components/annotations.d.ts +0 -1
  84. package/dist/shared-react/components/appearance-image.d.ts +12 -0
  85. package/dist/shared-react/components/built-in-renderers.d.ts +2 -0
  86. package/dist/shared-react/components/text-markup/highlight.d.ts +5 -3
  87. package/dist/shared-react/components/text-markup/squiggly.d.ts +5 -3
  88. package/dist/shared-react/components/text-markup/strikeout.d.ts +5 -3
  89. package/dist/shared-react/components/text-markup/underline.d.ts +5 -3
  90. package/dist/shared-react/components/types.d.ts +67 -11
  91. package/dist/shared-vue/annotation-bounds.d.ts +14 -0
  92. package/dist/svelte/components/Annotations.svelte.d.ts +0 -7
  93. package/dist/svelte/components/AppearanceImage.svelte.d.ts +8 -0
  94. package/dist/svelte/components/annotations/Caret.svelte.d.ts +13 -0
  95. package/dist/svelte/components/annotations/Circle.svelte.d.ts +2 -11
  96. package/dist/svelte/components/annotations/FreeText.svelte.d.ts +2 -1
  97. package/dist/svelte/components/annotations/Ink.svelte.d.ts +2 -2
  98. package/dist/svelte/components/annotations/Line.svelte.d.ts +2 -1
  99. package/dist/svelte/components/annotations/Link.svelte.d.ts +1 -1
  100. package/dist/svelte/components/annotations/Polygon.svelte.d.ts +2 -1
  101. package/dist/svelte/components/annotations/Polyline.svelte.d.ts +5 -3
  102. package/dist/svelte/components/annotations/Square.svelte.d.ts +2 -1
  103. package/dist/svelte/components/annotations/Stamp.svelte.d.ts +1 -1
  104. package/dist/svelte/components/annotations/Text.svelte.d.ts +10 -0
  105. package/dist/svelte/components/annotations/index.d.ts +1 -0
  106. package/dist/svelte/components/built-in-renderers.d.ts +2 -0
  107. package/dist/svelte/components/renderers/CaretRenderer.svelte.d.ts +5 -0
  108. package/dist/svelte/components/renderers/CircleRenderer.svelte.d.ts +5 -0
  109. package/dist/svelte/components/renderers/FreeTextRenderer.svelte.d.ts +5 -0
  110. package/dist/svelte/components/renderers/HighlightRenderer.svelte.d.ts +5 -0
  111. package/dist/svelte/components/renderers/InkRenderer.svelte.d.ts +5 -0
  112. package/dist/svelte/components/renderers/LineRenderer.svelte.d.ts +5 -0
  113. package/dist/svelte/components/renderers/LinkRenderer.svelte.d.ts +5 -0
  114. package/dist/svelte/components/renderers/PolygonRenderer.svelte.d.ts +5 -0
  115. package/dist/svelte/components/renderers/PolylineRenderer.svelte.d.ts +5 -0
  116. package/dist/svelte/components/renderers/SquareRenderer.svelte.d.ts +5 -0
  117. package/dist/svelte/components/renderers/SquigglyRenderer.svelte.d.ts +5 -0
  118. package/dist/svelte/components/renderers/StampRenderer.svelte.d.ts +5 -0
  119. package/dist/svelte/components/renderers/StrikeoutRenderer.svelte.d.ts +5 -0
  120. package/dist/svelte/components/renderers/TextRenderer.svelte.d.ts +5 -0
  121. package/dist/svelte/components/renderers/UnderlineRenderer.svelte.d.ts +5 -0
  122. package/dist/svelte/components/text-markup/Highlight.svelte.d.ts +3 -1
  123. package/dist/svelte/components/text-markup/Squiggly.svelte.d.ts +3 -1
  124. package/dist/svelte/components/text-markup/Strikeout.svelte.d.ts +3 -1
  125. package/dist/svelte/components/text-markup/Underline.svelte.d.ts +3 -1
  126. package/dist/svelte/components/types.d.ts +8 -2
  127. package/dist/svelte/context/renderer-registry.svelte.d.ts +2 -2
  128. package/dist/svelte/context/types.d.ts +63 -2
  129. package/dist/svelte/index.cjs +1 -1
  130. package/dist/svelte/index.cjs.map +1 -1
  131. package/dist/svelte/index.js +2738 -2890
  132. package/dist/svelte/index.js.map +1 -1
  133. package/dist/vue/components/annotation-container.vue.d.ts +7 -2
  134. package/dist/vue/components/annotation-layer.vue.d.ts +2 -21
  135. package/dist/vue/components/annotations/caret.vue.d.ts +24 -0
  136. package/dist/vue/components/annotations/circle.vue.d.ts +19 -6
  137. package/dist/vue/components/annotations/free-text.vue.d.ts +18 -6
  138. package/dist/vue/components/annotations/index.d.ts +1 -0
  139. package/dist/vue/components/annotations/ink.vue.d.ts +17 -7
  140. package/dist/vue/components/annotations/line.vue.d.ts +21 -6
  141. package/dist/vue/components/annotations/link.vue.d.ts +24 -6
  142. package/dist/vue/components/annotations/polygon.vue.d.ts +22 -6
  143. package/dist/vue/components/annotations/polyline.vue.d.ts +25 -7
  144. package/dist/vue/components/annotations/square.vue.d.ts +19 -6
  145. package/dist/vue/components/annotations/stamp.vue.d.ts +12 -6
  146. package/dist/vue/components/annotations/text.vue.d.ts +14 -0
  147. package/dist/vue/components/annotations.vue.d.ts +9 -576
  148. package/dist/vue/components/appearance-image.vue.d.ts +9 -0
  149. package/dist/vue/components/built-in-renderers.d.ts +2 -0
  150. package/dist/vue/components/group-selection-box.vue.d.ts +2 -2
  151. package/dist/vue/components/renderers/caret-renderer.vue.d.ts +6 -0
  152. package/dist/vue/components/renderers/circle-renderer.vue.d.ts +6 -0
  153. package/dist/vue/components/renderers/free-text-renderer.vue.d.ts +6 -0
  154. package/dist/vue/components/renderers/highlight-renderer.vue.d.ts +6 -0
  155. package/dist/vue/components/renderers/ink-renderer.vue.d.ts +6 -0
  156. package/dist/vue/components/renderers/line-renderer.vue.d.ts +6 -0
  157. package/dist/vue/components/renderers/link-renderer.vue.d.ts +6 -0
  158. package/dist/vue/components/renderers/polygon-renderer.vue.d.ts +6 -0
  159. package/dist/vue/components/renderers/polyline-renderer.vue.d.ts +6 -0
  160. package/dist/vue/components/renderers/square-renderer.vue.d.ts +6 -0
  161. package/dist/vue/components/renderers/squiggly-renderer.vue.d.ts +6 -0
  162. package/dist/vue/components/renderers/stamp-renderer.vue.d.ts +6 -0
  163. package/dist/vue/components/renderers/strikeout-renderer.vue.d.ts +6 -0
  164. package/dist/vue/components/renderers/text-renderer.vue.d.ts +6 -0
  165. package/dist/vue/components/renderers/underline-renderer.vue.d.ts +6 -0
  166. package/dist/vue/components/text-markup/highlight.vue.d.ts +18 -6
  167. package/dist/vue/components/text-markup/squiggly.vue.d.ts +18 -6
  168. package/dist/vue/components/text-markup/strikeout.vue.d.ts +18 -6
  169. package/dist/vue/components/text-markup/underline.vue.d.ts +18 -6
  170. package/dist/vue/context/renderer-registry.d.ts +2 -2
  171. package/dist/vue/context/types.d.ts +63 -2
  172. package/dist/vue/index.cjs +1 -1
  173. package/dist/vue/index.cjs.map +1 -1
  174. package/dist/vue/index.js +1995 -1336
  175. package/dist/vue/index.js.map +1 -1
  176. package/package.json +10 -10
@@ -1,15 +1,16 @@
1
1
  import { createPluginPackage } from "@embedpdf/core";
2
- import { initialDocumentState, AnnotationPlugin, patching, getAnnotationsByPageIndex, getSelectedAnnotationIds, resolveInteractionProp, isInk, isSquare, isCircle, isUnderline, isStrikeout, isSquiggly, isHighlight, isLine, isPolyline, isPolygon, isFreeText, isStamp, isLink, AnnotationPluginPackage as AnnotationPluginPackage$1 } from "@embedpdf/plugin-annotation";
2
+ import { initialDocumentState, AnnotationPlugin, patching, getAnnotationsByPageIndex, getSelectedAnnotationIds, resolveInteractionProp, AnnotationPluginPackage as AnnotationPluginPackage$1 } from "@embedpdf/plugin-annotation";
3
3
  export * from "@embedpdf/plugin-annotation";
4
4
  import { jsx, jsxs, Fragment } from "preact/jsx-runtime";
5
5
  import { createContext, Fragment as Fragment$1 } from "preact";
6
6
  import { useState, useCallback, useContext, useRef, useEffect, useMemo, useLayoutEffect } from "preact/hooks";
7
7
  import { createPortal } from "preact/compat";
8
8
  import { useCapability, usePlugin, useDocumentPermissions, useDocumentState } from "@embedpdf/core/preact";
9
- import { inferRotationCenterFromRects, boundingRectOrEmpty, PdfAnnotationBorderStyle, PdfVerticalAlignment, textAlignmentToCss, standardFontCssProperties, ignore, PdfErrorCode, blendModeToCss, PdfBlendMode, PdfAnnotationSubtype } from "@embedpdf/models";
9
+ import { inferRotationCenterFromRects, boundingRectOrEmpty, PdfAnnotationBorderStyle, getContrastStrokeColor, PdfVerticalAlignment, textAlignmentToCss, standardFontCssProperties, ignore, PdfErrorCode, PdfAnnotationSubtype, blendModeToCss, PdfBlendMode } from "@embedpdf/models";
10
10
  import { usePointerHandlers } from "@embedpdf/plugin-interaction-manager/preact";
11
11
  import { useSelectionCapability } from "@embedpdf/plugin-selection/preact";
12
12
  import { useInteractionHandles, useDoublePressProps, CounterRotate } from "@embedpdf/utils/preact";
13
+ import { getCounterRotation } from "@embedpdf/utils";
13
14
  const suppressContentEditableWarningProps = {};
14
15
  const RegisterContext = createContext(null);
15
16
  const RenderersContext = createContext([]);
@@ -59,6 +60,43 @@ const useAnnotation = (documentId) => {
59
60
  provides: (provides == null ? void 0 : provides.forDocument(documentId)) ?? null
60
61
  };
61
62
  };
63
+ function AppearanceImage({ appearance, style }) {
64
+ const [imageUrl, setImageUrl] = useState(null);
65
+ const urlRef = useRef(null);
66
+ useEffect(() => {
67
+ const url = URL.createObjectURL(appearance.data);
68
+ setImageUrl(url);
69
+ urlRef.current = url;
70
+ return () => {
71
+ if (urlRef.current) {
72
+ URL.revokeObjectURL(urlRef.current);
73
+ urlRef.current = null;
74
+ }
75
+ };
76
+ }, [appearance.data]);
77
+ const handleImageLoad = () => {
78
+ if (urlRef.current) {
79
+ URL.revokeObjectURL(urlRef.current);
80
+ urlRef.current = null;
81
+ }
82
+ };
83
+ return imageUrl ? /* @__PURE__ */ jsx(
84
+ "img",
85
+ {
86
+ src: imageUrl,
87
+ onLoad: handleImageLoad,
88
+ style: {
89
+ position: "absolute",
90
+ width: "100%",
91
+ height: "100%",
92
+ display: "block",
93
+ pointerEvents: "none",
94
+ userSelect: "none",
95
+ ...style
96
+ }
97
+ }
98
+ ) : null;
99
+ }
62
100
  function AnnotationContainer({
63
101
  scale,
64
102
  documentId,
@@ -69,6 +107,7 @@ function AnnotationContainer({
69
107
  trackedAnnotation,
70
108
  children,
71
109
  isSelected,
110
+ isEditing = false,
72
111
  isMultiSelected = false,
73
112
  isDraggable,
74
113
  isResizable,
@@ -80,6 +119,7 @@ function AnnotationContainer({
80
119
  outlineOffset = 1,
81
120
  onDoubleClick,
82
121
  onSelect,
122
+ appearance,
83
123
  zIndex = 1,
84
124
  resizeUI,
85
125
  vertexUI,
@@ -98,6 +138,7 @@ function AnnotationContainer({
98
138
  const [liveRotation, setLiveRotation] = useState(null);
99
139
  const [cursorScreen, setCursorScreen] = useState(null);
100
140
  const [isHandleHovered, setIsHandleHovered] = useState(false);
141
+ const [gestureActive, setGestureActive] = useState(false);
101
142
  const { provides: annotationCapability } = useAnnotationCapability();
102
143
  const { plugin } = useAnnotationPlugin();
103
144
  const { canModifyAnnotations } = useDocumentPermissions(documentId);
@@ -110,6 +151,11 @@ function AnnotationContainer({
110
151
  [annotationCapability, documentId]
111
152
  );
112
153
  const currentObject = preview ? { ...trackedAnnotation.object, ...preview } : trackedAnnotation.object;
154
+ const annoFlags = trackedAnnotation.object.flags ?? [];
155
+ const hasNoZoom = annoFlags.includes("noZoom");
156
+ const hasNoRotate = annoFlags.includes("noRotate");
157
+ const visualScale = hasNoZoom ? 1 : scale;
158
+ const effectivePageRotation = hasNoRotate ? 0 : rotation;
113
159
  const HANDLE_COLOR = (resizeUI == null ? void 0 : resizeUI.color) ?? "#007ACC";
114
160
  const VERTEX_COLOR = (vertexUI == null ? void 0 : vertexUI.color) ?? "#007ACC";
115
161
  const ROTATION_COLOR = (rotationUI == null ? void 0 : rotationUI.color) ?? "white";
@@ -142,6 +188,9 @@ function AnnotationContainer({
142
188
  if (event.state === "start") {
143
189
  gestureBaseRectRef.current = trackedAnnotation.object.unrotatedRect ?? trackedAnnotation.object.rect;
144
190
  gestureBaseRef.current = trackedAnnotation.object;
191
+ if (type === "resize" || type === "vertex-edit") {
192
+ setGestureActive(true);
193
+ }
145
194
  if (type === "move") {
146
195
  plugin.startDrag(documentId, { annotationIds: [id], pageSize });
147
196
  } else if (type === "resize") {
@@ -202,6 +251,7 @@ function AnnotationContainer({
202
251
  if (event.state === "end") {
203
252
  gestureBaseRectRef.current = null;
204
253
  gestureBaseRef.current = null;
254
+ setGestureActive(false);
205
255
  if (type === "move") plugin.commitDrag(documentId);
206
256
  else if (type === "resize") plugin.commitResize(documentId);
207
257
  }
@@ -298,23 +348,28 @@ function AnnotationContainer({
298
348
  return () => unsubs.forEach((u) => u());
299
349
  }, [plugin, documentId, trackedAnnotation.object]);
300
350
  const showOutline = isSelected && !isMultiSelected;
301
- const aabbWidth = currentObject.rect.size.width * scale;
302
- const aabbHeight = currentObject.rect.size.height * scale;
303
- const innerWidth = effectiveUnrotatedRect.size.width * scale;
304
- const innerHeight = effectiveUnrotatedRect.size.height * scale;
351
+ const aabbWidth = currentObject.rect.size.width * visualScale;
352
+ const aabbHeight = currentObject.rect.size.height * visualScale;
353
+ const innerWidth = effectiveUnrotatedRect.size.width * visualScale;
354
+ const innerHeight = effectiveUnrotatedRect.size.height * visualScale;
305
355
  const usesCustomPivot = Boolean(explicitUnrotatedRect) && annotationRotation !== 0;
306
- const innerLeft = usesCustomPivot ? (effectiveUnrotatedRect.origin.x - currentObject.rect.origin.x) * scale : (aabbWidth - innerWidth) / 2;
307
- const innerTop = usesCustomPivot ? (effectiveUnrotatedRect.origin.y - currentObject.rect.origin.y) * scale : (aabbHeight - innerHeight) / 2;
308
- const innerTransformOrigin = usesCustomPivot && rotationPivot ? `${(rotationPivot.x - effectiveUnrotatedRect.origin.x) * scale}px ${(rotationPivot.y - effectiveUnrotatedRect.origin.y) * scale}px` : "center center";
309
- const centerX = rotationPivot ? (rotationPivot.x - currentObject.rect.origin.x) * scale : aabbWidth / 2;
310
- const centerY = rotationPivot ? (rotationPivot.y - currentObject.rect.origin.y) * scale : aabbHeight / 2;
356
+ const innerLeft = usesCustomPivot ? (effectiveUnrotatedRect.origin.x - currentObject.rect.origin.x) * visualScale : (aabbWidth - innerWidth) / 2;
357
+ const innerTop = usesCustomPivot ? (effectiveUnrotatedRect.origin.y - currentObject.rect.origin.y) * visualScale : (aabbHeight - innerHeight) / 2;
358
+ const innerTransformOrigin = usesCustomPivot && rotationPivot ? `${(rotationPivot.x - effectiveUnrotatedRect.origin.x) * visualScale}px ${(rotationPivot.y - effectiveUnrotatedRect.origin.y) * visualScale}px` : "center center";
359
+ const centerX = rotationPivot ? (rotationPivot.x - currentObject.rect.origin.x) * visualScale : aabbWidth / 2;
360
+ const centerY = rotationPivot ? (rotationPivot.y - currentObject.rect.origin.y) * visualScale : aabbHeight / 2;
311
361
  const guideLength = Math.max(300, Math.max(aabbWidth, aabbHeight) + 80);
362
+ const counterRot = hasNoRotate ? getCounterRotation(
363
+ { origin: { x: 0, y: 0 }, size: { width: aabbWidth, height: aabbHeight } },
364
+ rotation
365
+ ) : null;
312
366
  const childObject = useMemo(() => {
313
367
  if (explicitUnrotatedRect) {
314
368
  return { ...currentObject, rect: explicitUnrotatedRect };
315
369
  }
316
370
  return currentObject;
317
371
  }, [currentObject, explicitUnrotatedRect]);
372
+ const apActive = !!(appearance == null ? void 0 : appearance.normal) && !gestureActive && !isEditing && !trackedAnnotation.dictMode;
318
373
  return /* @__PURE__ */ jsxs("div", { "data-no-interaction": true, children: [
319
374
  /* @__PURE__ */ jsxs(
320
375
  "div",
@@ -323,10 +378,15 @@ function AnnotationContainer({
323
378
  position: "absolute",
324
379
  left: currentObject.rect.origin.x * scale,
325
380
  top: currentObject.rect.origin.y * scale,
326
- width: aabbWidth,
327
- height: aabbHeight,
381
+ width: counterRot ? counterRot.width : aabbWidth,
382
+ height: counterRot ? counterRot.height : aabbHeight,
328
383
  pointerEvents: "none",
329
384
  zIndex,
385
+ // noRotate: apply counter-rotation matrix so the annotation stays upright
386
+ ...counterRot && {
387
+ transform: counterRot.matrix,
388
+ transformOrigin: "0 0"
389
+ },
330
390
  ...style
331
391
  },
332
392
  ...props,
@@ -491,7 +551,7 @@ function AnnotationContainer({
491
551
  },
492
552
  children: [
493
553
  (() => {
494
- const childrenRender = typeof children === "function" ? children(childObject) : children;
554
+ const childrenRender = typeof children === "function" ? children(childObject, { appearanceActive: apActive }) : children;
495
555
  const customRender = customAnnotationRenderer == null ? void 0 : customAnnotationRenderer({
496
556
  annotation: childObject,
497
557
  children: childrenRender,
@@ -503,11 +563,15 @@ function AnnotationContainer({
503
563
  pageIndex,
504
564
  onSelect
505
565
  });
506
- if (customRender !== null && customRender !== void 0) {
507
- return customRender;
508
- }
509
- return childrenRender;
566
+ return customRender ?? childrenRender;
510
567
  })(),
568
+ (appearance == null ? void 0 : appearance.normal) && /* @__PURE__ */ jsx(
569
+ AppearanceImage,
570
+ {
571
+ appearance: appearance.normal,
572
+ style: { display: apActive ? "block" : "none" }
573
+ }
574
+ ),
511
575
  isSelected && effectiveIsResizable && !rotationActive && resize.map(
512
576
  ({ key, ...hProps }) => (resizeUI == null ? void 0 : resizeUI.component) ? resizeUI.component({
513
577
  key,
@@ -551,13 +615,13 @@ function AnnotationContainer({
551
615
  y: currentObject.rect.origin.y * scale
552
616
  },
553
617
  size: {
554
- width: currentObject.rect.size.width * scale,
555
- height: currentObject.rect.size.height * scale
618
+ width: currentObject.rect.size.width * visualScale,
619
+ height: currentObject.rect.size.height * visualScale
556
620
  }
557
621
  },
558
622
  rotation,
559
623
  children: (counterRotateProps) => {
560
- const effectiveAngle = ((annotationRotation + rotation * 90) % 360 + 360) % 360;
624
+ const effectiveAngle = ((annotationRotation + effectivePageRotation * 90) % 360 + 360) % 360;
561
625
  const handleNearMenuSide = effectiveIsRotatable && effectiveAngle > 90 && effectiveAngle < 270;
562
626
  return selectionMenu({
563
627
  ...counterRotateProps,
@@ -602,6 +666,57 @@ function AnnotationContainer({
602
666
  )
603
667
  ] });
604
668
  }
669
+ function mapCounterRotatePoint(x, y, width, height, rotation) {
670
+ switch (rotation) {
671
+ case 1:
672
+ return { x: y, y: height - x };
673
+ case 2:
674
+ return { x: width - x, y: height - y };
675
+ case 3:
676
+ return { x: width - y, y: x };
677
+ default:
678
+ return { x, y };
679
+ }
680
+ }
681
+ function getAnnotationScreenBounds(annotation, scale, rotation) {
682
+ const flags = annotation.object.flags ?? [];
683
+ const hasNoZoom = flags.includes("noZoom");
684
+ const hasNoRotate = flags.includes("noRotate");
685
+ const left = annotation.object.rect.origin.x * scale;
686
+ const top = annotation.object.rect.origin.y * scale;
687
+ const width = annotation.object.rect.size.width * (hasNoZoom ? 1 : scale);
688
+ const height = annotation.object.rect.size.height * (hasNoZoom ? 1 : scale);
689
+ if (!hasNoRotate || rotation === 0) {
690
+ return {
691
+ left,
692
+ top,
693
+ right: left + width,
694
+ bottom: top + height
695
+ };
696
+ }
697
+ const corners = [
698
+ mapCounterRotatePoint(0, 0, width, height, rotation),
699
+ mapCounterRotatePoint(width, 0, width, height, rotation),
700
+ mapCounterRotatePoint(0, height, width, height, rotation),
701
+ mapCounterRotatePoint(width, height, width, height, rotation)
702
+ ];
703
+ let minX = Infinity;
704
+ let minY = Infinity;
705
+ let maxX = -Infinity;
706
+ let maxY = -Infinity;
707
+ for (const corner of corners) {
708
+ if (corner.x < minX) minX = corner.x;
709
+ if (corner.y < minY) minY = corner.y;
710
+ if (corner.x > maxX) maxX = corner.x;
711
+ if (corner.y > maxY) maxY = corner.y;
712
+ }
713
+ return {
714
+ left: left + minX,
715
+ top: top + minY,
716
+ right: left + maxX,
717
+ bottom: top + maxY
718
+ };
719
+ }
605
720
  function GroupSelectionBox({
606
721
  documentId,
607
722
  pageIndex,
@@ -809,8 +924,29 @@ function GroupSelectionBox({
809
924
  if (selectedAnnotations.length < 2) {
810
925
  return null;
811
926
  }
812
- const groupBoxWidth = previewGroupBox.size.width * scale;
813
- const groupBoxHeight = previewGroupBox.size.height * scale;
927
+ let visualLeft = Infinity;
928
+ let visualTop = Infinity;
929
+ let visualRight = -Infinity;
930
+ let visualBottom = -Infinity;
931
+ for (const ta of selectedAnnotations) {
932
+ const bounds = getAnnotationScreenBounds(ta, scale, rotation);
933
+ visualLeft = Math.min(visualLeft, bounds.left);
934
+ visualTop = Math.min(visualTop, bounds.top);
935
+ visualRight = Math.max(visualRight, bounds.right);
936
+ visualBottom = Math.max(visualBottom, bounds.bottom);
937
+ }
938
+ const initialLogicalLeft = groupBox.origin.x * scale;
939
+ const initialLogicalTop = groupBox.origin.y * scale;
940
+ const initialLogicalRight = (groupBox.origin.x + groupBox.size.width) * scale;
941
+ const initialLogicalBottom = (groupBox.origin.y + groupBox.size.height) * scale;
942
+ const leftCorrection = visualLeft - initialLogicalLeft;
943
+ const topCorrection = visualTop - initialLogicalTop;
944
+ const rightCorrection = visualRight - initialLogicalRight;
945
+ const bottomCorrection = visualBottom - initialLogicalBottom;
946
+ const groupBoxLeft = previewGroupBox.origin.x * scale + leftCorrection;
947
+ const groupBoxTop = previewGroupBox.origin.y * scale + topCorrection;
948
+ const groupBoxWidth = previewGroupBox.size.width * scale + (rightCorrection - leftCorrection);
949
+ const groupBoxHeight = previewGroupBox.size.height * scale + (bottomCorrection - topCorrection);
814
950
  const groupCenterX = groupBoxWidth / 2;
815
951
  const groupCenterY = groupBoxHeight / 2;
816
952
  const groupGuideLength = Math.max(300, Math.max(groupBoxWidth, groupBoxHeight) + 80);
@@ -820,8 +956,8 @@ function GroupSelectionBox({
820
956
  {
821
957
  style: {
822
958
  position: "absolute",
823
- left: previewGroupBox.origin.x * scale,
824
- top: previewGroupBox.origin.y * scale,
959
+ left: groupBoxLeft,
960
+ top: groupBoxTop,
825
961
  width: groupBoxWidth,
826
962
  height: groupBoxHeight,
827
963
  pointerEvents: "none",
@@ -1035,12 +1171,12 @@ function GroupSelectionBox({
1035
1171
  {
1036
1172
  rect: {
1037
1173
  origin: {
1038
- x: previewGroupBox.origin.x * scale,
1039
- y: previewGroupBox.origin.y * scale
1174
+ x: groupBoxLeft,
1175
+ y: groupBoxTop
1040
1176
  },
1041
1177
  size: {
1042
- width: previewGroupBox.size.width * scale,
1043
- height: previewGroupBox.size.height * scale
1178
+ width: groupBoxWidth,
1179
+ height: groupBoxHeight
1044
1180
  }
1045
1181
  },
1046
1182
  rotation,
@@ -1064,188 +1200,23 @@ function GroupSelectionBox({
1064
1200
  )
1065
1201
  ] });
1066
1202
  }
1067
- function Highlight({
1068
- strokeColor,
1069
- opacity = 0.5,
1070
- segmentRects,
1071
- rect,
1072
- scale,
1073
- onClick,
1074
- style
1075
- }) {
1076
- const resolvedColor = strokeColor ?? "#FFFF00";
1077
- return /* @__PURE__ */ jsx(Fragment, { children: segmentRects.map((b, i) => /* @__PURE__ */ jsx(
1078
- "div",
1079
- {
1080
- onPointerDown: onClick,
1081
- onTouchStart: onClick,
1082
- style: {
1083
- position: "absolute",
1084
- left: (rect ? b.origin.x - rect.origin.x : b.origin.x) * scale,
1085
- top: (rect ? b.origin.y - rect.origin.y : b.origin.y) * scale,
1086
- width: b.size.width * scale,
1087
- height: b.size.height * scale,
1088
- background: resolvedColor,
1089
- opacity,
1090
- pointerEvents: onClick ? "auto" : "none",
1091
- cursor: onClick ? "pointer" : "default",
1092
- zIndex: onClick ? 1 : void 0,
1093
- ...style
1094
- }
1095
- },
1096
- i
1097
- )) });
1098
- }
1099
- function Underline({
1100
- strokeColor,
1101
- opacity = 0.5,
1102
- segmentRects,
1103
- rect,
1104
- scale,
1105
- onClick,
1106
- style
1107
- }) {
1108
- const resolvedColor = strokeColor ?? "#FFFF00";
1109
- const thickness = 2 * scale;
1110
- return /* @__PURE__ */ jsx(Fragment, { children: segmentRects.map((r, i) => /* @__PURE__ */ jsx(
1111
- "div",
1112
- {
1113
- onPointerDown: onClick,
1114
- onTouchStart: onClick,
1115
- style: {
1116
- position: "absolute",
1117
- left: (rect ? r.origin.x - rect.origin.x : r.origin.x) * scale,
1118
- top: (rect ? r.origin.y - rect.origin.y : r.origin.y) * scale,
1119
- width: r.size.width * scale,
1120
- height: r.size.height * scale,
1121
- background: "transparent",
1122
- pointerEvents: onClick ? "auto" : "none",
1123
- cursor: onClick ? "pointer" : "default",
1124
- zIndex: onClick ? 1 : 0,
1125
- ...style
1126
- },
1127
- children: /* @__PURE__ */ jsx(
1128
- "div",
1129
- {
1130
- style: {
1131
- position: "absolute",
1132
- left: 0,
1133
- bottom: 0,
1134
- width: "100%",
1135
- height: thickness,
1136
- background: resolvedColor,
1137
- opacity,
1138
- pointerEvents: "none"
1139
- }
1140
- }
1141
- )
1142
- },
1143
- i
1144
- )) });
1145
- }
1146
- function Strikeout({
1147
- strokeColor,
1148
- opacity = 0.5,
1149
- segmentRects,
1150
- rect,
1151
- scale,
1152
- onClick,
1153
- style
1154
- }) {
1155
- const resolvedColor = strokeColor ?? "#FFFF00";
1156
- const thickness = 2 * scale;
1157
- return /* @__PURE__ */ jsx(Fragment, { children: segmentRects.map((r, i) => /* @__PURE__ */ jsx(
1158
- "div",
1159
- {
1160
- onPointerDown: onClick,
1161
- onTouchStart: onClick,
1162
- style: {
1163
- position: "absolute",
1164
- left: (rect ? r.origin.x - rect.origin.x : r.origin.x) * scale,
1165
- top: (rect ? r.origin.y - rect.origin.y : r.origin.y) * scale,
1166
- width: r.size.width * scale,
1167
- height: r.size.height * scale,
1168
- background: "transparent",
1169
- pointerEvents: onClick ? "auto" : "none",
1170
- cursor: onClick ? "pointer" : "default",
1171
- zIndex: onClick ? 1 : 0,
1172
- ...style
1173
- },
1174
- children: /* @__PURE__ */ jsx(
1175
- "div",
1176
- {
1177
- style: {
1178
- position: "absolute",
1179
- left: 0,
1180
- top: "50%",
1181
- width: "100%",
1182
- height: thickness,
1183
- background: resolvedColor,
1184
- opacity,
1185
- transform: "translateY(-50%)",
1186
- pointerEvents: "none"
1187
- }
1188
- }
1189
- )
1190
- },
1191
- i
1192
- )) });
1193
- }
1194
- function Squiggly({
1195
- strokeColor,
1196
- opacity = 0.5,
1197
- segmentRects,
1198
- rect,
1199
- scale,
1200
- onClick,
1201
- style
1202
- }) {
1203
- const resolvedColor = strokeColor ?? "#FFFF00";
1204
- const amplitude = 2 * scale;
1205
- const period = 6 * scale;
1206
- const svg = `<svg xmlns="http://www.w3.org/2000/svg" width="${period}" height="${amplitude * 2}" viewBox="0 0 ${period} ${amplitude * 2}">
1207
- <path d="M0 ${amplitude} Q ${period / 4} 0 ${period / 2} ${amplitude} T ${period} ${amplitude}"
1208
- fill="none" stroke="${resolvedColor}" stroke-width="${amplitude}" stroke-linecap="round"/>
1209
- </svg>`;
1210
- const svgDataUri = `url("data:image/svg+xml;utf8,${encodeURIComponent(svg)}")`;
1211
- return /* @__PURE__ */ jsx(Fragment, { children: segmentRects.map((r, i) => /* @__PURE__ */ jsx(
1212
- "div",
1213
- {
1214
- onPointerDown: onClick,
1215
- onTouchStart: onClick,
1216
- style: {
1217
- position: "absolute",
1218
- left: (rect ? r.origin.x - rect.origin.x : r.origin.x) * scale,
1219
- top: (rect ? r.origin.y - rect.origin.y : r.origin.y) * scale,
1220
- width: r.size.width * scale,
1221
- height: r.size.height * scale,
1222
- background: "transparent",
1223
- pointerEvents: onClick ? "auto" : "none",
1224
- cursor: onClick ? "pointer" : "default",
1225
- zIndex: onClick ? 1 : 0,
1226
- ...style
1227
- },
1228
- children: /* @__PURE__ */ jsx(
1229
- "div",
1230
- {
1231
- style: {
1232
- position: "absolute",
1233
- left: 0,
1234
- bottom: 0,
1235
- width: "100%",
1236
- height: amplitude * 2,
1237
- backgroundImage: svgDataUri,
1238
- backgroundRepeat: "repeat-x",
1239
- backgroundSize: `${period}px ${amplitude * 2}px`,
1240
- opacity,
1241
- pointerEvents: "none"
1242
- }
1243
- }
1244
- )
1245
- },
1246
- i
1247
- )) });
1203
+ function createRenderer(entry) {
1204
+ return {
1205
+ id: entry.id,
1206
+ matches: (annotation) => entry.matches(annotation),
1207
+ render: (props) => entry.render(props),
1208
+ vertexConfig: entry.vertexConfig,
1209
+ zIndex: entry.zIndex,
1210
+ containerStyle: entry.containerStyle,
1211
+ interactionDefaults: entry.interactionDefaults,
1212
+ useAppearanceStream: entry.useAppearanceStream,
1213
+ isDraggable: entry.isDraggable,
1214
+ onDoubleClick: entry.onDoubleClick,
1215
+ selectOverride: entry.selectOverride,
1216
+ hideSelectionMenu: entry.hideSelectionMenu
1217
+ };
1248
1218
  }
1219
+ const MIN_HIT_AREA_SCREEN_PX$5 = 20;
1249
1220
  function Ink({
1250
1221
  isSelected,
1251
1222
  strokeColor,
@@ -1254,7 +1225,8 @@ function Ink({
1254
1225
  inkList,
1255
1226
  rect,
1256
1227
  scale,
1257
- onClick
1228
+ onClick,
1229
+ appearanceActive = false
1258
1230
  }) {
1259
1231
  const resolvedColor = strokeColor ?? "#000000";
1260
1232
  const paths = useMemo(() => {
@@ -1270,7 +1242,8 @@ function Ink({
1270
1242
  }, [inkList, rect]);
1271
1243
  const width = rect.size.width * scale;
1272
1244
  const height = rect.size.height * scale;
1273
- return /* @__PURE__ */ jsx(
1245
+ const hitStrokeWidth = Math.max(strokeWidth, MIN_HIT_AREA_SCREEN_PX$5 / scale);
1246
+ return /* @__PURE__ */ jsxs(
1274
1247
  "svg",
1275
1248
  {
1276
1249
  style: {
@@ -1284,28 +1257,45 @@ function Ink({
1284
1257
  width,
1285
1258
  height,
1286
1259
  viewBox: `0 0 ${rect.size.width} ${rect.size.height}`,
1287
- children: paths.map((d, i) => /* @__PURE__ */ jsx(
1288
- "path",
1289
- {
1290
- d,
1291
- fill: "none",
1292
- opacity,
1293
- onPointerDown: onClick,
1294
- onTouchStart: onClick,
1295
- style: {
1296
- cursor: isSelected ? "move" : "pointer",
1297
- pointerEvents: isSelected ? "none" : "visibleStroke",
1298
- stroke: resolvedColor,
1299
- strokeWidth,
1300
- strokeLinecap: "round",
1301
- strokeLinejoin: "round"
1302
- }
1303
- },
1304
- i
1305
- ))
1260
+ children: [
1261
+ paths.map((d, i) => /* @__PURE__ */ jsx(
1262
+ "path",
1263
+ {
1264
+ d,
1265
+ fill: "none",
1266
+ stroke: "transparent",
1267
+ strokeWidth: hitStrokeWidth,
1268
+ onPointerDown: onClick,
1269
+ style: {
1270
+ cursor: isSelected ? "move" : "pointer",
1271
+ pointerEvents: isSelected ? "none" : "visibleStroke",
1272
+ strokeLinecap: "round",
1273
+ strokeLinejoin: "round"
1274
+ }
1275
+ },
1276
+ `hit-${i}`
1277
+ )),
1278
+ !appearanceActive && paths.map((d, i) => /* @__PURE__ */ jsx(
1279
+ "path",
1280
+ {
1281
+ d,
1282
+ fill: "none",
1283
+ opacity,
1284
+ style: {
1285
+ pointerEvents: "none",
1286
+ stroke: resolvedColor,
1287
+ strokeWidth,
1288
+ strokeLinecap: "round",
1289
+ strokeLinejoin: "round"
1290
+ }
1291
+ },
1292
+ `vis-${i}`
1293
+ ))
1294
+ ]
1306
1295
  }
1307
1296
  );
1308
1297
  }
1298
+ const MIN_HIT_AREA_SCREEN_PX$4 = 20;
1309
1299
  function Square({
1310
1300
  isSelected,
1311
1301
  color = "#000000",
@@ -1316,7 +1306,8 @@ function Square({
1316
1306
  strokeDashArray,
1317
1307
  rect,
1318
1308
  scale,
1319
- onClick
1309
+ onClick,
1310
+ appearanceActive = false
1320
1311
  }) {
1321
1312
  const { width, height, x, y } = useMemo(() => {
1322
1313
  const outerW = rect.size.width;
@@ -1332,7 +1323,8 @@ function Square({
1332
1323
  }, [rect, strokeWidth]);
1333
1324
  const svgWidth = (width + strokeWidth) * scale;
1334
1325
  const svgHeight = (height + strokeWidth) * scale;
1335
- return /* @__PURE__ */ jsx(
1326
+ const hitStrokeWidth = Math.max(strokeWidth, MIN_HIT_AREA_SCREEN_PX$4 / scale);
1327
+ return /* @__PURE__ */ jsxs(
1336
1328
  "svg",
1337
1329
  {
1338
1330
  style: {
@@ -1345,31 +1337,49 @@ function Square({
1345
1337
  width: svgWidth,
1346
1338
  height: svgHeight,
1347
1339
  viewBox: `0 0 ${width + strokeWidth} ${height + strokeWidth}`,
1348
- children: /* @__PURE__ */ jsx(
1349
- "rect",
1350
- {
1351
- x,
1352
- y,
1353
- width,
1354
- height,
1355
- fill: color,
1356
- opacity,
1357
- onPointerDown: onClick,
1358
- onTouchStart: onClick,
1359
- style: {
1360
- cursor: isSelected ? "move" : "pointer",
1361
- pointerEvents: isSelected ? "none" : color === "transparent" ? "visibleStroke" : "visible",
1362
- stroke: strokeColor ?? color,
1363
- strokeWidth,
1364
- ...strokeStyle === PdfAnnotationBorderStyle.DASHED && {
1365
- strokeDasharray: strokeDashArray == null ? void 0 : strokeDashArray.join(",")
1366
- }
1367
- }
1368
- }
1369
- )
1370
- }
1340
+ overflow: "visible",
1341
+ children: [
1342
+ /* @__PURE__ */ jsx(
1343
+ "rect",
1344
+ {
1345
+ x,
1346
+ y,
1347
+ width,
1348
+ height,
1349
+ fill: "transparent",
1350
+ stroke: "transparent",
1351
+ strokeWidth: hitStrokeWidth,
1352
+ onPointerDown: onClick,
1353
+ style: {
1354
+ cursor: isSelected ? "move" : "pointer",
1355
+ pointerEvents: isSelected ? "none" : color === "transparent" ? "visibleStroke" : "visible"
1356
+ }
1357
+ }
1358
+ ),
1359
+ !appearanceActive && /* @__PURE__ */ jsx(
1360
+ "rect",
1361
+ {
1362
+ x,
1363
+ y,
1364
+ width,
1365
+ height,
1366
+ fill: color,
1367
+ opacity,
1368
+ style: {
1369
+ pointerEvents: "none",
1370
+ stroke: strokeColor ?? color,
1371
+ strokeWidth,
1372
+ ...strokeStyle === PdfAnnotationBorderStyle.DASHED && {
1373
+ strokeDasharray: strokeDashArray == null ? void 0 : strokeDashArray.join(",")
1374
+ }
1375
+ }
1376
+ }
1377
+ )
1378
+ ]
1379
+ }
1371
1380
  );
1372
1381
  }
1382
+ const MIN_HIT_AREA_SCREEN_PX$3 = 20;
1373
1383
  function Circle({
1374
1384
  color = "#000000",
1375
1385
  strokeColor,
@@ -1380,7 +1390,8 @@ function Circle({
1380
1390
  rect,
1381
1391
  scale,
1382
1392
  onClick,
1383
- isSelected
1393
+ isSelected,
1394
+ appearanceActive = false
1384
1395
  }) {
1385
1396
  const { width, height, cx, cy, rx, ry } = useMemo(() => {
1386
1397
  const outerW = rect.size.width;
@@ -1390,7 +1401,6 @@ function Circle({
1390
1401
  return {
1391
1402
  width: outerW,
1392
1403
  height: outerH,
1393
- // Centre of the fill sits strokeWidth/2 in from the edges
1394
1404
  cx: strokeWidth / 2 + innerW / 2,
1395
1405
  cy: strokeWidth / 2 + innerH / 2,
1396
1406
  rx: innerW / 2,
@@ -1399,7 +1409,8 @@ function Circle({
1399
1409
  }, [rect, strokeWidth]);
1400
1410
  const svgWidth = width * scale;
1401
1411
  const svgHeight = height * scale;
1402
- return /* @__PURE__ */ jsx(
1412
+ const hitStrokeWidth = Math.max(strokeWidth, MIN_HIT_AREA_SCREEN_PX$3 / scale);
1413
+ return /* @__PURE__ */ jsxs(
1403
1414
  "svg",
1404
1415
  {
1405
1416
  style: {
@@ -1412,31 +1423,49 @@ function Circle({
1412
1423
  width: svgWidth,
1413
1424
  height: svgHeight,
1414
1425
  viewBox: `0 0 ${width} ${height}`,
1415
- children: /* @__PURE__ */ jsx(
1416
- "ellipse",
1417
- {
1418
- cx,
1419
- cy,
1420
- rx,
1421
- ry,
1422
- fill: color,
1423
- opacity,
1424
- onPointerDown: onClick,
1425
- onTouchStart: onClick,
1426
- style: {
1427
- cursor: isSelected ? "move" : "pointer",
1428
- pointerEvents: isSelected ? "none" : color === "transparent" ? "visibleStroke" : "visible",
1429
- stroke: strokeColor ?? color,
1430
- strokeWidth,
1431
- ...strokeStyle === PdfAnnotationBorderStyle.DASHED && {
1432
- strokeDasharray: strokeDashArray == null ? void 0 : strokeDashArray.join(",")
1426
+ overflow: "visible",
1427
+ children: [
1428
+ /* @__PURE__ */ jsx(
1429
+ "ellipse",
1430
+ {
1431
+ cx,
1432
+ cy,
1433
+ rx,
1434
+ ry,
1435
+ fill: "transparent",
1436
+ stroke: "transparent",
1437
+ strokeWidth: hitStrokeWidth,
1438
+ onPointerDown: onClick,
1439
+ style: {
1440
+ cursor: isSelected ? "move" : "pointer",
1441
+ pointerEvents: isSelected ? "none" : color === "transparent" ? "visibleStroke" : "visible"
1433
1442
  }
1434
1443
  }
1435
- }
1436
- )
1444
+ ),
1445
+ !appearanceActive && /* @__PURE__ */ jsx(
1446
+ "ellipse",
1447
+ {
1448
+ cx,
1449
+ cy,
1450
+ rx,
1451
+ ry,
1452
+ fill: color,
1453
+ opacity,
1454
+ style: {
1455
+ pointerEvents: "none",
1456
+ stroke: strokeColor ?? color,
1457
+ strokeWidth,
1458
+ ...strokeStyle === PdfAnnotationBorderStyle.DASHED && {
1459
+ strokeDasharray: strokeDashArray == null ? void 0 : strokeDashArray.join(",")
1460
+ }
1461
+ }
1462
+ }
1463
+ )
1464
+ ]
1437
1465
  }
1438
1466
  );
1439
1467
  }
1468
+ const MIN_HIT_AREA_SCREEN_PX$2 = 20;
1440
1469
  function Line({
1441
1470
  color = "transparent",
1442
1471
  opacity = 1,
@@ -1449,7 +1478,8 @@ function Line({
1449
1478
  lineEndings,
1450
1479
  scale,
1451
1480
  onClick,
1452
- isSelected
1481
+ isSelected,
1482
+ appearanceActive = false
1453
1483
  }) {
1454
1484
  const { x1, y1, x2, y2 } = useMemo(() => {
1455
1485
  return {
@@ -1468,6 +1498,7 @@ function Line({
1468
1498
  }, [lineEndings, strokeWidth, x1, y1, x2, y2]);
1469
1499
  const width = rect.size.width * scale;
1470
1500
  const height = rect.size.height * scale;
1501
+ const hitStrokeWidth = Math.max(strokeWidth, MIN_HIT_AREA_SCREEN_PX$2 / scale);
1471
1502
  return /* @__PURE__ */ jsxs(
1472
1503
  "svg",
1473
1504
  {
@@ -1490,18 +1521,13 @@ function Line({
1490
1521
  y1,
1491
1522
  x2,
1492
1523
  y2,
1493
- opacity,
1524
+ stroke: "transparent",
1525
+ strokeWidth: hitStrokeWidth,
1494
1526
  onPointerDown: onClick,
1495
- onTouchStart: onClick,
1496
1527
  style: {
1497
1528
  cursor: isSelected ? "move" : "pointer",
1498
1529
  pointerEvents: isSelected ? "none" : "visibleStroke",
1499
- stroke: strokeColor,
1500
- strokeWidth,
1501
- strokeLinecap: "butt",
1502
- ...strokeStyle === PdfAnnotationBorderStyle.DASHED && {
1503
- strokeDasharray: strokeDashArray == null ? void 0 : strokeDashArray.join(",")
1504
- }
1530
+ strokeLinecap: "butt"
1505
1531
  }
1506
1532
  }
1507
1533
  ),
@@ -1510,19 +1536,15 @@ function Line({
1510
1536
  {
1511
1537
  d: endings.start.d,
1512
1538
  transform: endings.start.transform,
1539
+ fill: "transparent",
1540
+ stroke: "transparent",
1541
+ strokeWidth: hitStrokeWidth,
1513
1542
  onPointerDown: onClick,
1514
- onTouchStart: onClick,
1515
- stroke: strokeColor,
1516
1543
  style: {
1517
1544
  cursor: isSelected ? "move" : "pointer",
1518
- strokeWidth,
1519
- strokeLinecap: "butt",
1520
1545
  pointerEvents: isSelected ? "none" : endings.start.filled ? "visible" : "visibleStroke",
1521
- ...strokeStyle === PdfAnnotationBorderStyle.DASHED && {
1522
- strokeDasharray: strokeDashArray == null ? void 0 : strokeDashArray.join(",")
1523
- }
1524
- },
1525
- fill: endings.start.filled ? color : "none"
1546
+ strokeLinecap: "butt"
1547
+ }
1526
1548
  }
1527
1549
  ),
1528
1550
  endings.end && /* @__PURE__ */ jsx(
@@ -1530,25 +1552,77 @@ function Line({
1530
1552
  {
1531
1553
  d: endings.end.d,
1532
1554
  transform: endings.end.transform,
1533
- stroke: strokeColor,
1555
+ fill: "transparent",
1556
+ stroke: "transparent",
1557
+ strokeWidth: hitStrokeWidth,
1534
1558
  onPointerDown: onClick,
1535
- onTouchStart: onClick,
1536
1559
  style: {
1537
1560
  cursor: isSelected ? "move" : "pointer",
1538
- strokeWidth,
1539
- strokeLinecap: "butt",
1540
1561
  pointerEvents: isSelected ? "none" : endings.end.filled ? "visible" : "visibleStroke",
1541
- ...strokeStyle === PdfAnnotationBorderStyle.DASHED && {
1542
- strokeDasharray: strokeDashArray == null ? void 0 : strokeDashArray.join(",")
1543
- }
1544
- },
1545
- fill: endings.end.filled ? color : "none"
1562
+ strokeLinecap: "butt"
1563
+ }
1546
1564
  }
1547
- )
1565
+ ),
1566
+ !appearanceActive && /* @__PURE__ */ jsxs(Fragment, { children: [
1567
+ /* @__PURE__ */ jsx(
1568
+ "line",
1569
+ {
1570
+ x1,
1571
+ y1,
1572
+ x2,
1573
+ y2,
1574
+ opacity,
1575
+ style: {
1576
+ pointerEvents: "none",
1577
+ stroke: strokeColor,
1578
+ strokeWidth,
1579
+ strokeLinecap: "butt",
1580
+ ...strokeStyle === PdfAnnotationBorderStyle.DASHED && {
1581
+ strokeDasharray: strokeDashArray == null ? void 0 : strokeDashArray.join(",")
1582
+ }
1583
+ }
1584
+ }
1585
+ ),
1586
+ endings.start && /* @__PURE__ */ jsx(
1587
+ "path",
1588
+ {
1589
+ d: endings.start.d,
1590
+ transform: endings.start.transform,
1591
+ stroke: strokeColor,
1592
+ fill: endings.start.filled ? color : "none",
1593
+ style: {
1594
+ pointerEvents: "none",
1595
+ strokeWidth,
1596
+ strokeLinecap: "butt",
1597
+ ...strokeStyle === PdfAnnotationBorderStyle.DASHED && {
1598
+ strokeDasharray: strokeDashArray == null ? void 0 : strokeDashArray.join(",")
1599
+ }
1600
+ }
1601
+ }
1602
+ ),
1603
+ endings.end && /* @__PURE__ */ jsx(
1604
+ "path",
1605
+ {
1606
+ d: endings.end.d,
1607
+ transform: endings.end.transform,
1608
+ stroke: strokeColor,
1609
+ fill: endings.end.filled ? color : "none",
1610
+ style: {
1611
+ pointerEvents: "none",
1612
+ strokeWidth,
1613
+ strokeLinecap: "butt",
1614
+ ...strokeStyle === PdfAnnotationBorderStyle.DASHED && {
1615
+ strokeDasharray: strokeDashArray == null ? void 0 : strokeDashArray.join(",")
1616
+ }
1617
+ }
1618
+ }
1619
+ )
1620
+ ] })
1548
1621
  ]
1549
1622
  }
1550
1623
  );
1551
1624
  }
1625
+ const MIN_HIT_AREA_SCREEN_PX$1 = 20;
1552
1626
  function Polyline({
1553
1627
  rect,
1554
1628
  vertices,
@@ -1556,10 +1630,13 @@ function Polyline({
1556
1630
  strokeColor = "#000000",
1557
1631
  opacity = 1,
1558
1632
  strokeWidth,
1633
+ strokeStyle = PdfAnnotationBorderStyle.SOLID,
1634
+ strokeDashArray,
1559
1635
  scale,
1560
1636
  isSelected,
1561
1637
  onClick,
1562
- lineEndings
1638
+ lineEndings,
1639
+ appearanceActive = false
1563
1640
  }) {
1564
1641
  const localPts = useMemo(
1565
1642
  () => vertices.map(({ x, y }) => ({ x: x - rect.origin.x, y: y - rect.origin.y })),
@@ -1579,7 +1656,6 @@ function Polyline({
1579
1656
  lineEndings == null ? void 0 : lineEndings.start,
1580
1657
  strokeWidth,
1581
1658
  startRad + Math.PI,
1582
- // tip points outward from line start
1583
1659
  localPts[0].x,
1584
1660
  localPts[0].y
1585
1661
  );
@@ -1587,7 +1663,6 @@ function Polyline({
1587
1663
  lineEndings == null ? void 0 : lineEndings.end,
1588
1664
  strokeWidth,
1589
1665
  endRad,
1590
- // tip points in line direction
1591
1666
  localPts[localPts.length - 1].x,
1592
1667
  localPts[localPts.length - 1].y
1593
1668
  );
@@ -1595,6 +1670,7 @@ function Polyline({
1595
1670
  }, [localPts, lineEndings, strokeWidth]);
1596
1671
  const width = rect.size.width * scale;
1597
1672
  const height = rect.size.height * scale;
1673
+ const hitStrokeWidth = Math.max(strokeWidth, MIN_HIT_AREA_SCREEN_PX$1 / scale);
1598
1674
  return /* @__PURE__ */ jsxs(
1599
1675
  "svg",
1600
1676
  {
@@ -1614,13 +1690,11 @@ function Polyline({
1614
1690
  "path",
1615
1691
  {
1616
1692
  d: pathData,
1693
+ fill: "none",
1694
+ stroke: "transparent",
1695
+ strokeWidth: hitStrokeWidth,
1617
1696
  onPointerDown: onClick,
1618
- onTouchStart: onClick,
1619
- opacity,
1620
1697
  style: {
1621
- fill: "none",
1622
- stroke: strokeColor ?? color,
1623
- strokeWidth,
1624
1698
  cursor: isSelected ? "move" : "pointer",
1625
1699
  pointerEvents: isSelected ? "none" : "visibleStroke",
1626
1700
  strokeLinecap: "butt",
@@ -1633,13 +1707,12 @@ function Polyline({
1633
1707
  {
1634
1708
  d: endings.start.d,
1635
1709
  transform: endings.start.transform,
1636
- stroke: strokeColor,
1637
- fill: endings.start.filled ? color : "none",
1710
+ fill: "transparent",
1711
+ stroke: "transparent",
1712
+ strokeWidth: hitStrokeWidth,
1638
1713
  onPointerDown: onClick,
1639
- onTouchStart: onClick,
1640
1714
  style: {
1641
1715
  cursor: isSelected ? "move" : "pointer",
1642
- strokeWidth,
1643
1716
  pointerEvents: isSelected ? "none" : endings.start.filled ? "visible" : "visibleStroke",
1644
1717
  strokeLinecap: "butt"
1645
1718
  }
@@ -1650,22 +1723,76 @@ function Polyline({
1650
1723
  {
1651
1724
  d: endings.end.d,
1652
1725
  transform: endings.end.transform,
1653
- stroke: strokeColor,
1654
- fill: endings.end.filled ? color : "none",
1726
+ fill: "transparent",
1727
+ stroke: "transparent",
1728
+ strokeWidth: hitStrokeWidth,
1655
1729
  onPointerDown: onClick,
1656
- onTouchStart: onClick,
1657
1730
  style: {
1658
1731
  cursor: isSelected ? "move" : "pointer",
1659
- strokeWidth,
1660
1732
  pointerEvents: isSelected ? "none" : endings.end.filled ? "visible" : "visibleStroke",
1661
1733
  strokeLinecap: "butt"
1662
1734
  }
1663
1735
  }
1664
- )
1736
+ ),
1737
+ !appearanceActive && /* @__PURE__ */ jsxs(Fragment, { children: [
1738
+ /* @__PURE__ */ jsx(
1739
+ "path",
1740
+ {
1741
+ d: pathData,
1742
+ opacity,
1743
+ style: {
1744
+ fill: "none",
1745
+ stroke: strokeColor ?? color,
1746
+ strokeWidth,
1747
+ pointerEvents: "none",
1748
+ strokeLinecap: "butt",
1749
+ strokeLinejoin: "miter",
1750
+ ...strokeStyle === PdfAnnotationBorderStyle.DASHED && {
1751
+ strokeDasharray: strokeDashArray == null ? void 0 : strokeDashArray.join(",")
1752
+ }
1753
+ }
1754
+ }
1755
+ ),
1756
+ endings.start && /* @__PURE__ */ jsx(
1757
+ "path",
1758
+ {
1759
+ d: endings.start.d,
1760
+ transform: endings.start.transform,
1761
+ stroke: strokeColor,
1762
+ fill: endings.start.filled ? color : "none",
1763
+ style: {
1764
+ pointerEvents: "none",
1765
+ strokeWidth,
1766
+ strokeLinecap: "butt",
1767
+ ...strokeStyle === PdfAnnotationBorderStyle.DASHED && {
1768
+ strokeDasharray: strokeDashArray == null ? void 0 : strokeDashArray.join(",")
1769
+ }
1770
+ }
1771
+ }
1772
+ ),
1773
+ endings.end && /* @__PURE__ */ jsx(
1774
+ "path",
1775
+ {
1776
+ d: endings.end.d,
1777
+ transform: endings.end.transform,
1778
+ stroke: strokeColor,
1779
+ fill: endings.end.filled ? color : "none",
1780
+ style: {
1781
+ pointerEvents: "none",
1782
+ strokeWidth,
1783
+ strokeLinecap: "butt",
1784
+ ...strokeStyle === PdfAnnotationBorderStyle.DASHED && {
1785
+ strokeDasharray: strokeDashArray == null ? void 0 : strokeDashArray.join(",")
1786
+ }
1787
+ }
1788
+ }
1789
+ )
1790
+ ] })
1665
1791
  ]
1666
1792
  }
1667
1793
  );
1668
1794
  }
1795
+ const MIN_HIT_AREA_SCREEN_PX = 20;
1669
1796
  function Polygon({
1670
1797
  rect,
1671
1798
  vertices,
@@ -1679,9 +1806,8 @@ function Polygon({
1679
1806
  isSelected,
1680
1807
  onClick,
1681
1808
  currentVertex,
1682
- // A preview-only prop
1683
- handleSize = 14
1684
- // in CSS pixels
1809
+ handleSize = 14,
1810
+ appearanceActive = false
1685
1811
  }) {
1686
1812
  const allPoints = currentVertex ? [...vertices, currentVertex] : vertices;
1687
1813
  const localPts = useMemo(
@@ -1697,6 +1823,7 @@ function Polygon({
1697
1823
  const isPreviewing = currentVertex && vertices.length > 0;
1698
1824
  const width = rect.size.width * scale;
1699
1825
  const height = rect.size.height * scale;
1826
+ const hitStrokeWidth = Math.max(strokeWidth, MIN_HIT_AREA_SCREEN_PX / scale);
1700
1827
  return /* @__PURE__ */ jsxs(
1701
1828
  "svg",
1702
1829
  {
@@ -1716,62 +1843,139 @@ function Polygon({
1716
1843
  "path",
1717
1844
  {
1718
1845
  d: pathData,
1846
+ fill: "transparent",
1847
+ stroke: "transparent",
1848
+ strokeWidth: hitStrokeWidth,
1719
1849
  onPointerDown: onClick,
1720
- onTouchStart: onClick,
1721
- opacity,
1722
1850
  style: {
1723
- fill: currentVertex ? "none" : color,
1724
- // No fill during preview
1725
- stroke: strokeColor ?? color,
1726
- strokeWidth,
1727
1851
  cursor: isSelected ? "move" : "pointer",
1728
1852
  pointerEvents: isSelected ? "none" : color === "transparent" ? "visibleStroke" : "visible",
1729
1853
  strokeLinecap: "butt",
1730
- strokeLinejoin: "miter",
1731
- ...strokeStyle === PdfAnnotationBorderStyle.DASHED && {
1732
- strokeDasharray: strokeDashArray == null ? void 0 : strokeDashArray.join(",")
1733
- }
1854
+ strokeLinejoin: "miter"
1734
1855
  }
1735
1856
  }
1736
1857
  ),
1737
- isPreviewing && vertices.length > 1 && /* @__PURE__ */ jsx(
1738
- "path",
1739
- {
1740
- d: `M ${localPts[localPts.length - 1].x} ${localPts[localPts.length - 1].y} L ${localPts[0].x} ${localPts[0].y}`,
1741
- fill: "none",
1742
- style: { stroke: strokeColor, strokeWidth, strokeDasharray: "4,4", opacity: 0.7 }
1743
- }
1744
- ),
1745
- isPreviewing && vertices.length >= 2 && /* @__PURE__ */ jsx(
1746
- "rect",
1747
- {
1748
- x: localPts[0].x - handleSize / scale / 2,
1749
- y: localPts[0].y - handleSize / scale / 2,
1750
- width: handleSize / scale,
1751
- height: handleSize / scale,
1752
- fill: strokeColor,
1753
- opacity: 0.4,
1754
- stroke: strokeColor,
1755
- strokeWidth: strokeWidth / 2
1756
- }
1757
- )
1858
+ !appearanceActive && /* @__PURE__ */ jsxs(Fragment, { children: [
1859
+ /* @__PURE__ */ jsx(
1860
+ "path",
1861
+ {
1862
+ d: pathData,
1863
+ opacity,
1864
+ style: {
1865
+ fill: currentVertex ? "none" : color,
1866
+ stroke: strokeColor ?? color,
1867
+ strokeWidth,
1868
+ pointerEvents: "none",
1869
+ strokeLinecap: "butt",
1870
+ strokeLinejoin: "miter",
1871
+ ...strokeStyle === PdfAnnotationBorderStyle.DASHED && {
1872
+ strokeDasharray: strokeDashArray == null ? void 0 : strokeDashArray.join(",")
1873
+ }
1874
+ }
1875
+ }
1876
+ ),
1877
+ isPreviewing && vertices.length > 1 && /* @__PURE__ */ jsx(
1878
+ "path",
1879
+ {
1880
+ d: `M ${localPts[localPts.length - 1].x} ${localPts[localPts.length - 1].y} L ${localPts[0].x} ${localPts[0].y}`,
1881
+ fill: "none",
1882
+ style: {
1883
+ stroke: strokeColor,
1884
+ strokeWidth,
1885
+ strokeDasharray: "4,4",
1886
+ opacity: 0.7,
1887
+ pointerEvents: "none"
1888
+ }
1889
+ }
1890
+ ),
1891
+ isPreviewing && vertices.length >= 2 && /* @__PURE__ */ jsx(
1892
+ "rect",
1893
+ {
1894
+ x: localPts[0].x - handleSize / scale / 2,
1895
+ y: localPts[0].y - handleSize / scale / 2,
1896
+ width: handleSize / scale,
1897
+ height: handleSize / scale,
1898
+ fill: strokeColor,
1899
+ opacity: 0.4,
1900
+ stroke: strokeColor,
1901
+ strokeWidth: strokeWidth / 2,
1902
+ style: { pointerEvents: "none" }
1903
+ }
1904
+ )
1905
+ ] })
1758
1906
  ]
1759
1907
  }
1760
1908
  );
1761
1909
  }
1910
+ function Text({
1911
+ isSelected,
1912
+ color = "#facc15",
1913
+ opacity = 1,
1914
+ onClick,
1915
+ appearanceActive = false
1916
+ }) {
1917
+ const lineColor = getContrastStrokeColor(color);
1918
+ return /* @__PURE__ */ jsx(
1919
+ "div",
1920
+ {
1921
+ style: {
1922
+ position: "absolute",
1923
+ inset: 0,
1924
+ zIndex: 2,
1925
+ pointerEvents: isSelected ? "none" : "auto",
1926
+ cursor: isSelected ? "move" : "pointer"
1927
+ },
1928
+ onPointerDown: onClick,
1929
+ children: !appearanceActive && /* @__PURE__ */ jsxs(
1930
+ "svg",
1931
+ {
1932
+ style: {
1933
+ position: "absolute",
1934
+ inset: 0,
1935
+ pointerEvents: "none"
1936
+ },
1937
+ viewBox: "0 0 20 20",
1938
+ width: "100%",
1939
+ height: "100%",
1940
+ children: [
1941
+ /* @__PURE__ */ jsx(
1942
+ "path",
1943
+ {
1944
+ d: "M 0.5 15.5 L 0.5 0.5 L 19.5 0.5 L 19.5 15.5 L 8.5 15.5 L 6.5 19.5 L 4.5 15.5 Z",
1945
+ fill: color,
1946
+ opacity,
1947
+ stroke: lineColor,
1948
+ strokeWidth: "1",
1949
+ strokeLinejoin: "miter"
1950
+ }
1951
+ ),
1952
+ /* @__PURE__ */ jsx("line", { x1: "2.5", y1: "4.25", x2: "17.5", y2: "4.25", stroke: lineColor, strokeWidth: "1" }),
1953
+ /* @__PURE__ */ jsx("line", { x1: "2.5", y1: "8", x2: "17.5", y2: "8", stroke: lineColor, strokeWidth: "1" }),
1954
+ /* @__PURE__ */ jsx("line", { x1: "2.5", y1: "11.75", x2: "17.5", y2: "11.75", stroke: lineColor, strokeWidth: "1" })
1955
+ ]
1956
+ }
1957
+ )
1958
+ }
1959
+ );
1960
+ }
1762
1961
  function FreeText({
1962
+ documentId,
1763
1963
  isSelected,
1764
1964
  isEditing,
1765
1965
  annotation,
1766
1966
  pageIndex,
1767
1967
  scale,
1768
- onClick
1968
+ onClick,
1969
+ appearanceActive = false
1769
1970
  }) {
1770
1971
  const editorRef = useRef(null);
1771
- const { provides: annotationProvides } = useAnnotationCapability();
1972
+ const editingRef = useRef(false);
1973
+ const { provides: annotationCapability } = useAnnotationCapability();
1974
+ const annotationProvides = (annotationCapability == null ? void 0 : annotationCapability.forDocument(documentId)) ?? null;
1772
1975
  const [isIOS, setIsIOS] = useState(false);
1773
1976
  useEffect(() => {
1774
1977
  if (isEditing && editorRef.current) {
1978
+ editingRef.current = true;
1775
1979
  const editor = editorRef.current;
1776
1980
  editor.focus();
1777
1981
  const selection = window.getSelection();
@@ -1794,6 +1998,8 @@ function FreeText({
1794
1998
  }
1795
1999
  }, []);
1796
2000
  const handleBlur = () => {
2001
+ if (!editingRef.current) return;
2002
+ editingRef.current = false;
1797
2003
  if (!annotationProvides) return;
1798
2004
  if (!editorRef.current) return;
1799
2005
  annotationProvides.updateAnnotation(pageIndex, annotation.object.id, {
@@ -1815,10 +2021,10 @@ function FreeText({
1815
2021
  height: annotation.object.rect.size.height * scale,
1816
2022
  cursor: isSelected && !isEditing ? "move" : "default",
1817
2023
  pointerEvents: isSelected && !isEditing ? "none" : "auto",
1818
- zIndex: 2
2024
+ zIndex: 2,
2025
+ opacity: appearanceActive ? 0 : 1
1819
2026
  },
1820
2027
  onPointerDown: onClick,
1821
- onTouchStart: onClick,
1822
2028
  children: /* @__PURE__ */ jsx(
1823
2029
  "span",
1824
2030
  {
@@ -1945,7 +2151,6 @@ function Stamp({
1945
2151
  cursor: "pointer"
1946
2152
  },
1947
2153
  onPointerDown: onClick,
1948
- onTouchStart: onClick,
1949
2154
  children: /* @__PURE__ */ jsx(
1950
2155
  RenderAnnotation,
1951
2156
  {
@@ -1984,7 +2189,7 @@ function Link({
1984
2189
  }
1985
2190
  return void 0;
1986
2191
  }, [strokeStyle, strokeDashArray, strokeWidth]);
1987
- const isUnderline2 = strokeStyle === PdfAnnotationBorderStyle.UNDERLINE;
2192
+ const isUnderline = strokeStyle === PdfAnnotationBorderStyle.UNDERLINE;
1988
2193
  return /* @__PURE__ */ jsxs(
1989
2194
  "svg",
1990
2195
  {
@@ -2008,14 +2213,13 @@ function Link({
2008
2213
  height,
2009
2214
  fill: "transparent",
2010
2215
  onPointerDown: hasIRT ? void 0 : onClick,
2011
- onTouchStart: hasIRT ? void 0 : onClick,
2012
2216
  style: {
2013
2217
  cursor: hasIRT ? "default" : isSelected ? "move" : "pointer",
2014
2218
  pointerEvents: hasIRT ? "none" : isSelected ? "none" : "visible"
2015
2219
  }
2016
2220
  }
2017
2221
  ),
2018
- isUnderline2 ? (
2222
+ isUnderline ? (
2019
2223
  // Underline style: line at bottom of rect
2020
2224
  /* @__PURE__ */ jsx(
2021
2225
  "line",
@@ -2055,45 +2259,603 @@ function Link({
2055
2259
  }
2056
2260
  );
2057
2261
  }
2058
- function Annotations(annotationsProps) {
2059
- const { documentId, pageIndex, scale, pageWidth, pageHeight, selectionMenu } = annotationsProps;
2060
- const { provides: annotationCapability } = useAnnotationCapability();
2061
- const { provides: selectionProvides } = useSelectionCapability();
2062
- const [annotations, setAnnotations] = useState([]);
2063
- const { register } = usePointerHandlers({ documentId, pageIndex });
2064
- const [allSelectedIds, setAllSelectedIds] = useState([]);
2065
- const [editingId, setEditingId] = useState(null);
2066
- const annotationProvides = useMemo(
2067
- () => annotationCapability ? annotationCapability.forDocument(documentId) : null,
2068
- [annotationCapability, documentId]
2069
- );
2070
- const isMultiSelected = allSelectedIds.length > 1;
2071
- useEffect(() => {
2072
- if (annotationProvides) {
2073
- const currentState = annotationProvides.getState();
2074
- setAnnotations(getAnnotationsByPageIndex(currentState, pageIndex));
2075
- setAllSelectedIds(getSelectedAnnotationIds(currentState));
2076
- return annotationProvides.onStateChange((state) => {
2077
- setAnnotations(getAnnotationsByPageIndex(state, pageIndex));
2078
- setAllSelectedIds(getSelectedAnnotationIds(state));
2079
- });
2080
- }
2081
- }, [annotationProvides, pageIndex]);
2082
- const handlers = useMemo(
2083
- () => ({
2084
- onPointerDown: (_, pe) => {
2085
- if (pe.target === pe.currentTarget && annotationProvides) {
2086
- annotationProvides.deselectAnnotation();
2087
- setEditingId(null);
2088
- }
2089
- }
2090
- }),
2091
- [annotationProvides]
2092
- );
2093
- const handleClick = useCallback(
2094
- (e, annotation) => {
2095
- e.stopPropagation();
2096
- if (annotationProvides && selectionProvides) {
2262
+ function Highlight({
2263
+ strokeColor,
2264
+ opacity = 0.5,
2265
+ segmentRects,
2266
+ rect,
2267
+ scale,
2268
+ onClick,
2269
+ style,
2270
+ appearanceActive = false
2271
+ }) {
2272
+ const resolvedColor = strokeColor ?? "#FFFF00";
2273
+ return /* @__PURE__ */ jsx(Fragment, { children: segmentRects.map((b, i) => /* @__PURE__ */ jsx(
2274
+ "div",
2275
+ {
2276
+ onPointerDown: onClick,
2277
+ style: {
2278
+ position: "absolute",
2279
+ left: (rect ? b.origin.x - rect.origin.x : b.origin.x) * scale,
2280
+ top: (rect ? b.origin.y - rect.origin.y : b.origin.y) * scale,
2281
+ width: b.size.width * scale,
2282
+ height: b.size.height * scale,
2283
+ background: appearanceActive ? "transparent" : resolvedColor,
2284
+ opacity: appearanceActive ? void 0 : opacity,
2285
+ pointerEvents: onClick ? "auto" : "none",
2286
+ cursor: onClick ? "pointer" : "default",
2287
+ zIndex: onClick ? 1 : void 0,
2288
+ ...style
2289
+ }
2290
+ },
2291
+ i
2292
+ )) });
2293
+ }
2294
+ function Underline({
2295
+ strokeColor,
2296
+ opacity = 0.5,
2297
+ segmentRects,
2298
+ rect,
2299
+ scale,
2300
+ onClick,
2301
+ style,
2302
+ appearanceActive = false
2303
+ }) {
2304
+ const resolvedColor = strokeColor ?? "#FFFF00";
2305
+ const thickness = 2 * scale;
2306
+ return /* @__PURE__ */ jsx(Fragment, { children: segmentRects.map((r, i) => /* @__PURE__ */ jsx(
2307
+ "div",
2308
+ {
2309
+ onPointerDown: onClick,
2310
+ style: {
2311
+ position: "absolute",
2312
+ left: (rect ? r.origin.x - rect.origin.x : r.origin.x) * scale,
2313
+ top: (rect ? r.origin.y - rect.origin.y : r.origin.y) * scale,
2314
+ width: r.size.width * scale,
2315
+ height: r.size.height * scale,
2316
+ background: "transparent",
2317
+ pointerEvents: onClick ? "auto" : "none",
2318
+ cursor: onClick ? "pointer" : "default",
2319
+ zIndex: onClick ? 1 : 0,
2320
+ ...style
2321
+ },
2322
+ children: !appearanceActive && /* @__PURE__ */ jsx(
2323
+ "div",
2324
+ {
2325
+ style: {
2326
+ position: "absolute",
2327
+ left: 0,
2328
+ bottom: 0,
2329
+ width: "100%",
2330
+ height: thickness,
2331
+ background: resolvedColor,
2332
+ opacity,
2333
+ pointerEvents: "none"
2334
+ }
2335
+ }
2336
+ )
2337
+ },
2338
+ i
2339
+ )) });
2340
+ }
2341
+ function Strikeout({
2342
+ strokeColor,
2343
+ opacity = 0.5,
2344
+ segmentRects,
2345
+ rect,
2346
+ scale,
2347
+ onClick,
2348
+ style,
2349
+ appearanceActive = false
2350
+ }) {
2351
+ const resolvedColor = strokeColor ?? "#FFFF00";
2352
+ const thickness = 2 * scale;
2353
+ return /* @__PURE__ */ jsx(Fragment, { children: segmentRects.map((r, i) => /* @__PURE__ */ jsx(
2354
+ "div",
2355
+ {
2356
+ onPointerDown: onClick,
2357
+ style: {
2358
+ position: "absolute",
2359
+ left: (rect ? r.origin.x - rect.origin.x : r.origin.x) * scale,
2360
+ top: (rect ? r.origin.y - rect.origin.y : r.origin.y) * scale,
2361
+ width: r.size.width * scale,
2362
+ height: r.size.height * scale,
2363
+ background: "transparent",
2364
+ pointerEvents: onClick ? "auto" : "none",
2365
+ cursor: onClick ? "pointer" : "default",
2366
+ zIndex: onClick ? 1 : 0,
2367
+ ...style
2368
+ },
2369
+ children: !appearanceActive && /* @__PURE__ */ jsx(
2370
+ "div",
2371
+ {
2372
+ style: {
2373
+ position: "absolute",
2374
+ left: 0,
2375
+ top: "50%",
2376
+ width: "100%",
2377
+ height: thickness,
2378
+ background: resolvedColor,
2379
+ opacity,
2380
+ transform: "translateY(-50%)",
2381
+ pointerEvents: "none"
2382
+ }
2383
+ }
2384
+ )
2385
+ },
2386
+ i
2387
+ )) });
2388
+ }
2389
+ function Squiggly({
2390
+ strokeColor,
2391
+ opacity = 0.5,
2392
+ segmentRects,
2393
+ rect,
2394
+ scale,
2395
+ onClick,
2396
+ style,
2397
+ appearanceActive = false
2398
+ }) {
2399
+ const resolvedColor = strokeColor ?? "#FFFF00";
2400
+ const amplitude = 2 * scale;
2401
+ const period = 6 * scale;
2402
+ const svg = `<svg xmlns="http://www.w3.org/2000/svg" width="${period}" height="${amplitude * 2}" viewBox="0 0 ${period} ${amplitude * 2}">
2403
+ <path d="M0 ${amplitude} Q ${period / 4} 0 ${period / 2} ${amplitude} T ${period} ${amplitude}"
2404
+ fill="none" stroke="${resolvedColor}" stroke-width="${amplitude}" stroke-linecap="round"/>
2405
+ </svg>`;
2406
+ const svgDataUri = `url("data:image/svg+xml;utf8,${encodeURIComponent(svg)}")`;
2407
+ return /* @__PURE__ */ jsx(Fragment, { children: segmentRects.map((r, i) => /* @__PURE__ */ jsx(
2408
+ "div",
2409
+ {
2410
+ onPointerDown: onClick,
2411
+ style: {
2412
+ position: "absolute",
2413
+ left: (rect ? r.origin.x - rect.origin.x : r.origin.x) * scale,
2414
+ top: (rect ? r.origin.y - rect.origin.y : r.origin.y) * scale,
2415
+ width: r.size.width * scale,
2416
+ height: r.size.height * scale,
2417
+ background: "transparent",
2418
+ pointerEvents: onClick ? "auto" : "none",
2419
+ cursor: onClick ? "pointer" : "default",
2420
+ zIndex: onClick ? 1 : 0,
2421
+ ...style
2422
+ },
2423
+ children: !appearanceActive && /* @__PURE__ */ jsx(
2424
+ "div",
2425
+ {
2426
+ style: {
2427
+ position: "absolute",
2428
+ left: 0,
2429
+ bottom: 0,
2430
+ width: "100%",
2431
+ height: amplitude * 2,
2432
+ backgroundImage: svgDataUri,
2433
+ backgroundRepeat: "repeat-x",
2434
+ backgroundSize: `${period}px ${amplitude * 2}px`,
2435
+ opacity,
2436
+ pointerEvents: "none"
2437
+ }
2438
+ }
2439
+ )
2440
+ },
2441
+ i
2442
+ )) });
2443
+ }
2444
+ function Caret({
2445
+ isSelected,
2446
+ strokeColor = "#000000",
2447
+ opacity = 1,
2448
+ rect,
2449
+ scale,
2450
+ onClick,
2451
+ appearanceActive = false
2452
+ }) {
2453
+ const { width, height, path } = useMemo(() => {
2454
+ const w = rect.size.width;
2455
+ const h = rect.size.height;
2456
+ const midX = w / 2;
2457
+ const d = [
2458
+ `M 0 ${h}`,
2459
+ `C ${w * 0.27} ${h} ${midX} ${h - h * 0.44} ${midX} 0`,
2460
+ `C ${midX} ${h - h * 0.44} ${w - w * 0.27} ${h} ${w} ${h}`,
2461
+ "Z"
2462
+ ].join(" ");
2463
+ return { width: w, height: h, path: d };
2464
+ }, [rect]);
2465
+ const svgWidth = width * scale;
2466
+ const svgHeight = height * scale;
2467
+ return /* @__PURE__ */ jsxs(
2468
+ "svg",
2469
+ {
2470
+ style: {
2471
+ position: "absolute",
2472
+ width: svgWidth,
2473
+ height: svgHeight,
2474
+ pointerEvents: "none",
2475
+ zIndex: 2
2476
+ },
2477
+ width: svgWidth,
2478
+ height: svgHeight,
2479
+ viewBox: `0 0 ${width} ${height}`,
2480
+ overflow: "visible",
2481
+ children: [
2482
+ /* @__PURE__ */ jsx(
2483
+ "path",
2484
+ {
2485
+ d: path,
2486
+ fill: "transparent",
2487
+ stroke: "transparent",
2488
+ strokeWidth: 4,
2489
+ onPointerDown: onClick,
2490
+ style: {
2491
+ cursor: isSelected ? "move" : "pointer",
2492
+ pointerEvents: isSelected ? "none" : "visible"
2493
+ }
2494
+ }
2495
+ ),
2496
+ !appearanceActive && /* @__PURE__ */ jsx(
2497
+ "path",
2498
+ {
2499
+ d: path,
2500
+ fill: strokeColor,
2501
+ stroke: strokeColor,
2502
+ strokeWidth: 0.5,
2503
+ opacity,
2504
+ fillRule: "evenodd",
2505
+ style: { pointerEvents: "none" }
2506
+ }
2507
+ )
2508
+ ]
2509
+ }
2510
+ );
2511
+ }
2512
+ const builtInRenderers = [
2513
+ // --- Drawing ---
2514
+ createRenderer({
2515
+ id: "ink",
2516
+ matches: (a) => a.type === PdfAnnotationSubtype.INK,
2517
+ render: ({ currentObject, isSelected, scale, onClick, appearanceActive }) => /* @__PURE__ */ jsx(
2518
+ Ink,
2519
+ {
2520
+ ...currentObject,
2521
+ isSelected,
2522
+ scale,
2523
+ onClick,
2524
+ appearanceActive
2525
+ }
2526
+ ),
2527
+ interactionDefaults: { isDraggable: true, isResizable: true, isRotatable: true }
2528
+ }),
2529
+ // --- Shapes ---
2530
+ createRenderer({
2531
+ id: "square",
2532
+ matches: (a) => a.type === PdfAnnotationSubtype.SQUARE,
2533
+ render: ({ currentObject, isSelected, scale, onClick, appearanceActive }) => /* @__PURE__ */ jsx(
2534
+ Square,
2535
+ {
2536
+ ...currentObject,
2537
+ isSelected,
2538
+ scale,
2539
+ onClick,
2540
+ appearanceActive
2541
+ }
2542
+ ),
2543
+ interactionDefaults: { isDraggable: true, isResizable: true, isRotatable: true }
2544
+ }),
2545
+ createRenderer({
2546
+ id: "circle",
2547
+ matches: (a) => a.type === PdfAnnotationSubtype.CIRCLE,
2548
+ render: ({ currentObject, isSelected, scale, onClick, appearanceActive }) => /* @__PURE__ */ jsx(
2549
+ Circle,
2550
+ {
2551
+ ...currentObject,
2552
+ isSelected,
2553
+ scale,
2554
+ onClick,
2555
+ appearanceActive
2556
+ }
2557
+ ),
2558
+ interactionDefaults: { isDraggable: true, isResizable: true, isRotatable: true }
2559
+ }),
2560
+ // --- Lines & Vertex-based ---
2561
+ createRenderer({
2562
+ id: "line",
2563
+ matches: (a) => a.type === PdfAnnotationSubtype.LINE,
2564
+ render: ({ currentObject, isSelected, scale, onClick, appearanceActive }) => /* @__PURE__ */ jsx(Fragment$1, { children: /* @__PURE__ */ jsx(
2565
+ Line,
2566
+ {
2567
+ ...currentObject,
2568
+ isSelected,
2569
+ scale,
2570
+ onClick,
2571
+ appearanceActive
2572
+ }
2573
+ ) }),
2574
+ vertexConfig: {
2575
+ extractVertices: (a) => [a.linePoints.start, a.linePoints.end],
2576
+ transformAnnotation: (a, v) => ({
2577
+ ...a,
2578
+ linePoints: { start: v[0], end: v[1] }
2579
+ })
2580
+ },
2581
+ interactionDefaults: { isDraggable: true, isResizable: false, isRotatable: true }
2582
+ }),
2583
+ createRenderer({
2584
+ id: "polyline",
2585
+ matches: (a) => a.type === PdfAnnotationSubtype.POLYLINE,
2586
+ render: ({ currentObject, isSelected, scale, onClick, appearanceActive }) => /* @__PURE__ */ jsx(Fragment$1, { children: /* @__PURE__ */ jsx(
2587
+ Polyline,
2588
+ {
2589
+ ...currentObject,
2590
+ isSelected,
2591
+ scale,
2592
+ onClick,
2593
+ appearanceActive
2594
+ }
2595
+ ) }),
2596
+ vertexConfig: {
2597
+ extractVertices: (a) => a.vertices,
2598
+ transformAnnotation: (a, vertices) => ({ ...a, vertices })
2599
+ },
2600
+ interactionDefaults: { isDraggable: true, isResizable: false, isRotatable: true }
2601
+ }),
2602
+ createRenderer({
2603
+ id: "polygon",
2604
+ matches: (a) => a.type === PdfAnnotationSubtype.POLYGON,
2605
+ render: ({ currentObject, isSelected, scale, onClick, appearanceActive }) => /* @__PURE__ */ jsx(Fragment$1, { children: /* @__PURE__ */ jsx(
2606
+ Polygon,
2607
+ {
2608
+ ...currentObject,
2609
+ isSelected,
2610
+ scale,
2611
+ onClick,
2612
+ appearanceActive
2613
+ }
2614
+ ) }),
2615
+ vertexConfig: {
2616
+ extractVertices: (a) => a.vertices,
2617
+ transformAnnotation: (a, vertices) => ({ ...a, vertices })
2618
+ },
2619
+ interactionDefaults: { isDraggable: true, isResizable: false, isRotatable: true }
2620
+ }),
2621
+ // --- Text Markup ---
2622
+ createRenderer({
2623
+ id: "highlight",
2624
+ matches: (a) => a.type === PdfAnnotationSubtype.HIGHLIGHT,
2625
+ render: ({ currentObject, scale, onClick, appearanceActive }) => /* @__PURE__ */ jsx(
2626
+ Highlight,
2627
+ {
2628
+ ...currentObject,
2629
+ scale,
2630
+ onClick,
2631
+ appearanceActive
2632
+ }
2633
+ ),
2634
+ zIndex: 0,
2635
+ interactionDefaults: { isDraggable: false, isResizable: false, isRotatable: false },
2636
+ containerStyle: (a) => ({
2637
+ mixBlendMode: blendModeToCss(a.blendMode ?? PdfBlendMode.Multiply)
2638
+ })
2639
+ }),
2640
+ createRenderer({
2641
+ id: "underline",
2642
+ matches: (a) => a.type === PdfAnnotationSubtype.UNDERLINE,
2643
+ render: ({ currentObject, scale, onClick, appearanceActive }) => /* @__PURE__ */ jsx(
2644
+ Underline,
2645
+ {
2646
+ ...currentObject,
2647
+ scale,
2648
+ onClick,
2649
+ appearanceActive
2650
+ }
2651
+ ),
2652
+ zIndex: 0,
2653
+ interactionDefaults: { isDraggable: false, isResizable: false, isRotatable: false }
2654
+ }),
2655
+ createRenderer({
2656
+ id: "strikeout",
2657
+ matches: (a) => a.type === PdfAnnotationSubtype.STRIKEOUT,
2658
+ render: ({ currentObject, scale, onClick, appearanceActive }) => /* @__PURE__ */ jsx(
2659
+ Strikeout,
2660
+ {
2661
+ ...currentObject,
2662
+ scale,
2663
+ onClick,
2664
+ appearanceActive
2665
+ }
2666
+ ),
2667
+ zIndex: 0,
2668
+ interactionDefaults: { isDraggable: false, isResizable: false, isRotatable: false }
2669
+ }),
2670
+ createRenderer({
2671
+ id: "squiggly",
2672
+ matches: (a) => a.type === PdfAnnotationSubtype.SQUIGGLY,
2673
+ render: ({ currentObject, scale, onClick, appearanceActive }) => /* @__PURE__ */ jsx(
2674
+ Squiggly,
2675
+ {
2676
+ ...currentObject,
2677
+ scale,
2678
+ onClick,
2679
+ appearanceActive
2680
+ }
2681
+ ),
2682
+ zIndex: 0,
2683
+ interactionDefaults: { isDraggable: false, isResizable: false, isRotatable: false }
2684
+ }),
2685
+ // --- Text Comment ---
2686
+ createRenderer({
2687
+ id: "text",
2688
+ matches: (a) => a.type === PdfAnnotationSubtype.TEXT && !a.inReplyToId,
2689
+ render: ({ currentObject, isSelected, onClick, appearanceActive }) => /* @__PURE__ */ jsx(
2690
+ Text,
2691
+ {
2692
+ isSelected,
2693
+ color: currentObject.strokeColor ?? currentObject.color,
2694
+ opacity: currentObject.opacity,
2695
+ onClick,
2696
+ appearanceActive
2697
+ }
2698
+ ),
2699
+ interactionDefaults: { isDraggable: true, isResizable: false, isRotatable: false }
2700
+ }),
2701
+ // --- Caret ---
2702
+ createRenderer({
2703
+ id: "caret",
2704
+ matches: (a) => a.type === PdfAnnotationSubtype.CARET,
2705
+ render: ({ currentObject, isSelected, scale, onClick, appearanceActive }) => /* @__PURE__ */ jsx(
2706
+ Caret,
2707
+ {
2708
+ ...currentObject,
2709
+ isSelected,
2710
+ scale,
2711
+ onClick,
2712
+ appearanceActive
2713
+ }
2714
+ ),
2715
+ interactionDefaults: { isDraggable: false, isResizable: false, isRotatable: false }
2716
+ }),
2717
+ // --- FreeText ---
2718
+ createRenderer({
2719
+ id: "freeText",
2720
+ matches: (a) => a.type === PdfAnnotationSubtype.FREETEXT,
2721
+ render: ({
2722
+ annotation,
2723
+ currentObject,
2724
+ isSelected,
2725
+ isEditing,
2726
+ scale,
2727
+ pageIndex,
2728
+ documentId,
2729
+ onClick,
2730
+ appearanceActive
2731
+ }) => /* @__PURE__ */ jsx(
2732
+ FreeText,
2733
+ {
2734
+ documentId,
2735
+ isSelected,
2736
+ isEditing,
2737
+ annotation: { ...annotation, object: currentObject },
2738
+ pageIndex,
2739
+ scale,
2740
+ onClick,
2741
+ appearanceActive
2742
+ }
2743
+ ),
2744
+ interactionDefaults: { isDraggable: true, isResizable: true, isRotatable: true },
2745
+ isDraggable: (toolDraggable, { isEditing }) => toolDraggable && !isEditing,
2746
+ onDoubleClick: (id, setEditingId) => setEditingId(id)
2747
+ }),
2748
+ // --- Stamp ---
2749
+ createRenderer({
2750
+ id: "stamp",
2751
+ matches: (a) => a.type === PdfAnnotationSubtype.STAMP,
2752
+ render: ({ annotation, isSelected, documentId, pageIndex, scale, onClick }) => /* @__PURE__ */ jsx(
2753
+ Stamp,
2754
+ {
2755
+ isSelected,
2756
+ annotation,
2757
+ documentId,
2758
+ pageIndex,
2759
+ scale,
2760
+ onClick
2761
+ }
2762
+ ),
2763
+ useAppearanceStream: false,
2764
+ interactionDefaults: { isDraggable: true, isResizable: true, isRotatable: true }
2765
+ }),
2766
+ // --- Link ---
2767
+ createRenderer({
2768
+ id: "link",
2769
+ matches: (a) => a.type === PdfAnnotationSubtype.LINK,
2770
+ render: ({ currentObject, isSelected, scale, onClick }) => /* @__PURE__ */ jsx(
2771
+ Link,
2772
+ {
2773
+ ...currentObject,
2774
+ isSelected,
2775
+ scale,
2776
+ onClick,
2777
+ hasIRT: !!currentObject.inReplyToId
2778
+ }
2779
+ ),
2780
+ interactionDefaults: {
2781
+ isDraggable: false,
2782
+ isResizable: false,
2783
+ isRotatable: false
2784
+ },
2785
+ useAppearanceStream: false,
2786
+ selectOverride: (e, annotation, helpers) => {
2787
+ e.stopPropagation();
2788
+ helpers.clearSelection();
2789
+ if (annotation.object.inReplyToId) {
2790
+ const parent = helpers.allAnnotations.find(
2791
+ (a) => a.object.id === annotation.object.inReplyToId
2792
+ );
2793
+ if (parent) {
2794
+ helpers.selectAnnotation(parent.object.pageIndex, parent.object.id);
2795
+ return;
2796
+ }
2797
+ }
2798
+ helpers.selectAnnotation(helpers.pageIndex, annotation.object.id);
2799
+ },
2800
+ hideSelectionMenu: (a) => !!a.inReplyToId
2801
+ })
2802
+ ];
2803
+ function Annotations(annotationsProps) {
2804
+ const { documentId, pageIndex, scale, pageWidth, pageHeight, selectionMenu } = annotationsProps;
2805
+ const { provides: annotationCapability } = useAnnotationCapability();
2806
+ const { provides: selectionProvides } = useSelectionCapability();
2807
+ const [annotations, setAnnotations] = useState([]);
2808
+ const { register } = usePointerHandlers({ documentId, pageIndex });
2809
+ const [allSelectedIds, setAllSelectedIds] = useState([]);
2810
+ const [editingId, setEditingId] = useState(null);
2811
+ const [appearanceMap, setAppearanceMap] = useState({});
2812
+ const prevScaleRef = useRef(scale);
2813
+ const annotationProvides = useMemo(
2814
+ () => annotationCapability ? annotationCapability.forDocument(documentId) : null,
2815
+ [annotationCapability, documentId]
2816
+ );
2817
+ const isMultiSelected = allSelectedIds.length > 1;
2818
+ useEffect(() => {
2819
+ if (annotationProvides) {
2820
+ const currentState = annotationProvides.getState();
2821
+ setAnnotations(getAnnotationsByPageIndex(currentState, pageIndex));
2822
+ setAllSelectedIds(getSelectedAnnotationIds(currentState));
2823
+ return annotationProvides.onStateChange((state) => {
2824
+ setAnnotations(getAnnotationsByPageIndex(state, pageIndex));
2825
+ setAllSelectedIds(getSelectedAnnotationIds(state));
2826
+ });
2827
+ }
2828
+ }, [annotationProvides, pageIndex]);
2829
+ useEffect(() => {
2830
+ if (!annotationProvides) return;
2831
+ if (prevScaleRef.current !== scale) {
2832
+ annotationProvides.invalidatePageAppearances(pageIndex);
2833
+ prevScaleRef.current = scale;
2834
+ }
2835
+ const task = annotationProvides.getPageAppearances(pageIndex, {
2836
+ scaleFactor: scale,
2837
+ dpr: typeof window !== "undefined" ? window.devicePixelRatio : 1
2838
+ });
2839
+ task.wait(
2840
+ (map) => setAppearanceMap(map),
2841
+ () => setAppearanceMap({})
2842
+ );
2843
+ }, [annotationProvides, pageIndex, scale]);
2844
+ const handlers = useMemo(
2845
+ () => ({
2846
+ onPointerDown: (_, pe) => {
2847
+ if (pe.target === pe.currentTarget && annotationProvides) {
2848
+ annotationProvides.deselectAnnotation();
2849
+ setEditingId(null);
2850
+ }
2851
+ }
2852
+ }),
2853
+ [annotationProvides]
2854
+ );
2855
+ const handleClick = useCallback(
2856
+ (e, annotation) => {
2857
+ e.stopPropagation();
2858
+ if (annotationProvides && selectionProvides) {
2097
2859
  selectionProvides.clear();
2098
2860
  const isModifierPressed = "metaKey" in e ? e.metaKey || e.ctrlKey : false;
2099
2861
  if (isModifierPressed) {
@@ -2108,23 +2870,6 @@ function Annotations(annotationsProps) {
2108
2870
  },
2109
2871
  [annotationProvides, selectionProvides, editingId, pageIndex]
2110
2872
  );
2111
- const handleLinkClick = useCallback(
2112
- (e, annotation) => {
2113
- e.stopPropagation();
2114
- if (!annotationProvides || !selectionProvides) return;
2115
- selectionProvides.clear();
2116
- if (annotation.object.inReplyToId) {
2117
- const parentId = annotation.object.inReplyToId;
2118
- const parent = annotations.find((a) => a.object.id === parentId);
2119
- if (parent) {
2120
- annotationProvides.selectAnnotation(parent.object.pageIndex, parentId);
2121
- return;
2122
- }
2123
- }
2124
- annotationProvides.selectAnnotation(pageIndex, annotation.object.id);
2125
- },
2126
- [annotationProvides, selectionProvides, annotations, pageIndex]
2127
- );
2128
2873
  useEffect(() => {
2129
2874
  return register(handlers, {
2130
2875
  documentId
@@ -2206,651 +2951,102 @@ function Annotations(annotationsProps) {
2206
2951
  const allSelected = annotationProvides.getSelectedAnnotations();
2207
2952
  return allSelected.length > 1 && allSelected.every((ta) => ta.object.pageIndex === pageIndex);
2208
2953
  }, [annotationProvides, pageIndex, allSelectedIds]);
2954
+ const getAppearanceForAnnotation = useCallback(
2955
+ (ta) => {
2956
+ if (ta.dictMode) return null;
2957
+ if (ta.object.rotation && ta.object.unrotatedRect) return null;
2958
+ const appearances = appearanceMap[ta.object.id];
2959
+ if (!(appearances == null ? void 0 : appearances.normal)) return null;
2960
+ return appearances;
2961
+ },
2962
+ [appearanceMap]
2963
+ );
2964
+ const allRenderers = useMemo(() => {
2965
+ const external = annotationsProps.annotationRenderers ?? [];
2966
+ const externalIds = new Set(external.map((r) => r.id));
2967
+ return [...external, ...builtInRenderers.filter((r) => !externalIds.has(r.id))];
2968
+ }, [annotationsProps.annotationRenderers]);
2969
+ const resolveRenderer = useCallback(
2970
+ (annotation) => allRenderers.find((r) => r.matches(annotation.object)) ?? null,
2971
+ [allRenderers]
2972
+ );
2973
+ const selectHelpers = useMemo(
2974
+ () => ({
2975
+ defaultSelect: handleClick,
2976
+ selectAnnotation: (pi, id) => annotationProvides == null ? void 0 : annotationProvides.selectAnnotation(pi, id),
2977
+ clearSelection: () => selectionProvides == null ? void 0 : selectionProvides.clear(),
2978
+ allAnnotations: annotations,
2979
+ pageIndex
2980
+ }),
2981
+ [handleClick, annotationProvides, selectionProvides, annotations, pageIndex]
2982
+ );
2209
2983
  return /* @__PURE__ */ jsxs(Fragment, { children: [
2210
2984
  annotations.map((annotation) => {
2985
+ var _a, _b, _c;
2986
+ const renderer = resolveRenderer(annotation);
2987
+ if (!renderer) return null;
2988
+ const tool = annotationProvides == null ? void 0 : annotationProvides.findToolForAnnotation(annotation.object);
2211
2989
  const isSelected = allSelectedIds.includes(annotation.object.id);
2212
2990
  const isEditing = editingId === annotation.object.id;
2213
- const tool = annotationProvides == null ? void 0 : annotationProvides.findToolForAnnotation(annotation.object);
2214
- for (const renderer of annotationsProps.annotationRenderers ?? []) {
2215
- const element = renderer.tryRender(annotation, {
2991
+ const defaults = renderer.interactionDefaults;
2992
+ const resolvedDraggable = resolveInteractionProp(
2993
+ tool == null ? void 0 : tool.interaction.isDraggable,
2994
+ annotation.object,
2995
+ (defaults == null ? void 0 : defaults.isDraggable) ?? true
2996
+ );
2997
+ const finalDraggable = renderer.isDraggable ? renderer.isDraggable(resolvedDraggable, { isEditing }) : resolvedDraggable;
2998
+ const useAP = ((_a = tool == null ? void 0 : tool.behavior) == null ? void 0 : _a.useAppearanceStream) ?? renderer.useAppearanceStream ?? true;
2999
+ const onSelect = renderer.selectOverride ? (e) => renderer.selectOverride(e, annotation, selectHelpers) : (e) => handleClick(e, annotation);
3000
+ return /* @__PURE__ */ jsx(
3001
+ AnnotationContainer,
3002
+ {
3003
+ trackedAnnotation: annotation,
2216
3004
  isSelected,
2217
- scale,
2218
- pageIndex,
2219
- onClick: (e) => handleClick(e, annotation)
2220
- });
2221
- if (element) {
2222
- return /* @__PURE__ */ jsx(
2223
- AnnotationContainer,
2224
- {
2225
- trackedAnnotation: annotation,
2226
- isSelected,
2227
- isMultiSelected,
2228
- isDraggable: resolveInteractionProp(
2229
- tool == null ? void 0 : tool.interaction.isDraggable,
2230
- annotation.object,
2231
- false
2232
- ),
2233
- isResizable: resolveInteractionProp(
2234
- tool == null ? void 0 : tool.interaction.isResizable,
2235
- annotation.object,
2236
- false
2237
- ),
2238
- lockAspectRatio: resolveInteractionProp(
2239
- tool == null ? void 0 : tool.interaction.lockAspectRatio,
2240
- annotation.object,
2241
- false
2242
- ),
2243
- isRotatable: resolveInteractionProp(
2244
- tool == null ? void 0 : tool.interaction.isRotatable,
2245
- annotation.object,
2246
- false
2247
- ),
2248
- selectionMenu,
2249
- onSelect: (e) => handleClick(e, annotation),
2250
- style: {
2251
- mixBlendMode: blendModeToCss(annotation.object.blendMode ?? PdfBlendMode.Normal)
2252
- },
2253
- ...annotationsProps,
2254
- children: () => element
2255
- },
2256
- annotation.object.id
2257
- );
2258
- }
2259
- }
2260
- if (isInk(annotation)) {
2261
- return /* @__PURE__ */ jsx(
2262
- AnnotationContainer,
2263
- {
2264
- trackedAnnotation: annotation,
2265
- isSelected,
2266
- isMultiSelected,
2267
- isDraggable: resolveInteractionProp(
2268
- tool == null ? void 0 : tool.interaction.isDraggable,
2269
- annotation.object,
2270
- true
2271
- ),
2272
- isResizable: resolveInteractionProp(
2273
- tool == null ? void 0 : tool.interaction.isResizable,
2274
- annotation.object,
2275
- true
2276
- ),
2277
- lockAspectRatio: resolveInteractionProp(
2278
- tool == null ? void 0 : tool.interaction.lockAspectRatio,
2279
- annotation.object,
2280
- false
2281
- ),
2282
- isRotatable: resolveInteractionProp(
2283
- tool == null ? void 0 : tool.interaction.isRotatable,
2284
- annotation.object,
2285
- true
2286
- ),
2287
- selectionMenu,
2288
- onSelect: (e) => handleClick(e, annotation),
2289
- style: {
2290
- mixBlendMode: blendModeToCss(annotation.object.blendMode ?? PdfBlendMode.Normal)
2291
- },
2292
- ...annotationsProps,
2293
- children: (obj) => /* @__PURE__ */ jsx(
2294
- Ink,
2295
- {
2296
- ...obj,
2297
- isSelected,
2298
- scale,
2299
- onClick: (e) => handleClick(e, annotation)
2300
- }
2301
- )
2302
- },
2303
- annotation.object.id
2304
- );
2305
- }
2306
- if (isSquare(annotation)) {
2307
- return /* @__PURE__ */ jsx(
2308
- AnnotationContainer,
2309
- {
2310
- trackedAnnotation: annotation,
2311
- isSelected,
2312
- isMultiSelected,
2313
- isDraggable: resolveInteractionProp(
2314
- tool == null ? void 0 : tool.interaction.isDraggable,
2315
- annotation.object,
2316
- true
2317
- ),
2318
- isResizable: resolveInteractionProp(
2319
- tool == null ? void 0 : tool.interaction.isResizable,
2320
- annotation.object,
2321
- true
2322
- ),
2323
- lockAspectRatio: resolveInteractionProp(
2324
- tool == null ? void 0 : tool.interaction.lockAspectRatio,
2325
- annotation.object,
2326
- false
2327
- ),
2328
- isRotatable: resolveInteractionProp(
2329
- tool == null ? void 0 : tool.interaction.isRotatable,
2330
- annotation.object,
2331
- true
2332
- ),
2333
- selectionMenu,
2334
- onSelect: (e) => handleClick(e, annotation),
2335
- style: {
2336
- mixBlendMode: blendModeToCss(annotation.object.blendMode ?? PdfBlendMode.Normal)
2337
- },
2338
- ...annotationsProps,
2339
- children: (obj) => /* @__PURE__ */ jsx(
2340
- Square,
2341
- {
2342
- ...obj,
2343
- isSelected,
2344
- scale,
2345
- onClick: (e) => handleClick(e, annotation)
2346
- }
2347
- )
2348
- },
2349
- annotation.object.id
2350
- );
2351
- }
2352
- if (isCircle(annotation)) {
2353
- return /* @__PURE__ */ jsx(
2354
- AnnotationContainer,
2355
- {
2356
- trackedAnnotation: annotation,
2357
- isSelected,
2358
- isMultiSelected,
2359
- isDraggable: resolveInteractionProp(
2360
- tool == null ? void 0 : tool.interaction.isDraggable,
2361
- annotation.object,
2362
- true
2363
- ),
2364
- isResizable: resolveInteractionProp(
2365
- tool == null ? void 0 : tool.interaction.isResizable,
2366
- annotation.object,
2367
- true
2368
- ),
2369
- lockAspectRatio: resolveInteractionProp(
2370
- tool == null ? void 0 : tool.interaction.lockAspectRatio,
2371
- annotation.object,
2372
- false
2373
- ),
2374
- isRotatable: resolveInteractionProp(
2375
- tool == null ? void 0 : tool.interaction.isRotatable,
2376
- annotation.object,
2377
- true
2378
- ),
2379
- selectionMenu,
2380
- onSelect: (e) => handleClick(e, annotation),
2381
- style: {
2382
- mixBlendMode: blendModeToCss(annotation.object.blendMode ?? PdfBlendMode.Normal)
2383
- },
2384
- ...annotationsProps,
2385
- children: (obj) => /* @__PURE__ */ jsx(
2386
- Circle,
2387
- {
2388
- ...obj,
2389
- isSelected,
2390
- scale,
2391
- onClick: (e) => handleClick(e, annotation)
2392
- }
2393
- )
2394
- },
2395
- annotation.object.id
2396
- );
2397
- }
2398
- if (isUnderline(annotation)) {
2399
- return /* @__PURE__ */ jsx(
2400
- AnnotationContainer,
2401
- {
2402
- trackedAnnotation: annotation,
2403
- isSelected,
2404
- isMultiSelected,
2405
- isDraggable: resolveInteractionProp(
2406
- tool == null ? void 0 : tool.interaction.isDraggable,
2407
- annotation.object,
2408
- false
2409
- ),
2410
- isResizable: resolveInteractionProp(
2411
- tool == null ? void 0 : tool.interaction.isResizable,
2412
- annotation.object,
2413
- false
2414
- ),
2415
- lockAspectRatio: resolveInteractionProp(
2416
- tool == null ? void 0 : tool.interaction.lockAspectRatio,
2417
- annotation.object,
2418
- false
2419
- ),
2420
- isRotatable: resolveInteractionProp(
2421
- tool == null ? void 0 : tool.interaction.isRotatable,
2422
- annotation.object,
2423
- false
2424
- ),
2425
- selectionMenu,
2426
- onSelect: (e) => handleClick(e, annotation),
2427
- zIndex: 0,
2428
- style: {
2429
- mixBlendMode: blendModeToCss(annotation.object.blendMode ?? PdfBlendMode.Normal)
2430
- },
2431
- ...annotationsProps,
2432
- children: (obj) => /* @__PURE__ */ jsx(Underline, { ...obj, scale, onClick: (e) => handleClick(e, annotation) })
2433
- },
2434
- annotation.object.id
2435
- );
2436
- }
2437
- if (isStrikeout(annotation)) {
2438
- return /* @__PURE__ */ jsx(
2439
- AnnotationContainer,
2440
- {
2441
- trackedAnnotation: annotation,
2442
- isSelected,
2443
- isMultiSelected,
2444
- isDraggable: resolveInteractionProp(
2445
- tool == null ? void 0 : tool.interaction.isDraggable,
2446
- annotation.object,
2447
- false
2448
- ),
2449
- isResizable: resolveInteractionProp(
2450
- tool == null ? void 0 : tool.interaction.isResizable,
2451
- annotation.object,
2452
- false
2453
- ),
2454
- lockAspectRatio: resolveInteractionProp(
2455
- tool == null ? void 0 : tool.interaction.lockAspectRatio,
2456
- annotation.object,
2457
- false
2458
- ),
2459
- isRotatable: resolveInteractionProp(
2460
- tool == null ? void 0 : tool.interaction.isRotatable,
2461
- annotation.object,
2462
- false
2463
- ),
2464
- selectionMenu,
2465
- onSelect: (e) => handleClick(e, annotation),
2466
- zIndex: 0,
2467
- style: {
2468
- mixBlendMode: blendModeToCss(annotation.object.blendMode ?? PdfBlendMode.Normal)
2469
- },
2470
- ...annotationsProps,
2471
- children: (obj) => /* @__PURE__ */ jsx(Strikeout, { ...obj, scale, onClick: (e) => handleClick(e, annotation) })
3005
+ isEditing,
3006
+ isMultiSelected,
3007
+ isDraggable: finalDraggable,
3008
+ isResizable: resolveInteractionProp(
3009
+ tool == null ? void 0 : tool.interaction.isResizable,
3010
+ annotation.object,
3011
+ (defaults == null ? void 0 : defaults.isResizable) ?? false
3012
+ ),
3013
+ lockAspectRatio: resolveInteractionProp(
3014
+ tool == null ? void 0 : tool.interaction.lockAspectRatio,
3015
+ annotation.object,
3016
+ (defaults == null ? void 0 : defaults.lockAspectRatio) ?? false
3017
+ ),
3018
+ isRotatable: resolveInteractionProp(
3019
+ tool == null ? void 0 : tool.interaction.isRotatable,
3020
+ annotation.object,
3021
+ (defaults == null ? void 0 : defaults.isRotatable) ?? false
3022
+ ),
3023
+ vertexConfig: renderer.vertexConfig,
3024
+ selectionMenu: ((_b = renderer.hideSelectionMenu) == null ? void 0 : _b.call(renderer, annotation.object)) ? void 0 : selectionMenu,
3025
+ onSelect,
3026
+ onDoubleClick: renderer.onDoubleClick ? (e) => {
3027
+ e.stopPropagation();
3028
+ renderer.onDoubleClick(annotation.object.id, setEditingId);
3029
+ } : void 0,
3030
+ zIndex: renderer.zIndex,
3031
+ style: ((_c = renderer.containerStyle) == null ? void 0 : _c.call(renderer, annotation.object)) ?? {
3032
+ mixBlendMode: blendModeToCss(annotation.object.blendMode ?? PdfBlendMode.Normal)
2472
3033
  },
2473
- annotation.object.id
2474
- );
2475
- }
2476
- if (isSquiggly(annotation)) {
2477
- return /* @__PURE__ */ jsx(
2478
- AnnotationContainer,
2479
- {
2480
- trackedAnnotation: annotation,
2481
- isSelected,
2482
- isMultiSelected,
2483
- isDraggable: resolveInteractionProp(
2484
- tool == null ? void 0 : tool.interaction.isDraggable,
2485
- annotation.object,
2486
- false
2487
- ),
2488
- isResizable: resolveInteractionProp(
2489
- tool == null ? void 0 : tool.interaction.isResizable,
2490
- annotation.object,
2491
- false
2492
- ),
2493
- lockAspectRatio: resolveInteractionProp(
2494
- tool == null ? void 0 : tool.interaction.lockAspectRatio,
2495
- annotation.object,
2496
- false
2497
- ),
2498
- isRotatable: resolveInteractionProp(
2499
- tool == null ? void 0 : tool.interaction.isRotatable,
2500
- annotation.object,
2501
- false
2502
- ),
2503
- selectionMenu,
2504
- onSelect: (e) => handleClick(e, annotation),
2505
- zIndex: 0,
2506
- style: {
2507
- mixBlendMode: blendModeToCss(annotation.object.blendMode ?? PdfBlendMode.Normal)
2508
- },
2509
- ...annotationsProps,
2510
- children: (obj) => /* @__PURE__ */ jsx(Squiggly, { ...obj, scale, onClick: (e) => handleClick(e, annotation) })
2511
- },
2512
- annotation.object.id
2513
- );
2514
- }
2515
- if (isHighlight(annotation)) {
2516
- return /* @__PURE__ */ jsx(
2517
- AnnotationContainer,
2518
- {
2519
- trackedAnnotation: annotation,
2520
- isSelected,
2521
- isMultiSelected,
2522
- isDraggable: resolveInteractionProp(
2523
- tool == null ? void 0 : tool.interaction.isDraggable,
2524
- annotation.object,
2525
- false
2526
- ),
2527
- isResizable: resolveInteractionProp(
2528
- tool == null ? void 0 : tool.interaction.isResizable,
2529
- annotation.object,
2530
- false
2531
- ),
2532
- lockAspectRatio: resolveInteractionProp(
2533
- tool == null ? void 0 : tool.interaction.lockAspectRatio,
2534
- annotation.object,
2535
- false
2536
- ),
2537
- isRotatable: resolveInteractionProp(
2538
- tool == null ? void 0 : tool.interaction.isRotatable,
2539
- annotation.object,
2540
- false
2541
- ),
2542
- selectionMenu,
2543
- onSelect: (e) => handleClick(e, annotation),
2544
- zIndex: 0,
2545
- style: {
2546
- mixBlendMode: blendModeToCss(annotation.object.blendMode ?? PdfBlendMode.Multiply)
2547
- },
2548
- ...annotationsProps,
2549
- children: (obj) => /* @__PURE__ */ jsx(Highlight, { ...obj, scale, onClick: (e) => handleClick(e, annotation) })
2550
- },
2551
- annotation.object.id
2552
- );
2553
- }
2554
- if (isLine(annotation)) {
2555
- return /* @__PURE__ */ jsx(
2556
- AnnotationContainer,
2557
- {
2558
- trackedAnnotation: annotation,
2559
- isSelected,
2560
- isMultiSelected,
2561
- isDraggable: resolveInteractionProp(
2562
- tool == null ? void 0 : tool.interaction.isDraggable,
2563
- annotation.object,
2564
- true
2565
- ),
2566
- isResizable: resolveInteractionProp(
2567
- tool == null ? void 0 : tool.interaction.isResizable,
2568
- annotation.object,
2569
- false
2570
- ),
2571
- lockAspectRatio: resolveInteractionProp(
2572
- tool == null ? void 0 : tool.interaction.lockAspectRatio,
2573
- annotation.object,
2574
- false
2575
- ),
2576
- isRotatable: resolveInteractionProp(
2577
- tool == null ? void 0 : tool.interaction.isRotatable,
2578
- annotation.object,
2579
- true
2580
- ),
2581
- selectionMenu,
2582
- onSelect: (e) => handleClick(e, annotation),
2583
- vertexConfig: {
2584
- extractVertices: (annotation2) => [
2585
- annotation2.linePoints.start,
2586
- annotation2.linePoints.end
2587
- ],
2588
- transformAnnotation: (annotation2, vertices) => {
2589
- return {
2590
- ...annotation2,
2591
- linePoints: {
2592
- start: vertices[0],
2593
- end: vertices[1]
2594
- }
2595
- };
2596
- }
2597
- },
2598
- style: {
2599
- mixBlendMode: blendModeToCss(annotation.object.blendMode ?? PdfBlendMode.Normal)
2600
- },
2601
- ...annotationsProps,
2602
- children: (obj) => /* @__PURE__ */ jsx(Fragment$1, { children: /* @__PURE__ */ jsx(
2603
- Line,
2604
- {
2605
- ...obj,
2606
- isSelected,
2607
- scale,
2608
- onClick: (e) => handleClick(e, annotation)
2609
- }
2610
- ) })
2611
- },
2612
- annotation.object.id
2613
- );
2614
- }
2615
- if (isPolyline(annotation)) {
2616
- return /* @__PURE__ */ jsx(
2617
- AnnotationContainer,
2618
- {
2619
- trackedAnnotation: annotation,
2620
- isSelected,
2621
- isMultiSelected,
2622
- isDraggable: resolveInteractionProp(
2623
- tool == null ? void 0 : tool.interaction.isDraggable,
2624
- annotation.object,
2625
- true
2626
- ),
2627
- isResizable: resolveInteractionProp(
2628
- tool == null ? void 0 : tool.interaction.isResizable,
2629
- annotation.object,
2630
- false
2631
- ),
2632
- lockAspectRatio: resolveInteractionProp(
2633
- tool == null ? void 0 : tool.interaction.lockAspectRatio,
2634
- annotation.object,
2635
- false
2636
- ),
2637
- isRotatable: resolveInteractionProp(
2638
- tool == null ? void 0 : tool.interaction.isRotatable,
2639
- annotation.object,
2640
- true
2641
- ),
2642
- selectionMenu,
2643
- onSelect: (e) => handleClick(e, annotation),
2644
- vertexConfig: {
2645
- extractVertices: (annotation2) => annotation2.vertices,
2646
- transformAnnotation: (annotation2, vertices) => {
2647
- return {
2648
- ...annotation2,
2649
- vertices
2650
- };
2651
- }
2652
- },
2653
- style: {
2654
- mixBlendMode: blendModeToCss(annotation.object.blendMode ?? PdfBlendMode.Normal)
2655
- },
2656
- ...annotationsProps,
2657
- children: (obj) => /* @__PURE__ */ jsx(Fragment$1, { children: /* @__PURE__ */ jsx(
2658
- Polyline,
2659
- {
2660
- ...obj,
2661
- isSelected,
2662
- scale,
2663
- onClick: (e) => handleClick(e, annotation)
2664
- }
2665
- ) })
2666
- },
2667
- annotation.object.id
2668
- );
2669
- }
2670
- if (isPolygon(annotation)) {
2671
- return /* @__PURE__ */ jsx(
2672
- AnnotationContainer,
2673
- {
2674
- trackedAnnotation: annotation,
2675
- isSelected,
2676
- isMultiSelected,
2677
- isDraggable: resolveInteractionProp(
2678
- tool == null ? void 0 : tool.interaction.isDraggable,
2679
- annotation.object,
2680
- true
2681
- ),
2682
- isResizable: resolveInteractionProp(
2683
- tool == null ? void 0 : tool.interaction.isResizable,
2684
- annotation.object,
2685
- false
2686
- ),
2687
- lockAspectRatio: resolveInteractionProp(
2688
- tool == null ? void 0 : tool.interaction.lockAspectRatio,
2689
- annotation.object,
2690
- false
2691
- ),
2692
- isRotatable: resolveInteractionProp(
2693
- tool == null ? void 0 : tool.interaction.isRotatable,
2694
- annotation.object,
2695
- true
2696
- ),
2697
- selectionMenu,
2698
- onSelect: (e) => handleClick(e, annotation),
2699
- vertexConfig: {
2700
- extractVertices: (annotation2) => annotation2.vertices,
2701
- transformAnnotation: (annotation2, vertices) => {
2702
- return {
2703
- ...annotation2,
2704
- vertices
2705
- };
2706
- }
2707
- },
2708
- style: {
2709
- mixBlendMode: blendModeToCss(annotation.object.blendMode ?? PdfBlendMode.Normal)
2710
- },
2711
- ...annotationsProps,
2712
- children: (obj) => /* @__PURE__ */ jsx(Fragment$1, { children: /* @__PURE__ */ jsx(
2713
- Polygon,
2714
- {
2715
- ...obj,
2716
- isSelected,
2717
- scale,
2718
- onClick: (e) => handleClick(e, annotation)
2719
- }
2720
- ) })
2721
- },
2722
- annotation.object.id
2723
- );
2724
- }
2725
- if (isFreeText(annotation)) {
2726
- return /* @__PURE__ */ jsx(
2727
- AnnotationContainer,
2728
- {
2729
- trackedAnnotation: annotation,
2730
- isSelected,
2731
- isMultiSelected,
2732
- isDraggable: resolveInteractionProp(tool == null ? void 0 : tool.interaction.isDraggable, annotation.object, true) && !isEditing,
2733
- isResizable: resolveInteractionProp(
2734
- tool == null ? void 0 : tool.interaction.isResizable,
2735
- annotation.object,
2736
- true
2737
- ),
2738
- lockAspectRatio: resolveInteractionProp(
2739
- tool == null ? void 0 : tool.interaction.lockAspectRatio,
2740
- annotation.object,
2741
- false
2742
- ),
2743
- isRotatable: resolveInteractionProp(
2744
- tool == null ? void 0 : tool.interaction.isRotatable,
2745
- annotation.object,
2746
- true
2747
- ),
2748
- selectionMenu,
2749
- onSelect: (e) => handleClick(e, annotation),
2750
- style: {
2751
- mixBlendMode: blendModeToCss(annotation.object.blendMode ?? PdfBlendMode.Normal)
2752
- },
2753
- onDoubleClick: (e) => {
2754
- e.stopPropagation();
2755
- setEditingId(annotation.object.id);
2756
- },
2757
- ...annotationsProps,
2758
- children: (object) => /* @__PURE__ */ jsx(
2759
- FreeText,
2760
- {
2761
- isSelected,
2762
- isEditing,
2763
- annotation: {
2764
- ...annotation,
2765
- object
2766
- },
2767
- pageIndex,
2768
- scale,
2769
- onClick: (e) => handleClick(e, annotation)
2770
- }
2771
- )
2772
- },
2773
- annotation.object.id
2774
- );
2775
- }
2776
- if (isStamp(annotation)) {
2777
- return /* @__PURE__ */ jsx(
2778
- AnnotationContainer,
2779
- {
2780
- trackedAnnotation: annotation,
2781
- isSelected,
2782
- isMultiSelected,
2783
- isDraggable: resolveInteractionProp(
2784
- tool == null ? void 0 : tool.interaction.isDraggable,
2785
- annotation.object,
2786
- true
2787
- ),
2788
- isResizable: resolveInteractionProp(
2789
- tool == null ? void 0 : tool.interaction.isResizable,
2790
- annotation.object,
2791
- true
2792
- ),
2793
- lockAspectRatio: resolveInteractionProp(
2794
- tool == null ? void 0 : tool.interaction.lockAspectRatio,
2795
- annotation.object,
2796
- false
2797
- ),
2798
- isRotatable: resolveInteractionProp(
2799
- tool == null ? void 0 : tool.interaction.isRotatable,
2800
- annotation.object,
2801
- true
2802
- ),
2803
- selectionMenu,
2804
- onSelect: (e) => handleClick(e, annotation),
2805
- style: {
2806
- mixBlendMode: blendModeToCss(annotation.object.blendMode ?? PdfBlendMode.Normal)
2807
- },
2808
- ...annotationsProps,
2809
- children: (_object) => /* @__PURE__ */ jsx(
2810
- Stamp,
2811
- {
2812
- isSelected,
2813
- annotation,
2814
- documentId,
2815
- pageIndex,
2816
- scale,
2817
- onClick: (e) => handleClick(e, annotation)
2818
- }
2819
- )
2820
- },
2821
- annotation.object.id
2822
- );
2823
- }
2824
- if (isLink(annotation)) {
2825
- const hasIRT = !!annotation.object.inReplyToId;
2826
- return /* @__PURE__ */ jsx(
2827
- AnnotationContainer,
2828
- {
2829
- trackedAnnotation: annotation,
3034
+ appearance: useAP ? getAppearanceForAnnotation(annotation) : void 0,
3035
+ ...annotationsProps,
3036
+ children: (currentObject, { appearanceActive }) => renderer.render({
3037
+ annotation,
3038
+ currentObject,
2830
3039
  isSelected,
2831
- isMultiSelected,
2832
- isDraggable: false,
2833
- isResizable: false,
2834
- lockAspectRatio: false,
2835
- isRotatable: false,
2836
- selectionMenu: hasIRT ? void 0 : selectionMenu,
2837
- onSelect: (e) => handleLinkClick(e, annotation),
2838
- ...annotationsProps,
2839
- children: (obj) => /* @__PURE__ */ jsx(
2840
- Link,
2841
- {
2842
- ...obj,
2843
- isSelected,
2844
- scale,
2845
- onClick: (e) => handleLinkClick(e, annotation),
2846
- hasIRT
2847
- }
2848
- )
2849
- },
2850
- annotation.object.id
2851
- );
2852
- }
2853
- return null;
3040
+ isEditing,
3041
+ scale,
3042
+ pageIndex,
3043
+ documentId,
3044
+ onClick: onSelect,
3045
+ appearanceActive
3046
+ })
3047
+ },
3048
+ annotation.object.id
3049
+ );
2854
3050
  }),
2855
3051
  allSelectedOnSamePage && selectedAnnotationsOnPage.length >= 2 && /* @__PURE__ */ jsx(
2856
3052
  GroupSelectionBox,
@@ -2981,6 +3177,8 @@ function TextMarkup({ documentId, pageIndex, scale }) {
2981
3177
  )
2982
3178
  }
2983
3179
  );
3180
+ case PdfAnnotationSubtype.CARET:
3181
+ return null;
2984
3182
  default:
2985
3183
  return null;
2986
3184
  }
@@ -3177,20 +3375,6 @@ function AnnotationLayer({
3177
3375
  }
3178
3376
  );
3179
3377
  }
3180
- function createRenderer(entry) {
3181
- return {
3182
- id: entry.id,
3183
- tryRender: (annotation, props) => {
3184
- if (entry.matches(annotation.object)) {
3185
- return entry.render({
3186
- ...props,
3187
- annotation
3188
- });
3189
- }
3190
- return null;
3191
- }
3192
- };
3193
- }
3194
3378
  const AnnotationPluginPackage = createPluginPackage(AnnotationPluginPackage$1).addWrapper(AnnotationRendererProvider).build();
3195
3379
  export {
3196
3380
  AnnotationLayer,