@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/preact/index.js
CHANGED
|
@@ -6,6 +6,7 @@ import { usePointerHandlers } from "@embedpdf/plugin-interaction-manager/preact"
|
|
|
6
6
|
import { useSelectionCapability } from "@embedpdf/plugin-selection/preact";
|
|
7
7
|
import { Fragment } from "preact";
|
|
8
8
|
import { useState, useRef, useEffect, useLayoutEffect, useMemo, useCallback } from "preact/hooks";
|
|
9
|
+
import { clamp } from "@embedpdf/core";
|
|
9
10
|
const useAnnotationPlugin = () => usePlugin(AnnotationPlugin.id);
|
|
10
11
|
const useAnnotationCapability = () => useCapability(AnnotationPlugin.id);
|
|
11
12
|
const mapDoubleClick = (handler) => handler ? { onDblClick: handler } : {};
|
|
@@ -163,7 +164,7 @@ function useDragResize({
|
|
|
163
164
|
const dir = useRef("none");
|
|
164
165
|
const startPos = useRef(null);
|
|
165
166
|
const startRect = useRef(null);
|
|
166
|
-
const
|
|
167
|
+
const clamp2 = (v, min, max) => Math.max(min, Math.min(max, v));
|
|
167
168
|
const pageW = pageWidth / scale;
|
|
168
169
|
const pageH = pageHeight / scale;
|
|
169
170
|
const applyDelta = (dx, dy) => {
|
|
@@ -206,10 +207,10 @@ function useDragResize({
|
|
|
206
207
|
}
|
|
207
208
|
}
|
|
208
209
|
if (w < 1 || h < 1) return currentRect;
|
|
209
|
-
w =
|
|
210
|
-
h =
|
|
211
|
-
ox =
|
|
212
|
-
oy =
|
|
210
|
+
w = clamp2(w, 1, pageW);
|
|
211
|
+
h = clamp2(h, 1, pageH);
|
|
212
|
+
ox = clamp2(ox, 0, pageW - w);
|
|
213
|
+
oy = clamp2(oy, 0, pageH - h);
|
|
213
214
|
return { origin: { x: ox, y: oy }, size: { width: w, height: h } };
|
|
214
215
|
};
|
|
215
216
|
const beginDrag = (kind, clientX, clientY) => {
|
|
@@ -1332,7 +1333,6 @@ function FreeText({
|
|
|
1332
1333
|
cursor: isEditing ? "text" : "pointer"
|
|
1333
1334
|
},
|
|
1334
1335
|
contentEditable: isEditing,
|
|
1335
|
-
suppressContentEditableWarning: true,
|
|
1336
1336
|
children: annotation.object.contents
|
|
1337
1337
|
}
|
|
1338
1338
|
)
|
|
@@ -1355,8 +1355,10 @@ function RenderAnnotation({
|
|
|
1355
1355
|
const task = annotationProvides.renderAnnotation({
|
|
1356
1356
|
pageIndex,
|
|
1357
1357
|
annotation,
|
|
1358
|
-
|
|
1359
|
-
|
|
1358
|
+
options: {
|
|
1359
|
+
scaleFactor,
|
|
1360
|
+
dpr: window.devicePixelRatio
|
|
1361
|
+
}
|
|
1360
1362
|
});
|
|
1361
1363
|
task.wait((blob) => {
|
|
1362
1364
|
const url = URL.createObjectURL(blob);
|
|
@@ -1974,7 +1976,6 @@ const InkPaint = ({ pageIndex, scale, pageWidth, pageHeight }) => {
|
|
|
1974
1976
|
const toolBlendMode = ((_d = activeTool.defaults) == null ? void 0 : _d.blendMode) ?? PdfBlendMode.Normal;
|
|
1975
1977
|
const intent = (_e = activeTool.defaults) == null ? void 0 : _e.intent;
|
|
1976
1978
|
const { register } = usePointerHandlers({ modeId: "ink", pageIndex });
|
|
1977
|
-
const clamp = (v, min, max) => Math.max(min, Math.min(max, v));
|
|
1978
1979
|
const [currentStrokes, setCurrentStrokes] = useState([]);
|
|
1979
1980
|
const [isDrawing, setIsDrawing] = useState(false);
|
|
1980
1981
|
const timerRef = useRef(null);
|
|
@@ -1983,7 +1984,7 @@ const InkPaint = ({ pageIndex, scale, pageWidth, pageHeight }) => {
|
|
|
1983
1984
|
const handlers = useMemo(
|
|
1984
1985
|
() => ({
|
|
1985
1986
|
onPointerDown: (pos, evt) => {
|
|
1986
|
-
var _a2
|
|
1987
|
+
var _a2;
|
|
1987
1988
|
const curX = clamp(pos.x, 0, pageWidthPDF);
|
|
1988
1989
|
const curY = clamp(pos.y, 0, pageHeightPDF);
|
|
1989
1990
|
setIsDrawing(true);
|
|
@@ -1994,7 +1995,7 @@ const InkPaint = ({ pageIndex, scale, pageWidth, pageHeight }) => {
|
|
|
1994
1995
|
} else {
|
|
1995
1996
|
setCurrentStrokes([{ points: [{ x: curX, y: curY }] }]);
|
|
1996
1997
|
}
|
|
1997
|
-
(
|
|
1998
|
+
(_a2 = evt.setPointerCapture) == null ? void 0 : _a2.call(evt);
|
|
1998
1999
|
},
|
|
1999
2000
|
onPointerMove: (pos) => {
|
|
2000
2001
|
if (!isDrawing) return;
|
|
@@ -2008,9 +2009,9 @@ const InkPaint = ({ pageIndex, scale, pageWidth, pageHeight }) => {
|
|
|
2008
2009
|
});
|
|
2009
2010
|
},
|
|
2010
2011
|
onPointerUp: (_, evt) => {
|
|
2011
|
-
var _a2
|
|
2012
|
+
var _a2;
|
|
2012
2013
|
setIsDrawing(false);
|
|
2013
|
-
(
|
|
2014
|
+
(_a2 = evt.releasePointerCapture) == null ? void 0 : _a2.call(evt);
|
|
2014
2015
|
if (timerRef.current) clearTimeout(timerRef.current);
|
|
2015
2016
|
timerRef.current = setTimeout(() => {
|
|
2016
2017
|
if (currentStrokes.length && annotationProvides) {
|
|
@@ -2040,9 +2041,9 @@ const InkPaint = ({ pageIndex, scale, pageWidth, pageHeight }) => {
|
|
|
2040
2041
|
}, 3e3);
|
|
2041
2042
|
},
|
|
2042
2043
|
onPointerCancel: (_, evt) => {
|
|
2043
|
-
var _a2
|
|
2044
|
+
var _a2;
|
|
2044
2045
|
setIsDrawing(false);
|
|
2045
|
-
(
|
|
2046
|
+
(_a2 = evt.releasePointerCapture) == null ? void 0 : _a2.call(evt);
|
|
2046
2047
|
setCurrentStrokes([]);
|
|
2047
2048
|
if (timerRef.current) {
|
|
2048
2049
|
clearTimeout(timerRef.current);
|
|
@@ -2139,7 +2140,6 @@ const CirclePaint = ({
|
|
|
2139
2140
|
const toolStrokeStyle = activeTool.defaults.strokeStyle ?? PdfAnnotationBorderStyle.SOLID;
|
|
2140
2141
|
const toolStrokeDashArray = activeTool.defaults.strokeDashArray ?? [];
|
|
2141
2142
|
const { register } = usePointerHandlers({ modeId: "circle", pageIndex });
|
|
2142
|
-
const clamp = (v, min, max) => Math.max(min, Math.min(max, v));
|
|
2143
2143
|
const pageWidthPDF = pageWidth / scale;
|
|
2144
2144
|
const pageHeightPDF = pageHeight / scale;
|
|
2145
2145
|
const [start, setStart] = useState(null);
|
|
@@ -2147,12 +2147,12 @@ const CirclePaint = ({
|
|
|
2147
2147
|
const handlers = useMemo(
|
|
2148
2148
|
() => ({
|
|
2149
2149
|
onPointerDown: (pos, evt) => {
|
|
2150
|
-
var _a
|
|
2150
|
+
var _a;
|
|
2151
2151
|
const x = clamp(pos.x, 0, pageWidthPDF);
|
|
2152
2152
|
const y = clamp(pos.y, 0, pageHeightPDF);
|
|
2153
2153
|
setStart({ x, y });
|
|
2154
2154
|
setCurrent({ x, y });
|
|
2155
|
-
(
|
|
2155
|
+
(_a = evt.setPointerCapture) == null ? void 0 : _a.call(evt);
|
|
2156
2156
|
},
|
|
2157
2157
|
onPointerMove: (pos) => {
|
|
2158
2158
|
if (!start) return;
|
|
@@ -2161,7 +2161,7 @@ const CirclePaint = ({
|
|
|
2161
2161
|
setCurrent({ x, y });
|
|
2162
2162
|
},
|
|
2163
2163
|
onPointerUp: (_, evt) => {
|
|
2164
|
-
var _a
|
|
2164
|
+
var _a;
|
|
2165
2165
|
if (start && current && annotationProvides) {
|
|
2166
2166
|
const minX2 = Math.min(start.x, current.x);
|
|
2167
2167
|
const minY2 = Math.min(start.y, current.y);
|
|
@@ -2195,13 +2195,13 @@ const CirclePaint = ({
|
|
|
2195
2195
|
annotationProvides.selectAnnotation(pageIndex, anno.id);
|
|
2196
2196
|
}
|
|
2197
2197
|
}
|
|
2198
|
-
(
|
|
2198
|
+
(_a = evt.releasePointerCapture) == null ? void 0 : _a.call(evt);
|
|
2199
2199
|
setStart(null);
|
|
2200
2200
|
setCurrent(null);
|
|
2201
2201
|
},
|
|
2202
2202
|
onPointerCancel: (_, evt) => {
|
|
2203
|
-
var _a
|
|
2204
|
-
(
|
|
2203
|
+
var _a;
|
|
2204
|
+
(_a = evt.releasePointerCapture) == null ? void 0 : _a.call(evt);
|
|
2205
2205
|
setStart(null);
|
|
2206
2206
|
setCurrent(null);
|
|
2207
2207
|
}
|
|
@@ -2294,7 +2294,6 @@ const SquarePaint = ({
|
|
|
2294
2294
|
const toolStrokeStyle = activeTool.defaults.strokeStyle ?? PdfAnnotationBorderStyle.SOLID;
|
|
2295
2295
|
const toolStrokeDashArray = activeTool.defaults.strokeDashArray ?? [];
|
|
2296
2296
|
const { register } = usePointerHandlers({ modeId: "square", pageIndex });
|
|
2297
|
-
const clamp = (v, min, max) => Math.max(min, Math.min(max, v));
|
|
2298
2297
|
const pageWidthPDF = pageWidth / scale;
|
|
2299
2298
|
const pageHeightPDF = pageHeight / scale;
|
|
2300
2299
|
const [start, setStart] = useState(null);
|
|
@@ -2446,7 +2445,6 @@ const PolylinePaint = ({
|
|
|
2446
2445
|
const toolStrokeStyle = activeTool.defaults.strokeStyle ?? PdfAnnotationBorderStyle.SOLID;
|
|
2447
2446
|
const toolStrokeDashArray = activeTool.defaults.strokeDashArray;
|
|
2448
2447
|
const { register } = usePointerHandlers({ modeId: "polyline", pageIndex });
|
|
2449
|
-
const clamp = (v, min, max) => Math.max(min, Math.min(max, v));
|
|
2450
2448
|
const pageWidthPDF = pageWidth / scale;
|
|
2451
2449
|
const pageHeightPDF = pageHeight / scale;
|
|
2452
2450
|
const [vertices, setVertices] = useState([]);
|
|
@@ -2554,7 +2552,6 @@ const LinePaint = ({ pageIndex, scale, pageWidth, pageHeight, cursor }) => {
|
|
|
2554
2552
|
const toolLineEndings = activeTool.defaults.lineEndings;
|
|
2555
2553
|
const intent = activeTool.defaults.intent;
|
|
2556
2554
|
const { register } = usePointerHandlers({ modeId: ["line", "lineArrow"], pageIndex });
|
|
2557
|
-
const clamp = (v, min, max) => Math.max(min, Math.min(max, v));
|
|
2558
2555
|
const pageWidthPDF = pageWidth / scale;
|
|
2559
2556
|
const pageHeightPDF = pageHeight / scale;
|
|
2560
2557
|
const [start, setStart] = useState(null);
|
|
@@ -2585,12 +2582,12 @@ const LinePaint = ({ pageIndex, scale, pageWidth, pageHeight, cursor }) => {
|
|
|
2585
2582
|
const handlers = useMemo(
|
|
2586
2583
|
() => ({
|
|
2587
2584
|
onPointerDown: (pos, evt) => {
|
|
2588
|
-
var _a
|
|
2585
|
+
var _a;
|
|
2589
2586
|
const x = clamp(pos.x, 0, pageWidthPDF);
|
|
2590
2587
|
const y = clamp(pos.y, 0, pageHeightPDF);
|
|
2591
2588
|
setStart({ x, y });
|
|
2592
2589
|
setCurrent({ x, y });
|
|
2593
|
-
(
|
|
2590
|
+
(_a = evt.setPointerCapture) == null ? void 0 : _a.call(evt);
|
|
2594
2591
|
},
|
|
2595
2592
|
onPointerMove: (pos) => {
|
|
2596
2593
|
if (!start) return;
|
|
@@ -2599,17 +2596,17 @@ const LinePaint = ({ pageIndex, scale, pageWidth, pageHeight, cursor }) => {
|
|
|
2599
2596
|
setCurrent({ x, y });
|
|
2600
2597
|
},
|
|
2601
2598
|
onPointerUp: (_, evt) => {
|
|
2602
|
-
var _a
|
|
2599
|
+
var _a;
|
|
2603
2600
|
if (start && current && annotationProvides) {
|
|
2604
2601
|
commitLine(start, current);
|
|
2605
2602
|
}
|
|
2606
|
-
(
|
|
2603
|
+
(_a = evt.releasePointerCapture) == null ? void 0 : _a.call(evt);
|
|
2607
2604
|
setStart(null);
|
|
2608
2605
|
setCurrent(null);
|
|
2609
2606
|
},
|
|
2610
2607
|
onPointerCancel: (_, evt) => {
|
|
2611
|
-
var _a
|
|
2612
|
-
(
|
|
2608
|
+
var _a;
|
|
2609
|
+
(_a = evt.releasePointerCapture) == null ? void 0 : _a.call(evt);
|
|
2613
2610
|
setStart(null);
|
|
2614
2611
|
setCurrent(null);
|
|
2615
2612
|
}
|
|
@@ -2672,7 +2669,6 @@ const PolygonPaint = ({
|
|
|
2672
2669
|
const toolStrokeStyle = activeTool.defaults.strokeStyle ?? PdfAnnotationBorderStyle.SOLID;
|
|
2673
2670
|
const toolStrokeDashArray = activeTool.defaults.strokeDashArray;
|
|
2674
2671
|
const { register } = usePointerHandlers({ modeId: "polygon", pageIndex });
|
|
2675
|
-
const clamp = (v, min, max) => Math.max(min, Math.min(max, v));
|
|
2676
2672
|
const pageWidthPDF = pageWidth / scale;
|
|
2677
2673
|
const pageHeightPDF = pageHeight / scale;
|
|
2678
2674
|
const [vertices, setVertices] = useState([]);
|
|
@@ -2861,7 +2857,7 @@ const FreeTextPaint = ({
|
|
|
2861
2857
|
const toolVerticalAlign = activeTool.defaults.verticalAlign;
|
|
2862
2858
|
const toolContent = activeTool.defaults.content ?? "Insert text here";
|
|
2863
2859
|
const { register } = usePointerHandlers({ modeId: "freeText", pageIndex });
|
|
2864
|
-
const
|
|
2860
|
+
const clamp2 = (v, min, max) => Math.max(min, Math.min(max, v));
|
|
2865
2861
|
const pageWidthPDF = pageWidth / scale;
|
|
2866
2862
|
const pageHeightPDF = pageHeight / scale;
|
|
2867
2863
|
const [start, setStart] = useState(null);
|
|
@@ -2900,31 +2896,31 @@ const FreeTextPaint = ({
|
|
|
2900
2896
|
const handlers = useMemo(
|
|
2901
2897
|
() => ({
|
|
2902
2898
|
onPointerDown: (pos, evt) => {
|
|
2903
|
-
var _a
|
|
2904
|
-
const x =
|
|
2905
|
-
const y =
|
|
2899
|
+
var _a;
|
|
2900
|
+
const x = clamp2(pos.x, 0, pageWidthPDF);
|
|
2901
|
+
const y = clamp2(pos.y, 0, pageHeightPDF);
|
|
2906
2902
|
setStart({ x, y });
|
|
2907
2903
|
setCurrent({ x, y });
|
|
2908
|
-
(
|
|
2904
|
+
(_a = evt.setPointerCapture) == null ? void 0 : _a.call(evt);
|
|
2909
2905
|
},
|
|
2910
2906
|
onPointerMove: (pos) => {
|
|
2911
2907
|
if (!start) return;
|
|
2912
|
-
const x =
|
|
2913
|
-
const y =
|
|
2908
|
+
const x = clamp2(pos.x, 0, pageWidthPDF);
|
|
2909
|
+
const y = clamp2(pos.y, 0, pageHeightPDF);
|
|
2914
2910
|
setCurrent({ x, y });
|
|
2915
2911
|
},
|
|
2916
2912
|
onPointerUp: (_, evt) => {
|
|
2917
|
-
var _a
|
|
2913
|
+
var _a;
|
|
2918
2914
|
if (start && current && annotationProvides) {
|
|
2919
2915
|
commitFreeText(start, current);
|
|
2920
2916
|
}
|
|
2921
|
-
(
|
|
2917
|
+
(_a = evt.releasePointerCapture) == null ? void 0 : _a.call(evt);
|
|
2922
2918
|
setStart(null);
|
|
2923
2919
|
setCurrent(null);
|
|
2924
2920
|
},
|
|
2925
2921
|
onPointerCancel: (_, evt) => {
|
|
2926
|
-
var _a
|
|
2927
|
-
(
|
|
2922
|
+
var _a;
|
|
2923
|
+
(_a = evt.releasePointerCapture) == null ? void 0 : _a.call(evt);
|
|
2928
2924
|
setStart(null);
|
|
2929
2925
|
setCurrent(null);
|
|
2930
2926
|
}
|
|
@@ -2987,7 +2983,6 @@ const StampPaint = ({ pageIndex, scale, pageWidth, pageHeight }) => {
|
|
|
2987
2983
|
const { register } = usePointerHandlers({ modeId: "stamp", pageIndex });
|
|
2988
2984
|
const pageWidthPDF = pageWidth / scale;
|
|
2989
2985
|
const pageHeightPDF = pageHeight / scale;
|
|
2990
|
-
const clamp = (v, min, max) => Math.max(min, Math.min(max, v));
|
|
2991
2986
|
const [start, setStart] = useState(null);
|
|
2992
2987
|
const handlers = useMemo(
|
|
2993
2988
|
() => ({
|