@deepnoid/canvas 0.1.68 → 0.1.69
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,16 @@ 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++;
|
|
50
49
|
}
|
|
51
50
|
imageLoadingRef.current = true;
|
|
52
51
|
if (!image?.trim()) {
|
|
@@ -61,7 +60,6 @@ const AnnotationCanvas = ({ image, annotations = [], setAnnotations, options, dr
|
|
|
61
60
|
if (cancelled || !imageCanvasRef.current || !annotationsCanvasRef.current) {
|
|
62
61
|
return;
|
|
63
62
|
}
|
|
64
|
-
// resetOnImageChange 옵션에 따라 상태 결정
|
|
65
63
|
const imageCanvasState = !resetOnImageChange && prevImageCanvasState
|
|
66
64
|
? prevImageCanvasState
|
|
67
65
|
: {
|
|
@@ -76,11 +74,9 @@ const AnnotationCanvas = ({ image, annotations = [], setAnnotations, options, dr
|
|
|
76
74
|
dh: img.height,
|
|
77
75
|
initZoom: 1,
|
|
78
76
|
};
|
|
79
|
-
// pendingAnnotationsRef가 있으면 사용, 없으면 빈 배열
|
|
80
77
|
const initialAnnotations = pendingAnnotationsRef.current ?? [];
|
|
81
78
|
pendingAnnotationsRef.current = null;
|
|
82
|
-
|
|
83
|
-
const currentImage = image;
|
|
79
|
+
const currentEngineId = engineIdRef.current;
|
|
84
80
|
engineRef.current = new AnnotationEngine({
|
|
85
81
|
imageCanvas: imageCanvasRef.current,
|
|
86
82
|
image: img,
|
|
@@ -88,8 +84,7 @@ const AnnotationCanvas = ({ image, annotations = [], setAnnotations, options, dr
|
|
|
88
84
|
annotationsCanvas: annotationsCanvasRef.current,
|
|
89
85
|
annotations: initialAnnotations,
|
|
90
86
|
setAnnotations: (next) => {
|
|
91
|
-
|
|
92
|
-
if (currentImageRef.current === currentImage) {
|
|
87
|
+
if (engineIdRef.current === currentEngineId) {
|
|
93
88
|
setAnnotations?.(next);
|
|
94
89
|
}
|
|
95
90
|
},
|
|
@@ -124,12 +119,10 @@ const AnnotationCanvas = ({ image, annotations = [], setAnnotations, options, dr
|
|
|
124
119
|
useEffect(() => {
|
|
125
120
|
if (!annotations)
|
|
126
121
|
return;
|
|
127
|
-
// 이미지 로딩 중이거나 엔진이 없으면 pending에 저장
|
|
128
122
|
if (imageLoadingRef.current || !engineRef.current) {
|
|
129
123
|
pendingAnnotationsRef.current = annotations;
|
|
130
124
|
return;
|
|
131
125
|
}
|
|
132
|
-
// 엔진이 있으면 업데이트
|
|
133
126
|
const before = engineRef.current.getAnnotations();
|
|
134
127
|
if (JSON.stringify(before) !== JSON.stringify(annotations)) {
|
|
135
128
|
engineRef.current.setAnnotations(annotations);
|