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