@deepnoid/canvas 0.1.39 → 0.1.40
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/index.d.ts +3 -2
- package/dist/components/AnnotationCanvas/index.js +2 -2
- package/dist/components/AnnotationLayer/_hooks/drawEvents/rectangleUtils.d.ts +6 -6
- package/dist/components/AnnotationLayer/_hooks/drawEvents/useDrawEvents.d.ts +3 -3
- package/dist/components/AnnotationLayer/_hooks/useCanvasDraw.d.ts +3 -3
- package/dist/components/AnnotationLayer/_hooks/useMouse.d.ts +3 -3
- package/dist/components/AnnotationLayer/index.d.ts +3 -3
- package/dist/components/AnnotationLayer/index.js +2 -2
- package/dist/types/index.d.ts +2 -4
- package/package.json +1 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ComponentType, ReactNode } from 'react';
|
|
1
|
+
import { ComponentType, Dispatch, ReactNode, SetStateAction } from 'react';
|
|
2
2
|
import { AnnotationCanvasDrawing, AnnotationCanvasOptionsZoom, Coordinate } from '../../types';
|
|
3
3
|
export type ZoomButtonType = {
|
|
4
4
|
onClick: () => void;
|
|
@@ -7,6 +7,7 @@ export type ZoomButtonType = {
|
|
|
7
7
|
export type AnnotationCanvasProps = {
|
|
8
8
|
image: string;
|
|
9
9
|
coordinates?: Coordinate[];
|
|
10
|
+
setCoordinates?: Dispatch<SetStateAction<Coordinate[] | undefined>>;
|
|
10
11
|
options: {
|
|
11
12
|
panZoomEnabled?: boolean;
|
|
12
13
|
zoom?: AnnotationCanvasOptionsZoom;
|
|
@@ -21,5 +22,5 @@ export type AnnotationCanvasProps = {
|
|
|
21
22
|
};
|
|
22
23
|
editable?: boolean;
|
|
23
24
|
};
|
|
24
|
-
declare const AnnotationCanvas: ({ image, coordinates, options, drawing, events, editable, }: AnnotationCanvasProps) => import("react/jsx-runtime").JSX.Element;
|
|
25
|
+
declare const AnnotationCanvas: ({ image, coordinates, setCoordinates, options, drawing, events, editable, }: AnnotationCanvasProps) => import("react/jsx-runtime").JSX.Element;
|
|
25
26
|
export default AnnotationCanvas;
|
|
@@ -8,7 +8,7 @@ import { useDebounce } from '../../hooks/useDebounce';
|
|
|
8
8
|
import { DrawMode } from '../../enum/common';
|
|
9
9
|
import { createHistory } from './_utils/createHistory';
|
|
10
10
|
import { clearCanvasRect, drawCanvas, resolutionCanvas } from '../../utils/canvas';
|
|
11
|
-
const AnnotationCanvas = ({ image, coordinates, options, drawing, events, editable = false, }) => {
|
|
11
|
+
const AnnotationCanvas = ({ image, coordinates, setCoordinates, options, drawing, events, editable = false, }) => {
|
|
12
12
|
const { panZoomEnabled, zoom, ZoomButton, resetOnImageChange, timeout = 10000 } = options;
|
|
13
13
|
const { onImageLoadSuccess, onImageLoadError } = events;
|
|
14
14
|
const canvasRef = useRef(null);
|
|
@@ -78,6 +78,6 @@ const AnnotationCanvas = ({ image, coordinates, options, drawing, events, editab
|
|
|
78
78
|
if (canvas)
|
|
79
79
|
redraw(canvas);
|
|
80
80
|
}, [canvasState]);
|
|
81
|
-
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:
|
|
81
|
+
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)}%` }))] }) }));
|
|
82
82
|
};
|
|
83
83
|
export default AnnotationCanvas;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { RefObject } from 'react';
|
|
2
|
-
import {
|
|
2
|
+
import { Coordinate, Point, Rectangle, CanvasState } from '../../../../types';
|
|
3
3
|
import { CoordinateHistory } from '../../../AnnotationCanvas/_utils/createHistory';
|
|
4
4
|
import { MouseAction } from '../../../../utils/mouseActions';
|
|
5
5
|
import { RectangleAnchor } from '../../../../enum/common';
|
|
@@ -8,21 +8,21 @@ export declare const getRectangleCorners: ({ x, y, width, height }: Rectangle) =
|
|
|
8
8
|
x: number;
|
|
9
9
|
y: number;
|
|
10
10
|
}[];
|
|
11
|
-
export declare const selectRectangleAtPoint: (zoom: number, mousePoint: Point, coordinatesRef: RefObject<
|
|
12
|
-
export declare const updateActiveRectangleAnchor: (zoom: number, mousePointRef: Point, currentCoordinateRef: RefObject<
|
|
13
|
-
export declare const createCoordinate: (coordinate:
|
|
11
|
+
export declare const selectRectangleAtPoint: (zoom: number, mousePoint: Point, coordinatesRef: RefObject<Coordinate[]>, currentCoordinateRef: RefObject<Coordinate | null>) => void;
|
|
12
|
+
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;
|
|
14
14
|
export declare const clampBoundingBoxToImage: (x: number, y: number, width: number, height: number, dw: number, dh: number) => Rectangle & {
|
|
15
15
|
selected?: boolean;
|
|
16
16
|
};
|
|
17
17
|
export declare const getCanvasMousePoint: (event: globalThis.MouseEvent | React.MouseEvent, canvas: HTMLCanvasElement, canvasState: CanvasState) => Point;
|
|
18
18
|
type BBoxParams = {
|
|
19
|
-
coordinatesRef: RefObject<
|
|
19
|
+
coordinatesRef: RefObject<Coordinate[]>;
|
|
20
20
|
dw: number;
|
|
21
21
|
dh: number;
|
|
22
22
|
mousePoint: Point;
|
|
23
23
|
prevMousePoint: Point;
|
|
24
24
|
mouseAction: MouseAction | null;
|
|
25
|
-
currentCoordinate:
|
|
25
|
+
currentCoordinate: Coordinate | null;
|
|
26
26
|
rectangleAnchor: RectangleAnchor | null;
|
|
27
27
|
};
|
|
28
28
|
export declare const handleBBoxOperations: (params: BBoxParams) => void;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { RefObject } from 'react';
|
|
2
|
-
import { Point, Coordinate,
|
|
2
|
+
import { Point, Coordinate, CanvasState, Label } from '../../../../types';
|
|
3
3
|
import { CoordinateHistory } from '../../../AnnotationCanvas/_utils/createHistory';
|
|
4
4
|
import { DrawMode, RectangleAnchor } from '../../../../enum/common';
|
|
5
5
|
import { MouseAction } from '../../../../utils/mouseActions';
|
|
@@ -12,8 +12,8 @@ export type DrawEventsParams = {
|
|
|
12
12
|
startMousePointRef: RefObject<Point | null>;
|
|
13
13
|
prevMousePointRef: RefObject<Point | null>;
|
|
14
14
|
currentCoordinateRef: RefObject<Coordinate | null>;
|
|
15
|
-
coordinatesRef: RefObject<
|
|
16
|
-
setCoordinates: (coordinates:
|
|
15
|
+
coordinatesRef: RefObject<Coordinate[]>;
|
|
16
|
+
setCoordinates: (coordinates: Coordinate[]) => void;
|
|
17
17
|
rectangleAnchorRef: RefObject<RectangleAnchor | null>;
|
|
18
18
|
historyRef: RefObject<CoordinateHistory>;
|
|
19
19
|
maskImageRef: RefObject<HTMLImageElement | null>;
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { RefObject } from 'react';
|
|
2
|
-
import {
|
|
2
|
+
import { Coordinate, Point } from '../../../types';
|
|
3
3
|
type UseCanvasDrawParams = {
|
|
4
4
|
drawLineSize: number;
|
|
5
5
|
drawColor?: string;
|
|
6
6
|
};
|
|
7
7
|
export declare function useCanvasDraw({ drawLineSize, drawColor }: UseCanvasDrawParams): {
|
|
8
8
|
drawCross: (context: CanvasRenderingContext2D, dw: number, dh: number, zoom: number, point: Point) => void;
|
|
9
|
-
drawActiveRect: (context: CanvasRenderingContext2D, coordinate:
|
|
9
|
+
drawActiveRect: (context: CanvasRenderingContext2D, coordinate: Coordinate, zoom: number) => void;
|
|
10
10
|
drawRectFromPoints: (context: CanvasRenderingContext2D, startPoint: Point, endPoint: Point, zoom: number, color?: string | undefined) => void;
|
|
11
|
-
setCursorStyle: (canvas: HTMLCanvasElement, mousePointRef: RefObject<Point>, coordinate:
|
|
11
|
+
setCursorStyle: (canvas: HTMLCanvasElement, mousePointRef: RefObject<Point>, coordinate: Coordinate, zoom: number) => void;
|
|
12
12
|
};
|
|
13
13
|
export {};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { MouseEvent, RefObject } from 'react';
|
|
2
|
-
import {
|
|
2
|
+
import { Coordinate, Point } from '../../../types';
|
|
3
3
|
import { MouseAction } from '../../../utils/mouseActions';
|
|
4
4
|
import { CoordinateHistory } from '../../AnnotationCanvas/_utils/createHistory';
|
|
5
5
|
import { DrawMode } from '../../../enum/common';
|
|
@@ -8,8 +8,8 @@ type UseMouseParams = {
|
|
|
8
8
|
canvasRef: RefObject<HTMLCanvasElement | null>;
|
|
9
9
|
mouseActionRef: RefObject<MouseAction | null>;
|
|
10
10
|
setMousePoint: (point: Point) => void;
|
|
11
|
-
coordinatesRef?: RefObject<
|
|
12
|
-
setCoordinates?: (coordinates:
|
|
11
|
+
coordinatesRef?: RefObject<Coordinate[]>;
|
|
12
|
+
setCoordinates?: (coordinates: Coordinate[]) => void;
|
|
13
13
|
historyRef: RefObject<CoordinateHistory>;
|
|
14
14
|
selectedDrawMode?: DrawMode;
|
|
15
15
|
};
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { Dispatch, RefObject, SetStateAction } from 'react';
|
|
2
|
-
import { CanvasState,
|
|
2
|
+
import { CanvasState, Coordinate, AnnotationCanvasDrawing } from '../../types';
|
|
3
3
|
import { CoordinateHistory } from '../AnnotationCanvas/_utils/createHistory';
|
|
4
4
|
type Props = {
|
|
5
5
|
canvasState: CanvasState;
|
|
6
|
-
coordinates:
|
|
7
|
-
setCoordinates
|
|
6
|
+
coordinates: Coordinate[] | undefined;
|
|
7
|
+
setCoordinates?: Dispatch<SetStateAction<Coordinate[] | undefined>>;
|
|
8
8
|
historyRef: RefObject<CoordinateHistory>;
|
|
9
9
|
drawing: AnnotationCanvasDrawing;
|
|
10
10
|
editable: boolean;
|
|
@@ -27,8 +27,8 @@ const AnnotationLayer = ({ canvasState, coordinates = [], setCoordinates: propSe
|
|
|
27
27
|
const [showSelectedOnly, setShowSelectedOnly] = useState(false);
|
|
28
28
|
const setCoordinates = useCallback((coordinates) => {
|
|
29
29
|
coordinatesRef.current = cloneDeep(coordinates) || [];
|
|
30
|
-
propSetCoordinates(coordinates);
|
|
31
|
-
}, [
|
|
30
|
+
propSetCoordinates && propSetCoordinates(coordinates);
|
|
31
|
+
}, [propSetCoordinates]);
|
|
32
32
|
const setMousePoint = useCallback((point) => (mousePointRef.current = point), []);
|
|
33
33
|
const { drawCross, drawActiveRect, drawRectFromPoints, setCursorStyle } = useCanvasDraw({ drawLineSize, drawColor });
|
|
34
34
|
useDrawEvents({
|
package/dist/types/index.d.ts
CHANGED
|
@@ -31,15 +31,13 @@ export type Coordinate = {
|
|
|
31
31
|
label?: Label;
|
|
32
32
|
type?: DrawMode;
|
|
33
33
|
color?: 'success' | 'warning' | 'danger';
|
|
34
|
-
} & Rectangle;
|
|
35
|
-
export type EditableCoordinate = Coordinate & {
|
|
36
34
|
selected?: boolean;
|
|
37
|
-
};
|
|
35
|
+
} & Rectangle;
|
|
38
36
|
export type ApplyAnnotationStyleVariant = 'drawRect' | 'drawText';
|
|
39
37
|
export type ApplyAnnotationStyleParams = {
|
|
40
38
|
variant: ApplyAnnotationStyleVariant;
|
|
41
39
|
context: CanvasRenderingContext2D;
|
|
42
|
-
coordinate:
|
|
40
|
+
coordinate: Coordinate;
|
|
43
41
|
drawLineSize: number;
|
|
44
42
|
zoom: number;
|
|
45
43
|
};
|