@deepnoid/canvas 0.1.69 → 0.1.71
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,6 +14,7 @@ const AnnotationCanvas = ({ image, annotations = [], setAnnotations, options, dr
|
|
|
14
14
|
const pendingAnnotationsRef = useRef(null);
|
|
15
15
|
const imageLoadingRef = useRef(false);
|
|
16
16
|
const currentImageRef = useRef(image);
|
|
17
|
+
const engineIdRef = useRef(0);
|
|
17
18
|
const [, forceRender] = useState(0);
|
|
18
19
|
/* ---------- Resize ---------- */
|
|
19
20
|
useResizeObserver({
|
|
@@ -36,7 +37,6 @@ const AnnotationCanvas = ({ image, annotations = [], setAnnotations, options, dr
|
|
|
36
37
|
enabled: enableHotkeys,
|
|
37
38
|
});
|
|
38
39
|
/* ---------- Image / Engine lifecycle ---------- */
|
|
39
|
-
const engineIdRef = useRef(0);
|
|
40
40
|
useEffect(() => {
|
|
41
41
|
const isImageChanged = currentImageRef.current !== image;
|
|
42
42
|
const prevImageCanvasState = engineRef.current?.getImageCanvasState();
|
|
@@ -46,6 +46,7 @@ const AnnotationCanvas = ({ image, annotations = [], setAnnotations, options, dr
|
|
|
46
46
|
pendingAnnotationsRef.current = null;
|
|
47
47
|
currentImageRef.current = image;
|
|
48
48
|
engineIdRef.current++;
|
|
49
|
+
setAnnotations?.([]);
|
|
49
50
|
}
|
|
50
51
|
imageLoadingRef.current = true;
|
|
51
52
|
if (!image?.trim()) {
|
|
@@ -57,9 +58,8 @@ const AnnotationCanvas = ({ image, annotations = [], setAnnotations, options, dr
|
|
|
57
58
|
let cancelled = false;
|
|
58
59
|
const img = new Image();
|
|
59
60
|
img.onload = () => {
|
|
60
|
-
if (cancelled || !imageCanvasRef.current || !annotationsCanvasRef.current)
|
|
61
|
+
if (cancelled || !imageCanvasRef.current || !annotationsCanvasRef.current)
|
|
61
62
|
return;
|
|
62
|
-
}
|
|
63
63
|
const imageCanvasState = !resetOnImageChange && prevImageCanvasState
|
|
64
64
|
? prevImageCanvasState
|
|
65
65
|
: {
|
|
@@ -75,8 +75,8 @@ const AnnotationCanvas = ({ image, annotations = [], setAnnotations, options, dr
|
|
|
75
75
|
initZoom: 1,
|
|
76
76
|
};
|
|
77
77
|
const initialAnnotations = pendingAnnotationsRef.current ?? [];
|
|
78
|
-
pendingAnnotationsRef.current = null;
|
|
79
78
|
const currentEngineId = engineIdRef.current;
|
|
79
|
+
pendingAnnotationsRef.current = null;
|
|
80
80
|
engineRef.current = new AnnotationEngine({
|
|
81
81
|
imageCanvas: imageCanvasRef.current,
|
|
82
82
|
image: img,
|