@embedpdf/plugin-annotation 2.11.1 → 2.12.1

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