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