@yorab/react-paint 0.6.3 → 0.6.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -1
- package/dist/components/App.js +235 -387
- package/dist/components/Canvas.js +104 -114
- package/dist/components/common/Button.js +41 -50
- package/dist/components/common/Loading.js +21 -33
- package/dist/components/common/Modal.js +18 -17
- package/dist/components/common/Panel.js +20 -24
- package/dist/components/common/Snackbar.js +27 -34
- package/dist/components/settings/ColorField.js +59 -68
- package/dist/components/settings/DeleteButton.js +10 -9
- package/dist/components/settings/FontFamilyField.js +25 -20
- package/dist/components/settings/LayoutButton.js +11 -9
- package/dist/components/settings/Layouts.js +93 -103
- package/dist/components/settings/LineArrowField.js +25 -22
- package/dist/components/settings/LineTypeField.js +23 -20
- package/dist/components/settings/PointsNumberField.js +14 -13
- package/dist/components/settings/RangeField.js +35 -47
- package/dist/components/settings/SelectField.js +34 -43
- package/dist/components/settings/SettingsBar.js +95 -118
- package/dist/components/settings/ToggleField.js +18 -25
- package/dist/components/toolbox/EditTextBox.js +65 -40
- package/dist/components/toolbox/LoadFileTool.js +19 -21
- package/dist/components/toolbox/MenuGroup.js +60 -96
- package/dist/components/toolbox/PictureUrlInput.js +33 -62
- package/dist/components/toolbox/Tool.js +13 -13
- package/dist/components/toolbox/Toolbar.js +74 -106
- package/dist/components/toolbox/ToolbarGroup.js +41 -57
- package/dist/constants/icons.js +43 -43
- package/dist/constants/shapes.js +6 -6
- package/dist/constants/snackbar.js +3 -3
- package/dist/constants/style.js +13 -13
- package/dist/constants/tools.js +80 -80
- package/dist/hooks/useComponent.js +12 -19
- package/dist/hooks/useDoubleClick.js +12 -12
- package/dist/hooks/useDrag.js +24 -32
- package/dist/hooks/useDrawableCanvas.js +86 -100
- package/dist/hooks/useKeyboard.js +26 -36
- package/dist/hooks/useResizeObserver.js +18 -16
- package/dist/hooks/useShapes.js +91 -143
- package/dist/hooks/useSnackbar.js +28 -58
- package/dist/styles.css +55 -55
- package/dist/types/Mode.js +1 -1
- package/dist/types/Shapes.js +1 -1
- package/dist/types/keyboard.js +2 -2
- package/dist/types/tools.js +1 -1
- package/dist/utils/data.js +91 -107
- package/dist/utils/draw.js +116 -146
- package/dist/utils/file.js +69 -119
- package/dist/utils/intersect.js +57 -97
- package/dist/utils/selection.js +12 -12
- package/dist/utils/shapeData.js +33 -51
- package/dist/utils/string.js +10 -16
- package/dist/utils/style.js +1 -1
- package/dist/utils/toolbar.js +26 -38
- package/dist/utils/transform.js +183 -239
- package/package.json +5 -4
package/dist/utils/draw.js
CHANGED
|
@@ -1,16 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
3
|
Object.defineProperty(exports, "__esModule", {
|
|
6
4
|
value: true
|
|
7
5
|
});
|
|
8
6
|
exports.drawTriangle = exports.drawText = exports.drawShape = exports.drawSelection = exports.drawRect = exports.drawPolygon = exports.drawPicture = exports.drawLine = exports.drawEllipse = exports.drawCurve = exports.drawCircle = exports.drawBrush = void 0;
|
|
9
7
|
|
|
10
|
-
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
11
|
-
|
|
12
|
-
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
|
13
|
-
|
|
14
8
|
var _shapes = require("../constants/shapes");
|
|
15
9
|
|
|
16
10
|
var _style = require("../constants/style");
|
|
@@ -19,47 +13,34 @@ var _intersect = require("./intersect");
|
|
|
19
13
|
|
|
20
14
|
var _shapeData = require("./shapeData");
|
|
21
15
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
25
|
-
|
|
26
|
-
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
|
|
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 applyShapeTransformations = function applyShapeTransformations(ctx, marker, responsiveScale, canvasOffset, selectionPadding) {
|
|
16
|
+
const applyShapeTransformations = (ctx, marker, responsiveScale, canvasOffset, selectionPadding) => {
|
|
33
17
|
ctx.save();
|
|
34
18
|
ctx.scale(responsiveScale, responsiveScale);
|
|
35
19
|
ctx.translate(marker.translation[0] + canvasOffset[0], marker.translation[1] + canvasOffset[1]);
|
|
36
20
|
|
|
37
21
|
if (marker.rotation !== 0) {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
22
|
+
const {
|
|
23
|
+
center
|
|
24
|
+
} = (0, _shapeData.getShapeInfos)(marker, selectionPadding);
|
|
41
25
|
ctx.translate(center[0], center[1]);
|
|
42
26
|
ctx.rotate(marker.rotation);
|
|
43
27
|
ctx.translate(-center[0], -center[1]);
|
|
44
28
|
}
|
|
45
29
|
};
|
|
46
30
|
|
|
47
|
-
|
|
31
|
+
const restoreShapeTransformations = ctx => {
|
|
48
32
|
ctx.restore();
|
|
49
33
|
};
|
|
50
34
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
lineWidth = _style$lineWidth === void 0 ? _shapes.SELECTION_DEFAULT_WIDTH : _style$lineWidth,
|
|
61
|
-
_style$lineDash = style.lineDash,
|
|
62
|
-
lineDash = _style$lineDash === void 0 ? 0 : _style$lineDash;
|
|
35
|
+
const updateDrawStyle = function (ctx) {
|
|
36
|
+
let style = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
37
|
+
const {
|
|
38
|
+
fillColor = 'transparent',
|
|
39
|
+
globalAlpha = 100,
|
|
40
|
+
strokeColor = _shapes.SELECTION_DEFAULT_COLOR,
|
|
41
|
+
lineWidth = _shapes.SELECTION_DEFAULT_WIDTH,
|
|
42
|
+
lineDash = 0
|
|
43
|
+
} = style;
|
|
63
44
|
ctx.lineCap = 'round';
|
|
64
45
|
ctx.lineJoin = 'round';
|
|
65
46
|
globalAlpha !== undefined && (ctx.globalAlpha = globalAlpha / 100);
|
|
@@ -69,20 +50,20 @@ var updateDrawStyle = function updateDrawStyle(ctx) {
|
|
|
69
50
|
lineDash !== undefined && lineWidth && ctx.setLineDash([_style.LINE_DASH_DATA[lineDash][0] * lineWidth, _style.LINE_DASH_DATA[lineDash][1] * lineWidth]);
|
|
70
51
|
};
|
|
71
52
|
|
|
72
|
-
|
|
53
|
+
const drawBrush = (ctx, brush) => {
|
|
73
54
|
var _brush$style;
|
|
74
55
|
|
|
75
56
|
if (brush.points.length < 1) return;
|
|
76
57
|
updateDrawStyle(ctx, brush.style);
|
|
77
58
|
ctx.beginPath();
|
|
78
59
|
if (((_brush$style = brush.style) === null || _brush$style === void 0 ? void 0 : _brush$style.strokeColor) === 'transparent' || ctx.globalAlpha === 0) return;
|
|
79
|
-
brush.points.forEach(
|
|
60
|
+
brush.points.forEach(points => {
|
|
80
61
|
if (points.length === 1) {
|
|
81
62
|
ctx.rect(points[0][0], points[0][1], 1, 1);
|
|
82
63
|
} else {
|
|
83
|
-
ctx.moveTo
|
|
84
|
-
points.slice(1).forEach(
|
|
85
|
-
ctx.lineTo
|
|
64
|
+
ctx.moveTo(...points[0]);
|
|
65
|
+
points.slice(1).forEach(point => {
|
|
66
|
+
ctx.lineTo(...point);
|
|
86
67
|
});
|
|
87
68
|
}
|
|
88
69
|
});
|
|
@@ -91,57 +72,56 @@ var drawBrush = function drawBrush(ctx, brush) {
|
|
|
91
72
|
|
|
92
73
|
exports.drawBrush = drawBrush;
|
|
93
74
|
|
|
94
|
-
|
|
75
|
+
const drawTriangle = (ctx, triangle) => {
|
|
95
76
|
var _triangle$style, _triangle$style2;
|
|
96
77
|
|
|
97
78
|
updateDrawStyle(ctx, triangle.style);
|
|
98
79
|
if (ctx.globalAlpha === 0) return;
|
|
99
80
|
ctx.beginPath();
|
|
100
|
-
ctx.moveTo
|
|
101
|
-
ctx.lineTo
|
|
102
|
-
ctx.lineTo
|
|
103
|
-
ctx.lineTo
|
|
81
|
+
ctx.moveTo(...triangle.points[0]);
|
|
82
|
+
ctx.lineTo(...triangle.points[1]);
|
|
83
|
+
ctx.lineTo(...triangle.points[2]);
|
|
84
|
+
ctx.lineTo(...triangle.points[0]);
|
|
104
85
|
((_triangle$style = triangle.style) === null || _triangle$style === void 0 ? void 0 : _triangle$style.fillColor) !== 'transparent' && ctx.fill();
|
|
105
86
|
((_triangle$style2 = triangle.style) === null || _triangle$style2 === void 0 ? void 0 : _triangle$style2.strokeColor) !== 'transparent' && ctx.stroke();
|
|
106
87
|
};
|
|
107
88
|
|
|
108
89
|
exports.drawTriangle = drawTriangle;
|
|
109
90
|
|
|
110
|
-
|
|
91
|
+
const buildTriangleOnLine = (center, angle, lineStyle) => {
|
|
111
92
|
var _lineStyle$style$line, _lineStyle$style, _lineStyle$style$line2, _lineStyle$style2, _lineStyle$style$line3, _lineStyle$style3, _lineStyle$style$line4, _lineStyle$style4, _lineStyle$style$line5, _lineStyle$style5, _lineStyle$style6;
|
|
112
93
|
|
|
113
|
-
|
|
94
|
+
const trianglePoints = [(0, _intersect.applyRotationToVector)([0, -(10 + ((_lineStyle$style$line = (_lineStyle$style = lineStyle.style) === null || _lineStyle$style === void 0 ? void 0 : _lineStyle$style.lineWidth) !== null && _lineStyle$style$line !== void 0 ? _lineStyle$style$line : 0) * 1)], angle), (0, _intersect.applyRotationToVector)([-(5 + ((_lineStyle$style$line2 = (_lineStyle$style2 = lineStyle.style) === null || _lineStyle$style2 === void 0 ? void 0 : _lineStyle$style2.lineWidth) !== null && _lineStyle$style$line2 !== void 0 ? _lineStyle$style$line2 : 0) * 1), 5 + ((_lineStyle$style$line3 = (_lineStyle$style3 = lineStyle.style) === null || _lineStyle$style3 === void 0 ? void 0 : _lineStyle$style3.lineWidth) !== null && _lineStyle$style$line3 !== void 0 ? _lineStyle$style$line3 : 0) * 2], angle), (0, _intersect.applyRotationToVector)([5 + ((_lineStyle$style$line4 = (_lineStyle$style4 = lineStyle.style) === null || _lineStyle$style4 === void 0 ? void 0 : _lineStyle$style4.lineWidth) !== null && _lineStyle$style$line4 !== void 0 ? _lineStyle$style$line4 : 0) * 1, 5 + ((_lineStyle$style$line5 = (_lineStyle$style5 = lineStyle.style) === null || _lineStyle$style5 === void 0 ? void 0 : _lineStyle$style5.lineWidth) !== null && _lineStyle$style$line5 !== void 0 ? _lineStyle$style$line5 : 0) * 2], angle)];
|
|
114
95
|
return {
|
|
115
96
|
points: [[center[0] + trianglePoints[0][0], center[1] + trianglePoints[0][1]], [center[0] + trianglePoints[1][0], center[1] + trianglePoints[1][1]], [center[0] + trianglePoints[2][0], center[1] + trianglePoints[2][1]]],
|
|
116
|
-
style:
|
|
97
|
+
style: { ...lineStyle.style,
|
|
117
98
|
fillColor: (_lineStyle$style6 = lineStyle.style) === null || _lineStyle$style6 === void 0 ? void 0 : _lineStyle$style6.strokeColor,
|
|
118
99
|
strokeColor: 'transparent'
|
|
119
|
-
}
|
|
100
|
+
}
|
|
120
101
|
};
|
|
121
102
|
};
|
|
122
103
|
|
|
123
|
-
|
|
104
|
+
const drawLine = (ctx, line) => {
|
|
124
105
|
var _line$style, _line$style2, _line$style3, _line$style4, _line$style5, _line$style6;
|
|
125
106
|
|
|
126
107
|
updateDrawStyle(ctx, line.style);
|
|
127
108
|
if (ctx.globalAlpha === 0) return;
|
|
128
109
|
ctx.beginPath();
|
|
129
|
-
ctx.moveTo
|
|
130
|
-
ctx.lineTo
|
|
110
|
+
ctx.moveTo(...line.points[0]);
|
|
111
|
+
ctx.lineTo(...line.points[1]);
|
|
131
112
|
((_line$style = line.style) === null || _line$style === void 0 ? void 0 : _line$style.fillColor) !== 'transparent' && ctx.fill();
|
|
132
113
|
((_line$style2 = line.style) === null || _line$style2 === void 0 ? void 0 : _line$style2.strokeColor) !== 'transparent' && ctx.stroke();
|
|
133
114
|
|
|
134
115
|
if (((_line$style3 = line.style) === null || _line$style3 === void 0 ? void 0 : _line$style3.lineArrow) === 1 || ((_line$style4 = line.style) === null || _line$style4 === void 0 ? void 0 : _line$style4.lineArrow) === 3) {
|
|
135
|
-
|
|
116
|
+
const rotation = Math.PI / 2 - Math.atan2(line.points[1][1] - line.points[0][1], line.points[1][0] - line.points[0][0]);
|
|
136
117
|
drawTriangle(ctx, buildTriangleOnLine(line.points[0], rotation, {
|
|
137
118
|
style: line.style
|
|
138
119
|
}));
|
|
139
120
|
}
|
|
140
121
|
|
|
141
122
|
if (((_line$style5 = line.style) === null || _line$style5 === void 0 ? void 0 : _line$style5.lineArrow) === 2 || ((_line$style6 = line.style) === null || _line$style6 === void 0 ? void 0 : _line$style6.lineArrow) === 3) {
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
drawTriangle(ctx, buildTriangleOnLine(line.points[1], _rotation, {
|
|
123
|
+
const rotation = Math.PI / 2 - Math.atan2(line.points[0][1] - line.points[1][1], line.points[0][0] - line.points[1][0]);
|
|
124
|
+
drawTriangle(ctx, buildTriangleOnLine(line.points[1], rotation, {
|
|
145
125
|
style: line.style
|
|
146
126
|
}));
|
|
147
127
|
}
|
|
@@ -149,35 +129,35 @@ var drawLine = function drawLine(ctx, line) {
|
|
|
149
129
|
|
|
150
130
|
exports.drawLine = drawLine;
|
|
151
131
|
|
|
152
|
-
|
|
132
|
+
const drawPolygon = (ctx, polygon) => {
|
|
153
133
|
var _polygon$style, _polygon$style2;
|
|
154
134
|
|
|
155
135
|
if (polygon.points.length < 1) return;
|
|
156
136
|
updateDrawStyle(ctx, polygon.style);
|
|
157
137
|
if (ctx.globalAlpha === 0) return;
|
|
158
138
|
ctx.beginPath();
|
|
159
|
-
ctx.moveTo
|
|
160
|
-
polygon.points.slice(1).forEach(
|
|
161
|
-
ctx.lineTo
|
|
139
|
+
ctx.moveTo(...polygon.points[0]);
|
|
140
|
+
polygon.points.slice(1).forEach(point => {
|
|
141
|
+
ctx.lineTo(...point);
|
|
162
142
|
});
|
|
163
|
-
ctx.lineTo
|
|
143
|
+
ctx.lineTo(...polygon.points[0]);
|
|
164
144
|
((_polygon$style = polygon.style) === null || _polygon$style === void 0 ? void 0 : _polygon$style.fillColor) !== 'transparent' && ctx.fill();
|
|
165
145
|
((_polygon$style2 = polygon.style) === null || _polygon$style2 === void 0 ? void 0 : _polygon$style2.strokeColor) !== 'transparent' && ctx.stroke();
|
|
166
146
|
};
|
|
167
147
|
|
|
168
148
|
exports.drawPolygon = drawPolygon;
|
|
169
149
|
|
|
170
|
-
|
|
150
|
+
const drawCurve = (ctx, curve) => {
|
|
171
151
|
var _curve$style, _curve$style2;
|
|
172
152
|
|
|
173
153
|
if (curve.points.length < 3) return;
|
|
174
154
|
updateDrawStyle(ctx, curve.style);
|
|
175
155
|
if (ctx.globalAlpha === 0) return;
|
|
176
156
|
ctx.beginPath();
|
|
177
|
-
ctx.moveTo
|
|
157
|
+
ctx.moveTo(...curve.points[0]);
|
|
178
158
|
|
|
179
|
-
for (
|
|
180
|
-
ctx.quadraticCurveTo
|
|
159
|
+
for (let i = 1; i < curve.points.length - 1; i++) {
|
|
160
|
+
ctx.quadraticCurveTo(...curve.points[i], curve.points.length - 2 === i ? curve.points[i + 1][0] : (curve.points[i + 1][0] - curve.points[i][0]) / 2 + curve.points[i][0], curve.points.length - 2 === i ? curve.points[i + 1][1] : (curve.points[i + 1][1] - curve.points[i][1]) / 2 + curve.points[i][1]);
|
|
181
161
|
}
|
|
182
162
|
|
|
183
163
|
((_curve$style = curve.style) === null || _curve$style === void 0 ? void 0 : _curve$style.fillColor) !== 'transparent' && ctx.fill();
|
|
@@ -186,7 +166,7 @@ var drawCurve = function drawCurve(ctx, curve) {
|
|
|
186
166
|
|
|
187
167
|
exports.drawCurve = drawCurve;
|
|
188
168
|
|
|
189
|
-
|
|
169
|
+
const drawCircle = (ctx, circle) => {
|
|
190
170
|
var _circle$style, _circle$style2;
|
|
191
171
|
|
|
192
172
|
updateDrawStyle(ctx, circle.style);
|
|
@@ -198,7 +178,7 @@ var drawCircle = function drawCircle(ctx, circle) {
|
|
|
198
178
|
|
|
199
179
|
exports.drawCircle = drawCircle;
|
|
200
180
|
|
|
201
|
-
|
|
181
|
+
const drawEllipse = (ctx, ellipse) => {
|
|
202
182
|
var _ellipse$style, _ellipse$style2;
|
|
203
183
|
|
|
204
184
|
updateDrawStyle(ctx, ellipse.style);
|
|
@@ -211,7 +191,7 @@ var drawEllipse = function drawEllipse(ctx, ellipse) {
|
|
|
211
191
|
|
|
212
192
|
exports.drawEllipse = drawEllipse;
|
|
213
193
|
|
|
214
|
-
|
|
194
|
+
const drawRect = (ctx, rect) => {
|
|
215
195
|
var _rect$style, _rect$style2;
|
|
216
196
|
|
|
217
197
|
updateDrawStyle(ctx, rect.style);
|
|
@@ -224,7 +204,7 @@ var drawRect = function drawRect(ctx, rect) {
|
|
|
224
204
|
|
|
225
205
|
exports.drawRect = drawRect;
|
|
226
206
|
|
|
227
|
-
|
|
207
|
+
const drawText = (ctx, text) => {
|
|
228
208
|
var _text$style, _text$style2, _text$style3, _text$style$fontFamil, _text$style4;
|
|
229
209
|
|
|
230
210
|
updateDrawStyle(ctx, text.style);
|
|
@@ -233,14 +213,14 @@ var drawText = function drawText(ctx, text) {
|
|
|
233
213
|
ctx.textBaseline = 'top';
|
|
234
214
|
ctx.fillStyle = text.style.strokeColor;
|
|
235
215
|
|
|
236
|
-
for (
|
|
216
|
+
for (let i = 0; i < text.value.length; i++) {
|
|
237
217
|
ctx.fillText(text.value[i], text.x, text.y + i * text.fontSize, text.width);
|
|
238
218
|
}
|
|
239
219
|
};
|
|
240
220
|
|
|
241
221
|
exports.drawText = drawText;
|
|
242
222
|
|
|
243
|
-
|
|
223
|
+
const drawPicture = (ctx, picture) => {
|
|
244
224
|
updateDrawStyle(ctx, picture.style);
|
|
245
225
|
if (ctx.globalAlpha === 0) return;
|
|
246
226
|
ctx.beginPath();
|
|
@@ -249,7 +229,7 @@ var drawPicture = function drawPicture(ctx, picture) {
|
|
|
249
229
|
|
|
250
230
|
exports.drawPicture = drawPicture;
|
|
251
231
|
|
|
252
|
-
|
|
232
|
+
const drawShape = (ctx, shape, responsiveScale, canvasOffset, selectionPadding) => {
|
|
253
233
|
if (shape.visible === false) return;
|
|
254
234
|
applyShapeTransformations(ctx, shape, responsiveScale, canvasOffset, selectionPadding);
|
|
255
235
|
|
|
@@ -297,26 +277,26 @@ var drawShape = function drawShape(ctx, shape, responsiveScale, canvasOffset, se
|
|
|
297
277
|
|
|
298
278
|
exports.drawShape = drawShape;
|
|
299
279
|
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
drawRect(ctx,
|
|
280
|
+
const drawSelectionDefault = _ref => {
|
|
281
|
+
let {
|
|
282
|
+
ctx,
|
|
283
|
+
shape,
|
|
284
|
+
withAnchors,
|
|
285
|
+
selectionPadding,
|
|
286
|
+
selectionWidth,
|
|
287
|
+
selectionColor,
|
|
288
|
+
currentScale = 1
|
|
289
|
+
} = _ref;
|
|
290
|
+
const {
|
|
291
|
+
borders
|
|
292
|
+
} = (0, _shapeData.getShapeInfos)(shape, selectionPadding / currentScale);
|
|
293
|
+
drawRect(ctx, { ...borders,
|
|
314
294
|
style: {
|
|
315
295
|
fillColor: 'transparent',
|
|
316
296
|
strokeColor: selectionColor,
|
|
317
297
|
lineWidth: selectionWidth / currentScale
|
|
318
298
|
}
|
|
319
|
-
})
|
|
299
|
+
});
|
|
320
300
|
if (!withAnchors || shape.locked) return;
|
|
321
301
|
drawLine(ctx, {
|
|
322
302
|
points: [[borders.x + borders.width / 2, borders.y], [borders.x + borders.width / 2, borders.y - _shapes.SELECTION_ANCHOR_SIZE / 2 - _shapes.SELECTION_ROTATED_ANCHOR_POSITION / currentScale]],
|
|
@@ -327,27 +307,17 @@ var drawSelectionDefault = function drawSelectionDefault(_ref) {
|
|
|
327
307
|
}
|
|
328
308
|
});
|
|
329
309
|
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
fillColor: 'rgb(255,255,255)',
|
|
342
|
-
strokeColor: 'rgb(150,150,150)',
|
|
343
|
-
lineWidth: selectionWidth / currentScale
|
|
344
|
-
}
|
|
345
|
-
});
|
|
346
|
-
}
|
|
347
|
-
} catch (err) {
|
|
348
|
-
_iterator.e(err);
|
|
349
|
-
} finally {
|
|
350
|
-
_iterator.f();
|
|
310
|
+
for (const anchorPosition of _shapes.SELECTION_RESIZE_ANCHOR_POSITIONS) {
|
|
311
|
+
drawCircle(ctx, {
|
|
312
|
+
x: borders.x + borders.width * anchorPosition[0],
|
|
313
|
+
y: borders.y + borders.height * anchorPosition[1],
|
|
314
|
+
radius: _shapes.SELECTION_ANCHOR_SIZE / 2 / currentScale,
|
|
315
|
+
style: {
|
|
316
|
+
fillColor: 'rgb(255,255,255)',
|
|
317
|
+
strokeColor: 'rgb(150,150,150)',
|
|
318
|
+
lineWidth: selectionWidth / currentScale
|
|
319
|
+
}
|
|
320
|
+
});
|
|
351
321
|
}
|
|
352
322
|
|
|
353
323
|
drawCircle(ctx, {
|
|
@@ -362,30 +332,30 @@ var drawSelectionDefault = function drawSelectionDefault(_ref) {
|
|
|
362
332
|
});
|
|
363
333
|
};
|
|
364
334
|
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
drawRect(ctx,
|
|
335
|
+
const drawLineSelection = _ref2 => {
|
|
336
|
+
let {
|
|
337
|
+
ctx,
|
|
338
|
+
shape,
|
|
339
|
+
withAnchors,
|
|
340
|
+
selectionPadding,
|
|
341
|
+
selectionWidth,
|
|
342
|
+
selectionColor,
|
|
343
|
+
currentScale = 1
|
|
344
|
+
} = _ref2;
|
|
345
|
+
const {
|
|
346
|
+
borders
|
|
347
|
+
} = (0, _shapeData.getShapeInfos)(shape, selectionPadding);
|
|
348
|
+
drawRect(ctx, { ...borders,
|
|
379
349
|
style: {
|
|
380
350
|
fillColor: 'transparent',
|
|
381
351
|
strokeColor: selectionColor,
|
|
382
352
|
lineWidth: selectionWidth / currentScale
|
|
383
353
|
}
|
|
384
|
-
})
|
|
354
|
+
});
|
|
385
355
|
if (!withAnchors || shape.locked) return;
|
|
386
356
|
|
|
387
|
-
for (
|
|
388
|
-
|
|
357
|
+
for (let i = 0; i < shape.points.length; i++) {
|
|
358
|
+
const coordinate = shape.points[i];
|
|
389
359
|
|
|
390
360
|
if (shape.type === 'curve' && i > 0 && i < shape.points.length - 1) {
|
|
391
361
|
drawRect(ctx, {
|
|
@@ -414,17 +384,17 @@ var drawLineSelection = function drawLineSelection(_ref2) {
|
|
|
414
384
|
}
|
|
415
385
|
};
|
|
416
386
|
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
387
|
+
const drawSelection = _ref3 => {
|
|
388
|
+
let {
|
|
389
|
+
ctx,
|
|
390
|
+
shape,
|
|
391
|
+
scaleRatio = 1,
|
|
392
|
+
canvasOffset,
|
|
393
|
+
selectionPadding,
|
|
394
|
+
selectionWidth,
|
|
395
|
+
selectionColor,
|
|
396
|
+
withAnchors = true
|
|
397
|
+
} = _ref3;
|
|
428
398
|
applyShapeTransformations(ctx, shape, scaleRatio, canvasOffset, selectionPadding);
|
|
429
399
|
|
|
430
400
|
switch (shape.type) {
|
|
@@ -432,24 +402,24 @@ var drawSelection = function drawSelection(_ref3) {
|
|
|
432
402
|
case 'line':
|
|
433
403
|
case 'curve':
|
|
434
404
|
drawLineSelection({
|
|
435
|
-
ctx
|
|
436
|
-
shape
|
|
437
|
-
withAnchors
|
|
438
|
-
selectionPadding
|
|
439
|
-
selectionWidth
|
|
440
|
-
selectionColor
|
|
405
|
+
ctx,
|
|
406
|
+
shape,
|
|
407
|
+
withAnchors,
|
|
408
|
+
selectionPadding,
|
|
409
|
+
selectionWidth,
|
|
410
|
+
selectionColor,
|
|
441
411
|
currentScale: scaleRatio
|
|
442
412
|
});
|
|
443
413
|
break;
|
|
444
414
|
|
|
445
415
|
default:
|
|
446
416
|
drawSelectionDefault({
|
|
447
|
-
ctx
|
|
448
|
-
shape
|
|
449
|
-
withAnchors
|
|
450
|
-
selectionPadding
|
|
451
|
-
selectionWidth
|
|
452
|
-
selectionColor
|
|
417
|
+
ctx,
|
|
418
|
+
shape,
|
|
419
|
+
withAnchors,
|
|
420
|
+
selectionPadding,
|
|
421
|
+
selectionWidth,
|
|
422
|
+
selectionColor,
|
|
453
423
|
currentScale: scaleRatio
|
|
454
424
|
});
|
|
455
425
|
break;
|