@deepnoid/canvas 0.1.11 → 0.1.12
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.
|
@@ -98,6 +98,18 @@ const XrayViewer = ({ image, hasZoom, coordinates, onImageLoadError, onImageLoad
|
|
|
98
98
|
onImageLoadError?.(new Error(errorMessage));
|
|
99
99
|
}
|
|
100
100
|
}, [calculateInitZoom, calculatorZoomPoint, onImageLoadError]);
|
|
101
|
+
const initWithPreservedState = useCallback((image) => {
|
|
102
|
+
try {
|
|
103
|
+
setDw(image.width);
|
|
104
|
+
setDh(image.height);
|
|
105
|
+
setImageError(null);
|
|
106
|
+
}
|
|
107
|
+
catch (error) {
|
|
108
|
+
const errorMessage = error instanceof Error ? error.message : 'Canvas initialization failed';
|
|
109
|
+
setImageError(errorMessage);
|
|
110
|
+
onImageLoadError?.(new Error(errorMessage));
|
|
111
|
+
}
|
|
112
|
+
}, [onImageLoadError]);
|
|
101
113
|
const initCanvas = useCallback(async () => {
|
|
102
114
|
if (!image)
|
|
103
115
|
return;
|
|
@@ -130,17 +142,24 @@ const XrayViewer = ({ image, hasZoom, coordinates, onImageLoadError, onImageLoad
|
|
|
130
142
|
if (!image)
|
|
131
143
|
return;
|
|
132
144
|
const imageInfo = `${image.itemId}-${image.type}`;
|
|
145
|
+
const preserveViewState = hasZoom?.preserveViewState || false;
|
|
133
146
|
const loadImageAsync = async () => {
|
|
134
147
|
try {
|
|
135
148
|
setIsImageLoading(true);
|
|
136
149
|
setImageError(null);
|
|
137
150
|
const loadedImage = await loadImage(image.imagePath);
|
|
138
151
|
imageRef.current = loadedImage;
|
|
139
|
-
|
|
152
|
+
const isNewImage = prevImageInfo.current !== imageInfo || image.type === 'REALITY';
|
|
153
|
+
if (isNewImage) {
|
|
140
154
|
prevImageInfo.current = imageInfo;
|
|
141
155
|
const canvas_el = resolutionCanvas(viewer.current);
|
|
142
156
|
if (canvas_el) {
|
|
143
|
-
|
|
157
|
+
if (preserveViewState && initZoom !== 0) {
|
|
158
|
+
initWithPreservedState(loadedImage);
|
|
159
|
+
}
|
|
160
|
+
else {
|
|
161
|
+
init(canvas_el, loadedImage);
|
|
162
|
+
}
|
|
144
163
|
}
|
|
145
164
|
}
|
|
146
165
|
setImageOnloadCount((prev) => prev + 1);
|
|
@@ -182,7 +201,16 @@ const XrayViewer = ({ image, hasZoom, coordinates, onImageLoadError, onImageLoad
|
|
|
182
201
|
clearTimeout(loadTimeoutRef.current);
|
|
183
202
|
}
|
|
184
203
|
};
|
|
185
|
-
}, [
|
|
204
|
+
}, [
|
|
205
|
+
image,
|
|
206
|
+
loadImage,
|
|
207
|
+
init,
|
|
208
|
+
initWithPreservedState,
|
|
209
|
+
onImageLoadError,
|
|
210
|
+
onImageLoadSuccess,
|
|
211
|
+
hasZoom?.preserveViewState,
|
|
212
|
+
initZoom,
|
|
213
|
+
]);
|
|
186
214
|
useEffect(() => {
|
|
187
215
|
const _redraw = () => {
|
|
188
216
|
if (viewer.current && imageRef.current && !isImageLoading && !imageError) {
|
|
@@ -199,15 +227,21 @@ const XrayViewer = ({ image, hasZoom, coordinates, onImageLoadError, onImageLoad
|
|
|
199
227
|
useEffect(() => {
|
|
200
228
|
if (image && imageRef.current && !isImageLoading) {
|
|
201
229
|
const imageInfo = `${image.itemId}-${image.type}`;
|
|
230
|
+
const preserveViewState = hasZoom?.preserveViewState || false;
|
|
202
231
|
if (prevImageInfo.current === imageInfo) {
|
|
203
232
|
const canvas_el = resolutionCanvas(viewer.current);
|
|
204
233
|
if (canvas_el) {
|
|
205
|
-
|
|
206
|
-
|
|
234
|
+
if (preserveViewState && initZoom !== 0) {
|
|
235
|
+
setImageOnloadCount((prev) => prev + 1);
|
|
236
|
+
}
|
|
237
|
+
else {
|
|
238
|
+
init(canvas_el, imageRef.current);
|
|
239
|
+
setImageOnloadCount((prev) => prev + 1);
|
|
240
|
+
}
|
|
207
241
|
}
|
|
208
242
|
}
|
|
209
243
|
}
|
|
210
|
-
}, [width, height, image, init, isImageLoading]);
|
|
244
|
+
}, [width, height, image, init, isImageLoading, hasZoom?.preserveViewState, initZoom]);
|
|
211
245
|
const handleWheel = (event) => {
|
|
212
246
|
if (!hasZoom || isImageLoading || imageError)
|
|
213
247
|
return;
|