@deepnoid/canvas 0.1.50 → 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.
@@ -1,11 +1,11 @@
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;
7
7
  add: (coordinates: Coordinate[]) => void;
8
- undo: () => Coordinate[];
8
+ undo: () => Coordinate[] | undefined;
9
9
  redo: () => Coordinate[] | undefined;
10
10
  };
11
11
  export declare const createHistory: () => CoordinateHistory;
@@ -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,21 +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 > -1)
21
- historyIndex--;
22
- return history[historyIndex] || [];
24
+ if (history === undefined || historyIndex <= 0)
25
+ return undefined;
26
+ historyIndex--;
27
+ return history[historyIndex];
23
28
  },
24
29
  redo: () => {
25
- if (historyIndex < history.length - 1) {
26
- historyIndex++;
27
- return history[historyIndex];
28
- }
29
- return undefined;
30
+ if (history === undefined || historyIndex > history.length)
31
+ return undefined;
32
+ historyIndex++;
33
+ return history[historyIndex];
30
34
  },
31
35
  };
32
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, historyRef, drawLabelRef, }: DrawEventsParams) => (event: globalThis.MouseEvent) => void;
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, historyRef, drawLabelRef, }) => (event) => {
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);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@deepnoid/canvas",
3
- "version": "0.1.50",
3
+ "version": "0.1.51",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "main": "./dist/index.cjs",