@yorab/react-paint 0.2.2
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/Changelog.md +26 -0
- package/README.md +99 -0
- package/dist/components/App.d.ts +20 -0
- package/dist/components/App.js +533 -0
- package/dist/components/Canvas.d.ts +28 -0
- package/dist/components/Canvas.js +188 -0
- package/dist/components/common/Button.d.ts +14 -0
- package/dist/components/common/Button.js +97 -0
- package/dist/components/common/Loading.d.ts +6 -0
- package/dist/components/common/Loading.js +66 -0
- package/dist/components/common/Modal.d.ts +8 -0
- package/dist/components/common/Modal.js +41 -0
- package/dist/components/common/Panel.d.ts +10 -0
- package/dist/components/common/Panel.js +48 -0
- package/dist/components/common/Snackbar.d.ts +7 -0
- package/dist/components/common/Snackbar.js +75 -0
- package/dist/components/settings/ColorField.d.ts +12 -0
- package/dist/components/settings/ColorField.js +128 -0
- package/dist/components/settings/DeleteButton.d.ts +9 -0
- package/dist/components/settings/DeleteButton.js +36 -0
- package/dist/components/settings/FontFamilyField.d.ts +10 -0
- package/dist/components/settings/FontFamilyField.js +57 -0
- package/dist/components/settings/LayoutButton.d.ts +8 -0
- package/dist/components/settings/LayoutButton.js +37 -0
- package/dist/components/settings/Layouts.d.ts +18 -0
- package/dist/components/settings/Layouts.js +218 -0
- package/dist/components/settings/LineArrowField.d.ts +10 -0
- package/dist/components/settings/LineArrowField.js +59 -0
- package/dist/components/settings/LineTypeField.d.ts +14 -0
- package/dist/components/settings/LineTypeField.js +57 -0
- package/dist/components/settings/PointsNumberField.d.ts +11 -0
- package/dist/components/settings/PointsNumberField.js +51 -0
- package/dist/components/settings/RangeField.d.ts +16 -0
- package/dist/components/settings/RangeField.js +90 -0
- package/dist/components/settings/SelectField.d.ts +16 -0
- package/dist/components/settings/SelectField.js +82 -0
- package/dist/components/settings/SettingsBar.d.ts +16 -0
- package/dist/components/settings/SettingsBar.js +262 -0
- package/dist/components/toolbox/EditTextBox.d.ts +10 -0
- package/dist/components/toolbox/EditTextBox.js +89 -0
- package/dist/components/toolbox/LoadFileTool.d.ts +11 -0
- package/dist/components/toolbox/LoadFileTool.js +58 -0
- package/dist/components/toolbox/MenuGroup.d.ts +23 -0
- package/dist/components/toolbox/MenuGroup.js +173 -0
- package/dist/components/toolbox/PictureUrlInput.d.ts +7 -0
- package/dist/components/toolbox/PictureUrlInput.js +96 -0
- package/dist/components/toolbox/Tool.d.ts +13 -0
- package/dist/components/toolbox/Tool.js +41 -0
- package/dist/components/toolbox/Toolbar.d.ts +20 -0
- package/dist/components/toolbox/Toolbar.js +205 -0
- package/dist/components/toolbox/ToolbarGroup.d.ts +18 -0
- package/dist/components/toolbox/ToolbarGroup.js +139 -0
- package/dist/constants/draw.d.ts +2 -0
- package/dist/constants/draw.js +10 -0
- package/dist/constants/icons.d.ts +36 -0
- package/dist/constants/icons.js +80 -0
- package/dist/constants/shapes.d.ts +5 -0
- package/dist/constants/shapes.js +14 -0
- package/dist/constants/snackbar.d.ts +11 -0
- package/dist/constants/snackbar.js +23 -0
- package/dist/constants/style.d.ts +12 -0
- package/dist/constants/style.js +30 -0
- package/dist/hooks/useComponent.d.ts +9 -0
- package/dist/hooks/useComponent.js +48 -0
- package/dist/hooks/useDrag.d.ts +15 -0
- package/dist/hooks/useDrag.js +100 -0
- package/dist/hooks/useDrawableCanvas.d.ts +30 -0
- package/dist/hooks/useDrawableCanvas.js +250 -0
- package/dist/hooks/useKeyboard.d.ts +15 -0
- package/dist/hooks/useKeyboard.js +123 -0
- package/dist/hooks/useShapes.d.ts +22 -0
- package/dist/hooks/useShapes.js +229 -0
- package/dist/hooks/useSnackbar.d.ts +16 -0
- package/dist/hooks/useSnackbar.js +86 -0
- package/dist/schemas/drawableShape.json +1021 -0
- package/dist/styles.css +88 -0
- package/dist/types/Mode.d.ts +51 -0
- package/dist/types/Mode.js +17 -0
- package/dist/types/Shapes.d.ts +122 -0
- package/dist/types/Shapes.js +35 -0
- package/dist/types/keyboard.d.ts +15 -0
- package/dist/types/keyboard.js +28 -0
- package/dist/utils/data.d.ts +4 -0
- package/dist/utils/data.js +178 -0
- package/dist/utils/draw.d.ts +18 -0
- package/dist/utils/draw.js +422 -0
- package/dist/utils/file.d.ts +33 -0
- package/dist/utils/file.js +220 -0
- package/dist/utils/intersect.d.ts +8 -0
- package/dist/utils/intersect.js +194 -0
- package/dist/utils/selection.d.ts +7 -0
- package/dist/utils/selection.js +88 -0
- package/dist/utils/shapeData.d.ts +5 -0
- package/dist/utils/shapeData.js +178 -0
- package/dist/utils/string.d.ts +3 -0
- package/dist/utils/string.js +42 -0
- package/dist/utils/style.d.ts +2 -0
- package/dist/utils/style.js +46 -0
- package/dist/utils/toolbar.d.ts +12 -0
- package/dist/utils/toolbar.js +37 -0
- package/dist/utils/transform.d.ts +271 -0
- package/dist/utils/transform.js +371 -0
- package/package.json +79 -0
|
@@ -0,0 +1,271 @@
|
|
|
1
|
+
import { SelectionModeData, SelectionModeResize } from 'types/Mode';
|
|
2
|
+
import { DrawableCircle, DrawableEllipse, Point, DrawableShape, DrawablePicture, Rect, DrawableLine, DrawablePolygon, DrawableBrush, DrawableCurve } from 'types/Shapes';
|
|
3
|
+
export declare const getNormalizedSize: (originalShape: Rect, width: number, height: number) => number[];
|
|
4
|
+
export declare const translateShape: (shape: DrawableShape, cursorPosition: Point, originalShape: DrawableShape, originalCursorPosition: Point) => DrawableShape;
|
|
5
|
+
export declare const rotateShape: (shape: DrawableShape, cursorPosition: Point, originalShape: DrawableShape, originalCursorPosition: Point, shapeCenter: Point) => {
|
|
6
|
+
rotation: number;
|
|
7
|
+
visible?: boolean | undefined;
|
|
8
|
+
locked?: boolean | undefined;
|
|
9
|
+
style?: {
|
|
10
|
+
fillColor?: string | undefined;
|
|
11
|
+
globalAlpha?: number | undefined;
|
|
12
|
+
strokeColor?: string | undefined;
|
|
13
|
+
lineWidth?: number | undefined;
|
|
14
|
+
lineDash?: number | undefined;
|
|
15
|
+
lineArrow?: number | undefined;
|
|
16
|
+
pointsCount?: number | undefined;
|
|
17
|
+
fontFamily?: string | undefined;
|
|
18
|
+
} | undefined;
|
|
19
|
+
x: number;
|
|
20
|
+
y: number;
|
|
21
|
+
width: number;
|
|
22
|
+
height: number;
|
|
23
|
+
id: string;
|
|
24
|
+
translation: Point;
|
|
25
|
+
type: import("types/Shapes").ShapeEnum.rect;
|
|
26
|
+
} | {
|
|
27
|
+
rotation: number;
|
|
28
|
+
visible?: boolean | undefined;
|
|
29
|
+
locked?: boolean | undefined;
|
|
30
|
+
style?: {
|
|
31
|
+
fillColor?: string | undefined;
|
|
32
|
+
globalAlpha?: number | undefined;
|
|
33
|
+
strokeColor?: string | undefined;
|
|
34
|
+
lineWidth?: number | undefined;
|
|
35
|
+
lineDash?: number | undefined;
|
|
36
|
+
lineArrow?: number | undefined;
|
|
37
|
+
pointsCount?: number | undefined;
|
|
38
|
+
fontFamily?: string | undefined;
|
|
39
|
+
} | undefined;
|
|
40
|
+
x: number;
|
|
41
|
+
y: number;
|
|
42
|
+
width: number;
|
|
43
|
+
height: number;
|
|
44
|
+
id: string;
|
|
45
|
+
translation: Point;
|
|
46
|
+
type: import("types/Shapes").ShapeEnum.square;
|
|
47
|
+
} | {
|
|
48
|
+
rotation: number;
|
|
49
|
+
visible?: boolean | undefined;
|
|
50
|
+
locked?: boolean | undefined;
|
|
51
|
+
style?: {
|
|
52
|
+
fillColor?: string | undefined;
|
|
53
|
+
globalAlpha?: number | undefined;
|
|
54
|
+
strokeColor?: string | undefined;
|
|
55
|
+
lineWidth?: number | undefined;
|
|
56
|
+
lineDash?: number | undefined;
|
|
57
|
+
lineArrow?: number | undefined;
|
|
58
|
+
pointsCount?: number | undefined;
|
|
59
|
+
fontFamily?: string | undefined;
|
|
60
|
+
} | undefined;
|
|
61
|
+
x: number;
|
|
62
|
+
y: number;
|
|
63
|
+
width: number;
|
|
64
|
+
height: number;
|
|
65
|
+
src: string;
|
|
66
|
+
img: HTMLImageElement;
|
|
67
|
+
id: string;
|
|
68
|
+
translation: Point;
|
|
69
|
+
type: import("types/Shapes").ShapeEnum.picture;
|
|
70
|
+
} | {
|
|
71
|
+
rotation: number;
|
|
72
|
+
visible?: boolean | undefined;
|
|
73
|
+
locked?: boolean | undefined;
|
|
74
|
+
style?: {
|
|
75
|
+
fillColor?: string | undefined;
|
|
76
|
+
globalAlpha?: number | undefined;
|
|
77
|
+
strokeColor?: string | undefined;
|
|
78
|
+
lineWidth?: number | undefined;
|
|
79
|
+
lineDash?: number | undefined;
|
|
80
|
+
lineArrow?: number | undefined;
|
|
81
|
+
pointsCount?: number | undefined;
|
|
82
|
+
fontFamily?: string | undefined;
|
|
83
|
+
} | undefined;
|
|
84
|
+
x: number;
|
|
85
|
+
y: number;
|
|
86
|
+
width: number;
|
|
87
|
+
height: number;
|
|
88
|
+
value: string[];
|
|
89
|
+
fontSize: number;
|
|
90
|
+
id: string;
|
|
91
|
+
translation: Point;
|
|
92
|
+
type: import("types/Shapes").ShapeEnum.text;
|
|
93
|
+
} | {
|
|
94
|
+
rotation: number;
|
|
95
|
+
visible?: boolean | undefined;
|
|
96
|
+
locked?: boolean | undefined;
|
|
97
|
+
style?: {
|
|
98
|
+
fillColor?: string | undefined;
|
|
99
|
+
globalAlpha?: number | undefined;
|
|
100
|
+
strokeColor?: string | undefined;
|
|
101
|
+
lineWidth?: number | undefined;
|
|
102
|
+
lineDash?: number | undefined;
|
|
103
|
+
lineArrow?: number | undefined;
|
|
104
|
+
pointsCount?: number | undefined;
|
|
105
|
+
fontFamily?: string | undefined;
|
|
106
|
+
} | undefined;
|
|
107
|
+
points: [Point, Point];
|
|
108
|
+
id: string;
|
|
109
|
+
translation: Point;
|
|
110
|
+
type: import("types/Shapes").ShapeEnum.line;
|
|
111
|
+
} | {
|
|
112
|
+
rotation: number;
|
|
113
|
+
visible?: boolean | undefined;
|
|
114
|
+
locked?: boolean | undefined;
|
|
115
|
+
style?: {
|
|
116
|
+
fillColor?: string | undefined;
|
|
117
|
+
globalAlpha?: number | undefined;
|
|
118
|
+
strokeColor?: string | undefined;
|
|
119
|
+
lineWidth?: number | undefined;
|
|
120
|
+
lineDash?: number | undefined;
|
|
121
|
+
lineArrow?: number | undefined;
|
|
122
|
+
pointsCount?: number | undefined;
|
|
123
|
+
fontFamily?: string | undefined;
|
|
124
|
+
} | undefined;
|
|
125
|
+
points: Point[];
|
|
126
|
+
id: string;
|
|
127
|
+
translation: Point;
|
|
128
|
+
type: import("types/Shapes").ShapeEnum.polygon;
|
|
129
|
+
} | {
|
|
130
|
+
rotation: number;
|
|
131
|
+
visible?: boolean | undefined;
|
|
132
|
+
locked?: boolean | undefined;
|
|
133
|
+
style?: {
|
|
134
|
+
fillColor?: string | undefined;
|
|
135
|
+
globalAlpha?: number | undefined;
|
|
136
|
+
strokeColor?: string | undefined;
|
|
137
|
+
lineWidth?: number | undefined;
|
|
138
|
+
lineDash?: number | undefined;
|
|
139
|
+
lineArrow?: number | undefined;
|
|
140
|
+
pointsCount?: number | undefined;
|
|
141
|
+
fontFamily?: string | undefined;
|
|
142
|
+
} | undefined;
|
|
143
|
+
points: Point[];
|
|
144
|
+
id: string;
|
|
145
|
+
translation: Point;
|
|
146
|
+
type: import("types/Shapes").ShapeEnum.curve;
|
|
147
|
+
} | {
|
|
148
|
+
rotation: number;
|
|
149
|
+
visible?: boolean | undefined;
|
|
150
|
+
locked?: boolean | undefined;
|
|
151
|
+
style?: {
|
|
152
|
+
fillColor?: string | undefined;
|
|
153
|
+
globalAlpha?: number | undefined;
|
|
154
|
+
strokeColor?: string | undefined;
|
|
155
|
+
lineWidth?: number | undefined;
|
|
156
|
+
lineDash?: number | undefined;
|
|
157
|
+
lineArrow?: number | undefined;
|
|
158
|
+
pointsCount?: number | undefined;
|
|
159
|
+
fontFamily?: string | undefined;
|
|
160
|
+
} | undefined;
|
|
161
|
+
points: Point[][];
|
|
162
|
+
id: string;
|
|
163
|
+
translation: Point;
|
|
164
|
+
type: import("types/Shapes").ShapeEnum.brush;
|
|
165
|
+
} | {
|
|
166
|
+
rotation: number;
|
|
167
|
+
visible?: boolean | undefined;
|
|
168
|
+
locked?: boolean | undefined;
|
|
169
|
+
style?: {
|
|
170
|
+
fillColor?: string | undefined;
|
|
171
|
+
globalAlpha?: number | undefined;
|
|
172
|
+
strokeColor?: string | undefined;
|
|
173
|
+
lineWidth?: number | undefined;
|
|
174
|
+
lineDash?: number | undefined;
|
|
175
|
+
lineArrow?: number | undefined;
|
|
176
|
+
pointsCount?: number | undefined;
|
|
177
|
+
fontFamily?: string | undefined;
|
|
178
|
+
} | undefined;
|
|
179
|
+
x: number;
|
|
180
|
+
y: number;
|
|
181
|
+
radius: number;
|
|
182
|
+
id: string;
|
|
183
|
+
translation: Point;
|
|
184
|
+
type: import("types/Shapes").ShapeEnum.circle;
|
|
185
|
+
} | {
|
|
186
|
+
rotation: number;
|
|
187
|
+
visible?: boolean | undefined;
|
|
188
|
+
locked?: boolean | undefined;
|
|
189
|
+
style?: {
|
|
190
|
+
fillColor?: string | undefined;
|
|
191
|
+
globalAlpha?: number | undefined;
|
|
192
|
+
strokeColor?: string | undefined;
|
|
193
|
+
lineWidth?: number | undefined;
|
|
194
|
+
lineDash?: number | undefined;
|
|
195
|
+
lineArrow?: number | undefined;
|
|
196
|
+
pointsCount?: number | undefined;
|
|
197
|
+
fontFamily?: string | undefined;
|
|
198
|
+
} | undefined;
|
|
199
|
+
x: number;
|
|
200
|
+
y: number;
|
|
201
|
+
radiusX: number;
|
|
202
|
+
radiusY: number;
|
|
203
|
+
id: string;
|
|
204
|
+
translation: Point;
|
|
205
|
+
type: import("types/Shapes").ShapeEnum.ellipse;
|
|
206
|
+
};
|
|
207
|
+
export declare const paintNewPointToShape: (shape: DrawableBrush, cursorPosition: Point) => {
|
|
208
|
+
points: Point[][];
|
|
209
|
+
visible?: boolean | undefined;
|
|
210
|
+
locked?: boolean | undefined;
|
|
211
|
+
style?: {
|
|
212
|
+
fillColor?: string | undefined;
|
|
213
|
+
globalAlpha?: number | undefined;
|
|
214
|
+
strokeColor?: string | undefined;
|
|
215
|
+
lineWidth?: number | undefined;
|
|
216
|
+
lineDash?: number | undefined;
|
|
217
|
+
lineArrow?: number | undefined;
|
|
218
|
+
pointsCount?: number | undefined;
|
|
219
|
+
fontFamily?: string | undefined;
|
|
220
|
+
} | undefined;
|
|
221
|
+
id: string;
|
|
222
|
+
translation: Point;
|
|
223
|
+
rotation: number;
|
|
224
|
+
type: import("types/Shapes").ShapeEnum.brush;
|
|
225
|
+
};
|
|
226
|
+
export declare const createNewPointGroupToShape: (shape: DrawableBrush, cursorPosition: Point) => {
|
|
227
|
+
points: Point[][];
|
|
228
|
+
visible?: boolean | undefined;
|
|
229
|
+
locked?: boolean | undefined;
|
|
230
|
+
style?: {
|
|
231
|
+
fillColor?: string | undefined;
|
|
232
|
+
globalAlpha?: number | undefined;
|
|
233
|
+
strokeColor?: string | undefined;
|
|
234
|
+
lineWidth?: number | undefined;
|
|
235
|
+
lineDash?: number | undefined;
|
|
236
|
+
lineArrow?: number | undefined;
|
|
237
|
+
pointsCount?: number | undefined;
|
|
238
|
+
fontFamily?: string | undefined;
|
|
239
|
+
} | undefined;
|
|
240
|
+
id: string;
|
|
241
|
+
translation: Point;
|
|
242
|
+
rotation: number;
|
|
243
|
+
type: import("types/Shapes").ShapeEnum.brush;
|
|
244
|
+
};
|
|
245
|
+
export declare const resizeBrush: (cursorPosition: Point, canvasOffset: Point, originalShape: DrawableBrush, selectionMode: SelectionModeResize) => DrawableBrush;
|
|
246
|
+
export declare const resizeLine: (cursorPosition: Point, canvasOffset: Point, originalShape: DrawableLine | DrawablePolygon | DrawableCurve, selectionMode: SelectionModeResize<number>) => DrawableLine | DrawablePolygon | DrawableCurve;
|
|
247
|
+
export declare const updatePolygonLinesCount: (shape: DrawablePolygon, newPointsCount: number) => DrawablePolygon;
|
|
248
|
+
export declare const resizeCircle: (cursorPosition: Point, canvasOffset: Point, originalShape: DrawableCircle, selectionMode: SelectionModeResize) => DrawableCircle;
|
|
249
|
+
export declare const resizeEllipse: (cursorPosition: Point, canvasOffset: Point, originalShape: DrawableEllipse, selectionMode: SelectionModeResize) => DrawableEllipse;
|
|
250
|
+
export declare const resizeRect: <T extends DrawableShape & import("types/Shapes").StyledShape & {
|
|
251
|
+
x: number;
|
|
252
|
+
y: number;
|
|
253
|
+
width: number;
|
|
254
|
+
height: number;
|
|
255
|
+
}>(cursorPosition: Point, canvasOffset: Point, originalShape: T, selectionMode: SelectionModeResize, keepRatio?: boolean) => T;
|
|
256
|
+
export declare const resizeText: <T extends DrawableShape & import("types/Shapes").StyledShape & {
|
|
257
|
+
x: number;
|
|
258
|
+
y: number;
|
|
259
|
+
width: number;
|
|
260
|
+
height: number;
|
|
261
|
+
} & {
|
|
262
|
+
value: string[];
|
|
263
|
+
fontSize: number;
|
|
264
|
+
}>(ctx: CanvasRenderingContext2D, cursorPosition: Point, canvasOffset: Point, originalShape: T, selectionMode: SelectionModeResize) => T;
|
|
265
|
+
export declare const resizePicture: (cursorPosition: Point, canvasOffset: Point, originalShape: DrawablePicture, selectionMode: SelectionModeResize) => DrawablePicture;
|
|
266
|
+
export declare const resizeShape: (ctx: CanvasRenderingContext2D, shape: DrawableShape, cursorPosition: Point, canvasOffset: Point, originalShape: DrawableShape, selectionMode: SelectionModeData<Point | number>) => DrawableShape;
|
|
267
|
+
export declare const transformShape: (ctx: CanvasRenderingContext2D, shape: DrawableShape, cursorPosition: Point, canvasOffset: Point, selectionMode: SelectionModeData<Point | number>) => DrawableShape;
|
|
268
|
+
export declare const calculateTextFontSize: (ctx: CanvasRenderingContext2D, text: string[], maxWidth: number, fontFamily?: string | undefined) => number;
|
|
269
|
+
export declare const calculateTextWidth: (ctx: CanvasRenderingContext2D, text: string[], fontSize: number, fontFamily?: string | undefined) => number;
|
|
270
|
+
export declare const degreesToRadians: (degrees: number) => number;
|
|
271
|
+
export declare const radiansToDegrees: (radians: number) => number;
|
|
@@ -0,0 +1,371 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.updatePolygonLinesCount = exports.translateShape = exports.transformShape = exports.rotateShape = exports.resizeText = exports.resizeShape = exports.resizeRect = exports.resizePicture = exports.resizeLine = exports.resizeEllipse = exports.resizeCircle = exports.resizeBrush = exports.radiansToDegrees = exports.paintNewPointToShape = exports.getNormalizedSize = exports.degreesToRadians = exports.createNewPointGroupToShape = exports.calculateTextWidth = exports.calculateTextFontSize = void 0;
|
|
9
|
+
|
|
10
|
+
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
11
|
+
|
|
12
|
+
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
|
13
|
+
|
|
14
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
15
|
+
|
|
16
|
+
var _fp = _interopRequireDefault(require("lodash/fp"));
|
|
17
|
+
|
|
18
|
+
var _shapeData = require("./shapeData");
|
|
19
|
+
|
|
20
|
+
var _shapes = require("../constants/shapes");
|
|
21
|
+
|
|
22
|
+
var _Mode = require("../types/Mode");
|
|
23
|
+
|
|
24
|
+
var _intersect = require("./intersect");
|
|
25
|
+
|
|
26
|
+
var _style = require("../constants/style");
|
|
27
|
+
|
|
28
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
29
|
+
|
|
30
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2["default"])(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
31
|
+
|
|
32
|
+
var getNormalizedSize = function getNormalizedSize(originalShape, width, height) {
|
|
33
|
+
var originalRatio = originalShape.width / originalShape.height;
|
|
34
|
+
var newRatio = width / height;
|
|
35
|
+
|
|
36
|
+
if (newRatio > originalRatio || height < 0) {
|
|
37
|
+
return width > originalShape.width ? [width, width / originalRatio] : [height * originalRatio, height];
|
|
38
|
+
} else if (newRatio < originalRatio) {
|
|
39
|
+
return height > originalShape.height ? [height * originalRatio, height] : [width, width / originalRatio];
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
return [width, height];
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
exports.getNormalizedSize = getNormalizedSize;
|
|
46
|
+
|
|
47
|
+
var translateShape = function translateShape(shape, cursorPosition, originalShape, originalCursorPosition) {
|
|
48
|
+
return _objectSpread(_objectSpread({}, shape), {
|
|
49
|
+
translation: [originalShape.translation[0] + cursorPosition[0] - originalCursorPosition[0], originalShape.translation[1] + cursorPosition[1] - originalCursorPosition[1]]
|
|
50
|
+
});
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
exports.translateShape = translateShape;
|
|
54
|
+
|
|
55
|
+
var rotateShape = function rotateShape(shape, cursorPosition, originalShape, originalCursorPosition, shapeCenter) {
|
|
56
|
+
var p1x = shapeCenter[0] + originalShape.translation[0] - originalCursorPosition[0];
|
|
57
|
+
var p1y = shapeCenter[1] + originalShape.translation[1] - originalCursorPosition[1];
|
|
58
|
+
var p2x = shapeCenter[0] + originalShape.translation[0] - cursorPosition[0];
|
|
59
|
+
var p2y = shapeCenter[1] + originalShape.translation[1] - cursorPosition[1];
|
|
60
|
+
var rotation = originalShape.rotation + Math.atan2(p2y, p2x) - Math.atan2(p1y, p1x);
|
|
61
|
+
return _objectSpread(_objectSpread({}, shape), {
|
|
62
|
+
rotation: rotation
|
|
63
|
+
});
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
exports.rotateShape = rotateShape;
|
|
67
|
+
|
|
68
|
+
var paintNewPointToShape = function paintNewPointToShape(shape, cursorPosition) {
|
|
69
|
+
return _objectSpread(_objectSpread({}, shape), {
|
|
70
|
+
points: _fp["default"].set(shape.points.length - 1, [].concat((0, _toConsumableArray2["default"])(shape.points[shape.points.length - 1]), [cursorPosition]), shape.points)
|
|
71
|
+
});
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
exports.paintNewPointToShape = paintNewPointToShape;
|
|
75
|
+
|
|
76
|
+
var createNewPointGroupToShape = function createNewPointGroupToShape(shape, cursorPosition) {
|
|
77
|
+
return _objectSpread(_objectSpread({}, shape), {
|
|
78
|
+
points: _fp["default"].set(shape.points.length, [cursorPosition], shape.points)
|
|
79
|
+
});
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
exports.createNewPointGroupToShape = createNewPointGroupToShape;
|
|
83
|
+
|
|
84
|
+
var resizeBrush = function resizeBrush(cursorPosition, canvasOffset, originalShape, selectionMode) {
|
|
85
|
+
var _getShapeInfos = (0, _shapeData.getShapeInfos)(originalShape),
|
|
86
|
+
center = _getShapeInfos.center,
|
|
87
|
+
borders = _getShapeInfos.borders;
|
|
88
|
+
|
|
89
|
+
var cursorPositionBeforeResize = (0, _intersect.getPointPositionAfterCanvasTransformation)(cursorPosition, canvasOffset, originalShape.translation, originalShape.rotation, center);
|
|
90
|
+
var scaledWidth = selectionMode.anchor[0] === 0.5 ? 1 : selectionMode.anchor[0] === 0 ? (borders.x + borders.width - cursorPositionBeforeResize[0] + _shapes.SELECTION_PADDING * -2) / (borders.width + _shapes.SELECTION_PADDING * -2) : (cursorPositionBeforeResize[0] - borders.x - _shapes.SELECTION_PADDING * 2) / (borders.width - _shapes.SELECTION_PADDING * 2);
|
|
91
|
+
var scaledHeight = selectionMode.anchor[1] === 0.5 ? 1 : selectionMode.anchor[1] === 0 ? (borders.y + borders.height - cursorPositionBeforeResize[1] + _shapes.SELECTION_PADDING * -2) / (borders.height + _shapes.SELECTION_PADDING * -2) : (cursorPositionBeforeResize[1] - borders.y - _shapes.SELECTION_PADDING * 2) / (borders.height - _shapes.SELECTION_PADDING * 2);
|
|
92
|
+
|
|
93
|
+
var shapeWithNewDimensions = _objectSpread(_objectSpread({}, originalShape), {}, {
|
|
94
|
+
points: originalShape.points.map(function (points) {
|
|
95
|
+
return points.map(function (point) {
|
|
96
|
+
return [(point[0] - borders.x) * scaledWidth + borders.x, (point[1] - borders.y) * scaledHeight + borders.y];
|
|
97
|
+
});
|
|
98
|
+
})
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
var _getShapeInfos2 = (0, _shapeData.getShapeInfos)(shapeWithNewDimensions),
|
|
102
|
+
shapeWithNewDimensionsCenter = _getShapeInfos2.center,
|
|
103
|
+
shapeWithNewDimensionsBorders = _getShapeInfos2.borders;
|
|
104
|
+
|
|
105
|
+
var _getRectOppositeAncho = getRectOppositeAnchorAbsolutePosition(selectionMode.anchor, center, _objectSpread(_objectSpread({}, originalShape), borders)),
|
|
106
|
+
_getRectOppositeAncho2 = (0, _slicedToArray2["default"])(_getRectOppositeAncho, 2),
|
|
107
|
+
oppTrueX = _getRectOppositeAncho2[0],
|
|
108
|
+
oppTrueY = _getRectOppositeAncho2[1];
|
|
109
|
+
|
|
110
|
+
var _getRectOppositeAncho3 = getRectOppositeAnchorAbsolutePosition(selectionMode.anchor, shapeWithNewDimensionsCenter, _objectSpread(_objectSpread({}, shapeWithNewDimensions), shapeWithNewDimensionsBorders), [scaledWidth < 0, scaledHeight < 0]),
|
|
111
|
+
_getRectOppositeAncho4 = (0, _slicedToArray2["default"])(_getRectOppositeAncho3, 2),
|
|
112
|
+
newOppTrueX = _getRectOppositeAncho4[0],
|
|
113
|
+
newOppTrueY = _getRectOppositeAncho4[1];
|
|
114
|
+
|
|
115
|
+
return _objectSpread(_objectSpread({}, shapeWithNewDimensions), {
|
|
116
|
+
translation: [originalShape.translation[0] - (newOppTrueX - oppTrueX), originalShape.translation[1] - (newOppTrueY - oppTrueY)]
|
|
117
|
+
});
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
exports.resizeBrush = resizeBrush;
|
|
121
|
+
|
|
122
|
+
var resizeLine = function resizeLine(cursorPosition, canvasOffset, originalShape, selectionMode) {
|
|
123
|
+
var _getShapeInfos3 = (0, _shapeData.getShapeInfos)(originalShape),
|
|
124
|
+
center = _getShapeInfos3.center;
|
|
125
|
+
|
|
126
|
+
var cursorPositionBeforeResize = (0, _intersect.getPointPositionAfterCanvasTransformation)(cursorPosition, canvasOffset, originalShape.translation, originalShape.rotation, center);
|
|
127
|
+
|
|
128
|
+
var updatedShape = _fp["default"].set(['points', selectionMode.anchor], cursorPositionBeforeResize, originalShape);
|
|
129
|
+
|
|
130
|
+
return updatedShape;
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
exports.resizeLine = resizeLine;
|
|
134
|
+
|
|
135
|
+
var updatePolygonLinesCount = function updatePolygonLinesCount(shape, newPointsCount) {
|
|
136
|
+
var currentPointsCount = shape.points.length;
|
|
137
|
+
if (currentPointsCount === newPointsCount) return shape;
|
|
138
|
+
|
|
139
|
+
if (currentPointsCount > newPointsCount) {
|
|
140
|
+
return _fp["default"].set('points', shape.points.slice(0, newPointsCount), shape);
|
|
141
|
+
} else {
|
|
142
|
+
//TODO : better distribution for new points
|
|
143
|
+
var nbPointsToAdd = newPointsCount - currentPointsCount;
|
|
144
|
+
|
|
145
|
+
var newPoints = _fp["default"].flow(_fp["default"].range(0), _fp["default"].map(function (index) {
|
|
146
|
+
return [shape.points[0][0] + (shape.points[1][0] - shape.points[0][0]) * (index + 1) / (nbPointsToAdd + 1), shape.points[0][1] + (shape.points[1][1] - shape.points[0][1]) * (index + 1) / (nbPointsToAdd + 1)];
|
|
147
|
+
}))(nbPointsToAdd);
|
|
148
|
+
|
|
149
|
+
return _fp["default"].set('points', [shape.points[0]].concat((0, _toConsumableArray2["default"])(newPoints), (0, _toConsumableArray2["default"])(shape.points.slice(1, shape.points.length))), shape);
|
|
150
|
+
}
|
|
151
|
+
};
|
|
152
|
+
|
|
153
|
+
exports.updatePolygonLinesCount = updatePolygonLinesCount;
|
|
154
|
+
|
|
155
|
+
var resizeCircle = function resizeCircle(cursorPosition, canvasOffset, originalShape, selectionMode) {
|
|
156
|
+
var _getShapeInfos4 = (0, _shapeData.getShapeInfos)(originalShape),
|
|
157
|
+
center = _getShapeInfos4.center,
|
|
158
|
+
borders = _getShapeInfos4.borders;
|
|
159
|
+
|
|
160
|
+
var cursorPositionBeforeResize = (0, _intersect.getPointPositionAfterCanvasTransformation)(cursorPosition, canvasOffset, originalShape.translation, originalShape.rotation, center);
|
|
161
|
+
var newCursorPosition = [cursorPositionBeforeResize[0], cursorPositionBeforeResize[1]];
|
|
162
|
+
var scaledRadius = selectionMode.anchor[1] === 0.5 ? (selectionMode.anchor[0] === 0 ? borders.x + borders.width - newCursorPosition[0] + _shapes.SELECTION_PADDING * (selectionMode.anchor[0] === 0 ? -2 : 2) : newCursorPosition[0] - borders.x - _shapes.SELECTION_PADDING * (selectionMode.anchor[0] === 0 ? -2 : 2)) / 2 : (selectionMode.anchor[1] === 0 ? borders.y + borders.height - newCursorPosition[1] + _shapes.SELECTION_PADDING * (selectionMode.anchor[1] === 0 ? -2 : 2) : newCursorPosition[1] - borders.y - _shapes.SELECTION_PADDING * (selectionMode.anchor[1] === 0 ? -2 : 2)) / 2;
|
|
163
|
+
|
|
164
|
+
var shapeWithNewDimensions = _objectSpread(_objectSpread({}, originalShape), {
|
|
165
|
+
radius: Math.abs(scaledRadius)
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
var _getShapeInfos5 = (0, _shapeData.getShapeInfos)(shapeWithNewDimensions),
|
|
169
|
+
shapeWithNewDimensionsCenter = _getShapeInfos5.center;
|
|
170
|
+
|
|
171
|
+
var _getCircleOppositeAnc = getCircleOppositeAnchorAbsolutePosition(selectionMode.anchor, center, originalShape),
|
|
172
|
+
_getCircleOppositeAnc2 = (0, _slicedToArray2["default"])(_getCircleOppositeAnc, 2),
|
|
173
|
+
oppTrueX = _getCircleOppositeAnc2[0],
|
|
174
|
+
oppTrueY = _getCircleOppositeAnc2[1];
|
|
175
|
+
|
|
176
|
+
var _getCircleOppositeAnc3 = getCircleOppositeAnchorAbsolutePosition(selectionMode.anchor, shapeWithNewDimensionsCenter, shapeWithNewDimensions, [scaledRadius < 0, scaledRadius < 0]),
|
|
177
|
+
_getCircleOppositeAnc4 = (0, _slicedToArray2["default"])(_getCircleOppositeAnc3, 2),
|
|
178
|
+
newOppTrueX = _getCircleOppositeAnc4[0],
|
|
179
|
+
newOppTrueY = _getCircleOppositeAnc4[1];
|
|
180
|
+
|
|
181
|
+
return _objectSpread(_objectSpread({}, shapeWithNewDimensions), {
|
|
182
|
+
translation: [originalShape.translation[0] - (newOppTrueX - oppTrueX), originalShape.translation[1] - (newOppTrueY - oppTrueY)]
|
|
183
|
+
});
|
|
184
|
+
};
|
|
185
|
+
|
|
186
|
+
exports.resizeCircle = resizeCircle;
|
|
187
|
+
|
|
188
|
+
var resizeEllipse = function resizeEllipse(cursorPosition, canvasOffset, originalShape, selectionMode) {
|
|
189
|
+
var _getShapeInfos6 = (0, _shapeData.getShapeInfos)(originalShape),
|
|
190
|
+
center = _getShapeInfos6.center,
|
|
191
|
+
borders = _getShapeInfos6.borders;
|
|
192
|
+
|
|
193
|
+
var cursorPositionBeforeResize = (0, _intersect.getPointPositionAfterCanvasTransformation)(cursorPosition, canvasOffset, originalShape.translation, originalShape.rotation, center);
|
|
194
|
+
var newCursorPosition = [cursorPositionBeforeResize[0], cursorPositionBeforeResize[1]];
|
|
195
|
+
var scaledRadiusX = selectionMode.anchor[0] === 0.5 ? originalShape.radiusX : (selectionMode.anchor[0] === 0 ? borders.x + borders.width - newCursorPosition[0] + _shapes.SELECTION_PADDING * (selectionMode.anchor[0] === 0 ? -2 : 2) : newCursorPosition[0] - borders.x - _shapes.SELECTION_PADDING * (selectionMode.anchor[0] === 0 ? -2 : 2)) / 2;
|
|
196
|
+
var scaledRadiusY = selectionMode.anchor[1] === 0.5 ? originalShape.radiusY : (selectionMode.anchor[1] === 0 ? borders.y + borders.height - newCursorPosition[1] + _shapes.SELECTION_PADDING * (selectionMode.anchor[1] === 0 ? -2 : 2) : newCursorPosition[1] - borders.y - _shapes.SELECTION_PADDING * (selectionMode.anchor[1] === 0 ? -2 : 2)) / 2;
|
|
197
|
+
|
|
198
|
+
var shapeWithNewDimensions = _objectSpread(_objectSpread({}, originalShape), {
|
|
199
|
+
radiusX: Math.abs(scaledRadiusX),
|
|
200
|
+
radiusY: Math.abs(scaledRadiusY)
|
|
201
|
+
});
|
|
202
|
+
|
|
203
|
+
var _getShapeInfos7 = (0, _shapeData.getShapeInfos)(shapeWithNewDimensions),
|
|
204
|
+
shapeWithNewDimensionsCenter = _getShapeInfos7.center;
|
|
205
|
+
|
|
206
|
+
var _getEllipseOppositeAn = getEllipseOppositeAnchorAbsolutePosition(selectionMode.anchor, center, originalShape),
|
|
207
|
+
_getEllipseOppositeAn2 = (0, _slicedToArray2["default"])(_getEllipseOppositeAn, 2),
|
|
208
|
+
oppTrueX = _getEllipseOppositeAn2[0],
|
|
209
|
+
oppTrueY = _getEllipseOppositeAn2[1];
|
|
210
|
+
|
|
211
|
+
var _getEllipseOppositeAn3 = getEllipseOppositeAnchorAbsolutePosition(selectionMode.anchor, shapeWithNewDimensionsCenter, shapeWithNewDimensions, [scaledRadiusX < 0, scaledRadiusY < 0]),
|
|
212
|
+
_getEllipseOppositeAn4 = (0, _slicedToArray2["default"])(_getEllipseOppositeAn3, 2),
|
|
213
|
+
newOppTrueX = _getEllipseOppositeAn4[0],
|
|
214
|
+
newOppTrueY = _getEllipseOppositeAn4[1];
|
|
215
|
+
|
|
216
|
+
return _objectSpread(_objectSpread({}, shapeWithNewDimensions), {
|
|
217
|
+
translation: [originalShape.translation[0] - (newOppTrueX - oppTrueX), originalShape.translation[1] - (newOppTrueY - oppTrueY)]
|
|
218
|
+
});
|
|
219
|
+
};
|
|
220
|
+
|
|
221
|
+
exports.resizeEllipse = resizeEllipse;
|
|
222
|
+
|
|
223
|
+
var resizeRect = function resizeRect(cursorPosition, canvasOffset, originalShape, selectionMode) {
|
|
224
|
+
var keepRatio = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : false;
|
|
225
|
+
|
|
226
|
+
var _getShapeInfos8 = (0, _shapeData.getShapeInfos)(originalShape),
|
|
227
|
+
center = _getShapeInfos8.center,
|
|
228
|
+
borders = _getShapeInfos8.borders;
|
|
229
|
+
|
|
230
|
+
var cursorPositionBeforeResize = (0, _intersect.getPointPositionAfterCanvasTransformation)(cursorPosition, canvasOffset, originalShape.translation, originalShape.rotation, center);
|
|
231
|
+
var scaledWidth = selectionMode.anchor[0] === 0.5 ? originalShape.width : selectionMode.anchor[0] === 0 ? borders.x + borders.width - cursorPositionBeforeResize[0] + _shapes.SELECTION_PADDING * -2 : cursorPositionBeforeResize[0] - borders.x - _shapes.SELECTION_PADDING * 2;
|
|
232
|
+
var scaledHeight = selectionMode.anchor[1] === 0.5 ? originalShape.height : selectionMode.anchor[1] === 0 ? borders.y + borders.height - cursorPositionBeforeResize[1] + _shapes.SELECTION_PADDING * -2 : cursorPositionBeforeResize[1] - borders.y - _shapes.SELECTION_PADDING * 2;
|
|
233
|
+
|
|
234
|
+
var _ref = keepRatio ? getNormalizedSize(originalShape, scaledWidth, scaledHeight) : [scaledWidth, scaledHeight],
|
|
235
|
+
_ref2 = (0, _slicedToArray2["default"])(_ref, 2),
|
|
236
|
+
widthWithRatio = _ref2[0],
|
|
237
|
+
heightWithRatio = _ref2[1];
|
|
238
|
+
|
|
239
|
+
var shapeWithNewDimensions = _objectSpread(_objectSpread({}, originalShape), {}, {
|
|
240
|
+
width: Math.abs(widthWithRatio),
|
|
241
|
+
height: Math.abs(heightWithRatio)
|
|
242
|
+
});
|
|
243
|
+
|
|
244
|
+
var _getShapeInfos9 = (0, _shapeData.getShapeInfos)(shapeWithNewDimensions),
|
|
245
|
+
shapeWithNewDimensionsCenter = _getShapeInfos9.center;
|
|
246
|
+
|
|
247
|
+
var _getRectOppositeAncho5 = getRectOppositeAnchorAbsolutePosition(selectionMode.anchor, center, originalShape),
|
|
248
|
+
_getRectOppositeAncho6 = (0, _slicedToArray2["default"])(_getRectOppositeAncho5, 2),
|
|
249
|
+
oppTrueX = _getRectOppositeAncho6[0],
|
|
250
|
+
oppTrueY = _getRectOppositeAncho6[1];
|
|
251
|
+
|
|
252
|
+
var _getRectOppositeAncho7 = getRectOppositeAnchorAbsolutePosition(selectionMode.anchor, shapeWithNewDimensionsCenter, shapeWithNewDimensions, [widthWithRatio < 0, heightWithRatio < 0]),
|
|
253
|
+
_getRectOppositeAncho8 = (0, _slicedToArray2["default"])(_getRectOppositeAncho7, 2),
|
|
254
|
+
newOppTrueX = _getRectOppositeAncho8[0],
|
|
255
|
+
newOppTrueY = _getRectOppositeAncho8[1];
|
|
256
|
+
|
|
257
|
+
return _objectSpread(_objectSpread({}, shapeWithNewDimensions), {
|
|
258
|
+
translation: [originalShape.translation[0] - (newOppTrueX - oppTrueX), originalShape.translation[1] - (newOppTrueY - oppTrueY)]
|
|
259
|
+
});
|
|
260
|
+
};
|
|
261
|
+
|
|
262
|
+
exports.resizeRect = resizeRect;
|
|
263
|
+
|
|
264
|
+
var resizeText = function resizeText(ctx, cursorPosition, canvasOffset, originalShape, selectionMode) {
|
|
265
|
+
var _newRect$style;
|
|
266
|
+
|
|
267
|
+
var newRect = resizeRect(cursorPosition, canvasOffset, originalShape, selectionMode, true);
|
|
268
|
+
return _objectSpread(_objectSpread({}, newRect), {}, {
|
|
269
|
+
fontSize: calculateTextFontSize(ctx, newRect.value, newRect.width, (_newRect$style = newRect.style) === null || _newRect$style === void 0 ? void 0 : _newRect$style.fontFamily)
|
|
270
|
+
});
|
|
271
|
+
};
|
|
272
|
+
|
|
273
|
+
exports.resizeText = resizeText;
|
|
274
|
+
|
|
275
|
+
var getRectOppositeAnchorAbsolutePosition = function getRectOppositeAnchorAbsolutePosition(anchor, center, shape) {
|
|
276
|
+
var _ref3 = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : [false, false],
|
|
277
|
+
_ref4 = (0, _slicedToArray2["default"])(_ref3, 2),
|
|
278
|
+
negW = _ref4[0],
|
|
279
|
+
negH = _ref4[1];
|
|
280
|
+
|
|
281
|
+
var oppositeX = (anchor[0] === 0.5 ? shape.x + shape.width / 2 : anchor[0] === 0 ? shape.x + (negW ? 0 : shape.width) : shape.x + (negW ? shape.width : 0)) + shape.translation[0];
|
|
282
|
+
var oppositeY = (anchor[1] === 0.5 ? shape.y + shape.height / 2 : anchor[1] === 0 ? shape.y + (negH ? 0 : shape.height) : shape.y + (negH ? shape.height : 0)) + shape.translation[1];
|
|
283
|
+
return (0, _intersect.getPointPositionBeforeCanvasTransformation)([oppositeX, oppositeY], shape.translation, shape.rotation, center);
|
|
284
|
+
};
|
|
285
|
+
|
|
286
|
+
var getEllipseOppositeAnchorAbsolutePosition = function getEllipseOppositeAnchorAbsolutePosition(anchor, center, shape) {
|
|
287
|
+
var _ref5 = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : [false, false],
|
|
288
|
+
_ref6 = (0, _slicedToArray2["default"])(_ref5, 2),
|
|
289
|
+
negW = _ref6[0],
|
|
290
|
+
negH = _ref6[1];
|
|
291
|
+
|
|
292
|
+
var oppositeX = (anchor[0] === 0.5 ? shape.x + shape.radiusX / 2 : anchor[0] === 0 ? shape.x + (negW ? -shape.radiusX : shape.radiusX) : shape.x + (negW ? shape.radiusX : -shape.radiusX)) + shape.translation[0];
|
|
293
|
+
var oppositeY = (anchor[1] === 0.5 ? shape.y + shape.radiusY / 2 : anchor[1] === 0 ? shape.y + (negH ? -shape.radiusY : shape.radiusY) : shape.y + (negH ? shape.radiusY : -shape.radiusY)) + shape.translation[1];
|
|
294
|
+
return (0, _intersect.getPointPositionBeforeCanvasTransformation)([oppositeX, oppositeY], shape.translation, shape.rotation, center);
|
|
295
|
+
};
|
|
296
|
+
|
|
297
|
+
var getCircleOppositeAnchorAbsolutePosition = function getCircleOppositeAnchorAbsolutePosition(anchor, center, shape) {
|
|
298
|
+
var _ref7 = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : [false, false],
|
|
299
|
+
_ref8 = (0, _slicedToArray2["default"])(_ref7, 2),
|
|
300
|
+
negW = _ref8[0],
|
|
301
|
+
negH = _ref8[1];
|
|
302
|
+
|
|
303
|
+
var oppositeX = (anchor[0] === 0.5 ? shape.x : anchor[0] === 0 ? shape.x + (negW ? -shape.radius : shape.radius) : shape.x + (negW ? shape.radius : -shape.radius)) + shape.translation[0];
|
|
304
|
+
var oppositeY = (anchor[1] === 0.5 ? shape.y : anchor[1] === 0 ? shape.y + (negH ? -shape.radius : shape.radius) : shape.y + (negH ? shape.radius : -shape.radius)) + shape.translation[1];
|
|
305
|
+
return (0, _intersect.getPointPositionBeforeCanvasTransformation)([oppositeX, oppositeY], shape.translation, shape.rotation, center);
|
|
306
|
+
};
|
|
307
|
+
|
|
308
|
+
var resizePicture = function resizePicture(cursorPosition, canvasOffset, originalShape, selectionMode) {
|
|
309
|
+
return resizeRect(cursorPosition, canvasOffset, originalShape, selectionMode, true);
|
|
310
|
+
};
|
|
311
|
+
|
|
312
|
+
exports.resizePicture = resizePicture;
|
|
313
|
+
|
|
314
|
+
var resizeShape = function resizeShape(ctx, shape, cursorPosition, canvasOffset, originalShape, selectionMode) {
|
|
315
|
+
if (shape.type === 'line' || shape.type === 'polygon' || shape.type === 'curve') return resizeLine(cursorPosition, canvasOffset, originalShape, selectionMode);else if (shape.type === 'brush') return resizeBrush(cursorPosition, canvasOffset, originalShape, selectionMode);else if (shape.type === 'circle') return resizeCircle(cursorPosition, canvasOffset, originalShape, selectionMode);else if (shape.type === 'ellipse') return resizeEllipse(cursorPosition, canvasOffset, originalShape, selectionMode);else if (shape.type === 'rect') return resizeRect(cursorPosition, canvasOffset, originalShape, selectionMode);else if (shape.type === 'square') return resizeRect(cursorPosition, canvasOffset, originalShape, selectionMode, true);else if (shape.type === 'text') return resizeText(ctx, cursorPosition, canvasOffset, originalShape, selectionMode);else if (shape.type === 'picture') return resizePicture(cursorPosition, canvasOffset, originalShape, selectionMode);
|
|
316
|
+
return shape;
|
|
317
|
+
};
|
|
318
|
+
|
|
319
|
+
exports.resizeShape = resizeShape;
|
|
320
|
+
|
|
321
|
+
var transformShape = function transformShape(ctx, shape, cursorPosition, canvasOffset, selectionMode) {
|
|
322
|
+
if (selectionMode.mode === _Mode.SelectionModeLib.brush) {
|
|
323
|
+
return paintNewPointToShape(shape, cursorPosition);
|
|
324
|
+
} else if (selectionMode.mode === _Mode.SelectionModeLib.translate) {
|
|
325
|
+
return translateShape(shape, cursorPosition, selectionMode.originalShape, selectionMode.cursorStartPosition);
|
|
326
|
+
} else if (selectionMode.mode === _Mode.SelectionModeLib.rotate) {
|
|
327
|
+
return rotateShape(shape, cursorPosition, selectionMode.originalShape, selectionMode.cursorStartPosition, selectionMode.center);
|
|
328
|
+
} else if (selectionMode.mode === _Mode.SelectionModeLib.resize) {
|
|
329
|
+
return resizeShape(ctx, shape, cursorPosition, canvasOffset, selectionMode.originalShape, selectionMode);
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
return shape;
|
|
333
|
+
};
|
|
334
|
+
|
|
335
|
+
exports.transformShape = transformShape;
|
|
336
|
+
|
|
337
|
+
var calculateTextFontSize = function calculateTextFontSize(ctx, text, maxWidth) {
|
|
338
|
+
var _$flow;
|
|
339
|
+
|
|
340
|
+
var fontFamily = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : _style.STYLE_FONT_DEFAULT;
|
|
341
|
+
ctx.font = "1px ".concat(fontFamily);
|
|
342
|
+
return (_$flow = _fp["default"].flow(_fp["default"].map(function (value) {
|
|
343
|
+
return maxWidth / ctx.measureText(value).width;
|
|
344
|
+
}), _fp["default"].min)(text)) !== null && _$flow !== void 0 ? _$flow : 12;
|
|
345
|
+
};
|
|
346
|
+
|
|
347
|
+
exports.calculateTextFontSize = calculateTextFontSize;
|
|
348
|
+
|
|
349
|
+
var calculateTextWidth = function calculateTextWidth(ctx, text, fontSize) {
|
|
350
|
+
var _$flow2;
|
|
351
|
+
|
|
352
|
+
var fontFamily = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : _style.STYLE_FONT_DEFAULT;
|
|
353
|
+
ctx.font = "".concat(fontSize, "px ").concat(fontFamily);
|
|
354
|
+
return (_$flow2 = _fp["default"].flow(_fp["default"].map(function (value) {
|
|
355
|
+
return ctx.measureText(value).width;
|
|
356
|
+
}), _fp["default"].max)(text)) !== null && _$flow2 !== void 0 ? _$flow2 : 20;
|
|
357
|
+
};
|
|
358
|
+
|
|
359
|
+
exports.calculateTextWidth = calculateTextWidth;
|
|
360
|
+
|
|
361
|
+
var degreesToRadians = function degreesToRadians(degrees) {
|
|
362
|
+
return degrees * (Math.PI / 180);
|
|
363
|
+
};
|
|
364
|
+
|
|
365
|
+
exports.degreesToRadians = degreesToRadians;
|
|
366
|
+
|
|
367
|
+
var radiansToDegrees = function radiansToDegrees(radians) {
|
|
368
|
+
return radians * 180 / Math.PI;
|
|
369
|
+
};
|
|
370
|
+
|
|
371
|
+
exports.radiansToDegrees = radiansToDegrees;
|