@embedpdf/plugin-annotation 1.0.17 → 1.0.19
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 +5 -23
- package/dist/index.js.map +1 -1
- package/dist/lib/annotation-plugin.d.ts +1 -3
- package/dist/lib/types.d.ts +2 -6
- package/dist/preact/index.cjs +1 -1
- package/dist/preact/index.cjs.map +1 -1
- package/dist/preact/index.js +39 -44
- 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 +39 -44
- package/dist/react/index.js.map +1 -1
- package/package.json +9 -9
package/dist/react/index.js
CHANGED
|
@@ -5,6 +5,7 @@ import { restoreOffset, rectEquals, PdfAnnotationBorderStyle, PdfAnnotationSubty
|
|
|
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) => {
|
|
@@ -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
|
)
|
|
@@ -1354,8 +1354,10 @@ function RenderAnnotation({
|
|
|
1354
1354
|
const task = annotationProvides.renderAnnotation({
|
|
1355
1355
|
pageIndex,
|
|
1356
1356
|
annotation,
|
|
1357
|
-
|
|
1358
|
-
|
|
1357
|
+
options: {
|
|
1358
|
+
scaleFactor,
|
|
1359
|
+
dpr: window.devicePixelRatio
|
|
1360
|
+
}
|
|
1359
1361
|
});
|
|
1360
1362
|
task.wait((blob) => {
|
|
1361
1363
|
const url = URL.createObjectURL(blob);
|
|
@@ -1973,7 +1975,6 @@ const InkPaint = ({ pageIndex, scale, pageWidth, pageHeight }) => {
|
|
|
1973
1975
|
const toolBlendMode = ((_d = activeTool.defaults) == null ? void 0 : _d.blendMode) ?? PdfBlendMode.Normal;
|
|
1974
1976
|
const intent = (_e = activeTool.defaults) == null ? void 0 : _e.intent;
|
|
1975
1977
|
const { register } = usePointerHandlers({ modeId: "ink", pageIndex });
|
|
1976
|
-
const clamp = (v, min, max) => Math.max(min, Math.min(max, v));
|
|
1977
1978
|
const [currentStrokes, setCurrentStrokes] = useState([]);
|
|
1978
1979
|
const [isDrawing, setIsDrawing] = useState(false);
|
|
1979
1980
|
const timerRef = useRef(null);
|
|
@@ -1982,7 +1983,7 @@ const InkPaint = ({ pageIndex, scale, pageWidth, pageHeight }) => {
|
|
|
1982
1983
|
const handlers = useMemo(
|
|
1983
1984
|
() => ({
|
|
1984
1985
|
onPointerDown: (pos, evt) => {
|
|
1985
|
-
var _a2
|
|
1986
|
+
var _a2;
|
|
1986
1987
|
const curX = clamp(pos.x, 0, pageWidthPDF);
|
|
1987
1988
|
const curY = clamp(pos.y, 0, pageHeightPDF);
|
|
1988
1989
|
setIsDrawing(true);
|
|
@@ -1993,7 +1994,7 @@ const InkPaint = ({ pageIndex, scale, pageWidth, pageHeight }) => {
|
|
|
1993
1994
|
} else {
|
|
1994
1995
|
setCurrentStrokes([{ points: [{ x: curX, y: curY }] }]);
|
|
1995
1996
|
}
|
|
1996
|
-
(
|
|
1997
|
+
(_a2 = evt.setPointerCapture) == null ? void 0 : _a2.call(evt);
|
|
1997
1998
|
},
|
|
1998
1999
|
onPointerMove: (pos) => {
|
|
1999
2000
|
if (!isDrawing) return;
|
|
@@ -2007,9 +2008,9 @@ const InkPaint = ({ pageIndex, scale, pageWidth, pageHeight }) => {
|
|
|
2007
2008
|
});
|
|
2008
2009
|
},
|
|
2009
2010
|
onPointerUp: (_, evt) => {
|
|
2010
|
-
var _a2
|
|
2011
|
+
var _a2;
|
|
2011
2012
|
setIsDrawing(false);
|
|
2012
|
-
(
|
|
2013
|
+
(_a2 = evt.releasePointerCapture) == null ? void 0 : _a2.call(evt);
|
|
2013
2014
|
if (timerRef.current) clearTimeout(timerRef.current);
|
|
2014
2015
|
timerRef.current = setTimeout(() => {
|
|
2015
2016
|
if (currentStrokes.length && annotationProvides) {
|
|
@@ -2039,9 +2040,9 @@ const InkPaint = ({ pageIndex, scale, pageWidth, pageHeight }) => {
|
|
|
2039
2040
|
}, 3e3);
|
|
2040
2041
|
},
|
|
2041
2042
|
onPointerCancel: (_, evt) => {
|
|
2042
|
-
var _a2
|
|
2043
|
+
var _a2;
|
|
2043
2044
|
setIsDrawing(false);
|
|
2044
|
-
(
|
|
2045
|
+
(_a2 = evt.releasePointerCapture) == null ? void 0 : _a2.call(evt);
|
|
2045
2046
|
setCurrentStrokes([]);
|
|
2046
2047
|
if (timerRef.current) {
|
|
2047
2048
|
clearTimeout(timerRef.current);
|
|
@@ -2138,7 +2139,6 @@ const CirclePaint = ({
|
|
|
2138
2139
|
const toolStrokeStyle = activeTool.defaults.strokeStyle ?? PdfAnnotationBorderStyle.SOLID;
|
|
2139
2140
|
const toolStrokeDashArray = activeTool.defaults.strokeDashArray ?? [];
|
|
2140
2141
|
const { register } = usePointerHandlers({ modeId: "circle", pageIndex });
|
|
2141
|
-
const clamp = (v, min, max) => Math.max(min, Math.min(max, v));
|
|
2142
2142
|
const pageWidthPDF = pageWidth / scale;
|
|
2143
2143
|
const pageHeightPDF = pageHeight / scale;
|
|
2144
2144
|
const [start, setStart] = useState(null);
|
|
@@ -2146,12 +2146,12 @@ const CirclePaint = ({
|
|
|
2146
2146
|
const handlers = useMemo(
|
|
2147
2147
|
() => ({
|
|
2148
2148
|
onPointerDown: (pos, evt) => {
|
|
2149
|
-
var _a
|
|
2149
|
+
var _a;
|
|
2150
2150
|
const x = clamp(pos.x, 0, pageWidthPDF);
|
|
2151
2151
|
const y = clamp(pos.y, 0, pageHeightPDF);
|
|
2152
2152
|
setStart({ x, y });
|
|
2153
2153
|
setCurrent({ x, y });
|
|
2154
|
-
(
|
|
2154
|
+
(_a = evt.setPointerCapture) == null ? void 0 : _a.call(evt);
|
|
2155
2155
|
},
|
|
2156
2156
|
onPointerMove: (pos) => {
|
|
2157
2157
|
if (!start) return;
|
|
@@ -2160,7 +2160,7 @@ const CirclePaint = ({
|
|
|
2160
2160
|
setCurrent({ x, y });
|
|
2161
2161
|
},
|
|
2162
2162
|
onPointerUp: (_, evt) => {
|
|
2163
|
-
var _a
|
|
2163
|
+
var _a;
|
|
2164
2164
|
if (start && current && annotationProvides) {
|
|
2165
2165
|
const minX2 = Math.min(start.x, current.x);
|
|
2166
2166
|
const minY2 = Math.min(start.y, current.y);
|
|
@@ -2194,13 +2194,13 @@ const CirclePaint = ({
|
|
|
2194
2194
|
annotationProvides.selectAnnotation(pageIndex, anno.id);
|
|
2195
2195
|
}
|
|
2196
2196
|
}
|
|
2197
|
-
(
|
|
2197
|
+
(_a = evt.releasePointerCapture) == null ? void 0 : _a.call(evt);
|
|
2198
2198
|
setStart(null);
|
|
2199
2199
|
setCurrent(null);
|
|
2200
2200
|
},
|
|
2201
2201
|
onPointerCancel: (_, evt) => {
|
|
2202
|
-
var _a
|
|
2203
|
-
(
|
|
2202
|
+
var _a;
|
|
2203
|
+
(_a = evt.releasePointerCapture) == null ? void 0 : _a.call(evt);
|
|
2204
2204
|
setStart(null);
|
|
2205
2205
|
setCurrent(null);
|
|
2206
2206
|
}
|
|
@@ -2293,7 +2293,6 @@ const SquarePaint = ({
|
|
|
2293
2293
|
const toolStrokeStyle = activeTool.defaults.strokeStyle ?? PdfAnnotationBorderStyle.SOLID;
|
|
2294
2294
|
const toolStrokeDashArray = activeTool.defaults.strokeDashArray ?? [];
|
|
2295
2295
|
const { register } = usePointerHandlers({ modeId: "square", pageIndex });
|
|
2296
|
-
const clamp = (v, min, max) => Math.max(min, Math.min(max, v));
|
|
2297
2296
|
const pageWidthPDF = pageWidth / scale;
|
|
2298
2297
|
const pageHeightPDF = pageHeight / scale;
|
|
2299
2298
|
const [start, setStart] = useState(null);
|
|
@@ -2445,7 +2444,6 @@ const PolylinePaint = ({
|
|
|
2445
2444
|
const toolStrokeStyle = activeTool.defaults.strokeStyle ?? PdfAnnotationBorderStyle.SOLID;
|
|
2446
2445
|
const toolStrokeDashArray = activeTool.defaults.strokeDashArray;
|
|
2447
2446
|
const { register } = usePointerHandlers({ modeId: "polyline", pageIndex });
|
|
2448
|
-
const clamp = (v, min, max) => Math.max(min, Math.min(max, v));
|
|
2449
2447
|
const pageWidthPDF = pageWidth / scale;
|
|
2450
2448
|
const pageHeightPDF = pageHeight / scale;
|
|
2451
2449
|
const [vertices, setVertices] = useState([]);
|
|
@@ -2553,7 +2551,6 @@ const LinePaint = ({ pageIndex, scale, pageWidth, pageHeight, cursor }) => {
|
|
|
2553
2551
|
const toolLineEndings = activeTool.defaults.lineEndings;
|
|
2554
2552
|
const intent = activeTool.defaults.intent;
|
|
2555
2553
|
const { register } = usePointerHandlers({ modeId: ["line", "lineArrow"], pageIndex });
|
|
2556
|
-
const clamp = (v, min, max) => Math.max(min, Math.min(max, v));
|
|
2557
2554
|
const pageWidthPDF = pageWidth / scale;
|
|
2558
2555
|
const pageHeightPDF = pageHeight / scale;
|
|
2559
2556
|
const [start, setStart] = useState(null);
|
|
@@ -2584,12 +2581,12 @@ const LinePaint = ({ pageIndex, scale, pageWidth, pageHeight, cursor }) => {
|
|
|
2584
2581
|
const handlers = useMemo(
|
|
2585
2582
|
() => ({
|
|
2586
2583
|
onPointerDown: (pos, evt) => {
|
|
2587
|
-
var _a
|
|
2584
|
+
var _a;
|
|
2588
2585
|
const x = clamp(pos.x, 0, pageWidthPDF);
|
|
2589
2586
|
const y = clamp(pos.y, 0, pageHeightPDF);
|
|
2590
2587
|
setStart({ x, y });
|
|
2591
2588
|
setCurrent({ x, y });
|
|
2592
|
-
(
|
|
2589
|
+
(_a = evt.setPointerCapture) == null ? void 0 : _a.call(evt);
|
|
2593
2590
|
},
|
|
2594
2591
|
onPointerMove: (pos) => {
|
|
2595
2592
|
if (!start) return;
|
|
@@ -2598,17 +2595,17 @@ const LinePaint = ({ pageIndex, scale, pageWidth, pageHeight, cursor }) => {
|
|
|
2598
2595
|
setCurrent({ x, y });
|
|
2599
2596
|
},
|
|
2600
2597
|
onPointerUp: (_, evt) => {
|
|
2601
|
-
var _a
|
|
2598
|
+
var _a;
|
|
2602
2599
|
if (start && current && annotationProvides) {
|
|
2603
2600
|
commitLine(start, current);
|
|
2604
2601
|
}
|
|
2605
|
-
(
|
|
2602
|
+
(_a = evt.releasePointerCapture) == null ? void 0 : _a.call(evt);
|
|
2606
2603
|
setStart(null);
|
|
2607
2604
|
setCurrent(null);
|
|
2608
2605
|
},
|
|
2609
2606
|
onPointerCancel: (_, evt) => {
|
|
2610
|
-
var _a
|
|
2611
|
-
(
|
|
2607
|
+
var _a;
|
|
2608
|
+
(_a = evt.releasePointerCapture) == null ? void 0 : _a.call(evt);
|
|
2612
2609
|
setStart(null);
|
|
2613
2610
|
setCurrent(null);
|
|
2614
2611
|
}
|
|
@@ -2671,7 +2668,6 @@ const PolygonPaint = ({
|
|
|
2671
2668
|
const toolStrokeStyle = activeTool.defaults.strokeStyle ?? PdfAnnotationBorderStyle.SOLID;
|
|
2672
2669
|
const toolStrokeDashArray = activeTool.defaults.strokeDashArray;
|
|
2673
2670
|
const { register } = usePointerHandlers({ modeId: "polygon", pageIndex });
|
|
2674
|
-
const clamp = (v, min, max) => Math.max(min, Math.min(max, v));
|
|
2675
2671
|
const pageWidthPDF = pageWidth / scale;
|
|
2676
2672
|
const pageHeightPDF = pageHeight / scale;
|
|
2677
2673
|
const [vertices, setVertices] = useState([]);
|
|
@@ -2860,7 +2856,7 @@ const FreeTextPaint = ({
|
|
|
2860
2856
|
const toolVerticalAlign = activeTool.defaults.verticalAlign;
|
|
2861
2857
|
const toolContent = activeTool.defaults.content ?? "Insert text here";
|
|
2862
2858
|
const { register } = usePointerHandlers({ modeId: "freeText", pageIndex });
|
|
2863
|
-
const
|
|
2859
|
+
const clamp2 = (v, min, max) => Math.max(min, Math.min(max, v));
|
|
2864
2860
|
const pageWidthPDF = pageWidth / scale;
|
|
2865
2861
|
const pageHeightPDF = pageHeight / scale;
|
|
2866
2862
|
const [start, setStart] = useState(null);
|
|
@@ -2899,31 +2895,31 @@ const FreeTextPaint = ({
|
|
|
2899
2895
|
const handlers = useMemo(
|
|
2900
2896
|
() => ({
|
|
2901
2897
|
onPointerDown: (pos, evt) => {
|
|
2902
|
-
var _a
|
|
2903
|
-
const x =
|
|
2904
|
-
const y =
|
|
2898
|
+
var _a;
|
|
2899
|
+
const x = clamp2(pos.x, 0, pageWidthPDF);
|
|
2900
|
+
const y = clamp2(pos.y, 0, pageHeightPDF);
|
|
2905
2901
|
setStart({ x, y });
|
|
2906
2902
|
setCurrent({ x, y });
|
|
2907
|
-
(
|
|
2903
|
+
(_a = evt.setPointerCapture) == null ? void 0 : _a.call(evt);
|
|
2908
2904
|
},
|
|
2909
2905
|
onPointerMove: (pos) => {
|
|
2910
2906
|
if (!start) return;
|
|
2911
|
-
const x =
|
|
2912
|
-
const y =
|
|
2907
|
+
const x = clamp2(pos.x, 0, pageWidthPDF);
|
|
2908
|
+
const y = clamp2(pos.y, 0, pageHeightPDF);
|
|
2913
2909
|
setCurrent({ x, y });
|
|
2914
2910
|
},
|
|
2915
2911
|
onPointerUp: (_, evt) => {
|
|
2916
|
-
var _a
|
|
2912
|
+
var _a;
|
|
2917
2913
|
if (start && current && annotationProvides) {
|
|
2918
2914
|
commitFreeText(start, current);
|
|
2919
2915
|
}
|
|
2920
|
-
(
|
|
2916
|
+
(_a = evt.releasePointerCapture) == null ? void 0 : _a.call(evt);
|
|
2921
2917
|
setStart(null);
|
|
2922
2918
|
setCurrent(null);
|
|
2923
2919
|
},
|
|
2924
2920
|
onPointerCancel: (_, evt) => {
|
|
2925
|
-
var _a
|
|
2926
|
-
(
|
|
2921
|
+
var _a;
|
|
2922
|
+
(_a = evt.releasePointerCapture) == null ? void 0 : _a.call(evt);
|
|
2927
2923
|
setStart(null);
|
|
2928
2924
|
setCurrent(null);
|
|
2929
2925
|
}
|
|
@@ -2986,7 +2982,6 @@ const StampPaint = ({ pageIndex, scale, pageWidth, pageHeight }) => {
|
|
|
2986
2982
|
const { register } = usePointerHandlers({ modeId: "stamp", pageIndex });
|
|
2987
2983
|
const pageWidthPDF = pageWidth / scale;
|
|
2988
2984
|
const pageHeightPDF = pageHeight / scale;
|
|
2989
|
-
const clamp = (v, min, max) => Math.max(min, Math.min(max, v));
|
|
2990
2985
|
const [start, setStart] = useState(null);
|
|
2991
2986
|
const handlers = useMemo(
|
|
2992
2987
|
() => ({
|