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