@deepnoid/canvas 0.1.68 → 0.1.70
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.
|
@@ -36,17 +36,17 @@ const AnnotationCanvas = ({ image, annotations = [], setAnnotations, options, dr
|
|
|
36
36
|
enabled: enableHotkeys,
|
|
37
37
|
});
|
|
38
38
|
/* ---------- Image / Engine lifecycle ---------- */
|
|
39
|
+
const engineIdRef = useRef(0);
|
|
39
40
|
useEffect(() => {
|
|
40
|
-
// 이미지가 실제로 변경되었는지 확인
|
|
41
41
|
const isImageChanged = currentImageRef.current !== image;
|
|
42
|
-
// 이미지 변경 전에 현재 상태 저장
|
|
43
42
|
const prevImageCanvasState = engineRef.current?.getImageCanvasState();
|
|
44
43
|
if (isImageChanged) {
|
|
45
|
-
// 이미지 변경 시: 즉시 엔진 제거 + pending 초기화
|
|
46
44
|
engineRef.current?.destroy();
|
|
47
45
|
engineRef.current = null;
|
|
48
46
|
pendingAnnotationsRef.current = null;
|
|
49
47
|
currentImageRef.current = image;
|
|
48
|
+
engineIdRef.current++;
|
|
49
|
+
setAnnotations?.([]);
|
|
50
50
|
}
|
|
51
51
|
imageLoadingRef.current = true;
|
|
52
52
|
if (!image?.trim()) {
|
|
@@ -61,7 +61,6 @@ const AnnotationCanvas = ({ image, annotations = [], setAnnotations, options, dr
|
|
|
61
61
|
if (cancelled || !imageCanvasRef.current || !annotationsCanvasRef.current) {
|
|
62
62
|
return;
|
|
63
63
|
}
|
|
64
|
-
// resetOnImageChange 옵션에 따라 상태 결정
|
|
65
64
|
const imageCanvasState = !resetOnImageChange && prevImageCanvasState
|
|
66
65
|
? prevImageCanvasState
|
|
67
66
|
: {
|
|
@@ -76,11 +75,9 @@ const AnnotationCanvas = ({ image, annotations = [], setAnnotations, options, dr
|
|
|
76
75
|
dh: img.height,
|
|
77
76
|
initZoom: 1,
|
|
78
77
|
};
|
|
79
|
-
// pendingAnnotationsRef가 있으면 사용, 없으면 빈 배열
|
|
80
78
|
const initialAnnotations = pendingAnnotationsRef.current ?? [];
|
|
81
79
|
pendingAnnotationsRef.current = null;
|
|
82
|
-
|
|
83
|
-
const currentImage = image;
|
|
80
|
+
const currentEngineId = engineIdRef.current;
|
|
84
81
|
engineRef.current = new AnnotationEngine({
|
|
85
82
|
imageCanvas: imageCanvasRef.current,
|
|
86
83
|
image: img,
|
|
@@ -88,8 +85,7 @@ const AnnotationCanvas = ({ image, annotations = [], setAnnotations, options, dr
|
|
|
88
85
|
annotationsCanvas: annotationsCanvasRef.current,
|
|
89
86
|
annotations: initialAnnotations,
|
|
90
87
|
setAnnotations: (next) => {
|
|
91
|
-
|
|
92
|
-
if (currentImageRef.current === currentImage) {
|
|
88
|
+
if (engineIdRef.current === currentEngineId) {
|
|
93
89
|
setAnnotations?.(next);
|
|
94
90
|
}
|
|
95
91
|
},
|
|
@@ -124,12 +120,10 @@ const AnnotationCanvas = ({ image, annotations = [], setAnnotations, options, dr
|
|
|
124
120
|
useEffect(() => {
|
|
125
121
|
if (!annotations)
|
|
126
122
|
return;
|
|
127
|
-
// 이미지 로딩 중이거나 엔진이 없으면 pending에 저장
|
|
128
123
|
if (imageLoadingRef.current || !engineRef.current) {
|
|
129
124
|
pendingAnnotationsRef.current = annotations;
|
|
130
125
|
return;
|
|
131
126
|
}
|
|
132
|
-
// 엔진이 있으면 업데이트
|
|
133
127
|
const before = engineRef.current.getAnnotations();
|
|
134
128
|
if (JSON.stringify(before) !== JSON.stringify(annotations)) {
|
|
135
129
|
engineRef.current.setAnnotations(annotations);
|