@embedpdf/plugin-annotation 2.11.0 → 2.12.0

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.
@@ -2944,6 +2944,7 @@ const builtInRenderers = [
2944
2944
  createRenderer({
2945
2945
  id: "stamp",
2946
2946
  matches: (a) => a.type === PdfAnnotationSubtype.STAMP,
2947
+ matchesPreview: (p) => p.type === PdfAnnotationSubtype.STAMP,
2947
2948
  render: ({ annotation, isSelected, documentId, pageIndex, scale, onClick }) => /* @__PURE__ */ jsx(
2948
2949
  Stamp,
2949
2950
  {
@@ -2955,6 +2956,24 @@ const builtInRenderers = [
2955
2956
  onClick
2956
2957
  }
2957
2958
  ),
2959
+ renderPreview: ({ data }) => {
2960
+ const rotationDeg = (4 - data.pageRotation) % 4 * 90;
2961
+ return /* @__PURE__ */ jsx(
2962
+ "img",
2963
+ {
2964
+ src: data.ghostUrl,
2965
+ style: {
2966
+ width: "100%",
2967
+ height: "100%",
2968
+ opacity: 0.6,
2969
+ objectFit: "contain",
2970
+ pointerEvents: "none",
2971
+ transform: rotationDeg ? `rotate(${rotationDeg}deg)` : void 0
2972
+ },
2973
+ alt: ""
2974
+ }
2975
+ );
2976
+ },
2958
2977
  useAppearanceStream: false,
2959
2978
  interactionDefaults: { isDraggable: true, isResizable: true, isRotatable: true }
2960
2979
  }),
@@ -3468,7 +3487,6 @@ function AnnotationPaintLayer({ documentId, pageIndex, scale }) {
3468
3487
  const { plugin: annotationPlugin } = useAnnotationPlugin();
3469
3488
  const [previews, setPreviews] = useState(/* @__PURE__ */ new Map());
3470
3489
  const fileInputRef = useRef(null);
3471
- const canvasRef = useRef(null);
3472
3490
  const services = useMemo(
3473
3491
  () => ({
3474
3492
  requestFile: ({ accept, onFile }) => {
@@ -3484,29 +3502,6 @@ function AnnotationPaintLayer({ documentId, pageIndex, scale }) {
3484
3502
  }
3485
3503
  };
3486
3504
  input.click();
3487
- },
3488
- processImage: ({ source, maxWidth, maxHeight, onComplete }) => {
3489
- const canvas = canvasRef.current;
3490
- if (!canvas || !canvas.getContext) return;
3491
- const ctx = canvas.getContext("2d");
3492
- if (!ctx) return;
3493
- const img = new Image();
3494
- img.crossOrigin = "Anonymous";
3495
- img.onload = () => {
3496
- let { naturalWidth: width, naturalHeight: height } = img;
3497
- const scaleX = maxWidth ? maxWidth / width : 1;
3498
- const scaleY = maxHeight ? maxHeight / height : 1;
3499
- const scaleFactor = Math.min(scaleX, scaleY, 1);
3500
- const finalWidth = width * scaleFactor;
3501
- const finalHeight = height * scaleFactor;
3502
- canvas.width = finalWidth;
3503
- canvas.height = finalHeight;
3504
- ctx.drawImage(img, 0, 0, finalWidth, finalHeight);
3505
- const imageData = ctx.getImageData(0, 0, finalWidth, finalHeight);
3506
- if (typeof source !== "string") URL.revokeObjectURL(img.src);
3507
- onComplete({ imageData, width: finalWidth, height: finalHeight });
3508
- };
3509
- img.src = typeof source === "string" ? source : URL.createObjectURL(source);
3510
3505
  }
3511
3506
  }),
3512
3507
  []
@@ -3530,7 +3525,6 @@ function AnnotationPaintLayer({ documentId, pageIndex, scale }) {
3530
3525
  }, [documentId, pageIndex, scale, annotationPlugin, services]);
3531
3526
  return /* @__PURE__ */ jsxs(Fragment, { children: [
3532
3527
  /* @__PURE__ */ jsx("input", { ref: fileInputRef, type: "file", style: { display: "none" } }),
3533
- /* @__PURE__ */ jsx("canvas", { ref: canvasRef, style: { display: "none" } }),
3534
3528
  Array.from(previews.entries()).map(([toolId, preview]) => /* @__PURE__ */ jsx(PreviewRenderer, { toolId, preview, scale }, toolId))
3535
3529
  ] });
3536
3530
  }