@antv/g-canvas 1.1.3 → 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,165 +535,184 @@
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;
438
- var MOBILE_REGEX = /mobile|tablet|ip(ad|hone|od)|android/i;
439
566
  /**
440
567
  * listen to mouse/touch/pointer events on DOM wrapper, trigger pointer events
441
568
  */
442
569
 
443
570
  var DOMInteractionPlugin = DOMInteractionPlugin_1 = (_class = /*#__PURE__*/function () {
444
571
  function DOMInteractionPlugin() {
572
+ _classCallCheck$1(this, DOMInteractionPlugin);
573
+
445
574
  this.contextService = void 0;
446
575
  this.renderingContext = void 0;
447
576
  }
448
577
 
449
- var _proto = DOMInteractionPlugin.prototype;
578
+ _createClass$1(DOMInteractionPlugin, [{
579
+ key: "apply",
580
+ value: function apply(renderingService) {
581
+ var _this = this;
450
582
 
451
- _proto.apply = function apply(renderingService) {
452
- var _this = this;
453
-
454
- var canvas = this.renderingContext.root.ownerDocument.defaultView;
455
- var SUPPORT_ONLY_TOUCH = canvas.supportTouchEvent && MOBILE_REGEX.test(navigator.userAgent);
583
+ var canvas = this.renderingContext.root.ownerDocument.defaultView; // const SUPPORT_ONLY_TOUCH = canvas.supportsTouchEvents && MOBILE_REGEX.test(navigator.userAgent);
456
584
 
457
- var onPointerMove = function onPointerMove(ev) {
458
- renderingService.hooks.pointerMove.call(ev);
459
- };
585
+ var onPointerMove = function onPointerMove(ev) {
586
+ renderingService.hooks.pointerMove.call(ev);
587
+ };
460
588
 
461
- var onPointerUp = function onPointerUp(ev) {
462
- renderingService.hooks.pointerUp.call(ev);
463
- };
589
+ var onPointerUp = function onPointerUp(ev) {
590
+ renderingService.hooks.pointerUp.call(ev);
591
+ };
464
592
 
465
- var onPointerDown = function onPointerDown(ev) {
466
- renderingService.hooks.pointerDown.call(ev);
467
- };
593
+ var onPointerDown = function onPointerDown(ev) {
594
+ renderingService.hooks.pointerDown.call(ev);
595
+ };
468
596
 
469
- var onPointerOver = function onPointerOver(ev) {
470
- renderingService.hooks.pointerOver.call(ev);
471
- };
597
+ var onPointerOver = function onPointerOver(ev) {
598
+ renderingService.hooks.pointerOver.call(ev);
599
+ };
472
600
 
473
- var onPointerOut = function onPointerOut(ev) {
474
- renderingService.hooks.pointerOut.call(ev);
475
- };
601
+ var onPointerOut = function onPointerOut(ev) {
602
+ renderingService.hooks.pointerOut.call(ev);
603
+ };
476
604
 
477
- var onPointerCancel = function onPointerCancel(ev) {
478
- renderingService.hooks.pointerCancel.call(ev);
479
- };
605
+ var onPointerCancel = function onPointerCancel(ev) {
606
+ renderingService.hooks.pointerCancel.call(ev);
607
+ };
480
608
 
481
- var onPointerWheel = function onPointerWheel(ev) {
482
- renderingService.hooks.pointerWheel.call(ev);
483
- };
609
+ var onPointerWheel = function onPointerWheel(ev) {
610
+ renderingService.hooks.pointerWheel.call(ev);
611
+ };
484
612
 
485
- var addPointerEventListener = function addPointerEventListener($el) {
486
- globalThis.document.addEventListener('pointermove', onPointerMove, true);
487
- $el.addEventListener('pointerdown', onPointerDown, true);
488
- $el.addEventListener('pointerleave', onPointerOut, true);
489
- $el.addEventListener('pointerover', onPointerOver, true);
490
- globalThis.addEventListener('pointerup', onPointerUp, true);
491
- };
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
+ };
492
620
 
493
- var addTouchEventListener = function addTouchEventListener($el) {
494
- $el.addEventListener('touchstart', onPointerDown, true);
495
- $el.addEventListener('touchend', onPointerUp, true);
496
- $el.addEventListener('touchmove', onPointerMove, true);
497
- $el.addEventListener('touchcancel', onPointerCancel, true);
498
- };
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
+ };
499
627
 
500
- var addMouseEventListener = function addMouseEventListener($el) {
501
- globalThis.document.addEventListener('mousemove', onPointerMove, true);
502
- $el.addEventListener('mousedown', onPointerDown, true);
503
- $el.addEventListener('mouseout', onPointerOut, true);
504
- $el.addEventListener('mouseover', onPointerOver, true);
505
- globalThis.addEventListener('mouseup', onPointerUp, true);
506
- };
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
+ };
507
635
 
508
- var removePointerEventListener = function removePointerEventListener($el) {
509
- globalThis.document.removeEventListener('pointermove', onPointerMove, true);
510
- $el.removeEventListener('pointerdown', onPointerDown, true);
511
- $el.removeEventListener('pointerleave', onPointerOut, true);
512
- $el.removeEventListener('pointerover', onPointerOver, true);
513
- globalThis.removeEventListener('pointerup', onPointerUp, true);
514
- };
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
+ };
515
643
 
516
- var removeTouchEventListener = function removeTouchEventListener($el) {
517
- $el.removeEventListener('touchstart', onPointerDown, true);
518
- $el.removeEventListener('touchend', onPointerUp, true);
519
- $el.removeEventListener('touchmove', onPointerMove, true);
520
- };
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
+ };
521
649
 
522
- var removeMouseEventListener = function removeMouseEventListener($el) {
523
- globalThis.document.removeEventListener('mousemove', onPointerMove, true);
524
- $el.removeEventListener('mousedown', onPointerDown, true);
525
- $el.removeEventListener('mouseout', onPointerOut, true);
526
- $el.removeEventListener('mouseover', onPointerOver, true);
527
- globalThis.removeEventListener('mouseup', onPointerUp, true);
528
- };
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
+ };
529
657
 
530
- renderingService.hooks.init.tapPromise(DOMInteractionPlugin_1.tag, /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
531
- var $el;
532
- return _regeneratorRuntime().wrap(function _callee$(_context) {
533
- while (1) {
534
- switch (_context.prev = _context.next) {
535
- case 0:
536
- $el = _this.contextService.getDomElement();
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
537
665
 
538
- if (canvas.supportPointerEvent) {
539
- addPointerEventListener($el);
540
- }
666
+ if (globalThis.navigator.msPointerEnabled) {
667
+ // @ts-ignore
668
+ $el.style.msContentZooming = 'none'; // @ts-ignore
541
669
 
542
- if (SUPPORT_ONLY_TOUCH) {
543
- addTouchEventListener($el);
544
- } else if (!canvas.supportTouchEvent) {
545
- if (!canvas.supportPointerEvent) {
546
- addMouseEventListener($el);
670
+ $el.style.msTouchAction = 'none';
671
+ } else if (canvas.supportsPointerEvents) {
672
+ $el.style.touchAction = 'none';
547
673
  }
548
- } else {
549
- addTouchEventListener($el);
550
674
 
551
- if (!canvas.supportPointerEvent) {
675
+ if (canvas.supportsPointerEvents) {
676
+ addPointerEventListener($el);
677
+ } else {
552
678
  addMouseEventListener($el);
553
679
  }
554
- } // use passive event listeners
555
- // @see https://zhuanlan.zhihu.com/p/24555031
556
680
 
681
+ if (canvas.supportsTouchEvents) {
682
+ addTouchEventListener($el);
683
+ } // use passive event listeners
684
+ // @see https://zhuanlan.zhihu.com/p/24555031
557
685
 
558
- $el.addEventListener('wheel', onPointerWheel, {
559
- passive: true,
560
- capture: true
561
- });
562
686
 
563
- case 4:
564
- case "end":
565
- return _context.stop();
566
- }
567
- }
568
- }, _callee);
569
- })));
570
- renderingService.hooks.destroy.tap(DOMInteractionPlugin_1.tag, function () {
571
- var $el = _this.contextService.getDomElement();
687
+ $el.addEventListener('wheel', onPointerWheel, {
688
+ passive: true,
689
+ capture: true
690
+ });
572
691
 
573
- if (canvas.supportPointerEvent) {
574
- removePointerEventListener($el);
575
- }
692
+ case 5:
693
+ case "end":
694
+ return _context.stop();
695
+ }
696
+ }
697
+ }, _callee);
698
+ })));
699
+ renderingService.hooks.destroy.tap(DOMInteractionPlugin_1.tag, function () {
700
+ var $el = _this.contextService.getDomElement();
576
701
 
577
- if (SUPPORT_ONLY_TOUCH) {
578
- removeTouchEventListener($el);
579
- } else if (!canvas.supportTouchEvent) {
580
- if (!canvas.supportPointerEvent) {
702
+ if (canvas.supportsPointerEvents) {
703
+ removePointerEventListener($el);
704
+ } else {
581
705
  removeMouseEventListener($el);
582
706
  }
583
- } else {
584
- removeTouchEventListener($el);
585
707
 
586
- if (!canvas.supportPointerEvent) {
587
- removeMouseEventListener($el);
708
+ if (canvas.supportsTouchEvents) {
709
+ removeTouchEventListener($el);
588
710
  }
589
- }
590
711
 
591
- $el.removeEventListener('wheel', onPointerWheel, true);
592
- });
593
- };
712
+ $el.removeEventListener('wheel', onPointerWheel, true);
713
+ });
714
+ }
715
+ }]);
594
716
 
595
717
  return DOMInteractionPlugin;
596
718
  }(), _class.tag = 'DOMInteraction', _class);
@@ -608,18 +730,22 @@
608
730
 
609
731
  var Plugin = /*#__PURE__*/function () {
610
732
  function Plugin() {
733
+ _classCallCheck$1(this, Plugin);
734
+
611
735
  this.name = 'dom-interaction';
612
736
  }
613
737
 
614
- var _proto = Plugin.prototype;
615
-
616
- _proto.init = function init(container) {
617
- container.load(containerModule, true);
618
- };
619
-
620
- _proto.destroy = function destroy(container) {
621
- container.unload(containerModule);
622
- };
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
+ }]);
623
749
 
624
750
  return Plugin;
625
751
  }();
@@ -1194,418 +1320,123 @@
1194
1320
  }
1195
1321
  }
1196
1322
 
1197
- var StyleRendererFactory = manaSyringe.Syringe.defineToken('StyleRendererFactory');
1198
- var CircleRendererContribution = manaSyringe.Syringe.defineToken('CircleRenderer', {
1199
- multiple: false
1200
- });
1201
- var EllipseRendererContribution = manaSyringe.Syringe.defineToken('EllipseRenderer', {
1202
- multiple: false
1203
- });
1204
- var RectRendererContribution = manaSyringe.Syringe.defineToken('RectRenderer', {
1205
- multiple: false
1206
- });
1207
- var LineRendererContribution = manaSyringe.Syringe.defineToken('LineRenderer', {
1208
- multiple: false
1209
- });
1210
- var PolylineRendererContribution = manaSyringe.Syringe.defineToken('PolylineRenderer', {
1211
- multiple: false
1212
- });
1213
- var PolygonRendererContribution = manaSyringe.Syringe.defineToken('PolygonRenderer', {
1214
- multiple: false
1215
- });
1216
- var PathRendererContribution = manaSyringe.Syringe.defineToken('PathRenderer', {
1217
- multiple: false
1218
- });
1219
- var TextRendererContribution = manaSyringe.Syringe.defineToken('TextRenderer', {
1220
- multiple: false
1221
- });
1222
- var ImageRendererContribution = manaSyringe.Syringe.defineToken('ImageRenderer', {
1223
- multiple: false
1224
- });
1323
+ function ownKeys(object, enumerableOnly) {
1324
+ var keys = Object.keys(object);
1225
1325
 
1226
- var ImagePool = /*#__PURE__*/function () {
1227
- function ImagePool() {
1228
- this.imageCache = {};
1229
- this.patternCache = {};
1230
- this.canvasConfig = void 0;
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);
1231
1331
  }
1232
1332
 
1233
- var _proto = ImagePool.prototype;
1234
-
1235
- _proto.getImageSync = function getImageSync(src) {
1236
- return this.imageCache[src];
1237
- };
1238
-
1239
- _proto.getOrCreateImage = function getOrCreateImage(src) {
1240
- var _this = this;
1241
-
1242
- if (this.imageCache[src]) {
1243
- return Promise.resolve(this.imageCache[src]);
1244
- } // @see https://github.com/antvis/g/issues/938
1245
-
1246
-
1247
- var createImage = this.canvasConfig.createImage;
1248
- return new Promise(function (resolve, reject) {
1249
- var image;
1250
-
1251
- if (createImage) {
1252
- image = createImage(src);
1253
- } else if (g.isBrowser) {
1254
- image = new window.Image();
1255
- }
1256
-
1257
- if (image) {
1258
- image.onload = function () {
1259
- resolve(image);
1260
- };
1261
-
1262
- image.onerror = function (ev) {
1263
- reject(ev);
1264
- };
1333
+ return keys;
1334
+ }
1265
1335
 
1266
- image.crossOrigin = 'Anonymous';
1267
- image.src = src;
1268
- _this.imageCache[src] = image;
1269
- }
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));
1270
1343
  });
1271
- };
1344
+ }
1272
1345
 
1273
- _proto.getPatternSync = function getPatternSync(pattern) {
1274
- var patternKey = this.generatePatternKey(pattern);
1346
+ return target;
1347
+ }
1275
1348
 
1276
- if (this.patternCache[patternKey]) {
1277
- return this.patternCache[patternKey];
1278
- }
1349
+ function _regeneratorRuntime$1() {
1350
+ /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */
1351
+ _regeneratorRuntime$1 = function _regeneratorRuntime() {
1352
+ return exports;
1279
1353
  };
1280
1354
 
1281
- _proto.createPattern = function createPattern(patternParams, context) {
1282
- var _this2 = this;
1355
+ var exports = {},
1356
+ Op = Object.prototype,
1357
+ hasOwn = Op.hasOwnProperty,
1358
+ $Symbol = "function" == typeof Symbol ? Symbol : {},
1359
+ iteratorSymbol = $Symbol.iterator || "@@iterator",
1360
+ asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator",
1361
+ toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag";
1283
1362
 
1284
- return this.getOrCreateImage(patternParams.src).then(function (image) {
1285
- var patternKey = _this2.generatePatternKey(patternParams); // @see https://developer.mozilla.org/zh-CN/docs/Web/API/CanvasRenderingContext2D/createPattern
1363
+ function define(obj, key, value) {
1364
+ return Object.defineProperty(obj, key, {
1365
+ value: value,
1366
+ enumerable: !0,
1367
+ configurable: !0,
1368
+ writable: !0
1369
+ }), obj[key];
1370
+ }
1286
1371
 
1372
+ try {
1373
+ define({}, "");
1374
+ } catch (err) {
1375
+ define = function define(obj, key, value) {
1376
+ return obj[key] = value;
1377
+ };
1378
+ }
1287
1379
 
1288
- var pattern = context.createPattern(image, patternParams.repetition);
1380
+ function wrap(innerFn, outerFn, self, tryLocsList) {
1381
+ var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator,
1382
+ generator = Object.create(protoGenerator.prototype),
1383
+ context = new Context(tryLocsList || []);
1384
+ return generator._invoke = function (innerFn, self, context) {
1385
+ var state = "suspendedStart";
1386
+ return function (method, arg) {
1387
+ if ("executing" === state) throw new Error("Generator is already running");
1289
1388
 
1290
- if (pattern) {
1291
- _this2.patternCache[patternKey] = pattern;
1292
- }
1389
+ if ("completed" === state) {
1390
+ if ("throw" === method) throw arg;
1391
+ return doneResult();
1392
+ }
1293
1393
 
1294
- return _this2.patternCache[patternKey];
1295
- });
1296
- };
1394
+ for (context.method = method, context.arg = arg;;) {
1395
+ var delegate = context.delegate;
1297
1396
 
1298
- _proto.generatePatternKey = function generatePatternKey(pattern) {
1299
- var src = pattern.src,
1300
- repetition = pattern.repetition;
1301
- return "pattern-" + src + "-" + repetition;
1302
- };
1397
+ if (delegate) {
1398
+ var delegateResult = maybeInvokeDelegate(delegate, context);
1303
1399
 
1304
- return ImagePool;
1305
- }();
1400
+ if (delegateResult) {
1401
+ if (delegateResult === ContinueSentinel) continue;
1402
+ return delegateResult;
1403
+ }
1404
+ }
1306
1405
 
1307
- __decorate([manaSyringe.inject(g.CanvasConfig), __metadata("design:type", Object)], ImagePool.prototype, "canvasConfig", void 0);
1406
+ if ("next" === context.method) context.sent = context._sent = context.arg;else if ("throw" === context.method) {
1407
+ if ("suspendedStart" === state) throw state = "completed", context.arg;
1408
+ context.dispatchException(context.arg);
1409
+ } else "return" === context.method && context.abrupt("return", context.arg);
1410
+ state = "executing";
1411
+ var record = tryCatch(innerFn, self, context);
1308
1412
 
1309
- ImagePool = __decorate([manaSyringe.singleton()], ImagePool);
1413
+ if ("normal" === record.type) {
1414
+ if (state = context.done ? "completed" : "suspendedYield", record.arg === ContinueSentinel) continue;
1415
+ return {
1416
+ value: record.arg,
1417
+ done: context.done
1418
+ };
1419
+ }
1310
1420
 
1311
- var ImageRenderer = /*#__PURE__*/function () {
1312
- function ImageRenderer() {
1313
- this.imagePool = void 0;
1421
+ "throw" === record.type && (state = "completed", context.method = "throw", context.arg = record.arg);
1422
+ }
1423
+ };
1424
+ }(innerFn, self, context), generator;
1314
1425
  }
1315
1426
 
1316
- var _proto = ImageRenderer.prototype;
1317
-
1318
- _proto.hash = function hash(parsedStyle) {
1319
- return '';
1320
- };
1321
-
1322
- _proto.render = function render(context, parsedStyle) {
1323
- var width = parsedStyle.width,
1324
- height = parsedStyle.height,
1325
- img = parsedStyle.img;
1326
- var image;
1327
- var iw = width.value;
1328
- var ih = height.value;
1329
-
1330
- if (g.isString(img)) {
1331
- // image has been loaded in `mounted` hook
1332
- image = this.imagePool.getImageSync(img);
1333
- } else {
1334
- iw || (iw = img.width);
1335
- ih || (ih = img.height);
1336
- image = img;
1427
+ function tryCatch(fn, obj, arg) {
1428
+ try {
1429
+ return {
1430
+ type: "normal",
1431
+ arg: fn.call(obj, arg)
1432
+ };
1433
+ } catch (err) {
1434
+ return {
1435
+ type: "throw",
1436
+ arg: err
1437
+ };
1337
1438
  }
1338
-
1339
- if (image) {
1340
- // node-canvas will throw the following err:
1341
- // Error: Image given has not completed loading
1342
- try {
1343
- context.drawImage(image, 0, 0, iw, ih);
1344
- } catch (e) {}
1345
- }
1346
- };
1347
-
1348
- return ImageRenderer;
1349
- }();
1350
-
1351
- __decorate([manaSyringe.inject(ImagePool), __metadata("design:type", ImagePool)], ImageRenderer.prototype, "imagePool", void 0);
1352
-
1353
- ImageRenderer = __decorate([manaSyringe.singleton({
1354
- token: ImageRendererContribution
1355
- })], ImageRenderer);
1356
-
1357
- var TextRenderer = /*#__PURE__*/function () {
1358
- function TextRenderer() {}
1359
-
1360
- var _proto = TextRenderer.prototype;
1361
-
1362
- _proto.hash = function hash(parsedStyle) {
1363
- return '';
1364
- };
1365
-
1366
- _proto.render = function render(context, parsedStyle, object) {
1367
- var lineWidth = parsedStyle.lineWidth,
1368
- textAlign = parsedStyle.textAlign,
1369
- textBaseline = parsedStyle.textBaseline,
1370
- lineJoin = parsedStyle.lineJoin,
1371
- _parsedStyle$miterLim = parsedStyle.miterLimit,
1372
- miterLimit = _parsedStyle$miterLim === void 0 ? 0 : _parsedStyle$miterLim,
1373
- _parsedStyle$letterSp = parsedStyle.letterSpacing,
1374
- letterSpacing = _parsedStyle$letterSp === void 0 ? 0 : _parsedStyle$letterSp,
1375
- stroke = parsedStyle.stroke,
1376
- fill = parsedStyle.fill,
1377
- fillOpacity = parsedStyle.fillOpacity,
1378
- strokeOpacity = parsedStyle.strokeOpacity,
1379
- opacity = parsedStyle.opacity,
1380
- metrics = parsedStyle.metrics,
1381
- dx = parsedStyle.dx,
1382
- dy = parsedStyle.dy;
1383
- var font = metrics.font,
1384
- lines = metrics.lines,
1385
- height = metrics.height,
1386
- lineHeight = metrics.lineHeight,
1387
- lineMetrics = metrics.lineMetrics;
1388
- context.font = font;
1389
- context.lineWidth = lineWidth.value;
1390
- context.textAlign = textAlign.value;
1391
- context.textBaseline = textBaseline.value;
1392
- context.lineJoin = lineJoin.value;
1393
- context.miterLimit = miterLimit;
1394
- var linePositionY = 0; // handle vertical text baseline
1395
-
1396
- if (textBaseline.value === 'middle') {
1397
- linePositionY = -height / 2 - lineHeight / 2;
1398
- } else if (textBaseline.value === 'bottom' || textBaseline.value === 'alphabetic' || textBaseline.value === 'ideographic') {
1399
- linePositionY = -height;
1400
- } else if (textBaseline.value === 'top' || textBaseline.value === 'hanging') {
1401
- linePositionY = -lineHeight;
1402
- } // account for dx & dy
1403
-
1404
-
1405
- var offsetX = 0;
1406
-
1407
- if (dx && dx.unit === g.UnitType.kPixels) {
1408
- offsetX += dx.value;
1409
- }
1410
-
1411
- if (dy && dy.unit === g.UnitType.kPixels) {
1412
- linePositionY += dy.value;
1413
- } // draw lines line by line
1414
-
1415
-
1416
- for (var i = 0; i < lines.length; i++) {
1417
- var linePositionX = lineWidth.value / 2 + offsetX;
1418
- linePositionY += lineHeight; // no need to re-position X, cause we already set text align
1419
- // @see https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/textAlign
1420
-
1421
- if (!g.isNil(stroke) && lineWidth && lineWidth.value) {
1422
- this.drawLetterSpacing(context, lines[i], lineMetrics[i], textAlign.value, linePositionX, linePositionY, letterSpacing, fillOpacity.value, strokeOpacity.value, opacity.value, true);
1423
- }
1424
-
1425
- if (!g.isNil(fill)) {
1426
- this.drawLetterSpacing(context, lines[i], lineMetrics[i], textAlign.value, linePositionX, linePositionY, letterSpacing, fillOpacity.value, strokeOpacity.value, opacity.value);
1427
- }
1428
- }
1429
- };
1430
-
1431
- _proto.drawLetterSpacing = function drawLetterSpacing(context, text, lineMetrics, textAlign, x, y, letterSpacing, fillOpacity, strokeOpacity, opacity, isStroke) {
1432
- if (isStroke === void 0) {
1433
- isStroke = false;
1434
- } // letterSpacing of 0 means normal, render all texts directly
1435
-
1436
-
1437
- if (letterSpacing === 0) {
1438
- if (isStroke) {
1439
- this.strokeText(context, text, x, y, strokeOpacity);
1440
- } else {
1441
- this.fillText(context, text, x, y, fillOpacity, opacity);
1442
- }
1443
-
1444
- return;
1445
- } // draw text using left align
1446
-
1447
-
1448
- var currentTextAlign = context.textAlign;
1449
- context.textAlign = 'left';
1450
- var currentPosition = x;
1451
-
1452
- if (textAlign === 'center') {
1453
- currentPosition = x - lineMetrics.width / 2;
1454
- } else if (textAlign === 'right' || textAlign === 'end') {
1455
- currentPosition = x - lineMetrics.width;
1456
- }
1457
-
1458
- var stringArray = Array.from(text);
1459
- var previousWidth = context.measureText(text).width;
1460
- var currentWidth = 0;
1461
-
1462
- for (var i = 0; i < stringArray.length; ++i) {
1463
- var currentChar = stringArray[i];
1464
-
1465
- if (isStroke) {
1466
- this.strokeText(context, currentChar, currentPosition, y, strokeOpacity);
1467
- } else {
1468
- this.fillText(context, currentChar, currentPosition, y, fillOpacity, opacity);
1469
- }
1470
-
1471
- currentWidth = context.measureText(text.substring(i + 1)).width;
1472
- currentPosition += previousWidth - currentWidth + letterSpacing;
1473
- previousWidth = currentWidth;
1474
- }
1475
-
1476
- context.textAlign = currentTextAlign;
1477
- };
1478
-
1479
- _proto.fillText = function fillText(context, text, x, y, fillOpacity, opacity) {
1480
- var currentGlobalAlpha;
1481
- var applyOpacity = !g.isNil(fillOpacity) && fillOpacity !== 1;
1482
-
1483
- if (applyOpacity) {
1484
- currentGlobalAlpha = context.globalAlpha;
1485
- context.globalAlpha = fillOpacity * opacity;
1486
- }
1487
-
1488
- context.fillText(text, x, y);
1489
-
1490
- if (applyOpacity) {
1491
- context.globalAlpha = currentGlobalAlpha;
1492
- }
1493
- };
1494
-
1495
- _proto.strokeText = function strokeText(context, text, x, y, strokeOpacity) {
1496
- var currentGlobalAlpha;
1497
- var applyOpacity = !g.isNil(strokeOpacity) && strokeOpacity !== 1;
1498
-
1499
- if (applyOpacity) {
1500
- currentGlobalAlpha = context.globalAlpha;
1501
- context.globalAlpha = strokeOpacity;
1502
- }
1503
-
1504
- context.strokeText(text, x, y);
1505
-
1506
- if (applyOpacity) {
1507
- context.globalAlpha = currentGlobalAlpha;
1508
- }
1509
- };
1510
-
1511
- return TextRenderer;
1512
- }();
1513
-
1514
- TextRenderer = __decorate([manaSyringe.singleton({
1515
- token: TextRendererContribution
1516
- })], TextRenderer);
1517
-
1518
- function _regeneratorRuntime$1() {
1519
- /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */
1520
- _regeneratorRuntime$1 = function _regeneratorRuntime() {
1521
- return exports;
1522
- };
1523
-
1524
- var exports = {},
1525
- Op = Object.prototype,
1526
- hasOwn = Op.hasOwnProperty,
1527
- $Symbol = "function" == typeof Symbol ? Symbol : {},
1528
- iteratorSymbol = $Symbol.iterator || "@@iterator",
1529
- asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator",
1530
- toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag";
1531
-
1532
- function define(obj, key, value) {
1533
- return Object.defineProperty(obj, key, {
1534
- value: value,
1535
- enumerable: !0,
1536
- configurable: !0,
1537
- writable: !0
1538
- }), obj[key];
1539
- }
1540
-
1541
- try {
1542
- define({}, "");
1543
- } catch (err) {
1544
- define = function define(obj, key, value) {
1545
- return obj[key] = value;
1546
- };
1547
- }
1548
-
1549
- function wrap(innerFn, outerFn, self, tryLocsList) {
1550
- var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator,
1551
- generator = Object.create(protoGenerator.prototype),
1552
- context = new Context(tryLocsList || []);
1553
- return generator._invoke = function (innerFn, self, context) {
1554
- var state = "suspendedStart";
1555
- return function (method, arg) {
1556
- if ("executing" === state) throw new Error("Generator is already running");
1557
-
1558
- if ("completed" === state) {
1559
- if ("throw" === method) throw arg;
1560
- return doneResult();
1561
- }
1562
-
1563
- for (context.method = method, context.arg = arg;;) {
1564
- var delegate = context.delegate;
1565
-
1566
- if (delegate) {
1567
- var delegateResult = maybeInvokeDelegate(delegate, context);
1568
-
1569
- if (delegateResult) {
1570
- if (delegateResult === ContinueSentinel) continue;
1571
- return delegateResult;
1572
- }
1573
- }
1574
-
1575
- if ("next" === context.method) context.sent = context._sent = context.arg;else if ("throw" === context.method) {
1576
- if ("suspendedStart" === state) throw state = "completed", context.arg;
1577
- context.dispatchException(context.arg);
1578
- } else "return" === context.method && context.abrupt("return", context.arg);
1579
- state = "executing";
1580
- var record = tryCatch(innerFn, self, context);
1581
-
1582
- if ("normal" === record.type) {
1583
- if (state = context.done ? "completed" : "suspendedYield", record.arg === ContinueSentinel) continue;
1584
- return {
1585
- value: record.arg,
1586
- done: context.done
1587
- };
1588
- }
1589
-
1590
- "throw" === record.type && (state = "completed", context.method = "throw", context.arg = record.arg);
1591
- }
1592
- };
1593
- }(innerFn, self, context), generator;
1594
- }
1595
-
1596
- function tryCatch(fn, obj, arg) {
1597
- try {
1598
- return {
1599
- type: "normal",
1600
- arg: fn.call(obj, arg)
1601
- };
1602
- } catch (err) {
1603
- return {
1604
- type: "throw",
1605
- arg: err
1606
- };
1607
- }
1608
- }
1439
+ }
1609
1440
 
1610
1441
  exports.wrap = wrap;
1611
1442
  var ContinueSentinel = {};
@@ -1640,7 +1471,7 @@
1640
1471
  if ("throw" !== record.type) {
1641
1472
  var result = record.arg,
1642
1473
  value = result.value;
1643
- 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) {
1644
1475
  invoke("next", value, resolve, reject);
1645
1476
  }, function (err) {
1646
1477
  invoke("throw", err, resolve, reject);
@@ -1901,29 +1732,69 @@
1901
1732
  };
1902
1733
  }
1903
1734
 
1904
- function _extends() {
1905
- _extends = Object.assign || function (target) {
1906
- for (var i = 1; i < arguments.length; i++) {
1907
- 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
+ }
1908
1740
 
1909
- for (var key in source) {
1910
- if (Object.prototype.hasOwnProperty.call(source, key)) {
1911
- target[key] = source[key];
1912
- }
1913
- }
1914
- }
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
+ }
1915
1750
 
1916
- return target;
1917
- };
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
+ }
1918
1771
 
1919
- return _extends.apply(this, arguments);
1772
+ return obj;
1920
1773
  }
1921
1774
 
1922
- function _inheritsLoose$1(subClass, superClass) {
1923
- subClass.prototype = Object.create(superClass.prototype);
1924
- 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
+ }
1925
1792
 
1926
- _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);
1927
1798
  }
1928
1799
 
1929
1800
  function _setPrototypeOf$1(o, p) {
@@ -1935,465 +1806,147 @@
1935
1806
  return _setPrototypeOf$1(o, p);
1936
1807
  }
1937
1808
 
1938
- var DefaultRenderer = /*#__PURE__*/function () {
1939
- function DefaultRenderer() {}
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;
1940
1813
 
1941
- var _proto = DefaultRenderer.prototype;
1814
+ try {
1815
+ Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {}));
1816
+ return true;
1817
+ } catch (e) {
1818
+ return false;
1819
+ }
1820
+ }
1942
1821
 
1943
- _proto.hash = function hash(parsedStyle) {
1944
- // const { fill, opacity, fillOpacity, stroke, strokeOpacity, lineWidth, lineCap, lineJoin } =
1945
- // parsedStyle;
1946
- // return fill + opacity + fillOpacity + stroke + strokeOpacity + lineWidth + lineCap + lineJoin;
1947
- return '';
1948
- };
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
+ }
1949
1826
 
1950
- _proto.render = function render(context, parsedStyle) {
1951
- var fill = parsedStyle.fill,
1952
- opacity = parsedStyle.opacity,
1953
- fillOpacity = parsedStyle.fillOpacity,
1954
- stroke = parsedStyle.stroke,
1955
- strokeOpacity = parsedStyle.strokeOpacity,
1956
- lineWidth = parsedStyle.lineWidth,
1957
- lineCap = parsedStyle.lineCap,
1958
- lineJoin = parsedStyle.lineJoin,
1959
- shadowColor = parsedStyle.shadowColor,
1960
- filter = parsedStyle.filter,
1961
- miterLimit = parsedStyle.miterLimit;
1962
- var hasFill = !g.isNil(fill);
1963
- var hasStroke = !g.isNil(stroke);
1964
- var isFillTransparent = fill.alpha === 0;
1827
+ return self;
1828
+ }
1965
1829
 
1966
- if (hasFill) {
1967
- if (!g.isNil(fillOpacity) && fillOpacity.value !== 1) {
1968
- context.globalAlpha = fillOpacity.value;
1969
- context.fill();
1970
- context.globalAlpha = opacity.value;
1971
- } else {
1972
- context.fill();
1973
- }
1974
- }
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
+ }
1975
1836
 
1976
- if (hasStroke) {
1977
- if (lineWidth && lineWidth.value > 0) {
1978
- var applyOpacity = !g.isNil(strokeOpacity) && strokeOpacity.value !== 1;
1837
+ return _assertThisInitialized$1(self);
1838
+ }
1979
1839
 
1980
- if (applyOpacity) {
1981
- context.globalAlpha = strokeOpacity.value;
1982
- }
1840
+ function _createSuper$1(Derived) {
1841
+ var hasNativeReflectConstruct = _isNativeReflectConstruct$1();
1983
1842
 
1984
- context.lineWidth = lineWidth.value;
1843
+ return function _createSuperInternal() {
1844
+ var Super = _getPrototypeOf$1(Derived),
1845
+ result;
1985
1846
 
1986
- if (!g.isNil(miterLimit)) {
1987
- context.miterLimit = miterLimit;
1988
- }
1847
+ if (hasNativeReflectConstruct) {
1848
+ var NewTarget = _getPrototypeOf$1(this).constructor;
1989
1849
 
1990
- if (!g.isNil(lineCap)) {
1991
- context.lineCap = lineCap.value;
1992
- }
1850
+ result = Reflect.construct(Super, arguments, NewTarget);
1851
+ } else {
1852
+ result = Super.apply(this, arguments);
1853
+ }
1993
1854
 
1994
- if (!g.isNil(lineJoin)) {
1995
- context.lineJoin = lineJoin.value;
1996
- }
1855
+ return _possibleConstructorReturn$1(this, result);
1856
+ };
1857
+ }
1997
1858
 
1998
- var oldShadowBlur;
1999
- var oldShadowColor;
2000
- var oldFilter;
2001
- var hasShadowColor = !g.isNil(shadowColor);
2002
- var hasFilter = !g.isNil(filter);
2003
-
2004
- if (hasShadowColor) {
2005
- // prevent inner shadow when drawing stroke, toggle shadowBlur & filter(drop-shadow)
2006
- // save shadow blur
2007
- oldShadowBlur = context.shadowBlur;
2008
- oldShadowColor = context.shadowColor;
2009
-
2010
- if (!g.isNil(oldShadowBlur)) {
2011
- context.shadowColor = 'transparent';
2012
- context.shadowBlur = 0;
2013
- }
2014
- }
1859
+ function _slicedToArray(arr, i) {
1860
+ return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest();
1861
+ }
2015
1862
 
2016
- if (hasFilter) {
2017
- // save drop-shadow filter
2018
- oldFilter = context.filter;
1863
+ function _toConsumableArray(arr) {
1864
+ return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread();
1865
+ }
2019
1866
 
2020
- if (!g.isNil(oldFilter) && oldFilter.indexOf('drop-shadow') > -1) {
2021
- context.filter = oldFilter.replace(/drop-shadow\([^)]*\)/, '').trim() || 'none';
2022
- }
2023
- }
1867
+ function _arrayWithoutHoles(arr) {
1868
+ if (Array.isArray(arr)) return _arrayLikeToArray(arr);
1869
+ }
2024
1870
 
2025
- var drawStroke = hasFill && !isFillTransparent;
1871
+ function _arrayWithHoles(arr) {
1872
+ if (Array.isArray(arr)) return arr;
1873
+ }
2026
1874
 
2027
- if (drawStroke) {
2028
- context.stroke();
2029
- } // restore shadow blur
1875
+ function _iterableToArray(iter) {
1876
+ if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
1877
+ }
2030
1878
 
1879
+ function _iterableToArrayLimit(arr, i) {
1880
+ var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
2031
1881
 
2032
- if (hasShadowColor) {
2033
- context.shadowColor = oldShadowColor;
2034
- context.shadowBlur = oldShadowBlur;
2035
- } // restore filters
1882
+ if (_i == null) return;
1883
+ var _arr = [];
1884
+ var _n = true;
1885
+ var _d = false;
2036
1886
 
1887
+ var _s, _e;
2037
1888
 
2038
- if (hasFilter) {
2039
- context.filter = oldFilter;
2040
- }
1889
+ try {
1890
+ for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) {
1891
+ _arr.push(_s.value);
2041
1892
 
2042
- if (!drawStroke) {
2043
- context.stroke();
2044
- }
2045
- }
1893
+ if (i && _arr.length === i) break;
2046
1894
  }
2047
- };
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
+ }
2048
1905
 
2049
- return DefaultRenderer;
2050
- }();
1906
+ return _arr;
1907
+ }
2051
1908
 
2052
- DefaultRenderer = __decorate([manaSyringe.singleton()], DefaultRenderer);
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
+ }
2053
1917
 
2054
- var RectRenderer = /*#__PURE__*/function (_DefaultRenderer) {
2055
- _inheritsLoose$1(RectRenderer, _DefaultRenderer);
1918
+ function _arrayLikeToArray(arr, len) {
1919
+ if (len == null || len > arr.length) len = arr.length;
2056
1920
 
2057
- function RectRenderer() {
2058
- return _DefaultRenderer.apply(this, arguments) || this;
1921
+ for (var i = 0, arr2 = new Array(len); i < len; i++) {
1922
+ arr2[i] = arr[i];
2059
1923
  }
2060
1924
 
2061
- return RectRenderer;
2062
- }(DefaultRenderer);
2063
-
2064
- RectRenderer = __decorate([manaSyringe.singleton({
2065
- token: RectRendererContribution
2066
- })], RectRenderer);
2067
-
2068
- var CircleRenderer = /*#__PURE__*/function (_DefaultRenderer) {
2069
- _inheritsLoose$1(CircleRenderer, _DefaultRenderer);
1925
+ return arr2;
1926
+ }
2070
1927
 
2071
- function CircleRenderer() {
2072
- return _DefaultRenderer.apply(this, arguments) || this;
2073
- }
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
+ }
2074
1931
 
2075
- return CircleRenderer;
2076
- }(DefaultRenderer);
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
+ }
1935
+ /**
1936
+ * Common utilities
1937
+ * @module glMatrix
1938
+ */
1939
+ // Configuration Constants
2077
1940
 
2078
- CircleRenderer = __decorate([manaSyringe.singleton({
2079
- token: CircleRendererContribution
2080
- })], CircleRenderer);
2081
1941
 
2082
- var EllipseRenderer = /*#__PURE__*/function (_DefaultRenderer) {
2083
- _inheritsLoose$1(EllipseRenderer, _DefaultRenderer);
1942
+ var EPSILON = 0.000001;
1943
+ var ARRAY_TYPE = typeof Float32Array !== 'undefined' ? Float32Array : Array;
1944
+ if (!Math.hypot) Math.hypot = function () {
1945
+ var y = 0,
1946
+ i = arguments.length;
2084
1947
 
2085
- function EllipseRenderer() {
2086
- return _DefaultRenderer.apply(this, arguments) || this;
2087
- }
2088
-
2089
- return EllipseRenderer;
2090
- }(DefaultRenderer);
2091
-
2092
- EllipseRenderer = __decorate([manaSyringe.singleton({
2093
- token: EllipseRendererContribution
2094
- })], EllipseRenderer);
2095
-
2096
- var LineRenderer = /*#__PURE__*/function (_DefaultRenderer) {
2097
- _inheritsLoose$1(LineRenderer, _DefaultRenderer);
2098
-
2099
- function LineRenderer() {
2100
- return _DefaultRenderer.apply(this, arguments) || this;
2101
- }
2102
-
2103
- return LineRenderer;
2104
- }(DefaultRenderer);
2105
-
2106
- LineRenderer = __decorate([manaSyringe.singleton({
2107
- token: LineRendererContribution
2108
- })], LineRenderer);
2109
-
2110
- var PolylineRenderer = /*#__PURE__*/function (_DefaultRenderer) {
2111
- _inheritsLoose$1(PolylineRenderer, _DefaultRenderer);
2112
-
2113
- function PolylineRenderer() {
2114
- return _DefaultRenderer.apply(this, arguments) || this;
2115
- }
2116
-
2117
- return PolylineRenderer;
2118
- }(DefaultRenderer);
2119
-
2120
- PolylineRenderer = __decorate([manaSyringe.singleton({
2121
- token: PolylineRendererContribution
2122
- })], PolylineRenderer);
2123
-
2124
- var PolygonRenderer = /*#__PURE__*/function (_DefaultRenderer) {
2125
- _inheritsLoose$1(PolygonRenderer, _DefaultRenderer);
2126
-
2127
- function PolygonRenderer() {
2128
- return _DefaultRenderer.apply(this, arguments) || this;
2129
- }
2130
-
2131
- return PolygonRenderer;
2132
- }(DefaultRenderer);
2133
-
2134
- PolygonRenderer = __decorate([manaSyringe.singleton({
2135
- token: PolygonRendererContribution
2136
- })], PolygonRenderer);
2137
-
2138
- var PathRenderer = /*#__PURE__*/function (_DefaultRenderer) {
2139
- _inheritsLoose$1(PathRenderer, _DefaultRenderer);
2140
-
2141
- function PathRenderer() {
2142
- return _DefaultRenderer.apply(this, arguments) || this;
2143
- }
2144
-
2145
- return PathRenderer;
2146
- }(DefaultRenderer);
2147
-
2148
- PathRenderer = __decorate([manaSyringe.singleton({
2149
- token: PathRendererContribution
2150
- })], PathRenderer);
2151
-
2152
- var GradientPool = /*#__PURE__*/function () {
2153
- function GradientPool() {
2154
- this.gradientCache = {};
2155
- }
2156
-
2157
- var _proto = GradientPool.prototype;
2158
-
2159
- _proto.getOrCreateGradient = function getOrCreateGradient(params, context) {
2160
- var key = this.generateCacheKey(params);
2161
- var type = params.type,
2162
- x0 = params.x0,
2163
- y0 = params.y0,
2164
- x1 = params.x1,
2165
- y1 = params.y1,
2166
- steps = params.steps,
2167
- width = params.width,
2168
- height = params.height;
2169
-
2170
- if (this.gradientCache[key]) {
2171
- return this.gradientCache[key];
2172
- }
2173
-
2174
- var gradient = null;
2175
-
2176
- if (type === g.GradientPatternType.LinearGradient) {
2177
- // @see https://developer.mozilla.org/zh-CN/docs/Web/API/CanvasRenderingContext2D/createLinearGradient
2178
- gradient = context.createLinearGradient(x0 * width, y0 * height, x1 * width, y1 * height);
2179
- } else if (type === g.GradientPatternType.RadialGradient) {
2180
- var r = Math.sqrt(width * width + height * height) / 2; // @see https://developer.mozilla.org/zh-CN/docs/Web/API/CanvasRenderingContext2D/createRadialGradient
2181
-
2182
- gradient = context.createRadialGradient(x0 * width, y0 * height, 0, x1 * width, y1 * height, params.r1 * r);
2183
- }
2184
-
2185
- if (gradient) {
2186
- steps.forEach(function (_ref) {
2187
- var _gradient;
2188
-
2189
- var offset = _ref[0],
2190
- color = _ref[1];
2191
- (_gradient = gradient) === null || _gradient === void 0 ? void 0 : _gradient.addColorStop(Number(offset), color);
2192
- });
2193
- this.gradientCache[key] = gradient;
2194
- }
2195
-
2196
- return this.gradientCache[key];
2197
- };
2198
-
2199
- _proto.generateCacheKey = function generateCacheKey(params) {
2200
- // @ts-ignore
2201
- var type = params.type,
2202
- x0 = params.x0,
2203
- y0 = params.y0,
2204
- x1 = params.x1,
2205
- y1 = params.y1,
2206
- r1 = params.r1,
2207
- steps = params.steps,
2208
- width = params.width,
2209
- height = params.height;
2210
- return "gradient-" + type + "-" + x0 + "-" + y0 + "-" + x1 + "-" + y1 + "-" + (r1 || 0) + "-" + width + "-" + height + "-" + steps.map(function (step) {
2211
- return step.join('');
2212
- }).join('-');
2213
- };
2214
-
2215
- return GradientPool;
2216
- }();
2217
-
2218
- GradientPool = __decorate([manaSyringe.singleton()], GradientPool);
2219
-
2220
- function generatePath(context, parsedStyle) {
2221
- var r = parsedStyle.r;
2222
- context.arc(r.value, r.value, r.value, 0, Math.PI * 2, false);
2223
- }
2224
-
2225
- function generatePath$1(context, parsedStyle) {
2226
- var rxInPixels = parsedStyle.rx,
2227
- ryInPixels = parsedStyle.ry;
2228
- var rx = rxInPixels.value;
2229
- var ry = ryInPixels.value; // @see https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/ellipse
2230
-
2231
- if (context.ellipse) {
2232
- context.ellipse(rx, ry, rx, ry, 0, 0, Math.PI * 2, false);
2233
- } else {
2234
- // 如果不支持,则使用圆来绘制,进行变形
2235
- var r = rx > ry ? rx : ry;
2236
- var scaleX = rx > ry ? 1 : rx / ry;
2237
- var scaleY = rx > ry ? ry / rx : 1;
2238
- context.save();
2239
- context.scale(scaleX, scaleY);
2240
- context.arc(0, 0, r, 0, Math.PI * 2);
2241
- }
2242
- }
2243
-
2244
- function generatePath$2(context, parsedStyle) {
2245
- var radius = parsedStyle.radius,
2246
- width = parsedStyle.width,
2247
- height = parsedStyle.height;
2248
- var w = width.value;
2249
- var h = height.value;
2250
- var hasRadius = radius && radius.some(function (r) {
2251
- return r.value !== 0;
2252
- });
2253
-
2254
- if (!hasRadius) {
2255
- context.rect(0, 0, w, h);
2256
- } else {
2257
- var _radius$map = radius.map(function (r) {
2258
- return r.value;
2259
- }),
2260
- r1 = _radius$map[0],
2261
- r2 = _radius$map[1],
2262
- r3 = _radius$map[2],
2263
- r4 = _radius$map[3];
2264
-
2265
- context.moveTo(r1, 0);
2266
- context.lineTo(w - r2, 0);
2267
-
2268
- if (r2 !== 0) {
2269
- context.arc(w - r2, r2, r2, -Math.PI / 2, 0);
2270
- }
2271
-
2272
- context.lineTo(w, h - r3);
2273
-
2274
- if (r3 !== 0) {
2275
- context.arc(w - r3, h - r3, r3, 0, Math.PI / 2);
2276
- }
2277
-
2278
- context.lineTo(r4, h);
2279
-
2280
- if (r4 !== 0) {
2281
- context.arc(r4, h - r4, r4, Math.PI / 2, Math.PI);
2282
- }
2283
-
2284
- context.lineTo(0, r1);
2285
-
2286
- if (r1 !== 0) {
2287
- context.arc(r1, r1, r1, Math.PI, Math.PI * 1.5);
2288
- }
2289
- }
2290
- }
2291
-
2292
- function generatePath$3(context, parsedStyle) {
2293
- var x1 = parsedStyle.x1,
2294
- y1 = parsedStyle.y1,
2295
- x2 = parsedStyle.x2,
2296
- y2 = parsedStyle.y2,
2297
- _parsedStyle$defX = parsedStyle.defX,
2298
- defX = _parsedStyle$defX === void 0 ? 0 : _parsedStyle$defX,
2299
- _parsedStyle$defY = parsedStyle.defY,
2300
- defY = _parsedStyle$defY === void 0 ? 0 : _parsedStyle$defY;
2301
- context.moveTo(x1.value - defX, y1.value - defY);
2302
- context.lineTo(x2.value - defX, y2.value - defY);
2303
- }
2304
-
2305
- function generatePath$4(context, parsedStyle) {
2306
- var _parsedStyle$defX = parsedStyle.defX,
2307
- x = _parsedStyle$defX === void 0 ? 0 : _parsedStyle$defX,
2308
- _parsedStyle$defY = parsedStyle.defY,
2309
- y = _parsedStyle$defY === void 0 ? 0 : _parsedStyle$defY;
2310
- var points = parsedStyle.points.points;
2311
- var length = points.length;
2312
- var x1 = points[0][0] - x;
2313
- var y1 = points[0][1] - y;
2314
- var x2 = points[length - 1][0] - x;
2315
- var y2 = points[length - 1][1] - y;
2316
- context.moveTo(x1, y1);
2317
-
2318
- for (var i = 0; i < length - 1; i++) {
2319
- var point = points[i];
2320
- context.lineTo(point[0] - x, point[1] - y);
2321
- }
2322
-
2323
- context.lineTo(x2, y2);
2324
- }
2325
-
2326
- function generatePath$5(context, parsedStyle) {
2327
- var _parsedStyle$defX = parsedStyle.defX,
2328
- x = _parsedStyle$defX === void 0 ? 0 : _parsedStyle$defX,
2329
- _parsedStyle$defY = parsedStyle.defY,
2330
- y = _parsedStyle$defY === void 0 ? 0 : _parsedStyle$defY;
2331
- var points = parsedStyle.points.points;
2332
- var length = points.length;
2333
- var x1 = points[0][0] - x;
2334
- var y1 = points[0][1] - y;
2335
- var x2 = points[length - 1][0] - x;
2336
- var y2 = points[length - 1][1] - y;
2337
- context.moveTo(x1, y1);
2338
-
2339
- for (var i = 0; i < length - 1; i++) {
2340
- var point = points[i];
2341
- context.lineTo(point[0] - x, point[1] - y);
2342
- }
2343
-
2344
- context.lineTo(x2, y2);
2345
- }
2346
-
2347
- function generatePath$6(context, parsedStyle) {
2348
- var _parsedStyle$defX = parsedStyle.defX,
2349
- x = _parsedStyle$defX === void 0 ? 0 : _parsedStyle$defX,
2350
- _parsedStyle$defY = parsedStyle.defY,
2351
- y = _parsedStyle$defY === void 0 ? 0 : _parsedStyle$defY;
2352
- var _parsedStyle$path = parsedStyle.path,
2353
- curve = _parsedStyle$path.curve,
2354
- zCommandIndexes = _parsedStyle$path.zCommandIndexes;
2355
- var path = [].concat(curve);
2356
- zCommandIndexes.forEach(function (zIndex, index) {
2357
- path.splice(zIndex + index, 1, ['Z']);
2358
- });
2359
-
2360
- for (var i = 0; i < path.length; i++) {
2361
- var params = path[i]; // eg. M 100 200
2362
-
2363
- var command = params[0]; // V,H,S,T 都在前面被转换成标准形式
2364
-
2365
- switch (command) {
2366
- case 'M':
2367
- context.moveTo(params[1] - x, params[2] - y);
2368
- break;
2369
-
2370
- case 'C':
2371
- context.bezierCurveTo(params[1] - x, params[2] - y, params[3] - x, params[4] - y, params[5] - x, params[6] - y);
2372
- break;
2373
-
2374
- case 'Z':
2375
- context.closePath();
2376
- break;
2377
- }
2378
- }
2379
- }
2380
-
2381
- var PathGeneratorFactory = manaSyringe.Syringe.defineToken('PathGeneratorFactory');
2382
- var PathGenerator = manaSyringe.Syringe.defineToken('PathGenerator');
2383
- /**
2384
- * Common utilities
2385
- * @module glMatrix
2386
- */
2387
- // Configuration Constants
2388
-
2389
- var EPSILON = 0.000001;
2390
- var ARRAY_TYPE = typeof Float32Array !== 'undefined' ? Float32Array : Array;
2391
- if (!Math.hypot) Math.hypot = function () {
2392
- var y = 0,
2393
- i = arguments.length;
2394
-
2395
- while (i--) {
2396
- y += arguments[i] * arguments[i];
1948
+ while (i--) {
1949
+ y += arguments[i] * arguments[i];
2397
1950
  }
2398
1951
 
2399
1952
  return Math.sqrt(y);
@@ -3038,14 +2591,838 @@
3038
2591
  };
3039
2592
  }();
3040
2593
 
3041
- var RBushNode = function RBushNode() {
2594
+ var RBushNode = /*#__PURE__*/_createClass$2(function RBushNode() {
2595
+ _classCallCheck$2(this, RBushNode);
2596
+
3042
2597
  this.aabb = void 0;
3043
- };
2598
+ });
3044
2599
 
3045
2600
  RBushNode.tag = 'c-canvas-rbush-node';
3046
2601
 
3047
- var _class$1;
3048
-
2602
+ var GradientPool = /*#__PURE__*/function () {
2603
+ function GradientPool() {
2604
+ _classCallCheck$2(this, GradientPool);
2605
+
2606
+ this.gradientCache = {};
2607
+ }
2608
+
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
+ }
2625
+
2626
+ var gradient = null;
2627
+
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
2633
+
2634
+ gradient = context.createRadialGradient(x0 * width, y0 * height, 0, x1 * width, y1 * height, params.r1 * r);
2635
+ }
2636
+
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);
2828
+
2829
+ if (r4 !== 0) {
2830
+ context.arc(r4, h - r4, r4, Math.PI / 2, Math.PI);
2831
+ }
2832
+
2833
+ context.lineTo(0, r1);
2834
+
2835
+ if (r1 !== 0) {
2836
+ context.arc(r1, r1, r1, Math.PI, Math.PI * 1.5);
2837
+ }
2838
+ }
2839
+ }
2840
+
2841
+ function generatePath$3(context, parsedStyle) {
2842
+ var x1 = parsedStyle.x1,
2843
+ y1 = parsedStyle.y1,
2844
+ x2 = parsedStyle.x2,
2845
+ y2 = parsedStyle.y2,
2846
+ _parsedStyle$defX = parsedStyle.defX,
2847
+ defX = _parsedStyle$defX === void 0 ? 0 : _parsedStyle$defX,
2848
+ _parsedStyle$defY = parsedStyle.defY,
2849
+ defY = _parsedStyle$defY === void 0 ? 0 : _parsedStyle$defY;
2850
+ context.moveTo(x1.value - defX, y1.value - defY);
2851
+ context.lineTo(x2.value - defX, y2.value - defY);
2852
+ }
2853
+
2854
+ function generatePath$4(context, parsedStyle) {
2855
+ var _parsedStyle$defX = parsedStyle.defX,
2856
+ x = _parsedStyle$defX === void 0 ? 0 : _parsedStyle$defX,
2857
+ _parsedStyle$defY = parsedStyle.defY,
2858
+ y = _parsedStyle$defY === void 0 ? 0 : _parsedStyle$defY;
2859
+ var points = parsedStyle.points.points;
2860
+ var length = points.length;
2861
+ var x1 = points[0][0] - x;
2862
+ var y1 = points[0][1] - y;
2863
+ var x2 = points[length - 1][0] - x;
2864
+ var y2 = points[length - 1][1] - y;
2865
+ context.moveTo(x1, y1);
2866
+
2867
+ for (var i = 0; i < length - 1; i++) {
2868
+ var point = points[i];
2869
+ context.lineTo(point[0] - x, point[1] - y);
2870
+ }
2871
+
2872
+ context.lineTo(x2, y2);
2873
+ }
2874
+
2875
+ function generatePath$5(context, parsedStyle) {
2876
+ var _parsedStyle$defX = parsedStyle.defX,
2877
+ x = _parsedStyle$defX === void 0 ? 0 : _parsedStyle$defX,
2878
+ _parsedStyle$defY = parsedStyle.defY,
2879
+ y = _parsedStyle$defY === void 0 ? 0 : _parsedStyle$defY;
2880
+ var points = parsedStyle.points.points;
2881
+ var length = points.length;
2882
+ var x1 = points[0][0] - x;
2883
+ var y1 = points[0][1] - y;
2884
+ var x2 = points[length - 1][0] - x;
2885
+ var y2 = points[length - 1][1] - y;
2886
+ context.moveTo(x1, y1);
2887
+
2888
+ for (var i = 0; i < length - 1; i++) {
2889
+ var point = points[i];
2890
+ context.lineTo(point[0] - x, point[1] - y);
2891
+ }
2892
+
2893
+ context.lineTo(x2, y2);
2894
+ }
2895
+
2896
+ function generatePath$6(context, parsedStyle) {
2897
+ var _parsedStyle$defX = parsedStyle.defX,
2898
+ x = _parsedStyle$defX === void 0 ? 0 : _parsedStyle$defX,
2899
+ _parsedStyle$defY = parsedStyle.defY,
2900
+ y = _parsedStyle$defY === void 0 ? 0 : _parsedStyle$defY;
2901
+ var _parsedStyle$path = parsedStyle.path,
2902
+ curve = _parsedStyle$path.curve,
2903
+ zCommandIndexes = _parsedStyle$path.zCommandIndexes;
2904
+
2905
+ var path = _toConsumableArray(curve);
2906
+
2907
+ zCommandIndexes.forEach(function (zIndex, index) {
2908
+ path.splice(zIndex + index, 1, ['Z']);
2909
+ });
2910
+
2911
+ for (var i = 0; i < path.length; i++) {
2912
+ var params = path[i]; // eg. M 100 200
2913
+
2914
+ var command = params[0]; // V,H,S,T 都在前面被转换成标准形式
2915
+
2916
+ switch (command) {
2917
+ case 'M':
2918
+ context.moveTo(params[1] - x, params[2] - y);
2919
+ break;
2920
+
2921
+ case 'C':
2922
+ context.bezierCurveTo(params[1] - x, params[2] - y, params[3] - x, params[4] - y, params[5] - x, params[6] - y);
2923
+ break;
2924
+
2925
+ case 'Z':
2926
+ context.closePath();
2927
+ break;
2928
+ }
2929
+ }
2930
+ }
2931
+
2932
+ var PathGeneratorFactory = manaSyringe.Syringe.defineToken('PathGeneratorFactory');
2933
+ var PathGenerator = manaSyringe.Syringe.defineToken('PathGenerator');
2934
+ var StyleRendererFactory = manaSyringe.Syringe.defineToken('StyleRendererFactory');
2935
+ var CircleRendererContribution = manaSyringe.Syringe.defineToken('CircleRenderer', {
2936
+ multiple: false
2937
+ });
2938
+ var EllipseRendererContribution = manaSyringe.Syringe.defineToken('EllipseRenderer', {
2939
+ multiple: false
2940
+ });
2941
+ var RectRendererContribution = manaSyringe.Syringe.defineToken('RectRenderer', {
2942
+ multiple: false
2943
+ });
2944
+ var LineRendererContribution = manaSyringe.Syringe.defineToken('LineRenderer', {
2945
+ multiple: false
2946
+ });
2947
+ var PolylineRendererContribution = manaSyringe.Syringe.defineToken('PolylineRenderer', {
2948
+ multiple: false
2949
+ });
2950
+ var PolygonRendererContribution = manaSyringe.Syringe.defineToken('PolygonRenderer', {
2951
+ multiple: false
2952
+ });
2953
+ var PathRendererContribution = manaSyringe.Syringe.defineToken('PathRenderer', {
2954
+ multiple: false
2955
+ });
2956
+ var TextRendererContribution = manaSyringe.Syringe.defineToken('TextRenderer', {
2957
+ multiple: false
2958
+ });
2959
+ var ImageRendererContribution = manaSyringe.Syringe.defineToken('ImageRenderer', {
2960
+ multiple: false
2961
+ });
2962
+
2963
+ var ImageRenderer = /*#__PURE__*/function () {
2964
+ function ImageRenderer() {
2965
+ _classCallCheck$2(this, ImageRenderer);
2966
+
2967
+ this.imagePool = void 0;
2968
+ }
2969
+
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;
2981
+ var image;
2982
+ var iw = width.value;
2983
+ var ih = height.value;
2984
+
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;
2992
+ }
2993
+
2994
+ if (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) {}
3000
+ }
3001
+ }
3002
+ }]);
3003
+
3004
+ return ImageRenderer;
3005
+ }();
3006
+
3007
+ __decorate([manaSyringe.inject(ImagePool), __metadata("design:type", ImagePool)], ImageRenderer.prototype, "imagePool", void 0);
3008
+
3009
+ ImageRenderer = __decorate([manaSyringe.singleton({
3010
+ token: ImageRendererContribution
3011
+ })], ImageRenderer);
3012
+
3013
+ var TextRenderer = /*#__PURE__*/function () {
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
+ }
3069
+
3070
+ if (dy && dy.unit === g.UnitType.kPixels) {
3071
+ linePositionY += dy.value;
3072
+ } // draw lines line by line
3073
+
3074
+
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
+ }
3083
+
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
+ }
3087
+ }
3088
+ }
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
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
+ }
3100
+
3101
+ return;
3102
+ } // draw text using left align
3103
+
3104
+
3105
+ var currentTextAlign = context.textAlign;
3106
+ context.textAlign = 'left';
3107
+ var currentPosition = x;
3108
+
3109
+ if (textAlign === 'center') {
3110
+ currentPosition = x - lineMetrics.width / 2;
3111
+ } else if (textAlign === 'right' || textAlign === 'end') {
3112
+ currentPosition = x - lineMetrics.width;
3113
+ }
3114
+
3115
+ var stringArray = Array.from(text);
3116
+ var previousWidth = context.measureText(text).width;
3117
+ var currentWidth = 0;
3118
+
3119
+ for (var i = 0; i < stringArray.length; ++i) {
3120
+ var currentChar = stringArray[i];
3121
+
3122
+ if (isStroke) {
3123
+ this.strokeText(context, currentChar, currentPosition, y, strokeOpacity);
3124
+ } else {
3125
+ this.fillText(context, currentChar, currentPosition, y, fillOpacity, opacity);
3126
+ }
3127
+
3128
+ currentWidth = context.measureText(text.substring(i + 1)).width;
3129
+ currentPosition += previousWidth - currentWidth + letterSpacing;
3130
+ previousWidth = currentWidth;
3131
+ }
3132
+
3133
+ context.textAlign = currentTextAlign;
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;
3140
+
3141
+ if (applyOpacity) {
3142
+ currentGlobalAlpha = context.globalAlpha;
3143
+ context.globalAlpha = fillOpacity * opacity;
3144
+ }
3145
+
3146
+ context.fillText(text, x, y);
3147
+
3148
+ if (applyOpacity) {
3149
+ context.globalAlpha = currentGlobalAlpha;
3150
+ }
3151
+ }
3152
+ }, {
3153
+ key: "strokeText",
3154
+ value: function strokeText(context, text, x, y, strokeOpacity) {
3155
+ var currentGlobalAlpha;
3156
+ var applyOpacity = !g.isNil(strokeOpacity) && strokeOpacity !== 1;
3157
+
3158
+ if (applyOpacity) {
3159
+ currentGlobalAlpha = context.globalAlpha;
3160
+ context.globalAlpha = strokeOpacity;
3161
+ }
3162
+
3163
+ context.strokeText(text, x, y);
3164
+
3165
+ if (applyOpacity) {
3166
+ context.globalAlpha = currentGlobalAlpha;
3167
+ }
3168
+ }
3169
+ }]);
3170
+
3171
+ return TextRenderer;
3172
+ }();
3173
+
3174
+ TextRenderer = __decorate([manaSyringe.singleton({
3175
+ token: TextRendererContribution
3176
+ })], TextRenderer);
3177
+
3178
+ var DefaultRenderer = /*#__PURE__*/function () {
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
+ }
3217
+ }
3218
+
3219
+ if (hasStroke) {
3220
+ if (lineWidth && lineWidth.value > 0) {
3221
+ var applyOpacity = !g.isNil(strokeOpacity) && strokeOpacity.value !== 1;
3222
+
3223
+ if (applyOpacity) {
3224
+ context.globalAlpha = strokeOpacity.value;
3225
+ }
3226
+
3227
+ context.lineWidth = lineWidth.value;
3228
+
3229
+ if (!g.isNil(miterLimit)) {
3230
+ context.miterLimit = miterLimit;
3231
+ }
3232
+
3233
+ if (!g.isNil(lineCap)) {
3234
+ context.lineCap = lineCap.value;
3235
+ }
3236
+
3237
+ if (!g.isNil(lineJoin)) {
3238
+ context.lineJoin = lineJoin.value;
3239
+ }
3240
+
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
+ }
3257
+ }
3258
+
3259
+ if (hasFilter) {
3260
+ // save drop-shadow filter
3261
+ oldFilter = context.filter;
3262
+
3263
+ if (!g.isNil(oldFilter) && oldFilter.indexOf('drop-shadow') > -1) {
3264
+ context.filter = oldFilter.replace(/drop-shadow\([^)]*\)/, '').trim() || 'none';
3265
+ }
3266
+ }
3267
+
3268
+ var drawStroke = hasFill && !isFillTransparent;
3269
+
3270
+ if (drawStroke) {
3271
+ context.stroke();
3272
+ } // restore shadow blur
3273
+
3274
+
3275
+ if (hasShadowColor) {
3276
+ context.shadowColor = oldShadowColor;
3277
+ context.shadowBlur = oldShadowBlur;
3278
+ } // restore filters
3279
+
3280
+
3281
+ if (hasFilter) {
3282
+ context.filter = oldFilter;
3283
+ }
3284
+
3285
+ if (!drawStroke) {
3286
+ context.stroke();
3287
+ }
3288
+ }
3289
+ }
3290
+ }
3291
+ }]);
3292
+
3293
+ return DefaultRenderer;
3294
+ }();
3295
+
3296
+ DefaultRenderer = __decorate([manaSyringe.singleton()], DefaultRenderer);
3297
+
3298
+ var RectRenderer = /*#__PURE__*/function (_DefaultRenderer) {
3299
+ _inherits$1(RectRenderer, _DefaultRenderer);
3300
+
3301
+ var _super = _createSuper$1(RectRenderer);
3302
+
3303
+ function RectRenderer() {
3304
+ _classCallCheck$2(this, RectRenderer);
3305
+
3306
+ return _super.apply(this, arguments);
3307
+ }
3308
+
3309
+ return _createClass$2(RectRenderer);
3310
+ }(DefaultRenderer);
3311
+
3312
+ RectRenderer = __decorate([manaSyringe.singleton({
3313
+ token: RectRendererContribution
3314
+ })], RectRenderer);
3315
+
3316
+ var CircleRenderer = /*#__PURE__*/function (_DefaultRenderer) {
3317
+ _inherits$1(CircleRenderer, _DefaultRenderer);
3318
+
3319
+ var _super = _createSuper$1(CircleRenderer);
3320
+
3321
+ function CircleRenderer() {
3322
+ _classCallCheck$2(this, CircleRenderer);
3323
+
3324
+ return _super.apply(this, arguments);
3325
+ }
3326
+
3327
+ return _createClass$2(CircleRenderer);
3328
+ }(DefaultRenderer);
3329
+
3330
+ CircleRenderer = __decorate([manaSyringe.singleton({
3331
+ token: CircleRendererContribution
3332
+ })], CircleRenderer);
3333
+
3334
+ var EllipseRenderer = /*#__PURE__*/function (_DefaultRenderer) {
3335
+ _inherits$1(EllipseRenderer, _DefaultRenderer);
3336
+
3337
+ var _super = _createSuper$1(EllipseRenderer);
3338
+
3339
+ function EllipseRenderer() {
3340
+ _classCallCheck$2(this, EllipseRenderer);
3341
+
3342
+ return _super.apply(this, arguments);
3343
+ }
3344
+
3345
+ return _createClass$2(EllipseRenderer);
3346
+ }(DefaultRenderer);
3347
+
3348
+ EllipseRenderer = __decorate([manaSyringe.singleton({
3349
+ token: EllipseRendererContribution
3350
+ })], EllipseRenderer);
3351
+
3352
+ var LineRenderer = /*#__PURE__*/function (_DefaultRenderer) {
3353
+ _inherits$1(LineRenderer, _DefaultRenderer);
3354
+
3355
+ var _super = _createSuper$1(LineRenderer);
3356
+
3357
+ function LineRenderer() {
3358
+ _classCallCheck$2(this, LineRenderer);
3359
+
3360
+ return _super.apply(this, arguments);
3361
+ }
3362
+
3363
+ return _createClass$2(LineRenderer);
3364
+ }(DefaultRenderer);
3365
+
3366
+ LineRenderer = __decorate([manaSyringe.singleton({
3367
+ token: LineRendererContribution
3368
+ })], LineRenderer);
3369
+
3370
+ var PolylineRenderer = /*#__PURE__*/function (_DefaultRenderer) {
3371
+ _inherits$1(PolylineRenderer, _DefaultRenderer);
3372
+
3373
+ var _super = _createSuper$1(PolylineRenderer);
3374
+
3375
+ function PolylineRenderer() {
3376
+ _classCallCheck$2(this, PolylineRenderer);
3377
+
3378
+ return _super.apply(this, arguments);
3379
+ }
3380
+
3381
+ return _createClass$2(PolylineRenderer);
3382
+ }(DefaultRenderer);
3383
+
3384
+ PolylineRenderer = __decorate([manaSyringe.singleton({
3385
+ token: PolylineRendererContribution
3386
+ })], PolylineRenderer);
3387
+
3388
+ var PolygonRenderer = /*#__PURE__*/function (_DefaultRenderer) {
3389
+ _inherits$1(PolygonRenderer, _DefaultRenderer);
3390
+
3391
+ var _super = _createSuper$1(PolygonRenderer);
3392
+
3393
+ function PolygonRenderer() {
3394
+ _classCallCheck$2(this, PolygonRenderer);
3395
+
3396
+ return _super.apply(this, arguments);
3397
+ }
3398
+
3399
+ return _createClass$2(PolygonRenderer);
3400
+ }(DefaultRenderer);
3401
+
3402
+ PolygonRenderer = __decorate([manaSyringe.singleton({
3403
+ token: PolygonRendererContribution
3404
+ })], PolygonRenderer);
3405
+
3406
+ var PathRenderer = /*#__PURE__*/function (_DefaultRenderer) {
3407
+ _inherits$1(PathRenderer, _DefaultRenderer);
3408
+
3409
+ var _super = _createSuper$1(PathRenderer);
3410
+
3411
+ function PathRenderer() {
3412
+ _classCallCheck$2(this, PathRenderer);
3413
+
3414
+ return _super.apply(this, arguments);
3415
+ }
3416
+
3417
+ return _createClass$2(PathRenderer);
3418
+ }(DefaultRenderer);
3419
+
3420
+ PathRenderer = __decorate([manaSyringe.singleton({
3421
+ token: PathRendererContribution
3422
+ })], PathRenderer);
3423
+
3424
+ var _class$1;
3425
+
3049
3426
  var CanvasRendererPlugin_1;
3050
3427
  var RBushRoot = 'RBushRoot';
3051
3428
  /**
@@ -3056,6 +3433,8 @@
3056
3433
 
3057
3434
  var CanvasRendererPlugin = CanvasRendererPlugin_1 = (_class$1 = /*#__PURE__*/function () {
3058
3435
  function CanvasRendererPlugin() {
3436
+ _classCallCheck$2(this, CanvasRendererPlugin);
3437
+
3059
3438
  this.canvasConfig = void 0;
3060
3439
  this.camera = void 0;
3061
3440
  this.contextService = void 0;
@@ -3076,619 +3455,641 @@
3076
3455
  this.toSync = new Set();
3077
3456
  }
3078
3457
 
3079
- var _proto = CanvasRendererPlugin.prototype;
3458
+ _createClass$2(CanvasRendererPlugin, [{
3459
+ key: "syncRTree",
3460
+ value: function syncRTree() {
3461
+ var _this = this; // bounds changed, need re-inserting its children
3080
3462
 
3081
- _proto.syncRTree = function syncRTree() {
3082
- var _this = this; // bounds changed, need re-inserting its children
3083
3463
 
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
3084
3471
 
3085
- var bulk = [];
3086
- Array.from(this.toSync) // some objects may be removed since last frame
3087
- .filter(function (object) {
3088
- return object.isConnected;
3089
- }).forEach(function (node) {
3090
- // @ts-ignore
3091
- var rBushNode = node.rBushNode; // clear dirty node
3092
-
3093
- if (rBushNode) {
3094
- _this.rBush.remove(rBushNode.aabb);
3095
- }
3472
+ if (rBushNode) {
3473
+ _this.rBush.remove(rBushNode.aabb);
3474
+ }
3096
3475
 
3097
- 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
+ }
3098
3497
 
3099
- if (renderBounds) {
3100
- var _renderBounds$getMin = renderBounds.getMin(),
3101
- minX = _renderBounds$getMin[0],
3102
- minY = _renderBounds$getMin[1];
3103
-
3104
- var _renderBounds$getMax = renderBounds.getMax(),
3105
- maxX = _renderBounds$getMax[0],
3106
- maxY = _renderBounds$getMax[1];
3107
-
3108
- rBushNode.aabb = {
3109
- id: node.entity,
3110
- minX: minX,
3111
- minY: minY,
3112
- maxX: maxX,
3113
- maxY: maxY
3114
- };
3115
- }
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
3116
3503
 
3117
- if (rBushNode.aabb) {
3118
- bulk.push(rBushNode.aabb);
3119
- }
3120
- }); // use bulk inserting, which is ~2-3 times faster
3121
- // @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
+ */
3122
3510
 
3123
- this.rBush.load(bulk);
3124
- this.toSync.clear();
3125
- }
3126
- /**
3127
- * sync to RBush later
3128
- */
3129
- ;
3511
+ }, {
3512
+ key: "pushToSync",
3513
+ value: function pushToSync(list) {
3514
+ var _this2 = this;
3130
3515
 
3131
- _proto.pushToSync = function pushToSync(list) {
3132
- 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;
3133
3524
 
3134
- list.forEach(function (i) {
3135
- _this2.toSync.add(i);
3136
- });
3137
- };
3525
+ var handleMounted = function handleMounted(e) {
3526
+ var object = e.target; // @ts-ignore
3138
3527
 
3139
- _proto.apply = function apply(renderingService) {
3140
- var _this3 = this;
3528
+ object.rBushNode = new RBushNode();
3141
3529
 
3142
- var handleMounted = function handleMounted(e) {
3143
- var object = e.target; // @ts-ignore
3530
+ _this3.pushToSync(e.composedPath().slice(0, -2));
3531
+ };
3144
3532
 
3145
- object.rBushNode = new RBushNode();
3533
+ var handleUnmounted = function handleUnmounted(e) {
3534
+ var object = e.target; // remove r-bush node
3535
+ // @ts-ignore
3146
3536
 
3147
- _this3.pushToSync(e.composedPath().slice(0, -2));
3148
- };
3537
+ var rBushNode = object.rBushNode;
3149
3538
 
3150
- var handleUnmounted = function handleUnmounted(e) {
3151
- var object = e.target; // remove r-bush node
3152
- // @ts-ignore
3539
+ if (rBushNode.aabb) {
3540
+ _this3.rBush.remove(rBushNode.aabb);
3153
3541
 
3154
- var rBushNode = object.rBushNode;
3542
+ _this3.toSync.delete(object); // save removed aabbs for dirty-rectangle rendering later
3155
3543
 
3156
- if (rBushNode.aabb) {
3157
- _this3.rBush.remove(rBushNode.aabb);
3158
3544
 
3159
- _this3.toSync.delete(object); // save removed aabbs for dirty-rectangle rendering later
3545
+ _this3.removedRBushNodeAABBs.push(rBushNode.aabb);
3546
+ }
3547
+ };
3160
3548
 
3549
+ var handleBoundsChanged = function handleBoundsChanged(e) {
3550
+ var _object$ownerDocument;
3161
3551
 
3162
- _this3.removedRBushNodeAABBs.push(rBushNode.aabb);
3163
- }
3164
- };
3552
+ var object = e.target; // skip if this object mounted on another scenegraph root
3165
3553
 
3166
- var handleBoundsChanged = function handleBoundsChanged(e) {
3167
- 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
+ }
3168
3557
 
3169
- var object = e.target; // skip if this object mounted on another scenegraph root
3558
+ var affectChildren = e.detail.affectChildren;
3170
3559
 
3171
- if (((_object$ownerDocument = object.ownerDocument) === null || _object$ownerDocument === void 0 ? void 0 : _object$ownerDocument.documentElement) !== _this3.renderingContext.root) {
3172
- return;
3173
- }
3560
+ if (affectChildren) {
3561
+ object.forEach(function (node) {
3562
+ _this3.pushToSync([node]);
3563
+ });
3564
+ }
3174
3565
 
3175
- var affectChildren = e.detail.affectChildren;
3566
+ _this3.pushToSync(e.composedPath().slice(0, -2));
3567
+ };
3176
3568
 
3177
- if (affectChildren) {
3178
- object.forEach(function (node) {
3179
- _this3.pushToSync([node]);
3180
- });
3181
- }
3569
+ renderingService.hooks.init.tapPromise(CanvasRendererPlugin_1.tag, /*#__PURE__*/_asyncToGenerator$1( /*#__PURE__*/_regeneratorRuntime$1().mark(function _callee() {
3570
+ var _this3$canvasConfig, width, height, context;
3182
3571
 
3183
- _this3.pushToSync(e.composedPath().slice(0, -2));
3184
- };
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);
3185
3577
 
3186
- renderingService.hooks.init.tapPromise(CanvasRendererPlugin_1.tag, /*#__PURE__*/_asyncToGenerator$1( /*#__PURE__*/_regeneratorRuntime$1().mark(function _callee() {
3187
- var _this3$canvasConfig, width, height, context;
3578
+ _this3.renderingContext.root.addEventListener(g.ElementEvent.UNMOUNTED, handleUnmounted);
3188
3579
 
3189
- return _regeneratorRuntime$1().wrap(function _callee$(_context) {
3190
- while (1) {
3191
- switch (_context.prev = _context.next) {
3192
- case 0:
3193
- _this3.renderingContext.root.addEventListener(g.ElementEvent.MOUNTED, handleMounted);
3580
+ _this3.renderingContext.root.addEventListener(g.ElementEvent.BOUNDS_CHANGED, handleBoundsChanged); // clear fullscreen
3194
3581
 
3195
- _this3.renderingContext.root.addEventListener(g.ElementEvent.UNMOUNTED, handleUnmounted);
3196
3582
 
3197
- _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();
3198
3585
 
3586
+ _this3.clearRect(context, 0, 0, width, height);
3199
3587
 
3200
- _this3$canvasConfig = _this3.canvasConfig, width = _this3$canvasConfig.width, height = _this3$canvasConfig.height;
3201
- 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);
3202
3597
 
3203
- _this3.clearRect(context, 0, 0, width, height);
3598
+ _this3.renderingContext.root.removeEventListener(g.ElementEvent.UNMOUNTED, handleUnmounted);
3204
3599
 
3205
- case 6:
3206
- case "end":
3207
- return _context.stop();
3208
- }
3209
- }
3210
- }, _callee);
3211
- })));
3212
- renderingService.hooks.destroy.tap(CanvasRendererPlugin_1.tag, function () {
3213
- _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();
3214
3604
 
3215
- _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;
3216
3609
 
3217
- _this3.renderingContext.root.removeEventListener(g.ElementEvent.BOUNDS_CHANGED, handleBoundsChanged);
3218
- });
3219
- renderingService.hooks.beginFrame.tap(CanvasRendererPlugin_1.tag, function () {
3220
- 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
3221
3614
 
3222
- var _this3$canvasConfig2 = _this3.canvasConfig,
3223
- renderer = _this3$canvasConfig2.renderer,
3224
- width = _this3$canvasConfig2.width,
3225
- height = _this3$canvasConfig2.height;
3226
3615
 
3227
- var _renderer$getConfig = renderer.getConfig(),
3228
- enableDirtyRectangleRendering = _renderer$getConfig.enableDirtyRectangleRendering; // clear fullscreen when:
3229
- // 1. dirty rectangle rendering disabled
3230
- // 2. camera changed
3616
+ _this3.clearFullScreen = !enableDirtyRectangleRendering || _this3.renderingContext.renderReasons.has(g.RenderReason.CAMERA_CHANGED);
3231
3617
 
3618
+ if (context) {
3619
+ context.save();
3232
3620
 
3233
- _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
3234
3624
 
3235
- if (context) {
3236
- context.save();
3237
3625
 
3238
- if (_this3.clearFullScreen) {
3239
- _this3.clearRect(context, 0, 0, width, height);
3240
- } // account for camera's world matrix
3626
+ _this3.applyTransform(context, _this3.camera.getOrthoMatrix());
3627
+ }
3628
+ }); // render at the end of frame
3241
3629
 
3630
+ renderingService.hooks.endFrame.tap(CanvasRendererPlugin_1.tag, function () {
3631
+ _this3.syncRTree();
3242
3632
 
3243
- _this3.applyTransform(context, _this3.camera.getOrthoMatrix());
3244
- }
3245
- }); // 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;
3246
3636
 
3247
- renderingService.hooks.endFrame.tap(CanvasRendererPlugin_1.tag, function () {
3248
- _this3.syncRTree();
3637
+ var context = _this3.contextService.getContext();
3249
3638
 
3250
- var _this3$canvasConfig$r = _this3.canvasConfig.renderer.getConfig(),
3251
- enableDirtyRectangleRendering = _this3$canvasConfig$r.enableDirtyRectangleRendering,
3252
- enableDirtyRectangleRenderingDebug = _this3$canvasConfig$r.enableDirtyRectangleRenderingDebug;
3639
+ var dirtyObjects = _this3.renderQueue;
3253
3640
 
3254
- 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
+ }))));
3255
3656
 
3256
- var dirtyObjects = _this3.renderQueue;
3657
+ _this3.removedRBushNodeAABBs = [];
3257
3658
 
3258
- if (enableDirtyRectangleRendering) {
3259
- // eg. camera changed
3260
- if (!_this3.clearFullScreen) {
3261
- // merge removed AABB
3262
- var dirtyRenderBounds = _this3.safeMergeAABB.apply(_this3, [_this3.mergeDirtyAABBs( // should not ignore group since clipPath may affect its children
3263
- // this.renderQueue.filter((o) => o.nodeName !== Shape.GROUP)),
3264
- _this3.renderQueue)].concat(_this3.removedRBushNodeAABBs.map(function (_ref2) {
3265
- var minX = _ref2.minX,
3266
- minY = _ref2.minY,
3267
- maxX = _ref2.maxX,
3268
- maxY = _ref2.maxY;
3269
- var aabb = new g.AABB();
3270
- aabb.setMinMax(fromValues(minX, minY, 0), fromValues(maxX, maxY, 0));
3271
- return aabb;
3272
- })));
3659
+ if (g.AABB.isEmpty(dirtyRenderBounds)) {
3660
+ _this3.renderQueue = [];
3661
+ return;
3662
+ } // clear & clip dirty rectangle
3273
3663
 
3274
- _this3.removedRBushNodeAABBs = [];
3275
3664
 
3276
- if (g.AABB.isEmpty(dirtyRenderBounds)) {
3277
- _this3.renderQueue = [];
3278
- return;
3279
- } // 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;
3280
3670
 
3671
+ _this3.clearRect(context, x, y, width, height);
3281
3672
 
3282
- var _this3$convertAABB2Re = _this3.convertAABB2Rect(dirtyRenderBounds),
3283
- x = _this3$convertAABB2Re.x,
3284
- y = _this3$convertAABB2Re.y,
3285
- width = _this3$convertAABB2Re.width,
3286
- height = _this3$convertAABB2Re.height;
3673
+ context.beginPath();
3674
+ context.rect(x, y, width, height);
3675
+ context.clip(); // draw dirty rectangle
3287
3676
 
3288
- _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
3289
3682
 
3290
- context.beginPath();
3291
- context.rect(x, y, width, height);
3292
- context.clip(); // draw dirty rectangle
3293
3683
 
3294
- if (enableDirtyRectangleRenderingDebug) {
3295
- context.lineWidth = 4;
3296
- context.strokeStyle = "rgba(" + Math.random() * 255 + ", " + Math.random() * 255 + ", " + Math.random() * 255 + ", 1)";
3297
- context.strokeRect(x, y, width, height);
3298
- } // search objects intersect with dirty rectangle
3684
+ dirtyObjects = _this3.searchDirtyObjects(dirtyRenderBounds);
3685
+ } // do rendering
3299
3686
 
3300
3687
 
3301
- dirtyObjects = _this3.searchDirtyObjects(dirtyRenderBounds);
3302
- } // 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
+ });
3303
3697
 
3698
+ if (_this3.enableBatch && _this3.batchedStyleHash) {
3699
+ _this3.flush(context, renderingService);
3700
+ } // save dirty AABBs in last frame
3304
3701
 
3305
- dirtyObjects // sort by z-index
3306
- .sort(function (a, b) {
3307
- return a.sortable.renderOrder - b.sortable.renderOrder;
3308
- }).forEach(function (object) {
3309
- // culled object should not be rendered
3310
- if (object && object.isVisible() && !object.isCulled()) {
3311
- _this3.renderDisplayObject(object, renderingService);
3312
- }
3313
- });
3314
3702
 
3315
- if (_this3.enableBatch && _this3.batchedStyleHash) {
3316
- _this3.flush(context, renderingService);
3317
- } // save dirty AABBs in last frame
3703
+ _this3.renderQueue.forEach(function (object) {
3704
+ _this3.saveDirtyAABB(object);
3705
+ }); // clear queue
3318
3706
 
3319
3707
 
3320
- _this3.renderQueue.forEach(function (object) {
3321
- _this3.saveDirtyAABB(object);
3322
- }); // clear queue
3708
+ _this3.renderQueue = [];
3709
+ } // pop restore stack, eg. root -> parent -> child
3323
3710
 
3324
3711
 
3325
- _this3.renderQueue = [];
3326
- } // pop restore stack, eg. root -> parent -> child
3712
+ _this3.restoreStack.forEach(function (s) {
3713
+ context.restore();
3714
+ }); // clear restore stack
3327
3715
 
3328
3716
 
3329
- _this3.restoreStack.forEach(function (s) {
3717
+ _this3.restoreStack = [];
3718
+ _this3.clearFullScreen = false;
3330
3719
  context.restore();
3331
- }); // clear restore stack
3332
-
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;
3333
3724
 
3334
- _this3.restoreStack = [];
3335
- _this3.clearFullScreen = false;
3336
- context.restore();
3337
- });
3338
- renderingService.hooks.render.tap(CanvasRendererPlugin_1.tag, function (object) {
3339
- var _this3$canvasConfig$r2 = _this3.canvasConfig.renderer.getConfig(),
3340
- enableDirtyRectangleRendering = _this3$canvasConfig$r2.enableDirtyRectangleRendering;
3341
-
3342
- if (!enableDirtyRectangleRendering) {
3343
- if (object.isVisible() && !object.isCulled()) {
3344
- // render immediately
3345
- _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);
3346
3733
  }
3347
- } else {
3348
- // render at the end of frame
3349
- _this3.renderQueue.push(object);
3350
- }
3351
- });
3352
- };
3353
-
3354
- _proto.clearRect = function clearRect(context, x, y, width, height) {
3355
- context.clearRect(x, y, width, height);
3356
- var background = this.canvasConfig.background;
3357
-
3358
- if (background) {
3359
- context.fillStyle = background;
3360
- context.fillRect(x, y, width, height);
3734
+ });
3361
3735
  }
3362
- };
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;
3363
3741
 
3364
- _proto.flush = function flush(context, renderingService) {
3365
- if (this.batchedDisplayObject) {
3366
- var styleRenderer = this.styleRendererFactory(this.batchedDisplayObject.nodeName);
3367
-
3368
- if (styleRenderer) {
3369
- // apply attributes to context
3370
- this.applyAttributesToContext(context, this.batchedDisplayObject, renderingService); // close path first
3371
-
3372
- context.closePath();
3373
- styleRenderer.render(context, this.batchedDisplayObject.parsedStyle, this.batchedDisplayObject);
3374
- context.restore();
3742
+ if (background) {
3743
+ context.fillStyle = background;
3744
+ context.fillRect(x, y, width, height);
3375
3745
  }
3376
-
3377
- this.batchedStyleHash = '';
3378
- this.batchedDisplayObject = null;
3379
3746
  }
3380
- };
3747
+ }, {
3748
+ key: "flush",
3749
+ value: function flush(context, renderingService) {
3750
+ if (this.batchedDisplayObject) {
3751
+ var styleRenderer = this.styleRendererFactory(this.batchedDisplayObject.nodeName);
3381
3752
 
3382
- _proto.renderDisplayObject = function renderDisplayObject(object, renderingService) {
3383
- var _this4 = this;
3753
+ if (styleRenderer) {
3754
+ // apply attributes to context
3755
+ this.applyAttributesToContext(context, this.batchedDisplayObject, renderingService); // close path first
3384
3756
 
3385
- var context = this.contextService.getContext(); // restore to its parent
3386
-
3387
- var parent = this.restoreStack[this.restoreStack.length - 1];
3757
+ context.closePath();
3758
+ styleRenderer.render(context, this.batchedDisplayObject.parsedStyle, this.batchedDisplayObject);
3759
+ context.restore();
3760
+ }
3388
3761
 
3389
- while (parent && object.parentNode !== parent) {
3390
- context.restore();
3391
- this.restoreStack.pop();
3392
- parent = this.restoreStack[this.restoreStack.length - 1];
3762
+ this.batchedStyleHash = '';
3763
+ this.batchedDisplayObject = null;
3764
+ }
3393
3765
  }
3766
+ }, {
3767
+ key: "renderDisplayObject",
3768
+ value: function renderDisplayObject(object, renderingService) {
3769
+ var _this4 = this;
3394
3770
 
3395
- var nodeName = object.nodeName;
3396
- var styleRenderer = this.styleRendererFactory(nodeName);
3397
- var startBatch = false;
3771
+ var context = this.contextService.getContext(); // restore to its parent
3398
3772
 
3399
- if (this.enableBatch && styleRenderer) {
3400
- var hash = styleRenderer.hash(object.attributes);
3401
-
3402
- if (this.batchedStyleHash && hash !== this.batchedStyleHash) {
3403
- this.flush(context, renderingService);
3404
- }
3773
+ var parent = this.restoreStack[this.restoreStack.length - 1];
3405
3774
 
3406
- if (!this.batchedStyleHash) {
3407
- this.batchedStyleHash = hash;
3408
- this.batchedDisplayObject = object;
3409
- startBatch = true;
3775
+ while (parent && object.parentNode !== parent) {
3776
+ context.restore();
3777
+ this.restoreStack.pop();
3778
+ parent = this.restoreStack[this.restoreStack.length - 1];
3410
3779
  }
3411
- } // reset transformation
3412
-
3413
-
3414
- context.save(); // apply RTS transformation in world space
3415
-
3416
- this.applyTransform(context, object.getLocalTransform()); // clip path
3417
3780
 
3418
- var clipPathShape = object.style.clipPath;
3781
+ var nodeName = object.nodeName;
3782
+ var styleRenderer = this.styleRendererFactory(nodeName);
3783
+ var startBatch = false;
3419
3784
 
3420
- if (clipPathShape) {
3421
- context.save(); // apply clip shape's RTS
3785
+ if (this.enableBatch && styleRenderer) {
3786
+ var hash = styleRenderer.hash(object.attributes);
3422
3787
 
3423
- this.applyTransform(context, clipPathShape.getLocalTransform()); // generate path in local space
3788
+ if (this.batchedStyleHash && hash !== this.batchedStyleHash) {
3789
+ this.flush(context, renderingService);
3790
+ }
3424
3791
 
3425
- 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
3426
3798
 
3427
- if (generatePath) {
3428
- this.useAnchor(context, clipPathShape, function () {
3429
- context.beginPath();
3430
- generatePath(context, clipPathShape.parsedStyle);
3431
- context.closePath();
3432
- });
3433
- }
3434
3799
 
3435
- context.restore();
3436
- context.clip();
3437
- } // fill & stroke
3800
+ context.save(); // apply RTS transformation in world space
3438
3801
 
3802
+ this.applyTransform(context, object.getLocalTransform()); // clip path
3439
3803
 
3440
- if (!this.enableBatch) {
3441
- context.save(); // apply attributes to context
3804
+ var clipPathShape = object.style.clipPath;
3442
3805
 
3443
- this.applyAttributesToContext(context, object, renderingService);
3444
- } // apply anchor in local space
3806
+ if (clipPathShape) {
3807
+ context.save(); // apply clip shape's RTS
3445
3808
 
3809
+ this.applyTransform(context, clipPathShape.getLocalTransform()); // generate path in local space
3446
3810
 
3447
- this.useAnchor(context, object, function () {
3448
- // generate path in local space
3449
- var generatePath = _this4.pathGeneratorFactory(object.nodeName);
3811
+ var generatePath = this.pathGeneratorFactory(clipPathShape.nodeName);
3450
3812
 
3451
- if (generatePath) {
3452
- if (startBatch || !_this4.enableBatch) {
3453
- context.beginPath();
3813
+ if (generatePath) {
3814
+ this.useAnchor(context, clipPathShape, function () {
3815
+ context.beginPath();
3816
+ generatePath(context, clipPathShape.parsedStyle);
3817
+ context.closePath();
3818
+ });
3454
3819
  }
3455
3820
 
3456
- generatePath(context, object.parsedStyle);
3457
-
3458
- if (!_this4.enableBatch && object.nodeName !== g.Shape.LINE && object.nodeName !== g.Shape.PATH && object.nodeName !== g.Shape.POLYLINE) {
3459
- context.closePath();
3460
- }
3821
+ context.restore();
3822
+ context.clip();
3461
3823
  } // fill & stroke
3462
3824
 
3463
3825
 
3464
- if (styleRenderer && !_this4.enableBatch) {
3465
- styleRenderer.render(context, object.parsedStyle, object);
3466
- }
3467
- }); // restore applied attributes, eg. shadowBlur shadowColor...
3468
-
3469
- if (!this.enableBatch) {
3470
- context.restore();
3471
- } // finish rendering, clear dirty flag
3826
+ if (!this.enableBatch) {
3827
+ context.save(); // apply attributes to context
3472
3828
 
3829
+ this.applyAttributesToContext(context, object, renderingService);
3830
+ } // apply anchor in local space
3473
3831
 
3474
- object.renderable.dirty = false;
3475
- this.restoreStack.push(object);
3476
- };
3477
-
3478
- _proto.convertAABB2Rect = function convertAABB2Rect(aabb) {
3479
- var min = aabb.getMin();
3480
- var max = aabb.getMax(); // expand the rectangle a bit to avoid artifacts
3481
- // @see https://www.yuque.com/antv/ou292n/bi8nix#ExvCu
3482
-
3483
- var minX = Math.floor(min[0]);
3484
- var minY = Math.floor(min[1]);
3485
- var maxX = Math.ceil(max[0]);
3486
- var maxY = Math.ceil(max[1]);
3487
- var width = maxX - minX;
3488
- var height = maxY - minY;
3489
- return {
3490
- x: minX,
3491
- y: minY,
3492
- width: width,
3493
- height: height
3494
- };
3495
- }
3496
- /**
3497
- * TODO: merge dirty rectangles with some strategies.
3498
- * For now, we just simply merge all the rectangles into one.
3499
- * @see https://idom.me/articles/841.html
3500
- */
3501
- ;
3502
3832
 
3503
- _proto.mergeDirtyAABBs = function mergeDirtyAABBs(dirtyObjects) {
3504
- // merge into a big AABB
3505
- var aabb = new g.AABB();
3506
- dirtyObjects.forEach(function (object) {
3507
- var renderBounds = object.getRenderBounds();
3508
- aabb.add(renderBounds);
3509
- var dirtyRenderBounds = object.renderable.dirtyRenderBounds;
3833
+ this.useAnchor(context, object, function () {
3834
+ // generate path in local space
3835
+ var generatePath = _this4.pathGeneratorFactory(object.nodeName);
3510
3836
 
3511
- if (dirtyRenderBounds) {
3512
- aabb.add(dirtyRenderBounds);
3513
- }
3514
- });
3515
- return aabb;
3516
- };
3837
+ if (generatePath) {
3838
+ if (startBatch || !_this4.enableBatch) {
3839
+ context.beginPath();
3840
+ }
3517
3841
 
3518
- _proto.searchDirtyObjects = function searchDirtyObjects(dirtyRectangle) {
3519
- var _this5 = this; // search in r-tree, get all affected nodes
3842
+ generatePath(context, object.parsedStyle);
3520
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
3521
3848
 
3522
- var _dirtyRectangle$getMi = dirtyRectangle.getMin(),
3523
- minX = _dirtyRectangle$getMi[0],
3524
- minY = _dirtyRectangle$getMi[1];
3525
3849
 
3526
- var _dirtyRectangle$getMa = dirtyRectangle.getMax(),
3527
- maxX = _dirtyRectangle$getMa[0],
3528
- maxY = _dirtyRectangle$getMa[1];
3850
+ if (styleRenderer && !_this4.enableBatch) {
3851
+ styleRenderer.render(context, object.parsedStyle, object);
3852
+ }
3853
+ }); // restore applied attributes, eg. shadowBlur shadowColor...
3529
3854
 
3530
- var rBushNodes = this.rBush.search({
3531
- minX: minX,
3532
- minY: minY,
3533
- maxX: maxX,
3534
- maxY: maxY
3535
- });
3536
- return rBushNodes.map(function (_ref3) {
3537
- var id = _ref3.id;
3538
- return _this5.displayObjectPool.getByEntity(id);
3539
- });
3540
- };
3855
+ if (!this.enableBatch) {
3856
+ context.restore();
3857
+ } // finish rendering, clear dirty flag
3541
3858
 
3542
- _proto.saveDirtyAABB = function saveDirtyAABB(object) {
3543
- var renderable = object.renderable;
3544
3859
 
3545
- if (!renderable.dirtyRenderBounds) {
3546
- renderable.dirtyRenderBounds = new g.AABB();
3860
+ object.renderable.dirty = false;
3861
+ this.restoreStack.push(object);
3547
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
3548
3869
 
3549
- var renderBounds = object.getRenderBounds();
3550
-
3551
- if (renderBounds) {
3552
- // save last dirty aabb
3553
- 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
+ };
3554
3882
  }
3555
- };
3556
-
3557
- _proto.applyTransform = function applyTransform(context, transform) {
3558
- var _mat4$getTranslation = getTranslation(create$1(), transform),
3559
- tx = _mat4$getTranslation[0],
3560
- ty = _mat4$getTranslation[1];
3561
-
3562
- var _mat4$getScaling = getScaling(create$1(), transform),
3563
- sx = _mat4$getScaling[0],
3564
- 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
3565
3909
 
3566
- var rotation = getRotation(create$3(), transform); // eslint-disable-next-line @typescript-eslint/no-unused-vars
3567
3910
 
3568
- var _getEuler = g.getEuler(create$1(), rotation),
3569
- eux = _getEuler[0],
3570
- euy = _getEuler[1],
3571
- 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];
3572
3915
 
3916
+ var _dirtyRectangle$getMa = dirtyRectangle.getMax(),
3917
+ _dirtyRectangle$getMa2 = _slicedToArray(_dirtyRectangle$getMa, 2),
3918
+ maxX = _dirtyRectangle$getMa2[0],
3919
+ maxY = _dirtyRectangle$getMa2[1];
3573
3920
 
3574
- 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;
3575
3936
 
3576
- context.transform(rts[0], rts[1], rts[3], rts[4], rts[6], rts[7]);
3577
- };
3937
+ if (!renderable.dirtyRenderBounds) {
3938
+ renderable.dirtyRenderBounds = new g.AABB();
3939
+ }
3578
3940
 
3579
- _proto.getColor = function getColor(parsedColor, object, context, renderingService) {
3580
- var color;
3581
-
3582
- if (parsedColor instanceof g.CSSGradientValue) {
3583
- if (parsedColor.type === g.GradientPatternType.LinearGradient || parsedColor.type === g.GradientPatternType.RadialGradient) {
3584
- var bounds = object.getGeometryBounds();
3585
- var width = bounds && bounds.halfExtents[0] * 2 || 0;
3586
- var height = bounds && bounds.halfExtents[1] * 2 || 0;
3587
- color = this.gradientPool.getOrCreateGradient(_extends({
3588
- type: parsedColor.type
3589
- }, parsedColor.value, {
3590
- width: width,
3591
- height: height
3592
- }), context);
3593
- } else if (parsedColor.type === g.GradientPatternType.Pattern) {
3594
- var pattern = this.imagePool.getPatternSync(parsedColor.value);
3941
+ var renderBounds = object.getRenderBounds();
3595
3942
 
3596
- if (pattern) {
3597
- color = pattern;
3598
- } else {
3599
- this.imagePool.createPattern(parsedColor.value, context).then(function () {
3600
- // set dirty rectangle flag
3601
- object.renderable.dirty = true;
3602
- renderingService.dirtify();
3603
- });
3604
- }
3943
+ if (renderBounds) {
3944
+ // save last dirty aabb
3945
+ renderable.dirtyRenderBounds.update(renderBounds.center, renderBounds.halfExtents);
3605
3946
  }
3606
- } else {
3607
- // constant, eg. rgba(255,255,255,1)
3608
- color = parsedColor.toString();
3609
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
+ }
3610
4007
 
3611
- return color;
3612
- };
3613
-
3614
- _proto.applyAttributesToContext = function applyAttributesToContext(context, object, renderingService) {
3615
- var _object$parsedStyle = object.parsedStyle,
3616
- stroke = _object$parsedStyle.stroke,
3617
- fill = _object$parsedStyle.fill,
3618
- opacity = _object$parsedStyle.opacity,
3619
- lineDash = _object$parsedStyle.lineDash,
3620
- lineDashOffset = _object$parsedStyle.lineDashOffset,
3621
- filter = _object$parsedStyle.filter,
3622
- shadowColor = _object$parsedStyle.shadowColor,
3623
- shadowBlur = _object$parsedStyle.shadowBlur,
3624
- shadowOffsetX = _object$parsedStyle.shadowOffsetX,
3625
- shadowOffsetY = _object$parsedStyle.shadowOffsetY; // @see https://developer.mozilla.org/zh-CN/docs/Web/API/CanvasRenderingContext2D/setLineDash
3626
-
3627
- if (lineDash && Array.isArray(lineDash)) {
3628
- context.setLineDash(lineDash.map(function (segment) {
3629
- return segment.value;
3630
- }));
3631
- } // @see https://developer.mozilla.org/zh-CN/docs/Web/API/CanvasRenderingContext2D/lineDashOffset
3632
-
3633
-
3634
- if (!g.isNil(lineDashOffset)) {
3635
- context.lineDashOffset = lineDashOffset.value;
3636
- }
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
+ }
3637
4035
 
3638
- if (!g.isNil(opacity)) {
3639
- context.globalAlpha *= opacity.value;
3640
- }
4036
+ if (!g.isNil(opacity)) {
4037
+ context.globalAlpha *= opacity.value;
4038
+ }
3641
4039
 
3642
- if (!g.isNil(stroke)) {
3643
- context.strokeStyle = this.getColor(stroke, object, context, renderingService);
3644
- }
4040
+ if (!g.isNil(stroke) && !stroke.isNone) {
4041
+ context.strokeStyle = this.getColor(stroke, object, context, renderingService);
4042
+ }
3645
4043
 
3646
- if (!g.isNil(fill)) {
3647
- context.fillStyle = this.getColor(fill, object, context, renderingService);
3648
- }
4044
+ if (!g.isNil(fill) && !fill.isNone) {
4045
+ context.fillStyle = this.getColor(fill, object, context, renderingService);
4046
+ }
3649
4047
 
3650
- if (!g.isNil(filter)) {
3651
- // use raw filter string
3652
- context.filter = object.style.filter;
3653
- }
4048
+ if (!g.isNil(filter)) {
4049
+ // use raw filter string
4050
+ context.filter = object.style.filter;
4051
+ }
3654
4052
 
3655
- if (!g.isNil(shadowColor)) {
3656
- context.shadowColor = shadowColor.toString();
3657
- context.shadowBlur = shadowBlur && shadowBlur.value || 0;
3658
- context.shadowOffsetX = shadowOffsetX && shadowOffsetX.value || 0;
3659
- 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
+ }
3660
4059
  }
3661
- };
3662
-
3663
- _proto.useAnchor = function useAnchor(context, object, callback) {
3664
- var contentBounds = object.getGeometryBounds();
4060
+ }, {
4061
+ key: "useAnchor",
4062
+ value: function useAnchor(context, object, callback) {
4063
+ var contentBounds = object.getGeometryBounds();
3665
4064
 
3666
- if (contentBounds) {
3667
- var halfExtents = contentBounds.halfExtents; // apply anchor, use true size, not include stroke,
3668
- // eg. bounds = true size + half lineWidth
4065
+ if (contentBounds) {
4066
+ var halfExtents = contentBounds.halfExtents; // apply anchor, use true size, not include stroke,
4067
+ // eg. bounds = true size + half lineWidth
3669
4068
 
3670
- var _ref4 = object.parsedStyle || {},
3671
- anchor = _ref4.anchor;
4069
+ var _ref4 = object.parsedStyle || {},
4070
+ anchor = _ref4.anchor;
3672
4071
 
3673
- context.translate(-(anchor && anchor[0].value || 0) * halfExtents[0] * 2, -(anchor && anchor[1].value || 0) * halfExtents[1] * 2);
3674
- callback();
3675
- } else {
3676
- 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
+ }
3677
4077
  }
3678
- };
4078
+ }, {
4079
+ key: "safeMergeAABB",
4080
+ value: function safeMergeAABB() {
4081
+ var merged = new g.AABB();
3679
4082
 
3680
- _proto.safeMergeAABB = function safeMergeAABB() {
3681
- 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
+ }
3682
4086
 
3683
- for (var _len = arguments.length, aabbs = new Array(_len), _key = 0; _key < _len; _key++) {
3684
- aabbs[_key] = arguments[_key];
4087
+ aabbs.forEach(function (aabb) {
4088
+ merged.add(aabb);
4089
+ });
4090
+ return merged;
3685
4091
  }
3686
-
3687
- aabbs.forEach(function (aabb) {
3688
- merged.add(aabb);
3689
- });
3690
- return merged;
3691
- };
4092
+ }]);
3692
4093
 
3693
4094
  return CanvasRendererPlugin;
3694
4095
  }(), _class$1.tag = 'CanvasRenderer', _class$1);
@@ -3722,73 +4123,76 @@
3722
4123
  var LoadImagePlugin_1;
3723
4124
  var LoadImagePlugin = LoadImagePlugin_1 = (_class$1$1 = /*#__PURE__*/function () {
3724
4125
  function LoadImagePlugin() {
3725
- this.imagePool = void 0;
3726
- this.renderingContext = void 0;
3727
- }
4126
+ _classCallCheck$2(this, LoadImagePlugin);
3728
4127
 
3729
- var _proto = LoadImagePlugin.prototype;
3730
-
3731
- _proto.apply = function apply(renderingService) {
3732
- var _this = this;
3733
-
3734
- var handleMounted = function handleMounted(e) {
3735
- var object = e.target;
3736
- var nodeName = object.nodeName,
3737
- attributes = object.attributes;
4128
+ this.imagePool = void 0;
4129
+ this.renderingContext = void 0;
4130
+ }
3738
4131
 
3739
- if (nodeName === g.Shape.IMAGE) {
3740
- var img = attributes.img;
4132
+ _createClass$2(LoadImagePlugin, [{
4133
+ key: "apply",
4134
+ value: function apply(renderingService) {
4135
+ var _this = this;
3741
4136
 
3742
- if (g.isString(img)) {
3743
- _this.imagePool.getOrCreateImage(img).then(function () {
3744
- // set dirty rectangle flag
3745
- object.renderable.dirty = true;
3746
- renderingService.dirtify();
3747
- });
3748
- }
3749
- }
3750
- };
4137
+ var handleMounted = function handleMounted(e) {
4138
+ var object = e.target;
4139
+ var nodeName = object.nodeName,
4140
+ attributes = object.attributes;
3751
4141
 
3752
- var handleAttributeChanged = function handleAttributeChanged(e) {
3753
- var object = e.target;
3754
- var attrName = e.attrName,
3755
- newValue = e.newValue;
4142
+ if (nodeName === g.Shape.IMAGE) {
4143
+ var img = attributes.img;
3756
4144
 
3757
- if (object.nodeName === g.Shape.IMAGE) {
3758
- if (attrName === 'img') {
3759
- if (g.isString(newValue)) {
3760
- _this.imagePool.getOrCreateImage(newValue).then(function () {
4145
+ if (g.isString(img)) {
4146
+ _this.imagePool.getOrCreateImage(img).then(function () {
3761
4147
  // set dirty rectangle flag
3762
4148
  object.renderable.dirty = true;
3763
4149
  renderingService.dirtify();
3764
4150
  });
3765
4151
  }
3766
4152
  }
3767
- }
3768
- };
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
+ };
3769
4172
 
3770
- renderingService.hooks.init.tapPromise(LoadImagePlugin_1.tag, /*#__PURE__*/_asyncToGenerator$1( /*#__PURE__*/_regeneratorRuntime$1().mark(function _callee() {
3771
- return _regeneratorRuntime$1().wrap(function _callee$(_context) {
3772
- while (1) {
3773
- switch (_context.prev = _context.next) {
3774
- case 0:
3775
- _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);
3776
4179
 
3777
- _this.renderingContext.root.addEventListener(g.ElementEvent.ATTR_MODIFIED, handleAttributeChanged);
4180
+ _this.renderingContext.root.addEventListener(g.ElementEvent.ATTR_MODIFIED, handleAttributeChanged);
3778
4181
 
3779
- case 2:
3780
- case "end":
3781
- return _context.stop();
4182
+ case 2:
4183
+ case "end":
4184
+ return _context.stop();
4185
+ }
3782
4186
  }
3783
- }
3784
- }, _callee);
3785
- })));
3786
- renderingService.hooks.destroy.tap(LoadImagePlugin_1.tag, function () {
3787
- _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);
3788
4191
 
3789
- _this.renderingContext.root.removeEventListener(g.ElementEvent.ATTR_MODIFIED, handleAttributeChanged);
3790
- });
3791
- };
4192
+ _this.renderingContext.root.removeEventListener(g.ElementEvent.ATTR_MODIFIED, handleAttributeChanged);
4193
+ });
4194
+ }
4195
+ }]);
3792
4196
 
3793
4197
  return LoadImagePlugin;
3794
4198
  }(), _class$1$1.tag = 'LoadImage', _class$1$1);
@@ -3885,7 +4289,7 @@
3885
4289
  register(PolylineRenderer);
3886
4290
  register(PolygonRenderer);
3887
4291
  register(PathRenderer);
3888
- 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);
3889
4293
  register({
3890
4294
  token: StyleRendererFactory,
3891
4295
  useFactory: function useFactory(ctx) {
@@ -3910,18 +4314,22 @@
3910
4314
 
3911
4315
  var Plugin$1 = /*#__PURE__*/function () {
3912
4316
  function Plugin() {
4317
+ _classCallCheck$2(this, Plugin);
4318
+
3913
4319
  this.name = 'canvas-renderer';
3914
4320
  }
3915
4321
 
3916
- var _proto = Plugin.prototype;
3917
-
3918
- _proto.init = function init(container) {
3919
- container.load(containerModule$1, true);
3920
- };
3921
-
3922
- _proto.destroy = function destroy(container) {
3923
- container.unload(containerModule$1);
3924
- };
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
+ }]);
3925
4333
 
3926
4334
  return Plugin;
3927
4335
  }();
@@ -4080,7 +4488,7 @@
4080
4488
  if ("throw" !== record.type) {
4081
4489
  var result = record.arg,
4082
4490
  value = result.value;
4083
- 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) {
4084
4492
  invoke("next", value, resolve, reject);
4085
4493
  }, function (err) {
4086
4494
  invoke("throw", err, resolve, reject);
@@ -4340,6 +4748,92 @@
4340
4748
  });
4341
4749
  };
4342
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
+ }
4343
4837
  /**
4344
4838
  * Common utilities
4345
4839
  * @module glMatrix
@@ -4934,6 +5428,8 @@
4934
5428
  function CanvasPickerPlugin() {
4935
5429
  var _this = this;
4936
5430
 
5431
+ _classCallCheck$3(this, CanvasPickerPlugin);
5432
+
4937
5433
  this.displayObjectPool = void 0;
4938
5434
  this.canvasConfig = void 0;
4939
5435
  this.offscreenCanvas = void 0;
@@ -4979,108 +5475,109 @@
4979
5475
  };
4980
5476
  }
4981
5477
 
4982
- var _proto = CanvasPickerPlugin.prototype;
4983
-
4984
- _proto.apply = function apply(renderingService) {
4985
- var _this2 = this;
4986
-
4987
- renderingService.hooks.pick.tapPromise(CanvasPickerPlugin_1.tag, /*#__PURE__*/function () {
4988
- var _ref = _asyncToGenerator$2( /*#__PURE__*/_regeneratorRuntime$2().mark(function _callee(result) {
4989
- var topmost, _result$position, x, y, position, rBushNodes, queriedIds, hitTestList, pickedDisplayObjects, _i, _hitTestList, displayObject, clipPath, objectToTest, worldTransform;
4990
-
4991
- return _regeneratorRuntime$2().wrap(function _callee$(_context) {
4992
- while (1) {
4993
- switch (_context.prev = _context.next) {
4994
- case 0:
4995
- topmost = result.topmost, _result$position = result.position, x = _result$position.x, y = _result$position.y; // position in world space
4996
-
4997
- position = fromValues$1(x, y, 0); // query by AABB first with spatial index(r-tree)
4998
-
4999
- rBushNodes = _this2.rBush.search({
5000
- minX: position[0],
5001
- minY: position[1],
5002
- maxX: position[0],
5003
- maxY: position[1]
5004
- });
5005
- queriedIds = rBushNodes.map(function (node) {
5006
- return node.id;
5007
- });
5008
- hitTestList = [];
5009
- rBushNodes.forEach(function (_ref2) {
5010
- var id = _ref2.id;
5011
-
5012
- var displayObject = _this2.displayObjectPool.getByEntity(id);
5013
-
5014
- if (displayObject.isVisible() && !displayObject.isCulled() && displayObject.isInteractive()) {
5015
- // parent is not included, eg. parent is clipped
5016
- if (displayObject.parentNode && queriedIds.indexOf(displayObject.parentNode.entity) === -1) {
5017
- 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);
5018
5517
  }
5019
-
5020
- 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;
5021
5530
  }
5022
- }); // find group with max z-index
5023
-
5024
- hitTestList.sort(function (a, b) {
5025
- return b.sortable.renderOrder - a.sortable.renderOrder;
5026
- });
5027
- pickedDisplayObjects = [];
5028
- _i = 0, _hitTestList = hitTestList;
5029
-
5030
- case 9:
5031
- if (!(_i < _hitTestList.length)) {
5032
- _context.next = 25;
5033
- break;
5034
- }
5035
5531
 
5036
- displayObject = _hitTestList[_i]; // test with clip path
5532
+ displayObject = _hitTestList[_i]; // test with clip path
5037
5533
 
5038
- clipPath = displayObject.parsedStyle.clipPath;
5039
- objectToTest = clipPath || displayObject;
5040
- 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
5041
5537
 
5042
- if (clipPath) {
5043
- worldTransform = multiply$1(create$1$1(), worldTransform, clipPath.getLocalTransform());
5044
- }
5538
+ if (clipPath) {
5539
+ worldTransform = multiply$1(create$1$1(), worldTransform, clipPath.getLocalTransform());
5540
+ }
5045
5541
 
5046
- if (!_this2.isHit(objectToTest, position, worldTransform)) {
5047
- _context.next = 22;
5048
- break;
5049
- }
5542
+ if (!_this2.isHit(objectToTest, position, worldTransform)) {
5543
+ _context.next = 22;
5544
+ break;
5545
+ }
5050
5546
 
5051
- if (!topmost) {
5052
- _context.next = 21;
5053
- break;
5054
- }
5547
+ if (!topmost) {
5548
+ _context.next = 21;
5549
+ break;
5550
+ }
5055
5551
 
5056
- result.picked = [displayObject];
5057
- return _context.abrupt("return", result);
5552
+ result.picked = [displayObject];
5553
+ return _context.abrupt("return", result);
5058
5554
 
5059
- case 21:
5060
- pickedDisplayObjects.push(displayObject);
5555
+ case 21:
5556
+ pickedDisplayObjects.push(displayObject);
5061
5557
 
5062
- case 22:
5063
- _i++;
5064
- _context.next = 9;
5065
- break;
5558
+ case 22:
5559
+ _i++;
5560
+ _context.next = 9;
5561
+ break;
5066
5562
 
5067
- case 25:
5068
- result.picked = pickedDisplayObjects;
5069
- return _context.abrupt("return", result);
5563
+ case 25:
5564
+ result.picked = pickedDisplayObjects;
5565
+ return _context.abrupt("return", result);
5070
5566
 
5071
- case 27:
5072
- case "end":
5073
- return _context.stop();
5567
+ case 27:
5568
+ case "end":
5569
+ return _context.stop();
5570
+ }
5074
5571
  }
5075
- }
5076
- }, _callee);
5077
- }));
5572
+ }, _callee);
5573
+ }));
5078
5574
 
5079
- return function (_x) {
5080
- return _ref.apply(this, arguments);
5081
- };
5082
- }());
5083
- };
5575
+ return function (_x) {
5576
+ return _ref.apply(this, arguments);
5577
+ };
5578
+ }());
5579
+ }
5580
+ }]);
5084
5581
 
5085
5582
  return CanvasPickerPlugin;
5086
5583
  }(), _class$2.tag = 'CanvasPicker', _class$2);
@@ -5100,6 +5597,41 @@
5100
5597
  CanvasPickerPlugin = CanvasPickerPlugin_1 = __decorate([manaSyringe.singleton({
5101
5598
  contrib: g.RenderingPluginContribution
5102
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
+ }
5103
5635
  /**
5104
5636
  * 两点之间的距离
5105
5637
  * @param {number} x1 起始点 x
@@ -5109,6 +5641,7 @@
5109
5641
  * @return {number} 距离
5110
5642
  */
5111
5643
 
5644
+
5112
5645
  function distance(x1, y1, x2, y2) {
5113
5646
  var dx = x1 - x2;
5114
5647
  var dy = y1 - y2;
@@ -5120,10 +5653,10 @@
5120
5653
  }
5121
5654
 
5122
5655
  function getBBoxByArray(xArr, yArr) {
5123
- var minX = Math.min.apply(Math, xArr);
5124
- var minY = Math.min.apply(Math, yArr);
5125
- var maxX = Math.max.apply(Math, xArr);
5126
- 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));
5127
5660
  return {
5128
5661
  x: minX,
5129
5662
  y: minY,
@@ -5266,7 +5799,7 @@
5266
5799
  for (var i = 0; i <= segNum; i++) {
5267
5800
  var _t = i * increaseRate;
5268
5801
 
5269
- 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])))];
5270
5803
  var d1 = distance(v0[0], v0[1], v1[0], v1[1]);
5271
5804
 
5272
5805
  if (d1 < d) {
@@ -5300,7 +5833,7 @@
5300
5833
 
5301
5834
  var prev = t - interval;
5302
5835
  var next = t + interval;
5303
- 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])))];
5304
5837
 
5305
5838
  var _d = distance(v0[0], v0[1], _v[0], _v[1]);
5306
5839
 
@@ -5308,7 +5841,7 @@
5308
5841
  t = prev;
5309
5842
  d = _d;
5310
5843
  } else {
5311
- 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])))];
5312
5845
  var d2 = distance(v0[0], v0[1], v2[0], v2[1]);
5313
5846
 
5314
5847
  if (next <= 1 && d2 < d) {
@@ -5321,8 +5854,8 @@
5321
5854
  }
5322
5855
 
5323
5856
  return {
5324
- x: tCallback.apply(void 0, xArr.concat([t])),
5325
- 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])))
5326
5859
  };
5327
5860
  } // 近似求解 https://community.khronos.org/t/3d-cubic-bezier-segment-length/62363/2
5328
5861
 
@@ -5391,7 +5924,7 @@
5391
5924
  var right = quadratics[1];
5392
5925
  left.push(iterationCount - 1);
5393
5926
  right.push(iterationCount - 1);
5394
- 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));
5395
5928
  }
5396
5929
 
5397
5930
  var quadratic = {
@@ -5512,9 +6045,9 @@
5512
6045
  }
5513
6046
 
5514
6047
  var cubics = divideCubic(x1, y1, x2, y2, x3, y3, x4, y4, 0.5);
5515
- var left = [].concat(cubics[0], [iterationCount - 1]);
5516
- var right = [].concat(cubics[1], [iterationCount - 1]);
5517
- 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));
5518
6051
  }
5519
6052
 
5520
6053
  var cubic = {
@@ -5716,7 +6249,7 @@
5716
6249
  increasedLineWidthForHitTesting = _displayObject$parsed.increasedLineWidthForHitTesting,
5717
6250
  clipPathTargets = _displayObject$parsed.clipPathTargets;
5718
6251
  var r = rInPixels.value;
5719
- var halfLineWidth = (lineWidth.value + increasedLineWidthForHitTesting.value) / 2;
6252
+ var halfLineWidth = (((lineWidth === null || lineWidth === void 0 ? void 0 : lineWidth.value) || 0) + increasedLineWidthForHitTesting.value) / 2;
5720
6253
  var absDistance = distance$1(r, r, position.x, position.y);
5721
6254
  var isClipPath = !!(clipPathTargets === null || clipPathTargets === void 0 ? void 0 : clipPathTargets.length);
5722
6255
  var hasFill = fill && !fill.isNone;
@@ -5757,7 +6290,7 @@
5757
6290
  var hasStroke = stroke && !stroke.isNone;
5758
6291
  var rx = rxInPixels.value;
5759
6292
  var ry = ryInPixels.value;
5760
- var halfLineWith = (lineWidth.value + increasedLineWidthForHitTesting.value) / 2;
6293
+ var halfLineWith = (((lineWidth === null || lineWidth === void 0 ? void 0 : lineWidth.value) || 0) + increasedLineWidthForHitTesting.value) / 2;
5761
6294
  var squareX = (x - rx) * (x - rx);
5762
6295
  var squareY = (y - ry) * (y - ry); // 使用椭圆的公式: x*x/rx*rx + y*y/ry*ry = 1;
5763
6296
 
@@ -5994,10 +6527,12 @@
5994
6527
  }
5995
6528
 
5996
6529
  function inRectWithRadius(minX, minY, width, height, radiusArray, lineWidth, x, y) {
5997
- var tlr = radiusArray[0],
5998
- trr = radiusArray[1],
5999
- brr = radiusArray[2],
6000
- 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
+
6001
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);
6002
6537
  }
6003
6538
 
@@ -6064,18 +6599,22 @@
6064
6599
 
6065
6600
  var Plugin$2 = /*#__PURE__*/function () {
6066
6601
  function Plugin() {
6602
+ _classCallCheck$3(this, Plugin);
6603
+
6067
6604
  this.name = 'canvas-picker';
6068
6605
  }
6069
6606
 
6070
- var _proto = Plugin.prototype;
6071
-
6072
- _proto.init = function init(container) {
6073
- container.load(containerModule$2, true);
6074
- };
6075
-
6076
- _proto.destroy = function destroy(container) {
6077
- container.unload(containerModule$2);
6078
- };
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
+ }]);
6079
6618
 
6080
6619
  return Plugin;
6081
6620
  }();
@@ -6210,7 +6749,7 @@
6210
6749
  if ("throw" !== record.type) {
6211
6750
  var result = record.arg,
6212
6751
  value = result.value;
6213
- 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) {
6214
6753
  invoke("next", value, resolve, reject);
6215
6754
  }, function (err) {
6216
6755
  invoke("throw", err, resolve, reject);
@@ -6471,229 +7010,260 @@
6471
7010
  };
6472
7011
  }
6473
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
+
6474
7038
  var _class$3;
6475
7039
 
6476
7040
  var HTMLRenderingPlugin_1;
6477
7041
  var HTML_PREFIX = 'g-html-';
6478
7042
  var HTMLRenderingPlugin = HTMLRenderingPlugin_1 = (_class$3 = /*#__PURE__*/function () {
6479
7043
  function HTMLRenderingPlugin() {
7044
+ _classCallCheck$4(this, HTMLRenderingPlugin);
7045
+
6480
7046
  this.contextService = void 0;
6481
7047
  this.renderingContext = void 0;
6482
7048
  this.$camera = void 0;
6483
7049
  }
6484
7050
 
6485
- var _proto = HTMLRenderingPlugin.prototype;
7051
+ _createClass$4(HTMLRenderingPlugin, [{
7052
+ key: "apply",
7053
+ value: function apply(renderingService) {
7054
+ var _this = this;
6486
7055
 
6487
- _proto.apply = function apply(renderingService) {
6488
- var _this = this;
6489
-
6490
- var handleMounted = function handleMounted(e) {
6491
- var object = e.target;
7056
+ var handleMounted = function handleMounted(e) {
7057
+ var object = e.target;
6492
7058
 
6493
- if (object.nodeName === g.Shape.HTML) {
6494
- 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
6495
7061
 
6496
7062
 
6497
- var attributes = object.ownerDocument.documentElement.attributes;
6498
- Object.keys(attributes).forEach(function (name) {
6499
- $el.style[name] = attributes[name];
6500
- });
6501
- Object.keys(object.attributes).forEach(function (name) {
6502
- _this.updateAttribute(name, object);
6503
- });
6504
- }
6505
- };
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
+ };
6506
7072
 
6507
- var handleUnmounted = function handleUnmounted(e) {
6508
- var object = e.target;
7073
+ var handleUnmounted = function handleUnmounted(e) {
7074
+ var object = e.target;
6509
7075
 
6510
- if (object.nodeName === g.Shape.HTML) {
6511
- var existedId = _this.getId(object);
7076
+ if (object.nodeName === g.Shape.HTML) {
7077
+ var existedId = _this.getId(object);
6512
7078
 
6513
- var $container = _this.contextService.getDomElement().parentNode;
7079
+ var $container = _this.contextService.getDomElement().parentNode;
6514
7080
 
6515
- if ($container) {
6516
- var $existedElement = $container.querySelector('#' + existedId);
7081
+ if ($container) {
7082
+ var $existedElement = $container.querySelector('#' + existedId);
6517
7083
 
6518
- if ($existedElement) {
6519
- $container.removeChild($existedElement);
7084
+ if ($existedElement) {
7085
+ $container.removeChild($existedElement);
7086
+ }
6520
7087
  }
6521
7088
  }
6522
- }
6523
- };
7089
+ };
6524
7090
 
6525
- var handleAttributeChanged = function handleAttributeChanged(e) {
6526
- var object = e.target;
7091
+ var handleAttributeChanged = function handleAttributeChanged(e) {
7092
+ var object = e.target;
6527
7093
 
6528
- if (object.nodeName === g.Shape.HTML) {
6529
- var attrName = e.attrName;
7094
+ if (object.nodeName === g.Shape.HTML) {
7095
+ var attrName = e.attrName;
6530
7096
 
6531
- _this.updateAttribute(attrName, object);
6532
- }
6533
- };
7097
+ _this.updateAttribute(attrName, object);
7098
+ }
7099
+ };
6534
7100
 
6535
- renderingService.hooks.init.tapPromise(HTMLRenderingPlugin_1.tag, /*#__PURE__*/_asyncToGenerator$3( /*#__PURE__*/_regeneratorRuntime$3().mark(function _callee() {
6536
- return _regeneratorRuntime$3().wrap(function _callee$(_context) {
6537
- while (1) {
6538
- switch (_context.prev = _context.next) {
6539
- case 0:
6540
- _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);
6541
7107
 
6542
- _this.renderingContext.root.addEventListener(g.ElementEvent.UNMOUNTED, handleUnmounted);
7108
+ _this.renderingContext.root.addEventListener(g.ElementEvent.UNMOUNTED, handleUnmounted);
6543
7109
 
6544
- _this.renderingContext.root.addEventListener(g.ElementEvent.ATTR_MODIFIED, handleAttributeChanged);
7110
+ _this.renderingContext.root.addEventListener(g.ElementEvent.ATTR_MODIFIED, handleAttributeChanged);
6545
7111
 
6546
- case 3:
6547
- case "end":
6548
- return _context.stop();
7112
+ case 3:
7113
+ case "end":
7114
+ return _context.stop();
7115
+ }
6549
7116
  }
6550
- }
6551
- }, _callee);
6552
- })));
6553
- renderingService.hooks.destroy.tap(HTMLRenderingPlugin_1.tag, function () {
6554
- _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);
6555
7121
 
6556
- _this.renderingContext.root.removeEventListener(g.ElementEvent.UNMOUNTED, handleUnmounted);
7122
+ _this.renderingContext.root.removeEventListener(g.ElementEvent.UNMOUNTED, handleUnmounted);
6557
7123
 
6558
- _this.renderingContext.root.removeEventListener(g.ElementEvent.ATTR_MODIFIED, handleAttributeChanged);
6559
- });
6560
- };
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;
6561
7137
 
6562
- _proto.getId = function getId(object) {
6563
- return object.id || HTML_PREFIX + object.entity;
6564
- };
7138
+ if ($container) {
7139
+ var $existedElement = $container.querySelector('#' + existedId);
6565
7140
 
6566
- _proto.getOrCreateEl = function getOrCreateEl(object) {
6567
- var existedId = this.getId(object);
6568
- var $container = this.contextService.getDomElement().parentNode;
7141
+ if (!$existedElement) {
7142
+ $existedElement = document.createElement('div');
7143
+ object.parsedStyle.$el = $existedElement;
7144
+ $existedElement.id = existedId;
6569
7145
 
6570
- if ($container) {
6571
- var $existedElement = $container.querySelector('#' + existedId);
7146
+ if (object.name) {
7147
+ $existedElement.setAttribute('name', object.name);
7148
+ }
6572
7149
 
6573
- if (!$existedElement) {
6574
- $existedElement = document.createElement('div');
6575
- object.parsedStyle.$el = $existedElement;
6576
- $existedElement.id = existedId;
7150
+ if (object.className) {
7151
+ $existedElement.className = object.className;
7152
+ }
6577
7153
 
6578
- if (object.name) {
6579
- $existedElement.setAttribute('name', object.name);
6580
- }
7154
+ $container.appendChild($existedElement); // use absolute position
6581
7155
 
6582
- if (object.className) {
6583
- $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(','), ")");
6584
7162
  }
6585
7163
 
6586
- $container.appendChild($existedElement); // use absolute position
6587
-
6588
- $existedElement.style.position = 'absolute';
6589
- $existedElement.style.left = '0';
6590
- $existedElement.style.top = '0';
6591
- $existedElement.style['will-change'] = 'transform';
6592
- var worldTransform = object.getWorldTransform();
6593
- $existedElement.style.transform = "matrix(" + [worldTransform[0], worldTransform[1], worldTransform[4], worldTransform[5], worldTransform[12], worldTransform[13]].join(',') + ")";
7164
+ return $existedElement;
6594
7165
  }
6595
7166
 
6596
- return $existedElement;
7167
+ return null;
6597
7168
  }
7169
+ }, {
7170
+ key: "updateAttribute",
7171
+ value: function updateAttribute(name, object) {
7172
+ var $el = this.getOrCreateEl(object);
6598
7173
 
6599
- return null;
6600
- };
6601
-
6602
- _proto.updateAttribute = function updateAttribute(name, object) {
6603
- var $el = this.getOrCreateEl(object);
6604
-
6605
- switch (name) {
6606
- case 'innerHTML':
6607
- var innerHTML = object.parsedStyle.innerHTML;
7174
+ switch (name) {
7175
+ case 'innerHTML':
7176
+ var innerHTML = object.parsedStyle.innerHTML;
6608
7177
 
6609
- if (g.isString(innerHTML)) {
6610
- $el.innerHTML = innerHTML;
6611
- } else {
6612
- $el.innerHTML = '';
6613
- $el.appendChild(innerHTML);
6614
- }
7178
+ if (g.isString(innerHTML)) {
7179
+ $el.innerHTML = innerHTML;
7180
+ } else {
7181
+ $el.innerHTML = '';
7182
+ $el.appendChild(innerHTML);
7183
+ }
6615
7184
 
6616
- break;
7185
+ break;
6617
7186
 
6618
- case 'modelMatrix':
6619
- case 'transformOrigin':
6620
- var transformOrigin = object.parsedStyle.transformOrigin;
6621
- $el.style['transform-origin'] = transformOrigin[0].value + " " + transformOrigin[1].value;
6622
- var worldTransform = object.getWorldTransform();
6623
- $el.style.transform = "matrix(" + [worldTransform[0], worldTransform[1], worldTransform[4], worldTransform[5], worldTransform[12], worldTransform[13]].join(',') + ")";
6624
- 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;
6625
7194
 
6626
- case 'width':
6627
- var width = object.computedStyleMap().get('width');
6628
- $el.style.width = width.toString();
6629
- break;
7195
+ case 'width':
7196
+ var width = object.computedStyleMap().get('width');
7197
+ $el.style.width = width.toString();
7198
+ break;
6630
7199
 
6631
- case 'height':
6632
- var height = object.computedStyleMap().get('height');
6633
- $el.style.height = height.toString();
6634
- break;
7200
+ case 'height':
7201
+ var height = object.computedStyleMap().get('height');
7202
+ $el.style.height = height.toString();
7203
+ break;
6635
7204
 
6636
- case 'zIndex':
6637
- var zIndex = object.parsedStyle.zIndex;
6638
- $el.style['z-index'] = "" + zIndex.value;
6639
- break;
7205
+ case 'zIndex':
7206
+ var zIndex = object.parsedStyle.zIndex;
7207
+ $el.style['z-index'] = "".concat(zIndex.value);
7208
+ break;
6640
7209
 
6641
- case 'visibility':
6642
- var visibility = object.parsedStyle.visibility;
6643
- $el.style.visibility = visibility.value;
6644
- break;
7210
+ case 'visibility':
7211
+ var visibility = object.parsedStyle.visibility;
7212
+ $el.style.visibility = visibility.value;
7213
+ break;
6645
7214
 
6646
- case 'pointerEvents':
6647
- var pointerEvents = object.parsedStyle.pointerEvents;
6648
- $el.style.pointerEvents = pointerEvents.value;
6649
- break;
7215
+ case 'pointerEvents':
7216
+ var pointerEvents = object.parsedStyle.pointerEvents;
7217
+ $el.style.pointerEvents = pointerEvents.value;
7218
+ break;
6650
7219
 
6651
- case 'opacity':
6652
- var opacity = object.parsedStyle.opacity;
6653
- $el.style.opacity = "" + opacity.value;
6654
- break;
7220
+ case 'opacity':
7221
+ var opacity = object.parsedStyle.opacity;
7222
+ $el.style.opacity = "".concat(opacity.value);
7223
+ break;
6655
7224
 
6656
- case 'fill':
6657
- var fill = object.parsedStyle.fill;
6658
- var color = '';
7225
+ case 'fill':
7226
+ var fill = object.parsedStyle.fill;
7227
+ var color = '';
6659
7228
 
6660
- if (fill instanceof g.CSSRGB) {
6661
- color = fill.toString();
6662
- } else if (fill instanceof g.CSSGradientValue) {
6663
- if (fill.type === g.GradientPatternType.LinearGradient) {
6664
- var steps = fill.value.steps.map(function (cur) {
6665
- // ['0', '#ffffff'],
6666
- return cur[1] + " " + Number(cur[0]) * 100 + "%";
6667
- }).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()
6668
7237
 
6669
- color = "linear-gradient(to right, " + steps + ");";
7238
+ color = "linear-gradient(to right, ".concat(steps, ");");
7239
+ }
6670
7240
  }
6671
- }
6672
7241
 
6673
- $el.style.background = color;
6674
- break;
7242
+ $el.style.background = color;
7243
+ break;
6675
7244
 
6676
- case 'stroke':
6677
- var stroke = object.parsedStyle.stroke;
6678
- $el.style['border-color'] = stroke.toString();
6679
- $el.style['border-style'] = 'solid';
6680
- 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;
6681
7250
 
6682
- case 'lineWidth':
6683
- var lineWidth = object.parsedStyle.lineWidth;
6684
- $el.style['border-width'] = (lineWidth.value || 0) + "px";
6685
- break;
7251
+ case 'lineWidth':
7252
+ var lineWidth = object.parsedStyle.lineWidth;
7253
+ $el.style['border-width'] = "".concat(lineWidth.value || 0, "px");
7254
+ break;
6686
7255
 
6687
- case 'lineDash':
6688
- $el.style['border-style'] = 'dashed';
6689
- break;
7256
+ case 'lineDash':
7257
+ $el.style['border-style'] = 'dashed';
7258
+ break;
6690
7259
 
6691
- case 'filter':
6692
- var filter = object.parsedStyle.filter;
6693
- $el.style.filter = filter;
6694
- break;
7260
+ case 'filter':
7261
+ var filter = object.parsedStyle.filter;
7262
+ $el.style.filter = filter;
7263
+ break;
7264
+ }
6695
7265
  }
6696
- };
7266
+ }]);
6697
7267
 
6698
7268
  return HTMLRenderingPlugin;
6699
7269
  }(), _class$3.tag = 'HTMLRendering', _class$3);
@@ -6711,18 +7281,22 @@
6711
7281
 
6712
7282
  var Plugin$3 = /*#__PURE__*/function () {
6713
7283
  function Plugin() {
7284
+ _classCallCheck$4(this, Plugin);
7285
+
6714
7286
  this.name = 'html-renderer';
6715
7287
  }
6716
7288
 
6717
- var _proto = Plugin.prototype;
6718
-
6719
- _proto.init = function init(container) {
6720
- container.load(containerModule$3, true);
6721
- };
6722
-
6723
- _proto.destroy = function destroy(container) {
6724
- container.unload(containerModule$3);
6725
- };
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
+ }]);
6726
7300
 
6727
7301
  return Plugin;
6728
7302
  }();
@@ -6734,6 +7308,8 @@
6734
7308
 
6735
7309
  var Canvas2DContextService = /*#__PURE__*/function () {
6736
7310
  function Canvas2DContextService() {
7311
+ _classCallCheck(this, Canvas2DContextService);
7312
+
6737
7313
  this.$container = void 0;
6738
7314
  this.$canvas = void 0;
6739
7315
  this.dpr = void 0;
@@ -6741,94 +7317,102 @@
6741
7317
  this.canvasConfig = void 0;
6742
7318
  }
6743
7319
 
6744
- 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;
6745
7327
 
6746
- _proto.init = function init() {
6747
- var _this$canvasConfig = this.canvasConfig,
6748
- container = _this$canvasConfig.container,
6749
- canvas = _this$canvasConfig.canvas,
6750
- devicePixelRatio = _this$canvasConfig.devicePixelRatio;
7328
+ if (canvas) {
7329
+ this.$canvas = canvas;
6751
7330
 
6752
- if (canvas) {
6753
- this.$canvas = canvas;
7331
+ if (container && canvas.parentElement !== container) {
7332
+ container.appendChild(canvas);
7333
+ }
6754
7334
 
6755
- if (container && canvas.parentElement !== container) {
6756
- container.appendChild(canvas);
6757
- }
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;
6758
7340
 
6759
- this.$container = canvas.parentElement;
6760
- this.canvasConfig.container = this.$container;
6761
- } else if (container) {
6762
- // create container
6763
- 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);
6764
7345
 
6765
- if (this.$container) {
6766
- // create canvas
6767
- var $canvas = document.createElement('canvas');
6768
- this.$container.appendChild($canvas);
7346
+ if (!this.$container.style.position) {
7347
+ this.$container.style.position = 'relative';
7348
+ }
6769
7349
 
6770
- if (!this.$container.style.position) {
6771
- this.$container.style.position = 'relative';
7350
+ this.$canvas = $canvas;
6772
7351
  }
6773
-
6774
- this.$canvas = $canvas;
6775
7352
  }
6776
- }
6777
-
6778
- this.context = this.$canvas.getContext('2d'); // use user-defined dpr first
6779
-
6780
- var dpr = devicePixelRatio || g.isBrowser && window.devicePixelRatio || 1;
6781
- dpr = dpr >= 1 ? Math.ceil(dpr) : 1;
6782
- this.dpr = dpr;
6783
- this.resize(this.canvasConfig.width, this.canvasConfig.height);
6784
- };
6785
-
6786
- _proto.getContext = function getContext() {
6787
- return this.context;
6788
- };
6789
7353
 
6790
- _proto.getDomElement = function getDomElement() {
6791
- return this.$canvas;
6792
- };
6793
-
6794
- _proto.getDPR = function getDPR() {
6795
- return this.dpr;
6796
- };
6797
-
6798
- _proto.getBoundingClientRect = function getBoundingClientRect() {
6799
- if (this.$canvas.getBoundingClientRect) {
6800
- 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
+ }
6801
7382
  }
6802
- };
6803
-
6804
- _proto.destroy = function destroy() {
6805
- // @ts-ignore
6806
- if (this.$container && this.$canvas && this.$canvas.parentNode) {
6807
- // destroy context
7383
+ }, {
7384
+ key: "destroy",
7385
+ value: function destroy() {
6808
7386
  // @ts-ignore
6809
- 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
+ }
6810
7392
  }
6811
- };
6812
-
6813
- _proto.resize = function resize(width, height) {
6814
- if (this.$canvas) {
6815
- // set canvas width & height
6816
- this.$canvas.width = this.dpr * width;
6817
- 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
6818
7400
 
6819
- g.setDOMSize(this.$canvas, width, height);
6820
- var dpr = this.getDPR(); // scale all drawing operations by the dpr
6821
- // @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/
6822
7404
 
6823
- this.context.scale(dpr, dpr);
7405
+ this.context.scale(dpr, dpr);
7406
+ }
6824
7407
  }
6825
- };
6826
-
6827
- _proto.applyCursorStyle = function applyCursorStyle(cursor) {
6828
- if (this.$container && this.$container.style) {
6829
- 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
+ }
6830
7414
  }
6831
- };
7415
+ }]);
6832
7416
 
6833
7417
  return Canvas2DContextService;
6834
7418
  }();
@@ -6847,29 +7431,37 @@
6847
7431
  });
6848
7432
  var ContextRegisterPlugin = /*#__PURE__*/function () {
6849
7433
  function ContextRegisterPlugin() {
7434
+ _classCallCheck(this, ContextRegisterPlugin);
7435
+
6850
7436
  this.name = 'canvas-context-register';
6851
7437
  }
6852
7438
 
6853
- var _proto = ContextRegisterPlugin.prototype;
6854
-
6855
- _proto.init = function init(container) {
6856
- container.load(containerModule$4, true);
6857
- };
6858
-
6859
- _proto.destroy = function destroy(container) {
6860
- container.unload(containerModule$4);
6861
- };
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
+ }]);
6862
7450
 
6863
7451
  return ContextRegisterPlugin;
6864
7452
  }();
6865
7453
 
6866
7454
  var Renderer = /*#__PURE__*/function (_AbstractRenderer) {
6867
- _inheritsLoose(Renderer, _AbstractRenderer);
7455
+ _inherits(Renderer, _AbstractRenderer);
7456
+
7457
+ var _super = _createSuper(Renderer);
6868
7458
 
6869
7459
  function Renderer(config) {
6870
7460
  var _this;
6871
7461
 
6872
- _this = _AbstractRenderer.call(this, config) || this; // register Canvas2DContext
7462
+ _classCallCheck(this, Renderer);
7463
+
7464
+ _this = _super.call(this, config); // register Canvas2DContext
6873
7465
 
6874
7466
  _this.registerPlugin(new ContextRegisterPlugin()); // enable rendering with Canvas2D API
6875
7467
 
@@ -6887,7 +7479,7 @@
6887
7479
  return _this;
6888
7480
  }
6889
7481
 
6890
- return Renderer;
7482
+ return _createClass(Renderer);
6891
7483
  }(g.AbstractRenderer);
6892
7484
 
6893
7485
  exports.CanvasPicker = index_esm$2;