@yorab/react-paint 0.2.2 → 0.3.0
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/Changelog.md +24 -0
- package/LICENSE.txt +21 -0
- package/README.md +6 -89
- package/dist/components/App.js +125 -102
- package/dist/components/Canvas.js +17 -14
- package/dist/components/settings/LayoutButton.js +3 -3
- package/dist/components/settings/Layouts.js +6 -19
- package/dist/components/settings/SettingsBar.js +3 -3
- package/dist/components/toolbox/EditTextBox.js +3 -2
- package/dist/components/toolbox/MenuGroup.js +1 -0
- package/dist/components/toolbox/PictureUrlInput.js +8 -7
- package/dist/hooks/useDrawableCanvas.js +19 -17
- package/dist/hooks/useResizeObserver.js +40 -0
- package/dist/hooks/useShapes.js +12 -8
- package/dist/styles.css +16 -17
- package/dist/utils/data.js +71 -19
- package/dist/utils/draw.js +53 -44
- package/dist/utils/file.js +26 -60
- package/dist/utils/intersect.js +18 -14
- package/dist/utils/selection.js +3 -3
- package/dist/utils/transform.js +18 -2
- package/package.json +6 -7
- package/dist/components/App.d.ts +0 -20
- package/dist/components/Canvas.d.ts +0 -28
- package/dist/components/common/Button.d.ts +0 -14
- package/dist/components/common/Loading.d.ts +0 -6
- package/dist/components/common/Modal.d.ts +0 -8
- package/dist/components/common/Panel.d.ts +0 -10
- package/dist/components/common/Snackbar.d.ts +0 -7
- package/dist/components/settings/ColorField.d.ts +0 -12
- package/dist/components/settings/DeleteButton.d.ts +0 -9
- package/dist/components/settings/FontFamilyField.d.ts +0 -10
- package/dist/components/settings/LayoutButton.d.ts +0 -8
- package/dist/components/settings/Layouts.d.ts +0 -18
- package/dist/components/settings/LineArrowField.d.ts +0 -10
- package/dist/components/settings/LineTypeField.d.ts +0 -14
- package/dist/components/settings/PointsNumberField.d.ts +0 -11
- package/dist/components/settings/RangeField.d.ts +0 -16
- package/dist/components/settings/SelectField.d.ts +0 -16
- package/dist/components/settings/SettingsBar.d.ts +0 -16
- package/dist/components/toolbox/EditTextBox.d.ts +0 -10
- package/dist/components/toolbox/LoadFileTool.d.ts +0 -11
- package/dist/components/toolbox/MenuGroup.d.ts +0 -23
- package/dist/components/toolbox/PictureUrlInput.d.ts +0 -7
- package/dist/components/toolbox/Tool.d.ts +0 -13
- package/dist/components/toolbox/Toolbar.d.ts +0 -20
- package/dist/components/toolbox/ToolbarGroup.d.ts +0 -18
- package/dist/constants/draw.d.ts +0 -2
- package/dist/constants/draw.js +0 -10
- package/dist/constants/icons.d.ts +0 -36
- package/dist/constants/shapes.d.ts +0 -5
- package/dist/constants/snackbar.d.ts +0 -11
- package/dist/constants/style.d.ts +0 -12
- package/dist/hooks/useComponent.d.ts +0 -9
- package/dist/hooks/useDrag.d.ts +0 -15
- package/dist/hooks/useDrawableCanvas.d.ts +0 -30
- package/dist/hooks/useKeyboard.d.ts +0 -15
- package/dist/hooks/useShapes.d.ts +0 -22
- package/dist/hooks/useSnackbar.d.ts +0 -16
- package/dist/schemas/drawableShape.json +0 -1021
- package/dist/types/Mode.d.ts +0 -51
- package/dist/types/Shapes.d.ts +0 -122
- package/dist/types/keyboard.d.ts +0 -15
- package/dist/utils/data.d.ts +0 -4
- package/dist/utils/draw.d.ts +0 -18
- package/dist/utils/file.d.ts +0 -33
- package/dist/utils/intersect.d.ts +0 -8
- package/dist/utils/selection.d.ts +0 -7
- package/dist/utils/shapeData.d.ts +0 -5
- package/dist/utils/string.d.ts +0 -3
- package/dist/utils/style.d.ts +0 -2
- package/dist/utils/toolbar.d.ts +0 -12
- package/dist/utils/transform.d.ts +0 -271
package/dist/utils/data.js
CHANGED
|
@@ -5,34 +5,41 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", {
|
|
6
6
|
value: true
|
|
7
7
|
});
|
|
8
|
-
exports.createShape = exports.createPicture = exports.copyShape = void 0;
|
|
8
|
+
exports.roundValues = exports.createShape = exports.createPicture = exports.copyShape = exports.cleanShapesBeforeExport = exports.addDefaultAndTempShapeProps = void 0;
|
|
9
9
|
|
|
10
10
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
11
11
|
|
|
12
|
+
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
13
|
+
|
|
12
14
|
var _fp = _interopRequireDefault(require("lodash/fp"));
|
|
13
15
|
|
|
14
16
|
var _transform = require("./transform");
|
|
15
17
|
|
|
16
18
|
var _Shapes = require("../types/Shapes");
|
|
17
19
|
|
|
20
|
+
var _file = require("./file");
|
|
21
|
+
|
|
18
22
|
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
19
23
|
|
|
20
24
|
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; }
|
|
21
25
|
|
|
22
|
-
var createPicture = function createPicture(fileOrUrl,
|
|
26
|
+
var createPicture = function createPicture(fileOrUrl, maxPictureWidth, maxPictureHeight) {
|
|
23
27
|
return new Promise(function (resolve, reject) {
|
|
24
28
|
var img = new Image();
|
|
25
29
|
|
|
26
30
|
img.onload = function () {
|
|
27
|
-
var
|
|
28
|
-
|
|
31
|
+
var _fitContentInsideCont = (0, _transform.fitContentInsideContainer)(img.width, img.height, maxPictureWidth, maxPictureHeight),
|
|
32
|
+
_fitContentInsideCont2 = (0, _slicedToArray2["default"])(_fitContentInsideCont, 2),
|
|
33
|
+
width = _fitContentInsideCont2[0],
|
|
34
|
+
height = _fitContentInsideCont2[1];
|
|
35
|
+
|
|
29
36
|
var pictureShape = {
|
|
30
37
|
type: _Shapes.ShapeEnum.picture,
|
|
31
|
-
id: _fp["default"].uniqueId(_Shapes.ShapeEnum.picture),
|
|
32
|
-
x:
|
|
33
|
-
y:
|
|
34
|
-
width:
|
|
35
|
-
height:
|
|
38
|
+
id: _fp["default"].uniqueId("".concat(_Shapes.ShapeEnum.picture, "_")),
|
|
39
|
+
x: (maxPictureWidth - width) / 2,
|
|
40
|
+
y: (maxPictureHeight - height) / 2,
|
|
41
|
+
width: width,
|
|
42
|
+
height: height,
|
|
36
43
|
src: img.src,
|
|
37
44
|
img: img,
|
|
38
45
|
translation: [0, 0],
|
|
@@ -66,7 +73,7 @@ var createShape = function createShape(ctx, shape, cursorPosition, defaultConf)
|
|
|
66
73
|
case _Shapes.ShapeEnum.brush:
|
|
67
74
|
return {
|
|
68
75
|
type: _Shapes.ShapeEnum.brush,
|
|
69
|
-
id: _fp["default"].uniqueId(shape),
|
|
76
|
+
id: _fp["default"].uniqueId("".concat(shape, "_")),
|
|
70
77
|
points: [[cursorPosition]],
|
|
71
78
|
translation: [0, 0],
|
|
72
79
|
rotation: 0,
|
|
@@ -76,7 +83,7 @@ var createShape = function createShape(ctx, shape, cursorPosition, defaultConf)
|
|
|
76
83
|
case _Shapes.ShapeEnum.line:
|
|
77
84
|
return {
|
|
78
85
|
type: _Shapes.ShapeEnum.line,
|
|
79
|
-
id: _fp["default"].uniqueId(shape),
|
|
86
|
+
id: _fp["default"].uniqueId("".concat(shape, "_")),
|
|
80
87
|
points: [cursorPosition, cursorPosition],
|
|
81
88
|
translation: [0, 0],
|
|
82
89
|
rotation: 0,
|
|
@@ -86,7 +93,7 @@ var createShape = function createShape(ctx, shape, cursorPosition, defaultConf)
|
|
|
86
93
|
case _Shapes.ShapeEnum.polygon:
|
|
87
94
|
return {
|
|
88
95
|
type: _Shapes.ShapeEnum.polygon,
|
|
89
|
-
id: _fp["default"].uniqueId(shape),
|
|
96
|
+
id: _fp["default"].uniqueId("".concat(shape, "_")),
|
|
90
97
|
points: _fp["default"].flow(_fp["default"].range(0), _fp["default"].map(function () {
|
|
91
98
|
return cursorPosition;
|
|
92
99
|
}))((_defaultConf$style$po = (_defaultConf$style = defaultConf.style) === null || _defaultConf$style === void 0 ? void 0 : _defaultConf$style.pointsCount) !== null && _defaultConf$style$po !== void 0 ? _defaultConf$style$po : 3),
|
|
@@ -98,7 +105,7 @@ var createShape = function createShape(ctx, shape, cursorPosition, defaultConf)
|
|
|
98
105
|
case _Shapes.ShapeEnum.curve:
|
|
99
106
|
return {
|
|
100
107
|
type: _Shapes.ShapeEnum.curve,
|
|
101
|
-
id: _fp["default"].uniqueId(shape),
|
|
108
|
+
id: _fp["default"].uniqueId("".concat(shape, "_")),
|
|
102
109
|
points: _fp["default"].flow(_fp["default"].range(0), _fp["default"].map(function () {
|
|
103
110
|
return cursorPosition;
|
|
104
111
|
}))((_defaultConf$style$po2 = (_defaultConf$style2 = defaultConf.style) === null || _defaultConf$style2 === void 0 ? void 0 : _defaultConf$style2.pointsCount) !== null && _defaultConf$style$po2 !== void 0 ? _defaultConf$style$po2 : 3),
|
|
@@ -111,7 +118,7 @@ var createShape = function createShape(ctx, shape, cursorPosition, defaultConf)
|
|
|
111
118
|
case _Shapes.ShapeEnum.square:
|
|
112
119
|
return {
|
|
113
120
|
type: shape,
|
|
114
|
-
id: _fp["default"].uniqueId(shape),
|
|
121
|
+
id: _fp["default"].uniqueId("".concat(shape, "_")),
|
|
115
122
|
x: cursorPosition[0],
|
|
116
123
|
y: cursorPosition[1],
|
|
117
124
|
width: 1,
|
|
@@ -126,7 +133,7 @@ var createShape = function createShape(ctx, shape, cursorPosition, defaultConf)
|
|
|
126
133
|
var fontSize = (0, _transform.calculateTextFontSize)(ctx, defaultValue, 50, (_defaultConf$style3 = defaultConf.style) === null || _defaultConf$style3 === void 0 ? void 0 : _defaultConf$style3.fontFamily);
|
|
127
134
|
return {
|
|
128
135
|
type: _Shapes.ShapeEnum.text,
|
|
129
|
-
id: _fp["default"].uniqueId(shape),
|
|
136
|
+
id: _fp["default"].uniqueId("".concat(shape, "_")),
|
|
130
137
|
x: cursorPosition[0],
|
|
131
138
|
y: cursorPosition[1],
|
|
132
139
|
value: defaultValue,
|
|
@@ -141,7 +148,7 @@ var createShape = function createShape(ctx, shape, cursorPosition, defaultConf)
|
|
|
141
148
|
case _Shapes.ShapeEnum.ellipse:
|
|
142
149
|
return {
|
|
143
150
|
type: _Shapes.ShapeEnum.ellipse,
|
|
144
|
-
id: _fp["default"].uniqueId(shape),
|
|
151
|
+
id: _fp["default"].uniqueId("".concat(shape, "_")),
|
|
145
152
|
x: cursorPosition[0],
|
|
146
153
|
y: cursorPosition[1],
|
|
147
154
|
radiusX: 0,
|
|
@@ -155,7 +162,7 @@ var createShape = function createShape(ctx, shape, cursorPosition, defaultConf)
|
|
|
155
162
|
default:
|
|
156
163
|
return {
|
|
157
164
|
type: _Shapes.ShapeEnum.circle,
|
|
158
|
-
id: _fp["default"].uniqueId(shape),
|
|
165
|
+
id: _fp["default"].uniqueId("".concat(shape, "_")),
|
|
159
166
|
x: cursorPosition[0],
|
|
160
167
|
y: cursorPosition[1],
|
|
161
168
|
radius: 0,
|
|
@@ -170,9 +177,54 @@ exports.createShape = createShape;
|
|
|
170
177
|
|
|
171
178
|
var copyShape = function copyShape(shape) {
|
|
172
179
|
return _objectSpread(_objectSpread({}, shape), {}, {
|
|
173
|
-
id: _fp["default"].uniqueId(shape.type),
|
|
180
|
+
id: _fp["default"].uniqueId("".concat(shape.type, "_")),
|
|
174
181
|
translation: [shape.translation[0] + 20, shape.translation[1] + 20]
|
|
175
182
|
});
|
|
176
183
|
};
|
|
177
184
|
|
|
178
|
-
exports.copyShape = copyShape;
|
|
185
|
+
exports.copyShape = copyShape;
|
|
186
|
+
|
|
187
|
+
var roundValues = function roundValues(prop) {
|
|
188
|
+
var precision = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 2;
|
|
189
|
+
|
|
190
|
+
if (_fp["default"].isArray(prop)) {
|
|
191
|
+
return prop.map(roundValues);
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
if (_fp["default"].isObject(prop)) {
|
|
195
|
+
return _fp["default"].mapValues(roundValues, prop);
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
if (_fp["default"].isNumber(prop)) {
|
|
199
|
+
return +prop.toFixed(precision);
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
return prop;
|
|
203
|
+
};
|
|
204
|
+
|
|
205
|
+
exports.roundValues = roundValues;
|
|
206
|
+
|
|
207
|
+
var cleanShapesBeforeExport = function cleanShapesBeforeExport(shapes) {
|
|
208
|
+
var propsToOmit = ['img', 'id'];
|
|
209
|
+
return shapes.map(function (shape) {
|
|
210
|
+
if (shape.type === _Shapes.ShapeEnum.picture) {
|
|
211
|
+
if (!shape.src.startsWith('http')) {
|
|
212
|
+
return roundValues(_fp["default"].omit(propsToOmit, _objectSpread(_objectSpread({}, shape), {}, {
|
|
213
|
+
src: (0, _file.getBase64Image)(shape.img)
|
|
214
|
+
})));
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
return roundValues(_fp["default"].omit(propsToOmit, shape));
|
|
219
|
+
});
|
|
220
|
+
};
|
|
221
|
+
|
|
222
|
+
exports.cleanShapesBeforeExport = cleanShapesBeforeExport;
|
|
223
|
+
|
|
224
|
+
var addDefaultAndTempShapeProps = function addDefaultAndTempShapeProps(shape) {
|
|
225
|
+
return _objectSpread(_objectSpread({}, shape), {}, {
|
|
226
|
+
id: _fp["default"].uniqueId("".concat(shape.type, "_"))
|
|
227
|
+
});
|
|
228
|
+
};
|
|
229
|
+
|
|
230
|
+
exports.addDefaultAndTempShapeProps = addDefaultAndTempShapeProps;
|
package/dist/utils/draw.js
CHANGED
|
@@ -29,8 +29,9 @@ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (O
|
|
|
29
29
|
|
|
30
30
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2["default"])(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
31
31
|
|
|
32
|
-
var applyShapeTransformations = function applyShapeTransformations(ctx, marker, canvasOffset) {
|
|
32
|
+
var applyShapeTransformations = function applyShapeTransformations(ctx, marker, responsiveScale, canvasOffset) {
|
|
33
33
|
ctx.save();
|
|
34
|
+
ctx.scale(responsiveScale, responsiveScale);
|
|
34
35
|
ctx.translate(marker.translation[0] + canvasOffset[0], marker.translation[1] + canvasOffset[1]);
|
|
35
36
|
|
|
36
37
|
if (marker.rotation !== 0) {
|
|
@@ -48,19 +49,17 @@ var restoreShapeTransformations = function restoreShapeTransformations(ctx) {
|
|
|
48
49
|
};
|
|
49
50
|
|
|
50
51
|
var updateDrawStyle = function updateDrawStyle(ctx) {
|
|
51
|
-
var
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
lineDash = _ref.lineDash;
|
|
63
|
-
|
|
52
|
+
var style = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
53
|
+
var _style$fillColor = style.fillColor,
|
|
54
|
+
fillColor = _style$fillColor === void 0 ? 'transparent' : _style$fillColor,
|
|
55
|
+
_style$globalAlpha = style.globalAlpha,
|
|
56
|
+
globalAlpha = _style$globalAlpha === void 0 ? 100 : _style$globalAlpha,
|
|
57
|
+
_style$strokeColor = style.strokeColor,
|
|
58
|
+
strokeColor = _style$strokeColor === void 0 ? 'blue' : _style$strokeColor,
|
|
59
|
+
_style$lineWidth = style.lineWidth,
|
|
60
|
+
lineWidth = _style$lineWidth === void 0 ? 1 : _style$lineWidth,
|
|
61
|
+
_style$lineDash = style.lineDash,
|
|
62
|
+
lineDash = _style$lineDash === void 0 ? 0 : _style$lineDash;
|
|
64
63
|
ctx.lineCap = 'round';
|
|
65
64
|
ctx.lineJoin = 'round';
|
|
66
65
|
globalAlpha !== undefined && (ctx.globalAlpha = globalAlpha / 100);
|
|
@@ -250,9 +249,9 @@ var drawPicture = function drawPicture(ctx, picture) {
|
|
|
250
249
|
|
|
251
250
|
exports.drawPicture = drawPicture;
|
|
252
251
|
|
|
253
|
-
var drawShape = function drawShape(ctx, shape, canvasOffset) {
|
|
252
|
+
var drawShape = function drawShape(ctx, shape, responsiveScale, canvasOffset) {
|
|
254
253
|
if (shape.visible === false) return;
|
|
255
|
-
applyShapeTransformations(ctx, shape, canvasOffset);
|
|
254
|
+
applyShapeTransformations(ctx, shape, responsiveScale, canvasOffset);
|
|
256
255
|
|
|
257
256
|
switch (shape.type) {
|
|
258
257
|
case 'brush':
|
|
@@ -298,10 +297,13 @@ var drawShape = function drawShape(ctx, shape, canvasOffset) {
|
|
|
298
297
|
|
|
299
298
|
exports.drawShape = drawShape;
|
|
300
299
|
|
|
301
|
-
var drawSelectionDefault = function drawSelectionDefault(
|
|
302
|
-
var ctx =
|
|
303
|
-
shape =
|
|
304
|
-
withAnchors =
|
|
300
|
+
var drawSelectionDefault = function drawSelectionDefault(_ref) {
|
|
301
|
+
var ctx = _ref.ctx,
|
|
302
|
+
shape = _ref.shape,
|
|
303
|
+
withAnchors = _ref.withAnchors,
|
|
304
|
+
_ref$currentScale = _ref.currentScale,
|
|
305
|
+
currentScale = _ref$currentScale === void 0 ? 1 : _ref$currentScale;
|
|
306
|
+
var scaleWithMinCap = Math.min(1, currentScale);
|
|
305
307
|
|
|
306
308
|
var _getShapeInfos2 = (0, _shapeData.getShapeInfos)(shape),
|
|
307
309
|
borders = _getShapeInfos2.borders;
|
|
@@ -309,7 +311,7 @@ var drawSelectionDefault = function drawSelectionDefault(_ref2) {
|
|
|
309
311
|
drawRect(ctx, borders);
|
|
310
312
|
if (!withAnchors || shape.locked) return;
|
|
311
313
|
drawLine(ctx, {
|
|
312
|
-
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]]
|
|
314
|
+
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 / scaleWithMinCap]]
|
|
313
315
|
});
|
|
314
316
|
|
|
315
317
|
var _iterator = _createForOfIteratorHelper(_shapes.SELECTION_RESIZE_ANCHOR_POSITIONS),
|
|
@@ -321,11 +323,11 @@ var drawSelectionDefault = function drawSelectionDefault(_ref2) {
|
|
|
321
323
|
drawCircle(ctx, {
|
|
322
324
|
x: borders.x + borders.width * anchorPosition[0],
|
|
323
325
|
y: borders.y + borders.height * anchorPosition[1],
|
|
324
|
-
radius: _shapes.SELECTION_ANCHOR_SIZE / 2,
|
|
326
|
+
radius: _shapes.SELECTION_ANCHOR_SIZE / 2 / scaleWithMinCap,
|
|
325
327
|
style: {
|
|
326
328
|
fillColor: 'rgb(255,255,255)',
|
|
327
329
|
strokeColor: 'rgb(150,150,150)',
|
|
328
|
-
lineWidth: 2
|
|
330
|
+
lineWidth: 2 / scaleWithMinCap
|
|
329
331
|
}
|
|
330
332
|
});
|
|
331
333
|
}
|
|
@@ -337,20 +339,23 @@ var drawSelectionDefault = function drawSelectionDefault(_ref2) {
|
|
|
337
339
|
|
|
338
340
|
drawCircle(ctx, {
|
|
339
341
|
x: borders.x + borders.width / 2,
|
|
340
|
-
y: borders.y - _shapes.SELECTION_ANCHOR_SIZE / 2 - _shapes.SELECTION_ROTATED_ANCHOR_POSITION,
|
|
341
|
-
radius: _shapes.SELECTION_ANCHOR_SIZE / 2,
|
|
342
|
+
y: borders.y - _shapes.SELECTION_ANCHOR_SIZE / 2 - _shapes.SELECTION_ROTATED_ANCHOR_POSITION / scaleWithMinCap,
|
|
343
|
+
radius: _shapes.SELECTION_ANCHOR_SIZE / 2 / scaleWithMinCap,
|
|
342
344
|
style: {
|
|
343
345
|
fillColor: 'rgb(255,255,255)',
|
|
344
346
|
strokeColor: 'rgb(150,150,150)',
|
|
345
|
-
lineWidth: 2
|
|
347
|
+
lineWidth: 2 / scaleWithMinCap
|
|
346
348
|
}
|
|
347
349
|
});
|
|
348
350
|
};
|
|
349
351
|
|
|
350
|
-
var drawLineSelection = function drawLineSelection(
|
|
351
|
-
var ctx =
|
|
352
|
-
shape =
|
|
353
|
-
withAnchors =
|
|
352
|
+
var drawLineSelection = function drawLineSelection(_ref2) {
|
|
353
|
+
var ctx = _ref2.ctx,
|
|
354
|
+
shape = _ref2.shape,
|
|
355
|
+
withAnchors = _ref2.withAnchors,
|
|
356
|
+
_ref2$currentScale = _ref2.currentScale,
|
|
357
|
+
currentScale = _ref2$currentScale === void 0 ? 1 : _ref2$currentScale;
|
|
358
|
+
var scaleWithMinCap = Math.min(1, currentScale);
|
|
354
359
|
|
|
355
360
|
var _getShapeInfos3 = (0, _shapeData.getShapeInfos)(shape),
|
|
356
361
|
borders = _getShapeInfos3.borders;
|
|
@@ -365,36 +370,38 @@ var drawLineSelection = function drawLineSelection(_ref3) {
|
|
|
365
370
|
drawRect(ctx, {
|
|
366
371
|
x: coordinate[0] - _shapes.SELECTION_ANCHOR_SIZE / 2,
|
|
367
372
|
y: coordinate[1] - _shapes.SELECTION_ANCHOR_SIZE / 2,
|
|
368
|
-
width: _shapes.SELECTION_ANCHOR_SIZE,
|
|
369
|
-
height: _shapes.SELECTION_ANCHOR_SIZE,
|
|
373
|
+
width: _shapes.SELECTION_ANCHOR_SIZE / scaleWithMinCap,
|
|
374
|
+
height: _shapes.SELECTION_ANCHOR_SIZE / scaleWithMinCap,
|
|
370
375
|
style: {
|
|
371
376
|
fillColor: 'rgb(255,255,255)',
|
|
372
377
|
strokeColor: 'rgb(150,150,150)',
|
|
373
|
-
lineWidth: 2
|
|
378
|
+
lineWidth: 2 / scaleWithMinCap
|
|
374
379
|
}
|
|
375
380
|
});
|
|
376
381
|
} else {
|
|
377
382
|
drawCircle(ctx, {
|
|
378
383
|
x: coordinate[0],
|
|
379
384
|
y: coordinate[1],
|
|
380
|
-
radius: _shapes.SELECTION_ANCHOR_SIZE / 2,
|
|
385
|
+
radius: _shapes.SELECTION_ANCHOR_SIZE / 2 / scaleWithMinCap,
|
|
381
386
|
style: {
|
|
382
387
|
fillColor: 'rgb(255,255,255)',
|
|
383
388
|
strokeColor: 'rgb(150,150,150)',
|
|
384
|
-
lineWidth: 2
|
|
389
|
+
lineWidth: 2 / scaleWithMinCap
|
|
385
390
|
}
|
|
386
391
|
});
|
|
387
392
|
}
|
|
388
393
|
}
|
|
389
394
|
};
|
|
390
395
|
|
|
391
|
-
var drawSelection = function drawSelection(
|
|
392
|
-
var ctx =
|
|
393
|
-
shape =
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
396
|
+
var drawSelection = function drawSelection(_ref3) {
|
|
397
|
+
var ctx = _ref3.ctx,
|
|
398
|
+
shape = _ref3.shape,
|
|
399
|
+
_ref3$scaleRatio = _ref3.scaleRatio,
|
|
400
|
+
scaleRatio = _ref3$scaleRatio === void 0 ? 1 : _ref3$scaleRatio,
|
|
401
|
+
canvasOffset = _ref3.canvasOffset,
|
|
402
|
+
_ref3$withAnchors = _ref3.withAnchors,
|
|
403
|
+
withAnchors = _ref3$withAnchors === void 0 ? true : _ref3$withAnchors;
|
|
404
|
+
applyShapeTransformations(ctx, shape, scaleRatio, canvasOffset);
|
|
398
405
|
|
|
399
406
|
switch (shape.type) {
|
|
400
407
|
case 'polygon':
|
|
@@ -403,7 +410,8 @@ var drawSelection = function drawSelection(_ref4) {
|
|
|
403
410
|
drawLineSelection({
|
|
404
411
|
ctx: ctx,
|
|
405
412
|
shape: shape,
|
|
406
|
-
withAnchors: withAnchors
|
|
413
|
+
withAnchors: withAnchors,
|
|
414
|
+
currentScale: scaleRatio
|
|
407
415
|
});
|
|
408
416
|
break;
|
|
409
417
|
|
|
@@ -411,7 +419,8 @@ var drawSelection = function drawSelection(_ref4) {
|
|
|
411
419
|
drawSelectionDefault({
|
|
412
420
|
ctx: ctx,
|
|
413
421
|
shape: shape,
|
|
414
|
-
withAnchors: withAnchors
|
|
422
|
+
withAnchors: withAnchors,
|
|
423
|
+
currentScale: scaleRatio
|
|
415
424
|
});
|
|
416
425
|
break;
|
|
417
426
|
}
|
package/dist/utils/file.js
CHANGED
|
@@ -5,27 +5,21 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", {
|
|
6
6
|
value: true
|
|
7
7
|
});
|
|
8
|
-
exports.
|
|
8
|
+
exports.getCanvasImage = exports.getBase64Image = exports.fetchAndStringify = exports.encodeShapesInString = exports.downloadFile = exports.decodePicturesInShapes = exports.decodeJson = void 0;
|
|
9
9
|
|
|
10
10
|
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
|
|
11
11
|
|
|
12
|
-
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
|
13
|
-
|
|
14
12
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
15
13
|
|
|
16
|
-
var
|
|
14
|
+
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
|
17
15
|
|
|
18
16
|
var _fp = _interopRequireDefault(require("lodash/fp"));
|
|
19
17
|
|
|
20
|
-
var _drawableShape = _interopRequireDefault(require("../schemas/drawableShape.json"));
|
|
21
|
-
|
|
22
18
|
var _Shapes = require("../types/Shapes");
|
|
23
19
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
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); }
|
|
20
|
+
var _data = require("./data");
|
|
27
21
|
|
|
28
|
-
|
|
22
|
+
var _draw = require("./draw");
|
|
29
23
|
|
|
30
24
|
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
31
25
|
|
|
@@ -63,38 +57,32 @@ var getBase64Image = function getBase64Image(img) {
|
|
|
63
57
|
return dataURL;
|
|
64
58
|
};
|
|
65
59
|
|
|
60
|
+
exports.getBase64Image = getBase64Image;
|
|
61
|
+
|
|
66
62
|
var encodeObjectToString = function encodeObjectToString(objectToEncode) {
|
|
67
63
|
return 'data:text/plain;charset=utf-8,' + encodeURIComponent(JSON.stringify(objectToEncode));
|
|
68
64
|
};
|
|
69
65
|
|
|
70
|
-
var getCanvasImage = function getCanvasImage(
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
66
|
+
var getCanvasImage = function getCanvasImage(shapes, canvasOffset, width, height) {
|
|
67
|
+
var newCanvas = document.createElement('canvas');
|
|
68
|
+
newCanvas.width = width;
|
|
69
|
+
newCanvas.height = height;
|
|
70
|
+
var ctx = newCanvas.getContext('2d');
|
|
71
|
+
if (!ctx) return '';
|
|
72
|
+
ctx.clearRect(0, 0, width, height);
|
|
75
73
|
|
|
76
|
-
var
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
if (shape.src.startsWith('http')) {
|
|
80
|
-
return _fp["default"].omit('img', shape);
|
|
81
|
-
} else {
|
|
82
|
-
return _objectSpread(_objectSpread({}, shape), {}, {
|
|
83
|
-
src: getBase64Image(shape.img),
|
|
84
|
-
img: undefined
|
|
85
|
-
});
|
|
86
|
-
}
|
|
87
|
-
}
|
|
74
|
+
for (var i = shapes.length - 1; i >= 0; i--) {
|
|
75
|
+
(0, _draw.drawShape)(ctx, shapes[i], 1, canvasOffset);
|
|
76
|
+
}
|
|
88
77
|
|
|
89
|
-
|
|
90
|
-
});
|
|
78
|
+
return newCanvas.toDataURL('image/png');
|
|
91
79
|
};
|
|
92
80
|
|
|
93
|
-
exports.
|
|
81
|
+
exports.getCanvasImage = getCanvasImage;
|
|
94
82
|
|
|
95
83
|
var encodeShapesInString = function encodeShapesInString(shapes) {
|
|
96
|
-
var
|
|
97
|
-
return encodeObjectToString(
|
|
84
|
+
var cleanShapes = (0, _data.cleanShapesBeforeExport)(shapes);
|
|
85
|
+
return encodeObjectToString(cleanShapes);
|
|
98
86
|
};
|
|
99
87
|
|
|
100
88
|
exports.encodeShapesInString = encodeShapesInString;
|
|
@@ -143,7 +131,9 @@ var decodePicturesInShapes = /*#__PURE__*/function () {
|
|
|
143
131
|
switch (_context2.prev = _context2.next) {
|
|
144
132
|
case 0:
|
|
145
133
|
promisesArray = [];
|
|
146
|
-
shapes =
|
|
134
|
+
shapes = _fp["default"].flow(_fp["default"].map(function (shape) {
|
|
135
|
+
if (!_fp["default"].includes(shape.type, _Shapes.ShapeEnum)) return null;
|
|
136
|
+
|
|
147
137
|
if (shape.type === _Shapes.ShapeEnum.picture) {
|
|
148
138
|
var img = new Image();
|
|
149
139
|
var newPromise = new Promise(function (resolve, reject) {
|
|
@@ -172,8 +162,8 @@ var decodePicturesInShapes = /*#__PURE__*/function () {
|
|
|
172
162
|
});
|
|
173
163
|
}
|
|
174
164
|
|
|
175
|
-
return shape;
|
|
176
|
-
});
|
|
165
|
+
return (0, _data.addDefaultAndTempShapeProps)(shape);
|
|
166
|
+
}), _fp["default"].compact)(shapesForJson);
|
|
177
167
|
_context2.next = 4;
|
|
178
168
|
return Promise.all(promisesArray);
|
|
179
169
|
|
|
@@ -193,28 +183,4 @@ var decodePicturesInShapes = /*#__PURE__*/function () {
|
|
|
193
183
|
};
|
|
194
184
|
}();
|
|
195
185
|
|
|
196
|
-
exports.decodePicturesInShapes = decodePicturesInShapes;
|
|
197
|
-
|
|
198
|
-
var validateJson = function validateJson(json) {
|
|
199
|
-
var ajv = new _ajv["default"]();
|
|
200
|
-
var validate = ajv.compile(_drawableShape["default"]);
|
|
201
|
-
if (!_fp["default"].isArray(json)) return false;
|
|
202
|
-
|
|
203
|
-
var _iterator = _createForOfIteratorHelper(json),
|
|
204
|
-
_step;
|
|
205
|
-
|
|
206
|
-
try {
|
|
207
|
-
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
208
|
-
var shape = _step.value;
|
|
209
|
-
if (!validate(shape)) return false;
|
|
210
|
-
}
|
|
211
|
-
} catch (err) {
|
|
212
|
-
_iterator.e(err);
|
|
213
|
-
} finally {
|
|
214
|
-
_iterator.f();
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
return true;
|
|
218
|
-
};
|
|
219
|
-
|
|
220
|
-
exports.validateJson = validateJson;
|
|
186
|
+
exports.decodePicturesInShapes = decodePicturesInShapes;
|
package/dist/utils/intersect.js
CHANGED
|
@@ -28,6 +28,8 @@ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len
|
|
|
28
28
|
var getCursorPosition = function getCursorPosition(e, canvas, givenWidth, givenHeight) {
|
|
29
29
|
var _canvas$getBoundingCl;
|
|
30
30
|
|
|
31
|
+
var scaleRatio = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : 1;
|
|
32
|
+
|
|
31
33
|
var _$getOr = _fp["default"].getOr(_fp["default"].getOr(e, 'changedTouches[0]', e), 'touches[0]', e),
|
|
32
34
|
clientX = _$getOr.clientX,
|
|
33
35
|
clientY = _$getOr.clientY;
|
|
@@ -38,7 +40,7 @@ var getCursorPosition = function getCursorPosition(e, canvas, givenWidth, givenH
|
|
|
38
40
|
width: givenWidth,
|
|
39
41
|
height: givenHeight
|
|
40
42
|
};
|
|
41
|
-
return [(clientX - canvasBoundingRect.left) * (givenWidth / canvasBoundingRect.width), (clientY - canvasBoundingRect.top) * (givenHeight / canvasBoundingRect.height)];
|
|
43
|
+
return [(clientX - canvasBoundingRect.left) * (givenWidth / canvasBoundingRect.width) / scaleRatio, (clientY - canvasBoundingRect.top) * (givenHeight / canvasBoundingRect.height) / scaleRatio];
|
|
42
44
|
};
|
|
43
45
|
|
|
44
46
|
exports.getCursorPosition = getCursorPosition;
|
|
@@ -124,7 +126,9 @@ var applyRotationToVector = function applyRotationToVector(vector, shapeRotation
|
|
|
124
126
|
exports.applyRotationToVector = applyRotationToVector;
|
|
125
127
|
|
|
126
128
|
var checkPositionIntersection = function checkPositionIntersection(shape, position, canvasOffset) {
|
|
127
|
-
var
|
|
129
|
+
var currentScale = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 1;
|
|
130
|
+
var checkAnchors = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : false;
|
|
131
|
+
var scaleWithMinCap = Math.min(1, currentScale);
|
|
128
132
|
|
|
129
133
|
var _getShapeInfos = (0, _shapeData.getShapeInfos)(shape),
|
|
130
134
|
borders = _getShapeInfos.borders,
|
|
@@ -136,10 +140,10 @@ var checkPositionIntersection = function checkPositionIntersection(shape, positi
|
|
|
136
140
|
if (shape.type === _Shapes.ShapeEnum.line || shape.type === _Shapes.ShapeEnum.polygon || shape.type === _Shapes.ShapeEnum.curve) {
|
|
137
141
|
for (var i = 0; i < shape.points.length; i++) {
|
|
138
142
|
if (isPointInsideRect({
|
|
139
|
-
x: shape.points[i][0] - _shapes.SELECTION_ANCHOR_SIZE / 2,
|
|
140
|
-
y: shape.points[i][1] - _shapes.SELECTION_ANCHOR_SIZE / 2,
|
|
141
|
-
width: _shapes.SELECTION_ANCHOR_SIZE,
|
|
142
|
-
height: _shapes.SELECTION_ANCHOR_SIZE
|
|
143
|
+
x: shape.points[i][0] - _shapes.SELECTION_ANCHOR_SIZE / 2 / scaleWithMinCap,
|
|
144
|
+
y: shape.points[i][1] - _shapes.SELECTION_ANCHOR_SIZE / 2 / scaleWithMinCap,
|
|
145
|
+
width: _shapes.SELECTION_ANCHOR_SIZE / scaleWithMinCap,
|
|
146
|
+
height: _shapes.SELECTION_ANCHOR_SIZE / scaleWithMinCap
|
|
143
147
|
}, newPosition)) {
|
|
144
148
|
return {
|
|
145
149
|
mode: _Mode.SelectionModeLib.resize,
|
|
@@ -149,10 +153,10 @@ var checkPositionIntersection = function checkPositionIntersection(shape, positi
|
|
|
149
153
|
}
|
|
150
154
|
} else {
|
|
151
155
|
if (isPointInsideRect({
|
|
152
|
-
x: borders.x + borders.width / 2 - _shapes.SELECTION_ANCHOR_SIZE / 2,
|
|
153
|
-
y: borders.y - _shapes.SELECTION_ANCHOR_SIZE - _shapes.SELECTION_ROTATED_ANCHOR_POSITION,
|
|
154
|
-
width: _shapes.SELECTION_ANCHOR_SIZE,
|
|
155
|
-
height: _shapes.SELECTION_ANCHOR_SIZE
|
|
156
|
+
x: borders.x + borders.width / 2 - _shapes.SELECTION_ANCHOR_SIZE / 2 / scaleWithMinCap,
|
|
157
|
+
y: borders.y - _shapes.SELECTION_ANCHOR_SIZE / scaleWithMinCap - _shapes.SELECTION_ROTATED_ANCHOR_POSITION / scaleWithMinCap,
|
|
158
|
+
width: _shapes.SELECTION_ANCHOR_SIZE / scaleWithMinCap,
|
|
159
|
+
height: _shapes.SELECTION_ANCHOR_SIZE / scaleWithMinCap
|
|
156
160
|
}, newPosition)) {
|
|
157
161
|
return {
|
|
158
162
|
mode: _Mode.SelectionModeLib.rotate
|
|
@@ -167,10 +171,10 @@ var checkPositionIntersection = function checkPositionIntersection(shape, positi
|
|
|
167
171
|
var anchorPosition = _step.value;
|
|
168
172
|
|
|
169
173
|
if (isPointInsideRect({
|
|
170
|
-
x: borders.x + borders.width * anchorPosition[0] - _shapes.SELECTION_ANCHOR_SIZE / 2,
|
|
171
|
-
y: borders.y + borders.height * anchorPosition[1] - _shapes.SELECTION_ANCHOR_SIZE / 2,
|
|
172
|
-
width: _shapes.SELECTION_ANCHOR_SIZE,
|
|
173
|
-
height: _shapes.SELECTION_ANCHOR_SIZE
|
|
174
|
+
x: borders.x + borders.width * anchorPosition[0] - _shapes.SELECTION_ANCHOR_SIZE / 2 / scaleWithMinCap,
|
|
175
|
+
y: borders.y + borders.height * anchorPosition[1] - _shapes.SELECTION_ANCHOR_SIZE / 2 / scaleWithMinCap,
|
|
176
|
+
width: _shapes.SELECTION_ANCHOR_SIZE / scaleWithMinCap,
|
|
177
|
+
height: _shapes.SELECTION_ANCHOR_SIZE / scaleWithMinCap
|
|
174
178
|
}, newPosition)) {
|
|
175
179
|
return {
|
|
176
180
|
mode: _Mode.SelectionModeLib.resize,
|
package/dist/utils/selection.js
CHANGED
|
@@ -47,9 +47,9 @@ var getNewSelectionData = function getNewSelectionData(hoverMode, selectedShape,
|
|
|
47
47
|
|
|
48
48
|
exports.getNewSelectionData = getNewSelectionData;
|
|
49
49
|
|
|
50
|
-
var selectShape = function selectShape(shapes, cursorPosition, canvasOffset, selectedShape) {
|
|
50
|
+
var selectShape = function selectShape(shapes, cursorPosition, currentScale, canvasOffset, selectedShape) {
|
|
51
51
|
if (selectedShape) {
|
|
52
|
-
var positionIntersection = (0, _intersect.checkPositionIntersection)(selectedShape, cursorPosition, canvasOffset, true) || {
|
|
52
|
+
var positionIntersection = (0, _intersect.checkPositionIntersection)(selectedShape, cursorPosition, canvasOffset, currentScale, true) || {
|
|
53
53
|
mode: _Mode.SelectionModeLib["default"]
|
|
54
54
|
};
|
|
55
55
|
var newSelectionMode = getNewSelectionData(positionIntersection, selectedShape, cursorPosition);
|
|
@@ -63,7 +63,7 @@ var selectShape = function selectShape(shapes, cursorPosition, canvasOffset, sel
|
|
|
63
63
|
}
|
|
64
64
|
|
|
65
65
|
var foundShape = _fp["default"].find(function (shape) {
|
|
66
|
-
return !!(0, _intersect.checkPositionIntersection)(shape, cursorPosition, canvasOffset, false);
|
|
66
|
+
return !!(0, _intersect.checkPositionIntersection)(shape, cursorPosition, canvasOffset, currentScale, false);
|
|
67
67
|
}, shapes);
|
|
68
68
|
|
|
69
69
|
if (!!foundShape) {
|
package/dist/utils/transform.js
CHANGED
|
@@ -5,7 +5,7 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", {
|
|
6
6
|
value: true
|
|
7
7
|
});
|
|
8
|
-
exports.updatePolygonLinesCount = exports.translateShape = exports.transformShape = exports.rotateShape = exports.resizeText = exports.resizeShape = exports.resizeRect = exports.resizePicture = exports.resizeLine = exports.resizeEllipse = exports.resizeCircle = exports.resizeBrush = exports.radiansToDegrees = exports.paintNewPointToShape = exports.getNormalizedSize = exports.degreesToRadians = exports.createNewPointGroupToShape = exports.calculateTextWidth = exports.calculateTextFontSize = void 0;
|
|
8
|
+
exports.updatePolygonLinesCount = exports.translateShape = exports.transformShape = exports.rotateShape = exports.resizeText = exports.resizeShape = exports.resizeRect = exports.resizePicture = exports.resizeLine = exports.resizeEllipse = exports.resizeCircle = exports.resizeBrush = exports.radiansToDegrees = exports.paintNewPointToShape = exports.getNormalizedSize = exports.fitContentInsideContainer = exports.degreesToRadians = exports.createNewPointGroupToShape = exports.calculateTextWidth = exports.calculateTextFontSize = void 0;
|
|
9
9
|
|
|
10
10
|
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
11
11
|
|
|
@@ -368,4 +368,20 @@ var radiansToDegrees = function radiansToDegrees(radians) {
|
|
|
368
368
|
return radians * 180 / Math.PI;
|
|
369
369
|
};
|
|
370
370
|
|
|
371
|
-
exports.radiansToDegrees = radiansToDegrees;
|
|
371
|
+
exports.radiansToDegrees = radiansToDegrees;
|
|
372
|
+
|
|
373
|
+
var fitContentInsideContainer = function fitContentInsideContainer(contentWidth, contentHeight, containerWidth, containerHeight) {
|
|
374
|
+
var shouldFillContainer = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : false;
|
|
375
|
+
var contentRatio = contentWidth / contentHeight;
|
|
376
|
+
var containerRatio = containerWidth / containerHeight;
|
|
377
|
+
|
|
378
|
+
if (contentRatio > containerRatio) {
|
|
379
|
+
var newWidth = shouldFillContainer ? containerWidth : Math.min(contentWidth, containerWidth);
|
|
380
|
+
return [newWidth, newWidth / contentRatio];
|
|
381
|
+
} else {
|
|
382
|
+
var newHeight = shouldFillContainer ? containerHeight : Math.min(contentHeight, containerHeight);
|
|
383
|
+
return [newHeight * contentRatio, newHeight];
|
|
384
|
+
}
|
|
385
|
+
};
|
|
386
|
+
|
|
387
|
+
exports.fitContentInsideContainer = fitContentInsideContainer;
|