@deepnoid/canvas 0.1.41 → 0.1.42
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.
- package/dist/components/AnnotationCanvas/index.js +14 -6
- package/dist/components/AnnotationLayer/_hooks/drawEvents/useDrawEvents.js +2 -1
- package/dist/components/AnnotationLayer/index.js +1 -4
- package/package.json +1 -1
- package/dist/utils/common/cloneDeepWith.d.ts +0 -1
- package/dist/utils/common/cloneDeepWith.js +0 -34
|
@@ -26,6 +26,12 @@ const AnnotationCanvas = ({ image, coordinates, setCoordinates, options, drawing
|
|
|
26
26
|
}, 150),
|
|
27
27
|
});
|
|
28
28
|
const { canvasState, initZoomAndPosition, initCanvas, preserveZoomAndPosition, handleWheel, handleMouseDown, handleMouseMove, handleMouseUp, handleMouseLeave, } = useImagePanZoom({ canvasRef, imageRef, panZoomEnabled, zoom, editable });
|
|
29
|
+
const updateDisplayCoordinates = (coordinates) => {
|
|
30
|
+
setDisplayCoordinates(coordinates?.map((coordinate) => ({
|
|
31
|
+
...coordinate,
|
|
32
|
+
type: coordinate.type ?? DrawMode.RECTANGLE,
|
|
33
|
+
})) || []);
|
|
34
|
+
};
|
|
29
35
|
const createEmptyImage = () => {
|
|
30
36
|
const img = new Image();
|
|
31
37
|
img.width = img.height = 0;
|
|
@@ -54,19 +60,21 @@ const AnnotationCanvas = ({ image, coordinates, setCoordinates, options, drawing
|
|
|
54
60
|
preserveZoomAndPosition(canvasRef.current, tempImage, canvasState.zoom / (canvasState.initZoom || 1));
|
|
55
61
|
}
|
|
56
62
|
imageRef.current = tempImage;
|
|
57
|
-
|
|
58
|
-
return {
|
|
59
|
-
...coordinate,
|
|
60
|
-
type: coordinate.type ? coordinate.type : DrawMode.RECTANGLE,
|
|
61
|
-
};
|
|
62
|
-
}) || []);
|
|
63
|
+
updateDisplayCoordinates(coordinates);
|
|
63
64
|
};
|
|
64
65
|
tempImage.onerror = () => !cancelled && resetCanvas(`Failed to load image: ${image}`);
|
|
65
66
|
tempImage.src = image;
|
|
66
67
|
return () => {
|
|
67
68
|
cancelled = true;
|
|
69
|
+
tempImage.onload = null;
|
|
70
|
+
tempImage.onerror = null;
|
|
68
71
|
};
|
|
69
72
|
}, [image, resetOnImageChange]);
|
|
73
|
+
useEffect(() => {
|
|
74
|
+
if (imageRef.current.src && imageRef.current.complete) {
|
|
75
|
+
updateDisplayCoordinates(coordinates);
|
|
76
|
+
}
|
|
77
|
+
}, [coordinates]);
|
|
70
78
|
useEffect(() => {
|
|
71
79
|
if (!canvasRef.current)
|
|
72
80
|
return;
|
|
@@ -28,7 +28,8 @@ export const useDrawEvents = (params) => {
|
|
|
28
28
|
canvasRef.current.addEventListener('mouseup', handlers.up);
|
|
29
29
|
canvasRef.current.addEventListener('mouseleave', handlers.leave);
|
|
30
30
|
setMousePoint({ x: 0, y: 0, selected: false });
|
|
31
|
-
|
|
31
|
+
if (coordinatesRef.current.length > 0)
|
|
32
|
+
setCoordinates(initSelector(coordinatesRef.current));
|
|
32
33
|
currentCoordinateRef.current = null;
|
|
33
34
|
startMousePointRef.current = null;
|
|
34
35
|
maskImageRef.current = new Image();
|
|
@@ -2,7 +2,6 @@ import { jsx as _jsx } from "react/jsx-runtime";
|
|
|
2
2
|
import { useCallback, useEffect, useRef, useState } from 'react';
|
|
3
3
|
import { DrawMode } from '../../enum/common';
|
|
4
4
|
import { ignoreImageKey, isEqualWith } from '../../utils/common/isEqualWith';
|
|
5
|
-
import { cloneDeepWith } from '../../utils/common/cloneDeepWith';
|
|
6
5
|
import { cloneDeep } from '../../utils/common/cloneDeep';
|
|
7
6
|
import { MouseAction } from '../../utils/mouseActions';
|
|
8
7
|
import { useDrawEvents } from './_hooks/drawEvents/useDrawEvents';
|
|
@@ -75,9 +74,7 @@ const AnnotationLayer = ({ canvasState, coordinates = [], setCoordinates: propSe
|
|
|
75
74
|
});
|
|
76
75
|
useEffect(() => {
|
|
77
76
|
if (!isEqualWith(coordinates, coordinatesRef.current, ignoreImageKey)) {
|
|
78
|
-
coordinatesRef.current =
|
|
79
|
-
return undefined;
|
|
80
|
-
});
|
|
77
|
+
coordinatesRef.current = cloneDeep(coordinates) || [];
|
|
81
78
|
}
|
|
82
79
|
}, [coordinates]);
|
|
83
80
|
useEffect(() => {
|
package/package.json
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function cloneDeepWith<T>(obj: T, cloneValue: (value: unknown, key: PropertyKey | undefined, parent: unknown, stack: Map<unknown, unknown>) => unknown): T;
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
export function cloneDeepWith(obj, cloneValue) {
|
|
2
|
-
const stack = new Map();
|
|
3
|
-
const baseClone = (value, key, parent) => {
|
|
4
|
-
const customResult = cloneValue(value, key, parent, stack);
|
|
5
|
-
if (customResult !== undefined) {
|
|
6
|
-
return customResult;
|
|
7
|
-
}
|
|
8
|
-
if (value === null || typeof value !== 'object') {
|
|
9
|
-
return value;
|
|
10
|
-
}
|
|
11
|
-
if (stack.has(value)) {
|
|
12
|
-
return stack.get(value);
|
|
13
|
-
}
|
|
14
|
-
if (value instanceof Date) {
|
|
15
|
-
return new Date(value.getTime());
|
|
16
|
-
}
|
|
17
|
-
if (Array.isArray(value)) {
|
|
18
|
-
const arr = [];
|
|
19
|
-
stack.set(value, arr);
|
|
20
|
-
value.forEach((item, i) => {
|
|
21
|
-
arr[i] = baseClone(item, i, value);
|
|
22
|
-
});
|
|
23
|
-
return arr;
|
|
24
|
-
}
|
|
25
|
-
const result = {};
|
|
26
|
-
stack.set(value, result);
|
|
27
|
-
Object.keys(value).forEach((k) => {
|
|
28
|
-
const v = value[k];
|
|
29
|
-
result[k] = baseClone(v, k, value);
|
|
30
|
-
});
|
|
31
|
-
return result;
|
|
32
|
-
};
|
|
33
|
-
return baseClone(obj, undefined, undefined);
|
|
34
|
-
}
|