@embedpdf/plugin-annotation 1.0.16 → 1.0.18
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 +189 -189
- package/dist/index.js.map +1 -1
- package/dist/lib/actions.d.ts +8 -26
- package/dist/lib/annotation-plugin.d.ts +1 -1
- package/dist/lib/helpers.d.ts +5 -1
- package/dist/lib/selectors.d.ts +29 -7
- package/dist/lib/types.d.ts +18 -19
- package/dist/preact/index.cjs +1 -1
- package/dist/preact/index.cjs.map +1 -1
- package/dist/preact/index.js +78 -77
- package/dist/preact/index.js.map +1 -1
- package/dist/react/index.cjs +1 -1
- package/dist/react/index.cjs.map +1 -1
- package/dist/react/index.js +78 -77
- package/dist/react/index.js.map +1 -1
- package/package.json +9 -9
- package/dist/lib/utils.d.ts +0 -11
package/dist/react/index.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { usePlugin, useCapability } from "@embedpdf/core/react";
|
|
2
2
|
import { AnnotationPlugin, patching, getAnnotationsByPageIndex, getSelectedAnnotationByPageIndex, isInk, isSquare, isCircle, isUnderline, isStrikeout, isSquiggly, isHighlight, isLine, isPolyline, isPolygon, isFreeText, isStamp } from "@embedpdf/plugin-annotation";
|
|
3
3
|
import { jsx, jsxs, Fragment as Fragment$1 } from "react/jsx-runtime";
|
|
4
|
-
import { restoreOffset, rectEquals, PdfAnnotationBorderStyle, PdfAnnotationSubtype, expandRect, rectFromPoints, textAlignmentToCss, standardFontCss, PdfVerticalAlignment, ignore, PdfErrorCode, blendModeToCss, PdfBlendMode } from "@embedpdf/models";
|
|
4
|
+
import { restoreOffset, rectEquals, PdfAnnotationBorderStyle, PdfAnnotationSubtype, expandRect, rectFromPoints, textAlignmentToCss, standardFontCss, PdfVerticalAlignment, ignore, PdfErrorCode, blendModeToCss, PdfBlendMode, uuidV4 } from "@embedpdf/models";
|
|
5
5
|
import { usePointerHandlers } from "@embedpdf/plugin-interaction-manager/react";
|
|
6
6
|
import { useSelectionCapability } from "@embedpdf/plugin-selection/react";
|
|
7
7
|
import { Fragment, useState, useRef, useEffect, useLayoutEffect, useMemo, useCallback } from "react";
|
|
8
|
+
import { clamp } from "@embedpdf/core";
|
|
8
9
|
const useAnnotationPlugin = () => usePlugin(AnnotationPlugin.id);
|
|
9
10
|
const useAnnotationCapability = () => useCapability(AnnotationPlugin.id);
|
|
10
11
|
const mapDoubleClick = (handler) => handler ? { onDoubleClick: handler } : {};
|
|
@@ -162,7 +163,7 @@ function useDragResize({
|
|
|
162
163
|
const dir = useRef("none");
|
|
163
164
|
const startPos = useRef(null);
|
|
164
165
|
const startRect = useRef(null);
|
|
165
|
-
const
|
|
166
|
+
const clamp2 = (v, min, max) => Math.max(min, Math.min(max, v));
|
|
166
167
|
const pageW = pageWidth / scale;
|
|
167
168
|
const pageH = pageHeight / scale;
|
|
168
169
|
const applyDelta = (dx, dy) => {
|
|
@@ -205,10 +206,10 @@ function useDragResize({
|
|
|
205
206
|
}
|
|
206
207
|
}
|
|
207
208
|
if (w < 1 || h < 1) return currentRect;
|
|
208
|
-
w =
|
|
209
|
-
h =
|
|
210
|
-
ox =
|
|
211
|
-
oy =
|
|
209
|
+
w = clamp2(w, 1, pageW);
|
|
210
|
+
h = clamp2(h, 1, pageH);
|
|
211
|
+
ox = clamp2(ox, 0, pageW - w);
|
|
212
|
+
oy = clamp2(oy, 0, pageH - h);
|
|
212
213
|
return { origin: { x: ox, y: oy }, size: { width: w, height: h } };
|
|
213
214
|
};
|
|
214
215
|
const beginDrag = (kind, clientX, clientY) => {
|
|
@@ -415,7 +416,7 @@ function AnnotationContainer({
|
|
|
415
416
|
setCurrentRect,
|
|
416
417
|
setCurrentVertices,
|
|
417
418
|
setPreviewObject,
|
|
418
|
-
commit: (patch) => annotationProvides == null ? void 0 : annotationProvides.updateAnnotation(pageIndex, trackedAnnotation.
|
|
419
|
+
commit: (patch) => annotationProvides == null ? void 0 : annotationProvides.updateAnnotation(pageIndex, trackedAnnotation.object.id, patch)
|
|
419
420
|
});
|
|
420
421
|
useLayoutEffect(() => {
|
|
421
422
|
if (!rectEquals(trackedAnnotation.object.rect, currentRect)) {
|
|
@@ -474,7 +475,7 @@ function AnnotationContainer({
|
|
|
474
475
|
rect: currentRect,
|
|
475
476
|
vertices: v
|
|
476
477
|
});
|
|
477
|
-
annotationProvides.updateAnnotation(pageIndex, trackedAnnotation.
|
|
478
|
+
annotationProvides.updateAnnotation(pageIndex, trackedAnnotation.object.id, patch);
|
|
478
479
|
}
|
|
479
480
|
}
|
|
480
481
|
}
|
|
@@ -984,7 +985,7 @@ function Line({
|
|
|
984
985
|
onTouchStart: onClick,
|
|
985
986
|
style: {
|
|
986
987
|
cursor: isSelected ? "move" : "pointer",
|
|
987
|
-
pointerEvents: "visibleStroke",
|
|
988
|
+
pointerEvents: isSelected ? "none" : "visibleStroke",
|
|
988
989
|
stroke: strokeColor,
|
|
989
990
|
strokeWidth,
|
|
990
991
|
strokeLinecap: "butt",
|
|
@@ -1006,7 +1007,7 @@ function Line({
|
|
|
1006
1007
|
cursor: isSelected ? "move" : "pointer",
|
|
1007
1008
|
strokeWidth,
|
|
1008
1009
|
strokeLinecap: "butt",
|
|
1009
|
-
pointerEvents: endings.start.filled ? "visible" : "visibleStroke",
|
|
1010
|
+
pointerEvents: isSelected ? "none" : endings.start.filled ? "visible" : "visibleStroke",
|
|
1010
1011
|
...strokeStyle === PdfAnnotationBorderStyle.DASHED && {
|
|
1011
1012
|
strokeDasharray: strokeDashArray == null ? void 0 : strokeDashArray.join(",")
|
|
1012
1013
|
}
|
|
@@ -1026,7 +1027,7 @@ function Line({
|
|
|
1026
1027
|
cursor: isSelected ? "move" : "pointer",
|
|
1027
1028
|
strokeWidth,
|
|
1028
1029
|
strokeLinecap: "butt",
|
|
1029
|
-
pointerEvents: endings.end.filled ? "visible" : "visibleStroke",
|
|
1030
|
+
pointerEvents: isSelected ? "none" : endings.end.filled ? "visible" : "visibleStroke",
|
|
1030
1031
|
...strokeStyle === PdfAnnotationBorderStyle.DASHED && {
|
|
1031
1032
|
strokeDasharray: strokeDashArray == null ? void 0 : strokeDashArray.join(",")
|
|
1032
1033
|
}
|
|
@@ -1110,7 +1111,7 @@ function Polyline({
|
|
|
1110
1111
|
stroke: strokeColor ?? color,
|
|
1111
1112
|
strokeWidth,
|
|
1112
1113
|
cursor: isSelected ? "move" : "pointer",
|
|
1113
|
-
pointerEvents: "visibleStroke",
|
|
1114
|
+
pointerEvents: isSelected ? "none" : "visibleStroke",
|
|
1114
1115
|
strokeLinecap: "butt",
|
|
1115
1116
|
strokeLinejoin: "miter"
|
|
1116
1117
|
}
|
|
@@ -1128,7 +1129,7 @@ function Polyline({
|
|
|
1128
1129
|
style: {
|
|
1129
1130
|
cursor: isSelected ? "move" : "pointer",
|
|
1130
1131
|
strokeWidth,
|
|
1131
|
-
pointerEvents: endings.start.filled ? "visible" : "visibleStroke",
|
|
1132
|
+
pointerEvents: isSelected ? "none" : endings.start.filled ? "visible" : "visibleStroke",
|
|
1132
1133
|
strokeLinecap: "butt"
|
|
1133
1134
|
}
|
|
1134
1135
|
}
|
|
@@ -1292,7 +1293,7 @@ function FreeText({
|
|
|
1292
1293
|
const handleBlur = () => {
|
|
1293
1294
|
if (!annotationProvides) return;
|
|
1294
1295
|
if (!editorRef.current) return;
|
|
1295
|
-
annotationProvides.updateAnnotation(pageIndex, annotation.
|
|
1296
|
+
annotationProvides.updateAnnotation(pageIndex, annotation.object.id, {
|
|
1296
1297
|
contents: editorRef.current.innerText
|
|
1297
1298
|
});
|
|
1298
1299
|
};
|
|
@@ -1331,7 +1332,6 @@ function FreeText({
|
|
|
1331
1332
|
cursor: isEditing ? "text" : "pointer"
|
|
1332
1333
|
},
|
|
1333
1334
|
contentEditable: isEditing,
|
|
1334
|
-
suppressContentEditableWarning: true,
|
|
1335
1335
|
children: annotation.object.contents
|
|
1336
1336
|
}
|
|
1337
1337
|
)
|
|
@@ -1408,11 +1408,11 @@ function Stamp({ isSelected, annotation, pageIndex, scale, onClick }) {
|
|
|
1408
1408
|
},
|
|
1409
1409
|
onPointerDown: onClick,
|
|
1410
1410
|
onTouchStart: onClick,
|
|
1411
|
-
children:
|
|
1411
|
+
children: /* @__PURE__ */ jsx(
|
|
1412
1412
|
RenderAnnotation,
|
|
1413
1413
|
{
|
|
1414
1414
|
pageIndex,
|
|
1415
|
-
annotation: { ...annotation.object, id: annotation.
|
|
1415
|
+
annotation: { ...annotation.object, id: annotation.object.id },
|
|
1416
1416
|
scaleFactor: scale
|
|
1417
1417
|
}
|
|
1418
1418
|
)
|
|
@@ -1450,7 +1450,7 @@ function Annotations(annotationsProps) {
|
|
|
1450
1450
|
(e, annotation) => {
|
|
1451
1451
|
e.stopPropagation();
|
|
1452
1452
|
if (annotationProvides && selectionProvides) {
|
|
1453
|
-
annotationProvides.selectAnnotation(pageIndex, annotation.
|
|
1453
|
+
annotationProvides.selectAnnotation(pageIndex, annotation.object.id);
|
|
1454
1454
|
selectionProvides.clear();
|
|
1455
1455
|
setEditingId(null);
|
|
1456
1456
|
}
|
|
@@ -1461,8 +1461,8 @@ function Annotations(annotationsProps) {
|
|
|
1461
1461
|
return register(handlers);
|
|
1462
1462
|
}, [register, handlers]);
|
|
1463
1463
|
return /* @__PURE__ */ jsx(Fragment$1, { children: annotations.map((annotation) => {
|
|
1464
|
-
const isSelected = (selectionState == null ? void 0 : selectionState.
|
|
1465
|
-
const isEditing = editingId === annotation.
|
|
1464
|
+
const isSelected = (selectionState == null ? void 0 : selectionState.object.id) === annotation.object.id;
|
|
1465
|
+
const isEditing = editingId === annotation.object.id;
|
|
1466
1466
|
if (isInk(annotation)) {
|
|
1467
1467
|
return /* @__PURE__ */ jsx(
|
|
1468
1468
|
AnnotationContainer,
|
|
@@ -1491,7 +1491,7 @@ function Annotations(annotationsProps) {
|
|
|
1491
1491
|
}
|
|
1492
1492
|
)
|
|
1493
1493
|
},
|
|
1494
|
-
annotation.
|
|
1494
|
+
annotation.object.id
|
|
1495
1495
|
);
|
|
1496
1496
|
}
|
|
1497
1497
|
if (isSquare(annotation)) {
|
|
@@ -1523,7 +1523,7 @@ function Annotations(annotationsProps) {
|
|
|
1523
1523
|
}
|
|
1524
1524
|
)
|
|
1525
1525
|
},
|
|
1526
|
-
annotation.
|
|
1526
|
+
annotation.object.id
|
|
1527
1527
|
);
|
|
1528
1528
|
}
|
|
1529
1529
|
if (isCircle(annotation)) {
|
|
@@ -1555,7 +1555,7 @@ function Annotations(annotationsProps) {
|
|
|
1555
1555
|
}
|
|
1556
1556
|
)
|
|
1557
1557
|
},
|
|
1558
|
-
annotation.
|
|
1558
|
+
annotation.object.id
|
|
1559
1559
|
);
|
|
1560
1560
|
}
|
|
1561
1561
|
if (isUnderline(annotation)) {
|
|
@@ -1583,7 +1583,7 @@ function Annotations(annotationsProps) {
|
|
|
1583
1583
|
}
|
|
1584
1584
|
)
|
|
1585
1585
|
},
|
|
1586
|
-
annotation.
|
|
1586
|
+
annotation.object.id
|
|
1587
1587
|
);
|
|
1588
1588
|
}
|
|
1589
1589
|
if (isStrikeout(annotation)) {
|
|
@@ -1611,7 +1611,7 @@ function Annotations(annotationsProps) {
|
|
|
1611
1611
|
}
|
|
1612
1612
|
)
|
|
1613
1613
|
},
|
|
1614
|
-
annotation.
|
|
1614
|
+
annotation.object.id
|
|
1615
1615
|
);
|
|
1616
1616
|
}
|
|
1617
1617
|
if (isSquiggly(annotation)) {
|
|
@@ -1639,7 +1639,7 @@ function Annotations(annotationsProps) {
|
|
|
1639
1639
|
}
|
|
1640
1640
|
)
|
|
1641
1641
|
},
|
|
1642
|
-
annotation.
|
|
1642
|
+
annotation.object.id
|
|
1643
1643
|
);
|
|
1644
1644
|
}
|
|
1645
1645
|
if (isHighlight(annotation)) {
|
|
@@ -1667,7 +1667,7 @@ function Annotations(annotationsProps) {
|
|
|
1667
1667
|
}
|
|
1668
1668
|
)
|
|
1669
1669
|
},
|
|
1670
|
-
annotation.
|
|
1670
|
+
annotation.object.id
|
|
1671
1671
|
);
|
|
1672
1672
|
}
|
|
1673
1673
|
if (isLine(annotation)) {
|
|
@@ -1706,7 +1706,7 @@ function Annotations(annotationsProps) {
|
|
|
1706
1706
|
}
|
|
1707
1707
|
) })
|
|
1708
1708
|
},
|
|
1709
|
-
annotation.
|
|
1709
|
+
annotation.object.id
|
|
1710
1710
|
);
|
|
1711
1711
|
}
|
|
1712
1712
|
if (isPolyline(annotation)) {
|
|
@@ -1740,7 +1740,7 @@ function Annotations(annotationsProps) {
|
|
|
1740
1740
|
}
|
|
1741
1741
|
) })
|
|
1742
1742
|
},
|
|
1743
|
-
annotation.
|
|
1743
|
+
annotation.object.id
|
|
1744
1744
|
);
|
|
1745
1745
|
}
|
|
1746
1746
|
if (isPolygon(annotation)) {
|
|
@@ -1775,7 +1775,7 @@ function Annotations(annotationsProps) {
|
|
|
1775
1775
|
}
|
|
1776
1776
|
) })
|
|
1777
1777
|
},
|
|
1778
|
-
annotation.
|
|
1778
|
+
annotation.object.id
|
|
1779
1779
|
);
|
|
1780
1780
|
}
|
|
1781
1781
|
if (isFreeText(annotation)) {
|
|
@@ -1790,7 +1790,7 @@ function Annotations(annotationsProps) {
|
|
|
1790
1790
|
outlineOffset: 6,
|
|
1791
1791
|
onDoubleClick: (e) => {
|
|
1792
1792
|
e.stopPropagation();
|
|
1793
|
-
setEditingId(annotation.
|
|
1793
|
+
setEditingId(annotation.object.id);
|
|
1794
1794
|
},
|
|
1795
1795
|
style: {
|
|
1796
1796
|
mixBlendMode: blendModeToCss(annotation.object.blendMode ?? PdfBlendMode.Normal)
|
|
@@ -1811,7 +1811,7 @@ function Annotations(annotationsProps) {
|
|
|
1811
1811
|
}
|
|
1812
1812
|
)
|
|
1813
1813
|
},
|
|
1814
|
-
annotation.
|
|
1814
|
+
annotation.object.id
|
|
1815
1815
|
);
|
|
1816
1816
|
}
|
|
1817
1817
|
if (isStamp(annotation)) {
|
|
@@ -1839,7 +1839,7 @@ function Annotations(annotationsProps) {
|
|
|
1839
1839
|
}
|
|
1840
1840
|
)
|
|
1841
1841
|
},
|
|
1842
|
-
annotation.
|
|
1842
|
+
annotation.object.id
|
|
1843
1843
|
);
|
|
1844
1844
|
}
|
|
1845
1845
|
return null;
|
|
@@ -1973,7 +1973,6 @@ const InkPaint = ({ pageIndex, scale, pageWidth, pageHeight }) => {
|
|
|
1973
1973
|
const toolBlendMode = ((_d = activeTool.defaults) == null ? void 0 : _d.blendMode) ?? PdfBlendMode.Normal;
|
|
1974
1974
|
const intent = (_e = activeTool.defaults) == null ? void 0 : _e.intent;
|
|
1975
1975
|
const { register } = usePointerHandlers({ modeId: "ink", pageIndex });
|
|
1976
|
-
const clamp = (v, min, max) => Math.max(min, Math.min(max, v));
|
|
1977
1976
|
const [currentStrokes, setCurrentStrokes] = useState([]);
|
|
1978
1977
|
const [isDrawing, setIsDrawing] = useState(false);
|
|
1979
1978
|
const timerRef = useRef(null);
|
|
@@ -1982,7 +1981,7 @@ const InkPaint = ({ pageIndex, scale, pageWidth, pageHeight }) => {
|
|
|
1982
1981
|
const handlers = useMemo(
|
|
1983
1982
|
() => ({
|
|
1984
1983
|
onPointerDown: (pos, evt) => {
|
|
1985
|
-
var _a2
|
|
1984
|
+
var _a2;
|
|
1986
1985
|
const curX = clamp(pos.x, 0, pageWidthPDF);
|
|
1987
1986
|
const curY = clamp(pos.y, 0, pageHeightPDF);
|
|
1988
1987
|
setIsDrawing(true);
|
|
@@ -1993,7 +1992,7 @@ const InkPaint = ({ pageIndex, scale, pageWidth, pageHeight }) => {
|
|
|
1993
1992
|
} else {
|
|
1994
1993
|
setCurrentStrokes([{ points: [{ x: curX, y: curY }] }]);
|
|
1995
1994
|
}
|
|
1996
|
-
(
|
|
1995
|
+
(_a2 = evt.setPointerCapture) == null ? void 0 : _a2.call(evt);
|
|
1997
1996
|
},
|
|
1998
1997
|
onPointerMove: (pos) => {
|
|
1999
1998
|
if (!isDrawing) return;
|
|
@@ -2007,9 +2006,9 @@ const InkPaint = ({ pageIndex, scale, pageWidth, pageHeight }) => {
|
|
|
2007
2006
|
});
|
|
2008
2007
|
},
|
|
2009
2008
|
onPointerUp: (_, evt) => {
|
|
2010
|
-
var _a2
|
|
2009
|
+
var _a2;
|
|
2011
2010
|
setIsDrawing(false);
|
|
2012
|
-
(
|
|
2011
|
+
(_a2 = evt.releasePointerCapture) == null ? void 0 : _a2.call(evt);
|
|
2013
2012
|
if (timerRef.current) clearTimeout(timerRef.current);
|
|
2014
2013
|
timerRef.current = setTimeout(() => {
|
|
2015
2014
|
if (currentStrokes.length && annotationProvides) {
|
|
@@ -2026,8 +2025,9 @@ const InkPaint = ({ pageIndex, scale, pageWidth, pageHeight }) => {
|
|
|
2026
2025
|
color: toolColor,
|
|
2027
2026
|
opacity: toolOpacity,
|
|
2028
2027
|
strokeWidth: toolStrokeWidth,
|
|
2028
|
+
created: /* @__PURE__ */ new Date(),
|
|
2029
2029
|
pageIndex,
|
|
2030
|
-
id:
|
|
2030
|
+
id: uuidV4()
|
|
2031
2031
|
};
|
|
2032
2032
|
annotationProvides.createAnnotation(pageIndex, anno);
|
|
2033
2033
|
annotationProvides.setActiveVariant(null);
|
|
@@ -2038,9 +2038,9 @@ const InkPaint = ({ pageIndex, scale, pageWidth, pageHeight }) => {
|
|
|
2038
2038
|
}, 3e3);
|
|
2039
2039
|
},
|
|
2040
2040
|
onPointerCancel: (_, evt) => {
|
|
2041
|
-
var _a2
|
|
2041
|
+
var _a2;
|
|
2042
2042
|
setIsDrawing(false);
|
|
2043
|
-
(
|
|
2043
|
+
(_a2 = evt.releasePointerCapture) == null ? void 0 : _a2.call(evt);
|
|
2044
2044
|
setCurrentStrokes([]);
|
|
2045
2045
|
if (timerRef.current) {
|
|
2046
2046
|
clearTimeout(timerRef.current);
|
|
@@ -2137,7 +2137,6 @@ const CirclePaint = ({
|
|
|
2137
2137
|
const toolStrokeStyle = activeTool.defaults.strokeStyle ?? PdfAnnotationBorderStyle.SOLID;
|
|
2138
2138
|
const toolStrokeDashArray = activeTool.defaults.strokeDashArray ?? [];
|
|
2139
2139
|
const { register } = usePointerHandlers({ modeId: "circle", pageIndex });
|
|
2140
|
-
const clamp = (v, min, max) => Math.max(min, Math.min(max, v));
|
|
2141
2140
|
const pageWidthPDF = pageWidth / scale;
|
|
2142
2141
|
const pageHeightPDF = pageHeight / scale;
|
|
2143
2142
|
const [start, setStart] = useState(null);
|
|
@@ -2145,12 +2144,12 @@ const CirclePaint = ({
|
|
|
2145
2144
|
const handlers = useMemo(
|
|
2146
2145
|
() => ({
|
|
2147
2146
|
onPointerDown: (pos, evt) => {
|
|
2148
|
-
var _a
|
|
2147
|
+
var _a;
|
|
2149
2148
|
const x = clamp(pos.x, 0, pageWidthPDF);
|
|
2150
2149
|
const y = clamp(pos.y, 0, pageHeightPDF);
|
|
2151
2150
|
setStart({ x, y });
|
|
2152
2151
|
setCurrent({ x, y });
|
|
2153
|
-
(
|
|
2152
|
+
(_a = evt.setPointerCapture) == null ? void 0 : _a.call(evt);
|
|
2154
2153
|
},
|
|
2155
2154
|
onPointerMove: (pos) => {
|
|
2156
2155
|
if (!start) return;
|
|
@@ -2159,7 +2158,7 @@ const CirclePaint = ({
|
|
|
2159
2158
|
setCurrent({ x, y });
|
|
2160
2159
|
},
|
|
2161
2160
|
onPointerUp: (_, evt) => {
|
|
2162
|
-
var _a
|
|
2161
|
+
var _a;
|
|
2163
2162
|
if (start && current && annotationProvides) {
|
|
2164
2163
|
const minX2 = Math.min(start.x, current.x);
|
|
2165
2164
|
const minY2 = Math.min(start.y, current.y);
|
|
@@ -2184,21 +2183,22 @@ const CirclePaint = ({
|
|
|
2184
2183
|
strokeColor: toolStrokeColor,
|
|
2185
2184
|
strokeStyle: toolStrokeStyle,
|
|
2186
2185
|
strokeDashArray: toolStrokeDashArray,
|
|
2186
|
+
created: /* @__PURE__ */ new Date(),
|
|
2187
2187
|
pageIndex,
|
|
2188
|
-
id:
|
|
2188
|
+
id: uuidV4()
|
|
2189
2189
|
};
|
|
2190
2190
|
annotationProvides.createAnnotation(pageIndex, anno);
|
|
2191
2191
|
annotationProvides.setActiveVariant(null);
|
|
2192
2192
|
annotationProvides.selectAnnotation(pageIndex, anno.id);
|
|
2193
2193
|
}
|
|
2194
2194
|
}
|
|
2195
|
-
(
|
|
2195
|
+
(_a = evt.releasePointerCapture) == null ? void 0 : _a.call(evt);
|
|
2196
2196
|
setStart(null);
|
|
2197
2197
|
setCurrent(null);
|
|
2198
2198
|
},
|
|
2199
2199
|
onPointerCancel: (_, evt) => {
|
|
2200
|
-
var _a
|
|
2201
|
-
(
|
|
2200
|
+
var _a;
|
|
2201
|
+
(_a = evt.releasePointerCapture) == null ? void 0 : _a.call(evt);
|
|
2202
2202
|
setStart(null);
|
|
2203
2203
|
setCurrent(null);
|
|
2204
2204
|
}
|
|
@@ -2291,7 +2291,6 @@ const SquarePaint = ({
|
|
|
2291
2291
|
const toolStrokeStyle = activeTool.defaults.strokeStyle ?? PdfAnnotationBorderStyle.SOLID;
|
|
2292
2292
|
const toolStrokeDashArray = activeTool.defaults.strokeDashArray ?? [];
|
|
2293
2293
|
const { register } = usePointerHandlers({ modeId: "square", pageIndex });
|
|
2294
|
-
const clamp = (v, min, max) => Math.max(min, Math.min(max, v));
|
|
2295
2294
|
const pageWidthPDF = pageWidth / scale;
|
|
2296
2295
|
const pageHeightPDF = pageHeight / scale;
|
|
2297
2296
|
const [start, setStart] = useState(null);
|
|
@@ -2339,7 +2338,8 @@ const SquarePaint = ({
|
|
|
2339
2338
|
strokeStyle: toolStrokeStyle,
|
|
2340
2339
|
strokeDashArray: toolStrokeDashArray,
|
|
2341
2340
|
pageIndex,
|
|
2342
|
-
id:
|
|
2341
|
+
id: uuidV4(),
|
|
2342
|
+
created: /* @__PURE__ */ new Date()
|
|
2343
2343
|
};
|
|
2344
2344
|
annotationProvides.createAnnotation(pageIndex, anno);
|
|
2345
2345
|
annotationProvides.setActiveVariant(null);
|
|
@@ -2442,7 +2442,6 @@ const PolylinePaint = ({
|
|
|
2442
2442
|
const toolStrokeStyle = activeTool.defaults.strokeStyle ?? PdfAnnotationBorderStyle.SOLID;
|
|
2443
2443
|
const toolStrokeDashArray = activeTool.defaults.strokeDashArray;
|
|
2444
2444
|
const { register } = usePointerHandlers({ modeId: "polyline", pageIndex });
|
|
2445
|
-
const clamp = (v, min, max) => Math.max(min, Math.min(max, v));
|
|
2446
2445
|
const pageWidthPDF = pageWidth / scale;
|
|
2447
2446
|
const pageHeightPDF = pageHeight / scale;
|
|
2448
2447
|
const [vertices, setVertices] = useState([]);
|
|
@@ -2462,7 +2461,8 @@ const PolylinePaint = ({
|
|
|
2462
2461
|
strokeDashArray: toolStrokeDashArray,
|
|
2463
2462
|
lineEndings: toolLineEndings,
|
|
2464
2463
|
pageIndex,
|
|
2465
|
-
id:
|
|
2464
|
+
id: uuidV4(),
|
|
2465
|
+
created: /* @__PURE__ */ new Date()
|
|
2466
2466
|
};
|
|
2467
2467
|
annotationProvides.createAnnotation(pageIndex, anno);
|
|
2468
2468
|
annotationProvides.setActiveVariant(null);
|
|
@@ -2549,7 +2549,6 @@ const LinePaint = ({ pageIndex, scale, pageWidth, pageHeight, cursor }) => {
|
|
|
2549
2549
|
const toolLineEndings = activeTool.defaults.lineEndings;
|
|
2550
2550
|
const intent = activeTool.defaults.intent;
|
|
2551
2551
|
const { register } = usePointerHandlers({ modeId: ["line", "lineArrow"], pageIndex });
|
|
2552
|
-
const clamp = (v, min, max) => Math.max(min, Math.min(max, v));
|
|
2553
2552
|
const pageWidthPDF = pageWidth / scale;
|
|
2554
2553
|
const pageHeightPDF = pageHeight / scale;
|
|
2555
2554
|
const [start, setStart] = useState(null);
|
|
@@ -2570,7 +2569,8 @@ const LinePaint = ({ pageIndex, scale, pageWidth, pageHeight, cursor }) => {
|
|
|
2570
2569
|
lineEndings: toolLineEndings,
|
|
2571
2570
|
intent,
|
|
2572
2571
|
pageIndex,
|
|
2573
|
-
id:
|
|
2572
|
+
id: uuidV4(),
|
|
2573
|
+
created: /* @__PURE__ */ new Date()
|
|
2574
2574
|
};
|
|
2575
2575
|
annotationProvides.createAnnotation(pageIndex, anno);
|
|
2576
2576
|
annotationProvides.setActiveVariant(null);
|
|
@@ -2579,12 +2579,12 @@ const LinePaint = ({ pageIndex, scale, pageWidth, pageHeight, cursor }) => {
|
|
|
2579
2579
|
const handlers = useMemo(
|
|
2580
2580
|
() => ({
|
|
2581
2581
|
onPointerDown: (pos, evt) => {
|
|
2582
|
-
var _a
|
|
2582
|
+
var _a;
|
|
2583
2583
|
const x = clamp(pos.x, 0, pageWidthPDF);
|
|
2584
2584
|
const y = clamp(pos.y, 0, pageHeightPDF);
|
|
2585
2585
|
setStart({ x, y });
|
|
2586
2586
|
setCurrent({ x, y });
|
|
2587
|
-
(
|
|
2587
|
+
(_a = evt.setPointerCapture) == null ? void 0 : _a.call(evt);
|
|
2588
2588
|
},
|
|
2589
2589
|
onPointerMove: (pos) => {
|
|
2590
2590
|
if (!start) return;
|
|
@@ -2593,17 +2593,17 @@ const LinePaint = ({ pageIndex, scale, pageWidth, pageHeight, cursor }) => {
|
|
|
2593
2593
|
setCurrent({ x, y });
|
|
2594
2594
|
},
|
|
2595
2595
|
onPointerUp: (_, evt) => {
|
|
2596
|
-
var _a
|
|
2596
|
+
var _a;
|
|
2597
2597
|
if (start && current && annotationProvides) {
|
|
2598
2598
|
commitLine(start, current);
|
|
2599
2599
|
}
|
|
2600
|
-
(
|
|
2600
|
+
(_a = evt.releasePointerCapture) == null ? void 0 : _a.call(evt);
|
|
2601
2601
|
setStart(null);
|
|
2602
2602
|
setCurrent(null);
|
|
2603
2603
|
},
|
|
2604
2604
|
onPointerCancel: (_, evt) => {
|
|
2605
|
-
var _a
|
|
2606
|
-
(
|
|
2605
|
+
var _a;
|
|
2606
|
+
(_a = evt.releasePointerCapture) == null ? void 0 : _a.call(evt);
|
|
2607
2607
|
setStart(null);
|
|
2608
2608
|
setCurrent(null);
|
|
2609
2609
|
}
|
|
@@ -2666,7 +2666,6 @@ const PolygonPaint = ({
|
|
|
2666
2666
|
const toolStrokeStyle = activeTool.defaults.strokeStyle ?? PdfAnnotationBorderStyle.SOLID;
|
|
2667
2667
|
const toolStrokeDashArray = activeTool.defaults.strokeDashArray;
|
|
2668
2668
|
const { register } = usePointerHandlers({ modeId: "polygon", pageIndex });
|
|
2669
|
-
const clamp = (v, min, max) => Math.max(min, Math.min(max, v));
|
|
2670
2669
|
const pageWidthPDF = pageWidth / scale;
|
|
2671
2670
|
const pageHeightPDF = pageHeight / scale;
|
|
2672
2671
|
const [vertices, setVertices] = useState([]);
|
|
@@ -2692,7 +2691,8 @@ const PolygonPaint = ({
|
|
|
2692
2691
|
strokeStyle: toolStrokeStyle,
|
|
2693
2692
|
strokeDashArray: toolStrokeDashArray,
|
|
2694
2693
|
pageIndex,
|
|
2695
|
-
id:
|
|
2694
|
+
id: uuidV4(),
|
|
2695
|
+
created: /* @__PURE__ */ new Date()
|
|
2696
2696
|
};
|
|
2697
2697
|
annotationProvides.createAnnotation(pageIndex, anno);
|
|
2698
2698
|
annotationProvides.setActiveVariant(null);
|
|
@@ -2854,7 +2854,7 @@ const FreeTextPaint = ({
|
|
|
2854
2854
|
const toolVerticalAlign = activeTool.defaults.verticalAlign;
|
|
2855
2855
|
const toolContent = activeTool.defaults.content ?? "Insert text here";
|
|
2856
2856
|
const { register } = usePointerHandlers({ modeId: "freeText", pageIndex });
|
|
2857
|
-
const
|
|
2857
|
+
const clamp2 = (v, min, max) => Math.max(min, Math.min(max, v));
|
|
2858
2858
|
const pageWidthPDF = pageWidth / scale;
|
|
2859
2859
|
const pageHeightPDF = pageHeight / scale;
|
|
2860
2860
|
const [start, setStart] = useState(null);
|
|
@@ -2883,7 +2883,8 @@ const FreeTextPaint = ({
|
|
|
2883
2883
|
textAlign: toolTextAlign,
|
|
2884
2884
|
verticalAlign: toolVerticalAlign,
|
|
2885
2885
|
pageIndex,
|
|
2886
|
-
id:
|
|
2886
|
+
id: uuidV4(),
|
|
2887
|
+
created: /* @__PURE__ */ new Date()
|
|
2887
2888
|
};
|
|
2888
2889
|
annotationProvides.createAnnotation(pageIndex, anno);
|
|
2889
2890
|
annotationProvides.setActiveVariant(null);
|
|
@@ -2892,31 +2893,31 @@ const FreeTextPaint = ({
|
|
|
2892
2893
|
const handlers = useMemo(
|
|
2893
2894
|
() => ({
|
|
2894
2895
|
onPointerDown: (pos, evt) => {
|
|
2895
|
-
var _a
|
|
2896
|
-
const x =
|
|
2897
|
-
const y =
|
|
2896
|
+
var _a;
|
|
2897
|
+
const x = clamp2(pos.x, 0, pageWidthPDF);
|
|
2898
|
+
const y = clamp2(pos.y, 0, pageHeightPDF);
|
|
2898
2899
|
setStart({ x, y });
|
|
2899
2900
|
setCurrent({ x, y });
|
|
2900
|
-
(
|
|
2901
|
+
(_a = evt.setPointerCapture) == null ? void 0 : _a.call(evt);
|
|
2901
2902
|
},
|
|
2902
2903
|
onPointerMove: (pos) => {
|
|
2903
2904
|
if (!start) return;
|
|
2904
|
-
const x =
|
|
2905
|
-
const y =
|
|
2905
|
+
const x = clamp2(pos.x, 0, pageWidthPDF);
|
|
2906
|
+
const y = clamp2(pos.y, 0, pageHeightPDF);
|
|
2906
2907
|
setCurrent({ x, y });
|
|
2907
2908
|
},
|
|
2908
2909
|
onPointerUp: (_, evt) => {
|
|
2909
|
-
var _a
|
|
2910
|
+
var _a;
|
|
2910
2911
|
if (start && current && annotationProvides) {
|
|
2911
2912
|
commitFreeText(start, current);
|
|
2912
2913
|
}
|
|
2913
|
-
(
|
|
2914
|
+
(_a = evt.releasePointerCapture) == null ? void 0 : _a.call(evt);
|
|
2914
2915
|
setStart(null);
|
|
2915
2916
|
setCurrent(null);
|
|
2916
2917
|
},
|
|
2917
2918
|
onPointerCancel: (_, evt) => {
|
|
2918
|
-
var _a
|
|
2919
|
-
(
|
|
2919
|
+
var _a;
|
|
2920
|
+
(_a = evt.releasePointerCapture) == null ? void 0 : _a.call(evt);
|
|
2920
2921
|
setStart(null);
|
|
2921
2922
|
setCurrent(null);
|
|
2922
2923
|
}
|
|
@@ -2979,7 +2980,6 @@ const StampPaint = ({ pageIndex, scale, pageWidth, pageHeight }) => {
|
|
|
2979
2980
|
const { register } = usePointerHandlers({ modeId: "stamp", pageIndex });
|
|
2980
2981
|
const pageWidthPDF = pageWidth / scale;
|
|
2981
2982
|
const pageHeightPDF = pageHeight / scale;
|
|
2982
|
-
const clamp = (v, min, max) => Math.max(min, Math.min(max, v));
|
|
2983
2983
|
const [start, setStart] = useState(null);
|
|
2984
2984
|
const handlers = useMemo(
|
|
2985
2985
|
() => ({
|
|
@@ -3029,7 +3029,8 @@ const StampPaint = ({ pageIndex, scale, pageWidth, pageHeight }) => {
|
|
|
3029
3029
|
type: PdfAnnotationSubtype.STAMP,
|
|
3030
3030
|
flags: ["print"],
|
|
3031
3031
|
pageIndex,
|
|
3032
|
-
id:
|
|
3032
|
+
id: uuidV4(),
|
|
3033
|
+
created: /* @__PURE__ */ new Date(),
|
|
3033
3034
|
rect
|
|
3034
3035
|
};
|
|
3035
3036
|
annotationProvides.createAnnotation(pageIndex, anno, { imageData });
|