@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.
- package/README.md +2 -0
- package/dist/components/App.js +224 -384
- 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 +24 -19
- 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 +53 -42
- 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 +6 -5
- package/Changelog.md +0 -123
package/dist/utils/file.js
CHANGED
|
@@ -7,12 +7,6 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
7
7
|
});
|
|
8
8
|
exports.getCanvasImage = exports.getBase64Image = exports.fetchAndStringify = exports.encodeShapesInString = exports.downloadFile = exports.decodeJson = exports.decodeImportedData = void 0;
|
|
9
9
|
|
|
10
|
-
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
|
|
11
|
-
|
|
12
|
-
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
13
|
-
|
|
14
|
-
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
|
15
|
-
|
|
16
10
|
var _fp = _interopRequireDefault(require("lodash/fp"));
|
|
17
11
|
|
|
18
12
|
var _Shapes = require("../types/Shapes");
|
|
@@ -21,22 +15,14 @@ var _data = require("./data");
|
|
|
21
15
|
|
|
22
16
|
var _draw = require("./draw");
|
|
23
17
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
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; }
|
|
27
|
-
|
|
28
|
-
var fetchAndStringify = function fetchAndStringify(url) {
|
|
29
|
-
return fetch(url).then(function (response) {
|
|
30
|
-
return response.blob();
|
|
31
|
-
}).then(function (myBlob) {
|
|
32
|
-
return URL.createObjectURL(myBlob);
|
|
33
|
-
});
|
|
18
|
+
const fetchAndStringify = url => {
|
|
19
|
+
return fetch(url).then(response => response.blob()).then(myBlob => URL.createObjectURL(myBlob));
|
|
34
20
|
};
|
|
35
21
|
|
|
36
22
|
exports.fetchAndStringify = fetchAndStringify;
|
|
37
23
|
|
|
38
|
-
|
|
39
|
-
|
|
24
|
+
const downloadFile = (content, fileName) => {
|
|
25
|
+
const a = document.createElement('a');
|
|
40
26
|
a.href = content;
|
|
41
27
|
a.download = fileName;
|
|
42
28
|
document.body.appendChild(a);
|
|
@@ -46,32 +32,32 @@ var downloadFile = function downloadFile(content, fileName) {
|
|
|
46
32
|
|
|
47
33
|
exports.downloadFile = downloadFile;
|
|
48
34
|
|
|
49
|
-
|
|
50
|
-
|
|
35
|
+
const getBase64Image = img => {
|
|
36
|
+
const canvas = document.createElement('canvas');
|
|
51
37
|
canvas.width = img.width;
|
|
52
38
|
canvas.height = img.height;
|
|
53
|
-
|
|
39
|
+
const ctx = canvas.getContext('2d');
|
|
54
40
|
if (!ctx) return '';
|
|
55
41
|
ctx.drawImage(img, 0, 0);
|
|
56
|
-
|
|
42
|
+
const dataURL = canvas.toDataURL('image/png');
|
|
57
43
|
return dataURL;
|
|
58
44
|
};
|
|
59
45
|
|
|
60
46
|
exports.getBase64Image = getBase64Image;
|
|
61
47
|
|
|
62
|
-
|
|
48
|
+
const encodeObjectToString = objectToEncode => {
|
|
63
49
|
return 'data:text/plain;charset=utf-8,' + encodeURIComponent(JSON.stringify(objectToEncode));
|
|
64
50
|
};
|
|
65
51
|
|
|
66
|
-
|
|
67
|
-
|
|
52
|
+
const getCanvasImage = (shapes, canvasOffset, width, height, selectionPadding) => {
|
|
53
|
+
const newCanvas = document.createElement('canvas');
|
|
68
54
|
newCanvas.width = width;
|
|
69
55
|
newCanvas.height = height;
|
|
70
|
-
|
|
56
|
+
const ctx = newCanvas.getContext('2d');
|
|
71
57
|
if (!ctx) return '';
|
|
72
58
|
ctx.clearRect(0, 0, width, height);
|
|
73
59
|
|
|
74
|
-
for (
|
|
60
|
+
for (let i = shapes.length - 1; i >= 0; i--) {
|
|
75
61
|
(0, _draw.drawShape)(ctx, shapes[i], 1, canvasOffset, selectionPadding);
|
|
76
62
|
}
|
|
77
63
|
|
|
@@ -80,108 +66,72 @@ var getCanvasImage = function getCanvasImage(shapes, canvasOffset, width, height
|
|
|
80
66
|
|
|
81
67
|
exports.getCanvasImage = getCanvasImage;
|
|
82
68
|
|
|
83
|
-
|
|
84
|
-
|
|
69
|
+
const encodeShapesInString = (shapes, width, height) => {
|
|
70
|
+
const dataToExport = (0, _data.buildDataToExport)(shapes, width, height);
|
|
85
71
|
return encodeObjectToString(dataToExport);
|
|
86
72
|
};
|
|
87
73
|
|
|
88
74
|
exports.encodeShapesInString = encodeShapesInString;
|
|
89
75
|
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
while (1) {
|
|
94
|
-
switch (_context.prev = _context.next) {
|
|
95
|
-
case 0:
|
|
96
|
-
return _context.abrupt("return", new Promise(function (resolve, reject) {
|
|
97
|
-
var reader = new FileReader();
|
|
98
|
-
|
|
99
|
-
reader.onload = function (event) {
|
|
100
|
-
var _event$target;
|
|
101
|
-
|
|
102
|
-
var result = (_event$target = event.target) === null || _event$target === void 0 ? void 0 : _event$target.result;
|
|
103
|
-
if (!result) return reject('Impossible de récupérer les données du fichier');
|
|
104
|
-
var json = JSON.parse(result);
|
|
105
|
-
resolve(json);
|
|
106
|
-
};
|
|
107
|
-
|
|
108
|
-
reader.readAsText(file);
|
|
109
|
-
}));
|
|
110
|
-
|
|
111
|
-
case 1:
|
|
112
|
-
case "end":
|
|
113
|
-
return _context.stop();
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
}, _callee);
|
|
117
|
-
}));
|
|
76
|
+
const decodeJson = async file => {
|
|
77
|
+
return new Promise((resolve, reject) => {
|
|
78
|
+
const reader = new FileReader();
|
|
118
79
|
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
80
|
+
reader.onload = event => {
|
|
81
|
+
var _event$target;
|
|
82
|
+
|
|
83
|
+
const result = (_event$target = event.target) === null || _event$target === void 0 ? void 0 : _event$target.result;
|
|
84
|
+
if (!result) return reject('Impossible de récupérer les données du fichier');
|
|
85
|
+
const json = JSON.parse(result);
|
|
86
|
+
resolve(json);
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
reader.readAsText(file);
|
|
90
|
+
});
|
|
91
|
+
};
|
|
123
92
|
|
|
124
93
|
exports.decodeJson = decodeJson;
|
|
125
94
|
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
})["catch"](function () {
|
|
155
|
-
img.src = ''; // to trigger onerror
|
|
156
|
-
});
|
|
157
|
-
} else {
|
|
158
|
-
img.src = shape.src;
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
return (0, _data.addDefaultAndTempShapeProps)(_objectSpread(_objectSpread({}, shape), {}, {
|
|
162
|
-
img: img
|
|
163
|
-
}));
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
return (0, _data.addDefaultAndTempShapeProps)(shape);
|
|
167
|
-
}), _fp["default"].compact)(jsonShapes);
|
|
168
|
-
_context2.next = 5;
|
|
169
|
-
return Promise.all(promisesArray);
|
|
170
|
-
|
|
171
|
-
case 5:
|
|
172
|
-
return _context2.abrupt("return", shapes);
|
|
173
|
-
|
|
174
|
-
case 6:
|
|
175
|
-
case "end":
|
|
176
|
-
return _context2.stop();
|
|
177
|
-
}
|
|
95
|
+
const decodeImportedData = async shapesForJson => {
|
|
96
|
+
const promisesArray = [];
|
|
97
|
+
const jsonShapes = shapesForJson.shapes;
|
|
98
|
+
|
|
99
|
+
const shapes = _fp.default.flow(_fp.default.map(shape => {
|
|
100
|
+
if (!_fp.default.includes(shape.type, _Shapes.ShapeEnum)) return null;
|
|
101
|
+
|
|
102
|
+
if (shape.type === _Shapes.ShapeEnum.picture) {
|
|
103
|
+
const img = new Image();
|
|
104
|
+
const newPromise = new Promise((resolve, reject) => {
|
|
105
|
+
img.onload = () => {
|
|
106
|
+
resolve();
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
img.onerror = () => {
|
|
110
|
+
reject(new Error('Some images could not be loaded'));
|
|
111
|
+
};
|
|
112
|
+
});
|
|
113
|
+
promisesArray.push(newPromise);
|
|
114
|
+
|
|
115
|
+
if (shape.src.startsWith('http')) {
|
|
116
|
+
fetchAndStringify(shape.src).then(picData => {
|
|
117
|
+
img.src = picData;
|
|
118
|
+
}).catch(() => {
|
|
119
|
+
img.src = ''; // to trigger onerror
|
|
120
|
+
});
|
|
121
|
+
} else {
|
|
122
|
+
img.src = shape.src;
|
|
178
123
|
}
|
|
179
|
-
}, _callee2);
|
|
180
|
-
}));
|
|
181
124
|
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
}
|
|
125
|
+
return (0, _data.addDefaultAndTempShapeProps)({ ...shape,
|
|
126
|
+
img
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
return (0, _data.addDefaultAndTempShapeProps)(shape);
|
|
131
|
+
}), _fp.default.compact)(jsonShapes);
|
|
132
|
+
|
|
133
|
+
await Promise.all(promisesArray);
|
|
134
|
+
return shapes;
|
|
135
|
+
};
|
|
186
136
|
|
|
187
137
|
exports.decodeImportedData = decodeImportedData;
|
package/dist/utils/intersect.js
CHANGED
|
@@ -7,8 +7,6 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
7
7
|
});
|
|
8
8
|
exports.getSettingsPosition = exports.getPointPositionBeforeCanvasTransformation = exports.getPointPositionAfterCanvasTransformation = exports.getCursorPosition = exports.checkPositionIntersection = exports.applyRotationToVector = void 0;
|
|
9
9
|
|
|
10
|
-
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
11
|
-
|
|
12
10
|
var _shapes = require("../constants/shapes");
|
|
13
11
|
|
|
14
12
|
var _fp = _interopRequireDefault(require("lodash/fp"));
|
|
@@ -19,22 +17,17 @@ var _Shapes = require("../types/Shapes");
|
|
|
19
17
|
|
|
20
18
|
var _shapeData = require("./shapeData");
|
|
21
19
|
|
|
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
|
-
var getCursorPosition = function getCursorPosition(e, canvas, givenWidth, givenHeight) {
|
|
20
|
+
const getCursorPosition = function (e, canvas, givenWidth, givenHeight) {
|
|
29
21
|
var _canvas$getBoundingCl;
|
|
30
22
|
|
|
31
|
-
|
|
23
|
+
let scaleRatio = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : 1;
|
|
32
24
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
25
|
+
const {
|
|
26
|
+
clientX,
|
|
27
|
+
clientY
|
|
28
|
+
} = _fp.default.getOr(_fp.default.getOr(e, 'changedTouches[0]', e), 'touches[0]', e);
|
|
36
29
|
|
|
37
|
-
|
|
30
|
+
const canvasBoundingRect = (_canvas$getBoundingCl = canvas === null || canvas === void 0 ? void 0 : canvas.getBoundingClientRect()) !== null && _canvas$getBoundingCl !== void 0 ? _canvas$getBoundingCl : {
|
|
38
31
|
left: 0,
|
|
39
32
|
top: 0,
|
|
40
33
|
width: givenWidth,
|
|
@@ -45,12 +38,12 @@ var getCursorPosition = function getCursorPosition(e, canvas, givenWidth, givenH
|
|
|
45
38
|
|
|
46
39
|
exports.getCursorPosition = getCursorPosition;
|
|
47
40
|
|
|
48
|
-
|
|
41
|
+
const getSettingsPosition = (shape, canvas, givenWidth, givenHeight, selectionPadding) => {
|
|
49
42
|
var _canvas$getBoundingCl2;
|
|
50
43
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
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 : {
|
|
54
47
|
left: 0,
|
|
55
48
|
top: 0,
|
|
56
49
|
width: givenWidth,
|
|
@@ -61,85 +54,63 @@ var getSettingsPosition = function getSettingsPosition(shape, canvas, givenWidth
|
|
|
61
54
|
|
|
62
55
|
exports.getSettingsPosition = getSettingsPosition;
|
|
63
56
|
|
|
64
|
-
|
|
57
|
+
const isPointInsideRect = (rect, point) => {
|
|
65
58
|
return point[0] >= rect.x && point[0] <= rect.x + rect.width && point[1] >= rect.y && point[1] <= rect.y + rect.height;
|
|
66
59
|
};
|
|
67
60
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
translationY = _ref7[1];
|
|
80
|
-
|
|
81
|
-
var _ref8 = (0, _slicedToArray2["default"])(_ref4, 2),
|
|
82
|
-
centerX = _ref8[0],
|
|
83
|
-
centerY = _ref8[1];
|
|
84
|
-
|
|
85
|
-
var newX = positionX + canvasOffsetX - centerX - translationX;
|
|
86
|
-
var newY = positionY + canvasOffsetY - centerY - translationY;
|
|
87
|
-
var rotatedY = newY * Math.cos(shapeRotation) - newX * Math.sin(shapeRotation);
|
|
88
|
-
var rotatedX = newY * Math.sin(shapeRotation) + newX * Math.cos(shapeRotation);
|
|
89
|
-
var translatedX = rotatedX + centerX;
|
|
90
|
-
var translatedY = rotatedY + centerY;
|
|
61
|
+
const getPointPositionAfterCanvasTransformation = (_ref, _ref2, _ref3, shapeRotation, _ref4) => {
|
|
62
|
+
let [positionX, positionY] = _ref;
|
|
63
|
+
let [canvasOffsetX, canvasOffsetY] = _ref2;
|
|
64
|
+
let [translationX, translationY] = _ref3;
|
|
65
|
+
let [centerX, centerY] = _ref4;
|
|
66
|
+
const newX = positionX + canvasOffsetX - centerX - translationX;
|
|
67
|
+
const newY = positionY + canvasOffsetY - centerY - translationY;
|
|
68
|
+
const rotatedY = newY * Math.cos(shapeRotation) - newX * Math.sin(shapeRotation);
|
|
69
|
+
const rotatedX = newY * Math.sin(shapeRotation) + newX * Math.cos(shapeRotation);
|
|
70
|
+
const translatedX = rotatedX + centerX;
|
|
71
|
+
const translatedY = rotatedY + centerY;
|
|
91
72
|
return [translatedX, translatedY];
|
|
92
73
|
};
|
|
93
74
|
|
|
94
75
|
exports.getPointPositionAfterCanvasTransformation = getPointPositionAfterCanvasTransformation;
|
|
95
76
|
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
centerX = _ref14[0],
|
|
107
|
-
centerY = _ref14[1];
|
|
108
|
-
|
|
109
|
-
var newX = positionX - centerX;
|
|
110
|
-
var newY = positionY - centerY;
|
|
111
|
-
var rotatedY = newY * Math.cos(-shapeRotation) - newX * Math.sin(-shapeRotation);
|
|
112
|
-
var rotatedX = newY * Math.sin(-shapeRotation) + newX * Math.cos(-shapeRotation);
|
|
113
|
-
var translatedX = rotatedX + centerX;
|
|
114
|
-
var translatedY = rotatedY + centerY;
|
|
77
|
+
const getPointPositionBeforeCanvasTransformation = (_ref5, _ref6, shapeRotation, _ref7) => {
|
|
78
|
+
let [positionX, positionY] = _ref5;
|
|
79
|
+
let [translationX, translationY] = _ref6;
|
|
80
|
+
let [centerX, centerY] = _ref7;
|
|
81
|
+
const newX = positionX - centerX;
|
|
82
|
+
const newY = positionY - centerY;
|
|
83
|
+
const rotatedY = newY * Math.cos(-shapeRotation) - newX * Math.sin(-shapeRotation);
|
|
84
|
+
const rotatedX = newY * Math.sin(-shapeRotation) + newX * Math.cos(-shapeRotation);
|
|
85
|
+
const translatedX = rotatedX + centerX;
|
|
86
|
+
const translatedY = rotatedY + centerY;
|
|
115
87
|
return [translatedX - translationX, translatedY - translationY];
|
|
116
88
|
};
|
|
117
89
|
|
|
118
90
|
exports.getPointPositionBeforeCanvasTransformation = getPointPositionBeforeCanvasTransformation;
|
|
119
91
|
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
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);
|
|
123
95
|
return [rotatedX, rotatedY];
|
|
124
96
|
};
|
|
125
97
|
|
|
126
98
|
exports.applyRotationToVector = applyRotationToVector;
|
|
127
99
|
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
100
|
+
const checkPositionIntersection = function (shape, position, canvasOffset, selectionPadding) {
|
|
101
|
+
let currentScale = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : 1;
|
|
102
|
+
let checkAnchors = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : false;
|
|
131
103
|
if (shape.locked) return false;
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
var newPosition = getPointPositionAfterCanvasTransformation(position, canvasOffset, shape.translation, shape.rotation, center);
|
|
104
|
+
const scaleWithMinCap = Math.min(1, currentScale);
|
|
105
|
+
const {
|
|
106
|
+
borders,
|
|
107
|
+
center
|
|
108
|
+
} = (0, _shapeData.getShapeInfos)(shape, selectionPadding);
|
|
109
|
+
const newPosition = getPointPositionAfterCanvasTransformation(position, canvasOffset, shape.translation, shape.rotation, center);
|
|
139
110
|
|
|
140
111
|
if (checkAnchors) {
|
|
141
112
|
if (shape.type === _Shapes.ShapeEnum.line || shape.type === _Shapes.ShapeEnum.polygon || shape.type === _Shapes.ShapeEnum.curve) {
|
|
142
|
-
for (
|
|
113
|
+
for (let i = 0; i < shape.points.length; i++) {
|
|
143
114
|
if (isPointInsideRect({
|
|
144
115
|
x: shape.points[i][0] - _shapes.SELECTION_ANCHOR_SIZE / 2 / scaleWithMinCap,
|
|
145
116
|
y: shape.points[i][1] - _shapes.SELECTION_ANCHOR_SIZE / 2 / scaleWithMinCap,
|
|
@@ -164,29 +135,18 @@ var checkPositionIntersection = function checkPositionIntersection(shape, positi
|
|
|
164
135
|
};
|
|
165
136
|
}
|
|
166
137
|
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
height: _shapes.SELECTION_ANCHOR_SIZE / scaleWithMinCap
|
|
179
|
-
}, newPosition)) {
|
|
180
|
-
return {
|
|
181
|
-
mode: _Mode.SelectionModeLib.resize,
|
|
182
|
-
anchor: anchorPosition
|
|
183
|
-
};
|
|
184
|
-
}
|
|
138
|
+
for (const anchorPosition of _shapes.SELECTION_RESIZE_ANCHOR_POSITIONS) {
|
|
139
|
+
if (isPointInsideRect({
|
|
140
|
+
x: borders.x + borders.width * anchorPosition[0] - _shapes.SELECTION_ANCHOR_SIZE / 2 / scaleWithMinCap,
|
|
141
|
+
y: borders.y + borders.height * anchorPosition[1] - _shapes.SELECTION_ANCHOR_SIZE / 2 / scaleWithMinCap,
|
|
142
|
+
width: _shapes.SELECTION_ANCHOR_SIZE / scaleWithMinCap,
|
|
143
|
+
height: _shapes.SELECTION_ANCHOR_SIZE / scaleWithMinCap
|
|
144
|
+
}, newPosition)) {
|
|
145
|
+
return {
|
|
146
|
+
mode: _Mode.SelectionModeLib.resize,
|
|
147
|
+
anchor: anchorPosition
|
|
148
|
+
};
|
|
185
149
|
}
|
|
186
|
-
} catch (err) {
|
|
187
|
-
_iterator.e(err);
|
|
188
|
-
} finally {
|
|
189
|
-
_iterator.f();
|
|
190
150
|
}
|
|
191
151
|
}
|
|
192
152
|
}
|
package/dist/utils/selection.js
CHANGED
|
@@ -15,7 +15,7 @@ var _intersect = require("./intersect");
|
|
|
15
15
|
|
|
16
16
|
var _shapeData = require("./shapeData");
|
|
17
17
|
|
|
18
|
-
|
|
18
|
+
const getNewSelectionData = (hoverMode, selectedShape, cursorPosition, selectionPadding) => {
|
|
19
19
|
if (hoverMode.mode === 'translate') {
|
|
20
20
|
return {
|
|
21
21
|
mode: _Mode.SelectionModeLib.translate,
|
|
@@ -23,15 +23,15 @@ var getNewSelectionData = function getNewSelectionData(hoverMode, selectedShape,
|
|
|
23
23
|
originalShape: selectedShape
|
|
24
24
|
};
|
|
25
25
|
} else if (hoverMode.mode === 'rotate') {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
26
|
+
const {
|
|
27
|
+
center: centerBeforeResize
|
|
28
|
+
} = (0, _shapeData.getShapeInfos)(selectedShape, selectionPadding);
|
|
29
|
+
const center = [centerBeforeResize[0], centerBeforeResize[1]];
|
|
30
30
|
return {
|
|
31
31
|
mode: _Mode.SelectionModeLib.rotate,
|
|
32
32
|
cursorStartPosition: cursorPosition,
|
|
33
33
|
originalShape: selectedShape,
|
|
34
|
-
center
|
|
34
|
+
center
|
|
35
35
|
};
|
|
36
36
|
} else if (hoverMode.mode === 'resize') {
|
|
37
37
|
return {
|
|
@@ -47,12 +47,12 @@ var getNewSelectionData = function getNewSelectionData(hoverMode, selectedShape,
|
|
|
47
47
|
|
|
48
48
|
exports.getNewSelectionData = getNewSelectionData;
|
|
49
49
|
|
|
50
|
-
|
|
50
|
+
const selectShape = (shapes, cursorPosition, currentScale, canvasOffset, selectedShape, selectionPadding) => {
|
|
51
51
|
if (selectedShape) {
|
|
52
|
-
|
|
53
|
-
mode: _Mode.SelectionModeLib
|
|
52
|
+
const positionIntersection = (0, _intersect.checkPositionIntersection)(selectedShape, cursorPosition, canvasOffset, selectionPadding, currentScale, true) || {
|
|
53
|
+
mode: _Mode.SelectionModeLib.default
|
|
54
54
|
};
|
|
55
|
-
|
|
55
|
+
const newSelectionMode = getNewSelectionData(positionIntersection, selectedShape, cursorPosition, selectionPadding);
|
|
56
56
|
|
|
57
57
|
if ((newSelectionMode === null || newSelectionMode === void 0 ? void 0 : newSelectionMode.mode) === _Mode.SelectionModeLib.resize || (newSelectionMode === null || newSelectionMode === void 0 ? void 0 : newSelectionMode.mode) === _Mode.SelectionModeLib.rotate) {
|
|
58
58
|
return {
|
|
@@ -62,7 +62,7 @@ var selectShape = function selectShape(shapes, cursorPosition, currentScale, can
|
|
|
62
62
|
}
|
|
63
63
|
}
|
|
64
64
|
|
|
65
|
-
|
|
65
|
+
const foundShape = _fp.default.find(shape => {
|
|
66
66
|
return !!(0, _intersect.checkPositionIntersection)(shape, cursorPosition, canvasOffset, selectionPadding, currentScale, false);
|
|
67
67
|
}, shapes);
|
|
68
68
|
|
|
@@ -79,7 +79,7 @@ var selectShape = function selectShape(shapes, cursorPosition, currentScale, can
|
|
|
79
79
|
return {
|
|
80
80
|
shape: undefined,
|
|
81
81
|
mode: {
|
|
82
|
-
mode: _Mode.SelectionModeLib
|
|
82
|
+
mode: _Mode.SelectionModeLib.default
|
|
83
83
|
}
|
|
84
84
|
};
|
|
85
85
|
}
|