@yorab/react-paint 0.5.0 → 0.6.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 +96 -0
- package/README.md +0 -7
- package/dist/components/App.js +69 -49
- package/dist/components/Canvas.js +7 -7
- package/dist/components/common/Button.js +4 -4
- package/dist/components/common/Loading.js +3 -3
- package/dist/components/common/Modal.js +3 -3
- package/dist/components/common/Panel.js +2 -2
- package/dist/components/common/Snackbar.js +2 -2
- package/dist/components/settings/ColorField.js +4 -4
- package/dist/components/settings/FontFamilyField.js +3 -3
- package/dist/components/settings/LayoutButton.js +1 -1
- package/dist/components/settings/Layouts.js +18 -9
- package/dist/components/settings/LineArrowField.js +4 -4
- package/dist/components/settings/LineTypeField.js +3 -3
- package/dist/components/settings/PointsNumberField.js +1 -1
- package/dist/components/settings/RangeField.js +1 -1
- package/dist/components/settings/SelectField.js +1 -1
- package/dist/components/settings/SettingsBar.js +105 -79
- package/dist/components/settings/ToggleField.js +56 -0
- package/dist/components/toolbox/EditTextBox.js +23 -16
- package/dist/components/toolbox/MenuGroup.js +10 -8
- package/dist/components/toolbox/PictureUrlInput.js +1 -1
- package/dist/components/toolbox/Toolbar.js +12 -4
- package/dist/components/toolbox/ToolbarGroup.js +13 -11
- package/dist/constants/icons.js +6 -2
- package/dist/constants/tools.js +8 -0
- package/dist/hooks/useDoubleClick.js +46 -0
- package/dist/hooks/useDrawableCanvas.js +29 -45
- package/dist/styles.css +52 -51
- package/dist/utils/data.js +27 -5
- package/dist/utils/draw.js +3 -3
- package/dist/utils/file.js +15 -14
- package/dist/utils/selection.js +1 -1
- package/dist/utils/transform.js +23 -10
- package/package.json +1 -1
package/dist/utils/file.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.getCanvasImage = exports.getBase64Image = exports.fetchAndStringify = exports.encodeShapesInString = exports.downloadFile = exports.
|
|
8
|
+
exports.getCanvasImage = exports.getBase64Image = exports.fetchAndStringify = exports.encodeShapesInString = exports.downloadFile = exports.decodeJson = exports.decodeImportedData = void 0;
|
|
9
9
|
|
|
10
10
|
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
|
|
11
11
|
|
|
@@ -80,9 +80,9 @@ var getCanvasImage = function getCanvasImage(shapes, canvasOffset, width, height
|
|
|
80
80
|
|
|
81
81
|
exports.getCanvasImage = getCanvasImage;
|
|
82
82
|
|
|
83
|
-
var encodeShapesInString = function encodeShapesInString(shapes) {
|
|
84
|
-
var
|
|
85
|
-
return encodeObjectToString(
|
|
83
|
+
var encodeShapesInString = function encodeShapesInString(shapes, width, height) {
|
|
84
|
+
var dataToExport = (0, _data.buildDataToExport)(shapes, width, height);
|
|
85
|
+
return encodeObjectToString(dataToExport);
|
|
86
86
|
};
|
|
87
87
|
|
|
88
88
|
exports.encodeShapesInString = encodeShapesInString;
|
|
@@ -123,14 +123,15 @@ var decodeJson = /*#__PURE__*/function () {
|
|
|
123
123
|
|
|
124
124
|
exports.decodeJson = decodeJson;
|
|
125
125
|
|
|
126
|
-
var
|
|
126
|
+
var decodeImportedData = /*#__PURE__*/function () {
|
|
127
127
|
var _ref2 = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee2(shapesForJson) {
|
|
128
|
-
var promisesArray, shapes;
|
|
128
|
+
var promisesArray, jsonShapes, shapes;
|
|
129
129
|
return _regenerator["default"].wrap(function _callee2$(_context2) {
|
|
130
130
|
while (1) {
|
|
131
131
|
switch (_context2.prev = _context2.next) {
|
|
132
132
|
case 0:
|
|
133
133
|
promisesArray = [];
|
|
134
|
+
jsonShapes = shapesForJson.shapes;
|
|
134
135
|
shapes = _fp["default"].flow(_fp["default"].map(function (shape) {
|
|
135
136
|
if (!_fp["default"].includes(shape.type, _Shapes.ShapeEnum)) return null;
|
|
136
137
|
|
|
@@ -157,20 +158,20 @@ var decodePicturesInShapes = /*#__PURE__*/function () {
|
|
|
157
158
|
img.src = shape.src;
|
|
158
159
|
}
|
|
159
160
|
|
|
160
|
-
return _objectSpread(_objectSpread({}, shape), {}, {
|
|
161
|
+
return (0, _data.addDefaultAndTempShapeProps)(_objectSpread(_objectSpread({}, shape), {}, {
|
|
161
162
|
img: img
|
|
162
|
-
});
|
|
163
|
+
}));
|
|
163
164
|
}
|
|
164
165
|
|
|
165
166
|
return (0, _data.addDefaultAndTempShapeProps)(shape);
|
|
166
|
-
}), _fp["default"].compact)(
|
|
167
|
-
_context2.next =
|
|
167
|
+
}), _fp["default"].compact)(jsonShapes);
|
|
168
|
+
_context2.next = 5;
|
|
168
169
|
return Promise.all(promisesArray);
|
|
169
170
|
|
|
170
|
-
case
|
|
171
|
+
case 5:
|
|
171
172
|
return _context2.abrupt("return", shapes);
|
|
172
173
|
|
|
173
|
-
case
|
|
174
|
+
case 6:
|
|
174
175
|
case "end":
|
|
175
176
|
return _context2.stop();
|
|
176
177
|
}
|
|
@@ -178,9 +179,9 @@ var decodePicturesInShapes = /*#__PURE__*/function () {
|
|
|
178
179
|
}, _callee2);
|
|
179
180
|
}));
|
|
180
181
|
|
|
181
|
-
return function
|
|
182
|
+
return function decodeImportedData(_x2) {
|
|
182
183
|
return _ref2.apply(this, arguments);
|
|
183
184
|
};
|
|
184
185
|
}();
|
|
185
186
|
|
|
186
|
-
exports.
|
|
187
|
+
exports.decodeImportedData = decodeImportedData;
|
package/dist/utils/selection.js
CHANGED
|
@@ -54,7 +54,7 @@ var selectShape = function selectShape(shapes, cursorPosition, currentScale, can
|
|
|
54
54
|
};
|
|
55
55
|
var newSelectionMode = getNewSelectionData(positionIntersection, selectedShape, cursorPosition, selectionPadding);
|
|
56
56
|
|
|
57
|
-
if (newSelectionMode) {
|
|
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 {
|
|
59
59
|
shape: selectedShape,
|
|
60
60
|
mode: newSelectionMode
|
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,11 +345,11 @@ 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
355
|
}), _fp["default"].min)(text)) !== null && _$flow !== void 0 ? _$flow : _style.STYLE_FONT_SIZE_DEFAULT;
|
|
@@ -344,11 +357,11 @@ var calculateTextFontSize = function calculateTextFontSize(ctx, text, maxWidth)
|
|
|
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;
|