@yorab/react-paint 0.11.7 → 0.12.0
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/README.md +4 -2
- package/dist/canvas/components/Canvas.d.ts +10 -10
- package/dist/canvas/components/EditTextBox.d.ts +1 -2
- package/dist/canvas/constants/app.d.ts +14 -2
- package/dist/canvas/constants/zoom.d.ts +5 -0
- package/dist/canvas/hooks/useComponent.d.ts +4 -3
- package/dist/canvas/hooks/useDrawableCanvas.d.ts +12 -8
- package/dist/canvas/hooks/usePinchZoomAndMove.d.ts +17 -0
- package/dist/canvas/hooks/useReactPaint.d.ts +45 -32
- package/dist/canvas/hooks/useResizeObserver.d.ts +1 -1
- package/dist/canvas/hooks/useShapes.d.ts +3 -3
- package/dist/canvas/hooks/useZoom.d.ts +21 -0
- package/dist/canvas/utils/file.d.ts +7 -3
- package/dist/canvas/utils/grid.d.ts +1 -1
- package/dist/canvas/utils/intersect.d.ts +9 -3
- package/dist/canvas/utils/shapes/index.d.ts +1 -0
- package/dist/canvas/utils/shapes/path.d.ts +1 -1
- package/dist/canvas/utils/shapes/picture.d.ts +1 -1
- package/dist/canvas/utils/shapes/rectangle.d.ts +1 -1
- package/dist/canvas/utils/transform.d.ts +1 -1
- package/dist/canvas/utils/trigo.d.ts +2 -0
- package/dist/canvas/utils/zoom.d.ts +58 -0
- package/dist/common/types/Canvas.d.ts +8 -0
- package/dist/common/types/Mode.d.ts +3 -1
- package/dist/common/types/Shapes.d.ts +1 -0
- package/dist/common/utils/array.d.ts +1 -0
- package/dist/common/utils/util.d.ts +2 -0
- package/dist/editor/components/common/Modal.d.ts +3 -2
- package/dist/editor/components/common/Panel.d.ts +3 -1
- package/dist/editor/components/settings/Layouts.d.ts +3 -2
- package/dist/editor/components/settings/SettingsBar.d.ts +6 -3
- package/dist/editor/components/settings/ZoomButton.d.ts +8 -0
- package/dist/editor/components/toolbox/ExportModal.d.ts +7 -0
- package/dist/editor/components/toolbox/MenuGroup.d.ts +3 -3
- package/dist/editor/components/toolbox/Toolbar.d.ts +5 -5
- package/dist/editor/constants/icons.d.ts +4 -4
- package/dist/editor/hooks/useDrag.d.ts +2 -2
- package/dist/index.d.ts +2 -1
- package/dist/react-paint.css +1 -1
- package/dist/react-paint.js +1171 -1023
- package/dist/react-paint.umd.cjs +1 -1
- package/package.json +21 -24
package/README.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# React Paint
|
|
1
|
+
# React Paint
|
|
2
2
|
|
|
3
3
|
An open-source canvas-based library for React used for image annotation or as a digital whiteboard
|
|
4
4
|
|
|
@@ -129,7 +129,7 @@ you will find other usages in <a href="https://github.com/YoRab/react-paint-edit
|
|
|
129
129
|
| `registerEvent` | `(event: "dataChanged", listener: (data: StateData, source: 'user' \| 'remote') => void) => void` | registerEvent is used to register a listener for special events triggered by react-paint. The only currently available event is `dataChanged`. `source` indicates the origin of the state update |
|
|
130
130
|
| `unregisterEvent` | `(event: "dataChanged", listener?: ((data: StateData, source: 'user' \| 'remote') => void) \| undefined) => void` | unregisterEvent is used to unregister a listener previously registered. Omitting listener will result in unregistering every listeners for the the given event |
|
|
131
131
|
| `resetCanvas` | `(shapes: DrawableShape[], clearHistory?: boolean) => Promise<void>` | reset canvas with the given shapes. use `[]` or `undefined` to clear the canvas. Set `false` to `clearHistory` to prevent history stack to be cleared |
|
|
132
|
-
| `getCurrentImage` | `() => string
|
|
132
|
+
| `getCurrentImage` | `(view: 'defaultView' \| 'currentZoom' \| 'fitToShapes') => string` | Returns a data URL containing the content of the current canvas as a PNG image. `defaultView` will export a picture with dimensions based on canvas and no zoom. `currentZoom` will export a picture with dimensions based on canvas and current zoom and offset. `fitToShapes` will export a picture containing all drawn shapes. |
|
|
133
133
|
| `getCurrentData` | `() => StateData` | Returns the current state of the canvas |
|
|
134
134
|
|
|
135
135
|
#### `OptionalOptions`
|
|
@@ -151,6 +151,8 @@ you will find other usages in <a href="https://github.com/YoRab/react-paint-edit
|
|
|
151
151
|
| `isBrushShapeDoneOnMouseUp` | `boolean` | *Optional*. Choose whether drawing brush shape after releasing mouse should create a new shape or not | `true` |
|
|
152
152
|
| `canvasSelectionPadding` | `boolean` | *Optional*. Padding between shape and selection frame | `0` |
|
|
153
153
|
| `availableTools` | `CustomToolInput[]` | *Optional*. List of available tools. See CustomTool for more details | `` |
|
|
154
|
+
| `size` | `'fixed' \| 'infinite'` | *Optional*. Choose canvas size mode. `fixed` canvas is bound within its width and height, `infinite` canvas has no bound | `fixed` |
|
|
155
|
+
| `canZoom` | `'never' \| 'always'` | *Optional*. Choose wether zoom is available `never` zoom is not available, `always` zoom is available | `never` |
|
|
154
156
|
|
|
155
157
|
|
|
156
158
|
|
|
@@ -5,13 +5,7 @@ import type { ToolsType } from './../../common/types/tools';
|
|
|
5
5
|
import React from 'react';
|
|
6
6
|
import './Canvas.css';
|
|
7
7
|
type DrawerType = {
|
|
8
|
-
disabled?: boolean;
|
|
9
8
|
canGrow?: boolean;
|
|
10
|
-
canvasSize: {
|
|
11
|
-
width: number;
|
|
12
|
-
height: number;
|
|
13
|
-
scaleRatio: number;
|
|
14
|
-
};
|
|
15
9
|
selectionColor: string;
|
|
16
10
|
selectionWidth: number;
|
|
17
11
|
settings: UtilsSettings;
|
|
@@ -25,13 +19,19 @@ type DrawerType = {
|
|
|
25
19
|
setSelectionFrame: React.Dispatch<React.SetStateAction<[Point, Point] | undefined>>;
|
|
26
20
|
hoveredShape: ShapeEntity | undefined;
|
|
27
21
|
selectionFrame: [Point, Point] | undefined;
|
|
28
|
-
refreshHoveredShape: (e: MouseEvent | TouchEvent, ctx: CanvasRenderingContext2D, cursorPosition: Point,
|
|
22
|
+
refreshHoveredShape: (e: MouseEvent | TouchEvent, ctx: CanvasRenderingContext2D, cursorPosition: Point, isInsideMask: boolean) => void;
|
|
29
23
|
refreshSelectedShapes: (ctx: CanvasRenderingContext2D, cursorPosition: Point, settings: UtilsSettings) => void;
|
|
30
24
|
activeTool: ToolsType;
|
|
31
25
|
setActiveTool: React.Dispatch<React.SetStateAction<ToolsType>>;
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
26
|
+
canvasOffsetStartData: {
|
|
27
|
+
start: Point;
|
|
28
|
+
originalOffset: Point;
|
|
29
|
+
} | undefined;
|
|
30
|
+
setCanvasOffsetStartData: React.Dispatch<React.SetStateAction<{
|
|
31
|
+
start: Point;
|
|
32
|
+
originalOffset: Point;
|
|
33
|
+
} | undefined>>;
|
|
34
|
+
setCanvasOffset: (offset: Point) => void;
|
|
35
35
|
isInsideComponent: boolean;
|
|
36
36
|
selectionMode: SelectionModeData<number | Point>;
|
|
37
37
|
setSelectionMode: React.Dispatch<React.SetStateAction<SelectionModeData<number | Point>>>;
|
|
@@ -2,7 +2,6 @@ import type { UtilsSettings } from './../../canvas/constants/app';
|
|
|
2
2
|
import type { DrawableShape } from './../../common/types/Shapes';
|
|
3
3
|
import './EditTextBox.css';
|
|
4
4
|
type EditTextBoxType = {
|
|
5
|
-
scaleRatio: number;
|
|
6
5
|
disabled?: boolean;
|
|
7
6
|
shape: DrawableShape<'text'>;
|
|
8
7
|
defaultValue: string[];
|
|
@@ -10,5 +9,5 @@ type EditTextBoxType = {
|
|
|
10
9
|
updateValue: (newValue: string[]) => void;
|
|
11
10
|
saveShapes: () => void;
|
|
12
11
|
};
|
|
13
|
-
declare const EditTextBox: ({ disabled,
|
|
12
|
+
declare const EditTextBox: ({ disabled, shape, defaultValue, updateValue, saveShapes, settings }: EditTextBoxType) => import("react/jsx-runtime").JSX.Element;
|
|
14
13
|
export default EditTextBox;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { Size } from './../../common/types/Canvas';
|
|
2
|
+
import type { ExportedDrawableShape, Point } from './../../common/types/Shapes';
|
|
2
3
|
import type { CustomToolInput } from './../../common/types/tools';
|
|
3
4
|
import type { RecursivePartial } from './../../common/types/utils';
|
|
4
5
|
export declare const APP_NAME = "react_paint";
|
|
@@ -10,12 +11,21 @@ export type UtilsSettings = {
|
|
|
10
11
|
isBrushShapeDoneOnMouseUp: boolean;
|
|
11
12
|
gridGap: number;
|
|
12
13
|
canvasOffset: Point;
|
|
14
|
+
canvasZoom: number;
|
|
13
15
|
canvasSize: {
|
|
16
|
+
realWidth: number;
|
|
17
|
+
realHeight: number;
|
|
14
18
|
width: number;
|
|
15
19
|
height: number;
|
|
16
20
|
scaleRatio: number;
|
|
21
|
+
scaleRatioWithNoZoom: number;
|
|
17
22
|
};
|
|
18
23
|
selectionPadding: number;
|
|
24
|
+
size: 'infinite' | 'fixed';
|
|
25
|
+
features: {
|
|
26
|
+
zoom: boolean;
|
|
27
|
+
edition: boolean;
|
|
28
|
+
};
|
|
19
29
|
};
|
|
20
30
|
type AppOptionsType = {
|
|
21
31
|
layersManipulation: boolean;
|
|
@@ -29,10 +39,12 @@ type AppOptionsType = {
|
|
|
29
39
|
withUrlPicture: boolean;
|
|
30
40
|
withFrameSelection: boolean;
|
|
31
41
|
withSkeleton: boolean;
|
|
32
|
-
clearCallback: 'empty' | 'defaultShapes' | (() =>
|
|
42
|
+
clearCallback: 'empty' | 'defaultShapes' | (() => ExportedDrawableShape[]);
|
|
33
43
|
brushAlgo: BrushAlgo;
|
|
34
44
|
isBrushShapeDoneOnMouseUp: boolean;
|
|
35
45
|
canvasSelectionPadding: number;
|
|
46
|
+
size: Size;
|
|
47
|
+
canZoom: 'never' | 'always';
|
|
36
48
|
};
|
|
37
49
|
export type OptionalOptions = RecursivePartial<AppOptionsType>;
|
|
38
50
|
export declare const DEFAULT_OPTIONS: AppOptionsType;
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
+
import type { UtilsSettings } from './../../canvas/constants/app';
|
|
1
2
|
import { type RefObject } from 'react';
|
|
2
3
|
type UseComponentType = {
|
|
3
|
-
|
|
4
|
-
componentRef: RefObject<HTMLElement>;
|
|
4
|
+
settings: UtilsSettings;
|
|
5
|
+
componentRef: RefObject<HTMLElement | null>;
|
|
5
6
|
};
|
|
6
|
-
declare const useComponent: ({
|
|
7
|
+
declare const useComponent: ({ settings, componentRef }: UseComponentType) => {
|
|
7
8
|
isInsideComponent: boolean;
|
|
8
9
|
};
|
|
9
10
|
export default useComponent;
|
|
@@ -4,7 +4,6 @@ import type { Point, ShapeEntity } from './../../common/types/Shapes';
|
|
|
4
4
|
import type { ToolsType } from './../../common/types/tools';
|
|
5
5
|
import type React from 'react';
|
|
6
6
|
type UseCanvasType = {
|
|
7
|
-
disabled?: boolean;
|
|
8
7
|
shapes: ShapeEntity[];
|
|
9
8
|
saveShapes: () => void;
|
|
10
9
|
addShape: (newShape: ShapeEntity) => void;
|
|
@@ -13,22 +12,27 @@ type UseCanvasType = {
|
|
|
13
12
|
setSelectedShape: React.Dispatch<React.SetStateAction<ShapeEntity | undefined>>;
|
|
14
13
|
activeTool: ToolsType;
|
|
15
14
|
setActiveTool: React.Dispatch<React.SetStateAction<ToolsType>>;
|
|
16
|
-
refreshHoveredShape: (e: MouseEvent | TouchEvent, ctx: CanvasRenderingContext2D, cursorPosition: Point,
|
|
15
|
+
refreshHoveredShape: (e: MouseEvent | TouchEvent, ctx: CanvasRenderingContext2D, cursorPosition: Point, isInsideMask: boolean) => void;
|
|
17
16
|
refreshSelectedShapes: (ctx: CanvasRenderingContext2D, cursorPosition: Point, settings: UtilsSettings) => void;
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
17
|
+
canvasOffsetStartData: {
|
|
18
|
+
start: Point;
|
|
19
|
+
originalOffset: Point;
|
|
20
|
+
} | undefined;
|
|
21
|
+
setCanvasOffsetStartData: React.Dispatch<React.SetStateAction<{
|
|
22
|
+
start: Point;
|
|
23
|
+
originalOffset: Point;
|
|
24
|
+
} | undefined>>;
|
|
25
|
+
setCanvasOffset: (offset: Point) => void;
|
|
21
26
|
isInsideComponent: boolean;
|
|
22
27
|
selectionMode: SelectionModeData<number | Point>;
|
|
23
28
|
setSelectionMode: React.Dispatch<React.SetStateAction<SelectionModeData<number | Point>>>;
|
|
24
29
|
setSelectionFrame: React.Dispatch<React.SetStateAction<[Point, Point] | undefined>>;
|
|
25
|
-
drawCanvasRef: React.
|
|
26
|
-
selectionCanvasRef: React.MutableRefObject<HTMLCanvasElement | null>;
|
|
30
|
+
drawCanvasRef: React.RefObject<HTMLCanvasElement | null>;
|
|
27
31
|
isShiftPressed: boolean;
|
|
28
32
|
withFrameSelection: boolean;
|
|
29
33
|
settings: UtilsSettings;
|
|
30
34
|
};
|
|
31
|
-
declare const useDrawableCanvas: ({
|
|
35
|
+
declare const useDrawableCanvas: ({ addShape, drawCanvasRef, setActiveTool, refreshHoveredShape, shapes, selectionMode, activeTool, isInsideComponent, setCanvasOffset, selectedShape, canvasOffsetStartData, refreshSelectedShapes, setSelectedShape, setSelectionFrame, setCanvasOffsetStartData, updateSingleShape, saveShapes, setSelectionMode, settings, isShiftPressed, withFrameSelection }: UseCanvasType) => {
|
|
32
36
|
hoverMode: HoverModeData;
|
|
33
37
|
};
|
|
34
38
|
export default useDrawableCanvas;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { CanvasSize, Size } from './../../common/types/Canvas';
|
|
2
|
+
import type { Point } from './../../common/types/Shapes';
|
|
3
|
+
type UsePinchZoomProps = {
|
|
4
|
+
canvasElt: HTMLElement | null;
|
|
5
|
+
canvasTransformation: {
|
|
6
|
+
offset: Point;
|
|
7
|
+
zoom: number;
|
|
8
|
+
};
|
|
9
|
+
canvasSize: CanvasSize;
|
|
10
|
+
size: Size;
|
|
11
|
+
setCanvasTransformation: (transformation: {
|
|
12
|
+
offset: Point;
|
|
13
|
+
zoom: number;
|
|
14
|
+
}) => void;
|
|
15
|
+
};
|
|
16
|
+
declare const usePinchZoomAndMove: ({ canvasElt, canvasTransformation, canvasSize, size, setCanvasTransformation }: UsePinchZoomProps) => void;
|
|
17
|
+
export default usePinchZoomAndMove;
|
|
@@ -1,19 +1,34 @@
|
|
|
1
1
|
import { type OptionalOptions, type UtilsSettings } from './../../canvas/constants/app';
|
|
2
|
-
import type {
|
|
2
|
+
import type { CanvasSize } from './../../common/types/Canvas';
|
|
3
|
+
import type { SelectionModeData } from './../../common/types/Mode';
|
|
4
|
+
import type { ExportedDrawableShape, Point, ShapeEntity, StateData } from './../../common/types/Shapes';
|
|
3
5
|
import type { ToolsType } from './../../common/types/tools';
|
|
4
6
|
type UseReactPaintProps = {
|
|
5
7
|
width?: number;
|
|
6
8
|
height?: number;
|
|
7
|
-
shapes?:
|
|
9
|
+
shapes?: ExportedDrawableShape[];
|
|
8
10
|
mode?: 'editor' | 'viewer';
|
|
9
11
|
disabled?: boolean;
|
|
10
12
|
options?: OptionalOptions;
|
|
11
13
|
};
|
|
12
|
-
declare const useReactPaint: ({ width, height, shapes: defaultShapes, mode, disabled, options }
|
|
14
|
+
declare const useReactPaint: ({ width, height, shapes: defaultShapes, mode, disabled, options }?: UseReactPaintProps) => {
|
|
15
|
+
annotationsProps: {
|
|
16
|
+
style: {
|
|
17
|
+
'user-select': string;
|
|
18
|
+
'touch-action': string;
|
|
19
|
+
transformOrigin: string;
|
|
20
|
+
transform: string;
|
|
21
|
+
'--react-paint-canvas-zoom': number;
|
|
22
|
+
'--react-paint-canvas-offset-x': number;
|
|
23
|
+
'--react-paint-canvas-offset-y': number;
|
|
24
|
+
'--react-paint-app-canvaswidth': number;
|
|
25
|
+
'--react-paint-app-canvasheight': number;
|
|
26
|
+
};
|
|
27
|
+
};
|
|
13
28
|
editorProps: {
|
|
14
|
-
shapesRef: import("react").
|
|
29
|
+
shapesRef: import("react").RefObject<ShapeEntity[]>;
|
|
15
30
|
addPictureShape: (fileOrUrl: File | string, maxWidth?: number, maxHeight?: number) => Promise<ShapeEntity<"picture">>;
|
|
16
|
-
moveShapes: (
|
|
31
|
+
moveShapes: (startPositionShapeId: string, endPositionShapeId: string) => void;
|
|
17
32
|
toggleShapeVisibility: (shape: ShapeEntity) => void;
|
|
18
33
|
toggleShapeLock: (shape: ShapeEntity) => void;
|
|
19
34
|
canGoBackward: boolean;
|
|
@@ -25,32 +40,27 @@ declare const useReactPaint: ({ width, height, shapes: defaultShapes, mode, disa
|
|
|
25
40
|
backwardShape: () => void;
|
|
26
41
|
forwardShape: () => void;
|
|
27
42
|
refs: {
|
|
28
|
-
canvas: import("react").RefObject<HTMLCanvasElement>;
|
|
29
|
-
editor: import("react").
|
|
43
|
+
canvas: import("react").RefObject<HTMLCanvasElement | null>;
|
|
44
|
+
editor: import("react").RefObject<HTMLElement | null>;
|
|
30
45
|
setEditor: (node: HTMLElement | null) => void;
|
|
31
46
|
};
|
|
32
47
|
width: number;
|
|
33
48
|
height: number;
|
|
34
|
-
canvasSize: {
|
|
35
|
-
width: number;
|
|
36
|
-
height: number;
|
|
37
|
-
scaleRatio: number;
|
|
38
|
-
};
|
|
39
49
|
selectTool: (tool: ToolsType) => void;
|
|
40
50
|
selectShape: (shape: ShapeEntity) => void;
|
|
41
51
|
activeTool: ToolsType;
|
|
42
52
|
setActiveTool: import("react").Dispatch<import("react").SetStateAction<ToolsType>>;
|
|
43
53
|
setAvailableTools: import("react").Dispatch<import("react").SetStateAction<import("./../../common/types/tools").CustomTool[]>>;
|
|
44
54
|
isEditMode: boolean;
|
|
45
|
-
isDisabled: boolean;
|
|
46
55
|
availableTools: import("./../../common/types/tools").CustomTool[];
|
|
47
56
|
gridGap: number;
|
|
48
57
|
setGridGap: import("react").Dispatch<import("react").SetStateAction<number>>;
|
|
49
58
|
loadFile: (file: File) => Promise<void>;
|
|
50
|
-
exportPicture: () => void;
|
|
59
|
+
exportPicture: (view: "fitToShapes" | "defaultView" | "currentZoom") => void;
|
|
51
60
|
exportData: () => void;
|
|
52
61
|
clearCanvas: () => void;
|
|
53
62
|
settings: UtilsSettings;
|
|
63
|
+
setCanvasZoom: (action: "unzoom" | "zoom" | "default") => void;
|
|
54
64
|
canvas: {
|
|
55
65
|
canGrow: boolean;
|
|
56
66
|
canShrink: boolean;
|
|
@@ -62,7 +72,7 @@ declare const useReactPaint: ({ width, height, shapes: defaultShapes, mode, disa
|
|
|
62
72
|
};
|
|
63
73
|
};
|
|
64
74
|
canvasProps: {
|
|
65
|
-
shapesRef: import("react").
|
|
75
|
+
shapesRef: import("react").RefObject<ShapeEntity[]>;
|
|
66
76
|
selectedShape: ShapeEntity | undefined;
|
|
67
77
|
selectionFrame: [Point, Point] | undefined;
|
|
68
78
|
hoveredShape: ShapeEntity | undefined;
|
|
@@ -70,49 +80,52 @@ declare const useReactPaint: ({ width, height, shapes: defaultShapes, mode, disa
|
|
|
70
80
|
setSelectedShape: import("react").Dispatch<import("react").SetStateAction<ShapeEntity | undefined>>;
|
|
71
81
|
setSelectionFrame: import("react").Dispatch<import("react").SetStateAction<[Point, Point] | undefined>>;
|
|
72
82
|
refreshSelectedShapes: (ctx: CanvasRenderingContext2D, cursorPosition: Point) => void;
|
|
73
|
-
refreshHoveredShape: (e: MouseEvent | TouchEvent, ctx: CanvasRenderingContext2D, cursorPosition: Point) => void;
|
|
83
|
+
refreshHoveredShape: (e: MouseEvent | TouchEvent, ctx: CanvasRenderingContext2D, cursorPosition: Point, isInsideMask: boolean) => void;
|
|
74
84
|
removeShape: (shape: ShapeEntity) => void;
|
|
75
85
|
updateShape: (updatedShape: ShapeEntity, withSave?: boolean) => void;
|
|
76
86
|
backwardShape: () => void;
|
|
77
87
|
forwardShape: () => void;
|
|
78
88
|
saveShapes: () => void;
|
|
79
89
|
refs: {
|
|
80
|
-
canvas: import("react").RefObject<HTMLCanvasElement>;
|
|
81
|
-
editor: import("react").
|
|
90
|
+
canvas: import("react").RefObject<HTMLCanvasElement | null>;
|
|
91
|
+
editor: import("react").RefObject<HTMLElement | null>;
|
|
82
92
|
setEditor: (node: HTMLElement | null) => void;
|
|
83
93
|
};
|
|
84
94
|
width: number;
|
|
85
95
|
height: number;
|
|
86
96
|
settings: UtilsSettings;
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
scaleRatio: number;
|
|
91
|
-
};
|
|
92
|
-
setCanvasSize: import("react").Dispatch<import("react").SetStateAction<{
|
|
93
|
-
width: number;
|
|
94
|
-
height: number;
|
|
95
|
-
scaleRatio: number;
|
|
96
|
-
}>>;
|
|
97
|
-
setCanvasOffset: import("react").Dispatch<import("react").SetStateAction<Point>>;
|
|
97
|
+
setCanvasSize: import("react").Dispatch<import("react").SetStateAction<CanvasSize>>;
|
|
98
|
+
setCanvasOffset: (newOffset: Point) => void;
|
|
99
|
+
setCanvasZoom: (action: "unzoom" | "zoom" | "default") => void;
|
|
98
100
|
selectShape: (shape: ShapeEntity) => void;
|
|
99
101
|
activeTool: ToolsType;
|
|
100
102
|
setActiveTool: import("react").Dispatch<import("react").SetStateAction<ToolsType>>;
|
|
101
103
|
isInsideComponent: boolean;
|
|
102
104
|
isEditMode: boolean;
|
|
103
|
-
isDisabled: boolean;
|
|
104
105
|
canvas: {
|
|
105
106
|
withSkeleton: boolean;
|
|
106
107
|
withFrameSelection: boolean;
|
|
107
108
|
canGrow: boolean;
|
|
108
109
|
canShrink: boolean;
|
|
109
110
|
};
|
|
111
|
+
canvasOffsetStartData: {
|
|
112
|
+
start: Point;
|
|
113
|
+
originalOffset: Point;
|
|
114
|
+
} | undefined;
|
|
115
|
+
setCanvasOffsetStartData: import("react").Dispatch<import("react").SetStateAction<{
|
|
116
|
+
start: Point;
|
|
117
|
+
originalOffset: Point;
|
|
118
|
+
} | undefined>>;
|
|
119
|
+
selectionMode: SelectionModeData<number | Point>;
|
|
120
|
+
setSelectionMode: import("react").Dispatch<import("react").SetStateAction<SelectionModeData<number | Point>>>;
|
|
110
121
|
};
|
|
111
122
|
registerEvent: (event: "dataChanged", fn: (data: StateData, source: "user" | "remote") => void) => void;
|
|
112
123
|
unregisterEvent: (event: "dataChanged", fn?: (data: StateData, source: "user" | "remote") => void) => void;
|
|
113
|
-
resetCanvas: (json?:
|
|
114
|
-
getCurrentImage: () => string
|
|
124
|
+
resetCanvas: (json?: ExportedDrawableShape[], clearHistory?: boolean) => void;
|
|
125
|
+
getCurrentImage: (view: "fitToShapes" | "defaultView" | "currentZoom") => string;
|
|
115
126
|
getCurrentData: () => StateData;
|
|
127
|
+
setCanvasOffset: (newOffset: Point) => void;
|
|
128
|
+
setCanvasZoom: (action: "unzoom" | "zoom" | "default") => void;
|
|
116
129
|
};
|
|
117
130
|
export type UseReactPaintReturnType = ReturnType<typeof useReactPaint>;
|
|
118
131
|
export default useReactPaint;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
type UseResizeObserverType = {
|
|
2
|
-
element: React.RefObject<HTMLElement>;
|
|
2
|
+
element: React.RefObject<HTMLElement | null>;
|
|
3
3
|
onResized: (width: number, height: number) => unknown;
|
|
4
4
|
};
|
|
5
5
|
declare const useResizeObserver: ({ onResized, element }: UseResizeObserverType) => void;
|
|
@@ -3,7 +3,7 @@ import type { Point, ShapeEntity, StateData } from './../../common/types/Shapes'
|
|
|
3
3
|
declare const useShapes: (settings: UtilsSettings, width: number, height: number) => {
|
|
4
4
|
registerEvent: (event: "dataChanged", fn: (data: StateData, source: "user" | "remote") => void) => void;
|
|
5
5
|
unregisterEvent: (event: "dataChanged", fn?: (data: StateData, source: "user" | "remote") => void) => void;
|
|
6
|
-
shapesRef: import("react").
|
|
6
|
+
shapesRef: import("react").RefObject<ShapeEntity[]>;
|
|
7
7
|
selectedShape: ShapeEntity | undefined;
|
|
8
8
|
hoveredShape: ShapeEntity | undefined;
|
|
9
9
|
selectionFrame: [Point, Point] | undefined;
|
|
@@ -11,10 +11,10 @@ declare const useShapes: (settings: UtilsSettings, width: number, height: number
|
|
|
11
11
|
refreshSelectedShapes: (ctx: CanvasRenderingContext2D, cursorPosition: Point) => void;
|
|
12
12
|
addShape: (newShape: ShapeEntity) => void;
|
|
13
13
|
addPictureShape: (fileOrUrl: File | string, maxWidth?: number, maxHeight?: number) => Promise<ShapeEntity<"picture">>;
|
|
14
|
-
moveShapes: (
|
|
14
|
+
moveShapes: (startPositionShapeId: string, endPositionShapeId: string) => void;
|
|
15
15
|
saveShapes: () => void;
|
|
16
16
|
setSelectedShape: import("react").Dispatch<import("react").SetStateAction<ShapeEntity | undefined>>;
|
|
17
|
-
refreshHoveredShape: (e: MouseEvent | TouchEvent, ctx: CanvasRenderingContext2D, cursorPosition: Point) => void;
|
|
17
|
+
refreshHoveredShape: (e: MouseEvent | TouchEvent, ctx: CanvasRenderingContext2D, cursorPosition: Point, isInsideMask: boolean) => void;
|
|
18
18
|
toggleShapeVisibility: (shape: ShapeEntity) => void;
|
|
19
19
|
toggleShapeLock: (shape: ShapeEntity) => void;
|
|
20
20
|
removeShape: (shape: ShapeEntity) => void;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { CanvasSize, Size } from './../../common/types/Canvas';
|
|
2
|
+
import type { Point } from './../../common/types/Shapes';
|
|
3
|
+
type UseZoomProps = {
|
|
4
|
+
canvasSize: CanvasSize;
|
|
5
|
+
size: Size;
|
|
6
|
+
canvasElt: HTMLCanvasElement | null;
|
|
7
|
+
zoomEnabled: boolean;
|
|
8
|
+
};
|
|
9
|
+
declare const useZoom: ({ canvasSize, size, zoomEnabled, canvasElt }: UseZoomProps) => {
|
|
10
|
+
setCanvasTransformation: import("react").Dispatch<import("react").SetStateAction<{
|
|
11
|
+
offset: Point;
|
|
12
|
+
zoom: number;
|
|
13
|
+
}>>;
|
|
14
|
+
setCanvasOffset: (newOffset: Point) => void;
|
|
15
|
+
setCanvasZoom: (action: "unzoom" | "zoom" | "default") => void;
|
|
16
|
+
canvasTransformation: {
|
|
17
|
+
offset: Point;
|
|
18
|
+
zoom: number;
|
|
19
|
+
};
|
|
20
|
+
};
|
|
21
|
+
export default useZoom;
|
|
@@ -1,12 +1,16 @@
|
|
|
1
1
|
import type { UtilsSettings } from './../../canvas/constants/app';
|
|
2
|
-
import type { DrawableShape, ShapeEntity } from './../../common/types/Shapes';
|
|
2
|
+
import type { DrawableShape, ExportedDrawableShape, ShapeEntity } from './../../common/types/Shapes';
|
|
3
3
|
export declare const addSizeAndConvertSvgToObjectUrl: (svgFileContent: string) => string;
|
|
4
4
|
export declare const isSvg: (fileOrUrl: File | string) => boolean;
|
|
5
5
|
export declare const fetchAndStringify: (url: string) => Promise<string>;
|
|
6
6
|
export declare const downloadFile: (content: string, fileName: string) => void;
|
|
7
7
|
export declare const getBase64Image: (img: HTMLImageElement) => string;
|
|
8
8
|
export declare const getStringifiedImage: (shape: DrawableShape<"picture">) => string;
|
|
9
|
-
export declare const getCanvasImage: (shapes
|
|
9
|
+
export declare const getCanvasImage: ({ shapes, settings, view }: {
|
|
10
|
+
shapes: DrawableShape[];
|
|
11
|
+
settings: UtilsSettings;
|
|
12
|
+
view: "fitToShapes" | "defaultView" | "currentZoom";
|
|
13
|
+
}) => string;
|
|
10
14
|
export declare const encodeShapesInString: (shapes: DrawableShape[], width: number, height: number) => string;
|
|
11
15
|
export declare const decodeJson: (file: File) => Promise<unknown>;
|
|
12
|
-
export declare const decodeImportedData: (shapesForJson:
|
|
16
|
+
export declare const decodeImportedData: (shapesForJson: ExportedDrawableShape[], settings: UtilsSettings) => Promise<ShapeEntity[]>;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import type { UtilsSettings } from './../../canvas/constants/app';
|
|
2
|
-
export declare const drawGrid: (ctx: CanvasRenderingContext2D,
|
|
2
|
+
export declare const drawGrid: (ctx: CanvasRenderingContext2D, settings: UtilsSettings) => void;
|
|
@@ -1,10 +1,16 @@
|
|
|
1
1
|
import type { UtilsSettings } from './../../canvas/constants/app';
|
|
2
|
+
import type { CanvasSize } from './../../common/types/Canvas';
|
|
2
3
|
import type { HoverModeData } from './../../common/types/Mode';
|
|
3
4
|
import type { DrawableShape, Point, Rect } from './../../common/types/Shapes';
|
|
4
|
-
export declare const getCursorPosition: (e: MouseEvent | TouchEvent
|
|
5
|
+
export declare const getCursorPosition: (e: MouseEvent | TouchEvent) => {
|
|
6
|
+
clientX: number;
|
|
7
|
+
clientY: number;
|
|
8
|
+
};
|
|
9
|
+
export declare const getCursorPositionInElement: (e: MouseEvent | TouchEvent, element: HTMLElement, canvasSize: CanvasSize) => Point;
|
|
10
|
+
export declare const getCursorPositionInTransformedCanvas: (e: MouseEvent | TouchEvent, canvas: HTMLElement | null, settings: UtilsSettings) => Point;
|
|
5
11
|
export declare const isTouchGesture: (e: MouseEvent | TouchEvent) => e is TouchEvent;
|
|
6
|
-
export declare const getPointPositionAfterCanvasTransformation: (point: Point, shapeRotation: number, [originX, originY]: Point
|
|
7
|
-
export declare const getPointPositionBeforeCanvasTransformation: (point: Point, shapeRotation: number, [originX, originY]: Point
|
|
12
|
+
export declare const getPointPositionAfterCanvasTransformation: (point: Point, shapeRotation: number, [originX, originY]: Point) => Point;
|
|
13
|
+
export declare const getPointPositionBeforeCanvasTransformation: (point: Point, shapeRotation: number, [originX, originY]: Point) => Point;
|
|
8
14
|
export declare const checkSelectionIntersection: (shape: DrawableShape, position: Point, settings: UtilsSettings, checkAnchors?: boolean, radius?: number) => false | HoverModeData;
|
|
9
15
|
export declare const checkPositionIntersection: (ctx: CanvasRenderingContext2D, shape: DrawableShape, position: Point, settings: UtilsSettings) => false | HoverModeData;
|
|
10
16
|
export declare function getRectIntersection(rect1: Rect, rect2: Rect): Rect | undefined;
|
|
@@ -8,6 +8,7 @@ export declare const createShape: (ctx: CanvasRenderingContext2D, shape: Exclude
|
|
|
8
8
|
export declare const drawShape: (ctx: CanvasRenderingContext2D, shape: DrawableShape, settings: UtilsSettings) => void;
|
|
9
9
|
export declare const getShapeInfos: (shape: DrawableShape, settings: UtilsSettings) => {
|
|
10
10
|
borders: Rect;
|
|
11
|
+
outerBorders: Rect;
|
|
11
12
|
center: Point;
|
|
12
13
|
};
|
|
13
14
|
export declare const rotateShape: <T extends DrawableShape>(shape: T, cursorPosition: Point, originalShape: T, originalCursorPosition: Point, shapeCenter: Point, settings: UtilsSettings) => T & {
|
|
@@ -4,7 +4,7 @@ export declare const createRecPath: (rect: Rect) => Path2D;
|
|
|
4
4
|
export declare const createCirclePath: (shape: Circle) => Path2D;
|
|
5
5
|
export declare const createEllipsePath: (ellipse: DrawableShape<"ellipse">) => Path2D;
|
|
6
6
|
export declare const createLinePath: (line: Line) => Path2D;
|
|
7
|
-
export declare const createBrushPath: (brush: DrawableShape<"brush">,
|
|
7
|
+
export declare const createBrushPath: (brush: DrawableShape<"brush">, { brushAlgo }: UtilsSettings) => Path2D | undefined;
|
|
8
8
|
export declare const createCurvePath: (curve: DrawableShape<"curve">) => Path2D | undefined;
|
|
9
9
|
export declare const createPolygonPath: (polygon: DrawableShape<"polygon">) => Path2D | undefined;
|
|
10
10
|
export declare const createTrianglePath: (triangle: DrawableShape<"triangle">) => Path2D;
|
|
@@ -9,4 +9,4 @@ export declare const translatePicture: <U extends DrawableShape<"picture">>(curs
|
|
|
9
9
|
x: number;
|
|
10
10
|
y: number;
|
|
11
11
|
};
|
|
12
|
-
export declare const resizePicture: (cursorPosition: Point, originalShape: DrawableShape<"picture">, selectionMode: SelectionModeResize, settings: UtilsSettings
|
|
12
|
+
export declare const resizePicture: (cursorPosition: Point, originalShape: DrawableShape<"picture">, selectionMode: SelectionModeResize, settings: UtilsSettings) => DrawableShape<"picture">;
|
|
@@ -11,7 +11,7 @@ export declare const createRectangle: <T extends "rect" | "square">(shape: {
|
|
|
11
11
|
}, cursorPosition: Point, settings: UtilsSettings, width?: number, height?: number) => ShapeEntity<T>;
|
|
12
12
|
export declare const drawRect: (ctx: CanvasRenderingContext2D, shape: DrawableShape<"rect" | "square">) => void;
|
|
13
13
|
export declare const getRectBorder: (rect: Rect, settings: UtilsSettings) => Rect;
|
|
14
|
-
export declare const getRectOppositeAnchorAbsolutePosition: <T extends DrawableShape & Rect>(anchor: Point, center: Point, shape: T,
|
|
14
|
+
export declare const getRectOppositeAnchorAbsolutePosition: <T extends DrawableShape & Rect>(anchor: Point, center: Point, shape: T, [negW, negH]?: [boolean, boolean]) => Point;
|
|
15
15
|
export declare const translateRect: <T extends "rect" | "square", U extends DrawableShape<T>>(cursorPosition: Point, originalShape: U, originalCursorPosition: Point, settings: UtilsSettings) => U & {
|
|
16
16
|
x: number;
|
|
17
17
|
y: number;
|
|
@@ -5,7 +5,7 @@ export declare const getNormalizedSize: (originalWidth: number, originalHeight:
|
|
|
5
5
|
export declare const roundValues: (prop: number, precision?: number) => number;
|
|
6
6
|
export declare const scalePoint: (point: Point, minX: number, minY: number, scaleX?: number, scaleY?: number) => Point;
|
|
7
7
|
export declare const roundForGrid: (value: number, settings: UtilsSettings, gridOffset?: number) => number;
|
|
8
|
-
export declare const roundRotationForGrid: (rotation: number, settings: UtilsSettings
|
|
8
|
+
export declare const roundRotationForGrid: (rotation: number, settings: UtilsSettings) => number;
|
|
9
9
|
export declare const transformShape: (ctx: CanvasRenderingContext2D, shape: ShapeEntity, cursorPosition: Point, selectionMode: SelectionModeData<Point | number>, settings: UtilsSettings, isShiftPressed: boolean) => ShapeEntity;
|
|
10
10
|
export declare const fitContentInsideContainer: (contentWidth: number, contentHeight: number, containerWidth: number, containerHeight: number, shouldFillContainer?: boolean) => number[];
|
|
11
11
|
export declare const shortenLine: ({ line, size, direction }: {
|
|
@@ -14,4 +14,6 @@ export declare const getAngleFromVector: ({ targetVector: [point1, point2], radi
|
|
|
14
14
|
radian?: boolean;
|
|
15
15
|
originVector?: Vector;
|
|
16
16
|
}) => number;
|
|
17
|
+
export declare const getDistanceBetweenPoints: (p1: Point, p2: Point) => number;
|
|
18
|
+
export declare const getCenter: (e1: Point, e2: Point) => Point;
|
|
17
19
|
export {};
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import type { UtilsSettings } from './../../canvas/constants/app';
|
|
2
|
+
import type { CanvasSize, Size } from './../../common/types/Canvas';
|
|
3
|
+
import type { Point, Rect } from './../../common/types/Shapes';
|
|
4
|
+
export declare const getNewOffset: ({ size, zoom, newOffset: [x, y], canvasSize }: {
|
|
5
|
+
zoom: number;
|
|
6
|
+
size: Size;
|
|
7
|
+
newOffset: Point;
|
|
8
|
+
canvasSize: CanvasSize;
|
|
9
|
+
}) => {
|
|
10
|
+
zoom: number;
|
|
11
|
+
offset: Point;
|
|
12
|
+
};
|
|
13
|
+
export declare const calculateNewZoomAndOffset: ({ size, canvasSize, currentOffset, currentZoom, zoom, centerPoint: iCenterPoint }: {
|
|
14
|
+
size: Size;
|
|
15
|
+
canvasSize: CanvasSize;
|
|
16
|
+
currentOffset: Point;
|
|
17
|
+
currentZoom: number;
|
|
18
|
+
zoom: number;
|
|
19
|
+
centerPoint: Point;
|
|
20
|
+
}) => {
|
|
21
|
+
offset: Point;
|
|
22
|
+
zoom: number;
|
|
23
|
+
};
|
|
24
|
+
export declare const getNewZoomAndOffset: ({ size, canvasSize, currentOffset, currentZoom, action }: {
|
|
25
|
+
size: Size;
|
|
26
|
+
canvasSize: CanvasSize;
|
|
27
|
+
currentOffset: Point;
|
|
28
|
+
currentZoom: number;
|
|
29
|
+
action: "unzoom" | "zoom" | "default";
|
|
30
|
+
}) => {
|
|
31
|
+
offset: Point;
|
|
32
|
+
zoom: number;
|
|
33
|
+
};
|
|
34
|
+
export declare const getNewZoomAndOffsetFromDelta: ({ size, canvasSize, currentOffset, currentZoom, delta, centerPoint }: {
|
|
35
|
+
size: Size;
|
|
36
|
+
canvasSize: CanvasSize;
|
|
37
|
+
currentOffset: Point;
|
|
38
|
+
currentZoom: number;
|
|
39
|
+
delta: number;
|
|
40
|
+
centerPoint: Point;
|
|
41
|
+
}) => {
|
|
42
|
+
offset: Point;
|
|
43
|
+
zoom: number;
|
|
44
|
+
};
|
|
45
|
+
export declare const getCurrentView: (settings: UtilsSettings) => Rect;
|
|
46
|
+
export declare const getMaskRect: (settings: UtilsSettings) => {
|
|
47
|
+
x: number;
|
|
48
|
+
y: number;
|
|
49
|
+
width: number;
|
|
50
|
+
height: number;
|
|
51
|
+
};
|
|
52
|
+
export declare const clipMask: (ctx: CanvasRenderingContext2D, settings: UtilsSettings) => void;
|
|
53
|
+
export declare const drawMask: (ctx: CanvasRenderingContext2D, settings: UtilsSettings) => void;
|
|
54
|
+
export declare const isCursorInsideMask: (cursorPosition: Point, settings: UtilsSettings) => boolean;
|
|
55
|
+
export declare const normalizeWheel: (event: WheelEvent, lastTimeEvent: number) => {
|
|
56
|
+
deltaX: number;
|
|
57
|
+
deltaY: number;
|
|
58
|
+
};
|
|
@@ -31,6 +31,8 @@ export type SelectionModeTranslate = {
|
|
|
31
31
|
};
|
|
32
32
|
export type SelectionModeData<AnchorType extends Point | number> = SelectionModeDefault | SelectionModeSelectionFrame | SelectionModeBrush | SelectionModeResize<AnchorType> | SelectionModeRotate | SelectionModeTranslate | SelectionModeEditText;
|
|
33
33
|
export type HoverModeData = {
|
|
34
|
+
outOfView?: boolean;
|
|
35
|
+
} & ({
|
|
34
36
|
mode: 'default';
|
|
35
37
|
} | {
|
|
36
38
|
mode: 'selectionFrame';
|
|
@@ -45,4 +47,4 @@ export type HoverModeData = {
|
|
|
45
47
|
mode: 'translate';
|
|
46
48
|
} | {
|
|
47
49
|
mode: 'textedition';
|
|
48
|
-
};
|
|
50
|
+
});
|
|
@@ -115,6 +115,7 @@ export type DrawableShape<T extends ShapeType = ShapeType> = {
|
|
|
115
115
|
scaleX?: number;
|
|
116
116
|
scaleY?: number;
|
|
117
117
|
} : never);
|
|
118
|
+
export type ExportedDrawableShape<T extends ShapeType = ShapeType> = T extends 'picture' ? Omit<DrawableShape<'picture'>, 'img'> : DrawableShape<T>;
|
|
118
119
|
export type ShapeEntity<T extends Exclude<ShapeType, 'triangle'> = Exclude<ShapeType, 'triangle'>> = {
|
|
119
120
|
id: string;
|
|
120
121
|
toolId?: string;
|