@embedpdf/plugin-annotation 1.0.11 → 1.0.13

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 (109) hide show
  1. package/dist/index.cjs +2 -693
  2. package/dist/index.cjs.map +1 -1
  3. package/dist/index.d.ts +1 -266
  4. package/dist/index.js +509 -164
  5. package/dist/index.js.map +1 -1
  6. package/dist/lib/actions.d.ts +104 -0
  7. package/dist/lib/annotation-plugin.d.ts +34 -0
  8. package/dist/lib/helpers.d.ts +18 -0
  9. package/dist/lib/index.d.ts +12 -0
  10. package/dist/lib/manifest.d.ts +4 -0
  11. package/dist/lib/patching/derived-rect.d.ts +2 -0
  12. package/dist/lib/patching/index.d.ts +4 -0
  13. package/dist/lib/patching/line-ending-handlers.d.ts +20 -0
  14. package/dist/lib/patching/line-endings.d.ts +13 -0
  15. package/dist/lib/patching/patch-utils.d.ts +7 -0
  16. package/dist/lib/reducer.d.ts +5 -0
  17. package/dist/lib/selectors.d.ts +25 -0
  18. package/dist/lib/types.d.ts +168 -0
  19. package/dist/lib/utils.d.ts +11 -0
  20. package/dist/lib/variant-key.d.ts +8 -0
  21. package/dist/preact/adapter.d.ts +8 -0
  22. package/dist/preact/core.d.ts +1 -0
  23. package/dist/preact/index.cjs +2 -1038
  24. package/dist/preact/index.cjs.map +1 -1
  25. package/dist/preact/index.d.ts +1 -28
  26. package/dist/preact/index.js +2150 -539
  27. package/dist/preact/index.js.map +1 -1
  28. package/dist/preact/interaction-manager.d.ts +1 -0
  29. package/dist/preact/selection.d.ts +1 -0
  30. package/dist/react/adapter.d.ts +2 -0
  31. package/dist/react/core.d.ts +1 -0
  32. package/dist/react/index.cjs +2 -0
  33. package/dist/react/index.cjs.map +1 -0
  34. package/dist/react/index.d.ts +1 -0
  35. package/dist/react/index.js +2624 -0
  36. package/dist/react/index.js.map +1 -0
  37. package/dist/react/interaction-manager.d.ts +1 -0
  38. package/dist/react/selection.d.ts +1 -0
  39. package/dist/shared-preact/components/annotation-container.d.ts +24 -0
  40. package/dist/shared-preact/components/annotation-layer.d.ts +13 -0
  41. package/dist/shared-preact/components/annotations/circle-paint.d.ts +10 -0
  42. package/dist/shared-preact/components/annotations/circle.d.ts +29 -0
  43. package/dist/shared-preact/components/annotations/ink-highlight-paint.d.ts +0 -0
  44. package/dist/shared-preact/components/annotations/ink-paint.d.ts +18 -0
  45. package/dist/shared-preact/components/annotations/ink.d.ts +25 -0
  46. package/dist/shared-preact/components/annotations/line-paint.d.ts +10 -0
  47. package/dist/shared-preact/components/annotations/line.d.ts +33 -0
  48. package/dist/shared-preact/components/annotations/polygon-paint.d.ts +9 -0
  49. package/dist/shared-preact/components/annotations/polygon.d.ts +17 -0
  50. package/dist/shared-preact/components/annotations/polyline-paint.d.ts +10 -0
  51. package/dist/shared-preact/components/annotations/polyline.d.ts +17 -0
  52. package/dist/shared-preact/components/annotations/square-paint.d.ts +10 -0
  53. package/dist/shared-preact/components/annotations/square.d.ts +29 -0
  54. package/dist/shared-preact/components/annotations.d.ts +11 -0
  55. package/dist/shared-preact/components/counter-rotate-container.d.ts +32 -0
  56. package/dist/shared-preact/components/index.d.ts +1 -0
  57. package/dist/shared-preact/components/render-annotation.d.ts +11 -0
  58. package/dist/shared-preact/components/resize-handles.d.ts +9 -0
  59. package/dist/shared-preact/components/text-markup/highlight.d.ts +13 -0
  60. package/dist/shared-preact/components/text-markup/squiggly.d.ts +13 -0
  61. package/dist/shared-preact/components/text-markup/strikeout.d.ts +13 -0
  62. package/dist/shared-preact/components/text-markup/underline.d.ts +13 -0
  63. package/dist/shared-preact/components/text-markup.d.ts +6 -0
  64. package/dist/shared-preact/components/vertex-editor.d.ts +19 -0
  65. package/dist/shared-preact/hooks/index.d.ts +1 -0
  66. package/dist/shared-preact/hooks/use-annotation.d.ts +11 -0
  67. package/dist/shared-preact/hooks/use-drag-resize.d.ts +31 -0
  68. package/dist/shared-preact/index.d.ts +2 -0
  69. package/dist/shared-preact/patch-ink.d.ts +16 -0
  70. package/dist/shared-preact/patchers.d.ts +9 -0
  71. package/dist/shared-preact/types.d.ts +12 -0
  72. package/dist/shared-preact/vertex-patchers.d.ts +10 -0
  73. package/dist/shared-react/components/annotation-container.d.ts +24 -0
  74. package/dist/shared-react/components/annotation-layer.d.ts +13 -0
  75. package/dist/shared-react/components/annotations/circle-paint.d.ts +10 -0
  76. package/dist/shared-react/components/annotations/circle.d.ts +29 -0
  77. package/dist/shared-react/components/annotations/ink-highlight-paint.d.ts +0 -0
  78. package/dist/shared-react/components/annotations/ink-paint.d.ts +17 -0
  79. package/dist/shared-react/components/annotations/ink.d.ts +25 -0
  80. package/dist/shared-react/components/annotations/line-paint.d.ts +10 -0
  81. package/dist/shared-react/components/annotations/line.d.ts +33 -0
  82. package/dist/shared-react/components/annotations/polygon-paint.d.ts +9 -0
  83. package/dist/shared-react/components/annotations/polygon.d.ts +17 -0
  84. package/dist/shared-react/components/annotations/polyline-paint.d.ts +10 -0
  85. package/dist/shared-react/components/annotations/polyline.d.ts +17 -0
  86. package/dist/shared-react/components/annotations/square-paint.d.ts +10 -0
  87. package/dist/shared-react/components/annotations/square.d.ts +29 -0
  88. package/dist/shared-react/components/annotations.d.ts +11 -0
  89. package/dist/shared-react/components/counter-rotate-container.d.ts +32 -0
  90. package/dist/shared-react/components/index.d.ts +1 -0
  91. package/dist/shared-react/components/render-annotation.d.ts +11 -0
  92. package/dist/shared-react/components/resize-handles.d.ts +9 -0
  93. package/dist/shared-react/components/text-markup/highlight.d.ts +13 -0
  94. package/dist/shared-react/components/text-markup/squiggly.d.ts +13 -0
  95. package/dist/shared-react/components/text-markup/strikeout.d.ts +13 -0
  96. package/dist/shared-react/components/text-markup/underline.d.ts +13 -0
  97. package/dist/shared-react/components/text-markup.d.ts +6 -0
  98. package/dist/shared-react/components/vertex-editor.d.ts +19 -0
  99. package/dist/shared-react/hooks/index.d.ts +1 -0
  100. package/dist/shared-react/hooks/use-annotation.d.ts +11 -0
  101. package/dist/shared-react/hooks/use-drag-resize.d.ts +31 -0
  102. package/dist/shared-react/index.d.ts +2 -0
  103. package/dist/shared-react/patch-ink.d.ts +16 -0
  104. package/dist/shared-react/patchers.d.ts +9 -0
  105. package/dist/shared-react/types.d.ts +12 -0
  106. package/dist/shared-react/vertex-patchers.d.ts +10 -0
  107. package/package.json +17 -15
  108. package/dist/index.d.cts +0 -266
  109. package/dist/preact/index.d.cts +0 -28
@@ -1,1038 +1,2 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
-
20
- // src/preact/index.ts
21
- var preact_exports = {};
22
- __export(preact_exports, {
23
- AnnotationLayer: () => AnnotationLayer,
24
- useAnnotationCapability: () => useAnnotationCapability,
25
- useAnnotationPlugin: () => useAnnotationPlugin
26
- });
27
- module.exports = __toCommonJS(preact_exports);
28
-
29
- // src/preact/hooks/use-annotation.ts
30
- var import_preact = require("@embedpdf/core/preact");
31
- var import_plugin_annotation = require("@embedpdf/plugin-annotation");
32
- var useAnnotationPlugin = () => (0, import_preact.usePlugin)(import_plugin_annotation.AnnotationPlugin.id);
33
- var useAnnotationCapability = () => (0, import_preact.useCapability)(import_plugin_annotation.AnnotationPlugin.id);
34
-
35
- // src/preact/components/annotations.tsx
36
- var import_models3 = require("@embedpdf/models");
37
- var import_preact2 = require("@embedpdf/plugin-interaction-manager/preact");
38
- var import_plugin_annotation2 = require("@embedpdf/plugin-annotation");
39
- var import_hooks5 = require("preact/hooks");
40
-
41
- // src/preact/components/annotation-container.tsx
42
- var import_hooks = require("preact/hooks");
43
- var import_models = require("@embedpdf/models");
44
- var import_jsx_runtime = require("preact/jsx-runtime");
45
- function AnnotationContainer({
46
- scale,
47
- pageIndex,
48
- rotation,
49
- trackedAnnotation,
50
- children,
51
- style,
52
- outlineOffset = 1,
53
- isSelected = false,
54
- isDraggable = true,
55
- isResizable = true,
56
- computeResizePatch,
57
- ...props
58
- }) {
59
- const { provides: annotationProvides } = useAnnotationCapability();
60
- const ref = (0, import_hooks.useRef)(null);
61
- const [dragState, setDragState] = (0, import_hooks.useState)("idle");
62
- const [resizeDirection, setResizeDirection] = (0, import_hooks.useState)(null);
63
- const [startPos, setStartPos] = (0, import_hooks.useState)(null);
64
- const [startRect, setStartRect] = (0, import_hooks.useState)(null);
65
- const [currentRect, setCurrentRect] = (0, import_hooks.useState)(trackedAnnotation.object.rect);
66
- const [previewObject, setPreviewObject] = (0, import_hooks.useState)(null);
67
- (0, import_hooks.useEffect)(() => {
68
- setCurrentRect(trackedAnnotation.object.rect);
69
- setPreviewObject(null);
70
- }, [trackedAnnotation]);
71
- const handlePointerDown = (e) => {
72
- if (!isSelected) return;
73
- e.stopPropagation();
74
- e.preventDefault();
75
- const target = e.target;
76
- if (isResizable && target.classList.contains("resize-handle")) {
77
- setDragState("resizing");
78
- setResizeDirection(target.dataset.direction);
79
- } else if (isDraggable) {
80
- setDragState("dragging");
81
- } else {
82
- return;
83
- }
84
- setStartPos({ x: e.clientX, y: e.clientY });
85
- setStartRect(currentRect);
86
- ref.current?.setPointerCapture(e.pointerId);
87
- };
88
- const handlePointerMove = (e) => {
89
- if (dragState === "idle" || !startPos || !startRect) return;
90
- const dispDelta = { x: e.clientX - startPos.x, y: e.clientY - startPos.y };
91
- const { x: dx, y: dy } = (0, import_models.restoreOffset)(dispDelta, rotation, scale);
92
- let newOriginX = startRect.origin.x;
93
- let newOriginY = startRect.origin.y;
94
- let newWidth = startRect.size.width;
95
- let newHeight = startRect.size.height;
96
- if (dragState === "dragging") {
97
- newOriginX += dx;
98
- newOriginY += dy;
99
- } else if (dragState === "resizing" && resizeDirection) {
100
- if (resizeDirection.includes("right")) {
101
- newWidth += dx;
102
- } else if (resizeDirection.includes("left")) {
103
- newOriginX += dx;
104
- newWidth -= dx;
105
- }
106
- if (resizeDirection.includes("bottom")) {
107
- newHeight += dy;
108
- } else if (resizeDirection.includes("top")) {
109
- newOriginY += dy;
110
- newHeight -= dy;
111
- }
112
- if (newWidth < 1 || newHeight < 1) return;
113
- }
114
- const tentativeRect = {
115
- origin: { x: newOriginX, y: newOriginY },
116
- size: { width: newWidth, height: newHeight }
117
- };
118
- let previewPatch = { rect: tentativeRect };
119
- if (computeResizePatch) {
120
- const dir = dragState === "resizing" ? resizeDirection : "bottom-right";
121
- if (dir) {
122
- previewPatch = computeResizePatch(trackedAnnotation.object, tentativeRect, dir);
123
- }
124
- }
125
- setCurrentRect(previewPatch.rect || tentativeRect);
126
- setPreviewObject(previewPatch);
127
- };
128
- const handlePointerUp = (e) => {
129
- if (dragState === "idle") return;
130
- const usedDirection = resizeDirection || "bottom-right";
131
- setDragState("idle");
132
- setResizeDirection(null);
133
- ref.current?.releasePointerCapture(e.pointerId);
134
- if (annotationProvides && trackedAnnotation) {
135
- let patch = { rect: currentRect };
136
- if (computeResizePatch && usedDirection) {
137
- patch = computeResizePatch(trackedAnnotation.object, currentRect, usedDirection);
138
- }
139
- annotationProvides.updateAnnotation(pageIndex, trackedAnnotation.localId, patch);
140
- }
141
- setStartPos(null);
142
- setStartRect(null);
143
- setPreviewObject(null);
144
- };
145
- const currentObject = previewObject ? { ...trackedAnnotation.object, ...previewObject } : trackedAnnotation.object;
146
- return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
147
- "div",
148
- {
149
- ref,
150
- onPointerDown: handlePointerDown,
151
- onPointerMove: handlePointerMove,
152
- onPointerUp: handlePointerUp,
153
- style: {
154
- position: "absolute",
155
- outline: isSelected ? "1px solid #007ACC" : "none",
156
- outlineOffset: isSelected ? `${outlineOffset}px` : "0px",
157
- left: `${currentRect.origin.x * scale}px`,
158
- top: `${currentRect.origin.y * scale}px`,
159
- width: `${currentRect.size.width * scale}px`,
160
- height: `${currentRect.size.height * scale}px`,
161
- pointerEvents: isSelected ? "auto" : "none",
162
- cursor: isSelected && isDraggable ? "move" : "default",
163
- ...style
164
- },
165
- ...props,
166
- children: [
167
- typeof children === "function" ? children(currentObject) : children,
168
- isSelected && isResizable && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
169
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
170
- "div",
171
- {
172
- className: "resize-handle",
173
- "data-direction": "top-left",
174
- style: {
175
- position: "absolute",
176
- top: -7 - outlineOffset,
177
- left: -7 - outlineOffset,
178
- width: 13,
179
- height: 13,
180
- background: "blue",
181
- borderRadius: "50%",
182
- cursor: rotation % 2 ? "nesw-resize" : "nwse-resize"
183
- }
184
- }
185
- ),
186
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
187
- "div",
188
- {
189
- className: "resize-handle",
190
- "data-direction": "top-right",
191
- style: {
192
- position: "absolute",
193
- top: -7 - outlineOffset,
194
- right: -7 - outlineOffset,
195
- width: 13,
196
- height: 13,
197
- background: "blue",
198
- borderRadius: "50%",
199
- cursor: rotation % 2 ? "nwse-resize" : "nesw-resize"
200
- }
201
- }
202
- ),
203
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
204
- "div",
205
- {
206
- className: "resize-handle",
207
- "data-direction": "bottom-left",
208
- style: {
209
- position: "absolute",
210
- bottom: -7 - outlineOffset,
211
- left: -7 - outlineOffset,
212
- width: 13,
213
- height: 13,
214
- background: "blue",
215
- borderRadius: "50%",
216
- cursor: rotation % 2 ? "nwse-resize" : "nesw-resize"
217
- }
218
- }
219
- ),
220
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
221
- "div",
222
- {
223
- className: "resize-handle",
224
- "data-direction": "bottom-right",
225
- style: {
226
- position: "absolute",
227
- bottom: -7 - outlineOffset,
228
- right: -7 - outlineOffset,
229
- width: 13,
230
- height: 13,
231
- background: "blue",
232
- borderRadius: "50%",
233
- cursor: rotation % 2 ? "nesw-resize" : "nwse-resize"
234
- }
235
- }
236
- )
237
- ] })
238
- ]
239
- }
240
- );
241
- }
242
-
243
- // src/preact/components/text-markup/highlight.tsx
244
- var import_jsx_runtime2 = require("preact/jsx-runtime");
245
- function Highlight({
246
- color = "#FFFF00",
247
- opacity = 0.5,
248
- rects,
249
- rect,
250
- scale,
251
- onClick,
252
- style,
253
- ...props
254
- }) {
255
- return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_jsx_runtime2.Fragment, { children: rects.map((b, i) => /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
256
- "div",
257
- {
258
- onMouseDown: onClick,
259
- style: {
260
- position: "absolute",
261
- left: (rect ? b.origin.x - rect.origin.x : b.origin.x) * scale,
262
- top: (rect ? b.origin.y - rect.origin.y : b.origin.y) * scale,
263
- width: b.size.width * scale,
264
- height: b.size.height * scale,
265
- background: color,
266
- opacity,
267
- pointerEvents: onClick ? "auto" : "none",
268
- cursor: onClick ? "pointer" : "default",
269
- zIndex: onClick ? 1 : null,
270
- ...style
271
- },
272
- ...props
273
- },
274
- i
275
- )) });
276
- }
277
-
278
- // src/preact/components/text-markup/underline.tsx
279
- var import_jsx_runtime3 = require("preact/jsx-runtime");
280
- function Underline({
281
- color = "#FFFF00",
282
- opacity = 0.5,
283
- rects,
284
- rect,
285
- scale,
286
- onClick,
287
- style,
288
- ...props
289
- }) {
290
- const thickness = 2 * scale;
291
- return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_jsx_runtime3.Fragment, { children: rects.map((r, i) => /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
292
- "div",
293
- {
294
- onMouseDown: onClick,
295
- style: {
296
- position: "absolute",
297
- left: (rect ? r.origin.x - rect.origin.x : r.origin.x) * scale,
298
- top: (rect ? r.origin.y - rect.origin.y : r.origin.y) * scale,
299
- width: r.size.width * scale,
300
- height: r.size.height * scale,
301
- background: "transparent",
302
- pointerEvents: onClick ? "auto" : "none",
303
- cursor: onClick ? "pointer" : "default",
304
- zIndex: onClick ? 1 : 0,
305
- ...style
306
- },
307
- ...props,
308
- children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
309
- "div",
310
- {
311
- style: {
312
- position: "absolute",
313
- left: 0,
314
- bottom: 0,
315
- width: "100%",
316
- height: thickness,
317
- background: color,
318
- opacity,
319
- pointerEvents: "none"
320
- }
321
- }
322
- )
323
- },
324
- i
325
- )) });
326
- }
327
-
328
- // src/preact/components/text-markup/strikeout.tsx
329
- var import_jsx_runtime4 = require("preact/jsx-runtime");
330
- function Strikeout({
331
- color = "#FFFF00",
332
- opacity = 0.5,
333
- rects,
334
- rect,
335
- scale,
336
- onClick,
337
- style,
338
- ...props
339
- }) {
340
- const thickness = 2 * scale;
341
- return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(import_jsx_runtime4.Fragment, { children: rects.map((r, i) => /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
342
- "div",
343
- {
344
- onMouseDown: onClick,
345
- style: {
346
- position: "absolute",
347
- left: (rect ? r.origin.x - rect.origin.x : r.origin.x) * scale,
348
- top: (rect ? r.origin.y - rect.origin.y : r.origin.y) * scale,
349
- width: r.size.width * scale,
350
- height: r.size.height * scale,
351
- background: "transparent",
352
- pointerEvents: onClick ? "auto" : "none",
353
- cursor: onClick ? "pointer" : "default",
354
- zIndex: onClick ? 1 : 0,
355
- ...style
356
- },
357
- ...props,
358
- children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
359
- "div",
360
- {
361
- style: {
362
- position: "absolute",
363
- left: 0,
364
- top: "50%",
365
- width: "100%",
366
- height: thickness,
367
- background: color,
368
- opacity,
369
- transform: "translateY(-50%)",
370
- pointerEvents: "none"
371
- }
372
- }
373
- )
374
- },
375
- i
376
- )) });
377
- }
378
-
379
- // src/preact/components/text-markup/squiggly.tsx
380
- var import_jsx_runtime5 = require("preact/jsx-runtime");
381
- function Squiggly({
382
- color = "#FFFF00",
383
- opacity = 0.5,
384
- rects,
385
- rect,
386
- scale,
387
- onClick,
388
- style,
389
- ...props
390
- }) {
391
- const amplitude = 2 * scale;
392
- const period = 6 * scale;
393
- const svg = `<svg xmlns="http://www.w3.org/2000/svg" width="${period}" height="${amplitude * 2}" viewBox="0 0 ${period} ${amplitude * 2}">
394
- <path d="M0 ${amplitude} Q ${period / 4} 0 ${period / 2} ${amplitude} T ${period} ${amplitude}"
395
- fill="none" stroke="${color}" stroke-width="${amplitude}" stroke-linecap="round"/>
396
- </svg>`;
397
- const svgDataUri = `url("data:image/svg+xml;utf8,${encodeURIComponent(svg)}")`;
398
- return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_jsx_runtime5.Fragment, { children: rects.map((r, i) => /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
399
- "div",
400
- {
401
- onMouseDown: onClick,
402
- style: {
403
- position: "absolute",
404
- left: (rect ? r.origin.x - rect.origin.x : r.origin.x) * scale,
405
- top: (rect ? r.origin.y - rect.origin.y : r.origin.y) * scale,
406
- width: r.size.width * scale,
407
- height: r.size.height * scale,
408
- background: "transparent",
409
- pointerEvents: onClick ? "auto" : "none",
410
- cursor: onClick ? "pointer" : "default",
411
- zIndex: onClick ? 1 : 0,
412
- ...style
413
- },
414
- ...props,
415
- children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
416
- "div",
417
- {
418
- style: {
419
- position: "absolute",
420
- left: 0,
421
- bottom: 0,
422
- width: "100%",
423
- height: amplitude * 2,
424
- backgroundImage: svgDataUri,
425
- backgroundRepeat: "repeat-x",
426
- backgroundSize: `${period}px ${amplitude * 2}px`,
427
- opacity,
428
- pointerEvents: "none"
429
- }
430
- }
431
- )
432
- },
433
- i
434
- )) });
435
- }
436
-
437
- // src/preact/components/annotations/ink.tsx
438
- var import_hooks3 = require("preact/hooks");
439
- var import_jsx_runtime6 = require("preact/jsx-runtime");
440
- function Ink({
441
- color = "#000000",
442
- opacity = 1,
443
- strokeWidth,
444
- inkList,
445
- rect,
446
- scale,
447
- onClick
448
- }) {
449
- const paths = (0, import_hooks3.useMemo)(() => {
450
- return inkList.map(({ points }) => {
451
- let d = "";
452
- points.forEach(({ x, y }, i) => {
453
- const lx = x - rect.origin.x;
454
- const ly = y - rect.origin.y;
455
- d += (i === 0 ? "M" : "L") + lx + " " + ly + " ";
456
- });
457
- return d.trim();
458
- });
459
- }, [inkList, rect]);
460
- const width = rect.size.width * scale;
461
- const height = rect.size.height * scale;
462
- return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
463
- "svg",
464
- {
465
- style: {
466
- position: "absolute",
467
- width,
468
- height,
469
- pointerEvents: "none",
470
- zIndex: 2
471
- },
472
- width,
473
- height,
474
- viewBox: `0 0 ${rect.size.width} ${rect.size.height}`,
475
- children: paths.map((d, i) => /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
476
- "path",
477
- {
478
- d,
479
- fill: "none",
480
- stroke: color,
481
- strokeWidth,
482
- strokeLinecap: "round",
483
- strokeLinejoin: "round",
484
- opacity,
485
- pointerEvents: "visibleStroke",
486
- onMouseDown: onClick,
487
- style: {
488
- cursor: "pointer"
489
- }
490
- },
491
- i
492
- ))
493
- }
494
- );
495
- }
496
-
497
- // src/preact/components/annotations.tsx
498
- var import_preact3 = require("@embedpdf/plugin-selection/preact");
499
-
500
- // src/shared/resize-ink.ts
501
- var import_models2 = require("@embedpdf/models");
502
- function resizeInkAnnotation(original, newRect, direction, uniform = false) {
503
- if (original.type !== import_models2.PdfAnnotationSubtype.INK) {
504
- throw new Error("resizeInkAnnotation: original is not an ink annotation");
505
- }
506
- const oldRect = original.rect;
507
- let scaleX = newRect.size.width / oldRect.size.width;
508
- let scaleY = newRect.size.height / oldRect.size.height;
509
- const minSize = 10;
510
- if (newRect.size.width < minSize || newRect.size.height < minSize) {
511
- scaleX = Math.max(scaleX, minSize / oldRect.size.width);
512
- scaleY = Math.max(scaleY, minSize / oldRect.size.height);
513
- newRect = {
514
- origin: newRect.origin,
515
- size: {
516
- width: oldRect.size.width * scaleX,
517
- height: oldRect.size.height * scaleY
518
- }
519
- };
520
- }
521
- if (uniform) {
522
- const minScale = Math.min(scaleX, scaleY);
523
- scaleX = minScale;
524
- scaleY = minScale;
525
- newRect.size = {
526
- width: oldRect.size.width * minScale,
527
- height: oldRect.size.height * minScale
528
- };
529
- }
530
- const newInkList = original.inkList.map((stroke) => ({
531
- points: stroke.points.map((p) => ({
532
- x: newRect.origin.x + (p.x - oldRect.origin.x) * scaleX,
533
- y: newRect.origin.y + (p.y - oldRect.origin.y) * scaleY
534
- }))
535
- }));
536
- const avgScale = (scaleX + scaleY) / 2;
537
- const newStrokeWidth = original.strokeWidth * avgScale;
538
- return {
539
- rect: newRect,
540
- inkList: newInkList,
541
- strokeWidth: newStrokeWidth
542
- };
543
- }
544
-
545
- // src/preact/components/annotations.tsx
546
- var import_jsx_runtime7 = require("preact/jsx-runtime");
547
- function Annotations(annotationsProps) {
548
- const { pageIndex, scale } = annotationsProps;
549
- const { provides: annotationProvides } = useAnnotationCapability();
550
- const { provides: selectionProvides } = (0, import_preact3.useSelectionCapability)();
551
- const [annotations, setAnnotations] = (0, import_hooks5.useState)([]);
552
- const { register } = (0, import_preact2.usePointerHandlers)({ pageIndex });
553
- const [selectionState, setSelectionState] = (0, import_hooks5.useState)(null);
554
- (0, import_hooks5.useEffect)(() => {
555
- if (annotationProvides) {
556
- annotationProvides.onStateChange((state) => {
557
- setAnnotations((0, import_plugin_annotation2.getAnnotationsByPageIndex)(state, pageIndex));
558
- setSelectionState((0, import_plugin_annotation2.getSelectedAnnotationByPageIndex)(state, pageIndex));
559
- });
560
- }
561
- }, [annotationProvides]);
562
- const handlers = (0, import_hooks5.useMemo)(
563
- () => ({
564
- onPointerDown: (_, pe) => {
565
- if (pe.target === pe.currentTarget && annotationProvides) {
566
- annotationProvides.deselectAnnotation();
567
- }
568
- }
569
- }),
570
- [annotationProvides]
571
- );
572
- const handleClick = (0, import_hooks5.useCallback)(
573
- (e, annotation) => {
574
- e.stopPropagation();
575
- if (annotationProvides && selectionProvides) {
576
- annotationProvides.selectAnnotation(pageIndex, annotation.localId);
577
- selectionProvides.clear();
578
- }
579
- },
580
- [annotationProvides, selectionProvides, pageIndex]
581
- );
582
- (0, import_hooks5.useEffect)(() => {
583
- return register(handlers);
584
- }, [register, handlers]);
585
- return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_jsx_runtime7.Fragment, { children: annotations.map((annotation) => {
586
- const isSelected = selectionState?.localId === annotation.localId;
587
- switch (annotation.object.type) {
588
- case import_models3.PdfAnnotationSubtype.UNDERLINE:
589
- return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
590
- AnnotationContainer,
591
- {
592
- trackedAnnotation: annotation,
593
- isSelected,
594
- isDraggable: false,
595
- isResizable: false,
596
- style: { mixBlendMode: "multiply" },
597
- ...annotationsProps,
598
- children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
599
- Underline,
600
- {
601
- rect: annotation.object.rect,
602
- color: annotation.object.color,
603
- opacity: annotation.object.opacity,
604
- rects: annotation.object.segmentRects,
605
- scale,
606
- onClick: (e) => handleClick(e, annotation)
607
- }
608
- )
609
- },
610
- annotation.localId
611
- );
612
- case import_models3.PdfAnnotationSubtype.STRIKEOUT:
613
- return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
614
- AnnotationContainer,
615
- {
616
- trackedAnnotation: annotation,
617
- isSelected,
618
- isDraggable: false,
619
- isResizable: false,
620
- style: { mixBlendMode: "multiply" },
621
- ...annotationsProps,
622
- children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
623
- Strikeout,
624
- {
625
- rect: annotation.object.rect,
626
- color: annotation.object.color,
627
- opacity: annotation.object.opacity,
628
- rects: annotation.object.segmentRects,
629
- scale,
630
- onClick: (e) => handleClick(e, annotation)
631
- }
632
- )
633
- },
634
- annotation.localId
635
- );
636
- case import_models3.PdfAnnotationSubtype.SQUIGGLY:
637
- return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
638
- AnnotationContainer,
639
- {
640
- trackedAnnotation: annotation,
641
- isSelected,
642
- isDraggable: false,
643
- isResizable: false,
644
- style: { mixBlendMode: "multiply" },
645
- ...annotationsProps,
646
- children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
647
- Squiggly,
648
- {
649
- color: annotation.object.color,
650
- opacity: annotation.object.opacity,
651
- rects: annotation.object.segmentRects,
652
- rect: annotation.object.rect,
653
- scale,
654
- onClick: (e) => handleClick(e, annotation)
655
- }
656
- )
657
- },
658
- annotation.localId
659
- );
660
- case import_models3.PdfAnnotationSubtype.HIGHLIGHT:
661
- return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
662
- AnnotationContainer,
663
- {
664
- trackedAnnotation: annotation,
665
- isSelected,
666
- isDraggable: false,
667
- isResizable: false,
668
- style: { mixBlendMode: "multiply" },
669
- ...annotationsProps,
670
- children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
671
- Highlight,
672
- {
673
- color: annotation.object.color,
674
- opacity: annotation.object.opacity,
675
- rects: annotation.object.segmentRects,
676
- scale,
677
- rect: annotation.object.rect,
678
- onClick: (e) => handleClick(e, annotation)
679
- }
680
- )
681
- },
682
- annotation.localId
683
- );
684
- case import_models3.PdfAnnotationSubtype.INK:
685
- return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
686
- AnnotationContainer,
687
- {
688
- isSelected,
689
- trackedAnnotation: annotation,
690
- outlineOffset: 6,
691
- computeResizePatch: resizeInkAnnotation,
692
- ...annotationsProps,
693
- children: (obj) => /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
694
- Ink,
695
- {
696
- color: obj.color,
697
- opacity: obj.opacity,
698
- strokeWidth: obj.strokeWidth,
699
- inkList: obj.inkList,
700
- rect: obj.rect,
701
- scale,
702
- onClick: (e) => handleClick(e, annotation)
703
- }
704
- )
705
- },
706
- annotation.localId
707
- );
708
- default:
709
- return null;
710
- }
711
- }) });
712
- }
713
-
714
- // src/preact/components/text-markup.tsx
715
- var import_models4 = require("@embedpdf/models");
716
- var import_preact4 = require("@embedpdf/plugin-selection/preact");
717
- var import_hooks6 = require("preact/hooks");
718
- var import_jsx_runtime8 = require("preact/jsx-runtime");
719
- function TextMarkup({ pageIndex, scale }) {
720
- const { provides: selectionProvides } = (0, import_preact4.useSelectionCapability)();
721
- const { provides: annotationProvides } = useAnnotationCapability();
722
- const [rects, setRects] = (0, import_hooks6.useState)([]);
723
- const [boundingRect, setBoundingRect] = (0, import_hooks6.useState)(null);
724
- const [activeTool, setActiveTool] = (0, import_hooks6.useState)({ mode: null, defaults: null });
725
- (0, import_hooks6.useEffect)(() => {
726
- if (!selectionProvides) return;
727
- const off = selectionProvides.onSelectionChange(() => {
728
- setRects(selectionProvides.getHighlightRectsForPage(pageIndex));
729
- setBoundingRect(selectionProvides.getBoundingRectForPage(pageIndex));
730
- });
731
- return off;
732
- }, [selectionProvides, pageIndex]);
733
- (0, import_hooks6.useEffect)(() => {
734
- if (!annotationProvides) return;
735
- const off = annotationProvides.onActiveToolChange(setActiveTool);
736
- return off;
737
- }, [annotationProvides]);
738
- if (!boundingRect) return null;
739
- switch (activeTool.mode) {
740
- case import_models4.PdfAnnotationSubtype.UNDERLINE:
741
- return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
742
- "div",
743
- {
744
- style: {
745
- mixBlendMode: "multiply",
746
- pointerEvents: "none",
747
- position: "absolute",
748
- inset: 0
749
- },
750
- children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
751
- Underline,
752
- {
753
- color: activeTool.defaults?.color,
754
- opacity: activeTool.defaults?.opacity,
755
- rects,
756
- scale
757
- }
758
- )
759
- }
760
- );
761
- case import_models4.PdfAnnotationSubtype.HIGHLIGHT:
762
- return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
763
- "div",
764
- {
765
- style: {
766
- mixBlendMode: "multiply",
767
- pointerEvents: "none",
768
- position: "absolute",
769
- inset: 0
770
- },
771
- children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
772
- Highlight,
773
- {
774
- color: activeTool.defaults?.color,
775
- opacity: activeTool.defaults?.opacity,
776
- rects,
777
- scale
778
- }
779
- )
780
- }
781
- );
782
- case import_models4.PdfAnnotationSubtype.STRIKEOUT:
783
- return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
784
- "div",
785
- {
786
- style: {
787
- mixBlendMode: "multiply",
788
- pointerEvents: "none",
789
- position: "absolute",
790
- inset: 0
791
- },
792
- children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
793
- Strikeout,
794
- {
795
- color: activeTool.defaults?.color,
796
- opacity: activeTool.defaults?.opacity,
797
- rects,
798
- scale
799
- }
800
- )
801
- }
802
- );
803
- case import_models4.PdfAnnotationSubtype.SQUIGGLY:
804
- return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
805
- "div",
806
- {
807
- style: {
808
- mixBlendMode: "multiply",
809
- pointerEvents: "none",
810
- position: "absolute",
811
- inset: 0
812
- },
813
- children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
814
- Squiggly,
815
- {
816
- color: activeTool.defaults?.color,
817
- opacity: activeTool.defaults?.opacity,
818
- rects,
819
- scale
820
- }
821
- )
822
- }
823
- );
824
- default:
825
- return null;
826
- }
827
- }
828
-
829
- // src/preact/components/annotations/ink-paint.tsx
830
- var import_hooks8 = require("preact/hooks");
831
- var import_preact5 = require("@embedpdf/plugin-interaction-manager/preact");
832
- var import_models5 = require("@embedpdf/models");
833
- var import_jsx_runtime9 = require("preact/jsx-runtime");
834
- var MAX_STROKE_WIDTH = 30;
835
- var InkPaint = ({ pageIndex, scale, pageWidth, pageHeight }) => {
836
- const { provides: annotationProvides } = useAnnotationCapability();
837
- const [activeTool, setActiveTool] = (0, import_hooks8.useState)({ mode: null, defaults: null });
838
- (0, import_hooks8.useEffect)(() => {
839
- if (!annotationProvides) return;
840
- const off = annotationProvides.onActiveToolChange(setActiveTool);
841
- return off;
842
- }, [annotationProvides]);
843
- if (activeTool.mode !== import_models5.PdfAnnotationSubtype.INK) return null;
844
- const toolColor = activeTool.defaults?.color ?? "#000000";
845
- const toolOpacity = activeTool.defaults?.opacity ?? 1;
846
- const toolStrokeWidth = activeTool.defaults?.strokeWidth ?? 2;
847
- const { register } = (0, import_preact5.usePointerHandlers)({ modeId: "ink", pageIndex });
848
- const clamp = (v, min, max) => Math.max(min, Math.min(max, v));
849
- const [currentStrokes, setCurrentStrokes] = (0, import_hooks8.useState)([]);
850
- const [isDrawing, setIsDrawing] = (0, import_hooks8.useState)(false);
851
- const timerRef = (0, import_hooks8.useRef)(null);
852
- const pageWidthPDF = pageWidth / scale;
853
- const pageHeightPDF = pageHeight / scale;
854
- const handlers = (0, import_hooks8.useMemo)(
855
- () => ({
856
- onPointerDown: (pos, evt) => {
857
- const curX = clamp(pos.x, 0, pageWidthPDF);
858
- const curY = clamp(pos.y, 0, pageHeightPDF);
859
- setIsDrawing(true);
860
- if (timerRef.current) {
861
- clearTimeout(timerRef.current);
862
- timerRef.current = null;
863
- setCurrentStrokes((prev) => [...prev, { points: [{ x: curX, y: curY }] }]);
864
- } else {
865
- setCurrentStrokes([{ points: [{ x: curX, y: curY }] }]);
866
- }
867
- evt.target?.setPointerCapture?.(evt.pointerId);
868
- },
869
- onPointerMove: (pos) => {
870
- if (!isDrawing) return;
871
- const curX = clamp(pos.x, 0, pageWidthPDF);
872
- const curY = clamp(pos.y, 0, pageHeightPDF);
873
- setCurrentStrokes((prev) => {
874
- if (!prev.length) return prev;
875
- const last = prev[prev.length - 1];
876
- const newLast = { points: [...last.points, { x: curX, y: curY }] };
877
- return [...prev.slice(0, -1), newLast];
878
- });
879
- },
880
- onPointerUp: (_, evt) => {
881
- setIsDrawing(false);
882
- evt.target?.releasePointerCapture?.(evt.pointerId);
883
- if (timerRef.current) clearTimeout(timerRef.current);
884
- timerRef.current = setTimeout(() => {
885
- if (currentStrokes.length && annotationProvides) {
886
- const allPoints2 = currentStrokes.flatMap((s) => s.points);
887
- if (!allPoints2.length) return;
888
- const minX2 = Math.min(...allPoints2.map((p) => p.x));
889
- const minY2 = Math.min(...allPoints2.map((p) => p.y));
890
- const maxX2 = Math.max(...allPoints2.map((p) => p.x));
891
- const maxY2 = Math.max(...allPoints2.map((p) => p.y));
892
- const halfStroke2 = MAX_STROKE_WIDTH / 2;
893
- const rectMinX = minX2 - halfStroke2;
894
- const rectMinY = minY2 - halfStroke2;
895
- const rectMaxX = maxX2 + halfStroke2;
896
- const rectMaxY = maxY2 + halfStroke2;
897
- if (rectMaxX - rectMinX < 1 || rectMaxY - rectMinY < 1) return;
898
- const rect = {
899
- origin: { x: rectMinX, y: rectMinY },
900
- size: { width: rectMaxX - rectMinX, height: rectMaxY - rectMinY }
901
- };
902
- const anno = {
903
- type: import_models5.PdfAnnotationSubtype.INK,
904
- rect,
905
- inkList: currentStrokes,
906
- color: toolColor,
907
- opacity: toolOpacity,
908
- strokeWidth: toolStrokeWidth,
909
- pageIndex,
910
- id: Date.now() + Math.random()
911
- };
912
- annotationProvides.createAnnotation(pageIndex, anno);
913
- annotationProvides.setAnnotationMode(null);
914
- annotationProvides.selectAnnotation(pageIndex, anno.id);
915
- }
916
- setCurrentStrokes([]);
917
- timerRef.current = null;
918
- }, 3e3);
919
- },
920
- onPointerCancel: (_, evt) => {
921
- setIsDrawing(false);
922
- evt.target?.releasePointerCapture?.(evt.pointerId);
923
- setCurrentStrokes([]);
924
- if (timerRef.current) {
925
- clearTimeout(timerRef.current);
926
- timerRef.current = null;
927
- }
928
- }
929
- }),
930
- [
931
- pageWidthPDF,
932
- pageHeightPDF,
933
- currentStrokes,
934
- annotationProvides,
935
- pageIndex,
936
- toolColor,
937
- toolOpacity,
938
- toolStrokeWidth,
939
- isDrawing
940
- ]
941
- );
942
- (0, import_hooks8.useEffect)(() => {
943
- if (!register) return;
944
- return register(handlers);
945
- }, [register, handlers]);
946
- (0, import_hooks8.useEffect)(() => {
947
- return () => {
948
- if (timerRef.current) clearTimeout(timerRef.current);
949
- };
950
- }, []);
951
- if (!currentStrokes.length) return null;
952
- const allPoints = currentStrokes.flatMap((s) => s.points);
953
- if (!allPoints.length) return null;
954
- const minX = Math.min(...allPoints.map((p) => p.x));
955
- const minY = Math.min(...allPoints.map((p) => p.y));
956
- const maxX = Math.max(...allPoints.map((p) => p.x));
957
- const maxY = Math.max(...allPoints.map((p) => p.y));
958
- const halfStroke = MAX_STROKE_WIDTH / 2;
959
- const svgMinX = minX - halfStroke;
960
- const svgMinY = minY - halfStroke;
961
- const svgMaxX = maxX + halfStroke;
962
- const svgMaxY = maxY + halfStroke;
963
- const dw = svgMaxX - svgMinX;
964
- const dh = svgMaxY - svgMinY;
965
- const paths = currentStrokes.map(({ points }) => {
966
- let d = "";
967
- points.forEach(({ x, y }, i) => {
968
- const lx = x - svgMinX;
969
- const ly = y - svgMinY;
970
- d += (i === 0 ? "M" : "L") + lx + " " + ly + " ";
971
- });
972
- return d.trim();
973
- });
974
- return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
975
- "svg",
976
- {
977
- style: {
978
- position: "absolute",
979
- left: svgMinX * scale,
980
- top: svgMinY * scale,
981
- width: dw * scale,
982
- height: dh * scale,
983
- pointerEvents: "none",
984
- zIndex: 2
985
- },
986
- width: dw * scale,
987
- height: dh * scale,
988
- viewBox: `0 0 ${dw} ${dh}`,
989
- children: paths.map((d, i) => /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
990
- "path",
991
- {
992
- d,
993
- fill: "none",
994
- stroke: toolColor,
995
- strokeWidth: toolStrokeWidth,
996
- strokeLinecap: "round",
997
- strokeLinejoin: "round",
998
- opacity: toolOpacity
999
- },
1000
- i
1001
- ))
1002
- }
1003
- );
1004
- };
1005
-
1006
- // src/preact/components/annotation-layer.tsx
1007
- var import_jsx_runtime10 = require("preact/jsx-runtime");
1008
- function AnnotationLayer({
1009
- pageIndex,
1010
- scale,
1011
- pageWidth,
1012
- pageHeight,
1013
- rotation,
1014
- style,
1015
- ...props
1016
- }) {
1017
- return /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)(
1018
- "div",
1019
- {
1020
- style: {
1021
- ...style
1022
- },
1023
- ...props,
1024
- children: [
1025
- /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(Annotations, { pageIndex, scale, rotation }),
1026
- /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(TextMarkup, { pageIndex, scale }),
1027
- /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(InkPaint, { pageIndex, scale, pageWidth, pageHeight })
1028
- ]
1029
- }
1030
- );
1031
- }
1032
- // Annotate the CommonJS export names for ESM import in node:
1033
- 0 && (module.exports = {
1034
- AnnotationLayer,
1035
- useAnnotationCapability,
1036
- useAnnotationPlugin
1037
- });
1038
- //# sourceMappingURL=index.cjs.map
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("@embedpdf/core/preact"),t=require("@embedpdf/plugin-annotation"),n=require("preact/jsx-runtime"),o=require("@embedpdf/models"),i=require("@embedpdf/plugin-interaction-manager/preact"),r=require("@embedpdf/plugin-selection/preact"),s=require("preact"),l=require("preact/hooks"),a=()=>e.useCapability(t.AnnotationPlugin.id);function c({children:e,...t}){const{rect:o,rotation:i}=t,{matrix:r,width:l,height:a}=function(e,t){const{width:n,height:o}=e.size;switch(t%4){case 1:return{matrix:`matrix(0, -1, 1, 0, 0, ${o})`,width:o,height:n};case 2:return{matrix:`matrix(-1, 0, 0, -1, ${n}, ${o})`,width:n,height:o};case 3:return{matrix:`matrix(0, 1, -1, 0, ${n}, 0)`,width:o,height:n};default:return{matrix:"matrix(1, 0, 0, 1, 0, 0)",width:n,height:o}}}(o,i),c={style:{position:"absolute",left:o.origin.x,top:o.origin.y,transform:r,transformOrigin:"0 0",width:l,height:a,pointerEvents:"none",zIndex:3},onPointerDown:e=>e.stopPropagation()};return n.jsx(s.Fragment,{children:e({menuWrapperProps:c,matrix:r,rect:{origin:{x:o.origin.x,y:o.origin.y},size:{width:l,height:a}}})})}function d({rect:e,rotation:t,scale:i,vertices:r,onEdit:a,onCommit:c,handleSize:d=12}){const[u,h]=l.useState(null),p=l.useRef(null),g=l.useRef([]),y=e=>{const n=o.restoreOffset(e,t,i),r=[...g.current];return null!==u&&(r[u]={x:r[u].x+n.x,y:r[u].y+n.y}),r},x=e=>{if(null===u||!p.current)return;const t={x:e.clientX-p.current.x,y:e.clientY-p.current.y};a(y(t))},f=e=>{if(null===u||!p.current)return;e.target.releasePointerCapture(e.pointerId);const t={x:e.clientX-p.current.x,y:e.clientY-p.current.y};c(y(t)),h(null)};return n.jsx(s.Fragment,{children:r.map(((t,o)=>{const s=(t.x-e.origin.x)*i-d/2,l=(t.y-e.origin.y)*i-d/2;return n.jsx("div",{style:{position:"absolute",left:s,top:l,width:d,height:d,borderRadius:"50%",background:"#2196f3",cursor:"pointer",pointerEvents:"auto",zIndex:4},onPointerDown:(a=o,e=>{e.stopPropagation(),e.preventDefault(),h(a),p.current={x:e.clientX,y:e.clientY},g.current=r,e.target.setPointerCapture(e.pointerId)}),onPointerMove:x,onPointerUp:f},o);var a}))})}function u({scale:e,pageWidth:t,pageHeight:n,rotation:i,tracked:r,isSelected:s,isDraggable:a,isResizable:c,computePatch:d,computeVertices:u,currentRect:h,setCurrentRect:p,setCurrentVertices:g,setPreviewObject:y,commit:x}){const f=l.useRef("idle"),v=l.useRef("none"),k=l.useRef(null),m=l.useRef(null),b=(e,t,n)=>Math.max(t,Math.min(n,e)),M=t/e,w=n/e;return l.useEffect((()=>{f.current="idle",v.current="none",k.current=null,m.current=null}),[r]),{rootHandlers:{onPointerDown:e=>{s&&a&&(e.stopPropagation(),e.preventDefault(),f.current="dragging",k.current={x:e.clientX,y:e.clientY},m.current=h,e.currentTarget.setPointerCapture(e.pointerId))},onPointerMove:t=>{if("idle"===f.current||!k.current)return;const n={x:t.clientX-k.current.x,y:t.clientY-k.current.y},{x:s,y:l}=o.restoreOffset(n,i,e),a=((e,t)=>{if(!m.current)return h;let{origin:n,size:o}=m.current,i=n.x,r=n.y,s=o.width,l=o.height;return"dragging"===f.current?(i+=e,r+=t):"resizing"===f.current&&(v.current.includes("right")?s+=e:v.current.includes("left")&&(i+=e,s-=e),v.current.includes("bottom")?l+=t:v.current.includes("top")&&(r+=t,l-=t)),s<1||l<1?h:(s=b(s,1,M),l=b(l,1,w),i=b(i,0,M-s),r=b(r,0,w-l),{origin:{x:i,y:r},size:{width:s,height:l}})})(s,l);let c={rect:a};d&&(c=d(r.object,{rect:a,direction:"resizing"===f.current?v.current:"bottom-right"}),u&&g(u({...r.object,...c}))),p(c.rect??a),y(c)},onPointerUp:()=>{if("idle"===f.current)return;const e=v.current||"bottom-right";f.current="idle";let t={rect:h};d&&(t=d(r.object,{rect:h,direction:e})),x(t),k.current=null,m.current=null,v.current="none",y(null)}},startResize:e=>t=>{s&&c&&(t.stopPropagation(),t.preventDefault(),f.current="resizing",v.current=e,k.current={x:t.clientX,y:t.clientY},m.current=h,t.currentTarget.setPointerCapture(t.pointerId))}}}function h({rotation:e,outlineOffset:t=1,startResize:o}){const i=t;return n.jsxs(n.Fragment,{children:[n.jsx("div",{style:{position:"absolute",width:13,height:13,background:"blue",borderRadius:"50%",top:-7-i,left:-7-i,cursor:e%2?"nesw-resize":"nwse-resize"},onPointerDown:o("top-left")}),n.jsx("div",{style:{position:"absolute",width:13,height:13,background:"blue",borderRadius:"50%",top:-7-i,right:-7-i,cursor:e%2?"nwse-resize":"nesw-resize"},onPointerDown:o("top-right")}),n.jsx("div",{style:{position:"absolute",width:13,height:13,background:"blue",borderRadius:"50%",bottom:-7-i,left:-7-i,cursor:e%2?"nwse-resize":"nesw-resize"},onPointerDown:o("bottom-left")}),n.jsx("div",{style:{position:"absolute",width:13,height:13,background:"blue",borderRadius:"50%",bottom:-7-i,right:-7-i,cursor:e%2?"nesw-resize":"nwse-resize"},onPointerDown:o("bottom-right")})]})}function p({scale:e,pageIndex:t,rotation:i,pageWidth:r,pageHeight:p,trackedAnnotation:g,children:y,style:x,outlineOffset:f=1,isSelected:v=!1,isDraggable:k=!0,isResizable:m=!0,computeVertices:b,computePatch:M,selectionMenu:w,...P}){const{provides:S}=a(),[j,A]=l.useState(g.object.rect),[I,z]=l.useState((null==b?void 0:b(g.object))??[]),[C,D]=l.useState(null),{rootHandlers:E,startResize:W}=u({scale:e,pageWidth:r,pageHeight:p,rotation:i,tracked:g,isSelected:v,isDraggable:k,isResizable:m,computePatch:M,computeVertices:b,currentRect:j,setCurrentRect:A,setCurrentVertices:z,setPreviewObject:D,commit:e=>null==S?void 0:S.updateAnnotation(t,g.localId,e)});l.useLayoutEffect((()=>{o.rectEquals(g.object.rect,j)||(A(g.object.rect),D((e=>e?{...e,rect:g.object.rect}:null)),z((null==b?void 0:b(g.object))??[]))}),[g]);const B=C?{...g.object,...C}:g.object;return n.jsxs(s.Fragment,{children:[n.jsxs("div",{...E,style:{position:"absolute",outline:v?"1px solid #007ACC":"none",outlineOffset:v?`${f}px`:"0px",left:j.origin.x*e+"px",top:j.origin.y*e+"px",width:j.size.width*e+"px",height:j.size.height*e+"px",pointerEvents:v?"auto":"none",cursor:v&&k?"move":"default",...x},...P,children:["function"==typeof y?y(B):y,v&&I.length>0&&n.jsx(d,{rect:j,rotation:i,scale:e,vertices:I,onEdit:e=>{if(z(e),M){const t=M(g.object,{rect:j,vertices:e});D(t),A(t.rect||j)}},onCommit:e=>{if(S&&M){const n=M(g.object,{rect:j,vertices:e});S.updateAnnotation(t,g.localId,n)}}}),v&&m&&n.jsx(h,{rotation:i,outlineOffset:f,startResize:W})]}),n.jsx(c,{rect:{origin:{x:j.origin.x*e,y:j.origin.y*e},size:{width:j.size.width*e,height:j.size.height*e}},rotation:i,children:({rect:e,menuWrapperProps:t})=>w&&w({annotation:g,selected:v,rect:e,menuWrapperProps:t})})]})}function g({color:e="#FFFF00",opacity:t=.5,rects:o,rect:i,scale:r,onClick:s,style:l,...a}){return n.jsx(n.Fragment,{children:o.map(((o,c)=>n.jsx("div",{onMouseDown:s,style:{position:"absolute",left:(i?o.origin.x-i.origin.x:o.origin.x)*r,top:(i?o.origin.y-i.origin.y:o.origin.y)*r,width:o.size.width*r,height:o.size.height*r,background:e,opacity:t,pointerEvents:s?"auto":"none",cursor:s?"pointer":"default",zIndex:s?1:void 0,...l},...a},c)))})}function y({color:e="#FFFF00",opacity:t=.5,rects:o,rect:i,scale:r,onClick:s,style:l,...a}){const c=2*r;return n.jsx(n.Fragment,{children:o.map(((o,d)=>n.jsx("div",{onMouseDown:s,style:{position:"absolute",left:(i?o.origin.x-i.origin.x:o.origin.x)*r,top:(i?o.origin.y-i.origin.y:o.origin.y)*r,width:o.size.width*r,height:o.size.height*r,background:"transparent",pointerEvents:s?"auto":"none",cursor:s?"pointer":"default",zIndex:s?1:0,...l},...a,children:n.jsx("div",{style:{position:"absolute",left:0,bottom:0,width:"100%",height:c,background:e,opacity:t,pointerEvents:"none"}})},d)))})}function x({color:e="#FFFF00",opacity:t=.5,rects:o,rect:i,scale:r,onClick:s,style:l,...a}){const c=2*r;return n.jsx(n.Fragment,{children:o.map(((o,d)=>n.jsx("div",{onMouseDown:s,style:{position:"absolute",left:(i?o.origin.x-i.origin.x:o.origin.x)*r,top:(i?o.origin.y-i.origin.y:o.origin.y)*r,width:o.size.width*r,height:o.size.height*r,background:"transparent",pointerEvents:s?"auto":"none",cursor:s?"pointer":"default",zIndex:s?1:0,...l},...a,children:n.jsx("div",{style:{position:"absolute",left:0,top:"50%",width:"100%",height:c,background:e,opacity:t,transform:"translateY(-50%)",pointerEvents:"none"}})},d)))})}function f({color:e="#FFFF00",opacity:t=.5,rects:o,rect:i,scale:r,onClick:s,style:l,...a}){const c=2*r,d=6*r,u=`url("data:image/svg+xml;utf8,${encodeURIComponent(`<svg xmlns="http://www.w3.org/2000/svg" width="${d}" height="${2*c}" viewBox="0 0 ${d} ${2*c}">\n <path d="M0 ${c} Q ${d/4} 0 ${d/2} ${c} T ${d} ${c}"\n fill="none" stroke="${e}" stroke-width="${c}" stroke-linecap="round"/>\n </svg>`)}")`;return n.jsx(n.Fragment,{children:o.map(((e,o)=>n.jsx("div",{onMouseDown:s,style:{position:"absolute",left:(i?e.origin.x-i.origin.x:e.origin.x)*r,top:(i?e.origin.y-i.origin.y:e.origin.y)*r,width:e.size.width*r,height:e.size.height*r,background:"transparent",pointerEvents:s?"auto":"none",cursor:s?"pointer":"default",zIndex:s?1:0,...l},...a,children:n.jsx("div",{style:{position:"absolute",left:0,bottom:0,width:"100%",height:2*c,backgroundImage:u,backgroundRepeat:"repeat-x",backgroundSize:`${d}px ${2*c}px`,opacity:t,pointerEvents:"none"}})},o)))})}function v({color:e="#000000",opacity:t=1,strokeWidth:o,inkList:i,rect:r,scale:s,onClick:a,cursor:c}){const d=l.useMemo((()=>i.map((({points:e})=>{let t="";return e.forEach((({x:e,y:n},o)=>{const i=e-r.origin.x,s=n-r.origin.y;t+=(0===o?"M":"L")+i+" "+s+" "})),t.trim()}))),[i,r]),u=r.size.width*s,h=r.size.height*s;return n.jsx("svg",{style:{position:"absolute",width:u,height:h,pointerEvents:"none",zIndex:2,overflow:"visible"},width:u,height:h,viewBox:`0 0 ${r.size.width} ${r.size.height}`,children:d.map(((i,r)=>n.jsx("path",{d:i,fill:"none",opacity:t,onMouseDown:a,style:{cursor:c,pointerEvents:"visibleStroke",stroke:e,strokeWidth:o,strokeLinecap:"round",strokeLinejoin:"round"}},r)))})}function k({color:e="#000000",strokeColor:t,opacity:i=1,strokeWidth:r,strokeStyle:s=o.PdfAnnotationBorderStyle.SOLID,strokeDashArray:a,rect:c,scale:d,onClick:u,cursor:h}){const{width:p,height:g,x:y,y:x}=l.useMemo((()=>{const e=c.size.width,t=c.size.height;return{width:Math.max(e-r,0),height:Math.max(t-r,0),x:r/2,y:r/2}}),[c,r]),f=(p+r)*d,v=(g+r)*d;return n.jsx("svg",{style:{position:"absolute",width:f,height:v,pointerEvents:"none",zIndex:2},width:f,height:v,viewBox:`0 0 ${p+r} ${g+r}`,children:n.jsx("rect",{x:y,y:x,width:p,height:g,fill:e,opacity:i,onMouseDown:u,style:{cursor:h,pointerEvents:"transparent"===e?"visibleStroke":"visible",stroke:t??e,strokeWidth:r,...s===o.PdfAnnotationBorderStyle.DASHED&&{strokeDasharray:null==a?void 0:a.join(",")}}})})}function m({color:e="#000000",strokeColor:t,opacity:i=1,strokeWidth:r,strokeStyle:s=o.PdfAnnotationBorderStyle.SOLID,strokeDashArray:a,rect:c,scale:d,onClick:u,cursor:h}){const{width:p,height:g,cx:y,cy:x,rx:f,ry:v}=l.useMemo((()=>{const e=c.size.width,t=c.size.height,n=Math.max(e-r,0),o=Math.max(t-r,0);return{width:e,height:t,cx:r/2+n/2,cy:r/2+o/2,rx:n/2,ry:o/2}}),[c,r]),k=p*d,m=g*d;return n.jsx("svg",{style:{position:"absolute",width:k,height:m,pointerEvents:"none",zIndex:2},width:k,height:m,viewBox:`0 0 ${p} ${g}`,children:n.jsx("ellipse",{cx:y,cy:x,rx:f,ry:v,fill:e,opacity:i,onMouseDown:u,style:{cursor:h,pointerEvents:"transparent"===e?"visibleStroke":"visible",stroke:t??e,strokeWidth:r,...s===o.PdfAnnotationBorderStyle.DASHED&&{strokeDasharray:null==a?void 0:a.join(",")}}})})}const b=(e,t)=>{if(e.type!==o.PdfAnnotationSubtype.INK)throw new Error("resizeInkAnnotation: original is not an ink annotation");const n=e.rect;let i=t.rect.size.width/n.size.width,r=t.rect.size.height/n.size.height;if((t.rect.size.width<10||t.rect.size.height<10)&&(i=Math.max(i,10/n.size.width),r=Math.max(r,10/n.size.height),t.rect={origin:t.rect.origin,size:{width:n.size.width*i,height:n.size.height*r}}),t.uniform){const e=Math.min(i,r);i=e,r=e,t.rect.size={width:n.size.width*e,height:n.size.height*e}}const s=e.inkList.map((e=>({points:e.points.map((e=>({x:t.rect.origin.x+(e.x-n.origin.x)*i,y:t.rect.origin.y+(e.y-n.origin.y)*r})))}))),l=(i+r)/2,a=Math.round(e.strokeWidth*l);return{rect:t.rect,inkList:s,strokeWidth:a}};function M({color:e="transparent",opacity:i=1,strokeWidth:r,strokeColor:s="#000000",strokeStyle:a=o.PdfAnnotationBorderStyle.SOLID,strokeDashArray:c,rect:d,linePoints:u,lineEndings:h,scale:p,onClick:g,isSelected:y}){const{x1:x,y1:f,x2:v,y2:k}=l.useMemo((()=>({x1:u.start.x-d.origin.x,y1:u.start.y-d.origin.y,x2:u.end.x-d.origin.x,y2:u.end.y-d.origin.y})),[u,d]),m=l.useMemo((()=>{const e=Math.atan2(k-f,v-x);return{start:t.patching.createEnding(null==h?void 0:h.start,r,e+Math.PI,x,f),end:t.patching.createEnding(null==h?void 0:h.end,r,e,v,k)}}),[h,r,x,f,v,k]),b=d.size.width*p,M=d.size.height*p;return n.jsxs("svg",{style:{position:"absolute",width:b,height:M,pointerEvents:"none",zIndex:2,overflow:"visible"},width:b,height:M,viewBox:`0 0 ${d.size.width} ${d.size.height}`,children:[n.jsx("line",{x1:x,y1:f,x2:v,y2:k,opacity:i,onMouseDown:g,style:{cursor:y?"move":"pointer",pointerEvents:"visibleStroke",stroke:s,strokeWidth:r,strokeLinecap:"butt",...a===o.PdfAnnotationBorderStyle.DASHED&&{strokeDasharray:null==c?void 0:c.join(",")}}}),m.start&&n.jsx("path",{d:m.start.d,transform:m.start.transform,onMouseDown:g,stroke:s,style:{cursor:y?"move":"pointer",strokeWidth:r,strokeLinecap:"butt",pointerEvents:m.start.filled?"visible":"visibleStroke",...a===o.PdfAnnotationBorderStyle.DASHED&&{strokeDasharray:null==c?void 0:c.join(",")}},fill:m.start.filled?e:"none"}),m.end&&n.jsx("path",{d:m.end.d,transform:m.end.transform,stroke:s,onMouseDown:g,style:{cursor:y?"move":"pointer",strokeWidth:r,strokeLinecap:"butt",pointerEvents:m.end.filled?"visible":"visibleStroke",...a===o.PdfAnnotationBorderStyle.DASHED&&{strokeDasharray:null==c?void 0:c.join(",")}},fill:m.end.filled?e:"none"})]})}function w({rect:e,vertices:o,color:i="transparent",strokeColor:r="#000000",opacity:s=1,strokeWidth:a,scale:c,isSelected:d,onClick:u,lineEndings:h}){const p=l.useMemo((()=>o.map((({x:t,y:n})=>({x:t-e.origin.x,y:n-e.origin.y})))),[o,e]),g=l.useMemo((()=>{if(!p.length)return"";const[e,...t]=p;return`M ${e.x} ${e.y} `+t.map((e=>`L ${e.x} ${e.y} `)).join("").trim()}),[p]),y=l.useMemo((()=>{if(p.length<2)return{start:null,end:null};const e=(e,t)=>Math.atan2(t.y-e.y,t.x-e.x),n=e(p[1],p[0]),o=e(p[p.length-2],p[p.length-1]);return{start:t.patching.createEnding(null==h?void 0:h.start,a,n+Math.PI,p[0].x,p[0].y),end:t.patching.createEnding(null==h?void 0:h.end,a,o,p[p.length-1].x,p[p.length-1].y)}}),[p,h,a]),x=e.size.width*c,f=e.size.height*c;return n.jsxs("svg",{style:{position:"absolute",width:x,height:f,pointerEvents:"none",zIndex:2,overflow:"visible"},width:x,height:f,viewBox:`0 0 ${e.size.width} ${e.size.height}`,children:[n.jsx("path",{d:g,onMouseDown:u,opacity:s,style:{fill:"none",stroke:r??i,strokeWidth:a,cursor:d?"move":"pointer",pointerEvents:"visibleStroke",strokeLinecap:"butt",strokeLinejoin:"miter"}}),y.start&&n.jsx("path",{d:y.start.d,transform:y.start.transform,stroke:r,fill:y.start.filled?i:"none",onMouseDown:u,style:{cursor:d?"move":"pointer",strokeWidth:a,pointerEvents:y.start.filled?"visible":"visibleStroke",strokeLinecap:"butt"}}),y.end&&n.jsx("path",{d:y.end.d,transform:y.end.transform,stroke:r,fill:y.end.filled?i:"none",onMouseDown:u,style:{cursor:d?"move":"pointer",strokeWidth:a,pointerEvents:y.end.filled?"visible":"visibleStroke",strokeLinecap:"butt"}})]})}function P({rect:e,vertices:t,color:i="transparent",strokeColor:r="#000000",opacity:s=1,strokeWidth:a,strokeStyle:c=o.PdfAnnotationBorderStyle.SOLID,strokeDashArray:d,scale:u,isSelected:h,onClick:p}){const g=l.useMemo((()=>t.map((({x:t,y:n})=>({x:t-e.origin.x,y:n-e.origin.y})))),[t,e]),y=l.useMemo((()=>{if(!g.length)return"";const[e,...t]=g;return(`M ${e.x} ${e.y} `+t.map((e=>`L ${e.x} ${e.y} `)).join("")+"Z").trim()}),[g]),x=e.size.width*u,f=e.size.height*u;return n.jsx("svg",{style:{position:"absolute",width:x,height:f,pointerEvents:"none",zIndex:2,overflow:"visible"},width:x,height:f,viewBox:`0 0 ${e.size.width} ${e.size.height}`,children:n.jsx("path",{d:y,onMouseDown:p,opacity:s,style:{fill:i,stroke:r??i,strokeWidth:a,cursor:h?"move":"pointer",pointerEvents:"transparent"===i?"visibleStroke":"visible",strokeLinecap:"butt",strokeLinejoin:"miter",...c===o.PdfAnnotationBorderStyle.DASHED&&{strokeDasharray:null==d?void 0:d.join(",")}}})})}const S=(e,n)=>{if(n.vertices&&n.vertices.length>=2){return{rect:t.patching.lineRectWithEndings(n.vertices,e.strokeWidth,e.lineEndings),linePoints:{start:n.vertices[0],end:n.vertices[1]}}}const o=n.rect.origin.x-e.rect.origin.x,i=n.rect.origin.y-e.rect.origin.y;return{rect:n.rect,linePoints:{start:{x:e.linePoints.start.x+o,y:e.linePoints.start.y+i},end:{x:e.linePoints.end.x+o,y:e.linePoints.end.y+i}}}},j=(e,n)=>{if(n.vertices&&n.vertices.length)return{rect:t.patching.lineRectWithEndings(n.vertices,e.strokeWidth,e.lineEndings),vertices:n.vertices};const o=n.rect.origin.x-e.rect.origin.x,i=n.rect.origin.y-e.rect.origin.y,r=e.vertices.map((e=>({x:e.x+o,y:e.y+i})));return{rect:n.rect,vertices:r}},A=(e,t)=>{if(t.vertices&&t.vertices.length){const n=e.strokeWidth/2;return{rect:o.expandRect(o.rectFromPoints(t.vertices),n),vertices:t.vertices}}const n=t.rect.origin.x-e.rect.origin.x,i=t.rect.origin.y-e.rect.origin.y,r=e.vertices.map((e=>({x:e.x+n,y:e.y+i})));return{rect:t.rect,vertices:r}};function I(e){const{pageIndex:c,scale:d,selectionMenu:u}=e,{provides:h}=a(),{provides:I}=r.useSelectionCapability(),[z,C]=l.useState([]),{register:D}=i.usePointerHandlers({pageIndex:c}),[E,W]=l.useState(null);l.useEffect((()=>{h&&h.onStateChange((e=>{C(t.getAnnotationsByPageIndex(e,c)),W(t.getSelectedAnnotationByPageIndex(e,c))}))}),[h]);const B=l.useMemo((()=>({onPointerDown:(e,t)=>{t.target===t.currentTarget&&h&&h.deselectAnnotation()}})),[h]),R=l.useCallback(((e,t)=>{e.stopPropagation(),h&&I&&(h.selectAnnotation(c,t.localId),I.clear())}),[h,I,c]);return l.useEffect((()=>D(B)),[D,B]),n.jsx(n.Fragment,{children:z.map((i=>{const r=(null==E?void 0:E.localId)===i.localId;return t.isInk(i)?n.jsx(p,{trackedAnnotation:i,isSelected:r,isDraggable:!0,isResizable:!0,selectionMenu:u,computePatch:b,style:{mixBlendMode:o.blendModeToCss(i.object.blendMode??o.PdfBlendMode.Normal)},...e,children:e=>n.jsx(v,{cursor:r?"move":"pointer",color:e.color,opacity:e.opacity,strokeWidth:e.strokeWidth,inkList:e.inkList,rect:e.rect,scale:d,onClick:e=>R(e,i)})},i.localId):t.isSquare(i)?n.jsx(p,{trackedAnnotation:i,isSelected:r,isDraggable:!0,isResizable:!0,selectionMenu:u,style:{mixBlendMode:o.blendModeToCss(i.object.blendMode??o.PdfBlendMode.Normal)},...e,children:e=>n.jsx(k,{cursor:r?"move":"pointer",rect:e.rect,color:e.color,opacity:e.opacity,strokeWidth:e.strokeWidth,strokeColor:e.strokeColor,strokeStyle:e.strokeStyle,strokeDashArray:e.strokeDashArray,scale:d,onClick:e=>R(e,i)})},i.localId):t.isCircle(i)?n.jsx(p,{trackedAnnotation:i,isSelected:r,isDraggable:!0,isResizable:!0,selectionMenu:u,style:{mixBlendMode:o.blendModeToCss(i.object.blendMode??o.PdfBlendMode.Normal)},...e,children:e=>n.jsx(m,{cursor:r?"move":"pointer",rect:e.rect,color:e.color,opacity:e.opacity,strokeWidth:e.strokeWidth,strokeColor:e.strokeColor,strokeStyle:e.strokeStyle,strokeDashArray:e.strokeDashArray,scale:d,onClick:e=>R(e,i)})},i.localId):t.isUnderline(i)?n.jsx(p,{trackedAnnotation:i,isSelected:r,isDraggable:!1,isResizable:!1,selectionMenu:u,style:{mixBlendMode:o.blendModeToCss(i.object.blendMode??o.PdfBlendMode.Normal)},...e,children:e=>n.jsx(y,{rect:e.rect,color:e.color,opacity:e.opacity,rects:e.segmentRects,scale:d,onClick:e=>R(e,i)})},i.localId):t.isStrikeout(i)?n.jsx(p,{trackedAnnotation:i,isSelected:r,isDraggable:!1,isResizable:!1,selectionMenu:u,style:{mixBlendMode:o.blendModeToCss(i.object.blendMode??o.PdfBlendMode.Normal)},...e,children:e=>n.jsx(x,{rect:e.rect,color:e.color,opacity:e.opacity,rects:e.segmentRects,scale:d,onClick:e=>R(e,i)})},i.localId):t.isSquiggly(i)?n.jsx(p,{trackedAnnotation:i,isSelected:r,isDraggable:!1,isResizable:!1,selectionMenu:u,style:{mixBlendMode:o.blendModeToCss(i.object.blendMode??o.PdfBlendMode.Normal)},...e,children:e=>n.jsx(f,{color:e.color,opacity:e.opacity,rects:e.segmentRects,rect:e.rect,scale:d,onClick:e=>R(e,i)})},i.localId):t.isHighlight(i)?n.jsx(p,{trackedAnnotation:i,isSelected:r,isDraggable:!1,isResizable:!1,selectionMenu:u,style:{mixBlendMode:o.blendModeToCss(i.object.blendMode??o.PdfBlendMode.Multiply)},...e,children:e=>n.jsx(g,{color:e.color,opacity:e.opacity,rects:e.segmentRects,scale:d,rect:e.rect,onClick:e=>R(e,i)})},i.localId):t.isLine(i)?n.jsx(p,{trackedAnnotation:i,isSelected:r,isDraggable:!0,isResizable:!1,selectionMenu:u,computePatch:S,computeVertices:e=>[e.linePoints.start,e.linePoints.end],style:{mixBlendMode:o.blendModeToCss(i.object.blendMode??o.PdfBlendMode.Normal)},...e,children:e=>n.jsx(s.Fragment,{children:n.jsx(M,{isSelected:r,rect:e.rect,color:e.color,opacity:e.opacity,linePoints:e.linePoints,lineEndings:e.lineEndings,strokeWidth:e.strokeWidth,strokeColor:e.strokeColor,strokeStyle:e.strokeStyle,strokeDashArray:e.strokeDashArray,scale:d,onClick:e=>R(e,i)})})},i.localId):t.isPolyline(i)?n.jsx(p,{trackedAnnotation:i,isSelected:r,isDraggable:!0,isResizable:!1,selectionMenu:u,computePatch:j,computeVertices:e=>e.vertices,style:{mixBlendMode:o.blendModeToCss(i.object.blendMode??o.PdfBlendMode.Normal)},...e,children:e=>n.jsx(s.Fragment,{children:n.jsx(w,{isSelected:r,rect:e.rect,color:e.color,opacity:e.opacity,vertices:e.vertices,lineEndings:e.lineEndings,strokeWidth:e.strokeWidth,strokeColor:e.strokeColor,scale:d,onClick:e=>R(e,i)})})},i.localId):t.isPolygon(i)?n.jsx(p,{trackedAnnotation:i,isSelected:r,isDraggable:!0,isResizable:!1,selectionMenu:u,computeVertices:e=>e.vertices,computePatch:A,style:{mixBlendMode:o.blendModeToCss(i.object.blendMode??o.PdfBlendMode.Normal)},...e,children:e=>n.jsx(s.Fragment,{children:n.jsx(P,{isSelected:r,rect:e.rect,color:e.color,opacity:e.opacity,vertices:e.vertices,strokeWidth:e.strokeWidth,strokeColor:e.strokeColor,strokeStyle:e.strokeStyle,strokeDashArray:e.strokeDashArray,scale:d,onClick:e=>R(e,i)})})},i.localId):null}))})}function z({pageIndex:e,scale:i}){var s,c,d,u,h,p,v,k,m,b,M,w;const{provides:P}=r.useSelectionCapability(),{provides:S}=a(),[j,A]=l.useState([]),[I,z]=l.useState(null),[C,D]=l.useState({variantKey:null,defaults:null});if(l.useEffect((()=>{if(!P)return;return P.onSelectionChange((()=>{A(P.getHighlightRectsForPage(e)),z(P.getBoundingRectForPage(e))}))}),[P,e]),l.useEffect((()=>{if(!S)return;return S.onActiveToolChange(D)}),[S]),!I)return null;switch(C.variantKey){case t.makeVariantKey(o.PdfAnnotationSubtype.UNDERLINE):return n.jsx("div",{style:{mixBlendMode:o.blendModeToCss((null==(s=C.defaults)?void 0:s.blendMode)??o.PdfBlendMode.Normal),pointerEvents:"none",position:"absolute",inset:0},children:n.jsx(y,{color:null==(c=C.defaults)?void 0:c.color,opacity:null==(d=C.defaults)?void 0:d.opacity,rects:j,scale:i})});case t.makeVariantKey(o.PdfAnnotationSubtype.HIGHLIGHT):return n.jsx("div",{style:{mixBlendMode:o.blendModeToCss((null==(u=C.defaults)?void 0:u.blendMode)??o.PdfBlendMode.Multiply),pointerEvents:"none",position:"absolute",inset:0},children:n.jsx(g,{color:null==(h=C.defaults)?void 0:h.color,opacity:null==(p=C.defaults)?void 0:p.opacity,rects:j,scale:i})});case t.makeVariantKey(o.PdfAnnotationSubtype.STRIKEOUT):return n.jsx("div",{style:{mixBlendMode:o.blendModeToCss((null==(v=C.defaults)?void 0:v.blendMode)??o.PdfBlendMode.Normal),pointerEvents:"none",position:"absolute",inset:0},children:n.jsx(x,{color:null==(k=C.defaults)?void 0:k.color,opacity:null==(m=C.defaults)?void 0:m.opacity,rects:j,scale:i})});case t.makeVariantKey(o.PdfAnnotationSubtype.SQUIGGLY):return n.jsx("div",{style:{mixBlendMode:o.blendModeToCss((null==(b=C.defaults)?void 0:b.blendMode)??o.PdfBlendMode.Normal),pointerEvents:"none",position:"absolute",inset:0},children:n.jsx(f,{color:null==(M=C.defaults)?void 0:M.color,opacity:null==(w=C.defaults)?void 0:w.opacity,rects:j,scale:i})});default:return null}}const C=({pageIndex:e,scale:t,pageWidth:r,pageHeight:s})=>{var c,d,u,h,p;const{provides:g}=a(),[y,x]=l.useState({variantKey:null,defaults:null});if(l.useEffect((()=>{if(!g)return;return g.onActiveToolChange(x)}),[g]),!y.defaults)return null;if(y.defaults.subtype!==o.PdfAnnotationSubtype.INK)return null;const f=(null==(c=y.defaults)?void 0:c.color)??"#000000",v=(null==(d=y.defaults)?void 0:d.opacity)??1,k=(null==(u=y.defaults)?void 0:u.strokeWidth)??2,m=(null==(h=y.defaults)?void 0:h.blendMode)??o.PdfBlendMode.Normal,b=null==(p=y.defaults)?void 0:p.intent,{register:M}=i.usePointerHandlers({modeId:"ink",pageIndex:e}),w=(e,t,n)=>Math.max(t,Math.min(n,e)),[P,S]=l.useState([]),[j,A]=l.useState(!1),I=l.useRef(null),z=r/t,C=s/t,D=l.useMemo((()=>({onPointerDown:(e,t)=>{var n,o;const i=w(e.x,0,z),r=w(e.y,0,C);A(!0),I.current?(clearTimeout(I.current),I.current=null,S((e=>[...e,{points:[{x:i,y:r}]}]))):S([{points:[{x:i,y:r}]}]),null==(o=null==(n=t.target)?void 0:n.setPointerCapture)||o.call(n,t.pointerId)},onPointerMove:e=>{if(!j)return;const t=w(e.x,0,z),n=w(e.y,0,C);S((e=>{if(!e.length)return e;const o={points:[...e[e.length-1].points,{x:t,y:n}]};return[...e.slice(0,-1),o]}))},onPointerUp:(t,n)=>{var i,r;A(!1),null==(r=null==(i=n.target)?void 0:i.releasePointerCapture)||r.call(i,n.pointerId),I.current&&clearTimeout(I.current),I.current=setTimeout((()=>{if(P.length&&g){const t=P.flatMap((e=>e.points));if(!t.length)return;const n=o.expandRect(o.rectFromPoints(t),k/2);if(n.size.width<1||n.size.height<1)return;const i={type:o.PdfAnnotationSubtype.INK,intent:b,blendMode:m,rect:n,inkList:P,color:f,opacity:v,strokeWidth:k,pageIndex:e,id:Date.now()+Math.random()};g.createAnnotation(e,i),g.setActiveVariant(null),g.selectAnnotation(e,i.id)}S([]),I.current=null}),3e3)},onPointerCancel:(e,t)=>{var n,o;A(!1),null==(o=null==(n=t.target)?void 0:n.releasePointerCapture)||o.call(n,t.pointerId),S([]),I.current&&(clearTimeout(I.current),I.current=null)}})),[z,C,P,g,e,f,v,k,j]);if(l.useEffect((()=>{if(M)return M(D)}),[M,D]),l.useEffect((()=>()=>{I.current&&clearTimeout(I.current)}),[]),!P.length)return null;const E=P.flatMap((e=>e.points));if(!E.length)return null;const W=o.expandRect(o.rectFromPoints(E),k/2),B=P.map((({points:e})=>{let t="";return e.forEach((({x:e,y:n},o)=>{const i=e-W.origin.x,r=n-W.origin.y;t+=(0===o?"M":"L")+i+" "+r+" "})),t.trim()}));return n.jsx("svg",{style:{position:"absolute",left:W.origin.x*t,top:W.origin.y*t,width:W.size.width*t,height:W.size.height*t,pointerEvents:"none",zIndex:2},width:W.size.width*t,height:W.size.height*t,viewBox:`0 0 ${W.size.width} ${W.size.height}`,children:B.map(((e,t)=>n.jsx("path",{d:e,fill:"none",opacity:v,style:{stroke:f,strokeWidth:k,strokeLinecap:"round",strokeLinejoin:"round"}},t)))})},D=({pageIndex:e,scale:t,pageWidth:r,pageHeight:s,cursor:c})=>{const{provides:d}=a(),[u,h]=l.useState({variantKey:null,defaults:null});if(l.useEffect((()=>{if(d)return d.onActiveToolChange(h)}),[d]),!u.defaults)return null;if(u.defaults.subtype!==o.PdfAnnotationSubtype.CIRCLE)return null;const p=u.defaults.color??"#000000",g=u.defaults.opacity??1,y=u.defaults.strokeWidth??2,x=u.defaults.strokeColor??"#000000",f=u.defaults.strokeStyle??o.PdfAnnotationBorderStyle.SOLID,v=u.defaults.strokeDashArray??[],{register:k}=i.usePointerHandlers({modeId:"circle",pageIndex:e}),m=(e,t,n)=>Math.max(t,Math.min(n,e)),b=r/t,M=s/t,[w,P]=l.useState(null),[S,j]=l.useState(null),A=l.useMemo((()=>({onPointerDown:(e,t)=>{var n,o;const i=m(e.x,0,b),r=m(e.y,0,M);P({x:i,y:r}),j({x:i,y:r}),null==(o=null==(n=t.target)?void 0:n.setPointerCapture)||o.call(n,t.pointerId)},onPointerMove:e=>{if(!w)return;const t=m(e.x,0,b),n=m(e.y,0,M);j({x:t,y:n})},onPointerUp:(t,n)=>{var i,r;if(w&&S&&d){const t=Math.min(w.x,S.x),n=Math.min(w.y,S.y),i=Math.max(w.x,S.x),r=Math.max(w.y,S.y);if(i-t>=1&&r-n>=1){const s=y/2,l={origin:{x:t-s,y:n-s},size:{width:i-t+y,height:r-n+y}},a={type:o.PdfAnnotationSubtype.CIRCLE,rect:l,flags:["print"],color:p,opacity:g,strokeWidth:y,strokeColor:x,strokeStyle:f,strokeDashArray:v,pageIndex:e,id:Date.now()+Math.random()};d.createAnnotation(e,a),d.setActiveVariant(null),d.selectAnnotation(e,a.id)}}null==(r=null==(i=n.target)?void 0:i.releasePointerCapture)||r.call(i,n.pointerId),P(null),j(null)},onPointerCancel:(e,t)=>{var n,o;null==(o=null==(n=t.target)?void 0:n.releasePointerCapture)||o.call(n,t.pointerId),P(null),j(null)}})),[w,S,d,e,b,M,p,g,y]);if(l.useEffect((()=>k?k(A):void 0),[k,A]),!w||!S)return null;const I=Math.min(w.x,S.x),z=Math.min(w.y,S.y),C=Math.max(w.x,S.x),D=Math.max(w.y,S.y),E=y/2,W=I-E,B=z-E,R=C-I,$=D-z,L=R+y,H=$+y,T=E+R/2,F=E+$/2,O=R/2,N=$/2;return n.jsx("svg",{style:{position:"absolute",left:W*t,top:B*t,width:L*t,height:H*t,pointerEvents:"none",zIndex:2},width:L*t,height:H*t,viewBox:`0 0 ${L} ${H}`,children:n.jsx("ellipse",{cx:T,cy:F,rx:O,ry:N,fill:p,opacity:g,style:{cursor:c,stroke:x,strokeWidth:y,...f===o.PdfAnnotationBorderStyle.DASHED&&{strokeDasharray:v.join(",")}}})})},E=({pageIndex:e,scale:t,pageWidth:r,pageHeight:s,cursor:c})=>{const{provides:d}=a(),[u,h]=l.useState({variantKey:null,defaults:null});if(l.useEffect((()=>{if(d)return d.onActiveToolChange(h)}),[d]),!u.defaults)return null;if(u.defaults.subtype!==o.PdfAnnotationSubtype.SQUARE)return null;const p=u.defaults.color??"#000000",g=u.defaults.opacity??1,y=u.defaults.strokeWidth??2,x=u.defaults.strokeColor??"#000000",f=u.defaults.strokeStyle??o.PdfAnnotationBorderStyle.SOLID,v=u.defaults.strokeDashArray??[],{register:k}=i.usePointerHandlers({modeId:"square",pageIndex:e}),m=(e,t,n)=>Math.max(t,Math.min(n,e)),b=r/t,M=s/t,[w,P]=l.useState(null),[S,j]=l.useState(null),A=l.useMemo((()=>({onPointerDown:(e,t)=>{var n,o;const i=m(e.x,0,b),r=m(e.y,0,M);P({x:i,y:r}),j({x:i,y:r}),null==(o=null==(n=t.target)?void 0:n.setPointerCapture)||o.call(n,t.pointerId)},onPointerMove:e=>{if(!w)return;const t=m(e.x,0,b),n=m(e.y,0,M);j({x:t,y:n})},onPointerUp:(t,n)=>{var i,r;if(w&&S&&d){const t=Math.min(w.x,S.x),n=Math.min(w.y,S.y),i=Math.max(w.x,S.x),r=Math.max(w.y,S.y);if(i-t>=1&&r-n>=1){const s=y/2,l={origin:{x:t-s,y:n-s},size:{width:i-t+y,height:r-n+y}},a={type:o.PdfAnnotationSubtype.SQUARE,rect:l,flags:["print"],color:p,opacity:g,strokeWidth:y,strokeColor:x,strokeStyle:f,strokeDashArray:v,pageIndex:e,id:Date.now()+Math.random()};d.createAnnotation(e,a),d.setActiveVariant(null),d.selectAnnotation(e,a.id)}}null==(r=null==(i=n.target)?void 0:i.releasePointerCapture)||r.call(i,n.pointerId),P(null),j(null)},onPointerCancel:(e,t)=>{var n,o;null==(o=null==(n=t.target)?void 0:n.releasePointerCapture)||o.call(n,t.pointerId),P(null),j(null)}})),[w,S,d,e,b,M,p,g,y]);if(l.useEffect((()=>k?k(A):void 0),[k,A]),!w||!S)return null;const I=Math.min(w.x,S.x),z=Math.min(w.y,S.y),C=Math.max(w.x,S.x),D=Math.max(w.y,S.y),E=y/2,W=I-E,B=z-E,R=C-I,$=D-z,L=R+y,H=$+y;return n.jsx("svg",{style:{position:"absolute",left:W*t,top:B*t,width:L*t,height:H*t,pointerEvents:"none",zIndex:2},width:L*t,height:H*t,viewBox:`0 0 ${L} ${H}`,children:n.jsx("rect",{x:E,y:E,width:R,height:$,fill:p,opacity:g,style:{cursor:c,stroke:x,strokeWidth:y,...f===o.PdfAnnotationBorderStyle.DASHED&&{strokeDasharray:v.join(",")}}})})},W=({pageIndex:e,scale:r,pageWidth:s,pageHeight:c,cursor:d})=>{const{provides:u}=a(),[h,p]=l.useState({variantKey:null,defaults:null});if(l.useEffect((()=>{if(u)return u.onActiveToolChange(p)}),[u]),!h.defaults)return null;if(h.defaults.subtype!==o.PdfAnnotationSubtype.POLYLINE)return null;const g=h.defaults.color??"#000000",y=h.defaults.opacity??1,x=h.defaults.strokeWidth??2,f=h.defaults.strokeColor??"#000000",v=h.defaults.lineEndings,k=h.defaults.strokeStyle??o.PdfAnnotationBorderStyle.SOLID,m=h.defaults.strokeDashArray,{register:b}=i.usePointerHandlers({modeId:"polyline",pageIndex:e}),M=(e,t,n)=>Math.max(t,Math.min(n,e)),P=s/r,S=c/r,[j,A]=l.useState([]),[I,z]=l.useState(null),C=l.useMemo((()=>({onClick:e=>{const t=M(e.x,0,P),n=M(e.y,0,S);A((e=>[...e,{x:t,y:n}])),z({x:t,y:n})},onDoubleClick:()=>{j.length>=1&&u&&(n=>{if(n.length<2)return;const i=t.patching.lineRectWithEndings(n,x,v),r={type:o.PdfAnnotationSubtype.POLYLINE,rect:i,vertices:n,color:g,opacity:y,strokeWidth:x,strokeColor:f,strokeStyle:k,strokeDashArray:m,lineEndings:v,pageIndex:e,id:Date.now()+Math.random()};u.createAnnotation(e,r),u.setActiveVariant(null),u.selectAnnotation(e,r.id)})(j),A([]),z(null)},onPointerMove:e=>{if(!j.length)return;const t=M(e.x,0,P),n=M(e.y,0,S);z({x:t,y:n})},onPointerCancel:()=>{A([]),z(null)}})),[j,u,P,S]);if(l.useEffect((()=>b?b(C):void 0),[b,C]),!j.length||!I)return null;const D=[...j,I],E=t.patching.lineRectWithEndings(D,x,v);return n.jsx("div",{style:{position:"absolute",left:E.origin.x*r,top:E.origin.y*r,width:E.size.width*r,height:E.size.height*r,pointerEvents:"none",zIndex:2,overflow:"visible",cursor:d},children:n.jsx(w,{rect:E,vertices:D,strokeWidth:x,scale:r,isSelected:!1,color:g,strokeColor:f,opacity:y,lineEndings:v})})},B=({pageIndex:e,scale:r,pageWidth:s,pageHeight:c,cursor:d})=>{const{provides:u}=a(),[h,p]=l.useState({variantKey:null,defaults:null});if(l.useEffect((()=>{if(u)return u.onActiveToolChange(p)}),[u]),!h.defaults)return null;if(h.defaults.subtype!==o.PdfAnnotationSubtype.LINE)return null;const g=h.defaults.color??"#000000",y=h.defaults.opacity??1,x=h.defaults.strokeWidth??2,f=h.defaults.strokeColor??"#000000",v=h.defaults.strokeStyle??o.PdfAnnotationBorderStyle.SOLID,k=h.defaults.strokeDashArray,m=h.defaults.lineEndings,b=h.defaults.intent,{register:w}=i.usePointerHandlers({modeId:["line","lineArrow"],pageIndex:e}),P=(e,t,n)=>Math.max(t,Math.min(n,e)),S=s/r,j=c/r,[A,I]=l.useState(null),[z,C]=l.useState(null),D=l.useMemo((()=>({onPointerDown:(e,t)=>{var n,o;const i=P(e.x,0,S),r=P(e.y,0,j);I({x:i,y:r}),C({x:i,y:r}),null==(o=null==(n=t.target)?void 0:n.setPointerCapture)||o.call(n,t.pointerId)},onPointerMove:e=>{if(!A)return;const t=P(e.x,0,S),n=P(e.y,0,j);C({x:t,y:n})},onPointerUp:(n,i)=>{var r,s;A&&z&&u&&((n,i)=>{if(Math.abs(i.x-n.x)<1&&Math.abs(i.y-n.y)<1)return;const r=t.patching.lineRectWithEndings([n,i],x,m),s={type:o.PdfAnnotationSubtype.LINE,rect:r,linePoints:{start:n,end:i},color:g,opacity:y,strokeWidth:x,strokeColor:f,strokeStyle:v,strokeDashArray:k,lineEndings:m,intent:b,pageIndex:e,id:Date.now()+Math.random()};u.createAnnotation(e,s),u.setActiveVariant(null),u.selectAnnotation(e,s.id)})(A,z),null==(s=null==(r=i.target)?void 0:r.releasePointerCapture)||s.call(r,i.pointerId),I(null),C(null)},onPointerCancel:(e,t)=>{var n,o;null==(o=null==(n=t.target)?void 0:n.releasePointerCapture)||o.call(n,t.pointerId),I(null),C(null)}})),[A,z,u,S,j]);if(l.useEffect((()=>w?w(D):void 0),[w,D]),!A||!z)return null;const E=t.patching.lineRectWithEndings([A,z],x,m);return n.jsx("div",{style:{position:"absolute",left:E.origin.x*r,top:E.origin.y*r,width:E.size.width*r,height:E.size.height*r,pointerEvents:"none",zIndex:2,overflow:"visible",cursor:d},children:n.jsx(M,{rect:E,linePoints:{start:A,end:z},strokeWidth:x,scale:r,isSelected:!1,color:g,strokeColor:f,opacity:y,lineEndings:m,strokeStyle:v,strokeDashArray:k})})},R=({pageIndex:e,scale:t,pageWidth:r,pageHeight:s,cursor:c})=>{const{provides:d}=a(),[u,h]=l.useState({variantKey:null,defaults:null});if(l.useEffect((()=>null==d?void 0:d.onActiveToolChange(h)),[d]),!u.defaults||u.defaults.subtype!==o.PdfAnnotationSubtype.POLYGON)return null;const p=u.defaults.color??"#000000",g=u.defaults.opacity??1,y=u.defaults.strokeWidth??2,x=u.defaults.strokeColor??"#000000",f=u.defaults.strokeStyle??o.PdfAnnotationBorderStyle.SOLID,v=u.defaults.strokeDashArray,{register:k}=i.usePointerHandlers({modeId:"polygon",pageIndex:e}),m=(e,t,n)=>Math.max(t,Math.min(n,e)),b=r/t,M=s/t,[w,P]=l.useState([]),[S,j]=l.useState(null),A=t=>{const n=t.map((e=>e.x)),i=t.map((e=>e.y)),r=Math.min(...n),s=Math.min(...i),l=Math.max(...n),a=Math.max(...i);if(l-r<1||a-s<1)return;const c=y/2,u={origin:{x:r-c,y:s-c},size:{width:l-r+y,height:a-s+y}},h={type:o.PdfAnnotationSubtype.POLYGON,rect:u,vertices:t,color:p,opacity:g,strokeWidth:y,strokeColor:x,strokeStyle:f,strokeDashArray:v,pageIndex:e,id:Date.now()+Math.random()};d.createAnnotation(e,h),d.setActiveVariant(null),d.selectAnnotation(e,h.id)},I=l.useMemo((()=>({onClick:e=>{const n=m(e.x,0,b),o=m(e.y,0,M);if(((e,n)=>{if(w.length<2)return!1;const o=14/t/2,i=w[0];return e>=i.x-o&&e<=i.x+o&&n>=i.y-o&&n<=i.y+o})(n,o)&&w.length>=3&&d)return A(w),P([]),void j(null);P((e=>[...e,{x:n,y:o}])),j({x:n,y:o})},onDoubleClick:()=>{w.length>=3&&d?(A(w),P([]),j(null)):(P([]),j(null))},onPointerMove:e=>{if(!w.length)return;const t=m(e.x,0,b),n=m(e.y,0,M);j({x:t,y:n})},onPointerCancel:()=>{P([]),j(null)}})),[w,S,d,b,M]);if(l.useEffect((()=>k?k(I):void 0),[k,I]),!w.length||!S)return null;const z=[...w,S],C=z.map((e=>e.x)),D=z.map((e=>e.y)),E=Math.min(...C),W=Math.min(...D),B=Math.max(...C),R=Math.max(...D),$=y/2,L=E-$,H=W-$,T=B+$-L,F=R+$-H,O=l.useMemo((()=>{let e="";return z.forEach((({x:t,y:n},o)=>{e+=(0===o?"M":"L")+(t-L)+" "+(n-H)+" "})),e.trim()}),[z,L,H]),N=w.length>=2?`M ${S.x-L} ${S.y-H} L ${w[0].x-L} ${w[0].y-H}`:null,V=14/t,K=V/2,U=w[0].x-K-L,q=w[0].y-K-H;return n.jsxs("svg",{style:{position:"absolute",left:L*t,top:H*t,width:T*t,height:F*t,pointerEvents:"none",zIndex:2,overflow:"visible"},width:T*t,height:F*t,viewBox:`0 0 ${T} ${F}`,children:[n.jsx("path",{d:O,fill:p,opacity:g,style:{cursor:c,stroke:x,strokeWidth:y,...f===o.PdfAnnotationBorderStyle.DASHED&&{strokeDasharray:null==v?void 0:v.join(",")}}}),N&&n.jsx("path",{d:N,fill:"none",style:{stroke:x,strokeWidth:y,strokeDasharray:"4,4"}}),w.length>=3&&n.jsx("rect",{x:U,y:q,width:V,height:V,fill:x,opacity:.4,stroke:x,strokeWidth:y/2,style:{pointerEvents:"none"}})]})};exports.AnnotationLayer=function({pageIndex:e,scale:t,pageWidth:o,pageHeight:i,rotation:r,selectionMenu:s,style:l,...a}){return n.jsxs("div",{style:{...l},...a,children:[n.jsx(I,{selectionMenu:s,pageIndex:e,scale:t,rotation:r,pageWidth:o,pageHeight:i}),n.jsx(z,{pageIndex:e,scale:t}),n.jsx(C,{pageIndex:e,scale:t,pageWidth:o,pageHeight:i}),n.jsx(D,{pageIndex:e,scale:t,pageWidth:o,pageHeight:i}),n.jsx(E,{pageIndex:e,scale:t,pageWidth:o,pageHeight:i}),n.jsx(R,{pageIndex:e,scale:t,pageWidth:o,pageHeight:i}),n.jsx(W,{pageIndex:e,scale:t,pageWidth:o,pageHeight:i}),n.jsx(B,{pageIndex:e,scale:t,pageWidth:o,pageHeight:i})]})},exports.useAnnotationCapability=a,exports.useAnnotationPlugin=()=>e.usePlugin(t.AnnotationPlugin.id);
2
+ //# sourceMappingURL=index.cjs.map