@embedpdf/plugin-annotation 1.0.17 → 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.
@@ -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 clamp = (v, min, max) => Math.max(min, Math.min(max, v));
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 = clamp(w, 1, pageW);
209
- h = clamp(h, 1, pageH);
210
- ox = clamp(ox, 0, pageW - w);
211
- oy = clamp(oy, 0, pageH - h);
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
  )
@@ -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, _b2;
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
- (_b2 = (_a2 = evt.target) == null ? void 0 : _a2.setPointerCapture) == null ? void 0 : _b2.call(_a2, evt.pointerId);
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, _b2;
2009
+ var _a2;
2011
2010
  setIsDrawing(false);
2012
- (_b2 = (_a2 = evt.target) == null ? void 0 : _a2.releasePointerCapture) == null ? void 0 : _b2.call(_a2, evt.pointerId);
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) {
@@ -2039,9 +2038,9 @@ const InkPaint = ({ pageIndex, scale, pageWidth, pageHeight }) => {
2039
2038
  }, 3e3);
2040
2039
  },
2041
2040
  onPointerCancel: (_, evt) => {
2042
- var _a2, _b2;
2041
+ var _a2;
2043
2042
  setIsDrawing(false);
2044
- (_b2 = (_a2 = evt.target) == null ? void 0 : _a2.releasePointerCapture) == null ? void 0 : _b2.call(_a2, evt.pointerId);
2043
+ (_a2 = evt.releasePointerCapture) == null ? void 0 : _a2.call(evt);
2045
2044
  setCurrentStrokes([]);
2046
2045
  if (timerRef.current) {
2047
2046
  clearTimeout(timerRef.current);
@@ -2138,7 +2137,6 @@ const CirclePaint = ({
2138
2137
  const toolStrokeStyle = activeTool.defaults.strokeStyle ?? PdfAnnotationBorderStyle.SOLID;
2139
2138
  const toolStrokeDashArray = activeTool.defaults.strokeDashArray ?? [];
2140
2139
  const { register } = usePointerHandlers({ modeId: "circle", pageIndex });
2141
- const clamp = (v, min, max) => Math.max(min, Math.min(max, v));
2142
2140
  const pageWidthPDF = pageWidth / scale;
2143
2141
  const pageHeightPDF = pageHeight / scale;
2144
2142
  const [start, setStart] = useState(null);
@@ -2146,12 +2144,12 @@ const CirclePaint = ({
2146
2144
  const handlers = useMemo(
2147
2145
  () => ({
2148
2146
  onPointerDown: (pos, evt) => {
2149
- var _a, _b;
2147
+ var _a;
2150
2148
  const x = clamp(pos.x, 0, pageWidthPDF);
2151
2149
  const y = clamp(pos.y, 0, pageHeightPDF);
2152
2150
  setStart({ x, y });
2153
2151
  setCurrent({ x, y });
2154
- (_b = (_a = evt.target) == null ? void 0 : _a.setPointerCapture) == null ? void 0 : _b.call(_a, evt.pointerId);
2152
+ (_a = evt.setPointerCapture) == null ? void 0 : _a.call(evt);
2155
2153
  },
2156
2154
  onPointerMove: (pos) => {
2157
2155
  if (!start) return;
@@ -2160,7 +2158,7 @@ const CirclePaint = ({
2160
2158
  setCurrent({ x, y });
2161
2159
  },
2162
2160
  onPointerUp: (_, evt) => {
2163
- var _a, _b;
2161
+ var _a;
2164
2162
  if (start && current && annotationProvides) {
2165
2163
  const minX2 = Math.min(start.x, current.x);
2166
2164
  const minY2 = Math.min(start.y, current.y);
@@ -2194,13 +2192,13 @@ const CirclePaint = ({
2194
2192
  annotationProvides.selectAnnotation(pageIndex, anno.id);
2195
2193
  }
2196
2194
  }
2197
- (_b = (_a = evt.target) == null ? void 0 : _a.releasePointerCapture) == null ? void 0 : _b.call(_a, evt.pointerId);
2195
+ (_a = evt.releasePointerCapture) == null ? void 0 : _a.call(evt);
2198
2196
  setStart(null);
2199
2197
  setCurrent(null);
2200
2198
  },
2201
2199
  onPointerCancel: (_, evt) => {
2202
- var _a, _b;
2203
- (_b = (_a = evt.target) == null ? void 0 : _a.releasePointerCapture) == null ? void 0 : _b.call(_a, evt.pointerId);
2200
+ var _a;
2201
+ (_a = evt.releasePointerCapture) == null ? void 0 : _a.call(evt);
2204
2202
  setStart(null);
2205
2203
  setCurrent(null);
2206
2204
  }
@@ -2293,7 +2291,6 @@ const SquarePaint = ({
2293
2291
  const toolStrokeStyle = activeTool.defaults.strokeStyle ?? PdfAnnotationBorderStyle.SOLID;
2294
2292
  const toolStrokeDashArray = activeTool.defaults.strokeDashArray ?? [];
2295
2293
  const { register } = usePointerHandlers({ modeId: "square", pageIndex });
2296
- const clamp = (v, min, max) => Math.max(min, Math.min(max, v));
2297
2294
  const pageWidthPDF = pageWidth / scale;
2298
2295
  const pageHeightPDF = pageHeight / scale;
2299
2296
  const [start, setStart] = useState(null);
@@ -2445,7 +2442,6 @@ const PolylinePaint = ({
2445
2442
  const toolStrokeStyle = activeTool.defaults.strokeStyle ?? PdfAnnotationBorderStyle.SOLID;
2446
2443
  const toolStrokeDashArray = activeTool.defaults.strokeDashArray;
2447
2444
  const { register } = usePointerHandlers({ modeId: "polyline", pageIndex });
2448
- const clamp = (v, min, max) => Math.max(min, Math.min(max, v));
2449
2445
  const pageWidthPDF = pageWidth / scale;
2450
2446
  const pageHeightPDF = pageHeight / scale;
2451
2447
  const [vertices, setVertices] = useState([]);
@@ -2553,7 +2549,6 @@ const LinePaint = ({ pageIndex, scale, pageWidth, pageHeight, cursor }) => {
2553
2549
  const toolLineEndings = activeTool.defaults.lineEndings;
2554
2550
  const intent = activeTool.defaults.intent;
2555
2551
  const { register } = usePointerHandlers({ modeId: ["line", "lineArrow"], pageIndex });
2556
- const clamp = (v, min, max) => Math.max(min, Math.min(max, v));
2557
2552
  const pageWidthPDF = pageWidth / scale;
2558
2553
  const pageHeightPDF = pageHeight / scale;
2559
2554
  const [start, setStart] = useState(null);
@@ -2584,12 +2579,12 @@ const LinePaint = ({ pageIndex, scale, pageWidth, pageHeight, cursor }) => {
2584
2579
  const handlers = useMemo(
2585
2580
  () => ({
2586
2581
  onPointerDown: (pos, evt) => {
2587
- var _a, _b;
2582
+ var _a;
2588
2583
  const x = clamp(pos.x, 0, pageWidthPDF);
2589
2584
  const y = clamp(pos.y, 0, pageHeightPDF);
2590
2585
  setStart({ x, y });
2591
2586
  setCurrent({ x, y });
2592
- (_b = (_a = evt.target) == null ? void 0 : _a.setPointerCapture) == null ? void 0 : _b.call(_a, evt.pointerId);
2587
+ (_a = evt.setPointerCapture) == null ? void 0 : _a.call(evt);
2593
2588
  },
2594
2589
  onPointerMove: (pos) => {
2595
2590
  if (!start) return;
@@ -2598,17 +2593,17 @@ const LinePaint = ({ pageIndex, scale, pageWidth, pageHeight, cursor }) => {
2598
2593
  setCurrent({ x, y });
2599
2594
  },
2600
2595
  onPointerUp: (_, evt) => {
2601
- var _a, _b;
2596
+ var _a;
2602
2597
  if (start && current && annotationProvides) {
2603
2598
  commitLine(start, current);
2604
2599
  }
2605
- (_b = (_a = evt.target) == null ? void 0 : _a.releasePointerCapture) == null ? void 0 : _b.call(_a, evt.pointerId);
2600
+ (_a = evt.releasePointerCapture) == null ? void 0 : _a.call(evt);
2606
2601
  setStart(null);
2607
2602
  setCurrent(null);
2608
2603
  },
2609
2604
  onPointerCancel: (_, evt) => {
2610
- var _a, _b;
2611
- (_b = (_a = evt.target) == null ? void 0 : _a.releasePointerCapture) == null ? void 0 : _b.call(_a, evt.pointerId);
2605
+ var _a;
2606
+ (_a = evt.releasePointerCapture) == null ? void 0 : _a.call(evt);
2612
2607
  setStart(null);
2613
2608
  setCurrent(null);
2614
2609
  }
@@ -2671,7 +2666,6 @@ const PolygonPaint = ({
2671
2666
  const toolStrokeStyle = activeTool.defaults.strokeStyle ?? PdfAnnotationBorderStyle.SOLID;
2672
2667
  const toolStrokeDashArray = activeTool.defaults.strokeDashArray;
2673
2668
  const { register } = usePointerHandlers({ modeId: "polygon", pageIndex });
2674
- const clamp = (v, min, max) => Math.max(min, Math.min(max, v));
2675
2669
  const pageWidthPDF = pageWidth / scale;
2676
2670
  const pageHeightPDF = pageHeight / scale;
2677
2671
  const [vertices, setVertices] = useState([]);
@@ -2860,7 +2854,7 @@ const FreeTextPaint = ({
2860
2854
  const toolVerticalAlign = activeTool.defaults.verticalAlign;
2861
2855
  const toolContent = activeTool.defaults.content ?? "Insert text here";
2862
2856
  const { register } = usePointerHandlers({ modeId: "freeText", pageIndex });
2863
- const clamp = (v, min, max) => Math.max(min, Math.min(max, v));
2857
+ const clamp2 = (v, min, max) => Math.max(min, Math.min(max, v));
2864
2858
  const pageWidthPDF = pageWidth / scale;
2865
2859
  const pageHeightPDF = pageHeight / scale;
2866
2860
  const [start, setStart] = useState(null);
@@ -2899,31 +2893,31 @@ const FreeTextPaint = ({
2899
2893
  const handlers = useMemo(
2900
2894
  () => ({
2901
2895
  onPointerDown: (pos, evt) => {
2902
- var _a, _b;
2903
- const x = clamp(pos.x, 0, pageWidthPDF);
2904
- const y = clamp(pos.y, 0, pageHeightPDF);
2896
+ var _a;
2897
+ const x = clamp2(pos.x, 0, pageWidthPDF);
2898
+ const y = clamp2(pos.y, 0, pageHeightPDF);
2905
2899
  setStart({ x, y });
2906
2900
  setCurrent({ x, y });
2907
- (_b = (_a = evt.target) == null ? void 0 : _a.setPointerCapture) == null ? void 0 : _b.call(_a, evt.pointerId);
2901
+ (_a = evt.setPointerCapture) == null ? void 0 : _a.call(evt);
2908
2902
  },
2909
2903
  onPointerMove: (pos) => {
2910
2904
  if (!start) return;
2911
- const x = clamp(pos.x, 0, pageWidthPDF);
2912
- const y = clamp(pos.y, 0, pageHeightPDF);
2905
+ const x = clamp2(pos.x, 0, pageWidthPDF);
2906
+ const y = clamp2(pos.y, 0, pageHeightPDF);
2913
2907
  setCurrent({ x, y });
2914
2908
  },
2915
2909
  onPointerUp: (_, evt) => {
2916
- var _a, _b;
2910
+ var _a;
2917
2911
  if (start && current && annotationProvides) {
2918
2912
  commitFreeText(start, current);
2919
2913
  }
2920
- (_b = (_a = evt.target) == null ? void 0 : _a.releasePointerCapture) == null ? void 0 : _b.call(_a, evt.pointerId);
2914
+ (_a = evt.releasePointerCapture) == null ? void 0 : _a.call(evt);
2921
2915
  setStart(null);
2922
2916
  setCurrent(null);
2923
2917
  },
2924
2918
  onPointerCancel: (_, evt) => {
2925
- var _a, _b;
2926
- (_b = (_a = evt.target) == null ? void 0 : _a.releasePointerCapture) == null ? void 0 : _b.call(_a, evt.pointerId);
2919
+ var _a;
2920
+ (_a = evt.releasePointerCapture) == null ? void 0 : _a.call(evt);
2927
2921
  setStart(null);
2928
2922
  setCurrent(null);
2929
2923
  }
@@ -2986,7 +2980,6 @@ const StampPaint = ({ pageIndex, scale, pageWidth, pageHeight }) => {
2986
2980
  const { register } = usePointerHandlers({ modeId: "stamp", pageIndex });
2987
2981
  const pageWidthPDF = pageWidth / scale;
2988
2982
  const pageHeightPDF = pageHeight / scale;
2989
- const clamp = (v, min, max) => Math.max(min, Math.min(max, v));
2990
2983
  const [start, setStart] = useState(null);
2991
2984
  const handlers = useMemo(
2992
2985
  () => ({