@yorab/react-paint 0.10.1 → 0.11.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.
Files changed (96) hide show
  1. package/README.md +173 -1
  2. package/dist/{components → canvas/components}/Canvas.d.ts +4 -4
  3. package/dist/{components/toolbox → canvas/components}/EditTextBox.d.ts +3 -4
  4. package/dist/canvas/constants/app.d.ts +44 -0
  5. package/dist/canvas/constants/grid.d.ts +1 -0
  6. package/dist/{constants → canvas/constants}/shapes.d.ts +1 -1
  7. package/dist/{hooks → canvas/hooks}/useComponent.d.ts +1 -1
  8. package/dist/{hooks → canvas/hooks}/useDrawableCanvas.d.ts +5 -5
  9. package/dist/{hooks → canvas/hooks}/useKeyboard.d.ts +2 -2
  10. package/dist/canvas/hooks/useReactPaint.d.ts +131 -0
  11. package/dist/{hooks → canvas/hooks}/useShapes.d.ts +5 -3
  12. package/dist/canvas/index.d.ts +13 -0
  13. package/dist/{utils → canvas/utils}/canvas.d.ts +2 -2
  14. package/dist/{utils → canvas/utils}/data.d.ts +4 -4
  15. package/dist/{utils → canvas/utils}/file.d.ts +3 -3
  16. package/dist/{utils → canvas/utils}/grid.d.ts +1 -1
  17. package/dist/{utils → canvas/utils}/intersect.d.ts +3 -3
  18. package/dist/{utils → canvas/utils}/selection/lineSelection.d.ts +2 -2
  19. package/dist/{utils → canvas/utils}/selection/rectSelection.d.ts +3 -3
  20. package/dist/canvas/utils/selection/selectionFrame.d.ts +3 -0
  21. package/dist/{utils → canvas/utils}/selection.d.ts +3 -3
  22. package/dist/{utils → canvas/utils}/shapes/brush.d.ts +4 -4
  23. package/dist/{utils → canvas/utils}/shapes/circle.d.ts +4 -4
  24. package/dist/{utils → canvas/utils}/shapes/curve.d.ts +5 -5
  25. package/dist/{utils → canvas/utils}/shapes/ellipse.d.ts +4 -4
  26. package/dist/{utils → canvas/utils}/shapes/index.d.ts +5 -5
  27. package/dist/{utils → canvas/utils}/shapes/line.d.ts +4 -4
  28. package/dist/{utils → canvas/utils}/shapes/path.d.ts +2 -2
  29. package/dist/{utils → canvas/utils}/shapes/picture.d.ts +3 -3
  30. package/dist/{utils → canvas/utils}/shapes/polygon.d.ts +4 -4
  31. package/dist/{utils → canvas/utils}/shapes/rectangle.d.ts +4 -4
  32. package/dist/{utils → canvas/utils}/shapes/text.d.ts +4 -4
  33. package/dist/{utils → canvas/utils}/shapes/triangle.d.ts +1 -1
  34. package/dist/{utils → canvas/utils}/string.d.ts +0 -1
  35. package/dist/canvas/utils/tools.d.ts +3 -0
  36. package/dist/{utils → canvas/utils}/transform.d.ts +3 -3
  37. package/dist/{utils → canvas/utils}/trigo.d.ts +4 -4
  38. package/dist/{types → common/types}/Shapes.d.ts +4 -4
  39. package/dist/common/utils/array.d.ts +1 -0
  40. package/dist/editor/components/common/Loading.d.ts +6 -0
  41. package/dist/{components → editor/components}/common/Modal.d.ts +2 -2
  42. package/dist/{components → editor/components}/common/Panel.d.ts +2 -2
  43. package/dist/{components → editor/components}/common/Snackbar.d.ts +2 -3
  44. package/dist/{components → editor/components}/settings/ColorField.d.ts +2 -2
  45. package/dist/{components → editor/components}/settings/DeleteButton.d.ts +2 -3
  46. package/dist/{components → editor/components}/settings/FontFamilyField.d.ts +2 -2
  47. package/dist/{components → editor/components}/settings/LayoutButton.d.ts +1 -2
  48. package/dist/{components → editor/components}/settings/Layouts.d.ts +5 -6
  49. package/dist/{components → editor/components}/settings/LineArrowField.d.ts +2 -2
  50. package/dist/{components → editor/components}/settings/LineTypeField.d.ts +3 -3
  51. package/dist/{components → editor/components}/settings/PointsNumberField.d.ts +2 -2
  52. package/dist/{components → editor/components}/settings/RangeField.d.ts +2 -2
  53. package/dist/{components → editor/components}/settings/SelectField.d.ts +2 -2
  54. package/dist/{components → editor/components}/settings/SettingsBar.d.ts +4 -5
  55. package/dist/{components → editor/components}/settings/ToggleField.d.ts +2 -2
  56. package/dist/{components → editor/components}/toolbox/LoadFileTool.d.ts +2 -3
  57. package/dist/{components → editor/components}/toolbox/MenuGroup.d.ts +3 -4
  58. package/dist/{components → editor/components}/toolbox/PictureUrlInput.d.ts +1 -2
  59. package/dist/{components → editor/components}/toolbox/Tool.d.ts +2 -3
  60. package/dist/{components → editor/components}/toolbox/Toolbar.d.ts +3 -4
  61. package/dist/{components → editor/components}/toolbox/ToolbarGroup.d.ts +2 -3
  62. package/dist/editor/constants/grid.d.ts +7 -0
  63. package/dist/editor/constants/options.d.ts +13 -0
  64. package/dist/{constants → editor/constants}/snackbar.d.ts +1 -1
  65. package/dist/{constants → editor/constants}/style.d.ts +0 -3
  66. package/dist/{constants → editor/constants}/tools.d.ts +1 -1
  67. package/dist/{hooks → editor/hooks}/useDrag.d.ts +2 -2
  68. package/dist/{hooks → editor/hooks}/useSnackbar.d.ts +3 -3
  69. package/dist/editor/index.d.ts +24 -0
  70. package/dist/{utils → editor/utils}/style.d.ts +1 -1
  71. package/dist/editor/utils/toolbar.d.ts +11 -0
  72. package/dist/index.d.ts +6 -0
  73. package/dist/react-paint.css +1 -1
  74. package/dist/react-paint.js +943 -916
  75. package/dist/react-paint.umd.cjs +1 -1
  76. package/package.json +61 -56
  77. package/dist/components/App.d.ts +0 -20
  78. package/dist/components/common/Loading.d.ts +0 -7
  79. package/dist/constants/app.d.ts +0 -58
  80. package/dist/utils/array.d.ts +0 -1
  81. package/dist/utils/selection/selectionFrame.d.ts +0 -3
  82. package/dist/utils/toolbar.d.ts +0 -13
  83. /package/dist/{constants → canvas/constants}/picture.d.ts +0 -0
  84. /package/dist/{hooks → canvas/hooks}/useDoubleClick.d.ts +0 -0
  85. /package/dist/{hooks → canvas/hooks}/useResizeObserver.d.ts +0 -0
  86. /package/dist/{types → common/types}/Mode.d.ts +0 -0
  87. /package/dist/{types → common/types}/react.d.ts +0 -0
  88. /package/dist/{types → common/types}/tools.d.ts +0 -0
  89. /package/dist/{types → common/types}/utils.d.ts +0 -0
  90. /package/dist/{utils → common/utils}/dom.d.ts +0 -0
  91. /package/dist/{utils → common/utils}/object.d.ts +0 -0
  92. /package/dist/{utils → common/utils}/util.d.ts +0 -0
  93. /package/dist/{components → editor/components}/common/Button.d.ts +0 -0
  94. /package/dist/{constants → editor/constants}/icons.d.ts +0 -0
  95. /package/dist/{constants → editor/constants}/loading.d.ts +0 -0
  96. /package/dist/{types → editor/types}/snackbar.d.ts +0 -0
package/README.md CHANGED
@@ -1 +1,173 @@
1
- # React Paint V0.10.1
1
+ # React Paint V0.11.0
2
+
3
+ An open-source canvas-based library for React used for image annotation or as a digital whiteboard
4
+
5
+ ## Features
6
+
7
+
8
+ ## Quick start
9
+
10
+ ```bash
11
+ npm i @yorab/react-paint
12
+ ```
13
+ Note : react-paint needs <a href="https://www.npmjs.com/package/react">react</a> and <a href="https://www.npmjs.com/package/react-dom">react-dom</a> packages to work properly
14
+
15
+ ## Usage
16
+
17
+ ### Basic usage
18
+
19
+ ```tsx
20
+ import { Canvas, Editor, useReactPaint } from '@yorab/react-paint'
21
+
22
+ const BasicUsage = () => {
23
+ const { editorProps, canvasProps } = useReactPaint()
24
+
25
+ return (
26
+ <Editor editorProps={editorProps}>
27
+ <Canvas canvasProps={canvasProps} />
28
+ </Editor>
29
+ )
30
+ }
31
+ ```
32
+
33
+ ### Advanced usage
34
+
35
+ ```tsx
36
+ import { useEffect, useState } from 'react'
37
+ import { Canvas, Editor, useReactPaint, type DrawableShape, type StateData } from '@yorab/react-paint'
38
+
39
+ const SHAPES_INIT = [
40
+ {
41
+ type: 'rect',
42
+ x: 300,
43
+ y: 300,
44
+ width: 100,
45
+ height: 200,
46
+ rotation: 0,
47
+ style: {
48
+ fillColor: '#6a4e01',
49
+ strokeColor: 'transparent',
50
+ opacity: 100,
51
+ lineWidth: 1,
52
+ lineDash: 0,
53
+ lineArrow: 0,
54
+ pointsCount: 3,
55
+ fontFamily: 'serif'
56
+ }
57
+ }
58
+ ]
59
+
60
+ const AdvancedUsage = () => {
61
+ const [shapes, setShapes] = useState<DrawableShape[] | undefined>(SHAPES_INIT) // keep shapes state for internal use
62
+
63
+ const { editorProps, canvasProps, registerEvent, unregisterEvent } = useReactPaint({
64
+ width: 1920,
65
+ height: 1080,
66
+ shapes,
67
+ options: {
68
+ canGrow: true,
69
+ canShrink: true,
70
+ brushAlgo: 'quadratic',
71
+ clearCallback: 'defaultShapes'
72
+ }
73
+ })
74
+
75
+ const editorOptions = {
76
+ fontColor: '#2c1e69',
77
+ fontHoverColor: '#0d0931'
78
+ }
79
+
80
+ const canvasOptions = {
81
+ canvasBackgroundColor: '#ffffff'
82
+ }
83
+
84
+ useEffect(() => {
85
+ const onDataChanged = (data: StateData) => {
86
+ setShapes(data.shapes)
87
+ }
88
+ registerEvent('dataChanged', onDataChanged)
89
+
90
+ return () => {
91
+ unregisterEvent('dataChanged', onDataChanged)
92
+ }
93
+ }, [registerEvent, unregisterEvent])
94
+
95
+ return (
96
+ <Editor editorProps={editorProps} options={editorOptions}>
97
+ <Canvas canvasProps={canvasProps} options={canvasOptions} />
98
+ </Editor>
99
+ )
100
+ }
101
+ ```
102
+
103
+ ### Other usages
104
+
105
+ you will find other usages in <a href="https://github.com/YoRab/react-paint-editor/tree/main/stories">stories</a>
106
+
107
+ ### API
108
+
109
+ #### `useReactPaint`
110
+
111
+ ##### Parameters
112
+
113
+ | Parameter | Type | Description | Default value |
114
+ | :--- | :--- | :--- | :--- |
115
+ | `width` | `number` | *Optional*. Canvas width in px | `1000` |
116
+ | `height` | `number` | *Optional*. Canvas height in px | `600` |
117
+ | `shapes` | [`DrawableShape[]`](####drawableshape) | *Optional*. Array of shapes used to init the canvas | `undefined` |
118
+ | `mode` | `editor\|viewer` | *Optional*. `editor` lets you interact with the canvas and editor. `viewer` hides the editor and makes the canvas read-only| `editor` |
119
+ | `disabled` | `boolean` | *Optional*. Global parameter used to prevent interaction with every element in the editor or canvas | `false` |
120
+ | `options` | [`OptionalOptions`](####optionaloptions) | *Optional*. Set of options to customize available features | See [`OptionalOptions`]((####optionaloptions)) |
121
+
122
+
123
+ ##### Returns
124
+
125
+ | Parameter | Type | Description |
126
+ | :--- | :--- | :--- |
127
+ | `canvasProps` | `object` | Set of properties to forward to Canvas component |
128
+ | `editorProps` | `object` | Set of properties to forward to Editor component |
129
+ | `registerEvent` | `(event: "dataChanged", listener: (data: StateData) => void) => void` | registerEvent is used to register a listener for special events triggered by react-paint. The only currently available event is `dataChanged` |
130
+ | `unregisterEvent` | `(event: "dataChanged", listener?: ((data: StateData) => 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
+ | `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 \| undefined` | Returns a data URL containing the content of the current canvas as a PNG image, or undefined if an error occured |
133
+ | `getCurrentData` | `() => StateData` | Returns the current state of the canvas |
134
+
135
+ #### Canvas
136
+
137
+ ##### Parameters
138
+
139
+ | Parameter | Type | Description | Default value |
140
+ | :--- | :--- | :--- | :--- |
141
+ | `canvasProps` | `object` | **Required**. Set of properties coming from useReactPaint | |
142
+ | `className` | `string` | *Optional*. Classname for canvas parent node | `undefined` |
143
+ | `style` | `CSSProperties` | *Optional*. css properties to inject to canvas parent node | `undefined` |
144
+ | `options` | `{canvasBackgroundColor?: string}` | *Optional*. Set of properties to use to customize canvas style | `{canvasBackgroundColor: 'white'}` |
145
+
146
+
147
+ #### Editor
148
+
149
+ ##### Parameters
150
+
151
+ | Parameter | Type | Description | Default value |
152
+ | :--- | :--- | :--- | :--- |
153
+ | `editorProps` | `object` | **Required**. Set of properties coming from useReactPaint | |
154
+ | `children` | `ReactNode` | **Required**. Need Canvas component to work properly | |
155
+ | `className` | `string` | *Optional*. Classname for canvas parent node | `undefined` |
156
+ | `style` | `CSSProperties` | *Optional*. css properties to inject to canvas parent node | `undefined` |
157
+ | `options` | `{ toolbarBackgroundColor?: string; dividerColor?: string; fontRadius?: number; fontDisabledColor?: string; fontDisabledBackgroundColor?: string; fontColor?: string; fontBackgroundColor?: string; fontSelectedColor?: string; fontSelectedBackgroundColor?: string; fontHoverColor?: string; fontHoverBackgroundColor?: string; }` | *Optional*. Set of properties to use to customize editor style | ` { toolbarBackgroundColor: 'white', dividerColor: '#36418129', fontRadius: 8, fontDisabledColor: '#3641812b', fontDisabledBackgroundColor: 'transparent', fontColor: '#364181', fontBackgroundColor: 'transparent', fontSelectedColor: 'white', fontSelectedBackgroundColor: '#364181', fontHoverColor: '#364181', fontHoverBackgroundColor: '#afd8d8'}` |
158
+
159
+ ### Types
160
+
161
+ #### `DrawableShape`
162
+ #### `StateData`
163
+ #### `OptionalOptions`
164
+
165
+
166
+ ## Changelog
167
+ https://github.com/YoRab/react-paint-editor/blob/main/Changelog.md
168
+
169
+ ## License
170
+ <a href="https://github.com/YoRab/react-paint-editor/blob/main/LICENSE.txt">MIT</a>
171
+
172
+
173
+ ## Contributing
@@ -1,8 +1,8 @@
1
+ import { type UtilsSettings } from './../../canvas/constants/app';
2
+ import type { SelectionModeData } from './../../common/types/Mode';
3
+ import type { Point, ShapeEntity } from './../../common/types/Shapes';
4
+ import type { ToolsType } from './../../common/types/tools';
1
5
  import React from 'react';
2
- import { UtilsSettings } from '../constants/app';
3
- import type { SelectionModeData } from '../types/Mode';
4
- import type { Point, ShapeEntity } from '../types/Shapes';
5
- import type { ToolsType } from '../types/tools';
6
6
  import './Canvas.css';
7
7
  type DrawerType = {
8
8
  disabled?: boolean;
@@ -1,7 +1,6 @@
1
- import React from 'react';
2
- import type { DrawableShape } from '../../types/Shapes';
1
+ import type { UtilsSettings } from './../../canvas/constants/app';
2
+ import type { DrawableShape } from './../../common/types/Shapes';
3
3
  import './EditTextBox.css';
4
- import { UtilsSettings } from 'src/constants/app';
5
4
  type EditTextBoxType = {
6
5
  scaleRatio: number;
7
6
  disabled?: boolean;
@@ -11,5 +10,5 @@ type EditTextBoxType = {
11
10
  updateValue: (newValue: string[]) => void;
12
11
  saveShapes: () => void;
13
12
  };
14
- declare const EditTextBox: ({ disabled, scaleRatio, shape, defaultValue, updateValue, saveShapes, settings }: EditTextBoxType) => React.JSX.Element;
13
+ declare const EditTextBox: ({ disabled, scaleRatio, shape, defaultValue, updateValue, saveShapes, settings }: EditTextBoxType) => import("react/jsx-runtime").JSX.Element;
15
14
  export default EditTextBox;
@@ -0,0 +1,44 @@
1
+ import type { DrawableShape, Point } from './../../common/types/Shapes';
2
+ import type { CustomToolInput } from './../../common/types/tools';
3
+ import type { RecursivePartial } from './../../common/types/utils';
4
+ export declare const APP_NAME = "react_paint";
5
+ export declare const DRAWCANVAS_CLASSNAME = "react-paint-canvas-drawcanvas";
6
+ export declare const SELECTIONCANVAS_CLASSNAME = "react-paint-canvas-selectioncanvas";
7
+ export type BrushAlgo = 'simple' | 'quadratic';
8
+ export type UtilsSettings = {
9
+ brushAlgo: BrushAlgo;
10
+ gridGap: number;
11
+ canvasOffset: Point;
12
+ canvasSize: {
13
+ width: number;
14
+ height: number;
15
+ scaleRatio: number;
16
+ };
17
+ selectionPadding: number;
18
+ };
19
+ type AppOptionsType = {
20
+ layersManipulation: boolean;
21
+ grid: number;
22
+ canGrow: boolean;
23
+ canShrink: boolean;
24
+ availableTools: CustomToolInput[];
25
+ withExport: boolean;
26
+ withLoadAndSave: boolean;
27
+ withUploadPicture: boolean;
28
+ withUrlPicture: boolean;
29
+ withFrameSelection: boolean;
30
+ withSkeleton: boolean;
31
+ clearCallback: 'empty' | 'defaultShapes' | (() => DrawableShape[]);
32
+ brushAlgo: BrushAlgo;
33
+ selection: {
34
+ canvasSelectionColor: string;
35
+ canvasSelectionWidth: number;
36
+ canvasSelectionPadding: number;
37
+ };
38
+ };
39
+ export type OptionalOptions = RecursivePartial<AppOptionsType>;
40
+ export declare const DEFAULT_OPTIONS: AppOptionsType;
41
+ export declare const DEFAULT_CANVAS_OPTIONS: {
42
+ canvasBackgroundColor: string;
43
+ };
44
+ export {};
@@ -0,0 +1 @@
1
+ export declare const GRID_ROTATION_STEPS = 18;
@@ -1,4 +1,4 @@
1
- import type { Point } from '../types/Shapes';
1
+ import type { Point } from './../../common/types/Shapes';
2
2
  export declare const SELECTION_DEFAULT_PADDING = 0;
3
3
  export declare const SELECTION_DEFAULT_WIDTH = 2;
4
4
  export declare const SELECTION_DEFAULT_COLOR = "blue";
@@ -1,4 +1,4 @@
1
- import { RefObject } from 'react';
1
+ import { type RefObject } from 'react';
2
2
  type UseComponentType = {
3
3
  disabled: boolean;
4
4
  componentRef: RefObject<HTMLElement>;
@@ -1,8 +1,8 @@
1
- import React from 'react';
2
- import type { UtilsSettings } from '../constants/app';
3
- import type { HoverModeData, SelectionModeData } from '../types/Mode';
4
- import type { Point, ShapeEntity } from '../types/Shapes';
5
- import type { ToolsType } from '../types/tools';
1
+ import type { UtilsSettings } from './../../canvas/constants/app';
2
+ import type { HoverModeData, SelectionModeData } from './../../common/types/Mode';
3
+ import type { Point, ShapeEntity } from './../../common/types/Shapes';
4
+ import type { ToolsType } from './../../common/types/tools';
5
+ import type React from 'react';
6
6
  type UseCanvasType = {
7
7
  disabled?: boolean;
8
8
  shapes: ShapeEntity[];
@@ -1,6 +1,6 @@
1
1
  /// <reference types="react" />
2
- import type { UtilsSettings } from '../constants/app';
3
- import type { ShapeEntity } from '../types/Shapes';
2
+ import type { UtilsSettings } from './../../canvas/constants/app';
3
+ import type { ShapeEntity } from './../../common/types/Shapes';
4
4
  type UseKeyboardType = {
5
5
  isInsideComponent: boolean;
6
6
  selectedShape: ShapeEntity | undefined;
@@ -0,0 +1,131 @@
1
+ /// <reference types="react" />
2
+ import { type OptionalOptions, type UtilsSettings } from './../../canvas/constants/app';
3
+ import type { DrawableShape, StateData, Point, ShapeEntity } from './../../common/types/Shapes';
4
+ import type { ToolsType } from './../../common/types/tools';
5
+ type UseReactPaintProps = {
6
+ width?: number;
7
+ height?: number;
8
+ shapes?: DrawableShape[];
9
+ mode?: 'editor' | 'viewer';
10
+ disabled?: boolean;
11
+ options?: OptionalOptions;
12
+ };
13
+ declare const useReactPaint: ({ width, height, shapes: shapesFromProps, mode, disabled, options }: UseReactPaintProps) => {
14
+ editorProps: {
15
+ shapesRef: import("react").MutableRefObject<ShapeEntity[]>;
16
+ addPictureShape: (fileOrUrl: string | File, maxWidth?: number, maxHeight?: number) => Promise<ShapeEntity<"picture">>;
17
+ moveShapes: (firstShapeId: string, lastShapeId: string) => void;
18
+ toggleShapeVisibility: (shape: ShapeEntity) => void;
19
+ toggleShapeLock: (shape: ShapeEntity) => void;
20
+ canGoBackward: boolean;
21
+ canGoForward: boolean;
22
+ canClear: boolean;
23
+ selectedShape: ShapeEntity | undefined;
24
+ removeShape: (shape: ShapeEntity) => void;
25
+ updateShape: (updatedShape: ShapeEntity, withSave?: boolean) => void;
26
+ backwardShape: () => void;
27
+ forwardShape: () => void;
28
+ refs: {
29
+ canvas: import("react").RefObject<HTMLCanvasElement>;
30
+ editor: import("react").MutableRefObject<HTMLElement | null>;
31
+ setEditor: (node: HTMLElement | null) => void;
32
+ };
33
+ width: number;
34
+ height: number;
35
+ canvasSize: {
36
+ width: number;
37
+ height: number;
38
+ scaleRatio: number;
39
+ };
40
+ selectTool: (tool: ToolsType) => void;
41
+ selectShape: (shape: ShapeEntity) => void;
42
+ activeTool: ToolsType;
43
+ setActiveTool: import("react").Dispatch<import("react").SetStateAction<ToolsType>>;
44
+ setAvailableTools: import("react").Dispatch<import("react").SetStateAction<import("./../../common/types/tools").CustomTool[]>>;
45
+ isEditMode: boolean;
46
+ isDisabled: boolean;
47
+ availableTools: import("./../../common/types/tools").CustomTool[];
48
+ gridGap: number;
49
+ setGridGap: import("react").Dispatch<import("react").SetStateAction<number>>;
50
+ loadFile: (file: File) => Promise<void>;
51
+ exportPicture: () => void;
52
+ exportData: () => void;
53
+ clearCanvas: () => void;
54
+ settings: UtilsSettings;
55
+ canvas: {
56
+ selection: {
57
+ canvasSelectionColor: string;
58
+ canvasSelectionWidth: number;
59
+ canvasSelectionPadding: number;
60
+ };
61
+ withSkeleton: boolean;
62
+ withFrameSelection: boolean;
63
+ canGrow: boolean;
64
+ canShrink: boolean;
65
+ layersManipulation: boolean;
66
+ withExport: boolean;
67
+ withLoadAndSave: boolean;
68
+ withUploadPicture: boolean;
69
+ withUrlPicture: boolean;
70
+ clearCallback: "empty" | "defaultShapes" | (() => DrawableShape[]);
71
+ };
72
+ };
73
+ canvasProps: {
74
+ shapesRef: import("react").MutableRefObject<ShapeEntity[]>;
75
+ selectedShape: ShapeEntity | undefined;
76
+ selectionFrame: [Point, Point] | undefined;
77
+ hoveredShape: ShapeEntity | undefined;
78
+ addShape: (newShape: ShapeEntity) => void;
79
+ setSelectedShape: import("react").Dispatch<import("react").SetStateAction<ShapeEntity | undefined>>;
80
+ setSelectionFrame: import("react").Dispatch<import("react").SetStateAction<[Point, Point] | undefined>>;
81
+ refreshSelectedShapes: (ctx: CanvasRenderingContext2D, cursorPosition: Point) => void;
82
+ refreshHoveredShape: (e: MouseEvent | TouchEvent, ctx: CanvasRenderingContext2D, cursorPosition: Point) => void;
83
+ removeShape: (shape: ShapeEntity) => void;
84
+ updateShape: (updatedShape: ShapeEntity, withSave?: boolean) => void;
85
+ backwardShape: () => void;
86
+ forwardShape: () => void;
87
+ saveShapes: () => void;
88
+ refs: {
89
+ canvas: import("react").RefObject<HTMLCanvasElement>;
90
+ editor: import("react").MutableRefObject<HTMLElement | null>;
91
+ setEditor: (node: HTMLElement | null) => void;
92
+ };
93
+ width: number;
94
+ height: number;
95
+ settings: UtilsSettings;
96
+ canvasSize: {
97
+ width: number;
98
+ height: number;
99
+ scaleRatio: number;
100
+ };
101
+ setCanvasSize: import("react").Dispatch<import("react").SetStateAction<{
102
+ width: number;
103
+ height: number;
104
+ scaleRatio: number;
105
+ }>>;
106
+ setCanvasOffset: import("react").Dispatch<import("react").SetStateAction<Point>>;
107
+ selectShape: (shape: ShapeEntity) => void;
108
+ activeTool: ToolsType;
109
+ setActiveTool: import("react").Dispatch<import("react").SetStateAction<ToolsType>>;
110
+ isInsideComponent: boolean;
111
+ isEditMode: boolean;
112
+ isDisabled: boolean;
113
+ canvas: {
114
+ selection: {
115
+ canvasSelectionColor: string;
116
+ canvasSelectionWidth: number;
117
+ };
118
+ withSkeleton: boolean;
119
+ withFrameSelection: boolean;
120
+ canGrow: boolean;
121
+ canShrink: boolean;
122
+ };
123
+ };
124
+ registerEvent: (event: "dataChanged", fn: (data: StateData) => void) => void;
125
+ unregisterEvent: (event: "dataChanged", fn?: ((data: StateData) => void) | undefined) => void;
126
+ resetCanvas: (json: DrawableShape[], clearHistory?: boolean) => Promise<void>;
127
+ getCurrentImage: () => string | undefined;
128
+ getCurrentData: () => StateData;
129
+ };
130
+ export type UseReactPaintReturnType = ReturnType<typeof useReactPaint>;
131
+ export default useReactPaint;
@@ -1,7 +1,9 @@
1
1
  /// <reference types="react" />
2
- import { UtilsSettings } from 'src/constants/app';
3
- import type { Point, ShapeEntity } from '../types/Shapes';
4
- declare const useShapes: (onDataChanged: (() => void) | undefined, settings: UtilsSettings) => {
2
+ import { type UtilsSettings } from './../../canvas/constants/app';
3
+ import type { StateData, Point, ShapeEntity } from './../../common/types/Shapes';
4
+ declare const useShapes: (settings: UtilsSettings) => {
5
+ registerEvent: (event: 'dataChanged', fn: (data: StateData) => void) => void;
6
+ unregisterEvent: (event: 'dataChanged', fn?: (data: StateData) => void) => void;
5
7
  shapesRef: import("react").MutableRefObject<ShapeEntity[]>;
6
8
  selectedShape: ShapeEntity | undefined;
7
9
  hoveredShape: ShapeEntity | undefined;
@@ -0,0 +1,13 @@
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;
10
+ };
11
+ };
12
+ declare const App: ({ options, className, style, canvasProps }: AppProps) => import("react/jsx-runtime").JSX.Element;
13
+ export default App;
@@ -1,5 +1,5 @@
1
- import { UtilsSettings } from 'src/constants/app';
2
- import type { Point } from '../types/Shapes';
1
+ import type { UtilsSettings } from './../../canvas/constants/app';
2
+ import type { Point } from './../../common/types/Shapes';
3
3
  export declare const initCanvasContext: (ctx: CanvasRenderingContext2D) => void;
4
4
  export declare const updateCanvasContext: (ctx: CanvasRenderingContext2D, style?: {
5
5
  fillColor?: string;
@@ -1,5 +1,5 @@
1
- import { UtilsSettings } from 'src/constants/app';
2
- import type { DrawableShape, DrawableShapeJson, ExportDataType, ShapeEntity } from '../types/Shapes';
3
- export declare const cleanShapesBeforeExport: (shapes: DrawableShape[]) => DrawableShapeJson[];
4
- export declare const buildDataToExport: (shapes: DrawableShape[], width: number, height: number) => ExportDataType;
1
+ import type { UtilsSettings } from './../../canvas/constants/app';
2
+ import type { DrawableShape, StateData, ShapeEntity } from './../../common/types/Shapes';
3
+ export declare const cleanShapesBeforeExport: (shapes: DrawableShape[]) => DrawableShape[];
4
+ export declare const buildDataToExport: (shapes: DrawableShape[], width: number, height: number) => StateData;
5
5
  export declare const addDefaultAndTempShapeProps: (shape: DrawableShape, settings: UtilsSettings) => ShapeEntity;
@@ -1,5 +1,5 @@
1
- import { UtilsSettings } from 'src/constants/app';
2
- import type { DrawableShape, ExportDataType, ShapeEntity } from '../types/Shapes';
1
+ import type { UtilsSettings } from './../../canvas/constants/app';
2
+ import type { DrawableShape, 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>;
@@ -8,4 +8,4 @@ export declare const getBase64Image: (img: HTMLImageElement) => string;
8
8
  export declare const getCanvasImage: (shapes: DrawableShape[], width: number, height: number, settings: UtilsSettings) => string;
9
9
  export declare const encodeShapesInString: (shapes: DrawableShape[], width: number, height: number) => string;
10
10
  export declare const decodeJson: (file: File) => Promise<unknown>;
11
- export declare const decodeImportedData: (shapesForJson: ExportDataType, settings: UtilsSettings) => Promise<ShapeEntity[]>;
11
+ export declare const decodeImportedData: (shapesForJson: DrawableShape[], settings: UtilsSettings) => Promise<ShapeEntity[]>;
@@ -1,2 +1,2 @@
1
- import { UtilsSettings } from '../constants/app';
1
+ import type { UtilsSettings } from './../../canvas/constants/app';
2
2
  export declare const drawGrid: (ctx: CanvasRenderingContext2D, width: number, height: number, settings: UtilsSettings) => void;
@@ -1,6 +1,6 @@
1
- import type { HoverModeData } from '../types/Mode';
2
- import type { DrawableShape, Point, Rect } from '../types/Shapes';
3
- import { UtilsSettings } from 'src/constants/app';
1
+ import type { UtilsSettings } from './../../canvas/constants/app';
2
+ import type { HoverModeData } from './../../common/types/Mode';
3
+ import type { DrawableShape, Point, Rect } from './../../common/types/Shapes';
4
4
  export declare const getCursorPosition: (e: MouseEvent | TouchEvent, canvas: HTMLCanvasElement | null, settings: UtilsSettings) => Point;
5
5
  export declare const isTouchGesture: (e: MouseEvent | TouchEvent) => e is TouchEvent;
6
6
  export declare const getPointPositionAfterCanvasTransformation: (point: Point, shapeRotation: number, [originX, originY]: Point, [canvasOffsetX, canvasOffsetY]: Point) => Point;
@@ -1,5 +1,5 @@
1
- import { UtilsSettings } from 'src/constants/app';
2
- import { DrawableShape, Point, SelectionLinesType } from 'src/types/Shapes';
1
+ import type { UtilsSettings } from './../../../canvas/constants/app';
2
+ import type { DrawableShape, Point, SelectionLinesType } from './../../../common/types/Shapes';
3
3
  export declare const createLineSelectionPath: (path: Path2D | undefined, shape: DrawableShape<'line' | 'polygon' | 'curve'> & {
4
4
  points: readonly Point[];
5
5
  }, settings: UtilsSettings, gravityAnchors?: boolean) => SelectionLinesType;
@@ -1,6 +1,6 @@
1
- import type { UtilsSettings } from '../../constants/app';
2
- import type { SelectionModeResize } from '../../types/Mode';
3
- import type { DrawableShape, Point, SelectionDefaultType } from '../../types/Shapes';
1
+ import type { UtilsSettings } from './../../../canvas/constants/app';
2
+ import type { SelectionModeResize } from './../../../common/types/Mode';
3
+ import type { DrawableShape, Point, SelectionDefaultType } from './../../../common/types/Shapes';
4
4
  export declare const createRecSelectionPath: (path: Path2D | undefined, rect: DrawableShape, settings: UtilsSettings) => SelectionDefaultType;
5
5
  export declare const drawSelectionRect: (ctx: CanvasRenderingContext2D, shape: DrawableShape & {
6
6
  selection?: SelectionDefaultType;
@@ -0,0 +1,3 @@
1
+ import type { UtilsSettings } from './../../../canvas/constants/app';
2
+ import type { Point } from './../../../common/types/Shapes';
3
+ export declare const drawFrame: (ctx: CanvasRenderingContext2D, selectionFrame: [Point, Point], settings: UtilsSettings) => void;
@@ -1,6 +1,6 @@
1
- import { UtilsSettings } from 'src/constants/app';
2
- import type { HoverModeData, SelectionModeData } from '../types/Mode';
3
- import type { Point, ShapeEntity } from '../types/Shapes';
1
+ import type { UtilsSettings } from './../../canvas/constants/app';
2
+ import type { HoverModeData, SelectionModeData } from './../../common/types/Mode';
3
+ import type { Point, ShapeEntity } from './../../common/types/Shapes';
4
4
  export declare const getNewSelectionData: (hoverMode: HoverModeData, selectedShape: ShapeEntity, cursorPosition: Point, settings: UtilsSettings) => SelectionModeData<Point | number> | undefined;
5
5
  export declare const selectShape: (ctx: CanvasRenderingContext2D, shapes: ShapeEntity[], cursorPosition: Point, settings: UtilsSettings, selectedShape: ShapeEntity | undefined, isTouchGesture: boolean, withFrameSelection: boolean) => {
6
6
  mode: SelectionModeData<Point | number>;
@@ -1,7 +1,7 @@
1
- import { UtilsSettings } from '../../constants/app';
2
- import { SelectionModeResize } from '../../types/Mode';
3
- import type { DrawableShape, Point, Rect, ShapeEntity } from '../../types/Shapes';
4
- import type { ToolsSettingsType } from '../../types/tools';
1
+ import type { UtilsSettings } from './../../../canvas/constants/app';
2
+ import type { SelectionModeResize } from './../../../common/types/Mode';
3
+ import type { DrawableShape, Point, Rect, ShapeEntity } from './../../../common/types/Shapes';
4
+ import type { ToolsSettingsType } from './../../../common/types/tools';
5
5
  export declare const refreshBrush: <T extends DrawableShape<"brush">>(brush: T, settings: UtilsSettings) => T;
6
6
  export declare const createBrush: (shape: {
7
7
  id: string;
@@ -1,7 +1,7 @@
1
- import { UtilsSettings } from '../../constants/app';
2
- import { SelectionModeResize } from '../../types/Mode';
3
- import type { Circle, DrawableShape, Point, Rect, ShapeEntity } from '../../types/Shapes';
4
- import type { ToolsSettingsType } from '../../types/tools';
1
+ import type { UtilsSettings } from './../../../canvas/constants/app';
2
+ import type { SelectionModeResize } from './../../../common/types/Mode';
3
+ import type { Circle, DrawableShape, Point, Rect, ShapeEntity } from './../../../common/types/Shapes';
4
+ import type { ToolsSettingsType } from './../../../common/types/tools';
5
5
  export declare const refreshCircle: <T extends DrawableShape<"circle">>(shape: T, settings: UtilsSettings) => T;
6
6
  export declare const createCircle: (shape: {
7
7
  id: string;
@@ -1,7 +1,7 @@
1
- import { UtilsSettings } from '../../constants/app';
2
- import { SelectionModeResize } from '../../types/Mode';
3
- import type { DrawableShape, Point, ShapeEntity } from '../../types/Shapes';
4
- import type { ToolsSettingsType } from '../../types/tools';
1
+ import type { UtilsSettings } from './../../../canvas/constants/app';
2
+ import type { SelectionModeResize } from './../../../common/types/Mode';
3
+ import type { DrawableShape, Point, ShapeEntity } from './../../../common/types/Shapes';
4
+ import type { ToolsSettingsType } from './../../../common/types/tools';
5
5
  export declare const refreshCurve: <T extends DrawableShape<"curve">>(shape: T, settings: UtilsSettings) => T;
6
6
  export declare const createCurve: (shape: {
7
7
  id: string;
@@ -10,7 +10,7 @@ export declare const createCurve: (shape: {
10
10
  }, cursorPosition: Point, settings: UtilsSettings) => ShapeEntity<'curve'>;
11
11
  export declare const resizeCurve: (cursorPosition: Point, originalShape: DrawableShape<'curve'>, selectionMode: SelectionModeResize<number>, settings: UtilsSettings) => DrawableShape<'curve'>;
12
12
  export declare const drawCurve: (ctx: CanvasRenderingContext2D, curve: DrawableShape<'curve'>) => void;
13
- export declare const getCurveBorder: (polygon: import("../../types/Shapes").Polygon, settings: UtilsSettings) => import("../../types/Shapes").Rect;
13
+ export declare const getCurveBorder: (polygon: import("./../../../common/types/Shapes").Polygon, settings: UtilsSettings) => import("./../../../common/types/Shapes").Rect;
14
14
  export declare const translateCurve: <U extends DrawableShape<"curve">>(cursorPosition: Point, originalShape: U, originalCursorPosition: Point, settings: UtilsSettings) => U & {
15
15
  points: [number, number][];
16
16
  };
@@ -1,7 +1,7 @@
1
- import { UtilsSettings } from '../../constants/app';
2
- import { SelectionModeResize } from '../../types/Mode';
3
- import type { DrawableShape, Ellipse, Point, Rect, ShapeEntity } from '../../types/Shapes';
4
- import type { ToolsSettingsType } from '../../types/tools';
1
+ import type { UtilsSettings } from './../../../canvas/constants/app';
2
+ import type { SelectionModeResize } from './../../../common/types/Mode';
3
+ import type { DrawableShape, Ellipse, Point, Rect, ShapeEntity } from './../../../common/types/Shapes';
4
+ import type { ToolsSettingsType } from './../../../common/types/tools';
5
5
  export declare const refreshEllipse: <T extends DrawableShape<"ellipse">>(shape: T, settings: UtilsSettings) => T;
6
6
  export declare const createEllipse: (shape: {
7
7
  id: string;
@@ -1,7 +1,7 @@
1
- import type { UtilsSettings } from '../../constants/app';
2
- import { SelectionModeData } from '../../types/Mode';
3
- import type { DrawableShape, Point, Rect, ShapeEntity } from '../../types/Shapes';
4
- import type { CustomTool } from '../../types/tools';
1
+ import type { UtilsSettings } from './../../../canvas/constants/app';
2
+ import type { SelectionModeData } from './../../../common/types/Mode';
3
+ import type { DrawableShape, Point, Rect, ShapeEntity } from './../../../common/types/Shapes';
4
+ import type { CustomTool } from './../../../common/types/tools';
5
5
  export declare const createShape: (ctx: CanvasRenderingContext2D, shape: Exclude<CustomTool, {
6
6
  type: 'picture';
7
7
  }>, cursorPosition: Point, settings: UtilsSettings) => ShapeEntity;
@@ -22,7 +22,7 @@ export declare const drawShapeSelection: ({ ctx, shape, settings, selectionWidth
22
22
  settings: UtilsSettings;
23
23
  selectionWidth: number;
24
24
  selectionColor: string;
25
- withAnchors?: boolean | undefined;
25
+ withAnchors?: boolean;
26
26
  }) => void;
27
27
  export declare const drawSelectionFrame: ({ ctx, selectionFrame, settings }: {
28
28
  ctx: CanvasRenderingContext2D;