@deepnoid/canvas 0.1.31 → 0.1.33
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.
|
@@ -14,29 +14,40 @@ const AnnotatedCanvas = ({ image, coordinates, panZoomable = false, ZoomButton,
|
|
|
14
14
|
useEffect(() => {
|
|
15
15
|
if (!image || image.trim() === '') {
|
|
16
16
|
clearCanvas();
|
|
17
|
+
setDisplayCoordinates([]);
|
|
17
18
|
return;
|
|
18
19
|
}
|
|
19
|
-
|
|
20
|
-
|
|
20
|
+
const tempImage = new Image();
|
|
21
|
+
let cancelled = false;
|
|
22
|
+
tempImage.src = image;
|
|
23
|
+
tempImage.onload = () => {
|
|
24
|
+
if (cancelled)
|
|
25
|
+
return;
|
|
21
26
|
onImageLoadSuccess?.();
|
|
22
27
|
const canvas = resolutionCanvas(canvasRef.current);
|
|
23
28
|
if (!canvas)
|
|
24
29
|
return;
|
|
25
30
|
if (resetOnImageChange) {
|
|
26
|
-
init(canvas,
|
|
31
|
+
init(canvas, tempImage);
|
|
27
32
|
}
|
|
28
33
|
else {
|
|
29
|
-
preserveZoomAndPosition(canvas,
|
|
34
|
+
preserveZoomAndPosition(canvas, tempImage, canvasState.zoom / (canvasState.initZoom || 1));
|
|
30
35
|
}
|
|
36
|
+
imageRef.current = tempImage;
|
|
31
37
|
setImageOnloadCount((prev) => prev + 1);
|
|
32
38
|
setDisplayCoordinates(coordinates);
|
|
33
39
|
};
|
|
34
|
-
|
|
40
|
+
tempImage.onerror = () => {
|
|
41
|
+
if (cancelled)
|
|
42
|
+
return;
|
|
35
43
|
const err = new Error(`Failed to load image: ${image}`);
|
|
36
44
|
onImageLoadError?.(err);
|
|
37
45
|
clearCanvas();
|
|
38
46
|
setDisplayCoordinates([]);
|
|
39
47
|
};
|
|
48
|
+
return () => {
|
|
49
|
+
cancelled = true;
|
|
50
|
+
};
|
|
40
51
|
}, [image, resetOnImageChange]);
|
|
41
52
|
useEffect(() => {
|
|
42
53
|
if (image && width && height) {
|
|
@@ -65,16 +76,6 @@ const AnnotatedCanvas = ({ image, coordinates, panZoomable = false, ZoomButton,
|
|
|
65
76
|
height: '100%',
|
|
66
77
|
left: 0,
|
|
67
78
|
top: 0,
|
|
68
|
-
} }), _jsx(Canvas, { ...canvasState,
|
|
69
|
-
// moveX={canvasState.moveX}
|
|
70
|
-
// moveY={canvasState.moveY}
|
|
71
|
-
// zoomX={canvasState.zoomX}
|
|
72
|
-
// zoomY={canvasState.zoomY}
|
|
73
|
-
// zoom={canvasState.zoom}
|
|
74
|
-
// dx={canvasState.dx}
|
|
75
|
-
// dy={canvasState.dy}
|
|
76
|
-
// dw={canvasState.dw}
|
|
77
|
-
// dh={canvasState.dh}
|
|
78
|
-
coordinates: displayCoordinates, editable: editable }), ZoomButton && canvasState.initZoom > 0 && (_jsx(ZoomButton, { onClick: initCanvas, children: `${Math.round((canvasState.zoom / canvasState.initZoom) * 100)}%` }))] }) }));
|
|
79
|
+
} }), _jsx(Canvas, { ...canvasState, coordinates: displayCoordinates, editable: editable }), ZoomButton && canvasState.initZoom > 0 && (_jsx(ZoomButton, { onClick: initCanvas, children: `${Math.round((canvasState.zoom / canvasState.initZoom) * 100)}%` }))] }) }));
|
|
79
80
|
};
|
|
80
81
|
export default AnnotatedCanvas;
|