@yorab/react-paint 0.4.2 → 0.6.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/Changelog.md +25 -0
- package/README.md +0 -6
- package/dist/components/App.js +52 -43
- package/dist/components/Canvas.js +6 -6
- package/dist/components/settings/ColorField.js +5 -5
- package/dist/components/settings/FontFamilyField.js +6 -4
- package/dist/components/settings/Layouts.js +17 -8
- package/dist/components/settings/LineArrowField.js +6 -4
- package/dist/components/settings/LineTypeField.js +6 -4
- package/dist/components/settings/PointsNumberField.js +20 -30
- package/dist/components/settings/RangeField.js +1 -0
- package/dist/components/settings/SelectField.js +1 -0
- package/dist/components/settings/SettingsBar.js +141 -88
- package/dist/components/settings/ToggleField.js +56 -0
- package/dist/components/toolbox/EditTextBox.js +17 -10
- package/dist/components/toolbox/LoadFileTool.js +5 -3
- package/dist/components/toolbox/MenuGroup.js +37 -44
- package/dist/components/toolbox/Tool.js +4 -4
- package/dist/components/toolbox/Toolbar.js +81 -69
- package/dist/components/toolbox/ToolbarGroup.js +29 -31
- package/dist/constants/icons.js +6 -2
- package/dist/constants/style.js +3 -1
- package/dist/constants/tools.js +428 -0
- package/dist/hooks/useDoubleClick.js +46 -0
- package/dist/hooks/useDrawableCanvas.js +42 -53
- package/dist/styles.css +10 -10
- package/dist/types/Shapes.js +2 -16
- package/dist/types/tools.js +22 -0
- package/dist/utils/data.js +106 -28
- package/dist/utils/draw.js +3 -3
- package/dist/utils/file.js +15 -14
- package/dist/utils/selection.js +1 -1
- package/dist/utils/style.js +4 -2
- package/dist/utils/toolbar.js +66 -11
- package/dist/utils/transform.js +24 -11
- package/package.json +1 -1
package/dist/utils/transform.js
CHANGED
|
@@ -135,7 +135,13 @@ var updatePolygonLinesCount = function updatePolygonLinesCount(shape, newPointsC
|
|
|
135
135
|
if (currentPointsCount === newPointsCount) return shape;
|
|
136
136
|
|
|
137
137
|
if (currentPointsCount > newPointsCount) {
|
|
138
|
-
|
|
138
|
+
var totalPoints = shape.points.slice(0, newPointsCount);
|
|
139
|
+
return _objectSpread(_objectSpread({}, shape), {}, {
|
|
140
|
+
points: totalPoints,
|
|
141
|
+
style: _objectSpread(_objectSpread({}, shape.style), {}, {
|
|
142
|
+
pointsCount: totalPoints.length
|
|
143
|
+
})
|
|
144
|
+
});
|
|
139
145
|
} else {
|
|
140
146
|
//TODO : better distribution for new points
|
|
141
147
|
var nbPointsToAdd = newPointsCount - currentPointsCount;
|
|
@@ -144,7 +150,14 @@ var updatePolygonLinesCount = function updatePolygonLinesCount(shape, newPointsC
|
|
|
144
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)];
|
|
145
151
|
}))(nbPointsToAdd);
|
|
146
152
|
|
|
147
|
-
|
|
153
|
+
var _totalPoints = [shape.points[0]].concat((0, _toConsumableArray2["default"])(newPoints), (0, _toConsumableArray2["default"])(shape.points.slice(1, shape.points.length)));
|
|
154
|
+
|
|
155
|
+
return _objectSpread(_objectSpread({}, shape), {}, {
|
|
156
|
+
points: _totalPoints,
|
|
157
|
+
style: _objectSpread(_objectSpread({}, shape.style), {}, {
|
|
158
|
+
pointsCount: _totalPoints.length
|
|
159
|
+
})
|
|
160
|
+
});
|
|
148
161
|
}
|
|
149
162
|
};
|
|
150
163
|
|
|
@@ -260,11 +273,11 @@ var resizeRect = function resizeRect(cursorPosition, canvasOffset, originalShape
|
|
|
260
273
|
exports.resizeRect = resizeRect;
|
|
261
274
|
|
|
262
275
|
var resizeText = function resizeText(ctx, cursorPosition, canvasOffset, originalShape, selectionMode, selectionPadding) {
|
|
263
|
-
var _newRect$style;
|
|
276
|
+
var _newRect$style$fontBo, _newRect$style, _newRect$style$fontIt, _newRect$style2, _newRect$style3;
|
|
264
277
|
|
|
265
278
|
var newRect = resizeRect(cursorPosition, canvasOffset, originalShape, selectionMode, selectionPadding, true);
|
|
266
279
|
return _objectSpread(_objectSpread({}, newRect), {}, {
|
|
267
|
-
fontSize: calculateTextFontSize(ctx, newRect.value, newRect.width, (_newRect$style = newRect.style) === null || _newRect$style === void 0 ? void 0 : _newRect$style.fontFamily)
|
|
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)
|
|
268
281
|
});
|
|
269
282
|
};
|
|
270
283
|
|
|
@@ -332,23 +345,23 @@ var transformShape = function transformShape(ctx, shape, cursorPosition, canvasO
|
|
|
332
345
|
|
|
333
346
|
exports.transformShape = transformShape;
|
|
334
347
|
|
|
335
|
-
var calculateTextFontSize = function calculateTextFontSize(ctx, text, maxWidth) {
|
|
348
|
+
var calculateTextFontSize = function calculateTextFontSize(ctx, text, maxWidth, fontBold, fontItalic) {
|
|
336
349
|
var _$flow;
|
|
337
350
|
|
|
338
|
-
var fontFamily = arguments.length >
|
|
339
|
-
ctx.font = "1px ".concat(fontFamily);
|
|
351
|
+
var fontFamily = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : _style.STYLE_FONT_DEFAULT;
|
|
352
|
+
ctx.font = "".concat(fontItalic ? 'italic' : '', " ").concat(fontBold ? 'bold' : '', " 1px ").concat(fontFamily);
|
|
340
353
|
return (_$flow = _fp["default"].flow(_fp["default"].map(function (value) {
|
|
341
354
|
return maxWidth / ctx.measureText(value).width;
|
|
342
|
-
}), _fp["default"].min)(text)) !== null && _$flow !== void 0 ? _$flow :
|
|
355
|
+
}), _fp["default"].min)(text)) !== null && _$flow !== void 0 ? _$flow : _style.STYLE_FONT_SIZE_DEFAULT;
|
|
343
356
|
};
|
|
344
357
|
|
|
345
358
|
exports.calculateTextFontSize = calculateTextFontSize;
|
|
346
359
|
|
|
347
|
-
var calculateTextWidth = function calculateTextWidth(ctx, text, fontSize) {
|
|
360
|
+
var calculateTextWidth = function calculateTextWidth(ctx, text, fontSize, fontBold, fontItalic) {
|
|
348
361
|
var _$flow2;
|
|
349
362
|
|
|
350
|
-
var fontFamily = arguments.length >
|
|
351
|
-
ctx.font = "".concat(fontSize, "px ").concat(fontFamily);
|
|
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);
|
|
352
365
|
return (_$flow2 = _fp["default"].flow(_fp["default"].map(function (value) {
|
|
353
366
|
return ctx.measureText(value).width;
|
|
354
367
|
}), _fp["default"].max)(text)) !== null && _$flow2 !== void 0 ? _$flow2 : 20;
|