@embedpdf/plugin-annotation 2.15.0 → 3.0.0-next.1

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 (348) hide show
  1. package/LICENSE +192 -21
  2. package/dist/capability-fghl0JmE.js +2680 -0
  3. package/dist/capability-fghl0JmE.js.map +1 -0
  4. package/dist/capability-hb2AU0f6.cjs +2739 -0
  5. package/dist/capability-hb2AU0f6.cjs.map +1 -0
  6. package/dist/index.cjs +593 -2
  7. package/dist/index.cjs.map +1 -1
  8. package/dist/index.d.cts +65 -0
  9. package/dist/index.d.ts +65 -1
  10. package/dist/index.js +562 -6998
  11. package/dist/index.js.map +1 -1
  12. package/dist/internal.cjs +5 -0
  13. package/dist/internal.d.cts +13 -0
  14. package/dist/internal.d.ts +13 -0
  15. package/dist/internal.js +2 -0
  16. package/dist/types-BhWgqgbX.d.cts +879 -0
  17. package/dist/types-Da6JRmhw.d.ts +879 -0
  18. package/package.json +26 -66
  19. package/dist/lib/actions.d.ts +0 -192
  20. package/dist/lib/annotation-plugin.d.ts +0 -310
  21. package/dist/lib/geometry/cloudy-border.d.ts +0 -90
  22. package/dist/lib/geometry/index.d.ts +0 -2
  23. package/dist/lib/geometry/rotation.d.ts +0 -32
  24. package/dist/lib/handlers/callout-free-text.handler.d.ts +0 -3
  25. package/dist/lib/handlers/circle.handler.d.ts +0 -3
  26. package/dist/lib/handlers/click-detector.d.ts +0 -27
  27. package/dist/lib/handlers/free-text.handler.d.ts +0 -3
  28. package/dist/lib/handlers/index.d.ts +0 -14
  29. package/dist/lib/handlers/ink.handler.d.ts +0 -3
  30. package/dist/lib/handlers/insert-text.handler.d.ts +0 -8
  31. package/dist/lib/handlers/line.handler.d.ts +0 -3
  32. package/dist/lib/handlers/link.handler.d.ts +0 -3
  33. package/dist/lib/handlers/polygon.handler.d.ts +0 -3
  34. package/dist/lib/handlers/polyline.handler.d.ts +0 -3
  35. package/dist/lib/handlers/replace-text.handler.d.ts +0 -9
  36. package/dist/lib/handlers/selection-utils.d.ts +0 -7
  37. package/dist/lib/handlers/square.handler.d.ts +0 -3
  38. package/dist/lib/handlers/stamp.handler.d.ts +0 -3
  39. package/dist/lib/handlers/text-markup.handler.d.ts +0 -7
  40. package/dist/lib/handlers/text.handler.d.ts +0 -3
  41. package/dist/lib/handlers/types.d.ts +0 -176
  42. package/dist/lib/helpers.d.ts +0 -46
  43. package/dist/lib/index.d.ts +0 -21
  44. package/dist/lib/manifest.d.ts +0 -4
  45. package/dist/lib/patching/base-patch.d.ts +0 -87
  46. package/dist/lib/patching/index.d.ts +0 -6
  47. package/dist/lib/patching/insert-upright.d.ts +0 -20
  48. package/dist/lib/patching/line-ending-handlers.d.ts +0 -20
  49. package/dist/lib/patching/line-endings.d.ts +0 -13
  50. package/dist/lib/patching/patch-registry.d.ts +0 -40
  51. package/dist/lib/patching/patch-utils.d.ts +0 -97
  52. package/dist/lib/patching/patches/callout-freetext.patch.d.ts +0 -3
  53. package/dist/lib/patching/patches/circle.patch.d.ts +0 -3
  54. package/dist/lib/patching/patches/freetext.patch.d.ts +0 -3
  55. package/dist/lib/patching/patches/index.d.ts +0 -9
  56. package/dist/lib/patching/patches/ink.patch.d.ts +0 -3
  57. package/dist/lib/patching/patches/line.patch.d.ts +0 -3
  58. package/dist/lib/patching/patches/polygon.patch.d.ts +0 -3
  59. package/dist/lib/patching/patches/polyline.patch.d.ts +0 -3
  60. package/dist/lib/patching/patches/square.patch.d.ts +0 -3
  61. package/dist/lib/patching/patches/stamp.patch.d.ts +0 -3
  62. package/dist/lib/reducer.d.ts +0 -6
  63. package/dist/lib/selectors.d.ts +0 -139
  64. package/dist/lib/tools/default-tools.d.ts +0 -521
  65. package/dist/lib/tools/tools-utils.d.ts +0 -453
  66. package/dist/lib/tools/types.d.ts +0 -209
  67. package/dist/lib/types.d.ts +0 -671
  68. package/dist/lib/utils/index.d.ts +0 -1
  69. package/dist/lib/utils/use-state.d.ts +0 -12
  70. package/dist/preact/adapter.d.ts +0 -14
  71. package/dist/preact/core.d.ts +0 -1
  72. package/dist/preact/index.cjs +0 -2
  73. package/dist/preact/index.cjs.map +0 -1
  74. package/dist/preact/index.d.ts +0 -1
  75. package/dist/preact/index.js +0 -4013
  76. package/dist/preact/index.js.map +0 -1
  77. package/dist/preact/interaction-manager.d.ts +0 -1
  78. package/dist/preact/selection.d.ts +0 -1
  79. package/dist/preact/utils.d.ts +0 -1
  80. package/dist/react/adapter.d.ts +0 -6
  81. package/dist/react/core.d.ts +0 -1
  82. package/dist/react/index.cjs +0 -2
  83. package/dist/react/index.cjs.map +0 -1
  84. package/dist/react/index.d.ts +0 -1
  85. package/dist/react/index.js +0 -4014
  86. package/dist/react/index.js.map +0 -1
  87. package/dist/react/interaction-manager.d.ts +0 -1
  88. package/dist/react/selection.d.ts +0 -1
  89. package/dist/react/utils.d.ts +0 -1
  90. package/dist/shared/annotation-bounds.d.ts +0 -14
  91. package/dist/shared/components/annotation-container.d.ts +0 -71
  92. package/dist/shared/components/annotation-layer.d.ts +0 -33
  93. package/dist/shared/components/annotation-navigation-handler.d.ts +0 -1
  94. package/dist/shared/components/annotation-paint-layer.d.ts +0 -7
  95. package/dist/shared/components/annotations/callout-free-text-preview.d.ts +0 -15
  96. package/dist/shared/components/annotations/callout-free-text.d.ts +0 -15
  97. package/dist/shared/components/annotations/caret.d.ts +0 -24
  98. package/dist/shared/components/annotations/circle.d.ts +0 -35
  99. package/dist/shared/components/annotations/free-text.d.ts +0 -17
  100. package/dist/shared/components/annotations/ink.d.ts +0 -27
  101. package/dist/shared/components/annotations/line.d.ts +0 -35
  102. package/dist/shared/components/annotations/link-locked.d.ts +0 -3
  103. package/dist/shared/components/annotations/link.d.ts +0 -28
  104. package/dist/shared/components/annotations/polygon.d.ts +0 -23
  105. package/dist/shared/components/annotations/polyline.d.ts +0 -23
  106. package/dist/shared/components/annotations/square.d.ts +0 -35
  107. package/dist/shared/components/annotations/stamp.d.ts +0 -13
  108. package/dist/shared/components/annotations/text.d.ts +0 -14
  109. package/dist/shared/components/annotations.d.ts +0 -22
  110. package/dist/shared/components/appearance-image.d.ts +0 -12
  111. package/dist/shared/components/built-in-renderers.d.ts +0 -2
  112. package/dist/shared/components/group-selection-box.d.ts +0 -40
  113. package/dist/shared/components/index.d.ts +0 -2
  114. package/dist/shared/components/preview-renderer.d.ts +0 -8
  115. package/dist/shared/components/render-annotation.d.ts +0 -13
  116. package/dist/shared/components/text-markup/highlight.d.ts +0 -16
  117. package/dist/shared/components/text-markup/squiggly.d.ts +0 -16
  118. package/dist/shared/components/text-markup/strikeout.d.ts +0 -16
  119. package/dist/shared/components/text-markup/underline.d.ts +0 -16
  120. package/dist/shared/components/text-markup.d.ts +0 -7
  121. package/dist/shared/components/types.d.ts +0 -253
  122. package/dist/shared/context/index.d.ts +0 -1
  123. package/dist/shared/context/renderer-registry.d.ts +0 -21
  124. package/dist/shared/hooks/index.d.ts +0 -2
  125. package/dist/shared/hooks/use-annotation.d.ts +0 -19
  126. package/dist/shared/hooks/use-ios-zoom-prevention.d.ts +0 -16
  127. package/dist/shared/index.d.ts +0 -6
  128. package/dist/shared/types.d.ts +0 -10
  129. package/dist/shared-preact/annotation-bounds.d.ts +0 -14
  130. package/dist/shared-preact/components/annotation-container.d.ts +0 -71
  131. package/dist/shared-preact/components/annotation-layer.d.ts +0 -33
  132. package/dist/shared-preact/components/annotation-navigation-handler.d.ts +0 -1
  133. package/dist/shared-preact/components/annotation-paint-layer.d.ts +0 -7
  134. package/dist/shared-preact/components/annotations/callout-free-text-preview.d.ts +0 -15
  135. package/dist/shared-preact/components/annotations/callout-free-text.d.ts +0 -15
  136. package/dist/shared-preact/components/annotations/caret.d.ts +0 -24
  137. package/dist/shared-preact/components/annotations/circle.d.ts +0 -35
  138. package/dist/shared-preact/components/annotations/free-text.d.ts +0 -17
  139. package/dist/shared-preact/components/annotations/ink.d.ts +0 -27
  140. package/dist/shared-preact/components/annotations/line.d.ts +0 -35
  141. package/dist/shared-preact/components/annotations/link-locked.d.ts +0 -3
  142. package/dist/shared-preact/components/annotations/link.d.ts +0 -28
  143. package/dist/shared-preact/components/annotations/polygon.d.ts +0 -23
  144. package/dist/shared-preact/components/annotations/polyline.d.ts +0 -23
  145. package/dist/shared-preact/components/annotations/square.d.ts +0 -35
  146. package/dist/shared-preact/components/annotations/stamp.d.ts +0 -13
  147. package/dist/shared-preact/components/annotations/text.d.ts +0 -14
  148. package/dist/shared-preact/components/annotations.d.ts +0 -22
  149. package/dist/shared-preact/components/appearance-image.d.ts +0 -12
  150. package/dist/shared-preact/components/built-in-renderers.d.ts +0 -2
  151. package/dist/shared-preact/components/group-selection-box.d.ts +0 -40
  152. package/dist/shared-preact/components/index.d.ts +0 -2
  153. package/dist/shared-preact/components/preview-renderer.d.ts +0 -8
  154. package/dist/shared-preact/components/render-annotation.d.ts +0 -13
  155. package/dist/shared-preact/components/text-markup/highlight.d.ts +0 -16
  156. package/dist/shared-preact/components/text-markup/squiggly.d.ts +0 -16
  157. package/dist/shared-preact/components/text-markup/strikeout.d.ts +0 -16
  158. package/dist/shared-preact/components/text-markup/underline.d.ts +0 -16
  159. package/dist/shared-preact/components/text-markup.d.ts +0 -7
  160. package/dist/shared-preact/components/types.d.ts +0 -253
  161. package/dist/shared-preact/context/index.d.ts +0 -1
  162. package/dist/shared-preact/context/renderer-registry.d.ts +0 -21
  163. package/dist/shared-preact/hooks/index.d.ts +0 -2
  164. package/dist/shared-preact/hooks/use-annotation.d.ts +0 -19
  165. package/dist/shared-preact/hooks/use-ios-zoom-prevention.d.ts +0 -15
  166. package/dist/shared-preact/index.d.ts +0 -6
  167. package/dist/shared-preact/types.d.ts +0 -10
  168. package/dist/shared-react/annotation-bounds.d.ts +0 -14
  169. package/dist/shared-react/components/annotation-container.d.ts +0 -71
  170. package/dist/shared-react/components/annotation-layer.d.ts +0 -33
  171. package/dist/shared-react/components/annotation-navigation-handler.d.ts +0 -1
  172. package/dist/shared-react/components/annotation-paint-layer.d.ts +0 -7
  173. package/dist/shared-react/components/annotations/callout-free-text-preview.d.ts +0 -15
  174. package/dist/shared-react/components/annotations/callout-free-text.d.ts +0 -15
  175. package/dist/shared-react/components/annotations/caret.d.ts +0 -24
  176. package/dist/shared-react/components/annotations/circle.d.ts +0 -35
  177. package/dist/shared-react/components/annotations/free-text.d.ts +0 -17
  178. package/dist/shared-react/components/annotations/ink.d.ts +0 -27
  179. package/dist/shared-react/components/annotations/line.d.ts +0 -35
  180. package/dist/shared-react/components/annotations/link-locked.d.ts +0 -3
  181. package/dist/shared-react/components/annotations/link.d.ts +0 -28
  182. package/dist/shared-react/components/annotations/polygon.d.ts +0 -23
  183. package/dist/shared-react/components/annotations/polyline.d.ts +0 -23
  184. package/dist/shared-react/components/annotations/square.d.ts +0 -35
  185. package/dist/shared-react/components/annotations/stamp.d.ts +0 -13
  186. package/dist/shared-react/components/annotations/text.d.ts +0 -14
  187. package/dist/shared-react/components/annotations.d.ts +0 -22
  188. package/dist/shared-react/components/appearance-image.d.ts +0 -12
  189. package/dist/shared-react/components/built-in-renderers.d.ts +0 -2
  190. package/dist/shared-react/components/group-selection-box.d.ts +0 -40
  191. package/dist/shared-react/components/index.d.ts +0 -2
  192. package/dist/shared-react/components/preview-renderer.d.ts +0 -8
  193. package/dist/shared-react/components/render-annotation.d.ts +0 -13
  194. package/dist/shared-react/components/text-markup/highlight.d.ts +0 -16
  195. package/dist/shared-react/components/text-markup/squiggly.d.ts +0 -16
  196. package/dist/shared-react/components/text-markup/strikeout.d.ts +0 -16
  197. package/dist/shared-react/components/text-markup/underline.d.ts +0 -16
  198. package/dist/shared-react/components/text-markup.d.ts +0 -7
  199. package/dist/shared-react/components/types.d.ts +0 -253
  200. package/dist/shared-react/context/index.d.ts +0 -1
  201. package/dist/shared-react/context/renderer-registry.d.ts +0 -21
  202. package/dist/shared-react/hooks/index.d.ts +0 -2
  203. package/dist/shared-react/hooks/use-annotation.d.ts +0 -19
  204. package/dist/shared-react/hooks/use-ios-zoom-prevention.d.ts +0 -16
  205. package/dist/shared-react/index.d.ts +0 -6
  206. package/dist/shared-react/types.d.ts +0 -10
  207. package/dist/shared-vue/annotation-bounds.d.ts +0 -14
  208. package/dist/svelte/components/AnnotationContainer.svelte.d.ts +0 -26
  209. package/dist/svelte/components/AnnotationLayer.svelte.d.ts +0 -40
  210. package/dist/svelte/components/AnnotationNavigationHandler.svelte.d.ts +0 -3
  211. package/dist/svelte/components/AnnotationPaintLayer.svelte.d.ts +0 -8
  212. package/dist/svelte/components/Annotations.svelte.d.ts +0 -28
  213. package/dist/svelte/components/AppearanceImage.svelte.d.ts +0 -8
  214. package/dist/svelte/components/GroupSelectionBox.svelte.d.ts +0 -40
  215. package/dist/svelte/components/PreviewRenderer.svelte.d.ts +0 -9
  216. package/dist/svelte/components/RenderAnnotation.svelte.d.ts +0 -14
  217. package/dist/svelte/components/RendererRegistryProvider.svelte.d.ts +0 -7
  218. package/dist/svelte/components/TextMarkup.svelte.d.ts +0 -8
  219. package/dist/svelte/components/annotations/CalloutFreeText.svelte.d.ts +0 -15
  220. package/dist/svelte/components/annotations/CalloutFreeTextPreview.svelte.d.ts +0 -10
  221. package/dist/svelte/components/annotations/Caret.svelte.d.ts +0 -13
  222. package/dist/svelte/components/annotations/Circle.svelte.d.ts +0 -19
  223. package/dist/svelte/components/annotations/CirclePreview.svelte.d.ts +0 -10
  224. package/dist/svelte/components/annotations/FreeText.svelte.d.ts +0 -16
  225. package/dist/svelte/components/annotations/FreeTextPreview.svelte.d.ts +0 -10
  226. package/dist/svelte/components/annotations/Ink.svelte.d.ts +0 -15
  227. package/dist/svelte/components/annotations/InkPreview.svelte.d.ts +0 -10
  228. package/dist/svelte/components/annotations/Line.svelte.d.ts +0 -19
  229. package/dist/svelte/components/annotations/LinePreview.svelte.d.ts +0 -10
  230. package/dist/svelte/components/annotations/Link.svelte.d.ts +0 -24
  231. package/dist/svelte/components/annotations/LinkLockedMode.svelte.d.ts +0 -5
  232. package/dist/svelte/components/annotations/LinkPreview.svelte.d.ts +0 -10
  233. package/dist/svelte/components/annotations/Polygon.svelte.d.ts +0 -21
  234. package/dist/svelte/components/annotations/PolygonPreview.svelte.d.ts +0 -10
  235. package/dist/svelte/components/annotations/Polyline.svelte.d.ts +0 -19
  236. package/dist/svelte/components/annotations/PolylinePreview.svelte.d.ts +0 -10
  237. package/dist/svelte/components/annotations/Square.svelte.d.ts +0 -19
  238. package/dist/svelte/components/annotations/SquarePreview.svelte.d.ts +0 -10
  239. package/dist/svelte/components/annotations/Stamp.svelte.d.ts +0 -13
  240. package/dist/svelte/components/annotations/StampPreview.svelte.d.ts +0 -10
  241. package/dist/svelte/components/annotations/Text.svelte.d.ts +0 -10
  242. package/dist/svelte/components/annotations/index.d.ts +0 -10
  243. package/dist/svelte/components/built-in-renderers.d.ts +0 -2
  244. package/dist/svelte/components/index.d.ts +0 -11
  245. package/dist/svelte/components/renderers/CalloutFreeTextRenderer.svelte.d.ts +0 -5
  246. package/dist/svelte/components/renderers/CaretRenderer.svelte.d.ts +0 -5
  247. package/dist/svelte/components/renderers/CircleRenderer.svelte.d.ts +0 -5
  248. package/dist/svelte/components/renderers/FreeTextRenderer.svelte.d.ts +0 -5
  249. package/dist/svelte/components/renderers/HighlightRenderer.svelte.d.ts +0 -5
  250. package/dist/svelte/components/renderers/InkRenderer.svelte.d.ts +0 -5
  251. package/dist/svelte/components/renderers/LineRenderer.svelte.d.ts +0 -5
  252. package/dist/svelte/components/renderers/LinkRenderer.svelte.d.ts +0 -5
  253. package/dist/svelte/components/renderers/PolygonRenderer.svelte.d.ts +0 -5
  254. package/dist/svelte/components/renderers/PolylineRenderer.svelte.d.ts +0 -5
  255. package/dist/svelte/components/renderers/SquareRenderer.svelte.d.ts +0 -5
  256. package/dist/svelte/components/renderers/SquigglyRenderer.svelte.d.ts +0 -5
  257. package/dist/svelte/components/renderers/StampRenderer.svelte.d.ts +0 -5
  258. package/dist/svelte/components/renderers/StrikeoutRenderer.svelte.d.ts +0 -5
  259. package/dist/svelte/components/renderers/TextRenderer.svelte.d.ts +0 -5
  260. package/dist/svelte/components/renderers/UnderlineRenderer.svelte.d.ts +0 -5
  261. package/dist/svelte/components/text-markup/Highlight.svelte.d.ts +0 -16
  262. package/dist/svelte/components/text-markup/Squiggly.svelte.d.ts +0 -16
  263. package/dist/svelte/components/text-markup/Strikeout.svelte.d.ts +0 -16
  264. package/dist/svelte/components/text-markup/Underline.svelte.d.ts +0 -16
  265. package/dist/svelte/components/text-markup/index.d.ts +0 -4
  266. package/dist/svelte/components/types.d.ts +0 -66
  267. package/dist/svelte/context/index.d.ts +0 -2
  268. package/dist/svelte/context/renderer-registry.svelte.d.ts +0 -20
  269. package/dist/svelte/context/types.d.ts +0 -129
  270. package/dist/svelte/hooks/index.d.ts +0 -2
  271. package/dist/svelte/hooks/use-annotation.svelte.d.ts +0 -21
  272. package/dist/svelte/hooks/use-ios-zoom-prevention.svelte.d.ts +0 -6
  273. package/dist/svelte/index.cjs +0 -2
  274. package/dist/svelte/index.cjs.map +0 -1
  275. package/dist/svelte/index.d.ts +0 -6
  276. package/dist/svelte/index.js +0 -5257
  277. package/dist/svelte/index.js.map +0 -1
  278. package/dist/svelte/types.d.ts +0 -126
  279. package/dist/vue/components/annotation-container.vue.d.ts +0 -134
  280. package/dist/vue/components/annotation-layer.vue.d.ts +0 -99
  281. package/dist/vue/components/annotation-navigation-handler.vue.d.ts +0 -3
  282. package/dist/vue/components/annotation-paint-layer.vue.d.ts +0 -8
  283. package/dist/vue/components/annotations/callout-free-text-preview.vue.d.ts +0 -10
  284. package/dist/vue/components/annotations/callout-free-text.vue.d.ts +0 -25
  285. package/dist/vue/components/annotations/caret.vue.d.ts +0 -24
  286. package/dist/vue/components/annotations/circle-preview.vue.d.ts +0 -10
  287. package/dist/vue/components/annotations/circle.vue.d.ts +0 -37
  288. package/dist/vue/components/annotations/free-text-preview.vue.d.ts +0 -10
  289. package/dist/vue/components/annotations/free-text.vue.d.ts +0 -25
  290. package/dist/vue/components/annotations/index.d.ts +0 -10
  291. package/dist/vue/components/annotations/ink-preview.vue.d.ts +0 -10
  292. package/dist/vue/components/annotations/ink.vue.d.ts +0 -27
  293. package/dist/vue/components/annotations/line-preview.vue.d.ts +0 -10
  294. package/dist/vue/components/annotations/line.vue.d.ts +0 -38
  295. package/dist/vue/components/annotations/link-locked.vue.d.ts +0 -5
  296. package/dist/vue/components/annotations/link-preview.vue.d.ts +0 -10
  297. package/dist/vue/components/annotations/link.vue.d.ts +0 -47
  298. package/dist/vue/components/annotations/polygon-preview.vue.d.ts +0 -10
  299. package/dist/vue/components/annotations/polygon.vue.d.ts +0 -43
  300. package/dist/vue/components/annotations/polyline-preview.vue.d.ts +0 -10
  301. package/dist/vue/components/annotations/polyline.vue.d.ts +0 -38
  302. package/dist/vue/components/annotations/square-preview.vue.d.ts +0 -10
  303. package/dist/vue/components/annotations/square.vue.d.ts +0 -37
  304. package/dist/vue/components/annotations/stamp-preview.vue.d.ts +0 -10
  305. package/dist/vue/components/annotations/stamp.vue.d.ts +0 -19
  306. package/dist/vue/components/annotations/text.vue.d.ts +0 -14
  307. package/dist/vue/components/annotations.vue.d.ts +0 -111
  308. package/dist/vue/components/appearance-image.vue.d.ts +0 -9
  309. package/dist/vue/components/built-in-renderers.d.ts +0 -2
  310. package/dist/vue/components/group-selection-box.vue.d.ts +0 -98
  311. package/dist/vue/components/index.d.ts +0 -11
  312. package/dist/vue/components/preview-renderer.vue.d.ts +0 -9
  313. package/dist/vue/components/render-annotation.vue.d.ts +0 -16
  314. package/dist/vue/components/renderer-registry-provider.vue.d.ts +0 -13
  315. package/dist/vue/components/renderers/callout-free-text-renderer.vue.d.ts +0 -6
  316. package/dist/vue/components/renderers/caret-renderer.vue.d.ts +0 -6
  317. package/dist/vue/components/renderers/circle-renderer.vue.d.ts +0 -6
  318. package/dist/vue/components/renderers/free-text-renderer.vue.d.ts +0 -6
  319. package/dist/vue/components/renderers/highlight-renderer.vue.d.ts +0 -6
  320. package/dist/vue/components/renderers/ink-renderer.vue.d.ts +0 -6
  321. package/dist/vue/components/renderers/line-renderer.vue.d.ts +0 -6
  322. package/dist/vue/components/renderers/link-renderer.vue.d.ts +0 -6
  323. package/dist/vue/components/renderers/polygon-renderer.vue.d.ts +0 -6
  324. package/dist/vue/components/renderers/polyline-renderer.vue.d.ts +0 -6
  325. package/dist/vue/components/renderers/square-renderer.vue.d.ts +0 -6
  326. package/dist/vue/components/renderers/squiggly-renderer.vue.d.ts +0 -6
  327. package/dist/vue/components/renderers/stamp-renderer.vue.d.ts +0 -6
  328. package/dist/vue/components/renderers/strikeout-renderer.vue.d.ts +0 -6
  329. package/dist/vue/components/renderers/text-renderer.vue.d.ts +0 -6
  330. package/dist/vue/components/renderers/underline-renderer.vue.d.ts +0 -6
  331. package/dist/vue/components/text-markup/highlight.vue.d.ts +0 -27
  332. package/dist/vue/components/text-markup/index.d.ts +0 -4
  333. package/dist/vue/components/text-markup/squiggly.vue.d.ts +0 -27
  334. package/dist/vue/components/text-markup/strikeout.vue.d.ts +0 -27
  335. package/dist/vue/components/text-markup/underline.vue.d.ts +0 -27
  336. package/dist/vue/components/text-markup.vue.d.ts +0 -8
  337. package/dist/vue/context/index.d.ts +0 -2
  338. package/dist/vue/context/renderer-registry.d.ts +0 -26
  339. package/dist/vue/context/types.d.ts +0 -129
  340. package/dist/vue/hooks/index.d.ts +0 -2
  341. package/dist/vue/hooks/use-annotation.d.ts +0 -50
  342. package/dist/vue/hooks/use-ios-zoom-prevention.d.ts +0 -7
  343. package/dist/vue/index.cjs +0 -2
  344. package/dist/vue/index.cjs.map +0 -1
  345. package/dist/vue/index.d.ts +0 -6
  346. package/dist/vue/index.js +0 -4984
  347. package/dist/vue/index.js.map +0 -1
  348. package/dist/vue/types.d.ts +0 -94
@@ -1,4014 +0,0 @@
1
- import { createPluginPackage } from "@embedpdf/core";
2
- import { AnnotationPlugin, initialDocumentState, generateCloudyRectanglePath, generateCloudyEllipsePath, patching, generateCloudyPolygonPath, LockModeType, getAnnotationsByPageIndex, getSelectedAnnotationIds, resolveInteractionProp, hasNoViewFlag, hasHiddenFlag, AnnotationPluginPackage as AnnotationPluginPackage$1 } from "@embedpdf/plugin-annotation";
3
- export * from "@embedpdf/plugin-annotation";
4
- import { jsx, jsxs, Fragment } from "react/jsx-runtime";
5
- import { createContext, useState, useCallback, useContext, useRef, useEffect, useMemo, Fragment as Fragment$1 } from "react";
6
- import { createPortal } from "react-dom";
7
- import { usePlugin, useCapability, useDocumentPermissions, useDocumentState } from "@embedpdf/core/react";
8
- import { inferRotationCenterFromRects, boundingRectOrEmpty, PdfAnnotationBorderStyle, getContrastStrokeColor, PdfVerticalAlignment, textAlignmentToCss, standardFontCssProperties, ignore, PdfErrorCode, PdfBlendMode, blendModeToCss, PdfAnnotationSubtype } from "@embedpdf/models";
9
- import { usePointerHandlers } from "@embedpdf/plugin-interaction-manager/react";
10
- import { useSelectionCapability } from "@embedpdf/plugin-selection/react";
11
- import { useInteractionHandles, useDoublePressProps, CounterRotate } from "@embedpdf/utils/react";
12
- import { getCounterRotation } from "@embedpdf/utils";
13
- const suppressContentEditableWarningProps = {
14
- suppressContentEditableWarning: true
15
- };
16
- const RegisterContext = createContext(null);
17
- const RenderersContext = createContext([]);
18
- function AnnotationRendererProvider({ children }) {
19
- const [renderers, setRenderers] = useState([]);
20
- const register = useCallback((entries) => {
21
- setRenderers((prev) => {
22
- const ids = new Set(entries.map((e) => e.id));
23
- return [...prev.filter((r) => !ids.has(r.id)), ...entries];
24
- });
25
- return () => setRenderers((prev) => prev.filter((r) => !entries.some((e) => e.id === r.id)));
26
- }, []);
27
- return /* @__PURE__ */ jsx(RegisterContext.Provider, { value: register, children: /* @__PURE__ */ jsx(RenderersContext.Provider, { value: renderers, children }) });
28
- }
29
- function useRegisterRenderers(renderers) {
30
- const register = useContext(RegisterContext);
31
- const renderersRef = useRef(renderers);
32
- useEffect(() => {
33
- if (!register) return;
34
- return register(renderersRef.current);
35
- }, [register]);
36
- }
37
- function useRegisteredRenderers() {
38
- return useContext(RenderersContext);
39
- }
40
- function useRendererRegistry() {
41
- return useContext(RegisterContext);
42
- }
43
- const useAnnotationPlugin = () => usePlugin(AnnotationPlugin.id);
44
- const useAnnotationCapability = () => useCapability(AnnotationPlugin.id);
45
- const useAnnotation = (documentId) => {
46
- var _a;
47
- const { provides } = useAnnotationCapability();
48
- const [state, setState] = useState(
49
- ((_a = provides == null ? void 0 : provides.forDocument(documentId)) == null ? void 0 : _a.getState()) ?? initialDocumentState()
50
- );
51
- useEffect(() => {
52
- if (!provides) return;
53
- const scope = provides.forDocument(documentId);
54
- setState(scope.getState());
55
- return scope.onStateChange((newState) => {
56
- setState(newState);
57
- });
58
- }, [provides, documentId]);
59
- return {
60
- state,
61
- provides: (provides == null ? void 0 : provides.forDocument(documentId)) ?? null
62
- };
63
- };
64
- function AnnotationNavigationHandler() {
65
- const { plugin } = useAnnotationPlugin();
66
- const { provides } = useAnnotationCapability();
67
- useEffect(() => {
68
- if (!provides || !plugin) return;
69
- return provides.onNavigate((event) => {
70
- if (event.result.outcome === "uri" && plugin.config.autoOpenLinks !== false) {
71
- window.open(event.result.uri, "_blank", "noopener,noreferrer");
72
- }
73
- });
74
- }, [provides, plugin]);
75
- return null;
76
- }
77
- const MIN_IOS_FOCUS_FONT_PX = 16;
78
- function detectIOS() {
79
- try {
80
- const nav = navigator;
81
- return /iPad|iPhone|iPod/.test(navigator.userAgent) || navigator.platform === "MacIntel" && (nav == null ? void 0 : nav.maxTouchPoints) > 1;
82
- } catch {
83
- return false;
84
- }
85
- }
86
- let _isIOS;
87
- function getIsIOS() {
88
- if (_isIOS === void 0) {
89
- _isIOS = detectIOS();
90
- }
91
- return _isIOS;
92
- }
93
- function useIOSZoomPrevention(computedFontPx, active) {
94
- const isIOS = getIsIOS();
95
- return useMemo(() => {
96
- const needsComp = isIOS && active && computedFontPx > 0 && computedFontPx < MIN_IOS_FOCUS_FONT_PX;
97
- const adjustedFontPx = needsComp ? MIN_IOS_FOCUS_FONT_PX : computedFontPx;
98
- const scaleComp = needsComp ? computedFontPx / MIN_IOS_FOCUS_FONT_PX : 1;
99
- const wrapperStyle = needsComp ? {
100
- width: `${100 / scaleComp}%`,
101
- height: `${100 / scaleComp}%`,
102
- transform: `scale(${scaleComp})`,
103
- transformOrigin: "top left"
104
- } : void 0;
105
- return { needsComp, adjustedFontPx, scaleComp, wrapperStyle };
106
- }, [isIOS, active, computedFontPx]);
107
- }
108
- function AppearanceImage({ appearance, style }) {
109
- const [imageUrl, setImageUrl] = useState(null);
110
- const urlRef = useRef(null);
111
- useEffect(() => {
112
- const url = URL.createObjectURL(appearance.data);
113
- setImageUrl(url);
114
- urlRef.current = url;
115
- return () => {
116
- if (urlRef.current) {
117
- URL.revokeObjectURL(urlRef.current);
118
- urlRef.current = null;
119
- }
120
- };
121
- }, [appearance.data]);
122
- const handleImageLoad = () => {
123
- if (urlRef.current) {
124
- URL.revokeObjectURL(urlRef.current);
125
- urlRef.current = null;
126
- }
127
- };
128
- return imageUrl ? /* @__PURE__ */ jsx(
129
- "img",
130
- {
131
- src: imageUrl,
132
- onLoad: handleImageLoad,
133
- style: {
134
- position: "absolute",
135
- width: "100%",
136
- height: "100%",
137
- display: "block",
138
- pointerEvents: "none",
139
- userSelect: "none",
140
- ...style
141
- }
142
- }
143
- ) : null;
144
- }
145
- function AnnotationContainer({
146
- scale,
147
- documentId,
148
- pageIndex,
149
- rotation,
150
- pageWidth,
151
- pageHeight,
152
- trackedAnnotation,
153
- children,
154
- isSelected,
155
- isEditing = false,
156
- isMultiSelected = false,
157
- isDraggable,
158
- isResizable,
159
- isRotatable = true,
160
- lockAspectRatio = false,
161
- style = {},
162
- blendMode,
163
- vertexConfig,
164
- selectionMenu,
165
- structurallyLocked = false,
166
- contentLocked = false,
167
- outlineOffset = 1,
168
- onDoubleClick,
169
- onSelect,
170
- appearance,
171
- zIndex = 1,
172
- resizeUI,
173
- vertexUI,
174
- rotationUI,
175
- selectionOutlineColor,
176
- selectionOutline,
177
- customAnnotationRenderer,
178
- // Destructure props that shouldn't be passed to DOM elements
179
- groupSelectionMenu: _groupSelectionMenu,
180
- groupSelectionOutline: _groupSelectionOutline,
181
- annotationRenderers: _annotationRenderers,
182
- ...props
183
- }) {
184
- var _a, _b, _c;
185
- const [preview, setPreview] = useState(trackedAnnotation.object);
186
- const [liveRotation, setLiveRotation] = useState(null);
187
- const [cursorScreen, setCursorScreen] = useState(null);
188
- const [isHandleHovered, setIsHandleHovered] = useState(false);
189
- const [gestureActive, setGestureActive] = useState(false);
190
- const { provides: annotationCapability } = useAnnotationCapability();
191
- const { plugin } = useAnnotationPlugin();
192
- const { canModifyAnnotations } = useDocumentPermissions(documentId);
193
- const gestureBaseRef = useRef(null);
194
- const effectiveIsDraggable = canModifyAnnotations && isDraggable && !isMultiSelected;
195
- const effectiveIsResizable = canModifyAnnotations && isResizable && !isMultiSelected;
196
- const effectiveIsRotatable = canModifyAnnotations && isRotatable && !isMultiSelected;
197
- const annotationProvides = useMemo(
198
- () => annotationCapability ? annotationCapability.forDocument(documentId) : null,
199
- [annotationCapability, documentId]
200
- );
201
- const currentObject = preview ? { ...trackedAnnotation.object, ...preview } : trackedAnnotation.object;
202
- const annoFlags = trackedAnnotation.object.flags ?? [];
203
- const hasNoZoom = annoFlags.includes("noZoom");
204
- const hasNoRotate = annoFlags.includes("noRotate");
205
- const visualScale = hasNoZoom ? 1 : scale;
206
- const effectivePageRotation = hasNoRotate ? 0 : rotation;
207
- const HANDLE_COLOR = (resizeUI == null ? void 0 : resizeUI.color) ?? "#007ACC";
208
- const VERTEX_COLOR = (vertexUI == null ? void 0 : vertexUI.color) ?? "#007ACC";
209
- const ROTATION_COLOR = (rotationUI == null ? void 0 : rotationUI.color) ?? "white";
210
- const ROTATION_CONNECTOR_COLOR = (rotationUI == null ? void 0 : rotationUI.connectorColor) ?? "#007ACC";
211
- const HANDLE_SIZE = (resizeUI == null ? void 0 : resizeUI.size) ?? 12;
212
- const VERTEX_SIZE = (vertexUI == null ? void 0 : vertexUI.size) ?? 12;
213
- const ROTATION_SIZE = (rotationUI == null ? void 0 : rotationUI.size) ?? 32;
214
- const ROTATION_MARGIN = rotationUI == null ? void 0 : rotationUI.margin;
215
- const ROTATION_ICON_COLOR = (rotationUI == null ? void 0 : rotationUI.iconColor) ?? "#007ACC";
216
- const SHOW_CONNECTOR = (rotationUI == null ? void 0 : rotationUI.showConnector) ?? false;
217
- const ROTATION_BORDER_COLOR = ((_a = rotationUI == null ? void 0 : rotationUI.border) == null ? void 0 : _a.color) ?? "#007ACC";
218
- const ROTATION_BORDER_WIDTH = ((_b = rotationUI == null ? void 0 : rotationUI.border) == null ? void 0 : _b.width) ?? 1;
219
- const ROTATION_BORDER_STYLE = ((_c = rotationUI == null ? void 0 : rotationUI.border) == null ? void 0 : _c.style) ?? "solid";
220
- const outlineColor = (selectionOutline == null ? void 0 : selectionOutline.color) ?? selectionOutlineColor ?? "#007ACC";
221
- const outlineStyle = (selectionOutline == null ? void 0 : selectionOutline.style) ?? "solid";
222
- const outlineWidth = (selectionOutline == null ? void 0 : selectionOutline.width) ?? 1;
223
- const outlineOff = (selectionOutline == null ? void 0 : selectionOutline.offset) ?? outlineOffset ?? 1;
224
- const annotationRotation = liveRotation ?? currentObject.rotation ?? 0;
225
- const rotationDisplay = liveRotation ?? currentObject.rotation ?? 0;
226
- const normalizedRotationDisplay = Number.isFinite(rotationDisplay) ? Math.round(rotationDisplay * 10) / 10 : 0;
227
- const rotationActive = liveRotation !== null;
228
- const gestureBaseRectRef = useRef(null);
229
- const handleUpdate = useCallback(
230
- (event) => {
231
- var _a2;
232
- if (!((_a2 = event.transformData) == null ? void 0 : _a2.type) || isMultiSelected || !plugin) return;
233
- const { type, changes, metadata } = event.transformData;
234
- const id = trackedAnnotation.object.id;
235
- const pageSize = { width: pageWidth, height: pageHeight };
236
- if (event.state === "start") {
237
- gestureBaseRectRef.current = trackedAnnotation.object.unrotatedRect ?? trackedAnnotation.object.rect;
238
- gestureBaseRef.current = trackedAnnotation.object;
239
- if (type === "resize" || type === "vertex-edit") {
240
- setGestureActive(true);
241
- }
242
- if (type === "move") {
243
- plugin.startDrag(documentId, { annotationIds: [id], pageSize });
244
- } else if (type === "resize") {
245
- plugin.startResize(documentId, {
246
- annotationIds: [id],
247
- pageSize,
248
- resizeHandle: (metadata == null ? void 0 : metadata.handle) ?? "se"
249
- });
250
- }
251
- }
252
- if (changes.rect && gestureBaseRectRef.current) {
253
- if (type === "move") {
254
- const delta = {
255
- x: changes.rect.origin.x - gestureBaseRectRef.current.origin.x,
256
- y: changes.rect.origin.y - gestureBaseRectRef.current.origin.y
257
- };
258
- plugin.updateDrag(documentId, delta);
259
- } else if (type === "resize") {
260
- plugin.updateResize(documentId, changes.rect);
261
- }
262
- }
263
- if (type === "vertex-edit" && changes.vertices && vertexConfig) {
264
- const base = gestureBaseRef.current ?? trackedAnnotation.object;
265
- const vertexChanges = vertexConfig.transformAnnotation(base, changes.vertices);
266
- const patched = annotationCapability == null ? void 0 : annotationCapability.transformAnnotation(base, {
267
- type,
268
- changes: vertexChanges,
269
- metadata
270
- });
271
- if (patched) {
272
- setPreview((prev) => ({ ...prev, ...patched }));
273
- if (event.state === "end") {
274
- annotationProvides == null ? void 0 : annotationProvides.updateAnnotation(pageIndex, id, patched);
275
- }
276
- }
277
- }
278
- if (type === "rotate") {
279
- const cursorAngle = (metadata == null ? void 0 : metadata.rotationAngle) ?? annotationRotation;
280
- const cursorPos = metadata == null ? void 0 : metadata.cursorPosition;
281
- if (cursorPos) setCursorScreen({ x: cursorPos.clientX, y: cursorPos.clientY });
282
- if (event.state === "start") {
283
- setLiveRotation(cursorAngle);
284
- plugin.startRotation(documentId, {
285
- annotationIds: [id],
286
- cursorAngle,
287
- rotationCenter: metadata == null ? void 0 : metadata.rotationCenter
288
- });
289
- } else if (event.state === "move") {
290
- setLiveRotation(cursorAngle);
291
- plugin.updateRotation(documentId, cursorAngle, metadata == null ? void 0 : metadata.rotationDelta);
292
- } else if (event.state === "end") {
293
- setLiveRotation(null);
294
- setCursorScreen(null);
295
- plugin.commitRotation(documentId);
296
- }
297
- return;
298
- }
299
- if (event.state === "end") {
300
- gestureBaseRectRef.current = null;
301
- gestureBaseRef.current = null;
302
- setGestureActive(false);
303
- if (type === "move") plugin.commitDrag(documentId);
304
- else if (type === "resize") plugin.commitResize(documentId);
305
- }
306
- },
307
- [
308
- plugin,
309
- documentId,
310
- trackedAnnotation.object,
311
- pageWidth,
312
- pageHeight,
313
- pageIndex,
314
- isMultiSelected,
315
- vertexConfig,
316
- annotationCapability,
317
- annotationProvides,
318
- annotationRotation
319
- ]
320
- );
321
- const explicitUnrotatedRect = currentObject.unrotatedRect;
322
- const effectiveUnrotatedRect = explicitUnrotatedRect ?? currentObject.rect;
323
- const rotationPivot = explicitUnrotatedRect && annotationRotation !== 0 ? inferRotationCenterFromRects(effectiveUnrotatedRect, currentObject.rect, annotationRotation) : void 0;
324
- const controllerElement = effectiveUnrotatedRect;
325
- const {
326
- dragProps,
327
- vertices,
328
- resize,
329
- rotation: rotationHandle
330
- } = useInteractionHandles({
331
- controller: {
332
- element: controllerElement,
333
- vertices: vertexConfig == null ? void 0 : vertexConfig.extractVertices(currentObject),
334
- constraints: {
335
- minWidth: 10,
336
- minHeight: 10,
337
- boundingBox: { width: pageWidth, height: pageHeight }
338
- },
339
- maintainAspectRatio: lockAspectRatio,
340
- pageRotation: rotation,
341
- annotationRotation,
342
- rotationCenter: rotationPivot,
343
- rotationElement: currentObject.rect,
344
- scale,
345
- // Disable interaction handles when multi-selected
346
- enabled: isSelected && !isMultiSelected,
347
- onUpdate: handleUpdate
348
- },
349
- resizeUI: {
350
- handleSize: HANDLE_SIZE,
351
- spacing: outlineOff,
352
- offsetMode: "outside",
353
- includeSides: lockAspectRatio ? false : true,
354
- zIndex: zIndex + 1
355
- },
356
- vertexUI: {
357
- vertexSize: VERTEX_SIZE,
358
- zIndex: zIndex + 2
359
- },
360
- rotationUI: {
361
- handleSize: ROTATION_SIZE,
362
- margin: ROTATION_MARGIN,
363
- zIndex: zIndex + 3,
364
- showConnector: SHOW_CONNECTOR
365
- },
366
- includeVertices: vertexConfig ? true : false,
367
- includeRotation: effectiveIsRotatable,
368
- currentRotation: annotationRotation
369
- });
370
- const guardedOnDoubleClick = useMemo(() => {
371
- if (!canModifyAnnotations || !onDoubleClick) return void 0;
372
- return onDoubleClick;
373
- }, [canModifyAnnotations, onDoubleClick]);
374
- const doubleProps = useDoublePressProps(guardedOnDoubleClick);
375
- useEffect(() => {
376
- setPreview(trackedAnnotation.object);
377
- }, [trackedAnnotation.object]);
378
- useEffect(() => {
379
- if (!plugin) return;
380
- const id = trackedAnnotation.object.id;
381
- const handleEvent = (event) => {
382
- var _a2;
383
- if (event.documentId !== documentId) return;
384
- if (event.type === "end" || event.type === "cancel") {
385
- setLiveRotation(null);
386
- }
387
- const patch = (_a2 = event.previewPatches) == null ? void 0 : _a2[id];
388
- if (event.type === "update" && patch) setPreview((prev) => ({ ...prev, ...patch }));
389
- else if (event.type === "cancel") setPreview(trackedAnnotation.object);
390
- };
391
- const unsubs = [
392
- plugin.onDragChange(handleEvent),
393
- plugin.onResizeChange(handleEvent),
394
- plugin.onRotateChange(handleEvent)
395
- ];
396
- return () => unsubs.forEach((u) => u());
397
- }, [plugin, documentId, trackedAnnotation.object]);
398
- const showOutline = isSelected && !isMultiSelected;
399
- const aabbWidth = currentObject.rect.size.width * visualScale;
400
- const aabbHeight = currentObject.rect.size.height * visualScale;
401
- const innerWidth = effectiveUnrotatedRect.size.width * visualScale;
402
- const innerHeight = effectiveUnrotatedRect.size.height * visualScale;
403
- const usesCustomPivot = Boolean(explicitUnrotatedRect) && annotationRotation !== 0;
404
- const innerLeft = usesCustomPivot ? (effectiveUnrotatedRect.origin.x - currentObject.rect.origin.x) * visualScale : (aabbWidth - innerWidth) / 2;
405
- const innerTop = usesCustomPivot ? (effectiveUnrotatedRect.origin.y - currentObject.rect.origin.y) * visualScale : (aabbHeight - innerHeight) / 2;
406
- const innerTransformOrigin = usesCustomPivot && rotationPivot ? `${(rotationPivot.x - effectiveUnrotatedRect.origin.x) * visualScale}px ${(rotationPivot.y - effectiveUnrotatedRect.origin.y) * visualScale}px` : "center center";
407
- const centerX = rotationPivot ? (rotationPivot.x - currentObject.rect.origin.x) * visualScale : aabbWidth / 2;
408
- const centerY = rotationPivot ? (rotationPivot.y - currentObject.rect.origin.y) * visualScale : aabbHeight / 2;
409
- const guideLength = Math.max(300, Math.max(aabbWidth, aabbHeight) + 80);
410
- const counterRot = hasNoRotate ? getCounterRotation(
411
- { origin: { x: 0, y: 0 }, size: { width: aabbWidth, height: aabbHeight } },
412
- rotation
413
- ) : null;
414
- const childObject = useMemo(() => {
415
- if (explicitUnrotatedRect) {
416
- return { ...currentObject, rect: explicitUnrotatedRect };
417
- }
418
- return currentObject;
419
- }, [currentObject, explicitUnrotatedRect]);
420
- const apActive = !!(appearance == null ? void 0 : appearance.normal) && !gestureActive && !isEditing && !trackedAnnotation.dictMode;
421
- const layerBaseStyle = {
422
- position: "absolute",
423
- left: currentObject.rect.origin.x * scale,
424
- top: currentObject.rect.origin.y * scale,
425
- width: counterRot ? counterRot.width : aabbWidth,
426
- height: counterRot ? counterRot.height : aabbHeight,
427
- pointerEvents: "none",
428
- zIndex,
429
- // noRotate: apply counter-rotation matrix so the annotation stays upright
430
- ...counterRot && {
431
- transform: counterRot.matrix,
432
- transformOrigin: "0 0"
433
- }
434
- };
435
- const innerDivBaseStyle = {
436
- position: "absolute",
437
- left: innerLeft,
438
- top: innerTop,
439
- width: innerWidth,
440
- height: innerHeight,
441
- transform: annotationRotation !== 0 ? `rotate(${annotationRotation}deg)` : void 0,
442
- transformOrigin: innerTransformOrigin
443
- };
444
- return /* @__PURE__ */ jsxs("div", { "data-no-interaction": true, children: [
445
- /* @__PURE__ */ jsx(
446
- "div",
447
- {
448
- style: {
449
- ...layerBaseStyle,
450
- ...blendMode && { mixBlendMode: blendMode },
451
- ...style
452
- },
453
- children: /* @__PURE__ */ jsxs("div", { style: { ...innerDivBaseStyle, pointerEvents: isEditing ? "auto" : "none" }, children: [
454
- (() => {
455
- const childrenRender = typeof children === "function" ? children(childObject, { appearanceActive: apActive }) : children;
456
- const customRender = customAnnotationRenderer == null ? void 0 : customAnnotationRenderer({
457
- annotation: childObject,
458
- children: childrenRender,
459
- isSelected,
460
- scale,
461
- rotation,
462
- pageWidth,
463
- pageHeight,
464
- pageIndex,
465
- onSelect
466
- });
467
- return customRender ?? childrenRender;
468
- })(),
469
- (appearance == null ? void 0 : appearance.normal) && /* @__PURE__ */ jsx(
470
- AppearanceImage,
471
- {
472
- appearance: appearance.normal,
473
- style: { display: apActive ? "block" : "none" }
474
- }
475
- )
476
- ] })
477
- }
478
- ),
479
- /* @__PURE__ */ jsxs("div", { style: layerBaseStyle, ...props, children: [
480
- rotationActive && /* @__PURE__ */ jsxs(Fragment, { children: [
481
- /* @__PURE__ */ jsx(
482
- "div",
483
- {
484
- style: {
485
- position: "absolute",
486
- left: centerX - guideLength / 2,
487
- top: centerY,
488
- width: guideLength,
489
- height: 1,
490
- backgroundColor: ROTATION_CONNECTOR_COLOR,
491
- opacity: 0.35,
492
- pointerEvents: "none"
493
- }
494
- }
495
- ),
496
- /* @__PURE__ */ jsx(
497
- "div",
498
- {
499
- style: {
500
- position: "absolute",
501
- left: centerX,
502
- top: centerY - guideLength / 2,
503
- width: 1,
504
- height: guideLength,
505
- backgroundColor: ROTATION_CONNECTOR_COLOR,
506
- opacity: 0.35,
507
- pointerEvents: "none"
508
- }
509
- }
510
- ),
511
- /* @__PURE__ */ jsx(
512
- "div",
513
- {
514
- style: {
515
- position: "absolute",
516
- left: centerX - guideLength / 2,
517
- top: centerY,
518
- width: guideLength,
519
- height: 1,
520
- transformOrigin: "center center",
521
- transform: `rotate(${annotationRotation}deg)`,
522
- backgroundColor: ROTATION_CONNECTOR_COLOR,
523
- opacity: 0.8,
524
- pointerEvents: "none"
525
- }
526
- }
527
- )
528
- ] }),
529
- isSelected && effectiveIsRotatable && rotationHandle && ((rotationUI == null ? void 0 : rotationUI.component) ? /* @__PURE__ */ jsx(
530
- "div",
531
- {
532
- onPointerEnter: () => setIsHandleHovered(true),
533
- onPointerLeave: () => {
534
- setIsHandleHovered(false);
535
- setCursorScreen(null);
536
- },
537
- onPointerMove: (e) => {
538
- if (!rotationActive) setCursorScreen({ x: e.clientX, y: e.clientY });
539
- },
540
- style: { display: "contents" },
541
- children: rotationUI.component({
542
- ...rotationHandle.handle,
543
- backgroundColor: ROTATION_COLOR,
544
- iconColor: ROTATION_ICON_COLOR,
545
- connectorStyle: {
546
- ...rotationHandle.connector.style,
547
- backgroundColor: ROTATION_CONNECTOR_COLOR,
548
- opacity: rotationActive ? 0 : 1
549
- },
550
- showConnector: SHOW_CONNECTOR,
551
- opacity: rotationActive ? 0 : 1,
552
- border: {
553
- color: ROTATION_BORDER_COLOR,
554
- width: ROTATION_BORDER_WIDTH,
555
- style: ROTATION_BORDER_STYLE
556
- }
557
- })
558
- }
559
- ) : /* @__PURE__ */ jsxs(
560
- "div",
561
- {
562
- onPointerEnter: () => setIsHandleHovered(true),
563
- onPointerLeave: () => {
564
- setIsHandleHovered(false);
565
- setCursorScreen(null);
566
- },
567
- onPointerMove: (e) => {
568
- if (!rotationActive) setCursorScreen({ x: e.clientX, y: e.clientY });
569
- },
570
- style: { display: "contents" },
571
- children: [
572
- SHOW_CONNECTOR && /* @__PURE__ */ jsx(
573
- "div",
574
- {
575
- style: {
576
- ...rotationHandle.connector.style,
577
- backgroundColor: ROTATION_CONNECTOR_COLOR,
578
- opacity: rotationActive ? 0 : 1
579
- }
580
- }
581
- ),
582
- /* @__PURE__ */ jsx(
583
- "div",
584
- {
585
- ...rotationHandle.handle,
586
- style: {
587
- ...rotationHandle.handle.style,
588
- backgroundColor: ROTATION_COLOR,
589
- border: `${ROTATION_BORDER_WIDTH}px ${ROTATION_BORDER_STYLE} ${ROTATION_BORDER_COLOR}`,
590
- boxSizing: "border-box",
591
- display: "flex",
592
- alignItems: "center",
593
- justifyContent: "center",
594
- pointerEvents: "auto",
595
- opacity: rotationActive ? 0 : 1
596
- },
597
- children: /* @__PURE__ */ jsxs(
598
- "svg",
599
- {
600
- width: Math.round(ROTATION_SIZE * 0.6),
601
- height: Math.round(ROTATION_SIZE * 0.6),
602
- viewBox: "0 0 24 24",
603
- fill: "none",
604
- stroke: ROTATION_ICON_COLOR,
605
- strokeWidth: "2",
606
- strokeLinecap: "round",
607
- strokeLinejoin: "round",
608
- children: [
609
- /* @__PURE__ */ jsx("path", { d: "M21 12a9 9 0 1 1-9-9c2.52 0 4.93 1 6.74 2.74L21 8" }),
610
- /* @__PURE__ */ jsx("path", { d: "M21 3v5h-5" })
611
- ]
612
- }
613
- )
614
- }
615
- )
616
- ]
617
- }
618
- )),
619
- /* @__PURE__ */ jsxs(
620
- "div",
621
- {
622
- ...effectiveIsDraggable && isSelected ? dragProps : {},
623
- ...doubleProps,
624
- style: {
625
- ...innerDivBaseStyle,
626
- outline: showOutline ? `${outlineWidth}px ${outlineStyle} ${outlineColor}` : "none",
627
- outlineOffset: showOutline ? `${outlineOff}px` : "0px",
628
- pointerEvents: isSelected && !isMultiSelected && !isEditing ? "auto" : "none",
629
- touchAction: "none",
630
- cursor: isSelected && effectiveIsDraggable ? "move" : "default"
631
- },
632
- children: [
633
- isSelected && effectiveIsResizable && !rotationActive && resize.map(
634
- ({ key, ...hProps }) => (resizeUI == null ? void 0 : resizeUI.component) ? resizeUI.component({
635
- key,
636
- ...hProps,
637
- backgroundColor: HANDLE_COLOR
638
- }) : /* @__PURE__ */ jsx(
639
- "div",
640
- {
641
- ...hProps,
642
- style: { ...hProps.style, backgroundColor: HANDLE_COLOR }
643
- },
644
- key
645
- )
646
- ),
647
- isSelected && canModifyAnnotations && !isMultiSelected && !rotationActive && vertices.map(
648
- ({ key, ...vProps }) => (vertexUI == null ? void 0 : vertexUI.component) ? vertexUI.component({
649
- key,
650
- ...vProps,
651
- backgroundColor: VERTEX_COLOR
652
- }) : /* @__PURE__ */ jsx(
653
- "div",
654
- {
655
- ...vProps,
656
- style: { ...vProps.style, backgroundColor: VERTEX_COLOR }
657
- },
658
- key
659
- )
660
- )
661
- ]
662
- }
663
- )
664
- ] }),
665
- selectionMenu && !isMultiSelected && !rotationActive && /* @__PURE__ */ jsx(
666
- CounterRotate,
667
- {
668
- rect: {
669
- origin: {
670
- x: currentObject.rect.origin.x * scale,
671
- y: currentObject.rect.origin.y * scale
672
- },
673
- size: {
674
- width: currentObject.rect.size.width * visualScale,
675
- height: currentObject.rect.size.height * visualScale
676
- }
677
- },
678
- rotation,
679
- children: (counterRotateProps) => {
680
- const effectiveAngle = ((annotationRotation + effectivePageRotation * 90) % 360 + 360) % 360;
681
- const handleNearMenuSide = effectiveIsRotatable && effectiveAngle > 90 && effectiveAngle < 270;
682
- return selectionMenu({
683
- ...counterRotateProps,
684
- context: {
685
- type: "annotation",
686
- annotation: trackedAnnotation,
687
- pageIndex,
688
- structurallyLocked,
689
- contentLocked
690
- },
691
- selected: isSelected,
692
- placement: {
693
- suggestTop: handleNearMenuSide
694
- }
695
- });
696
- }
697
- }
698
- ),
699
- (rotationActive || isHandleHovered) && cursorScreen && createPortal(
700
- /* @__PURE__ */ jsxs(
701
- "div",
702
- {
703
- style: {
704
- position: "fixed",
705
- left: cursorScreen.x + 16,
706
- top: cursorScreen.y - 16,
707
- background: "rgba(0,0,0,0.8)",
708
- color: "#fff",
709
- padding: "4px 8px",
710
- borderRadius: 4,
711
- fontSize: 12,
712
- fontFamily: "monospace",
713
- pointerEvents: "none",
714
- zIndex: 1e4,
715
- whiteSpace: "nowrap"
716
- },
717
- children: [
718
- normalizedRotationDisplay.toFixed(0),
719
- "°"
720
- ]
721
- }
722
- ),
723
- document.body
724
- )
725
- ] });
726
- }
727
- function mapCounterRotatePoint(x, y, width, height, rotation) {
728
- switch (rotation) {
729
- case 1:
730
- return { x: y, y: height - x };
731
- case 2:
732
- return { x: width - x, y: height - y };
733
- case 3:
734
- return { x: width - y, y: x };
735
- default:
736
- return { x, y };
737
- }
738
- }
739
- function getAnnotationScreenBounds(annotation, scale, rotation) {
740
- const flags = annotation.object.flags ?? [];
741
- const hasNoZoom = flags.includes("noZoom");
742
- const hasNoRotate = flags.includes("noRotate");
743
- const left = annotation.object.rect.origin.x * scale;
744
- const top = annotation.object.rect.origin.y * scale;
745
- const width = annotation.object.rect.size.width * (hasNoZoom ? 1 : scale);
746
- const height = annotation.object.rect.size.height * (hasNoZoom ? 1 : scale);
747
- if (!hasNoRotate || rotation === 0) {
748
- return {
749
- left,
750
- top,
751
- right: left + width,
752
- bottom: top + height
753
- };
754
- }
755
- const corners = [
756
- mapCounterRotatePoint(0, 0, width, height, rotation),
757
- mapCounterRotatePoint(width, 0, width, height, rotation),
758
- mapCounterRotatePoint(0, height, width, height, rotation),
759
- mapCounterRotatePoint(width, height, width, height, rotation)
760
- ];
761
- let minX = Infinity;
762
- let minY = Infinity;
763
- let maxX = -Infinity;
764
- let maxY = -Infinity;
765
- for (const corner of corners) {
766
- if (corner.x < minX) minX = corner.x;
767
- if (corner.y < minY) minY = corner.y;
768
- if (corner.x > maxX) maxX = corner.x;
769
- if (corner.y > maxY) maxY = corner.y;
770
- }
771
- return {
772
- left: left + minX,
773
- top: top + minY,
774
- right: left + maxX,
775
- bottom: top + maxY
776
- };
777
- }
778
- function GroupSelectionBox({
779
- documentId,
780
- pageIndex,
781
- scale,
782
- rotation,
783
- pageWidth,
784
- pageHeight,
785
- selectedAnnotations,
786
- isDraggable,
787
- isResizable,
788
- isRotatable = true,
789
- lockAspectRatio = false,
790
- resizeUI,
791
- rotationUI,
792
- selectionOutlineColor,
793
- outlineOffset,
794
- selectionOutline,
795
- zIndex = 2,
796
- groupSelectionMenu
797
- }) {
798
- var _a, _b, _c;
799
- const { plugin } = useAnnotationPlugin();
800
- const { canModifyAnnotations } = useDocumentPermissions(documentId);
801
- const gestureBaseRef = useRef(null);
802
- const isDraggingRef = useRef(false);
803
- const isResizingRef = useRef(false);
804
- const [liveRotation, setLiveRotation] = useState(null);
805
- const [cursorScreen, setCursorScreen] = useState(null);
806
- const [isHandleHovered, setIsHandleHovered] = useState(false);
807
- const effectiveIsDraggable = canModifyAnnotations && isDraggable;
808
- const effectiveIsResizable = canModifyAnnotations && isResizable;
809
- const effectiveIsRotatable = canModifyAnnotations && isRotatable;
810
- const groupBox = useMemo(() => {
811
- const rects = selectedAnnotations.map((ta) => ta.object.rect);
812
- return boundingRectOrEmpty(rects);
813
- }, [selectedAnnotations]);
814
- const [previewGroupBox, setPreviewGroupBox] = useState(groupBox);
815
- useEffect(() => {
816
- if (!isDraggingRef.current && !isResizingRef.current) {
817
- setPreviewGroupBox(groupBox);
818
- }
819
- }, [groupBox]);
820
- useEffect(() => {
821
- if (!plugin) return;
822
- const unsubscribe = plugin.onRotateChange((event) => {
823
- if (event.documentId !== documentId) return;
824
- if (event.type === "end" || event.type === "cancel") {
825
- setLiveRotation(null);
826
- }
827
- });
828
- return unsubscribe;
829
- }, [plugin, documentId]);
830
- const handleUpdate = useCallback(
831
- (event) => {
832
- var _a2, _b2, _c2, _d, _e, _f;
833
- if (!((_a2 = event.transformData) == null ? void 0 : _a2.type)) return;
834
- if (!plugin) return;
835
- const transformType = event.transformData.type;
836
- const isMove = transformType === "move";
837
- const isResize = transformType === "resize";
838
- if (isMove && !effectiveIsDraggable) return;
839
- if (event.state === "start") {
840
- gestureBaseRef.current = groupBox;
841
- if (isMove) {
842
- isDraggingRef.current = true;
843
- plugin.startDrag(documentId, {
844
- annotationIds: selectedAnnotations.map((ta) => ta.object.id),
845
- pageSize: { width: pageWidth, height: pageHeight }
846
- });
847
- } else if (isResize) {
848
- isResizingRef.current = true;
849
- plugin.startResize(documentId, {
850
- annotationIds: selectedAnnotations.map((ta) => ta.object.id),
851
- pageSize: { width: pageWidth, height: pageHeight },
852
- resizeHandle: ((_b2 = event.transformData.metadata) == null ? void 0 : _b2.handle) ?? "se"
853
- });
854
- }
855
- }
856
- if (transformType === "rotate") {
857
- if (!isRotatable) return;
858
- const ids = selectedAnnotations.map((ta) => ta.object.id);
859
- const cursorAngle = ((_c2 = event.transformData.metadata) == null ? void 0 : _c2.rotationAngle) ?? 0;
860
- const cursorPos = (_d = event.transformData.metadata) == null ? void 0 : _d.cursorPosition;
861
- if (cursorPos) setCursorScreen({ x: cursorPos.clientX, y: cursorPos.clientY });
862
- if (event.state === "start") {
863
- setLiveRotation(cursorAngle);
864
- plugin.startRotation(documentId, {
865
- annotationIds: ids,
866
- cursorAngle,
867
- rotationCenter: (_e = event.transformData.metadata) == null ? void 0 : _e.rotationCenter
868
- });
869
- } else if (event.state === "move") {
870
- setLiveRotation(cursorAngle);
871
- plugin.updateRotation(
872
- documentId,
873
- cursorAngle,
874
- (_f = event.transformData.metadata) == null ? void 0 : _f.rotationDelta
875
- );
876
- } else if (event.state === "end") {
877
- setLiveRotation(null);
878
- setCursorScreen(null);
879
- plugin.commitRotation(documentId);
880
- }
881
- return;
882
- }
883
- const base = gestureBaseRef.current ?? groupBox;
884
- if (isMove && event.transformData.changes.rect) {
885
- const newRect = event.transformData.changes.rect;
886
- const rawDelta = {
887
- x: newRect.origin.x - base.origin.x,
888
- y: newRect.origin.y - base.origin.y
889
- };
890
- const clampedDelta = plugin.updateDrag(documentId, rawDelta);
891
- setPreviewGroupBox({
892
- ...base,
893
- origin: {
894
- x: base.origin.x + clampedDelta.x,
895
- y: base.origin.y + clampedDelta.y
896
- }
897
- });
898
- } else if (isResize && event.transformData.changes.rect) {
899
- const newGroupBox = event.transformData.changes.rect;
900
- plugin.updateResize(documentId, newGroupBox);
901
- setPreviewGroupBox(newGroupBox);
902
- }
903
- if (event.state === "end") {
904
- gestureBaseRef.current = null;
905
- if (isMove && isDraggingRef.current) {
906
- isDraggingRef.current = false;
907
- plugin.commitDrag(documentId);
908
- } else if (isResize && isResizingRef.current) {
909
- isResizingRef.current = false;
910
- plugin.commitResize(documentId);
911
- }
912
- }
913
- },
914
- [
915
- plugin,
916
- documentId,
917
- pageWidth,
918
- pageHeight,
919
- groupBox,
920
- effectiveIsDraggable,
921
- selectedAnnotations,
922
- isRotatable
923
- ]
924
- );
925
- const groupRotationDisplay = liveRotation ?? 0;
926
- const rotationActive = liveRotation !== null;
927
- const normalizedRotationDisplay = Number.isFinite(groupRotationDisplay) ? Math.round(groupRotationDisplay * 10) / 10 : 0;
928
- const HANDLE_COLOR = (resizeUI == null ? void 0 : resizeUI.color) ?? "#007ACC";
929
- const HANDLE_SIZE = (resizeUI == null ? void 0 : resizeUI.size) ?? 12;
930
- const ROTATION_COLOR = (rotationUI == null ? void 0 : rotationUI.color) ?? "white";
931
- const ROTATION_CONNECTOR_COLOR = (rotationUI == null ? void 0 : rotationUI.connectorColor) ?? "#007ACC";
932
- const ROTATION_SIZE = (rotationUI == null ? void 0 : rotationUI.size) ?? 32;
933
- const ROTATION_MARGIN = rotationUI == null ? void 0 : rotationUI.margin;
934
- const ROTATION_ICON_COLOR = (rotationUI == null ? void 0 : rotationUI.iconColor) ?? "#007ACC";
935
- const SHOW_CONNECTOR = (rotationUI == null ? void 0 : rotationUI.showConnector) ?? false;
936
- const ROTATION_BORDER_COLOR = ((_a = rotationUI == null ? void 0 : rotationUI.border) == null ? void 0 : _a.color) ?? "#007ACC";
937
- const ROTATION_BORDER_WIDTH = ((_b = rotationUI == null ? void 0 : rotationUI.border) == null ? void 0 : _b.width) ?? 1;
938
- const ROTATION_BORDER_STYLE = ((_c = rotationUI == null ? void 0 : rotationUI.border) == null ? void 0 : _c.style) ?? "solid";
939
- const outlineColor = (selectionOutline == null ? void 0 : selectionOutline.color) ?? selectionOutlineColor ?? "#007ACC";
940
- const outlineStyleVal = (selectionOutline == null ? void 0 : selectionOutline.style) ?? "dashed";
941
- const outlineWidth = (selectionOutline == null ? void 0 : selectionOutline.width) ?? 2;
942
- const outlineOff = (selectionOutline == null ? void 0 : selectionOutline.offset) ?? outlineOffset ?? 2;
943
- const {
944
- dragProps,
945
- resize,
946
- rotation: rotationHandle
947
- } = useInteractionHandles({
948
- controller: {
949
- element: previewGroupBox,
950
- constraints: {
951
- minWidth: 20,
952
- minHeight: 20,
953
- boundingBox: { width: pageWidth, height: pageHeight }
954
- },
955
- maintainAspectRatio: lockAspectRatio,
956
- pageRotation: rotation,
957
- scale,
958
- enabled: true,
959
- onUpdate: handleUpdate
960
- },
961
- resizeUI: {
962
- handleSize: HANDLE_SIZE,
963
- spacing: outlineOff,
964
- offsetMode: "outside",
965
- includeSides: !lockAspectRatio,
966
- zIndex: zIndex + 1
967
- },
968
- vertexUI: {
969
- vertexSize: 0,
970
- zIndex
971
- },
972
- rotationUI: {
973
- handleSize: ROTATION_SIZE,
974
- margin: ROTATION_MARGIN,
975
- zIndex: zIndex + 2,
976
- showConnector: SHOW_CONNECTOR
977
- },
978
- includeVertices: false,
979
- includeRotation: effectiveIsRotatable,
980
- currentRotation: liveRotation ?? 0
981
- });
982
- if (selectedAnnotations.length < 2) {
983
- return null;
984
- }
985
- let visualLeft = Infinity;
986
- let visualTop = Infinity;
987
- let visualRight = -Infinity;
988
- let visualBottom = -Infinity;
989
- for (const ta of selectedAnnotations) {
990
- const bounds = getAnnotationScreenBounds(ta, scale, rotation);
991
- visualLeft = Math.min(visualLeft, bounds.left);
992
- visualTop = Math.min(visualTop, bounds.top);
993
- visualRight = Math.max(visualRight, bounds.right);
994
- visualBottom = Math.max(visualBottom, bounds.bottom);
995
- }
996
- const initialLogicalLeft = groupBox.origin.x * scale;
997
- const initialLogicalTop = groupBox.origin.y * scale;
998
- const initialLogicalRight = (groupBox.origin.x + groupBox.size.width) * scale;
999
- const initialLogicalBottom = (groupBox.origin.y + groupBox.size.height) * scale;
1000
- const leftCorrection = visualLeft - initialLogicalLeft;
1001
- const topCorrection = visualTop - initialLogicalTop;
1002
- const rightCorrection = visualRight - initialLogicalRight;
1003
- const bottomCorrection = visualBottom - initialLogicalBottom;
1004
- const groupBoxLeft = previewGroupBox.origin.x * scale + leftCorrection;
1005
- const groupBoxTop = previewGroupBox.origin.y * scale + topCorrection;
1006
- const groupBoxWidth = previewGroupBox.size.width * scale + (rightCorrection - leftCorrection);
1007
- const groupBoxHeight = previewGroupBox.size.height * scale + (bottomCorrection - topCorrection);
1008
- const groupCenterX = groupBoxWidth / 2;
1009
- const groupCenterY = groupBoxHeight / 2;
1010
- const groupGuideLength = Math.max(300, Math.max(groupBoxWidth, groupBoxHeight) + 80);
1011
- return /* @__PURE__ */ jsxs("div", { "data-group-selection-box": true, "data-no-interaction": true, children: [
1012
- /* @__PURE__ */ jsxs(
1013
- "div",
1014
- {
1015
- style: {
1016
- position: "absolute",
1017
- left: groupBoxLeft,
1018
- top: groupBoxTop,
1019
- width: groupBoxWidth,
1020
- height: groupBoxHeight,
1021
- pointerEvents: "none",
1022
- zIndex
1023
- },
1024
- children: [
1025
- rotationActive && /* @__PURE__ */ jsxs(Fragment, { children: [
1026
- /* @__PURE__ */ jsx(
1027
- "div",
1028
- {
1029
- style: {
1030
- position: "absolute",
1031
- left: groupCenterX - groupGuideLength / 2,
1032
- top: groupCenterY,
1033
- width: groupGuideLength,
1034
- height: 1,
1035
- backgroundColor: HANDLE_COLOR,
1036
- opacity: 0.35,
1037
- pointerEvents: "none"
1038
- }
1039
- }
1040
- ),
1041
- /* @__PURE__ */ jsx(
1042
- "div",
1043
- {
1044
- style: {
1045
- position: "absolute",
1046
- left: groupCenterX,
1047
- top: groupCenterY - groupGuideLength / 2,
1048
- width: 1,
1049
- height: groupGuideLength,
1050
- backgroundColor: HANDLE_COLOR,
1051
- opacity: 0.35,
1052
- pointerEvents: "none"
1053
- }
1054
- }
1055
- ),
1056
- /* @__PURE__ */ jsx(
1057
- "div",
1058
- {
1059
- style: {
1060
- position: "absolute",
1061
- left: groupCenterX - groupGuideLength / 2,
1062
- top: groupCenterY,
1063
- width: groupGuideLength,
1064
- height: 1,
1065
- transformOrigin: "center center",
1066
- transform: `rotate(${groupRotationDisplay}deg)`,
1067
- backgroundColor: HANDLE_COLOR,
1068
- opacity: 0.8,
1069
- pointerEvents: "none"
1070
- }
1071
- }
1072
- )
1073
- ] }),
1074
- effectiveIsRotatable && rotationHandle && ((rotationUI == null ? void 0 : rotationUI.component) ? /* @__PURE__ */ jsx(
1075
- "div",
1076
- {
1077
- onPointerEnter: () => setIsHandleHovered(true),
1078
- onPointerLeave: () => {
1079
- setIsHandleHovered(false);
1080
- setCursorScreen(null);
1081
- },
1082
- onPointerMove: (e) => {
1083
- if (!rotationActive) setCursorScreen({ x: e.clientX, y: e.clientY });
1084
- },
1085
- style: { display: "contents" },
1086
- children: rotationUI.component({
1087
- ...rotationHandle.handle,
1088
- backgroundColor: ROTATION_COLOR,
1089
- iconColor: ROTATION_ICON_COLOR,
1090
- connectorStyle: {
1091
- ...rotationHandle.connector.style,
1092
- backgroundColor: ROTATION_CONNECTOR_COLOR,
1093
- opacity: rotationActive ? 0 : 1
1094
- },
1095
- showConnector: SHOW_CONNECTOR,
1096
- opacity: rotationActive ? 0 : 1,
1097
- border: {
1098
- color: ROTATION_BORDER_COLOR,
1099
- width: ROTATION_BORDER_WIDTH,
1100
- style: ROTATION_BORDER_STYLE
1101
- }
1102
- })
1103
- }
1104
- ) : /* @__PURE__ */ jsxs(
1105
- "div",
1106
- {
1107
- onPointerEnter: () => setIsHandleHovered(true),
1108
- onPointerLeave: () => {
1109
- setIsHandleHovered(false);
1110
- setCursorScreen(null);
1111
- },
1112
- onPointerMove: (e) => {
1113
- if (!rotationActive) setCursorScreen({ x: e.clientX, y: e.clientY });
1114
- },
1115
- style: { display: "contents" },
1116
- children: [
1117
- SHOW_CONNECTOR && /* @__PURE__ */ jsx(
1118
- "div",
1119
- {
1120
- style: {
1121
- ...rotationHandle.connector.style,
1122
- backgroundColor: ROTATION_CONNECTOR_COLOR,
1123
- opacity: rotationActive ? 0 : 1
1124
- }
1125
- }
1126
- ),
1127
- /* @__PURE__ */ jsx(
1128
- "div",
1129
- {
1130
- ...rotationHandle.handle,
1131
- style: {
1132
- ...rotationHandle.handle.style,
1133
- backgroundColor: ROTATION_COLOR,
1134
- border: `${ROTATION_BORDER_WIDTH}px ${ROTATION_BORDER_STYLE} ${ROTATION_BORDER_COLOR}`,
1135
- boxSizing: "border-box",
1136
- display: "flex",
1137
- alignItems: "center",
1138
- justifyContent: "center",
1139
- pointerEvents: "auto",
1140
- opacity: rotationActive ? 0 : 1
1141
- },
1142
- children: /* @__PURE__ */ jsxs(
1143
- "svg",
1144
- {
1145
- width: Math.round(ROTATION_SIZE * 0.6),
1146
- height: Math.round(ROTATION_SIZE * 0.6),
1147
- viewBox: "0 0 24 24",
1148
- fill: "none",
1149
- stroke: ROTATION_ICON_COLOR,
1150
- strokeWidth: "2",
1151
- strokeLinecap: "round",
1152
- strokeLinejoin: "round",
1153
- children: [
1154
- /* @__PURE__ */ jsx("path", { d: "M21 12a9 9 0 1 1-9-9c2.52 0 4.93 1 6.74 2.74L21 8" }),
1155
- /* @__PURE__ */ jsx("path", { d: "M21 3v5h-5" })
1156
- ]
1157
- }
1158
- )
1159
- }
1160
- )
1161
- ]
1162
- }
1163
- )),
1164
- /* @__PURE__ */ jsx(
1165
- "div",
1166
- {
1167
- ...effectiveIsDraggable ? dragProps : {
1168
- onPointerDown: (e) => e.stopPropagation()
1169
- },
1170
- style: {
1171
- position: "absolute",
1172
- left: 0,
1173
- top: 0,
1174
- width: groupBoxWidth,
1175
- height: groupBoxHeight,
1176
- outline: rotationActive ? "none" : `${outlineWidth}px ${outlineStyleVal} ${outlineColor}`,
1177
- outlineOffset: outlineOff - 1,
1178
- cursor: effectiveIsDraggable ? "move" : "default",
1179
- touchAction: "none",
1180
- pointerEvents: "auto"
1181
- },
1182
- children: effectiveIsResizable && !rotationActive && resize.map(
1183
- ({ key, ...hProps }) => (resizeUI == null ? void 0 : resizeUI.component) ? resizeUI.component({
1184
- key,
1185
- ...hProps,
1186
- backgroundColor: HANDLE_COLOR
1187
- }) : /* @__PURE__ */ jsx(
1188
- "div",
1189
- {
1190
- ...hProps,
1191
- style: { ...hProps.style, backgroundColor: HANDLE_COLOR }
1192
- },
1193
- key
1194
- )
1195
- )
1196
- }
1197
- )
1198
- ]
1199
- }
1200
- ),
1201
- (rotationActive || isHandleHovered) && cursorScreen && createPortal(
1202
- /* @__PURE__ */ jsxs(
1203
- "div",
1204
- {
1205
- style: {
1206
- position: "fixed",
1207
- left: cursorScreen.x + 16,
1208
- top: cursorScreen.y - 16,
1209
- background: "rgba(0,0,0,0.8)",
1210
- color: "#fff",
1211
- padding: "4px 8px",
1212
- borderRadius: 4,
1213
- fontSize: 12,
1214
- fontFamily: "monospace",
1215
- pointerEvents: "none",
1216
- zIndex: 1e4,
1217
- whiteSpace: "nowrap"
1218
- },
1219
- children: [
1220
- normalizedRotationDisplay.toFixed(0),
1221
- "°"
1222
- ]
1223
- }
1224
- ),
1225
- document.body
1226
- ),
1227
- groupSelectionMenu && !rotationActive && /* @__PURE__ */ jsx(
1228
- CounterRotate,
1229
- {
1230
- rect: {
1231
- origin: {
1232
- x: groupBoxLeft,
1233
- y: groupBoxTop
1234
- },
1235
- size: {
1236
- width: groupBoxWidth,
1237
- height: groupBoxHeight
1238
- }
1239
- },
1240
- rotation,
1241
- children: (counterRotateProps) => {
1242
- const effectiveAngle = ((groupRotationDisplay + rotation * 90) % 360 + 360) % 360;
1243
- const handleNearMenuSide = effectiveIsRotatable && effectiveAngle > 90 && effectiveAngle < 270;
1244
- return groupSelectionMenu({
1245
- ...counterRotateProps,
1246
- context: {
1247
- type: "group",
1248
- annotations: selectedAnnotations,
1249
- pageIndex
1250
- },
1251
- selected: true,
1252
- placement: {
1253
- suggestTop: handleNearMenuSide
1254
- }
1255
- });
1256
- }
1257
- }
1258
- )
1259
- ] });
1260
- }
1261
- function createRenderer(entry) {
1262
- return {
1263
- id: entry.id,
1264
- matches: entry.matches ? (annotation) => entry.matches(annotation) : () => false,
1265
- render: entry.render ? (props) => entry.render(props) : () => null,
1266
- matchesPreview: entry.matchesPreview,
1267
- renderPreview: entry.renderPreview ? (props) => entry.renderPreview(props) : void 0,
1268
- previewContainerStyle: entry.previewContainerStyle ? (props) => entry.previewContainerStyle(props) : void 0,
1269
- vertexConfig: entry.vertexConfig,
1270
- zIndex: entry.zIndex,
1271
- defaultBlendMode: entry.defaultBlendMode,
1272
- containerStyle: entry.containerStyle,
1273
- interactionDefaults: entry.interactionDefaults,
1274
- useAppearanceStream: entry.useAppearanceStream,
1275
- isDraggable: entry.isDraggable,
1276
- onDoubleClick: entry.onDoubleClick,
1277
- selectOverride: entry.selectOverride,
1278
- hideSelectionMenu: entry.hideSelectionMenu,
1279
- hiddenWhenLocked: entry.hiddenWhenLocked,
1280
- renderLocked: entry.renderLocked ? (props) => entry.renderLocked(props) : void 0
1281
- };
1282
- }
1283
- const MIN_HIT_AREA_SCREEN_PX$6 = 20;
1284
- function Ink({
1285
- isSelected,
1286
- strokeColor,
1287
- opacity = 1,
1288
- strokeWidth,
1289
- inkList,
1290
- rect,
1291
- scale,
1292
- onClick,
1293
- appearanceActive = false
1294
- }) {
1295
- const resolvedColor = strokeColor ?? "#000000";
1296
- const paths = useMemo(() => {
1297
- return inkList.map(({ points }) => {
1298
- let d = "";
1299
- points.forEach(({ x, y }, i) => {
1300
- const lx = x - rect.origin.x;
1301
- const ly = y - rect.origin.y;
1302
- d += (i === 0 ? "M" : "L") + lx + " " + ly + " ";
1303
- });
1304
- return d.trim();
1305
- });
1306
- }, [inkList, rect]);
1307
- const width = rect.size.width * scale;
1308
- const height = rect.size.height * scale;
1309
- const hitStrokeWidth = Math.max(strokeWidth, MIN_HIT_AREA_SCREEN_PX$6 / scale);
1310
- return /* @__PURE__ */ jsxs(
1311
- "svg",
1312
- {
1313
- style: {
1314
- position: "absolute",
1315
- width,
1316
- height,
1317
- pointerEvents: "none",
1318
- zIndex: 2,
1319
- overflow: "visible"
1320
- },
1321
- width,
1322
- height,
1323
- viewBox: `0 0 ${rect.size.width} ${rect.size.height}`,
1324
- children: [
1325
- paths.map((d, i) => /* @__PURE__ */ jsx(
1326
- "path",
1327
- {
1328
- d,
1329
- fill: "none",
1330
- stroke: "transparent",
1331
- strokeWidth: hitStrokeWidth,
1332
- onPointerDown: onClick,
1333
- style: {
1334
- cursor: isSelected ? "move" : onClick ? "pointer" : "default",
1335
- pointerEvents: !onClick ? "none" : isSelected ? "none" : "visibleStroke",
1336
- strokeLinecap: "round",
1337
- strokeLinejoin: "round"
1338
- }
1339
- },
1340
- `hit-${i}`
1341
- )),
1342
- !appearanceActive && paths.map((d, i) => /* @__PURE__ */ jsx(
1343
- "path",
1344
- {
1345
- d,
1346
- fill: "none",
1347
- opacity,
1348
- style: {
1349
- pointerEvents: "none",
1350
- stroke: resolvedColor,
1351
- strokeWidth,
1352
- strokeLinecap: "round",
1353
- strokeLinejoin: "round"
1354
- }
1355
- },
1356
- `vis-${i}`
1357
- ))
1358
- ]
1359
- }
1360
- );
1361
- }
1362
- const MIN_HIT_AREA_SCREEN_PX$5 = 20;
1363
- function Square({
1364
- isSelected,
1365
- color = "#000000",
1366
- strokeColor,
1367
- opacity = 1,
1368
- strokeWidth,
1369
- strokeStyle = PdfAnnotationBorderStyle.SOLID,
1370
- strokeDashArray,
1371
- rect,
1372
- scale,
1373
- onClick,
1374
- appearanceActive = false,
1375
- cloudyBorderIntensity,
1376
- rectangleDifferences
1377
- }) {
1378
- const isCloudy = (cloudyBorderIntensity ?? 0) > 0;
1379
- const { width, height, x, y } = useMemo(() => {
1380
- const outerW = rect.size.width;
1381
- const outerH = rect.size.height;
1382
- const innerW = Math.max(outerW - strokeWidth, 0);
1383
- const innerH = Math.max(outerH - strokeWidth, 0);
1384
- return {
1385
- width: innerW,
1386
- height: innerH,
1387
- x: strokeWidth / 2,
1388
- y: strokeWidth / 2
1389
- };
1390
- }, [rect, strokeWidth]);
1391
- const cloudyPath = useMemo(() => {
1392
- if (!isCloudy) return null;
1393
- return generateCloudyRectanglePath(
1394
- { x: 0, y: 0, width: rect.size.width, height: rect.size.height },
1395
- rectangleDifferences,
1396
- cloudyBorderIntensity,
1397
- strokeWidth
1398
- );
1399
- }, [isCloudy, rect, rectangleDifferences, cloudyBorderIntensity, strokeWidth]);
1400
- const svgWidth = rect.size.width * scale;
1401
- const svgHeight = rect.size.height * scale;
1402
- const hitStrokeWidth = Math.max(strokeWidth, MIN_HIT_AREA_SCREEN_PX$5 / scale);
1403
- return /* @__PURE__ */ jsxs(
1404
- "svg",
1405
- {
1406
- style: {
1407
- position: "absolute",
1408
- width: svgWidth,
1409
- height: svgHeight,
1410
- pointerEvents: "none",
1411
- zIndex: 2
1412
- },
1413
- width: svgWidth,
1414
- height: svgHeight,
1415
- viewBox: `0 0 ${rect.size.width} ${rect.size.height}`,
1416
- overflow: "visible",
1417
- children: [
1418
- isCloudy && cloudyPath ? /* @__PURE__ */ jsx(
1419
- "path",
1420
- {
1421
- d: cloudyPath.path,
1422
- fill: "transparent",
1423
- stroke: "transparent",
1424
- strokeWidth: hitStrokeWidth,
1425
- onPointerDown: onClick,
1426
- style: {
1427
- cursor: isSelected ? "move" : onClick ? "pointer" : "default",
1428
- pointerEvents: !onClick ? "none" : isSelected ? "none" : color === "transparent" ? "visibleStroke" : "visible"
1429
- }
1430
- }
1431
- ) : /* @__PURE__ */ jsx(
1432
- "rect",
1433
- {
1434
- x,
1435
- y,
1436
- width,
1437
- height,
1438
- fill: "transparent",
1439
- stroke: "transparent",
1440
- strokeWidth: hitStrokeWidth,
1441
- onPointerDown: onClick,
1442
- style: {
1443
- cursor: isSelected ? "move" : onClick ? "pointer" : "default",
1444
- pointerEvents: !onClick ? "none" : isSelected ? "none" : color === "transparent" ? "visibleStroke" : "visible"
1445
- }
1446
- }
1447
- ),
1448
- !appearanceActive && (isCloudy && cloudyPath ? /* @__PURE__ */ jsx(
1449
- "path",
1450
- {
1451
- d: cloudyPath.path,
1452
- fill: color,
1453
- opacity,
1454
- style: {
1455
- pointerEvents: "none",
1456
- stroke: strokeColor ?? color,
1457
- strokeWidth,
1458
- strokeLinejoin: "round"
1459
- }
1460
- }
1461
- ) : /* @__PURE__ */ jsx(
1462
- "rect",
1463
- {
1464
- x,
1465
- y,
1466
- width,
1467
- height,
1468
- fill: color,
1469
- opacity,
1470
- style: {
1471
- pointerEvents: "none",
1472
- stroke: strokeColor ?? color,
1473
- strokeWidth,
1474
- ...strokeStyle === PdfAnnotationBorderStyle.DASHED && {
1475
- strokeDasharray: strokeDashArray == null ? void 0 : strokeDashArray.join(",")
1476
- }
1477
- }
1478
- }
1479
- ))
1480
- ]
1481
- }
1482
- );
1483
- }
1484
- const MIN_HIT_AREA_SCREEN_PX$4 = 20;
1485
- function Circle({
1486
- color = "#000000",
1487
- strokeColor,
1488
- opacity = 1,
1489
- strokeWidth,
1490
- strokeStyle = PdfAnnotationBorderStyle.SOLID,
1491
- strokeDashArray,
1492
- rect,
1493
- scale,
1494
- onClick,
1495
- isSelected,
1496
- appearanceActive = false,
1497
- cloudyBorderIntensity,
1498
- rectangleDifferences
1499
- }) {
1500
- const isCloudy = (cloudyBorderIntensity ?? 0) > 0;
1501
- const { width, height, cx, cy, rx, ry } = useMemo(() => {
1502
- const outerW = rect.size.width;
1503
- const outerH = rect.size.height;
1504
- const innerW = Math.max(outerW - strokeWidth, 0);
1505
- const innerH = Math.max(outerH - strokeWidth, 0);
1506
- return {
1507
- width: outerW,
1508
- height: outerH,
1509
- cx: strokeWidth / 2 + innerW / 2,
1510
- cy: strokeWidth / 2 + innerH / 2,
1511
- rx: innerW / 2,
1512
- ry: innerH / 2
1513
- };
1514
- }, [rect, strokeWidth]);
1515
- const cloudyPath = useMemo(() => {
1516
- if (!isCloudy) return null;
1517
- return generateCloudyEllipsePath(
1518
- { x: 0, y: 0, width: rect.size.width, height: rect.size.height },
1519
- rectangleDifferences,
1520
- cloudyBorderIntensity,
1521
- strokeWidth
1522
- );
1523
- }, [isCloudy, rect, rectangleDifferences, cloudyBorderIntensity, strokeWidth]);
1524
- const svgWidth = width * scale;
1525
- const svgHeight = height * scale;
1526
- const hitStrokeWidth = Math.max(strokeWidth, MIN_HIT_AREA_SCREEN_PX$4 / scale);
1527
- return /* @__PURE__ */ jsxs(
1528
- "svg",
1529
- {
1530
- style: {
1531
- position: "absolute",
1532
- width: svgWidth,
1533
- height: svgHeight,
1534
- pointerEvents: "none",
1535
- zIndex: 2
1536
- },
1537
- width: svgWidth,
1538
- height: svgHeight,
1539
- viewBox: `0 0 ${width} ${height}`,
1540
- overflow: "visible",
1541
- children: [
1542
- isCloudy && cloudyPath ? /* @__PURE__ */ jsx(
1543
- "path",
1544
- {
1545
- d: cloudyPath.path,
1546
- fill: "transparent",
1547
- stroke: "transparent",
1548
- strokeWidth: hitStrokeWidth,
1549
- onPointerDown: onClick,
1550
- style: {
1551
- cursor: isSelected ? "move" : onClick ? "pointer" : "default",
1552
- pointerEvents: !onClick ? "none" : isSelected ? "none" : color === "transparent" ? "visibleStroke" : "visible"
1553
- }
1554
- }
1555
- ) : /* @__PURE__ */ jsx(
1556
- "ellipse",
1557
- {
1558
- cx,
1559
- cy,
1560
- rx,
1561
- ry,
1562
- fill: "transparent",
1563
- stroke: "transparent",
1564
- strokeWidth: hitStrokeWidth,
1565
- onPointerDown: onClick,
1566
- style: {
1567
- cursor: isSelected ? "move" : onClick ? "pointer" : "default",
1568
- pointerEvents: !onClick ? "none" : isSelected ? "none" : color === "transparent" ? "visibleStroke" : "visible"
1569
- }
1570
- }
1571
- ),
1572
- !appearanceActive && (isCloudy && cloudyPath ? /* @__PURE__ */ jsx(
1573
- "path",
1574
- {
1575
- d: cloudyPath.path,
1576
- fill: color,
1577
- opacity,
1578
- style: {
1579
- pointerEvents: "none",
1580
- stroke: strokeColor ?? color,
1581
- strokeWidth,
1582
- strokeLinejoin: "round"
1583
- }
1584
- }
1585
- ) : /* @__PURE__ */ jsx(
1586
- "ellipse",
1587
- {
1588
- cx,
1589
- cy,
1590
- rx,
1591
- ry,
1592
- fill: color,
1593
- opacity,
1594
- style: {
1595
- pointerEvents: "none",
1596
- stroke: strokeColor ?? color,
1597
- strokeWidth,
1598
- ...strokeStyle === PdfAnnotationBorderStyle.DASHED && {
1599
- strokeDasharray: strokeDashArray == null ? void 0 : strokeDashArray.join(",")
1600
- }
1601
- }
1602
- }
1603
- ))
1604
- ]
1605
- }
1606
- );
1607
- }
1608
- const MIN_HIT_AREA_SCREEN_PX$3 = 20;
1609
- function Line({
1610
- color = "transparent",
1611
- opacity = 1,
1612
- strokeWidth,
1613
- strokeColor = "#000000",
1614
- strokeStyle = PdfAnnotationBorderStyle.SOLID,
1615
- strokeDashArray,
1616
- rect,
1617
- linePoints,
1618
- lineEndings,
1619
- scale,
1620
- onClick,
1621
- isSelected,
1622
- appearanceActive = false
1623
- }) {
1624
- const { x1, y1, x2, y2 } = useMemo(() => {
1625
- return {
1626
- x1: linePoints.start.x - rect.origin.x,
1627
- y1: linePoints.start.y - rect.origin.y,
1628
- x2: linePoints.end.x - rect.origin.x,
1629
- y2: linePoints.end.y - rect.origin.y
1630
- };
1631
- }, [linePoints, rect]);
1632
- const endings = useMemo(() => {
1633
- const angle = Math.atan2(y2 - y1, x2 - x1);
1634
- return {
1635
- start: patching.createEnding(lineEndings == null ? void 0 : lineEndings.start, strokeWidth, angle + Math.PI, x1, y1),
1636
- end: patching.createEnding(lineEndings == null ? void 0 : lineEndings.end, strokeWidth, angle, x2, y2)
1637
- };
1638
- }, [lineEndings, strokeWidth, x1, y1, x2, y2]);
1639
- const width = rect.size.width * scale;
1640
- const height = rect.size.height * scale;
1641
- const hitStrokeWidth = Math.max(strokeWidth, MIN_HIT_AREA_SCREEN_PX$3 / scale);
1642
- return /* @__PURE__ */ jsxs(
1643
- "svg",
1644
- {
1645
- style: {
1646
- position: "absolute",
1647
- width,
1648
- height,
1649
- pointerEvents: "none",
1650
- zIndex: 2,
1651
- overflow: "visible"
1652
- },
1653
- width,
1654
- height,
1655
- viewBox: `0 0 ${rect.size.width} ${rect.size.height}`,
1656
- children: [
1657
- /* @__PURE__ */ jsx(
1658
- "line",
1659
- {
1660
- x1,
1661
- y1,
1662
- x2,
1663
- y2,
1664
- stroke: "transparent",
1665
- strokeWidth: hitStrokeWidth,
1666
- onPointerDown: onClick,
1667
- style: {
1668
- cursor: isSelected ? "move" : onClick ? "pointer" : "default",
1669
- pointerEvents: !onClick ? "none" : isSelected ? "none" : "visibleStroke",
1670
- strokeLinecap: "butt"
1671
- }
1672
- }
1673
- ),
1674
- endings.start && /* @__PURE__ */ jsx(
1675
- "path",
1676
- {
1677
- d: endings.start.d,
1678
- transform: endings.start.transform,
1679
- fill: "transparent",
1680
- stroke: "transparent",
1681
- strokeWidth: hitStrokeWidth,
1682
- onPointerDown: onClick,
1683
- style: {
1684
- cursor: isSelected ? "move" : onClick ? "pointer" : "default",
1685
- pointerEvents: !onClick ? "none" : isSelected ? "none" : endings.start.filled ? "visible" : "visibleStroke",
1686
- strokeLinecap: "butt"
1687
- }
1688
- }
1689
- ),
1690
- endings.end && /* @__PURE__ */ jsx(
1691
- "path",
1692
- {
1693
- d: endings.end.d,
1694
- transform: endings.end.transform,
1695
- fill: "transparent",
1696
- stroke: "transparent",
1697
- strokeWidth: hitStrokeWidth,
1698
- onPointerDown: onClick,
1699
- style: {
1700
- cursor: isSelected ? "move" : onClick ? "pointer" : "default",
1701
- pointerEvents: !onClick ? "none" : isSelected ? "none" : endings.end.filled ? "visible" : "visibleStroke",
1702
- strokeLinecap: "butt"
1703
- }
1704
- }
1705
- ),
1706
- !appearanceActive && /* @__PURE__ */ jsxs(Fragment, { children: [
1707
- /* @__PURE__ */ jsx(
1708
- "line",
1709
- {
1710
- x1,
1711
- y1,
1712
- x2,
1713
- y2,
1714
- opacity,
1715
- style: {
1716
- pointerEvents: "none",
1717
- stroke: strokeColor,
1718
- strokeWidth,
1719
- strokeLinecap: "butt",
1720
- ...strokeStyle === PdfAnnotationBorderStyle.DASHED && {
1721
- strokeDasharray: strokeDashArray == null ? void 0 : strokeDashArray.join(",")
1722
- }
1723
- }
1724
- }
1725
- ),
1726
- endings.start && /* @__PURE__ */ jsx(
1727
- "path",
1728
- {
1729
- d: endings.start.d,
1730
- transform: endings.start.transform,
1731
- stroke: strokeColor,
1732
- fill: endings.start.filled ? color : "none",
1733
- style: {
1734
- pointerEvents: "none",
1735
- strokeWidth,
1736
- strokeLinecap: "butt",
1737
- ...strokeStyle === PdfAnnotationBorderStyle.DASHED && {
1738
- strokeDasharray: strokeDashArray == null ? void 0 : strokeDashArray.join(",")
1739
- }
1740
- }
1741
- }
1742
- ),
1743
- endings.end && /* @__PURE__ */ jsx(
1744
- "path",
1745
- {
1746
- d: endings.end.d,
1747
- transform: endings.end.transform,
1748
- stroke: strokeColor,
1749
- fill: endings.end.filled ? color : "none",
1750
- style: {
1751
- pointerEvents: "none",
1752
- strokeWidth,
1753
- strokeLinecap: "butt",
1754
- ...strokeStyle === PdfAnnotationBorderStyle.DASHED && {
1755
- strokeDasharray: strokeDashArray == null ? void 0 : strokeDashArray.join(",")
1756
- }
1757
- }
1758
- }
1759
- )
1760
- ] })
1761
- ]
1762
- }
1763
- );
1764
- }
1765
- const MIN_HIT_AREA_SCREEN_PX$2 = 20;
1766
- function Polyline({
1767
- rect,
1768
- vertices,
1769
- color = "transparent",
1770
- strokeColor = "#000000",
1771
- opacity = 1,
1772
- strokeWidth,
1773
- strokeStyle = PdfAnnotationBorderStyle.SOLID,
1774
- strokeDashArray,
1775
- scale,
1776
- isSelected,
1777
- onClick,
1778
- lineEndings,
1779
- appearanceActive = false
1780
- }) {
1781
- const localPts = useMemo(
1782
- () => vertices.map(({ x, y }) => ({ x: x - rect.origin.x, y: y - rect.origin.y })),
1783
- [vertices, rect]
1784
- );
1785
- const pathData = useMemo(() => {
1786
- if (!localPts.length) return "";
1787
- const [first, ...rest] = localPts;
1788
- return `M ${first.x} ${first.y} ` + rest.map((p) => `L ${p.x} ${p.y} `).join("").trim();
1789
- }, [localPts]);
1790
- const endings = useMemo(() => {
1791
- if (localPts.length < 2) return { start: null, end: null };
1792
- const toAngle = (a, b) => Math.atan2(b.y - a.y, b.x - a.x);
1793
- const startRad = toAngle(localPts[0], localPts[1]);
1794
- const endRad = toAngle(localPts[localPts.length - 2], localPts[localPts.length - 1]);
1795
- const start = patching.createEnding(
1796
- lineEndings == null ? void 0 : lineEndings.start,
1797
- strokeWidth,
1798
- startRad + Math.PI,
1799
- localPts[0].x,
1800
- localPts[0].y
1801
- );
1802
- const end = patching.createEnding(
1803
- lineEndings == null ? void 0 : lineEndings.end,
1804
- strokeWidth,
1805
- endRad,
1806
- localPts[localPts.length - 1].x,
1807
- localPts[localPts.length - 1].y
1808
- );
1809
- return { start, end };
1810
- }, [localPts, lineEndings, strokeWidth]);
1811
- const width = rect.size.width * scale;
1812
- const height = rect.size.height * scale;
1813
- const hitStrokeWidth = Math.max(strokeWidth, MIN_HIT_AREA_SCREEN_PX$2 / scale);
1814
- return /* @__PURE__ */ jsxs(
1815
- "svg",
1816
- {
1817
- style: {
1818
- position: "absolute",
1819
- width,
1820
- height,
1821
- pointerEvents: "none",
1822
- zIndex: 2,
1823
- overflow: "visible"
1824
- },
1825
- width,
1826
- height,
1827
- viewBox: `0 0 ${rect.size.width} ${rect.size.height}`,
1828
- children: [
1829
- /* @__PURE__ */ jsx(
1830
- "path",
1831
- {
1832
- d: pathData,
1833
- fill: "none",
1834
- stroke: "transparent",
1835
- strokeWidth: hitStrokeWidth,
1836
- onPointerDown: onClick,
1837
- style: {
1838
- cursor: isSelected ? "move" : onClick ? "pointer" : "default",
1839
- pointerEvents: !onClick ? "none" : isSelected ? "none" : "visibleStroke",
1840
- strokeLinecap: "butt",
1841
- strokeLinejoin: "miter"
1842
- }
1843
- }
1844
- ),
1845
- endings.start && /* @__PURE__ */ jsx(
1846
- "path",
1847
- {
1848
- d: endings.start.d,
1849
- transform: endings.start.transform,
1850
- fill: "transparent",
1851
- stroke: "transparent",
1852
- strokeWidth: hitStrokeWidth,
1853
- onPointerDown: onClick,
1854
- style: {
1855
- cursor: isSelected ? "move" : onClick ? "pointer" : "default",
1856
- pointerEvents: !onClick ? "none" : isSelected ? "none" : endings.start.filled ? "visible" : "visibleStroke",
1857
- strokeLinecap: "butt"
1858
- }
1859
- }
1860
- ),
1861
- endings.end && /* @__PURE__ */ jsx(
1862
- "path",
1863
- {
1864
- d: endings.end.d,
1865
- transform: endings.end.transform,
1866
- fill: "transparent",
1867
- stroke: "transparent",
1868
- strokeWidth: hitStrokeWidth,
1869
- onPointerDown: onClick,
1870
- style: {
1871
- cursor: isSelected ? "move" : onClick ? "pointer" : "default",
1872
- pointerEvents: !onClick ? "none" : isSelected ? "none" : endings.end.filled ? "visible" : "visibleStroke",
1873
- strokeLinecap: "butt"
1874
- }
1875
- }
1876
- ),
1877
- !appearanceActive && /* @__PURE__ */ jsxs(Fragment, { children: [
1878
- /* @__PURE__ */ jsx(
1879
- "path",
1880
- {
1881
- d: pathData,
1882
- opacity,
1883
- style: {
1884
- fill: "none",
1885
- stroke: strokeColor ?? color,
1886
- strokeWidth,
1887
- pointerEvents: "none",
1888
- strokeLinecap: "butt",
1889
- strokeLinejoin: "miter",
1890
- ...strokeStyle === PdfAnnotationBorderStyle.DASHED && {
1891
- strokeDasharray: strokeDashArray == null ? void 0 : strokeDashArray.join(",")
1892
- }
1893
- }
1894
- }
1895
- ),
1896
- endings.start && /* @__PURE__ */ jsx(
1897
- "path",
1898
- {
1899
- d: endings.start.d,
1900
- transform: endings.start.transform,
1901
- stroke: strokeColor,
1902
- fill: endings.start.filled ? color : "none",
1903
- style: {
1904
- pointerEvents: "none",
1905
- strokeWidth,
1906
- strokeLinecap: "butt",
1907
- ...strokeStyle === PdfAnnotationBorderStyle.DASHED && {
1908
- strokeDasharray: strokeDashArray == null ? void 0 : strokeDashArray.join(",")
1909
- }
1910
- }
1911
- }
1912
- ),
1913
- endings.end && /* @__PURE__ */ jsx(
1914
- "path",
1915
- {
1916
- d: endings.end.d,
1917
- transform: endings.end.transform,
1918
- stroke: strokeColor,
1919
- fill: endings.end.filled ? color : "none",
1920
- style: {
1921
- pointerEvents: "none",
1922
- strokeWidth,
1923
- strokeLinecap: "butt",
1924
- ...strokeStyle === PdfAnnotationBorderStyle.DASHED && {
1925
- strokeDasharray: strokeDashArray == null ? void 0 : strokeDashArray.join(",")
1926
- }
1927
- }
1928
- }
1929
- )
1930
- ] })
1931
- ]
1932
- }
1933
- );
1934
- }
1935
- const MIN_HIT_AREA_SCREEN_PX$1 = 20;
1936
- function Polygon({
1937
- rect,
1938
- vertices,
1939
- color = "transparent",
1940
- strokeColor = "#000000",
1941
- opacity = 1,
1942
- strokeWidth,
1943
- strokeStyle = PdfAnnotationBorderStyle.SOLID,
1944
- strokeDashArray,
1945
- scale,
1946
- isSelected,
1947
- onClick,
1948
- currentVertex,
1949
- handleSize = 14,
1950
- appearanceActive = false,
1951
- cloudyBorderIntensity
1952
- }) {
1953
- const isCloudy = (cloudyBorderIntensity ?? 0) > 0;
1954
- const allPoints = currentVertex ? [...vertices, currentVertex] : vertices;
1955
- const localPts = useMemo(
1956
- () => allPoints.map(({ x, y }) => ({ x: x - rect.origin.x, y: y - rect.origin.y })),
1957
- [allPoints, rect]
1958
- );
1959
- const pathData = useMemo(() => {
1960
- if (!localPts.length) return "";
1961
- const [first, ...rest] = localPts;
1962
- const isPreview = !!currentVertex;
1963
- return (`M ${first.x} ${first.y} ` + rest.map((p) => `L ${p.x} ${p.y}`).join(" ") + (isPreview ? "" : " Z")).trim();
1964
- }, [localPts, currentVertex]);
1965
- const cloudyPath = useMemo(() => {
1966
- if (!isCloudy || allPoints.length < 3) return null;
1967
- return generateCloudyPolygonPath(allPoints, rect.origin, cloudyBorderIntensity, strokeWidth);
1968
- }, [isCloudy, allPoints, rect.origin, cloudyBorderIntensity, strokeWidth]);
1969
- const isPreviewing = currentVertex && vertices.length > 0;
1970
- const width = rect.size.width * scale;
1971
- const height = rect.size.height * scale;
1972
- const hitStrokeWidth = Math.max(strokeWidth, MIN_HIT_AREA_SCREEN_PX$1 / scale);
1973
- return /* @__PURE__ */ jsxs(
1974
- "svg",
1975
- {
1976
- style: {
1977
- position: "absolute",
1978
- width,
1979
- height,
1980
- pointerEvents: "none",
1981
- zIndex: 2,
1982
- overflow: "visible"
1983
- },
1984
- width,
1985
- height,
1986
- viewBox: `0 0 ${rect.size.width} ${rect.size.height}`,
1987
- children: [
1988
- /* @__PURE__ */ jsx(
1989
- "path",
1990
- {
1991
- d: isCloudy && cloudyPath ? cloudyPath.path : pathData,
1992
- fill: "transparent",
1993
- stroke: "transparent",
1994
- strokeWidth: hitStrokeWidth,
1995
- onPointerDown: onClick,
1996
- style: {
1997
- cursor: isSelected ? "move" : onClick ? "pointer" : "default",
1998
- pointerEvents: !onClick ? "none" : isSelected ? "none" : color === "transparent" ? "visibleStroke" : "visible",
1999
- strokeLinecap: "butt",
2000
- strokeLinejoin: "miter"
2001
- }
2002
- }
2003
- ),
2004
- !appearanceActive && /* @__PURE__ */ jsx(Fragment, { children: isCloudy && cloudyPath ? /* @__PURE__ */ jsx(
2005
- "path",
2006
- {
2007
- d: cloudyPath.path,
2008
- opacity,
2009
- style: {
2010
- fill: color,
2011
- stroke: strokeColor ?? color,
2012
- strokeWidth,
2013
- pointerEvents: "none",
2014
- strokeLinejoin: "round"
2015
- }
2016
- }
2017
- ) : /* @__PURE__ */ jsxs(Fragment, { children: [
2018
- /* @__PURE__ */ jsx(
2019
- "path",
2020
- {
2021
- d: pathData,
2022
- opacity,
2023
- style: {
2024
- fill: currentVertex ? "none" : color,
2025
- stroke: strokeColor ?? color,
2026
- strokeWidth,
2027
- pointerEvents: "none",
2028
- strokeLinecap: "butt",
2029
- strokeLinejoin: "miter",
2030
- ...strokeStyle === PdfAnnotationBorderStyle.DASHED && {
2031
- strokeDasharray: strokeDashArray == null ? void 0 : strokeDashArray.join(",")
2032
- }
2033
- }
2034
- }
2035
- ),
2036
- isPreviewing && vertices.length > 1 && /* @__PURE__ */ jsx(
2037
- "path",
2038
- {
2039
- d: `M ${localPts[localPts.length - 1].x} ${localPts[localPts.length - 1].y} L ${localPts[0].x} ${localPts[0].y}`,
2040
- fill: "none",
2041
- style: {
2042
- stroke: strokeColor,
2043
- strokeWidth,
2044
- strokeDasharray: "4,4",
2045
- opacity: 0.7,
2046
- pointerEvents: "none"
2047
- }
2048
- }
2049
- ),
2050
- isPreviewing && vertices.length >= 2 && /* @__PURE__ */ jsx(
2051
- "rect",
2052
- {
2053
- x: localPts[0].x - handleSize / scale / 2,
2054
- y: localPts[0].y - handleSize / scale / 2,
2055
- width: handleSize / scale,
2056
- height: handleSize / scale,
2057
- fill: strokeColor,
2058
- opacity: 0.4,
2059
- stroke: strokeColor,
2060
- strokeWidth: strokeWidth / 2,
2061
- style: { pointerEvents: "none" }
2062
- }
2063
- )
2064
- ] }) })
2065
- ]
2066
- }
2067
- );
2068
- }
2069
- function Text({
2070
- isSelected,
2071
- color = "#facc15",
2072
- opacity = 1,
2073
- onClick,
2074
- appearanceActive = false
2075
- }) {
2076
- const lineColor = getContrastStrokeColor(color);
2077
- return /* @__PURE__ */ jsx(
2078
- "div",
2079
- {
2080
- style: {
2081
- position: "absolute",
2082
- inset: 0,
2083
- zIndex: 2,
2084
- pointerEvents: !onClick ? "none" : isSelected ? "none" : "auto",
2085
- cursor: isSelected ? "move" : onClick ? "pointer" : "default"
2086
- },
2087
- onPointerDown: onClick,
2088
- children: !appearanceActive && /* @__PURE__ */ jsxs(
2089
- "svg",
2090
- {
2091
- style: {
2092
- position: "absolute",
2093
- inset: 0,
2094
- pointerEvents: "none"
2095
- },
2096
- viewBox: "0 0 20 20",
2097
- width: "100%",
2098
- height: "100%",
2099
- children: [
2100
- /* @__PURE__ */ jsx(
2101
- "path",
2102
- {
2103
- 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",
2104
- fill: color,
2105
- opacity,
2106
- stroke: lineColor,
2107
- strokeWidth: "1",
2108
- strokeLinejoin: "miter"
2109
- }
2110
- ),
2111
- /* @__PURE__ */ jsx("line", { x1: "2.5", y1: "4.25", x2: "17.5", y2: "4.25", stroke: lineColor, strokeWidth: "1" }),
2112
- /* @__PURE__ */ jsx("line", { x1: "2.5", y1: "8", x2: "17.5", y2: "8", stroke: lineColor, strokeWidth: "1" }),
2113
- /* @__PURE__ */ jsx("line", { x1: "2.5", y1: "11.75", x2: "17.5", y2: "11.75", stroke: lineColor, strokeWidth: "1" })
2114
- ]
2115
- }
2116
- )
2117
- }
2118
- );
2119
- }
2120
- function FreeText({
2121
- documentId,
2122
- isSelected,
2123
- isEditing,
2124
- annotation,
2125
- pageIndex,
2126
- scale,
2127
- onClick,
2128
- appearanceActive = false
2129
- }) {
2130
- const editorRef = useRef(null);
2131
- const editingRef = useRef(false);
2132
- const { provides: annotationCapability } = useAnnotationCapability();
2133
- const annotationProvides = (annotationCapability == null ? void 0 : annotationCapability.forDocument(documentId)) ?? null;
2134
- const { adjustedFontPx, wrapperStyle } = useIOSZoomPrevention(
2135
- annotation.object.fontSize * scale,
2136
- isEditing
2137
- );
2138
- useEffect(() => {
2139
- var _a;
2140
- if (isEditing && editorRef.current) {
2141
- editingRef.current = true;
2142
- const editor = editorRef.current;
2143
- editor.focus();
2144
- const tool = annotationProvides == null ? void 0 : annotationProvides.findToolForAnnotation(annotation.object);
2145
- const isDefaultContent = ((_a = tool == null ? void 0 : tool.defaults) == null ? void 0 : _a.contents) != null && annotation.object.contents === tool.defaults.contents;
2146
- const selection = window.getSelection();
2147
- if (selection) {
2148
- const range = document.createRange();
2149
- range.selectNodeContents(editor);
2150
- if (!isDefaultContent) {
2151
- range.collapse(false);
2152
- }
2153
- selection.removeAllRanges();
2154
- selection.addRange(range);
2155
- }
2156
- }
2157
- }, [isEditing]);
2158
- const handleBlur = () => {
2159
- if (!editingRef.current) return;
2160
- editingRef.current = false;
2161
- if (!annotationProvides) return;
2162
- if (!editorRef.current) return;
2163
- annotationProvides.updateAnnotation(pageIndex, annotation.object.id, {
2164
- contents: editorRef.current.innerText.replace(/\u00A0/g, " ")
2165
- });
2166
- };
2167
- return /* @__PURE__ */ jsx(
2168
- "div",
2169
- {
2170
- style: {
2171
- position: "absolute",
2172
- width: annotation.object.rect.size.width * scale,
2173
- height: annotation.object.rect.size.height * scale,
2174
- cursor: isSelected && !isEditing ? "move" : "default",
2175
- pointerEvents: !onClick ? "none" : isSelected && !isEditing ? "none" : "auto",
2176
- zIndex: 2,
2177
- opacity: appearanceActive ? 0 : 1
2178
- },
2179
- onPointerDown: onClick,
2180
- children: /* @__PURE__ */ jsx(
2181
- "span",
2182
- {
2183
- ref: editorRef,
2184
- onBlur: handleBlur,
2185
- tabIndex: 0,
2186
- style: {
2187
- color: annotation.object.fontColor,
2188
- fontSize: adjustedFontPx,
2189
- ...standardFontCssProperties(annotation.object.fontFamily),
2190
- textAlign: textAlignmentToCss(annotation.object.textAlign),
2191
- flexDirection: "column",
2192
- justifyContent: annotation.object.verticalAlign === PdfVerticalAlignment.Top ? "flex-start" : annotation.object.verticalAlign === PdfVerticalAlignment.Middle ? "center" : "flex-end",
2193
- display: "flex",
2194
- backgroundColor: annotation.object.color ?? annotation.object.backgroundColor,
2195
- opacity: annotation.object.opacity,
2196
- width: "100%",
2197
- height: "100%",
2198
- lineHeight: "1.18",
2199
- overflow: "hidden",
2200
- cursor: isEditing ? "text" : onClick ? "pointer" : "default",
2201
- outline: "none",
2202
- ...wrapperStyle
2203
- },
2204
- contentEditable: isEditing,
2205
- ...suppressContentEditableWarningProps,
2206
- children: annotation.object.contents
2207
- }
2208
- )
2209
- }
2210
- );
2211
- }
2212
- const MIN_HIT_AREA_SCREEN_PX = 20;
2213
- function CalloutFreeText({
2214
- documentId,
2215
- isSelected,
2216
- isEditing,
2217
- annotation,
2218
- pageIndex,
2219
- scale,
2220
- onClick,
2221
- appearanceActive = false
2222
- }) {
2223
- const editorRef = useRef(null);
2224
- const editingRef = useRef(false);
2225
- const { provides: annotationCapability } = useAnnotationCapability();
2226
- const annotationProvides = (annotationCapability == null ? void 0 : annotationCapability.forDocument(documentId)) ?? null;
2227
- const obj = annotation.object;
2228
- const rect = obj.rect;
2229
- const rd = obj.rectangleDifferences;
2230
- const calloutLine = obj.calloutLine;
2231
- const strokeWidth = obj.strokeWidth ?? 1;
2232
- const strokeColor = obj.strokeColor ?? "#000000";
2233
- const textBox = useMemo(() => patching.computeTextBoxFromRD(rect, rd), [rect, rd]);
2234
- const textBoxRelative = useMemo(
2235
- () => ({
2236
- left: (textBox.origin.x - rect.origin.x + strokeWidth / 2) * scale,
2237
- top: (textBox.origin.y - rect.origin.y + strokeWidth / 2) * scale,
2238
- width: (textBox.size.width - strokeWidth) * scale,
2239
- height: (textBox.size.height - strokeWidth) * scale
2240
- }),
2241
- [textBox, rect, scale, strokeWidth]
2242
- );
2243
- const lineCoords = useMemo(() => {
2244
- if (!calloutLine || calloutLine.length < 3) return null;
2245
- return calloutLine.map((p) => ({
2246
- x: p.x - rect.origin.x,
2247
- y: p.y - rect.origin.y
2248
- }));
2249
- }, [calloutLine, rect]);
2250
- const ending = useMemo(() => {
2251
- if (!lineCoords || lineCoords.length < 2) return null;
2252
- const angle = Math.atan2(lineCoords[1].y - lineCoords[0].y, lineCoords[1].x - lineCoords[0].x);
2253
- return patching.createEnding(
2254
- obj.lineEnding,
2255
- strokeWidth,
2256
- angle + Math.PI,
2257
- lineCoords[0].x,
2258
- lineCoords[0].y
2259
- );
2260
- }, [lineCoords, obj.lineEnding, strokeWidth]);
2261
- const visualLineCoords = useMemo(() => {
2262
- if (!lineCoords || lineCoords.length < 2) return lineCoords;
2263
- const pts = lineCoords.map((p) => ({ ...p }));
2264
- const last = pts.length - 1;
2265
- const prev = last - 1;
2266
- const dx = pts[last].x - pts[prev].x;
2267
- const dy = pts[last].y - pts[prev].y;
2268
- const len = Math.sqrt(dx * dx + dy * dy);
2269
- if (len > 0) {
2270
- const halfBw = strokeWidth / 2;
2271
- pts[last].x += dx / len * halfBw;
2272
- pts[last].y += dy / len * halfBw;
2273
- }
2274
- return pts;
2275
- }, [lineCoords, strokeWidth]);
2276
- const { adjustedFontPx, wrapperStyle } = useIOSZoomPrevention(obj.fontSize * scale, isEditing);
2277
- useEffect(() => {
2278
- var _a;
2279
- if (isEditing && editorRef.current) {
2280
- editingRef.current = true;
2281
- const editor = editorRef.current;
2282
- editor.focus();
2283
- const tool = annotationProvides == null ? void 0 : annotationProvides.findToolForAnnotation(obj);
2284
- const isDefaultContent = ((_a = tool == null ? void 0 : tool.defaults) == null ? void 0 : _a.contents) != null && obj.contents === tool.defaults.contents;
2285
- const selection = window.getSelection();
2286
- if (selection) {
2287
- const range = document.createRange();
2288
- range.selectNodeContents(editor);
2289
- if (!isDefaultContent) {
2290
- range.collapse(false);
2291
- }
2292
- selection.removeAllRanges();
2293
- selection.addRange(range);
2294
- }
2295
- }
2296
- }, [isEditing]);
2297
- const handleBlur = () => {
2298
- if (!editingRef.current) return;
2299
- editingRef.current = false;
2300
- if (!annotationProvides) return;
2301
- if (!editorRef.current) return;
2302
- annotationProvides.updateAnnotation(pageIndex, obj.id, {
2303
- contents: editorRef.current.innerText.replace(/\u00A0/g, " ")
2304
- });
2305
- };
2306
- const width = rect.size.width * scale;
2307
- const height = rect.size.height * scale;
2308
- const hitStrokeWidth = Math.max(strokeWidth, MIN_HIT_AREA_SCREEN_PX / scale);
2309
- return /* @__PURE__ */ jsxs(
2310
- "div",
2311
- {
2312
- style: {
2313
- position: "absolute",
2314
- width,
2315
- height,
2316
- cursor: isSelected && !isEditing ? "move" : "default",
2317
- pointerEvents: "none",
2318
- zIndex: 2,
2319
- opacity: appearanceActive ? 0 : 1
2320
- },
2321
- children: [
2322
- /* @__PURE__ */ jsxs(
2323
- "svg",
2324
- {
2325
- style: {
2326
- position: "absolute",
2327
- width,
2328
- height,
2329
- pointerEvents: "none",
2330
- overflow: "visible"
2331
- },
2332
- width,
2333
- height,
2334
- viewBox: `0 0 ${rect.size.width} ${rect.size.height}`,
2335
- children: [
2336
- lineCoords && /* @__PURE__ */ jsxs(Fragment, { children: [
2337
- /* @__PURE__ */ jsx(
2338
- "polyline",
2339
- {
2340
- points: lineCoords.map((p) => `${p.x},${p.y}`).join(" "),
2341
- fill: "none",
2342
- stroke: "transparent",
2343
- strokeWidth: hitStrokeWidth,
2344
- onPointerDown: onClick ? (e) => onClick(e) : void 0,
2345
- style: {
2346
- cursor: isSelected ? "move" : onClick ? "pointer" : "default",
2347
- pointerEvents: !onClick ? "none" : isSelected ? "none" : "visibleStroke"
2348
- }
2349
- }
2350
- ),
2351
- ending && /* @__PURE__ */ jsx(
2352
- "path",
2353
- {
2354
- d: ending.d,
2355
- transform: ending.transform,
2356
- fill: "transparent",
2357
- stroke: "transparent",
2358
- strokeWidth: hitStrokeWidth,
2359
- onPointerDown: onClick ? (e) => onClick(e) : void 0,
2360
- style: {
2361
- cursor: isSelected ? "move" : onClick ? "pointer" : "default",
2362
- pointerEvents: !onClick ? "none" : isSelected ? "none" : ending.filled ? "visible" : "visibleStroke"
2363
- }
2364
- }
2365
- )
2366
- ] }),
2367
- !appearanceActive && /* @__PURE__ */ jsxs(Fragment, { children: [
2368
- visualLineCoords && /* @__PURE__ */ jsxs(Fragment, { children: [
2369
- /* @__PURE__ */ jsx(
2370
- "polyline",
2371
- {
2372
- points: visualLineCoords.map((p) => `${p.x},${p.y}`).join(" "),
2373
- fill: "none",
2374
- stroke: strokeColor,
2375
- strokeWidth,
2376
- opacity: obj.opacity,
2377
- style: { pointerEvents: "none" }
2378
- }
2379
- ),
2380
- ending && /* @__PURE__ */ jsx(
2381
- "path",
2382
- {
2383
- d: ending.d,
2384
- transform: ending.transform,
2385
- stroke: strokeColor,
2386
- fill: ending.filled ? obj.color ?? "transparent" : "none",
2387
- strokeWidth,
2388
- opacity: obj.opacity,
2389
- style: { pointerEvents: "none" }
2390
- }
2391
- )
2392
- ] }),
2393
- /* @__PURE__ */ jsx(
2394
- "rect",
2395
- {
2396
- x: textBox.origin.x - rect.origin.x + strokeWidth / 2,
2397
- y: textBox.origin.y - rect.origin.y + strokeWidth / 2,
2398
- width: textBox.size.width - strokeWidth,
2399
- height: textBox.size.height - strokeWidth,
2400
- fill: obj.color ?? obj.backgroundColor ?? "transparent",
2401
- stroke: strokeColor,
2402
- strokeWidth,
2403
- opacity: obj.opacity,
2404
- style: { pointerEvents: "none" }
2405
- }
2406
- )
2407
- ] })
2408
- ]
2409
- }
2410
- ),
2411
- /* @__PURE__ */ jsx(
2412
- "div",
2413
- {
2414
- onPointerDown: onClick ? (e) => onClick(e) : void 0,
2415
- style: {
2416
- position: "absolute",
2417
- left: (textBox.origin.x - rect.origin.x) * scale,
2418
- top: (textBox.origin.y - rect.origin.y) * scale,
2419
- width: textBox.size.width * scale,
2420
- height: textBox.size.height * scale,
2421
- cursor: isSelected && !isEditing ? "move" : onClick ? "pointer" : "default",
2422
- pointerEvents: !onClick ? "none" : isSelected && !isEditing ? "none" : "auto"
2423
- }
2424
- }
2425
- ),
2426
- /* @__PURE__ */ jsx(
2427
- "span",
2428
- {
2429
- ref: editorRef,
2430
- onBlur: handleBlur,
2431
- tabIndex: 0,
2432
- style: {
2433
- position: "absolute",
2434
- left: textBoxRelative.left,
2435
- top: textBoxRelative.top,
2436
- width: textBoxRelative.width,
2437
- height: textBoxRelative.height,
2438
- color: obj.fontColor,
2439
- fontSize: adjustedFontPx,
2440
- ...standardFontCssProperties(obj.fontFamily),
2441
- textAlign: textAlignmentToCss(obj.textAlign),
2442
- flexDirection: "column",
2443
- justifyContent: obj.verticalAlign === PdfVerticalAlignment.Top ? "flex-start" : obj.verticalAlign === PdfVerticalAlignment.Middle ? "center" : "flex-end",
2444
- display: "flex",
2445
- padding: strokeWidth * scale / 2 + 2 * scale,
2446
- opacity: obj.opacity,
2447
- lineHeight: "1.18",
2448
- overflow: "hidden",
2449
- cursor: isEditing ? "text" : "default",
2450
- outline: "none",
2451
- pointerEvents: isEditing ? "auto" : "none",
2452
- ...wrapperStyle
2453
- },
2454
- contentEditable: isEditing,
2455
- ...suppressContentEditableWarningProps,
2456
- children: obj.contents
2457
- }
2458
- )
2459
- ]
2460
- }
2461
- );
2462
- }
2463
- function CalloutFreeTextPreview({
2464
- calloutLine,
2465
- textBox,
2466
- bounds,
2467
- scale,
2468
- strokeColor,
2469
- strokeWidth,
2470
- color,
2471
- backgroundColor,
2472
- opacity,
2473
- lineEnding
2474
- }) {
2475
- if (!calloutLine || calloutLine.length < 2) return /* @__PURE__ */ jsx(Fragment$1, {});
2476
- const sw = strokeWidth ?? 1;
2477
- const sc = strokeColor ?? "#000000";
2478
- const op = opacity ?? 1;
2479
- const w = bounds.size.width;
2480
- const h = bounds.size.height;
2481
- const ox = bounds.origin.x;
2482
- const oy = bounds.origin.y;
2483
- const lineCoords = calloutLine.map((p) => ({ x: p.x - ox, y: p.y - oy }));
2484
- const angle = Math.atan2(lineCoords[1].y - lineCoords[0].y, lineCoords[1].x - lineCoords[0].x);
2485
- const ending = patching.createEnding(
2486
- lineEnding,
2487
- sw,
2488
- angle + Math.PI,
2489
- lineCoords[0].x,
2490
- lineCoords[0].y
2491
- );
2492
- const halfSw = sw / 2;
2493
- return /* @__PURE__ */ jsxs(
2494
- "svg",
2495
- {
2496
- style: {
2497
- position: "absolute",
2498
- width: w * scale,
2499
- height: h * scale,
2500
- pointerEvents: "none",
2501
- overflow: "visible"
2502
- },
2503
- width: w * scale,
2504
- height: h * scale,
2505
- viewBox: `0 0 ${w} ${h}`,
2506
- children: [
2507
- /* @__PURE__ */ jsx(
2508
- "polyline",
2509
- {
2510
- points: lineCoords.map((p) => `${p.x},${p.y}`).join(" "),
2511
- fill: "none",
2512
- stroke: sc,
2513
- strokeWidth: sw,
2514
- opacity: op
2515
- }
2516
- ),
2517
- ending && /* @__PURE__ */ jsx(
2518
- "path",
2519
- {
2520
- d: ending.d,
2521
- transform: ending.transform,
2522
- stroke: sc,
2523
- fill: ending.filled ? color ?? "transparent" : "none",
2524
- strokeWidth: sw,
2525
- opacity: op
2526
- }
2527
- ),
2528
- textBox && /* @__PURE__ */ jsx(
2529
- "rect",
2530
- {
2531
- x: textBox.origin.x - ox + halfSw,
2532
- y: textBox.origin.y - oy + halfSw,
2533
- width: textBox.size.width - sw,
2534
- height: textBox.size.height - sw,
2535
- fill: color ?? backgroundColor ?? "transparent",
2536
- stroke: sc,
2537
- strokeWidth: sw,
2538
- opacity: op
2539
- }
2540
- )
2541
- ]
2542
- }
2543
- );
2544
- }
2545
- function RenderAnnotation({
2546
- documentId,
2547
- pageIndex,
2548
- annotation,
2549
- scaleFactor = 1,
2550
- unrotated,
2551
- style,
2552
- ...props
2553
- }) {
2554
- const { provides: annotationProvides } = useAnnotationCapability();
2555
- const [imageUrl, setImageUrl] = useState(null);
2556
- const urlRef = useRef(null);
2557
- const { width, height } = annotation.rect.size;
2558
- useEffect(() => {
2559
- if (annotationProvides) {
2560
- const task = annotationProvides.forDocument(documentId).renderAnnotation({
2561
- pageIndex,
2562
- annotation,
2563
- options: {
2564
- scaleFactor,
2565
- dpr: window.devicePixelRatio,
2566
- unrotated
2567
- }
2568
- });
2569
- task.wait((blob) => {
2570
- const url = URL.createObjectURL(blob);
2571
- setImageUrl(url);
2572
- urlRef.current = url;
2573
- }, ignore);
2574
- return () => {
2575
- if (urlRef.current) {
2576
- URL.revokeObjectURL(urlRef.current);
2577
- urlRef.current = null;
2578
- } else {
2579
- task.abort({
2580
- code: PdfErrorCode.Cancelled,
2581
- message: "canceled render task"
2582
- });
2583
- }
2584
- };
2585
- }
2586
- }, [
2587
- pageIndex,
2588
- scaleFactor,
2589
- unrotated,
2590
- annotationProvides,
2591
- documentId,
2592
- annotation.id,
2593
- width,
2594
- height
2595
- ]);
2596
- const handleImageLoad = () => {
2597
- if (urlRef.current) {
2598
- URL.revokeObjectURL(urlRef.current);
2599
- urlRef.current = null;
2600
- }
2601
- };
2602
- return /* @__PURE__ */ jsx(Fragment$1, { children: imageUrl && /* @__PURE__ */ jsx(
2603
- "img",
2604
- {
2605
- src: imageUrl,
2606
- onLoad: handleImageLoad,
2607
- ...props,
2608
- style: {
2609
- width: "100%",
2610
- height: "100%",
2611
- display: "block",
2612
- ...style || {}
2613
- }
2614
- }
2615
- ) });
2616
- }
2617
- function Stamp({
2618
- isSelected,
2619
- annotation,
2620
- documentId,
2621
- pageIndex,
2622
- scale,
2623
- onClick
2624
- }) {
2625
- const unrotated = !!annotation.object.rotation && !!annotation.object.unrotatedRect;
2626
- return /* @__PURE__ */ jsx(
2627
- "div",
2628
- {
2629
- style: {
2630
- position: "absolute",
2631
- width: "100%",
2632
- height: "100%",
2633
- zIndex: 2,
2634
- pointerEvents: !onClick ? "none" : isSelected ? "none" : "auto",
2635
- cursor: onClick ? "pointer" : "default"
2636
- },
2637
- onPointerDown: onClick,
2638
- children: /* @__PURE__ */ jsx(
2639
- RenderAnnotation,
2640
- {
2641
- documentId,
2642
- pageIndex,
2643
- annotation: { ...annotation.object, id: annotation.object.id },
2644
- scaleFactor: scale,
2645
- unrotated
2646
- }
2647
- )
2648
- }
2649
- );
2650
- }
2651
- function Link({
2652
- isSelected,
2653
- strokeColor = "#0000FF",
2654
- strokeWidth = 2,
2655
- strokeStyle = PdfAnnotationBorderStyle.UNDERLINE,
2656
- strokeDashArray,
2657
- rect,
2658
- scale,
2659
- onClick,
2660
- hasIRT = false
2661
- }) {
2662
- const { width, height } = useMemo(() => {
2663
- return {
2664
- width: rect.size.width,
2665
- height: rect.size.height
2666
- };
2667
- }, [rect]);
2668
- const svgWidth = width * scale;
2669
- const svgHeight = height * scale;
2670
- const dashArray = useMemo(() => {
2671
- if (strokeStyle === PdfAnnotationBorderStyle.DASHED) {
2672
- return (strokeDashArray == null ? void 0 : strokeDashArray.join(",")) ?? `${strokeWidth * 3},${strokeWidth}`;
2673
- }
2674
- return void 0;
2675
- }, [strokeStyle, strokeDashArray, strokeWidth]);
2676
- const isUnderline = strokeStyle === PdfAnnotationBorderStyle.UNDERLINE;
2677
- return /* @__PURE__ */ jsxs(
2678
- "svg",
2679
- {
2680
- style: {
2681
- position: "absolute",
2682
- width: svgWidth,
2683
- height: svgHeight,
2684
- pointerEvents: "none",
2685
- zIndex: 2
2686
- },
2687
- width: svgWidth,
2688
- height: svgHeight,
2689
- viewBox: `0 0 ${width} ${height}`,
2690
- children: [
2691
- /* @__PURE__ */ jsx(
2692
- "rect",
2693
- {
2694
- x: 0,
2695
- y: 0,
2696
- width,
2697
- height,
2698
- fill: "transparent",
2699
- onPointerDown: hasIRT ? void 0 : onClick,
2700
- style: {
2701
- cursor: hasIRT || !onClick ? "default" : isSelected ? "move" : "pointer",
2702
- pointerEvents: hasIRT || !onClick ? "none" : isSelected ? "none" : "visible"
2703
- }
2704
- }
2705
- ),
2706
- isUnderline ? (
2707
- // Underline style: line at bottom of rect
2708
- /* @__PURE__ */ jsx(
2709
- "line",
2710
- {
2711
- x1: 1,
2712
- y1: height - 1,
2713
- x2: width - 1,
2714
- y2: height - 1,
2715
- stroke: strokeColor,
2716
- strokeWidth,
2717
- strokeDasharray: dashArray,
2718
- style: {
2719
- pointerEvents: "none"
2720
- }
2721
- }
2722
- )
2723
- ) : (
2724
- // Solid/Dashed style: rectangle border
2725
- /* @__PURE__ */ jsx(
2726
- "rect",
2727
- {
2728
- x: strokeWidth / 2,
2729
- y: strokeWidth / 2,
2730
- width: Math.max(width - strokeWidth, 0),
2731
- height: Math.max(height - strokeWidth, 0),
2732
- fill: "transparent",
2733
- stroke: strokeColor,
2734
- strokeWidth,
2735
- strokeDasharray: dashArray,
2736
- style: {
2737
- pointerEvents: "none"
2738
- }
2739
- }
2740
- )
2741
- )
2742
- ]
2743
- }
2744
- );
2745
- }
2746
- function Highlight({
2747
- strokeColor,
2748
- opacity = 0.5,
2749
- segmentRects,
2750
- rect,
2751
- scale,
2752
- onClick,
2753
- style,
2754
- appearanceActive = false
2755
- }) {
2756
- const resolvedColor = strokeColor ?? "#FFFF00";
2757
- return /* @__PURE__ */ jsx(Fragment, { children: segmentRects.map((b, i) => /* @__PURE__ */ jsx(
2758
- "div",
2759
- {
2760
- onPointerDown: onClick,
2761
- style: {
2762
- position: "absolute",
2763
- left: (rect ? b.origin.x - rect.origin.x : b.origin.x) * scale,
2764
- top: (rect ? b.origin.y - rect.origin.y : b.origin.y) * scale,
2765
- width: b.size.width * scale,
2766
- height: b.size.height * scale,
2767
- background: appearanceActive ? "transparent" : resolvedColor,
2768
- opacity: appearanceActive ? void 0 : opacity,
2769
- pointerEvents: onClick ? "auto" : "none",
2770
- cursor: onClick ? "pointer" : "default",
2771
- zIndex: onClick ? 1 : void 0,
2772
- ...style
2773
- }
2774
- },
2775
- i
2776
- )) });
2777
- }
2778
- function Underline({
2779
- strokeColor,
2780
- opacity = 0.5,
2781
- segmentRects,
2782
- rect,
2783
- scale,
2784
- onClick,
2785
- style,
2786
- appearanceActive = false
2787
- }) {
2788
- const resolvedColor = strokeColor ?? "#FFFF00";
2789
- const thickness = 2 * scale;
2790
- return /* @__PURE__ */ jsx(Fragment, { children: segmentRects.map((r, i) => /* @__PURE__ */ jsx(
2791
- "div",
2792
- {
2793
- onPointerDown: onClick,
2794
- style: {
2795
- position: "absolute",
2796
- left: (rect ? r.origin.x - rect.origin.x : r.origin.x) * scale,
2797
- top: (rect ? r.origin.y - rect.origin.y : r.origin.y) * scale,
2798
- width: r.size.width * scale,
2799
- height: r.size.height * scale,
2800
- background: "transparent",
2801
- pointerEvents: onClick ? "auto" : "none",
2802
- cursor: onClick ? "pointer" : "default",
2803
- zIndex: onClick ? 1 : 0,
2804
- ...style
2805
- },
2806
- children: !appearanceActive && /* @__PURE__ */ jsx(
2807
- "div",
2808
- {
2809
- style: {
2810
- position: "absolute",
2811
- left: 0,
2812
- bottom: 0,
2813
- width: "100%",
2814
- height: thickness,
2815
- background: resolvedColor,
2816
- opacity,
2817
- pointerEvents: "none"
2818
- }
2819
- }
2820
- )
2821
- },
2822
- i
2823
- )) });
2824
- }
2825
- function Strikeout({
2826
- strokeColor,
2827
- opacity = 0.5,
2828
- segmentRects,
2829
- rect,
2830
- scale,
2831
- onClick,
2832
- style,
2833
- appearanceActive = false
2834
- }) {
2835
- const resolvedColor = strokeColor ?? "#FFFF00";
2836
- const thickness = 2 * scale;
2837
- return /* @__PURE__ */ jsx(Fragment, { children: segmentRects.map((r, i) => /* @__PURE__ */ jsx(
2838
- "div",
2839
- {
2840
- onPointerDown: onClick,
2841
- style: {
2842
- position: "absolute",
2843
- left: (rect ? r.origin.x - rect.origin.x : r.origin.x) * scale,
2844
- top: (rect ? r.origin.y - rect.origin.y : r.origin.y) * scale,
2845
- width: r.size.width * scale,
2846
- height: r.size.height * scale,
2847
- background: "transparent",
2848
- pointerEvents: onClick ? "auto" : "none",
2849
- cursor: onClick ? "pointer" : "default",
2850
- zIndex: onClick ? 1 : 0,
2851
- ...style
2852
- },
2853
- children: !appearanceActive && /* @__PURE__ */ jsx(
2854
- "div",
2855
- {
2856
- style: {
2857
- position: "absolute",
2858
- left: 0,
2859
- top: "50%",
2860
- width: "100%",
2861
- height: thickness,
2862
- background: resolvedColor,
2863
- opacity,
2864
- transform: "translateY(-50%)",
2865
- pointerEvents: "none"
2866
- }
2867
- }
2868
- )
2869
- },
2870
- i
2871
- )) });
2872
- }
2873
- function Squiggly({
2874
- strokeColor,
2875
- opacity = 0.5,
2876
- segmentRects,
2877
- rect,
2878
- scale,
2879
- onClick,
2880
- style,
2881
- appearanceActive = false
2882
- }) {
2883
- const resolvedColor = strokeColor ?? "#FFFF00";
2884
- const amplitude = 2 * scale;
2885
- const period = 6 * scale;
2886
- const svg = `<svg xmlns="http://www.w3.org/2000/svg" width="${period}" height="${amplitude * 2}" viewBox="0 0 ${period} ${amplitude * 2}">
2887
- <path d="M0 ${amplitude} Q ${period / 4} 0 ${period / 2} ${amplitude} T ${period} ${amplitude}"
2888
- fill="none" stroke="${resolvedColor}" stroke-width="${amplitude}" stroke-linecap="round"/>
2889
- </svg>`;
2890
- const svgDataUri = `url("data:image/svg+xml;utf8,${encodeURIComponent(svg)}")`;
2891
- return /* @__PURE__ */ jsx(Fragment, { children: segmentRects.map((r, i) => /* @__PURE__ */ jsx(
2892
- "div",
2893
- {
2894
- onPointerDown: onClick,
2895
- style: {
2896
- position: "absolute",
2897
- left: (rect ? r.origin.x - rect.origin.x : r.origin.x) * scale,
2898
- top: (rect ? r.origin.y - rect.origin.y : r.origin.y) * scale,
2899
- width: r.size.width * scale,
2900
- height: r.size.height * scale,
2901
- background: "transparent",
2902
- pointerEvents: onClick ? "auto" : "none",
2903
- cursor: onClick ? "pointer" : "default",
2904
- zIndex: onClick ? 1 : 0,
2905
- ...style
2906
- },
2907
- children: !appearanceActive && /* @__PURE__ */ jsx(
2908
- "div",
2909
- {
2910
- style: {
2911
- position: "absolute",
2912
- left: 0,
2913
- bottom: 0,
2914
- width: "100%",
2915
- height: amplitude * 2,
2916
- backgroundImage: svgDataUri,
2917
- backgroundRepeat: "repeat-x",
2918
- backgroundSize: `${period}px ${amplitude * 2}px`,
2919
- opacity,
2920
- pointerEvents: "none"
2921
- }
2922
- }
2923
- )
2924
- },
2925
- i
2926
- )) });
2927
- }
2928
- function Caret({
2929
- isSelected,
2930
- strokeColor = "#000000",
2931
- opacity = 1,
2932
- rect,
2933
- scale,
2934
- onClick,
2935
- appearanceActive = false
2936
- }) {
2937
- const { width, height, path } = useMemo(() => {
2938
- const w = rect.size.width;
2939
- const h = rect.size.height;
2940
- const midX = w / 2;
2941
- const d = [
2942
- `M 0 ${h}`,
2943
- `C ${w * 0.27} ${h} ${midX} ${h - h * 0.44} ${midX} 0`,
2944
- `C ${midX} ${h - h * 0.44} ${w - w * 0.27} ${h} ${w} ${h}`,
2945
- "Z"
2946
- ].join(" ");
2947
- return { width: w, height: h, path: d };
2948
- }, [rect]);
2949
- const svgWidth = width * scale;
2950
- const svgHeight = height * scale;
2951
- return /* @__PURE__ */ jsxs(
2952
- "svg",
2953
- {
2954
- style: {
2955
- position: "absolute",
2956
- width: svgWidth,
2957
- height: svgHeight,
2958
- pointerEvents: "none",
2959
- zIndex: 2
2960
- },
2961
- width: svgWidth,
2962
- height: svgHeight,
2963
- viewBox: `0 0 ${width} ${height}`,
2964
- overflow: "visible",
2965
- children: [
2966
- /* @__PURE__ */ jsx(
2967
- "path",
2968
- {
2969
- d: path,
2970
- fill: "transparent",
2971
- stroke: "transparent",
2972
- strokeWidth: 4,
2973
- onPointerDown: onClick,
2974
- style: {
2975
- cursor: isSelected ? "move" : onClick ? "pointer" : "default",
2976
- pointerEvents: !onClick ? "none" : isSelected ? "none" : "visible"
2977
- }
2978
- }
2979
- ),
2980
- !appearanceActive && /* @__PURE__ */ jsx(
2981
- "path",
2982
- {
2983
- d: path,
2984
- fill: strokeColor,
2985
- stroke: strokeColor,
2986
- strokeWidth: 0.5,
2987
- opacity,
2988
- fillRule: "evenodd",
2989
- style: { pointerEvents: "none" }
2990
- }
2991
- )
2992
- ]
2993
- }
2994
- );
2995
- }
2996
- function LinkLockedMode({
2997
- annotation,
2998
- documentId
2999
- }) {
3000
- const { provides } = useAnnotationCapability();
3001
- const handleClick = useCallback(() => {
3002
- const target = annotation.object.target;
3003
- if (!target || !provides) return;
3004
- provides.forDocument(documentId).navigateTarget(target);
3005
- }, [annotation.object.target, provides, documentId]);
3006
- return /* @__PURE__ */ jsx(
3007
- "div",
3008
- {
3009
- onClick: handleClick,
3010
- style: {
3011
- width: "100%",
3012
- height: "100%",
3013
- cursor: "pointer",
3014
- pointerEvents: "auto"
3015
- }
3016
- }
3017
- );
3018
- }
3019
- const builtInRenderers = [
3020
- // --- Drawing ---
3021
- createRenderer({
3022
- id: "ink",
3023
- matches: (a) => a.type === PdfAnnotationSubtype.INK,
3024
- matchesPreview: (p) => p.type === PdfAnnotationSubtype.INK,
3025
- render: ({ currentObject, isSelected, scale, onClick, appearanceActive }) => /* @__PURE__ */ jsx(
3026
- Ink,
3027
- {
3028
- ...currentObject,
3029
- isSelected,
3030
- scale,
3031
- onClick,
3032
- appearanceActive
3033
- }
3034
- ),
3035
- renderPreview: ({ data, scale }) => /* @__PURE__ */ jsx(Ink, { isSelected: false, scale, ...data }),
3036
- previewContainerStyle: ({ data }) => ({
3037
- mixBlendMode: blendModeToCss(data.blendMode ?? PdfBlendMode.Normal)
3038
- }),
3039
- interactionDefaults: { isDraggable: true, isResizable: true, isRotatable: true }
3040
- }),
3041
- // --- Shapes ---
3042
- createRenderer({
3043
- id: "square",
3044
- matches: (a) => a.type === PdfAnnotationSubtype.SQUARE,
3045
- matchesPreview: (p) => p.type === PdfAnnotationSubtype.SQUARE,
3046
- render: ({ currentObject, isSelected, scale, onClick, appearanceActive }) => /* @__PURE__ */ jsx(
3047
- Square,
3048
- {
3049
- ...currentObject,
3050
- isSelected,
3051
- scale,
3052
- onClick,
3053
- appearanceActive
3054
- }
3055
- ),
3056
- renderPreview: ({ data, scale }) => /* @__PURE__ */ jsx(Square, { isSelected: false, scale, ...data }),
3057
- interactionDefaults: { isDraggable: true, isResizable: true, isRotatable: true }
3058
- }),
3059
- createRenderer({
3060
- id: "circle",
3061
- matches: (a) => a.type === PdfAnnotationSubtype.CIRCLE,
3062
- matchesPreview: (p) => p.type === PdfAnnotationSubtype.CIRCLE,
3063
- render: ({ currentObject, isSelected, scale, onClick, appearanceActive }) => /* @__PURE__ */ jsx(
3064
- Circle,
3065
- {
3066
- ...currentObject,
3067
- isSelected,
3068
- scale,
3069
- onClick,
3070
- appearanceActive
3071
- }
3072
- ),
3073
- renderPreview: ({ data, scale }) => /* @__PURE__ */ jsx(Circle, { isSelected: false, scale, ...data }),
3074
- interactionDefaults: { isDraggable: true, isResizable: true, isRotatable: true }
3075
- }),
3076
- // --- Lines & Vertex-based ---
3077
- createRenderer({
3078
- id: "line",
3079
- matches: (a) => a.type === PdfAnnotationSubtype.LINE,
3080
- matchesPreview: (p) => p.type === PdfAnnotationSubtype.LINE,
3081
- render: ({ currentObject, isSelected, scale, onClick, appearanceActive }) => /* @__PURE__ */ jsx(Fragment$1, { children: /* @__PURE__ */ jsx(
3082
- Line,
3083
- {
3084
- ...currentObject,
3085
- isSelected,
3086
- scale,
3087
- onClick,
3088
- appearanceActive
3089
- }
3090
- ) }),
3091
- renderPreview: ({ data, scale }) => /* @__PURE__ */ jsx(Line, { isSelected: false, scale, ...data }),
3092
- vertexConfig: {
3093
- extractVertices: (a) => [a.linePoints.start, a.linePoints.end],
3094
- transformAnnotation: (a, v) => ({
3095
- ...a,
3096
- linePoints: { start: v[0], end: v[1] }
3097
- })
3098
- },
3099
- interactionDefaults: { isDraggable: true, isResizable: false, isRotatable: true }
3100
- }),
3101
- createRenderer({
3102
- id: "polyline",
3103
- matches: (a) => a.type === PdfAnnotationSubtype.POLYLINE,
3104
- matchesPreview: (p) => p.type === PdfAnnotationSubtype.POLYLINE,
3105
- render: ({ currentObject, isSelected, scale, onClick, appearanceActive }) => /* @__PURE__ */ jsx(Fragment$1, { children: /* @__PURE__ */ jsx(
3106
- Polyline,
3107
- {
3108
- ...currentObject,
3109
- isSelected,
3110
- scale,
3111
- onClick,
3112
- appearanceActive
3113
- }
3114
- ) }),
3115
- renderPreview: ({ data, scale }) => /* @__PURE__ */ jsx(Polyline, { isSelected: false, scale, ...data }),
3116
- vertexConfig: {
3117
- extractVertices: (a) => a.vertices,
3118
- transformAnnotation: (a, vertices) => ({ ...a, vertices })
3119
- },
3120
- interactionDefaults: { isDraggable: true, isResizable: false, isRotatable: true }
3121
- }),
3122
- createRenderer({
3123
- id: "polygon",
3124
- matches: (a) => a.type === PdfAnnotationSubtype.POLYGON,
3125
- matchesPreview: (p) => p.type === PdfAnnotationSubtype.POLYGON,
3126
- render: ({ currentObject, isSelected, scale, onClick, appearanceActive }) => /* @__PURE__ */ jsx(Fragment$1, { children: /* @__PURE__ */ jsx(
3127
- Polygon,
3128
- {
3129
- ...currentObject,
3130
- isSelected,
3131
- scale,
3132
- onClick,
3133
- appearanceActive
3134
- }
3135
- ) }),
3136
- renderPreview: ({ data, scale }) => /* @__PURE__ */ jsx(Polygon, { isSelected: false, scale, ...data }),
3137
- vertexConfig: {
3138
- extractVertices: (a) => a.vertices,
3139
- transformAnnotation: (a, vertices) => ({ ...a, vertices })
3140
- },
3141
- interactionDefaults: { isDraggable: true, isResizable: false, isRotatable: true }
3142
- }),
3143
- // --- Text Markup ---
3144
- createRenderer({
3145
- id: "highlight",
3146
- matches: (a) => a.type === PdfAnnotationSubtype.HIGHLIGHT,
3147
- render: ({ currentObject, scale, onClick, appearanceActive }) => /* @__PURE__ */ jsx(
3148
- Highlight,
3149
- {
3150
- ...currentObject,
3151
- scale,
3152
- onClick,
3153
- appearanceActive
3154
- }
3155
- ),
3156
- zIndex: 0,
3157
- interactionDefaults: { isDraggable: false, isResizable: false, isRotatable: false },
3158
- defaultBlendMode: PdfBlendMode.Multiply
3159
- }),
3160
- createRenderer({
3161
- id: "underline",
3162
- matches: (a) => a.type === PdfAnnotationSubtype.UNDERLINE,
3163
- render: ({ currentObject, scale, onClick, appearanceActive }) => /* @__PURE__ */ jsx(
3164
- Underline,
3165
- {
3166
- ...currentObject,
3167
- scale,
3168
- onClick,
3169
- appearanceActive
3170
- }
3171
- ),
3172
- zIndex: 0,
3173
- interactionDefaults: { isDraggable: false, isResizable: false, isRotatable: false }
3174
- }),
3175
- createRenderer({
3176
- id: "strikeout",
3177
- matches: (a) => a.type === PdfAnnotationSubtype.STRIKEOUT,
3178
- render: ({ currentObject, scale, onClick, appearanceActive }) => /* @__PURE__ */ jsx(
3179
- Strikeout,
3180
- {
3181
- ...currentObject,
3182
- scale,
3183
- onClick,
3184
- appearanceActive
3185
- }
3186
- ),
3187
- zIndex: 0,
3188
- interactionDefaults: { isDraggable: false, isResizable: false, isRotatable: false }
3189
- }),
3190
- createRenderer({
3191
- id: "squiggly",
3192
- matches: (a) => a.type === PdfAnnotationSubtype.SQUIGGLY,
3193
- render: ({ currentObject, scale, onClick, appearanceActive }) => /* @__PURE__ */ jsx(
3194
- Squiggly,
3195
- {
3196
- ...currentObject,
3197
- scale,
3198
- onClick,
3199
- appearanceActive
3200
- }
3201
- ),
3202
- zIndex: 0,
3203
- interactionDefaults: { isDraggable: false, isResizable: false, isRotatable: false }
3204
- }),
3205
- // --- Text Comment ---
3206
- createRenderer({
3207
- id: "text",
3208
- matches: (a) => a.type === PdfAnnotationSubtype.TEXT && !a.inReplyToId,
3209
- render: ({ currentObject, isSelected, onClick, appearanceActive }) => /* @__PURE__ */ jsx(
3210
- Text,
3211
- {
3212
- isSelected,
3213
- color: currentObject.strokeColor ?? currentObject.color,
3214
- opacity: currentObject.opacity,
3215
- onClick,
3216
- appearanceActive
3217
- }
3218
- ),
3219
- interactionDefaults: { isDraggable: true, isResizable: false, isRotatable: false }
3220
- }),
3221
- // --- Caret ---
3222
- createRenderer({
3223
- id: "caret",
3224
- matches: (a) => a.type === PdfAnnotationSubtype.CARET,
3225
- render: ({ currentObject, isSelected, scale, onClick, appearanceActive }) => /* @__PURE__ */ jsx(
3226
- Caret,
3227
- {
3228
- ...currentObject,
3229
- isSelected,
3230
- scale,
3231
- onClick,
3232
- appearanceActive
3233
- }
3234
- ),
3235
- interactionDefaults: { isDraggable: false, isResizable: false, isRotatable: false }
3236
- }),
3237
- // --- Callout FreeText (must appear before regular FreeText to match first) ---
3238
- createRenderer({
3239
- id: "freeTextCallout",
3240
- matches: (a) => a.type === PdfAnnotationSubtype.FREETEXT && a.intent === "FreeTextCallout",
3241
- matchesPreview: (p) => p.type === PdfAnnotationSubtype.FREETEXT && !!p.data.calloutLine,
3242
- render: ({
3243
- annotation,
3244
- currentObject,
3245
- isSelected,
3246
- isEditing,
3247
- scale,
3248
- pageIndex,
3249
- documentId,
3250
- onClick,
3251
- appearanceActive
3252
- }) => /* @__PURE__ */ jsx(
3253
- CalloutFreeText,
3254
- {
3255
- documentId,
3256
- isSelected,
3257
- isEditing,
3258
- annotation: { ...annotation, object: currentObject },
3259
- pageIndex,
3260
- scale,
3261
- onClick,
3262
- appearanceActive
3263
- }
3264
- ),
3265
- renderPreview: ({ data, bounds, scale }) => /* @__PURE__ */ jsx(
3266
- CalloutFreeTextPreview,
3267
- {
3268
- calloutLine: data.calloutLine,
3269
- textBox: data.textBox,
3270
- bounds,
3271
- scale,
3272
- strokeColor: data.strokeColor,
3273
- strokeWidth: data.strokeWidth,
3274
- color: data.color,
3275
- backgroundColor: data.backgroundColor,
3276
- opacity: data.opacity,
3277
- lineEnding: data.lineEnding
3278
- }
3279
- ),
3280
- vertexConfig: patching.calloutVertexConfig,
3281
- interactionDefaults: { isDraggable: true, isResizable: false, isRotatable: false },
3282
- isDraggable: (toolDraggable, { isEditing }) => toolDraggable && !isEditing,
3283
- onDoubleClick: (id, setEditingId) => setEditingId(id)
3284
- }),
3285
- // --- FreeText ---
3286
- createRenderer({
3287
- id: "freeText",
3288
- matches: (a) => a.type === PdfAnnotationSubtype.FREETEXT && a.intent !== "FreeTextCallout",
3289
- matchesPreview: (p) => p.type === PdfAnnotationSubtype.FREETEXT && !p.data.calloutLine,
3290
- render: ({
3291
- annotation,
3292
- currentObject,
3293
- isSelected,
3294
- isEditing,
3295
- scale,
3296
- pageIndex,
3297
- documentId,
3298
- onClick,
3299
- appearanceActive
3300
- }) => /* @__PURE__ */ jsx(
3301
- FreeText,
3302
- {
3303
- documentId,
3304
- isSelected,
3305
- isEditing,
3306
- annotation: { ...annotation, object: currentObject },
3307
- pageIndex,
3308
- scale,
3309
- onClick,
3310
- appearanceActive
3311
- }
3312
- ),
3313
- renderPreview: ({ data }) => /* @__PURE__ */ jsx(
3314
- "div",
3315
- {
3316
- style: {
3317
- width: "100%",
3318
- height: "100%",
3319
- border: `1px dashed ${data.fontColor || "#000000"}`,
3320
- backgroundColor: "transparent"
3321
- }
3322
- }
3323
- ),
3324
- interactionDefaults: { isDraggable: true, isResizable: true, isRotatable: true },
3325
- isDraggable: (toolDraggable, { isEditing }) => toolDraggable && !isEditing,
3326
- onDoubleClick: (id, setEditingId) => setEditingId(id)
3327
- }),
3328
- // --- Stamp ---
3329
- createRenderer({
3330
- id: "stamp",
3331
- matches: (a) => a.type === PdfAnnotationSubtype.STAMP,
3332
- matchesPreview: (p) => p.type === PdfAnnotationSubtype.STAMP,
3333
- render: ({ annotation, isSelected, documentId, pageIndex, scale, onClick }) => /* @__PURE__ */ jsx(
3334
- Stamp,
3335
- {
3336
- isSelected,
3337
- annotation,
3338
- documentId,
3339
- pageIndex,
3340
- scale,
3341
- onClick
3342
- }
3343
- ),
3344
- renderPreview: ({ data }) => {
3345
- const rotationDeg = (4 - data.pageRotation) % 4 * 90;
3346
- return /* @__PURE__ */ jsx(
3347
- "img",
3348
- {
3349
- src: data.ghostUrl,
3350
- style: {
3351
- width: "100%",
3352
- height: "100%",
3353
- opacity: 0.6,
3354
- objectFit: "contain",
3355
- pointerEvents: "none",
3356
- transform: rotationDeg ? `rotate(${rotationDeg}deg)` : void 0
3357
- },
3358
- alt: ""
3359
- }
3360
- );
3361
- },
3362
- useAppearanceStream: false,
3363
- interactionDefaults: { isDraggable: true, isResizable: true, isRotatable: true }
3364
- }),
3365
- // --- Link ---
3366
- createRenderer({
3367
- id: "link",
3368
- matches: (a) => a.type === PdfAnnotationSubtype.LINK,
3369
- matchesPreview: (p) => p.type === PdfAnnotationSubtype.LINK,
3370
- render: ({ currentObject, isSelected, scale, onClick }) => /* @__PURE__ */ jsx(
3371
- Link,
3372
- {
3373
- ...currentObject,
3374
- isSelected,
3375
- scale,
3376
- onClick,
3377
- hasIRT: !!currentObject.inReplyToId
3378
- }
3379
- ),
3380
- renderPreview: ({ data, bounds, scale }) => /* @__PURE__ */ jsx(
3381
- "div",
3382
- {
3383
- style: {
3384
- position: "absolute",
3385
- left: 0,
3386
- top: 0,
3387
- width: bounds.size.width * scale,
3388
- height: bounds.size.height * scale,
3389
- borderBottom: `${data.strokeWidth * scale}px solid ${data.strokeColor}`,
3390
- backgroundColor: "rgba(0, 0, 255, 0.05)",
3391
- boxSizing: "border-box"
3392
- }
3393
- }
3394
- ),
3395
- interactionDefaults: {
3396
- isDraggable: true,
3397
- isResizable: true,
3398
- isRotatable: false
3399
- },
3400
- useAppearanceStream: false,
3401
- selectOverride: (e, annotation, helpers) => {
3402
- e.stopPropagation();
3403
- helpers.clearSelection();
3404
- if (annotation.object.inReplyToId) {
3405
- const parent = helpers.allAnnotations.find(
3406
- (a) => a.object.id === annotation.object.inReplyToId
3407
- );
3408
- if (parent) {
3409
- helpers.selectAnnotation(parent.object.pageIndex, parent.object.id);
3410
- return;
3411
- }
3412
- }
3413
- helpers.selectAnnotation(helpers.pageIndex, annotation.object.id);
3414
- },
3415
- hideSelectionMenu: (a) => !!a.inReplyToId,
3416
- renderLocked: (props) => /* @__PURE__ */ jsx(LinkLockedMode, { ...props })
3417
- })
3418
- ];
3419
- function Annotations(annotationsProps) {
3420
- const { documentId, pageIndex, scale, pageWidth, pageHeight, selectionMenu } = annotationsProps;
3421
- const { provides: annotationCapability } = useAnnotationCapability();
3422
- const { provides: selectionProvides } = useSelectionCapability();
3423
- const [annotations, setAnnotations] = useState([]);
3424
- const { register } = usePointerHandlers({ documentId, pageIndex });
3425
- const [allSelectedIds, setAllSelectedIds] = useState([]);
3426
- const [editingId, setEditingId] = useState(null);
3427
- const [appearanceMap, setAppearanceMap] = useState({});
3428
- const [, setLockedMode] = useState({ type: LockModeType.None });
3429
- const prevScaleRef = useRef(scale);
3430
- const annotationProvides = useMemo(
3431
- () => annotationCapability ? annotationCapability.forDocument(documentId) : null,
3432
- [annotationCapability, documentId]
3433
- );
3434
- const isMultiSelected = allSelectedIds.length > 1;
3435
- useEffect(() => {
3436
- if (annotationProvides) {
3437
- const currentState = annotationProvides.getState();
3438
- setAnnotations(getAnnotationsByPageIndex(currentState, pageIndex));
3439
- setAllSelectedIds(getSelectedAnnotationIds(currentState));
3440
- setLockedMode(currentState.locked);
3441
- return annotationProvides.onStateChange((state) => {
3442
- setAnnotations(getAnnotationsByPageIndex(state, pageIndex));
3443
- setAllSelectedIds(getSelectedAnnotationIds(state));
3444
- setLockedMode(state.locked);
3445
- });
3446
- }
3447
- }, [annotationProvides, pageIndex]);
3448
- useEffect(() => {
3449
- if (!annotationProvides) return;
3450
- return annotationProvides.onAnnotationEvent((event) => {
3451
- if (event.type === "create" && event.editAfterCreate) {
3452
- setEditingId(event.annotation.id);
3453
- }
3454
- });
3455
- }, [annotationProvides]);
3456
- useEffect(() => {
3457
- if (!annotationProvides) return;
3458
- if (prevScaleRef.current !== scale) {
3459
- annotationProvides.invalidatePageAppearances(pageIndex);
3460
- prevScaleRef.current = scale;
3461
- }
3462
- const task = annotationProvides.getPageAppearances(pageIndex, {
3463
- scaleFactor: scale,
3464
- dpr: typeof window !== "undefined" ? window.devicePixelRatio : 1
3465
- });
3466
- task.wait(
3467
- (map) => setAppearanceMap(map),
3468
- () => setAppearanceMap({})
3469
- );
3470
- }, [annotationProvides, pageIndex, scale]);
3471
- const handlers = useMemo(
3472
- () => ({
3473
- onPointerDown: (_, pe) => {
3474
- if (pe.target === pe.currentTarget && annotationProvides) {
3475
- if (editingId && annotations.some((a) => a.object.id === editingId)) {
3476
- pe.stopImmediatePropagation();
3477
- }
3478
- annotationProvides.deselectAnnotation();
3479
- setEditingId(null);
3480
- }
3481
- }
3482
- }),
3483
- [annotationProvides, editingId, annotations]
3484
- );
3485
- const handleClick = useCallback(
3486
- (e, annotation) => {
3487
- e.stopPropagation();
3488
- if (annotationProvides && selectionProvides) {
3489
- selectionProvides.clear();
3490
- const isModifierPressed = "metaKey" in e ? e.metaKey || e.ctrlKey : false;
3491
- if (isModifierPressed) {
3492
- annotationProvides.toggleSelection(pageIndex, annotation.object.id);
3493
- } else {
3494
- annotationProvides.selectAnnotation(pageIndex, annotation.object.id);
3495
- }
3496
- if (annotation.object.id !== editingId) {
3497
- setEditingId(null);
3498
- }
3499
- }
3500
- },
3501
- [annotationProvides, selectionProvides, editingId, pageIndex]
3502
- );
3503
- useEffect(() => {
3504
- return register(handlers, {
3505
- documentId
3506
- });
3507
- }, [register, handlers]);
3508
- const selectedAnnotationsOnPage = useMemo(() => {
3509
- return annotations.filter((anno) => allSelectedIds.includes(anno.object.id));
3510
- }, [annotations, allSelectedIds]);
3511
- const areAllSelectedDraggable = useMemo(() => {
3512
- if (selectedAnnotationsOnPage.length < 2) return false;
3513
- return selectedAnnotationsOnPage.every((ta) => {
3514
- const tool = annotationProvides == null ? void 0 : annotationProvides.findToolForAnnotation(ta.object);
3515
- const groupDraggable = resolveInteractionProp(
3516
- tool == null ? void 0 : tool.interaction.isGroupDraggable,
3517
- ta.object,
3518
- true
3519
- );
3520
- const singleDraggable = resolveInteractionProp(
3521
- tool == null ? void 0 : tool.interaction.isDraggable,
3522
- ta.object,
3523
- true
3524
- );
3525
- return (tool == null ? void 0 : tool.interaction.isGroupDraggable) !== void 0 ? groupDraggable : singleDraggable;
3526
- });
3527
- }, [selectedAnnotationsOnPage, annotationProvides]);
3528
- const areAllSelectedResizable = useMemo(() => {
3529
- if (selectedAnnotationsOnPage.length < 2) return false;
3530
- return selectedAnnotationsOnPage.every((ta) => {
3531
- const tool = annotationProvides == null ? void 0 : annotationProvides.findToolForAnnotation(ta.object);
3532
- const groupResizable = resolveInteractionProp(
3533
- tool == null ? void 0 : tool.interaction.isGroupResizable,
3534
- ta.object,
3535
- true
3536
- );
3537
- const singleResizable = resolveInteractionProp(
3538
- tool == null ? void 0 : tool.interaction.isResizable,
3539
- ta.object,
3540
- true
3541
- );
3542
- return (tool == null ? void 0 : tool.interaction.isGroupResizable) !== void 0 ? groupResizable : singleResizable;
3543
- });
3544
- }, [selectedAnnotationsOnPage, annotationProvides]);
3545
- const areAllSelectedRotatable = useMemo(() => {
3546
- if (selectedAnnotationsOnPage.length < 2) return false;
3547
- return selectedAnnotationsOnPage.every((ta) => {
3548
- const tool = annotationProvides == null ? void 0 : annotationProvides.findToolForAnnotation(ta.object);
3549
- const groupRotatable = resolveInteractionProp(
3550
- tool == null ? void 0 : tool.interaction.isGroupRotatable,
3551
- ta.object,
3552
- true
3553
- );
3554
- const singleRotatable = resolveInteractionProp(
3555
- tool == null ? void 0 : tool.interaction.isRotatable,
3556
- ta.object,
3557
- true
3558
- );
3559
- return (tool == null ? void 0 : tool.interaction.isGroupRotatable) !== void 0 ? groupRotatable : singleRotatable;
3560
- });
3561
- }, [selectedAnnotationsOnPage, annotationProvides]);
3562
- const shouldLockGroupAspectRatio = useMemo(() => {
3563
- if (selectedAnnotationsOnPage.length < 2) return false;
3564
- return selectedAnnotationsOnPage.some((ta) => {
3565
- const tool = annotationProvides == null ? void 0 : annotationProvides.findToolForAnnotation(ta.object);
3566
- const groupLock = resolveInteractionProp(
3567
- tool == null ? void 0 : tool.interaction.lockGroupAspectRatio,
3568
- ta.object,
3569
- false
3570
- );
3571
- const singleLock = resolveInteractionProp(
3572
- tool == null ? void 0 : tool.interaction.lockAspectRatio,
3573
- ta.object,
3574
- false
3575
- );
3576
- return (tool == null ? void 0 : tool.interaction.lockGroupAspectRatio) !== void 0 ? groupLock : singleLock;
3577
- });
3578
- }, [selectedAnnotationsOnPage, annotationProvides]);
3579
- const allSelectedOnSamePage = useMemo(() => {
3580
- if (!annotationProvides) return false;
3581
- const allSelected = annotationProvides.getSelectedAnnotations();
3582
- return allSelected.length > 1 && allSelected.every((ta) => ta.object.pageIndex === pageIndex);
3583
- }, [annotationProvides, pageIndex, allSelectedIds]);
3584
- const getAppearanceForAnnotation = useCallback(
3585
- (ta) => {
3586
- if (ta.dictMode) return null;
3587
- if (ta.object.rotation && ta.object.unrotatedRect) return null;
3588
- const appearances = appearanceMap[ta.object.id];
3589
- if (!(appearances == null ? void 0 : appearances.normal)) return null;
3590
- return appearances;
3591
- },
3592
- [appearanceMap]
3593
- );
3594
- const allRenderers = useMemo(() => {
3595
- const external = annotationsProps.annotationRenderers ?? [];
3596
- const externalIds = new Set(external.map((r) => r.id));
3597
- return [...external, ...builtInRenderers.filter((r) => !externalIds.has(r.id))];
3598
- }, [annotationsProps.annotationRenderers]);
3599
- const resolveRenderer = useCallback(
3600
- (annotation) => allRenderers.find((r) => r.matches(annotation.object)) ?? null,
3601
- [allRenderers]
3602
- );
3603
- const selectHelpers = useMemo(
3604
- () => ({
3605
- defaultSelect: handleClick,
3606
- selectAnnotation: (pi, id) => annotationProvides == null ? void 0 : annotationProvides.selectAnnotation(pi, id),
3607
- clearSelection: () => selectionProvides == null ? void 0 : selectionProvides.clear(),
3608
- allAnnotations: annotations,
3609
- pageIndex
3610
- }),
3611
- [handleClick, annotationProvides, selectionProvides, annotations, pageIndex]
3612
- );
3613
- return /* @__PURE__ */ jsxs(Fragment, { children: [
3614
- annotations.map((annotation) => {
3615
- var _a, _b, _c;
3616
- const renderer = resolveRenderer(annotation);
3617
- if (!renderer) return null;
3618
- if (hasNoViewFlag(annotation.object)) return null;
3619
- if (hasHiddenFlag(annotation.object)) return null;
3620
- const tool = (annotationProvides == null ? void 0 : annotationProvides.findToolForAnnotation(annotation.object)) ?? null;
3621
- const nonInteractive = annotationProvides ? !annotationProvides.isAnnotationInteractive(annotation.object) : false;
3622
- const structurallyLocked = annotationProvides ? annotationProvides.isAnnotationStructurallyLocked(annotation.object) : false;
3623
- const contentLocked = annotationProvides ? annotationProvides.isAnnotationContentLocked(annotation.object) : false;
3624
- if (nonInteractive && renderer.hiddenWhenLocked) return null;
3625
- const hasRenderLocked = nonInteractive && !!renderer.renderLocked;
3626
- const isSelected = nonInteractive ? false : allSelectedIds.includes(annotation.object.id);
3627
- const isEditing = nonInteractive ? false : editingId === annotation.object.id;
3628
- const defaults = renderer.interactionDefaults;
3629
- const resolvedDraggable = resolveInteractionProp(
3630
- tool == null ? void 0 : tool.interaction.isDraggable,
3631
- annotation.object,
3632
- (defaults == null ? void 0 : defaults.isDraggable) ?? true
3633
- );
3634
- const finalDraggable = structurallyLocked ? false : renderer.isDraggable ? renderer.isDraggable(resolvedDraggable, { isEditing }) : resolvedDraggable;
3635
- const useAP = ((_a = tool == null ? void 0 : tool.behavior) == null ? void 0 : _a.useAppearanceStream) ?? renderer.useAppearanceStream ?? true;
3636
- const appearance = hasRenderLocked ? void 0 : useAP ? getAppearanceForAnnotation(annotation) : void 0;
3637
- const noopSelect = (e) => {
3638
- e.stopPropagation();
3639
- };
3640
- const onSelect = nonInteractive ? noopSelect : renderer.selectOverride ? (e) => renderer.selectOverride(e, annotation, selectHelpers) : (e) => handleClick(e, annotation);
3641
- return /* @__PURE__ */ jsx(
3642
- AnnotationContainer,
3643
- {
3644
- trackedAnnotation: annotation,
3645
- isSelected,
3646
- isEditing,
3647
- isMultiSelected: nonInteractive ? false : isMultiSelected,
3648
- isDraggable: finalDraggable,
3649
- isResizable: structurallyLocked ? false : resolveInteractionProp(
3650
- tool == null ? void 0 : tool.interaction.isResizable,
3651
- annotation.object,
3652
- (defaults == null ? void 0 : defaults.isResizable) ?? false
3653
- ),
3654
- lockAspectRatio: resolveInteractionProp(
3655
- tool == null ? void 0 : tool.interaction.lockAspectRatio,
3656
- annotation.object,
3657
- (defaults == null ? void 0 : defaults.lockAspectRatio) ?? false
3658
- ),
3659
- isRotatable: structurallyLocked ? false : resolveInteractionProp(
3660
- tool == null ? void 0 : tool.interaction.isRotatable,
3661
- annotation.object,
3662
- (defaults == null ? void 0 : defaults.isRotatable) ?? false
3663
- ),
3664
- vertexConfig: structurallyLocked ? void 0 : renderer.vertexConfig,
3665
- selectionMenu: nonInteractive ? void 0 : ((_b = renderer.hideSelectionMenu) == null ? void 0 : _b.call(renderer, annotation.object)) ? void 0 : selectionMenu,
3666
- structurallyLocked,
3667
- contentLocked,
3668
- onSelect,
3669
- onDoubleClick: nonInteractive || contentLocked ? void 0 : renderer.onDoubleClick ? (e) => {
3670
- e.stopPropagation();
3671
- renderer.onDoubleClick(annotation.object.id, setEditingId);
3672
- } : void 0,
3673
- zIndex: renderer.zIndex,
3674
- blendMode: blendModeToCss(
3675
- annotation.object.blendMode ?? renderer.defaultBlendMode ?? PdfBlendMode.Normal
3676
- ),
3677
- style: (_c = renderer.containerStyle) == null ? void 0 : _c.call(renderer, annotation.object),
3678
- appearance,
3679
- ...annotationsProps,
3680
- children: (currentObject, { appearanceActive }) => {
3681
- if (hasRenderLocked) {
3682
- return renderer.renderLocked({
3683
- annotation,
3684
- currentObject,
3685
- isSelected: false,
3686
- isEditing: false,
3687
- scale,
3688
- pageIndex,
3689
- documentId,
3690
- onClick: void 0,
3691
- appearanceActive
3692
- });
3693
- }
3694
- return renderer.render({
3695
- annotation,
3696
- currentObject,
3697
- isSelected,
3698
- isEditing,
3699
- scale,
3700
- pageIndex,
3701
- documentId,
3702
- onClick: nonInteractive ? void 0 : onSelect,
3703
- appearanceActive
3704
- });
3705
- }
3706
- },
3707
- annotation.object.id
3708
- );
3709
- }),
3710
- allSelectedOnSamePage && selectedAnnotationsOnPage.length >= 2 && /* @__PURE__ */ jsx(
3711
- GroupSelectionBox,
3712
- {
3713
- documentId,
3714
- pageIndex,
3715
- scale,
3716
- rotation: annotationsProps.rotation,
3717
- pageWidth,
3718
- pageHeight,
3719
- selectedAnnotations: selectedAnnotationsOnPage,
3720
- isDraggable: areAllSelectedDraggable,
3721
- isResizable: areAllSelectedResizable,
3722
- isRotatable: areAllSelectedRotatable,
3723
- lockAspectRatio: shouldLockGroupAspectRatio,
3724
- resizeUI: annotationsProps.resizeUI,
3725
- rotationUI: annotationsProps.rotationUI,
3726
- selectionOutlineColor: annotationsProps.selectionOutlineColor,
3727
- selectionOutline: annotationsProps.groupSelectionOutline ?? annotationsProps.selectionOutline,
3728
- groupSelectionMenu: annotationsProps.groupSelectionMenu
3729
- }
3730
- )
3731
- ] });
3732
- }
3733
- function TextMarkup({ documentId, pageIndex, scale }) {
3734
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
3735
- const { provides: selectionProvides } = useSelectionCapability();
3736
- const { provides: annotationProvides } = useAnnotationCapability();
3737
- const [rects, setRects] = useState([]);
3738
- const [boundingRect, setBoundingRect] = useState(null);
3739
- const [activeTool, setActiveTool] = useState(null);
3740
- useEffect(() => {
3741
- if (!selectionProvides) return;
3742
- return selectionProvides.forDocument(documentId).onSelectionChange(() => {
3743
- setRects(selectionProvides.forDocument(documentId).getHighlightRectsForPage(pageIndex));
3744
- setBoundingRect(selectionProvides.forDocument(documentId).getBoundingRectForPage(pageIndex));
3745
- });
3746
- }, [selectionProvides, documentId, pageIndex]);
3747
- useEffect(() => {
3748
- if (!annotationProvides) return;
3749
- setActiveTool(annotationProvides.forDocument(documentId).getActiveTool());
3750
- return annotationProvides.forDocument(documentId).onActiveToolChange((event) => setActiveTool(event));
3751
- }, [annotationProvides, documentId]);
3752
- if (!boundingRect) return null;
3753
- if (!activeTool || !activeTool.defaults) return null;
3754
- switch (activeTool.defaults.type) {
3755
- case PdfAnnotationSubtype.UNDERLINE:
3756
- return /* @__PURE__ */ jsx(
3757
- "div",
3758
- {
3759
- style: {
3760
- mixBlendMode: blendModeToCss(((_a = activeTool.defaults) == null ? void 0 : _a.blendMode) ?? PdfBlendMode.Normal),
3761
- pointerEvents: "none",
3762
- position: "absolute",
3763
- inset: 0
3764
- },
3765
- children: /* @__PURE__ */ jsx(
3766
- Underline,
3767
- {
3768
- strokeColor: (_b = activeTool.defaults) == null ? void 0 : _b.strokeColor,
3769
- opacity: (_c = activeTool.defaults) == null ? void 0 : _c.opacity,
3770
- segmentRects: rects,
3771
- scale
3772
- }
3773
- )
3774
- }
3775
- );
3776
- case PdfAnnotationSubtype.HIGHLIGHT:
3777
- return /* @__PURE__ */ jsx(
3778
- "div",
3779
- {
3780
- style: {
3781
- mixBlendMode: blendModeToCss(((_d = activeTool.defaults) == null ? void 0 : _d.blendMode) ?? PdfBlendMode.Multiply),
3782
- pointerEvents: "none",
3783
- position: "absolute",
3784
- inset: 0
3785
- },
3786
- children: /* @__PURE__ */ jsx(
3787
- Highlight,
3788
- {
3789
- strokeColor: (_e = activeTool.defaults) == null ? void 0 : _e.strokeColor,
3790
- opacity: (_f = activeTool.defaults) == null ? void 0 : _f.opacity,
3791
- segmentRects: rects,
3792
- scale
3793
- }
3794
- )
3795
- }
3796
- );
3797
- case PdfAnnotationSubtype.STRIKEOUT:
3798
- return /* @__PURE__ */ jsx(
3799
- "div",
3800
- {
3801
- style: {
3802
- mixBlendMode: blendModeToCss(((_g = activeTool.defaults) == null ? void 0 : _g.blendMode) ?? PdfBlendMode.Normal),
3803
- pointerEvents: "none",
3804
- position: "absolute",
3805
- inset: 0
3806
- },
3807
- children: /* @__PURE__ */ jsx(
3808
- Strikeout,
3809
- {
3810
- strokeColor: (_h = activeTool.defaults) == null ? void 0 : _h.strokeColor,
3811
- opacity: (_i = activeTool.defaults) == null ? void 0 : _i.opacity,
3812
- segmentRects: rects,
3813
- scale
3814
- }
3815
- )
3816
- }
3817
- );
3818
- case PdfAnnotationSubtype.SQUIGGLY:
3819
- return /* @__PURE__ */ jsx(
3820
- "div",
3821
- {
3822
- style: {
3823
- mixBlendMode: blendModeToCss(((_j = activeTool.defaults) == null ? void 0 : _j.blendMode) ?? PdfBlendMode.Normal),
3824
- pointerEvents: "none",
3825
- position: "absolute",
3826
- inset: 0
3827
- },
3828
- children: /* @__PURE__ */ jsx(
3829
- Squiggly,
3830
- {
3831
- strokeColor: (_k = activeTool.defaults) == null ? void 0 : _k.strokeColor,
3832
- opacity: (_l = activeTool.defaults) == null ? void 0 : _l.opacity,
3833
- segmentRects: rects,
3834
- scale
3835
- }
3836
- )
3837
- }
3838
- );
3839
- case PdfAnnotationSubtype.CARET:
3840
- return null;
3841
- default:
3842
- return null;
3843
- }
3844
- }
3845
- function PreviewRenderer({ toolId, preview, scale }) {
3846
- var _a;
3847
- const { bounds } = preview;
3848
- const registeredRenderers = useRegisteredRenderers();
3849
- const allRenderers = useMemo(() => {
3850
- const externalIds = new Set(registeredRenderers.map((r) => r.id));
3851
- return [...registeredRenderers, ...builtInRenderers.filter((r) => !externalIds.has(r.id))];
3852
- }, [registeredRenderers]);
3853
- const style = {
3854
- position: "absolute",
3855
- left: bounds.origin.x * scale,
3856
- top: bounds.origin.y * scale,
3857
- width: bounds.size.width * scale,
3858
- height: bounds.size.height * scale,
3859
- pointerEvents: "none",
3860
- zIndex: 10
3861
- };
3862
- const match = allRenderers.find((r) => {
3863
- var _a2;
3864
- return ((_a2 = r.matchesPreview) == null ? void 0 : _a2.call(r, preview)) && r.renderPreview;
3865
- }) ?? allRenderers.find((r) => r.id === toolId && r.renderPreview);
3866
- if (match == null ? void 0 : match.renderPreview) {
3867
- const containerExtra = (_a = match.previewContainerStyle) == null ? void 0 : _a.call(match, {
3868
- data: preview.data,
3869
- bounds: preview.bounds,
3870
- scale
3871
- });
3872
- return /* @__PURE__ */ jsx("div", { style: { ...style, ...containerExtra }, children: match.renderPreview({ data: preview.data, bounds: preview.bounds, scale }) });
3873
- }
3874
- return null;
3875
- }
3876
- function AnnotationPaintLayer({ documentId, pageIndex, scale }) {
3877
- const { plugin: annotationPlugin } = useAnnotationPlugin();
3878
- const [previews, setPreviews] = useState(/* @__PURE__ */ new Map());
3879
- const fileInputRef = useRef(null);
3880
- const services = useMemo(
3881
- () => ({
3882
- requestFile: ({ accept, onFile }) => {
3883
- if (!fileInputRef.current) return;
3884
- const input = fileInputRef.current;
3885
- input.accept = accept;
3886
- input.onchange = (e) => {
3887
- var _a;
3888
- const file = (_a = e.target.files) == null ? void 0 : _a[0];
3889
- if (file) {
3890
- onFile(file);
3891
- input.value = "";
3892
- }
3893
- };
3894
- input.click();
3895
- }
3896
- }),
3897
- []
3898
- );
3899
- useEffect(() => {
3900
- if (!annotationPlugin) return;
3901
- return annotationPlugin.registerPageHandlers(documentId, pageIndex, scale, {
3902
- services,
3903
- onPreview: (toolId, state) => {
3904
- setPreviews((prev) => {
3905
- const next = new Map(prev);
3906
- if (state) {
3907
- next.set(toolId, state);
3908
- } else {
3909
- next.delete(toolId);
3910
- }
3911
- return next;
3912
- });
3913
- }
3914
- });
3915
- }, [documentId, pageIndex, scale, annotationPlugin, services]);
3916
- return /* @__PURE__ */ jsxs(Fragment, { children: [
3917
- /* @__PURE__ */ jsx("input", { ref: fileInputRef, type: "file", style: { display: "none" } }),
3918
- Array.from(previews.entries()).map(([toolId, preview]) => /* @__PURE__ */ jsx(PreviewRenderer, { toolId, preview, scale }, toolId))
3919
- ] });
3920
- }
3921
- function AnnotationLayer({
3922
- style,
3923
- documentId,
3924
- pageIndex,
3925
- scale: overrideScale,
3926
- rotation: overrideRotation,
3927
- selectionMenu,
3928
- groupSelectionMenu,
3929
- resizeUI,
3930
- vertexUI,
3931
- rotationUI,
3932
- selectionOutlineColor,
3933
- selectionOutline,
3934
- groupSelectionOutline,
3935
- customAnnotationRenderer,
3936
- annotationRenderers,
3937
- ...props
3938
- }) {
3939
- var _a, _b, _c, _d;
3940
- const documentState = useDocumentState(documentId);
3941
- const page = (_b = (_a = documentState == null ? void 0 : documentState.document) == null ? void 0 : _a.pages) == null ? void 0 : _b[pageIndex];
3942
- const width = ((_c = page == null ? void 0 : page.size) == null ? void 0 : _c.width) ?? 0;
3943
- const height = ((_d = page == null ? void 0 : page.size) == null ? void 0 : _d.height) ?? 0;
3944
- const contextRenderers = useRegisteredRenderers();
3945
- const allRenderers = useMemo(() => {
3946
- const merged = [...contextRenderers];
3947
- for (const renderer of annotationRenderers ?? []) {
3948
- const idx = merged.findIndex((r) => r.id === renderer.id);
3949
- if (idx >= 0) merged[idx] = renderer;
3950
- else merged.push(renderer);
3951
- }
3952
- return merged;
3953
- }, [contextRenderers, annotationRenderers]);
3954
- const actualScale = useMemo(() => {
3955
- if (overrideScale !== void 0) return overrideScale;
3956
- return (documentState == null ? void 0 : documentState.scale) ?? 1;
3957
- }, [overrideScale, documentState == null ? void 0 : documentState.scale]);
3958
- const actualRotation = useMemo(() => {
3959
- if (overrideRotation !== void 0) return overrideRotation;
3960
- const pageRotation = (page == null ? void 0 : page.rotation) ?? 0;
3961
- const docRotation = (documentState == null ? void 0 : documentState.rotation) ?? 0;
3962
- return (pageRotation + docRotation) % 4;
3963
- }, [overrideRotation, page == null ? void 0 : page.rotation, documentState == null ? void 0 : documentState.rotation]);
3964
- return /* @__PURE__ */ jsxs(
3965
- "div",
3966
- {
3967
- style: {
3968
- ...style
3969
- },
3970
- ...props,
3971
- children: [
3972
- /* @__PURE__ */ jsx(
3973
- Annotations,
3974
- {
3975
- documentId,
3976
- selectionMenu,
3977
- groupSelectionMenu,
3978
- pageIndex,
3979
- scale: actualScale,
3980
- rotation: actualRotation,
3981
- pageWidth: width,
3982
- pageHeight: height,
3983
- resizeUI,
3984
- vertexUI,
3985
- rotationUI,
3986
- selectionOutlineColor,
3987
- selectionOutline,
3988
- groupSelectionOutline,
3989
- customAnnotationRenderer,
3990
- annotationRenderers: allRenderers
3991
- }
3992
- ),
3993
- /* @__PURE__ */ jsx(TextMarkup, { documentId, pageIndex, scale: actualScale }),
3994
- /* @__PURE__ */ jsx(AnnotationPaintLayer, { documentId, pageIndex, scale: actualScale })
3995
- ]
3996
- }
3997
- );
3998
- }
3999
- const AnnotationPluginPackage = createPluginPackage(AnnotationPluginPackage$1).addWrapper(AnnotationRendererProvider).addUtility(AnnotationNavigationHandler).build();
4000
- export {
4001
- AnnotationLayer,
4002
- AnnotationPluginPackage,
4003
- AnnotationRendererProvider,
4004
- GroupSelectionBox,
4005
- createRenderer,
4006
- useAnnotation,
4007
- useAnnotationCapability,
4008
- useAnnotationPlugin,
4009
- useIOSZoomPrevention,
4010
- useRegisterRenderers,
4011
- useRegisteredRenderers,
4012
- useRendererRegistry
4013
- };
4014
- //# sourceMappingURL=index.js.map