@deepnoid/canvas 0.1.48 → 0.1.50

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.
@@ -9,7 +9,7 @@ export function useImagePanZoom({ canvasRef, imageRef, panZoomEnabled = false, z
9
9
  moveY: 0,
10
10
  zoomX: 0,
11
11
  zoomY: 0,
12
- zoom: 0,
12
+ zoom: 1,
13
13
  dx: 0,
14
14
  dy: 0,
15
15
  dw: 0,
@@ -5,7 +5,7 @@ export type CoordinateHistory = {
5
5
  setHistoryIndex: (index: number) => void;
6
6
  init: (coordinates?: Coordinate[]) => void;
7
7
  add: (coordinates: Coordinate[]) => void;
8
- undo: () => Coordinate[] | undefined;
8
+ undo: () => Coordinate[];
9
9
  redo: () => Coordinate[] | undefined;
10
10
  };
11
11
  export declare const createHistory: () => CoordinateHistory;
@@ -17,11 +17,9 @@ export const createHistory = () => {
17
17
  historyIndex++;
18
18
  },
19
19
  undo: () => {
20
- if (historyIndex > 0) {
20
+ if (historyIndex > -1)
21
21
  historyIndex--;
22
- return history[historyIndex];
23
- }
24
- return undefined;
22
+ return history[historyIndex] || [];
25
23
  },
26
24
  redo: () => {
27
25
  if (historyIndex < history.length - 1) {
@@ -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, historyRef, currentCoordinateRef);
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[]>, historyRef: RefObject<CoordinateHistory>, currentCoordinateRef: RefObject<Coordinate | null>) => void;
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, historyRef, currentCoordinateRef) => {
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(JSON.parse(JSON.stringify(coordinatesRef.current)));
18
+ historyRef.current.add(cloneDeep(coordinatesRef.current));
18
19
  }
19
20
  }
20
21
  mouseActionRef.current = null;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@deepnoid/canvas",
3
- "version": "0.1.48",
3
+ "version": "0.1.50",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "main": "./dist/index.cjs",