@deepnoid/canvas 0.1.42 → 0.1.43

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,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, drawLabel, }: 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;
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, drawLabel, }) => (event) => {
39
+ export const handleMouseUpRectangle = ({ canvasRef, canvasStateRef, mouseActionRef, mousePointRef, setMousePoint, startMousePointRef, prevMousePointRef, currentCoordinateRef, coordinatesRef, setCoordinates, rectangleAnchorRef, historyRef, 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);
@@ -48,7 +48,8 @@ export const handleMouseUpRectangle = ({ canvasRef, canvasStateRef, mouseActionR
48
48
  if (movedWidth > ACTIVE_POINT_SIZE || movedHeight > ACTIVE_POINT_SIZE) {
49
49
  const { x, y, width, height } = clampBoundingBoxToImage(Math.min(startMousePointRef.current.x, mousePoint.x), Math.min(startMousePointRef.current.y, mousePoint.y), movedWidth, movedHeight, dw, dh);
50
50
  if (!currentCoordinateRef.current) {
51
- const newCoordinate = { label: drawLabel, type: DrawMode.RECTANGLE, x, y, width, height, selected: false };
51
+ const label = drawLabelRef.current;
52
+ const newCoordinate = { label, type: DrawMode.RECTANGLE, x, y, width, height, selected: false };
52
53
  createCoordinate(newCoordinate, setCoordinates, coordinatesRef, historyRef, currentCoordinateRef);
53
54
  }
54
55
  }
@@ -17,7 +17,7 @@ export type DrawEventsParams = {
17
17
  rectangleAnchorRef: RefObject<RectangleAnchor | null>;
18
18
  historyRef: RefObject<CoordinateHistory>;
19
19
  maskImageRef: RefObject<HTMLImageElement | null>;
20
- drawLabel?: Label;
20
+ drawLabelRef: RefObject<Label | undefined>;
21
21
  };
22
22
  export declare const useDrawEvents: (params: DrawEventsParams & {
23
23
  selectedDrawMode?: DrawMode;
@@ -23,7 +23,11 @@ const AnnotationLayer = ({ canvasState, coordinates = [], setCoordinates: propSe
23
23
  const startMousePointRef = useRef(null);
24
24
  const prevMousePointRef = useRef(null);
25
25
  const rectangleAnchorRef = useRef(null);
26
+ const drawLabelRef = useRef(drawLabel);
26
27
  const [showSelectedOnly, setShowSelectedOnly] = useState(false);
28
+ useEffect(() => {
29
+ drawLabelRef.current = drawLabel;
30
+ }, [drawLabel]);
27
31
  const setCoordinates = useCallback((coordinates) => {
28
32
  coordinatesRef.current = cloneDeep(coordinates) || [];
29
33
  propSetCoordinates && propSetCoordinates(coordinates);
@@ -44,7 +48,7 @@ const AnnotationLayer = ({ canvasState, coordinates = [], setCoordinates: propSe
44
48
  rectangleAnchorRef,
45
49
  historyRef,
46
50
  maskImageRef,
47
- drawLabel,
51
+ drawLabelRef,
48
52
  selectedDrawMode,
49
53
  editable,
50
54
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@deepnoid/canvas",
3
- "version": "0.1.42",
3
+ "version": "0.1.43",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "main": "./dist/index.cjs",