@antv/g-canvas 1.1.5 → 1.1.6

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/dist/index.umd.js CHANGED
@@ -4,11 +4,64 @@
4
4
  (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory((global.G = global.G || {}, global.G.Canvas2D = {}), global.window.G, global.window.G.ManaSyringe));
5
5
  }(this, (function (exports, g, manaSyringe) { 'use strict';
6
6
 
7
- function _inheritsLoose(subClass, superClass) {
8
- subClass.prototype = Object.create(superClass.prototype);
9
- subClass.prototype.constructor = subClass;
7
+ function _typeof(obj) {
8
+ "@babel/helpers - typeof";
9
+
10
+ return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) {
11
+ return typeof obj;
12
+ } : function (obj) {
13
+ return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
14
+ }, _typeof(obj);
15
+ }
16
+
17
+ function _classCallCheck(instance, Constructor) {
18
+ if (!(instance instanceof Constructor)) {
19
+ throw new TypeError("Cannot call a class as a function");
20
+ }
21
+ }
22
+
23
+ function _defineProperties(target, props) {
24
+ for (var i = 0; i < props.length; i++) {
25
+ var descriptor = props[i];
26
+ descriptor.enumerable = descriptor.enumerable || false;
27
+ descriptor.configurable = true;
28
+ if ("value" in descriptor) descriptor.writable = true;
29
+ Object.defineProperty(target, descriptor.key, descriptor);
30
+ }
31
+ }
32
+
33
+ function _createClass(Constructor, protoProps, staticProps) {
34
+ if (protoProps) _defineProperties(Constructor.prototype, protoProps);
35
+ if (staticProps) _defineProperties(Constructor, staticProps);
36
+ Object.defineProperty(Constructor, "prototype", {
37
+ writable: false
38
+ });
39
+ return Constructor;
40
+ }
41
+
42
+ function _inherits(subClass, superClass) {
43
+ if (typeof superClass !== "function" && superClass !== null) {
44
+ throw new TypeError("Super expression must either be null or a function");
45
+ }
46
+
47
+ subClass.prototype = Object.create(superClass && superClass.prototype, {
48
+ constructor: {
49
+ value: subClass,
50
+ writable: true,
51
+ configurable: true
52
+ }
53
+ });
54
+ Object.defineProperty(subClass, "prototype", {
55
+ writable: false
56
+ });
57
+ if (superClass) _setPrototypeOf(subClass, superClass);
58
+ }
10
59
 
11
- _setPrototypeOf(subClass, superClass);
60
+ function _getPrototypeOf(o) {
61
+ _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) {
62
+ return o.__proto__ || Object.getPrototypeOf(o);
63
+ };
64
+ return _getPrototypeOf(o);
12
65
  }
13
66
 
14
67
  function _setPrototypeOf(o, p) {
@@ -20,6 +73,56 @@
20
73
  return _setPrototypeOf(o, p);
21
74
  }
22
75
 
76
+ function _isNativeReflectConstruct() {
77
+ if (typeof Reflect === "undefined" || !Reflect.construct) return false;
78
+ if (Reflect.construct.sham) return false;
79
+ if (typeof Proxy === "function") return true;
80
+
81
+ try {
82
+ Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {}));
83
+ return true;
84
+ } catch (e) {
85
+ return false;
86
+ }
87
+ }
88
+
89
+ function _assertThisInitialized(self) {
90
+ if (self === void 0) {
91
+ throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
92
+ }
93
+
94
+ return self;
95
+ }
96
+
97
+ function _possibleConstructorReturn(self, call) {
98
+ if (call && (typeof call === "object" || typeof call === "function")) {
99
+ return call;
100
+ } else if (call !== void 0) {
101
+ throw new TypeError("Derived constructors may only return object or undefined");
102
+ }
103
+
104
+ return _assertThisInitialized(self);
105
+ }
106
+
107
+ function _createSuper(Derived) {
108
+ var hasNativeReflectConstruct = _isNativeReflectConstruct();
109
+
110
+ return function _createSuperInternal() {
111
+ var Super = _getPrototypeOf(Derived),
112
+ result;
113
+
114
+ if (hasNativeReflectConstruct) {
115
+ var NewTarget = _getPrototypeOf(this).constructor;
116
+
117
+ result = Reflect.construct(Super, arguments, NewTarget);
118
+ } else {
119
+ result = Super.apply(this, arguments);
120
+ }
121
+
122
+ return _possibleConstructorReturn(this, result);
123
+ };
124
+ }
125
+
23
126
  /******************************************************************************
24
127
  Copyright (c) Microsoft Corporation.
25
128
 
@@ -171,7 +274,7 @@
171
274
  if ("throw" !== record.type) {
172
275
  var result = record.arg,
173
276
  value = result.value;
174
- return value && "object" == typeof value && hasOwn.call(value, "__await") ? PromiseImpl.resolve(value.__await).then(function (value) {
277
+ return value && "object" == _typeof(value) && hasOwn.call(value, "__await") ? PromiseImpl.resolve(value.__await).then(function (value) {
175
278
  invoke("next", value, resolve, reject);
176
279
  }, function (err) {
177
280
  invoke("throw", err, resolve, reject);
@@ -432,6 +535,31 @@
432
535
  };
433
536
  }
434
537
 
538
+ function _classCallCheck$1(instance, Constructor) {
539
+ if (!(instance instanceof Constructor)) {
540
+ throw new TypeError("Cannot call a class as a function");
541
+ }
542
+ }
543
+
544
+ function _defineProperties$1(target, props) {
545
+ for (var i = 0; i < props.length; i++) {
546
+ var descriptor = props[i];
547
+ descriptor.enumerable = descriptor.enumerable || false;
548
+ descriptor.configurable = true;
549
+ if ("value" in descriptor) descriptor.writable = true;
550
+ Object.defineProperty(target, descriptor.key, descriptor);
551
+ }
552
+ }
553
+
554
+ function _createClass$1(Constructor, protoProps, staticProps) {
555
+ if (protoProps) _defineProperties$1(Constructor.prototype, protoProps);
556
+ if (staticProps) _defineProperties$1(Constructor, staticProps);
557
+ Object.defineProperty(Constructor, "prototype", {
558
+ writable: false
559
+ });
560
+ return Constructor;
561
+ }
562
+
435
563
  var _class;
436
564
 
437
565
  var DOMInteractionPlugin_1;
@@ -441,147 +569,150 @@
441
569
 
442
570
  var DOMInteractionPlugin = DOMInteractionPlugin_1 = (_class = /*#__PURE__*/function () {
443
571
  function DOMInteractionPlugin() {
572
+ _classCallCheck$1(this, DOMInteractionPlugin);
573
+
444
574
  this.contextService = void 0;
445
575
  this.renderingContext = void 0;
446
576
  }
447
577
 
448
- var _proto = DOMInteractionPlugin.prototype;
578
+ _createClass$1(DOMInteractionPlugin, [{
579
+ key: "apply",
580
+ value: function apply(renderingService) {
581
+ var _this = this;
449
582
 
450
- _proto.apply = function apply(renderingService) {
451
- var _this = this;
583
+ var canvas = this.renderingContext.root.ownerDocument.defaultView; // const SUPPORT_ONLY_TOUCH = canvas.supportsTouchEvents && MOBILE_REGEX.test(navigator.userAgent);
452
584
 
453
- var canvas = this.renderingContext.root.ownerDocument.defaultView; // const SUPPORT_ONLY_TOUCH = canvas.supportsTouchEvents && MOBILE_REGEX.test(navigator.userAgent);
585
+ var onPointerMove = function onPointerMove(ev) {
586
+ renderingService.hooks.pointerMove.call(ev);
587
+ };
454
588
 
455
- var onPointerMove = function onPointerMove(ev) {
456
- renderingService.hooks.pointerMove.call(ev);
457
- };
589
+ var onPointerUp = function onPointerUp(ev) {
590
+ renderingService.hooks.pointerUp.call(ev);
591
+ };
458
592
 
459
- var onPointerUp = function onPointerUp(ev) {
460
- renderingService.hooks.pointerUp.call(ev);
461
- };
593
+ var onPointerDown = function onPointerDown(ev) {
594
+ renderingService.hooks.pointerDown.call(ev);
595
+ };
462
596
 
463
- var onPointerDown = function onPointerDown(ev) {
464
- renderingService.hooks.pointerDown.call(ev);
465
- };
597
+ var onPointerOver = function onPointerOver(ev) {
598
+ renderingService.hooks.pointerOver.call(ev);
599
+ };
466
600
 
467
- var onPointerOver = function onPointerOver(ev) {
468
- renderingService.hooks.pointerOver.call(ev);
469
- };
601
+ var onPointerOut = function onPointerOut(ev) {
602
+ renderingService.hooks.pointerOut.call(ev);
603
+ };
470
604
 
471
- var onPointerOut = function onPointerOut(ev) {
472
- renderingService.hooks.pointerOut.call(ev);
473
- };
605
+ var onPointerCancel = function onPointerCancel(ev) {
606
+ renderingService.hooks.pointerCancel.call(ev);
607
+ };
474
608
 
475
- var onPointerCancel = function onPointerCancel(ev) {
476
- renderingService.hooks.pointerCancel.call(ev);
477
- };
609
+ var onPointerWheel = function onPointerWheel(ev) {
610
+ renderingService.hooks.pointerWheel.call(ev);
611
+ };
478
612
 
479
- var onPointerWheel = function onPointerWheel(ev) {
480
- renderingService.hooks.pointerWheel.call(ev);
481
- };
613
+ var addPointerEventListener = function addPointerEventListener($el) {
614
+ globalThis.document.addEventListener('pointermove', onPointerMove, true);
615
+ $el.addEventListener('pointerdown', onPointerDown, true);
616
+ $el.addEventListener('pointerleave', onPointerOut, true);
617
+ $el.addEventListener('pointerover', onPointerOver, true);
618
+ globalThis.addEventListener('pointerup', onPointerUp, true);
619
+ };
482
620
 
483
- var addPointerEventListener = function addPointerEventListener($el) {
484
- globalThis.document.addEventListener('pointermove', onPointerMove, true);
485
- $el.addEventListener('pointerdown', onPointerDown, true);
486
- $el.addEventListener('pointerleave', onPointerOut, true);
487
- $el.addEventListener('pointerover', onPointerOver, true);
488
- globalThis.addEventListener('pointerup', onPointerUp, true);
489
- };
621
+ var addTouchEventListener = function addTouchEventListener($el) {
622
+ $el.addEventListener('touchstart', onPointerDown, true);
623
+ $el.addEventListener('touchend', onPointerUp, true);
624
+ $el.addEventListener('touchmove', onPointerMove, true);
625
+ $el.addEventListener('touchcancel', onPointerCancel, true);
626
+ };
490
627
 
491
- var addTouchEventListener = function addTouchEventListener($el) {
492
- $el.addEventListener('touchstart', onPointerDown, true);
493
- $el.addEventListener('touchend', onPointerUp, true);
494
- $el.addEventListener('touchmove', onPointerMove, true);
495
- $el.addEventListener('touchcancel', onPointerCancel, true);
496
- };
628
+ var addMouseEventListener = function addMouseEventListener($el) {
629
+ globalThis.document.addEventListener('mousemove', onPointerMove, true);
630
+ $el.addEventListener('mousedown', onPointerDown, true);
631
+ $el.addEventListener('mouseout', onPointerOut, true);
632
+ $el.addEventListener('mouseover', onPointerOver, true);
633
+ globalThis.addEventListener('mouseup', onPointerUp, true);
634
+ };
497
635
 
498
- var addMouseEventListener = function addMouseEventListener($el) {
499
- globalThis.document.addEventListener('mousemove', onPointerMove, true);
500
- $el.addEventListener('mousedown', onPointerDown, true);
501
- $el.addEventListener('mouseout', onPointerOut, true);
502
- $el.addEventListener('mouseover', onPointerOver, true);
503
- globalThis.addEventListener('mouseup', onPointerUp, true);
504
- };
636
+ var removePointerEventListener = function removePointerEventListener($el) {
637
+ globalThis.document.removeEventListener('pointermove', onPointerMove, true);
638
+ $el.removeEventListener('pointerdown', onPointerDown, true);
639
+ $el.removeEventListener('pointerleave', onPointerOut, true);
640
+ $el.removeEventListener('pointerover', onPointerOver, true);
641
+ globalThis.removeEventListener('pointerup', onPointerUp, true);
642
+ };
505
643
 
506
- var removePointerEventListener = function removePointerEventListener($el) {
507
- globalThis.document.removeEventListener('pointermove', onPointerMove, true);
508
- $el.removeEventListener('pointerdown', onPointerDown, true);
509
- $el.removeEventListener('pointerleave', onPointerOut, true);
510
- $el.removeEventListener('pointerover', onPointerOver, true);
511
- globalThis.removeEventListener('pointerup', onPointerUp, true);
512
- };
644
+ var removeTouchEventListener = function removeTouchEventListener($el) {
645
+ $el.removeEventListener('touchstart', onPointerDown, true);
646
+ $el.removeEventListener('touchend', onPointerUp, true);
647
+ $el.removeEventListener('touchmove', onPointerMove, true);
648
+ };
513
649
 
514
- var removeTouchEventListener = function removeTouchEventListener($el) {
515
- $el.removeEventListener('touchstart', onPointerDown, true);
516
- $el.removeEventListener('touchend', onPointerUp, true);
517
- $el.removeEventListener('touchmove', onPointerMove, true);
518
- };
650
+ var removeMouseEventListener = function removeMouseEventListener($el) {
651
+ globalThis.document.removeEventListener('mousemove', onPointerMove, true);
652
+ $el.removeEventListener('mousedown', onPointerDown, true);
653
+ $el.removeEventListener('mouseout', onPointerOut, true);
654
+ $el.removeEventListener('mouseover', onPointerOver, true);
655
+ globalThis.removeEventListener('mouseup', onPointerUp, true);
656
+ };
519
657
 
520
- var removeMouseEventListener = function removeMouseEventListener($el) {
521
- globalThis.document.removeEventListener('mousemove', onPointerMove, true);
522
- $el.removeEventListener('mousedown', onPointerDown, true);
523
- $el.removeEventListener('mouseout', onPointerOut, true);
524
- $el.removeEventListener('mouseover', onPointerOver, true);
525
- globalThis.removeEventListener('mouseup', onPointerUp, true);
526
- };
658
+ renderingService.hooks.init.tapPromise(DOMInteractionPlugin_1.tag, /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
659
+ var $el;
660
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
661
+ while (1) {
662
+ switch (_context.prev = _context.next) {
663
+ case 0:
664
+ $el = _this.contextService.getDomElement(); // @ts-ignore
527
665
 
528
- renderingService.hooks.init.tapPromise(DOMInteractionPlugin_1.tag, /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
529
- var $el;
530
- return _regeneratorRuntime().wrap(function _callee$(_context) {
531
- while (1) {
532
- switch (_context.prev = _context.next) {
533
- case 0:
534
- $el = _this.contextService.getDomElement(); // @ts-ignore
535
-
536
- if (globalThis.navigator.msPointerEnabled) {
537
- // @ts-ignore
538
- $el.style.msContentZooming = 'none'; // @ts-ignore
539
-
540
- $el.style.msTouchAction = 'none';
541
- } else if (canvas.supportsPointerEvents) {
542
- $el.style.touchAction = 'none';
543
- }
666
+ if (globalThis.navigator.msPointerEnabled) {
667
+ // @ts-ignore
668
+ $el.style.msContentZooming = 'none'; // @ts-ignore
544
669
 
545
- if (canvas.supportsPointerEvents) {
546
- addPointerEventListener($el);
547
- } else {
548
- addMouseEventListener($el);
549
- }
670
+ $el.style.msTouchAction = 'none';
671
+ } else if (canvas.supportsPointerEvents) {
672
+ $el.style.touchAction = 'none';
673
+ }
674
+
675
+ if (canvas.supportsPointerEvents) {
676
+ addPointerEventListener($el);
677
+ } else {
678
+ addMouseEventListener($el);
679
+ }
550
680
 
551
- if (canvas.supportsTouchEvents) {
552
- addTouchEventListener($el);
553
- } // use passive event listeners
554
- // @see https://zhuanlan.zhihu.com/p/24555031
681
+ if (canvas.supportsTouchEvents) {
682
+ addTouchEventListener($el);
683
+ } // use passive event listeners
684
+ // @see https://zhuanlan.zhihu.com/p/24555031
555
685
 
556
686
 
557
- $el.addEventListener('wheel', onPointerWheel, {
558
- passive: true,
559
- capture: true
560
- });
687
+ $el.addEventListener('wheel', onPointerWheel, {
688
+ passive: true,
689
+ capture: true
690
+ });
561
691
 
562
- case 5:
563
- case "end":
564
- return _context.stop();
692
+ case 5:
693
+ case "end":
694
+ return _context.stop();
695
+ }
565
696
  }
566
- }
567
- }, _callee);
568
- })));
569
- renderingService.hooks.destroy.tap(DOMInteractionPlugin_1.tag, function () {
570
- var $el = _this.contextService.getDomElement();
697
+ }, _callee);
698
+ })));
699
+ renderingService.hooks.destroy.tap(DOMInteractionPlugin_1.tag, function () {
700
+ var $el = _this.contextService.getDomElement();
571
701
 
572
- if (canvas.supportsPointerEvents) {
573
- removePointerEventListener($el);
574
- } else {
575
- removeMouseEventListener($el);
576
- }
702
+ if (canvas.supportsPointerEvents) {
703
+ removePointerEventListener($el);
704
+ } else {
705
+ removeMouseEventListener($el);
706
+ }
577
707
 
578
- if (canvas.supportsTouchEvents) {
579
- removeTouchEventListener($el);
580
- }
708
+ if (canvas.supportsTouchEvents) {
709
+ removeTouchEventListener($el);
710
+ }
581
711
 
582
- $el.removeEventListener('wheel', onPointerWheel, true);
583
- });
584
- };
712
+ $el.removeEventListener('wheel', onPointerWheel, true);
713
+ });
714
+ }
715
+ }]);
585
716
 
586
717
  return DOMInteractionPlugin;
587
718
  }(), _class.tag = 'DOMInteraction', _class);
@@ -599,18 +730,22 @@
599
730
 
600
731
  var Plugin = /*#__PURE__*/function () {
601
732
  function Plugin() {
733
+ _classCallCheck$1(this, Plugin);
734
+
602
735
  this.name = 'dom-interaction';
603
736
  }
604
737
 
605
- var _proto = Plugin.prototype;
606
-
607
- _proto.init = function init(container) {
608
- container.load(containerModule, true);
609
- };
610
-
611
- _proto.destroy = function destroy(container) {
612
- container.unload(containerModule);
613
- };
738
+ _createClass$1(Plugin, [{
739
+ key: "init",
740
+ value: function init(container) {
741
+ container.load(containerModule, true);
742
+ }
743
+ }, {
744
+ key: "destroy",
745
+ value: function destroy(container) {
746
+ container.unload(containerModule);
747
+ }
748
+ }]);
614
749
 
615
750
  return Plugin;
616
751
  }();
@@ -1185,6 +1320,32 @@
1185
1320
  }
1186
1321
  }
1187
1322
 
1323
+ function ownKeys(object, enumerableOnly) {
1324
+ var keys = Object.keys(object);
1325
+
1326
+ if (Object.getOwnPropertySymbols) {
1327
+ var symbols = Object.getOwnPropertySymbols(object);
1328
+ enumerableOnly && (symbols = symbols.filter(function (sym) {
1329
+ return Object.getOwnPropertyDescriptor(object, sym).enumerable;
1330
+ })), keys.push.apply(keys, symbols);
1331
+ }
1332
+
1333
+ return keys;
1334
+ }
1335
+
1336
+ function _objectSpread2(target) {
1337
+ for (var i = 1; i < arguments.length; i++) {
1338
+ var source = null != arguments[i] ? arguments[i] : {};
1339
+ i % 2 ? ownKeys(Object(source), !0).forEach(function (key) {
1340
+ _defineProperty(target, key, source[key]);
1341
+ }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) {
1342
+ Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
1343
+ });
1344
+ }
1345
+
1346
+ return target;
1347
+ }
1348
+
1188
1349
  function _regeneratorRuntime$1() {
1189
1350
  /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */
1190
1351
  _regeneratorRuntime$1 = function _regeneratorRuntime() {
@@ -1310,7 +1471,7 @@
1310
1471
  if ("throw" !== record.type) {
1311
1472
  var result = record.arg,
1312
1473
  value = result.value;
1313
- return value && "object" == typeof value && hasOwn.call(value, "__await") ? PromiseImpl.resolve(value.__await).then(function (value) {
1474
+ return value && "object" == _typeof(value) && hasOwn.call(value, "__await") ? PromiseImpl.resolve(value.__await).then(function (value) {
1314
1475
  invoke("next", value, resolve, reject);
1315
1476
  }, function (err) {
1316
1477
  invoke("throw", err, resolve, reject);
@@ -1571,29 +1732,69 @@
1571
1732
  };
1572
1733
  }
1573
1734
 
1574
- function _extends() {
1575
- _extends = Object.assign || function (target) {
1576
- for (var i = 1; i < arguments.length; i++) {
1577
- var source = arguments[i];
1735
+ function _classCallCheck$2(instance, Constructor) {
1736
+ if (!(instance instanceof Constructor)) {
1737
+ throw new TypeError("Cannot call a class as a function");
1738
+ }
1739
+ }
1578
1740
 
1579
- for (var key in source) {
1580
- if (Object.prototype.hasOwnProperty.call(source, key)) {
1581
- target[key] = source[key];
1582
- }
1583
- }
1584
- }
1741
+ function _defineProperties$2(target, props) {
1742
+ for (var i = 0; i < props.length; i++) {
1743
+ var descriptor = props[i];
1744
+ descriptor.enumerable = descriptor.enumerable || false;
1745
+ descriptor.configurable = true;
1746
+ if ("value" in descriptor) descriptor.writable = true;
1747
+ Object.defineProperty(target, descriptor.key, descriptor);
1748
+ }
1749
+ }
1585
1750
 
1586
- return target;
1587
- };
1751
+ function _createClass$2(Constructor, protoProps, staticProps) {
1752
+ if (protoProps) _defineProperties$2(Constructor.prototype, protoProps);
1753
+ if (staticProps) _defineProperties$2(Constructor, staticProps);
1754
+ Object.defineProperty(Constructor, "prototype", {
1755
+ writable: false
1756
+ });
1757
+ return Constructor;
1758
+ }
1759
+
1760
+ function _defineProperty(obj, key, value) {
1761
+ if (key in obj) {
1762
+ Object.defineProperty(obj, key, {
1763
+ value: value,
1764
+ enumerable: true,
1765
+ configurable: true,
1766
+ writable: true
1767
+ });
1768
+ } else {
1769
+ obj[key] = value;
1770
+ }
1588
1771
 
1589
- return _extends.apply(this, arguments);
1772
+ return obj;
1590
1773
  }
1591
1774
 
1592
- function _inheritsLoose$1(subClass, superClass) {
1593
- subClass.prototype = Object.create(superClass.prototype);
1594
- subClass.prototype.constructor = subClass;
1775
+ function _inherits$1(subClass, superClass) {
1776
+ if (typeof superClass !== "function" && superClass !== null) {
1777
+ throw new TypeError("Super expression must either be null or a function");
1778
+ }
1779
+
1780
+ subClass.prototype = Object.create(superClass && superClass.prototype, {
1781
+ constructor: {
1782
+ value: subClass,
1783
+ writable: true,
1784
+ configurable: true
1785
+ }
1786
+ });
1787
+ Object.defineProperty(subClass, "prototype", {
1788
+ writable: false
1789
+ });
1790
+ if (superClass) _setPrototypeOf$1(subClass, superClass);
1791
+ }
1595
1792
 
1596
- _setPrototypeOf$1(subClass, superClass);
1793
+ function _getPrototypeOf$1(o) {
1794
+ _getPrototypeOf$1 = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) {
1795
+ return o.__proto__ || Object.getPrototypeOf(o);
1796
+ };
1797
+ return _getPrototypeOf$1(o);
1597
1798
  }
1598
1799
 
1599
1800
  function _setPrototypeOf$1(o, p) {
@@ -1604,6 +1805,133 @@
1604
1805
 
1605
1806
  return _setPrototypeOf$1(o, p);
1606
1807
  }
1808
+
1809
+ function _isNativeReflectConstruct$1() {
1810
+ if (typeof Reflect === "undefined" || !Reflect.construct) return false;
1811
+ if (Reflect.construct.sham) return false;
1812
+ if (typeof Proxy === "function") return true;
1813
+
1814
+ try {
1815
+ Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {}));
1816
+ return true;
1817
+ } catch (e) {
1818
+ return false;
1819
+ }
1820
+ }
1821
+
1822
+ function _assertThisInitialized$1(self) {
1823
+ if (self === void 0) {
1824
+ throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
1825
+ }
1826
+
1827
+ return self;
1828
+ }
1829
+
1830
+ function _possibleConstructorReturn$1(self, call) {
1831
+ if (call && (_typeof(call) === "object" || typeof call === "function")) {
1832
+ return call;
1833
+ } else if (call !== void 0) {
1834
+ throw new TypeError("Derived constructors may only return object or undefined");
1835
+ }
1836
+
1837
+ return _assertThisInitialized$1(self);
1838
+ }
1839
+
1840
+ function _createSuper$1(Derived) {
1841
+ var hasNativeReflectConstruct = _isNativeReflectConstruct$1();
1842
+
1843
+ return function _createSuperInternal() {
1844
+ var Super = _getPrototypeOf$1(Derived),
1845
+ result;
1846
+
1847
+ if (hasNativeReflectConstruct) {
1848
+ var NewTarget = _getPrototypeOf$1(this).constructor;
1849
+
1850
+ result = Reflect.construct(Super, arguments, NewTarget);
1851
+ } else {
1852
+ result = Super.apply(this, arguments);
1853
+ }
1854
+
1855
+ return _possibleConstructorReturn$1(this, result);
1856
+ };
1857
+ }
1858
+
1859
+ function _slicedToArray(arr, i) {
1860
+ return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest();
1861
+ }
1862
+
1863
+ function _toConsumableArray(arr) {
1864
+ return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread();
1865
+ }
1866
+
1867
+ function _arrayWithoutHoles(arr) {
1868
+ if (Array.isArray(arr)) return _arrayLikeToArray(arr);
1869
+ }
1870
+
1871
+ function _arrayWithHoles(arr) {
1872
+ if (Array.isArray(arr)) return arr;
1873
+ }
1874
+
1875
+ function _iterableToArray(iter) {
1876
+ if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
1877
+ }
1878
+
1879
+ function _iterableToArrayLimit(arr, i) {
1880
+ var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
1881
+
1882
+ if (_i == null) return;
1883
+ var _arr = [];
1884
+ var _n = true;
1885
+ var _d = false;
1886
+
1887
+ var _s, _e;
1888
+
1889
+ try {
1890
+ for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) {
1891
+ _arr.push(_s.value);
1892
+
1893
+ if (i && _arr.length === i) break;
1894
+ }
1895
+ } catch (err) {
1896
+ _d = true;
1897
+ _e = err;
1898
+ } finally {
1899
+ try {
1900
+ if (!_n && _i["return"] != null) _i["return"]();
1901
+ } finally {
1902
+ if (_d) throw _e;
1903
+ }
1904
+ }
1905
+
1906
+ return _arr;
1907
+ }
1908
+
1909
+ function _unsupportedIterableToArray(o, minLen) {
1910
+ if (!o) return;
1911
+ if (typeof o === "string") return _arrayLikeToArray(o, minLen);
1912
+ var n = Object.prototype.toString.call(o).slice(8, -1);
1913
+ if (n === "Object" && o.constructor) n = o.constructor.name;
1914
+ if (n === "Map" || n === "Set") return Array.from(o);
1915
+ if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
1916
+ }
1917
+
1918
+ function _arrayLikeToArray(arr, len) {
1919
+ if (len == null || len > arr.length) len = arr.length;
1920
+
1921
+ for (var i = 0, arr2 = new Array(len); i < len; i++) {
1922
+ arr2[i] = arr[i];
1923
+ }
1924
+
1925
+ return arr2;
1926
+ }
1927
+
1928
+ function _nonIterableSpread() {
1929
+ throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
1930
+ }
1931
+
1932
+ function _nonIterableRest() {
1933
+ throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
1934
+ }
1607
1935
  /**
1608
1936
  * Common utilities
1609
1937
  * @module glMatrix
@@ -2263,65 +2591,240 @@
2263
2591
  };
2264
2592
  }();
2265
2593
 
2266
- function generatePath(context, parsedStyle) {
2267
- var r = parsedStyle.r;
2268
- context.arc(r.value, r.value, r.value, 0, Math.PI * 2, false);
2269
- }
2594
+ var RBushNode = /*#__PURE__*/_createClass$2(function RBushNode() {
2595
+ _classCallCheck$2(this, RBushNode);
2270
2596
 
2271
- function generatePath$1(context, parsedStyle) {
2272
- var rxInPixels = parsedStyle.rx,
2273
- ryInPixels = parsedStyle.ry;
2274
- var rx = rxInPixels.value;
2275
- var ry = ryInPixels.value; // @see https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/ellipse
2597
+ this.aabb = void 0;
2598
+ });
2276
2599
 
2277
- if (context.ellipse) {
2278
- context.ellipse(rx, ry, rx, ry, 0, 0, Math.PI * 2, false);
2279
- } else {
2280
- // 如果不支持,则使用圆来绘制,进行变形
2281
- var r = rx > ry ? rx : ry;
2282
- var scaleX = rx > ry ? 1 : rx / ry;
2283
- var scaleY = rx > ry ? ry / rx : 1;
2284
- context.save();
2285
- context.scale(scaleX, scaleY);
2286
- context.arc(0, 0, r, 0, Math.PI * 2);
2287
- }
2288
- }
2600
+ RBushNode.tag = 'c-canvas-rbush-node';
2289
2601
 
2290
- function generatePath$2(context, parsedStyle) {
2291
- var radius = parsedStyle.radius,
2292
- width = parsedStyle.width,
2293
- height = parsedStyle.height;
2294
- var w = width.value;
2295
- var h = height.value;
2296
- var hasRadius = radius && radius.some(function (r) {
2297
- return r.value !== 0;
2298
- });
2602
+ var GradientPool = /*#__PURE__*/function () {
2603
+ function GradientPool() {
2604
+ _classCallCheck$2(this, GradientPool);
2299
2605
 
2300
- if (!hasRadius) {
2301
- context.rect(0, 0, w, h);
2302
- } else {
2303
- var _radius$map = radius.map(function (r) {
2304
- return r.value;
2305
- }),
2306
- r1 = _radius$map[0],
2307
- r2 = _radius$map[1],
2308
- r3 = _radius$map[2],
2309
- r4 = _radius$map[3];
2606
+ this.gradientCache = {};
2607
+ }
2310
2608
 
2311
- context.moveTo(r1, 0);
2312
- context.lineTo(w - r2, 0);
2609
+ _createClass$2(GradientPool, [{
2610
+ key: "getOrCreateGradient",
2611
+ value: function getOrCreateGradient(params, context) {
2612
+ var key = this.generateCacheKey(params);
2613
+ var type = params.type,
2614
+ x0 = params.x0,
2615
+ y0 = params.y0,
2616
+ x1 = params.x1,
2617
+ y1 = params.y1,
2618
+ steps = params.steps,
2619
+ width = params.width,
2620
+ height = params.height;
2621
+
2622
+ if (this.gradientCache[key]) {
2623
+ return this.gradientCache[key];
2624
+ }
2313
2625
 
2314
- if (r2 !== 0) {
2315
- context.arc(w - r2, r2, r2, -Math.PI / 2, 0);
2316
- }
2626
+ var gradient = null;
2317
2627
 
2318
- context.lineTo(w, h - r3);
2628
+ if (type === g.GradientPatternType.LinearGradient) {
2629
+ // @see https://developer.mozilla.org/zh-CN/docs/Web/API/CanvasRenderingContext2D/createLinearGradient
2630
+ gradient = context.createLinearGradient(x0 * width, y0 * height, x1 * width, y1 * height);
2631
+ } else if (type === g.GradientPatternType.RadialGradient) {
2632
+ var r = Math.sqrt(width * width + height * height) / 2; // @see https://developer.mozilla.org/zh-CN/docs/Web/API/CanvasRenderingContext2D/createRadialGradient
2319
2633
 
2320
- if (r3 !== 0) {
2321
- context.arc(w - r3, h - r3, r3, 0, Math.PI / 2);
2322
- }
2634
+ gradient = context.createRadialGradient(x0 * width, y0 * height, 0, x1 * width, y1 * height, params.r1 * r);
2635
+ }
2323
2636
 
2324
- context.lineTo(r4, h);
2637
+ if (gradient) {
2638
+ steps.forEach(function (_ref) {
2639
+ var _gradient;
2640
+
2641
+ var _ref2 = _slicedToArray(_ref, 2),
2642
+ offset = _ref2[0],
2643
+ color = _ref2[1];
2644
+
2645
+ (_gradient = gradient) === null || _gradient === void 0 ? void 0 : _gradient.addColorStop(Number(offset), color);
2646
+ });
2647
+ this.gradientCache[key] = gradient;
2648
+ }
2649
+
2650
+ return this.gradientCache[key];
2651
+ }
2652
+ }, {
2653
+ key: "generateCacheKey",
2654
+ value: function generateCacheKey(params) {
2655
+ // @ts-ignore
2656
+ var type = params.type,
2657
+ x0 = params.x0,
2658
+ y0 = params.y0,
2659
+ x1 = params.x1,
2660
+ y1 = params.y1,
2661
+ r1 = params.r1,
2662
+ steps = params.steps,
2663
+ width = params.width,
2664
+ height = params.height;
2665
+ return "gradient-".concat(type, "-").concat(x0, "-").concat(y0, "-").concat(x1, "-").concat(y1, "-").concat(r1 || 0, "-").concat(width, "-").concat(height, "-").concat(steps.map(function (step) {
2666
+ return step.join('');
2667
+ }).join('-'));
2668
+ }
2669
+ }]);
2670
+
2671
+ return GradientPool;
2672
+ }();
2673
+
2674
+ GradientPool = __decorate([manaSyringe.singleton()], GradientPool);
2675
+
2676
+ var ImagePool = /*#__PURE__*/function () {
2677
+ function ImagePool() {
2678
+ _classCallCheck$2(this, ImagePool);
2679
+
2680
+ this.imageCache = {};
2681
+ this.patternCache = {};
2682
+ this.canvasConfig = void 0;
2683
+ }
2684
+
2685
+ _createClass$2(ImagePool, [{
2686
+ key: "getImageSync",
2687
+ value: function getImageSync(src) {
2688
+ return this.imageCache[src];
2689
+ }
2690
+ }, {
2691
+ key: "getOrCreateImage",
2692
+ value: function getOrCreateImage(src) {
2693
+ var _this = this;
2694
+
2695
+ if (this.imageCache[src]) {
2696
+ return Promise.resolve(this.imageCache[src]);
2697
+ } // @see https://github.com/antvis/g/issues/938
2698
+
2699
+
2700
+ var createImage = this.canvasConfig.createImage;
2701
+ return new Promise(function (resolve, reject) {
2702
+ var image;
2703
+
2704
+ if (createImage) {
2705
+ image = createImage(src);
2706
+ } else if (g.isBrowser) {
2707
+ image = new window.Image();
2708
+ }
2709
+
2710
+ if (image) {
2711
+ image.onload = function () {
2712
+ resolve(image);
2713
+ };
2714
+
2715
+ image.onerror = function (ev) {
2716
+ reject(ev);
2717
+ };
2718
+
2719
+ image.crossOrigin = 'Anonymous';
2720
+ image.src = src;
2721
+ _this.imageCache[src] = image;
2722
+ }
2723
+ });
2724
+ }
2725
+ }, {
2726
+ key: "getPatternSync",
2727
+ value: function getPatternSync(pattern) {
2728
+ var patternKey = this.generatePatternKey(pattern);
2729
+
2730
+ if (this.patternCache[patternKey]) {
2731
+ return this.patternCache[patternKey];
2732
+ }
2733
+ }
2734
+ }, {
2735
+ key: "createPattern",
2736
+ value: function createPattern(patternParams, context) {
2737
+ var _this2 = this;
2738
+
2739
+ return this.getOrCreateImage(patternParams.src).then(function (image) {
2740
+ var patternKey = _this2.generatePatternKey(patternParams); // @see https://developer.mozilla.org/zh-CN/docs/Web/API/CanvasRenderingContext2D/createPattern
2741
+
2742
+
2743
+ var pattern = context.createPattern(image, patternParams.repetition);
2744
+
2745
+ if (pattern) {
2746
+ _this2.patternCache[patternKey] = pattern;
2747
+ }
2748
+
2749
+ return _this2.patternCache[patternKey];
2750
+ });
2751
+ }
2752
+ }, {
2753
+ key: "generatePatternKey",
2754
+ value: function generatePatternKey(pattern) {
2755
+ var src = pattern.src,
2756
+ repetition = pattern.repetition;
2757
+ return "pattern-".concat(src, "-").concat(repetition);
2758
+ }
2759
+ }]);
2760
+
2761
+ return ImagePool;
2762
+ }();
2763
+
2764
+ __decorate([manaSyringe.inject(g.CanvasConfig), __metadata("design:type", Object)], ImagePool.prototype, "canvasConfig", void 0);
2765
+
2766
+ ImagePool = __decorate([manaSyringe.singleton()], ImagePool);
2767
+
2768
+ function generatePath(context, parsedStyle) {
2769
+ var r = parsedStyle.r;
2770
+ context.arc(r.value, r.value, r.value, 0, Math.PI * 2, false);
2771
+ }
2772
+
2773
+ function generatePath$1(context, parsedStyle) {
2774
+ var rxInPixels = parsedStyle.rx,
2775
+ ryInPixels = parsedStyle.ry;
2776
+ var rx = rxInPixels.value;
2777
+ var ry = ryInPixels.value; // @see https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/ellipse
2778
+
2779
+ if (context.ellipse) {
2780
+ context.ellipse(rx, ry, rx, ry, 0, 0, Math.PI * 2, false);
2781
+ } else {
2782
+ // 如果不支持,则使用圆来绘制,进行变形
2783
+ var r = rx > ry ? rx : ry;
2784
+ var scaleX = rx > ry ? 1 : rx / ry;
2785
+ var scaleY = rx > ry ? ry / rx : 1;
2786
+ context.save();
2787
+ context.scale(scaleX, scaleY);
2788
+ context.arc(0, 0, r, 0, Math.PI * 2);
2789
+ }
2790
+ }
2791
+
2792
+ function generatePath$2(context, parsedStyle) {
2793
+ var radius = parsedStyle.radius,
2794
+ width = parsedStyle.width,
2795
+ height = parsedStyle.height;
2796
+ var w = width.value;
2797
+ var h = height.value;
2798
+ var hasRadius = radius && radius.some(function (r) {
2799
+ return r.value !== 0;
2800
+ });
2801
+
2802
+ if (!hasRadius) {
2803
+ context.rect(0, 0, w, h);
2804
+ } else {
2805
+ var _radius$map = radius.map(function (r) {
2806
+ return r.value;
2807
+ }),
2808
+ _radius$map2 = _slicedToArray(_radius$map, 4),
2809
+ r1 = _radius$map2[0],
2810
+ r2 = _radius$map2[1],
2811
+ r3 = _radius$map2[2],
2812
+ r4 = _radius$map2[3];
2813
+
2814
+ context.moveTo(r1, 0);
2815
+ context.lineTo(w - r2, 0);
2816
+
2817
+ if (r2 !== 0) {
2818
+ context.arc(w - r2, r2, r2, -Math.PI / 2, 0);
2819
+ }
2820
+
2821
+ context.lineTo(w, h - r3);
2822
+
2823
+ if (r3 !== 0) {
2824
+ context.arc(w - r3, h - r3, r3, 0, Math.PI / 2);
2825
+ }
2826
+
2827
+ context.lineTo(r4, h);
2325
2828
 
2326
2829
  if (r4 !== 0) {
2327
2830
  context.arc(r4, h - r4, r4, Math.PI / 2, Math.PI);
@@ -2398,7 +2901,9 @@
2398
2901
  var _parsedStyle$path = parsedStyle.path,
2399
2902
  curve = _parsedStyle$path.curve,
2400
2903
  zCommandIndexes = _parsedStyle$path.zCommandIndexes;
2401
- var path = [].concat(curve);
2904
+
2905
+ var path = _toConsumableArray(curve);
2906
+
2402
2907
  zCommandIndexes.forEach(function (zIndex, index) {
2403
2908
  path.splice(zIndex + index, 1, ['Z']);
2404
2909
  });
@@ -2455,127 +2960,46 @@
2455
2960
  multiple: false
2456
2961
  });
2457
2962
 
2458
- var ImagePool = /*#__PURE__*/function () {
2459
- function ImagePool() {
2460
- this.imageCache = {};
2461
- this.patternCache = {};
2462
- this.canvasConfig = void 0;
2463
- }
2464
-
2465
- var _proto = ImagePool.prototype;
2466
-
2467
- _proto.getImageSync = function getImageSync(src) {
2468
- return this.imageCache[src];
2469
- };
2470
-
2471
- _proto.getOrCreateImage = function getOrCreateImage(src) {
2472
- var _this = this;
2473
-
2474
- if (this.imageCache[src]) {
2475
- return Promise.resolve(this.imageCache[src]);
2476
- } // @see https://github.com/antvis/g/issues/938
2963
+ var ImageRenderer = /*#__PURE__*/function () {
2964
+ function ImageRenderer() {
2965
+ _classCallCheck$2(this, ImageRenderer);
2477
2966
 
2967
+ this.imagePool = void 0;
2968
+ }
2478
2969
 
2479
- var createImage = this.canvasConfig.createImage;
2480
- return new Promise(function (resolve, reject) {
2970
+ _createClass$2(ImageRenderer, [{
2971
+ key: "hash",
2972
+ value: function hash(parsedStyle) {
2973
+ return '';
2974
+ }
2975
+ }, {
2976
+ key: "render",
2977
+ value: function render(context, parsedStyle) {
2978
+ var width = parsedStyle.width,
2979
+ height = parsedStyle.height,
2980
+ img = parsedStyle.img;
2481
2981
  var image;
2982
+ var iw = width.value;
2983
+ var ih = height.value;
2482
2984
 
2483
- if (createImage) {
2484
- image = createImage(src);
2485
- } else if (g.isBrowser) {
2486
- image = new window.Image();
2985
+ if (g.isString(img)) {
2986
+ // image has been loaded in `mounted` hook
2987
+ image = this.imagePool.getImageSync(img);
2988
+ } else {
2989
+ iw || (iw = img.width);
2990
+ ih || (ih = img.height);
2991
+ image = img;
2487
2992
  }
2488
2993
 
2489
2994
  if (image) {
2490
- image.onload = function () {
2491
- resolve(image);
2492
- };
2493
-
2494
- image.onerror = function (ev) {
2495
- reject(ev);
2496
- };
2497
-
2498
- image.crossOrigin = 'Anonymous';
2499
- image.src = src;
2500
- _this.imageCache[src] = image;
2995
+ // node-canvas will throw the following err:
2996
+ // Error: Image given has not completed loading
2997
+ try {
2998
+ context.drawImage(image, 0, 0, iw, ih);
2999
+ } catch (e) {}
2501
3000
  }
2502
- });
2503
- };
2504
-
2505
- _proto.getPatternSync = function getPatternSync(pattern) {
2506
- var patternKey = this.generatePatternKey(pattern);
2507
-
2508
- if (this.patternCache[patternKey]) {
2509
- return this.patternCache[patternKey];
2510
- }
2511
- };
2512
-
2513
- _proto.createPattern = function createPattern(patternParams, context) {
2514
- var _this2 = this;
2515
-
2516
- return this.getOrCreateImage(patternParams.src).then(function (image) {
2517
- var patternKey = _this2.generatePatternKey(patternParams); // @see https://developer.mozilla.org/zh-CN/docs/Web/API/CanvasRenderingContext2D/createPattern
2518
-
2519
-
2520
- var pattern = context.createPattern(image, patternParams.repetition);
2521
-
2522
- if (pattern) {
2523
- _this2.patternCache[patternKey] = pattern;
2524
- }
2525
-
2526
- return _this2.patternCache[patternKey];
2527
- });
2528
- };
2529
-
2530
- _proto.generatePatternKey = function generatePatternKey(pattern) {
2531
- var src = pattern.src,
2532
- repetition = pattern.repetition;
2533
- return "pattern-" + src + "-" + repetition;
2534
- };
2535
-
2536
- return ImagePool;
2537
- }();
2538
-
2539
- __decorate([manaSyringe.inject(g.CanvasConfig), __metadata("design:type", Object)], ImagePool.prototype, "canvasConfig", void 0);
2540
-
2541
- ImagePool = __decorate([manaSyringe.singleton()], ImagePool);
2542
-
2543
- var ImageRenderer = /*#__PURE__*/function () {
2544
- function ImageRenderer() {
2545
- this.imagePool = void 0;
2546
- }
2547
-
2548
- var _proto = ImageRenderer.prototype;
2549
-
2550
- _proto.hash = function hash(parsedStyle) {
2551
- return '';
2552
- };
2553
-
2554
- _proto.render = function render(context, parsedStyle) {
2555
- var width = parsedStyle.width,
2556
- height = parsedStyle.height,
2557
- img = parsedStyle.img;
2558
- var image;
2559
- var iw = width.value;
2560
- var ih = height.value;
2561
-
2562
- if (g.isString(img)) {
2563
- // image has been loaded in `mounted` hook
2564
- image = this.imagePool.getImageSync(img);
2565
- } else {
2566
- iw || (iw = img.width);
2567
- ih || (ih = img.height);
2568
- image = img;
2569
- }
2570
-
2571
- if (image) {
2572
- // node-canvas will throw the following err:
2573
- // Error: Image given has not completed loading
2574
- try {
2575
- context.drawImage(image, 0, 0, iw, ih);
2576
- } catch (e) {}
2577
3001
  }
2578
- };
3002
+ }]);
2579
3003
 
2580
3004
  return ImageRenderer;
2581
3005
  }();
@@ -2587,158 +3011,162 @@
2587
3011
  })], ImageRenderer);
2588
3012
 
2589
3013
  var TextRenderer = /*#__PURE__*/function () {
2590
- function TextRenderer() {}
3014
+ function TextRenderer() {
3015
+ _classCallCheck$2(this, TextRenderer);
3016
+ }
3017
+
3018
+ _createClass$2(TextRenderer, [{
3019
+ key: "hash",
3020
+ value: function hash(parsedStyle) {
3021
+ return '';
3022
+ }
3023
+ }, {
3024
+ key: "render",
3025
+ value: function render(context, parsedStyle, object) {
3026
+ var lineWidth = parsedStyle.lineWidth,
3027
+ textAlign = parsedStyle.textAlign,
3028
+ textBaseline = parsedStyle.textBaseline,
3029
+ lineJoin = parsedStyle.lineJoin,
3030
+ _parsedStyle$miterLim = parsedStyle.miterLimit,
3031
+ miterLimit = _parsedStyle$miterLim === void 0 ? 0 : _parsedStyle$miterLim,
3032
+ _parsedStyle$letterSp = parsedStyle.letterSpacing,
3033
+ letterSpacing = _parsedStyle$letterSp === void 0 ? 0 : _parsedStyle$letterSp,
3034
+ stroke = parsedStyle.stroke,
3035
+ fill = parsedStyle.fill,
3036
+ fillOpacity = parsedStyle.fillOpacity,
3037
+ strokeOpacity = parsedStyle.strokeOpacity,
3038
+ opacity = parsedStyle.opacity,
3039
+ metrics = parsedStyle.metrics,
3040
+ dx = parsedStyle.dx,
3041
+ dy = parsedStyle.dy;
3042
+ var font = metrics.font,
3043
+ lines = metrics.lines,
3044
+ height = metrics.height,
3045
+ lineHeight = metrics.lineHeight,
3046
+ lineMetrics = metrics.lineMetrics;
3047
+ context.font = font;
3048
+ context.lineWidth = lineWidth.value;
3049
+ context.textAlign = textAlign.value;
3050
+ context.textBaseline = textBaseline.value;
3051
+ context.lineJoin = lineJoin.value;
3052
+ context.miterLimit = miterLimit;
3053
+ var linePositionY = 0; // handle vertical text baseline
3054
+
3055
+ if (textBaseline.value === 'middle') {
3056
+ linePositionY = -height / 2 - lineHeight / 2;
3057
+ } else if (textBaseline.value === 'bottom' || textBaseline.value === 'alphabetic' || textBaseline.value === 'ideographic') {
3058
+ linePositionY = -height;
3059
+ } else if (textBaseline.value === 'top' || textBaseline.value === 'hanging') {
3060
+ linePositionY = -lineHeight;
3061
+ } // account for dx & dy
3062
+
3063
+
3064
+ var offsetX = 0;
3065
+
3066
+ if (dx && dx.unit === g.UnitType.kPixels) {
3067
+ offsetX += dx.value;
3068
+ }
2591
3069
 
2592
- var _proto = TextRenderer.prototype;
3070
+ if (dy && dy.unit === g.UnitType.kPixels) {
3071
+ linePositionY += dy.value;
3072
+ } // draw lines line by line
2593
3073
 
2594
- _proto.hash = function hash(parsedStyle) {
2595
- return '';
2596
- };
2597
3074
 
2598
- _proto.render = function render(context, parsedStyle, object) {
2599
- var lineWidth = parsedStyle.lineWidth,
2600
- textAlign = parsedStyle.textAlign,
2601
- textBaseline = parsedStyle.textBaseline,
2602
- lineJoin = parsedStyle.lineJoin,
2603
- _parsedStyle$miterLim = parsedStyle.miterLimit,
2604
- miterLimit = _parsedStyle$miterLim === void 0 ? 0 : _parsedStyle$miterLim,
2605
- _parsedStyle$letterSp = parsedStyle.letterSpacing,
2606
- letterSpacing = _parsedStyle$letterSp === void 0 ? 0 : _parsedStyle$letterSp,
2607
- stroke = parsedStyle.stroke,
2608
- fill = parsedStyle.fill,
2609
- fillOpacity = parsedStyle.fillOpacity,
2610
- strokeOpacity = parsedStyle.strokeOpacity,
2611
- opacity = parsedStyle.opacity,
2612
- metrics = parsedStyle.metrics,
2613
- dx = parsedStyle.dx,
2614
- dy = parsedStyle.dy;
2615
- var font = metrics.font,
2616
- lines = metrics.lines,
2617
- height = metrics.height,
2618
- lineHeight = metrics.lineHeight,
2619
- lineMetrics = metrics.lineMetrics;
2620
- context.font = font;
2621
- context.lineWidth = lineWidth.value;
2622
- context.textAlign = textAlign.value;
2623
- context.textBaseline = textBaseline.value;
2624
- context.lineJoin = lineJoin.value;
2625
- context.miterLimit = miterLimit;
2626
- var linePositionY = 0; // handle vertical text baseline
2627
-
2628
- if (textBaseline.value === 'middle') {
2629
- linePositionY = -height / 2 - lineHeight / 2;
2630
- } else if (textBaseline.value === 'bottom' || textBaseline.value === 'alphabetic' || textBaseline.value === 'ideographic') {
2631
- linePositionY = -height;
2632
- } else if (textBaseline.value === 'top' || textBaseline.value === 'hanging') {
2633
- linePositionY = -lineHeight;
2634
- } // account for dx & dy
2635
-
2636
-
2637
- var offsetX = 0;
2638
-
2639
- if (dx && dx.unit === g.UnitType.kPixels) {
2640
- offsetX += dx.value;
2641
- }
2642
-
2643
- if (dy && dy.unit === g.UnitType.kPixels) {
2644
- linePositionY += dy.value;
2645
- } // draw lines line by line
2646
-
2647
-
2648
- for (var i = 0; i < lines.length; i++) {
2649
- var linePositionX = lineWidth.value / 2 + offsetX;
2650
- linePositionY += lineHeight; // no need to re-position X, cause we already set text align
2651
- // @see https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/textAlign
2652
-
2653
- if (!g.isNil(stroke) && lineWidth && lineWidth.value) {
2654
- this.drawLetterSpacing(context, lines[i], lineMetrics[i], textAlign.value, linePositionX, linePositionY, letterSpacing, fillOpacity.value, strokeOpacity.value, opacity.value, true);
2655
- }
3075
+ for (var i = 0; i < lines.length; i++) {
3076
+ var linePositionX = lineWidth.value / 2 + offsetX;
3077
+ linePositionY += lineHeight; // no need to re-position X, cause we already set text align
3078
+ // @see https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/textAlign
3079
+
3080
+ if (!g.isNil(stroke) && !stroke.isNone && lineWidth && lineWidth.value) {
3081
+ this.drawLetterSpacing(context, lines[i], lineMetrics[i], textAlign.value, linePositionX, linePositionY, letterSpacing, fillOpacity.value, strokeOpacity.value, opacity.value, true);
3082
+ }
2656
3083
 
2657
- if (!g.isNil(fill)) {
2658
- this.drawLetterSpacing(context, lines[i], lineMetrics[i], textAlign.value, linePositionX, linePositionY, letterSpacing, fillOpacity.value, strokeOpacity.value, opacity.value);
3084
+ if (!g.isNil(fill)) {
3085
+ this.drawLetterSpacing(context, lines[i], lineMetrics[i], textAlign.value, linePositionX, linePositionY, letterSpacing, fillOpacity.value, strokeOpacity.value, opacity.value);
3086
+ }
2659
3087
  }
2660
3088
  }
2661
- };
2662
-
2663
- _proto.drawLetterSpacing = function drawLetterSpacing(context, text, lineMetrics, textAlign, x, y, letterSpacing, fillOpacity, strokeOpacity, opacity, isStroke) {
2664
- if (isStroke === void 0) {
2665
- isStroke = false;
2666
- } // letterSpacing of 0 means normal, render all texts directly
3089
+ }, {
3090
+ key: "drawLetterSpacing",
3091
+ value: function drawLetterSpacing(context, text, lineMetrics, textAlign, x, y, letterSpacing, fillOpacity, strokeOpacity, opacity) {
3092
+ var isStroke = arguments.length > 10 && arguments[10] !== undefined ? arguments[10] : false; // letterSpacing of 0 means normal, render all texts directly
2667
3093
 
3094
+ if (letterSpacing === 0) {
3095
+ if (isStroke) {
3096
+ this.strokeText(context, text, x, y, strokeOpacity);
3097
+ } else {
3098
+ this.fillText(context, text, x, y, fillOpacity, opacity);
3099
+ }
2668
3100
 
2669
- if (letterSpacing === 0) {
2670
- if (isStroke) {
2671
- this.strokeText(context, text, x, y, strokeOpacity);
2672
- } else {
2673
- this.fillText(context, text, x, y, fillOpacity, opacity);
2674
- }
3101
+ return;
3102
+ } // draw text using left align
2675
3103
 
2676
- return;
2677
- } // draw text using left align
2678
3104
 
3105
+ var currentTextAlign = context.textAlign;
3106
+ context.textAlign = 'left';
3107
+ var currentPosition = x;
2679
3108
 
2680
- var currentTextAlign = context.textAlign;
2681
- context.textAlign = 'left';
2682
- var currentPosition = x;
3109
+ if (textAlign === 'center') {
3110
+ currentPosition = x - lineMetrics.width / 2;
3111
+ } else if (textAlign === 'right' || textAlign === 'end') {
3112
+ currentPosition = x - lineMetrics.width;
3113
+ }
2683
3114
 
2684
- if (textAlign === 'center') {
2685
- currentPosition = x - lineMetrics.width / 2;
2686
- } else if (textAlign === 'right' || textAlign === 'end') {
2687
- currentPosition = x - lineMetrics.width;
2688
- }
3115
+ var stringArray = Array.from(text);
3116
+ var previousWidth = context.measureText(text).width;
3117
+ var currentWidth = 0;
2689
3118
 
2690
- var stringArray = Array.from(text);
2691
- var previousWidth = context.measureText(text).width;
2692
- var currentWidth = 0;
3119
+ for (var i = 0; i < stringArray.length; ++i) {
3120
+ var currentChar = stringArray[i];
2693
3121
 
2694
- for (var i = 0; i < stringArray.length; ++i) {
2695
- var currentChar = stringArray[i];
3122
+ if (isStroke) {
3123
+ this.strokeText(context, currentChar, currentPosition, y, strokeOpacity);
3124
+ } else {
3125
+ this.fillText(context, currentChar, currentPosition, y, fillOpacity, opacity);
3126
+ }
2696
3127
 
2697
- if (isStroke) {
2698
- this.strokeText(context, currentChar, currentPosition, y, strokeOpacity);
2699
- } else {
2700
- this.fillText(context, currentChar, currentPosition, y, fillOpacity, opacity);
3128
+ currentWidth = context.measureText(text.substring(i + 1)).width;
3129
+ currentPosition += previousWidth - currentWidth + letterSpacing;
3130
+ previousWidth = currentWidth;
2701
3131
  }
2702
3132
 
2703
- currentWidth = context.measureText(text.substring(i + 1)).width;
2704
- currentPosition += previousWidth - currentWidth + letterSpacing;
2705
- previousWidth = currentWidth;
3133
+ context.textAlign = currentTextAlign;
2706
3134
  }
3135
+ }, {
3136
+ key: "fillText",
3137
+ value: function fillText(context, text, x, y, fillOpacity, opacity) {
3138
+ var currentGlobalAlpha;
3139
+ var applyOpacity = !g.isNil(fillOpacity) && fillOpacity !== 1;
2707
3140
 
2708
- context.textAlign = currentTextAlign;
2709
- };
2710
-
2711
- _proto.fillText = function fillText(context, text, x, y, fillOpacity, opacity) {
2712
- var currentGlobalAlpha;
2713
- var applyOpacity = !g.isNil(fillOpacity) && fillOpacity !== 1;
2714
-
2715
- if (applyOpacity) {
2716
- currentGlobalAlpha = context.globalAlpha;
2717
- context.globalAlpha = fillOpacity * opacity;
2718
- }
3141
+ if (applyOpacity) {
3142
+ currentGlobalAlpha = context.globalAlpha;
3143
+ context.globalAlpha = fillOpacity * opacity;
3144
+ }
2719
3145
 
2720
- context.fillText(text, x, y);
3146
+ context.fillText(text, x, y);
2721
3147
 
2722
- if (applyOpacity) {
2723
- context.globalAlpha = currentGlobalAlpha;
3148
+ if (applyOpacity) {
3149
+ context.globalAlpha = currentGlobalAlpha;
3150
+ }
2724
3151
  }
2725
- };
2726
-
2727
- _proto.strokeText = function strokeText(context, text, x, y, strokeOpacity) {
2728
- var currentGlobalAlpha;
2729
- var applyOpacity = !g.isNil(strokeOpacity) && strokeOpacity !== 1;
3152
+ }, {
3153
+ key: "strokeText",
3154
+ value: function strokeText(context, text, x, y, strokeOpacity) {
3155
+ var currentGlobalAlpha;
3156
+ var applyOpacity = !g.isNil(strokeOpacity) && strokeOpacity !== 1;
2730
3157
 
2731
- if (applyOpacity) {
2732
- currentGlobalAlpha = context.globalAlpha;
2733
- context.globalAlpha = strokeOpacity;
2734
- }
3158
+ if (applyOpacity) {
3159
+ currentGlobalAlpha = context.globalAlpha;
3160
+ context.globalAlpha = strokeOpacity;
3161
+ }
2735
3162
 
2736
- context.strokeText(text, x, y);
3163
+ context.strokeText(text, x, y);
2737
3164
 
2738
- if (applyOpacity) {
2739
- context.globalAlpha = currentGlobalAlpha;
3165
+ if (applyOpacity) {
3166
+ context.globalAlpha = currentGlobalAlpha;
3167
+ }
2740
3168
  }
2741
- };
3169
+ }]);
2742
3170
 
2743
3171
  return TextRenderer;
2744
3172
  }();
@@ -2748,115 +3176,119 @@
2748
3176
  })], TextRenderer);
2749
3177
 
2750
3178
  var DefaultRenderer = /*#__PURE__*/function () {
2751
- function DefaultRenderer() {}
2752
-
2753
- var _proto = DefaultRenderer.prototype;
2754
-
2755
- _proto.hash = function hash(parsedStyle) {
2756
- // const { fill, opacity, fillOpacity, stroke, strokeOpacity, lineWidth, lineCap, lineJoin } =
2757
- // parsedStyle;
2758
- // return fill + opacity + fillOpacity + stroke + strokeOpacity + lineWidth + lineCap + lineJoin;
2759
- return '';
2760
- };
2761
-
2762
- _proto.render = function render(context, parsedStyle) {
2763
- var fill = parsedStyle.fill,
2764
- opacity = parsedStyle.opacity,
2765
- fillOpacity = parsedStyle.fillOpacity,
2766
- stroke = parsedStyle.stroke,
2767
- strokeOpacity = parsedStyle.strokeOpacity,
2768
- lineWidth = parsedStyle.lineWidth,
2769
- lineCap = parsedStyle.lineCap,
2770
- lineJoin = parsedStyle.lineJoin,
2771
- shadowColor = parsedStyle.shadowColor,
2772
- filter = parsedStyle.filter,
2773
- miterLimit = parsedStyle.miterLimit;
2774
- var hasFill = !g.isNil(fill);
2775
- var hasStroke = !g.isNil(stroke);
2776
- var isFillTransparent = fill.alpha === 0;
2777
-
2778
- if (hasFill) {
2779
- if (!g.isNil(fillOpacity) && fillOpacity.value !== 1) {
2780
- context.globalAlpha = fillOpacity.value;
2781
- context.fill();
2782
- context.globalAlpha = opacity.value;
2783
- } else {
2784
- context.fill();
3179
+ function DefaultRenderer() {
3180
+ _classCallCheck$2(this, DefaultRenderer);
3181
+ }
3182
+
3183
+ _createClass$2(DefaultRenderer, [{
3184
+ key: "hash",
3185
+ value: function hash(parsedStyle) {
3186
+ // const { fill, opacity, fillOpacity, stroke, strokeOpacity, lineWidth, lineCap, lineJoin } =
3187
+ // parsedStyle;
3188
+ // return fill + opacity + fillOpacity + stroke + strokeOpacity + lineWidth + lineCap + lineJoin;
3189
+ return '';
3190
+ }
3191
+ }, {
3192
+ key: "render",
3193
+ value: function render(context, parsedStyle) {
3194
+ var fill = parsedStyle.fill,
3195
+ opacity = parsedStyle.opacity,
3196
+ fillOpacity = parsedStyle.fillOpacity,
3197
+ stroke = parsedStyle.stroke,
3198
+ strokeOpacity = parsedStyle.strokeOpacity,
3199
+ lineWidth = parsedStyle.lineWidth,
3200
+ lineCap = parsedStyle.lineCap,
3201
+ lineJoin = parsedStyle.lineJoin,
3202
+ shadowColor = parsedStyle.shadowColor,
3203
+ filter = parsedStyle.filter,
3204
+ miterLimit = parsedStyle.miterLimit;
3205
+ var hasFill = !g.isNil(fill) && !fill.isNone;
3206
+ var hasStroke = !g.isNil(stroke) && !stroke.isNone;
3207
+ var isFillTransparent = fill.alpha === 0;
3208
+
3209
+ if (hasFill) {
3210
+ if (!g.isNil(fillOpacity) && fillOpacity.value !== 1) {
3211
+ context.globalAlpha = fillOpacity.value;
3212
+ context.fill();
3213
+ context.globalAlpha = opacity.value;
3214
+ } else {
3215
+ context.fill();
3216
+ }
2785
3217
  }
2786
- }
2787
3218
 
2788
- if (hasStroke) {
2789
- if (lineWidth && lineWidth.value > 0) {
2790
- var applyOpacity = !g.isNil(strokeOpacity) && strokeOpacity.value !== 1;
3219
+ if (hasStroke) {
3220
+ if (lineWidth && lineWidth.value > 0) {
3221
+ var applyOpacity = !g.isNil(strokeOpacity) && strokeOpacity.value !== 1;
2791
3222
 
2792
- if (applyOpacity) {
2793
- context.globalAlpha = strokeOpacity.value;
2794
- }
3223
+ if (applyOpacity) {
3224
+ context.globalAlpha = strokeOpacity.value;
3225
+ }
2795
3226
 
2796
- context.lineWidth = lineWidth.value;
3227
+ context.lineWidth = lineWidth.value;
2797
3228
 
2798
- if (!g.isNil(miterLimit)) {
2799
- context.miterLimit = miterLimit;
2800
- }
3229
+ if (!g.isNil(miterLimit)) {
3230
+ context.miterLimit = miterLimit;
3231
+ }
2801
3232
 
2802
- if (!g.isNil(lineCap)) {
2803
- context.lineCap = lineCap.value;
2804
- }
3233
+ if (!g.isNil(lineCap)) {
3234
+ context.lineCap = lineCap.value;
3235
+ }
2805
3236
 
2806
- if (!g.isNil(lineJoin)) {
2807
- context.lineJoin = lineJoin.value;
2808
- }
3237
+ if (!g.isNil(lineJoin)) {
3238
+ context.lineJoin = lineJoin.value;
3239
+ }
2809
3240
 
2810
- var oldShadowBlur;
2811
- var oldShadowColor;
2812
- var oldFilter;
2813
- var hasShadowColor = !g.isNil(shadowColor);
2814
- var hasFilter = !g.isNil(filter);
2815
-
2816
- if (hasShadowColor) {
2817
- // prevent inner shadow when drawing stroke, toggle shadowBlur & filter(drop-shadow)
2818
- // save shadow blur
2819
- oldShadowBlur = context.shadowBlur;
2820
- oldShadowColor = context.shadowColor;
2821
-
2822
- if (!g.isNil(oldShadowBlur)) {
2823
- context.shadowColor = 'transparent';
2824
- context.shadowBlur = 0;
3241
+ var oldShadowBlur;
3242
+ var oldShadowColor;
3243
+ var oldFilter;
3244
+ var hasShadowColor = !g.isNil(shadowColor);
3245
+ var hasFilter = !g.isNil(filter);
3246
+
3247
+ if (hasShadowColor) {
3248
+ // prevent inner shadow when drawing stroke, toggle shadowBlur & filter(drop-shadow)
3249
+ // save shadow blur
3250
+ oldShadowBlur = context.shadowBlur;
3251
+ oldShadowColor = context.shadowColor;
3252
+
3253
+ if (!g.isNil(oldShadowBlur)) {
3254
+ context.shadowColor = 'transparent';
3255
+ context.shadowBlur = 0;
3256
+ }
2825
3257
  }
2826
- }
2827
3258
 
2828
- if (hasFilter) {
2829
- // save drop-shadow filter
2830
- oldFilter = context.filter;
3259
+ if (hasFilter) {
3260
+ // save drop-shadow filter
3261
+ oldFilter = context.filter;
2831
3262
 
2832
- if (!g.isNil(oldFilter) && oldFilter.indexOf('drop-shadow') > -1) {
2833
- context.filter = oldFilter.replace(/drop-shadow\([^)]*\)/, '').trim() || 'none';
3263
+ if (!g.isNil(oldFilter) && oldFilter.indexOf('drop-shadow') > -1) {
3264
+ context.filter = oldFilter.replace(/drop-shadow\([^)]*\)/, '').trim() || 'none';
3265
+ }
2834
3266
  }
2835
- }
2836
3267
 
2837
- var drawStroke = hasFill && !isFillTransparent;
3268
+ var drawStroke = hasFill && !isFillTransparent;
2838
3269
 
2839
- if (drawStroke) {
2840
- context.stroke();
2841
- } // restore shadow blur
3270
+ if (drawStroke) {
3271
+ context.stroke();
3272
+ } // restore shadow blur
2842
3273
 
2843
3274
 
2844
- if (hasShadowColor) {
2845
- context.shadowColor = oldShadowColor;
2846
- context.shadowBlur = oldShadowBlur;
2847
- } // restore filters
3275
+ if (hasShadowColor) {
3276
+ context.shadowColor = oldShadowColor;
3277
+ context.shadowBlur = oldShadowBlur;
3278
+ } // restore filters
2848
3279
 
2849
3280
 
2850
- if (hasFilter) {
2851
- context.filter = oldFilter;
2852
- }
3281
+ if (hasFilter) {
3282
+ context.filter = oldFilter;
3283
+ }
2853
3284
 
2854
- if (!drawStroke) {
2855
- context.stroke();
3285
+ if (!drawStroke) {
3286
+ context.stroke();
3287
+ }
2856
3288
  }
2857
3289
  }
2858
3290
  }
2859
- };
3291
+ }]);
2860
3292
 
2861
3293
  return DefaultRenderer;
2862
3294
  }();
@@ -2864,13 +3296,17 @@
2864
3296
  DefaultRenderer = __decorate([manaSyringe.singleton()], DefaultRenderer);
2865
3297
 
2866
3298
  var RectRenderer = /*#__PURE__*/function (_DefaultRenderer) {
2867
- _inheritsLoose$1(RectRenderer, _DefaultRenderer);
3299
+ _inherits$1(RectRenderer, _DefaultRenderer);
3300
+
3301
+ var _super = _createSuper$1(RectRenderer);
2868
3302
 
2869
3303
  function RectRenderer() {
2870
- return _DefaultRenderer.apply(this, arguments) || this;
3304
+ _classCallCheck$2(this, RectRenderer);
3305
+
3306
+ return _super.apply(this, arguments);
2871
3307
  }
2872
3308
 
2873
- return RectRenderer;
3309
+ return _createClass$2(RectRenderer);
2874
3310
  }(DefaultRenderer);
2875
3311
 
2876
3312
  RectRenderer = __decorate([manaSyringe.singleton({
@@ -2878,13 +3314,17 @@
2878
3314
  })], RectRenderer);
2879
3315
 
2880
3316
  var CircleRenderer = /*#__PURE__*/function (_DefaultRenderer) {
2881
- _inheritsLoose$1(CircleRenderer, _DefaultRenderer);
3317
+ _inherits$1(CircleRenderer, _DefaultRenderer);
3318
+
3319
+ var _super = _createSuper$1(CircleRenderer);
2882
3320
 
2883
3321
  function CircleRenderer() {
2884
- return _DefaultRenderer.apply(this, arguments) || this;
3322
+ _classCallCheck$2(this, CircleRenderer);
3323
+
3324
+ return _super.apply(this, arguments);
2885
3325
  }
2886
3326
 
2887
- return CircleRenderer;
3327
+ return _createClass$2(CircleRenderer);
2888
3328
  }(DefaultRenderer);
2889
3329
 
2890
3330
  CircleRenderer = __decorate([manaSyringe.singleton({
@@ -2892,13 +3332,17 @@
2892
3332
  })], CircleRenderer);
2893
3333
 
2894
3334
  var EllipseRenderer = /*#__PURE__*/function (_DefaultRenderer) {
2895
- _inheritsLoose$1(EllipseRenderer, _DefaultRenderer);
3335
+ _inherits$1(EllipseRenderer, _DefaultRenderer);
3336
+
3337
+ var _super = _createSuper$1(EllipseRenderer);
2896
3338
 
2897
3339
  function EllipseRenderer() {
2898
- return _DefaultRenderer.apply(this, arguments) || this;
3340
+ _classCallCheck$2(this, EllipseRenderer);
3341
+
3342
+ return _super.apply(this, arguments);
2899
3343
  }
2900
3344
 
2901
- return EllipseRenderer;
3345
+ return _createClass$2(EllipseRenderer);
2902
3346
  }(DefaultRenderer);
2903
3347
 
2904
3348
  EllipseRenderer = __decorate([manaSyringe.singleton({
@@ -2906,13 +3350,17 @@
2906
3350
  })], EllipseRenderer);
2907
3351
 
2908
3352
  var LineRenderer = /*#__PURE__*/function (_DefaultRenderer) {
2909
- _inheritsLoose$1(LineRenderer, _DefaultRenderer);
3353
+ _inherits$1(LineRenderer, _DefaultRenderer);
3354
+
3355
+ var _super = _createSuper$1(LineRenderer);
2910
3356
 
2911
3357
  function LineRenderer() {
2912
- return _DefaultRenderer.apply(this, arguments) || this;
3358
+ _classCallCheck$2(this, LineRenderer);
3359
+
3360
+ return _super.apply(this, arguments);
2913
3361
  }
2914
3362
 
2915
- return LineRenderer;
3363
+ return _createClass$2(LineRenderer);
2916
3364
  }(DefaultRenderer);
2917
3365
 
2918
3366
  LineRenderer = __decorate([manaSyringe.singleton({
@@ -2920,13 +3368,17 @@
2920
3368
  })], LineRenderer);
2921
3369
 
2922
3370
  var PolylineRenderer = /*#__PURE__*/function (_DefaultRenderer) {
2923
- _inheritsLoose$1(PolylineRenderer, _DefaultRenderer);
3371
+ _inherits$1(PolylineRenderer, _DefaultRenderer);
3372
+
3373
+ var _super = _createSuper$1(PolylineRenderer);
2924
3374
 
2925
3375
  function PolylineRenderer() {
2926
- return _DefaultRenderer.apply(this, arguments) || this;
3376
+ _classCallCheck$2(this, PolylineRenderer);
3377
+
3378
+ return _super.apply(this, arguments);
2927
3379
  }
2928
3380
 
2929
- return PolylineRenderer;
3381
+ return _createClass$2(PolylineRenderer);
2930
3382
  }(DefaultRenderer);
2931
3383
 
2932
3384
  PolylineRenderer = __decorate([manaSyringe.singleton({
@@ -2934,13 +3386,17 @@
2934
3386
  })], PolylineRenderer);
2935
3387
 
2936
3388
  var PolygonRenderer = /*#__PURE__*/function (_DefaultRenderer) {
2937
- _inheritsLoose$1(PolygonRenderer, _DefaultRenderer);
3389
+ _inherits$1(PolygonRenderer, _DefaultRenderer);
3390
+
3391
+ var _super = _createSuper$1(PolygonRenderer);
2938
3392
 
2939
3393
  function PolygonRenderer() {
2940
- return _DefaultRenderer.apply(this, arguments) || this;
3394
+ _classCallCheck$2(this, PolygonRenderer);
3395
+
3396
+ return _super.apply(this, arguments);
2941
3397
  }
2942
3398
 
2943
- return PolygonRenderer;
3399
+ return _createClass$2(PolygonRenderer);
2944
3400
  }(DefaultRenderer);
2945
3401
 
2946
3402
  PolygonRenderer = __decorate([manaSyringe.singleton({
@@ -2948,93 +3404,23 @@
2948
3404
  })], PolygonRenderer);
2949
3405
 
2950
3406
  var PathRenderer = /*#__PURE__*/function (_DefaultRenderer) {
2951
- _inheritsLoose$1(PathRenderer, _DefaultRenderer);
3407
+ _inherits$1(PathRenderer, _DefaultRenderer);
3408
+
3409
+ var _super = _createSuper$1(PathRenderer);
2952
3410
 
2953
3411
  function PathRenderer() {
2954
- return _DefaultRenderer.apply(this, arguments) || this;
3412
+ _classCallCheck$2(this, PathRenderer);
3413
+
3414
+ return _super.apply(this, arguments);
2955
3415
  }
2956
3416
 
2957
- return PathRenderer;
3417
+ return _createClass$2(PathRenderer);
2958
3418
  }(DefaultRenderer);
2959
3419
 
2960
3420
  PathRenderer = __decorate([manaSyringe.singleton({
2961
3421
  token: PathRendererContribution
2962
3422
  })], PathRenderer);
2963
3423
 
2964
- var GradientPool = /*#__PURE__*/function () {
2965
- function GradientPool() {
2966
- this.gradientCache = {};
2967
- }
2968
-
2969
- var _proto = GradientPool.prototype;
2970
-
2971
- _proto.getOrCreateGradient = function getOrCreateGradient(params, context) {
2972
- var key = this.generateCacheKey(params);
2973
- var type = params.type,
2974
- x0 = params.x0,
2975
- y0 = params.y0,
2976
- x1 = params.x1,
2977
- y1 = params.y1,
2978
- steps = params.steps,
2979
- width = params.width,
2980
- height = params.height;
2981
-
2982
- if (this.gradientCache[key]) {
2983
- return this.gradientCache[key];
2984
- }
2985
-
2986
- var gradient = null;
2987
-
2988
- if (type === g.GradientPatternType.LinearGradient) {
2989
- // @see https://developer.mozilla.org/zh-CN/docs/Web/API/CanvasRenderingContext2D/createLinearGradient
2990
- gradient = context.createLinearGradient(x0 * width, y0 * height, x1 * width, y1 * height);
2991
- } else if (type === g.GradientPatternType.RadialGradient) {
2992
- var r = Math.sqrt(width * width + height * height) / 2; // @see https://developer.mozilla.org/zh-CN/docs/Web/API/CanvasRenderingContext2D/createRadialGradient
2993
-
2994
- gradient = context.createRadialGradient(x0 * width, y0 * height, 0, x1 * width, y1 * height, params.r1 * r);
2995
- }
2996
-
2997
- if (gradient) {
2998
- steps.forEach(function (_ref) {
2999
- var _gradient;
3000
-
3001
- var offset = _ref[0],
3002
- color = _ref[1];
3003
- (_gradient = gradient) === null || _gradient === void 0 ? void 0 : _gradient.addColorStop(Number(offset), color);
3004
- });
3005
- this.gradientCache[key] = gradient;
3006
- }
3007
-
3008
- return this.gradientCache[key];
3009
- };
3010
-
3011
- _proto.generateCacheKey = function generateCacheKey(params) {
3012
- // @ts-ignore
3013
- var type = params.type,
3014
- x0 = params.x0,
3015
- y0 = params.y0,
3016
- x1 = params.x1,
3017
- y1 = params.y1,
3018
- r1 = params.r1,
3019
- steps = params.steps,
3020
- width = params.width,
3021
- height = params.height;
3022
- return "gradient-" + type + "-" + x0 + "-" + y0 + "-" + x1 + "-" + y1 + "-" + (r1 || 0) + "-" + width + "-" + height + "-" + steps.map(function (step) {
3023
- return step.join('');
3024
- }).join('-');
3025
- };
3026
-
3027
- return GradientPool;
3028
- }();
3029
-
3030
- GradientPool = __decorate([manaSyringe.singleton()], GradientPool);
3031
-
3032
- var RBushNode = function RBushNode() {
3033
- this.aabb = void 0;
3034
- };
3035
-
3036
- RBushNode.tag = 'c-canvas-rbush-node';
3037
-
3038
3424
  var _class$1;
3039
3425
 
3040
3426
  var CanvasRendererPlugin_1;
@@ -3047,6 +3433,8 @@
3047
3433
 
3048
3434
  var CanvasRendererPlugin = CanvasRendererPlugin_1 = (_class$1 = /*#__PURE__*/function () {
3049
3435
  function CanvasRendererPlugin() {
3436
+ _classCallCheck$2(this, CanvasRendererPlugin);
3437
+
3050
3438
  this.canvasConfig = void 0;
3051
3439
  this.camera = void 0;
3052
3440
  this.contextService = void 0;
@@ -3067,619 +3455,641 @@
3067
3455
  this.toSync = new Set();
3068
3456
  }
3069
3457
 
3070
- var _proto = CanvasRendererPlugin.prototype;
3071
-
3072
- _proto.syncRTree = function syncRTree() {
3073
- var _this = this; // bounds changed, need re-inserting its children
3458
+ _createClass$2(CanvasRendererPlugin, [{
3459
+ key: "syncRTree",
3460
+ value: function syncRTree() {
3461
+ var _this = this; // bounds changed, need re-inserting its children
3074
3462
 
3075
3463
 
3076
- var bulk = [];
3077
- Array.from(this.toSync) // some objects may be removed since last frame
3078
- .filter(function (object) {
3079
- return object.isConnected;
3080
- }).forEach(function (node) {
3081
- // @ts-ignore
3082
- var rBushNode = node.rBushNode; // clear dirty node
3464
+ var bulk = [];
3465
+ Array.from(this.toSync) // some objects may be removed since last frame
3466
+ .filter(function (object) {
3467
+ return object.isConnected;
3468
+ }).forEach(function (node) {
3469
+ // @ts-ignore
3470
+ var rBushNode = node.rBushNode; // clear dirty node
3083
3471
 
3084
- if (rBushNode) {
3085
- _this.rBush.remove(rBushNode.aabb);
3086
- }
3472
+ if (rBushNode) {
3473
+ _this.rBush.remove(rBushNode.aabb);
3474
+ }
3087
3475
 
3088
- var renderBounds = node.getRenderBounds();
3476
+ var renderBounds = node.getRenderBounds();
3477
+
3478
+ if (renderBounds) {
3479
+ var _renderBounds$getMin = renderBounds.getMin(),
3480
+ _renderBounds$getMin2 = _slicedToArray(_renderBounds$getMin, 2),
3481
+ minX = _renderBounds$getMin2[0],
3482
+ minY = _renderBounds$getMin2[1];
3483
+
3484
+ var _renderBounds$getMax = renderBounds.getMax(),
3485
+ _renderBounds$getMax2 = _slicedToArray(_renderBounds$getMax, 2),
3486
+ maxX = _renderBounds$getMax2[0],
3487
+ maxY = _renderBounds$getMax2[1];
3488
+
3489
+ rBushNode.aabb = {
3490
+ id: node.entity,
3491
+ minX: minX,
3492
+ minY: minY,
3493
+ maxX: maxX,
3494
+ maxY: maxY
3495
+ };
3496
+ }
3089
3497
 
3090
- if (renderBounds) {
3091
- var _renderBounds$getMin = renderBounds.getMin(),
3092
- minX = _renderBounds$getMin[0],
3093
- minY = _renderBounds$getMin[1];
3094
-
3095
- var _renderBounds$getMax = renderBounds.getMax(),
3096
- maxX = _renderBounds$getMax[0],
3097
- maxY = _renderBounds$getMax[1];
3098
-
3099
- rBushNode.aabb = {
3100
- id: node.entity,
3101
- minX: minX,
3102
- minY: minY,
3103
- maxX: maxX,
3104
- maxY: maxY
3105
- };
3106
- }
3498
+ if (rBushNode.aabb) {
3499
+ bulk.push(rBushNode.aabb);
3500
+ }
3501
+ }); // use bulk inserting, which is ~2-3 times faster
3502
+ // @see https://github.com/mourner/rbush#bulk-inserting-data
3107
3503
 
3108
- if (rBushNode.aabb) {
3109
- bulk.push(rBushNode.aabb);
3110
- }
3111
- }); // use bulk inserting, which is ~2-3 times faster
3112
- // @see https://github.com/mourner/rbush#bulk-inserting-data
3504
+ this.rBush.load(bulk);
3505
+ this.toSync.clear();
3506
+ }
3507
+ /**
3508
+ * sync to RBush later
3509
+ */
3113
3510
 
3114
- this.rBush.load(bulk);
3115
- this.toSync.clear();
3116
- }
3117
- /**
3118
- * sync to RBush later
3119
- */
3120
- ;
3511
+ }, {
3512
+ key: "pushToSync",
3513
+ value: function pushToSync(list) {
3514
+ var _this2 = this;
3121
3515
 
3122
- _proto.pushToSync = function pushToSync(list) {
3123
- var _this2 = this;
3516
+ list.forEach(function (i) {
3517
+ _this2.toSync.add(i);
3518
+ });
3519
+ }
3520
+ }, {
3521
+ key: "apply",
3522
+ value: function apply(renderingService) {
3523
+ var _this3 = this;
3124
3524
 
3125
- list.forEach(function (i) {
3126
- _this2.toSync.add(i);
3127
- });
3128
- };
3525
+ var handleMounted = function handleMounted(e) {
3526
+ var object = e.target; // @ts-ignore
3129
3527
 
3130
- _proto.apply = function apply(renderingService) {
3131
- var _this3 = this;
3528
+ object.rBushNode = new RBushNode();
3132
3529
 
3133
- var handleMounted = function handleMounted(e) {
3134
- var object = e.target; // @ts-ignore
3530
+ _this3.pushToSync(e.composedPath().slice(0, -2));
3531
+ };
3135
3532
 
3136
- object.rBushNode = new RBushNode();
3533
+ var handleUnmounted = function handleUnmounted(e) {
3534
+ var object = e.target; // remove r-bush node
3535
+ // @ts-ignore
3137
3536
 
3138
- _this3.pushToSync(e.composedPath().slice(0, -2));
3139
- };
3537
+ var rBushNode = object.rBushNode;
3140
3538
 
3141
- var handleUnmounted = function handleUnmounted(e) {
3142
- var object = e.target; // remove r-bush node
3143
- // @ts-ignore
3539
+ if (rBushNode.aabb) {
3540
+ _this3.rBush.remove(rBushNode.aabb);
3144
3541
 
3145
- var rBushNode = object.rBushNode;
3542
+ _this3.toSync.delete(object); // save removed aabbs for dirty-rectangle rendering later
3146
3543
 
3147
- if (rBushNode.aabb) {
3148
- _this3.rBush.remove(rBushNode.aabb);
3149
3544
 
3150
- _this3.toSync.delete(object); // save removed aabbs for dirty-rectangle rendering later
3545
+ _this3.removedRBushNodeAABBs.push(rBushNode.aabb);
3546
+ }
3547
+ };
3151
3548
 
3549
+ var handleBoundsChanged = function handleBoundsChanged(e) {
3550
+ var _object$ownerDocument;
3152
3551
 
3153
- _this3.removedRBushNodeAABBs.push(rBushNode.aabb);
3154
- }
3155
- };
3552
+ var object = e.target; // skip if this object mounted on another scenegraph root
3156
3553
 
3157
- var handleBoundsChanged = function handleBoundsChanged(e) {
3158
- var _object$ownerDocument;
3554
+ if (((_object$ownerDocument = object.ownerDocument) === null || _object$ownerDocument === void 0 ? void 0 : _object$ownerDocument.documentElement) !== _this3.renderingContext.root) {
3555
+ return;
3556
+ }
3159
3557
 
3160
- var object = e.target; // skip if this object mounted on another scenegraph root
3558
+ var affectChildren = e.detail.affectChildren;
3161
3559
 
3162
- if (((_object$ownerDocument = object.ownerDocument) === null || _object$ownerDocument === void 0 ? void 0 : _object$ownerDocument.documentElement) !== _this3.renderingContext.root) {
3163
- return;
3164
- }
3560
+ if (affectChildren) {
3561
+ object.forEach(function (node) {
3562
+ _this3.pushToSync([node]);
3563
+ });
3564
+ }
3165
3565
 
3166
- var affectChildren = e.detail.affectChildren;
3566
+ _this3.pushToSync(e.composedPath().slice(0, -2));
3567
+ };
3167
3568
 
3168
- if (affectChildren) {
3169
- object.forEach(function (node) {
3170
- _this3.pushToSync([node]);
3171
- });
3172
- }
3569
+ renderingService.hooks.init.tapPromise(CanvasRendererPlugin_1.tag, /*#__PURE__*/_asyncToGenerator$1( /*#__PURE__*/_regeneratorRuntime$1().mark(function _callee() {
3570
+ var _this3$canvasConfig, width, height, context;
3173
3571
 
3174
- _this3.pushToSync(e.composedPath().slice(0, -2));
3175
- };
3572
+ return _regeneratorRuntime$1().wrap(function _callee$(_context) {
3573
+ while (1) {
3574
+ switch (_context.prev = _context.next) {
3575
+ case 0:
3576
+ _this3.renderingContext.root.addEventListener(g.ElementEvent.MOUNTED, handleMounted);
3176
3577
 
3177
- renderingService.hooks.init.tapPromise(CanvasRendererPlugin_1.tag, /*#__PURE__*/_asyncToGenerator$1( /*#__PURE__*/_regeneratorRuntime$1().mark(function _callee() {
3178
- var _this3$canvasConfig, width, height, context;
3578
+ _this3.renderingContext.root.addEventListener(g.ElementEvent.UNMOUNTED, handleUnmounted);
3179
3579
 
3180
- return _regeneratorRuntime$1().wrap(function _callee$(_context) {
3181
- while (1) {
3182
- switch (_context.prev = _context.next) {
3183
- case 0:
3184
- _this3.renderingContext.root.addEventListener(g.ElementEvent.MOUNTED, handleMounted);
3580
+ _this3.renderingContext.root.addEventListener(g.ElementEvent.BOUNDS_CHANGED, handleBoundsChanged); // clear fullscreen
3185
3581
 
3186
- _this3.renderingContext.root.addEventListener(g.ElementEvent.UNMOUNTED, handleUnmounted);
3187
3582
 
3188
- _this3.renderingContext.root.addEventListener(g.ElementEvent.BOUNDS_CHANGED, handleBoundsChanged); // clear fullscreen
3583
+ _this3$canvasConfig = _this3.canvasConfig, width = _this3$canvasConfig.width, height = _this3$canvasConfig.height;
3584
+ context = _this3.contextService.getContext();
3189
3585
 
3586
+ _this3.clearRect(context, 0, 0, width, height);
3190
3587
 
3191
- _this3$canvasConfig = _this3.canvasConfig, width = _this3$canvasConfig.width, height = _this3$canvasConfig.height;
3192
- context = _this3.contextService.getContext();
3588
+ case 6:
3589
+ case "end":
3590
+ return _context.stop();
3591
+ }
3592
+ }
3593
+ }, _callee);
3594
+ })));
3595
+ renderingService.hooks.destroy.tap(CanvasRendererPlugin_1.tag, function () {
3596
+ _this3.renderingContext.root.removeEventListener(g.ElementEvent.MOUNTED, handleMounted);
3193
3597
 
3194
- _this3.clearRect(context, 0, 0, width, height);
3598
+ _this3.renderingContext.root.removeEventListener(g.ElementEvent.UNMOUNTED, handleUnmounted);
3195
3599
 
3196
- case 6:
3197
- case "end":
3198
- return _context.stop();
3199
- }
3200
- }
3201
- }, _callee);
3202
- })));
3203
- renderingService.hooks.destroy.tap(CanvasRendererPlugin_1.tag, function () {
3204
- _this3.renderingContext.root.removeEventListener(g.ElementEvent.MOUNTED, handleMounted);
3600
+ _this3.renderingContext.root.removeEventListener(g.ElementEvent.BOUNDS_CHANGED, handleBoundsChanged);
3601
+ });
3602
+ renderingService.hooks.beginFrame.tap(CanvasRendererPlugin_1.tag, function () {
3603
+ var context = _this3.contextService.getContext();
3205
3604
 
3206
- _this3.renderingContext.root.removeEventListener(g.ElementEvent.UNMOUNTED, handleUnmounted);
3605
+ var _this3$canvasConfig2 = _this3.canvasConfig,
3606
+ renderer = _this3$canvasConfig2.renderer,
3607
+ width = _this3$canvasConfig2.width,
3608
+ height = _this3$canvasConfig2.height;
3207
3609
 
3208
- _this3.renderingContext.root.removeEventListener(g.ElementEvent.BOUNDS_CHANGED, handleBoundsChanged);
3209
- });
3210
- renderingService.hooks.beginFrame.tap(CanvasRendererPlugin_1.tag, function () {
3211
- var context = _this3.contextService.getContext();
3610
+ var _renderer$getConfig = renderer.getConfig(),
3611
+ enableDirtyRectangleRendering = _renderer$getConfig.enableDirtyRectangleRendering; // clear fullscreen when:
3612
+ // 1. dirty rectangle rendering disabled
3613
+ // 2. camera changed
3212
3614
 
3213
- var _this3$canvasConfig2 = _this3.canvasConfig,
3214
- renderer = _this3$canvasConfig2.renderer,
3215
- width = _this3$canvasConfig2.width,
3216
- height = _this3$canvasConfig2.height;
3217
3615
 
3218
- var _renderer$getConfig = renderer.getConfig(),
3219
- enableDirtyRectangleRendering = _renderer$getConfig.enableDirtyRectangleRendering; // clear fullscreen when:
3220
- // 1. dirty rectangle rendering disabled
3221
- // 2. camera changed
3616
+ _this3.clearFullScreen = !enableDirtyRectangleRendering || _this3.renderingContext.renderReasons.has(g.RenderReason.CAMERA_CHANGED);
3222
3617
 
3618
+ if (context) {
3619
+ context.save();
3223
3620
 
3224
- _this3.clearFullScreen = !enableDirtyRectangleRendering || _this3.renderingContext.renderReasons.has(g.RenderReason.CAMERA_CHANGED);
3621
+ if (_this3.clearFullScreen) {
3622
+ _this3.clearRect(context, 0, 0, width, height);
3623
+ } // account for camera's world matrix
3225
3624
 
3226
- if (context) {
3227
- context.save();
3228
3625
 
3229
- if (_this3.clearFullScreen) {
3230
- _this3.clearRect(context, 0, 0, width, height);
3231
- } // account for camera's world matrix
3626
+ _this3.applyTransform(context, _this3.camera.getOrthoMatrix());
3627
+ }
3628
+ }); // render at the end of frame
3232
3629
 
3630
+ renderingService.hooks.endFrame.tap(CanvasRendererPlugin_1.tag, function () {
3631
+ _this3.syncRTree();
3233
3632
 
3234
- _this3.applyTransform(context, _this3.camera.getOrthoMatrix());
3235
- }
3236
- }); // render at the end of frame
3633
+ var _this3$canvasConfig$r = _this3.canvasConfig.renderer.getConfig(),
3634
+ enableDirtyRectangleRendering = _this3$canvasConfig$r.enableDirtyRectangleRendering,
3635
+ enableDirtyRectangleRenderingDebug = _this3$canvasConfig$r.enableDirtyRectangleRenderingDebug;
3237
3636
 
3238
- renderingService.hooks.endFrame.tap(CanvasRendererPlugin_1.tag, function () {
3239
- _this3.syncRTree();
3637
+ var context = _this3.contextService.getContext();
3240
3638
 
3241
- var _this3$canvasConfig$r = _this3.canvasConfig.renderer.getConfig(),
3242
- enableDirtyRectangleRendering = _this3$canvasConfig$r.enableDirtyRectangleRendering,
3243
- enableDirtyRectangleRenderingDebug = _this3$canvasConfig$r.enableDirtyRectangleRenderingDebug;
3639
+ var dirtyObjects = _this3.renderQueue;
3244
3640
 
3245
- var context = _this3.contextService.getContext();
3641
+ if (enableDirtyRectangleRendering) {
3642
+ // eg. camera changed
3643
+ if (!_this3.clearFullScreen) {
3644
+ // merge removed AABB
3645
+ var dirtyRenderBounds = _this3.safeMergeAABB.apply(_this3, [_this3.mergeDirtyAABBs( // should not ignore group since clipPath may affect its children
3646
+ // this.renderQueue.filter((o) => o.nodeName !== Shape.GROUP)),
3647
+ _this3.renderQueue)].concat(_toConsumableArray(_this3.removedRBushNodeAABBs.map(function (_ref2) {
3648
+ var minX = _ref2.minX,
3649
+ minY = _ref2.minY,
3650
+ maxX = _ref2.maxX,
3651
+ maxY = _ref2.maxY;
3652
+ var aabb = new g.AABB();
3653
+ aabb.setMinMax(fromValues(minX, minY, 0), fromValues(maxX, maxY, 0));
3654
+ return aabb;
3655
+ }))));
3246
3656
 
3247
- var dirtyObjects = _this3.renderQueue;
3657
+ _this3.removedRBushNodeAABBs = [];
3248
3658
 
3249
- if (enableDirtyRectangleRendering) {
3250
- // eg. camera changed
3251
- if (!_this3.clearFullScreen) {
3252
- // merge removed AABB
3253
- var dirtyRenderBounds = _this3.safeMergeAABB.apply(_this3, [_this3.mergeDirtyAABBs( // should not ignore group since clipPath may affect its children
3254
- // this.renderQueue.filter((o) => o.nodeName !== Shape.GROUP)),
3255
- _this3.renderQueue)].concat(_this3.removedRBushNodeAABBs.map(function (_ref2) {
3256
- var minX = _ref2.minX,
3257
- minY = _ref2.minY,
3258
- maxX = _ref2.maxX,
3259
- maxY = _ref2.maxY;
3260
- var aabb = new g.AABB();
3261
- aabb.setMinMax(fromValues(minX, minY, 0), fromValues(maxX, maxY, 0));
3262
- return aabb;
3263
- })));
3659
+ if (g.AABB.isEmpty(dirtyRenderBounds)) {
3660
+ _this3.renderQueue = [];
3661
+ return;
3662
+ } // clear & clip dirty rectangle
3264
3663
 
3265
- _this3.removedRBushNodeAABBs = [];
3266
3664
 
3267
- if (g.AABB.isEmpty(dirtyRenderBounds)) {
3268
- _this3.renderQueue = [];
3269
- return;
3270
- } // clear & clip dirty rectangle
3665
+ var _this3$convertAABB2Re = _this3.convertAABB2Rect(dirtyRenderBounds),
3666
+ x = _this3$convertAABB2Re.x,
3667
+ y = _this3$convertAABB2Re.y,
3668
+ width = _this3$convertAABB2Re.width,
3669
+ height = _this3$convertAABB2Re.height;
3271
3670
 
3671
+ _this3.clearRect(context, x, y, width, height);
3272
3672
 
3273
- var _this3$convertAABB2Re = _this3.convertAABB2Rect(dirtyRenderBounds),
3274
- x = _this3$convertAABB2Re.x,
3275
- y = _this3$convertAABB2Re.y,
3276
- width = _this3$convertAABB2Re.width,
3277
- height = _this3$convertAABB2Re.height;
3673
+ context.beginPath();
3674
+ context.rect(x, y, width, height);
3675
+ context.clip(); // draw dirty rectangle
3278
3676
 
3279
- _this3.clearRect(context, x, y, width, height);
3677
+ if (enableDirtyRectangleRenderingDebug) {
3678
+ context.lineWidth = 4;
3679
+ context.strokeStyle = "rgba(".concat(Math.random() * 255, ", ").concat(Math.random() * 255, ", ").concat(Math.random() * 255, ", 1)");
3680
+ context.strokeRect(x, y, width, height);
3681
+ } // search objects intersect with dirty rectangle
3280
3682
 
3281
- context.beginPath();
3282
- context.rect(x, y, width, height);
3283
- context.clip(); // draw dirty rectangle
3284
3683
 
3285
- if (enableDirtyRectangleRenderingDebug) {
3286
- context.lineWidth = 4;
3287
- context.strokeStyle = "rgba(" + Math.random() * 255 + ", " + Math.random() * 255 + ", " + Math.random() * 255 + ", 1)";
3288
- context.strokeRect(x, y, width, height);
3289
- } // search objects intersect with dirty rectangle
3684
+ dirtyObjects = _this3.searchDirtyObjects(dirtyRenderBounds);
3685
+ } // do rendering
3290
3686
 
3291
3687
 
3292
- dirtyObjects = _this3.searchDirtyObjects(dirtyRenderBounds);
3293
- } // do rendering
3688
+ dirtyObjects // sort by z-index
3689
+ .sort(function (a, b) {
3690
+ return a.sortable.renderOrder - b.sortable.renderOrder;
3691
+ }).forEach(function (object) {
3692
+ // culled object should not be rendered
3693
+ if (object && object.isVisible() && !object.isCulled()) {
3694
+ _this3.renderDisplayObject(object, renderingService);
3695
+ }
3696
+ });
3294
3697
 
3698
+ if (_this3.enableBatch && _this3.batchedStyleHash) {
3699
+ _this3.flush(context, renderingService);
3700
+ } // save dirty AABBs in last frame
3295
3701
 
3296
- dirtyObjects // sort by z-index
3297
- .sort(function (a, b) {
3298
- return a.sortable.renderOrder - b.sortable.renderOrder;
3299
- }).forEach(function (object) {
3300
- // culled object should not be rendered
3301
- if (object && object.isVisible() && !object.isCulled()) {
3302
- _this3.renderDisplayObject(object, renderingService);
3303
- }
3304
- });
3305
3702
 
3306
- if (_this3.enableBatch && _this3.batchedStyleHash) {
3307
- _this3.flush(context, renderingService);
3308
- } // save dirty AABBs in last frame
3703
+ _this3.renderQueue.forEach(function (object) {
3704
+ _this3.saveDirtyAABB(object);
3705
+ }); // clear queue
3309
3706
 
3310
3707
 
3311
- _this3.renderQueue.forEach(function (object) {
3312
- _this3.saveDirtyAABB(object);
3313
- }); // clear queue
3708
+ _this3.renderQueue = [];
3709
+ } // pop restore stack, eg. root -> parent -> child
3314
3710
 
3315
3711
 
3316
- _this3.renderQueue = [];
3317
- } // pop restore stack, eg. root -> parent -> child
3712
+ _this3.restoreStack.forEach(function (s) {
3713
+ context.restore();
3714
+ }); // clear restore stack
3318
3715
 
3319
3716
 
3320
- _this3.restoreStack.forEach(function (s) {
3717
+ _this3.restoreStack = [];
3718
+ _this3.clearFullScreen = false;
3321
3719
  context.restore();
3322
- }); // clear restore stack
3323
-
3720
+ });
3721
+ renderingService.hooks.render.tap(CanvasRendererPlugin_1.tag, function (object) {
3722
+ var _this3$canvasConfig$r2 = _this3.canvasConfig.renderer.getConfig(),
3723
+ enableDirtyRectangleRendering = _this3$canvasConfig$r2.enableDirtyRectangleRendering;
3324
3724
 
3325
- _this3.restoreStack = [];
3326
- _this3.clearFullScreen = false;
3327
- context.restore();
3328
- });
3329
- renderingService.hooks.render.tap(CanvasRendererPlugin_1.tag, function (object) {
3330
- var _this3$canvasConfig$r2 = _this3.canvasConfig.renderer.getConfig(),
3331
- enableDirtyRectangleRendering = _this3$canvasConfig$r2.enableDirtyRectangleRendering;
3332
-
3333
- if (!enableDirtyRectangleRendering) {
3334
- if (object.isVisible() && !object.isCulled()) {
3335
- // render immediately
3336
- _this3.renderDisplayObject(object, renderingService);
3725
+ if (!enableDirtyRectangleRendering) {
3726
+ if (object.isVisible() && !object.isCulled()) {
3727
+ // render immediately
3728
+ _this3.renderDisplayObject(object, renderingService);
3729
+ }
3730
+ } else {
3731
+ // render at the end of frame
3732
+ _this3.renderQueue.push(object);
3337
3733
  }
3338
- } else {
3339
- // render at the end of frame
3340
- _this3.renderQueue.push(object);
3341
- }
3342
- });
3343
- };
3344
-
3345
- _proto.clearRect = function clearRect(context, x, y, width, height) {
3346
- context.clearRect(x, y, width, height);
3347
- var background = this.canvasConfig.background;
3348
-
3349
- if (background) {
3350
- context.fillStyle = background;
3351
- context.fillRect(x, y, width, height);
3734
+ });
3352
3735
  }
3353
- };
3354
-
3355
- _proto.flush = function flush(context, renderingService) {
3356
- if (this.batchedDisplayObject) {
3357
- var styleRenderer = this.styleRendererFactory(this.batchedDisplayObject.nodeName);
3358
-
3359
- if (styleRenderer) {
3360
- // apply attributes to context
3361
- this.applyAttributesToContext(context, this.batchedDisplayObject, renderingService); // close path first
3736
+ }, {
3737
+ key: "clearRect",
3738
+ value: function clearRect(context, x, y, width, height) {
3739
+ context.clearRect(x, y, width, height);
3740
+ var background = this.canvasConfig.background;
3362
3741
 
3363
- context.closePath();
3364
- styleRenderer.render(context, this.batchedDisplayObject.parsedStyle, this.batchedDisplayObject);
3365
- context.restore();
3742
+ if (background) {
3743
+ context.fillStyle = background;
3744
+ context.fillRect(x, y, width, height);
3366
3745
  }
3367
-
3368
- this.batchedStyleHash = '';
3369
- this.batchedDisplayObject = null;
3370
3746
  }
3371
- };
3747
+ }, {
3748
+ key: "flush",
3749
+ value: function flush(context, renderingService) {
3750
+ if (this.batchedDisplayObject) {
3751
+ var styleRenderer = this.styleRendererFactory(this.batchedDisplayObject.nodeName);
3372
3752
 
3373
- _proto.renderDisplayObject = function renderDisplayObject(object, renderingService) {
3374
- var _this4 = this;
3753
+ if (styleRenderer) {
3754
+ // apply attributes to context
3755
+ this.applyAttributesToContext(context, this.batchedDisplayObject, renderingService); // close path first
3375
3756
 
3376
- var context = this.contextService.getContext(); // restore to its parent
3377
-
3378
- var parent = this.restoreStack[this.restoreStack.length - 1];
3757
+ context.closePath();
3758
+ styleRenderer.render(context, this.batchedDisplayObject.parsedStyle, this.batchedDisplayObject);
3759
+ context.restore();
3760
+ }
3379
3761
 
3380
- while (parent && object.parentNode !== parent) {
3381
- context.restore();
3382
- this.restoreStack.pop();
3383
- parent = this.restoreStack[this.restoreStack.length - 1];
3762
+ this.batchedStyleHash = '';
3763
+ this.batchedDisplayObject = null;
3764
+ }
3384
3765
  }
3766
+ }, {
3767
+ key: "renderDisplayObject",
3768
+ value: function renderDisplayObject(object, renderingService) {
3769
+ var _this4 = this;
3385
3770
 
3386
- var nodeName = object.nodeName;
3387
- var styleRenderer = this.styleRendererFactory(nodeName);
3388
- var startBatch = false;
3771
+ var context = this.contextService.getContext(); // restore to its parent
3389
3772
 
3390
- if (this.enableBatch && styleRenderer) {
3391
- var hash = styleRenderer.hash(object.attributes);
3773
+ var parent = this.restoreStack[this.restoreStack.length - 1];
3392
3774
 
3393
- if (this.batchedStyleHash && hash !== this.batchedStyleHash) {
3394
- this.flush(context, renderingService);
3395
- }
3396
-
3397
- if (!this.batchedStyleHash) {
3398
- this.batchedStyleHash = hash;
3399
- this.batchedDisplayObject = object;
3400
- startBatch = true;
3775
+ while (parent && object.parentNode !== parent) {
3776
+ context.restore();
3777
+ this.restoreStack.pop();
3778
+ parent = this.restoreStack[this.restoreStack.length - 1];
3401
3779
  }
3402
- } // reset transformation
3403
3780
 
3781
+ var nodeName = object.nodeName;
3782
+ var styleRenderer = this.styleRendererFactory(nodeName);
3783
+ var startBatch = false;
3404
3784
 
3405
- context.save(); // apply RTS transformation in world space
3785
+ if (this.enableBatch && styleRenderer) {
3786
+ var hash = styleRenderer.hash(object.attributes);
3406
3787
 
3407
- this.applyTransform(context, object.getLocalTransform()); // clip path
3408
-
3409
- var clipPathShape = object.style.clipPath;
3410
-
3411
- if (clipPathShape) {
3412
- context.save(); // apply clip shape's RTS
3413
-
3414
- this.applyTransform(context, clipPathShape.getLocalTransform()); // generate path in local space
3788
+ if (this.batchedStyleHash && hash !== this.batchedStyleHash) {
3789
+ this.flush(context, renderingService);
3790
+ }
3415
3791
 
3416
- var generatePath = this.pathGeneratorFactory(clipPathShape.nodeName);
3792
+ if (!this.batchedStyleHash) {
3793
+ this.batchedStyleHash = hash;
3794
+ this.batchedDisplayObject = object;
3795
+ startBatch = true;
3796
+ }
3797
+ } // reset transformation
3417
3798
 
3418
- if (generatePath) {
3419
- this.useAnchor(context, clipPathShape, function () {
3420
- context.beginPath();
3421
- generatePath(context, clipPathShape.parsedStyle);
3422
- context.closePath();
3423
- });
3424
- }
3425
3799
 
3426
- context.restore();
3427
- context.clip();
3428
- } // fill & stroke
3800
+ context.save(); // apply RTS transformation in world space
3429
3801
 
3802
+ this.applyTransform(context, object.getLocalTransform()); // clip path
3430
3803
 
3431
- if (!this.enableBatch) {
3432
- context.save(); // apply attributes to context
3804
+ var clipPathShape = object.style.clipPath;
3433
3805
 
3434
- this.applyAttributesToContext(context, object, renderingService);
3435
- } // apply anchor in local space
3806
+ if (clipPathShape) {
3807
+ context.save(); // apply clip shape's RTS
3436
3808
 
3809
+ this.applyTransform(context, clipPathShape.getLocalTransform()); // generate path in local space
3437
3810
 
3438
- this.useAnchor(context, object, function () {
3439
- // generate path in local space
3440
- var generatePath = _this4.pathGeneratorFactory(object.nodeName);
3811
+ var generatePath = this.pathGeneratorFactory(clipPathShape.nodeName);
3441
3812
 
3442
- if (generatePath) {
3443
- if (startBatch || !_this4.enableBatch) {
3444
- context.beginPath();
3813
+ if (generatePath) {
3814
+ this.useAnchor(context, clipPathShape, function () {
3815
+ context.beginPath();
3816
+ generatePath(context, clipPathShape.parsedStyle);
3817
+ context.closePath();
3818
+ });
3445
3819
  }
3446
3820
 
3447
- generatePath(context, object.parsedStyle);
3448
-
3449
- if (!_this4.enableBatch && object.nodeName !== g.Shape.LINE && object.nodeName !== g.Shape.PATH && object.nodeName !== g.Shape.POLYLINE) {
3450
- context.closePath();
3451
- }
3821
+ context.restore();
3822
+ context.clip();
3452
3823
  } // fill & stroke
3453
3824
 
3454
3825
 
3455
- if (styleRenderer && !_this4.enableBatch) {
3456
- styleRenderer.render(context, object.parsedStyle, object);
3457
- }
3458
- }); // restore applied attributes, eg. shadowBlur shadowColor...
3459
-
3460
- if (!this.enableBatch) {
3461
- context.restore();
3462
- } // finish rendering, clear dirty flag
3826
+ if (!this.enableBatch) {
3827
+ context.save(); // apply attributes to context
3463
3828
 
3829
+ this.applyAttributesToContext(context, object, renderingService);
3830
+ } // apply anchor in local space
3464
3831
 
3465
- object.renderable.dirty = false;
3466
- this.restoreStack.push(object);
3467
- };
3468
-
3469
- _proto.convertAABB2Rect = function convertAABB2Rect(aabb) {
3470
- var min = aabb.getMin();
3471
- var max = aabb.getMax(); // expand the rectangle a bit to avoid artifacts
3472
- // @see https://www.yuque.com/antv/ou292n/bi8nix#ExvCu
3473
-
3474
- var minX = Math.floor(min[0]);
3475
- var minY = Math.floor(min[1]);
3476
- var maxX = Math.ceil(max[0]);
3477
- var maxY = Math.ceil(max[1]);
3478
- var width = maxX - minX;
3479
- var height = maxY - minY;
3480
- return {
3481
- x: minX,
3482
- y: minY,
3483
- width: width,
3484
- height: height
3485
- };
3486
- }
3487
- /**
3488
- * TODO: merge dirty rectangles with some strategies.
3489
- * For now, we just simply merge all the rectangles into one.
3490
- * @see https://idom.me/articles/841.html
3491
- */
3492
- ;
3493
3832
 
3494
- _proto.mergeDirtyAABBs = function mergeDirtyAABBs(dirtyObjects) {
3495
- // merge into a big AABB
3496
- var aabb = new g.AABB();
3497
- dirtyObjects.forEach(function (object) {
3498
- var renderBounds = object.getRenderBounds();
3499
- aabb.add(renderBounds);
3500
- var dirtyRenderBounds = object.renderable.dirtyRenderBounds;
3833
+ this.useAnchor(context, object, function () {
3834
+ // generate path in local space
3835
+ var generatePath = _this4.pathGeneratorFactory(object.nodeName);
3501
3836
 
3502
- if (dirtyRenderBounds) {
3503
- aabb.add(dirtyRenderBounds);
3504
- }
3505
- });
3506
- return aabb;
3507
- };
3837
+ if (generatePath) {
3838
+ if (startBatch || !_this4.enableBatch) {
3839
+ context.beginPath();
3840
+ }
3508
3841
 
3509
- _proto.searchDirtyObjects = function searchDirtyObjects(dirtyRectangle) {
3510
- var _this5 = this; // search in r-tree, get all affected nodes
3842
+ generatePath(context, object.parsedStyle);
3511
3843
 
3844
+ if (!_this4.enableBatch && object.nodeName !== g.Shape.LINE && object.nodeName !== g.Shape.PATH && object.nodeName !== g.Shape.POLYLINE) {
3845
+ context.closePath();
3846
+ }
3847
+ } // fill & stroke
3512
3848
 
3513
- var _dirtyRectangle$getMi = dirtyRectangle.getMin(),
3514
- minX = _dirtyRectangle$getMi[0],
3515
- minY = _dirtyRectangle$getMi[1];
3516
3849
 
3517
- var _dirtyRectangle$getMa = dirtyRectangle.getMax(),
3518
- maxX = _dirtyRectangle$getMa[0],
3519
- maxY = _dirtyRectangle$getMa[1];
3850
+ if (styleRenderer && !_this4.enableBatch) {
3851
+ styleRenderer.render(context, object.parsedStyle, object);
3852
+ }
3853
+ }); // restore applied attributes, eg. shadowBlur shadowColor...
3520
3854
 
3521
- var rBushNodes = this.rBush.search({
3522
- minX: minX,
3523
- minY: minY,
3524
- maxX: maxX,
3525
- maxY: maxY
3526
- });
3527
- return rBushNodes.map(function (_ref3) {
3528
- var id = _ref3.id;
3529
- return _this5.displayObjectPool.getByEntity(id);
3530
- });
3531
- };
3855
+ if (!this.enableBatch) {
3856
+ context.restore();
3857
+ } // finish rendering, clear dirty flag
3532
3858
 
3533
- _proto.saveDirtyAABB = function saveDirtyAABB(object) {
3534
- var renderable = object.renderable;
3535
3859
 
3536
- if (!renderable.dirtyRenderBounds) {
3537
- renderable.dirtyRenderBounds = new g.AABB();
3860
+ object.renderable.dirty = false;
3861
+ this.restoreStack.push(object);
3538
3862
  }
3863
+ }, {
3864
+ key: "convertAABB2Rect",
3865
+ value: function convertAABB2Rect(aabb) {
3866
+ var min = aabb.getMin();
3867
+ var max = aabb.getMax(); // expand the rectangle a bit to avoid artifacts
3868
+ // @see https://www.yuque.com/antv/ou292n/bi8nix#ExvCu
3539
3869
 
3540
- var renderBounds = object.getRenderBounds();
3541
-
3542
- if (renderBounds) {
3543
- // save last dirty aabb
3544
- renderable.dirtyRenderBounds.update(renderBounds.center, renderBounds.halfExtents);
3870
+ var minX = Math.floor(min[0]);
3871
+ var minY = Math.floor(min[1]);
3872
+ var maxX = Math.ceil(max[0]);
3873
+ var maxY = Math.ceil(max[1]);
3874
+ var width = maxX - minX;
3875
+ var height = maxY - minY;
3876
+ return {
3877
+ x: minX,
3878
+ y: minY,
3879
+ width: width,
3880
+ height: height
3881
+ };
3545
3882
  }
3546
- };
3547
-
3548
- _proto.applyTransform = function applyTransform(context, transform) {
3549
- var _mat4$getTranslation = getTranslation(create$1(), transform),
3550
- tx = _mat4$getTranslation[0],
3551
- ty = _mat4$getTranslation[1];
3552
-
3553
- var _mat4$getScaling = getScaling(create$1(), transform),
3554
- sx = _mat4$getScaling[0],
3555
- sy = _mat4$getScaling[1];
3883
+ /**
3884
+ * TODO: merge dirty rectangles with some strategies.
3885
+ * For now, we just simply merge all the rectangles into one.
3886
+ * @see https://idom.me/articles/841.html
3887
+ */
3888
+
3889
+ }, {
3890
+ key: "mergeDirtyAABBs",
3891
+ value: function mergeDirtyAABBs(dirtyObjects) {
3892
+ // merge into a big AABB
3893
+ var aabb = new g.AABB();
3894
+ dirtyObjects.forEach(function (object) {
3895
+ var renderBounds = object.getRenderBounds();
3896
+ aabb.add(renderBounds);
3897
+ var dirtyRenderBounds = object.renderable.dirtyRenderBounds;
3898
+
3899
+ if (dirtyRenderBounds) {
3900
+ aabb.add(dirtyRenderBounds);
3901
+ }
3902
+ });
3903
+ return aabb;
3904
+ }
3905
+ }, {
3906
+ key: "searchDirtyObjects",
3907
+ value: function searchDirtyObjects(dirtyRectangle) {
3908
+ var _this5 = this; // search in r-tree, get all affected nodes
3556
3909
 
3557
- var rotation = getRotation(create$3(), transform); // eslint-disable-next-line @typescript-eslint/no-unused-vars
3558
3910
 
3559
- var _getEuler = g.getEuler(create$1(), rotation),
3560
- eux = _getEuler[0],
3561
- euy = _getEuler[1],
3562
- euz = _getEuler[2]; // gimbal lock at 90 degrees
3911
+ var _dirtyRectangle$getMi = dirtyRectangle.getMin(),
3912
+ _dirtyRectangle$getMi2 = _slicedToArray(_dirtyRectangle$getMi, 2),
3913
+ minX = _dirtyRectangle$getMi2[0],
3914
+ minY = _dirtyRectangle$getMi2[1];
3563
3915
 
3916
+ var _dirtyRectangle$getMa = dirtyRectangle.getMax(),
3917
+ _dirtyRectangle$getMa2 = _slicedToArray(_dirtyRectangle$getMa, 2),
3918
+ maxX = _dirtyRectangle$getMa2[0],
3919
+ maxY = _dirtyRectangle$getMa2[1];
3564
3920
 
3565
- var rts = g.fromRotationTranslationScale(eux || euz, tx, ty, sx, sy); // @see https://developer.mozilla.org/en-US/docs/Web/API/Canvas_API/Tutorial/Transformations
3921
+ var rBushNodes = this.rBush.search({
3922
+ minX: minX,
3923
+ minY: minY,
3924
+ maxX: maxX,
3925
+ maxY: maxY
3926
+ });
3927
+ return rBushNodes.map(function (_ref3) {
3928
+ var id = _ref3.id;
3929
+ return _this5.displayObjectPool.getByEntity(id);
3930
+ });
3931
+ }
3932
+ }, {
3933
+ key: "saveDirtyAABB",
3934
+ value: function saveDirtyAABB(object) {
3935
+ var renderable = object.renderable;
3566
3936
 
3567
- context.transform(rts[0], rts[1], rts[3], rts[4], rts[6], rts[7]);
3568
- };
3937
+ if (!renderable.dirtyRenderBounds) {
3938
+ renderable.dirtyRenderBounds = new g.AABB();
3939
+ }
3569
3940
 
3570
- _proto.getColor = function getColor(parsedColor, object, context, renderingService) {
3571
- var color;
3572
-
3573
- if (parsedColor instanceof g.CSSGradientValue) {
3574
- if (parsedColor.type === g.GradientPatternType.LinearGradient || parsedColor.type === g.GradientPatternType.RadialGradient) {
3575
- var bounds = object.getGeometryBounds();
3576
- var width = bounds && bounds.halfExtents[0] * 2 || 0;
3577
- var height = bounds && bounds.halfExtents[1] * 2 || 0;
3578
- color = this.gradientPool.getOrCreateGradient(_extends({
3579
- type: parsedColor.type
3580
- }, parsedColor.value, {
3581
- width: width,
3582
- height: height
3583
- }), context);
3584
- } else if (parsedColor.type === g.GradientPatternType.Pattern) {
3585
- var pattern = this.imagePool.getPatternSync(parsedColor.value);
3941
+ var renderBounds = object.getRenderBounds();
3586
3942
 
3587
- if (pattern) {
3588
- color = pattern;
3589
- } else {
3590
- this.imagePool.createPattern(parsedColor.value, context).then(function () {
3591
- // set dirty rectangle flag
3592
- object.renderable.dirty = true;
3593
- renderingService.dirtify();
3594
- });
3595
- }
3943
+ if (renderBounds) {
3944
+ // save last dirty aabb
3945
+ renderable.dirtyRenderBounds.update(renderBounds.center, renderBounds.halfExtents);
3596
3946
  }
3597
- } else {
3598
- // constant, eg. rgba(255,255,255,1)
3599
- color = parsedColor.toString();
3600
3947
  }
3948
+ }, {
3949
+ key: "applyTransform",
3950
+ value: function applyTransform(context, transform) {
3951
+ var _mat4$getTranslation = getTranslation(create$1(), transform),
3952
+ _mat4$getTranslation2 = _slicedToArray(_mat4$getTranslation, 2),
3953
+ tx = _mat4$getTranslation2[0],
3954
+ ty = _mat4$getTranslation2[1];
3955
+
3956
+ var _mat4$getScaling = getScaling(create$1(), transform),
3957
+ _mat4$getScaling2 = _slicedToArray(_mat4$getScaling, 2),
3958
+ sx = _mat4$getScaling2[0],
3959
+ sy = _mat4$getScaling2[1];
3960
+
3961
+ var rotation = getRotation(create$3(), transform); // eslint-disable-next-line @typescript-eslint/no-unused-vars
3962
+
3963
+ var _getEuler = g.getEuler(create$1(), rotation),
3964
+ _getEuler2 = _slicedToArray(_getEuler, 3),
3965
+ eux = _getEuler2[0],
3966
+ euy = _getEuler2[1],
3967
+ euz = _getEuler2[2]; // gimbal lock at 90 degrees
3968
+
3969
+
3970
+ var rts = g.fromRotationTranslationScale(eux || euz, tx, ty, sx, sy); // @see https://developer.mozilla.org/en-US/docs/Web/API/Canvas_API/Tutorial/Transformations
3971
+
3972
+ context.transform(rts[0], rts[1], rts[3], rts[4], rts[6], rts[7]);
3973
+ }
3974
+ }, {
3975
+ key: "getColor",
3976
+ value: function getColor(parsedColor, object, context, renderingService) {
3977
+ var color;
3978
+
3979
+ if (parsedColor instanceof g.CSSGradientValue) {
3980
+ if (parsedColor.type === g.GradientPatternType.LinearGradient || parsedColor.type === g.GradientPatternType.RadialGradient) {
3981
+ var bounds = object.getGeometryBounds();
3982
+ var width = bounds && bounds.halfExtents[0] * 2 || 0;
3983
+ var height = bounds && bounds.halfExtents[1] * 2 || 0;
3984
+ color = this.gradientPool.getOrCreateGradient(_objectSpread2(_objectSpread2({
3985
+ type: parsedColor.type
3986
+ }, parsedColor.value), {}, {
3987
+ width: width,
3988
+ height: height
3989
+ }), context);
3990
+ } else if (parsedColor.type === g.GradientPatternType.Pattern) {
3991
+ var pattern = this.imagePool.getPatternSync(parsedColor.value);
3992
+
3993
+ if (pattern) {
3994
+ color = pattern;
3995
+ } else {
3996
+ this.imagePool.createPattern(parsedColor.value, context).then(function () {
3997
+ // set dirty rectangle flag
3998
+ object.renderable.dirty = true;
3999
+ renderingService.dirtify();
4000
+ });
4001
+ }
4002
+ }
4003
+ } else {
4004
+ // constant, eg. rgba(255,255,255,1)
4005
+ color = parsedColor.toString();
4006
+ }
3601
4007
 
3602
- return color;
3603
- };
3604
-
3605
- _proto.applyAttributesToContext = function applyAttributesToContext(context, object, renderingService) {
3606
- var _object$parsedStyle = object.parsedStyle,
3607
- stroke = _object$parsedStyle.stroke,
3608
- fill = _object$parsedStyle.fill,
3609
- opacity = _object$parsedStyle.opacity,
3610
- lineDash = _object$parsedStyle.lineDash,
3611
- lineDashOffset = _object$parsedStyle.lineDashOffset,
3612
- filter = _object$parsedStyle.filter,
3613
- shadowColor = _object$parsedStyle.shadowColor,
3614
- shadowBlur = _object$parsedStyle.shadowBlur,
3615
- shadowOffsetX = _object$parsedStyle.shadowOffsetX,
3616
- shadowOffsetY = _object$parsedStyle.shadowOffsetY; // @see https://developer.mozilla.org/zh-CN/docs/Web/API/CanvasRenderingContext2D/setLineDash
3617
-
3618
- if (lineDash && Array.isArray(lineDash)) {
3619
- context.setLineDash(lineDash.map(function (segment) {
3620
- return segment.value;
3621
- }));
3622
- } // @see https://developer.mozilla.org/zh-CN/docs/Web/API/CanvasRenderingContext2D/lineDashOffset
3623
-
3624
-
3625
- if (!g.isNil(lineDashOffset)) {
3626
- context.lineDashOffset = lineDashOffset.value;
3627
- }
4008
+ return color;
4009
+ }
4010
+ }, {
4011
+ key: "applyAttributesToContext",
4012
+ value: function applyAttributesToContext(context, object, renderingService) {
4013
+ var _object$parsedStyle = object.parsedStyle,
4014
+ stroke = _object$parsedStyle.stroke,
4015
+ fill = _object$parsedStyle.fill,
4016
+ opacity = _object$parsedStyle.opacity,
4017
+ lineDash = _object$parsedStyle.lineDash,
4018
+ lineDashOffset = _object$parsedStyle.lineDashOffset,
4019
+ filter = _object$parsedStyle.filter,
4020
+ shadowColor = _object$parsedStyle.shadowColor,
4021
+ shadowBlur = _object$parsedStyle.shadowBlur,
4022
+ shadowOffsetX = _object$parsedStyle.shadowOffsetX,
4023
+ shadowOffsetY = _object$parsedStyle.shadowOffsetY; // @see https://developer.mozilla.org/zh-CN/docs/Web/API/CanvasRenderingContext2D/setLineDash
4024
+
4025
+ if (lineDash && Array.isArray(lineDash)) {
4026
+ context.setLineDash(lineDash.map(function (segment) {
4027
+ return segment.value;
4028
+ }));
4029
+ } // @see https://developer.mozilla.org/zh-CN/docs/Web/API/CanvasRenderingContext2D/lineDashOffset
4030
+
4031
+
4032
+ if (!g.isNil(lineDashOffset)) {
4033
+ context.lineDashOffset = lineDashOffset.value;
4034
+ }
3628
4035
 
3629
- if (!g.isNil(opacity)) {
3630
- context.globalAlpha *= opacity.value;
3631
- }
4036
+ if (!g.isNil(opacity)) {
4037
+ context.globalAlpha *= opacity.value;
4038
+ }
3632
4039
 
3633
- if (!g.isNil(stroke)) {
3634
- context.strokeStyle = this.getColor(stroke, object, context, renderingService);
3635
- }
4040
+ if (!g.isNil(stroke) && !stroke.isNone) {
4041
+ context.strokeStyle = this.getColor(stroke, object, context, renderingService);
4042
+ }
3636
4043
 
3637
- if (!g.isNil(fill)) {
3638
- context.fillStyle = this.getColor(fill, object, context, renderingService);
3639
- }
4044
+ if (!g.isNil(fill) && !fill.isNone) {
4045
+ context.fillStyle = this.getColor(fill, object, context, renderingService);
4046
+ }
3640
4047
 
3641
- if (!g.isNil(filter)) {
3642
- // use raw filter string
3643
- context.filter = object.style.filter;
3644
- }
4048
+ if (!g.isNil(filter)) {
4049
+ // use raw filter string
4050
+ context.filter = object.style.filter;
4051
+ }
3645
4052
 
3646
- if (!g.isNil(shadowColor)) {
3647
- context.shadowColor = shadowColor.toString();
3648
- context.shadowBlur = shadowBlur && shadowBlur.value || 0;
3649
- context.shadowOffsetX = shadowOffsetX && shadowOffsetX.value || 0;
3650
- context.shadowOffsetY = shadowOffsetY && shadowOffsetY.value || 0;
4053
+ if (!g.isNil(shadowColor)) {
4054
+ context.shadowColor = shadowColor.toString();
4055
+ context.shadowBlur = shadowBlur && shadowBlur.value || 0;
4056
+ context.shadowOffsetX = shadowOffsetX && shadowOffsetX.value || 0;
4057
+ context.shadowOffsetY = shadowOffsetY && shadowOffsetY.value || 0;
4058
+ }
3651
4059
  }
3652
- };
4060
+ }, {
4061
+ key: "useAnchor",
4062
+ value: function useAnchor(context, object, callback) {
4063
+ var contentBounds = object.getGeometryBounds();
3653
4064
 
3654
- _proto.useAnchor = function useAnchor(context, object, callback) {
3655
- var contentBounds = object.getGeometryBounds();
4065
+ if (contentBounds) {
4066
+ var halfExtents = contentBounds.halfExtents; // apply anchor, use true size, not include stroke,
4067
+ // eg. bounds = true size + half lineWidth
3656
4068
 
3657
- if (contentBounds) {
3658
- var halfExtents = contentBounds.halfExtents; // apply anchor, use true size, not include stroke,
3659
- // eg. bounds = true size + half lineWidth
4069
+ var _ref4 = object.parsedStyle || {},
4070
+ anchor = _ref4.anchor;
3660
4071
 
3661
- var _ref4 = object.parsedStyle || {},
3662
- anchor = _ref4.anchor;
3663
-
3664
- context.translate(-(anchor && anchor[0].value || 0) * halfExtents[0] * 2, -(anchor && anchor[1].value || 0) * halfExtents[1] * 2);
3665
- callback();
3666
- } else {
3667
- callback();
4072
+ context.translate(-(anchor && anchor[0].value || 0) * halfExtents[0] * 2, -(anchor && anchor[1].value || 0) * halfExtents[1] * 2);
4073
+ callback();
4074
+ } else {
4075
+ callback();
4076
+ }
3668
4077
  }
3669
- };
4078
+ }, {
4079
+ key: "safeMergeAABB",
4080
+ value: function safeMergeAABB() {
4081
+ var merged = new g.AABB();
3670
4082
 
3671
- _proto.safeMergeAABB = function safeMergeAABB() {
3672
- var merged = new g.AABB();
4083
+ for (var _len = arguments.length, aabbs = new Array(_len), _key = 0; _key < _len; _key++) {
4084
+ aabbs[_key] = arguments[_key];
4085
+ }
3673
4086
 
3674
- for (var _len = arguments.length, aabbs = new Array(_len), _key = 0; _key < _len; _key++) {
3675
- aabbs[_key] = arguments[_key];
4087
+ aabbs.forEach(function (aabb) {
4088
+ merged.add(aabb);
4089
+ });
4090
+ return merged;
3676
4091
  }
3677
-
3678
- aabbs.forEach(function (aabb) {
3679
- merged.add(aabb);
3680
- });
3681
- return merged;
3682
- };
4092
+ }]);
3683
4093
 
3684
4094
  return CanvasRendererPlugin;
3685
4095
  }(), _class$1.tag = 'CanvasRenderer', _class$1);
@@ -3713,73 +4123,76 @@
3713
4123
  var LoadImagePlugin_1;
3714
4124
  var LoadImagePlugin = LoadImagePlugin_1 = (_class$1$1 = /*#__PURE__*/function () {
3715
4125
  function LoadImagePlugin() {
3716
- this.imagePool = void 0;
3717
- this.renderingContext = void 0;
3718
- }
3719
-
3720
- var _proto = LoadImagePlugin.prototype;
4126
+ _classCallCheck$2(this, LoadImagePlugin);
3721
4127
 
3722
- _proto.apply = function apply(renderingService) {
3723
- var _this = this;
3724
-
3725
- var handleMounted = function handleMounted(e) {
3726
- var object = e.target;
3727
- var nodeName = object.nodeName,
3728
- attributes = object.attributes;
4128
+ this.imagePool = void 0;
4129
+ this.renderingContext = void 0;
4130
+ }
3729
4131
 
3730
- if (nodeName === g.Shape.IMAGE) {
3731
- var img = attributes.img;
4132
+ _createClass$2(LoadImagePlugin, [{
4133
+ key: "apply",
4134
+ value: function apply(renderingService) {
4135
+ var _this = this;
3732
4136
 
3733
- if (g.isString(img)) {
3734
- _this.imagePool.getOrCreateImage(img).then(function () {
3735
- // set dirty rectangle flag
3736
- object.renderable.dirty = true;
3737
- renderingService.dirtify();
3738
- });
3739
- }
3740
- }
3741
- };
4137
+ var handleMounted = function handleMounted(e) {
4138
+ var object = e.target;
4139
+ var nodeName = object.nodeName,
4140
+ attributes = object.attributes;
3742
4141
 
3743
- var handleAttributeChanged = function handleAttributeChanged(e) {
3744
- var object = e.target;
3745
- var attrName = e.attrName,
3746
- newValue = e.newValue;
4142
+ if (nodeName === g.Shape.IMAGE) {
4143
+ var img = attributes.img;
3747
4144
 
3748
- if (object.nodeName === g.Shape.IMAGE) {
3749
- if (attrName === 'img') {
3750
- if (g.isString(newValue)) {
3751
- _this.imagePool.getOrCreateImage(newValue).then(function () {
4145
+ if (g.isString(img)) {
4146
+ _this.imagePool.getOrCreateImage(img).then(function () {
3752
4147
  // set dirty rectangle flag
3753
4148
  object.renderable.dirty = true;
3754
4149
  renderingService.dirtify();
3755
4150
  });
3756
4151
  }
3757
4152
  }
3758
- }
3759
- };
4153
+ };
4154
+
4155
+ var handleAttributeChanged = function handleAttributeChanged(e) {
4156
+ var object = e.target;
4157
+ var attrName = e.attrName,
4158
+ newValue = e.newValue;
4159
+
4160
+ if (object.nodeName === g.Shape.IMAGE) {
4161
+ if (attrName === 'img') {
4162
+ if (g.isString(newValue)) {
4163
+ _this.imagePool.getOrCreateImage(newValue).then(function () {
4164
+ // set dirty rectangle flag
4165
+ object.renderable.dirty = true;
4166
+ renderingService.dirtify();
4167
+ });
4168
+ }
4169
+ }
4170
+ }
4171
+ };
3760
4172
 
3761
- renderingService.hooks.init.tapPromise(LoadImagePlugin_1.tag, /*#__PURE__*/_asyncToGenerator$1( /*#__PURE__*/_regeneratorRuntime$1().mark(function _callee() {
3762
- return _regeneratorRuntime$1().wrap(function _callee$(_context) {
3763
- while (1) {
3764
- switch (_context.prev = _context.next) {
3765
- case 0:
3766
- _this.renderingContext.root.addEventListener(g.ElementEvent.MOUNTED, handleMounted);
4173
+ renderingService.hooks.init.tapPromise(LoadImagePlugin_1.tag, /*#__PURE__*/_asyncToGenerator$1( /*#__PURE__*/_regeneratorRuntime$1().mark(function _callee() {
4174
+ return _regeneratorRuntime$1().wrap(function _callee$(_context) {
4175
+ while (1) {
4176
+ switch (_context.prev = _context.next) {
4177
+ case 0:
4178
+ _this.renderingContext.root.addEventListener(g.ElementEvent.MOUNTED, handleMounted);
3767
4179
 
3768
- _this.renderingContext.root.addEventListener(g.ElementEvent.ATTR_MODIFIED, handleAttributeChanged);
4180
+ _this.renderingContext.root.addEventListener(g.ElementEvent.ATTR_MODIFIED, handleAttributeChanged);
3769
4181
 
3770
- case 2:
3771
- case "end":
3772
- return _context.stop();
4182
+ case 2:
4183
+ case "end":
4184
+ return _context.stop();
4185
+ }
3773
4186
  }
3774
- }
3775
- }, _callee);
3776
- })));
3777
- renderingService.hooks.destroy.tap(LoadImagePlugin_1.tag, function () {
3778
- _this.renderingContext.root.removeEventListener(g.ElementEvent.MOUNTED, handleMounted);
4187
+ }, _callee);
4188
+ })));
4189
+ renderingService.hooks.destroy.tap(LoadImagePlugin_1.tag, function () {
4190
+ _this.renderingContext.root.removeEventListener(g.ElementEvent.MOUNTED, handleMounted);
3779
4191
 
3780
- _this.renderingContext.root.removeEventListener(g.ElementEvent.ATTR_MODIFIED, handleAttributeChanged);
3781
- });
3782
- };
4192
+ _this.renderingContext.root.removeEventListener(g.ElementEvent.ATTR_MODIFIED, handleAttributeChanged);
4193
+ });
4194
+ }
4195
+ }]);
3783
4196
 
3784
4197
  return LoadImagePlugin;
3785
4198
  }(), _class$1$1.tag = 'LoadImage', _class$1$1);
@@ -3876,7 +4289,7 @@
3876
4289
  register(PolylineRenderer);
3877
4290
  register(PolygonRenderer);
3878
4291
  register(PathRenderer);
3879
- var shape2Token = (_shape2Token = {}, _shape2Token[g.Shape.CIRCLE] = CircleRendererContribution, _shape2Token[g.Shape.ELLIPSE] = EllipseRendererContribution, _shape2Token[g.Shape.RECT] = RectRendererContribution, _shape2Token[g.Shape.IMAGE] = ImageRendererContribution, _shape2Token[g.Shape.TEXT] = TextRendererContribution, _shape2Token[g.Shape.LINE] = LineRendererContribution, _shape2Token[g.Shape.POLYLINE] = PolylineRendererContribution, _shape2Token[g.Shape.POLYGON] = PolygonRendererContribution, _shape2Token[g.Shape.PATH] = PathRendererContribution, _shape2Token);
4292
+ var shape2Token = (_shape2Token = {}, _defineProperty(_shape2Token, g.Shape.CIRCLE, CircleRendererContribution), _defineProperty(_shape2Token, g.Shape.ELLIPSE, EllipseRendererContribution), _defineProperty(_shape2Token, g.Shape.RECT, RectRendererContribution), _defineProperty(_shape2Token, g.Shape.IMAGE, ImageRendererContribution), _defineProperty(_shape2Token, g.Shape.TEXT, TextRendererContribution), _defineProperty(_shape2Token, g.Shape.LINE, LineRendererContribution), _defineProperty(_shape2Token, g.Shape.POLYLINE, PolylineRendererContribution), _defineProperty(_shape2Token, g.Shape.POLYGON, PolygonRendererContribution), _defineProperty(_shape2Token, g.Shape.PATH, PathRendererContribution), _shape2Token);
3880
4293
  register({
3881
4294
  token: StyleRendererFactory,
3882
4295
  useFactory: function useFactory(ctx) {
@@ -3901,18 +4314,22 @@
3901
4314
 
3902
4315
  var Plugin$1 = /*#__PURE__*/function () {
3903
4316
  function Plugin() {
4317
+ _classCallCheck$2(this, Plugin);
4318
+
3904
4319
  this.name = 'canvas-renderer';
3905
4320
  }
3906
4321
 
3907
- var _proto = Plugin.prototype;
3908
-
3909
- _proto.init = function init(container) {
3910
- container.load(containerModule$1, true);
3911
- };
3912
-
3913
- _proto.destroy = function destroy(container) {
3914
- container.unload(containerModule$1);
3915
- };
4322
+ _createClass$2(Plugin, [{
4323
+ key: "init",
4324
+ value: function init(container) {
4325
+ container.load(containerModule$1, true);
4326
+ }
4327
+ }, {
4328
+ key: "destroy",
4329
+ value: function destroy(container) {
4330
+ container.unload(containerModule$1);
4331
+ }
4332
+ }]);
3916
4333
 
3917
4334
  return Plugin;
3918
4335
  }();
@@ -4071,7 +4488,7 @@
4071
4488
  if ("throw" !== record.type) {
4072
4489
  var result = record.arg,
4073
4490
  value = result.value;
4074
- return value && "object" == typeof value && hasOwn.call(value, "__await") ? PromiseImpl.resolve(value.__await).then(function (value) {
4491
+ return value && "object" == _typeof(value) && hasOwn.call(value, "__await") ? PromiseImpl.resolve(value.__await).then(function (value) {
4075
4492
  invoke("next", value, resolve, reject);
4076
4493
  }, function (err) {
4077
4494
  invoke("throw", err, resolve, reject);
@@ -4331,6 +4748,92 @@
4331
4748
  });
4332
4749
  };
4333
4750
  }
4751
+
4752
+ function _classCallCheck$3(instance, Constructor) {
4753
+ if (!(instance instanceof Constructor)) {
4754
+ throw new TypeError("Cannot call a class as a function");
4755
+ }
4756
+ }
4757
+
4758
+ function _defineProperties$3(target, props) {
4759
+ for (var i = 0; i < props.length; i++) {
4760
+ var descriptor = props[i];
4761
+ descriptor.enumerable = descriptor.enumerable || false;
4762
+ descriptor.configurable = true;
4763
+ if ("value" in descriptor) descriptor.writable = true;
4764
+ Object.defineProperty(target, descriptor.key, descriptor);
4765
+ }
4766
+ }
4767
+
4768
+ function _createClass$3(Constructor, protoProps, staticProps) {
4769
+ if (protoProps) _defineProperties$3(Constructor.prototype, protoProps);
4770
+ if (staticProps) _defineProperties$3(Constructor, staticProps);
4771
+ Object.defineProperty(Constructor, "prototype", {
4772
+ writable: false
4773
+ });
4774
+ return Constructor;
4775
+ }
4776
+
4777
+ function _slicedToArray$1(arr, i) {
4778
+ return _arrayWithHoles$1(arr) || _iterableToArrayLimit$1(arr, i) || _unsupportedIterableToArray$1(arr, i) || _nonIterableRest$1();
4779
+ }
4780
+
4781
+ function _arrayWithHoles$1(arr) {
4782
+ if (Array.isArray(arr)) return arr;
4783
+ }
4784
+
4785
+ function _iterableToArrayLimit$1(arr, i) {
4786
+ var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
4787
+
4788
+ if (_i == null) return;
4789
+ var _arr = [];
4790
+ var _n = true;
4791
+ var _d = false;
4792
+
4793
+ var _s, _e;
4794
+
4795
+ try {
4796
+ for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) {
4797
+ _arr.push(_s.value);
4798
+
4799
+ if (i && _arr.length === i) break;
4800
+ }
4801
+ } catch (err) {
4802
+ _d = true;
4803
+ _e = err;
4804
+ } finally {
4805
+ try {
4806
+ if (!_n && _i["return"] != null) _i["return"]();
4807
+ } finally {
4808
+ if (_d) throw _e;
4809
+ }
4810
+ }
4811
+
4812
+ return _arr;
4813
+ }
4814
+
4815
+ function _unsupportedIterableToArray$1(o, minLen) {
4816
+ if (!o) return;
4817
+ if (typeof o === "string") return _arrayLikeToArray$1(o, minLen);
4818
+ var n = Object.prototype.toString.call(o).slice(8, -1);
4819
+ if (n === "Object" && o.constructor) n = o.constructor.name;
4820
+ if (n === "Map" || n === "Set") return Array.from(o);
4821
+ if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray$1(o, minLen);
4822
+ }
4823
+
4824
+ function _arrayLikeToArray$1(arr, len) {
4825
+ if (len == null || len > arr.length) len = arr.length;
4826
+
4827
+ for (var i = 0, arr2 = new Array(len); i < len; i++) {
4828
+ arr2[i] = arr[i];
4829
+ }
4830
+
4831
+ return arr2;
4832
+ }
4833
+
4834
+ function _nonIterableRest$1() {
4835
+ throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
4836
+ }
4334
4837
  /**
4335
4838
  * Common utilities
4336
4839
  * @module glMatrix
@@ -4925,6 +5428,8 @@
4925
5428
  function CanvasPickerPlugin() {
4926
5429
  var _this = this;
4927
5430
 
5431
+ _classCallCheck$3(this, CanvasPickerPlugin);
5432
+
4928
5433
  this.displayObjectPool = void 0;
4929
5434
  this.canvasConfig = void 0;
4930
5435
  this.offscreenCanvas = void 0;
@@ -4970,108 +5475,109 @@
4970
5475
  };
4971
5476
  }
4972
5477
 
4973
- var _proto = CanvasPickerPlugin.prototype;
4974
-
4975
- _proto.apply = function apply(renderingService) {
4976
- var _this2 = this;
4977
-
4978
- renderingService.hooks.pick.tapPromise(CanvasPickerPlugin_1.tag, /*#__PURE__*/function () {
4979
- var _ref = _asyncToGenerator$2( /*#__PURE__*/_regeneratorRuntime$2().mark(function _callee(result) {
4980
- var topmost, _result$position, x, y, position, rBushNodes, queriedIds, hitTestList, pickedDisplayObjects, _i, _hitTestList, displayObject, clipPath, objectToTest, worldTransform;
4981
-
4982
- return _regeneratorRuntime$2().wrap(function _callee$(_context) {
4983
- while (1) {
4984
- switch (_context.prev = _context.next) {
4985
- case 0:
4986
- topmost = result.topmost, _result$position = result.position, x = _result$position.x, y = _result$position.y; // position in world space
4987
-
4988
- position = fromValues$1(x, y, 0); // query by AABB first with spatial index(r-tree)
4989
-
4990
- rBushNodes = _this2.rBush.search({
4991
- minX: position[0],
4992
- minY: position[1],
4993
- maxX: position[0],
4994
- maxY: position[1]
4995
- });
4996
- queriedIds = rBushNodes.map(function (node) {
4997
- return node.id;
4998
- });
4999
- hitTestList = [];
5000
- rBushNodes.forEach(function (_ref2) {
5001
- var id = _ref2.id;
5002
-
5003
- var displayObject = _this2.displayObjectPool.getByEntity(id);
5004
-
5005
- if (displayObject.isVisible() && !displayObject.isCulled() && displayObject.isInteractive()) {
5006
- // parent is not included, eg. parent is clipped
5007
- if (displayObject.parentNode && queriedIds.indexOf(displayObject.parentNode.entity) === -1) {
5008
- return;
5478
+ _createClass$3(CanvasPickerPlugin, [{
5479
+ key: "apply",
5480
+ value: function apply(renderingService) {
5481
+ var _this2 = this;
5482
+
5483
+ renderingService.hooks.pick.tapPromise(CanvasPickerPlugin_1.tag, /*#__PURE__*/function () {
5484
+ var _ref = _asyncToGenerator$2( /*#__PURE__*/_regeneratorRuntime$2().mark(function _callee(result) {
5485
+ var topmost, _result$position, x, y, position, rBushNodes, queriedIds, hitTestList, pickedDisplayObjects, _i, _hitTestList, displayObject, clipPath, objectToTest, worldTransform;
5486
+
5487
+ return _regeneratorRuntime$2().wrap(function _callee$(_context) {
5488
+ while (1) {
5489
+ switch (_context.prev = _context.next) {
5490
+ case 0:
5491
+ topmost = result.topmost, _result$position = result.position, x = _result$position.x, y = _result$position.y; // position in world space
5492
+
5493
+ position = fromValues$1(x, y, 0); // query by AABB first with spatial index(r-tree)
5494
+
5495
+ rBushNodes = _this2.rBush.search({
5496
+ minX: position[0],
5497
+ minY: position[1],
5498
+ maxX: position[0],
5499
+ maxY: position[1]
5500
+ });
5501
+ queriedIds = rBushNodes.map(function (node) {
5502
+ return node.id;
5503
+ });
5504
+ hitTestList = [];
5505
+ rBushNodes.forEach(function (_ref2) {
5506
+ var id = _ref2.id;
5507
+
5508
+ var displayObject = _this2.displayObjectPool.getByEntity(id);
5509
+
5510
+ if (displayObject.isVisible() && !displayObject.isCulled() && displayObject.isInteractive()) {
5511
+ // parent is not included, eg. parent is clipped
5512
+ if (displayObject.parentNode && queriedIds.indexOf(displayObject.parentNode.entity) === -1) {
5513
+ return;
5514
+ }
5515
+
5516
+ hitTestList.push(displayObject);
5009
5517
  }
5010
-
5011
- hitTestList.push(displayObject);
5518
+ }); // find group with max z-index
5519
+
5520
+ hitTestList.sort(function (a, b) {
5521
+ return b.sortable.renderOrder - a.sortable.renderOrder;
5522
+ });
5523
+ pickedDisplayObjects = [];
5524
+ _i = 0, _hitTestList = hitTestList;
5525
+
5526
+ case 9:
5527
+ if (!(_i < _hitTestList.length)) {
5528
+ _context.next = 25;
5529
+ break;
5012
5530
  }
5013
- }); // find group with max z-index
5014
-
5015
- hitTestList.sort(function (a, b) {
5016
- return b.sortable.renderOrder - a.sortable.renderOrder;
5017
- });
5018
- pickedDisplayObjects = [];
5019
- _i = 0, _hitTestList = hitTestList;
5020
-
5021
- case 9:
5022
- if (!(_i < _hitTestList.length)) {
5023
- _context.next = 25;
5024
- break;
5025
- }
5026
5531
 
5027
- displayObject = _hitTestList[_i]; // test with clip path
5532
+ displayObject = _hitTestList[_i]; // test with clip path
5028
5533
 
5029
- clipPath = displayObject.parsedStyle.clipPath;
5030
- objectToTest = clipPath || displayObject;
5031
- worldTransform = displayObject.getWorldTransform(); // clipped's world matrix * clipPath's local matrix
5534
+ clipPath = displayObject.parsedStyle.clipPath;
5535
+ objectToTest = clipPath || displayObject;
5536
+ worldTransform = displayObject.getWorldTransform(); // clipped's world matrix * clipPath's local matrix
5032
5537
 
5033
- if (clipPath) {
5034
- worldTransform = multiply$1(create$1$1(), worldTransform, clipPath.getLocalTransform());
5035
- }
5538
+ if (clipPath) {
5539
+ worldTransform = multiply$1(create$1$1(), worldTransform, clipPath.getLocalTransform());
5540
+ }
5036
5541
 
5037
- if (!_this2.isHit(objectToTest, position, worldTransform)) {
5038
- _context.next = 22;
5039
- break;
5040
- }
5542
+ if (!_this2.isHit(objectToTest, position, worldTransform)) {
5543
+ _context.next = 22;
5544
+ break;
5545
+ }
5041
5546
 
5042
- if (!topmost) {
5043
- _context.next = 21;
5044
- break;
5045
- }
5547
+ if (!topmost) {
5548
+ _context.next = 21;
5549
+ break;
5550
+ }
5046
5551
 
5047
- result.picked = [displayObject];
5048
- return _context.abrupt("return", result);
5552
+ result.picked = [displayObject];
5553
+ return _context.abrupt("return", result);
5049
5554
 
5050
- case 21:
5051
- pickedDisplayObjects.push(displayObject);
5555
+ case 21:
5556
+ pickedDisplayObjects.push(displayObject);
5052
5557
 
5053
- case 22:
5054
- _i++;
5055
- _context.next = 9;
5056
- break;
5558
+ case 22:
5559
+ _i++;
5560
+ _context.next = 9;
5561
+ break;
5057
5562
 
5058
- case 25:
5059
- result.picked = pickedDisplayObjects;
5060
- return _context.abrupt("return", result);
5563
+ case 25:
5564
+ result.picked = pickedDisplayObjects;
5565
+ return _context.abrupt("return", result);
5061
5566
 
5062
- case 27:
5063
- case "end":
5064
- return _context.stop();
5567
+ case 27:
5568
+ case "end":
5569
+ return _context.stop();
5570
+ }
5065
5571
  }
5066
- }
5067
- }, _callee);
5068
- }));
5572
+ }, _callee);
5573
+ }));
5069
5574
 
5070
- return function (_x) {
5071
- return _ref.apply(this, arguments);
5072
- };
5073
- }());
5074
- };
5575
+ return function (_x) {
5576
+ return _ref.apply(this, arguments);
5577
+ };
5578
+ }());
5579
+ }
5580
+ }]);
5075
5581
 
5076
5582
  return CanvasPickerPlugin;
5077
5583
  }(), _class$2.tag = 'CanvasPicker', _class$2);
@@ -5091,6 +5597,41 @@
5091
5597
  CanvasPickerPlugin = CanvasPickerPlugin_1 = __decorate([manaSyringe.singleton({
5092
5598
  contrib: g.RenderingPluginContribution
5093
5599
  })], CanvasPickerPlugin);
5600
+
5601
+ function _toConsumableArray$1(arr) {
5602
+ return _arrayWithoutHoles$1(arr) || _iterableToArray$1(arr) || _unsupportedIterableToArray$1$1(arr) || _nonIterableSpread$1();
5603
+ }
5604
+
5605
+ function _arrayWithoutHoles$1(arr) {
5606
+ if (Array.isArray(arr)) return _arrayLikeToArray$1$1(arr);
5607
+ }
5608
+
5609
+ function _iterableToArray$1(iter) {
5610
+ if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
5611
+ }
5612
+
5613
+ function _unsupportedIterableToArray$1$1(o, minLen) {
5614
+ if (!o) return;
5615
+ if (typeof o === "string") return _arrayLikeToArray$1$1(o, minLen);
5616
+ var n = Object.prototype.toString.call(o).slice(8, -1);
5617
+ if (n === "Object" && o.constructor) n = o.constructor.name;
5618
+ if (n === "Map" || n === "Set") return Array.from(o);
5619
+ if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray$1$1(o, minLen);
5620
+ }
5621
+
5622
+ function _arrayLikeToArray$1$1(arr, len) {
5623
+ if (len == null || len > arr.length) len = arr.length;
5624
+
5625
+ for (var i = 0, arr2 = new Array(len); i < len; i++) {
5626
+ arr2[i] = arr[i];
5627
+ }
5628
+
5629
+ return arr2;
5630
+ }
5631
+
5632
+ function _nonIterableSpread$1() {
5633
+ throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
5634
+ }
5094
5635
  /**
5095
5636
  * 两点之间的距离
5096
5637
  * @param {number} x1 起始点 x
@@ -5100,6 +5641,7 @@
5100
5641
  * @return {number} 距离
5101
5642
  */
5102
5643
 
5644
+
5103
5645
  function distance(x1, y1, x2, y2) {
5104
5646
  var dx = x1 - x2;
5105
5647
  var dy = y1 - y2;
@@ -5111,10 +5653,10 @@
5111
5653
  }
5112
5654
 
5113
5655
  function getBBoxByArray(xArr, yArr) {
5114
- var minX = Math.min.apply(Math, xArr);
5115
- var minY = Math.min.apply(Math, yArr);
5116
- var maxX = Math.max.apply(Math, xArr);
5117
- var maxY = Math.max.apply(Math, yArr);
5656
+ var minX = Math.min.apply(Math, _toConsumableArray$1(xArr));
5657
+ var minY = Math.min.apply(Math, _toConsumableArray$1(yArr));
5658
+ var maxX = Math.max.apply(Math, _toConsumableArray$1(xArr));
5659
+ var maxY = Math.max.apply(Math, _toConsumableArray$1(yArr));
5118
5660
  return {
5119
5661
  x: minX,
5120
5662
  y: minY,
@@ -5257,7 +5799,7 @@
5257
5799
  for (var i = 0; i <= segNum; i++) {
5258
5800
  var _t = i * increaseRate;
5259
5801
 
5260
- var v1 = [tCallback.apply(void 0, xArr.concat([_t])), tCallback.apply(void 0, yArr.concat([_t]))];
5802
+ var v1 = [tCallback.apply(void 0, _toConsumableArray$1(xArr.concat([_t]))), tCallback.apply(void 0, _toConsumableArray$1(yArr.concat([_t])))];
5261
5803
  var d1 = distance(v0[0], v0[1], v1[0], v1[1]);
5262
5804
 
5263
5805
  if (d1 < d) {
@@ -5291,7 +5833,7 @@
5291
5833
 
5292
5834
  var prev = t - interval;
5293
5835
  var next = t + interval;
5294
- var _v = [tCallback.apply(void 0, xArr.concat([prev])), tCallback.apply(void 0, yArr.concat([prev]))];
5836
+ var _v = [tCallback.apply(void 0, _toConsumableArray$1(xArr.concat([prev]))), tCallback.apply(void 0, _toConsumableArray$1(yArr.concat([prev])))];
5295
5837
 
5296
5838
  var _d = distance(v0[0], v0[1], _v[0], _v[1]);
5297
5839
 
@@ -5299,7 +5841,7 @@
5299
5841
  t = prev;
5300
5842
  d = _d;
5301
5843
  } else {
5302
- var v2 = [tCallback.apply(void 0, xArr.concat([next])), tCallback.apply(void 0, yArr.concat([next]))];
5844
+ var v2 = [tCallback.apply(void 0, _toConsumableArray$1(xArr.concat([next]))), tCallback.apply(void 0, _toConsumableArray$1(yArr.concat([next])))];
5303
5845
  var d2 = distance(v0[0], v0[1], v2[0], v2[1]);
5304
5846
 
5305
5847
  if (next <= 1 && d2 < d) {
@@ -5312,8 +5854,8 @@
5312
5854
  }
5313
5855
 
5314
5856
  return {
5315
- x: tCallback.apply(void 0, xArr.concat([t])),
5316
- y: tCallback.apply(void 0, yArr.concat([t]))
5857
+ x: tCallback.apply(void 0, _toConsumableArray$1(xArr.concat([t]))),
5858
+ y: tCallback.apply(void 0, _toConsumableArray$1(yArr.concat([t])))
5317
5859
  };
5318
5860
  } // 近似求解 https://community.khronos.org/t/3d-cubic-bezier-segment-length/62363/2
5319
5861
 
@@ -5382,7 +5924,7 @@
5382
5924
  var right = quadratics[1];
5383
5925
  left.push(iterationCount - 1);
5384
5926
  right.push(iterationCount - 1);
5385
- return quadraticLength.apply(void 0, left) + quadraticLength.apply(void 0, right);
5927
+ return quadraticLength.apply(void 0, _toConsumableArray$1(left)) + quadraticLength.apply(void 0, _toConsumableArray$1(right));
5386
5928
  }
5387
5929
 
5388
5930
  var quadratic = {
@@ -5503,9 +6045,9 @@
5503
6045
  }
5504
6046
 
5505
6047
  var cubics = divideCubic(x1, y1, x2, y2, x3, y3, x4, y4, 0.5);
5506
- var left = [].concat(cubics[0], [iterationCount - 1]);
5507
- var right = [].concat(cubics[1], [iterationCount - 1]);
5508
- return cubicLength.apply(void 0, left) + cubicLength.apply(void 0, right);
6048
+ var left = [].concat(_toConsumableArray$1(cubics[0]), [iterationCount - 1]);
6049
+ var right = [].concat(_toConsumableArray$1(cubics[1]), [iterationCount - 1]);
6050
+ return cubicLength.apply(void 0, _toConsumableArray$1(left)) + cubicLength.apply(void 0, _toConsumableArray$1(right));
5509
6051
  }
5510
6052
 
5511
6053
  var cubic = {
@@ -5707,7 +6249,7 @@
5707
6249
  increasedLineWidthForHitTesting = _displayObject$parsed.increasedLineWidthForHitTesting,
5708
6250
  clipPathTargets = _displayObject$parsed.clipPathTargets;
5709
6251
  var r = rInPixels.value;
5710
- var halfLineWidth = (lineWidth.value + increasedLineWidthForHitTesting.value) / 2;
6252
+ var halfLineWidth = (((lineWidth === null || lineWidth === void 0 ? void 0 : lineWidth.value) || 0) + increasedLineWidthForHitTesting.value) / 2;
5711
6253
  var absDistance = distance$1(r, r, position.x, position.y);
5712
6254
  var isClipPath = !!(clipPathTargets === null || clipPathTargets === void 0 ? void 0 : clipPathTargets.length);
5713
6255
  var hasFill = fill && !fill.isNone;
@@ -5748,7 +6290,7 @@
5748
6290
  var hasStroke = stroke && !stroke.isNone;
5749
6291
  var rx = rxInPixels.value;
5750
6292
  var ry = ryInPixels.value;
5751
- var halfLineWith = (lineWidth.value + increasedLineWidthForHitTesting.value) / 2;
6293
+ var halfLineWith = (((lineWidth === null || lineWidth === void 0 ? void 0 : lineWidth.value) || 0) + increasedLineWidthForHitTesting.value) / 2;
5752
6294
  var squareX = (x - rx) * (x - rx);
5753
6295
  var squareY = (y - ry) * (y - ry); // 使用椭圆的公式: x*x/rx*rx + y*y/ry*ry = 1;
5754
6296
 
@@ -5985,10 +6527,12 @@
5985
6527
  }
5986
6528
 
5987
6529
  function inRectWithRadius(minX, minY, width, height, radiusArray, lineWidth, x, y) {
5988
- var tlr = radiusArray[0],
5989
- trr = radiusArray[1],
5990
- brr = radiusArray[2],
5991
- blr = radiusArray[3];
6530
+ var _radiusArray = _slicedToArray$1(radiusArray, 4),
6531
+ tlr = _radiusArray[0],
6532
+ trr = _radiusArray[1],
6533
+ brr = _radiusArray[2],
6534
+ blr = _radiusArray[3];
6535
+
5992
6536
  return inLine(minX + tlr, minY, minX + width - trr, minY, lineWidth, x, y) || inLine(minX + width, minY + trr, minX + width, minY + height - brr, lineWidth, x, y) || inLine(minX + width - brr, minY + height, minX + blr, minY + height, lineWidth, x, y) || inLine(minX, minY + height - blr, minX, minY + tlr, lineWidth, x, y) || inArc(minX + width - trr, minY + trr, trr, 1.5 * Math.PI, 2 * Math.PI, lineWidth, x, y) || inArc(minX + width - brr, minY + height - brr, brr, 0, 0.5 * Math.PI, lineWidth, x, y) || inArc(minX + blr, minY + height - blr, blr, 0.5 * Math.PI, Math.PI, lineWidth, x, y) || inArc(minX + tlr, minY + tlr, tlr, Math.PI, 1.5 * Math.PI, lineWidth, x, y);
5993
6537
  }
5994
6538
 
@@ -6055,18 +6599,22 @@
6055
6599
 
6056
6600
  var Plugin$2 = /*#__PURE__*/function () {
6057
6601
  function Plugin() {
6602
+ _classCallCheck$3(this, Plugin);
6603
+
6058
6604
  this.name = 'canvas-picker';
6059
6605
  }
6060
6606
 
6061
- var _proto = Plugin.prototype;
6062
-
6063
- _proto.init = function init(container) {
6064
- container.load(containerModule$2, true);
6065
- };
6066
-
6067
- _proto.destroy = function destroy(container) {
6068
- container.unload(containerModule$2);
6069
- };
6607
+ _createClass$3(Plugin, [{
6608
+ key: "init",
6609
+ value: function init(container) {
6610
+ container.load(containerModule$2, true);
6611
+ }
6612
+ }, {
6613
+ key: "destroy",
6614
+ value: function destroy(container) {
6615
+ container.unload(containerModule$2);
6616
+ }
6617
+ }]);
6070
6618
 
6071
6619
  return Plugin;
6072
6620
  }();
@@ -6201,7 +6749,7 @@
6201
6749
  if ("throw" !== record.type) {
6202
6750
  var result = record.arg,
6203
6751
  value = result.value;
6204
- return value && "object" == typeof value && hasOwn.call(value, "__await") ? PromiseImpl.resolve(value.__await).then(function (value) {
6752
+ return value && "object" == _typeof(value) && hasOwn.call(value, "__await") ? PromiseImpl.resolve(value.__await).then(function (value) {
6205
6753
  invoke("next", value, resolve, reject);
6206
6754
  }, function (err) {
6207
6755
  invoke("throw", err, resolve, reject);
@@ -6462,229 +7010,260 @@
6462
7010
  };
6463
7011
  }
6464
7012
 
7013
+ function _classCallCheck$4(instance, Constructor) {
7014
+ if (!(instance instanceof Constructor)) {
7015
+ throw new TypeError("Cannot call a class as a function");
7016
+ }
7017
+ }
7018
+
7019
+ function _defineProperties$4(target, props) {
7020
+ for (var i = 0; i < props.length; i++) {
7021
+ var descriptor = props[i];
7022
+ descriptor.enumerable = descriptor.enumerable || false;
7023
+ descriptor.configurable = true;
7024
+ if ("value" in descriptor) descriptor.writable = true;
7025
+ Object.defineProperty(target, descriptor.key, descriptor);
7026
+ }
7027
+ }
7028
+
7029
+ function _createClass$4(Constructor, protoProps, staticProps) {
7030
+ if (protoProps) _defineProperties$4(Constructor.prototype, protoProps);
7031
+ if (staticProps) _defineProperties$4(Constructor, staticProps);
7032
+ Object.defineProperty(Constructor, "prototype", {
7033
+ writable: false
7034
+ });
7035
+ return Constructor;
7036
+ }
7037
+
6465
7038
  var _class$3;
6466
7039
 
6467
7040
  var HTMLRenderingPlugin_1;
6468
7041
  var HTML_PREFIX = 'g-html-';
6469
7042
  var HTMLRenderingPlugin = HTMLRenderingPlugin_1 = (_class$3 = /*#__PURE__*/function () {
6470
7043
  function HTMLRenderingPlugin() {
7044
+ _classCallCheck$4(this, HTMLRenderingPlugin);
7045
+
6471
7046
  this.contextService = void 0;
6472
7047
  this.renderingContext = void 0;
6473
7048
  this.$camera = void 0;
6474
7049
  }
6475
7050
 
6476
- var _proto = HTMLRenderingPlugin.prototype;
7051
+ _createClass$4(HTMLRenderingPlugin, [{
7052
+ key: "apply",
7053
+ value: function apply(renderingService) {
7054
+ var _this = this;
6477
7055
 
6478
- _proto.apply = function apply(renderingService) {
6479
- var _this = this;
6480
-
6481
- var handleMounted = function handleMounted(e) {
6482
- var object = e.target;
7056
+ var handleMounted = function handleMounted(e) {
7057
+ var object = e.target;
6483
7058
 
6484
- if (object.nodeName === g.Shape.HTML) {
6485
- var $el = _this.getOrCreateEl(object); // apply documentElement's style
7059
+ if (object.nodeName === g.Shape.HTML) {
7060
+ var $el = _this.getOrCreateEl(object); // apply documentElement's style
6486
7061
 
6487
7062
 
6488
- var attributes = object.ownerDocument.documentElement.attributes;
6489
- Object.keys(attributes).forEach(function (name) {
6490
- $el.style[name] = attributes[name];
6491
- });
6492
- Object.keys(object.attributes).forEach(function (name) {
6493
- _this.updateAttribute(name, object);
6494
- });
6495
- }
6496
- };
7063
+ var attributes = object.ownerDocument.documentElement.attributes;
7064
+ Object.keys(attributes).forEach(function (name) {
7065
+ $el.style[name] = attributes[name];
7066
+ });
7067
+ Object.keys(object.attributes).forEach(function (name) {
7068
+ _this.updateAttribute(name, object);
7069
+ });
7070
+ }
7071
+ };
6497
7072
 
6498
- var handleUnmounted = function handleUnmounted(e) {
6499
- var object = e.target;
7073
+ var handleUnmounted = function handleUnmounted(e) {
7074
+ var object = e.target;
6500
7075
 
6501
- if (object.nodeName === g.Shape.HTML) {
6502
- var existedId = _this.getId(object);
7076
+ if (object.nodeName === g.Shape.HTML) {
7077
+ var existedId = _this.getId(object);
6503
7078
 
6504
- var $container = _this.contextService.getDomElement().parentNode;
7079
+ var $container = _this.contextService.getDomElement().parentNode;
6505
7080
 
6506
- if ($container) {
6507
- var $existedElement = $container.querySelector('#' + existedId);
7081
+ if ($container) {
7082
+ var $existedElement = $container.querySelector('#' + existedId);
6508
7083
 
6509
- if ($existedElement) {
6510
- $container.removeChild($existedElement);
7084
+ if ($existedElement) {
7085
+ $container.removeChild($existedElement);
7086
+ }
6511
7087
  }
6512
7088
  }
6513
- }
6514
- };
7089
+ };
6515
7090
 
6516
- var handleAttributeChanged = function handleAttributeChanged(e) {
6517
- var object = e.target;
7091
+ var handleAttributeChanged = function handleAttributeChanged(e) {
7092
+ var object = e.target;
6518
7093
 
6519
- if (object.nodeName === g.Shape.HTML) {
6520
- var attrName = e.attrName;
7094
+ if (object.nodeName === g.Shape.HTML) {
7095
+ var attrName = e.attrName;
6521
7096
 
6522
- _this.updateAttribute(attrName, object);
6523
- }
6524
- };
7097
+ _this.updateAttribute(attrName, object);
7098
+ }
7099
+ };
6525
7100
 
6526
- renderingService.hooks.init.tapPromise(HTMLRenderingPlugin_1.tag, /*#__PURE__*/_asyncToGenerator$3( /*#__PURE__*/_regeneratorRuntime$3().mark(function _callee() {
6527
- return _regeneratorRuntime$3().wrap(function _callee$(_context) {
6528
- while (1) {
6529
- switch (_context.prev = _context.next) {
6530
- case 0:
6531
- _this.renderingContext.root.addEventListener(g.ElementEvent.MOUNTED, handleMounted);
7101
+ renderingService.hooks.init.tapPromise(HTMLRenderingPlugin_1.tag, /*#__PURE__*/_asyncToGenerator$3( /*#__PURE__*/_regeneratorRuntime$3().mark(function _callee() {
7102
+ return _regeneratorRuntime$3().wrap(function _callee$(_context) {
7103
+ while (1) {
7104
+ switch (_context.prev = _context.next) {
7105
+ case 0:
7106
+ _this.renderingContext.root.addEventListener(g.ElementEvent.MOUNTED, handleMounted);
6532
7107
 
6533
- _this.renderingContext.root.addEventListener(g.ElementEvent.UNMOUNTED, handleUnmounted);
7108
+ _this.renderingContext.root.addEventListener(g.ElementEvent.UNMOUNTED, handleUnmounted);
6534
7109
 
6535
- _this.renderingContext.root.addEventListener(g.ElementEvent.ATTR_MODIFIED, handleAttributeChanged);
7110
+ _this.renderingContext.root.addEventListener(g.ElementEvent.ATTR_MODIFIED, handleAttributeChanged);
6536
7111
 
6537
- case 3:
6538
- case "end":
6539
- return _context.stop();
7112
+ case 3:
7113
+ case "end":
7114
+ return _context.stop();
7115
+ }
6540
7116
  }
6541
- }
6542
- }, _callee);
6543
- })));
6544
- renderingService.hooks.destroy.tap(HTMLRenderingPlugin_1.tag, function () {
6545
- _this.renderingContext.root.removeEventListener(g.ElementEvent.MOUNTED, handleMounted);
7117
+ }, _callee);
7118
+ })));
7119
+ renderingService.hooks.destroy.tap(HTMLRenderingPlugin_1.tag, function () {
7120
+ _this.renderingContext.root.removeEventListener(g.ElementEvent.MOUNTED, handleMounted);
6546
7121
 
6547
- _this.renderingContext.root.removeEventListener(g.ElementEvent.UNMOUNTED, handleUnmounted);
7122
+ _this.renderingContext.root.removeEventListener(g.ElementEvent.UNMOUNTED, handleUnmounted);
6548
7123
 
6549
- _this.renderingContext.root.removeEventListener(g.ElementEvent.ATTR_MODIFIED, handleAttributeChanged);
6550
- });
6551
- };
7124
+ _this.renderingContext.root.removeEventListener(g.ElementEvent.ATTR_MODIFIED, handleAttributeChanged);
7125
+ });
7126
+ }
7127
+ }, {
7128
+ key: "getId",
7129
+ value: function getId(object) {
7130
+ return object.id || HTML_PREFIX + object.entity;
7131
+ }
7132
+ }, {
7133
+ key: "getOrCreateEl",
7134
+ value: function getOrCreateEl(object) {
7135
+ var existedId = this.getId(object);
7136
+ var $container = this.contextService.getDomElement().parentNode;
6552
7137
 
6553
- _proto.getId = function getId(object) {
6554
- return object.id || HTML_PREFIX + object.entity;
6555
- };
7138
+ if ($container) {
7139
+ var $existedElement = $container.querySelector('#' + existedId);
6556
7140
 
6557
- _proto.getOrCreateEl = function getOrCreateEl(object) {
6558
- var existedId = this.getId(object);
6559
- var $container = this.contextService.getDomElement().parentNode;
7141
+ if (!$existedElement) {
7142
+ $existedElement = document.createElement('div');
7143
+ object.parsedStyle.$el = $existedElement;
7144
+ $existedElement.id = existedId;
6560
7145
 
6561
- if ($container) {
6562
- var $existedElement = $container.querySelector('#' + existedId);
7146
+ if (object.name) {
7147
+ $existedElement.setAttribute('name', object.name);
7148
+ }
6563
7149
 
6564
- if (!$existedElement) {
6565
- $existedElement = document.createElement('div');
6566
- object.parsedStyle.$el = $existedElement;
6567
- $existedElement.id = existedId;
7150
+ if (object.className) {
7151
+ $existedElement.className = object.className;
7152
+ }
6568
7153
 
6569
- if (object.name) {
6570
- $existedElement.setAttribute('name', object.name);
6571
- }
7154
+ $container.appendChild($existedElement); // use absolute position
6572
7155
 
6573
- if (object.className) {
6574
- $existedElement.className = object.className;
7156
+ $existedElement.style.position = 'absolute';
7157
+ $existedElement.style.left = '0';
7158
+ $existedElement.style.top = '0';
7159
+ $existedElement.style['will-change'] = 'transform';
7160
+ var worldTransform = object.getWorldTransform();
7161
+ $existedElement.style.transform = "matrix(".concat([worldTransform[0], worldTransform[1], worldTransform[4], worldTransform[5], worldTransform[12], worldTransform[13]].join(','), ")");
6575
7162
  }
6576
7163
 
6577
- $container.appendChild($existedElement); // use absolute position
6578
-
6579
- $existedElement.style.position = 'absolute';
6580
- $existedElement.style.left = '0';
6581
- $existedElement.style.top = '0';
6582
- $existedElement.style['will-change'] = 'transform';
6583
- var worldTransform = object.getWorldTransform();
6584
- $existedElement.style.transform = "matrix(" + [worldTransform[0], worldTransform[1], worldTransform[4], worldTransform[5], worldTransform[12], worldTransform[13]].join(',') + ")";
7164
+ return $existedElement;
6585
7165
  }
6586
7166
 
6587
- return $existedElement;
7167
+ return null;
6588
7168
  }
7169
+ }, {
7170
+ key: "updateAttribute",
7171
+ value: function updateAttribute(name, object) {
7172
+ var $el = this.getOrCreateEl(object);
6589
7173
 
6590
- return null;
6591
- };
6592
-
6593
- _proto.updateAttribute = function updateAttribute(name, object) {
6594
- var $el = this.getOrCreateEl(object);
6595
-
6596
- switch (name) {
6597
- case 'innerHTML':
6598
- var innerHTML = object.parsedStyle.innerHTML;
7174
+ switch (name) {
7175
+ case 'innerHTML':
7176
+ var innerHTML = object.parsedStyle.innerHTML;
6599
7177
 
6600
- if (g.isString(innerHTML)) {
6601
- $el.innerHTML = innerHTML;
6602
- } else {
6603
- $el.innerHTML = '';
6604
- $el.appendChild(innerHTML);
6605
- }
7178
+ if (g.isString(innerHTML)) {
7179
+ $el.innerHTML = innerHTML;
7180
+ } else {
7181
+ $el.innerHTML = '';
7182
+ $el.appendChild(innerHTML);
7183
+ }
6606
7184
 
6607
- break;
7185
+ break;
6608
7186
 
6609
- case 'modelMatrix':
6610
- case 'transformOrigin':
6611
- var transformOrigin = object.parsedStyle.transformOrigin;
6612
- $el.style['transform-origin'] = transformOrigin[0].value + " " + transformOrigin[1].value;
6613
- var worldTransform = object.getWorldTransform();
6614
- $el.style.transform = "matrix(" + [worldTransform[0], worldTransform[1], worldTransform[4], worldTransform[5], worldTransform[12], worldTransform[13]].join(',') + ")";
6615
- break;
7187
+ case 'modelMatrix':
7188
+ case 'transformOrigin':
7189
+ var transformOrigin = object.parsedStyle.transformOrigin;
7190
+ $el.style['transform-origin'] = "".concat(transformOrigin[0].value, " ").concat(transformOrigin[1].value);
7191
+ var worldTransform = object.getWorldTransform();
7192
+ $el.style.transform = "matrix(".concat([worldTransform[0], worldTransform[1], worldTransform[4], worldTransform[5], worldTransform[12], worldTransform[13]].join(','), ")");
7193
+ break;
6616
7194
 
6617
- case 'width':
6618
- var width = object.computedStyleMap().get('width');
6619
- $el.style.width = width.toString();
6620
- break;
7195
+ case 'width':
7196
+ var width = object.computedStyleMap().get('width');
7197
+ $el.style.width = width.toString();
7198
+ break;
6621
7199
 
6622
- case 'height':
6623
- var height = object.computedStyleMap().get('height');
6624
- $el.style.height = height.toString();
6625
- break;
7200
+ case 'height':
7201
+ var height = object.computedStyleMap().get('height');
7202
+ $el.style.height = height.toString();
7203
+ break;
6626
7204
 
6627
- case 'zIndex':
6628
- var zIndex = object.parsedStyle.zIndex;
6629
- $el.style['z-index'] = "" + zIndex.value;
6630
- break;
7205
+ case 'zIndex':
7206
+ var zIndex = object.parsedStyle.zIndex;
7207
+ $el.style['z-index'] = "".concat(zIndex.value);
7208
+ break;
6631
7209
 
6632
- case 'visibility':
6633
- var visibility = object.parsedStyle.visibility;
6634
- $el.style.visibility = visibility.value;
6635
- break;
7210
+ case 'visibility':
7211
+ var visibility = object.parsedStyle.visibility;
7212
+ $el.style.visibility = visibility.value;
7213
+ break;
6636
7214
 
6637
- case 'pointerEvents':
6638
- var pointerEvents = object.parsedStyle.pointerEvents;
6639
- $el.style.pointerEvents = pointerEvents.value;
6640
- break;
7215
+ case 'pointerEvents':
7216
+ var pointerEvents = object.parsedStyle.pointerEvents;
7217
+ $el.style.pointerEvents = pointerEvents.value;
7218
+ break;
6641
7219
 
6642
- case 'opacity':
6643
- var opacity = object.parsedStyle.opacity;
6644
- $el.style.opacity = "" + opacity.value;
6645
- break;
7220
+ case 'opacity':
7221
+ var opacity = object.parsedStyle.opacity;
7222
+ $el.style.opacity = "".concat(opacity.value);
7223
+ break;
6646
7224
 
6647
- case 'fill':
6648
- var fill = object.parsedStyle.fill;
6649
- var color = '';
7225
+ case 'fill':
7226
+ var fill = object.parsedStyle.fill;
7227
+ var color = '';
6650
7228
 
6651
- if (fill instanceof g.CSSRGB) {
6652
- color = fill.toString();
6653
- } else if (fill instanceof g.CSSGradientValue) {
6654
- if (fill.type === g.GradientPatternType.LinearGradient) {
6655
- var steps = fill.value.steps.map(function (cur) {
6656
- // ['0', '#ffffff'],
6657
- return cur[1] + " " + Number(cur[0]) * 100 + "%";
6658
- }).join(','); // @see https://developer.mozilla.org/en-US/docs/Web/CSS/gradient/linear-gradient()
7229
+ if (fill instanceof g.CSSRGB) {
7230
+ color = fill.toString();
7231
+ } else if (fill instanceof g.CSSGradientValue) {
7232
+ if (fill.type === g.GradientPatternType.LinearGradient) {
7233
+ var steps = fill.value.steps.map(function (cur) {
7234
+ // ['0', '#ffffff'],
7235
+ return "".concat(cur[1], " ").concat(Number(cur[0]) * 100, "%");
7236
+ }).join(','); // @see https://developer.mozilla.org/en-US/docs/Web/CSS/gradient/linear-gradient()
6659
7237
 
6660
- color = "linear-gradient(to right, " + steps + ");";
7238
+ color = "linear-gradient(to right, ".concat(steps, ");");
7239
+ }
6661
7240
  }
6662
- }
6663
7241
 
6664
- $el.style.background = color;
6665
- break;
7242
+ $el.style.background = color;
7243
+ break;
6666
7244
 
6667
- case 'stroke':
6668
- var stroke = object.parsedStyle.stroke;
6669
- $el.style['border-color'] = stroke.toString();
6670
- $el.style['border-style'] = 'solid';
6671
- break;
7245
+ case 'stroke':
7246
+ var stroke = object.parsedStyle.stroke;
7247
+ $el.style['border-color'] = stroke.toString();
7248
+ $el.style['border-style'] = 'solid';
7249
+ break;
6672
7250
 
6673
- case 'lineWidth':
6674
- var lineWidth = object.parsedStyle.lineWidth;
6675
- $el.style['border-width'] = (lineWidth.value || 0) + "px";
6676
- break;
7251
+ case 'lineWidth':
7252
+ var lineWidth = object.parsedStyle.lineWidth;
7253
+ $el.style['border-width'] = "".concat(lineWidth.value || 0, "px");
7254
+ break;
6677
7255
 
6678
- case 'lineDash':
6679
- $el.style['border-style'] = 'dashed';
6680
- break;
7256
+ case 'lineDash':
7257
+ $el.style['border-style'] = 'dashed';
7258
+ break;
6681
7259
 
6682
- case 'filter':
6683
- var filter = object.parsedStyle.filter;
6684
- $el.style.filter = filter;
6685
- break;
7260
+ case 'filter':
7261
+ var filter = object.parsedStyle.filter;
7262
+ $el.style.filter = filter;
7263
+ break;
7264
+ }
6686
7265
  }
6687
- };
7266
+ }]);
6688
7267
 
6689
7268
  return HTMLRenderingPlugin;
6690
7269
  }(), _class$3.tag = 'HTMLRendering', _class$3);
@@ -6702,18 +7281,22 @@
6702
7281
 
6703
7282
  var Plugin$3 = /*#__PURE__*/function () {
6704
7283
  function Plugin() {
7284
+ _classCallCheck$4(this, Plugin);
7285
+
6705
7286
  this.name = 'html-renderer';
6706
7287
  }
6707
7288
 
6708
- var _proto = Plugin.prototype;
6709
-
6710
- _proto.init = function init(container) {
6711
- container.load(containerModule$3, true);
6712
- };
6713
-
6714
- _proto.destroy = function destroy(container) {
6715
- container.unload(containerModule$3);
6716
- };
7289
+ _createClass$4(Plugin, [{
7290
+ key: "init",
7291
+ value: function init(container) {
7292
+ container.load(containerModule$3, true);
7293
+ }
7294
+ }, {
7295
+ key: "destroy",
7296
+ value: function destroy(container) {
7297
+ container.unload(containerModule$3);
7298
+ }
7299
+ }]);
6717
7300
 
6718
7301
  return Plugin;
6719
7302
  }();
@@ -6725,6 +7308,8 @@
6725
7308
 
6726
7309
  var Canvas2DContextService = /*#__PURE__*/function () {
6727
7310
  function Canvas2DContextService() {
7311
+ _classCallCheck(this, Canvas2DContextService);
7312
+
6728
7313
  this.$container = void 0;
6729
7314
  this.$canvas = void 0;
6730
7315
  this.dpr = void 0;
@@ -6732,94 +7317,102 @@
6732
7317
  this.canvasConfig = void 0;
6733
7318
  }
6734
7319
 
6735
- var _proto = Canvas2DContextService.prototype;
7320
+ _createClass(Canvas2DContextService, [{
7321
+ key: "init",
7322
+ value: function init() {
7323
+ var _this$canvasConfig = this.canvasConfig,
7324
+ container = _this$canvasConfig.container,
7325
+ canvas = _this$canvasConfig.canvas,
7326
+ devicePixelRatio = _this$canvasConfig.devicePixelRatio;
6736
7327
 
6737
- _proto.init = function init() {
6738
- var _this$canvasConfig = this.canvasConfig,
6739
- container = _this$canvasConfig.container,
6740
- canvas = _this$canvasConfig.canvas,
6741
- devicePixelRatio = _this$canvasConfig.devicePixelRatio;
7328
+ if (canvas) {
7329
+ this.$canvas = canvas;
6742
7330
 
6743
- if (canvas) {
6744
- this.$canvas = canvas;
7331
+ if (container && canvas.parentElement !== container) {
7332
+ container.appendChild(canvas);
7333
+ }
6745
7334
 
6746
- if (container && canvas.parentElement !== container) {
6747
- container.appendChild(canvas);
6748
- }
7335
+ this.$container = canvas.parentElement;
7336
+ this.canvasConfig.container = this.$container;
7337
+ } else if (container) {
7338
+ // create container
7339
+ this.$container = g.isString(container) ? document.getElementById(container) : container;
6749
7340
 
6750
- this.$container = canvas.parentElement;
6751
- this.canvasConfig.container = this.$container;
6752
- } else if (container) {
6753
- // create container
6754
- this.$container = g.isString(container) ? document.getElementById(container) : container;
7341
+ if (this.$container) {
7342
+ // create canvas
7343
+ var $canvas = document.createElement('canvas');
7344
+ this.$container.appendChild($canvas);
6755
7345
 
6756
- if (this.$container) {
6757
- // create canvas
6758
- var $canvas = document.createElement('canvas');
6759
- this.$container.appendChild($canvas);
7346
+ if (!this.$container.style.position) {
7347
+ this.$container.style.position = 'relative';
7348
+ }
6760
7349
 
6761
- if (!this.$container.style.position) {
6762
- this.$container.style.position = 'relative';
7350
+ this.$canvas = $canvas;
6763
7351
  }
6764
-
6765
- this.$canvas = $canvas;
6766
7352
  }
6767
- }
6768
-
6769
- this.context = this.$canvas.getContext('2d'); // use user-defined dpr first
6770
-
6771
- var dpr = devicePixelRatio || g.isBrowser && window.devicePixelRatio || 1;
6772
- dpr = dpr >= 1 ? Math.ceil(dpr) : 1;
6773
- this.dpr = dpr;
6774
- this.resize(this.canvasConfig.width, this.canvasConfig.height);
6775
- };
6776
-
6777
- _proto.getContext = function getContext() {
6778
- return this.context;
6779
- };
6780
7353
 
6781
- _proto.getDomElement = function getDomElement() {
6782
- return this.$canvas;
6783
- };
6784
-
6785
- _proto.getDPR = function getDPR() {
6786
- return this.dpr;
6787
- };
6788
-
6789
- _proto.getBoundingClientRect = function getBoundingClientRect() {
6790
- if (this.$canvas.getBoundingClientRect) {
6791
- return this.$canvas.getBoundingClientRect();
7354
+ this.context = this.$canvas.getContext('2d'); // use user-defined dpr first
7355
+
7356
+ var dpr = devicePixelRatio || g.isBrowser && window.devicePixelRatio || 1;
7357
+ dpr = dpr >= 1 ? Math.ceil(dpr) : 1;
7358
+ this.dpr = dpr;
7359
+ this.resize(this.canvasConfig.width, this.canvasConfig.height);
7360
+ }
7361
+ }, {
7362
+ key: "getContext",
7363
+ value: function getContext() {
7364
+ return this.context;
7365
+ }
7366
+ }, {
7367
+ key: "getDomElement",
7368
+ value: function getDomElement() {
7369
+ return this.$canvas;
7370
+ }
7371
+ }, {
7372
+ key: "getDPR",
7373
+ value: function getDPR() {
7374
+ return this.dpr;
7375
+ }
7376
+ }, {
7377
+ key: "getBoundingClientRect",
7378
+ value: function getBoundingClientRect() {
7379
+ if (this.$canvas.getBoundingClientRect) {
7380
+ return this.$canvas.getBoundingClientRect();
7381
+ }
6792
7382
  }
6793
- };
6794
-
6795
- _proto.destroy = function destroy() {
6796
- // @ts-ignore
6797
- if (this.$container && this.$canvas && this.$canvas.parentNode) {
6798
- // destroy context
7383
+ }, {
7384
+ key: "destroy",
7385
+ value: function destroy() {
6799
7386
  // @ts-ignore
6800
- this.$container.removeChild(this.$canvas);
7387
+ if (this.$container && this.$canvas && this.$canvas.parentNode) {
7388
+ // destroy context
7389
+ // @ts-ignore
7390
+ this.$container.removeChild(this.$canvas);
7391
+ }
6801
7392
  }
6802
- };
6803
-
6804
- _proto.resize = function resize(width, height) {
6805
- if (this.$canvas) {
6806
- // set canvas width & height
6807
- this.$canvas.width = this.dpr * width;
6808
- this.$canvas.height = this.dpr * height; // set CSS style width & height
7393
+ }, {
7394
+ key: "resize",
7395
+ value: function resize(width, height) {
7396
+ if (this.$canvas) {
7397
+ // set canvas width & height
7398
+ this.$canvas.width = this.dpr * width;
7399
+ this.$canvas.height = this.dpr * height; // set CSS style width & height
6809
7400
 
6810
- g.setDOMSize(this.$canvas, width, height);
6811
- var dpr = this.getDPR(); // scale all drawing operations by the dpr
6812
- // @see https://www.html5rocks.com/en/tutorials/canvas/hidpi/
7401
+ g.setDOMSize(this.$canvas, width, height);
7402
+ var dpr = this.getDPR(); // scale all drawing operations by the dpr
7403
+ // @see https://www.html5rocks.com/en/tutorials/canvas/hidpi/
6813
7404
 
6814
- this.context.scale(dpr, dpr);
7405
+ this.context.scale(dpr, dpr);
7406
+ }
6815
7407
  }
6816
- };
6817
-
6818
- _proto.applyCursorStyle = function applyCursorStyle(cursor) {
6819
- if (this.$container && this.$container.style) {
6820
- this.$container.style.cursor = cursor;
7408
+ }, {
7409
+ key: "applyCursorStyle",
7410
+ value: function applyCursorStyle(cursor) {
7411
+ if (this.$container && this.$container.style) {
7412
+ this.$container.style.cursor = cursor;
7413
+ }
6821
7414
  }
6822
- };
7415
+ }]);
6823
7416
 
6824
7417
  return Canvas2DContextService;
6825
7418
  }();
@@ -6838,29 +7431,37 @@
6838
7431
  });
6839
7432
  var ContextRegisterPlugin = /*#__PURE__*/function () {
6840
7433
  function ContextRegisterPlugin() {
7434
+ _classCallCheck(this, ContextRegisterPlugin);
7435
+
6841
7436
  this.name = 'canvas-context-register';
6842
7437
  }
6843
7438
 
6844
- var _proto = ContextRegisterPlugin.prototype;
6845
-
6846
- _proto.init = function init(container) {
6847
- container.load(containerModule$4, true);
6848
- };
6849
-
6850
- _proto.destroy = function destroy(container) {
6851
- container.unload(containerModule$4);
6852
- };
7439
+ _createClass(ContextRegisterPlugin, [{
7440
+ key: "init",
7441
+ value: function init(container) {
7442
+ container.load(containerModule$4, true);
7443
+ }
7444
+ }, {
7445
+ key: "destroy",
7446
+ value: function destroy(container) {
7447
+ container.unload(containerModule$4);
7448
+ }
7449
+ }]);
6853
7450
 
6854
7451
  return ContextRegisterPlugin;
6855
7452
  }();
6856
7453
 
6857
7454
  var Renderer = /*#__PURE__*/function (_AbstractRenderer) {
6858
- _inheritsLoose(Renderer, _AbstractRenderer);
7455
+ _inherits(Renderer, _AbstractRenderer);
7456
+
7457
+ var _super = _createSuper(Renderer);
6859
7458
 
6860
7459
  function Renderer(config) {
6861
7460
  var _this;
6862
7461
 
6863
- _this = _AbstractRenderer.call(this, config) || this; // register Canvas2DContext
7462
+ _classCallCheck(this, Renderer);
7463
+
7464
+ _this = _super.call(this, config); // register Canvas2DContext
6864
7465
 
6865
7466
  _this.registerPlugin(new ContextRegisterPlugin()); // enable rendering with Canvas2D API
6866
7467
 
@@ -6878,7 +7479,7 @@
6878
7479
  return _this;
6879
7480
  }
6880
7481
 
6881
- return Renderer;
7482
+ return _createClass(Renderer);
6882
7483
  }(g.AbstractRenderer);
6883
7484
 
6884
7485
  exports.CanvasPicker = index_esm$2;