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