@deepnoid/canvas 0.1.49 → 0.1.51
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/_utils/createHistory.d.ts +1 -1
- package/dist/components/AnnotationCanvas/_utils/createHistory.js +13 -11
- package/dist/components/AnnotationCanvas/index.js +3 -0
- package/dist/components/AnnotationLayer/_hooks/drawEvents/rectangle.d.ts +1 -1
- package/dist/components/AnnotationLayer/_hooks/drawEvents/rectangle.js +2 -2
- package/dist/components/AnnotationLayer/_hooks/drawEvents/rectangleUtils.d.ts +1 -2
- package/dist/components/AnnotationLayer/_hooks/drawEvents/rectangleUtils.js +1 -3
- package/dist/components/AnnotationLayer/_hooks/useMouse.js +2 -1
- package/package.json +1 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Coordinate } from '../../../types';
|
|
2
2
|
export type CoordinateHistory = {
|
|
3
|
-
getHistory: () => Coordinate[][];
|
|
3
|
+
getHistory: () => Coordinate[][] | undefined;
|
|
4
4
|
getHistoryIndex: () => number;
|
|
5
5
|
setHistoryIndex: (index: number) => void;
|
|
6
6
|
init: (coordinates?: Coordinate[]) => void;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export const createHistory = () => {
|
|
2
|
-
let history =
|
|
2
|
+
let history = undefined;
|
|
3
3
|
let historyIndex = -1;
|
|
4
4
|
return {
|
|
5
5
|
getHistory: () => history,
|
|
@@ -12,23 +12,25 @@ export const createHistory = () => {
|
|
|
12
12
|
historyIndex = 0;
|
|
13
13
|
},
|
|
14
14
|
add: (coordinates) => {
|
|
15
|
+
if (history === undefined) {
|
|
16
|
+
history = [];
|
|
17
|
+
historyIndex = -1;
|
|
18
|
+
}
|
|
15
19
|
history.splice(historyIndex + 1);
|
|
16
20
|
history.push(coordinates);
|
|
17
21
|
historyIndex++;
|
|
18
22
|
},
|
|
19
23
|
undo: () => {
|
|
20
|
-
if (historyIndex
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
return undefined;
|
|
24
|
+
if (history === undefined || historyIndex <= 0)
|
|
25
|
+
return undefined;
|
|
26
|
+
historyIndex--;
|
|
27
|
+
return history[historyIndex];
|
|
25
28
|
},
|
|
26
29
|
redo: () => {
|
|
27
|
-
if (historyIndex
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
return undefined;
|
|
30
|
+
if (history === undefined || historyIndex > history.length)
|
|
31
|
+
return undefined;
|
|
32
|
+
historyIndex++;
|
|
33
|
+
return history[historyIndex];
|
|
32
34
|
},
|
|
33
35
|
};
|
|
34
36
|
};
|
|
@@ -72,6 +72,9 @@ const AnnotationCanvas = ({ image, coordinates, setCoordinates, options, drawing
|
|
|
72
72
|
}, [image, resetOnImageChange]);
|
|
73
73
|
useEffect(() => {
|
|
74
74
|
if (imageRef.current.src) {
|
|
75
|
+
const history = historyRef.current.getHistory();
|
|
76
|
+
if (!history)
|
|
77
|
+
historyRef.current.init(coordinates);
|
|
75
78
|
updateDisplayCoordinates(coordinates);
|
|
76
79
|
}
|
|
77
80
|
}, [coordinates, imageRef.current]);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { DrawEventsParams } from './useDrawEvents';
|
|
2
2
|
export declare const handleMouseDownRectangle: ({ canvasRef, canvasStateRef, mouseActionRef, mousePointRef, setMousePoint, startMousePointRef, currentCoordinateRef, coordinatesRef, rectangleAnchorRef, }: DrawEventsParams) => (event: globalThis.MouseEvent) => void;
|
|
3
3
|
export declare const handleMouseMoveRectangle: ({ canvasRef, canvasStateRef, mouseActionRef, mousePointRef, setMousePoint, prevMousePointRef, currentCoordinateRef, coordinatesRef, rectangleAnchorRef, }: DrawEventsParams) => (event: globalThis.MouseEvent) => void;
|
|
4
|
-
export declare const handleMouseUpRectangle: ({ canvasRef, canvasStateRef, mouseActionRef, mousePointRef, setMousePoint, startMousePointRef, prevMousePointRef, currentCoordinateRef, coordinatesRef, setCoordinates, rectangleAnchorRef,
|
|
4
|
+
export declare const handleMouseUpRectangle: ({ canvasRef, canvasStateRef, mouseActionRef, mousePointRef, setMousePoint, startMousePointRef, prevMousePointRef, currentCoordinateRef, coordinatesRef, setCoordinates, rectangleAnchorRef, drawLabelRef, }: DrawEventsParams) => (event: globalThis.MouseEvent) => void;
|
|
5
5
|
export declare const handleMouseLeaveRectangle: ({ canvasRef, canvasStateRef, setMousePoint, startMousePointRef, prevMousePointRef, mouseActionRef, rectangleAnchorRef, }: DrawEventsParams) => (event: globalThis.MouseEvent) => void;
|
|
@@ -36,7 +36,7 @@ export const handleMouseMoveRectangle = ({ canvasRef, canvasStateRef, mouseActio
|
|
|
36
36
|
});
|
|
37
37
|
event.preventDefault();
|
|
38
38
|
};
|
|
39
|
-
export const handleMouseUpRectangle = ({ canvasRef, canvasStateRef, mouseActionRef, mousePointRef, setMousePoint, startMousePointRef, prevMousePointRef, currentCoordinateRef, coordinatesRef, setCoordinates, rectangleAnchorRef,
|
|
39
|
+
export const handleMouseUpRectangle = ({ canvasRef, canvasStateRef, mouseActionRef, mousePointRef, setMousePoint, startMousePointRef, prevMousePointRef, currentCoordinateRef, coordinatesRef, setCoordinates, rectangleAnchorRef, drawLabelRef, }) => (event) => {
|
|
40
40
|
if (!canvasRef.current || !isMouseClickAction(event.button, MouseAction.LEFT))
|
|
41
41
|
return;
|
|
42
42
|
const mousePoint = getCanvasMousePoint(event, canvasRef.current, canvasStateRef.current);
|
|
@@ -50,7 +50,7 @@ export const handleMouseUpRectangle = ({ canvasRef, canvasStateRef, mouseActionR
|
|
|
50
50
|
if (!currentCoordinateRef.current) {
|
|
51
51
|
const label = drawLabelRef.current;
|
|
52
52
|
const newCoordinate = { label, type: DrawMode.RECTANGLE, x, y, width, height, selected: false };
|
|
53
|
-
createCoordinate(newCoordinate, setCoordinates, coordinatesRef,
|
|
53
|
+
createCoordinate(newCoordinate, setCoordinates, coordinatesRef, currentCoordinateRef);
|
|
54
54
|
}
|
|
55
55
|
}
|
|
56
56
|
else {
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { RefObject } from 'react';
|
|
2
2
|
import { Coordinate, Point, Rectangle, CanvasState } from '../../../../types';
|
|
3
|
-
import { CoordinateHistory } from '../../../AnnotationCanvas/_utils/createHistory';
|
|
4
3
|
import { MouseAction } from '../../../../utils/mouseActions';
|
|
5
4
|
import { RectangleAnchor } from '../../../../enum/common';
|
|
6
5
|
export declare const ACTIVE_POINT_SIZE = 10;
|
|
@@ -10,7 +9,7 @@ export declare const getRectangleCorners: ({ x, y, width, height }: Rectangle) =
|
|
|
10
9
|
}[];
|
|
11
10
|
export declare const selectRectangleAtPoint: (zoom: number, mousePoint: Point, coordinatesRef: RefObject<Coordinate[]>, currentCoordinateRef: RefObject<Coordinate | null>) => void;
|
|
12
11
|
export declare const updateActiveRectangleAnchor: (zoom: number, mousePointRef: Point, currentCoordinateRef: RefObject<Coordinate | null>, rectangleAnchorRef: RefObject<RectangleAnchor | null>) => void;
|
|
13
|
-
export declare const createCoordinate: (coordinate: Coordinate, setCoordinates: (dataSet: Coordinate[]) => void, coordinatesRef: RefObject<Coordinate[]>,
|
|
12
|
+
export declare const createCoordinate: (coordinate: Coordinate, setCoordinates: (dataSet: Coordinate[]) => void, coordinatesRef: RefObject<Coordinate[]>, currentCoordinateRef: RefObject<Coordinate | null>) => void;
|
|
14
13
|
export declare const clampBoundingBoxToImage: (x: number, y: number, width: number, height: number, dw: number, dh: number) => Rectangle & {
|
|
15
14
|
selected?: boolean;
|
|
16
15
|
};
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { MouseAction } from '../../../../utils/mouseActions';
|
|
2
|
-
import { cloneDeep } from '../../../../utils/common/cloneDeep';
|
|
3
2
|
import { DrawMode, RectangleAnchor } from '../../../../enum/common';
|
|
4
3
|
import { getMousePointTransform } from '../../../../utils/pointTransform';
|
|
5
4
|
export const ACTIVE_POINT_SIZE = 10;
|
|
@@ -96,9 +95,8 @@ export const updateActiveRectangleAnchor = (zoom, mousePointRef, currentCoordina
|
|
|
96
95
|
rectangleAnchorRef.current = null;
|
|
97
96
|
}
|
|
98
97
|
};
|
|
99
|
-
export const createCoordinate = (coordinate, setCoordinates, coordinatesRef,
|
|
98
|
+
export const createCoordinate = (coordinate, setCoordinates, coordinatesRef, currentCoordinateRef) => {
|
|
100
99
|
coordinatesRef.current.push(coordinate);
|
|
101
|
-
historyRef.current.add(cloneDeep(coordinatesRef.current));
|
|
102
100
|
setCoordinates(coordinatesRef.current);
|
|
103
101
|
currentCoordinateRef.current = null;
|
|
104
102
|
};
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { useCallback } from 'react';
|
|
2
2
|
import { isMouseClickAction, mapButtonToMouseAction, MouseAction } from '../../../utils/mouseActions';
|
|
3
3
|
import { DrawMode } from '../../../enum/common';
|
|
4
|
+
import { cloneDeep } from '../../../utils/common/cloneDeep';
|
|
4
5
|
export const INIT_POINT = { x: 0, y: 0, selected: false };
|
|
5
6
|
export function useMouse({ canvasRef, mouseActionRef, setMousePoint, coordinatesRef, setCoordinates, historyRef, selectedDrawMode, }) {
|
|
6
7
|
const handleMouseDown = useCallback((event) => {
|
|
@@ -14,7 +15,7 @@ export function useMouse({ canvasRef, mouseActionRef, setMousePoint, coordinates
|
|
|
14
15
|
if (canvasRef.current && isMouseClickAction(event.button, MouseAction.LEFT) && selectedDrawMode) {
|
|
15
16
|
if (selectedDrawMode === DrawMode.RECTANGLE && coordinatesRef?.current && setCoordinates) {
|
|
16
17
|
setCoordinates(coordinatesRef.current);
|
|
17
|
-
historyRef.current.add(
|
|
18
|
+
historyRef.current.add(cloneDeep(coordinatesRef.current));
|
|
18
19
|
}
|
|
19
20
|
}
|
|
20
21
|
mouseActionRef.current = null;
|