@yorab/react-paint 0.2.2 → 0.4.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.
Files changed (79) hide show
  1. package/Changelog.md +44 -0
  2. package/LICENSE.txt +21 -0
  3. package/README.md +9 -90
  4. package/dist/components/App.js +233 -113
  5. package/dist/components/Canvas.js +45 -21
  6. package/dist/components/settings/ColorField.js +3 -7
  7. package/dist/components/settings/LayoutButton.js +3 -3
  8. package/dist/components/settings/Layouts.js +6 -19
  9. package/dist/components/settings/SettingsBar.js +3 -3
  10. package/dist/components/toolbox/EditTextBox.js +20 -13
  11. package/dist/components/toolbox/MenuGroup.js +48 -5
  12. package/dist/components/toolbox/PictureUrlInput.js +8 -7
  13. package/dist/components/toolbox/Toolbar.js +56 -33
  14. package/dist/components/toolbox/ToolbarGroup.js +3 -3
  15. package/dist/constants/shapes.js +7 -3
  16. package/dist/hooks/useDrawableCanvas.js +23 -20
  17. package/dist/hooks/useResizeObserver.js +40 -0
  18. package/dist/hooks/useShapes.js +14 -9
  19. package/dist/styles.css +32 -35
  20. package/dist/types/utils.js +5 -0
  21. package/dist/utils/data.js +71 -19
  22. package/dist/utils/draw.js +90 -51
  23. package/dist/utils/file.js +26 -60
  24. package/dist/utils/intersect.js +22 -18
  25. package/dist/utils/selection.js +6 -6
  26. package/dist/utils/shapeData.js +49 -54
  27. package/dist/utils/transform.js +48 -34
  28. package/package.json +6 -7
  29. package/dist/components/App.d.ts +0 -20
  30. package/dist/components/Canvas.d.ts +0 -28
  31. package/dist/components/common/Button.d.ts +0 -14
  32. package/dist/components/common/Loading.d.ts +0 -6
  33. package/dist/components/common/Modal.d.ts +0 -8
  34. package/dist/components/common/Panel.d.ts +0 -10
  35. package/dist/components/common/Snackbar.d.ts +0 -7
  36. package/dist/components/settings/ColorField.d.ts +0 -12
  37. package/dist/components/settings/DeleteButton.d.ts +0 -9
  38. package/dist/components/settings/FontFamilyField.d.ts +0 -10
  39. package/dist/components/settings/LayoutButton.d.ts +0 -8
  40. package/dist/components/settings/Layouts.d.ts +0 -18
  41. package/dist/components/settings/LineArrowField.d.ts +0 -10
  42. package/dist/components/settings/LineTypeField.d.ts +0 -14
  43. package/dist/components/settings/PointsNumberField.d.ts +0 -11
  44. package/dist/components/settings/RangeField.d.ts +0 -16
  45. package/dist/components/settings/SelectField.d.ts +0 -16
  46. package/dist/components/settings/SettingsBar.d.ts +0 -16
  47. package/dist/components/toolbox/EditTextBox.d.ts +0 -10
  48. package/dist/components/toolbox/LoadFileTool.d.ts +0 -11
  49. package/dist/components/toolbox/MenuGroup.d.ts +0 -23
  50. package/dist/components/toolbox/PictureUrlInput.d.ts +0 -7
  51. package/dist/components/toolbox/Tool.d.ts +0 -13
  52. package/dist/components/toolbox/Toolbar.d.ts +0 -20
  53. package/dist/components/toolbox/ToolbarGroup.d.ts +0 -18
  54. package/dist/constants/draw.d.ts +0 -2
  55. package/dist/constants/draw.js +0 -10
  56. package/dist/constants/icons.d.ts +0 -36
  57. package/dist/constants/shapes.d.ts +0 -5
  58. package/dist/constants/snackbar.d.ts +0 -11
  59. package/dist/constants/style.d.ts +0 -12
  60. package/dist/hooks/useComponent.d.ts +0 -9
  61. package/dist/hooks/useDrag.d.ts +0 -15
  62. package/dist/hooks/useDrawableCanvas.d.ts +0 -30
  63. package/dist/hooks/useKeyboard.d.ts +0 -15
  64. package/dist/hooks/useShapes.d.ts +0 -22
  65. package/dist/hooks/useSnackbar.d.ts +0 -16
  66. package/dist/schemas/drawableShape.json +0 -1021
  67. package/dist/types/Mode.d.ts +0 -51
  68. package/dist/types/Shapes.d.ts +0 -122
  69. package/dist/types/keyboard.d.ts +0 -15
  70. package/dist/utils/data.d.ts +0 -4
  71. package/dist/utils/draw.d.ts +0 -18
  72. package/dist/utils/file.d.ts +0 -33
  73. package/dist/utils/intersect.d.ts +0 -8
  74. package/dist/utils/selection.d.ts +0 -7
  75. package/dist/utils/shapeData.d.ts +0 -5
  76. package/dist/utils/string.d.ts +0 -3
  77. package/dist/utils/style.d.ts +0 -2
  78. package/dist/utils/toolbar.d.ts +0 -12
  79. package/dist/utils/transform.d.ts +0 -271
@@ -29,12 +29,13 @@ 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, selectionPadding) {
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) {
37
- var _getShapeInfos = (0, _shapeData.getShapeInfos)(marker),
38
+ var _getShapeInfos = (0, _shapeData.getShapeInfos)(marker, selectionPadding),
38
39
  center = _getShapeInfos.center;
39
40
 
40
41
  ctx.translate(center[0], center[1]);
@@ -48,19 +49,17 @@ var restoreShapeTransformations = function restoreShapeTransformations(ctx) {
48
49
  };
49
50
 
50
51
  var updateDrawStyle = function updateDrawStyle(ctx) {
51
- var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {
52
- fillColor: 'transparent',
53
- strokeColor: 'blue',
54
- globalAlpha: 100,
55
- lineWidth: 1,
56
- lineDash: 0
57
- },
58
- fillColor = _ref.fillColor,
59
- globalAlpha = _ref.globalAlpha,
60
- strokeColor = _ref.strokeColor,
61
- lineWidth = _ref.lineWidth,
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 ? _shapes.SELECTION_DEFAULT_COLOR : _style$strokeColor,
59
+ _style$lineWidth = style.lineWidth,
60
+ lineWidth = _style$lineWidth === void 0 ? _shapes.SELECTION_DEFAULT_WIDTH : _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, selectionPadding) {
254
253
  if (shape.visible === false) return;
255
- applyShapeTransformations(ctx, shape, canvasOffset);
254
+ applyShapeTransformations(ctx, shape, responsiveScale, canvasOffset, selectionPadding);
256
255
 
257
256
  switch (shape.type) {
258
257
  case 'brush':
@@ -298,18 +297,34 @@ var drawShape = function drawShape(ctx, shape, canvasOffset) {
298
297
 
299
298
  exports.drawShape = drawShape;
300
299
 
301
- var drawSelectionDefault = function drawSelectionDefault(_ref2) {
302
- var ctx = _ref2.ctx,
303
- shape = _ref2.shape,
304
- withAnchors = _ref2.withAnchors;
305
-
306
- var _getShapeInfos2 = (0, _shapeData.getShapeInfos)(shape),
300
+ var drawSelectionDefault = function drawSelectionDefault(_ref) {
301
+ var ctx = _ref.ctx,
302
+ shape = _ref.shape,
303
+ withAnchors = _ref.withAnchors,
304
+ selectionPadding = _ref.selectionPadding,
305
+ selectionWidth = _ref.selectionWidth,
306
+ selectionColor = _ref.selectionColor,
307
+ _ref$currentScale = _ref.currentScale,
308
+ currentScale = _ref$currentScale === void 0 ? 1 : _ref$currentScale;
309
+
310
+ var _getShapeInfos2 = (0, _shapeData.getShapeInfos)(shape, selectionPadding / currentScale),
307
311
  borders = _getShapeInfos2.borders;
308
312
 
309
- drawRect(ctx, borders);
313
+ drawRect(ctx, _objectSpread(_objectSpread({}, borders), {}, {
314
+ style: {
315
+ fillColor: 'transparent',
316
+ strokeColor: selectionColor,
317
+ lineWidth: selectionWidth / currentScale
318
+ }
319
+ }));
310
320
  if (!withAnchors || shape.locked) return;
311
321
  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]]
322
+ 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 / currentScale]],
323
+ style: {
324
+ fillColor: 'transparent',
325
+ strokeColor: selectionColor,
326
+ lineWidth: selectionWidth / currentScale
327
+ }
313
328
  });
314
329
 
315
330
  var _iterator = _createForOfIteratorHelper(_shapes.SELECTION_RESIZE_ANCHOR_POSITIONS),
@@ -321,11 +336,11 @@ var drawSelectionDefault = function drawSelectionDefault(_ref2) {
321
336
  drawCircle(ctx, {
322
337
  x: borders.x + borders.width * anchorPosition[0],
323
338
  y: borders.y + borders.height * anchorPosition[1],
324
- radius: _shapes.SELECTION_ANCHOR_SIZE / 2,
339
+ radius: _shapes.SELECTION_ANCHOR_SIZE / 2 / currentScale,
325
340
  style: {
326
341
  fillColor: 'rgb(255,255,255)',
327
342
  strokeColor: 'rgb(150,150,150)',
328
- lineWidth: 2
343
+ lineWidth: selectionWidth / currentScale
329
344
  }
330
345
  });
331
346
  }
@@ -337,25 +352,36 @@ var drawSelectionDefault = function drawSelectionDefault(_ref2) {
337
352
 
338
353
  drawCircle(ctx, {
339
354
  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,
355
+ y: borders.y - _shapes.SELECTION_ANCHOR_SIZE / 2 - _shapes.SELECTION_ROTATED_ANCHOR_POSITION / currentScale,
356
+ radius: _shapes.SELECTION_ANCHOR_SIZE / 2 / currentScale,
342
357
  style: {
343
358
  fillColor: 'rgb(255,255,255)',
344
359
  strokeColor: 'rgb(150,150,150)',
345
- lineWidth: 2
360
+ lineWidth: selectionWidth / currentScale
346
361
  }
347
362
  });
348
363
  };
349
364
 
350
- var drawLineSelection = function drawLineSelection(_ref3) {
351
- var ctx = _ref3.ctx,
352
- shape = _ref3.shape,
353
- withAnchors = _ref3.withAnchors;
354
-
355
- var _getShapeInfos3 = (0, _shapeData.getShapeInfos)(shape),
365
+ var drawLineSelection = function drawLineSelection(_ref2) {
366
+ var ctx = _ref2.ctx,
367
+ shape = _ref2.shape,
368
+ withAnchors = _ref2.withAnchors,
369
+ selectionPadding = _ref2.selectionPadding,
370
+ selectionWidth = _ref2.selectionWidth,
371
+ selectionColor = _ref2.selectionColor,
372
+ _ref2$currentScale = _ref2.currentScale,
373
+ currentScale = _ref2$currentScale === void 0 ? 1 : _ref2$currentScale;
374
+
375
+ var _getShapeInfos3 = (0, _shapeData.getShapeInfos)(shape, selectionPadding),
356
376
  borders = _getShapeInfos3.borders;
357
377
 
358
- drawRect(ctx, borders);
378
+ drawRect(ctx, _objectSpread(_objectSpread({}, borders), {}, {
379
+ style: {
380
+ fillColor: 'transparent',
381
+ strokeColor: selectionColor,
382
+ lineWidth: selectionWidth / currentScale
383
+ }
384
+ }));
359
385
  if (!withAnchors || shape.locked) return;
360
386
 
361
387
  for (var i = 0; i < shape.points.length; i++) {
@@ -365,36 +391,41 @@ var drawLineSelection = function drawLineSelection(_ref3) {
365
391
  drawRect(ctx, {
366
392
  x: coordinate[0] - _shapes.SELECTION_ANCHOR_SIZE / 2,
367
393
  y: coordinate[1] - _shapes.SELECTION_ANCHOR_SIZE / 2,
368
- width: _shapes.SELECTION_ANCHOR_SIZE,
369
- height: _shapes.SELECTION_ANCHOR_SIZE,
394
+ width: _shapes.SELECTION_ANCHOR_SIZE / currentScale,
395
+ height: _shapes.SELECTION_ANCHOR_SIZE / currentScale,
370
396
  style: {
371
397
  fillColor: 'rgb(255,255,255)',
372
398
  strokeColor: 'rgb(150,150,150)',
373
- lineWidth: 2
399
+ lineWidth: selectionWidth / currentScale
374
400
  }
375
401
  });
376
402
  } else {
377
403
  drawCircle(ctx, {
378
404
  x: coordinate[0],
379
405
  y: coordinate[1],
380
- radius: _shapes.SELECTION_ANCHOR_SIZE / 2,
406
+ radius: _shapes.SELECTION_ANCHOR_SIZE / 2 / currentScale,
381
407
  style: {
382
408
  fillColor: 'rgb(255,255,255)',
383
409
  strokeColor: 'rgb(150,150,150)',
384
- lineWidth: 2
410
+ lineWidth: selectionWidth / currentScale
385
411
  }
386
412
  });
387
413
  }
388
414
  }
389
415
  };
390
416
 
391
- var drawSelection = function drawSelection(_ref4) {
392
- var ctx = _ref4.ctx,
393
- shape = _ref4.shape,
394
- canvasOffset = _ref4.canvasOffset,
395
- _ref4$withAnchors = _ref4.withAnchors,
396
- withAnchors = _ref4$withAnchors === void 0 ? true : _ref4$withAnchors;
397
- applyShapeTransformations(ctx, shape, canvasOffset);
417
+ var drawSelection = function drawSelection(_ref3) {
418
+ var ctx = _ref3.ctx,
419
+ shape = _ref3.shape,
420
+ _ref3$scaleRatio = _ref3.scaleRatio,
421
+ scaleRatio = _ref3$scaleRatio === void 0 ? 1 : _ref3$scaleRatio,
422
+ canvasOffset = _ref3.canvasOffset,
423
+ selectionPadding = _ref3.selectionPadding,
424
+ selectionWidth = _ref3.selectionWidth,
425
+ selectionColor = _ref3.selectionColor,
426
+ _ref3$withAnchors = _ref3.withAnchors,
427
+ withAnchors = _ref3$withAnchors === void 0 ? true : _ref3$withAnchors;
428
+ applyShapeTransformations(ctx, shape, scaleRatio, canvasOffset, selectionPadding);
398
429
 
399
430
  switch (shape.type) {
400
431
  case 'polygon':
@@ -403,7 +434,11 @@ var drawSelection = function drawSelection(_ref4) {
403
434
  drawLineSelection({
404
435
  ctx: ctx,
405
436
  shape: shape,
406
- withAnchors: withAnchors
437
+ withAnchors: withAnchors,
438
+ selectionPadding: selectionPadding,
439
+ selectionWidth: selectionWidth,
440
+ selectionColor: selectionColor,
441
+ currentScale: scaleRatio
407
442
  });
408
443
  break;
409
444
 
@@ -411,7 +446,11 @@ var drawSelection = function drawSelection(_ref4) {
411
446
  drawSelectionDefault({
412
447
  ctx: ctx,
413
448
  shape: shape,
414
- withAnchors: withAnchors
449
+ withAnchors: withAnchors,
450
+ selectionPadding: selectionPadding,
451
+ selectionWidth: selectionWidth,
452
+ selectionColor: selectionColor,
453
+ currentScale: scaleRatio
415
454
  });
416
455
  break;
417
456
  }
@@ -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.validateJson = exports.getCanvasImage = exports.fetchAndStringify = exports.encodeShapesInString = exports.encodePicturesInShapes = exports.downloadFile = exports.decodePicturesInShapes = exports.decodeJson = void 0;
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 _ajv = _interopRequireDefault(require("ajv"));
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
- function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; }
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
- function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
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(canvas) {
71
- return canvas.toDataURL('image/png');
72
- };
73
-
74
- exports.getCanvasImage = getCanvasImage;
66
+ var getCanvasImage = function getCanvasImage(shapes, canvasOffset, width, height, selectionPadding) {
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 encodePicturesInShapes = function encodePicturesInShapes(shapes) {
77
- return shapes.map(function (shape) {
78
- if (shape.type === _Shapes.ShapeEnum.picture) {
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, selectionPadding);
76
+ }
88
77
 
89
- return shape;
90
- });
78
+ return newCanvas.toDataURL('image/png');
91
79
  };
92
80
 
93
- exports.encodePicturesInShapes = encodePicturesInShapes;
81
+ exports.getCanvasImage = getCanvasImage;
94
82
 
95
83
  var encodeShapesInString = function encodeShapesInString(shapes) {
96
- var shapesWithStringifyPictures = encodePicturesInShapes(shapes);
97
- return encodeObjectToString(shapesWithStringifyPictures);
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 = shapesForJson.map(function (shape) {
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;
@@ -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,15 +40,15 @@ 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;
45
47
 
46
- var getSettingsPosition = function getSettingsPosition(shape, canvas, givenWidth, givenHeight) {
48
+ var getSettingsPosition = function getSettingsPosition(shape, canvas, givenWidth, givenHeight, selectionPadding) {
47
49
  var _canvas$getBoundingCl2;
48
50
 
49
- var shapeInfos = (0, _shapeData.getShapeInfos)(shape);
51
+ var shapeInfos = (0, _shapeData.getShapeInfos)(shape, selectionPadding);
50
52
  var positionInCanvas = getPointPositionBeforeCanvasTransformation(shapeInfos.center, [-shape.translation[0], -shape.translation[1]], shape.rotation, shapeInfos.center);
51
53
  var canvasBoundingRect = (_canvas$getBoundingCl2 = canvas === null || canvas === void 0 ? void 0 : canvas.getBoundingClientRect()) !== null && _canvas$getBoundingCl2 !== void 0 ? _canvas$getBoundingCl2 : {
52
54
  left: 0,
@@ -123,10 +125,12 @@ var applyRotationToVector = function applyRotationToVector(vector, shapeRotation
123
125
 
124
126
  exports.applyRotationToVector = applyRotationToVector;
125
127
 
126
- var checkPositionIntersection = function checkPositionIntersection(shape, position, canvasOffset) {
127
- var checkAnchors = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
128
+ var checkPositionIntersection = function checkPositionIntersection(shape, position, canvasOffset, selectionPadding) {
129
+ var currentScale = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : 1;
130
+ var checkAnchors = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : false;
131
+ var scaleWithMinCap = Math.min(1, currentScale);
128
132
 
129
- var _getShapeInfos = (0, _shapeData.getShapeInfos)(shape),
133
+ var _getShapeInfos = (0, _shapeData.getShapeInfos)(shape, selectionPadding),
130
134
  borders = _getShapeInfos.borders,
131
135
  center = _getShapeInfos.center;
132
136
 
@@ -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,
@@ -15,7 +15,7 @@ var _intersect = require("./intersect");
15
15
 
16
16
  var _shapeData = require("./shapeData");
17
17
 
18
- var getNewSelectionData = function getNewSelectionData(hoverMode, selectedShape, cursorPosition) {
18
+ var getNewSelectionData = function getNewSelectionData(hoverMode, selectedShape, cursorPosition, selectionPadding) {
19
19
  if (hoverMode.mode === 'translate') {
20
20
  return {
21
21
  mode: _Mode.SelectionModeLib.translate,
@@ -23,7 +23,7 @@ var getNewSelectionData = function getNewSelectionData(hoverMode, selectedShape,
23
23
  originalShape: selectedShape
24
24
  };
25
25
  } else if (hoverMode.mode === 'rotate') {
26
- var _getShapeInfos = (0, _shapeData.getShapeInfos)(selectedShape),
26
+ var _getShapeInfos = (0, _shapeData.getShapeInfos)(selectedShape, selectionPadding),
27
27
  centerBeforeResize = _getShapeInfos.center;
28
28
 
29
29
  var center = [centerBeforeResize[0], centerBeforeResize[1]];
@@ -47,12 +47,12 @@ 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, selectionPadding) {
51
51
  if (selectedShape) {
52
- var positionIntersection = (0, _intersect.checkPositionIntersection)(selectedShape, cursorPosition, canvasOffset, true) || {
52
+ var positionIntersection = (0, _intersect.checkPositionIntersection)(selectedShape, cursorPosition, canvasOffset, selectionPadding, currentScale, true) || {
53
53
  mode: _Mode.SelectionModeLib["default"]
54
54
  };
55
- var newSelectionMode = getNewSelectionData(positionIntersection, selectedShape, cursorPosition);
55
+ var newSelectionMode = getNewSelectionData(positionIntersection, selectedShape, cursorPosition, selectionPadding);
56
56
 
57
57
  if (newSelectionMode) {
58
58
  return {
@@ -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, selectionPadding, currentScale, false);
67
67
  }, shapes);
68
68
 
69
69
  if (!!foundShape) {