redhotmagma-graphics-editor 1.41.1 → 1.42.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.
Files changed (82) hide show
  1. package/App.js +90 -165
  2. package/CanvasAdapters/Mock/Canvas.js +71 -125
  3. package/CanvasAdapters/Mock/Objects/CanvasObject.js +23 -40
  4. package/CanvasAdapters/Mock/Objects/Group.js +15 -46
  5. package/CanvasAdapters/Mock/Objects/Image.js +15 -46
  6. package/CanvasAdapters/Mock/Objects/Text.js +15 -51
  7. package/CanvasAdapters/Mock/index.js +0 -1
  8. package/CanvasAdapters/PaperJs/Canvas.js +268 -398
  9. package/CanvasAdapters/PaperJs/CanvasRepository.js +6 -23
  10. package/CanvasAdapters/PaperJs/Modifiers/FontSizeMin.js +2 -5
  11. package/CanvasAdapters/PaperJs/Objects/CanvasObject.js +33 -65
  12. package/CanvasAdapters/PaperJs/Objects/Group.js +14 -48
  13. package/CanvasAdapters/PaperJs/Objects/Image.js +58 -114
  14. package/CanvasAdapters/PaperJs/Objects/Text.js +43 -99
  15. package/CanvasAdapters/PaperJs/Utils/HTML2Paper.js +57 -108
  16. package/CanvasAdapters/PaperJs/Utils/SVGfix.js +9 -30
  17. package/CanvasAdapters/PaperJs/Utils/StyleParams.js +10 -21
  18. package/CanvasAdapters/PaperJs/Utils/TextToSVGRepository.js +53 -86
  19. package/CanvasAdapters/PaperJs/Utils/TextToSVGUtils.js +4 -14
  20. package/CanvasAdapters/PaperJs/Utils/UTF8Base64.js +3 -24
  21. package/CanvasAdapters/PaperJs/Utils/UseColorLayer.js +58 -0
  22. package/CanvasAdapters/PaperJs/Utils/UseMask.js +183 -279
  23. package/CanvasAdapters/PaperJs/Utils/__tests__/SVGfix.test.js +0 -1
  24. package/CanvasAdapters/PaperJs/Utils/__tests__/TextToSVGUtils.test.js +0 -1
  25. package/CanvasAdapters/PaperJs/Utils/__tests__/updateFontStyle.test.js +0 -1
  26. package/CanvasAdapters/PaperJs/Utils/updateFontStyle.js +5 -11
  27. package/CanvasAdapters/PaperJs/index.js +0 -1
  28. package/CanvasInterface/Canvas.js +145 -235
  29. package/CanvasInterface/CanvasProvider.js +25 -75
  30. package/CanvasInterface/Objects/CanvasObject.js +68 -148
  31. package/CanvasInterface/Objects/index.js +0 -1
  32. package/CanvasInterface/Observable.js +10 -29
  33. package/CanvasInterface/canvasConnect.js +12 -44
  34. package/CanvasInterface/index.js +1 -7
  35. package/Components/Canvas/Canvas.js +14 -41
  36. package/Components/Canvas/CanvasContainer.js +5 -18
  37. package/Components/Canvas/styles.js +2 -3
  38. package/Components/DelayedContainer.js +14 -39
  39. package/Components/Editor/Editor.js +47 -102
  40. package/Components/Editor/EditorContainer.js +47 -131
  41. package/Components/Editor/styles.js +2 -3
  42. package/Components/InlineToolbox/InlineToolbox.js +49 -142
  43. package/Components/InlineToolbox/InlineToolboxButton.js +9 -19
  44. package/Components/InlineToolbox/styles.js +2 -3
  45. package/Components/ManipulableContainer.js +15 -41
  46. package/Components/ResizeDetect/ResizeDetect.js +14 -47
  47. package/Components/Rulers/Ruler.js +20 -68
  48. package/Components/Rulers/Rulers.js +14 -46
  49. package/Components/Rulers/styles.js +2 -3
  50. package/Components/SelectionToolbox/ColorPalette.js +25 -73
  51. package/Components/SelectionToolbox/SelectionToolbox.js +39 -101
  52. package/Components/SelectionToolbox/TextTools.js +81 -157
  53. package/Components/SelectionToolbox/styles.js +2 -3
  54. package/Components/StandardToolbox/StandardToolbox.js +81 -144
  55. package/Components/TextEditor/TextEditor.js +67 -182
  56. package/Components/TextEditor/TextEditorStateProvider.js +20 -56
  57. package/Components/Toolbox/ToolboxContainer.js +5 -18
  58. package/Components/Toolbox/ToolboxRow.js +4 -16
  59. package/Components/Toolbox/styles.js +2 -3
  60. package/Utils/Calc2D.js +3 -9
  61. package/Utils/DOM.js +22 -80
  62. package/Utils/Device.js +2 -6
  63. package/Utils/Image.js +17 -11
  64. package/Utils/Logger.js +8 -32
  65. package/Utils/Range.js +6 -33
  66. package/Utils/String.js +2 -8
  67. package/Utils/UnitConversion.js +3 -9
  68. package/Utils/__tests__/Calc2D.test.js +1 -3
  69. package/Utils/__tests__/DOM.test.js +17 -25
  70. package/Utils/__tests__/Range.test.js +0 -1
  71. package/_demos/UsingExternalControls/App.js +13 -48
  72. package/_demos/UsingRenderProps/App.js +15 -54
  73. package/index.js +2 -6
  74. package/package.json +5 -7
  75. package/src/App.js +35 -38
  76. package/src/CanvasAdapters/PaperJs/Canvas.ts +11 -0
  77. package/src/CanvasAdapters/PaperJs/Utils/UseColorLayer.js +56 -0
  78. package/src/Components/InlineToolbox/InlineToolbox.js +2 -2
  79. package/src/Components/SelectionToolbox/TextTools.js +1 -1
  80. package/src/_demos/UsingExternalControls/App.js +25 -28
  81. package/src/_demos/UsingRenderProps/App.js +16 -19
  82. package/src/index.js +2 -2
@@ -3,93 +3,61 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.AbstractCanvasObject = exports.CanvasObjectEvents = void 0;
7
-
6
+ exports.CanvasObjectEvents = exports.AbstractCanvasObject = void 0;
8
7
  var _Observable = require("../Observable");
9
-
10
8
  var _Calc2D = require("../../Utils/Calc2D");
11
-
12
9
  var _v = _interopRequireDefault(require("uuid/v4"));
13
-
14
10
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
15
-
16
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
17
-
18
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
19
-
11
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
12
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
13
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
14
+ function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return e; }; var t, e = {}, r = Object.prototype, n = r.hasOwnProperty, o = Object.defineProperty || function (t, e, r) { t[e] = r.value; }, i = "function" == typeof Symbol ? Symbol : {}, a = i.iterator || "@@iterator", c = i.asyncIterator || "@@asyncIterator", u = i.toStringTag || "@@toStringTag"; function define(t, e, r) { return Object.defineProperty(t, e, { value: r, enumerable: !0, configurable: !0, writable: !0 }), t[e]; } try { define({}, ""); } catch (t) { define = function define(t, e, r) { return t[e] = r; }; } function wrap(t, e, r, n) { var i = e && e.prototype instanceof Generator ? e : Generator, a = Object.create(i.prototype), c = new Context(n || []); return o(a, "_invoke", { value: makeInvokeMethod(t, r, c) }), a; } function tryCatch(t, e, r) { try { return { type: "normal", arg: t.call(e, r) }; } catch (t) { return { type: "throw", arg: t }; } } e.wrap = wrap; var h = "suspendedStart", l = "suspendedYield", f = "executing", s = "completed", y = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var p = {}; define(p, a, function () { return this; }); var d = Object.getPrototypeOf, v = d && d(d(values([]))); v && v !== r && n.call(v, a) && (p = v); var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p); function defineIteratorMethods(t) { ["next", "throw", "return"].forEach(function (e) { define(t, e, function (t) { return this._invoke(e, t); }); }); } function AsyncIterator(t, e) { function invoke(r, o, i, a) { var c = tryCatch(t[r], t, o); if ("throw" !== c.type) { var u = c.arg, h = u.value; return h && "object" == _typeof(h) && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) { invoke("next", t, i, a); }, function (t) { invoke("throw", t, i, a); }) : e.resolve(h).then(function (t) { u.value = t, i(u); }, function (t) { return invoke("throw", t, i, a); }); } a(c.arg); } var r; o(this, "_invoke", { value: function value(t, n) { function callInvokeWithMethodAndArg() { return new e(function (e, r) { invoke(t, n, e, r); }); } return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(e, r, n) { var o = h; return function (i, a) { if (o === f) throw new Error("Generator is already running"); if (o === s) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var c = n.delegate; if (c) { var u = maybeInvokeDelegate(c, n); if (u) { if (u === y) continue; return u; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (o === h) throw o = s, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = f; var p = tryCatch(e, r, n); if ("normal" === p.type) { if (o = n.done ? s : l, p.arg === y) continue; return { value: p.arg, done: n.done }; } "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg); } }; } function maybeInvokeDelegate(e, r) { var n = r.method, o = e.iterator[n]; if (o === t) return r.delegate = null, "throw" === n && e.iterator["return"] && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y; var i = tryCatch(o, e.iterator, r.arg); if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y; var a = i.arg; return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y); } function pushTryEntry(t) { var e = { tryLoc: t[0] }; 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e); } function resetTryEntry(t) { var e = t.completion || {}; e.type = "normal", delete e.arg, t.completion = e; } function Context(t) { this.tryEntries = [{ tryLoc: "root" }], t.forEach(pushTryEntry, this), this.reset(!0); } function values(e) { if (e || "" === e) { var r = e[a]; if (r) return r.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) { var o = -1, i = function next() { for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next; return next.value = t, next.done = !0, next; }; return i.next = i; } } throw new TypeError(_typeof(e) + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), o(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) { var e = "function" == typeof t && t.constructor; return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name)); }, e.mark = function (t) { return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t; }, e.awrap = function (t) { return { __await: t }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () { return this; }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) { void 0 === i && (i = Promise); var a = new AsyncIterator(wrap(t, r, n, o), i); return e.isGeneratorFunction(r) ? a : a.next().then(function (t) { return t.done ? t.value : a.next(); }); }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () { return this; }), define(g, "toString", function () { return "[object Generator]"; }), e.keys = function (t) { var e = Object(t), r = []; for (var n in e) r.push(n); return r.reverse(), function next() { for (; r.length;) { var t = r.pop(); if (t in e) return next.value = t, next.done = !1, next; } return next.done = !0, next; }; }, e.values = values, Context.prototype = { constructor: Context, reset: function reset(e) { if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t); }, stop: function stop() { this.done = !0; var t = this.tryEntries[0].completion; if ("throw" === t.type) throw t.arg; return this.rval; }, dispatchException: function dispatchException(e) { if (this.done) throw e; var r = this; function handle(n, o) { return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o; } for (var o = this.tryEntries.length - 1; o >= 0; --o) { var i = this.tryEntries[o], a = i.completion; if ("root" === i.tryLoc) return handle("end"); if (i.tryLoc <= this.prev) { var c = n.call(i, "catchLoc"), u = n.call(i, "finallyLoc"); if (c && u) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } else if (c) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); } else { if (!u) throw new Error("try statement without catch or finally"); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } } } }, abrupt: function abrupt(t, e) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var o = this.tryEntries[r]; if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) { var i = o; break; } } i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null); var a = i ? i.completion : {}; return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a); }, complete: function complete(t, e) { if ("throw" === t.type) throw t.arg; return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y; }, finish: function finish(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y; } }, "catch": function _catch(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.tryLoc === t) { var n = r.completion; if ("throw" === n.type) { var o = n.arg; resetTryEntry(r); } return o; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(e, r, n) { return this.delegate = { iterator: values(e), resultName: r, nextLoc: n }, "next" === this.method && (this.arg = t), y; } }, e; }
20
15
  function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
21
-
22
16
  function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
23
-
24
17
  function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
25
-
26
- function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
27
-
28
- function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
29
-
30
- function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
31
-
32
- var CanvasObjectEvents;
33
- exports.CanvasObjectEvents = CanvasObjectEvents;
34
-
35
- (function (CanvasObjectEvents) {
18
+ function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
19
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
20
+ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
21
+ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
22
+ function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
23
+ var CanvasObjectEvents = exports.CanvasObjectEvents = /*#__PURE__*/function (CanvasObjectEvents) {
36
24
  CanvasObjectEvents["OnChange"] = "onChange";
37
- })(CanvasObjectEvents || (exports.CanvasObjectEvents = CanvasObjectEvents = {}));
38
-
39
- var AbstractCanvasObject = /*#__PURE__*/function () {
40
- // base properties
41
-
42
- /**
43
- * use only to set different scaling for the adapter in setScaling()
44
- * can be useful if we have to work with a smaller preview image which should be shown in its real size,
45
- * keeping the original scaling value
46
- * Notes:
47
- * - this value should not be saved with the object data, it has to be provided explicitly
48
- * - this value has no relation to any other attribute (eg. Image.src or Image.imageData)
49
- * - the responsibility of updating always belongs to the consumer of this package
50
- */
51
- // important: do not modify width and height directly,
52
- // they should only have getters if needed, all the others should be done by scaling
53
- // technical properties
54
- // this should be provided by every canvas object adapter
25
+ return CanvasObjectEvents;
26
+ }({});
27
+ var AbstractCanvasObject = exports.AbstractCanvasObject = /*#__PURE__*/function () {
55
28
  function AbstractCanvasObject(options) {
56
29
  _classCallCheck(this, AbstractCanvasObject);
57
-
30
+ // base properties
58
31
  _defineProperty(this, "_x", 0);
59
-
60
32
  _defineProperty(this, "_y", 0);
61
-
62
33
  _defineProperty(this, "_rotation", 0);
63
-
64
34
  _defineProperty(this, "_scaling", 1);
65
-
66
35
  _defineProperty(this, "_uuid", (0, _v["default"])());
67
-
36
+ /**
37
+ * use only to set different scaling for the adapter in setScaling()
38
+ * can be useful if we have to work with a smaller preview image which should be shown in its real size,
39
+ * keeping the original scaling value
40
+ * Notes:
41
+ * - this value should not be saved with the object data, it has to be provided explicitly
42
+ * - this value has no relation to any other attribute (eg. Image.src or Image.imageData)
43
+ * - the responsibility of updating always belongs to the consumer of this package
44
+ */
68
45
  _defineProperty(this, "_scaleFactor", 1);
69
-
46
+ // important: do not modify width and height directly,
47
+ // they should only have getters if needed, all the others should be done by scaling
48
+ // technical properties
70
49
  _defineProperty(this, "_wrappedObject", null);
71
-
72
50
  _defineProperty(this, "_selected", false);
73
-
74
51
  _defineProperty(this, "_locked", false);
75
-
76
52
  _defineProperty(this, "_autoFit", false);
77
-
78
53
  _defineProperty(this, "_grabbed", false);
79
-
80
54
  _defineProperty(this, "_activeAction", '');
81
-
82
55
  _defineProperty(this, "_userData", {});
83
-
84
56
  _defineProperty(this, "_canvas", null);
85
-
86
57
  _defineProperty(this, "_observable", new _Observable.Observable(this));
87
-
88
58
  this.initOptions(options);
89
-
90
59
  this._observable.on(CanvasObjectEvents.OnChange, this.updateConstraints.bind(this));
91
60
  }
92
-
93
61
  _createClass(AbstractCanvasObject, [{
94
62
  key: "initOptions",
95
63
  value: function initOptions(options) {
@@ -99,43 +67,34 @@ var AbstractCanvasObject = /*#__PURE__*/function () {
99
67
  this["_".concat(key)] = options[key];
100
68
  }
101
69
  }
102
-
103
70
  return this;
104
71
  }
105
72
  }, {
106
73
  key: "updateOptions",
107
74
  value: function () {
108
- var _updateOptions = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee(options) {
75
+ var _updateOptions = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(options) {
109
76
  var _i2, _Object$keys2, key;
110
-
111
- return regeneratorRuntime.wrap(function _callee$(_context) {
112
- while (1) {
113
- switch (_context.prev = _context.next) {
114
- case 0:
115
- if (options) {
116
- for (_i2 = 0, _Object$keys2 = Object.keys(options); _i2 < _Object$keys2.length; _i2++) {
117
- key = _Object$keys2[_i2];
118
-
119
- if (Object.prototype.hasOwnProperty.call(this, '_' + key) && key !== 'uuid') {
120
- this[key] = options[key];
121
- }
77
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
78
+ while (1) switch (_context.prev = _context.next) {
79
+ case 0:
80
+ if (options) {
81
+ for (_i2 = 0, _Object$keys2 = Object.keys(options); _i2 < _Object$keys2.length; _i2++) {
82
+ key = _Object$keys2[_i2];
83
+ if (Object.prototype.hasOwnProperty.call(this, '_' + key) && key !== 'uuid') {
84
+ this[key] = options[key];
122
85
  }
123
86
  }
124
-
125
- return _context.abrupt("return", this);
126
-
127
- case 2:
128
- case "end":
129
- return _context.stop();
130
- }
87
+ }
88
+ return _context.abrupt("return", this);
89
+ case 2:
90
+ case "end":
91
+ return _context.stop();
131
92
  }
132
93
  }, _callee, this);
133
94
  }));
134
-
135
95
  function updateOptions(_x) {
136
96
  return _updateOptions.apply(this, arguments);
137
97
  }
138
-
139
98
  return updateOptions;
140
99
  }()
141
100
  }, {
@@ -149,7 +108,6 @@ var AbstractCanvasObject = /*#__PURE__*/function () {
149
108
  if (this.constructor.type) {
150
109
  return this.constructor.type;
151
110
  }
152
-
153
111
  throw new TypeError('Type is not defined for this canvas object!');
154
112
  }
155
113
  }, {
@@ -161,10 +119,8 @@ var AbstractCanvasObject = /*#__PURE__*/function () {
161
119
  if (x === this._x) {
162
120
  return;
163
121
  }
164
-
165
122
  this._x = x;
166
123
  this.setPosition(this._x, this._y);
167
-
168
124
  this._observable.triggerEvent(CanvasObjectEvents.OnChange);
169
125
  }
170
126
  }, {
@@ -176,10 +132,8 @@ var AbstractCanvasObject = /*#__PURE__*/function () {
176
132
  if (y === this._y) {
177
133
  return;
178
134
  }
179
-
180
135
  this._y = y;
181
136
  this.setPosition(this._x, this._y);
182
-
183
137
  this._observable.triggerEvent(CanvasObjectEvents.OnChange);
184
138
  }
185
139
  }, {
@@ -189,14 +143,11 @@ var AbstractCanvasObject = /*#__PURE__*/function () {
189
143
  },
190
144
  set: function set(rotation) {
191
145
  var rot = (360 + rotation) % 360;
192
-
193
146
  if (rot === this._rotation) {
194
147
  return;
195
148
  }
196
-
197
149
  this._rotation = rot;
198
150
  this.setRotation(this._rotation);
199
-
200
151
  this._observable.triggerEvent(CanvasObjectEvents.OnChange);
201
152
  }
202
153
  }, {
@@ -208,10 +159,8 @@ var AbstractCanvasObject = /*#__PURE__*/function () {
208
159
  if (scaling === this._scaling || !Number.isFinite(scaling)) {
209
160
  return;
210
161
  }
211
-
212
162
  this._scaling = scaling;
213
163
  this.setScalingWithFactor(scaling);
214
-
215
164
  this._observable.triggerEvent(CanvasObjectEvents.OnChange);
216
165
  }
217
166
  }, {
@@ -231,15 +180,12 @@ var AbstractCanvasObject = /*#__PURE__*/function () {
231
180
  },
232
181
  set: function set(selected) {
233
182
  this._selected = selected;
234
-
235
183
  if (selected) {
236
184
  this.canvas.setSelectedObject(this);
237
185
  } else {
238
186
  this.canvas.deselectObject(this);
239
187
  }
240
-
241
188
  this.setSelected(selected);
242
-
243
189
  this._observable.triggerEvent(CanvasObjectEvents.OnChange);
244
190
  }
245
191
  }, {
@@ -249,7 +195,6 @@ var AbstractCanvasObject = /*#__PURE__*/function () {
249
195
  },
250
196
  set: function set(locked) {
251
197
  this._locked = locked;
252
-
253
198
  this._observable.triggerEvent(CanvasObjectEvents.OnChange);
254
199
  }
255
200
  }, {
@@ -259,7 +204,6 @@ var AbstractCanvasObject = /*#__PURE__*/function () {
259
204
  },
260
205
  set: function set(autoFit) {
261
206
  this._autoFit = autoFit;
262
-
263
207
  this._observable.triggerEvent(CanvasObjectEvents.OnChange);
264
208
  }
265
209
  }, {
@@ -269,7 +213,6 @@ var AbstractCanvasObject = /*#__PURE__*/function () {
269
213
  },
270
214
  set: function set(userDataObject) {
271
215
  this._userData = userDataObject;
272
-
273
216
  this._observable.triggerEvent(CanvasObjectEvents.OnChange);
274
217
  }
275
218
  }, {
@@ -279,7 +222,6 @@ var AbstractCanvasObject = /*#__PURE__*/function () {
279
222
  },
280
223
  set: function set(grabbed) {
281
224
  this._grabbed = grabbed;
282
-
283
225
  this._observable.triggerEvent(CanvasObjectEvents.OnChange);
284
226
  }
285
227
  }, {
@@ -289,7 +231,6 @@ var AbstractCanvasObject = /*#__PURE__*/function () {
289
231
  },
290
232
  set: function set(action) {
291
233
  this._activeAction = action;
292
-
293
234
  this._observable.triggerEvent(CanvasObjectEvents.OnChange);
294
235
  }
295
236
  }, {
@@ -310,11 +251,11 @@ var AbstractCanvasObject = /*#__PURE__*/function () {
310
251
  get: function get() {
311
252
  return this.getIndex() === this.canvas.getLength() - 1;
312
253
  }
254
+
313
255
  /**
314
256
  * Calls the setScaling method with the given scaling multiplied by the scaleFactor
315
257
  * @param scaling
316
258
  */
317
-
318
259
  }, {
319
260
  key: "setScalingWithFactor",
320
261
  value: function setScalingWithFactor(scaling) {
@@ -334,11 +275,11 @@ var AbstractCanvasObject = /*#__PURE__*/function () {
334
275
  key: "getState",
335
276
  value: function getState() {
336
277
  var selected = this.selected,
337
- grabbed = this.grabbed,
338
- isFirst = this.isFirst,
339
- isLast = this.isLast,
340
- locked = this.locked,
341
- autoFit = this.autoFit;
278
+ grabbed = this.grabbed,
279
+ isFirst = this.isFirst,
280
+ isLast = this.isLast,
281
+ locked = this.locked,
282
+ autoFit = this.autoFit;
342
283
  return _objectSpread(_objectSpread({}, this.toObject()), {}, {
343
284
  selected: selected,
344
285
  grabbed: grabbed,
@@ -358,7 +299,6 @@ var AbstractCanvasObject = /*#__PURE__*/function () {
358
299
  key: "remove",
359
300
  value: function remove() {
360
301
  this.canvas.remove(this);
361
-
362
302
  this._observable.triggerEvent(CanvasObjectEvents.OnChange);
363
303
  }
364
304
  }, {
@@ -371,7 +311,6 @@ var AbstractCanvasObject = /*#__PURE__*/function () {
371
311
  value: function setIndex(newIdx) {
372
312
  var overwrite = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
373
313
  this.canvas.setObjectIndex(this, newIdx, overwrite);
374
-
375
314
  this._observable.triggerEvent(CanvasObjectEvents.OnChange);
376
315
  }
377
316
  }, {
@@ -379,14 +318,14 @@ var AbstractCanvasObject = /*#__PURE__*/function () {
379
318
  value: function toObject() {
380
319
  var includeWrappedObject = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
381
320
  var type = this.type,
382
- x = this.x,
383
- y = this.y,
384
- rotation = this.rotation,
385
- scaling = this.scaling,
386
- locked = this.locked,
387
- autoFit = this.autoFit,
388
- userData = this.userData,
389
- uuid = this.uuid;
321
+ x = this.x,
322
+ y = this.y,
323
+ rotation = this.rotation,
324
+ scaling = this.scaling,
325
+ locked = this.locked,
326
+ autoFit = this.autoFit,
327
+ userData = this.userData,
328
+ uuid = this.uuid;
390
329
  var obj = {
391
330
  type: type,
392
331
  x: x,
@@ -398,20 +337,18 @@ var AbstractCanvasObject = /*#__PURE__*/function () {
398
337
  userData: userData,
399
338
  uuid: uuid
400
339
  };
401
-
402
340
  if (includeWrappedObject) {
403
341
  obj.__wrappedObject = this.wrappedObjectToObject();
404
342
  }
405
-
406
343
  return obj;
407
344
  }
408
345
  }, {
409
346
  key: "setOptionsFromObject",
410
347
  value: function setOptionsFromObject(obj) {
411
348
  var x = obj.x,
412
- y = obj.y,
413
- rotation = obj.rotation,
414
- scaling = obj.scaling;
349
+ y = obj.y,
350
+ rotation = obj.rotation,
351
+ scaling = obj.scaling;
415
352
  this.setPosition(x, y);
416
353
  this.setRotation(rotation);
417
354
  this.setScalingWithFactor(scaling);
@@ -420,40 +357,32 @@ var AbstractCanvasObject = /*#__PURE__*/function () {
420
357
  key: "alignTo",
421
358
  value: function alignTo(vertical, horizontal) {
422
359
  var x = this.x,
423
- y = this.y;
424
-
360
+ y = this.y;
425
361
  var _this$getBoundSize = this.getBoundSize(),
426
- height = _this$getBoundSize.height,
427
- width = _this$getBoundSize.width;
428
-
362
+ height = _this$getBoundSize.height,
363
+ width = _this$getBoundSize.width;
429
364
  switch (vertical) {
430
365
  case 'top':
431
366
  y = height / 2;
432
367
  break;
433
-
434
368
  case 'bottom':
435
369
  y = this.canvas.getSize().height - height / 2;
436
370
  break;
437
-
438
371
  case 'center':
439
372
  y = this.canvas.getSize().height / 2;
440
373
  break;
441
374
  }
442
-
443
375
  switch (horizontal) {
444
376
  case 'left':
445
377
  x = width / 2;
446
378
  break;
447
-
448
379
  case 'right':
449
380
  x = this.canvas.getSize().width - width / 2;
450
381
  break;
451
-
452
382
  case 'center':
453
383
  x = this.canvas.getSize().width / 2;
454
384
  break;
455
385
  }
456
-
457
386
  this.x = x;
458
387
  this.y = y;
459
388
  }
@@ -462,21 +391,16 @@ var AbstractCanvasObject = /*#__PURE__*/function () {
462
391
  value: function fitCanvas() {
463
392
  var enlarge = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
464
393
  var updatePosition = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
465
-
466
394
  var _this$canvas$getSize = this.canvas.getSize(),
467
- cw = _this$canvas$getSize.width,
468
- ch = _this$canvas$getSize.height;
469
-
395
+ cw = _this$canvas$getSize.width,
396
+ ch = _this$canvas$getSize.height;
470
397
  var _this$getBoundSize2 = this.getBoundSize(),
471
- ow = _this$getBoundSize2.width,
472
- oh = _this$getBoundSize2.height;
473
-
398
+ ow = _this$getBoundSize2.width,
399
+ oh = _this$getBoundSize2.height;
474
400
  var maxRatio = Math.max(ow / cw, oh / ch);
475
-
476
401
  if (maxRatio > 1 || maxRatio < 1 && enlarge) {
477
402
  this.scaling *= 1 / maxRatio;
478
403
  }
479
-
480
404
  if (updatePosition) {
481
405
  this.x = cw / 2;
482
406
  this.y = ch / 2;
@@ -486,9 +410,8 @@ var AbstractCanvasObject = /*#__PURE__*/function () {
486
410
  key: "getScaledSize",
487
411
  value: function getScaledSize() {
488
412
  var _this$getSize = this.getSize(),
489
- ow = _this$getSize.width,
490
- oh = _this$getSize.height;
491
-
413
+ ow = _this$getSize.width,
414
+ oh = _this$getSize.height;
492
415
  var scaling = this.scaling;
493
416
  return {
494
417
  width: ow * scaling,
@@ -501,10 +424,7 @@ var AbstractCanvasObject = /*#__PURE__*/function () {
501
424
  this.autoFit && this.fitCanvas(true, true);
502
425
  }
503
426
  }]);
504
-
505
427
  return AbstractCanvasObject;
506
428
  }();
507
-
508
- exports.AbstractCanvasObject = AbstractCanvasObject;
509
-
429
+ // this should be provided by every canvas object adapter
510
430
  _defineProperty(AbstractCanvasObject, "type", void 0);
@@ -9,5 +9,4 @@ Object.defineProperty(exports, "AbstractCanvasObject", {
9
9
  return _CanvasObject.AbstractCanvasObject;
10
10
  }
11
11
  });
12
-
13
12
  var _CanvasObject = require("./CanvasObject");
@@ -4,32 +4,23 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.Observable = void 0;
7
-
7
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
8
8
  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; } } }; }
9
-
10
9
  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); }
11
-
12
- 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; }
13
-
10
+ 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; }
14
11
  function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
15
-
16
- function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
17
-
18
- function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
19
-
20
- function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
21
-
22
- var Observable = /*#__PURE__*/function () {
12
+ function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
13
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
14
+ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
15
+ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
16
+ function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
17
+ var Observable = exports.Observable = /*#__PURE__*/function () {
23
18
  function Observable(object) {
24
19
  _classCallCheck(this, Observable);
25
-
26
20
  _defineProperty(this, "_eventListeners", []);
27
-
28
21
  _defineProperty(this, "_object", null);
29
-
30
22
  this._object = object;
31
23
  }
32
-
33
24
  _createClass(Observable, [{
34
25
  key: "on",
35
26
  value: function on(eventName, callback) {
@@ -37,7 +28,6 @@ var Observable = /*#__PURE__*/function () {
37
28
  console.warn("The following callback is already added to the event: ".concat(eventName), callback);
38
29
  return;
39
30
  }
40
-
41
31
  this._eventListeners.push({
42
32
  eventName: eventName,
43
33
  callback: callback
@@ -47,7 +37,6 @@ var Observable = /*#__PURE__*/function () {
47
37
  key: "off",
48
38
  value: function off(eventName, callback) {
49
39
  var idx = this.indexOf(eventName, callback);
50
-
51
40
  if (idx !== -1) {
52
41
  this._eventListeners.splice(idx, 1);
53
42
  }
@@ -57,27 +46,22 @@ var Observable = /*#__PURE__*/function () {
57
46
  value: function indexOf(eventName, callback) {
58
47
  for (var o = 0; o < this._eventListeners.length; o++) {
59
48
  var el = this._eventListeners[o];
60
-
61
49
  if (el.eventName === eventName && el.callback === callback) {
62
50
  return o;
63
51
  }
64
52
  }
65
-
66
53
  return -1;
67
54
  }
68
55
  }, {
69
56
  key: "triggerEvent",
70
57
  value: function triggerEvent(eventName, eventData) {
71
58
  var _this = this;
72
-
73
59
  setTimeout(function () {
74
60
  var _iterator = _createForOfIteratorHelper(_this._eventListeners),
75
- _step;
76
-
61
+ _step;
77
62
  try {
78
63
  for (_iterator.s(); !(_step = _iterator.n()).done;) {
79
64
  var el = _step.value;
80
-
81
65
  if (el.eventName === eventName) {
82
66
  el.callback(_this._object, eventData);
83
67
  }
@@ -90,8 +74,5 @@ var Observable = /*#__PURE__*/function () {
90
74
  });
91
75
  }
92
76
  }]);
93
-
94
77
  return Observable;
95
- }();
96
-
97
- exports.Observable = Observable;
78
+ }();