@antv/g-canvas 1.2.1 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.umd.js CHANGED
@@ -1,7 +1,7 @@
1
1
  (function (global, factory) {
2
2
  typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@antv/g')) :
3
3
  typeof define === 'function' && define.amd ? define(['exports', '@antv/g'], factory) :
4
- (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory((global.G = global.G || {}, global.G.Canvas2D = {}), global.window.G));
4
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory((global.G = global.G || {}, global.G.ImageExporter = {}), global.window.G));
5
5
  }(this, (function (exports, g) { 'use strict';
6
6
 
7
7
  function _regeneratorRuntime() {
@@ -349,16 +349,6 @@
349
349
  }, exports;
350
350
  }
351
351
 
352
- function _typeof(obj) {
353
- "@babel/helpers - typeof";
354
-
355
- return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) {
356
- return typeof obj;
357
- } : function (obj) {
358
- return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
359
- }, _typeof(obj);
360
- }
361
-
362
352
  function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
363
353
  try {
364
354
  var info = gen[key](arg);
@@ -395,54 +385,11 @@
395
385
  };
396
386
  }
397
387
 
398
- function _classCallCheck(instance, Constructor) {
399
- if (!(instance instanceof Constructor)) {
400
- throw new TypeError("Cannot call a class as a function");
401
- }
402
- }
403
-
404
- function _defineProperties(target, props) {
405
- for (var i = 0; i < props.length; i++) {
406
- var descriptor = props[i];
407
- descriptor.enumerable = descriptor.enumerable || false;
408
- descriptor.configurable = true;
409
- if ("value" in descriptor) descriptor.writable = true;
410
- Object.defineProperty(target, descriptor.key, descriptor);
411
- }
412
- }
413
-
414
- function _createClass(Constructor, protoProps, staticProps) {
415
- if (protoProps) _defineProperties(Constructor.prototype, protoProps);
416
- if (staticProps) _defineProperties(Constructor, staticProps);
417
- Object.defineProperty(Constructor, "prototype", {
418
- writable: false
419
- });
420
- return Constructor;
421
- }
422
-
423
- function _inherits(subClass, superClass) {
424
- if (typeof superClass !== "function" && superClass !== null) {
425
- throw new TypeError("Super expression must either be null or a function");
426
- }
427
-
428
- subClass.prototype = Object.create(superClass && superClass.prototype, {
429
- constructor: {
430
- value: subClass,
431
- writable: true,
432
- configurable: true
433
- }
434
- });
435
- Object.defineProperty(subClass, "prototype", {
436
- writable: false
437
- });
438
- if (superClass) _setPrototypeOf(subClass, superClass);
439
- }
388
+ function _inheritsLoose(subClass, superClass) {
389
+ subClass.prototype = Object.create(superClass.prototype);
390
+ subClass.prototype.constructor = subClass;
440
391
 
441
- function _getPrototypeOf(o) {
442
- _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) {
443
- return o.__proto__ || Object.getPrototypeOf(o);
444
- };
445
- return _getPrototypeOf(o);
392
+ _setPrototypeOf(subClass, superClass);
446
393
  }
447
394
 
448
395
  function _setPrototypeOf(o, p) {
@@ -453,158 +400,6 @@
453
400
  return _setPrototypeOf(o, p);
454
401
  }
455
402
 
456
- function _isNativeReflectConstruct() {
457
- if (typeof Reflect === "undefined" || !Reflect.construct) return false;
458
- if (Reflect.construct.sham) return false;
459
- if (typeof Proxy === "function") return true;
460
-
461
- try {
462
- Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {}));
463
- return true;
464
- } catch (e) {
465
- return false;
466
- }
467
- }
468
-
469
- function _assertThisInitialized(self) {
470
- if (self === void 0) {
471
- throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
472
- }
473
-
474
- return self;
475
- }
476
-
477
- function _possibleConstructorReturn(self, call) {
478
- if (call && (typeof call === "object" || typeof call === "function")) {
479
- return call;
480
- } else if (call !== void 0) {
481
- throw new TypeError("Derived constructors may only return object or undefined");
482
- }
483
-
484
- return _assertThisInitialized(self);
485
- }
486
-
487
- function _createSuper(Derived) {
488
- var hasNativeReflectConstruct = _isNativeReflectConstruct();
489
-
490
- return function _createSuperInternal() {
491
- var Super = _getPrototypeOf(Derived),
492
- result;
493
-
494
- if (hasNativeReflectConstruct) {
495
- var NewTarget = _getPrototypeOf(this).constructor;
496
-
497
- result = Reflect.construct(Super, arguments, NewTarget);
498
- } else {
499
- result = Super.apply(this, arguments);
500
- }
501
-
502
- return _possibleConstructorReturn(this, result);
503
- };
504
- }
505
-
506
- function _classCallCheck$1(instance, Constructor) {
507
- if (!(instance instanceof Constructor)) {
508
- throw new TypeError("Cannot call a class as a function");
509
- }
510
- }
511
-
512
- function _defineProperties$1(target, props) {
513
- for (var i = 0; i < props.length; i++) {
514
- var descriptor = props[i];
515
- descriptor.enumerable = descriptor.enumerable || false;
516
- descriptor.configurable = true;
517
- if ("value" in descriptor) descriptor.writable = true;
518
- Object.defineProperty(target, descriptor.key, descriptor);
519
- }
520
- }
521
-
522
- function _createClass$1(Constructor, protoProps, staticProps) {
523
- if (protoProps) _defineProperties$1(Constructor.prototype, protoProps);
524
- if (staticProps) _defineProperties$1(Constructor, staticProps);
525
- Object.defineProperty(Constructor, "prototype", {
526
- writable: false
527
- });
528
- return Constructor;
529
- }
530
-
531
- function _slicedToArray(arr, i) {
532
- return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest();
533
- }
534
-
535
- function _toConsumableArray(arr) {
536
- return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread();
537
- }
538
-
539
- function _arrayWithoutHoles(arr) {
540
- if (Array.isArray(arr)) return _arrayLikeToArray(arr);
541
- }
542
-
543
- function _arrayWithHoles(arr) {
544
- if (Array.isArray(arr)) return arr;
545
- }
546
-
547
- function _iterableToArray(iter) {
548
- if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
549
- }
550
-
551
- function _iterableToArrayLimit(arr, i) {
552
- var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
553
-
554
- if (_i == null) return;
555
- var _arr = [];
556
- var _n = true;
557
- var _d = false;
558
-
559
- var _s, _e;
560
-
561
- try {
562
- for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) {
563
- _arr.push(_s.value);
564
-
565
- if (i && _arr.length === i) break;
566
- }
567
- } catch (err) {
568
- _d = true;
569
- _e = err;
570
- } finally {
571
- try {
572
- if (!_n && _i["return"] != null) _i["return"]();
573
- } finally {
574
- if (_d) throw _e;
575
- }
576
- }
577
-
578
- return _arr;
579
- }
580
-
581
- function _unsupportedIterableToArray(o, minLen) {
582
- if (!o) return;
583
- if (typeof o === "string") return _arrayLikeToArray(o, minLen);
584
- var n = Object.prototype.toString.call(o).slice(8, -1);
585
- if (n === "Object" && o.constructor) n = o.constructor.name;
586
- if (n === "Map" || n === "Set") return Array.from(o);
587
- if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
588
- }
589
-
590
- function _arrayLikeToArray(arr, len) {
591
- if (len == null || len > arr.length) len = arr.length;
592
-
593
- for (var i = 0, arr2 = new Array(len); i < len; i++) {
594
- arr2[i] = arr[i];
595
- }
596
-
597
- return arr2;
598
- }
599
-
600
- function _nonIterableSpread() {
601
- throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
602
- }
603
-
604
- function _nonIterableRest() {
605
- throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
606
- }
607
-
608
403
  var PathGeneratorFactory = g.Syringe.defineToken('PathGeneratorFactory');
609
404
  var PathGenerator = g.Syringe.defineToken('PathGenerator');
610
405
 
@@ -647,32 +442,31 @@
647
442
 
648
443
  function generatePath$3(context, parsedStyle) {
649
444
  var _parsedStyle$defX = parsedStyle.defX,
650
- x = _parsedStyle$defX === void 0 ? 0 : _parsedStyle$defX,
445
+ defX = _parsedStyle$defX === void 0 ? 0 : _parsedStyle$defX,
651
446
  _parsedStyle$defY = parsedStyle.defY,
652
- y = _parsedStyle$defY === void 0 ? 0 : _parsedStyle$defY;
447
+ defY = _parsedStyle$defY === void 0 ? 0 : _parsedStyle$defY;
653
448
  var _parsedStyle$path = parsedStyle.path,
654
449
  curve = _parsedStyle$path.curve,
655
450
  zCommandIndexes = _parsedStyle$path.zCommandIndexes;
656
-
657
- var path = _toConsumableArray(curve);
658
-
451
+ var path = [].concat(curve);
659
452
  zCommandIndexes.forEach(function (zIndex, index) {
453
+ // @ts-ignore
660
454
  path.splice(zIndex + index, 1, ['Z']);
661
455
  });
662
456
 
663
457
  for (var i = 0; i < path.length; i++) {
664
- var params = path[i]; // eg. M 100 200
665
-
666
- var command = params[0]; // V,H,S,T 都在前面被转换成标准形式
458
+ var params = path[i];
459
+ var command = params[0];
667
460
 
668
461
  switch (command) {
669
462
  case 'M':
670
- context.moveTo(params[1] - x, params[2] - y);
463
+ context.moveTo(params[1] - defX, params[2] - defY);
671
464
  break;
672
465
 
673
466
  case 'C':
674
- context.bezierCurveTo(params[1] - x, params[2] - y, params[3] - x, params[4] - y, params[5] - x, params[6] - y);
467
+ context.bezierCurveTo(params[1] - defX, params[2] - defY, params[3] - defX, params[4] - defY, params[5] - defX, params[6] - defY);
675
468
  break;
469
+ // @ts-ignore
676
470
 
677
471
  case 'Z':
678
472
  context.closePath();
@@ -683,20 +477,20 @@
683
477
 
684
478
  function generatePath$4(context, parsedStyle) {
685
479
  var _parsedStyle$defX = parsedStyle.defX,
686
- x = _parsedStyle$defX === void 0 ? 0 : _parsedStyle$defX,
480
+ defX = _parsedStyle$defX === void 0 ? 0 : _parsedStyle$defX,
687
481
  _parsedStyle$defY = parsedStyle.defY,
688
- y = _parsedStyle$defY === void 0 ? 0 : _parsedStyle$defY;
482
+ defY = _parsedStyle$defY === void 0 ? 0 : _parsedStyle$defY;
689
483
  var points = parsedStyle.points.points;
690
484
  var length = points.length;
691
- var x1 = points[0][0] - x;
692
- var y1 = points[0][1] - y;
693
- var x2 = points[length - 1][0] - x;
694
- var y2 = points[length - 1][1] - y;
485
+ var x1 = points[0][0] - defX;
486
+ var y1 = points[0][1] - defY;
487
+ var x2 = points[length - 1][0] - defX;
488
+ var y2 = points[length - 1][1] - defY;
695
489
  context.moveTo(x1, y1);
696
490
 
697
491
  for (var i = 0; i < length - 1; i++) {
698
492
  var point = points[i];
699
- context.lineTo(point[0] - x, point[1] - y);
493
+ context.lineTo(point[0] - defX, point[1] - defY);
700
494
  }
701
495
 
702
496
  context.lineTo(x2, y2);
@@ -704,20 +498,20 @@
704
498
 
705
499
  function generatePath$5(context, parsedStyle) {
706
500
  var _parsedStyle$defX = parsedStyle.defX,
707
- x = _parsedStyle$defX === void 0 ? 0 : _parsedStyle$defX,
501
+ defX = _parsedStyle$defX === void 0 ? 0 : _parsedStyle$defX,
708
502
  _parsedStyle$defY = parsedStyle.defY,
709
- y = _parsedStyle$defY === void 0 ? 0 : _parsedStyle$defY;
503
+ defY = _parsedStyle$defY === void 0 ? 0 : _parsedStyle$defY;
710
504
  var points = parsedStyle.points.points;
711
505
  var length = points.length;
712
- var x1 = points[0][0] - x;
713
- var y1 = points[0][1] - y;
714
- var x2 = points[length - 1][0] - x;
715
- var y2 = points[length - 1][1] - y;
506
+ var x1 = points[0][0] - defX;
507
+ var y1 = points[0][1] - defY;
508
+ var x2 = points[length - 1][0] - defX;
509
+ var y2 = points[length - 1][1] - defY;
716
510
  context.moveTo(x1, y1);
717
511
 
718
512
  for (var i = 0; i < length - 1; i++) {
719
513
  var point = points[i];
720
- context.lineTo(point[0] - x, point[1] - y);
514
+ context.lineTo(point[0] - defX, point[1] - defY);
721
515
  }
722
516
 
723
517
  context.lineTo(x2, y2);
@@ -744,11 +538,10 @@
744
538
  var _radius$map = radius.map(function (r) {
745
539
  return g.clamp(r.value, 0, Math.min(Math.abs(w) / 2, Math.abs(h) / 2));
746
540
  }),
747
- _radius$map2 = _slicedToArray(_radius$map, 4),
748
- tlr = _radius$map2[0],
749
- trr = _radius$map2[1],
750
- brr = _radius$map2[2],
751
- blr = _radius$map2[3];
541
+ tlr = _radius$map[0],
542
+ trr = _radius$map[1],
543
+ brr = _radius$map[2],
544
+ blr = _radius$map[3];
752
545
 
753
546
  context.moveTo(signX * tlr, 0);
754
547
  context.lineTo(w - signX * trr, 0);
@@ -846,22 +639,18 @@
846
639
 
847
640
  var Plugin = /*#__PURE__*/function () {
848
641
  function Plugin() {
849
- _classCallCheck$1(this, Plugin);
850
-
851
642
  this.name = 'canvas-path-generator';
852
643
  }
853
644
 
854
- _createClass$1(Plugin, [{
855
- key: "init",
856
- value: function init(container) {
857
- container.load(containerModule, true);
858
- }
859
- }, {
860
- key: "destroy",
861
- value: function destroy(container) {
862
- container.unload(containerModule);
863
- }
864
- }]);
645
+ var _proto = Plugin.prototype;
646
+
647
+ _proto.init = function init(container) {
648
+ container.load(containerModule, true);
649
+ };
650
+
651
+ _proto.destroy = function destroy(container) {
652
+ container.unload(containerModule);
653
+ };
865
654
 
866
655
  return Plugin;
867
656
  }();
@@ -1024,7 +813,7 @@
1024
813
  if ("throw" !== record.type) {
1025
814
  var result = record.arg,
1026
815
  value = result.value;
1027
- return value && "object" == _typeof(value) && hasOwn.call(value, "__await") ? PromiseImpl.resolve(value.__await).then(function (value) {
816
+ return value && "object" == typeof value && hasOwn.call(value, "__await") ? PromiseImpl.resolve(value.__await).then(function (value) {
1028
817
  invoke("next", value, resolve, reject);
1029
818
  }, function (err) {
1030
819
  invoke("throw", err, resolve, reject);
@@ -1284,92 +1073,6 @@
1284
1073
  });
1285
1074
  };
1286
1075
  }
1287
-
1288
- function _classCallCheck$2(instance, Constructor) {
1289
- if (!(instance instanceof Constructor)) {
1290
- throw new TypeError("Cannot call a class as a function");
1291
- }
1292
- }
1293
-
1294
- function _defineProperties$2(target, props) {
1295
- for (var i = 0; i < props.length; i++) {
1296
- var descriptor = props[i];
1297
- descriptor.enumerable = descriptor.enumerable || false;
1298
- descriptor.configurable = true;
1299
- if ("value" in descriptor) descriptor.writable = true;
1300
- Object.defineProperty(target, descriptor.key, descriptor);
1301
- }
1302
- }
1303
-
1304
- function _createClass$2(Constructor, protoProps, staticProps) {
1305
- if (protoProps) _defineProperties$2(Constructor.prototype, protoProps);
1306
- if (staticProps) _defineProperties$2(Constructor, staticProps);
1307
- Object.defineProperty(Constructor, "prototype", {
1308
- writable: false
1309
- });
1310
- return Constructor;
1311
- }
1312
-
1313
- function _slicedToArray$1(arr, i) {
1314
- return _arrayWithHoles$1(arr) || _iterableToArrayLimit$1(arr, i) || _unsupportedIterableToArray$1(arr, i) || _nonIterableRest$1();
1315
- }
1316
-
1317
- function _arrayWithHoles$1(arr) {
1318
- if (Array.isArray(arr)) return arr;
1319
- }
1320
-
1321
- function _iterableToArrayLimit$1(arr, i) {
1322
- var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
1323
-
1324
- if (_i == null) return;
1325
- var _arr = [];
1326
- var _n = true;
1327
- var _d = false;
1328
-
1329
- var _s, _e;
1330
-
1331
- try {
1332
- for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) {
1333
- _arr.push(_s.value);
1334
-
1335
- if (i && _arr.length === i) break;
1336
- }
1337
- } catch (err) {
1338
- _d = true;
1339
- _e = err;
1340
- } finally {
1341
- try {
1342
- if (!_n && _i["return"] != null) _i["return"]();
1343
- } finally {
1344
- if (_d) throw _e;
1345
- }
1346
- }
1347
-
1348
- return _arr;
1349
- }
1350
-
1351
- function _unsupportedIterableToArray$1(o, minLen) {
1352
- if (!o) return;
1353
- if (typeof o === "string") return _arrayLikeToArray$1(o, minLen);
1354
- var n = Object.prototype.toString.call(o).slice(8, -1);
1355
- if (n === "Object" && o.constructor) n = o.constructor.name;
1356
- if (n === "Map" || n === "Set") return Array.from(o);
1357
- if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray$1(o, minLen);
1358
- }
1359
-
1360
- function _arrayLikeToArray$1(arr, len) {
1361
- if (len == null || len > arr.length) len = arr.length;
1362
-
1363
- for (var i = 0, arr2 = new Array(len); i < len; i++) {
1364
- arr2[i] = arr[i];
1365
- }
1366
-
1367
- return arr2;
1368
- }
1369
-
1370
- function _nonIterableRest$1() {
1371
- throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
1372
- }
1373
1076
  /**
1374
1077
  * Common utilities
1375
1078
  * @module glMatrix
@@ -1964,8 +1667,6 @@
1964
1667
  function CanvasPickerPlugin() {
1965
1668
  var _this = this;
1966
1669
 
1967
- _classCallCheck$2(this, CanvasPickerPlugin);
1968
-
1969
1670
  this.displayObjectPool = void 0;
1970
1671
  this.canvasConfig = void 0;
1971
1672
  this.offscreenCanvas = void 0;
@@ -2016,109 +1717,108 @@
2016
1717
  };
2017
1718
  }
2018
1719
 
2019
- _createClass$2(CanvasPickerPlugin, [{
2020
- key: "apply",
2021
- value: function apply(renderingService) {
2022
- var _this2 = this;
2023
-
2024
- renderingService.hooks.pick.tapPromise(CanvasPickerPlugin_1.tag, /*#__PURE__*/function () {
2025
- var _ref = _asyncToGenerator$1( /*#__PURE__*/_regeneratorRuntime$1().mark(function _callee(result) {
2026
- var topmost, _result$position, x, y, position, rBushNodes, queriedIds, hitTestList, pickedDisplayObjects, _i, _hitTestList, displayObject, clipPath, objectToTest, worldTransform;
2027
-
2028
- return _regeneratorRuntime$1().wrap(function _callee$(_context) {
2029
- while (1) {
2030
- switch (_context.prev = _context.next) {
2031
- case 0:
2032
- topmost = result.topmost, _result$position = result.position, x = _result$position.x, y = _result$position.y; // position in world space
2033
-
2034
- position = fromValues(x, y, 0); // query by AABB first with spatial index(r-tree)
2035
-
2036
- rBushNodes = _this2.rBush.search({
2037
- minX: position[0],
2038
- minY: position[1],
2039
- maxX: position[0],
2040
- maxY: position[1]
2041
- });
2042
- queriedIds = rBushNodes.map(function (node) {
2043
- return node.id;
2044
- });
2045
- hitTestList = [];
2046
- rBushNodes.forEach(function (_ref2) {
2047
- var id = _ref2.id;
2048
-
2049
- var displayObject = _this2.displayObjectPool.getByEntity(id);
2050
-
2051
- if (displayObject.isVisible() && !displayObject.isCulled() && displayObject.isInteractive()) {
2052
- // parent is not included, eg. parent is clipped
2053
- if (displayObject.parentNode && queriedIds.indexOf(displayObject.parentNode.entity) === -1) {
2054
- return;
2055
- }
2056
-
2057
- hitTestList.push(displayObject);
2058
- }
2059
- }); // find group with max z-index
2060
-
2061
- hitTestList.sort(function (a, b) {
2062
- return b.sortable.renderOrder - a.sortable.renderOrder;
2063
- });
2064
- pickedDisplayObjects = [];
2065
- _i = 0, _hitTestList = hitTestList;
2066
-
2067
- case 9:
2068
- if (!(_i < _hitTestList.length)) {
2069
- _context.next = 25;
2070
- break;
2071
- }
1720
+ var _proto = CanvasPickerPlugin.prototype;
2072
1721
 
2073
- displayObject = _hitTestList[_i]; // test with clip path
1722
+ _proto.apply = function apply(renderingService) {
1723
+ var _this2 = this;
2074
1724
 
2075
- clipPath = displayObject.parsedStyle.clipPath;
2076
- objectToTest = clipPath || displayObject;
2077
- worldTransform = displayObject.getWorldTransform(); // clipped's world matrix * clipPath's local matrix
1725
+ renderingService.hooks.pick.tapPromise(CanvasPickerPlugin_1.tag, /*#__PURE__*/function () {
1726
+ var _ref = _asyncToGenerator$1( /*#__PURE__*/_regeneratorRuntime$1().mark(function _callee(result) {
1727
+ var topmost, _result$position, x, y, position, rBushNodes, queriedIds, hitTestList, pickedDisplayObjects, _i, _hitTestList, displayObject, clipPath, objectToTest, worldTransform;
2078
1728
 
2079
- if (clipPath) {
2080
- worldTransform = multiply$1(create$1(), worldTransform, clipPath.getLocalTransform());
2081
- }
1729
+ return _regeneratorRuntime$1().wrap(function _callee$(_context) {
1730
+ while (1) {
1731
+ switch (_context.prev = _context.next) {
1732
+ case 0:
1733
+ topmost = result.topmost, _result$position = result.position, x = _result$position.x, y = _result$position.y; // position in world space
2082
1734
 
2083
- if (!_this2.isHit(objectToTest, position, worldTransform)) {
2084
- _context.next = 22;
2085
- break;
2086
- }
1735
+ position = fromValues(x, y, 0); // query by AABB first with spatial index(r-tree)
1736
+
1737
+ rBushNodes = _this2.rBush.search({
1738
+ minX: position[0],
1739
+ minY: position[1],
1740
+ maxX: position[0],
1741
+ maxY: position[1]
1742
+ });
1743
+ queriedIds = rBushNodes.map(function (node) {
1744
+ return node.id;
1745
+ });
1746
+ hitTestList = [];
1747
+ rBushNodes.forEach(function (_ref2) {
1748
+ var id = _ref2.id;
1749
+
1750
+ var displayObject = _this2.displayObjectPool.getByEntity(id);
1751
+
1752
+ if (displayObject.isVisible() && !displayObject.isCulled() && displayObject.isInteractive()) {
1753
+ // parent is not included, eg. parent is clipped
1754
+ if (displayObject.parentNode && queriedIds.indexOf(displayObject.parentNode.entity) === -1) {
1755
+ return;
1756
+ }
2087
1757
 
2088
- if (!topmost) {
2089
- _context.next = 21;
2090
- break;
1758
+ hitTestList.push(displayObject);
2091
1759
  }
1760
+ }); // find group with max z-index
1761
+
1762
+ hitTestList.sort(function (a, b) {
1763
+ return b.sortable.renderOrder - a.sortable.renderOrder;
1764
+ });
1765
+ pickedDisplayObjects = [];
1766
+ _i = 0, _hitTestList = hitTestList;
1767
+
1768
+ case 9:
1769
+ if (!(_i < _hitTestList.length)) {
1770
+ _context.next = 25;
1771
+ break;
1772
+ }
1773
+
1774
+ displayObject = _hitTestList[_i]; // test with clip path
1775
+
1776
+ clipPath = displayObject.parsedStyle.clipPath;
1777
+ objectToTest = clipPath || displayObject;
1778
+ worldTransform = displayObject.getWorldTransform(); // clipped's world matrix * clipPath's local matrix
2092
1779
 
2093
- result.picked = [displayObject];
2094
- return _context.abrupt("return", result);
1780
+ if (clipPath) {
1781
+ worldTransform = multiply$1(create$1(), worldTransform, clipPath.getLocalTransform());
1782
+ }
2095
1783
 
2096
- case 21:
2097
- pickedDisplayObjects.push(displayObject);
1784
+ if (!_this2.isHit(objectToTest, position, worldTransform)) {
1785
+ _context.next = 22;
1786
+ break;
1787
+ }
2098
1788
 
2099
- case 22:
2100
- _i++;
2101
- _context.next = 9;
1789
+ if (!topmost) {
1790
+ _context.next = 21;
2102
1791
  break;
1792
+ }
2103
1793
 
2104
- case 25:
2105
- result.picked = pickedDisplayObjects;
2106
- return _context.abrupt("return", result);
1794
+ result.picked = [displayObject];
1795
+ return _context.abrupt("return", result);
2107
1796
 
2108
- case 27:
2109
- case "end":
2110
- return _context.stop();
2111
- }
1797
+ case 21:
1798
+ pickedDisplayObjects.push(displayObject);
1799
+
1800
+ case 22:
1801
+ _i++;
1802
+ _context.next = 9;
1803
+ break;
1804
+
1805
+ case 25:
1806
+ result.picked = pickedDisplayObjects;
1807
+ return _context.abrupt("return", result);
1808
+
1809
+ case 27:
1810
+ case "end":
1811
+ return _context.stop();
2112
1812
  }
2113
- }, _callee);
2114
- }));
1813
+ }
1814
+ }, _callee);
1815
+ }));
2115
1816
 
2116
- return function (_x) {
2117
- return _ref.apply(this, arguments);
2118
- };
2119
- }());
2120
- }
2121
- }]);
1817
+ return function (_x) {
1818
+ return _ref.apply(this, arguments);
1819
+ };
1820
+ }());
1821
+ };
2122
1822
 
2123
1823
  return CanvasPickerPlugin;
2124
1824
  }(), _class.tag = 'CanvasPicker', _class);
@@ -2138,41 +1838,6 @@
2138
1838
  CanvasPickerPlugin = CanvasPickerPlugin_1 = __decorate([g.singleton({
2139
1839
  contrib: g.RenderingPluginContribution
2140
1840
  })], CanvasPickerPlugin);
2141
-
2142
- function _toConsumableArray$1(arr) {
2143
- return _arrayWithoutHoles$1(arr) || _iterableToArray$1(arr) || _unsupportedIterableToArray$1$1(arr) || _nonIterableSpread$1();
2144
- }
2145
-
2146
- function _arrayWithoutHoles$1(arr) {
2147
- if (Array.isArray(arr)) return _arrayLikeToArray$1$1(arr);
2148
- }
2149
-
2150
- function _iterableToArray$1(iter) {
2151
- if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
2152
- }
2153
-
2154
- function _unsupportedIterableToArray$1$1(o, minLen) {
2155
- if (!o) return;
2156
- if (typeof o === "string") return _arrayLikeToArray$1$1(o, minLen);
2157
- var n = Object.prototype.toString.call(o).slice(8, -1);
2158
- if (n === "Object" && o.constructor) n = o.constructor.name;
2159
- if (n === "Map" || n === "Set") return Array.from(o);
2160
- if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray$1$1(o, minLen);
2161
- }
2162
-
2163
- function _arrayLikeToArray$1$1(arr, len) {
2164
- if (len == null || len > arr.length) len = arr.length;
2165
-
2166
- for (var i = 0, arr2 = new Array(len); i < len; i++) {
2167
- arr2[i] = arr[i];
2168
- }
2169
-
2170
- return arr2;
2171
- }
2172
-
2173
- function _nonIterableSpread$1() {
2174
- throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
2175
- }
2176
1841
  /**
2177
1842
  * 两点之间的距离
2178
1843
  * @param {number} x1 起始点 x
@@ -2182,7 +1847,6 @@
2182
1847
  * @return {number} 距离
2183
1848
  */
2184
1849
 
2185
-
2186
1850
  function distance(x1, y1, x2, y2) {
2187
1851
  var dx = x1 - x2;
2188
1852
  var dy = y1 - y2;
@@ -2194,10 +1858,10 @@
2194
1858
  }
2195
1859
 
2196
1860
  function getBBoxByArray(xArr, yArr) {
2197
- var minX = Math.min.apply(Math, _toConsumableArray$1(xArr));
2198
- var minY = Math.min.apply(Math, _toConsumableArray$1(yArr));
2199
- var maxX = Math.max.apply(Math, _toConsumableArray$1(xArr));
2200
- var maxY = Math.max.apply(Math, _toConsumableArray$1(yArr));
1861
+ var minX = Math.min.apply(Math, xArr);
1862
+ var minY = Math.min.apply(Math, yArr);
1863
+ var maxX = Math.max.apply(Math, xArr);
1864
+ var maxY = Math.max.apply(Math, yArr);
2201
1865
  return {
2202
1866
  x: minX,
2203
1867
  y: minY,
@@ -2340,7 +2004,7 @@
2340
2004
  for (var i = 0; i <= segNum; i++) {
2341
2005
  var _t = i * increaseRate;
2342
2006
 
2343
- var v1 = [tCallback.apply(void 0, _toConsumableArray$1(xArr.concat([_t]))), tCallback.apply(void 0, _toConsumableArray$1(yArr.concat([_t])))];
2007
+ var v1 = [tCallback.apply(void 0, xArr.concat([_t])), tCallback.apply(void 0, yArr.concat([_t]))];
2344
2008
  var d1 = distance(v0[0], v0[1], v1[0], v1[1]);
2345
2009
 
2346
2010
  if (d1 < d) {
@@ -2374,7 +2038,7 @@
2374
2038
 
2375
2039
  var prev = t - interval;
2376
2040
  var next = t + interval;
2377
- var _v = [tCallback.apply(void 0, _toConsumableArray$1(xArr.concat([prev]))), tCallback.apply(void 0, _toConsumableArray$1(yArr.concat([prev])))];
2041
+ var _v = [tCallback.apply(void 0, xArr.concat([prev])), tCallback.apply(void 0, yArr.concat([prev]))];
2378
2042
 
2379
2043
  var _d = distance(v0[0], v0[1], _v[0], _v[1]);
2380
2044
 
@@ -2382,7 +2046,7 @@
2382
2046
  t = prev;
2383
2047
  d = _d;
2384
2048
  } else {
2385
- var v2 = [tCallback.apply(void 0, _toConsumableArray$1(xArr.concat([next]))), tCallback.apply(void 0, _toConsumableArray$1(yArr.concat([next])))];
2049
+ var v2 = [tCallback.apply(void 0, xArr.concat([next])), tCallback.apply(void 0, yArr.concat([next]))];
2386
2050
  var d2 = distance(v0[0], v0[1], v2[0], v2[1]);
2387
2051
 
2388
2052
  if (next <= 1 && d2 < d) {
@@ -2395,8 +2059,8 @@
2395
2059
  }
2396
2060
 
2397
2061
  return {
2398
- x: tCallback.apply(void 0, _toConsumableArray$1(xArr.concat([t]))),
2399
- y: tCallback.apply(void 0, _toConsumableArray$1(yArr.concat([t])))
2062
+ x: tCallback.apply(void 0, xArr.concat([t])),
2063
+ y: tCallback.apply(void 0, yArr.concat([t]))
2400
2064
  };
2401
2065
  } // 近似求解 https://community.khronos.org/t/3d-cubic-bezier-segment-length/62363/2
2402
2066
 
@@ -2465,7 +2129,7 @@
2465
2129
  var right = quadratics[1];
2466
2130
  left.push(iterationCount - 1);
2467
2131
  right.push(iterationCount - 1);
2468
- return quadraticLength.apply(void 0, _toConsumableArray$1(left)) + quadraticLength.apply(void 0, _toConsumableArray$1(right));
2132
+ return quadraticLength.apply(void 0, left) + quadraticLength.apply(void 0, right);
2469
2133
  }
2470
2134
 
2471
2135
  var quadratic = {
@@ -2586,9 +2250,9 @@
2586
2250
  }
2587
2251
 
2588
2252
  var cubics = divideCubic(x1, y1, x2, y2, x3, y3, x4, y4, 0.5);
2589
- var left = [].concat(_toConsumableArray$1(cubics[0]), [iterationCount - 1]);
2590
- var right = [].concat(_toConsumableArray$1(cubics[1]), [iterationCount - 1]);
2591
- return cubicLength.apply(void 0, _toConsumableArray$1(left)) + cubicLength.apply(void 0, _toConsumableArray$1(right));
2253
+ var left = [].concat(cubics[0], [iterationCount - 1]);
2254
+ var right = [].concat(cubics[1], [iterationCount - 1]);
2255
+ return cubicLength.apply(void 0, left) + cubicLength.apply(void 0, right);
2592
2256
  }
2593
2257
 
2594
2258
  var cubic = {
@@ -3096,12 +2760,10 @@
3096
2760
  }
3097
2761
 
3098
2762
  function inRectWithRadius(minX, minY, width, height, radiusArray, lineWidth, x, y) {
3099
- var _radiusArray = _slicedToArray$1(radiusArray, 4),
3100
- tlr = _radiusArray[0],
3101
- trr = _radiusArray[1],
3102
- brr = _radiusArray[2],
3103
- blr = _radiusArray[3];
3104
-
2763
+ var tlr = radiusArray[0],
2764
+ trr = radiusArray[1],
2765
+ brr = radiusArray[2],
2766
+ blr = radiusArray[3];
3105
2767
  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);
3106
2768
  }
3107
2769
 
@@ -3140,22 +2802,18 @@
3140
2802
 
3141
2803
  var Plugin$1 = /*#__PURE__*/function () {
3142
2804
  function Plugin() {
3143
- _classCallCheck$2(this, Plugin);
3144
-
3145
2805
  this.name = 'canvas-picker';
3146
2806
  }
3147
2807
 
3148
- _createClass$2(Plugin, [{
3149
- key: "init",
3150
- value: function init(container) {
3151
- container.load(containerModule$1, true);
3152
- }
3153
- }, {
3154
- key: "destroy",
3155
- value: function destroy(container) {
3156
- container.unload(containerModule$1);
3157
- }
3158
- }]);
2808
+ var _proto = Plugin.prototype;
2809
+
2810
+ _proto.init = function init(container) {
2811
+ container.load(containerModule$1, true);
2812
+ };
2813
+
2814
+ _proto.destroy = function destroy(container) {
2815
+ container.unload(containerModule$1);
2816
+ };
3159
2817
 
3160
2818
  return Plugin;
3161
2819
  }();
@@ -3165,58 +2823,221 @@
3165
2823
  Plugin: Plugin$1
3166
2824
  });
3167
2825
 
3168
- function _regeneratorRuntime$2() {
3169
- /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */
3170
- _regeneratorRuntime$2 = function _regeneratorRuntime() {
3171
- return exports;
3172
- };
3173
-
3174
- var exports = {},
3175
- Op = Object.prototype,
3176
- hasOwn = Op.hasOwnProperty,
3177
- $Symbol = "function" == typeof Symbol ? Symbol : {},
3178
- iteratorSymbol = $Symbol.iterator || "@@iterator",
3179
- asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator",
3180
- toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag";
3181
-
3182
- function define(obj, key, value) {
3183
- return Object.defineProperty(obj, key, {
3184
- value: value,
3185
- enumerable: !0,
3186
- configurable: !0,
3187
- writable: !0
3188
- }), obj[key];
3189
- }
3190
-
3191
- try {
3192
- define({}, "");
3193
- } catch (err) {
3194
- define = function define(obj, key, value) {
3195
- return obj[key] = value;
3196
- };
2826
+ var ImagePool = /*#__PURE__*/function () {
2827
+ function ImagePool() {
2828
+ this.imageCache = {};
2829
+ this.gradientCache = {};
2830
+ this.patternCache = {};
2831
+ this.canvasConfig = void 0;
3197
2832
  }
3198
2833
 
3199
- function wrap(innerFn, outerFn, self, tryLocsList) {
3200
- var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator,
3201
- generator = Object.create(protoGenerator.prototype),
3202
- context = new Context(tryLocsList || []);
3203
- return generator._invoke = function (innerFn, self, context) {
3204
- var state = "suspendedStart";
3205
- return function (method, arg) {
3206
- if ("executing" === state) throw new Error("Generator is already running");
2834
+ var _proto = ImagePool.prototype;
3207
2835
 
3208
- if ("completed" === state) {
3209
- if ("throw" === method) throw arg;
3210
- return doneResult();
2836
+ _proto.getImageSync = function getImageSync(src, callback) {
2837
+ if (!this.imageCache[src]) {
2838
+ this.getOrCreateImage(src).then(function () {
2839
+ if (callback) {
2840
+ callback();
3211
2841
  }
2842
+ });
2843
+ }
3212
2844
 
3213
- for (context.method = method, context.arg = arg;;) {
3214
- var delegate = context.delegate;
2845
+ return this.imageCache[src];
2846
+ };
3215
2847
 
3216
- if (delegate) {
3217
- var delegateResult = maybeInvokeDelegate(delegate, context);
2848
+ _proto.getOrCreateImage = function getOrCreateImage(src) {
2849
+ var _this = this;
3218
2850
 
3219
- if (delegateResult) {
2851
+ if (this.imageCache[src]) {
2852
+ return Promise.resolve(this.imageCache[src]);
2853
+ } // @see https://github.com/antvis/g/issues/938
2854
+
2855
+
2856
+ var createImage = this.canvasConfig.createImage;
2857
+ return new Promise(function (resolve, reject) {
2858
+ var image;
2859
+
2860
+ if (createImage) {
2861
+ image = createImage(src);
2862
+ } else if (g.isBrowser) {
2863
+ image = new window.Image();
2864
+ }
2865
+
2866
+ if (image) {
2867
+ image.onload = function () {
2868
+ resolve(image);
2869
+ };
2870
+
2871
+ image.onerror = function (ev) {
2872
+ reject(ev);
2873
+ };
2874
+
2875
+ image.crossOrigin = 'Anonymous';
2876
+ image.src = src;
2877
+ _this.imageCache[src] = image;
2878
+ }
2879
+ });
2880
+ };
2881
+
2882
+ _proto.getOrCreatePatternSync = function getOrCreatePatternSync(pattern, context, callback) {
2883
+ var patternKey = this.generatePatternKey(pattern);
2884
+
2885
+ if (patternKey && this.patternCache[patternKey]) {
2886
+ return this.patternCache[patternKey];
2887
+ }
2888
+
2889
+ var image = pattern.image,
2890
+ repetition = pattern.repetition;
2891
+ var src; // Image URL
2892
+
2893
+ if (g.isString(image)) {
2894
+ src = this.getImageSync(image, callback);
2895
+ } else {
2896
+ src = image;
2897
+ } // @see https://developer.mozilla.org/zh-CN/docs/Web/API/CanvasRenderingContext2D/createPattern
2898
+
2899
+
2900
+ var canvasPattern = src && context.createPattern(src, repetition);
2901
+
2902
+ if (patternKey && canvasPattern) {
2903
+ this.patternCache[patternKey] = canvasPattern;
2904
+ }
2905
+
2906
+ return canvasPattern;
2907
+ };
2908
+
2909
+ _proto.getOrCreateGradient = function getOrCreateGradient(params, context) {
2910
+ var key = this.generateGradientKey(params); // @ts-ignore
2911
+
2912
+ var type = params.type,
2913
+ steps = params.steps,
2914
+ width = params.width,
2915
+ height = params.height,
2916
+ angle = params.angle,
2917
+ cx = params.cx,
2918
+ cy = params.cy;
2919
+
2920
+ if (this.gradientCache[key]) {
2921
+ return this.gradientCache[key];
2922
+ }
2923
+
2924
+ var gradient = null;
2925
+
2926
+ if (type === g.GradientType.LinearGradient) {
2927
+ var _computeLinearGradien = g.computeLinearGradient(width, height, angle),
2928
+ x1 = _computeLinearGradien.x1,
2929
+ y1 = _computeLinearGradien.y1,
2930
+ x2 = _computeLinearGradien.x2,
2931
+ y2 = _computeLinearGradien.y2; // @see https://developer.mozilla.org/zh-CN/docs/Web/API/CanvasRenderingContext2D/createLinearGradient
2932
+
2933
+
2934
+ gradient = context.createLinearGradient(x1, y1, x2, y2);
2935
+ } else if (type === g.GradientType.RadialGradient) {
2936
+ var _computeRadialGradien = g.computeRadialGradient(width, height, cx, cy),
2937
+ x = _computeRadialGradien.x,
2938
+ y = _computeRadialGradien.y,
2939
+ r = _computeRadialGradien.r; // @see https://developer.mozilla.org/zh-CN/docs/Web/API/CanvasRenderingContext2D/createRadialGradient
2940
+
2941
+
2942
+ gradient = context.createRadialGradient(x, y, 0, x, y, r);
2943
+ }
2944
+
2945
+ if (gradient) {
2946
+ steps.forEach(function (_ref) {
2947
+ var _gradient;
2948
+
2949
+ var offset = _ref[0],
2950
+ color = _ref[1];
2951
+ (_gradient = gradient) === null || _gradient === void 0 ? void 0 : _gradient.addColorStop(offset, color);
2952
+ });
2953
+ this.gradientCache[key] = gradient;
2954
+ }
2955
+
2956
+ return this.gradientCache[key];
2957
+ };
2958
+
2959
+ _proto.generateGradientKey = function generateGradientKey(params) {
2960
+ // @ts-ignore
2961
+ var type = params.type,
2962
+ width = params.width,
2963
+ height = params.height,
2964
+ steps = params.steps,
2965
+ angle = params.angle,
2966
+ cx = params.cx,
2967
+ cy = params.cy;
2968
+ return "gradient-" + type + "-" + (angle || 0) + "-" + (cx || 0) + "-" + (cy || 0) + "-" + width + "-" + height + "-" + steps.map(function (step) {
2969
+ return step.join('');
2970
+ }).join('-');
2971
+ };
2972
+
2973
+ _proto.generatePatternKey = function generatePatternKey(pattern) {
2974
+ var image = pattern.image,
2975
+ repetition = pattern.repetition; // only generate cache for Image
2976
+
2977
+ if (g.isString(image)) {
2978
+ return "pattern-" + image + "-" + repetition;
2979
+ }
2980
+ };
2981
+
2982
+ return ImagePool;
2983
+ }();
2984
+
2985
+ __decorate([g.inject(g.CanvasConfig), __metadata("design:type", Object)], ImagePool.prototype, "canvasConfig", void 0);
2986
+
2987
+ ImagePool = __decorate([g.singleton()], ImagePool);
2988
+
2989
+ function _regeneratorRuntime$2() {
2990
+ /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */
2991
+ _regeneratorRuntime$2 = function _regeneratorRuntime() {
2992
+ return exports;
2993
+ };
2994
+
2995
+ var exports = {},
2996
+ Op = Object.prototype,
2997
+ hasOwn = Op.hasOwnProperty,
2998
+ $Symbol = "function" == typeof Symbol ? Symbol : {},
2999
+ iteratorSymbol = $Symbol.iterator || "@@iterator",
3000
+ asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator",
3001
+ toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag";
3002
+
3003
+ function define(obj, key, value) {
3004
+ return Object.defineProperty(obj, key, {
3005
+ value: value,
3006
+ enumerable: !0,
3007
+ configurable: !0,
3008
+ writable: !0
3009
+ }), obj[key];
3010
+ }
3011
+
3012
+ try {
3013
+ define({}, "");
3014
+ } catch (err) {
3015
+ define = function define(obj, key, value) {
3016
+ return obj[key] = value;
3017
+ };
3018
+ }
3019
+
3020
+ function wrap(innerFn, outerFn, self, tryLocsList) {
3021
+ var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator,
3022
+ generator = Object.create(protoGenerator.prototype),
3023
+ context = new Context(tryLocsList || []);
3024
+ return generator._invoke = function (innerFn, self, context) {
3025
+ var state = "suspendedStart";
3026
+ return function (method, arg) {
3027
+ if ("executing" === state) throw new Error("Generator is already running");
3028
+
3029
+ if ("completed" === state) {
3030
+ if ("throw" === method) throw arg;
3031
+ return doneResult();
3032
+ }
3033
+
3034
+ for (context.method = method, context.arg = arg;;) {
3035
+ var delegate = context.delegate;
3036
+
3037
+ if (delegate) {
3038
+ var delegateResult = maybeInvokeDelegate(delegate, context);
3039
+
3040
+ if (delegateResult) {
3220
3041
  if (delegateResult === ContinueSentinel) continue;
3221
3042
  return delegateResult;
3222
3043
  }
@@ -3290,7 +3111,7 @@
3290
3111
  if ("throw" !== record.type) {
3291
3112
  var result = record.arg,
3292
3113
  value = result.value;
3293
- return value && "object" == _typeof(value) && hasOwn.call(value, "__await") ? PromiseImpl.resolve(value.__await).then(function (value) {
3114
+ return value && "object" == typeof value && hasOwn.call(value, "__await") ? PromiseImpl.resolve(value.__await).then(function (value) {
3294
3115
  invoke("next", value, resolve, reject);
3295
3116
  }, function (err) {
3296
3117
  invoke("throw", err, resolve, reject);
@@ -3551,340 +3372,78 @@
3551
3372
  };
3552
3373
  }
3553
3374
 
3554
- function _classCallCheck$3(instance, Constructor) {
3555
- if (!(instance instanceof Constructor)) {
3556
- throw new TypeError("Cannot call a class as a function");
3557
- }
3558
- }
3559
-
3560
- function _defineProperties$3(target, props) {
3561
- for (var i = 0; i < props.length; i++) {
3562
- var descriptor = props[i];
3563
- descriptor.enumerable = descriptor.enumerable || false;
3564
- descriptor.configurable = true;
3565
- if ("value" in descriptor) descriptor.writable = true;
3566
- Object.defineProperty(target, descriptor.key, descriptor);
3567
- }
3568
- }
3569
-
3570
- function _createClass$3(Constructor, protoProps, staticProps) {
3571
- if (protoProps) _defineProperties$3(Constructor.prototype, protoProps);
3572
- if (staticProps) _defineProperties$3(Constructor, staticProps);
3573
- Object.defineProperty(Constructor, "prototype", {
3574
- writable: false
3575
- });
3576
- return Constructor;
3577
- }
3578
-
3579
- function _slicedToArray$2(arr, i) {
3580
- return _arrayWithHoles$2(arr) || _iterableToArrayLimit$2(arr, i) || _unsupportedIterableToArray$2(arr, i) || _nonIterableRest$2();
3581
- }
3582
-
3583
- function _arrayWithHoles$2(arr) {
3584
- if (Array.isArray(arr)) return arr;
3585
- }
3586
-
3587
- function _iterableToArrayLimit$2(arr, i) {
3588
- var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
3589
-
3590
- if (_i == null) return;
3591
- var _arr = [];
3592
- var _n = true;
3593
- var _d = false;
3594
-
3595
- var _s, _e;
3596
-
3597
- try {
3598
- for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) {
3599
- _arr.push(_s.value);
3600
-
3601
- if (i && _arr.length === i) break;
3602
- }
3603
- } catch (err) {
3604
- _d = true;
3605
- _e = err;
3606
- } finally {
3607
- try {
3608
- if (!_n && _i["return"] != null) _i["return"]();
3609
- } finally {
3610
- if (_d) throw _e;
3611
- }
3612
- }
3613
-
3614
- return _arr;
3615
- }
3616
-
3617
- function _unsupportedIterableToArray$2(o, minLen) {
3618
- if (!o) return;
3619
- if (typeof o === "string") return _arrayLikeToArray$2(o, minLen);
3620
- var n = Object.prototype.toString.call(o).slice(8, -1);
3621
- if (n === "Object" && o.constructor) n = o.constructor.name;
3622
- if (n === "Map" || n === "Set") return Array.from(o);
3623
- if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray$2(o, minLen);
3624
- }
3625
-
3626
- function _arrayLikeToArray$2(arr, len) {
3627
- if (len == null || len > arr.length) len = arr.length;
3628
-
3629
- for (var i = 0, arr2 = new Array(len); i < len; i++) {
3630
- arr2[i] = arr[i];
3631
- }
3632
-
3633
- return arr2;
3634
- }
3635
-
3636
- function _nonIterableRest$2() {
3637
- throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
3638
- }
3639
-
3640
- var ImagePool = /*#__PURE__*/function () {
3641
- function ImagePool() {
3642
- _classCallCheck$3(this, ImagePool);
3643
-
3644
- this.imageCache = {};
3645
- this.gradientCache = {};
3646
- this.patternCache = {};
3647
- this.canvasConfig = void 0;
3648
- }
3649
-
3650
- _createClass$3(ImagePool, [{
3651
- key: "getImageSync",
3652
- value: function getImageSync(src, callback) {
3653
- if (!this.imageCache[src]) {
3654
- this.getOrCreateImage(src).then(function () {
3655
- if (callback) {
3656
- callback();
3657
- }
3658
- });
3659
- }
3660
-
3661
- return this.imageCache[src];
3662
- }
3663
- }, {
3664
- key: "getOrCreateImage",
3665
- value: function getOrCreateImage(src) {
3666
- var _this = this;
3667
-
3668
- if (this.imageCache[src]) {
3669
- return Promise.resolve(this.imageCache[src]);
3670
- } // @see https://github.com/antvis/g/issues/938
3671
-
3672
-
3673
- var createImage = this.canvasConfig.createImage;
3674
- return new Promise(function (resolve, reject) {
3675
- var image;
3676
-
3677
- if (createImage) {
3678
- image = createImage(src);
3679
- } else if (g.isBrowser) {
3680
- image = new window.Image();
3681
- }
3682
-
3683
- if (image) {
3684
- image.onload = function () {
3685
- resolve(image);
3686
- };
3687
-
3688
- image.onerror = function (ev) {
3689
- reject(ev);
3690
- };
3691
-
3692
- image.crossOrigin = 'Anonymous';
3693
- image.src = src;
3694
- _this.imageCache[src] = image;
3695
- }
3696
- });
3697
- }
3698
- }, {
3699
- key: "getOrCreatePatternSync",
3700
- value: function getOrCreatePatternSync(pattern, context, callback) {
3701
- var patternKey = this.generatePatternKey(pattern);
3702
-
3703
- if (patternKey && this.patternCache[patternKey]) {
3704
- return this.patternCache[patternKey];
3705
- }
3706
-
3707
- var image = pattern.image,
3708
- repetition = pattern.repetition;
3709
- var src; // Image URL
3710
-
3711
- if (g.isString(image)) {
3712
- src = this.getImageSync(image, callback);
3713
- } else {
3714
- src = image;
3715
- } // @see https://developer.mozilla.org/zh-CN/docs/Web/API/CanvasRenderingContext2D/createPattern
3716
-
3717
-
3718
- var canvasPattern = src && context.createPattern(src, repetition);
3719
-
3720
- if (patternKey && canvasPattern) {
3721
- this.patternCache[patternKey] = canvasPattern;
3722
- }
3723
-
3724
- return canvasPattern;
3725
- }
3726
- }, {
3727
- key: "getOrCreateGradient",
3728
- value: function getOrCreateGradient(params, context) {
3729
- var key = this.generateGradientKey(params); // @ts-ignore
3730
-
3731
- var type = params.type,
3732
- steps = params.steps,
3733
- width = params.width,
3734
- height = params.height,
3735
- angle = params.angle,
3736
- cx = params.cx,
3737
- cy = params.cy;
3738
-
3739
- if (this.gradientCache[key]) {
3740
- return this.gradientCache[key];
3741
- }
3742
-
3743
- var gradient = null;
3744
-
3745
- if (type === g.GradientType.LinearGradient) {
3746
- var _computeLinearGradien = g.computeLinearGradient(width, height, angle),
3747
- x1 = _computeLinearGradien.x1,
3748
- y1 = _computeLinearGradien.y1,
3749
- x2 = _computeLinearGradien.x2,
3750
- y2 = _computeLinearGradien.y2; // @see https://developer.mozilla.org/zh-CN/docs/Web/API/CanvasRenderingContext2D/createLinearGradient
3751
-
3752
-
3753
- gradient = context.createLinearGradient(x1, y1, x2, y2);
3754
- } else if (type === g.GradientType.RadialGradient) {
3755
- var _computeRadialGradien = g.computeRadialGradient(width, height, cx, cy),
3756
- x = _computeRadialGradien.x,
3757
- y = _computeRadialGradien.y,
3758
- r = _computeRadialGradien.r; // @see https://developer.mozilla.org/zh-CN/docs/Web/API/CanvasRenderingContext2D/createRadialGradient
3759
-
3760
-
3761
- gradient = context.createRadialGradient(x, y, 0, x, y, r);
3762
- }
3763
-
3764
- if (gradient) {
3765
- steps.forEach(function (_ref) {
3766
- var _gradient;
3767
-
3768
- var _ref2 = _slicedToArray$2(_ref, 2),
3769
- offset = _ref2[0],
3770
- color = _ref2[1];
3771
-
3772
- (_gradient = gradient) === null || _gradient === void 0 ? void 0 : _gradient.addColorStop(offset, color);
3773
- });
3774
- this.gradientCache[key] = gradient;
3775
- }
3776
-
3777
- return this.gradientCache[key];
3778
- }
3779
- }, {
3780
- key: "generateGradientKey",
3781
- value: function generateGradientKey(params) {
3782
- // @ts-ignore
3783
- var type = params.type,
3784
- width = params.width,
3785
- height = params.height,
3786
- steps = params.steps,
3787
- angle = params.angle,
3788
- cx = params.cx,
3789
- cy = params.cy;
3790
- return "gradient-".concat(type, "-").concat(angle || 0, "-").concat(cx || 0, "-").concat(cy || 0, "-").concat(width, "-").concat(height, "-").concat(steps.map(function (step) {
3791
- return step.join('');
3792
- }).join('-'));
3793
- }
3794
- }, {
3795
- key: "generatePatternKey",
3796
- value: function generatePatternKey(pattern) {
3797
- var image = pattern.image,
3798
- repetition = pattern.repetition; // only generate cache for Image
3799
-
3800
- if (g.isString(image)) {
3801
- return "pattern-".concat(image, "-").concat(repetition);
3802
- }
3803
- }
3804
- }]);
3805
-
3806
- return ImagePool;
3807
- }();
3808
-
3809
- __decorate([g.inject(g.CanvasConfig), __metadata("design:type", Object)], ImagePool.prototype, "canvasConfig", void 0);
3810
-
3811
- ImagePool = __decorate([g.singleton()], ImagePool);
3812
-
3813
3375
  var _class$1;
3814
3376
 
3815
3377
  var LoadImagePlugin_1;
3816
3378
  var LoadImagePlugin = LoadImagePlugin_1 = (_class$1 = /*#__PURE__*/function () {
3817
3379
  function LoadImagePlugin() {
3818
- _classCallCheck$3(this, LoadImagePlugin);
3819
-
3820
3380
  this.imagePool = void 0;
3821
3381
  this.renderingContext = void 0;
3822
3382
  }
3823
3383
 
3824
- _createClass$3(LoadImagePlugin, [{
3825
- key: "apply",
3826
- value: function apply(renderingService) {
3827
- var _this = this;
3384
+ var _proto = LoadImagePlugin.prototype;
3385
+
3386
+ _proto.apply = function apply(renderingService) {
3387
+ var _this = this;
3828
3388
 
3829
- var handleMounted = function handleMounted(e) {
3830
- var object = e.target;
3831
- var nodeName = object.nodeName,
3832
- attributes = object.attributes;
3389
+ var handleMounted = function handleMounted(e) {
3390
+ var object = e.target;
3391
+ var nodeName = object.nodeName,
3392
+ attributes = object.attributes;
3833
3393
 
3834
- if (nodeName === g.Shape.IMAGE) {
3835
- var img = attributes.img;
3394
+ if (nodeName === g.Shape.IMAGE) {
3395
+ var img = attributes.img;
3396
+
3397
+ if (g.isString(img)) {
3398
+ _this.imagePool.getImageSync(img, function () {
3399
+ // set dirty rectangle flag
3400
+ object.renderable.dirty = true;
3401
+ renderingService.dirtify();
3402
+ });
3403
+ }
3404
+ }
3405
+ };
3836
3406
 
3837
- if (g.isString(img)) {
3838
- _this.imagePool.getImageSync(img, function () {
3407
+ var handleAttributeChanged = function handleAttributeChanged(e) {
3408
+ var object = e.target;
3409
+ var attrName = e.attrName,
3410
+ newValue = e.newValue;
3411
+
3412
+ if (object.nodeName === g.Shape.IMAGE) {
3413
+ if (attrName === 'img') {
3414
+ if (g.isString(newValue)) {
3415
+ _this.imagePool.getOrCreateImage(newValue).then(function () {
3839
3416
  // set dirty rectangle flag
3840
3417
  object.renderable.dirty = true;
3841
3418
  renderingService.dirtify();
3842
3419
  });
3843
3420
  }
3844
3421
  }
3845
- };
3846
-
3847
- var handleAttributeChanged = function handleAttributeChanged(e) {
3848
- var object = e.target;
3849
- var attrName = e.attrName,
3850
- newValue = e.newValue;
3851
-
3852
- if (object.nodeName === g.Shape.IMAGE) {
3853
- if (attrName === 'img') {
3854
- if (g.isString(newValue)) {
3855
- _this.imagePool.getOrCreateImage(newValue).then(function () {
3856
- // set dirty rectangle flag
3857
- object.renderable.dirty = true;
3858
- renderingService.dirtify();
3859
- });
3860
- }
3861
- }
3862
- }
3863
- };
3422
+ }
3423
+ };
3864
3424
 
3865
- renderingService.hooks.init.tapPromise(LoadImagePlugin_1.tag, /*#__PURE__*/_asyncToGenerator$2( /*#__PURE__*/_regeneratorRuntime$2().mark(function _callee() {
3866
- return _regeneratorRuntime$2().wrap(function _callee$(_context) {
3867
- while (1) {
3868
- switch (_context.prev = _context.next) {
3869
- case 0:
3870
- _this.renderingContext.root.addEventListener(g.ElementEvent.MOUNTED, handleMounted);
3425
+ renderingService.hooks.init.tapPromise(LoadImagePlugin_1.tag, /*#__PURE__*/_asyncToGenerator$2( /*#__PURE__*/_regeneratorRuntime$2().mark(function _callee() {
3426
+ return _regeneratorRuntime$2().wrap(function _callee$(_context) {
3427
+ while (1) {
3428
+ switch (_context.prev = _context.next) {
3429
+ case 0:
3430
+ _this.renderingContext.root.addEventListener(g.ElementEvent.MOUNTED, handleMounted);
3871
3431
 
3872
- _this.renderingContext.root.addEventListener(g.ElementEvent.ATTR_MODIFIED, handleAttributeChanged);
3432
+ _this.renderingContext.root.addEventListener(g.ElementEvent.ATTR_MODIFIED, handleAttributeChanged);
3873
3433
 
3874
- case 2:
3875
- case "end":
3876
- return _context.stop();
3877
- }
3434
+ case 2:
3435
+ case "end":
3436
+ return _context.stop();
3878
3437
  }
3879
- }, _callee);
3880
- })));
3881
- renderingService.hooks.destroy.tap(LoadImagePlugin_1.tag, function () {
3882
- _this.renderingContext.root.removeEventListener(g.ElementEvent.MOUNTED, handleMounted);
3438
+ }
3439
+ }, _callee);
3440
+ })));
3441
+ renderingService.hooks.destroy.tap(LoadImagePlugin_1.tag, function () {
3442
+ _this.renderingContext.root.removeEventListener(g.ElementEvent.MOUNTED, handleMounted);
3883
3443
 
3884
- _this.renderingContext.root.removeEventListener(g.ElementEvent.ATTR_MODIFIED, handleAttributeChanged);
3885
- });
3886
- }
3887
- }]);
3444
+ _this.renderingContext.root.removeEventListener(g.ElementEvent.ATTR_MODIFIED, handleAttributeChanged);
3445
+ });
3446
+ };
3888
3447
 
3889
3448
  return LoadImagePlugin;
3890
3449
  }(), _class$1.tag = 'LoadImage', _class$1);
@@ -3903,22 +3462,18 @@
3903
3462
 
3904
3463
  var Plugin$2 = /*#__PURE__*/function () {
3905
3464
  function Plugin() {
3906
- _classCallCheck$3(this, Plugin);
3907
-
3908
3465
  this.name = 'image-loader';
3909
3466
  }
3910
3467
 
3911
- _createClass$3(Plugin, [{
3912
- key: "init",
3913
- value: function init(container) {
3914
- container.load(containerModule$2, true);
3915
- }
3916
- }, {
3917
- key: "destroy",
3918
- value: function destroy(container) {
3919
- container.unload(containerModule$2);
3920
- }
3921
- }]);
3468
+ var _proto = Plugin.prototype;
3469
+
3470
+ _proto.init = function init(container) {
3471
+ container.load(containerModule$2, true);
3472
+ };
3473
+
3474
+ _proto.destroy = function destroy(container) {
3475
+ container.unload(containerModule$2);
3476
+ };
3922
3477
 
3923
3478
  return Plugin;
3924
3479
  }();
@@ -3929,32 +3484,6 @@
3929
3484
  Plugin: Plugin$2
3930
3485
  });
3931
3486
 
3932
- function ownKeys(object, enumerableOnly) {
3933
- var keys = Object.keys(object);
3934
-
3935
- if (Object.getOwnPropertySymbols) {
3936
- var symbols = Object.getOwnPropertySymbols(object);
3937
- enumerableOnly && (symbols = symbols.filter(function (sym) {
3938
- return Object.getOwnPropertyDescriptor(object, sym).enumerable;
3939
- })), keys.push.apply(keys, symbols);
3940
- }
3941
-
3942
- return keys;
3943
- }
3944
-
3945
- function _objectSpread2(target) {
3946
- for (var i = 1; i < arguments.length; i++) {
3947
- var source = null != arguments[i] ? arguments[i] : {};
3948
- i % 2 ? ownKeys(Object(source), !0).forEach(function (key) {
3949
- _defineProperty(target, key, source[key]);
3950
- }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) {
3951
- Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
3952
- });
3953
- }
3954
-
3955
- return target;
3956
- }
3957
-
3958
3487
  function _regeneratorRuntime$3() {
3959
3488
  /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */
3960
3489
  _regeneratorRuntime$3 = function _regeneratorRuntime() {
@@ -4080,7 +3609,7 @@
4080
3609
  if ("throw" !== record.type) {
4081
3610
  var result = record.arg,
4082
3611
  value = result.value;
4083
- return value && "object" == _typeof(value) && hasOwn.call(value, "__await") ? PromiseImpl.resolve(value.__await).then(function (value) {
3612
+ return value && "object" == typeof value && hasOwn.call(value, "__await") ? PromiseImpl.resolve(value.__await).then(function (value) {
4084
3613
  invoke("next", value, resolve, reject);
4085
3614
  }, function (err) {
4086
3615
  invoke("throw", err, resolve, reject);
@@ -4311,234 +3840,66 @@
4311
3840
  var value = info.value;
4312
3841
  } catch (error) {
4313
3842
  reject(error);
4314
- return;
4315
- }
4316
-
4317
- if (info.done) {
4318
- resolve(value);
4319
- } else {
4320
- Promise.resolve(value).then(_next, _throw);
4321
- }
4322
- }
4323
-
4324
- function _asyncToGenerator$3(fn) {
4325
- return function () {
4326
- var self = this,
4327
- args = arguments;
4328
- return new Promise(function (resolve, reject) {
4329
- var gen = fn.apply(self, args);
4330
-
4331
- function _next(value) {
4332
- asyncGeneratorStep$3(gen, resolve, reject, _next, _throw, "next", value);
4333
- }
4334
-
4335
- function _throw(err) {
4336
- asyncGeneratorStep$3(gen, resolve, reject, _next, _throw, "throw", err);
4337
- }
4338
-
4339
- _next(undefined);
4340
- });
4341
- };
4342
- }
4343
-
4344
- function _classCallCheck$4(instance, Constructor) {
4345
- if (!(instance instanceof Constructor)) {
4346
- throw new TypeError("Cannot call a class as a function");
4347
- }
4348
- }
4349
-
4350
- function _defineProperties$4(target, props) {
4351
- for (var i = 0; i < props.length; i++) {
4352
- var descriptor = props[i];
4353
- descriptor.enumerable = descriptor.enumerable || false;
4354
- descriptor.configurable = true;
4355
- if ("value" in descriptor) descriptor.writable = true;
4356
- Object.defineProperty(target, descriptor.key, descriptor);
4357
- }
4358
- }
4359
-
4360
- function _createClass$4(Constructor, protoProps, staticProps) {
4361
- if (protoProps) _defineProperties$4(Constructor.prototype, protoProps);
4362
- if (staticProps) _defineProperties$4(Constructor, staticProps);
4363
- Object.defineProperty(Constructor, "prototype", {
4364
- writable: false
4365
- });
4366
- return Constructor;
4367
- }
4368
-
4369
- function _defineProperty(obj, key, value) {
4370
- if (key in obj) {
4371
- Object.defineProperty(obj, key, {
4372
- value: value,
4373
- enumerable: true,
4374
- configurable: true,
4375
- writable: true
4376
- });
4377
- } else {
4378
- obj[key] = value;
4379
- }
4380
-
4381
- return obj;
4382
- }
4383
-
4384
- function _inherits$1(subClass, superClass) {
4385
- if (typeof superClass !== "function" && superClass !== null) {
4386
- throw new TypeError("Super expression must either be null or a function");
4387
- }
4388
-
4389
- subClass.prototype = Object.create(superClass && superClass.prototype, {
4390
- constructor: {
4391
- value: subClass,
4392
- writable: true,
4393
- configurable: true
4394
- }
4395
- });
4396
- Object.defineProperty(subClass, "prototype", {
4397
- writable: false
4398
- });
4399
- if (superClass) _setPrototypeOf$1(subClass, superClass);
4400
- }
4401
-
4402
- function _getPrototypeOf$1(o) {
4403
- _getPrototypeOf$1 = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) {
4404
- return o.__proto__ || Object.getPrototypeOf(o);
4405
- };
4406
- return _getPrototypeOf$1(o);
4407
- }
4408
-
4409
- function _setPrototypeOf$1(o, p) {
4410
- _setPrototypeOf$1 = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) {
4411
- o.__proto__ = p;
4412
- return o;
4413
- };
4414
- return _setPrototypeOf$1(o, p);
4415
- }
4416
-
4417
- function _isNativeReflectConstruct$1() {
4418
- if (typeof Reflect === "undefined" || !Reflect.construct) return false;
4419
- if (Reflect.construct.sham) return false;
4420
- if (typeof Proxy === "function") return true;
4421
-
4422
- try {
4423
- Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {}));
4424
- return true;
4425
- } catch (e) {
4426
- return false;
4427
- }
4428
- }
4429
-
4430
- function _assertThisInitialized$1(self) {
4431
- if (self === void 0) {
4432
- throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
4433
- }
4434
-
4435
- return self;
4436
- }
4437
-
4438
- function _possibleConstructorReturn$1(self, call) {
4439
- if (call && (_typeof(call) === "object" || typeof call === "function")) {
4440
- return call;
4441
- } else if (call !== void 0) {
4442
- throw new TypeError("Derived constructors may only return object or undefined");
3843
+ return;
4443
3844
  }
4444
3845
 
4445
- return _assertThisInitialized$1(self);
3846
+ if (info.done) {
3847
+ resolve(value);
3848
+ } else {
3849
+ Promise.resolve(value).then(_next, _throw);
3850
+ }
4446
3851
  }
4447
3852
 
4448
- function _createSuper$1(Derived) {
4449
- var hasNativeReflectConstruct = _isNativeReflectConstruct$1();
4450
-
4451
- return function _createSuperInternal() {
4452
- var Super = _getPrototypeOf$1(Derived),
4453
- result;
3853
+ function _asyncToGenerator$3(fn) {
3854
+ return function () {
3855
+ var self = this,
3856
+ args = arguments;
3857
+ return new Promise(function (resolve, reject) {
3858
+ var gen = fn.apply(self, args);
4454
3859
 
4455
- if (hasNativeReflectConstruct) {
4456
- var NewTarget = _getPrototypeOf$1(this).constructor;
3860
+ function _next(value) {
3861
+ asyncGeneratorStep$3(gen, resolve, reject, _next, _throw, "next", value);
3862
+ }
4457
3863
 
4458
- result = Reflect.construct(Super, arguments, NewTarget);
4459
- } else {
4460
- result = Super.apply(this, arguments);
4461
- }
3864
+ function _throw(err) {
3865
+ asyncGeneratorStep$3(gen, resolve, reject, _next, _throw, "throw", err);
3866
+ }
4462
3867
 
4463
- return _possibleConstructorReturn$1(this, result);
3868
+ _next(undefined);
3869
+ });
4464
3870
  };
4465
3871
  }
4466
3872
 
4467
- function _slicedToArray$3(arr, i) {
4468
- return _arrayWithHoles$3(arr) || _iterableToArrayLimit$3(arr, i) || _unsupportedIterableToArray$3(arr, i) || _nonIterableRest$3();
4469
- }
4470
-
4471
- function _toConsumableArray$2(arr) {
4472
- return _arrayWithoutHoles$2(arr) || _iterableToArray$2(arr) || _unsupportedIterableToArray$3(arr) || _nonIterableSpread$2();
4473
- }
4474
-
4475
- function _arrayWithoutHoles$2(arr) {
4476
- if (Array.isArray(arr)) return _arrayLikeToArray$3(arr);
4477
- }
4478
-
4479
- function _arrayWithHoles$3(arr) {
4480
- if (Array.isArray(arr)) return arr;
4481
- }
4482
-
4483
- function _iterableToArray$2(iter) {
4484
- if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
4485
- }
4486
-
4487
- function _iterableToArrayLimit$3(arr, i) {
4488
- var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
4489
-
4490
- if (_i == null) return;
4491
- var _arr = [];
4492
- var _n = true;
4493
- var _d = false;
4494
-
4495
- var _s, _e;
4496
-
4497
- try {
4498
- for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) {
4499
- _arr.push(_s.value);
3873
+ function _extends() {
3874
+ _extends = Object.assign ? Object.assign.bind() : function (target) {
3875
+ for (var i = 1; i < arguments.length; i++) {
3876
+ var source = arguments[i];
4500
3877
 
4501
- if (i && _arr.length === i) break;
4502
- }
4503
- } catch (err) {
4504
- _d = true;
4505
- _e = err;
4506
- } finally {
4507
- try {
4508
- if (!_n && _i["return"] != null) _i["return"]();
4509
- } finally {
4510
- if (_d) throw _e;
3878
+ for (var key in source) {
3879
+ if (Object.prototype.hasOwnProperty.call(source, key)) {
3880
+ target[key] = source[key];
3881
+ }
3882
+ }
4511
3883
  }
4512
- }
4513
-
4514
- return _arr;
4515
- }
4516
3884
 
4517
- function _unsupportedIterableToArray$3(o, minLen) {
4518
- if (!o) return;
4519
- if (typeof o === "string") return _arrayLikeToArray$3(o, minLen);
4520
- var n = Object.prototype.toString.call(o).slice(8, -1);
4521
- if (n === "Object" && o.constructor) n = o.constructor.name;
4522
- if (n === "Map" || n === "Set") return Array.from(o);
4523
- if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray$3(o, minLen);
3885
+ return target;
3886
+ };
3887
+ return _extends.apply(this, arguments);
4524
3888
  }
4525
3889
 
4526
- function _arrayLikeToArray$3(arr, len) {
4527
- if (len == null || len > arr.length) len = arr.length;
4528
-
4529
- for (var i = 0, arr2 = new Array(len); i < len; i++) {
4530
- arr2[i] = arr[i];
4531
- }
4532
-
4533
- return arr2;
4534
- }
3890
+ function _inheritsLoose$1(subClass, superClass) {
3891
+ subClass.prototype = Object.create(superClass.prototype);
3892
+ subClass.prototype.constructor = subClass;
4535
3893
 
4536
- function _nonIterableSpread$2() {
4537
- throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
3894
+ _setPrototypeOf$1(subClass, superClass);
4538
3895
  }
4539
3896
 
4540
- function _nonIterableRest$3() {
4541
- throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
3897
+ function _setPrototypeOf$1(o, p) {
3898
+ _setPrototypeOf$1 = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) {
3899
+ o.__proto__ = p;
3900
+ return o;
3901
+ };
3902
+ return _setPrototypeOf$1(o, p);
4542
3903
  }
4543
3904
  /**
4544
3905
  * Common utilities
@@ -5266,39 +4627,36 @@
5266
4627
 
5267
4628
  var ImageRenderer = /*#__PURE__*/function () {
5268
4629
  function ImageRenderer() {
5269
- _classCallCheck$4(this, ImageRenderer);
5270
-
5271
4630
  this.imagePool = void 0;
5272
4631
  }
5273
4632
 
5274
- _createClass$4(ImageRenderer, [{
5275
- key: "render",
5276
- value: function render(context, parsedStyle) {
5277
- var width = parsedStyle.width,
5278
- height = parsedStyle.height,
5279
- img = parsedStyle.img;
5280
- var image;
5281
- var iw = width.value;
5282
- var ih = height.value;
4633
+ var _proto = ImageRenderer.prototype;
5283
4634
 
5284
- if (g.isString(img)) {
5285
- // image has been loaded in `mounted` hook
5286
- image = this.imagePool.getImageSync(img);
5287
- } else {
5288
- iw || (iw = img.width);
5289
- ih || (ih = img.height);
5290
- image = img;
5291
- }
4635
+ _proto.render = function render(context, parsedStyle) {
4636
+ var width = parsedStyle.width,
4637
+ height = parsedStyle.height,
4638
+ img = parsedStyle.img;
4639
+ var image;
4640
+ var iw = width.value;
4641
+ var ih = height.value;
5292
4642
 
5293
- if (image) {
5294
- // node-canvas will throw the following err:
5295
- // Error: Image given has not completed loading
5296
- try {
5297
- context.drawImage(image, 0, 0, iw, ih);
5298
- } catch (e) {}
5299
- }
4643
+ if (g.isString(img)) {
4644
+ // image has been loaded in `mounted` hook
4645
+ image = this.imagePool.getImageSync(img);
4646
+ } else {
4647
+ iw || (iw = img.width);
4648
+ ih || (ih = img.height);
4649
+ image = img;
4650
+ }
4651
+
4652
+ if (image) {
4653
+ // node-canvas will throw the following err:
4654
+ // Error: Image given has not completed loading
4655
+ try {
4656
+ context.drawImage(image, 0, 0, iw, ih);
4657
+ } catch (e) {}
5300
4658
  }
5301
- }]);
4659
+ };
5302
4660
 
5303
4661
  return ImageRenderer;
5304
4662
  }();
@@ -5310,157 +4668,154 @@
5310
4668
  })], ImageRenderer);
5311
4669
 
5312
4670
  var TextRenderer = /*#__PURE__*/function () {
5313
- function TextRenderer() {
5314
- _classCallCheck$4(this, TextRenderer);
5315
- }
5316
-
5317
- _createClass$4(TextRenderer, [{
5318
- key: "render",
5319
- value: function render(context, parsedStyle, object) {
5320
- var lineWidth = parsedStyle.lineWidth,
5321
- textAlign = parsedStyle.textAlign,
5322
- textBaseline = parsedStyle.textBaseline,
5323
- lineJoin = parsedStyle.lineJoin,
5324
- _parsedStyle$miterLim = parsedStyle.miterLimit,
5325
- miterLimit = _parsedStyle$miterLim === void 0 ? 0 : _parsedStyle$miterLim,
5326
- _parsedStyle$letterSp = parsedStyle.letterSpacing,
5327
- letterSpacing = _parsedStyle$letterSp === void 0 ? 0 : _parsedStyle$letterSp,
5328
- stroke = parsedStyle.stroke,
5329
- fill = parsedStyle.fill,
5330
- fillOpacity = parsedStyle.fillOpacity,
5331
- strokeOpacity = parsedStyle.strokeOpacity,
5332
- opacity = parsedStyle.opacity,
5333
- metrics = parsedStyle.metrics,
5334
- dx = parsedStyle.dx,
5335
- dy = parsedStyle.dy;
5336
- var font = metrics.font,
5337
- lines = metrics.lines,
5338
- height = metrics.height,
5339
- lineHeight = metrics.lineHeight,
5340
- lineMetrics = metrics.lineMetrics;
5341
- context.font = font;
5342
- context.lineWidth = lineWidth.value;
5343
- context.textAlign = textAlign.value;
5344
- context.textBaseline = textBaseline.value;
5345
- context.lineJoin = lineJoin.value;
5346
- context.miterLimit = miterLimit;
5347
- var linePositionY = 0; // handle vertical text baseline
5348
-
5349
- if (textBaseline.value === 'middle') {
5350
- linePositionY = -height / 2 - lineHeight / 2;
5351
- } else if (textBaseline.value === 'bottom' || textBaseline.value === 'alphabetic' || textBaseline.value === 'ideographic') {
5352
- linePositionY = -height;
5353
- } else if (textBaseline.value === 'top' || textBaseline.value === 'hanging') {
5354
- linePositionY = -lineHeight;
5355
- } // account for dx & dy
5356
-
5357
-
5358
- var offsetX = 0;
5359
-
5360
- if (dx && dx.unit === g.UnitType.kPixels) {
5361
- offsetX += dx.value;
4671
+ function TextRenderer() {}
4672
+
4673
+ var _proto = TextRenderer.prototype;
4674
+
4675
+ _proto.render = function render(context, parsedStyle, object) {
4676
+ var lineWidth = parsedStyle.lineWidth,
4677
+ textAlign = parsedStyle.textAlign,
4678
+ textBaseline = parsedStyle.textBaseline,
4679
+ lineJoin = parsedStyle.lineJoin,
4680
+ _parsedStyle$miterLim = parsedStyle.miterLimit,
4681
+ miterLimit = _parsedStyle$miterLim === void 0 ? 0 : _parsedStyle$miterLim,
4682
+ _parsedStyle$letterSp = parsedStyle.letterSpacing,
4683
+ letterSpacing = _parsedStyle$letterSp === void 0 ? 0 : _parsedStyle$letterSp,
4684
+ stroke = parsedStyle.stroke,
4685
+ fill = parsedStyle.fill,
4686
+ fillOpacity = parsedStyle.fillOpacity,
4687
+ strokeOpacity = parsedStyle.strokeOpacity,
4688
+ opacity = parsedStyle.opacity,
4689
+ metrics = parsedStyle.metrics,
4690
+ dx = parsedStyle.dx,
4691
+ dy = parsedStyle.dy;
4692
+ var font = metrics.font,
4693
+ lines = metrics.lines,
4694
+ height = metrics.height,
4695
+ lineHeight = metrics.lineHeight,
4696
+ lineMetrics = metrics.lineMetrics;
4697
+ context.font = font;
4698
+ context.lineWidth = lineWidth.value;
4699
+ context.textAlign = textAlign.value;
4700
+ context.textBaseline = textBaseline.value;
4701
+ context.lineJoin = lineJoin.value;
4702
+ context.miterLimit = miterLimit;
4703
+ var linePositionY = 0; // handle vertical text baseline
4704
+
4705
+ if (textBaseline.value === 'middle') {
4706
+ linePositionY = -height / 2 - lineHeight / 2;
4707
+ } else if (textBaseline.value === 'bottom' || textBaseline.value === 'alphabetic' || textBaseline.value === 'ideographic') {
4708
+ linePositionY = -height;
4709
+ } else if (textBaseline.value === 'top' || textBaseline.value === 'hanging') {
4710
+ linePositionY = -lineHeight;
4711
+ } // account for dx & dy
4712
+
4713
+
4714
+ var offsetX = 0;
4715
+
4716
+ if (dx && dx.unit === g.UnitType.kPixels) {
4717
+ offsetX += dx.value;
4718
+ }
4719
+
4720
+ if (dy && dy.unit === g.UnitType.kPixels) {
4721
+ linePositionY += dy.value;
4722
+ } // draw lines line by line
4723
+
4724
+
4725
+ for (var i = 0; i < lines.length; i++) {
4726
+ var linePositionX = lineWidth.value / 2 + offsetX;
4727
+ linePositionY += lineHeight; // no need to re-position X, cause we already set text align
4728
+ // @see https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/textAlign
4729
+
4730
+ if (!g.isNil(stroke) && !stroke.isNone && lineWidth && lineWidth.value) {
4731
+ this.drawLetterSpacing(context, lines[i], lineMetrics[i], textAlign.value, linePositionX, linePositionY, letterSpacing, fillOpacity.value, strokeOpacity.value, opacity.value, true);
4732
+ }
4733
+
4734
+ if (!g.isNil(fill)) {
4735
+ this.drawLetterSpacing(context, lines[i], lineMetrics[i], textAlign.value, linePositionX, linePositionY, letterSpacing, fillOpacity.value, strokeOpacity.value, opacity.value);
5362
4736
  }
4737
+ }
4738
+ };
5363
4739
 
5364
- if (dy && dy.unit === g.UnitType.kPixels) {
5365
- linePositionY += dy.value;
5366
- } // draw lines line by line
4740
+ _proto.drawLetterSpacing = function drawLetterSpacing(context, text, lineMetrics, textAlign, x, y, letterSpacing, fillOpacity, strokeOpacity, opacity, isStroke) {
4741
+ if (isStroke === void 0) {
4742
+ isStroke = false;
4743
+ } // letterSpacing of 0 means normal, render all texts directly
5367
4744
 
5368
4745
 
5369
- for (var i = 0; i < lines.length; i++) {
5370
- var linePositionX = lineWidth.value / 2 + offsetX;
5371
- linePositionY += lineHeight; // no need to re-position X, cause we already set text align
5372
- // @see https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/textAlign
4746
+ if (letterSpacing === 0) {
4747
+ if (isStroke) {
4748
+ this.strokeText(context, text, x, y, strokeOpacity);
4749
+ } else {
4750
+ this.fillText(context, text, x, y, fillOpacity, opacity);
4751
+ }
5373
4752
 
5374
- if (!g.isNil(stroke) && !stroke.isNone && lineWidth && lineWidth.value) {
5375
- this.drawLetterSpacing(context, lines[i], lineMetrics[i], textAlign.value, linePositionX, linePositionY, letterSpacing, fillOpacity.value, strokeOpacity.value, opacity.value, true);
5376
- }
4753
+ return;
4754
+ } // draw text using left align
5377
4755
 
5378
- if (!g.isNil(fill)) {
5379
- this.drawLetterSpacing(context, lines[i], lineMetrics[i], textAlign.value, linePositionX, linePositionY, letterSpacing, fillOpacity.value, strokeOpacity.value, opacity.value);
5380
- }
5381
- }
5382
- }
5383
- }, {
5384
- key: "drawLetterSpacing",
5385
- value: function drawLetterSpacing(context, text, lineMetrics, textAlign, x, y, letterSpacing, fillOpacity, strokeOpacity, opacity) {
5386
- var isStroke = arguments.length > 10 && arguments[10] !== undefined ? arguments[10] : false; // letterSpacing of 0 means normal, render all texts directly
5387
4756
 
5388
- if (letterSpacing === 0) {
5389
- if (isStroke) {
5390
- this.strokeText(context, text, x, y, strokeOpacity);
5391
- } else {
5392
- this.fillText(context, text, x, y, fillOpacity, opacity);
5393
- }
4757
+ var currentTextAlign = context.textAlign;
4758
+ context.textAlign = 'left';
4759
+ var currentPosition = x;
5394
4760
 
5395
- return;
5396
- } // draw text using left align
4761
+ if (textAlign === 'center') {
4762
+ currentPosition = x - lineMetrics.width / 2;
4763
+ } else if (textAlign === 'right' || textAlign === 'end') {
4764
+ currentPosition = x - lineMetrics.width;
4765
+ }
5397
4766
 
4767
+ var stringArray = Array.from(text);
4768
+ var previousWidth = context.measureText(text).width;
4769
+ var currentWidth = 0;
5398
4770
 
5399
- var currentTextAlign = context.textAlign;
5400
- context.textAlign = 'left';
5401
- var currentPosition = x;
4771
+ for (var i = 0; i < stringArray.length; ++i) {
4772
+ var currentChar = stringArray[i];
5402
4773
 
5403
- if (textAlign === 'center') {
5404
- currentPosition = x - lineMetrics.width / 2;
5405
- } else if (textAlign === 'right' || textAlign === 'end') {
5406
- currentPosition = x - lineMetrics.width;
4774
+ if (isStroke) {
4775
+ this.strokeText(context, currentChar, currentPosition, y, strokeOpacity);
4776
+ } else {
4777
+ this.fillText(context, currentChar, currentPosition, y, fillOpacity, opacity);
5407
4778
  }
5408
4779
 
5409
- var stringArray = Array.from(text);
5410
- var previousWidth = context.measureText(text).width;
5411
- var currentWidth = 0;
5412
-
5413
- for (var i = 0; i < stringArray.length; ++i) {
5414
- var currentChar = stringArray[i];
4780
+ currentWidth = context.measureText(text.substring(i + 1)).width;
4781
+ currentPosition += previousWidth - currentWidth + letterSpacing;
4782
+ previousWidth = currentWidth;
4783
+ }
5415
4784
 
5416
- if (isStroke) {
5417
- this.strokeText(context, currentChar, currentPosition, y, strokeOpacity);
5418
- } else {
5419
- this.fillText(context, currentChar, currentPosition, y, fillOpacity, opacity);
5420
- }
4785
+ context.textAlign = currentTextAlign;
4786
+ };
5421
4787
 
5422
- currentWidth = context.measureText(text.substring(i + 1)).width;
5423
- currentPosition += previousWidth - currentWidth + letterSpacing;
5424
- previousWidth = currentWidth;
5425
- }
4788
+ _proto.fillText = function fillText(context, text, x, y, fillOpacity, opacity) {
4789
+ var currentGlobalAlpha;
4790
+ var applyOpacity = !g.isNil(fillOpacity) && fillOpacity !== 1;
5426
4791
 
5427
- context.textAlign = currentTextAlign;
4792
+ if (applyOpacity) {
4793
+ currentGlobalAlpha = context.globalAlpha;
4794
+ context.globalAlpha = fillOpacity * opacity;
5428
4795
  }
5429
- }, {
5430
- key: "fillText",
5431
- value: function fillText(context, text, x, y, fillOpacity, opacity) {
5432
- var currentGlobalAlpha;
5433
- var applyOpacity = !g.isNil(fillOpacity) && fillOpacity !== 1;
5434
4796
 
5435
- if (applyOpacity) {
5436
- currentGlobalAlpha = context.globalAlpha;
5437
- context.globalAlpha = fillOpacity * opacity;
5438
- }
5439
-
5440
- context.fillText(text, x, y);
4797
+ context.fillText(text, x, y);
5441
4798
 
5442
- if (applyOpacity) {
5443
- context.globalAlpha = currentGlobalAlpha;
5444
- }
4799
+ if (applyOpacity) {
4800
+ context.globalAlpha = currentGlobalAlpha;
5445
4801
  }
5446
- }, {
5447
- key: "strokeText",
5448
- value: function strokeText(context, text, x, y, strokeOpacity) {
5449
- var currentGlobalAlpha;
5450
- var applyOpacity = !g.isNil(strokeOpacity) && strokeOpacity !== 1;
4802
+ };
5451
4803
 
5452
- if (applyOpacity) {
5453
- currentGlobalAlpha = context.globalAlpha;
5454
- context.globalAlpha = strokeOpacity;
5455
- }
4804
+ _proto.strokeText = function strokeText(context, text, x, y, strokeOpacity) {
4805
+ var currentGlobalAlpha;
4806
+ var applyOpacity = !g.isNil(strokeOpacity) && strokeOpacity !== 1;
4807
+
4808
+ if (applyOpacity) {
4809
+ currentGlobalAlpha = context.globalAlpha;
4810
+ context.globalAlpha = strokeOpacity;
4811
+ }
5456
4812
 
5457
- context.strokeText(text, x, y);
4813
+ context.strokeText(text, x, y);
5458
4814
 
5459
- if (applyOpacity) {
5460
- context.globalAlpha = currentGlobalAlpha;
5461
- }
4815
+ if (applyOpacity) {
4816
+ context.globalAlpha = currentGlobalAlpha;
5462
4817
  }
5463
- }]);
4818
+ };
5464
4819
 
5465
4820
  return TextRenderer;
5466
4821
  }();
@@ -5471,177 +4826,170 @@
5471
4826
 
5472
4827
  var DefaultRenderer = /*#__PURE__*/function () {
5473
4828
  function DefaultRenderer() {
5474
- _classCallCheck$4(this, DefaultRenderer);
5475
-
5476
4829
  this.imagePool = void 0;
5477
4830
  }
5478
4831
 
5479
- _createClass$4(DefaultRenderer, [{
5480
- key: "render",
5481
- value: function render(context, parsedStyle, object, renderingService) {
5482
- var fill = parsedStyle.fill,
5483
- opacity = parsedStyle.opacity,
5484
- fillOpacity = parsedStyle.fillOpacity,
5485
- stroke = parsedStyle.stroke,
5486
- strokeOpacity = parsedStyle.strokeOpacity,
5487
- lineWidth = parsedStyle.lineWidth,
5488
- lineCap = parsedStyle.lineCap,
5489
- lineJoin = parsedStyle.lineJoin,
5490
- shadowColor = parsedStyle.shadowColor,
5491
- filter = parsedStyle.filter,
5492
- miterLimit = parsedStyle.miterLimit;
5493
- var hasFill = !g.isNil(fill) && !fill.isNone;
5494
- var hasStroke = !g.isNil(stroke) && !stroke.isNone;
5495
- var isFillTransparent = fill.alpha === 0;
5496
-
5497
- if (hasFill) {
5498
- if (!g.isNil(fillOpacity) && fillOpacity.value !== 1) {
5499
- context.globalAlpha = fillOpacity.value;
5500
- this.fill(context, object, fill, renderingService);
5501
- context.globalAlpha = opacity.value;
5502
- } else {
5503
- this.fill(context, object, fill, renderingService);
5504
- }
4832
+ var _proto = DefaultRenderer.prototype;
4833
+
4834
+ _proto.render = function render(context, parsedStyle, object, renderingService) {
4835
+ var fill = parsedStyle.fill,
4836
+ opacity = parsedStyle.opacity,
4837
+ fillOpacity = parsedStyle.fillOpacity,
4838
+ stroke = parsedStyle.stroke,
4839
+ strokeOpacity = parsedStyle.strokeOpacity,
4840
+ lineWidth = parsedStyle.lineWidth,
4841
+ lineCap = parsedStyle.lineCap,
4842
+ lineJoin = parsedStyle.lineJoin,
4843
+ shadowColor = parsedStyle.shadowColor,
4844
+ filter = parsedStyle.filter,
4845
+ miterLimit = parsedStyle.miterLimit;
4846
+ var hasFill = !g.isNil(fill) && !fill.isNone;
4847
+ var hasStroke = !g.isNil(stroke) && !stroke.isNone;
4848
+ var isFillTransparent = fill.alpha === 0;
4849
+
4850
+ if (hasFill) {
4851
+ if (!g.isNil(fillOpacity) && fillOpacity.value !== 1) {
4852
+ context.globalAlpha = fillOpacity.value;
4853
+ this.fill(context, object, fill, renderingService);
4854
+ context.globalAlpha = opacity.value;
4855
+ } else {
4856
+ this.fill(context, object, fill, renderingService);
5505
4857
  }
4858
+ }
5506
4859
 
5507
- if (hasStroke) {
5508
- if (lineWidth && lineWidth.value > 0) {
5509
- var applyOpacity = !g.isNil(strokeOpacity) && strokeOpacity.value !== 1;
4860
+ if (hasStroke) {
4861
+ if (lineWidth && lineWidth.value > 0) {
4862
+ var applyOpacity = !g.isNil(strokeOpacity) && strokeOpacity.value !== 1;
5510
4863
 
5511
- if (applyOpacity) {
5512
- context.globalAlpha = strokeOpacity.value;
5513
- }
4864
+ if (applyOpacity) {
4865
+ context.globalAlpha = strokeOpacity.value;
4866
+ }
5514
4867
 
5515
- context.lineWidth = lineWidth.value;
4868
+ context.lineWidth = lineWidth.value;
5516
4869
 
5517
- if (!g.isNil(miterLimit)) {
5518
- context.miterLimit = miterLimit;
5519
- }
4870
+ if (!g.isNil(miterLimit)) {
4871
+ context.miterLimit = miterLimit;
4872
+ }
5520
4873
 
5521
- if (!g.isNil(lineCap)) {
5522
- context.lineCap = lineCap.value;
5523
- }
4874
+ if (!g.isNil(lineCap)) {
4875
+ context.lineCap = lineCap.value;
4876
+ }
5524
4877
 
5525
- if (!g.isNil(lineJoin)) {
5526
- context.lineJoin = lineJoin.value;
5527
- }
4878
+ if (!g.isNil(lineJoin)) {
4879
+ context.lineJoin = lineJoin.value;
4880
+ }
5528
4881
 
5529
- var oldShadowBlur;
5530
- var oldShadowColor;
5531
- var oldFilter;
5532
- var hasShadowColor = !g.isNil(shadowColor);
5533
- var hasFilter = !g.isNil(filter);
5534
-
5535
- if (hasShadowColor) {
5536
- // prevent inner shadow when drawing stroke, toggle shadowBlur & filter(drop-shadow)
5537
- // save shadow blur
5538
- oldShadowBlur = context.shadowBlur;
5539
- oldShadowColor = context.shadowColor;
5540
-
5541
- if (!g.isNil(oldShadowBlur)) {
5542
- context.shadowColor = 'transparent';
5543
- context.shadowBlur = 0;
5544
- }
4882
+ var oldShadowBlur;
4883
+ var oldShadowColor;
4884
+ var oldFilter;
4885
+ var hasShadowColor = !g.isNil(shadowColor);
4886
+ var hasFilter = !g.isNil(filter);
4887
+
4888
+ if (hasShadowColor) {
4889
+ // prevent inner shadow when drawing stroke, toggle shadowBlur & filter(drop-shadow)
4890
+ // save shadow blur
4891
+ oldShadowBlur = context.shadowBlur;
4892
+ oldShadowColor = context.shadowColor;
4893
+
4894
+ if (!g.isNil(oldShadowBlur)) {
4895
+ context.shadowColor = 'transparent';
4896
+ context.shadowBlur = 0;
5545
4897
  }
4898
+ }
5546
4899
 
5547
- if (hasFilter) {
5548
- // save drop-shadow filter
5549
- oldFilter = context.filter;
4900
+ if (hasFilter) {
4901
+ // save drop-shadow filter
4902
+ oldFilter = context.filter;
5550
4903
 
5551
- if (!g.isNil(oldFilter) && oldFilter.indexOf('drop-shadow') > -1) {
5552
- context.filter = oldFilter.replace(/drop-shadow\([^)]*\)/, '').trim() || 'none';
5553
- }
4904
+ if (!g.isNil(oldFilter) && oldFilter.indexOf('drop-shadow') > -1) {
4905
+ context.filter = oldFilter.replace(/drop-shadow\([^)]*\)/, '').trim() || 'none';
5554
4906
  }
4907
+ }
5555
4908
 
5556
- var drawStroke = hasFill && !isFillTransparent;
4909
+ var drawStroke = hasFill && !isFillTransparent;
5557
4910
 
5558
- if (drawStroke) {
5559
- this.stroke(context, object, stroke, renderingService);
5560
- } // restore shadow blur
4911
+ if (drawStroke) {
4912
+ this.stroke(context, object, stroke, renderingService);
4913
+ } // restore shadow blur
5561
4914
 
5562
4915
 
5563
- if (hasShadowColor) {
5564
- context.shadowColor = oldShadowColor;
5565
- context.shadowBlur = oldShadowBlur;
5566
- } // restore filters
4916
+ if (hasShadowColor) {
4917
+ context.shadowColor = oldShadowColor;
4918
+ context.shadowBlur = oldShadowBlur;
4919
+ } // restore filters
5567
4920
 
5568
4921
 
5569
- if (hasFilter) {
5570
- context.filter = oldFilter;
5571
- }
4922
+ if (hasFilter) {
4923
+ context.filter = oldFilter;
4924
+ }
5572
4925
 
5573
- if (!drawStroke) {
5574
- this.stroke(context, object, stroke, renderingService);
5575
- }
4926
+ if (!drawStroke) {
4927
+ this.stroke(context, object, stroke, renderingService);
5576
4928
  }
5577
4929
  }
5578
4930
  }
5579
- }, {
5580
- key: "fill",
5581
- value: function fill(context, object, _fill, renderingService) {
5582
- var _this = this;
4931
+ };
5583
4932
 
5584
- if (Array.isArray(_fill)) {
5585
- _fill.forEach(function (gradient) {
5586
- context.fillStyle = _this.getColor(gradient, object, context);
5587
- context.fill();
5588
- });
5589
- } else {
5590
- if (g.isPattern(_fill)) {
5591
- context.fillStyle = this.getPattern(_fill, object, context, renderingService);
5592
- }
4933
+ _proto.fill = function fill(context, object, _fill, renderingService) {
4934
+ var _this = this;
5593
4935
 
4936
+ if (Array.isArray(_fill)) {
4937
+ _fill.forEach(function (gradient) {
4938
+ context.fillStyle = _this.getColor(gradient, object, context);
5594
4939
  context.fill();
4940
+ });
4941
+ } else {
4942
+ if (g.isPattern(_fill)) {
4943
+ context.fillStyle = this.getPattern(_fill, object, context, renderingService);
5595
4944
  }
4945
+
4946
+ context.fill();
5596
4947
  }
5597
- }, {
5598
- key: "stroke",
5599
- value: function stroke(context, object, _stroke, renderingService) {
5600
- var _this2 = this;
4948
+ };
5601
4949
 
5602
- if (Array.isArray(_stroke)) {
5603
- _stroke.forEach(function (gradient) {
5604
- context.strokeStyle = _this2.getColor(gradient, object, context);
5605
- context.stroke();
5606
- });
5607
- } else {
5608
- if (g.isPattern(_stroke)) {
5609
- context.strokeStyle = this.getPattern(_stroke, object, context, renderingService);
5610
- }
4950
+ _proto.stroke = function stroke(context, object, _stroke, renderingService) {
4951
+ var _this2 = this;
5611
4952
 
4953
+ if (Array.isArray(_stroke)) {
4954
+ _stroke.forEach(function (gradient) {
4955
+ context.strokeStyle = _this2.getColor(gradient, object, context);
5612
4956
  context.stroke();
5613
- }
5614
- }
5615
- }, {
5616
- key: "getPattern",
5617
- value: function getPattern(pattern, object, context, renderingService) {
5618
- var canvasPattern = this.imagePool.getOrCreatePatternSync(pattern, context, function () {
5619
- // set dirty rectangle flag
5620
- object.renderable.dirty = true;
5621
- renderingService.dirtify();
5622
4957
  });
5623
- return canvasPattern;
5624
- }
5625
- }, {
5626
- key: "getColor",
5627
- value: function getColor(parsedColor, object, context) {
5628
- var color;
5629
-
5630
- if (parsedColor.type === g.GradientType.LinearGradient || parsedColor.type === g.GradientType.RadialGradient) {
5631
- var bounds = object.getGeometryBounds();
5632
- var width = bounds && bounds.halfExtents[0] * 2 || 1;
5633
- var height = bounds && bounds.halfExtents[1] * 2 || 1;
5634
- color = this.imagePool.getOrCreateGradient(_objectSpread2(_objectSpread2({
5635
- type: parsedColor.type
5636
- }, parsedColor.value), {}, {
5637
- width: width,
5638
- height: height
5639
- }), context);
4958
+ } else {
4959
+ if (g.isPattern(_stroke)) {
4960
+ context.strokeStyle = this.getPattern(_stroke, object, context, renderingService);
5640
4961
  }
5641
4962
 
5642
- return color;
4963
+ context.stroke();
4964
+ }
4965
+ };
4966
+
4967
+ _proto.getPattern = function getPattern(pattern, object, context, renderingService) {
4968
+ var canvasPattern = this.imagePool.getOrCreatePatternSync(pattern, context, function () {
4969
+ // set dirty rectangle flag
4970
+ object.renderable.dirty = true;
4971
+ renderingService.dirtify();
4972
+ });
4973
+ return canvasPattern;
4974
+ };
4975
+
4976
+ _proto.getColor = function getColor(parsedColor, object, context) {
4977
+ var color;
4978
+
4979
+ if (parsedColor.type === g.GradientType.LinearGradient || parsedColor.type === g.GradientType.RadialGradient) {
4980
+ var bounds = object.getGeometryBounds();
4981
+ var width = bounds && bounds.halfExtents[0] * 2 || 1;
4982
+ var height = bounds && bounds.halfExtents[1] * 2 || 1;
4983
+ color = this.imagePool.getOrCreateGradient(_extends({
4984
+ type: parsedColor.type
4985
+ }, parsedColor.value, {
4986
+ width: width,
4987
+ height: height
4988
+ }), context);
5643
4989
  }
5644
- }]);
4990
+
4991
+ return color;
4992
+ };
5645
4993
 
5646
4994
  return DefaultRenderer;
5647
4995
  }();
@@ -5651,17 +4999,13 @@
5651
4999
  DefaultRenderer = __decorate([g.singleton()], DefaultRenderer);
5652
5000
 
5653
5001
  var RectRenderer = /*#__PURE__*/function (_DefaultRenderer) {
5654
- _inherits$1(RectRenderer, _DefaultRenderer);
5655
-
5656
- var _super = _createSuper$1(RectRenderer);
5002
+ _inheritsLoose$1(RectRenderer, _DefaultRenderer);
5657
5003
 
5658
5004
  function RectRenderer() {
5659
- _classCallCheck$4(this, RectRenderer);
5660
-
5661
- return _super.apply(this, arguments);
5005
+ return _DefaultRenderer.apply(this, arguments) || this;
5662
5006
  }
5663
5007
 
5664
- return _createClass$4(RectRenderer);
5008
+ return RectRenderer;
5665
5009
  }(DefaultRenderer);
5666
5010
 
5667
5011
  RectRenderer = __decorate([g.singleton({
@@ -5669,17 +5013,13 @@
5669
5013
  })], RectRenderer);
5670
5014
 
5671
5015
  var CircleRenderer = /*#__PURE__*/function (_DefaultRenderer) {
5672
- _inherits$1(CircleRenderer, _DefaultRenderer);
5673
-
5674
- var _super = _createSuper$1(CircleRenderer);
5016
+ _inheritsLoose$1(CircleRenderer, _DefaultRenderer);
5675
5017
 
5676
5018
  function CircleRenderer() {
5677
- _classCallCheck$4(this, CircleRenderer);
5678
-
5679
- return _super.apply(this, arguments);
5019
+ return _DefaultRenderer.apply(this, arguments) || this;
5680
5020
  }
5681
5021
 
5682
- return _createClass$4(CircleRenderer);
5022
+ return CircleRenderer;
5683
5023
  }(DefaultRenderer);
5684
5024
 
5685
5025
  CircleRenderer = __decorate([g.singleton({
@@ -5687,17 +5027,13 @@
5687
5027
  })], CircleRenderer);
5688
5028
 
5689
5029
  var EllipseRenderer = /*#__PURE__*/function (_DefaultRenderer) {
5690
- _inherits$1(EllipseRenderer, _DefaultRenderer);
5691
-
5692
- var _super = _createSuper$1(EllipseRenderer);
5030
+ _inheritsLoose$1(EllipseRenderer, _DefaultRenderer);
5693
5031
 
5694
5032
  function EllipseRenderer() {
5695
- _classCallCheck$4(this, EllipseRenderer);
5696
-
5697
- return _super.apply(this, arguments);
5033
+ return _DefaultRenderer.apply(this, arguments) || this;
5698
5034
  }
5699
5035
 
5700
- return _createClass$4(EllipseRenderer);
5036
+ return EllipseRenderer;
5701
5037
  }(DefaultRenderer);
5702
5038
 
5703
5039
  EllipseRenderer = __decorate([g.singleton({
@@ -5705,17 +5041,13 @@
5705
5041
  })], EllipseRenderer);
5706
5042
 
5707
5043
  var LineRenderer = /*#__PURE__*/function (_DefaultRenderer) {
5708
- _inherits$1(LineRenderer, _DefaultRenderer);
5709
-
5710
- var _super = _createSuper$1(LineRenderer);
5044
+ _inheritsLoose$1(LineRenderer, _DefaultRenderer);
5711
5045
 
5712
5046
  function LineRenderer() {
5713
- _classCallCheck$4(this, LineRenderer);
5714
-
5715
- return _super.apply(this, arguments);
5047
+ return _DefaultRenderer.apply(this, arguments) || this;
5716
5048
  }
5717
5049
 
5718
- return _createClass$4(LineRenderer);
5050
+ return LineRenderer;
5719
5051
  }(DefaultRenderer);
5720
5052
 
5721
5053
  LineRenderer = __decorate([g.singleton({
@@ -5723,17 +5055,13 @@
5723
5055
  })], LineRenderer);
5724
5056
 
5725
5057
  var PolylineRenderer = /*#__PURE__*/function (_DefaultRenderer) {
5726
- _inherits$1(PolylineRenderer, _DefaultRenderer);
5727
-
5728
- var _super = _createSuper$1(PolylineRenderer);
5058
+ _inheritsLoose$1(PolylineRenderer, _DefaultRenderer);
5729
5059
 
5730
5060
  function PolylineRenderer() {
5731
- _classCallCheck$4(this, PolylineRenderer);
5732
-
5733
- return _super.apply(this, arguments);
5061
+ return _DefaultRenderer.apply(this, arguments) || this;
5734
5062
  }
5735
5063
 
5736
- return _createClass$4(PolylineRenderer);
5064
+ return PolylineRenderer;
5737
5065
  }(DefaultRenderer);
5738
5066
 
5739
5067
  PolylineRenderer = __decorate([g.singleton({
@@ -5741,17 +5069,13 @@
5741
5069
  })], PolylineRenderer);
5742
5070
 
5743
5071
  var PolygonRenderer = /*#__PURE__*/function (_DefaultRenderer) {
5744
- _inherits$1(PolygonRenderer, _DefaultRenderer);
5745
-
5746
- var _super = _createSuper$1(PolygonRenderer);
5072
+ _inheritsLoose$1(PolygonRenderer, _DefaultRenderer);
5747
5073
 
5748
5074
  function PolygonRenderer() {
5749
- _classCallCheck$4(this, PolygonRenderer);
5750
-
5751
- return _super.apply(this, arguments);
5075
+ return _DefaultRenderer.apply(this, arguments) || this;
5752
5076
  }
5753
5077
 
5754
- return _createClass$4(PolygonRenderer);
5078
+ return PolygonRenderer;
5755
5079
  }(DefaultRenderer);
5756
5080
 
5757
5081
  PolygonRenderer = __decorate([g.singleton({
@@ -5759,17 +5083,13 @@
5759
5083
  })], PolygonRenderer);
5760
5084
 
5761
5085
  var PathRenderer = /*#__PURE__*/function (_DefaultRenderer) {
5762
- _inherits$1(PathRenderer, _DefaultRenderer);
5763
-
5764
- var _super = _createSuper$1(PathRenderer);
5086
+ _inheritsLoose$1(PathRenderer, _DefaultRenderer);
5765
5087
 
5766
5088
  function PathRenderer() {
5767
- _classCallCheck$4(this, PathRenderer);
5768
-
5769
- return _super.apply(this, arguments);
5089
+ return _DefaultRenderer.apply(this, arguments) || this;
5770
5090
  }
5771
5091
 
5772
- return _createClass$4(PathRenderer);
5092
+ return PathRenderer;
5773
5093
  }(DefaultRenderer);
5774
5094
 
5775
5095
  PathRenderer = __decorate([g.singleton({
@@ -5787,8 +5107,6 @@
5787
5107
 
5788
5108
  var CanvasRendererPlugin = CanvasRendererPlugin_1 = (_class$2 = /*#__PURE__*/function () {
5789
5109
  function CanvasRendererPlugin() {
5790
- _classCallCheck$4(this, CanvasRendererPlugin);
5791
-
5792
5110
  this.canvasConfig = void 0;
5793
5111
  this.camera = void 0;
5794
5112
  this.contextService = void 0;
@@ -5807,476 +5125,458 @@
5807
5125
  this.tmpMat4 = create$1$1();
5808
5126
  }
5809
5127
 
5810
- _createClass$4(CanvasRendererPlugin, [{
5811
- key: "apply",
5812
- value: function apply(renderingService) {
5813
- var _this = this;
5128
+ var _proto = CanvasRendererPlugin.prototype;
5814
5129
 
5815
- var handleUnmounted = function handleUnmounted(e) {
5816
- var object = e.target; // remove r-bush node
5817
- // @ts-ignore
5130
+ _proto.apply = function apply(renderingService) {
5131
+ var _this = this;
5818
5132
 
5819
- var rBushNode = object.rBushNode;
5133
+ var handleUnmounted = function handleUnmounted(e) {
5134
+ var object = e.target; // remove r-bush node
5135
+ // @ts-ignore
5820
5136
 
5821
- if (rBushNode.aabb) {
5822
- // save removed aabbs for dirty-rectangle rendering later
5823
- _this.removedRBushNodeAABBs.push(rBushNode.aabb);
5824
- }
5825
- };
5137
+ var rBushNode = object.rBushNode;
5826
5138
 
5827
- var handleCulled = function handleCulled(e) {
5828
- var object = e.target; // @ts-ignore
5139
+ if (rBushNode.aabb) {
5140
+ // save removed aabbs for dirty-rectangle rendering later
5141
+ _this.removedRBushNodeAABBs.push(rBushNode.aabb);
5142
+ }
5143
+ };
5829
5144
 
5830
- var rBushNode = object.rBushNode;
5145
+ var handleCulled = function handleCulled(e) {
5146
+ var object = e.target; // @ts-ignore
5831
5147
 
5832
- if (rBushNode.aabb) {
5833
- // save removed aabbs for dirty-rectangle rendering later
5834
- _this.removedRBushNodeAABBs.push(rBushNode.aabb);
5835
- }
5836
- };
5148
+ var rBushNode = object.rBushNode;
5837
5149
 
5838
- renderingService.hooks.init.tapPromise(CanvasRendererPlugin_1.tag, /*#__PURE__*/_asyncToGenerator$3( /*#__PURE__*/_regeneratorRuntime$3().mark(function _callee() {
5839
- var _this$canvasConfig, width, height, context;
5150
+ if (rBushNode.aabb) {
5151
+ // save removed aabbs for dirty-rectangle rendering later
5152
+ _this.removedRBushNodeAABBs.push(rBushNode.aabb);
5153
+ }
5154
+ };
5840
5155
 
5841
- return _regeneratorRuntime$3().wrap(function _callee$(_context) {
5842
- while (1) {
5843
- switch (_context.prev = _context.next) {
5844
- case 0:
5845
- _this.renderingContext.root.addEventListener(g.ElementEvent.UNMOUNTED, handleUnmounted);
5156
+ renderingService.hooks.init.tapPromise(CanvasRendererPlugin_1.tag, /*#__PURE__*/_asyncToGenerator$3( /*#__PURE__*/_regeneratorRuntime$3().mark(function _callee() {
5157
+ var _this$canvasConfig, width, height, context;
5846
5158
 
5847
- _this.renderingContext.root.addEventListener(g.ElementEvent.CULLED, handleCulled); // clear fullscreen
5159
+ return _regeneratorRuntime$3().wrap(function _callee$(_context) {
5160
+ while (1) {
5161
+ switch (_context.prev = _context.next) {
5162
+ case 0:
5163
+ _this.renderingContext.root.addEventListener(g.ElementEvent.UNMOUNTED, handleUnmounted);
5848
5164
 
5165
+ _this.renderingContext.root.addEventListener(g.ElementEvent.CULLED, handleCulled); // clear fullscreen
5849
5166
 
5850
- _this$canvasConfig = _this.canvasConfig, width = _this$canvasConfig.width, height = _this$canvasConfig.height;
5851
- context = _this.contextService.getContext();
5852
5167
 
5853
- _this.clearRect(context, 0, 0, width, height);
5168
+ _this$canvasConfig = _this.canvasConfig, width = _this$canvasConfig.width, height = _this$canvasConfig.height;
5169
+ context = _this.contextService.getContext();
5854
5170
 
5855
- case 5:
5856
- case "end":
5857
- return _context.stop();
5858
- }
5171
+ _this.clearRect(context, 0, 0, width, height);
5172
+
5173
+ case 5:
5174
+ case "end":
5175
+ return _context.stop();
5859
5176
  }
5860
- }, _callee);
5861
- })));
5862
- renderingService.hooks.destroy.tap(CanvasRendererPlugin_1.tag, function () {
5863
- _this.renderingContext.root.removeEventListener(g.ElementEvent.UNMOUNTED, handleUnmounted);
5177
+ }
5178
+ }, _callee);
5179
+ })));
5180
+ renderingService.hooks.destroy.tap(CanvasRendererPlugin_1.tag, function () {
5181
+ _this.renderingContext.root.removeEventListener(g.ElementEvent.UNMOUNTED, handleUnmounted);
5864
5182
 
5865
- _this.renderingContext.root.removeEventListener(g.ElementEvent.CULLED, handleCulled);
5866
- });
5867
- renderingService.hooks.beginFrame.tap(CanvasRendererPlugin_1.tag, function () {
5868
- var context = _this.contextService.getContext();
5183
+ _this.renderingContext.root.removeEventListener(g.ElementEvent.CULLED, handleCulled);
5184
+ });
5185
+ renderingService.hooks.beginFrame.tap(CanvasRendererPlugin_1.tag, function () {
5186
+ var context = _this.contextService.getContext();
5869
5187
 
5870
- var _this$canvasConfig2 = _this.canvasConfig,
5871
- width = _this$canvasConfig2.width,
5872
- height = _this$canvasConfig2.height; // clear fullscreen when:
5873
- // 1. dirty rectangle rendering disabled
5874
- // 2. camera changed
5188
+ var _this$canvasConfig2 = _this.canvasConfig,
5189
+ width = _this$canvasConfig2.width,
5190
+ height = _this$canvasConfig2.height; // clear fullscreen when:
5191
+ // 1. dirty rectangle rendering disabled
5192
+ // 2. camera changed
5875
5193
 
5876
- _this.clearFullScreen = _this.shouldClearFullScreen();
5194
+ _this.clearFullScreen = _this.shouldClearFullScreen();
5877
5195
 
5878
- if (context) {
5879
- context.save();
5196
+ if (context) {
5197
+ context.save();
5880
5198
 
5881
- if (_this.clearFullScreen) {
5882
- _this.clearRect(context, 0, 0, width, height);
5883
- } // account for camera's world matrix
5199
+ if (_this.clearFullScreen) {
5200
+ _this.clearRect(context, 0, 0, width, height);
5201
+ } // account for camera's world matrix
5884
5202
 
5885
5203
 
5886
- _this.applyTransform(context, _this.camera.getOrthoMatrix());
5887
- }
5888
- }); // render at the end of frame
5889
-
5890
- renderingService.hooks.endFrame.tap(CanvasRendererPlugin_1.tag, function () {
5891
- var context = _this.contextService.getContext();
5892
-
5893
- if (_this.clearFullScreen) ;else {
5894
- // merge removed AABB
5895
- var dirtyRenderBounds = _this.safeMergeAABB.apply(_this, [_this.mergeDirtyAABBs( // should not ignore group since clipPath may affect its children
5896
- // this.renderQueue.filter((o) => o.nodeName !== Shape.GROUP)),
5897
- _this.renderQueue)].concat(_toConsumableArray$2(_this.removedRBushNodeAABBs.map(function (_ref2) {
5898
- var minX = _ref2.minX,
5899
- minY = _ref2.minY,
5900
- maxX = _ref2.maxX,
5901
- maxY = _ref2.maxY;
5902
- var aabb = new g.AABB();
5903
- aabb.setMinMax(fromValues$2(minX, minY, 0), fromValues$2(maxX, maxY, 0));
5904
- return aabb;
5905
- }))));
5906
-
5907
- _this.removedRBushNodeAABBs = [];
5908
-
5909
- if (g.AABB.isEmpty(dirtyRenderBounds)) {
5910
- _this.renderQueue = [];
5911
- return;
5912
- } // clear & clip dirty rectangle
5913
-
5914
-
5915
- var _this$convertAABB2Rec = _this.convertAABB2Rect(dirtyRenderBounds),
5916
- x = _this$convertAABB2Rec.x,
5917
- y = _this$convertAABB2Rec.y,
5918
- width = _this$convertAABB2Rec.width,
5919
- height = _this$convertAABB2Rec.height;
5920
-
5921
- _this.clearRect(context, x, y, width, height);
5922
-
5923
- context.beginPath();
5924
- context.rect(x, y, width, height);
5925
- context.clip(); // draw dirty rectangle
5926
- // if (enableDirtyRectangleRenderingDebug) {
5927
- // context.lineWidth = 4;
5928
- // context.strokeStyle = `rgba(${Math.random() * 255}, ${Math.random() * 255}, ${
5929
- // Math.random() * 255
5930
- // }, 1)`;
5931
- // context.strokeRect(x, y, width, height);
5932
- // }
5933
- // search objects intersect with dirty rectangle
5934
-
5935
- var dirtyObjects = _this.searchDirtyObjects(dirtyRenderBounds); // do rendering
5936
-
5937
-
5938
- dirtyObjects // sort by z-index
5939
- .sort(function (a, b) {
5940
- return a.sortable.renderOrder - b.sortable.renderOrder;
5941
- }).forEach(function (object) {
5942
- // culled object should not be rendered
5943
- if (object && object.isVisible() && !object.isCulled()) {
5944
- _this.renderDisplayObject(object, renderingService);
5945
- }
5946
- }); // save dirty AABBs in last frame
5204
+ _this.applyTransform(context, _this.camera.getOrthoMatrix());
5205
+ }
5206
+ }); // render at the end of frame
5947
5207
 
5948
- _this.renderQueue.forEach(function (object) {
5949
- _this.saveDirtyAABB(object);
5950
- }); // clear queue
5208
+ renderingService.hooks.endFrame.tap(CanvasRendererPlugin_1.tag, function () {
5209
+ var context = _this.contextService.getContext();
5951
5210
 
5211
+ if (_this.clearFullScreen) ;else {
5212
+ // merge removed AABB
5213
+ var dirtyRenderBounds = _this.safeMergeAABB.apply(_this, [_this.mergeDirtyAABBs( // should not ignore group since clipPath may affect its children
5214
+ // this.renderQueue.filter((o) => o.nodeName !== Shape.GROUP)),
5215
+ _this.renderQueue)].concat(_this.removedRBushNodeAABBs.map(function (_ref2) {
5216
+ var minX = _ref2.minX,
5217
+ minY = _ref2.minY,
5218
+ maxX = _ref2.maxX,
5219
+ maxY = _ref2.maxY;
5220
+ var aabb = new g.AABB();
5221
+ aabb.setMinMax(fromValues$2(minX, minY, 0), fromValues$2(maxX, maxY, 0));
5222
+ return aabb;
5223
+ })));
5952
5224
 
5225
+ _this.removedRBushNodeAABBs = [];
5226
+
5227
+ if (g.AABB.isEmpty(dirtyRenderBounds)) {
5953
5228
  _this.renderQueue = [];
5954
- } // pop restore stack, eg. root -> parent -> child
5229
+ return;
5230
+ } // clear & clip dirty rectangle
5955
5231
 
5956
- _this.restoreStack.forEach(function (s) {
5957
- context.restore();
5958
- }); // clear restore stack
5959
5232
 
5233
+ var _this$convertAABB2Rec = _this.convertAABB2Rect(dirtyRenderBounds),
5234
+ x = _this$convertAABB2Rec.x,
5235
+ y = _this$convertAABB2Rec.y,
5236
+ width = _this$convertAABB2Rec.width,
5237
+ height = _this$convertAABB2Rec.height;
5960
5238
 
5961
- _this.restoreStack = [];
5962
- _this.clearFullScreen = false;
5963
- context.restore();
5964
- });
5965
- renderingService.hooks.render.tap(CanvasRendererPlugin_1.tag, function (object) {
5966
- if (_this.clearFullScreen) {
5967
- if (object.isVisible() && !object.isCulled()) {
5968
- // render immediately
5239
+ _this.clearRect(context, x, y, width, height);
5240
+
5241
+ context.beginPath();
5242
+ context.rect(x, y, width, height);
5243
+ context.clip(); // draw dirty rectangle
5244
+ // if (enableDirtyRectangleRenderingDebug) {
5245
+ // context.lineWidth = 4;
5246
+ // context.strokeStyle = `rgba(${Math.random() * 255}, ${Math.random() * 255}, ${
5247
+ // Math.random() * 255
5248
+ // }, 1)`;
5249
+ // context.strokeRect(x, y, width, height);
5250
+ // }
5251
+ // search objects intersect with dirty rectangle
5252
+
5253
+ var dirtyObjects = _this.searchDirtyObjects(dirtyRenderBounds); // do rendering
5254
+
5255
+
5256
+ dirtyObjects // sort by z-index
5257
+ .sort(function (a, b) {
5258
+ return a.sortable.renderOrder - b.sortable.renderOrder;
5259
+ }).forEach(function (object) {
5260
+ // culled object should not be rendered
5261
+ if (object && object.isVisible() && !object.isCulled()) {
5969
5262
  _this.renderDisplayObject(object, renderingService);
5970
5263
  }
5971
- } else {
5972
- // render at the end of frame
5973
- _this.renderQueue.push(object);
5264
+ }); // save dirty AABBs in last frame
5265
+
5266
+ _this.renderQueue.forEach(function (object) {
5267
+ _this.saveDirtyAABB(object);
5268
+ }); // clear queue
5269
+
5270
+
5271
+ _this.renderQueue = [];
5272
+ } // pop restore stack, eg. root -> parent -> child
5273
+
5274
+ _this.restoreStack.forEach(function (s) {
5275
+ context.restore();
5276
+ }); // clear restore stack
5277
+
5278
+
5279
+ _this.restoreStack = [];
5280
+ _this.clearFullScreen = false;
5281
+ context.restore();
5282
+ });
5283
+ renderingService.hooks.render.tap(CanvasRendererPlugin_1.tag, function (object) {
5284
+ if (_this.clearFullScreen) {
5285
+ if (object.isVisible() && !object.isCulled()) {
5286
+ // render immediately
5287
+ _this.renderDisplayObject(object, renderingService);
5974
5288
  }
5975
- });
5289
+ } else {
5290
+ // render at the end of frame
5291
+ _this.renderQueue.push(object);
5292
+ }
5293
+ });
5294
+ };
5295
+
5296
+ _proto.clearRect = function clearRect(context, x, y, width, height) {
5297
+ context.clearRect(x, y, width, height);
5298
+ var background = this.canvasConfig.background;
5299
+
5300
+ if (background) {
5301
+ context.fillStyle = background;
5302
+ context.fillRect(x, y, width, height);
5976
5303
  }
5977
- }, {
5978
- key: "clearRect",
5979
- value: function clearRect(context, x, y, width, height) {
5980
- context.clearRect(x, y, width, height);
5981
- var background = this.canvasConfig.background;
5304
+ };
5982
5305
 
5983
- if (background) {
5984
- context.fillStyle = background;
5985
- context.fillRect(x, y, width, height);
5986
- }
5306
+ _proto.renderDisplayObject = function renderDisplayObject(object, renderingService) {
5307
+ var context = this.contextService.getContext(); // restore to its parent
5308
+
5309
+ var parent = this.restoreStack[this.restoreStack.length - 1];
5310
+
5311
+ while (parent && object.parentNode !== parent) {
5312
+ context.restore();
5313
+ this.restoreStack.pop();
5314
+ parent = this.restoreStack[this.restoreStack.length - 1];
5987
5315
  }
5988
- }, {
5989
- key: "renderDisplayObject",
5990
- value: function renderDisplayObject(object, renderingService) {
5991
- var context = this.contextService.getContext(); // restore to its parent
5992
5316
 
5993
- var parent = this.restoreStack[this.restoreStack.length - 1];
5317
+ var nodeName = object.nodeName;
5994
5318
 
5995
- while (parent && object.parentNode !== parent) {
5996
- context.restore();
5997
- this.restoreStack.pop();
5998
- parent = this.restoreStack[this.restoreStack.length - 1];
5319
+ if (this.styleRendererFactoryCache[nodeName] === undefined) {
5320
+ this.styleRendererFactoryCache[nodeName] = this.styleRendererFactory(nodeName);
5321
+ }
5322
+
5323
+ var styleRenderer = this.styleRendererFactoryCache[nodeName]; // reset transformation
5324
+
5325
+ context.save(); // apply RTS transformation in world space
5326
+
5327
+ this.applyTransform(context, object.getLocalTransform()); // clip path
5328
+
5329
+ var clipPathShape = object.style.clipPath;
5330
+
5331
+ if (clipPathShape) {
5332
+ context.save(); // const parentTransform =
5333
+ // (object.parentElement as DisplayObject)?.getWorldTransform() || mat4.identity(this.tmpMat4);
5334
+ // mat4.multiply(this.tmpMat4, parentTransform, clipPathShape.getLocalTransform());
5335
+ // apply clip shape's RTS
5336
+
5337
+ this.applyTransform(context, clipPathShape.getLocalTransform()); // generate path in local space
5338
+
5339
+ if (this.pathGeneratorFactoryCache[clipPathShape.nodeName] === undefined) {
5340
+ this.pathGeneratorFactoryCache[clipPathShape.nodeName] = this.pathGeneratorFactory(clipPathShape.nodeName);
5999
5341
  }
6000
5342
 
6001
- var nodeName = object.nodeName;
5343
+ var _generatePath = this.pathGeneratorFactoryCache[clipPathShape.nodeName];
5344
+
5345
+ if (_generatePath) {
5346
+ this.useAnchor(context, clipPathShape);
5347
+ context.beginPath();
5348
+
5349
+ _generatePath(context, clipPathShape.parsedStyle);
6002
5350
 
6003
- if (this.styleRendererFactoryCache[nodeName] === undefined) {
6004
- this.styleRendererFactoryCache[nodeName] = this.styleRendererFactory(nodeName);
5351
+ context.closePath();
6005
5352
  }
6006
5353
 
6007
- var styleRenderer = this.styleRendererFactoryCache[nodeName]; // reset transformation
5354
+ context.restore();
5355
+ context.clip();
5356
+ } // fill & stroke
5357
+
6008
5358
 
6009
- context.save(); // apply RTS transformation in world space
5359
+ context.save(); // apply attributes to context
6010
5360
 
6011
- this.applyTransform(context, object.getLocalTransform()); // clip path
5361
+ this.applyAttributesToContext(context, object); // apply anchor in local space
6012
5362
 
6013
- var clipPathShape = object.style.clipPath;
5363
+ this.useAnchor(context, object); // generate path in local space
6014
5364
 
6015
- if (clipPathShape) {
6016
- context.save(); // const parentTransform =
6017
- // (object.parentElement as DisplayObject)?.getWorldTransform() || mat4.identity(this.tmpMat4);
6018
- // mat4.multiply(this.tmpMat4, parentTransform, clipPathShape.getLocalTransform());
6019
- // apply clip shape's RTS
5365
+ if (this.pathGeneratorFactoryCache[object.nodeName] === undefined) {
5366
+ this.pathGeneratorFactoryCache[object.nodeName] = this.pathGeneratorFactory(object.nodeName);
5367
+ }
6020
5368
 
6021
- this.applyTransform(context, clipPathShape.getLocalTransform()); // generate path in local space
5369
+ var generatePath = this.pathGeneratorFactoryCache[object.nodeName];
6022
5370
 
6023
- if (this.pathGeneratorFactoryCache[clipPathShape.nodeName] === undefined) {
6024
- this.pathGeneratorFactoryCache[clipPathShape.nodeName] = this.pathGeneratorFactory(clipPathShape.nodeName);
6025
- }
5371
+ if (generatePath) {
5372
+ context.beginPath();
5373
+ generatePath(context, object.parsedStyle);
6026
5374
 
6027
- var _generatePath = this.pathGeneratorFactoryCache[clipPathShape.nodeName];
5375
+ if (object.nodeName !== g.Shape.LINE && object.nodeName !== g.Shape.PATH && object.nodeName !== g.Shape.POLYLINE) {
5376
+ context.closePath();
5377
+ }
5378
+ } // fill & stroke
6028
5379
 
6029
- if (_generatePath) {
6030
- this.useAnchor(context, clipPathShape);
6031
- context.beginPath();
6032
5380
 
6033
- _generatePath(context, clipPathShape.parsedStyle);
5381
+ if (styleRenderer) {
5382
+ styleRenderer.render(context, object.parsedStyle, object, renderingService);
5383
+ } // restore applied attributes, eg. shadowBlur shadowColor...
6034
5384
 
6035
- context.closePath();
6036
- }
6037
5385
 
6038
- context.restore();
6039
- context.clip();
6040
- } // fill & stroke
5386
+ context.restore(); // finish rendering, clear dirty flag
6041
5387
 
5388
+ object.renderable.dirty = false;
5389
+ this.restoreStack.push(object);
5390
+ };
6042
5391
 
6043
- context.save(); // apply attributes to context
5392
+ _proto.shouldClearFullScreen = function shouldClearFullScreen() {
5393
+ var renderer = this.canvasConfig.renderer;
6044
5394
 
6045
- this.applyAttributesToContext(context, object); // apply anchor in local space
5395
+ var _renderer$getConfig = renderer.getConfig(),
5396
+ enableDirtyRectangleRendering = _renderer$getConfig.enableDirtyRectangleRendering;
6046
5397
 
6047
- this.useAnchor(context, object); // generate path in local space
5398
+ return !enableDirtyRectangleRendering || this.renderingContext.renderReasons.has(g.RenderReason.CAMERA_CHANGED);
5399
+ };
6048
5400
 
6049
- if (this.pathGeneratorFactoryCache[object.nodeName] === undefined) {
6050
- this.pathGeneratorFactoryCache[object.nodeName] = this.pathGeneratorFactory(object.nodeName);
6051
- }
5401
+ _proto.convertAABB2Rect = function convertAABB2Rect(aabb) {
5402
+ var min = aabb.getMin();
5403
+ var max = aabb.getMax(); // expand the rectangle a bit to avoid artifacts
5404
+ // @see https://www.yuque.com/antv/ou292n/bi8nix#ExvCu
5405
+
5406
+ var minX = Math.floor(min[0]);
5407
+ var minY = Math.floor(min[1]);
5408
+ var maxX = Math.ceil(max[0]);
5409
+ var maxY = Math.ceil(max[1]);
5410
+ var width = maxX - minX;
5411
+ var height = maxY - minY;
5412
+ return {
5413
+ x: minX,
5414
+ y: minY,
5415
+ width: width,
5416
+ height: height
5417
+ };
5418
+ }
5419
+ /**
5420
+ * TODO: merge dirty rectangles with some strategies.
5421
+ * For now, we just simply merge all the rectangles into one.
5422
+ * @see https://idom.me/articles/841.html
5423
+ */
5424
+ ;
6052
5425
 
6053
- var generatePath = this.pathGeneratorFactoryCache[object.nodeName];
5426
+ _proto.mergeDirtyAABBs = function mergeDirtyAABBs(dirtyObjects) {
5427
+ // merge into a big AABB
5428
+ var aabb = new g.AABB();
5429
+ dirtyObjects.forEach(function (object) {
5430
+ var renderBounds = object.getRenderBounds();
5431
+ aabb.add(renderBounds);
5432
+ var dirtyRenderBounds = object.renderable.dirtyRenderBounds;
6054
5433
 
6055
- if (generatePath) {
6056
- context.beginPath();
6057
- generatePath(context, object.parsedStyle);
5434
+ if (dirtyRenderBounds) {
5435
+ aabb.add(dirtyRenderBounds);
5436
+ }
5437
+ });
5438
+ return aabb;
5439
+ };
5440
+
5441
+ _proto.searchDirtyObjects = function searchDirtyObjects(dirtyRectangle) {
5442
+ var _this2 = this; // search in r-tree, get all affected nodes
6058
5443
 
6059
- if (object.nodeName !== g.Shape.LINE && object.nodeName !== g.Shape.PATH && object.nodeName !== g.Shape.POLYLINE) {
6060
- context.closePath();
6061
- }
6062
- } // fill & stroke
6063
5444
 
5445
+ var _dirtyRectangle$getMi = dirtyRectangle.getMin(),
5446
+ minX = _dirtyRectangle$getMi[0],
5447
+ minY = _dirtyRectangle$getMi[1];
6064
5448
 
6065
- if (styleRenderer) {
6066
- styleRenderer.render(context, object.parsedStyle, object, renderingService);
6067
- } // restore applied attributes, eg. shadowBlur shadowColor...
5449
+ var _dirtyRectangle$getMa = dirtyRectangle.getMax(),
5450
+ maxX = _dirtyRectangle$getMa[0],
5451
+ maxY = _dirtyRectangle$getMa[1];
6068
5452
 
5453
+ var rBushNodes = this.rBush.search({
5454
+ minX: minX,
5455
+ minY: minY,
5456
+ maxX: maxX,
5457
+ maxY: maxY
5458
+ });
5459
+ return rBushNodes.map(function (_ref3) {
5460
+ var id = _ref3.id;
5461
+ return _this2.displayObjectPool.getByEntity(id);
5462
+ });
5463
+ };
6069
5464
 
6070
- context.restore(); // finish rendering, clear dirty flag
5465
+ _proto.saveDirtyAABB = function saveDirtyAABB(object) {
5466
+ var renderable = object.renderable;
6071
5467
 
6072
- object.renderable.dirty = false;
6073
- this.restoreStack.push(object);
5468
+ if (!renderable.dirtyRenderBounds) {
5469
+ renderable.dirtyRenderBounds = new g.AABB();
6074
5470
  }
6075
- }, {
6076
- key: "shouldClearFullScreen",
6077
- value: function shouldClearFullScreen() {
6078
- var renderer = this.canvasConfig.renderer;
6079
5471
 
6080
- var _renderer$getConfig = renderer.getConfig(),
6081
- enableDirtyRectangleRendering = _renderer$getConfig.enableDirtyRectangleRendering;
5472
+ var renderBounds = object.getRenderBounds();
6082
5473
 
6083
- return !enableDirtyRectangleRendering || this.renderingContext.renderReasons.has(g.RenderReason.CAMERA_CHANGED);
5474
+ if (renderBounds) {
5475
+ // save last dirty aabb
5476
+ renderable.dirtyRenderBounds.update(renderBounds.center, renderBounds.halfExtents);
6084
5477
  }
6085
- }, {
6086
- key: "convertAABB2Rect",
6087
- value: function convertAABB2Rect(aabb) {
6088
- var min = aabb.getMin();
6089
- var max = aabb.getMax(); // expand the rectangle a bit to avoid artifacts
6090
- // @see https://www.yuque.com/antv/ou292n/bi8nix#ExvCu
5478
+ };
6091
5479
 
6092
- var minX = Math.floor(min[0]);
6093
- var minY = Math.floor(min[1]);
6094
- var maxX = Math.ceil(max[0]);
6095
- var maxY = Math.ceil(max[1]);
6096
- var width = maxX - minX;
6097
- var height = maxY - minY;
6098
- return {
6099
- x: minX,
6100
- y: minY,
6101
- width: width,
6102
- height: height
6103
- };
6104
- }
6105
- /**
6106
- * TODO: merge dirty rectangles with some strategies.
6107
- * For now, we just simply merge all the rectangles into one.
6108
- * @see https://idom.me/articles/841.html
6109
- */
6110
-
6111
- }, {
6112
- key: "mergeDirtyAABBs",
6113
- value: function mergeDirtyAABBs(dirtyObjects) {
6114
- // merge into a big AABB
6115
- var aabb = new g.AABB();
6116
- dirtyObjects.forEach(function (object) {
6117
- var renderBounds = object.getRenderBounds();
6118
- aabb.add(renderBounds);
6119
- var dirtyRenderBounds = object.renderable.dirtyRenderBounds;
6120
-
6121
- if (dirtyRenderBounds) {
6122
- aabb.add(dirtyRenderBounds);
6123
- }
6124
- });
6125
- return aabb;
6126
- }
6127
- }, {
6128
- key: "searchDirtyObjects",
6129
- value: function searchDirtyObjects(dirtyRectangle) {
6130
- var _this2 = this; // search in r-tree, get all affected nodes
5480
+ _proto.applyTransform = function applyTransform(context, transform) {
5481
+ var _mat4$getTranslation = getTranslation(create$2$1(), transform),
5482
+ tx = _mat4$getTranslation[0],
5483
+ ty = _mat4$getTranslation[1];
6131
5484
 
5485
+ var _mat4$getScaling = getScaling(create$2$1(), transform),
5486
+ sx = _mat4$getScaling[0],
5487
+ sy = _mat4$getScaling[1];
6132
5488
 
6133
- var _dirtyRectangle$getMi = dirtyRectangle.getMin(),
6134
- _dirtyRectangle$getMi2 = _slicedToArray$3(_dirtyRectangle$getMi, 2),
6135
- minX = _dirtyRectangle$getMi2[0],
6136
- minY = _dirtyRectangle$getMi2[1];
5489
+ var rotation = getRotation(create$4$1(), transform); // eslint-disable-next-line @typescript-eslint/no-unused-vars
6137
5490
 
6138
- var _dirtyRectangle$getMa = dirtyRectangle.getMax(),
6139
- _dirtyRectangle$getMa2 = _slicedToArray$3(_dirtyRectangle$getMa, 2),
6140
- maxX = _dirtyRectangle$getMa2[0],
6141
- maxY = _dirtyRectangle$getMa2[1];
5491
+ var _getEuler = g.getEuler(create$2$1(), rotation),
5492
+ eux = _getEuler[0],
5493
+ euy = _getEuler[1],
5494
+ euz = _getEuler[2]; // gimbal lock at 90 degrees
6142
5495
 
6143
- var rBushNodes = this.rBush.search({
6144
- minX: minX,
6145
- minY: minY,
6146
- maxX: maxX,
6147
- maxY: maxY
6148
- });
6149
- return rBushNodes.map(function (_ref3) {
6150
- var id = _ref3.id;
6151
- return _this2.displayObjectPool.getByEntity(id);
6152
- });
6153
- }
6154
- }, {
6155
- key: "saveDirtyAABB",
6156
- value: function saveDirtyAABB(object) {
6157
- var renderable = object.renderable;
6158
5496
 
6159
- if (!renderable.dirtyRenderBounds) {
6160
- renderable.dirtyRenderBounds = new g.AABB();
6161
- }
5497
+ var rts = g.fromRotationTranslationScale(eux || euz, tx, ty, sx, sy); // @see https://developer.mozilla.org/en-US/docs/Web/API/Canvas_API/Tutorial/Transformations
6162
5498
 
6163
- var renderBounds = object.getRenderBounds();
5499
+ context.transform(rts[0], rts[1], rts[3], rts[4], rts[6], rts[7]);
5500
+ };
6164
5501
 
6165
- if (renderBounds) {
6166
- // save last dirty aabb
6167
- renderable.dirtyRenderBounds.update(renderBounds.center, renderBounds.halfExtents);
6168
- }
6169
- }
6170
- }, {
6171
- key: "applyTransform",
6172
- value: function applyTransform(context, transform) {
6173
- var _mat4$getTranslation = getTranslation(create$2$1(), transform),
6174
- _mat4$getTranslation2 = _slicedToArray$3(_mat4$getTranslation, 2),
6175
- tx = _mat4$getTranslation2[0],
6176
- ty = _mat4$getTranslation2[1];
6177
-
6178
- var _mat4$getScaling = getScaling(create$2$1(), transform),
6179
- _mat4$getScaling2 = _slicedToArray$3(_mat4$getScaling, 2),
6180
- sx = _mat4$getScaling2[0],
6181
- sy = _mat4$getScaling2[1];
6182
-
6183
- var rotation = getRotation(create$4$1(), transform); // eslint-disable-next-line @typescript-eslint/no-unused-vars
6184
-
6185
- var _getEuler = g.getEuler(create$2$1(), rotation),
6186
- _getEuler2 = _slicedToArray$3(_getEuler, 3),
6187
- eux = _getEuler2[0],
6188
- euy = _getEuler2[1],
6189
- euz = _getEuler2[2]; // gimbal lock at 90 degrees
6190
-
6191
-
6192
- var rts = g.fromRotationTranslationScale(eux || euz, tx, ty, sx, sy); // @see https://developer.mozilla.org/en-US/docs/Web/API/Canvas_API/Tutorial/Transformations
6193
-
6194
- context.transform(rts[0], rts[1], rts[3], rts[4], rts[6], rts[7]);
6195
- }
6196
- }, {
6197
- key: "applyAttributesToContext",
6198
- value: function applyAttributesToContext(context, object) {
6199
- var _object$parsedStyle = object.parsedStyle,
6200
- stroke = _object$parsedStyle.stroke,
6201
- fill = _object$parsedStyle.fill,
6202
- opacity = _object$parsedStyle.opacity,
6203
- lineDash = _object$parsedStyle.lineDash,
6204
- lineDashOffset = _object$parsedStyle.lineDashOffset,
6205
- filter = _object$parsedStyle.filter,
6206
- shadowColor = _object$parsedStyle.shadowColor,
6207
- shadowBlur = _object$parsedStyle.shadowBlur,
6208
- shadowOffsetX = _object$parsedStyle.shadowOffsetX,
6209
- shadowOffsetY = _object$parsedStyle.shadowOffsetY; // @see https://developer.mozilla.org/zh-CN/docs/Web/API/CanvasRenderingContext2D/setLineDash
6210
-
6211
- if (lineDash && Array.isArray(lineDash)) {
6212
- context.setLineDash(lineDash.map(function (segment) {
6213
- return segment.value;
6214
- }));
6215
- } // @see https://developer.mozilla.org/zh-CN/docs/Web/API/CanvasRenderingContext2D/lineDashOffset
6216
-
6217
-
6218
- if (!g.isNil(lineDashOffset)) {
6219
- context.lineDashOffset = lineDashOffset.value;
6220
- }
5502
+ _proto.applyAttributesToContext = function applyAttributesToContext(context, object) {
5503
+ var _object$parsedStyle = object.parsedStyle,
5504
+ stroke = _object$parsedStyle.stroke,
5505
+ fill = _object$parsedStyle.fill,
5506
+ opacity = _object$parsedStyle.opacity,
5507
+ lineDash = _object$parsedStyle.lineDash,
5508
+ lineDashOffset = _object$parsedStyle.lineDashOffset,
5509
+ filter = _object$parsedStyle.filter,
5510
+ shadowColor = _object$parsedStyle.shadowColor,
5511
+ shadowBlur = _object$parsedStyle.shadowBlur,
5512
+ shadowOffsetX = _object$parsedStyle.shadowOffsetX,
5513
+ shadowOffsetY = _object$parsedStyle.shadowOffsetY; // @see https://developer.mozilla.org/zh-CN/docs/Web/API/CanvasRenderingContext2D/setLineDash
5514
+
5515
+ if (lineDash && Array.isArray(lineDash)) {
5516
+ context.setLineDash(lineDash.map(function (segment) {
5517
+ return segment.value;
5518
+ }));
5519
+ } // @see https://developer.mozilla.org/zh-CN/docs/Web/API/CanvasRenderingContext2D/lineDashOffset
6221
5520
 
6222
- if (!g.isNil(opacity)) {
6223
- context.globalAlpha *= opacity.value;
6224
- }
6225
5521
 
6226
- if (!g.isNil(stroke) && !Array.isArray(stroke) && !stroke.isNone) {
6227
- context.strokeStyle = object.attributes.stroke;
6228
- }
5522
+ if (!g.isNil(lineDashOffset)) {
5523
+ context.lineDashOffset = lineDashOffset.value;
5524
+ }
6229
5525
 
6230
- if (!g.isNil(fill) && !Array.isArray(fill) && !fill.isNone) {
6231
- context.fillStyle = object.attributes.fill;
6232
- }
5526
+ if (!g.isNil(opacity)) {
5527
+ context.globalAlpha *= opacity.value;
5528
+ }
6233
5529
 
6234
- if (!g.isNil(filter)) {
6235
- // use raw filter string
6236
- context.filter = object.style.filter;
6237
- }
5530
+ if (!g.isNil(stroke) && !Array.isArray(stroke) && !stroke.isNone) {
5531
+ context.strokeStyle = object.attributes.stroke;
5532
+ }
6238
5533
 
6239
- if (!g.isNil(shadowColor)) {
6240
- context.shadowColor = shadowColor.toString();
6241
- context.shadowBlur = shadowBlur && shadowBlur.value || 0;
6242
- context.shadowOffsetX = shadowOffsetX && shadowOffsetX.value || 0;
6243
- context.shadowOffsetY = shadowOffsetY && shadowOffsetY.value || 0;
6244
- }
5534
+ if (!g.isNil(fill) && !Array.isArray(fill) && !fill.isNone) {
5535
+ context.fillStyle = object.attributes.fill;
6245
5536
  }
6246
- }, {
6247
- key: "useAnchor",
6248
- value: function useAnchor(context, object) {
6249
- var _ref4 = object.parsedStyle || {},
6250
- anchor = _ref4.anchor;
6251
5537
 
6252
- if (!anchor || anchor[0].value === 0 && anchor[1].value === 0) {
6253
- return;
6254
- }
5538
+ if (!g.isNil(filter)) {
5539
+ // use raw filter string
5540
+ context.filter = object.style.filter;
5541
+ }
6255
5542
 
6256
- var contentBounds = object.getGeometryBounds();
5543
+ if (!g.isNil(shadowColor)) {
5544
+ context.shadowColor = shadowColor.toString();
5545
+ context.shadowBlur = shadowBlur && shadowBlur.value || 0;
5546
+ context.shadowOffsetX = shadowOffsetX && shadowOffsetX.value || 0;
5547
+ context.shadowOffsetY = shadowOffsetY && shadowOffsetY.value || 0;
5548
+ }
5549
+ };
6257
5550
 
6258
- if (contentBounds) {
6259
- var halfExtents = contentBounds.halfExtents; // apply anchor, use true size, not include stroke,
6260
- // eg. bounds = true size + half lineWidth
5551
+ _proto.useAnchor = function useAnchor(context, object) {
5552
+ var _ref4 = object.parsedStyle || {},
5553
+ anchor = _ref4.anchor;
6261
5554
 
6262
- context.translate(-anchor[0].value * halfExtents[0] * 2, -anchor[1].value * halfExtents[1] * 2);
6263
- }
5555
+ var bounds = object.getGeometryBounds();
5556
+ var width = bounds && bounds.halfExtents[0] * 2 || 0;
5557
+ var height = bounds && bounds.halfExtents[1] * 2 || 0;
5558
+ var tx = -((anchor && anchor[0].value || 0) * width);
5559
+ var ty = -((anchor && anchor[1].value || 0) * height);
5560
+
5561
+ if (tx !== 0 || ty !== 0) {
5562
+ // apply anchor, use true size, not include stroke,
5563
+ // eg. bounds = true size + half lineWidth
5564
+ context.translate(tx, ty);
6264
5565
  }
6265
- }, {
6266
- key: "safeMergeAABB",
6267
- value: function safeMergeAABB() {
6268
- var merged = new g.AABB();
5566
+ };
6269
5567
 
6270
- for (var _len = arguments.length, aabbs = new Array(_len), _key = 0; _key < _len; _key++) {
6271
- aabbs[_key] = arguments[_key];
6272
- }
5568
+ _proto.safeMergeAABB = function safeMergeAABB() {
5569
+ var merged = new g.AABB();
6273
5570
 
6274
- aabbs.forEach(function (aabb) {
6275
- merged.add(aabb);
6276
- });
6277
- return merged;
5571
+ for (var _len = arguments.length, aabbs = new Array(_len), _key = 0; _key < _len; _key++) {
5572
+ aabbs[_key] = arguments[_key];
6278
5573
  }
6279
- }]);
5574
+
5575
+ aabbs.forEach(function (aabb) {
5576
+ merged.add(aabb);
5577
+ });
5578
+ return merged;
5579
+ };
6280
5580
 
6281
5581
  return CanvasRendererPlugin;
6282
5582
  }(), _class$2.tag = 'CanvasRenderer', _class$2);
@@ -6312,7 +5612,7 @@
6312
5612
  register(PolylineRenderer);
6313
5613
  register(PolygonRenderer);
6314
5614
  register(PathRenderer);
6315
- 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);
5615
+ 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);
6316
5616
  register({
6317
5617
  token: StyleRendererFactory,
6318
5618
  useFactory: function useFactory(ctx) {
@@ -6332,22 +5632,18 @@
6332
5632
 
6333
5633
  var Plugin$3 = /*#__PURE__*/function () {
6334
5634
  function Plugin() {
6335
- _classCallCheck$4(this, Plugin);
6336
-
6337
5635
  this.name = 'canvas-renderer';
6338
5636
  }
6339
5637
 
6340
- _createClass$4(Plugin, [{
6341
- key: "init",
6342
- value: function init(container) {
6343
- container.load(containerModule$3, true);
6344
- }
6345
- }, {
6346
- key: "destroy",
6347
- value: function destroy(container) {
6348
- container.unload(containerModule$3);
6349
- }
6350
- }]);
5638
+ var _proto = Plugin.prototype;
5639
+
5640
+ _proto.init = function init(container) {
5641
+ container.load(containerModule$3, true);
5642
+ };
5643
+
5644
+ _proto.destroy = function destroy(container) {
5645
+ container.unload(containerModule$3);
5646
+ };
6351
5647
 
6352
5648
  return Plugin;
6353
5649
  }();
@@ -6501,7 +5797,7 @@
6501
5797
  if ("throw" !== record.type) {
6502
5798
  var result = record.arg,
6503
5799
  value = result.value;
6504
- return value && "object" == _typeof(value) && hasOwn.call(value, "__await") ? PromiseImpl.resolve(value.__await).then(function (value) {
5800
+ return value && "object" == typeof value && hasOwn.call(value, "__await") ? PromiseImpl.resolve(value.__await).then(function (value) {
6505
5801
  invoke("next", value, resolve, reject);
6506
5802
  }, function (err) {
6507
5803
  invoke("throw", err, resolve, reject);
@@ -6762,31 +6058,6 @@
6762
6058
  };
6763
6059
  }
6764
6060
 
6765
- function _classCallCheck$5(instance, Constructor) {
6766
- if (!(instance instanceof Constructor)) {
6767
- throw new TypeError("Cannot call a class as a function");
6768
- }
6769
- }
6770
-
6771
- function _defineProperties$5(target, props) {
6772
- for (var i = 0; i < props.length; i++) {
6773
- var descriptor = props[i];
6774
- descriptor.enumerable = descriptor.enumerable || false;
6775
- descriptor.configurable = true;
6776
- if ("value" in descriptor) descriptor.writable = true;
6777
- Object.defineProperty(target, descriptor.key, descriptor);
6778
- }
6779
- }
6780
-
6781
- function _createClass$5(Constructor, protoProps, staticProps) {
6782
- if (protoProps) _defineProperties$5(Constructor.prototype, protoProps);
6783
- if (staticProps) _defineProperties$5(Constructor, staticProps);
6784
- Object.defineProperty(Constructor, "prototype", {
6785
- writable: false
6786
- });
6787
- return Constructor;
6788
- }
6789
-
6790
6061
  var _class$3;
6791
6062
 
6792
6063
  var DOMInteractionPlugin_1;
@@ -6796,150 +6067,147 @@
6796
6067
 
6797
6068
  var DOMInteractionPlugin = DOMInteractionPlugin_1 = (_class$3 = /*#__PURE__*/function () {
6798
6069
  function DOMInteractionPlugin() {
6799
- _classCallCheck$5(this, DOMInteractionPlugin);
6800
-
6801
6070
  this.contextService = void 0;
6802
6071
  this.renderingContext = void 0;
6803
6072
  }
6804
6073
 
6805
- _createClass$5(DOMInteractionPlugin, [{
6806
- key: "apply",
6807
- value: function apply(renderingService) {
6808
- var _this = this;
6074
+ var _proto = DOMInteractionPlugin.prototype;
6809
6075
 
6810
- var canvas = this.renderingContext.root.ownerDocument.defaultView; // const SUPPORT_ONLY_TOUCH = canvas.supportsTouchEvents && MOBILE_REGEX.test(navigator.userAgent);
6811
-
6812
- var onPointerMove = function onPointerMove(ev) {
6813
- renderingService.hooks.pointerMove.call(ev);
6814
- };
6076
+ _proto.apply = function apply(renderingService) {
6077
+ var _this = this;
6815
6078
 
6816
- var onPointerUp = function onPointerUp(ev) {
6817
- renderingService.hooks.pointerUp.call(ev);
6818
- };
6079
+ var canvas = this.renderingContext.root.ownerDocument.defaultView; // const SUPPORT_ONLY_TOUCH = canvas.supportsTouchEvents && MOBILE_REGEX.test(navigator.userAgent);
6819
6080
 
6820
- var onPointerDown = function onPointerDown(ev) {
6821
- renderingService.hooks.pointerDown.call(ev);
6822
- };
6081
+ var onPointerMove = function onPointerMove(ev) {
6082
+ renderingService.hooks.pointerMove.call(ev);
6083
+ };
6823
6084
 
6824
- var onPointerOver = function onPointerOver(ev) {
6825
- renderingService.hooks.pointerOver.call(ev);
6826
- };
6085
+ var onPointerUp = function onPointerUp(ev) {
6086
+ renderingService.hooks.pointerUp.call(ev);
6087
+ };
6827
6088
 
6828
- var onPointerOut = function onPointerOut(ev) {
6829
- renderingService.hooks.pointerOut.call(ev);
6830
- };
6089
+ var onPointerDown = function onPointerDown(ev) {
6090
+ renderingService.hooks.pointerDown.call(ev);
6091
+ };
6831
6092
 
6832
- var onPointerCancel = function onPointerCancel(ev) {
6833
- renderingService.hooks.pointerCancel.call(ev);
6834
- };
6093
+ var onPointerOver = function onPointerOver(ev) {
6094
+ renderingService.hooks.pointerOver.call(ev);
6095
+ };
6835
6096
 
6836
- var onPointerWheel = function onPointerWheel(ev) {
6837
- renderingService.hooks.pointerWheel.call(ev);
6838
- };
6097
+ var onPointerOut = function onPointerOut(ev) {
6098
+ renderingService.hooks.pointerOut.call(ev);
6099
+ };
6839
6100
 
6840
- var addPointerEventListener = function addPointerEventListener($el) {
6841
- globalThis.document.addEventListener('pointermove', onPointerMove, true);
6842
- $el.addEventListener('pointerdown', onPointerDown, true);
6843
- $el.addEventListener('pointerleave', onPointerOut, true);
6844
- $el.addEventListener('pointerover', onPointerOver, true);
6845
- globalThis.addEventListener('pointerup', onPointerUp, true);
6846
- };
6101
+ var onPointerCancel = function onPointerCancel(ev) {
6102
+ renderingService.hooks.pointerCancel.call(ev);
6103
+ };
6847
6104
 
6848
- var addTouchEventListener = function addTouchEventListener($el) {
6849
- $el.addEventListener('touchstart', onPointerDown, true);
6850
- $el.addEventListener('touchend', onPointerUp, true);
6851
- $el.addEventListener('touchmove', onPointerMove, true);
6852
- $el.addEventListener('touchcancel', onPointerCancel, true);
6853
- };
6105
+ var onPointerWheel = function onPointerWheel(ev) {
6106
+ renderingService.hooks.pointerWheel.call(ev);
6107
+ };
6854
6108
 
6855
- var addMouseEventListener = function addMouseEventListener($el) {
6856
- globalThis.document.addEventListener('mousemove', onPointerMove, true);
6857
- $el.addEventListener('mousedown', onPointerDown, true);
6858
- $el.addEventListener('mouseout', onPointerOut, true);
6859
- $el.addEventListener('mouseover', onPointerOver, true);
6860
- globalThis.addEventListener('mouseup', onPointerUp, true);
6861
- };
6109
+ var addPointerEventListener = function addPointerEventListener($el) {
6110
+ globalThis.document.addEventListener('pointermove', onPointerMove, true);
6111
+ $el.addEventListener('pointerdown', onPointerDown, true);
6112
+ $el.addEventListener('pointerleave', onPointerOut, true);
6113
+ $el.addEventListener('pointerover', onPointerOver, true);
6114
+ globalThis.addEventListener('pointerup', onPointerUp, true);
6115
+ };
6862
6116
 
6863
- var removePointerEventListener = function removePointerEventListener($el) {
6864
- globalThis.document.removeEventListener('pointermove', onPointerMove, true);
6865
- $el.removeEventListener('pointerdown', onPointerDown, true);
6866
- $el.removeEventListener('pointerleave', onPointerOut, true);
6867
- $el.removeEventListener('pointerover', onPointerOver, true);
6868
- globalThis.removeEventListener('pointerup', onPointerUp, true);
6869
- };
6117
+ var addTouchEventListener = function addTouchEventListener($el) {
6118
+ $el.addEventListener('touchstart', onPointerDown, true);
6119
+ $el.addEventListener('touchend', onPointerUp, true);
6120
+ $el.addEventListener('touchmove', onPointerMove, true);
6121
+ $el.addEventListener('touchcancel', onPointerCancel, true);
6122
+ };
6870
6123
 
6871
- var removeTouchEventListener = function removeTouchEventListener($el) {
6872
- $el.removeEventListener('touchstart', onPointerDown, true);
6873
- $el.removeEventListener('touchend', onPointerUp, true);
6874
- $el.removeEventListener('touchmove', onPointerMove, true);
6875
- };
6124
+ var addMouseEventListener = function addMouseEventListener($el) {
6125
+ globalThis.document.addEventListener('mousemove', onPointerMove, true);
6126
+ $el.addEventListener('mousedown', onPointerDown, true);
6127
+ $el.addEventListener('mouseout', onPointerOut, true);
6128
+ $el.addEventListener('mouseover', onPointerOver, true);
6129
+ globalThis.addEventListener('mouseup', onPointerUp, true);
6130
+ };
6876
6131
 
6877
- var removeMouseEventListener = function removeMouseEventListener($el) {
6878
- globalThis.document.removeEventListener('mousemove', onPointerMove, true);
6879
- $el.removeEventListener('mousedown', onPointerDown, true);
6880
- $el.removeEventListener('mouseout', onPointerOut, true);
6881
- $el.removeEventListener('mouseover', onPointerOver, true);
6882
- globalThis.removeEventListener('mouseup', onPointerUp, true);
6883
- };
6132
+ var removePointerEventListener = function removePointerEventListener($el) {
6133
+ globalThis.document.removeEventListener('pointermove', onPointerMove, true);
6134
+ $el.removeEventListener('pointerdown', onPointerDown, true);
6135
+ $el.removeEventListener('pointerleave', onPointerOut, true);
6136
+ $el.removeEventListener('pointerover', onPointerOver, true);
6137
+ globalThis.removeEventListener('pointerup', onPointerUp, true);
6138
+ };
6884
6139
 
6885
- renderingService.hooks.init.tapPromise(DOMInteractionPlugin_1.tag, /*#__PURE__*/_asyncToGenerator$4( /*#__PURE__*/_regeneratorRuntime$4().mark(function _callee() {
6886
- var $el;
6887
- return _regeneratorRuntime$4().wrap(function _callee$(_context) {
6888
- while (1) {
6889
- switch (_context.prev = _context.next) {
6890
- case 0:
6891
- $el = _this.contextService.getDomElement(); // @ts-ignore
6140
+ var removeTouchEventListener = function removeTouchEventListener($el) {
6141
+ $el.removeEventListener('touchstart', onPointerDown, true);
6142
+ $el.removeEventListener('touchend', onPointerUp, true);
6143
+ $el.removeEventListener('touchmove', onPointerMove, true);
6144
+ };
6892
6145
 
6893
- if (globalThis.navigator.msPointerEnabled) {
6894
- // @ts-ignore
6895
- $el.style.msContentZooming = 'none'; // @ts-ignore
6146
+ var removeMouseEventListener = function removeMouseEventListener($el) {
6147
+ globalThis.document.removeEventListener('mousemove', onPointerMove, true);
6148
+ $el.removeEventListener('mousedown', onPointerDown, true);
6149
+ $el.removeEventListener('mouseout', onPointerOut, true);
6150
+ $el.removeEventListener('mouseover', onPointerOver, true);
6151
+ globalThis.removeEventListener('mouseup', onPointerUp, true);
6152
+ };
6896
6153
 
6897
- $el.style.msTouchAction = 'none';
6898
- } else if (canvas.supportsPointerEvents) {
6899
- $el.style.touchAction = 'none';
6900
- }
6154
+ renderingService.hooks.init.tapPromise(DOMInteractionPlugin_1.tag, /*#__PURE__*/_asyncToGenerator$4( /*#__PURE__*/_regeneratorRuntime$4().mark(function _callee() {
6155
+ var $el;
6156
+ return _regeneratorRuntime$4().wrap(function _callee$(_context) {
6157
+ while (1) {
6158
+ switch (_context.prev = _context.next) {
6159
+ case 0:
6160
+ $el = _this.contextService.getDomElement(); // @ts-ignore
6161
+
6162
+ if (globalThis.navigator.msPointerEnabled) {
6163
+ // @ts-ignore
6164
+ $el.style.msContentZooming = 'none'; // @ts-ignore
6165
+
6166
+ $el.style.msTouchAction = 'none';
6167
+ } else if (canvas.supportsPointerEvents) {
6168
+ $el.style.touchAction = 'none';
6169
+ }
6901
6170
 
6902
- if (canvas.supportsPointerEvents) {
6903
- addPointerEventListener($el);
6904
- } else {
6905
- addMouseEventListener($el);
6906
- }
6171
+ if (canvas.supportsPointerEvents) {
6172
+ addPointerEventListener($el);
6173
+ } else {
6174
+ addMouseEventListener($el);
6175
+ }
6907
6176
 
6908
- if (canvas.supportsTouchEvents) {
6909
- addTouchEventListener($el);
6910
- } // use passive event listeners
6911
- // @see https://zhuanlan.zhihu.com/p/24555031
6177
+ if (canvas.supportsTouchEvents) {
6178
+ addTouchEventListener($el);
6179
+ } // use passive event listeners
6180
+ // @see https://zhuanlan.zhihu.com/p/24555031
6912
6181
 
6913
6182
 
6914
- $el.addEventListener('wheel', onPointerWheel, {
6915
- passive: true,
6916
- capture: true
6917
- });
6183
+ $el.addEventListener('wheel', onPointerWheel, {
6184
+ passive: true,
6185
+ capture: true
6186
+ });
6918
6187
 
6919
- case 5:
6920
- case "end":
6921
- return _context.stop();
6922
- }
6188
+ case 5:
6189
+ case "end":
6190
+ return _context.stop();
6923
6191
  }
6924
- }, _callee);
6925
- })));
6926
- renderingService.hooks.destroy.tap(DOMInteractionPlugin_1.tag, function () {
6927
- var $el = _this.contextService.getDomElement();
6928
-
6929
- if (canvas.supportsPointerEvents) {
6930
- removePointerEventListener($el);
6931
- } else {
6932
- removeMouseEventListener($el);
6933
6192
  }
6193
+ }, _callee);
6194
+ })));
6195
+ renderingService.hooks.destroy.tap(DOMInteractionPlugin_1.tag, function () {
6196
+ var $el = _this.contextService.getDomElement();
6934
6197
 
6935
- if (canvas.supportsTouchEvents) {
6936
- removeTouchEventListener($el);
6937
- }
6198
+ if (canvas.supportsPointerEvents) {
6199
+ removePointerEventListener($el);
6200
+ } else {
6201
+ removeMouseEventListener($el);
6202
+ }
6938
6203
 
6939
- $el.removeEventListener('wheel', onPointerWheel, true);
6940
- });
6941
- }
6942
- }]);
6204
+ if (canvas.supportsTouchEvents) {
6205
+ removeTouchEventListener($el);
6206
+ }
6207
+
6208
+ $el.removeEventListener('wheel', onPointerWheel, true);
6209
+ });
6210
+ };
6943
6211
 
6944
6212
  return DOMInteractionPlugin;
6945
6213
  }(), _class$3.tag = 'DOMInteraction', _class$3);
@@ -6957,22 +6225,18 @@
6957
6225
 
6958
6226
  var Plugin$4 = /*#__PURE__*/function () {
6959
6227
  function Plugin() {
6960
- _classCallCheck$5(this, Plugin);
6961
-
6962
6228
  this.name = 'dom-interaction';
6963
6229
  }
6964
6230
 
6965
- _createClass$5(Plugin, [{
6966
- key: "init",
6967
- value: function init(container) {
6968
- container.load(containerModule$4, true);
6969
- }
6970
- }, {
6971
- key: "destroy",
6972
- value: function destroy(container) {
6973
- container.unload(containerModule$4);
6974
- }
6975
- }]);
6231
+ var _proto = Plugin.prototype;
6232
+
6233
+ _proto.init = function init(container) {
6234
+ container.load(containerModule$4, true);
6235
+ };
6236
+
6237
+ _proto.destroy = function destroy(container) {
6238
+ container.unload(containerModule$4);
6239
+ };
6976
6240
 
6977
6241
  return Plugin;
6978
6242
  }();
@@ -7107,7 +6371,7 @@
7107
6371
  if ("throw" !== record.type) {
7108
6372
  var result = record.arg,
7109
6373
  value = result.value;
7110
- return value && "object" == _typeof(value) && hasOwn.call(value, "__await") ? PromiseImpl.resolve(value.__await).then(function (value) {
6374
+ return value && "object" == typeof value && hasOwn.call(value, "__await") ? PromiseImpl.resolve(value.__await).then(function (value) {
7111
6375
  invoke("next", value, resolve, reject);
7112
6376
  }, function (err) {
7113
6377
  invoke("throw", err, resolve, reject);
@@ -7368,271 +6632,240 @@
7368
6632
  };
7369
6633
  }
7370
6634
 
7371
- function _classCallCheck$6(instance, Constructor) {
7372
- if (!(instance instanceof Constructor)) {
7373
- throw new TypeError("Cannot call a class as a function");
7374
- }
7375
- }
7376
-
7377
- function _defineProperties$6(target, props) {
7378
- for (var i = 0; i < props.length; i++) {
7379
- var descriptor = props[i];
7380
- descriptor.enumerable = descriptor.enumerable || false;
7381
- descriptor.configurable = true;
7382
- if ("value" in descriptor) descriptor.writable = true;
7383
- Object.defineProperty(target, descriptor.key, descriptor);
7384
- }
7385
- }
7386
-
7387
- function _createClass$6(Constructor, protoProps, staticProps) {
7388
- if (protoProps) _defineProperties$6(Constructor.prototype, protoProps);
7389
- if (staticProps) _defineProperties$6(Constructor, staticProps);
7390
- Object.defineProperty(Constructor, "prototype", {
7391
- writable: false
7392
- });
7393
- return Constructor;
7394
- }
7395
-
7396
6635
  var _class$4;
7397
6636
 
7398
6637
  var HTMLRenderingPlugin_1;
7399
6638
  var HTML_PREFIX = 'g-html-';
7400
6639
  var HTMLRenderingPlugin = HTMLRenderingPlugin_1 = (_class$4 = /*#__PURE__*/function () {
7401
6640
  function HTMLRenderingPlugin() {
7402
- _classCallCheck$6(this, HTMLRenderingPlugin);
7403
-
7404
6641
  this.contextService = void 0;
7405
6642
  this.renderingContext = void 0;
7406
6643
  this.canvasConfig = void 0;
7407
6644
  this.$camera = void 0;
7408
6645
  }
7409
6646
 
7410
- _createClass$6(HTMLRenderingPlugin, [{
7411
- key: "apply",
7412
- value: function apply(renderingService) {
7413
- var _this = this;
6647
+ var _proto = HTMLRenderingPlugin.prototype;
7414
6648
 
7415
- var handleMounted = function handleMounted(e) {
7416
- var object = e.target;
6649
+ _proto.apply = function apply(renderingService) {
6650
+ var _this = this;
7417
6651
 
7418
- if (object.nodeName === g.Shape.HTML) {
7419
- var $el = _this.getOrCreateEl(object); // apply documentElement's style
6652
+ var handleMounted = function handleMounted(e) {
6653
+ var object = e.target;
7420
6654
 
6655
+ if (object.nodeName === g.Shape.HTML) {
6656
+ var $el = _this.getOrCreateEl(object); // apply documentElement's style
7421
6657
 
7422
- var attributes = object.ownerDocument.documentElement.attributes;
7423
- Object.keys(attributes).forEach(function (name) {
7424
- $el.style[name] = attributes[name];
7425
- });
7426
- Object.keys(object.attributes).forEach(function (name) {
7427
- _this.updateAttribute(name, object);
7428
- });
7429
- }
7430
- };
7431
6658
 
7432
- var handleUnmounted = function handleUnmounted(e) {
7433
- var object = e.target;
6659
+ var attributes = object.ownerDocument.documentElement.attributes;
6660
+ Object.keys(attributes).forEach(function (name) {
6661
+ $el.style[name] = attributes[name];
6662
+ });
6663
+ Object.keys(object.attributes).forEach(function (name) {
6664
+ _this.updateAttribute(name, object);
6665
+ });
6666
+ }
6667
+ };
7434
6668
 
7435
- if (object.nodeName === g.Shape.HTML) {
7436
- var existedId = _this.getId(object);
6669
+ var handleUnmounted = function handleUnmounted(e) {
6670
+ var object = e.target;
7437
6671
 
7438
- var $container = _this.contextService.getDomElement().parentNode;
6672
+ if (object.nodeName === g.Shape.HTML) {
6673
+ var existedId = _this.getId(object);
7439
6674
 
7440
- if ($container) {
7441
- var $existedElement = $container.querySelector('#' + existedId);
6675
+ var $container = _this.contextService.getDomElement().parentNode;
7442
6676
 
7443
- if ($existedElement) {
7444
- $container.removeChild($existedElement);
7445
- }
6677
+ if ($container) {
6678
+ var $existedElement = $container.querySelector('#' + existedId);
6679
+
6680
+ if ($existedElement) {
6681
+ $container.removeChild($existedElement);
7446
6682
  }
7447
6683
  }
7448
- };
6684
+ }
6685
+ };
7449
6686
 
7450
- var handleAttributeChanged = function handleAttributeChanged(e) {
7451
- var object = e.target;
6687
+ var handleAttributeChanged = function handleAttributeChanged(e) {
6688
+ var object = e.target;
7452
6689
 
7453
- if (object.nodeName === g.Shape.HTML) {
7454
- var attrName = e.attrName;
6690
+ if (object.nodeName === g.Shape.HTML) {
6691
+ var attrName = e.attrName;
7455
6692
 
7456
- _this.updateAttribute(attrName, object);
7457
- }
7458
- };
6693
+ _this.updateAttribute(attrName, object);
6694
+ }
6695
+ };
7459
6696
 
7460
- renderingService.hooks.init.tapPromise(HTMLRenderingPlugin_1.tag, /*#__PURE__*/_asyncToGenerator$5( /*#__PURE__*/_regeneratorRuntime$5().mark(function _callee() {
7461
- return _regeneratorRuntime$5().wrap(function _callee$(_context) {
7462
- while (1) {
7463
- switch (_context.prev = _context.next) {
7464
- case 0:
7465
- _this.renderingContext.root.addEventListener(g.ElementEvent.MOUNTED, handleMounted);
6697
+ renderingService.hooks.init.tapPromise(HTMLRenderingPlugin_1.tag, /*#__PURE__*/_asyncToGenerator$5( /*#__PURE__*/_regeneratorRuntime$5().mark(function _callee() {
6698
+ return _regeneratorRuntime$5().wrap(function _callee$(_context) {
6699
+ while (1) {
6700
+ switch (_context.prev = _context.next) {
6701
+ case 0:
6702
+ _this.renderingContext.root.addEventListener(g.ElementEvent.MOUNTED, handleMounted);
7466
6703
 
7467
- _this.renderingContext.root.addEventListener(g.ElementEvent.UNMOUNTED, handleUnmounted);
6704
+ _this.renderingContext.root.addEventListener(g.ElementEvent.UNMOUNTED, handleUnmounted);
7468
6705
 
7469
- _this.renderingContext.root.addEventListener(g.ElementEvent.ATTR_MODIFIED, handleAttributeChanged);
6706
+ _this.renderingContext.root.addEventListener(g.ElementEvent.ATTR_MODIFIED, handleAttributeChanged);
7470
6707
 
7471
- case 3:
7472
- case "end":
7473
- return _context.stop();
7474
- }
6708
+ case 3:
6709
+ case "end":
6710
+ return _context.stop();
7475
6711
  }
7476
- }, _callee);
7477
- })));
7478
- renderingService.hooks.destroy.tap(HTMLRenderingPlugin_1.tag, function () {
7479
- _this.renderingContext.root.removeEventListener(g.ElementEvent.MOUNTED, handleMounted);
6712
+ }
6713
+ }, _callee);
6714
+ })));
6715
+ renderingService.hooks.destroy.tap(HTMLRenderingPlugin_1.tag, function () {
6716
+ _this.renderingContext.root.removeEventListener(g.ElementEvent.MOUNTED, handleMounted);
7480
6717
 
7481
- _this.renderingContext.root.removeEventListener(g.ElementEvent.UNMOUNTED, handleUnmounted);
6718
+ _this.renderingContext.root.removeEventListener(g.ElementEvent.UNMOUNTED, handleUnmounted);
7482
6719
 
7483
- _this.renderingContext.root.removeEventListener(g.ElementEvent.ATTR_MODIFIED, handleAttributeChanged);
7484
- });
7485
- }
7486
- }, {
7487
- key: "getId",
7488
- value: function getId(object) {
7489
- return object.id || HTML_PREFIX + object.entity;
7490
- }
7491
- }, {
7492
- key: "getOrCreateEl",
7493
- value: function getOrCreateEl(object) {
7494
- var doc = this.canvasConfig.document;
7495
- var existedId = this.getId(object);
7496
- var $container = this.contextService.getDomElement().parentNode;
6720
+ _this.renderingContext.root.removeEventListener(g.ElementEvent.ATTR_MODIFIED, handleAttributeChanged);
6721
+ });
6722
+ };
7497
6723
 
7498
- if ($container) {
7499
- var $existedElement = $container.querySelector('#' + existedId);
6724
+ _proto.getId = function getId(object) {
6725
+ return object.id || HTML_PREFIX + object.entity;
6726
+ };
7500
6727
 
7501
- if (!$existedElement) {
7502
- $existedElement = (doc || document).createElement('div');
7503
- object.parsedStyle.$el = $existedElement;
7504
- $existedElement.id = existedId;
6728
+ _proto.getOrCreateEl = function getOrCreateEl(object) {
6729
+ var doc = this.canvasConfig.document;
6730
+ var existedId = this.getId(object);
6731
+ var $container = this.contextService.getDomElement().parentNode;
7505
6732
 
7506
- if (object.name) {
7507
- $existedElement.setAttribute('name', object.name);
7508
- }
6733
+ if ($container) {
6734
+ var $existedElement = $container.querySelector('#' + existedId);
7509
6735
 
7510
- if (object.className) {
7511
- $existedElement.className = object.className;
7512
- }
6736
+ if (!$existedElement) {
6737
+ $existedElement = (doc || document).createElement('div');
6738
+ object.parsedStyle.$el = $existedElement;
6739
+ $existedElement.id = existedId;
7513
6740
 
7514
- $container.appendChild($existedElement); // use absolute position
6741
+ if (object.name) {
6742
+ $existedElement.setAttribute('name', object.name);
6743
+ }
7515
6744
 
7516
- $existedElement.style.position = 'absolute';
7517
- $existedElement.style.left = '0';
7518
- $existedElement.style.top = '0';
7519
- $existedElement.style['will-change'] = 'transform';
7520
- var worldTransform = object.getWorldTransform();
7521
- $existedElement.style.transform = "matrix(".concat([worldTransform[0], worldTransform[1], worldTransform[4], worldTransform[5], worldTransform[12], worldTransform[13]].join(','), ")");
6745
+ if (object.className) {
6746
+ $existedElement.className = object.className;
7522
6747
  }
7523
6748
 
7524
- return $existedElement;
6749
+ $container.appendChild($existedElement); // use absolute position
6750
+
6751
+ $existedElement.style.position = 'absolute';
6752
+ $existedElement.style.left = '0';
6753
+ $existedElement.style.top = '0';
6754
+ $existedElement.style['will-change'] = 'transform';
6755
+ var worldTransform = object.getWorldTransform();
6756
+ $existedElement.style.transform = "matrix(" + [worldTransform[0], worldTransform[1], worldTransform[4], worldTransform[5], worldTransform[12], worldTransform[13]].join(',') + ")";
7525
6757
  }
7526
6758
 
7527
- return null;
6759
+ return $existedElement;
7528
6760
  }
7529
- }, {
7530
- key: "updateAttribute",
7531
- value: function updateAttribute(name, object) {
7532
- var $el = this.getOrCreateEl(object);
7533
6761
 
7534
- switch (name) {
7535
- case 'innerHTML':
7536
- var innerHTML = object.parsedStyle.innerHTML;
6762
+ return null;
6763
+ };
7537
6764
 
7538
- if (g.isString(innerHTML)) {
7539
- $el.innerHTML = innerHTML;
7540
- } else {
7541
- $el.innerHTML = '';
7542
- $el.appendChild(innerHTML);
7543
- }
6765
+ _proto.updateAttribute = function updateAttribute(name, object) {
6766
+ var $el = this.getOrCreateEl(object);
7544
6767
 
7545
- break;
6768
+ switch (name) {
6769
+ case 'innerHTML':
6770
+ var innerHTML = object.parsedStyle.innerHTML;
7546
6771
 
7547
- case 'modelMatrix':
7548
- case 'transformOrigin':
7549
- var transformOrigin = object.parsedStyle.transformOrigin;
7550
- $el.style['transform-origin'] = "".concat(transformOrigin[0].value, " ").concat(transformOrigin[1].value);
7551
- var worldTransform = object.getWorldTransform();
7552
- $el.style.transform = "matrix(".concat([worldTransform[0], worldTransform[1], worldTransform[4], worldTransform[5], worldTransform[12], worldTransform[13]].join(','), ")");
7553
- break;
6772
+ if (g.isString(innerHTML)) {
6773
+ $el.innerHTML = innerHTML;
6774
+ } else {
6775
+ $el.innerHTML = '';
6776
+ $el.appendChild(innerHTML);
6777
+ }
7554
6778
 
7555
- case 'width':
7556
- var width = object.computedStyleMap().get('width');
7557
- $el.style.width = width.toString();
7558
- break;
6779
+ break;
7559
6780
 
7560
- case 'height':
7561
- var height = object.computedStyleMap().get('height');
7562
- $el.style.height = height.toString();
7563
- break;
6781
+ case 'modelMatrix':
6782
+ case 'transformOrigin':
6783
+ var transformOrigin = object.parsedStyle.transformOrigin;
6784
+ $el.style['transform-origin'] = transformOrigin[0].value + " " + transformOrigin[1].value;
6785
+ var worldTransform = object.getWorldTransform();
6786
+ $el.style.transform = "matrix(" + [worldTransform[0], worldTransform[1], worldTransform[4], worldTransform[5], worldTransform[12], worldTransform[13]].join(',') + ")";
6787
+ break;
7564
6788
 
7565
- case 'zIndex':
7566
- var zIndex = object.parsedStyle.zIndex;
7567
- $el.style['z-index'] = "".concat(zIndex.value);
7568
- break;
6789
+ case 'width':
6790
+ var width = object.computedStyleMap().get('width');
6791
+ $el.style.width = width.toString();
6792
+ break;
7569
6793
 
7570
- case 'visibility':
7571
- var visibility = object.parsedStyle.visibility;
7572
- $el.style.visibility = visibility.value;
7573
- break;
6794
+ case 'height':
6795
+ var height = object.computedStyleMap().get('height');
6796
+ $el.style.height = height.toString();
6797
+ break;
7574
6798
 
7575
- case 'pointerEvents':
7576
- var pointerEvents = object.parsedStyle.pointerEvents;
7577
- $el.style.pointerEvents = pointerEvents.value;
7578
- break;
6799
+ case 'zIndex':
6800
+ var zIndex = object.parsedStyle.zIndex;
6801
+ $el.style['z-index'] = "" + zIndex.value;
6802
+ break;
7579
6803
 
7580
- case 'opacity':
7581
- var opacity = object.parsedStyle.opacity;
7582
- $el.style.opacity = "".concat(opacity.value);
7583
- break;
6804
+ case 'visibility':
6805
+ var visibility = object.parsedStyle.visibility;
6806
+ $el.style.visibility = visibility.value;
6807
+ break;
7584
6808
 
7585
- case 'fill':
7586
- var fill = object.parsedStyle.fill;
7587
- var color = '';
6809
+ case 'pointerEvents':
6810
+ var pointerEvents = object.parsedStyle.pointerEvents;
6811
+ $el.style.pointerEvents = pointerEvents.value;
6812
+ break;
7588
6813
 
7589
- if (fill instanceof g.CSSRGB) {
7590
- if (fill.isNone) {
7591
- color = 'transparent';
7592
- } else {
7593
- color = object.getAttribute('fill');
7594
- }
7595
- } else if (Array.isArray(fill)) {
6814
+ case 'opacity':
6815
+ var opacity = object.parsedStyle.opacity;
6816
+ $el.style.opacity = "" + opacity.value;
6817
+ break;
6818
+
6819
+ case 'fill':
6820
+ var fill = object.parsedStyle.fill;
6821
+ var color = '';
6822
+
6823
+ if (fill instanceof g.CSSRGB) {
6824
+ if (fill.isNone) {
6825
+ color = 'transparent';
6826
+ } else {
7596
6827
  color = object.getAttribute('fill');
7597
- } else if (g.isPattern(fill)) ;
6828
+ }
6829
+ } else if (Array.isArray(fill)) {
6830
+ color = object.getAttribute('fill');
6831
+ } else if (g.isPattern(fill)) ;
7598
6832
 
7599
- $el.style.background = color;
7600
- break;
6833
+ $el.style.background = color;
6834
+ break;
7601
6835
 
7602
- case 'stroke':
7603
- var stroke = object.parsedStyle.stroke;
7604
- var borderColor = '';
6836
+ case 'stroke':
6837
+ var stroke = object.parsedStyle.stroke;
6838
+ var borderColor = '';
7605
6839
 
7606
- if (stroke instanceof g.CSSRGB) {
7607
- if (stroke.isNone) {
7608
- borderColor = 'transparent';
7609
- } else {
7610
- borderColor = object.getAttribute('stroke');
7611
- }
7612
- } else if (Array.isArray(stroke)) {
6840
+ if (stroke instanceof g.CSSRGB) {
6841
+ if (stroke.isNone) {
6842
+ borderColor = 'transparent';
6843
+ } else {
7613
6844
  borderColor = object.getAttribute('stroke');
7614
- } else if (g.isPattern(stroke)) ;
6845
+ }
6846
+ } else if (Array.isArray(stroke)) {
6847
+ borderColor = object.getAttribute('stroke');
6848
+ } else if (g.isPattern(stroke)) ;
7615
6849
 
7616
- $el.style['border-color'] = borderColor;
7617
- $el.style['border-style'] = 'solid';
7618
- break;
6850
+ $el.style['border-color'] = borderColor;
6851
+ $el.style['border-style'] = 'solid';
6852
+ break;
7619
6853
 
7620
- case 'lineWidth':
7621
- var lineWidth = object.parsedStyle.lineWidth;
7622
- $el.style['border-width'] = "".concat(lineWidth.value || 0, "px");
7623
- break;
6854
+ case 'lineWidth':
6855
+ var lineWidth = object.parsedStyle.lineWidth;
6856
+ $el.style['border-width'] = (lineWidth.value || 0) + "px";
6857
+ break;
7624
6858
 
7625
- case 'lineDash':
7626
- $el.style['border-style'] = 'dashed';
7627
- break;
6859
+ case 'lineDash':
6860
+ $el.style['border-style'] = 'dashed';
6861
+ break;
7628
6862
 
7629
- case 'filter':
7630
- var filter = object.parsedStyle.filter;
7631
- $el.style.filter = filter;
7632
- break;
7633
- }
6863
+ case 'filter':
6864
+ var filter = object.parsedStyle.filter;
6865
+ $el.style.filter = filter;
6866
+ break;
7634
6867
  }
7635
- }]);
6868
+ };
7636
6869
 
7637
6870
  return HTMLRenderingPlugin;
7638
6871
  }(), _class$4.tag = 'HTMLRendering', _class$4);
@@ -7652,22 +6885,18 @@
7652
6885
 
7653
6886
  var Plugin$5 = /*#__PURE__*/function () {
7654
6887
  function Plugin() {
7655
- _classCallCheck$6(this, Plugin);
7656
-
7657
6888
  this.name = 'html-renderer';
7658
6889
  }
7659
6890
 
7660
- _createClass$6(Plugin, [{
7661
- key: "init",
7662
- value: function init(container) {
7663
- container.load(containerModule$5, true);
7664
- }
7665
- }, {
7666
- key: "destroy",
7667
- value: function destroy(container) {
7668
- container.unload(containerModule$5);
7669
- }
7670
- }]);
6891
+ var _proto = Plugin.prototype;
6892
+
6893
+ _proto.init = function init(container) {
6894
+ container.load(containerModule$5, true);
6895
+ };
6896
+
6897
+ _proto.destroy = function destroy(container) {
6898
+ container.unload(containerModule$5);
6899
+ };
7671
6900
 
7672
6901
  return Plugin;
7673
6902
  }();
@@ -7679,8 +6908,6 @@
7679
6908
 
7680
6909
  var Canvas2DContextService = /*#__PURE__*/function () {
7681
6910
  function Canvas2DContextService() {
7682
- _classCallCheck(this, Canvas2DContextService);
7683
-
7684
6911
  this.$container = void 0;
7685
6912
  this.$canvas = void 0;
7686
6913
  this.dpr = void 0;
@@ -7688,120 +6915,142 @@
7688
6915
  this.canvasConfig = void 0;
7689
6916
  }
7690
6917
 
7691
- _createClass(Canvas2DContextService, [{
7692
- key: "init",
7693
- value: function () {
7694
- var _init = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
7695
- var _this$canvasConfig, container, canvas, devicePixelRatio, $canvas, dpr;
6918
+ var _proto = Canvas2DContextService.prototype;
7696
6919
 
7697
- return _regeneratorRuntime().wrap(function _callee$(_context) {
7698
- while (1) {
7699
- switch (_context.prev = _context.next) {
7700
- case 0:
7701
- _this$canvasConfig = this.canvasConfig, container = _this$canvasConfig.container, canvas = _this$canvasConfig.canvas, devicePixelRatio = _this$canvasConfig.devicePixelRatio;
6920
+ _proto.init = /*#__PURE__*/function () {
6921
+ var _init = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
6922
+ var _this$canvasConfig, container, canvas, devicePixelRatio, $canvas, dpr;
7702
6923
 
7703
- if (canvas) {
7704
- this.$canvas = canvas;
6924
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
6925
+ while (1) {
6926
+ switch (_context.prev = _context.next) {
6927
+ case 0:
6928
+ _this$canvasConfig = this.canvasConfig, container = _this$canvasConfig.container, canvas = _this$canvasConfig.canvas, devicePixelRatio = _this$canvasConfig.devicePixelRatio;
7705
6929
 
7706
- if (container && canvas.parentElement !== container) {
7707
- container.appendChild(canvas);
7708
- }
6930
+ if (canvas) {
6931
+ this.$canvas = canvas;
7709
6932
 
7710
- this.$container = canvas.parentElement;
7711
- this.canvasConfig.container = this.$container;
7712
- } else if (container) {
7713
- // create container
7714
- this.$container = g.isString(container) ? document.getElementById(container) : container;
6933
+ if (container && canvas.parentElement !== container) {
6934
+ container.appendChild(canvas);
6935
+ }
7715
6936
 
7716
- if (this.$container) {
7717
- // create canvas
7718
- $canvas = document.createElement('canvas');
7719
- this.$container.appendChild($canvas);
6937
+ this.$container = canvas.parentElement;
6938
+ this.canvasConfig.container = this.$container;
6939
+ } else if (container) {
6940
+ // create container
6941
+ this.$container = g.isString(container) ? document.getElementById(container) : container;
7720
6942
 
7721
- if (!this.$container.style.position) {
7722
- this.$container.style.position = 'relative';
7723
- }
6943
+ if (this.$container) {
6944
+ // create canvas
6945
+ $canvas = document.createElement('canvas');
6946
+ this.$container.appendChild($canvas);
7724
6947
 
7725
- this.$canvas = $canvas;
6948
+ if (!this.$container.style.position) {
6949
+ this.$container.style.position = 'relative';
7726
6950
  }
6951
+
6952
+ this.$canvas = $canvas;
7727
6953
  }
6954
+ }
7728
6955
 
7729
- this.context = this.$canvas.getContext('2d'); // use user-defined dpr first
6956
+ this.context = this.$canvas.getContext('2d'); // use user-defined dpr first
7730
6957
 
7731
- dpr = devicePixelRatio || g.isBrowser && window.devicePixelRatio || 1;
7732
- dpr = dpr >= 1 ? Math.ceil(dpr) : 1;
7733
- this.dpr = dpr;
7734
- this.resize(this.canvasConfig.width, this.canvasConfig.height);
6958
+ dpr = devicePixelRatio || g.isBrowser && window.devicePixelRatio || 1;
6959
+ dpr = dpr >= 1 ? Math.ceil(dpr) : 1;
6960
+ this.dpr = dpr;
6961
+ this.resize(this.canvasConfig.width, this.canvasConfig.height);
7735
6962
 
7736
- case 7:
7737
- case "end":
7738
- return _context.stop();
7739
- }
6963
+ case 7:
6964
+ case "end":
6965
+ return _context.stop();
7740
6966
  }
7741
- }, _callee, this);
7742
- }));
6967
+ }
6968
+ }, _callee, this);
6969
+ }));
7743
6970
 
7744
- function init() {
7745
- return _init.apply(this, arguments);
7746
- }
6971
+ function init() {
6972
+ return _init.apply(this, arguments);
6973
+ }
7747
6974
 
7748
- return init;
7749
- }()
7750
- }, {
7751
- key: "getContext",
7752
- value: function getContext() {
7753
- return this.context;
7754
- }
7755
- }, {
7756
- key: "getDomElement",
7757
- value: function getDomElement() {
7758
- return this.$canvas;
7759
- }
7760
- }, {
7761
- key: "getDPR",
7762
- value: function getDPR() {
7763
- return this.dpr;
7764
- }
7765
- }, {
7766
- key: "getBoundingClientRect",
7767
- value: function getBoundingClientRect() {
7768
- if (this.$canvas.getBoundingClientRect) {
7769
- return this.$canvas.getBoundingClientRect();
7770
- }
6975
+ return init;
6976
+ }();
6977
+
6978
+ _proto.getContext = function getContext() {
6979
+ return this.context;
6980
+ };
6981
+
6982
+ _proto.getDomElement = function getDomElement() {
6983
+ return this.$canvas;
6984
+ };
6985
+
6986
+ _proto.getDPR = function getDPR() {
6987
+ return this.dpr;
6988
+ };
6989
+
6990
+ _proto.getBoundingClientRect = function getBoundingClientRect() {
6991
+ if (this.$canvas.getBoundingClientRect) {
6992
+ return this.$canvas.getBoundingClientRect();
7771
6993
  }
7772
- }, {
7773
- key: "destroy",
7774
- value: function destroy() {
6994
+ };
6995
+
6996
+ _proto.destroy = function destroy() {
6997
+ // @ts-ignore
6998
+ if (this.$container && this.$canvas && this.$canvas.parentNode) {
6999
+ // destroy context
7775
7000
  // @ts-ignore
7776
- if (this.$container && this.$canvas && this.$canvas.parentNode) {
7777
- // destroy context
7778
- // @ts-ignore
7779
- this.$container.removeChild(this.$canvas);
7780
- }
7001
+ this.$container.removeChild(this.$canvas);
7781
7002
  }
7782
- }, {
7783
- key: "resize",
7784
- value: function resize(width, height) {
7785
- if (this.$canvas) {
7786
- // set canvas width & height
7787
- this.$canvas.width = this.dpr * width;
7788
- this.$canvas.height = this.dpr * height; // set CSS style width & height
7003
+ };
7789
7004
 
7790
- g.setDOMSize(this.$canvas, width, height);
7791
- var dpr = this.getDPR(); // scale all drawing operations by the dpr
7792
- // @see https://www.html5rocks.com/en/tutorials/canvas/hidpi/
7005
+ _proto.resize = function resize(width, height) {
7006
+ if (this.$canvas) {
7007
+ // set canvas width & height
7008
+ this.$canvas.width = this.dpr * width;
7009
+ this.$canvas.height = this.dpr * height; // set CSS style width & height
7793
7010
 
7794
- this.context.scale(dpr, dpr);
7795
- }
7011
+ g.setDOMSize(this.$canvas, width, height);
7012
+ var dpr = this.getDPR(); // scale all drawing operations by the dpr
7013
+ // @see https://www.html5rocks.com/en/tutorials/canvas/hidpi/
7014
+
7015
+ this.context.scale(dpr, dpr);
7796
7016
  }
7797
- }, {
7798
- key: "applyCursorStyle",
7799
- value: function applyCursorStyle(cursor) {
7800
- if (this.$container && this.$container.style) {
7801
- this.$container.style.cursor = cursor;
7802
- }
7017
+ };
7018
+
7019
+ _proto.applyCursorStyle = function applyCursorStyle(cursor) {
7020
+ if (this.$container && this.$container.style) {
7021
+ this.$container.style.cursor = cursor;
7022
+ }
7023
+ };
7024
+
7025
+ _proto.toDataURL = /*#__PURE__*/function () {
7026
+ var _toDataURL = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(options) {
7027
+ var _options, type, encoderOptions;
7028
+
7029
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
7030
+ while (1) {
7031
+ switch (_context2.prev = _context2.next) {
7032
+ case 0:
7033
+ if (options === void 0) {
7034
+ options = {};
7035
+ }
7036
+
7037
+ _options = options, type = _options.type, encoderOptions = _options.encoderOptions;
7038
+ return _context2.abrupt("return", this.context.canvas.toDataURL(type, encoderOptions));
7039
+
7040
+ case 3:
7041
+ case "end":
7042
+ return _context2.stop();
7043
+ }
7044
+ }
7045
+ }, _callee2, this);
7046
+ }));
7047
+
7048
+ function toDataURL(_x) {
7049
+ return _toDataURL.apply(this, arguments);
7803
7050
  }
7804
- }]);
7051
+
7052
+ return toDataURL;
7053
+ }();
7805
7054
 
7806
7055
  return Canvas2DContextService;
7807
7056
  }();
@@ -7820,37 +7069,29 @@
7820
7069
  });
7821
7070
  var ContextRegisterPlugin = /*#__PURE__*/function () {
7822
7071
  function ContextRegisterPlugin() {
7823
- _classCallCheck(this, ContextRegisterPlugin);
7824
-
7825
7072
  this.name = 'canvas-context-register';
7826
7073
  }
7827
7074
 
7828
- _createClass(ContextRegisterPlugin, [{
7829
- key: "init",
7830
- value: function init(container) {
7831
- container.load(containerModule$6, true);
7832
- }
7833
- }, {
7834
- key: "destroy",
7835
- value: function destroy(container) {
7836
- container.unload(containerModule$6);
7837
- }
7838
- }]);
7075
+ var _proto = ContextRegisterPlugin.prototype;
7076
+
7077
+ _proto.init = function init(container) {
7078
+ container.load(containerModule$6, true);
7079
+ };
7080
+
7081
+ _proto.destroy = function destroy(container) {
7082
+ container.unload(containerModule$6);
7083
+ };
7839
7084
 
7840
7085
  return ContextRegisterPlugin;
7841
7086
  }();
7842
7087
 
7843
7088
  var Renderer = /*#__PURE__*/function (_AbstractRenderer) {
7844
- _inherits(Renderer, _AbstractRenderer);
7845
-
7846
- var _super = _createSuper(Renderer);
7089
+ _inheritsLoose(Renderer, _AbstractRenderer);
7847
7090
 
7848
7091
  function Renderer(config) {
7849
7092
  var _this;
7850
7093
 
7851
- _classCallCheck(this, Renderer);
7852
-
7853
- _this = _super.call(this, config); // register Canvas2DContext
7094
+ _this = _AbstractRenderer.call(this, config) || this; // register Canvas2DContext
7854
7095
 
7855
7096
  _this.registerPlugin(new ContextRegisterPlugin());
7856
7097
 
@@ -7872,7 +7113,7 @@
7872
7113
  return _this;
7873
7114
  }
7874
7115
 
7875
- return _createClass(Renderer);
7116
+ return Renderer;
7876
7117
  }(g.AbstractRenderer);
7877
7118
 
7878
7119
  exports.CanvasPathGenerator = index_esm;