@yorab/react-paint 0.6.4 → 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.
- package/README.md +5 -5
- package/dist/components/App.js +236 -423
- package/dist/components/Canvas.js +120 -139
- package/dist/components/common/Button.js +41 -50
- package/dist/components/common/Loading.js +24 -33
- package/dist/components/common/Modal.js +18 -17
- package/dist/components/common/Panel.js +20 -28
- package/dist/components/common/Snackbar.js +31 -38
- package/dist/components/settings/ColorField.js +59 -68
- package/dist/components/settings/DeleteButton.js +10 -9
- package/dist/components/settings/FontFamilyField.js +25 -20
- package/dist/components/settings/LayoutButton.js +11 -9
- package/dist/components/settings/Layouts.js +111 -111
- 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 +100 -121
- package/dist/components/settings/ToggleField.js +18 -25
- package/dist/components/toolbox/EditTextBox.js +62 -49
- package/dist/components/toolbox/LoadFileTool.js +19 -21
- package/dist/components/toolbox/MenuGroup.js +66 -100
- package/dist/components/toolbox/PictureUrlInput.js +33 -62
- package/dist/components/toolbox/Tool.js +13 -13
- package/dist/components/toolbox/Toolbar.js +79 -113
- package/dist/components/toolbox/ToolbarGroup.js +60 -63
- package/dist/constants/app.js +51 -0
- package/dist/constants/icons.js +42 -48
- package/dist/constants/loading.js +8 -0
- package/dist/constants/shapes.js +10 -8
- package/dist/constants/snackbar.js +7 -15
- package/dist/constants/style.js +21 -18
- package/dist/constants/tools.js +99 -103
- package/dist/hooks/useComponent.js +15 -20
- package/dist/hooks/useDoubleClick.js +12 -12
- package/dist/hooks/useDrag.js +24 -32
- package/dist/hooks/useDrawableCanvas.js +106 -122
- package/dist/hooks/useKeyboard.js +80 -63
- package/dist/hooks/useResizeObserver.js +18 -16
- package/dist/hooks/useShapes.js +92 -144
- package/dist/hooks/useSnackbar.js +28 -58
- 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 +15 -274
- package/dist/utils/dom.js +12 -0
- package/dist/utils/file.js +75 -120
- package/dist/utils/intersect.js +54 -131
- package/dist/utils/migration.js +59 -0
- package/dist/utils/selection.js +18 -20
- 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/string.js +10 -16
- package/dist/utils/style.js +11 -13
- package/dist/utils/toolbar.js +35 -49
- package/dist/utils/transform.js +47 -339
- package/dist/utils/trigo.js +42 -0
- package/package.json +6 -6
- package/Changelog.md +0 -119
- package/dist/types/keyboard.js +0 -28
- package/dist/utils/draw.js +0 -461
- package/dist/utils/shapeData.js +0 -173
package/dist/utils/style.js
CHANGED
|
@@ -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
|
|
12
|
+
case 'brush':
|
|
15
13
|
return _icons.brushIcon;
|
|
16
14
|
|
|
17
|
-
case
|
|
15
|
+
case 'line':
|
|
18
16
|
return _icons.arrowIcon;
|
|
19
17
|
|
|
20
|
-
case
|
|
18
|
+
case 'polygon':
|
|
21
19
|
return _icons.polygonIcon;
|
|
22
20
|
|
|
23
|
-
case
|
|
21
|
+
case 'curve':
|
|
24
22
|
return _icons.curveIcon;
|
|
25
23
|
|
|
26
|
-
case
|
|
24
|
+
case 'rect':
|
|
27
25
|
return _icons.squareIcon;
|
|
28
26
|
// temporary
|
|
29
27
|
|
|
30
|
-
case
|
|
28
|
+
case 'square':
|
|
31
29
|
return _icons.squareIcon;
|
|
32
30
|
|
|
33
|
-
case
|
|
31
|
+
case 'circle':
|
|
34
32
|
return _icons.circleIcon;
|
|
35
33
|
|
|
36
|
-
case
|
|
34
|
+
case 'ellipse':
|
|
37
35
|
return _icons.circleIcon;
|
|
38
36
|
// temporary
|
|
39
37
|
|
|
40
|
-
case
|
|
38
|
+
case 'text':
|
|
41
39
|
return _icons.textIcon;
|
|
42
40
|
|
|
43
|
-
case
|
|
41
|
+
case 'picture':
|
|
44
42
|
return _icons.pictureIcon;
|
|
45
43
|
}
|
|
46
44
|
};
|
package/dist/utils/toolbar.js
CHANGED
|
@@ -7,86 +7,72 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
7
7
|
});
|
|
8
8
|
exports.sanitizeTools = exports.getCurrentStructure = void 0;
|
|
9
9
|
|
|
10
|
-
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
|
11
|
-
|
|
12
|
-
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
13
|
-
|
|
14
|
-
var _Shapes = require("../types/Shapes");
|
|
15
|
-
|
|
16
10
|
var _fp = _interopRequireDefault(require("lodash/fp"));
|
|
17
11
|
|
|
18
12
|
var _tools = require("../constants/tools");
|
|
19
13
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
var getCurrentStructure = function getCurrentStructure(availableTools, defaultStructure) {
|
|
25
|
-
return _fp["default"].flow(_fp["default"].flatMap(function (group) {
|
|
26
|
-
if (!_fp["default"].isObject(group)) {
|
|
27
|
-
return _fp["default"].filter({
|
|
14
|
+
const getCurrentStructure = (availableTools, defaultStructure) => {
|
|
15
|
+
return _fp.default.flow(_fp.default.flatMap(group => {
|
|
16
|
+
if (!_fp.default.isObject(group)) {
|
|
17
|
+
return _fp.default.filter({
|
|
28
18
|
type: group
|
|
29
19
|
}, availableTools);
|
|
30
20
|
}
|
|
31
21
|
|
|
32
|
-
|
|
33
|
-
return _fp["default"].includes(tool.type, group.toolsType);
|
|
34
|
-
}, availableTools);
|
|
22
|
+
const toolsType = _fp.default.filter(tool => _fp.default.includes(tool.type, group.toolsType), availableTools);
|
|
35
23
|
|
|
36
24
|
if (!toolsType) return null;
|
|
37
|
-
return
|
|
38
|
-
toolsType
|
|
39
|
-
}
|
|
40
|
-
}), _fp
|
|
25
|
+
return { ...group,
|
|
26
|
+
toolsType
|
|
27
|
+
};
|
|
28
|
+
}), _fp.default.compact)(defaultStructure);
|
|
41
29
|
};
|
|
42
30
|
|
|
43
31
|
exports.getCurrentStructure = getCurrentStructure;
|
|
44
32
|
|
|
45
|
-
|
|
46
|
-
|
|
33
|
+
const sanitizeTools = function (tools) {
|
|
34
|
+
let withPicture = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
|
47
35
|
|
|
48
|
-
|
|
49
|
-
if (_fp
|
|
36
|
+
const customizer = (objValue, srcValue) => {
|
|
37
|
+
if (_fp.default.isArray(objValue)) {
|
|
50
38
|
return srcValue;
|
|
51
39
|
}
|
|
52
40
|
};
|
|
53
41
|
|
|
54
|
-
return _fp
|
|
55
|
-
if (!_fp
|
|
42
|
+
return _fp.default.flow(_fp.default.map(tool => {
|
|
43
|
+
if (!_fp.default.isObject(tool)) return null;
|
|
56
44
|
|
|
57
|
-
switch (_fp
|
|
58
|
-
case
|
|
59
|
-
return _fp
|
|
45
|
+
switch (_fp.default.get('type', tool)) {
|
|
46
|
+
case 'brush':
|
|
47
|
+
return _fp.default.mergeWith(customizer, _tools.DEFAULT_SHAPE_BRUSH, tool);
|
|
60
48
|
|
|
61
|
-
case
|
|
62
|
-
return _fp
|
|
49
|
+
case 'circle':
|
|
50
|
+
return _fp.default.mergeWith(customizer, _tools.DEFAULT_SHAPE_CIRCLE, tool);
|
|
63
51
|
|
|
64
|
-
case
|
|
65
|
-
return _fp
|
|
52
|
+
case 'curve':
|
|
53
|
+
return _fp.default.mergeWith(customizer, _tools.DEFAULT_SHAPE_CURVE, tool);
|
|
66
54
|
|
|
67
|
-
case
|
|
68
|
-
return _fp
|
|
55
|
+
case 'ellipse':
|
|
56
|
+
return _fp.default.mergeWith(customizer, _tools.DEFAULT_SHAPE_ELLIPSE, tool);
|
|
69
57
|
|
|
70
|
-
case
|
|
71
|
-
return _fp
|
|
58
|
+
case 'line':
|
|
59
|
+
return _fp.default.mergeWith(customizer, _tools.DEFAULT_SHAPE_LINE, tool);
|
|
72
60
|
|
|
73
|
-
case
|
|
74
|
-
return _fp
|
|
61
|
+
case 'polygon':
|
|
62
|
+
return _fp.default.mergeWith(customizer, _tools.DEFAULT_SHAPE_POLYGON, tool);
|
|
75
63
|
|
|
76
|
-
case
|
|
77
|
-
return _fp
|
|
64
|
+
case 'rect':
|
|
65
|
+
return _fp.default.mergeWith(customizer, _tools.DEFAULT_SHAPE_RECT, tool);
|
|
78
66
|
|
|
79
|
-
case
|
|
80
|
-
return _fp
|
|
67
|
+
case 'square':
|
|
68
|
+
return _fp.default.mergeWith(customizer, _tools.DEFAULT_SHAPE_SQUARE, tool);
|
|
81
69
|
|
|
82
|
-
case
|
|
83
|
-
return _fp
|
|
70
|
+
case 'text':
|
|
71
|
+
return _fp.default.mergeWith(customizer, _tools.DEFAULT_SHAPE_TEXT, tool);
|
|
84
72
|
}
|
|
85
73
|
|
|
86
74
|
return null;
|
|
87
|
-
}),
|
|
88
|
-
return withPicture ? [].concat((0, _toConsumableArray2["default"])(tools), [_tools.DEFAULT_SHAPE_PICTURE]) : tools;
|
|
89
|
-
}, _fp["default"].compact)(tools);
|
|
75
|
+
}), tools => withPicture ? [...tools, _tools.DEFAULT_SHAPE_PICTURE] : tools, _fp.default.compact)(tools);
|
|
90
76
|
};
|
|
91
77
|
|
|
92
78
|
exports.sanitizeTools = sanitizeTools;
|
package/dist/utils/transform.js
CHANGED
|
@@ -5,36 +5,24 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", {
|
|
6
6
|
value: true
|
|
7
7
|
});
|
|
8
|
-
exports.updatePolygonLinesCount = exports.
|
|
9
|
-
|
|
10
|
-
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
11
|
-
|
|
12
|
-
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
|
13
|
-
|
|
14
|
-
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
8
|
+
exports.updatePolygonLinesCount = exports.transformShape = exports.roundForGrid = exports.getNormalizedSize = exports.fitContentInsideContainer = void 0;
|
|
15
9
|
|
|
16
10
|
var _fp = _interopRequireDefault(require("lodash/fp"));
|
|
17
11
|
|
|
18
|
-
var _shapeData = require("./shapeData");
|
|
19
|
-
|
|
20
|
-
var _Mode = require("../types/Mode");
|
|
21
|
-
|
|
22
|
-
var _intersect = require("./intersect");
|
|
23
|
-
|
|
24
12
|
var _style = require("../constants/style");
|
|
25
13
|
|
|
26
|
-
|
|
14
|
+
var _shapes = require("./shapes");
|
|
27
15
|
|
|
28
|
-
|
|
16
|
+
var _brush = require("./shapes/brush");
|
|
29
17
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
18
|
+
const getNormalizedSize = (originalWidth, originalHeight, width, height) => {
|
|
19
|
+
const originalRatio = originalWidth / originalHeight;
|
|
20
|
+
const newRatio = width / height;
|
|
33
21
|
|
|
34
22
|
if (newRatio > originalRatio || height < 0) {
|
|
35
|
-
return width >
|
|
23
|
+
return width > originalWidth ? [width, width / originalRatio] : [height * originalRatio, height];
|
|
36
24
|
} else if (newRatio < originalRatio) {
|
|
37
|
-
return height >
|
|
25
|
+
return height > originalHeight ? [height * originalRatio, height] : [width, width / originalRatio];
|
|
38
26
|
}
|
|
39
27
|
|
|
40
28
|
return [width, height];
|
|
@@ -42,355 +30,75 @@ var getNormalizedSize = function getNormalizedSize(originalShape, width, height)
|
|
|
42
30
|
|
|
43
31
|
exports.getNormalizedSize = getNormalizedSize;
|
|
44
32
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
});
|
|
49
|
-
};
|
|
50
|
-
|
|
51
|
-
exports.translateShape = translateShape;
|
|
52
|
-
|
|
53
|
-
var rotateShape = function rotateShape(shape, cursorPosition, originalShape, originalCursorPosition, shapeCenter) {
|
|
54
|
-
var p1x = shapeCenter[0] + originalShape.translation[0] - originalCursorPosition[0];
|
|
55
|
-
var p1y = shapeCenter[1] + originalShape.translation[1] - originalCursorPosition[1];
|
|
56
|
-
var p2x = shapeCenter[0] + originalShape.translation[0] - cursorPosition[0];
|
|
57
|
-
var p2y = shapeCenter[1] + originalShape.translation[1] - cursorPosition[1];
|
|
58
|
-
var rotation = originalShape.rotation + Math.atan2(p2y, p2x) - Math.atan2(p1y, p1x);
|
|
59
|
-
return _objectSpread(_objectSpread({}, shape), {
|
|
60
|
-
rotation: rotation
|
|
61
|
-
});
|
|
62
|
-
};
|
|
63
|
-
|
|
64
|
-
exports.rotateShape = rotateShape;
|
|
65
|
-
|
|
66
|
-
var paintNewPointToShape = function paintNewPointToShape(shape, cursorPosition) {
|
|
67
|
-
return _objectSpread(_objectSpread({}, shape), {
|
|
68
|
-
points: _fp["default"].set(shape.points.length - 1, [].concat((0, _toConsumableArray2["default"])(shape.points[shape.points.length - 1]), [cursorPosition]), shape.points)
|
|
69
|
-
});
|
|
70
|
-
};
|
|
71
|
-
|
|
72
|
-
exports.paintNewPointToShape = paintNewPointToShape;
|
|
73
|
-
|
|
74
|
-
var createNewPointGroupToShape = function createNewPointGroupToShape(shape, cursorPosition) {
|
|
75
|
-
return _objectSpread(_objectSpread({}, shape), {
|
|
76
|
-
points: _fp["default"].set(shape.points.length, [cursorPosition], shape.points)
|
|
77
|
-
});
|
|
78
|
-
};
|
|
79
|
-
|
|
80
|
-
exports.createNewPointGroupToShape = createNewPointGroupToShape;
|
|
81
|
-
|
|
82
|
-
var resizeBrush = function resizeBrush(cursorPosition, canvasOffset, originalShape, selectionMode, selectionPadding) {
|
|
83
|
-
var _getShapeInfos = (0, _shapeData.getShapeInfos)(originalShape, selectionPadding),
|
|
84
|
-
center = _getShapeInfos.center,
|
|
85
|
-
borders = _getShapeInfos.borders;
|
|
86
|
-
|
|
87
|
-
var cursorPositionBeforeResize = (0, _intersect.getPointPositionAfterCanvasTransformation)(cursorPosition, canvasOffset, originalShape.translation, originalShape.rotation, center);
|
|
88
|
-
var 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);
|
|
89
|
-
var 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);
|
|
90
|
-
|
|
91
|
-
var shapeWithNewDimensions = _objectSpread(_objectSpread({}, originalShape), {}, {
|
|
92
|
-
points: originalShape.points.map(function (points) {
|
|
93
|
-
return points.map(function (point) {
|
|
94
|
-
return [(point[0] - borders.x) * scaledWidth + borders.x, (point[1] - borders.y) * scaledHeight + borders.y];
|
|
95
|
-
});
|
|
96
|
-
})
|
|
97
|
-
});
|
|
98
|
-
|
|
99
|
-
var _getShapeInfos2 = (0, _shapeData.getShapeInfos)(shapeWithNewDimensions, selectionPadding),
|
|
100
|
-
shapeWithNewDimensionsCenter = _getShapeInfos2.center,
|
|
101
|
-
shapeWithNewDimensionsBorders = _getShapeInfos2.borders;
|
|
102
|
-
|
|
103
|
-
var _getRectOppositeAncho = getRectOppositeAnchorAbsolutePosition(selectionMode.anchor, center, _objectSpread(_objectSpread({}, originalShape), borders)),
|
|
104
|
-
_getRectOppositeAncho2 = (0, _slicedToArray2["default"])(_getRectOppositeAncho, 2),
|
|
105
|
-
oppTrueX = _getRectOppositeAncho2[0],
|
|
106
|
-
oppTrueY = _getRectOppositeAncho2[1];
|
|
107
|
-
|
|
108
|
-
var _getRectOppositeAncho3 = getRectOppositeAnchorAbsolutePosition(selectionMode.anchor, shapeWithNewDimensionsCenter, _objectSpread(_objectSpread({}, shapeWithNewDimensions), shapeWithNewDimensionsBorders), [scaledWidth < 0, scaledHeight < 0]),
|
|
109
|
-
_getRectOppositeAncho4 = (0, _slicedToArray2["default"])(_getRectOppositeAncho3, 2),
|
|
110
|
-
newOppTrueX = _getRectOppositeAncho4[0],
|
|
111
|
-
newOppTrueY = _getRectOppositeAncho4[1];
|
|
112
|
-
|
|
113
|
-
return _objectSpread(_objectSpread({}, shapeWithNewDimensions), {
|
|
114
|
-
translation: [originalShape.translation[0] - (newOppTrueX - oppTrueX), originalShape.translation[1] - (newOppTrueY - oppTrueY)]
|
|
115
|
-
});
|
|
116
|
-
};
|
|
117
|
-
|
|
118
|
-
exports.resizeBrush = resizeBrush;
|
|
119
|
-
|
|
120
|
-
var resizeLine = function resizeLine(cursorPosition, canvasOffset, originalShape, selectionMode, selectionPadding) {
|
|
121
|
-
var _getShapeInfos3 = (0, _shapeData.getShapeInfos)(originalShape, selectionPadding),
|
|
122
|
-
center = _getShapeInfos3.center;
|
|
123
|
-
|
|
124
|
-
var cursorPositionBeforeResize = (0, _intersect.getPointPositionAfterCanvasTransformation)(cursorPosition, canvasOffset, originalShape.translation, originalShape.rotation, center);
|
|
125
|
-
|
|
126
|
-
var updatedShape = _fp["default"].set(['points', selectionMode.anchor], cursorPositionBeforeResize, originalShape);
|
|
127
|
-
|
|
128
|
-
return updatedShape;
|
|
33
|
+
const roundForGrid = (value, gridFormat) => {
|
|
34
|
+
const step = value >= 0 ? _style.GRID_STEP[gridFormat - 1] : -_style.GRID_STEP[gridFormat - 1];
|
|
35
|
+
return gridFormat ? value + step / 2 - (value + step / 2) % step : Math.round(value);
|
|
129
36
|
};
|
|
130
37
|
|
|
131
|
-
exports.
|
|
38
|
+
exports.roundForGrid = roundForGrid;
|
|
132
39
|
|
|
133
|
-
|
|
134
|
-
|
|
40
|
+
const updatePolygonLinesCount = (shape, newPointsCount) => {
|
|
41
|
+
const currentPointsCount = shape.points.length;
|
|
135
42
|
if (currentPointsCount === newPointsCount) return shape;
|
|
136
43
|
|
|
137
44
|
if (currentPointsCount > newPointsCount) {
|
|
138
|
-
|
|
139
|
-
return
|
|
45
|
+
const totalPoints = shape.points.slice(0, newPointsCount);
|
|
46
|
+
return { ...shape,
|
|
140
47
|
points: totalPoints,
|
|
141
|
-
style:
|
|
48
|
+
style: { ...shape.style,
|
|
142
49
|
pointsCount: totalPoints.length
|
|
143
|
-
}
|
|
144
|
-
}
|
|
50
|
+
}
|
|
51
|
+
};
|
|
145
52
|
} else {
|
|
146
53
|
//TODO : better distribution for new points
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
var newPoints = _fp["default"].flow(_fp["default"].range(0), _fp["default"].map(function (index) {
|
|
150
|
-
return [shape.points[0][0] + (shape.points[1][0] - shape.points[0][0]) * (index + 1) / (nbPointsToAdd + 1), shape.points[0][1] + (shape.points[1][1] - shape.points[0][1]) * (index + 1) / (nbPointsToAdd + 1)];
|
|
151
|
-
}))(nbPointsToAdd);
|
|
54
|
+
const nbPointsToAdd = newPointsCount - currentPointsCount;
|
|
152
55
|
|
|
153
|
-
|
|
56
|
+
const newPoints = _fp.default.flow(_fp.default.range(0), _fp.default.map(index => [shape.points[0][0] + (shape.points[1][0] - shape.points[0][0]) * (index + 1) / (nbPointsToAdd + 1), shape.points[0][1] + (shape.points[1][1] - shape.points[0][1]) * (index + 1) / (nbPointsToAdd + 1)]))(nbPointsToAdd);
|
|
154
57
|
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
58
|
+
const totalPoints = [shape.points[0], ...newPoints, ...shape.points.slice(1, shape.points.length)];
|
|
59
|
+
return { ...shape,
|
|
60
|
+
points: totalPoints,
|
|
61
|
+
style: { ...shape.style,
|
|
62
|
+
pointsCount: totalPoints.length
|
|
63
|
+
}
|
|
64
|
+
};
|
|
161
65
|
}
|
|
162
66
|
};
|
|
163
67
|
|
|
164
68
|
exports.updatePolygonLinesCount = updatePolygonLinesCount;
|
|
165
69
|
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
var cursorPositionBeforeResize = (0, _intersect.getPointPositionAfterCanvasTransformation)(cursorPosition, canvasOffset, originalShape.translation, originalShape.rotation, center);
|
|
172
|
-
var newCursorPosition = [cursorPositionBeforeResize[0], cursorPositionBeforeResize[1]];
|
|
173
|
-
var 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;
|
|
174
|
-
|
|
175
|
-
var shapeWithNewDimensions = _objectSpread(_objectSpread({}, originalShape), {
|
|
176
|
-
radius: Math.abs(scaledRadius)
|
|
177
|
-
});
|
|
178
|
-
|
|
179
|
-
var _getShapeInfos5 = (0, _shapeData.getShapeInfos)(shapeWithNewDimensions, selectionPadding),
|
|
180
|
-
shapeWithNewDimensionsCenter = _getShapeInfos5.center;
|
|
181
|
-
|
|
182
|
-
var _getCircleOppositeAnc = getCircleOppositeAnchorAbsolutePosition(selectionMode.anchor, center, originalShape),
|
|
183
|
-
_getCircleOppositeAnc2 = (0, _slicedToArray2["default"])(_getCircleOppositeAnc, 2),
|
|
184
|
-
oppTrueX = _getCircleOppositeAnc2[0],
|
|
185
|
-
oppTrueY = _getCircleOppositeAnc2[1];
|
|
186
|
-
|
|
187
|
-
var _getCircleOppositeAnc3 = getCircleOppositeAnchorAbsolutePosition(selectionMode.anchor, shapeWithNewDimensionsCenter, shapeWithNewDimensions, [scaledRadius < 0, scaledRadius < 0]),
|
|
188
|
-
_getCircleOppositeAnc4 = (0, _slicedToArray2["default"])(_getCircleOppositeAnc3, 2),
|
|
189
|
-
newOppTrueX = _getCircleOppositeAnc4[0],
|
|
190
|
-
newOppTrueY = _getCircleOppositeAnc4[1];
|
|
191
|
-
|
|
192
|
-
return _objectSpread(_objectSpread({}, shapeWithNewDimensions), {
|
|
193
|
-
translation: [originalShape.translation[0] - (newOppTrueX - oppTrueX), originalShape.translation[1] - (newOppTrueY - oppTrueY)]
|
|
194
|
-
});
|
|
195
|
-
};
|
|
196
|
-
|
|
197
|
-
exports.resizeCircle = resizeCircle;
|
|
198
|
-
|
|
199
|
-
var resizeEllipse = function resizeEllipse(cursorPosition, canvasOffset, originalShape, selectionMode, selectionPadding) {
|
|
200
|
-
var _getShapeInfos6 = (0, _shapeData.getShapeInfos)(originalShape, selectionPadding),
|
|
201
|
-
center = _getShapeInfos6.center,
|
|
202
|
-
borders = _getShapeInfos6.borders;
|
|
203
|
-
|
|
204
|
-
var cursorPositionBeforeResize = (0, _intersect.getPointPositionAfterCanvasTransformation)(cursorPosition, canvasOffset, originalShape.translation, originalShape.rotation, center);
|
|
205
|
-
var newCursorPosition = [cursorPositionBeforeResize[0], cursorPositionBeforeResize[1]];
|
|
206
|
-
var scaledRadiusX = selectionMode.anchor[0] === 0.5 ? originalShape.radiusX : (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;
|
|
207
|
-
var scaledRadiusY = selectionMode.anchor[1] === 0.5 ? originalShape.radiusY : (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;
|
|
208
|
-
|
|
209
|
-
var shapeWithNewDimensions = _objectSpread(_objectSpread({}, originalShape), {
|
|
210
|
-
radiusX: Math.abs(scaledRadiusX),
|
|
211
|
-
radiusY: Math.abs(scaledRadiusY)
|
|
212
|
-
});
|
|
213
|
-
|
|
214
|
-
var _getShapeInfos7 = (0, _shapeData.getShapeInfos)(shapeWithNewDimensions, selectionPadding),
|
|
215
|
-
shapeWithNewDimensionsCenter = _getShapeInfos7.center;
|
|
216
|
-
|
|
217
|
-
var _getEllipseOppositeAn = getEllipseOppositeAnchorAbsolutePosition(selectionMode.anchor, center, originalShape),
|
|
218
|
-
_getEllipseOppositeAn2 = (0, _slicedToArray2["default"])(_getEllipseOppositeAn, 2),
|
|
219
|
-
oppTrueX = _getEllipseOppositeAn2[0],
|
|
220
|
-
oppTrueY = _getEllipseOppositeAn2[1];
|
|
70
|
+
const transformShape = (ctx, shape, cursorPosition, gridFormat, canvasOffset, selectionMode, selectionPadding, isShiftPressed) => {
|
|
71
|
+
switch (selectionMode.mode) {
|
|
72
|
+
case 'brush':
|
|
73
|
+
return (0, _brush.addNewPointToShape)(shape, cursorPosition);
|
|
221
74
|
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
newOppTrueX = _getEllipseOppositeAn4[0],
|
|
225
|
-
newOppTrueY = _getEllipseOppositeAn4[1];
|
|
75
|
+
case 'translate':
|
|
76
|
+
return (0, _shapes.translateShape)(cursorPosition, selectionMode.originalShape, selectionMode.cursorStartPosition, gridFormat);
|
|
226
77
|
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
});
|
|
230
|
-
};
|
|
231
|
-
|
|
232
|
-
exports.resizeEllipse = resizeEllipse;
|
|
233
|
-
|
|
234
|
-
var resizeRect = function resizeRect(cursorPosition, canvasOffset, originalShape, selectionMode, selectionPadding) {
|
|
235
|
-
var keepRatio = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : false;
|
|
236
|
-
|
|
237
|
-
var _getShapeInfos8 = (0, _shapeData.getShapeInfos)(originalShape, selectionPadding),
|
|
238
|
-
center = _getShapeInfos8.center,
|
|
239
|
-
borders = _getShapeInfos8.borders;
|
|
240
|
-
|
|
241
|
-
var cursorPositionBeforeResize = (0, _intersect.getPointPositionAfterCanvasTransformation)(cursorPosition, canvasOffset, originalShape.translation, originalShape.rotation, center);
|
|
242
|
-
var scaledWidth = selectionMode.anchor[0] === 0.5 ? originalShape.width : selectionMode.anchor[0] === 0 ? borders.x + borders.width - cursorPositionBeforeResize[0] + selectionPadding * -2 : cursorPositionBeforeResize[0] - borders.x - selectionPadding * 2;
|
|
243
|
-
var scaledHeight = selectionMode.anchor[1] === 0.5 ? originalShape.height : selectionMode.anchor[1] === 0 ? borders.y + borders.height - cursorPositionBeforeResize[1] + selectionPadding * -2 : cursorPositionBeforeResize[1] - borders.y - selectionPadding * 2;
|
|
244
|
-
|
|
245
|
-
var _ref = keepRatio ? getNormalizedSize(originalShape, scaledWidth, scaledHeight) : [scaledWidth, scaledHeight],
|
|
246
|
-
_ref2 = (0, _slicedToArray2["default"])(_ref, 2),
|
|
247
|
-
widthWithRatio = _ref2[0],
|
|
248
|
-
heightWithRatio = _ref2[1];
|
|
249
|
-
|
|
250
|
-
var shapeWithNewDimensions = _objectSpread(_objectSpread({}, originalShape), {}, {
|
|
251
|
-
width: Math.abs(widthWithRatio),
|
|
252
|
-
height: Math.abs(heightWithRatio)
|
|
253
|
-
});
|
|
254
|
-
|
|
255
|
-
var _getShapeInfos9 = (0, _shapeData.getShapeInfos)(shapeWithNewDimensions, selectionPadding),
|
|
256
|
-
shapeWithNewDimensionsCenter = _getShapeInfos9.center;
|
|
257
|
-
|
|
258
|
-
var _getRectOppositeAncho5 = getRectOppositeAnchorAbsolutePosition(selectionMode.anchor, center, originalShape),
|
|
259
|
-
_getRectOppositeAncho6 = (0, _slicedToArray2["default"])(_getRectOppositeAncho5, 2),
|
|
260
|
-
oppTrueX = _getRectOppositeAncho6[0],
|
|
261
|
-
oppTrueY = _getRectOppositeAncho6[1];
|
|
262
|
-
|
|
263
|
-
var _getRectOppositeAncho7 = getRectOppositeAnchorAbsolutePosition(selectionMode.anchor, shapeWithNewDimensionsCenter, shapeWithNewDimensions, [widthWithRatio < 0, heightWithRatio < 0]),
|
|
264
|
-
_getRectOppositeAncho8 = (0, _slicedToArray2["default"])(_getRectOppositeAncho7, 2),
|
|
265
|
-
newOppTrueX = _getRectOppositeAncho8[0],
|
|
266
|
-
newOppTrueY = _getRectOppositeAncho8[1];
|
|
267
|
-
|
|
268
|
-
return _objectSpread(_objectSpread({}, shapeWithNewDimensions), {
|
|
269
|
-
translation: [originalShape.translation[0] - (newOppTrueX - oppTrueX), originalShape.translation[1] - (newOppTrueY - oppTrueY)]
|
|
270
|
-
});
|
|
271
|
-
};
|
|
272
|
-
|
|
273
|
-
exports.resizeRect = resizeRect;
|
|
274
|
-
|
|
275
|
-
var resizeText = function resizeText(ctx, cursorPosition, canvasOffset, originalShape, selectionMode, selectionPadding) {
|
|
276
|
-
var _newRect$style$fontBo, _newRect$style, _newRect$style$fontIt, _newRect$style2, _newRect$style3;
|
|
277
|
-
|
|
278
|
-
var newRect = resizeRect(cursorPosition, canvasOffset, originalShape, selectionMode, selectionPadding, true);
|
|
279
|
-
return _objectSpread(_objectSpread({}, newRect), {}, {
|
|
280
|
-
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)
|
|
281
|
-
});
|
|
282
|
-
};
|
|
283
|
-
|
|
284
|
-
exports.resizeText = resizeText;
|
|
285
|
-
|
|
286
|
-
var getRectOppositeAnchorAbsolutePosition = function getRectOppositeAnchorAbsolutePosition(anchor, center, shape) {
|
|
287
|
-
var _ref3 = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : [false, false],
|
|
288
|
-
_ref4 = (0, _slicedToArray2["default"])(_ref3, 2),
|
|
289
|
-
negW = _ref4[0],
|
|
290
|
-
negH = _ref4[1];
|
|
291
|
-
|
|
292
|
-
var 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)) + shape.translation[0];
|
|
293
|
-
var 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)) + shape.translation[1];
|
|
294
|
-
return (0, _intersect.getPointPositionBeforeCanvasTransformation)([oppositeX, oppositeY], shape.translation, shape.rotation, center);
|
|
295
|
-
};
|
|
296
|
-
|
|
297
|
-
var getEllipseOppositeAnchorAbsolutePosition = function getEllipseOppositeAnchorAbsolutePosition(anchor, center, shape) {
|
|
298
|
-
var _ref5 = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : [false, false],
|
|
299
|
-
_ref6 = (0, _slicedToArray2["default"])(_ref5, 2),
|
|
300
|
-
negW = _ref6[0],
|
|
301
|
-
negH = _ref6[1];
|
|
302
|
-
|
|
303
|
-
var oppositeX = (anchor[0] === 0.5 ? shape.x + shape.radiusX / 2 : anchor[0] === 0 ? shape.x + (negW ? -shape.radiusX : shape.radiusX) : shape.x + (negW ? shape.radiusX : -shape.radiusX)) + shape.translation[0];
|
|
304
|
-
var oppositeY = (anchor[1] === 0.5 ? shape.y + shape.radiusY / 2 : anchor[1] === 0 ? shape.y + (negH ? -shape.radiusY : shape.radiusY) : shape.y + (negH ? shape.radiusY : -shape.radiusY)) + shape.translation[1];
|
|
305
|
-
return (0, _intersect.getPointPositionBeforeCanvasTransformation)([oppositeX, oppositeY], shape.translation, shape.rotation, center);
|
|
306
|
-
};
|
|
78
|
+
case 'rotate':
|
|
79
|
+
return (0, _shapes.rotateShape)(shape, cursorPosition, selectionMode.originalShape, selectionMode.cursorStartPosition, selectionMode.center, gridFormat);
|
|
307
80
|
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
negW = _ref8[0],
|
|
312
|
-
negH = _ref8[1];
|
|
81
|
+
case 'resize':
|
|
82
|
+
const roundCursorPosition = [roundForGrid(cursorPosition[0], gridFormat), roundForGrid(cursorPosition[1], gridFormat)];
|
|
83
|
+
return (0, _shapes.resizeShape)(ctx, shape, roundCursorPosition, canvasOffset, selectionMode.originalShape, selectionMode, selectionPadding, isShiftPressed);
|
|
313
84
|
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
return (0, _intersect.getPointPositionBeforeCanvasTransformation)([oppositeX, oppositeY], shape.translation, shape.rotation, center);
|
|
317
|
-
};
|
|
318
|
-
|
|
319
|
-
var resizePicture = function resizePicture(cursorPosition, canvasOffset, originalShape, selectionMode, selectionPadding) {
|
|
320
|
-
return resizeRect(cursorPosition, canvasOffset, originalShape, selectionMode, selectionPadding, true);
|
|
321
|
-
};
|
|
322
|
-
|
|
323
|
-
exports.resizePicture = resizePicture;
|
|
324
|
-
|
|
325
|
-
var resizeShape = function resizeShape(ctx, shape, cursorPosition, canvasOffset, originalShape, selectionMode, selectionPadding) {
|
|
326
|
-
if (shape.type === 'line' || shape.type === 'polygon' || shape.type === 'curve') return resizeLine(cursorPosition, canvasOffset, originalShape, selectionMode, selectionPadding);else if (shape.type === 'brush') return resizeBrush(cursorPosition, canvasOffset, originalShape, selectionMode, selectionPadding);else if (shape.type === 'circle') return resizeCircle(cursorPosition, canvasOffset, originalShape, selectionMode, selectionPadding);else if (shape.type === 'ellipse') return resizeEllipse(cursorPosition, canvasOffset, originalShape, selectionMode, selectionPadding);else if (shape.type === 'rect') return resizeRect(cursorPosition, canvasOffset, originalShape, selectionMode, selectionPadding);else if (shape.type === 'square') return resizeRect(cursorPosition, canvasOffset, originalShape, selectionMode, selectionPadding, true);else if (shape.type === 'text') return resizeText(ctx, cursorPosition, canvasOffset, originalShape, selectionMode, selectionPadding);else if (shape.type === 'picture') return resizePicture(cursorPosition, canvasOffset, originalShape, selectionMode, selectionPadding);
|
|
327
|
-
return shape;
|
|
328
|
-
};
|
|
329
|
-
|
|
330
|
-
exports.resizeShape = resizeShape;
|
|
331
|
-
|
|
332
|
-
var transformShape = function transformShape(ctx, shape, cursorPosition, canvasOffset, selectionMode, selectionPadding) {
|
|
333
|
-
if (selectionMode.mode === _Mode.SelectionModeLib.brush) {
|
|
334
|
-
return paintNewPointToShape(shape, cursorPosition);
|
|
335
|
-
} else if (selectionMode.mode === _Mode.SelectionModeLib.translate) {
|
|
336
|
-
return translateShape(shape, cursorPosition, selectionMode.originalShape, selectionMode.cursorStartPosition);
|
|
337
|
-
} else if (selectionMode.mode === _Mode.SelectionModeLib.rotate) {
|
|
338
|
-
return rotateShape(shape, cursorPosition, selectionMode.originalShape, selectionMode.cursorStartPosition, selectionMode.center);
|
|
339
|
-
} else if (selectionMode.mode === _Mode.SelectionModeLib.resize) {
|
|
340
|
-
return resizeShape(ctx, shape, cursorPosition, canvasOffset, selectionMode.originalShape, selectionMode, selectionPadding);
|
|
85
|
+
default:
|
|
86
|
+
return shape;
|
|
341
87
|
}
|
|
342
|
-
|
|
343
|
-
return shape;
|
|
344
88
|
};
|
|
345
89
|
|
|
346
90
|
exports.transformShape = transformShape;
|
|
347
91
|
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
ctx.font = "".concat(fontItalic ? 'italic' : '', " ").concat(fontBold ? 'bold' : '', " 1px ").concat(fontFamily);
|
|
353
|
-
return (_$flow = _fp["default"].flow(_fp["default"].map(function (value) {
|
|
354
|
-
return maxWidth / ctx.measureText(value).width;
|
|
355
|
-
}), _fp["default"].min)(text)) !== null && _$flow !== void 0 ? _$flow : _style.STYLE_FONT_SIZE_DEFAULT;
|
|
356
|
-
};
|
|
357
|
-
|
|
358
|
-
exports.calculateTextFontSize = calculateTextFontSize;
|
|
359
|
-
|
|
360
|
-
var calculateTextWidth = function calculateTextWidth(ctx, text, fontSize, fontBold, fontItalic) {
|
|
361
|
-
var _$flow2;
|
|
362
|
-
|
|
363
|
-
var fontFamily = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : _style.STYLE_FONT_DEFAULT;
|
|
364
|
-
ctx.font = "".concat(fontItalic ? 'italic' : '', " ").concat(fontBold ? 'bold' : '', " ").concat(fontSize, "px ").concat(fontFamily);
|
|
365
|
-
return (_$flow2 = _fp["default"].flow(_fp["default"].map(function (value) {
|
|
366
|
-
return ctx.measureText(value).width;
|
|
367
|
-
}), _fp["default"].max)(text)) !== null && _$flow2 !== void 0 ? _$flow2 : 20;
|
|
368
|
-
};
|
|
369
|
-
|
|
370
|
-
exports.calculateTextWidth = calculateTextWidth;
|
|
371
|
-
|
|
372
|
-
var degreesToRadians = function degreesToRadians(degrees) {
|
|
373
|
-
return degrees * (Math.PI / 180);
|
|
374
|
-
};
|
|
375
|
-
|
|
376
|
-
exports.degreesToRadians = degreesToRadians;
|
|
377
|
-
|
|
378
|
-
var radiansToDegrees = function radiansToDegrees(radians) {
|
|
379
|
-
return radians * 180 / Math.PI;
|
|
380
|
-
};
|
|
381
|
-
|
|
382
|
-
exports.radiansToDegrees = radiansToDegrees;
|
|
383
|
-
|
|
384
|
-
var fitContentInsideContainer = function fitContentInsideContainer(contentWidth, contentHeight, containerWidth, containerHeight) {
|
|
385
|
-
var shouldFillContainer = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : false;
|
|
386
|
-
var contentRatio = contentWidth / contentHeight;
|
|
387
|
-
var containerRatio = containerWidth / containerHeight;
|
|
92
|
+
const fitContentInsideContainer = function (contentWidth, contentHeight, containerWidth, containerHeight) {
|
|
93
|
+
let shouldFillContainer = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : false;
|
|
94
|
+
const contentRatio = contentWidth / contentHeight;
|
|
95
|
+
const containerRatio = containerWidth / containerHeight;
|
|
388
96
|
|
|
389
97
|
if (contentRatio > containerRatio) {
|
|
390
|
-
|
|
98
|
+
const newWidth = shouldFillContainer ? containerWidth : Math.min(contentWidth, containerWidth);
|
|
391
99
|
return [newWidth, newWidth / contentRatio];
|
|
392
100
|
} else {
|
|
393
|
-
|
|
101
|
+
const newHeight = shouldFillContainer ? containerHeight : Math.min(contentHeight, containerHeight);
|
|
394
102
|
return [newHeight * contentRatio, newHeight];
|
|
395
103
|
}
|
|
396
104
|
};
|