@yorab/react-paint 0.16.1 → 0.16.3

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.
@@ -21,7 +21,7 @@ export declare const decodeImportedData: (shapesForJson: ExportedDrawableShape[]
21
21
  center: Point;
22
22
  boundingBox: import("./../../common/types/Shapes").Rect;
23
23
  };
24
- path?: Path2D | undefined;
24
+ path: Path2D;
25
25
  } & {
26
26
  rotation?: number;
27
27
  toolId?: string;
@@ -31,9 +31,11 @@ export declare const decodeImportedData: (shapesForJson: ExportedDrawableShape[]
31
31
  } & import("./../../common/types/Shapes").Line & {
32
32
  type: "line";
33
33
  } & {
34
+ type: "brush" | "rect" | "square" | "line" | "polygon" | "circle" | "curve" | "ellipse" | "picture" | "text" | "group";
35
+ } & {
36
+ type: "line";
34
37
  selection?: import("./../../common/types/Shapes").SelectionLinesType | undefined;
35
38
  arrows?: import("./../../common/types/Shapes").TriangleEntity[];
36
- type: "line";
37
39
  }) | ({
38
40
  id: string;
39
41
  computed: {
@@ -42,7 +44,7 @@ export declare const decodeImportedData: (shapesForJson: ExportedDrawableShape[]
42
44
  center: Point;
43
45
  boundingBox: import("./../../common/types/Shapes").Rect;
44
46
  };
45
- path?: Path2D | undefined;
47
+ path: Path2D;
46
48
  } & {
47
49
  rotation?: number;
48
50
  toolId?: string;
@@ -52,15 +54,16 @@ export declare const decodeImportedData: (shapesForJson: ExportedDrawableShape[]
52
54
  } & import("./../../common/types/Shapes").Rect & {
53
55
  src: string;
54
56
  } & {
57
+ type: "picture";
55
58
  img: HTMLImageElement;
56
59
  flipX?: boolean;
57
60
  flipY?: boolean;
58
61
  ratio?: number;
59
- type: "picture";
60
62
  } & {
61
- img: HTMLImageElement;
63
+ type: "brush" | "rect" | "square" | "line" | "polygon" | "circle" | "curve" | "ellipse" | "picture" | "text" | "group";
64
+ } & {
65
+ type: "text" | "picture" | "rect" | "square" | "circle" | "ellipse" | "group" | "brush";
62
66
  selection?: import("./../../common/types/Shapes").SelectionDefaultType | undefined;
63
- type: "picture";
64
67
  }) | ({
65
68
  id: string;
66
69
  computed: {
@@ -69,7 +72,7 @@ export declare const decodeImportedData: (shapesForJson: ExportedDrawableShape[]
69
72
  center: Point;
70
73
  boundingBox: import("./../../common/types/Shapes").Rect;
71
74
  };
72
- path?: Path2D | undefined;
75
+ path: Path2D;
73
76
  } & {
74
77
  rotation?: number;
75
78
  toolId?: string;
@@ -80,13 +83,15 @@ export declare const decodeImportedData: (shapesForJson: ExportedDrawableShape[]
80
83
  value: string[];
81
84
  fontSize: number;
82
85
  } & {
86
+ type: "text";
83
87
  flipX?: boolean;
84
88
  flipY?: boolean;
85
89
  ratio?: number;
86
- type: "text";
87
90
  } & {
91
+ type: "brush" | "rect" | "square" | "line" | "polygon" | "circle" | "curve" | "ellipse" | "picture" | "text" | "group";
92
+ } & {
93
+ type: "text" | "picture" | "rect" | "square" | "circle" | "ellipse" | "group" | "brush";
88
94
  selection?: import("./../../common/types/Shapes").SelectionDefaultType | undefined;
89
- type: "text";
90
95
  }) | ({
91
96
  id: string;
92
97
  computed: {
@@ -95,7 +100,7 @@ export declare const decodeImportedData: (shapesForJson: ExportedDrawableShape[]
95
100
  center: Point;
96
101
  boundingBox: import("./../../common/types/Shapes").Rect;
97
102
  };
98
- path?: Path2D | undefined;
103
+ path: Path2D;
99
104
  } & {
100
105
  rotation?: number;
101
106
  toolId?: string;
@@ -105,8 +110,10 @@ export declare const decodeImportedData: (shapesForJson: ExportedDrawableShape[]
105
110
  } & import("./../../common/types/Shapes").Rect & {
106
111
  type: "rect";
107
112
  } & {
113
+ type: "brush" | "rect" | "square" | "line" | "polygon" | "circle" | "curve" | "ellipse" | "picture" | "text" | "group";
114
+ } & {
115
+ type: "text" | "picture" | "rect" | "square" | "circle" | "ellipse" | "group" | "brush";
108
116
  selection?: import("./../../common/types/Shapes").SelectionDefaultType | undefined;
109
- type: "rect";
110
117
  }) | ({
111
118
  id: string;
112
119
  computed: {
@@ -115,7 +122,7 @@ export declare const decodeImportedData: (shapesForJson: ExportedDrawableShape[]
115
122
  center: Point;
116
123
  boundingBox: import("./../../common/types/Shapes").Rect;
117
124
  };
118
- path?: Path2D | undefined;
125
+ path: Path2D;
119
126
  } & {
120
127
  rotation?: number;
121
128
  toolId?: string;
@@ -125,8 +132,10 @@ export declare const decodeImportedData: (shapesForJson: ExportedDrawableShape[]
125
132
  } & import("./../../common/types/Shapes").Rect & {
126
133
  type: "square";
127
134
  } & {
135
+ type: "brush" | "rect" | "square" | "line" | "polygon" | "circle" | "curve" | "ellipse" | "picture" | "text" | "group";
136
+ } & {
137
+ type: "text" | "picture" | "rect" | "square" | "circle" | "ellipse" | "group" | "brush";
128
138
  selection?: import("./../../common/types/Shapes").SelectionDefaultType | undefined;
129
- type: "square";
130
139
  }) | ({
131
140
  id: string;
132
141
  computed: {
@@ -135,7 +144,7 @@ export declare const decodeImportedData: (shapesForJson: ExportedDrawableShape[]
135
144
  center: Point;
136
145
  boundingBox: import("./../../common/types/Shapes").Rect;
137
146
  };
138
- path?: Path2D | undefined;
147
+ path: Path2D;
139
148
  } & {
140
149
  rotation?: number;
141
150
  toolId?: string;
@@ -145,8 +154,10 @@ export declare const decodeImportedData: (shapesForJson: ExportedDrawableShape[]
145
154
  } & import("./../../common/types/Shapes").Circle & {
146
155
  type: "circle";
147
156
  } & {
157
+ type: "brush" | "rect" | "square" | "line" | "polygon" | "circle" | "curve" | "ellipse" | "picture" | "text" | "group";
158
+ } & {
159
+ type: "text" | "picture" | "rect" | "square" | "circle" | "ellipse" | "group" | "brush";
148
160
  selection?: import("./../../common/types/Shapes").SelectionDefaultType | undefined;
149
- type: "circle";
150
161
  }) | ({
151
162
  id: string;
152
163
  computed: {
@@ -155,7 +166,7 @@ export declare const decodeImportedData: (shapesForJson: ExportedDrawableShape[]
155
166
  center: Point;
156
167
  boundingBox: import("./../../common/types/Shapes").Rect;
157
168
  };
158
- path?: Path2D | undefined;
169
+ path: Path2D;
159
170
  } & {
160
171
  rotation?: number;
161
172
  toolId?: string;
@@ -165,8 +176,10 @@ export declare const decodeImportedData: (shapesForJson: ExportedDrawableShape[]
165
176
  } & import("./../../common/types/Shapes").Ellipse & {
166
177
  type: "ellipse";
167
178
  } & {
179
+ type: "brush" | "rect" | "square" | "line" | "polygon" | "circle" | "curve" | "ellipse" | "picture" | "text" | "group";
180
+ } & {
181
+ type: "text" | "picture" | "rect" | "square" | "circle" | "ellipse" | "group" | "brush";
168
182
  selection?: import("./../../common/types/Shapes").SelectionDefaultType | undefined;
169
- type: "ellipse";
170
183
  }) | ({
171
184
  id: string;
172
185
  computed: {
@@ -175,7 +188,7 @@ export declare const decodeImportedData: (shapesForJson: ExportedDrawableShape[]
175
188
  center: Point;
176
189
  boundingBox: import("./../../common/types/Shapes").Rect;
177
190
  };
178
- path?: Path2D | undefined;
191
+ path: Path2D;
179
192
  } & {
180
193
  rotation?: number;
181
194
  toolId?: string;
@@ -185,8 +198,10 @@ export declare const decodeImportedData: (shapesForJson: ExportedDrawableShape[]
185
198
  } & import("./../../common/types/Shapes").Polygon & {
186
199
  type: "polygon";
187
200
  } & {
201
+ type: "brush" | "rect" | "square" | "line" | "polygon" | "circle" | "curve" | "ellipse" | "picture" | "text" | "group";
202
+ } & {
203
+ type: "polygon" | "curve";
188
204
  selection?: import("./../../common/types/Shapes").SelectionLinesType | undefined;
189
- type: "polygon";
190
205
  }) | ({
191
206
  id: string;
192
207
  computed: {
@@ -195,7 +210,7 @@ export declare const decodeImportedData: (shapesForJson: ExportedDrawableShape[]
195
210
  center: Point;
196
211
  boundingBox: import("./../../common/types/Shapes").Rect;
197
212
  };
198
- path?: Path2D | undefined;
213
+ path: Path2D;
199
214
  } & {
200
215
  rotation?: number;
201
216
  toolId?: string;
@@ -205,8 +220,10 @@ export declare const decodeImportedData: (shapesForJson: ExportedDrawableShape[]
205
220
  } & import("./../../common/types/Shapes").Curve & {
206
221
  type: "curve";
207
222
  } & {
223
+ type: "brush" | "rect" | "square" | "line" | "polygon" | "circle" | "curve" | "ellipse" | "picture" | "text" | "group";
224
+ } & {
225
+ type: "polygon" | "curve";
208
226
  selection?: import("./../../common/types/Shapes").SelectionLinesType | undefined;
209
- type: "curve";
210
227
  }) | ({
211
228
  id: string;
212
229
  computed: {
@@ -215,7 +232,7 @@ export declare const decodeImportedData: (shapesForJson: ExportedDrawableShape[]
215
232
  center: Point;
216
233
  boundingBox: import("./../../common/types/Shapes").Rect;
217
234
  };
218
- path?: Path2D | undefined;
235
+ path: Path2D;
219
236
  } & {
220
237
  rotation?: number;
221
238
  toolId?: string;
@@ -227,8 +244,10 @@ export declare const decodeImportedData: (shapesForJson: ExportedDrawableShape[]
227
244
  scaleX?: number;
228
245
  scaleY?: number;
229
246
  } & {
247
+ type: "brush" | "rect" | "square" | "line" | "polygon" | "circle" | "curve" | "ellipse" | "picture" | "text" | "group";
248
+ } & {
249
+ type: "text" | "picture" | "rect" | "square" | "circle" | "ellipse" | "group" | "brush";
230
250
  selection?: import("./../../common/types/Shapes").SelectionDefaultType | undefined;
231
- type: "brush";
232
251
  }) | ({
233
252
  id: string;
234
253
  computed: {
@@ -237,7 +256,7 @@ export declare const decodeImportedData: (shapesForJson: ExportedDrawableShape[]
237
256
  center: Point;
238
257
  boundingBox: import("./../../common/types/Shapes").Rect;
239
258
  };
240
- path?: Path2D | undefined;
259
+ path: Path2D;
241
260
  } & {
242
261
  rotation?: number;
243
262
  toolId?: string;
@@ -245,9 +264,11 @@ export declare const decodeImportedData: (shapesForJson: ExportedDrawableShape[]
245
264
  locked?: boolean;
246
265
  style?: import("./../../common/types/Shapes").StyleShape | undefined;
247
266
  } & import("./../../common/types/Shapes").Rect & {
248
- shapes: ShapeEntity[];
249
267
  type: "group";
268
+ shapes: ShapeEntity[];
269
+ } & {
270
+ type: "brush" | "rect" | "square" | "line" | "polygon" | "circle" | "curve" | "ellipse" | "picture" | "text" | "group";
250
271
  } & {
272
+ type: "text" | "picture" | "rect" | "square" | "circle" | "ellipse" | "group" | "brush";
251
273
  selection?: import("./../../common/types/Shapes").SelectionDefaultType | undefined;
252
- type: "group";
253
274
  }))[]>;
@@ -11,7 +11,7 @@ export declare const getCursorPositionInTransformedCanvas: (e: MouseEvent | Touc
11
11
  export declare const isTouchGesture: (e: MouseEvent | TouchEvent) => e is TouchEvent;
12
12
  export declare const getPointPositionAfterCanvasTransformation: (point: Point, shapeRotation: number, [originX, originY]: Point) => Point;
13
13
  export declare const getPointPositionBeforeCanvasTransformation: (point: Point, shapeRotation: number, [originX, originY]: Point) => Point;
14
- export declare const checkSelectionIntersection: (ctx: CanvasRenderingContext2D, shape: SelectionType, position: Point, settings: UtilsSettings, checkAnchors?: boolean, radius?: number) => false | HoverModeData;
14
+ export declare const checkSelectionIntersection: (ctx: CanvasRenderingContext2D, selection: SelectionType, position: Point, settings: UtilsSettings, checkAnchors?: boolean, radius?: number) => false | HoverModeData;
15
15
  export declare const checkPolygonLinesSelectionIntersection: (ctx: CanvasRenderingContext2D, shape: ShapeEntity<"polygon" | "curve">, position: Point, settings: UtilsSettings, radius?: number) => false | {
16
16
  lineIndex: number;
17
17
  };
@@ -3,7 +3,7 @@ import type { HoverModeData, SelectionModeData } from './../../common/types/Mode
3
3
  import type { Point, SelectionType, ShapeEntity } from './../../common/types/Shapes';
4
4
  import type { CustomTool } from './../../common/types/tools';
5
5
  export declare const getNewSelectionData: (hoverMode: HoverModeData, selectedShape: SelectionType, cursorPosition: Point) => SelectionModeData<Point | number> | undefined;
6
- export declare const selectShape: (ctx: CanvasRenderingContext2D, shapes: ShapeEntity[], cursorPosition: Point, settings: UtilsSettings, selectedShape: SelectionType | undefined, isTouchGesture: boolean, withFrameSelection: boolean, isGroupMode: boolean) => {
6
+ export declare const selectShape: (ctx: CanvasRenderingContext2D, shapes: ShapeEntity[], cursorPosition: Point, settings: UtilsSettings, selectedShape: SelectionType | undefined, isTouchGesture: boolean, withFrameSelection: boolean, behavior?: "add" | "remove" | "replace") => {
7
7
  mode: SelectionModeData<Point | number>;
8
8
  shape: SelectionType | undefined;
9
9
  };
@@ -4,7 +4,7 @@ export declare const createRecPath: (rect: Rect) => Path2D;
4
4
  export declare const createCirclePath: (shape: Circle) => Path2D;
5
5
  export declare const createEllipsePath: (ellipse: DrawableShape<"ellipse">) => Path2D;
6
6
  export declare const createLinePath: (line: Line) => Path2D;
7
- export declare const createBrushPath: (brush: DrawableShape<"brush">, { brushAlgo }: UtilsSettings) => Path2D | undefined;
7
+ export declare const createBrushPath: (brush: DrawableShape<"brush">, { brushAlgo }: UtilsSettings) => Path2D;
8
8
  /** Bounding box of a cubic Bezier segment B(t) = (1-t)³P0 + 3(1-t)²t P1 + 3(1-t)t² P2 + t³ P3 */
9
9
  export declare const getCubicBezierBounds: (p0: Point, p1: Point, p2: Point, p3: Point) => {
10
10
  minX: number;
@@ -17,8 +17,8 @@ export declare const catmullRomToBezier: (p0: Point, p1: Point, p2: Point, p3: P
17
17
  cp1: Point;
18
18
  cp2: Point;
19
19
  };
20
- export declare const createCurvePath: (curve: DrawableShape<"curve">) => Path2D | undefined;
21
- export declare const createPolygonPath: (polygon: DrawableShape<"polygon"> | DrawableShape<"curve">) => Path2D | undefined;
20
+ export declare const createCurvePath: (curve: DrawableShape<"curve">) => Path2D;
21
+ export declare const createPolygonPath: (polygon: DrawableShape<"polygon"> | DrawableShape<"curve">) => Path2D;
22
22
  export declare const createTrianglePath: (triangle: DrawableShape<"triangle">) => Path2D;
23
23
  export declare const getComputedShapeInfos: <T extends DrawableShape, U extends Pick<UtilsSettings, "selectionPadding">>(shape: T, getBorder: (shape: T, settings: U) => Rect, settings: U, getOuterBorder?: (shape: T, borders: Rect, settings: U) => Rect) => {
24
24
  borders: Rect;
@@ -10,7 +10,7 @@ export declare const getComputedRect: (rect: DrawableShape<rectish>, settings: U
10
10
  center: Point;
11
11
  boundingBox: Rect;
12
12
  };
13
- export declare const refreshRect: <T extends rectish>(rect: DrawableShape<T> & {
13
+ export declare const refreshRect: <T extends rectish>(rect: DrawableShape<rectish> & {
14
14
  id: string;
15
15
  }, settings: UtilsSettings) => ShapeEntity<T>;
16
16
  export declare const createRectangle: <T extends rectish>(shape: {
@@ -19,18 +19,21 @@ export type SelectionModeResize<AnchorType extends Point | number = Point> = {
19
19
  mode: 'resize';
20
20
  cursorStartPosition: Point;
21
21
  originalShape: SelectionType;
22
+ selectedShapesLengthAtMouseDown: number;
22
23
  anchor: AnchorType;
23
24
  };
24
25
  export type SelectionModeRotate = {
25
26
  mode: 'rotate';
26
27
  cursorStartPosition: Point;
27
28
  originalShape: SelectionType;
29
+ selectedShapesLengthAtMouseDown: number;
28
30
  center: Point;
29
31
  };
30
32
  export type SelectionModeTranslate = {
31
33
  mode: 'translate';
32
34
  cursorStartPosition: Point;
33
35
  originalShape: SelectionType;
36
+ selectedShapesLengthAtMouseDown: number;
34
37
  hasBeenDuplicated: boolean;
35
38
  dateStart: number;
36
39
  };
@@ -49,63 +49,69 @@ export type StyleShape = {
49
49
  lineWidth?: number;
50
50
  lineDash?: number;
51
51
  lineArrow?: number;
52
+ lineCap?: CanvasLineCap;
52
53
  closedPoints?: number;
53
54
  fontFamily?: string;
54
55
  fontItalic?: boolean;
55
56
  fontBold?: boolean;
56
57
  };
57
58
  export type SelectionDefaultType = {
59
+ type: 'rect';
58
60
  border: Path2D;
59
61
  line: Path2D | undefined;
60
62
  shapePath: Path2D | undefined;
61
63
  anchors: Path2D[];
62
64
  };
63
65
  export type SelectionLinesType = {
66
+ type: 'line';
64
67
  border: Path2D;
65
68
  shapePath: Path2D | undefined;
66
69
  anchors: Path2D[];
67
70
  };
68
- export type DrawableShape<T extends ShapeType = ShapeType> = {
71
+ type GenericDrawableShape = {
69
72
  rotation?: number;
70
73
  toolId?: string;
71
74
  visible?: boolean;
72
75
  locked?: boolean;
73
76
  style?: StyleShape | undefined;
74
- } & (T extends 'line' ? Line & {
77
+ } & ((Line & {
75
78
  type: 'line';
76
- } : T extends 'picture' ? Picture & {
79
+ }) | (Picture & {
80
+ type: 'picture';
77
81
  img: HTMLImageElement;
78
82
  flipX?: boolean;
79
83
  flipY?: boolean;
80
84
  ratio?: number;
81
- type: 'picture';
82
- } : T extends 'text' ? Text & {
85
+ }) | (Text & {
86
+ type: 'text';
83
87
  flipX?: boolean;
84
88
  flipY?: boolean;
85
89
  ratio?: number;
86
- type: 'text';
87
- } : T extends 'rect' ? Rect & {
90
+ }) | (Rect & {
88
91
  type: 'rect';
89
- } : T extends 'square' ? Rect & {
92
+ }) | (Rect & {
90
93
  type: 'square';
91
- } : T extends 'circle' ? Circle & {
94
+ }) | (Circle & {
92
95
  type: 'circle';
93
- } : T extends 'ellipse' ? Ellipse & {
96
+ }) | (Ellipse & {
94
97
  type: 'ellipse';
95
- } : T extends 'triangle' ? Triangle & {
98
+ }) | (Triangle & {
96
99
  type: 'triangle';
97
- } : T extends 'polygon' ? Polygon & {
100
+ }) | (Polygon & {
98
101
  type: 'polygon';
99
- } : T extends 'curve' ? Curve & {
102
+ }) | (Curve & {
100
103
  type: 'curve';
101
- } : T extends 'brush' ? Brush & {
104
+ }) | (Brush & {
102
105
  type: 'brush';
103
106
  scaleX?: number;
104
107
  scaleY?: number;
105
- } : T extends 'group' ? Rect & {
106
- shapes: ShapeEntity[];
108
+ }) | (Rect & {
107
109
  type: 'group';
108
- } : never);
110
+ shapes: ShapeEntity[];
111
+ }));
112
+ export type DrawableShape<T extends ShapeType = ShapeType> = GenericDrawableShape & {
113
+ type: T;
114
+ };
109
115
  export type ExportedDrawableShape<T extends ShapeType = ShapeType> = T extends 'picture' ? Omit<DrawableShape<'picture'>, 'img'> : DrawableShape<T>;
110
116
  export type TriangleEntity = DrawableShape<'triangle'> & {
111
117
  path: Path2D;
@@ -124,43 +130,18 @@ export type ShapeEntity<T extends Exclude<ShapeType, 'triangle'> = Exclude<Shape
124
130
  center: Point;
125
131
  boundingBox: Rect;
126
132
  };
127
- path?: Path2D | undefined;
128
- } & DrawableShape<T> & (T extends 'line' ? {
129
- selection?: SelectionLinesType | undefined;
130
- arrows?: TriangleEntity[];
133
+ path: Path2D;
134
+ } & DrawableShape<T> & ({
131
135
  type: 'line';
132
- } : T extends 'picture' ? {
133
- img: HTMLImageElement;
134
- selection?: SelectionDefaultType | undefined;
135
- type: 'picture';
136
- } : T extends 'text' ? {
137
- selection?: SelectionDefaultType | undefined;
138
- type: 'text';
139
- } : T extends 'rect' ? {
140
- selection?: SelectionDefaultType | undefined;
141
- type: 'rect';
142
- } : T extends 'square' ? {
143
- selection?: SelectionDefaultType | undefined;
144
- type: 'square';
145
- } : T extends 'circle' ? {
146
- selection?: SelectionDefaultType | undefined;
147
- type: 'circle';
148
- } : T extends 'ellipse' ? {
149
- selection?: SelectionDefaultType | undefined;
150
- type: 'ellipse';
151
- } : T extends 'polygon' ? {
152
136
  selection?: SelectionLinesType | undefined;
153
- type: 'polygon';
154
- } : T extends 'curve' ? {
137
+ arrows?: TriangleEntity[];
138
+ } | {
139
+ type: 'polygon' | 'curve';
155
140
  selection?: SelectionLinesType | undefined;
156
- type: 'curve';
157
- } : T extends 'brush' ? {
141
+ } | {
142
+ type: 'text' | 'picture' | 'rect' | 'square' | 'circle' | 'ellipse' | 'group' | 'brush';
158
143
  selection?: SelectionDefaultType | undefined;
159
- type: 'brush';
160
- } : T extends 'group' ? {
161
- selection?: SelectionDefaultType | undefined;
162
- type: 'group';
163
- } : never);
144
+ });
164
145
  export type StateData = {
165
146
  shapes?: DrawableShape[];
166
147
  config?: {
@@ -169,3 +150,4 @@ export type StateData = {
169
150
  };
170
151
  };
171
152
  export type SelectionType = ShapeEntity;
153
+ export {};