@embedpdf/plugin-annotation 1.0.15 → 1.0.16

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 (43) hide show
  1. package/dist/index.cjs +1 -1
  2. package/dist/index.cjs.map +1 -1
  3. package/dist/index.js +1 -1
  4. package/dist/index.js.map +1 -1
  5. package/dist/preact/adapter.d.ts +1 -0
  6. package/dist/preact/index.cjs +1 -1
  7. package/dist/preact/index.cjs.map +1 -1
  8. package/dist/preact/index.js +94 -52
  9. package/dist/preact/index.js.map +1 -1
  10. package/dist/react/adapter.d.ts +1 -1
  11. package/dist/react/index.cjs +1 -1
  12. package/dist/react/index.cjs.map +1 -1
  13. package/dist/react/index.js +94 -52
  14. package/dist/react/index.js.map +1 -1
  15. package/dist/shared-preact/components/annotations/circle.d.ts +5 -5
  16. package/dist/shared-preact/components/annotations/free-text.d.ts +2 -2
  17. package/dist/shared-preact/components/annotations/ink.d.ts +5 -5
  18. package/dist/shared-preact/components/annotations/line.d.ts +2 -2
  19. package/dist/shared-preact/components/annotations/polygon.d.ts +2 -2
  20. package/dist/shared-preact/components/annotations/polyline.d.ts +2 -2
  21. package/dist/shared-preact/components/annotations/square.d.ts +5 -5
  22. package/dist/shared-preact/components/annotations/stamp.d.ts +2 -2
  23. package/dist/shared-preact/components/counter-rotate-container.d.ts +2 -1
  24. package/dist/shared-preact/components/text-markup/highlight.d.ts +2 -2
  25. package/dist/shared-preact/components/text-markup/squiggly.d.ts +2 -2
  26. package/dist/shared-preact/components/text-markup/strikeout.d.ts +2 -2
  27. package/dist/shared-preact/components/text-markup/underline.d.ts +2 -2
  28. package/dist/shared-preact/hooks/use-drag-resize.d.ts +5 -1
  29. package/dist/shared-react/components/annotations/circle.d.ts +5 -5
  30. package/dist/shared-react/components/annotations/free-text.d.ts +2 -2
  31. package/dist/shared-react/components/annotations/ink.d.ts +5 -5
  32. package/dist/shared-react/components/annotations/line.d.ts +2 -2
  33. package/dist/shared-react/components/annotations/polygon.d.ts +2 -2
  34. package/dist/shared-react/components/annotations/polyline.d.ts +2 -2
  35. package/dist/shared-react/components/annotations/square.d.ts +5 -5
  36. package/dist/shared-react/components/annotations/stamp.d.ts +2 -2
  37. package/dist/shared-react/components/counter-rotate-container.d.ts +2 -1
  38. package/dist/shared-react/components/text-markup/highlight.d.ts +2 -2
  39. package/dist/shared-react/components/text-markup/squiggly.d.ts +2 -2
  40. package/dist/shared-react/components/text-markup/strikeout.d.ts +2 -2
  41. package/dist/shared-react/components/text-markup/underline.d.ts +2 -2
  42. package/dist/shared-react/hooks/use-drag-resize.d.ts +5 -1
  43. package/package.json +14 -9
@@ -54,7 +54,8 @@ function CounterRotate({ children, ...props }) {
54
54
  };
55
55
  const menuWrapperProps = {
56
56
  style: menuWrapperStyle,
57
- onPointerDown: (e) => e.stopPropagation()
57
+ onPointerDown: (e) => e.stopPropagation(),
58
+ onTouchStart: (e) => e.stopPropagation()
58
59
  };
59
60
  return /* @__PURE__ */ jsx(Fragment, { children: children({
60
61
  menuWrapperProps,
@@ -211,20 +212,16 @@ function useDragResize({
211
212
  oy = clamp(oy, 0, pageH - h);
212
213
  return { origin: { x: ox, y: oy }, size: { width: w, height: h } };
213
214
  };
214
- const onPointerDown = (e) => {
215
- if (!isSelected || !isDraggable) return;
216
- e.stopPropagation();
217
- e.preventDefault();
218
- drag.current = "dragging";
219
- startPos.current = { x: e.clientX, y: e.clientY };
215
+ const beginDrag = (kind, clientX, clientY) => {
216
+ drag.current = kind;
217
+ startPos.current = { x: clientX, y: clientY };
220
218
  startRect.current = currentRect;
221
- e.currentTarget.setPointerCapture(e.pointerId);
222
219
  };
223
- const onPointerMove = (e) => {
220
+ const handleMove = (clientX, clientY) => {
224
221
  if (drag.current === "idle" || !startPos.current) return;
225
222
  const disp = {
226
- x: e.clientX - startPos.current.x,
227
- y: e.clientY - startPos.current.y
223
+ x: clientX - startPos.current.x,
224
+ y: clientY - startPos.current.y
228
225
  };
229
226
  const { x, y } = restoreOffset(disp, rotation, scale);
230
227
  const nextRect = applyDelta(x, y);
@@ -239,14 +236,8 @@ function useDragResize({
239
236
  setCurrentRect(patch.rect ?? nextRect);
240
237
  setPreviewObject(patch);
241
238
  };
242
- const onPointerUp = (e) => {
239
+ const finishDragInternal = () => {
243
240
  if (drag.current === "idle") return;
244
- if ((e == null ? void 0 : e.currentTarget) && e.pointerId !== void 0) {
245
- try {
246
- e.currentTarget.releasePointerCapture(e.pointerId);
247
- } catch {
248
- }
249
- }
250
241
  const usedDir = dir.current || "bottom-right";
251
242
  drag.current = "idle";
252
243
  let patch = { rect: currentRect };
@@ -262,16 +253,45 @@ function useDragResize({
262
253
  dir.current = "none";
263
254
  setPreviewObject(null);
264
255
  };
256
+ const onPointerDown = (e) => {
257
+ if (!isSelected || !isDraggable) return;
258
+ e.stopPropagation();
259
+ e.preventDefault();
260
+ beginDrag("dragging", e.clientX, e.clientY);
261
+ e.currentTarget.setPointerCapture(e.pointerId);
262
+ };
263
+ const onPointerMove = (e) => handleMove(e.clientX, e.clientY);
264
+ const onPointerUp = (e) => {
265
+ finishDragInternal();
266
+ if ((e == null ? void 0 : e.currentTarget) && e.pointerId !== void 0) {
267
+ try {
268
+ e.currentTarget.releasePointerCapture(e.pointerId);
269
+ } catch {
270
+ }
271
+ }
272
+ };
265
273
  const startResize = (direction) => (e) => {
266
274
  if (!isSelected || !isResizable) return;
267
275
  e.stopPropagation();
268
276
  e.preventDefault();
269
- drag.current = "resizing";
270
277
  dir.current = direction;
271
- startPos.current = { x: e.clientX, y: e.clientY };
272
- startRect.current = currentRect;
278
+ beginDrag("resizing", e.clientX, e.clientY);
273
279
  e.currentTarget.setPointerCapture(e.pointerId);
274
280
  };
281
+ const onTouchStart = (e) => {
282
+ if (!isSelected || !isDraggable) return;
283
+ e.stopPropagation();
284
+ e.preventDefault();
285
+ const t = e.touches[0];
286
+ if (!t) return;
287
+ beginDrag("dragging", t.clientX, t.clientY);
288
+ };
289
+ const onTouchMove = (e) => {
290
+ const t = e.touches[0];
291
+ if (!t) return;
292
+ handleMove(t.clientX, t.clientY);
293
+ };
294
+ const onTouchEnd = () => finishDragInternal();
275
295
  useEffect(() => {
276
296
  drag.current = "idle";
277
297
  dir.current = "none";
@@ -284,7 +304,12 @@ function useDragResize({
284
304
  onPointerMove,
285
305
  onPointerUp,
286
306
  onPointerCancel: () => onPointerUp(),
287
- onLostPointerCapture: () => onPointerUp()
307
+ onLostPointerCapture: () => onPointerUp(),
308
+ /* mobile touch fallback */
309
+ onTouchStart,
310
+ onTouchMove,
311
+ onTouchEnd,
312
+ onTouchCancel: onTouchEnd
288
313
  },
289
314
  startResize
290
315
  };
@@ -416,6 +441,7 @@ function AnnotationContainer({
416
441
  width: `${currentRect.size.width * scale}px`,
417
442
  height: `${currentRect.size.height * scale}px`,
418
443
  pointerEvents: isSelected ? "auto" : "none",
444
+ touchAction: isSelected ? "auto" : "none",
419
445
  cursor: isSelected && isDraggable ? "move" : "default",
420
446
  ...isSelected && {
421
447
  zIndex: 3
@@ -496,7 +522,8 @@ function Highlight({
496
522
  return /* @__PURE__ */ jsx(Fragment$1, { children: rects.map((b, i) => /* @__PURE__ */ jsx(
497
523
  "div",
498
524
  {
499
- onMouseDown: onClick,
525
+ onPointerDown: onClick,
526
+ onTouchStart: onClick,
500
527
  style: {
501
528
  position: "absolute",
502
529
  left: (rect ? b.origin.x - rect.origin.x : b.origin.x) * scale,
@@ -529,7 +556,8 @@ function Underline({
529
556
  return /* @__PURE__ */ jsx(Fragment$1, { children: rects.map((r, i) => /* @__PURE__ */ jsx(
530
557
  "div",
531
558
  {
532
- onMouseDown: onClick,
559
+ onPointerDown: onClick,
560
+ onTouchStart: onClick,
533
561
  style: {
534
562
  position: "absolute",
535
563
  left: (rect ? r.origin.x - rect.origin.x : r.origin.x) * scale,
@@ -576,7 +604,8 @@ function Strikeout({
576
604
  return /* @__PURE__ */ jsx(Fragment$1, { children: rects.map((r, i) => /* @__PURE__ */ jsx(
577
605
  "div",
578
606
  {
579
- onMouseDown: onClick,
607
+ onPointerDown: onClick,
608
+ onTouchStart: onClick,
580
609
  style: {
581
610
  position: "absolute",
582
611
  left: (rect ? r.origin.x - rect.origin.x : r.origin.x) * scale,
@@ -630,7 +659,8 @@ function Squiggly({
630
659
  return /* @__PURE__ */ jsx(Fragment$1, { children: rects.map((r, i) => /* @__PURE__ */ jsx(
631
660
  "div",
632
661
  {
633
- onMouseDown: onClick,
662
+ onPointerDown: onClick,
663
+ onTouchStart: onClick,
634
664
  style: {
635
665
  position: "absolute",
636
666
  left: (rect ? r.origin.x - rect.origin.x : r.origin.x) * scale,
@@ -666,14 +696,14 @@ function Squiggly({
666
696
  )) });
667
697
  }
668
698
  function Ink({
699
+ isSelected,
669
700
  color = "#000000",
670
701
  opacity = 1,
671
702
  strokeWidth,
672
703
  inkList,
673
704
  rect,
674
705
  scale,
675
- onClick,
676
- cursor
706
+ onClick
677
707
  }) {
678
708
  const paths = useMemo(() => {
679
709
  return inkList.map(({ points }) => {
@@ -708,10 +738,11 @@ function Ink({
708
738
  d,
709
739
  fill: "none",
710
740
  opacity,
711
- onMouseDown: onClick,
741
+ onPointerDown: onClick,
742
+ onTouchStart: onClick,
712
743
  style: {
713
- cursor,
714
- pointerEvents: "visibleStroke",
744
+ cursor: isSelected ? "move" : "pointer",
745
+ pointerEvents: isSelected ? "none" : "visibleStroke",
715
746
  stroke: color,
716
747
  strokeWidth,
717
748
  strokeLinecap: "round",
@@ -724,6 +755,7 @@ function Ink({
724
755
  );
725
756
  }
726
757
  function Square({
758
+ isSelected,
727
759
  color = "#000000",
728
760
  strokeColor,
729
761
  opacity = 1,
@@ -732,8 +764,7 @@ function Square({
732
764
  strokeDashArray,
733
765
  rect,
734
766
  scale,
735
- onClick,
736
- cursor
767
+ onClick
737
768
  }) {
738
769
  const { width, height, x, y } = useMemo(() => {
739
770
  const outerW = rect.size.width;
@@ -771,10 +802,11 @@ function Square({
771
802
  height,
772
803
  fill: color,
773
804
  opacity,
774
- onMouseDown: onClick,
805
+ onPointerDown: onClick,
806
+ onTouchStart: onClick,
775
807
  style: {
776
- cursor,
777
- pointerEvents: color === "transparent" ? "visibleStroke" : "visible",
808
+ cursor: isSelected ? "move" : "pointer",
809
+ pointerEvents: isSelected ? "none" : color === "transparent" ? "visibleStroke" : "visible",
778
810
  stroke: strokeColor ?? color,
779
811
  strokeWidth,
780
812
  ...strokeStyle === PdfAnnotationBorderStyle.DASHED && {
@@ -796,7 +828,7 @@ function Circle({
796
828
  rect,
797
829
  scale,
798
830
  onClick,
799
- cursor
831
+ isSelected
800
832
  }) {
801
833
  const { width, height, cx, cy, rx, ry } = useMemo(() => {
802
834
  const outerW = rect.size.width;
@@ -837,10 +869,11 @@ function Circle({
837
869
  ry,
838
870
  fill: color,
839
871
  opacity,
840
- onMouseDown: onClick,
872
+ onPointerDown: onClick,
873
+ onTouchStart: onClick,
841
874
  style: {
842
- cursor,
843
- pointerEvents: color === "transparent" ? "visibleStroke" : "visible",
875
+ cursor: isSelected ? "move" : "pointer",
876
+ pointerEvents: isSelected ? "none" : color === "transparent" ? "visibleStroke" : "visible",
844
877
  stroke: strokeColor ?? color,
845
878
  strokeWidth,
846
879
  ...strokeStyle === PdfAnnotationBorderStyle.DASHED && {
@@ -948,7 +981,8 @@ function Line({
948
981
  x2,
949
982
  y2,
950
983
  opacity,
951
- onMouseDown: onClick,
984
+ onPointerDown: onClick,
985
+ onTouchStart: onClick,
952
986
  style: {
953
987
  cursor: isSelected ? "move" : "pointer",
954
988
  pointerEvents: "visibleStroke",
@@ -966,7 +1000,8 @@ function Line({
966
1000
  {
967
1001
  d: endings.start.d,
968
1002
  transform: endings.start.transform,
969
- onMouseDown: onClick,
1003
+ onPointerDown: onClick,
1004
+ onTouchStart: onClick,
970
1005
  stroke: strokeColor,
971
1006
  style: {
972
1007
  cursor: isSelected ? "move" : "pointer",
@@ -986,7 +1021,8 @@ function Line({
986
1021
  d: endings.end.d,
987
1022
  transform: endings.end.transform,
988
1023
  stroke: strokeColor,
989
- onMouseDown: onClick,
1024
+ onPointerDown: onClick,
1025
+ onTouchStart: onClick,
990
1026
  style: {
991
1027
  cursor: isSelected ? "move" : "pointer",
992
1028
  strokeWidth,
@@ -1067,7 +1103,8 @@ function Polyline({
1067
1103
  "path",
1068
1104
  {
1069
1105
  d: pathData,
1070
- onMouseDown: onClick,
1106
+ onPointerDown: onClick,
1107
+ onTouchStart: onClick,
1071
1108
  opacity,
1072
1109
  style: {
1073
1110
  fill: "none",
@@ -1087,7 +1124,8 @@ function Polyline({
1087
1124
  transform: endings.start.transform,
1088
1125
  stroke: strokeColor,
1089
1126
  fill: endings.start.filled ? color : "none",
1090
- onMouseDown: onClick,
1127
+ onPointerDown: onClick,
1128
+ onTouchStart: onClick,
1091
1129
  style: {
1092
1130
  cursor: isSelected ? "move" : "pointer",
1093
1131
  strokeWidth,
@@ -1103,11 +1141,12 @@ function Polyline({
1103
1141
  transform: endings.end.transform,
1104
1142
  stroke: strokeColor,
1105
1143
  fill: endings.end.filled ? color : "none",
1106
- onMouseDown: onClick,
1144
+ onPointerDown: onClick,
1145
+ onTouchStart: onClick,
1107
1146
  style: {
1108
1147
  cursor: isSelected ? "move" : "pointer",
1109
1148
  strokeWidth,
1110
- pointerEvents: endings.end.filled ? "visible" : "visibleStroke",
1149
+ pointerEvents: isSelected ? "none" : endings.end.filled ? "visible" : "visibleStroke",
1111
1150
  strokeLinecap: "butt"
1112
1151
  }
1113
1152
  }
@@ -1158,14 +1197,15 @@ function Polygon({
1158
1197
  "path",
1159
1198
  {
1160
1199
  d: pathData,
1161
- onMouseDown: onClick,
1200
+ onPointerDown: onClick,
1201
+ onTouchStart: onClick,
1162
1202
  opacity,
1163
1203
  style: {
1164
1204
  fill: color,
1165
1205
  stroke: strokeColor ?? color,
1166
1206
  strokeWidth,
1167
1207
  cursor: isSelected ? "move" : "pointer",
1168
- pointerEvents: color === "transparent" ? "visibleStroke" : "visible",
1208
+ pointerEvents: isSelected ? "none" : color === "transparent" ? "visibleStroke" : "visible",
1169
1209
  strokeLinecap: "butt",
1170
1210
  strokeLinejoin: "miter",
1171
1211
  ...strokeStyle === PdfAnnotationBorderStyle.DASHED && {
@@ -1269,6 +1309,7 @@ function FreeText({
1269
1309
  zIndex: 2
1270
1310
  },
1271
1311
  onPointerDown: onClick,
1312
+ onTouchStart: onClick,
1272
1313
  children: /* @__PURE__ */ jsx(
1273
1314
  "span",
1274
1315
  {
@@ -1367,6 +1408,7 @@ function Stamp({ isSelected, annotation, pageIndex, scale, onClick }) {
1367
1408
  pointerEvents: isSelected ? "none" : "auto"
1368
1409
  },
1369
1410
  onPointerDown: onClick,
1411
+ onTouchStart: onClick,
1370
1412
  children: annotation.pdfId !== void 0 && /* @__PURE__ */ jsx(
1371
1413
  RenderAnnotation,
1372
1414
  {
@@ -1439,7 +1481,7 @@ function Annotations(annotationsProps) {
1439
1481
  children: (obj) => /* @__PURE__ */ jsx(
1440
1482
  Ink,
1441
1483
  {
1442
- cursor: isSelected ? "move" : "pointer",
1484
+ isSelected,
1443
1485
  color: obj.color,
1444
1486
  opacity: obj.opacity,
1445
1487
  strokeWidth: obj.strokeWidth,
@@ -1469,7 +1511,7 @@ function Annotations(annotationsProps) {
1469
1511
  children: (obj) => /* @__PURE__ */ jsx(
1470
1512
  Square,
1471
1513
  {
1472
- cursor: isSelected ? "move" : "pointer",
1514
+ isSelected,
1473
1515
  rect: obj.rect,
1474
1516
  color: obj.color,
1475
1517
  opacity: obj.opacity,
@@ -1501,7 +1543,7 @@ function Annotations(annotationsProps) {
1501
1543
  children: (obj) => /* @__PURE__ */ jsx(
1502
1544
  Circle,
1503
1545
  {
1504
- cursor: isSelected ? "move" : "pointer",
1546
+ isSelected,
1505
1547
  rect: obj.rect,
1506
1548
  color: obj.color,
1507
1549
  opacity: obj.opacity,