ywana-core8 0.2.15 → 0.2.17
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.js +40 -16
- package/dist/index.js.map +1 -1
- package/dist/index.modern.js +40 -16
- package/dist/index.modern.js.map +1 -1
- package/dist/index.umd.js +40 -16
- package/dist/index.umd.js.map +1 -1
- package/package.json +1 -1
- package/src/widgets/image/ImageViewer.js +52 -17
package/dist/index.js
CHANGED
@@ -22682,24 +22682,34 @@ const ImageViewer = React.forwardRef(({ image }, ref2) => {
|
|
22682
22682
|
};
|
22683
22683
|
const handleMouseUp = () => setDragging(false);
|
22684
22684
|
const draw = () => {
|
22685
|
-
if (canvasRef.current) {
|
22686
|
-
|
22687
|
-
|
22688
|
-
|
22689
|
-
canvasRef.current
|
22685
|
+
if (!canvasRef.current || !background.complete || !background.naturalWidth) {
|
22686
|
+
return;
|
22687
|
+
}
|
22688
|
+
try {
|
22689
|
+
const canvas = canvasRef.current;
|
22690
|
+
const { width, height } = canvas;
|
22691
|
+
const context = canvas.getContext("2d");
|
22692
|
+
canvas.width = width;
|
22693
|
+
canvas.height = height;
|
22694
|
+
context.save();
|
22690
22695
|
context.translate(-offset2.x, -offset2.y);
|
22691
22696
|
context.scale(zoom, zoom);
|
22692
22697
|
context.clearRect(0, 0, width, height);
|
22693
|
-
const x = (
|
22694
|
-
const y = (
|
22698
|
+
const x = (canvas.width / zoom - background.width) / 2;
|
22699
|
+
const y = (canvas.height / zoom - background.height) / 2;
|
22695
22700
|
context.drawImage(background, x, y);
|
22701
|
+
context.restore();
|
22702
|
+
} catch (error) {
|
22703
|
+
console.warn("Error drawing image:", error);
|
22696
22704
|
}
|
22697
22705
|
};
|
22698
22706
|
React.useEffect(() => {
|
22707
|
+
const container = containerRef.current;
|
22708
|
+
if (!container) return;
|
22699
22709
|
observer.current = new ResizeObserver((entries) => {
|
22700
22710
|
entries.forEach(({ target }) => {
|
22701
22711
|
const { width, height } = background;
|
22702
|
-
if (target.clientWidth < width) {
|
22712
|
+
if (target.clientWidth < width && canvasRef.current) {
|
22703
22713
|
const scale = target.clientWidth / width;
|
22704
22714
|
canvasRef.current.width = width * scale;
|
22705
22715
|
canvasRef.current.height = height * scale;
|
@@ -22707,23 +22717,37 @@ const ImageViewer = React.forwardRef(({ image }, ref2) => {
|
|
22707
22717
|
}
|
22708
22718
|
});
|
22709
22719
|
});
|
22710
|
-
observer.current.observe(
|
22711
|
-
return () =>
|
22720
|
+
observer.current.observe(container);
|
22721
|
+
return () => {
|
22722
|
+
if (observer.current && container) {
|
22723
|
+
observer.current.unobserve(container);
|
22724
|
+
}
|
22725
|
+
};
|
22712
22726
|
}, []);
|
22713
22727
|
React.useEffect(() => {
|
22728
|
+
if (!image) return;
|
22714
22729
|
background.src = image;
|
22715
|
-
|
22716
|
-
|
22730
|
+
const handleImageLoad = () => {
|
22731
|
+
if (canvasRef.current) {
|
22717
22732
|
const { width, height } = background;
|
22718
22733
|
canvasRef.current.width = width;
|
22719
22734
|
canvasRef.current.height = height;
|
22720
22735
|
canvasRef.current.getContext("2d").drawImage(background, 0, 0);
|
22721
|
-
}
|
22722
|
-
}
|
22723
|
-
|
22736
|
+
}
|
22737
|
+
};
|
22738
|
+
const handleImageError = () => {
|
22739
|
+
console.warn("Failed to load image:", image);
|
22740
|
+
};
|
22741
|
+
background.onload = handleImageLoad;
|
22742
|
+
background.onerror = handleImageError;
|
22743
|
+
return () => {
|
22744
|
+
background.onload = null;
|
22745
|
+
background.onerror = null;
|
22746
|
+
};
|
22747
|
+
}, [image, background]);
|
22724
22748
|
React.useEffect(() => {
|
22725
22749
|
draw();
|
22726
|
-
}, [zoom, offset2]);
|
22750
|
+
}, [zoom, offset2, background.src]);
|
22727
22751
|
return /* @__PURE__ */ React.createElement("div", { className: "image-viewer", ref: containerRef }, /* @__PURE__ */ React.createElement(
|
22728
22752
|
"canvas",
|
22729
22753
|
{
|