@deepnoid/canvas 0.1.42 → 0.1.44

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.
@@ -86,6 +86,6 @@ const AnnotationCanvas = ({ image, coordinates, setCoordinates, options, drawing
86
86
  if (canvas)
87
87
  redraw(canvas);
88
88
  }, [canvasState]);
89
- return (_jsx("div", { style: { width: '100%', height: '100%', display: 'flex', flex: 1 }, children: _jsxs("div", { onWheel: handleWheel, onMouseMove: handleMouseMove, onMouseDown: handleMouseDown, onMouseUp: handleMouseUp, onMouseLeave: handleMouseLeave, onContextMenu: (e) => e.preventDefault(), style: { flex: 1, position: 'relative', cursor: editable ? 'default' : 'grab' }, children: [_jsx("canvas", { ref: canvasRef, style: { position: 'absolute', width: '100%', height: '100%', left: 0, top: 0 } }), _jsx(AnnotationLayer, { canvasState: canvasState, coordinates: displayCoordinates, setCoordinates: setCoordinates, historyRef: historyRef, drawing: drawing, editable: editable }), ZoomButton && canvasState.initZoom > 0 && (_jsx(ZoomButton, { onClick: initCanvas, children: `${Math.round((canvasState.zoom / canvasState.initZoom) * 100)}%` }))] }) }));
89
+ return (_jsx("div", { style: { width: '100%', height: '100%', display: 'flex', flex: 1 }, children: _jsxs("div", { onWheel: handleWheel, onMouseMove: handleMouseMove, onMouseDown: handleMouseDown, onMouseUp: handleMouseUp, onMouseLeave: handleMouseLeave, onContextMenu: (e) => e.preventDefault(), style: { flex: 1, position: 'relative', cursor: !panZoomEnabled || editable ? 'default' : 'grab' }, children: [_jsx("canvas", { ref: canvasRef, style: { position: 'absolute', width: '100%', height: '100%', left: 0, top: 0 } }), _jsx(AnnotationLayer, { canvasState: canvasState, coordinates: displayCoordinates, setCoordinates: setCoordinates, historyRef: historyRef, drawing: drawing, editable: editable }), ZoomButton && canvasState.initZoom > 0 && (_jsx(ZoomButton, { onClick: initCanvas, children: `${Math.round((canvasState.zoom / canvasState.initZoom) * 100)}%` }))] }) }));
90
90
  };
91
91
  export default AnnotationCanvas;
@@ -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;
@@ -21,7 +21,7 @@ export function useCanvasDraw({ drawLineSize, drawColor }) {
21
21
  };
22
22
  const drawActiveRect = (context, coordinate, zoom) => {
23
23
  const { x, y, width, height, selected } = coordinate;
24
- if (!(selected && x && y && width && height))
24
+ if (!selected)
25
25
  return;
26
26
  context.lineWidth = drawLineSize / zoom;
27
27
  context.fillStyle = '#FFF';
@@ -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
  });
@@ -26,6 +26,7 @@ export type Rectangle = {
26
26
  export type Label = {
27
27
  id: number;
28
28
  name: string;
29
+ type: string;
29
30
  };
30
31
  export type Coordinate = {
31
32
  label?: Label;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@deepnoid/canvas",
3
- "version": "0.1.42",
3
+ "version": "0.1.44",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "main": "./dist/index.cjs",