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