@yorab/react-paint 0.8.0 → 0.9.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 (45) hide show
  1. package/README.md +1 -11
  2. package/dist/components/Canvas.d.ts +6 -6
  3. package/dist/components/settings/DeleteButton.d.ts +3 -3
  4. package/dist/components/settings/Layouts.d.ts +7 -7
  5. package/dist/components/settings/SettingsBar.d.ts +7 -5
  6. package/dist/components/toolbox/EditTextBox.d.ts +2 -2
  7. package/dist/components/toolbox/Tool.d.ts +2 -2
  8. package/dist/constants/shapes.d.ts +1 -1
  9. package/dist/constants/style.d.ts +1 -1
  10. package/dist/hooks/useDrag.d.ts +3 -3
  11. package/dist/hooks/useDrawableCanvas.d.ts +6 -6
  12. package/dist/hooks/useKeyboard.d.ts +9 -7
  13. package/dist/hooks/useShapes.d.ts +16 -12
  14. package/dist/react-paint.css +1 -1
  15. package/dist/react-paint.js +5374 -5596
  16. package/dist/react-paint.umd.cjs +17 -43
  17. package/dist/types/Mode.d.ts +4 -4
  18. package/dist/types/Shapes.d.ts +83 -67
  19. package/dist/types/react.d.ts +7 -0
  20. package/dist/types/tools.d.ts +2 -1
  21. package/dist/types/utils.d.ts +1 -0
  22. package/dist/utils/data.d.ts +2 -223
  23. package/dist/utils/file.d.ts +2 -2
  24. package/dist/utils/{shapes/grid.d.ts → grid.d.ts} +2 -2
  25. package/dist/utils/migration.d.ts +98 -116
  26. package/dist/utils/selection/lineSelection.d.ts +12 -0
  27. package/dist/utils/selection/rectSelection.d.ts +13 -0
  28. package/dist/utils/selection.d.ts +4 -4
  29. package/dist/utils/shapes/brush.d.ts +10 -45
  30. package/dist/utils/shapes/circle.d.ts +10 -6
  31. package/dist/utils/shapes/curve.d.ts +10 -5
  32. package/dist/utils/shapes/ellipse.d.ts +10 -6
  33. package/dist/utils/shapes/index.d.ts +11 -227
  34. package/dist/utils/shapes/line.d.ts +10 -16
  35. package/dist/utils/shapes/path.d.ts +9 -0
  36. package/dist/utils/shapes/picture.d.ts +11 -5
  37. package/dist/utils/shapes/polygon.d.ts +11 -5
  38. package/dist/utils/shapes/rectangle.d.ts +11 -17
  39. package/dist/utils/shapes/text.d.ts +8 -37
  40. package/dist/utils/shapes/triangle.d.ts +3 -2
  41. package/dist/utils/style.d.ts +1 -1
  42. package/dist/utils/transform.d.ts +5 -4
  43. package/dist/utils/trigo.d.ts +7 -1
  44. package/package.json +15 -15
  45. package/dist/utils/shapes/default.d.ts +0 -10
@@ -1,4 +1,4 @@
1
- import type { Point, DrawableShape } from './Shapes';
1
+ import type { Point, ShapeEntity } from './Shapes';
2
2
  export type SelectionModeDefault = {
3
3
  mode: 'default';
4
4
  };
@@ -12,19 +12,19 @@ export type SelectionModeEditText = {
12
12
  export type SelectionModeResize<AnchorType extends Point | number = Point> = {
13
13
  mode: 'resize';
14
14
  cursorStartPosition: Point;
15
- originalShape: DrawableShape;
15
+ originalShape: ShapeEntity;
16
16
  anchor: AnchorType;
17
17
  };
18
18
  export type SelectionModeRotate = {
19
19
  mode: 'rotate';
20
20
  cursorStartPosition: Point;
21
- originalShape: DrawableShape;
21
+ originalShape: ShapeEntity;
22
22
  center: Point;
23
23
  };
24
24
  export type SelectionModeTranslate = {
25
25
  mode: 'translate';
26
26
  cursorStartPosition: Point;
27
- originalShape: DrawableShape;
27
+ originalShape: ShapeEntity;
28
28
  };
29
29
  export type SelectionModeData<AnchorType extends Point | number> = SelectionModeDefault | SelectionModeBrush | SelectionModeResize<AnchorType> | SelectionModeRotate | SelectionModeTranslate | SelectionModeEditText;
30
30
  export type HoverModeData = {
@@ -1,107 +1,124 @@
1
1
  import { ShapeTypeArray } from '../constants/shapes';
2
2
  export type ShapeType = typeof ShapeTypeArray[number];
3
3
  export type Point = [number, number];
4
- export type StyledShape = {
5
- visible?: boolean;
6
- locked?: boolean;
7
- style?: {
8
- fillColor?: string;
9
- globalAlpha?: number;
10
- strokeColor?: string;
11
- lineWidth?: number;
12
- lineDash?: number;
13
- lineArrow?: number;
14
- pointsCount?: number;
15
- fontFamily?: string;
16
- fontItalic?: boolean;
17
- fontBold?: boolean;
18
- };
19
- };
20
- type Drawable = {
21
- id: string;
22
- toolId?: string;
23
- rotation: number;
24
- };
25
- export type Rect = StyledShape & {
4
+ export type Rect = {
26
5
  x: number;
27
6
  y: number;
28
7
  width: number;
29
8
  height: number;
30
9
  };
31
- export type Square = Rect;
32
- export type StoredPicture = Rect & {
10
+ export type Picture = Rect & {
33
11
  src: string;
34
12
  };
35
- export type Picture = StoredPicture & {
36
- img: HTMLImageElement;
37
- };
38
13
  export type Text = Rect & {
39
14
  value: string[];
40
15
  fontSize: number;
41
16
  };
42
- export type Line = StyledShape & {
43
- points: [Point, Point];
17
+ export type Line = {
18
+ points: readonly [Point, Point];
44
19
  };
45
- export type Triangle = StyledShape & {
20
+ export type Triangle = {
46
21
  points: [Point, Point, Point];
47
22
  };
48
- export type Polygon = StyledShape & {
23
+ export type Polygon = {
49
24
  points: Point[];
50
25
  };
51
- export type Curve = StyledShape & {
26
+ export type Curve = {
52
27
  points: Point[];
53
28
  };
54
- export type Brush = StyledShape & {
29
+ export type Brush = {
55
30
  points: Point[][];
56
31
  };
57
- export type Circle = StyledShape & {
32
+ export type Circle = {
58
33
  x: number;
59
34
  y: number;
60
35
  radius: number;
61
36
  };
62
- export type Ellipse = StyledShape & {
37
+ export type Ellipse = {
63
38
  x: number;
64
39
  y: number;
65
40
  radiusX: number;
66
41
  radiusY: number;
67
42
  };
68
- export type DrawableRect = Rect & Drawable & {
69
- type: 'rect';
70
- };
71
- export type DrawableSquare = Square & Drawable & {
72
- type: 'square';
73
- };
74
- export type DrawablePictureJson = StoredPicture & Drawable & {
75
- type: 'picture';
76
- };
77
- export type DrawablePicture = Picture & Drawable & {
43
+ export type StyleShape = {
44
+ fillColor?: string;
45
+ globalAlpha?: number;
46
+ strokeColor?: string;
47
+ lineWidth?: number;
48
+ lineDash?: number;
49
+ lineArrow?: number;
50
+ pointsCount?: number;
51
+ fontFamily?: string;
52
+ fontItalic?: boolean;
53
+ fontBold?: boolean;
54
+ };
55
+ export type SelectionDefaultType = {
56
+ border: Path2D;
57
+ line: Path2D;
58
+ anchors: Path2D[];
59
+ };
60
+ export type SelectionLinesType = {
61
+ border: Path2D;
62
+ anchors: Path2D[];
63
+ };
64
+ export type DrawableShape<T extends ShapeType = ShapeType> = {
65
+ visible?: boolean;
66
+ locked?: boolean;
67
+ rotation: number;
68
+ style?: StyleShape;
69
+ } & (T extends 'line' ? Line & {
70
+ type: 'line';
71
+ selection?: SelectionLinesType;
72
+ path?: Path2D;
73
+ arrows?: DrawableShape<'triangle'>[];
74
+ } : T extends 'picture' ? Picture & {
78
75
  type: 'picture';
79
- };
80
- export type DrawableText = Text & Drawable & {
76
+ img: HTMLImageElement;
77
+ selection?: SelectionDefaultType;
78
+ } : T extends 'text' ? Text & {
81
79
  type: 'text';
82
- };
83
- export type DrawableLine = Line & Drawable & {
84
- type: 'line';
85
- };
86
- export type DrawablePolygon = Polygon & Drawable & {
80
+ selection?: SelectionDefaultType;
81
+ } : T extends 'rect' ? Rect & {
82
+ type: 'rect';
83
+ selection?: SelectionDefaultType;
84
+ path?: Path2D;
85
+ } : T extends 'square' ? Rect & {
86
+ type: 'square';
87
+ selection?: SelectionDefaultType;
88
+ path?: Path2D;
89
+ } : T extends 'circle' ? Circle & {
90
+ type: 'circle';
91
+ selection?: SelectionDefaultType;
92
+ path?: Path2D;
93
+ } : T extends 'ellipse' ? Ellipse & {
94
+ type: 'ellipse';
95
+ selection?: SelectionDefaultType;
96
+ path?: Path2D;
97
+ } : T extends 'triangle' ? Triangle & {
98
+ type: 'triangle';
99
+ path?: Path2D;
100
+ } : T extends 'polygon' ? Polygon & {
87
101
  type: 'polygon';
88
- };
89
- export type DrawableCurve = Curve & Drawable & {
102
+ selection?: SelectionLinesType;
103
+ path?: Path2D;
104
+ } : T extends 'curve' ? Curve & {
90
105
  type: 'curve';
91
- };
92
- export type DrawableBrush = Brush & Drawable & {
106
+ selection?: SelectionLinesType;
107
+ path?: Path2D;
108
+ } : T extends 'brush' ? Brush & {
93
109
  type: 'brush';
94
- };
95
- export type DrawableCircle = Circle & Drawable & {
96
- type: 'circle';
97
- };
98
- export type DrawableEllipse = Ellipse & Drawable & {
99
- type: 'ellipse';
100
- };
101
- export type DrawableShape = DrawableRect | DrawableSquare | DrawablePicture | DrawableText | DrawableLine | DrawablePolygon | DrawableCurve | DrawableBrush | DrawableCircle | DrawableEllipse;
102
- export type DrawableShapeJson = {
110
+ selection?: SelectionDefaultType;
111
+ path?: Path2D;
112
+ scaleX?: number;
113
+ scaleY?: number;
114
+ } : never);
115
+ export type DrawableShapeJson<T extends ShapeType = ShapeType> = DrawableShape<T> & {
103
116
  translation?: Point;
104
- } & (DrawableRect | DrawableSquare | DrawablePictureJson | DrawableText | DrawableLine | DrawableCurve | DrawablePolygon | DrawableBrush | DrawableCircle | DrawableEllipse);
117
+ };
118
+ export type ShapeEntity<T extends Exclude<ShapeType, 'triangle'> = Exclude<ShapeType, 'triangle'>> = {
119
+ id: string;
120
+ toolId?: string;
121
+ } & DrawableShape<T>;
105
122
  export type ExportDataType = {
106
123
  shapes: DrawableShapeJson[];
107
124
  config?: {
@@ -109,4 +126,3 @@ export type ExportDataType = {
109
126
  height: number;
110
127
  };
111
128
  };
112
- export {};
@@ -0,0 +1,7 @@
1
+ import 'react';
2
+ declare module 'react' {
3
+ interface CSSProperties {
4
+ [key: `--${string}`]: string | number;
5
+ }
6
+ }
7
+ export {};
@@ -112,8 +112,9 @@ export type ToolsLineSettings = SettingsOpacity & SettingsStrokeColor & Settings
112
112
  export type ToolsBrushSettings = SettingsOpacity & SettingsStrokeColor & SettingsLineWidth & SettingsLineDash;
113
113
  export type ToolsPolygonSettings = SettingsOpacity & SettingsStrokeColor & SettingsFillColor & SettingsLineWidth & SettingsLineDash & SettingsPointsCount;
114
114
  export type ToolsCurveSettings = SettingsOpacity & SettingsStrokeColor & SettingsFillColor & SettingsLineWidth & SettingsLineDash & SettingsPointsCount;
115
+ export type ToolsTriangleSettings = SettingsStrokeColor & SettingsFillColor & SettingsOpacity & SettingsLineWidth & SettingsLineDash;
115
116
  export type ToolsPictureSettings = SettingsOpacity;
116
- export type ToolsSettingsType<T extends ShapeType> = T extends 'rect' ? ToolsRectSettings : T extends 'square' ? ToolsSquareSettings : T extends 'circle' ? ToolsCircleSettings : T extends 'ellipse' ? ToolsEllipseSettings : T extends 'text' ? ToolsTextSettings : T extends 'line' ? ToolsLineSettings : T extends 'brush' ? ToolsBrushSettings : T extends 'polygon' ? ToolsPolygonSettings : T extends 'curve' ? ToolsCurveSettings : T extends 'picture' ? ToolsPictureSettings : unknown;
117
+ export type ToolsSettingsType<T extends ShapeType> = T extends 'rect' ? ToolsRectSettings : T extends 'square' ? ToolsSquareSettings : T extends 'circle' ? ToolsCircleSettings : T extends 'ellipse' ? ToolsEllipseSettings : T extends 'text' ? ToolsTextSettings : T extends 'line' ? ToolsLineSettings : T extends 'brush' ? ToolsBrushSettings : T extends 'polygon' ? ToolsPolygonSettings : T extends 'curve' ? ToolsCurveSettings : T extends 'triangle' ? ToolsTriangleSettings : T extends 'picture' ? ToolsPictureSettings : unknown;
117
118
  export type ActionsType = 'selection' | 'undo' | 'redo' | 'clear' | 'export' | 'loadfile' | 'savefile' | 'move' | 'uploadpicture' | 'addurlpicture';
118
119
  export type ActionsTool = {
119
120
  id: string;
@@ -1,3 +1,4 @@
1
1
  export type RecursivePartial<T> = {
2
2
  [P in keyof T]?: T[P] extends (infer U)[] ? RecursivePartial<U>[] : T[P] extends object ? RecursivePartial<T[P]> : T[P];
3
3
  };
4
+ export type ValueOf<T> = T[keyof T];
@@ -1,225 +1,4 @@
1
- import type { DrawableShape, DrawableShapeJson, ExportDataType } from '../types/Shapes';
1
+ import type { DrawableShape, DrawableShapeJson, ExportDataType, ShapeEntity } from '../types/Shapes';
2
2
  export declare const cleanShapesBeforeExport: (shapes: DrawableShape[]) => DrawableShapeJson[];
3
3
  export declare const buildDataToExport: (shapes: DrawableShape[], width: number, height: number) => ExportDataType;
4
- export declare const addDefaultAndTempShapeProps: (shape: DrawableShape) => {
5
- id: string;
6
- visible?: boolean | undefined;
7
- locked?: boolean | undefined;
8
- style?: {
9
- fillColor?: string | undefined;
10
- globalAlpha?: number | undefined;
11
- strokeColor?: string | undefined;
12
- lineWidth?: number | undefined;
13
- lineDash?: number | undefined;
14
- lineArrow?: number | undefined;
15
- pointsCount?: number | undefined;
16
- fontFamily?: string | undefined;
17
- fontItalic?: boolean | undefined;
18
- fontBold?: boolean | undefined;
19
- } | undefined;
20
- x: number;
21
- y: number;
22
- width: number;
23
- height: number;
24
- toolId?: string | undefined;
25
- rotation: number;
26
- type: "rect";
27
- } | {
28
- id: string;
29
- visible?: boolean | undefined;
30
- locked?: boolean | undefined;
31
- style?: {
32
- fillColor?: string | undefined;
33
- globalAlpha?: number | undefined;
34
- strokeColor?: string | undefined;
35
- lineWidth?: number | undefined;
36
- lineDash?: number | undefined;
37
- lineArrow?: number | undefined;
38
- pointsCount?: number | undefined;
39
- fontFamily?: string | undefined;
40
- fontItalic?: boolean | undefined;
41
- fontBold?: boolean | undefined;
42
- } | undefined;
43
- x: number;
44
- y: number;
45
- width: number;
46
- height: number;
47
- toolId?: string | undefined;
48
- rotation: number;
49
- type: "square";
50
- } | {
51
- id: string;
52
- visible?: boolean | undefined;
53
- locked?: boolean | undefined;
54
- style?: {
55
- fillColor?: string | undefined;
56
- globalAlpha?: number | undefined;
57
- strokeColor?: string | undefined;
58
- lineWidth?: number | undefined;
59
- lineDash?: number | undefined;
60
- lineArrow?: number | undefined;
61
- pointsCount?: number | undefined;
62
- fontFamily?: string | undefined;
63
- fontItalic?: boolean | undefined;
64
- fontBold?: boolean | undefined;
65
- } | undefined;
66
- x: number;
67
- y: number;
68
- width: number;
69
- height: number;
70
- src: string;
71
- img: HTMLImageElement;
72
- toolId?: string | undefined;
73
- rotation: number;
74
- type: "picture";
75
- } | {
76
- id: string;
77
- visible?: boolean | undefined;
78
- locked?: boolean | undefined;
79
- style?: {
80
- fillColor?: string | undefined;
81
- globalAlpha?: number | undefined;
82
- strokeColor?: string | undefined;
83
- lineWidth?: number | undefined;
84
- lineDash?: number | undefined;
85
- lineArrow?: number | undefined;
86
- pointsCount?: number | undefined;
87
- fontFamily?: string | undefined;
88
- fontItalic?: boolean | undefined;
89
- fontBold?: boolean | undefined;
90
- } | undefined;
91
- x: number;
92
- y: number;
93
- width: number;
94
- height: number;
95
- value: string[];
96
- fontSize: number;
97
- toolId?: string | undefined;
98
- rotation: number;
99
- type: "text";
100
- } | {
101
- id: string;
102
- visible?: boolean | undefined;
103
- locked?: boolean | undefined;
104
- style?: {
105
- fillColor?: string | undefined;
106
- globalAlpha?: number | undefined;
107
- strokeColor?: string | undefined;
108
- lineWidth?: number | undefined;
109
- lineDash?: number | undefined;
110
- lineArrow?: number | undefined;
111
- pointsCount?: number | undefined;
112
- fontFamily?: string | undefined;
113
- fontItalic?: boolean | undefined;
114
- fontBold?: boolean | undefined;
115
- } | undefined;
116
- points: [import("../types/Shapes").Point, import("../types/Shapes").Point];
117
- toolId?: string | undefined;
118
- rotation: number;
119
- type: "line";
120
- } | {
121
- id: string;
122
- visible?: boolean | undefined;
123
- locked?: boolean | undefined;
124
- style?: {
125
- fillColor?: string | undefined;
126
- globalAlpha?: number | undefined;
127
- strokeColor?: string | undefined;
128
- lineWidth?: number | undefined;
129
- lineDash?: number | undefined;
130
- lineArrow?: number | undefined;
131
- pointsCount?: number | undefined;
132
- fontFamily?: string | undefined;
133
- fontItalic?: boolean | undefined;
134
- fontBold?: boolean | undefined;
135
- } | undefined;
136
- points: import("../types/Shapes").Point[];
137
- toolId?: string | undefined;
138
- rotation: number;
139
- type: "polygon";
140
- } | {
141
- id: string;
142
- visible?: boolean | undefined;
143
- locked?: boolean | undefined;
144
- style?: {
145
- fillColor?: string | undefined;
146
- globalAlpha?: number | undefined;
147
- strokeColor?: string | undefined;
148
- lineWidth?: number | undefined;
149
- lineDash?: number | undefined;
150
- lineArrow?: number | undefined;
151
- pointsCount?: number | undefined;
152
- fontFamily?: string | undefined;
153
- fontItalic?: boolean | undefined;
154
- fontBold?: boolean | undefined;
155
- } | undefined;
156
- points: import("../types/Shapes").Point[];
157
- toolId?: string | undefined;
158
- rotation: number;
159
- type: "curve";
160
- } | {
161
- id: string;
162
- visible?: boolean | undefined;
163
- locked?: boolean | undefined;
164
- style?: {
165
- fillColor?: string | undefined;
166
- globalAlpha?: number | undefined;
167
- strokeColor?: string | undefined;
168
- lineWidth?: number | undefined;
169
- lineDash?: number | undefined;
170
- lineArrow?: number | undefined;
171
- pointsCount?: number | undefined;
172
- fontFamily?: string | undefined;
173
- fontItalic?: boolean | undefined;
174
- fontBold?: boolean | undefined;
175
- } | undefined;
176
- points: import("../types/Shapes").Point[][];
177
- toolId?: string | undefined;
178
- rotation: number;
179
- type: "brush";
180
- } | {
181
- id: string;
182
- visible?: boolean | undefined;
183
- locked?: boolean | undefined;
184
- style?: {
185
- fillColor?: string | undefined;
186
- globalAlpha?: number | undefined;
187
- strokeColor?: string | undefined;
188
- lineWidth?: number | undefined;
189
- lineDash?: number | undefined;
190
- lineArrow?: number | undefined;
191
- pointsCount?: number | undefined;
192
- fontFamily?: string | undefined;
193
- fontItalic?: boolean | undefined;
194
- fontBold?: boolean | undefined;
195
- } | undefined;
196
- x: number;
197
- y: number;
198
- radius: number;
199
- toolId?: string | undefined;
200
- rotation: number;
201
- type: "circle";
202
- } | {
203
- id: string;
204
- visible?: boolean | undefined;
205
- locked?: boolean | undefined;
206
- style?: {
207
- fillColor?: string | undefined;
208
- globalAlpha?: number | undefined;
209
- strokeColor?: string | undefined;
210
- lineWidth?: number | undefined;
211
- lineDash?: number | undefined;
212
- lineArrow?: number | undefined;
213
- pointsCount?: number | undefined;
214
- fontFamily?: string | undefined;
215
- fontItalic?: boolean | undefined;
216
- fontBold?: boolean | undefined;
217
- } | undefined;
218
- x: number;
219
- y: number;
220
- radiusX: number;
221
- radiusY: number;
222
- toolId?: string | undefined;
223
- rotation: number;
224
- type: "ellipse";
225
- };
4
+ export declare const addDefaultAndTempShapeProps: (shape: DrawableShape, currentScale: number, selectionPadding: number) => ShapeEntity;
@@ -1,4 +1,4 @@
1
- import type { DrawableShape, ExportDataType, Point } from '../types/Shapes';
1
+ import type { DrawableShape, ExportDataType, Point, ShapeEntity } from '../types/Shapes';
2
2
  export declare const addSizeAndConvertSvgToObjectUrl: (svgFileContent: string) => string;
3
3
  export declare const isSvg: (fileOrUrl: File | string) => boolean;
4
4
  export declare const fetchAndStringify: (url: string) => Promise<string>;
@@ -7,4 +7,4 @@ export declare const getBase64Image: (img: HTMLImageElement) => string;
7
7
  export declare const getCanvasImage: (shapes: DrawableShape[], canvasOffset: Point, width: number, height: number, selectionPadding: number) => string;
8
8
  export declare const encodeShapesInString: (shapes: DrawableShape[], width: number, height: number) => string;
9
9
  export declare const decodeJson: (file: File) => Promise<unknown>;
10
- export declare const decodeImportedData: (shapesForJson: ExportDataType) => Promise<DrawableShape[]>;
10
+ export declare const decodeImportedData: (shapesForJson: ExportDataType, currentScale: number, selectionPadding: number) => Promise<ShapeEntity[]>;
@@ -1,3 +1,3 @@
1
- import { GridFormatType } from '../../constants/app';
2
- import type { Point } from '../../types/Shapes';
1
+ import { GridFormatType } from '../constants/app';
2
+ import type { Point } from '../types/Shapes';
3
3
  export declare const drawGrid: (ctx: CanvasRenderingContext2D, width: number, height: number, responsiveScale: number, canvasOffset: Point, gridFormat: GridFormatType) => void;