@yorab/react-paint 0.6.5 → 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.
Files changed (57) hide show
  1. package/README.md +2 -0
  2. package/dist/components/App.js +224 -384
  3. package/dist/components/Canvas.js +104 -114
  4. package/dist/components/common/Button.js +41 -50
  5. package/dist/components/common/Loading.js +21 -33
  6. package/dist/components/common/Modal.js +18 -17
  7. package/dist/components/common/Panel.js +20 -24
  8. package/dist/components/common/Snackbar.js +27 -34
  9. package/dist/components/settings/ColorField.js +59 -68
  10. package/dist/components/settings/DeleteButton.js +10 -9
  11. package/dist/components/settings/FontFamilyField.js +24 -19
  12. package/dist/components/settings/LayoutButton.js +11 -9
  13. package/dist/components/settings/Layouts.js +93 -103
  14. package/dist/components/settings/LineArrowField.js +25 -22
  15. package/dist/components/settings/LineTypeField.js +23 -20
  16. package/dist/components/settings/PointsNumberField.js +14 -13
  17. package/dist/components/settings/RangeField.js +35 -47
  18. package/dist/components/settings/SelectField.js +34 -43
  19. package/dist/components/settings/SettingsBar.js +95 -118
  20. package/dist/components/settings/ToggleField.js +18 -25
  21. package/dist/components/toolbox/EditTextBox.js +53 -42
  22. package/dist/components/toolbox/LoadFileTool.js +19 -21
  23. package/dist/components/toolbox/MenuGroup.js +60 -96
  24. package/dist/components/toolbox/PictureUrlInput.js +33 -62
  25. package/dist/components/toolbox/Tool.js +13 -13
  26. package/dist/components/toolbox/Toolbar.js +74 -106
  27. package/dist/components/toolbox/ToolbarGroup.js +41 -57
  28. package/dist/constants/icons.js +43 -43
  29. package/dist/constants/shapes.js +6 -6
  30. package/dist/constants/snackbar.js +3 -3
  31. package/dist/constants/style.js +13 -13
  32. package/dist/constants/tools.js +80 -80
  33. package/dist/hooks/useComponent.js +12 -19
  34. package/dist/hooks/useDoubleClick.js +12 -12
  35. package/dist/hooks/useDrag.js +24 -32
  36. package/dist/hooks/useDrawableCanvas.js +86 -100
  37. package/dist/hooks/useKeyboard.js +26 -36
  38. package/dist/hooks/useResizeObserver.js +18 -16
  39. package/dist/hooks/useShapes.js +91 -143
  40. package/dist/hooks/useSnackbar.js +28 -58
  41. package/dist/styles.css +55 -55
  42. package/dist/types/Mode.js +1 -1
  43. package/dist/types/Shapes.js +1 -1
  44. package/dist/types/keyboard.js +2 -2
  45. package/dist/types/tools.js +1 -1
  46. package/dist/utils/data.js +91 -107
  47. package/dist/utils/draw.js +116 -146
  48. package/dist/utils/file.js +69 -119
  49. package/dist/utils/intersect.js +57 -97
  50. package/dist/utils/selection.js +12 -12
  51. package/dist/utils/shapeData.js +33 -51
  52. package/dist/utils/string.js +10 -16
  53. package/dist/utils/style.js +1 -1
  54. package/dist/utils/toolbar.js +26 -38
  55. package/dist/utils/transform.js +183 -239
  56. package/package.json +6 -5
  57. package/Changelog.md +0 -123
@@ -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
- function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; }
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
- var _getShapeInfos = (0, _shapeData.getShapeInfos)(marker, selectionPadding),
39
- center = _getShapeInfos.center;
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
- var restoreShapeTransformations = function restoreShapeTransformations(ctx) {
31
+ const restoreShapeTransformations = ctx => {
48
32
  ctx.restore();
49
33
  };
50
34
 
51
- var updateDrawStyle = function updateDrawStyle(ctx) {
52
- var style = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
53
- var _style$fillColor = style.fillColor,
54
- fillColor = _style$fillColor === void 0 ? 'transparent' : _style$fillColor,
55
- _style$globalAlpha = style.globalAlpha,
56
- globalAlpha = _style$globalAlpha === void 0 ? 100 : _style$globalAlpha,
57
- _style$strokeColor = style.strokeColor,
58
- strokeColor = _style$strokeColor === void 0 ? _shapes.SELECTION_DEFAULT_COLOR : _style$strokeColor,
59
- _style$lineWidth = style.lineWidth,
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
- var drawBrush = function drawBrush(ctx, brush) {
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(function (points) {
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.apply(ctx, (0, _toConsumableArray2["default"])(points[0]));
84
- points.slice(1).forEach(function (point) {
85
- ctx.lineTo.apply(ctx, (0, _toConsumableArray2["default"])(point));
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
- var drawTriangle = function drawTriangle(ctx, triangle) {
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.apply(ctx, (0, _toConsumableArray2["default"])(triangle.points[0]));
101
- ctx.lineTo.apply(ctx, (0, _toConsumableArray2["default"])(triangle.points[1]));
102
- ctx.lineTo.apply(ctx, (0, _toConsumableArray2["default"])(triangle.points[2]));
103
- ctx.lineTo.apply(ctx, (0, _toConsumableArray2["default"])(triangle.points[0]));
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
- var buildTriangleOnLine = function buildTriangleOnLine(center, angle, lineStyle) {
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
- var 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)];
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: _objectSpread(_objectSpread({}, lineStyle.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
- var drawLine = function drawLine(ctx, line) {
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.apply(ctx, (0, _toConsumableArray2["default"])(line.points[0]));
130
- ctx.lineTo.apply(ctx, (0, _toConsumableArray2["default"])(line.points[1]));
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
- var rotation = Math.PI / 2 - Math.atan2(line.points[1][1] - line.points[0][1], line.points[1][0] - line.points[0][0]);
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
- var _rotation = Math.PI / 2 - Math.atan2(line.points[0][1] - line.points[1][1], line.points[0][0] - line.points[1][0]);
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
- var drawPolygon = function drawPolygon(ctx, polygon) {
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.apply(ctx, (0, _toConsumableArray2["default"])(polygon.points[0]));
160
- polygon.points.slice(1).forEach(function (point) {
161
- ctx.lineTo.apply(ctx, (0, _toConsumableArray2["default"])(point));
139
+ ctx.moveTo(...polygon.points[0]);
140
+ polygon.points.slice(1).forEach(point => {
141
+ ctx.lineTo(...point);
162
142
  });
163
- ctx.lineTo.apply(ctx, (0, _toConsumableArray2["default"])(polygon.points[0]));
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
- var drawCurve = function drawCurve(ctx, curve) {
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.apply(ctx, (0, _toConsumableArray2["default"])(curve.points[0]));
157
+ ctx.moveTo(...curve.points[0]);
178
158
 
179
- for (var i = 1; i < curve.points.length - 1; i++) {
180
- ctx.quadraticCurveTo.apply(ctx, (0, _toConsumableArray2["default"])(curve.points[i]).concat([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]]));
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
- var drawCircle = function drawCircle(ctx, circle) {
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
- var drawEllipse = function drawEllipse(ctx, ellipse) {
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
- var drawRect = function drawRect(ctx, rect) {
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
- var drawText = function drawText(ctx, text) {
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 (var i = 0; i < text.value.length; i++) {
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
- var drawPicture = function drawPicture(ctx, picture) {
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
- var drawShape = function drawShape(ctx, shape, responsiveScale, canvasOffset, selectionPadding) {
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
- var drawSelectionDefault = function drawSelectionDefault(_ref) {
301
- var ctx = _ref.ctx,
302
- shape = _ref.shape,
303
- withAnchors = _ref.withAnchors,
304
- selectionPadding = _ref.selectionPadding,
305
- selectionWidth = _ref.selectionWidth,
306
- selectionColor = _ref.selectionColor,
307
- _ref$currentScale = _ref.currentScale,
308
- currentScale = _ref$currentScale === void 0 ? 1 : _ref$currentScale;
309
-
310
- var _getShapeInfos2 = (0, _shapeData.getShapeInfos)(shape, selectionPadding / currentScale),
311
- borders = _getShapeInfos2.borders;
312
-
313
- drawRect(ctx, _objectSpread(_objectSpread({}, borders), {}, {
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
- var _iterator = _createForOfIteratorHelper(_shapes.SELECTION_RESIZE_ANCHOR_POSITIONS),
331
- _step;
332
-
333
- try {
334
- for (_iterator.s(); !(_step = _iterator.n()).done;) {
335
- var anchorPosition = _step.value;
336
- drawCircle(ctx, {
337
- x: borders.x + borders.width * anchorPosition[0],
338
- y: borders.y + borders.height * anchorPosition[1],
339
- radius: _shapes.SELECTION_ANCHOR_SIZE / 2 / currentScale,
340
- style: {
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
- var drawLineSelection = function drawLineSelection(_ref2) {
366
- var ctx = _ref2.ctx,
367
- shape = _ref2.shape,
368
- withAnchors = _ref2.withAnchors,
369
- selectionPadding = _ref2.selectionPadding,
370
- selectionWidth = _ref2.selectionWidth,
371
- selectionColor = _ref2.selectionColor,
372
- _ref2$currentScale = _ref2.currentScale,
373
- currentScale = _ref2$currentScale === void 0 ? 1 : _ref2$currentScale;
374
-
375
- var _getShapeInfos3 = (0, _shapeData.getShapeInfos)(shape, selectionPadding),
376
- borders = _getShapeInfos3.borders;
377
-
378
- drawRect(ctx, _objectSpread(_objectSpread({}, borders), {}, {
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 (var i = 0; i < shape.points.length; i++) {
388
- var coordinate = shape.points[i];
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
- var drawSelection = function drawSelection(_ref3) {
418
- var ctx = _ref3.ctx,
419
- shape = _ref3.shape,
420
- _ref3$scaleRatio = _ref3.scaleRatio,
421
- scaleRatio = _ref3$scaleRatio === void 0 ? 1 : _ref3$scaleRatio,
422
- canvasOffset = _ref3.canvasOffset,
423
- selectionPadding = _ref3.selectionPadding,
424
- selectionWidth = _ref3.selectionWidth,
425
- selectionColor = _ref3.selectionColor,
426
- _ref3$withAnchors = _ref3.withAnchors,
427
- withAnchors = _ref3$withAnchors === void 0 ? true : _ref3$withAnchors;
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: ctx,
436
- shape: shape,
437
- withAnchors: withAnchors,
438
- selectionPadding: selectionPadding,
439
- selectionWidth: selectionWidth,
440
- selectionColor: 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: ctx,
448
- shape: shape,
449
- withAnchors: withAnchors,
450
- selectionPadding: selectionPadding,
451
- selectionWidth: selectionWidth,
452
- selectionColor: selectionColor,
417
+ ctx,
418
+ shape,
419
+ withAnchors,
420
+ selectionPadding,
421
+ selectionWidth,
422
+ selectionColor,
453
423
  currentScale: scaleRatio
454
424
  });
455
425
  break;