@yorab/react-paint 0.6.6 → 0.7.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/README.md +3 -5
- package/dist/components/App.js +30 -57
- package/dist/components/Canvas.js +32 -40
- package/dist/components/common/Button.js +4 -4
- package/dist/components/common/Loading.js +8 -5
- package/dist/components/common/Modal.js +3 -3
- package/dist/components/common/Panel.js +7 -11
- package/dist/components/common/Snackbar.js +6 -6
- package/dist/components/settings/ColorField.js +3 -3
- package/dist/components/settings/FontFamilyField.js +1 -1
- package/dist/components/settings/Layouts.js +36 -26
- package/dist/components/settings/LineArrowField.js +3 -3
- package/dist/components/settings/LineTypeField.js +2 -2
- package/dist/components/settings/RangeField.js +1 -1
- package/dist/components/settings/SelectField.js +1 -1
- package/dist/components/settings/SettingsBar.js +9 -7
- package/dist/components/toolbox/EditTextBox.js +19 -9
- package/dist/components/toolbox/MenuGroup.js +9 -7
- package/dist/components/toolbox/Toolbar.js +7 -9
- package/dist/components/toolbox/ToolbarGroup.js +24 -11
- package/dist/constants/app.js +51 -0
- package/dist/constants/icons.js +2 -8
- package/dist/constants/loading.js +8 -0
- package/dist/constants/shapes.js +4 -2
- package/dist/constants/snackbar.js +6 -14
- package/dist/constants/style.js +12 -9
- package/dist/constants/tools.js +20 -24
- package/dist/hooks/useComponent.js +3 -1
- package/dist/hooks/useDrawableCanvas.js +35 -37
- package/dist/hooks/useKeyboard.js +60 -33
- package/dist/hooks/useShapes.js +2 -2
- package/dist/styles.css +16 -13
- package/dist/types/Mode.js +1 -13
- package/dist/types/Shapes.js +1 -17
- package/dist/types/snackbar.js +5 -0
- package/dist/types/tools.js +1 -18
- package/dist/utils/canvas.js +49 -0
- package/dist/utils/data.js +5 -248
- package/dist/utils/dom.js +12 -0
- package/dist/utils/file.js +12 -7
- package/dist/utils/intersect.js +29 -66
- package/dist/utils/migration.js +59 -0
- package/dist/utils/selection.js +9 -11
- package/dist/utils/shapes/brush.js +135 -0
- package/dist/utils/shapes/circle.js +93 -0
- package/dist/utils/shapes/curve.js +55 -0
- package/dist/utils/shapes/default.js +73 -0
- package/dist/utils/shapes/ellipse.js +101 -0
- package/dist/utils/shapes/grid.js +36 -0
- package/dist/utils/shapes/index.js +341 -0
- package/dist/utils/shapes/line.js +179 -0
- package/dist/utils/shapes/picture.js +88 -0
- package/dist/utils/shapes/polygon.js +69 -0
- package/dist/utils/shapes/rectangle.js +100 -0
- package/dist/utils/shapes/text.js +128 -0
- package/dist/utils/shapes/triangle.js +24 -0
- package/dist/utils/style.js +10 -12
- package/dist/utils/toolbar.js +9 -11
- package/dist/utils/transform.js +25 -261
- package/dist/utils/trigo.js +42 -0
- package/package.json +7 -8
- package/dist/types/keyboard.js +0 -28
- package/dist/utils/draw.js +0 -431
- package/dist/utils/shapeData.js +0 -155
package/dist/utils/intersect.js
CHANGED
|
@@ -5,17 +5,15 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", {
|
|
6
6
|
value: true
|
|
7
7
|
});
|
|
8
|
-
exports.
|
|
8
|
+
exports.getPointPositionBeforeCanvasTransformation = exports.getPointPositionAfterCanvasTransformation = exports.getCursorPosition = exports.checkPositionIntersection = void 0;
|
|
9
9
|
|
|
10
10
|
var _shapes = require("../constants/shapes");
|
|
11
11
|
|
|
12
12
|
var _fp = _interopRequireDefault(require("lodash/fp"));
|
|
13
13
|
|
|
14
|
-
var
|
|
14
|
+
var _shapes2 = require("./shapes");
|
|
15
15
|
|
|
16
|
-
var
|
|
17
|
-
|
|
18
|
-
var _shapeData = require("./shapeData");
|
|
16
|
+
var _trigo = require("./trigo");
|
|
19
17
|
|
|
20
18
|
const getCursorPosition = function (e, canvas, givenWidth, givenHeight) {
|
|
21
19
|
var _canvas$getBoundingCl;
|
|
@@ -38,65 +36,30 @@ const getCursorPosition = function (e, canvas, givenWidth, givenHeight) {
|
|
|
38
36
|
|
|
39
37
|
exports.getCursorPosition = getCursorPosition;
|
|
40
38
|
|
|
41
|
-
const
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
const shapeInfos = (0, _shapeData.getShapeInfos)(shape, selectionPadding);
|
|
45
|
-
const positionInCanvas = getPointPositionBeforeCanvasTransformation(shapeInfos.center, [-shape.translation[0], -shape.translation[1]], shape.rotation, shapeInfos.center);
|
|
46
|
-
const canvasBoundingRect = (_canvas$getBoundingCl2 = canvas === null || canvas === void 0 ? void 0 : canvas.getBoundingClientRect()) !== null && _canvas$getBoundingCl2 !== void 0 ? _canvas$getBoundingCl2 : {
|
|
47
|
-
left: 0,
|
|
48
|
-
top: 0,
|
|
49
|
-
width: givenWidth,
|
|
50
|
-
height: givenHeight
|
|
51
|
-
};
|
|
52
|
-
return [canvasBoundingRect.left + positionInCanvas[0] * (canvasBoundingRect.width / givenWidth), canvasBoundingRect.top + positionInCanvas[1] * (canvasBoundingRect.height / givenHeight)];
|
|
53
|
-
};
|
|
54
|
-
|
|
55
|
-
exports.getSettingsPosition = getSettingsPosition;
|
|
56
|
-
|
|
57
|
-
const isPointInsideRect = (rect, point) => {
|
|
58
|
-
return point[0] >= rect.x && point[0] <= rect.x + rect.width && point[1] >= rect.y && point[1] <= rect.y + rect.height;
|
|
59
|
-
};
|
|
60
|
-
|
|
61
|
-
const getPointPositionAfterCanvasTransformation = (_ref, _ref2, _ref3, shapeRotation, _ref4) => {
|
|
62
|
-
let [positionX, positionY] = _ref;
|
|
39
|
+
const getPointPositionAfterCanvasTransformation = (point, shapeRotation, _ref, _ref2) => {
|
|
40
|
+
let [originX, originY] = _ref;
|
|
63
41
|
let [canvasOffsetX, canvasOffsetY] = _ref2;
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
const rotatedX = newY * Math.sin(shapeRotation) + newX * Math.cos(shapeRotation);
|
|
70
|
-
const translatedX = rotatedX + centerX;
|
|
71
|
-
const translatedY = rotatedY + centerY;
|
|
72
|
-
return [translatedX, translatedY];
|
|
42
|
+
return (0, _trigo.rotatePoint)({
|
|
43
|
+
origin: [originX - canvasOffsetX, originY - canvasOffsetY],
|
|
44
|
+
point,
|
|
45
|
+
rotation: shapeRotation
|
|
46
|
+
});
|
|
73
47
|
};
|
|
74
48
|
|
|
75
49
|
exports.getPointPositionAfterCanvasTransformation = getPointPositionAfterCanvasTransformation;
|
|
76
50
|
|
|
77
|
-
const getPointPositionBeforeCanvasTransformation = (
|
|
78
|
-
let [
|
|
79
|
-
let [
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
const translatedX = rotatedX + centerX;
|
|
86
|
-
const translatedY = rotatedY + centerY;
|
|
87
|
-
return [translatedX - translationX, translatedY - translationY];
|
|
51
|
+
const getPointPositionBeforeCanvasTransformation = (point, shapeRotation, _ref3, _ref4) => {
|
|
52
|
+
let [originX, originY] = _ref3;
|
|
53
|
+
let [canvasOffsetX, canvasOffsetY] = _ref4;
|
|
54
|
+
return (0, _trigo.rotatePoint)({
|
|
55
|
+
origin: [originX - canvasOffsetX, originY - canvasOffsetY],
|
|
56
|
+
point,
|
|
57
|
+
rotation: -shapeRotation
|
|
58
|
+
});
|
|
88
59
|
};
|
|
89
60
|
|
|
90
61
|
exports.getPointPositionBeforeCanvasTransformation = getPointPositionBeforeCanvasTransformation;
|
|
91
62
|
|
|
92
|
-
const applyRotationToVector = (vector, shapeRotation) => {
|
|
93
|
-
const rotatedY = vector[1] * Math.cos(shapeRotation) - vector[0] * Math.sin(shapeRotation);
|
|
94
|
-
const rotatedX = vector[1] * Math.sin(shapeRotation) + vector[0] * Math.cos(shapeRotation);
|
|
95
|
-
return [rotatedX, rotatedY];
|
|
96
|
-
};
|
|
97
|
-
|
|
98
|
-
exports.applyRotationToVector = applyRotationToVector;
|
|
99
|
-
|
|
100
63
|
const checkPositionIntersection = function (shape, position, canvasOffset, selectionPadding) {
|
|
101
64
|
let currentScale = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : 1;
|
|
102
65
|
let checkAnchors = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : false;
|
|
@@ -105,45 +68,45 @@ const checkPositionIntersection = function (shape, position, canvasOffset, selec
|
|
|
105
68
|
const {
|
|
106
69
|
borders,
|
|
107
70
|
center
|
|
108
|
-
} = (0,
|
|
109
|
-
const newPosition = getPointPositionAfterCanvasTransformation(position,
|
|
71
|
+
} = (0, _shapes2.getShapeInfos)(shape, selectionPadding);
|
|
72
|
+
const newPosition = getPointPositionAfterCanvasTransformation(position, shape.rotation, center, canvasOffset);
|
|
110
73
|
|
|
111
74
|
if (checkAnchors) {
|
|
112
|
-
if (shape.type ===
|
|
75
|
+
if (shape.type === 'line' || shape.type === 'polygon' || shape.type === 'curve') {
|
|
113
76
|
for (let i = 0; i < shape.points.length; i++) {
|
|
114
|
-
if (isPointInsideRect({
|
|
77
|
+
if ((0, _trigo.isPointInsideRect)({
|
|
115
78
|
x: shape.points[i][0] - _shapes.SELECTION_ANCHOR_SIZE / 2 / scaleWithMinCap,
|
|
116
79
|
y: shape.points[i][1] - _shapes.SELECTION_ANCHOR_SIZE / 2 / scaleWithMinCap,
|
|
117
80
|
width: _shapes.SELECTION_ANCHOR_SIZE / scaleWithMinCap,
|
|
118
81
|
height: _shapes.SELECTION_ANCHOR_SIZE / scaleWithMinCap
|
|
119
82
|
}, newPosition)) {
|
|
120
83
|
return {
|
|
121
|
-
mode:
|
|
84
|
+
mode: 'resize',
|
|
122
85
|
anchor: i
|
|
123
86
|
};
|
|
124
87
|
}
|
|
125
88
|
}
|
|
126
89
|
} else {
|
|
127
|
-
if (isPointInsideRect({
|
|
90
|
+
if ((0, _trigo.isPointInsideRect)({
|
|
128
91
|
x: borders.x + borders.width / 2 - _shapes.SELECTION_ANCHOR_SIZE / 2 / scaleWithMinCap,
|
|
129
92
|
y: borders.y - _shapes.SELECTION_ANCHOR_SIZE / scaleWithMinCap - _shapes.SELECTION_ROTATED_ANCHOR_POSITION / scaleWithMinCap,
|
|
130
93
|
width: _shapes.SELECTION_ANCHOR_SIZE / scaleWithMinCap,
|
|
131
94
|
height: _shapes.SELECTION_ANCHOR_SIZE / scaleWithMinCap
|
|
132
95
|
}, newPosition)) {
|
|
133
96
|
return {
|
|
134
|
-
mode:
|
|
97
|
+
mode: 'rotate'
|
|
135
98
|
};
|
|
136
99
|
}
|
|
137
100
|
|
|
138
101
|
for (const anchorPosition of _shapes.SELECTION_RESIZE_ANCHOR_POSITIONS) {
|
|
139
|
-
if (isPointInsideRect({
|
|
102
|
+
if ((0, _trigo.isPointInsideRect)({
|
|
140
103
|
x: borders.x + borders.width * anchorPosition[0] - _shapes.SELECTION_ANCHOR_SIZE / 2 / scaleWithMinCap,
|
|
141
104
|
y: borders.y + borders.height * anchorPosition[1] - _shapes.SELECTION_ANCHOR_SIZE / 2 / scaleWithMinCap,
|
|
142
105
|
width: _shapes.SELECTION_ANCHOR_SIZE / scaleWithMinCap,
|
|
143
106
|
height: _shapes.SELECTION_ANCHOR_SIZE / scaleWithMinCap
|
|
144
107
|
}, newPosition)) {
|
|
145
108
|
return {
|
|
146
|
-
mode:
|
|
109
|
+
mode: 'resize',
|
|
147
110
|
anchor: anchorPosition
|
|
148
111
|
};
|
|
149
112
|
}
|
|
@@ -151,8 +114,8 @@ const checkPositionIntersection = function (shape, position, canvasOffset, selec
|
|
|
151
114
|
}
|
|
152
115
|
}
|
|
153
116
|
|
|
154
|
-
return isPointInsideRect(borders, newPosition) ? {
|
|
155
|
-
mode:
|
|
117
|
+
return (0, _trigo.isPointInsideRect)(borders, newPosition) ? {
|
|
118
|
+
mode: 'translate'
|
|
156
119
|
} : false;
|
|
157
120
|
};
|
|
158
121
|
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.migrateShapesV065 = void 0;
|
|
9
|
+
|
|
10
|
+
var _fp = _interopRequireDefault(require("lodash/fp"));
|
|
11
|
+
|
|
12
|
+
const migrateShapesV065 = shapes => {
|
|
13
|
+
return _fp.default.map(shape => {
|
|
14
|
+
if (!shape.translation) {
|
|
15
|
+
return shape;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const translation = shape.translation;
|
|
19
|
+
|
|
20
|
+
switch (shape.type) {
|
|
21
|
+
case 'rect':
|
|
22
|
+
case 'square':
|
|
23
|
+
case 'ellipse':
|
|
24
|
+
case 'circle':
|
|
25
|
+
case 'picture':
|
|
26
|
+
return { ..._fp.default.omit(['translation'], shape),
|
|
27
|
+
x: shape.x + translation[0],
|
|
28
|
+
y: shape.y + translation[1]
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
case 'line':
|
|
32
|
+
return { ..._fp.default.omit(['translation'], shape),
|
|
33
|
+
points: shape.points.map(_ref => {
|
|
34
|
+
let [x, y] = _ref;
|
|
35
|
+
return [x + translation[0], y + translation[1]];
|
|
36
|
+
})
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
case 'polygon':
|
|
40
|
+
case 'curve':
|
|
41
|
+
return { ..._fp.default.omit(['translation'], shape),
|
|
42
|
+
points: shape.points.map(_ref2 => {
|
|
43
|
+
let [x, y] = _ref2;
|
|
44
|
+
return [x + translation[0], y + translation[1]];
|
|
45
|
+
})
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
case 'brush':
|
|
49
|
+
return { ..._fp.default.omit(['translation'], shape),
|
|
50
|
+
points: shape.points.map(coord => coord.map(_ref3 => {
|
|
51
|
+
let [x, y] = _ref3;
|
|
52
|
+
return [x + translation[0], y + translation[1]];
|
|
53
|
+
}))
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
}, shapes);
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
exports.migrateShapesV065 = migrateShapesV065;
|
package/dist/utils/selection.js
CHANGED
|
@@ -9,33 +9,31 @@ exports.selectShape = exports.getNewSelectionData = void 0;
|
|
|
9
9
|
|
|
10
10
|
var _fp = _interopRequireDefault(require("lodash/fp"));
|
|
11
11
|
|
|
12
|
-
var _Mode = require("../types/Mode");
|
|
13
|
-
|
|
14
12
|
var _intersect = require("./intersect");
|
|
15
13
|
|
|
16
|
-
var
|
|
14
|
+
var _shapes = require("./shapes");
|
|
17
15
|
|
|
18
16
|
const getNewSelectionData = (hoverMode, selectedShape, cursorPosition, selectionPadding) => {
|
|
19
17
|
if (hoverMode.mode === 'translate') {
|
|
20
18
|
return {
|
|
21
|
-
mode:
|
|
19
|
+
mode: 'translate',
|
|
22
20
|
cursorStartPosition: cursorPosition,
|
|
23
21
|
originalShape: selectedShape
|
|
24
22
|
};
|
|
25
23
|
} else if (hoverMode.mode === 'rotate') {
|
|
26
24
|
const {
|
|
27
25
|
center: centerBeforeResize
|
|
28
|
-
} = (0,
|
|
26
|
+
} = (0, _shapes.getShapeInfos)(selectedShape, selectionPadding);
|
|
29
27
|
const center = [centerBeforeResize[0], centerBeforeResize[1]];
|
|
30
28
|
return {
|
|
31
|
-
mode:
|
|
29
|
+
mode: 'rotate',
|
|
32
30
|
cursorStartPosition: cursorPosition,
|
|
33
31
|
originalShape: selectedShape,
|
|
34
32
|
center
|
|
35
33
|
};
|
|
36
34
|
} else if (hoverMode.mode === 'resize') {
|
|
37
35
|
return {
|
|
38
|
-
mode:
|
|
36
|
+
mode: 'resize',
|
|
39
37
|
cursorStartPosition: cursorPosition,
|
|
40
38
|
originalShape: selectedShape,
|
|
41
39
|
anchor: hoverMode.anchor
|
|
@@ -50,11 +48,11 @@ exports.getNewSelectionData = getNewSelectionData;
|
|
|
50
48
|
const selectShape = (shapes, cursorPosition, currentScale, canvasOffset, selectedShape, selectionPadding) => {
|
|
51
49
|
if (selectedShape) {
|
|
52
50
|
const positionIntersection = (0, _intersect.checkPositionIntersection)(selectedShape, cursorPosition, canvasOffset, selectionPadding, currentScale, true) || {
|
|
53
|
-
mode:
|
|
51
|
+
mode: 'default'
|
|
54
52
|
};
|
|
55
53
|
const newSelectionMode = getNewSelectionData(positionIntersection, selectedShape, cursorPosition, selectionPadding);
|
|
56
54
|
|
|
57
|
-
if ((newSelectionMode === null || newSelectionMode === void 0 ? void 0 : newSelectionMode.mode) ===
|
|
55
|
+
if ((newSelectionMode === null || newSelectionMode === void 0 ? void 0 : newSelectionMode.mode) === 'resize' || (newSelectionMode === null || newSelectionMode === void 0 ? void 0 : newSelectionMode.mode) === 'rotate') {
|
|
58
56
|
return {
|
|
59
57
|
shape: selectedShape,
|
|
60
58
|
mode: newSelectionMode
|
|
@@ -70,7 +68,7 @@ const selectShape = (shapes, cursorPosition, currentScale, canvasOffset, selecte
|
|
|
70
68
|
return {
|
|
71
69
|
shape: foundShape,
|
|
72
70
|
mode: {
|
|
73
|
-
mode:
|
|
71
|
+
mode: 'translate',
|
|
74
72
|
cursorStartPosition: cursorPosition,
|
|
75
73
|
originalShape: foundShape
|
|
76
74
|
}
|
|
@@ -79,7 +77,7 @@ const selectShape = (shapes, cursorPosition, currentScale, canvasOffset, selecte
|
|
|
79
77
|
return {
|
|
80
78
|
shape: undefined,
|
|
81
79
|
mode: {
|
|
82
|
-
mode:
|
|
80
|
+
mode: 'default'
|
|
83
81
|
}
|
|
84
82
|
};
|
|
85
83
|
}
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.resizeBrush = exports.getBrushBorder = exports.drawBrush = exports.createBrush = exports.addNewPointToShape = exports.addNewPointGroupToShape = 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
|
+
var _rectangle = require("./rectangle");
|
|
21
|
+
|
|
22
|
+
const createBrush = (shape, cursorPosition) => {
|
|
23
|
+
return {
|
|
24
|
+
toolId: shape.id,
|
|
25
|
+
type: shape.type,
|
|
26
|
+
id: _fp.default.uniqueId("".concat(shape.type, "_")),
|
|
27
|
+
points: [[cursorPosition]],
|
|
28
|
+
rotation: 0,
|
|
29
|
+
style: {
|
|
30
|
+
globalAlpha: shape.settings.opacity.default,
|
|
31
|
+
strokeColor: shape.settings.strokeColor.default,
|
|
32
|
+
lineWidth: shape.settings.lineWidth.default,
|
|
33
|
+
lineDash: shape.settings.lineDash.default
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
exports.createBrush = createBrush;
|
|
39
|
+
|
|
40
|
+
const drawBrush = (ctx, brush) => {
|
|
41
|
+
var _brush$style;
|
|
42
|
+
|
|
43
|
+
if (brush.points.length < 1) return;
|
|
44
|
+
(0, _canvas.updateCanvasContext)(ctx, brush.style);
|
|
45
|
+
ctx.beginPath();
|
|
46
|
+
if (((_brush$style = brush.style) === null || _brush$style === void 0 ? void 0 : _brush$style.strokeColor) === 'transparent' || ctx.globalAlpha === 0) return;
|
|
47
|
+
brush.points.forEach(points => {
|
|
48
|
+
if (points.length === 1) {
|
|
49
|
+
ctx.rect(points[0][0], points[0][1], 1, 1);
|
|
50
|
+
} else {
|
|
51
|
+
ctx.moveTo(...points[0]);
|
|
52
|
+
points.slice(1).forEach(point => {
|
|
53
|
+
ctx.lineTo(...point);
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
ctx.stroke();
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
exports.drawBrush = drawBrush;
|
|
61
|
+
|
|
62
|
+
const getBrushBorder = (brush, selectionPadding) => {
|
|
63
|
+
const brushPoints = _fp.default.flatMap(points => points, brush.points);
|
|
64
|
+
|
|
65
|
+
const minX = _fp.default.flow(_fp.default.map(point => point[0]), _fp.default.min, _fp.default.add(-selectionPadding))(brushPoints);
|
|
66
|
+
|
|
67
|
+
const maxX = _fp.default.flow(_fp.default.map(point => point[0]), _fp.default.max, _fp.default.add(selectionPadding))(brushPoints);
|
|
68
|
+
|
|
69
|
+
const minY = _fp.default.flow(_fp.default.map(point => point[1]), _fp.default.min, _fp.default.add(-selectionPadding))(brushPoints);
|
|
70
|
+
|
|
71
|
+
const maxY = _fp.default.flow(_fp.default.map(point => point[1]), _fp.default.max, _fp.default.add(selectionPadding))(brushPoints);
|
|
72
|
+
|
|
73
|
+
return {
|
|
74
|
+
x: minX,
|
|
75
|
+
width: maxX - minX,
|
|
76
|
+
y: minY,
|
|
77
|
+
height: maxY - minY
|
|
78
|
+
};
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
exports.getBrushBorder = getBrushBorder;
|
|
82
|
+
|
|
83
|
+
const resizeBrush = (cursorPosition, canvasOffset, originalShape, selectionMode, selectionPadding, keepRatio) => {
|
|
84
|
+
const {
|
|
85
|
+
center,
|
|
86
|
+
borders
|
|
87
|
+
} = (0, _2.getShapeInfos)(originalShape, selectionPadding);
|
|
88
|
+
const cursorPositionBeforeResize = (0, _intersect.getPointPositionAfterCanvasTransformation)(cursorPosition, originalShape.rotation, center, canvasOffset);
|
|
89
|
+
const scaledWidth = selectionMode.anchor[0] === 0.5 ? 1 : selectionMode.anchor[0] === 0 ? (borders.x + borders.width - cursorPositionBeforeResize[0] + selectionPadding * -2) / (borders.width + selectionPadding * -2) : (cursorPositionBeforeResize[0] - borders.x - selectionPadding * 2) / (borders.width - selectionPadding * 2);
|
|
90
|
+
const scaledHeight = selectionMode.anchor[1] === 0.5 ? 1 : selectionMode.anchor[1] === 0 ? (borders.y + borders.height - cursorPositionBeforeResize[1] + selectionPadding * -2) / (borders.height + selectionPadding * -2) : (cursorPositionBeforeResize[1] - borders.y - selectionPadding * 2) / (borders.height - selectionPadding * 2);
|
|
91
|
+
const [widthWithRatio, heightWithRatio] = keepRatio ? (0, _transform.getNormalizedSize)(1, 1, scaledWidth, scaledHeight) : [scaledWidth, scaledHeight];
|
|
92
|
+
const shapeWithNewDimensions = { ...originalShape,
|
|
93
|
+
points: originalShape.points.map(points => {
|
|
94
|
+
return points.map(point => [(point[0] - borders.x) * widthWithRatio + borders.x, (point[1] - borders.y) * heightWithRatio + borders.y]);
|
|
95
|
+
})
|
|
96
|
+
};
|
|
97
|
+
const {
|
|
98
|
+
center: shapeWithNewDimensionsCenter,
|
|
99
|
+
borders: shapeWithNewDimensionsBorders
|
|
100
|
+
} = (0, _2.getShapeInfos)(shapeWithNewDimensions, selectionPadding);
|
|
101
|
+
const [oppTrueX, oppTrueY] = (0, _rectangle.getRectOppositeAnchorAbsolutePosition)(selectionMode.anchor, center, { ...originalShape,
|
|
102
|
+
...borders
|
|
103
|
+
}, canvasOffset);
|
|
104
|
+
const [newOppTrueX, newOppTrueY] = (0, _rectangle.getRectOppositeAnchorAbsolutePosition)(selectionMode.anchor, shapeWithNewDimensionsCenter, { ...shapeWithNewDimensions,
|
|
105
|
+
...shapeWithNewDimensionsBorders
|
|
106
|
+
}, canvasOffset, [widthWithRatio < 0, heightWithRatio < 0]);
|
|
107
|
+
return { ...shapeWithNewDimensions,
|
|
108
|
+
points: shapeWithNewDimensions.points.map(coord => coord.map(_ref => {
|
|
109
|
+
let [x, y] = _ref;
|
|
110
|
+
return [x - (newOppTrueX - oppTrueX), y - (newOppTrueY - oppTrueY)];
|
|
111
|
+
}))
|
|
112
|
+
};
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
exports.resizeBrush = resizeBrush;
|
|
116
|
+
|
|
117
|
+
const addNewPointToShape = (shape, cursorPosition) => {
|
|
118
|
+
return { ...shape,
|
|
119
|
+
...{
|
|
120
|
+
points: _fp.default.set(shape.points.length - 1, [...shape.points[shape.points.length - 1], [Math.round(cursorPosition[0]), Math.round(cursorPosition[1])]], shape.points)
|
|
121
|
+
}
|
|
122
|
+
};
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
exports.addNewPointToShape = addNewPointToShape;
|
|
126
|
+
|
|
127
|
+
const addNewPointGroupToShape = (shape, cursorPosition) => {
|
|
128
|
+
return { ...shape,
|
|
129
|
+
...{
|
|
130
|
+
points: _fp.default.set(shape.points.length, [[Math.round(cursorPosition[0]), Math.round(cursorPosition[1])]], shape.points)
|
|
131
|
+
}
|
|
132
|
+
};
|
|
133
|
+
};
|
|
134
|
+
|
|
135
|
+
exports.addNewPointGroupToShape = addNewPointGroupToShape;
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.resizeCircle = exports.getCircleBorder = exports.drawCircle = exports.createCircle = 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 _2 = require(".");
|
|
17
|
+
|
|
18
|
+
const createCircle = (shape, cursorPosition) => {
|
|
19
|
+
return {
|
|
20
|
+
toolId: shape.id,
|
|
21
|
+
type: shape.type,
|
|
22
|
+
id: _fp.default.uniqueId("".concat(shape.type, "_")),
|
|
23
|
+
x: cursorPosition[0],
|
|
24
|
+
y: cursorPosition[1],
|
|
25
|
+
radius: 1,
|
|
26
|
+
rotation: 0,
|
|
27
|
+
style: {
|
|
28
|
+
globalAlpha: shape.settings.opacity.default,
|
|
29
|
+
fillColor: shape.settings.fillColor.default,
|
|
30
|
+
strokeColor: shape.settings.strokeColor.default,
|
|
31
|
+
lineWidth: shape.settings.lineWidth.default,
|
|
32
|
+
lineDash: shape.settings.lineDash.default
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
exports.createCircle = createCircle;
|
|
38
|
+
|
|
39
|
+
const drawCircle = (ctx, circle) => {
|
|
40
|
+
var _circle$style, _circle$style2;
|
|
41
|
+
|
|
42
|
+
(0, _canvas.updateCanvasContext)(ctx, circle.style);
|
|
43
|
+
ctx.beginPath();
|
|
44
|
+
ctx.arc(circle.x, circle.y, circle.radius, 0, 2 * Math.PI);
|
|
45
|
+
((_circle$style = circle.style) === null || _circle$style === void 0 ? void 0 : _circle$style.fillColor) !== 'transparent' && ctx.fill();
|
|
46
|
+
((_circle$style2 = circle.style) === null || _circle$style2 === void 0 ? void 0 : _circle$style2.strokeColor) !== 'transparent' && ctx.stroke();
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
exports.drawCircle = drawCircle;
|
|
50
|
+
|
|
51
|
+
const getCircleBorder = (circle, selectionPadding) => {
|
|
52
|
+
return {
|
|
53
|
+
x: circle.x - circle.radius - selectionPadding,
|
|
54
|
+
width: (circle.radius + selectionPadding) * 2,
|
|
55
|
+
y: circle.y - circle.radius - selectionPadding,
|
|
56
|
+
height: (circle.radius + selectionPadding) * 2
|
|
57
|
+
};
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
exports.getCircleBorder = getCircleBorder;
|
|
61
|
+
|
|
62
|
+
const getCircleOppositeAnchorAbsolutePosition = function (anchor, center, shape, canvasOffset) {
|
|
63
|
+
let [negW, negH] = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : [false, false];
|
|
64
|
+
const oppositeX = anchor[0] === 0.5 ? shape.x : anchor[0] === 0 ? shape.x + (negW ? -shape.radius : shape.radius) : shape.x + (negW ? shape.radius : -shape.radius);
|
|
65
|
+
const oppositeY = anchor[1] === 0.5 ? shape.y : anchor[1] === 0 ? shape.y + (negH ? -shape.radius : shape.radius) : shape.y + (negH ? shape.radius : -shape.radius);
|
|
66
|
+
return (0, _intersect.getPointPositionBeforeCanvasTransformation)([oppositeX, oppositeY], shape.rotation, center, canvasOffset);
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
const resizeCircle = (cursorPosition, canvasOffset, originalShape, selectionMode, selectionPadding) => {
|
|
70
|
+
const {
|
|
71
|
+
center,
|
|
72
|
+
borders
|
|
73
|
+
} = (0, _2.getShapeInfos)(originalShape, selectionPadding);
|
|
74
|
+
const cursorPositionBeforeResize = (0, _intersect.getPointPositionAfterCanvasTransformation)(cursorPosition, originalShape.rotation, center, canvasOffset);
|
|
75
|
+
const newCursorPosition = [cursorPositionBeforeResize[0], cursorPositionBeforeResize[1]];
|
|
76
|
+
const scaledRadius = selectionMode.anchor[1] === 0.5 ? (selectionMode.anchor[0] === 0 ? borders.x + borders.width - newCursorPosition[0] + selectionPadding * (selectionMode.anchor[0] === 0 ? -2 : 2) : newCursorPosition[0] - borders.x - selectionPadding * (selectionMode.anchor[0] === 0 ? -2 : 2)) / 2 : (selectionMode.anchor[1] === 0 ? borders.y + borders.height - newCursorPosition[1] + selectionPadding * (selectionMode.anchor[1] === 0 ? -2 : 2) : newCursorPosition[1] - borders.y - selectionPadding * (selectionMode.anchor[1] === 0 ? -2 : 2)) / 2;
|
|
77
|
+
const shapeWithNewDimensions = { ...originalShape,
|
|
78
|
+
...{
|
|
79
|
+
radius: Math.abs(scaledRadius)
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
const {
|
|
83
|
+
center: shapeWithNewDimensionsCenter
|
|
84
|
+
} = (0, _2.getShapeInfos)(shapeWithNewDimensions, selectionPadding);
|
|
85
|
+
const [oppTrueX, oppTrueY] = getCircleOppositeAnchorAbsolutePosition(selectionMode.anchor, center, originalShape, canvasOffset);
|
|
86
|
+
const [newOppTrueX, newOppTrueY] = getCircleOppositeAnchorAbsolutePosition(selectionMode.anchor, shapeWithNewDimensionsCenter, shapeWithNewDimensions, canvasOffset, [scaledRadius < 0, scaledRadius < 0]);
|
|
87
|
+
return { ...shapeWithNewDimensions,
|
|
88
|
+
x: shapeWithNewDimensions.x - (newOppTrueX - oppTrueX),
|
|
89
|
+
y: shapeWithNewDimensions.y - (newOppTrueY - oppTrueY)
|
|
90
|
+
};
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
exports.resizeCircle = resizeCircle;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.getCurveBorder = exports.drawCurve = exports.createCurve = void 0;
|
|
9
|
+
|
|
10
|
+
var _fp = _interopRequireDefault(require("lodash/fp"));
|
|
11
|
+
|
|
12
|
+
var _canvas = require("../canvas");
|
|
13
|
+
|
|
14
|
+
var _polygon = require("./polygon");
|
|
15
|
+
|
|
16
|
+
const createCurve = (shape, cursorPosition) => {
|
|
17
|
+
return {
|
|
18
|
+
toolId: shape.id,
|
|
19
|
+
type: shape.type,
|
|
20
|
+
id: _fp.default.uniqueId("".concat(shape.type, "_")),
|
|
21
|
+
points: _fp.default.flow(_fp.default.range(0), _fp.default.map(() => cursorPosition))(shape.settings.pointsCount.default),
|
|
22
|
+
rotation: 0,
|
|
23
|
+
style: {
|
|
24
|
+
globalAlpha: shape.settings.opacity.default,
|
|
25
|
+
fillColor: shape.settings.fillColor.default,
|
|
26
|
+
strokeColor: shape.settings.strokeColor.default,
|
|
27
|
+
lineWidth: shape.settings.lineWidth.default,
|
|
28
|
+
lineDash: shape.settings.lineDash.default,
|
|
29
|
+
pointsCount: shape.settings.pointsCount.default
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
exports.createCurve = createCurve;
|
|
35
|
+
|
|
36
|
+
const drawCurve = (ctx, curve) => {
|
|
37
|
+
var _curve$style, _curve$style2;
|
|
38
|
+
|
|
39
|
+
if (curve.points.length < 3) return;
|
|
40
|
+
(0, _canvas.updateCanvasContext)(ctx, curve.style);
|
|
41
|
+
if (ctx.globalAlpha === 0) return;
|
|
42
|
+
ctx.beginPath();
|
|
43
|
+
ctx.moveTo(...curve.points[0]);
|
|
44
|
+
|
|
45
|
+
for (let i = 1; i < curve.points.length - 1; i++) {
|
|
46
|
+
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]);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
((_curve$style = curve.style) === null || _curve$style === void 0 ? void 0 : _curve$style.fillColor) !== 'transparent' && ctx.fill();
|
|
50
|
+
((_curve$style2 = curve.style) === null || _curve$style2 === void 0 ? void 0 : _curve$style2.strokeColor) !== 'transparent' && ctx.stroke();
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
exports.drawCurve = drawCurve;
|
|
54
|
+
const getCurveBorder = _polygon.getPolygonBorder;
|
|
55
|
+
exports.getCurveBorder = getCurveBorder;
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.drawSelectionDefault = void 0;
|
|
7
|
+
|
|
8
|
+
var _shapes = require("../../constants/shapes");
|
|
9
|
+
|
|
10
|
+
var _ = require(".");
|
|
11
|
+
|
|
12
|
+
var _circle = require("./circle");
|
|
13
|
+
|
|
14
|
+
var _line = require("./line");
|
|
15
|
+
|
|
16
|
+
var _rectangle = require("./rectangle");
|
|
17
|
+
|
|
18
|
+
const drawSelectionDefault = _ref => {
|
|
19
|
+
let {
|
|
20
|
+
ctx,
|
|
21
|
+
shape,
|
|
22
|
+
withAnchors,
|
|
23
|
+
selectionPadding,
|
|
24
|
+
selectionWidth,
|
|
25
|
+
selectionColor,
|
|
26
|
+
currentScale = 1
|
|
27
|
+
} = _ref;
|
|
28
|
+
const {
|
|
29
|
+
borders
|
|
30
|
+
} = (0, _.getShapeInfos)(shape, selectionPadding / currentScale);
|
|
31
|
+
(0, _rectangle.drawRect)(ctx, { ...borders,
|
|
32
|
+
style: {
|
|
33
|
+
fillColor: 'transparent',
|
|
34
|
+
strokeColor: selectionColor,
|
|
35
|
+
lineWidth: selectionWidth / currentScale
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
if (!withAnchors || shape.locked) return;
|
|
39
|
+
(0, _line.drawLine)(ctx, {
|
|
40
|
+
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]],
|
|
41
|
+
style: {
|
|
42
|
+
fillColor: 'transparent',
|
|
43
|
+
strokeColor: selectionColor,
|
|
44
|
+
lineWidth: selectionWidth / currentScale
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
for (const anchorPosition of _shapes.SELECTION_RESIZE_ANCHOR_POSITIONS) {
|
|
49
|
+
(0, _circle.drawCircle)(ctx, {
|
|
50
|
+
x: borders.x + borders.width * anchorPosition[0],
|
|
51
|
+
y: borders.y + borders.height * anchorPosition[1],
|
|
52
|
+
radius: _shapes.SELECTION_ANCHOR_SIZE / 2 / currentScale,
|
|
53
|
+
style: {
|
|
54
|
+
fillColor: 'rgb(255,255,255)',
|
|
55
|
+
strokeColor: 'rgb(150,150,150)',
|
|
56
|
+
lineWidth: selectionWidth / currentScale
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
(0, _circle.drawCircle)(ctx, {
|
|
62
|
+
x: borders.x + borders.width / 2,
|
|
63
|
+
y: borders.y - _shapes.SELECTION_ANCHOR_SIZE / 2 - _shapes.SELECTION_ROTATED_ANCHOR_POSITION / currentScale,
|
|
64
|
+
radius: _shapes.SELECTION_ANCHOR_SIZE / 2 / currentScale,
|
|
65
|
+
style: {
|
|
66
|
+
fillColor: 'rgb(255,255,255)',
|
|
67
|
+
strokeColor: 'rgb(150,150,150)',
|
|
68
|
+
lineWidth: selectionWidth / currentScale
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
exports.drawSelectionDefault = drawSelectionDefault;
|