@yorab/react-paint 0.6.6 → 0.7.1

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 (64) hide show
  1. package/README.md +3 -5
  2. package/dist/components/App.js +30 -57
  3. package/dist/components/Canvas.js +31 -40
  4. package/dist/components/common/Button.js +4 -4
  5. package/dist/components/common/Loading.js +8 -5
  6. package/dist/components/common/Modal.js +3 -3
  7. package/dist/components/common/Panel.js +7 -11
  8. package/dist/components/common/Snackbar.js +6 -6
  9. package/dist/components/settings/ColorField.js +3 -3
  10. package/dist/components/settings/FontFamilyField.js +1 -1
  11. package/dist/components/settings/Layouts.js +36 -26
  12. package/dist/components/settings/LineArrowField.js +3 -3
  13. package/dist/components/settings/LineTypeField.js +2 -2
  14. package/dist/components/settings/RangeField.js +1 -1
  15. package/dist/components/settings/SelectField.js +1 -1
  16. package/dist/components/settings/SettingsBar.js +9 -7
  17. package/dist/components/toolbox/EditTextBox.js +11 -9
  18. package/dist/components/toolbox/MenuGroup.js +9 -7
  19. package/dist/components/toolbox/Toolbar.js +7 -9
  20. package/dist/components/toolbox/ToolbarGroup.js +24 -11
  21. package/dist/constants/app.js +51 -0
  22. package/dist/constants/icons.js +2 -8
  23. package/dist/constants/loading.js +8 -0
  24. package/dist/constants/shapes.js +4 -2
  25. package/dist/constants/snackbar.js +6 -14
  26. package/dist/constants/style.js +12 -9
  27. package/dist/constants/tools.js +20 -24
  28. package/dist/hooks/useComponent.js +3 -1
  29. package/dist/hooks/useDrawableCanvas.js +35 -37
  30. package/dist/hooks/useKeyboard.js +60 -33
  31. package/dist/hooks/useShapes.js +2 -2
  32. package/dist/styles.css +16 -13
  33. package/dist/types/Mode.js +1 -13
  34. package/dist/types/Shapes.js +1 -17
  35. package/dist/types/snackbar.js +5 -0
  36. package/dist/types/tools.js +1 -18
  37. package/dist/utils/canvas.js +49 -0
  38. package/dist/utils/data.js +5 -248
  39. package/dist/utils/dom.js +12 -0
  40. package/dist/utils/file.js +12 -7
  41. package/dist/utils/intersect.js +29 -66
  42. package/dist/utils/migration.js +59 -0
  43. package/dist/utils/selection.js +9 -11
  44. package/dist/utils/shapes/brush.js +135 -0
  45. package/dist/utils/shapes/circle.js +93 -0
  46. package/dist/utils/shapes/curve.js +55 -0
  47. package/dist/utils/shapes/default.js +73 -0
  48. package/dist/utils/shapes/ellipse.js +101 -0
  49. package/dist/utils/shapes/grid.js +36 -0
  50. package/dist/utils/shapes/index.js +341 -0
  51. package/dist/utils/shapes/line.js +179 -0
  52. package/dist/utils/shapes/picture.js +88 -0
  53. package/dist/utils/shapes/polygon.js +69 -0
  54. package/dist/utils/shapes/rectangle.js +100 -0
  55. package/dist/utils/shapes/text.js +128 -0
  56. package/dist/utils/shapes/triangle.js +24 -0
  57. package/dist/utils/style.js +10 -12
  58. package/dist/utils/toolbar.js +9 -11
  59. package/dist/utils/transform.js +25 -261
  60. package/dist/utils/trigo.js +42 -0
  61. package/package.json +7 -8
  62. package/dist/types/keyboard.js +0 -28
  63. package/dist/utils/draw.js +0 -431
  64. package/dist/utils/shapeData.js +0 -155
@@ -0,0 +1,88 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.resizePicture = exports.getPictureBorder = exports.drawPicture = exports.createPicture = void 0;
9
+
10
+ var _fp = _interopRequireDefault(require("lodash/fp"));
11
+
12
+ var _transform = require("../transform");
13
+
14
+ var _file = require("../file");
15
+
16
+ var _tools = require("../../constants/tools");
17
+
18
+ var _canvas = require("../canvas");
19
+
20
+ var _rectangle = require("./rectangle");
21
+
22
+ const createPicture = (fileOrUrl, maxPictureWidth, maxPictureHeight) => {
23
+ return new Promise((resolve, reject) => {
24
+ const img = new Image();
25
+
26
+ img.onload = () => {
27
+ const [width, height] = (0, _transform.fitContentInsideContainer)(img.width, img.height, maxPictureWidth, maxPictureHeight, true);
28
+ const pictureShape = {
29
+ toolId: _tools.DEFAULT_SHAPE_PICTURE.id,
30
+ type: 'picture',
31
+ id: _fp.default.uniqueId('picture'.concat("_")),
32
+ x: (maxPictureWidth - width) / 2,
33
+ y: (maxPictureHeight - height) / 2,
34
+ width,
35
+ height,
36
+ src: fileOrUrl instanceof File ? img.src : fileOrUrl,
37
+ img,
38
+ rotation: 0
39
+ };
40
+ resolve(pictureShape);
41
+ };
42
+
43
+ img.onerror = () => {
44
+ reject(new Error('Some images could not be loaded'));
45
+ };
46
+
47
+ if (fileOrUrl instanceof File) {
48
+ img.src = URL.createObjectURL(fileOrUrl);
49
+ } else {
50
+ (0, _file.fetchAndStringify)(fileOrUrl).then(picData => {
51
+ img.src = picData;
52
+ }).catch(() => {
53
+ img.src = ''; // to trigger onerror
54
+ });
55
+ }
56
+
57
+ img.onerror = () => {
58
+ reject(new Error('Error while loading the src'));
59
+ };
60
+
61
+ setTimeout(() => {
62
+ reject(new Error('Timeout while loading the src'));
63
+ }, 4000);
64
+ });
65
+ };
66
+
67
+ exports.createPicture = createPicture;
68
+
69
+ const drawPicture = (ctx, picture) => {
70
+ (0, _canvas.updateCanvasContext)(ctx, picture.style);
71
+ if (ctx.globalAlpha === 0) return;
72
+ ctx.beginPath();
73
+ ctx.drawImage(picture.img, picture.x, picture.y, picture.width, picture.height);
74
+ };
75
+
76
+ exports.drawPicture = drawPicture;
77
+
78
+ const getPictureBorder = (picture, selectionPadding) => {
79
+ return (0, _rectangle.getRectBorder)(picture, selectionPadding);
80
+ };
81
+
82
+ exports.getPictureBorder = getPictureBorder;
83
+
84
+ const resizePicture = (cursorPosition, canvasOffset, originalShape, selectionMode, selectionPadding, keepRatio) => {
85
+ return (0, _rectangle.resizeRect)(cursorPosition, canvasOffset, originalShape, selectionMode, selectionPadding, keepRatio);
86
+ };
87
+
88
+ exports.resizePicture = resizePicture;
@@ -0,0 +1,69 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.getPolygonBorder = exports.drawPolygon = exports.createPolygon = void 0;
9
+
10
+ var _fp = _interopRequireDefault(require("lodash/fp"));
11
+
12
+ var _canvas = require("../canvas");
13
+
14
+ const createPolygon = (shape, cursorPosition) => {
15
+ return {
16
+ toolId: shape.id,
17
+ type: shape.type,
18
+ id: _fp.default.uniqueId("".concat(shape.type, "_")),
19
+ points: _fp.default.flow(_fp.default.range(0), _fp.default.map(() => cursorPosition))(shape.settings.pointsCount.default),
20
+ rotation: 0,
21
+ style: {
22
+ globalAlpha: shape.settings.opacity.default,
23
+ fillColor: shape.settings.fillColor.default,
24
+ strokeColor: shape.settings.strokeColor.default,
25
+ lineWidth: shape.settings.lineWidth.default,
26
+ lineDash: shape.settings.lineDash.default,
27
+ pointsCount: shape.settings.pointsCount.default
28
+ }
29
+ };
30
+ };
31
+
32
+ exports.createPolygon = createPolygon;
33
+
34
+ const drawPolygon = (ctx, polygon) => {
35
+ var _polygon$style, _polygon$style2;
36
+
37
+ if (polygon.points.length < 1) return;
38
+ (0, _canvas.updateCanvasContext)(ctx, polygon.style);
39
+ if (ctx.globalAlpha === 0) return;
40
+ ctx.beginPath();
41
+ ctx.moveTo(...polygon.points[0]);
42
+ polygon.points.slice(1).forEach(point => {
43
+ ctx.lineTo(...point);
44
+ });
45
+ ctx.lineTo(...polygon.points[0]);
46
+ ((_polygon$style = polygon.style) === null || _polygon$style === void 0 ? void 0 : _polygon$style.fillColor) !== 'transparent' && ctx.fill();
47
+ ((_polygon$style2 = polygon.style) === null || _polygon$style2 === void 0 ? void 0 : _polygon$style2.strokeColor) !== 'transparent' && ctx.stroke();
48
+ };
49
+
50
+ exports.drawPolygon = drawPolygon;
51
+
52
+ const getPolygonBorder = (polygon, selectionPadding) => {
53
+ const minX = _fp.default.flow(_fp.default.map(point => point[0]), _fp.default.min, _fp.default.add(-selectionPadding))(polygon.points);
54
+
55
+ const maxX = _fp.default.flow(_fp.default.map(point => point[0]), _fp.default.max, _fp.default.add(selectionPadding))(polygon.points);
56
+
57
+ const minY = _fp.default.flow(_fp.default.map(point => point[1]), _fp.default.min, _fp.default.add(-selectionPadding))(polygon.points);
58
+
59
+ const maxY = _fp.default.flow(_fp.default.map(point => point[1]), _fp.default.max, _fp.default.add(selectionPadding))(polygon.points);
60
+
61
+ return {
62
+ x: minX,
63
+ width: maxX - minX,
64
+ y: minY,
65
+ height: maxY - minY
66
+ };
67
+ };
68
+
69
+ exports.getPolygonBorder = getPolygonBorder;
@@ -0,0 +1,100 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.resizeRect = exports.getRectOppositeAnchorAbsolutePosition = exports.getRectBorder = exports.drawRect = exports.createRectangle = void 0;
9
+
10
+ var _fp = _interopRequireDefault(require("lodash/fp"));
11
+
12
+ var _canvas = require("../canvas");
13
+
14
+ var _intersect = require("../intersect");
15
+
16
+ var _transform = require("../transform");
17
+
18
+ var _2 = require(".");
19
+
20
+ const createRectangle = (shape, cursorPosition) => {
21
+ return {
22
+ toolId: shape.id,
23
+ type: shape.type,
24
+ id: _fp.default.uniqueId("".concat(shape.type, "_")),
25
+ x: cursorPosition[0],
26
+ y: cursorPosition[1],
27
+ width: 1,
28
+ height: 1,
29
+ rotation: 0,
30
+ style: {
31
+ globalAlpha: shape.settings.opacity.default,
32
+ fillColor: shape.settings.fillColor.default,
33
+ strokeColor: shape.settings.strokeColor.default,
34
+ lineWidth: shape.settings.lineWidth.default,
35
+ lineDash: shape.settings.lineDash.default
36
+ }
37
+ };
38
+ };
39
+
40
+ exports.createRectangle = createRectangle;
41
+
42
+ const drawRect = (ctx, rect) => {
43
+ var _rect$style, _rect$style2;
44
+
45
+ (0, _canvas.updateCanvasContext)(ctx, rect.style);
46
+ if (ctx.globalAlpha === 0) return;
47
+ ctx.beginPath();
48
+ ctx.rect(rect.x, rect.y, rect.width, rect.height);
49
+ ((_rect$style = rect.style) === null || _rect$style === void 0 ? void 0 : _rect$style.fillColor) !== 'transparent' && ctx.fill();
50
+ ((_rect$style2 = rect.style) === null || _rect$style2 === void 0 ? void 0 : _rect$style2.strokeColor) !== 'transparent' && ctx.stroke();
51
+ };
52
+
53
+ exports.drawRect = drawRect;
54
+
55
+ const getRectBorder = (rect, selectionPadding) => {
56
+ return {
57
+ x: rect.x - selectionPadding,
58
+ width: rect.width + selectionPadding * 2,
59
+ y: rect.y - selectionPadding,
60
+ height: rect.height + selectionPadding * 2
61
+ };
62
+ };
63
+
64
+ exports.getRectBorder = getRectBorder;
65
+
66
+ const getRectOppositeAnchorAbsolutePosition = function (anchor, center, shape, canvasOffset) {
67
+ let [negW, negH] = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : [false, false];
68
+ const 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);
69
+ const 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);
70
+ return (0, _intersect.getPointPositionBeforeCanvasTransformation)([oppositeX, oppositeY], shape.rotation, center, canvasOffset);
71
+ };
72
+
73
+ exports.getRectOppositeAnchorAbsolutePosition = getRectOppositeAnchorAbsolutePosition;
74
+
75
+ const resizeRect = function (cursorPosition, canvasOffset, originalShape, selectionMode, selectionPadding) {
76
+ let keepRatio = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : false;
77
+ const {
78
+ center,
79
+ borders
80
+ } = (0, _2.getShapeInfos)(originalShape, selectionPadding);
81
+ const cusroPositionAfterShapeTransormation = (0, _intersect.getPointPositionAfterCanvasTransformation)(cursorPosition, originalShape.rotation, center, canvasOffset);
82
+ const scaledWidth = selectionMode.anchor[0] === 0.5 ? originalShape.width : selectionMode.anchor[0] === 0 ? borders.x + borders.width - cusroPositionAfterShapeTransormation[0] + selectionPadding * -2 : cusroPositionAfterShapeTransormation[0] - borders.x - selectionPadding * 2;
83
+ const scaledHeight = selectionMode.anchor[1] === 0.5 ? originalShape.height : selectionMode.anchor[1] === 0 ? borders.y + borders.height - cusroPositionAfterShapeTransormation[1] + selectionPadding * -2 : cusroPositionAfterShapeTransormation[1] - borders.y - selectionPadding * 2;
84
+ const [widthWithRatio, heightWithRatio] = keepRatio ? (0, _transform.getNormalizedSize)(originalShape.width, originalShape.height, scaledWidth, scaledHeight) : [scaledWidth, scaledHeight];
85
+ const shapeWithNewDimensions = { ...originalShape,
86
+ width: Math.abs(widthWithRatio),
87
+ height: Math.abs(heightWithRatio)
88
+ };
89
+ const {
90
+ center: shapeWithNewDimensionsCenter
91
+ } = (0, _2.getShapeInfos)(shapeWithNewDimensions, selectionPadding);
92
+ const [oppTrueX, oppTrueY] = getRectOppositeAnchorAbsolutePosition(selectionMode.anchor, center, originalShape, canvasOffset);
93
+ const [newOppTrueX, newOppTrueY] = getRectOppositeAnchorAbsolutePosition(selectionMode.anchor, shapeWithNewDimensionsCenter, shapeWithNewDimensions, canvasOffset, [widthWithRatio < 0, heightWithRatio < 0]);
94
+ return { ...shapeWithNewDimensions,
95
+ x: shapeWithNewDimensions.x - (newOppTrueX - oppTrueX),
96
+ y: shapeWithNewDimensions.y - (newOppTrueY - oppTrueY)
97
+ };
98
+ };
99
+
100
+ exports.resizeRect = resizeRect;
@@ -0,0 +1,128 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.resizeTextShapeWithNewContent = exports.resizeText = exports.getTextBorder = exports.drawText = exports.createText = exports.calculateTextFontSize = void 0;
9
+
10
+ var _fp = _interopRequireDefault(require("lodash/fp"));
11
+
12
+ var _canvas = require("../canvas");
13
+
14
+ var _style = require("../../constants/style");
15
+
16
+ var _rectangle = require("./rectangle");
17
+
18
+ var _2 = require(".");
19
+
20
+ const calculateTextFontSize = function (ctx, text, maxWidth, fontBold, fontItalic) {
21
+ var _$flow;
22
+
23
+ let fontFamily = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : _style.STYLE_FONT_DEFAULT;
24
+ ctx.font = "".concat(fontItalic ? 'italic' : '', " ").concat(fontBold ? 'bold' : '', " 1px ").concat(fontFamily);
25
+ return (_$flow = _fp.default.flow(_fp.default.map(value => maxWidth / ctx.measureText(value).width), _fp.default.min)(text)) !== null && _$flow !== void 0 ? _$flow : _style.STYLE_FONT_SIZE_DEFAULT;
26
+ };
27
+
28
+ exports.calculateTextFontSize = calculateTextFontSize;
29
+
30
+ const createText = (ctx, shape, cursorPosition) => {
31
+ var _shape$settings$fontB, _shape$settings, _shape$settings$fontI, _shape$settings2;
32
+
33
+ const defaultValue = ['Texte'];
34
+ const fontSize = calculateTextFontSize(ctx, defaultValue, 50, (_shape$settings$fontB = (_shape$settings = shape.settings) === null || _shape$settings === void 0 ? void 0 : _shape$settings.fontBold.default) !== null && _shape$settings$fontB !== void 0 ? _shape$settings$fontB : false, (_shape$settings$fontI = (_shape$settings2 = shape.settings) === null || _shape$settings2 === void 0 ? void 0 : _shape$settings2.fontItalic.default) !== null && _shape$settings$fontI !== void 0 ? _shape$settings$fontI : false, shape.settings.fontFamily.default);
35
+ return {
36
+ toolId: shape.id,
37
+ type: shape.type,
38
+ id: _fp.default.uniqueId("".concat(shape.type, "_")),
39
+ x: cursorPosition[0],
40
+ y: cursorPosition[1],
41
+ value: defaultValue,
42
+ fontSize,
43
+ width: 50,
44
+ height: fontSize * (defaultValue.length || 1),
45
+ rotation: 0,
46
+ style: {
47
+ globalAlpha: shape.settings.opacity.default,
48
+ strokeColor: shape.settings.strokeColor.default,
49
+ fontFamily: shape.settings.fontFamily.default
50
+ }
51
+ };
52
+ };
53
+
54
+ exports.createText = createText;
55
+
56
+ const drawText = (ctx, text) => {
57
+ var _text$style, _text$style2, _text$style3, _text$style$fontFamil, _text$style4;
58
+
59
+ (0, _canvas.updateCanvasContext)(ctx, text.style);
60
+ if (ctx.globalAlpha === 0 || !((_text$style = text.style) !== null && _text$style !== void 0 && _text$style.strokeColor) || text.style.strokeColor === 'transparent') return;
61
+ ctx.font = "".concat((_text$style2 = text.style) !== null && _text$style2 !== void 0 && _text$style2.fontItalic ? 'italic' : '', " ").concat((_text$style3 = text.style) !== null && _text$style3 !== void 0 && _text$style3.fontBold ? 'bold' : '', " ").concat(text.fontSize, "px ").concat((_text$style$fontFamil = (_text$style4 = text.style) === null || _text$style4 === void 0 ? void 0 : _text$style4.fontFamily) !== null && _text$style$fontFamil !== void 0 ? _text$style$fontFamil : _style.STYLE_FONT_DEFAULT);
62
+ ctx.textBaseline = 'top';
63
+ ctx.fillStyle = text.style.strokeColor;
64
+
65
+ for (let i = 0; i < text.value.length; i++) {
66
+ ctx.fillText(text.value[i], text.x, text.y + i * text.fontSize, text.width);
67
+ }
68
+ };
69
+
70
+ exports.drawText = drawText;
71
+
72
+ const getTextBorder = (text, selectionPadding) => {
73
+ return {
74
+ x: text.x - selectionPadding,
75
+ width: text.width + selectionPadding * 2,
76
+ y: text.y - selectionPadding,
77
+ height: text.height + selectionPadding * 2
78
+ };
79
+ };
80
+
81
+ exports.getTextBorder = getTextBorder;
82
+
83
+ const resizeText = (ctx, cursorPosition, canvasOffset, originalShape, selectionMode, selectionPadding) => {
84
+ var _newRect$style$fontBo, _newRect$style, _newRect$style$fontIt, _newRect$style2, _newRect$style3;
85
+
86
+ const newRect = (0, _rectangle.resizeRect)(cursorPosition, canvasOffset, originalShape, selectionMode, selectionPadding, true);
87
+ return { ...newRect,
88
+ fontSize: calculateTextFontSize(ctx, newRect.value, newRect.width, (_newRect$style$fontBo = (_newRect$style = newRect.style) === null || _newRect$style === void 0 ? void 0 : _newRect$style.fontBold) !== null && _newRect$style$fontBo !== void 0 ? _newRect$style$fontBo : false, (_newRect$style$fontIt = (_newRect$style2 = newRect.style) === null || _newRect$style2 === void 0 ? void 0 : _newRect$style2.fontItalic) !== null && _newRect$style$fontIt !== void 0 ? _newRect$style$fontIt : false, (_newRect$style3 = newRect.style) === null || _newRect$style3 === void 0 ? void 0 : _newRect$style3.fontFamily)
89
+ };
90
+ };
91
+
92
+ exports.resizeText = resizeText;
93
+
94
+ const calculateTextWidth = function (ctx, text, fontSize, fontBold, fontItalic) {
95
+ var _$flow2;
96
+
97
+ let fontFamily = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : _style.STYLE_FONT_DEFAULT;
98
+ ctx.font = "".concat(fontItalic ? 'italic' : '', " ").concat(fontBold ? 'bold' : '', " ").concat(fontSize, "px ").concat(fontFamily);
99
+ return (_$flow2 = _fp.default.flow(_fp.default.map(value => ctx.measureText(value).width), _fp.default.max)(text)) !== null && _$flow2 !== void 0 ? _$flow2 : 20;
100
+ };
101
+
102
+ const resizeTextShapeWithNewContent = (ctx, shape, newValue, canvasOffset) => {
103
+ var _newShape$style$fontB, _newShape$style, _newShape$style$fontI, _newShape$style2, _newShape$style3;
104
+
105
+ const newShape = _fp.default.set('value', newValue, shape);
106
+
107
+ const newWidth = calculateTextWidth(ctx, newShape.value, newShape.fontSize, (_newShape$style$fontB = (_newShape$style = newShape.style) === null || _newShape$style === void 0 ? void 0 : _newShape$style.fontBold) !== null && _newShape$style$fontB !== void 0 ? _newShape$style$fontB : false, (_newShape$style$fontI = (_newShape$style2 = newShape.style) === null || _newShape$style2 === void 0 ? void 0 : _newShape$style2.fontItalic) !== null && _newShape$style$fontI !== void 0 ? _newShape$style$fontI : false, (_newShape$style3 = newShape.style) === null || _newShape$style3 === void 0 ? void 0 : _newShape$style3.fontFamily);
108
+ const newHeight = newShape.fontSize * newShape.value.length;
109
+ const resizedShape = { ...newShape,
110
+ width: newWidth,
111
+ height: newHeight
112
+ };
113
+ const selectionPadding = 0;
114
+ const {
115
+ center
116
+ } = (0, _2.getShapeInfos)(shape, selectionPadding);
117
+ const {
118
+ center: shapeWithNewDimensionsCenter
119
+ } = (0, _2.getShapeInfos)(resizedShape, selectionPadding);
120
+ const [oppTrueX, oppTrueY] = (0, _rectangle.getRectOppositeAnchorAbsolutePosition)([1, 0.5], center, shape, canvasOffset);
121
+ const [newOppTrueX, newOppTrueY] = (0, _rectangle.getRectOppositeAnchorAbsolutePosition)([1, 0.5], shapeWithNewDimensionsCenter, resizedShape, canvasOffset, [false, false]);
122
+ return { ...resizedShape,
123
+ x: resizedShape.x - (newOppTrueX - oppTrueX),
124
+ y: resizedShape.y - (newOppTrueY - oppTrueY)
125
+ };
126
+ };
127
+
128
+ exports.resizeTextShapeWithNewContent = resizeTextShapeWithNewContent;
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.drawTriangle = void 0;
7
+
8
+ var _canvas = require("../canvas");
9
+
10
+ const drawTriangle = (ctx, triangle) => {
11
+ var _triangle$style, _triangle$style2;
12
+
13
+ (0, _canvas.updateCanvasContext)(ctx, triangle.style);
14
+ if (ctx.globalAlpha === 0) return;
15
+ ctx.beginPath();
16
+ ctx.moveTo(...triangle.points[0]);
17
+ ctx.lineTo(...triangle.points[1]);
18
+ ctx.lineTo(...triangle.points[2]);
19
+ ctx.lineTo(...triangle.points[0]);
20
+ ((_triangle$style = triangle.style) === null || _triangle$style === void 0 ? void 0 : _triangle$style.fillColor) !== 'transparent' && ctx.fill();
21
+ ((_triangle$style2 = triangle.style) === null || _triangle$style2 === void 0 ? void 0 : _triangle$style2.strokeColor) !== 'transparent' && ctx.stroke();
22
+ };
23
+
24
+ exports.drawTriangle = drawTriangle;
@@ -5,42 +5,40 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.getShapePicture = void 0;
7
7
 
8
- var _Shapes = require("../types/Shapes");
9
-
10
8
  var _icons = require("../constants/icons");
11
9
 
12
10
  const getShapePicture = shape => {
13
11
  switch (shape) {
14
- case _Shapes.ShapeEnum.brush:
12
+ case 'brush':
15
13
  return _icons.brushIcon;
16
14
 
17
- case _Shapes.ShapeEnum.line:
15
+ case 'line':
18
16
  return _icons.arrowIcon;
19
17
 
20
- case _Shapes.ShapeEnum.polygon:
18
+ case 'polygon':
21
19
  return _icons.polygonIcon;
22
20
 
23
- case _Shapes.ShapeEnum.curve:
21
+ case 'curve':
24
22
  return _icons.curveIcon;
25
23
 
26
- case _Shapes.ShapeEnum.rect:
24
+ case 'rect':
27
25
  return _icons.squareIcon;
28
26
  // temporary
29
27
 
30
- case _Shapes.ShapeEnum.square:
28
+ case 'square':
31
29
  return _icons.squareIcon;
32
30
 
33
- case _Shapes.ShapeEnum.circle:
31
+ case 'circle':
34
32
  return _icons.circleIcon;
35
33
 
36
- case _Shapes.ShapeEnum.ellipse:
34
+ case 'ellipse':
37
35
  return _icons.circleIcon;
38
36
  // temporary
39
37
 
40
- case _Shapes.ShapeEnum.text:
38
+ case 'text':
41
39
  return _icons.textIcon;
42
40
 
43
- case _Shapes.ShapeEnum.picture:
41
+ case 'picture':
44
42
  return _icons.pictureIcon;
45
43
  }
46
44
  };
@@ -7,8 +7,6 @@ Object.defineProperty(exports, "__esModule", {
7
7
  });
8
8
  exports.sanitizeTools = exports.getCurrentStructure = void 0;
9
9
 
10
- var _Shapes = require("../types/Shapes");
11
-
12
10
  var _fp = _interopRequireDefault(require("lodash/fp"));
13
11
 
14
12
  var _tools = require("../constants/tools");
@@ -45,31 +43,31 @@ const sanitizeTools = function (tools) {
45
43
  if (!_fp.default.isObject(tool)) return null;
46
44
 
47
45
  switch (_fp.default.get('type', tool)) {
48
- case _Shapes.ShapeEnum.brush:
46
+ case 'brush':
49
47
  return _fp.default.mergeWith(customizer, _tools.DEFAULT_SHAPE_BRUSH, tool);
50
48
 
51
- case _Shapes.ShapeEnum.circle:
49
+ case 'circle':
52
50
  return _fp.default.mergeWith(customizer, _tools.DEFAULT_SHAPE_CIRCLE, tool);
53
51
 
54
- case _Shapes.ShapeEnum.curve:
52
+ case 'curve':
55
53
  return _fp.default.mergeWith(customizer, _tools.DEFAULT_SHAPE_CURVE, tool);
56
54
 
57
- case _Shapes.ShapeEnum.ellipse:
55
+ case 'ellipse':
58
56
  return _fp.default.mergeWith(customizer, _tools.DEFAULT_SHAPE_ELLIPSE, tool);
59
57
 
60
- case _Shapes.ShapeEnum.line:
58
+ case 'line':
61
59
  return _fp.default.mergeWith(customizer, _tools.DEFAULT_SHAPE_LINE, tool);
62
60
 
63
- case _Shapes.ShapeEnum.polygon:
61
+ case 'polygon':
64
62
  return _fp.default.mergeWith(customizer, _tools.DEFAULT_SHAPE_POLYGON, tool);
65
63
 
66
- case _Shapes.ShapeEnum.rect:
64
+ case 'rect':
67
65
  return _fp.default.mergeWith(customizer, _tools.DEFAULT_SHAPE_RECT, tool);
68
66
 
69
- case _Shapes.ShapeEnum.square:
67
+ case 'square':
70
68
  return _fp.default.mergeWith(customizer, _tools.DEFAULT_SHAPE_SQUARE, tool);
71
69
 
72
- case _Shapes.ShapeEnum.text:
70
+ case 'text':
73
71
  return _fp.default.mergeWith(customizer, _tools.DEFAULT_SHAPE_TEXT, tool);
74
72
  }
75
73