@deepnoid/canvas 0.1.61 → 0.1.62
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.
|
@@ -35,8 +35,13 @@ const AnnotationCanvas = ({ image, annotations = [], setAnnotations, options, dr
|
|
|
35
35
|
});
|
|
36
36
|
/* ---------- Image / Engine lifecycle ---------- */
|
|
37
37
|
useEffect(() => {
|
|
38
|
+
const prevEngine = engineRef.current;
|
|
39
|
+
const prevImageCanvasState = prevEngine?.getImageCanvasState();
|
|
40
|
+
if (prevEngine) {
|
|
41
|
+
prevEngine.destroy();
|
|
42
|
+
engineRef.current = null;
|
|
43
|
+
}
|
|
38
44
|
if (!image?.trim()) {
|
|
39
|
-
engineRef.current?.resetCanvas();
|
|
40
45
|
return;
|
|
41
46
|
}
|
|
42
47
|
let cancelled = false;
|
|
@@ -45,9 +50,8 @@ const AnnotationCanvas = ({ image, annotations = [], setAnnotations, options, dr
|
|
|
45
50
|
if (cancelled || !imageCanvasRef.current || !annotationsCanvasRef.current) {
|
|
46
51
|
return;
|
|
47
52
|
}
|
|
48
|
-
const
|
|
49
|
-
|
|
50
|
-
? prevEngine.getImageCanvasState()
|
|
53
|
+
const imageCanvasState = !resetOnImageChange && prevImageCanvasState
|
|
54
|
+
? prevImageCanvasState
|
|
51
55
|
: {
|
|
52
56
|
moveX: 0,
|
|
53
57
|
moveY: 0,
|
|
@@ -60,9 +64,8 @@ const AnnotationCanvas = ({ image, annotations = [], setAnnotations, options, dr
|
|
|
60
64
|
dh: img.height,
|
|
61
65
|
initZoom: 1,
|
|
62
66
|
};
|
|
63
|
-
const initialAnnotations = pendingAnnotationsRef.current ?? [];
|
|
67
|
+
const initialAnnotations = pendingAnnotationsRef.current ?? annotations ?? [];
|
|
64
68
|
pendingAnnotationsRef.current = null;
|
|
65
|
-
prevEngine?.destroy();
|
|
66
69
|
engineRef.current = new AnnotationEngine({
|
|
67
70
|
imageCanvas: imageCanvasRef.current,
|
|
68
71
|
image: img,
|
|
@@ -84,7 +87,6 @@ const AnnotationCanvas = ({ image, annotations = [], setAnnotations, options, dr
|
|
|
84
87
|
if (cancelled)
|
|
85
88
|
return;
|
|
86
89
|
pendingAnnotationsRef.current = null;
|
|
87
|
-
engineRef.current?.resetCanvas();
|
|
88
90
|
onImageLoadError?.(new Error(`Failed to load image: ${image}`));
|
|
89
91
|
};
|
|
90
92
|
img.src = image;
|