@yorab/react-paint 0.17.1 → 0.18.1
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 -0
- package/dist/_chunks/array-DuJem3vg.js +1 -0
- package/dist/_chunks/canvas-DF1RWuxW.js +1 -0
- package/dist/_chunks/editor-DuVskl0R.js +1 -0
- package/dist/canvas/components/Canvas.d.ts +1 -52
- package/dist/canvas/constants/app.d.ts +3 -25
- package/dist/canvas/constants/rendering.d.ts +3 -0
- package/dist/canvas/constants/tools.d.ts +4 -0
- package/dist/canvas/context/CanvasContext.d.ts +55 -0
- package/dist/canvas/hooks/useDrawableCanvas.d.ts +2 -43
- package/dist/canvas/hooks/useEventListener.d.ts +2 -0
- package/dist/canvas/hooks/useReactPaint.d.ts +8 -3
- package/dist/canvas/hooks/useShapes.d.ts +1 -0
- package/dist/canvas/index.d.ts +4 -0
- package/dist/canvas/index.js +1 -0
- package/dist/canvas/utils/canvas.d.ts +2 -1
- package/dist/canvas/utils/intersect.d.ts +4 -0
- package/dist/canvas/utils/selection.d.ts +0 -3
- package/dist/canvas/utils/shapes/index.d.ts +2 -3
- package/dist/canvas/utils/shapes/line.d.ts +2 -2
- package/dist/canvas/utils/shapes/path.d.ts +1 -0
- package/dist/canvas/utils/tools.d.ts +1 -1
- package/dist/canvas/utils/transform.d.ts +0 -1
- package/dist/common/hooks/useDebounce.d.ts +2 -0
- package/dist/common/types/Settings.d.ts +24 -0
- package/dist/common/utils/selection.d.ts +4 -0
- package/dist/editor/components/settings/Layouts.d.ts +1 -1
- package/dist/editor/components/settings/SettingsBar.d.ts +4 -2
- package/dist/editor/components/toolbox/ContextMenu.d.ts +4 -2
- package/dist/editor/components/toolbox/Toolbar.d.ts +1 -1
- package/dist/editor/hooks/useMenu.d.ts +2 -1
- package/dist/editor/index.d.ts +3 -2
- package/dist/editor/index.js +1 -0
- package/dist/editor/utils/style.d.ts +1 -1
- package/dist/index.d.ts +4 -6
- package/dist/react-paint.css +2 -1
- package/dist/react-paint.js +1 -1914
- package/dist/react-paint.umd.cjs +1 -1
- package/dist/src/canvas/components/Canvas.d.ts +4 -0
- package/dist/src/canvas/components/EditTextBox.d.ts +13 -0
- package/dist/src/canvas/constants/app.d.ts +37 -0
- package/dist/src/canvas/constants/grid.d.ts +1 -0
- package/dist/src/canvas/constants/keyboard.d.ts +27 -0
- package/dist/src/canvas/constants/picture.d.ts +1 -0
- package/dist/src/canvas/constants/rendering.d.ts +3 -0
- package/dist/src/canvas/constants/shapes.d.ts +10 -0
- package/dist/src/canvas/constants/tools.d.ts +4 -0
- package/dist/src/canvas/constants/zoom.d.ts +5 -0
- package/dist/src/canvas/context/CanvasContext.d.ts +55 -0
- package/dist/src/canvas/hooks/useComponent.d.ts +12 -0
- package/dist/src/canvas/hooks/useDoubleClick.d.ts +5 -0
- package/dist/src/canvas/hooks/useDrawableCanvas.d.ts +6 -0
- package/dist/src/canvas/hooks/useEventListener.d.ts +2 -0
- package/dist/src/canvas/hooks/useKeyboard.d.ts +33 -0
- package/dist/src/canvas/hooks/usePinchZoomAndMove.d.ts +17 -0
- package/dist/src/canvas/hooks/useReactPaint.d.ts +164 -0
- package/dist/src/canvas/hooks/useResizeObserver.d.ts +6 -0
- package/dist/src/canvas/hooks/useShapes.d.ts +44 -0
- package/dist/src/canvas/hooks/useZoom.d.ts +22 -0
- package/dist/src/canvas/index.d.ts +19 -0
- package/dist/src/canvas/utils/canvas.d.ts +15 -0
- package/dist/src/canvas/utils/data.d.ts +5 -0
- package/dist/src/canvas/utils/file.d.ts +274 -0
- package/dist/src/canvas/utils/grid.d.ts +2 -0
- package/dist/src/canvas/utils/intersect.d.ts +27 -0
- package/dist/src/canvas/utils/selection/groupSelection.d.ts +4 -0
- package/dist/src/canvas/utils/selection/lineSelection.d.ts +19 -0
- package/dist/src/canvas/utils/selection/rectSelection.d.ts +20 -0
- package/dist/src/canvas/utils/selection/selectionFrame.d.ts +3 -0
- package/dist/src/canvas/utils/selection.d.ts +12 -0
- package/dist/src/canvas/utils/shapes/brush.d.ts +21 -0
- package/dist/src/canvas/utils/shapes/circle.d.ts +18 -0
- package/dist/src/canvas/utils/shapes/curve.d.ts +17 -0
- package/dist/src/canvas/utils/shapes/ellipse.d.ts +18 -0
- package/dist/src/canvas/utils/shapes/group.d.ts +33 -0
- package/dist/src/canvas/utils/shapes/index.d.ts +35 -0
- package/dist/src/canvas/utils/shapes/line.d.ts +19 -0
- package/dist/src/canvas/utils/shapes/path.d.ts +29 -0
- package/dist/src/canvas/utils/shapes/picture.d.ts +13 -0
- package/dist/src/canvas/utils/shapes/polygon.d.ts +18 -0
- package/dist/src/canvas/utils/shapes/rectangle.d.ts +22 -0
- package/dist/src/canvas/utils/shapes/text.d.ts +27 -0
- package/dist/src/canvas/utils/shapes/triangle.d.ts +4 -0
- package/dist/src/canvas/utils/transform.d.ts +15 -0
- package/dist/src/canvas/utils/trigo.d.ts +19 -0
- package/dist/src/canvas/utils/zoom.d.ts +58 -0
- package/dist/src/common/hooks/useDebounce.d.ts +2 -0
- package/dist/src/common/types/Canvas.d.ts +8 -0
- package/dist/src/common/types/Mode.d.ts +64 -0
- package/dist/src/common/types/Settings.d.ts +24 -0
- package/dist/src/common/types/Shapes.d.ts +153 -0
- package/dist/src/common/types/react.d.ts +6 -0
- package/dist/src/common/types/tools.d.ts +164 -0
- package/dist/src/common/types/utils.d.ts +4 -0
- package/dist/src/common/utils/array.d.ts +2 -0
- package/dist/src/common/utils/dom.d.ts +1 -0
- package/dist/src/common/utils/object.d.ts +4 -0
- package/dist/src/common/utils/selection.d.ts +4 -0
- package/dist/src/common/utils/util.d.ts +3 -0
- package/dist/src/editor/components/common/Button.d.ts +16 -0
- package/dist/src/editor/components/common/FileInput.d.ts +13 -0
- package/dist/src/editor/components/common/Loading.d.ts +6 -0
- package/dist/src/editor/components/common/Menu.d.ts +10 -0
- package/dist/src/editor/components/common/Modal.d.ts +11 -0
- package/dist/src/editor/components/common/Panel.d.ts +15 -0
- package/dist/src/editor/components/common/Snackbar.d.ts +7 -0
- package/dist/src/editor/components/settings/ClosedPointsField.d.ts +10 -0
- package/dist/src/editor/components/settings/ColorField.d.ts +15 -0
- package/dist/src/editor/components/settings/DeleteButton.d.ts +8 -0
- package/dist/src/editor/components/settings/FontFamilyField.d.ts +12 -0
- package/dist/src/editor/components/settings/LayoutButton.d.ts +7 -0
- package/dist/src/editor/components/settings/Layouts.d.ts +19 -0
- package/dist/src/editor/components/settings/LineArrowField.d.ts +12 -0
- package/dist/src/editor/components/settings/LineTypeField.d.ts +16 -0
- package/dist/src/editor/components/settings/RangeField.d.ts +19 -0
- package/dist/src/editor/components/settings/SelectField.d.ts +18 -0
- package/dist/src/editor/components/settings/SettingsBar.d.ts +26 -0
- package/dist/src/editor/components/settings/ToggleField.d.ts +13 -0
- package/dist/src/editor/components/settings/ZoomButton.d.ts +8 -0
- package/dist/src/editor/components/toolbox/ContextMenu.d.ts +25 -0
- package/dist/src/editor/components/toolbox/ExportModal.d.ts +7 -0
- package/dist/src/editor/components/toolbox/LoadFileTool.d.ts +11 -0
- package/dist/src/editor/components/toolbox/MenuGroup.d.ts +27 -0
- package/dist/src/editor/components/toolbox/PictureUrlInput.d.ts +7 -0
- package/dist/src/editor/components/toolbox/Tool.d.ts +11 -0
- package/dist/src/editor/components/toolbox/Toolbar.d.ts +26 -0
- package/dist/src/editor/components/toolbox/ToolbarGroup.d.ts +14 -0
- package/dist/src/editor/constants/grid.d.ts +7 -0
- package/dist/src/editor/constants/icons.d.ts +43 -0
- package/dist/src/editor/constants/loading.d.ts +1 -0
- package/dist/src/editor/constants/options.d.ts +13 -0
- package/dist/src/editor/constants/snackbar.d.ts +7 -0
- package/dist/src/editor/constants/style.d.ts +14 -0
- package/dist/src/editor/constants/tools.d.ts +32 -0
- package/dist/src/editor/hooks/useDrag.d.ts +15 -0
- package/dist/src/editor/hooks/useMenu.d.ts +11 -0
- package/dist/src/editor/hooks/useSnackbar.d.ts +10 -0
- package/dist/src/editor/index.d.ts +25 -0
- package/dist/src/editor/types/snackbar.d.ts +7 -0
- package/dist/src/editor/utils/style.d.ts +2 -0
- package/dist/src/editor/utils/toolbar.d.ts +11 -0
- package/dist/src/index.d.ts +5 -0
- package/package.json +42 -24
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { UtilsSettings } from './../../../canvas/constants/app';
|
|
2
|
+
import type { ShapeEntity } from './../../../common/types/Shapes';
|
|
3
|
+
import './EditTextBox.css';
|
|
4
|
+
type EditTextBoxType = {
|
|
5
|
+
disabled?: boolean;
|
|
6
|
+
shape: ShapeEntity<'text'>;
|
|
7
|
+
defaultValue: string[];
|
|
8
|
+
settings: UtilsSettings;
|
|
9
|
+
updateValue: (newValue: string[]) => void;
|
|
10
|
+
saveShapes: () => void;
|
|
11
|
+
};
|
|
12
|
+
declare const EditTextBox: ({ disabled, shape, defaultValue, updateValue, saveShapes, settings }: EditTextBoxType) => import("react/jsx-runtime").JSX.Element;
|
|
13
|
+
export default EditTextBox;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { Size } from './../../../common/types/Canvas';
|
|
2
|
+
import type { ExportedDrawableShape } from './../../../common/types/Shapes';
|
|
3
|
+
import type { CustomToolInput } from './../../../common/types/tools';
|
|
4
|
+
import type { RecursivePartial } from './../../../common/types/utils';
|
|
5
|
+
export declare const APP_NAME = "react_paint";
|
|
6
|
+
export declare const DRAWCANVAS_CLASSNAME = "react-paint-canvas-drawcanvas";
|
|
7
|
+
export declare const SELECTIONCANVAS_CLASSNAME = "react-paint-canvas-selectioncanvas";
|
|
8
|
+
import type { BrushAlgo } from './../../../common/types/Settings';
|
|
9
|
+
export type { BrushAlgo, UtilsSettings } from './../../../common/types/Settings';
|
|
10
|
+
type AppOptionsType = {
|
|
11
|
+
layersManipulation: boolean;
|
|
12
|
+
grid: number;
|
|
13
|
+
canGrow: boolean;
|
|
14
|
+
canShrink: boolean;
|
|
15
|
+
availableTools: CustomToolInput[];
|
|
16
|
+
withExport: boolean;
|
|
17
|
+
withLoadAndSave: boolean;
|
|
18
|
+
withUploadPicture: boolean;
|
|
19
|
+
withUrlPicture: boolean;
|
|
20
|
+
withFrameSelection: boolean;
|
|
21
|
+
withSkeleton: boolean;
|
|
22
|
+
withContextMenu: boolean;
|
|
23
|
+
clearCallback: 'empty' | 'defaultShapes' | (() => ExportedDrawableShape[]);
|
|
24
|
+
brushAlgo: BrushAlgo;
|
|
25
|
+
isBrushShapeDoneOnMouseUp: boolean;
|
|
26
|
+
canvasSelectionPadding: number;
|
|
27
|
+
size: Size;
|
|
28
|
+
canZoom: 'never' | 'always';
|
|
29
|
+
debug: boolean;
|
|
30
|
+
};
|
|
31
|
+
export type OptionalOptions = RecursivePartial<AppOptionsType>;
|
|
32
|
+
export declare const DEFAULT_OPTIONS: AppOptionsType;
|
|
33
|
+
export declare const DEFAULT_CANVAS_OPTIONS: {
|
|
34
|
+
canvasBackgroundColor: string;
|
|
35
|
+
canvasSelectionColor: string;
|
|
36
|
+
canvasSelectionWidth: number;
|
|
37
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const GRID_ROTATION_STEPS = 18;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
export declare const KeyboardCode: {
|
|
2
|
+
readonly ArrowUp: "ArrowUp";
|
|
3
|
+
readonly ArrowDown: "ArrowDown";
|
|
4
|
+
readonly ArrowLeft: "ArrowLeft";
|
|
5
|
+
readonly ArrowRight: "ArrowRight";
|
|
6
|
+
readonly Delete: "Delete";
|
|
7
|
+
readonly Backspace: "Backspace";
|
|
8
|
+
readonly Escape: "Escape";
|
|
9
|
+
readonly Shift: "Shift";
|
|
10
|
+
readonly Alt: "Alt";
|
|
11
|
+
readonly Option: "Option";
|
|
12
|
+
readonly Space: " ";
|
|
13
|
+
readonly A: "A";
|
|
14
|
+
readonly a: "a";
|
|
15
|
+
readonly z: "z";
|
|
16
|
+
readonly Z: "Z";
|
|
17
|
+
readonly y: "y";
|
|
18
|
+
readonly Y: "Y";
|
|
19
|
+
readonly Plus: "+";
|
|
20
|
+
readonly Minus: "-";
|
|
21
|
+
readonly Zero: "0";
|
|
22
|
+
};
|
|
23
|
+
export declare const KeyboardCommand: {
|
|
24
|
+
readonly Cut: "cut";
|
|
25
|
+
readonly Copy: "copy";
|
|
26
|
+
readonly Paste: "paste";
|
|
27
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const PICTURE_DEFAULT_SIZE = 300;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { Point } from './../../../common/types/Shapes';
|
|
2
|
+
export declare const SELECTION_DEFAULT_PADDING = 0;
|
|
3
|
+
export declare const SELECTION_DEFAULT_WIDTH = 2;
|
|
4
|
+
export declare const SELECTION_DEFAULT_COLOR = "blue";
|
|
5
|
+
export declare const SELECTION_ANCHOR_SIZE = 14;
|
|
6
|
+
export declare const SELECTION_ROTATED_ANCHOR_POSITION = 16;
|
|
7
|
+
export declare const SELECTION_RESIZE_ANCHOR_POSITIONS: Point[];
|
|
8
|
+
export declare const ShapeTypeArray: readonly ["brush", "rect", "square", "line", "polygon", "circle", "curve", "ellipse", "picture", "text", "triangle", "group"];
|
|
9
|
+
export declare const SHAPES_WITH_ROTATION: string[];
|
|
10
|
+
export declare const SHAPES_KEEPING_RATIO: string[];
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import type { UtilsSettings } from './../../../canvas/constants/app';
|
|
2
|
+
import type { SelectionModeData } from './../../../common/types/Mode';
|
|
3
|
+
import type { Point, SelectionType, ShapeEntity } from './../../../common/types/Shapes';
|
|
4
|
+
import type { ToolsType } from './../../../common/types/tools';
|
|
5
|
+
import type React from 'react';
|
|
6
|
+
export type CanvasContextType = {
|
|
7
|
+
shapes: ShapeEntity[];
|
|
8
|
+
settings: UtilsSettings;
|
|
9
|
+
selectedShape: SelectionType | undefined;
|
|
10
|
+
hoveredShape: ShapeEntity | undefined;
|
|
11
|
+
selectionFrame: {
|
|
12
|
+
oldSelection: SelectionType | undefined;
|
|
13
|
+
frame: [Point, Point];
|
|
14
|
+
} | undefined;
|
|
15
|
+
selectionMode: SelectionModeData<number | Point>;
|
|
16
|
+
activeTool: ToolsType;
|
|
17
|
+
canvasOffsetStartData: {
|
|
18
|
+
start: Point;
|
|
19
|
+
originalOffset: Point;
|
|
20
|
+
} | undefined;
|
|
21
|
+
isInsideComponent: boolean;
|
|
22
|
+
isInsideCanvas: boolean;
|
|
23
|
+
isShiftPressed: boolean;
|
|
24
|
+
isAltPressed: boolean;
|
|
25
|
+
isSpacePressed: boolean;
|
|
26
|
+
selectionColor: string;
|
|
27
|
+
selectionWidth: number;
|
|
28
|
+
isEditMode: boolean;
|
|
29
|
+
canGrow: boolean | undefined;
|
|
30
|
+
withFrameSelection: boolean;
|
|
31
|
+
withSkeleton: boolean;
|
|
32
|
+
withContextMenu: boolean;
|
|
33
|
+
setSelectedShape: React.Dispatch<React.SetStateAction<SelectionType | undefined>>;
|
|
34
|
+
setSelectionFrame: React.Dispatch<React.SetStateAction<{
|
|
35
|
+
oldSelection: SelectionType | undefined;
|
|
36
|
+
frame: [Point, Point];
|
|
37
|
+
} | undefined>>;
|
|
38
|
+
setSelectionMode: React.Dispatch<React.SetStateAction<SelectionModeData<number | Point>>>;
|
|
39
|
+
setActiveTool: React.Dispatch<React.SetStateAction<ToolsType>>;
|
|
40
|
+
setCanvasOffsetStartData: React.Dispatch<React.SetStateAction<{
|
|
41
|
+
start: Point;
|
|
42
|
+
originalOffset: Point;
|
|
43
|
+
} | undefined>>;
|
|
44
|
+
setCanvasOffset: (offset: Point) => void;
|
|
45
|
+
setCanvasMoveAcceleration: React.Dispatch<React.SetStateAction<Point>>;
|
|
46
|
+
addShapes: (newShapes: ShapeEntity[]) => void;
|
|
47
|
+
updateSingleShape: (updatedShape: ShapeEntity[], withSave?: boolean) => void;
|
|
48
|
+
duplicateShapes: (shapesToDuplicate: ShapeEntity[]) => void;
|
|
49
|
+
saveShapes: () => void;
|
|
50
|
+
refreshHoveredShape: (e: MouseEvent | TouchEvent, ctx: CanvasRenderingContext2D, cursorPosition: Point, isInsideMask: boolean) => void;
|
|
51
|
+
refreshSelectedShapes: (ctx: CanvasRenderingContext2D, cursorPosition: Point, settings: UtilsSettings) => void;
|
|
52
|
+
};
|
|
53
|
+
declare const CanvasContext: React.Context<CanvasContextType | undefined>;
|
|
54
|
+
export declare const useCanvasContext: () => CanvasContextType;
|
|
55
|
+
export default CanvasContext;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { UtilsSettings } from './../../../canvas/constants/app';
|
|
2
|
+
import { type RefObject } from 'react';
|
|
3
|
+
type UseComponentType = {
|
|
4
|
+
settings: UtilsSettings;
|
|
5
|
+
componentRef: RefObject<HTMLElement | null>;
|
|
6
|
+
canvasRef: RefObject<HTMLCanvasElement | null>;
|
|
7
|
+
};
|
|
8
|
+
declare const useComponent: ({ settings, componentRef, canvasRef }: UseComponentType) => {
|
|
9
|
+
isInsideComponent: boolean;
|
|
10
|
+
isInsideCanvas: boolean;
|
|
11
|
+
};
|
|
12
|
+
export default useComponent;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { UtilsSettings } from './../../../canvas/constants/app';
|
|
2
|
+
import type { SelectionModeData } from './../../../common/types/Mode';
|
|
3
|
+
import type { Point, SelectionType, ShapeEntity } from './../../../common/types/Shapes';
|
|
4
|
+
import type { ToolsType } from './../../../common/types/tools';
|
|
5
|
+
type UseKeyboardType = {
|
|
6
|
+
isInsideComponent: boolean;
|
|
7
|
+
isInsideCanvas: boolean;
|
|
8
|
+
selectedShape: SelectionType | undefined;
|
|
9
|
+
pasteShapes: (shape: ShapeEntity[]) => void;
|
|
10
|
+
updateShapes: (shapes: ShapeEntity[]) => void;
|
|
11
|
+
setSelectedShape: (value: React.SetStateAction<SelectionType | undefined>) => void;
|
|
12
|
+
selectAllShapes: () => void;
|
|
13
|
+
removeShape: (shape: ShapeEntity[]) => void;
|
|
14
|
+
backwardShape: () => void;
|
|
15
|
+
forwardShape: () => void;
|
|
16
|
+
setShiftPressed: (value: React.SetStateAction<boolean>) => void;
|
|
17
|
+
setAltPressed: (value: React.SetStateAction<boolean>) => void;
|
|
18
|
+
setIsSpacePressed: (value: React.SetStateAction<boolean>) => void;
|
|
19
|
+
isEditingText: boolean;
|
|
20
|
+
setActiveTool: (tool: ToolsType) => void;
|
|
21
|
+
setSelectionMode: (mode: SelectionModeData<number | Point>) => void;
|
|
22
|
+
setSelectionFrame: (args: {
|
|
23
|
+
oldSelection: SelectionType | undefined;
|
|
24
|
+
frame: [Point, Point];
|
|
25
|
+
} | undefined) => void;
|
|
26
|
+
settings: UtilsSettings;
|
|
27
|
+
setCanvasZoom: (action: 'unzoom' | 'zoom' | 'default') => void;
|
|
28
|
+
resetZoom: () => void;
|
|
29
|
+
copiedShape: SelectionType | undefined;
|
|
30
|
+
setCopiedShape: (shape: React.SetStateAction<SelectionType | undefined>) => void;
|
|
31
|
+
};
|
|
32
|
+
declare const useKeyboard: ({ isInsideComponent, isInsideCanvas, selectedShape, isEditingText, settings, copiedShape, setCopiedShape, setSelectedShape, setActiveTool, setCanvasZoom, resetZoom, setSelectionMode, setSelectionFrame, selectAllShapes, removeShape, pasteShapes, updateShapes, backwardShape, forwardShape, setShiftPressed, setAltPressed, setIsSpacePressed }: UseKeyboardType) => {};
|
|
33
|
+
export default useKeyboard;
|
|
@@ -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;
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
import { type OptionalOptions, type UtilsSettings } from './../../../canvas/constants/app';
|
|
2
|
+
import { calculateTextFontSize } from './../../../canvas/utils/shapes/text';
|
|
3
|
+
import type { CanvasSize } from './../../../common/types/Canvas';
|
|
4
|
+
import type { SelectionModeData } from './../../../common/types/Mode';
|
|
5
|
+
import type { ExportedDrawableShape, Point, SelectionType, ShapeEntity, StateData } from './../../../common/types/Shapes';
|
|
6
|
+
import type { CustomTool, ToolsType } from './../../../common/types/tools';
|
|
7
|
+
import { type CSSProperties } from 'react';
|
|
8
|
+
type UseReactPaintProps = {
|
|
9
|
+
width?: number | undefined;
|
|
10
|
+
height?: number | undefined;
|
|
11
|
+
shapes?: ExportedDrawableShape[] | undefined;
|
|
12
|
+
mode?: 'editor' | 'viewer' | undefined;
|
|
13
|
+
disabled?: boolean | undefined;
|
|
14
|
+
options?: OptionalOptions | undefined;
|
|
15
|
+
};
|
|
16
|
+
export type EditorProps = {
|
|
17
|
+
shapes: ShapeEntity[];
|
|
18
|
+
addPictureShape: (fileOrUrl: File | string, maxWidth?: number, maxHeight?: number) => Promise<ShapeEntity>;
|
|
19
|
+
swapShapes: (startPositionShapeId: string, endPositionShapeId: string) => void;
|
|
20
|
+
moveShapes: (shapes: ShapeEntity[], action: 'first' | 'last' | 'forward' | 'backward') => void;
|
|
21
|
+
toggleShapeVisibility: (shapes: ShapeEntity[]) => void;
|
|
22
|
+
toggleShapeLock: (shapeGroup: ShapeEntity[]) => void;
|
|
23
|
+
canGoBackward: boolean;
|
|
24
|
+
canGoForward: boolean;
|
|
25
|
+
canClear: boolean;
|
|
26
|
+
selectedShape: SelectionType | undefined;
|
|
27
|
+
copiedShape: SelectionType | undefined;
|
|
28
|
+
setCopiedShape: React.Dispatch<React.SetStateAction<SelectionType | undefined>>;
|
|
29
|
+
pasteShapes: (shapes: ShapeEntity[]) => void;
|
|
30
|
+
saveShapes: () => void;
|
|
31
|
+
removeShape: (shapes: ShapeEntity[]) => void;
|
|
32
|
+
updateShape: (updatedShapes: ShapeEntity[], withSave?: boolean) => void;
|
|
33
|
+
duplicateShapes: (shapesToDuplicate: ShapeEntity[], translate?: boolean, selectNewOnes?: boolean) => void;
|
|
34
|
+
backwardShape: () => void;
|
|
35
|
+
forwardShape: () => void;
|
|
36
|
+
removeShapePoint: (shape: ShapeEntity<'curve' | 'polygon'>, pointIndex: number) => void;
|
|
37
|
+
transformShape: (ctx: CanvasRenderingContext2D, shapes: ShapeEntity[], center: Point, action: 'flipHorizontally' | 'flipVertically' | 'rotateClockwise' | 'rotateCounterclockwise') => void;
|
|
38
|
+
refs: {
|
|
39
|
+
canvas: React.RefObject<HTMLCanvasElement | null>;
|
|
40
|
+
editor: React.RefObject<HTMLElement | null>;
|
|
41
|
+
setEditor: (node: HTMLElement | null) => void;
|
|
42
|
+
};
|
|
43
|
+
width: number;
|
|
44
|
+
height: number;
|
|
45
|
+
selectTool: (tool: ToolsType) => void;
|
|
46
|
+
selectShapes: (shapes: ShapeEntity[]) => void;
|
|
47
|
+
selectAllShapes: () => void;
|
|
48
|
+
activeTool: ToolsType;
|
|
49
|
+
setActiveTool: React.Dispatch<React.SetStateAction<ToolsType>>;
|
|
50
|
+
setAvailableTools: React.Dispatch<React.SetStateAction<CustomTool[]>>;
|
|
51
|
+
isEditMode: boolean;
|
|
52
|
+
availableTools: CustomTool[];
|
|
53
|
+
gridGap: number;
|
|
54
|
+
setGridGap: React.Dispatch<React.SetStateAction<number>>;
|
|
55
|
+
loadFile: (file: File) => Promise<void>;
|
|
56
|
+
exportPicture: (view: 'fitToShapes' | 'defaultView' | 'currentZoom') => void;
|
|
57
|
+
exportData: () => void;
|
|
58
|
+
clearCanvas: () => void;
|
|
59
|
+
selectionMode: SelectionModeData<number | Point>;
|
|
60
|
+
setSelectionMode: React.Dispatch<React.SetStateAction<SelectionModeData<number | Point>>>;
|
|
61
|
+
settings: UtilsSettings;
|
|
62
|
+
setCanvasZoom: (action: 'unzoom' | 'zoom' | 'default') => void;
|
|
63
|
+
resetZoom: () => void;
|
|
64
|
+
buildShapesGroup: (shapes: ShapeEntity[]) => SelectionType | undefined;
|
|
65
|
+
copyShapes: (selection: SelectionType) => ShapeEntity[];
|
|
66
|
+
refreshShape: (shape: ShapeEntity) => ShapeEntity;
|
|
67
|
+
calculateTextFontSize: typeof calculateTextFontSize;
|
|
68
|
+
canvas: {
|
|
69
|
+
canGrow: boolean;
|
|
70
|
+
canShrink: boolean;
|
|
71
|
+
layersManipulation: boolean;
|
|
72
|
+
withExport: boolean;
|
|
73
|
+
withLoadAndSave: boolean;
|
|
74
|
+
withUploadPicture: boolean;
|
|
75
|
+
withUrlPicture: boolean;
|
|
76
|
+
withContextMenu: boolean;
|
|
77
|
+
};
|
|
78
|
+
};
|
|
79
|
+
type CanvasProps = {
|
|
80
|
+
shapes: ShapeEntity[];
|
|
81
|
+
selectedShape: SelectionType | undefined;
|
|
82
|
+
copiedShape: SelectionType | undefined;
|
|
83
|
+
setCopiedShape: React.Dispatch<React.SetStateAction<SelectionType | undefined>>;
|
|
84
|
+
pasteShapes: (shapes: ShapeEntity[]) => void;
|
|
85
|
+
selectionFrame: {
|
|
86
|
+
oldSelection: SelectionType | undefined;
|
|
87
|
+
frame: [Point, Point];
|
|
88
|
+
} | undefined;
|
|
89
|
+
hoveredShape: ShapeEntity | undefined;
|
|
90
|
+
addShape: (newShapes: ShapeEntity[]) => void;
|
|
91
|
+
setSelectedShape: React.Dispatch<React.SetStateAction<SelectionType | undefined>>;
|
|
92
|
+
setSelectionFrame: React.Dispatch<React.SetStateAction<{
|
|
93
|
+
oldSelection: SelectionType | undefined;
|
|
94
|
+
frame: [Point, Point];
|
|
95
|
+
} | undefined>>;
|
|
96
|
+
refreshSelectedShapes: (ctx: CanvasRenderingContext2D, cursorPosition: Point) => void;
|
|
97
|
+
refreshHoveredShape: (e: MouseEvent | TouchEvent, ctx: CanvasRenderingContext2D, cursorPosition: Point, isInsideMask: boolean) => void;
|
|
98
|
+
removeShape: (shapes: ShapeEntity[]) => void;
|
|
99
|
+
updateShape: (updatedShapes: ShapeEntity[], withSave?: boolean) => void;
|
|
100
|
+
duplicateShapes: (shapesToDuplicate: ShapeEntity[], translate?: boolean, selectNewOnes?: boolean) => void;
|
|
101
|
+
backwardShape: () => void;
|
|
102
|
+
forwardShape: () => void;
|
|
103
|
+
saveShapes: () => void;
|
|
104
|
+
refs: {
|
|
105
|
+
canvas: React.RefObject<HTMLCanvasElement | null>;
|
|
106
|
+
editor: React.RefObject<HTMLElement | null>;
|
|
107
|
+
setEditor: (node: HTMLElement | null) => void;
|
|
108
|
+
};
|
|
109
|
+
width: number;
|
|
110
|
+
height: number;
|
|
111
|
+
selectShapes: (shapes: ShapeEntity[]) => void;
|
|
112
|
+
selectAllShapes: () => void;
|
|
113
|
+
activeTool: ToolsType;
|
|
114
|
+
setActiveTool: React.Dispatch<React.SetStateAction<ToolsType>>;
|
|
115
|
+
isEditMode: boolean;
|
|
116
|
+
settings: UtilsSettings;
|
|
117
|
+
setCanvasZoom: (action: 'unzoom' | 'zoom' | 'default') => void;
|
|
118
|
+
resetZoom: () => void;
|
|
119
|
+
setCanvasSize: React.Dispatch<React.SetStateAction<CanvasSize>>;
|
|
120
|
+
setCanvasOffset: (offset: Point) => void;
|
|
121
|
+
isInsideComponent: boolean;
|
|
122
|
+
isInsideCanvas: boolean;
|
|
123
|
+
canvas: {
|
|
124
|
+
withContextMenu: boolean;
|
|
125
|
+
withSkeleton: boolean;
|
|
126
|
+
withFrameSelection: boolean;
|
|
127
|
+
canGrow: boolean;
|
|
128
|
+
canShrink: boolean;
|
|
129
|
+
};
|
|
130
|
+
canvasOffsetStartData: {
|
|
131
|
+
start: Point;
|
|
132
|
+
originalOffset: Point;
|
|
133
|
+
} | undefined;
|
|
134
|
+
setCanvasOffsetStartData: React.Dispatch<React.SetStateAction<{
|
|
135
|
+
start: Point;
|
|
136
|
+
originalOffset: Point;
|
|
137
|
+
} | undefined>>;
|
|
138
|
+
selectionMode: SelectionModeData<number | Point>;
|
|
139
|
+
setSelectionMode: React.Dispatch<React.SetStateAction<SelectionModeData<number | Point>>>;
|
|
140
|
+
setCanvasMoveAcceleration: React.Dispatch<React.SetStateAction<Point>>;
|
|
141
|
+
isShiftPressed: boolean;
|
|
142
|
+
isAltPressed: boolean;
|
|
143
|
+
isSpacePressed: boolean;
|
|
144
|
+
setShiftPressed: React.Dispatch<React.SetStateAction<boolean>>;
|
|
145
|
+
setAltPressed: React.Dispatch<React.SetStateAction<boolean>>;
|
|
146
|
+
setIsSpacePressed: React.Dispatch<React.SetStateAction<boolean>>;
|
|
147
|
+
};
|
|
148
|
+
export type UseReactPaintReturnType = {
|
|
149
|
+
annotationsProps: {
|
|
150
|
+
style: CSSProperties;
|
|
151
|
+
};
|
|
152
|
+
editorProps: EditorProps;
|
|
153
|
+
canvasProps: CanvasProps;
|
|
154
|
+
registerEvent: (event: 'dataChanged', fn: (data: StateData, source: 'user' | 'remote') => void) => void;
|
|
155
|
+
unregisterEvent: (event: 'dataChanged', fn?: (data: StateData, source: 'user' | 'remote') => void) => void;
|
|
156
|
+
resetCanvas: (json?: ExportedDrawableShape[], clearHistory?: boolean) => void;
|
|
157
|
+
resetZoom: () => void;
|
|
158
|
+
getCurrentImage: (view: 'fitToShapes' | 'defaultView' | 'currentZoom') => string;
|
|
159
|
+
getCurrentData: () => StateData;
|
|
160
|
+
setCanvasOffset: (offset: Point) => void;
|
|
161
|
+
setCanvasZoom: (action: 'unzoom' | 'zoom' | 'default') => void;
|
|
162
|
+
};
|
|
163
|
+
declare const useReactPaint: ({ width, height, shapes: defaultShapes, mode, disabled, options }?: UseReactPaintProps) => UseReactPaintReturnType;
|
|
164
|
+
export default useReactPaint;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { type UtilsSettings } from './../../../canvas/constants/app';
|
|
2
|
+
import type { Point, SelectionType, ShapeEntity, StateData } from './../../../common/types/Shapes';
|
|
3
|
+
declare const useShapes: (settings: UtilsSettings, width: number, height: number, isShiftPressed: boolean) => {
|
|
4
|
+
registerEvent: (event: "dataChanged", fn: (data: StateData, source: "user" | "remote") => void) => void;
|
|
5
|
+
unregisterEvent: (event: "dataChanged", fn?: (data: StateData, source: "user" | "remote") => void) => void;
|
|
6
|
+
shapes: ShapeEntity[];
|
|
7
|
+
shapesRef: React.RefObject<ShapeEntity[]>;
|
|
8
|
+
selectedShape: SelectionType | undefined;
|
|
9
|
+
hoveredShape: ShapeEntity | undefined;
|
|
10
|
+
selectionFrame: {
|
|
11
|
+
oldSelection: SelectionType | undefined;
|
|
12
|
+
frame: [Point, Point];
|
|
13
|
+
} | undefined;
|
|
14
|
+
setSelectionFrame: React.Dispatch<React.SetStateAction<{
|
|
15
|
+
oldSelection: SelectionType | undefined;
|
|
16
|
+
frame: [Point, Point];
|
|
17
|
+
} | undefined>>;
|
|
18
|
+
refreshSelectedShapes: (ctx: CanvasRenderingContext2D, cursorPosition: Point) => void;
|
|
19
|
+
addShapes: (newShapes: ShapeEntity[]) => void;
|
|
20
|
+
duplicateShapes: (shapesToDuplicate: ShapeEntity[], translate?: boolean, selectNewOnes?: boolean) => void;
|
|
21
|
+
addPictureShape: (fileOrUrl: File | string, maxWidth?: number, maxHeight?: number) => Promise<ShapeEntity>;
|
|
22
|
+
swapShapes: (startPositionShapeId: string, endPositionShapeId: string) => void;
|
|
23
|
+
moveShapes: (shapes: ShapeEntity[], action: "first" | "last" | "forward" | "backward") => void;
|
|
24
|
+
saveShapes: () => void;
|
|
25
|
+
setSelectedShape: React.Dispatch<React.SetStateAction<SelectionType | undefined>>;
|
|
26
|
+
refreshHoveredShape: (e: MouseEvent | TouchEvent, ctx: CanvasRenderingContext2D, cursorPosition: Point, isInsideMask: boolean) => void;
|
|
27
|
+
toggleShapeVisibility: (shapes: ShapeEntity[]) => void;
|
|
28
|
+
toggleShapeLock: (shapeGroup: ShapeEntity[]) => void;
|
|
29
|
+
removeShape: (shapes: ShapeEntity[]) => void;
|
|
30
|
+
updateShape: (updatedShapes: ShapeEntity[], withSave?: boolean) => void;
|
|
31
|
+
transformShape: (ctx: CanvasRenderingContext2D, shapes: ShapeEntity[], center: Point, action: "flipHorizontally" | "flipVertically" | "rotateClockwise" | "rotateCounterclockwise") => void;
|
|
32
|
+
backwardShape: () => void;
|
|
33
|
+
forwardShape: () => void;
|
|
34
|
+
clearShapes: (shapesToInit: ShapeEntity[], options: {
|
|
35
|
+
clearHistory: boolean;
|
|
36
|
+
source: "user" | "remote";
|
|
37
|
+
}) => void;
|
|
38
|
+
canGoBackward: boolean;
|
|
39
|
+
canGoForward: boolean;
|
|
40
|
+
canClear: boolean;
|
|
41
|
+
copiedShape: SelectionType | undefined;
|
|
42
|
+
setCopiedShape: React.Dispatch<React.SetStateAction<SelectionType | undefined>>;
|
|
43
|
+
};
|
|
44
|
+
export default useShapes;
|
|
@@ -0,0 +1,22 @@
|
|
|
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
|
+
resetZoom: () => void;
|
|
17
|
+
canvasTransformation: {
|
|
18
|
+
offset: Point;
|
|
19
|
+
zoom: number;
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
export default useZoom;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { UseReactPaintReturnType } from './../../canvas/hooks/useReactPaint';
|
|
2
|
+
import { type CSSProperties } from 'react';
|
|
3
|
+
import './index.css';
|
|
4
|
+
type AppProps = {
|
|
5
|
+
canvasProps: UseReactPaintReturnType['canvasProps'];
|
|
6
|
+
className?: string;
|
|
7
|
+
style?: CSSProperties;
|
|
8
|
+
options?: {
|
|
9
|
+
canvasBackgroundColor?: string | undefined;
|
|
10
|
+
canvasSelectionColor?: string | undefined;
|
|
11
|
+
canvasSelectionWidth?: number | undefined;
|
|
12
|
+
};
|
|
13
|
+
};
|
|
14
|
+
declare const App: ({ options, className, style, canvasProps }: AppProps) => import("react/jsx-runtime").JSX.Element;
|
|
15
|
+
export default App;
|
|
16
|
+
export type { OptionalOptions } from './../../canvas/constants/app';
|
|
17
|
+
export { DEFAULT_OPTIONS } from './../../canvas/constants/app';
|
|
18
|
+
export { default as useReactPaint } from './../../canvas/hooks/useReactPaint';
|
|
19
|
+
export type { ExportedDrawableShape as DrawableShape, StateData } from './../../common/types/Shapes';
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { UtilsSettings } from './../../../canvas/constants/app';
|
|
2
|
+
import type { Point, StyleShape } from './../../../common/types/Shapes';
|
|
3
|
+
export declare const initCanvasContext: (ctx: CanvasRenderingContext2D) => void;
|
|
4
|
+
export declare const updateCanvasContext: (ctx: CanvasRenderingContext2D, style?: {
|
|
5
|
+
fillColor?: string;
|
|
6
|
+
opacity?: number;
|
|
7
|
+
strokeColor?: string;
|
|
8
|
+
lineWidth?: number;
|
|
9
|
+
lineDash?: number;
|
|
10
|
+
lineCap?: CanvasLineCap;
|
|
11
|
+
shadowColor?: string;
|
|
12
|
+
shadowBlur?: number;
|
|
13
|
+
}) => void;
|
|
14
|
+
export declare const transformCanvas: (ctx: CanvasRenderingContext2D, settings: UtilsSettings, rotation?: number, translation?: Point) => void;
|
|
15
|
+
export declare const drawPathWithFillAndStroke: (ctx: CanvasRenderingContext2D, path: Path2D, style?: Pick<StyleShape, "fillColor" | "strokeColor">) => void;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { UtilsSettings } from './../../../canvas/constants/app';
|
|
2
|
+
import type { DrawableShape, ShapeEntity, StateData } from './../../../common/types/Shapes';
|
|
3
|
+
export declare const cleanShapesBeforeExport: (shapes: ShapeEntity[]) => DrawableShape[];
|
|
4
|
+
export declare const buildDataToExport: (shapes: ShapeEntity[], width: number, height: number) => StateData;
|
|
5
|
+
export declare const addDefaultAndTempShapeProps: (shape: DrawableShape, settings: UtilsSettings) => ShapeEntity;
|