@antv/g-canvas 1.9.9 → 1.9.11

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
@@ -400,32 +400,6 @@
400
400
  return _setPrototypeOf(o, p);
401
401
  }
402
402
 
403
- /******************************************************************************
404
- Copyright (c) Microsoft Corporation.
405
-
406
- Permission to use, copy, modify, and/or distribute this software for any
407
- purpose with or without fee is hereby granted.
408
-
409
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
410
- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
411
- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
412
- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
413
- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
414
- OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
415
- PERFORMANCE OF THIS SOFTWARE.
416
- ***************************************************************************** */
417
-
418
- function __decorate(decorators, target, key, desc) {
419
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
420
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
421
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
422
- return c > 3 && r && Object.defineProperty(target, key, r), r;
423
- }
424
-
425
- function __param(paramIndex, decorator) {
426
- return function (target, key) { decorator(target, key, paramIndex); }
427
- }
428
-
429
403
  var toString = {}.toString;
430
404
  var isType = function (value, type) { return toString.call(value) === '[object ' + type + ']'; };
431
405
 
@@ -467,9 +441,6 @@
467
441
  return _setPrototypeOf$1(o, p);
468
442
  }
469
443
 
470
- var PathGeneratorFactory = gLite.Syringe.defineToken('');
471
- var PathGenerator = gLite.Syringe.defineToken('');
472
-
473
444
  function generatePath(context, parsedStyle) {
474
445
  var r = parsedStyle.r;
475
446
  context.arc(r, r, r, 0, Math.PI * 2, false);
@@ -761,73 +732,6 @@
761
732
  }
762
733
  }
763
734
 
764
- var containerModule = gLite.Module(function (register) {
765
- /**
766
- * register shape renderers
767
- */
768
- register({
769
- token: {
770
- token: PathGenerator,
771
- named: gLite.Shape.CIRCLE
772
- },
773
- useValue: generatePath
774
- });
775
- register({
776
- token: {
777
- token: PathGenerator,
778
- named: gLite.Shape.ELLIPSE
779
- },
780
- useValue: generatePath$1
781
- });
782
- register({
783
- token: {
784
- token: PathGenerator,
785
- named: gLite.Shape.RECT
786
- },
787
- useValue: generatePath$6
788
- });
789
- register({
790
- token: {
791
- token: PathGenerator,
792
- named: gLite.Shape.LINE
793
- },
794
- useValue: generatePath$2
795
- });
796
- register({
797
- token: {
798
- token: PathGenerator,
799
- named: gLite.Shape.POLYLINE
800
- },
801
- useValue: generatePath$5
802
- });
803
- register({
804
- token: {
805
- token: PathGenerator,
806
- named: gLite.Shape.POLYGON
807
- },
808
- useValue: generatePath$4
809
- });
810
- register({
811
- token: {
812
- token: PathGenerator,
813
- named: gLite.Shape.PATH
814
- },
815
- useValue: generatePath$3
816
- });
817
- register({
818
- token: PathGeneratorFactory,
819
- useFactory: function useFactory(ctx) {
820
- return function (tagName) {
821
- if (ctx.container.isBoundNamed(PathGenerator, tagName)) {
822
- return ctx.container.getNamed(PathGenerator, tagName);
823
- }
824
-
825
- return null;
826
- };
827
- }
828
- });
829
- });
830
-
831
735
  var Plugin = /*#__PURE__*/function (_AbstractRendererPlug) {
832
736
  _inheritsLoose$1(Plugin, _AbstractRendererPlug);
833
737
 
@@ -846,11 +750,16 @@
846
750
  var _proto = Plugin.prototype;
847
751
 
848
752
  _proto.init = function init() {
849
- this.container.load(containerModule, true);
753
+ var _pathGeneratorFactory;
754
+
755
+ var pathGeneratorFactory = (_pathGeneratorFactory = {}, _pathGeneratorFactory[gLite.Shape.CIRCLE] = generatePath, _pathGeneratorFactory[gLite.Shape.ELLIPSE] = generatePath$1, _pathGeneratorFactory[gLite.Shape.RECT] = generatePath$6, _pathGeneratorFactory[gLite.Shape.LINE] = generatePath$2, _pathGeneratorFactory[gLite.Shape.POLYLINE] = generatePath$5, _pathGeneratorFactory[gLite.Shape.POLYGON] = generatePath$4, _pathGeneratorFactory[gLite.Shape.PATH] = generatePath$3, _pathGeneratorFactory[gLite.Shape.TEXT] = undefined, _pathGeneratorFactory[gLite.Shape.GROUP] = undefined, _pathGeneratorFactory[gLite.Shape.IMAGE] = undefined, _pathGeneratorFactory[gLite.Shape.HTML] = undefined, _pathGeneratorFactory[gLite.Shape.MESH] = undefined, _pathGeneratorFactory); // @ts-ignore
756
+
757
+ this.context.pathGeneratorFactory = pathGeneratorFactory;
850
758
  };
851
759
 
852
760
  _proto.destroy = function destroy() {
853
- this.container.unload(containerModule);
761
+ // @ts-ignore
762
+ delete this.context.pathGeneratorFactory;
854
763
  };
855
764
 
856
765
  return Plugin;
@@ -858,8 +767,6 @@
858
767
 
859
768
  var index_esm = /*#__PURE__*/Object.freeze({
860
769
  __proto__: null,
861
- PathGenerator: PathGenerator,
862
- PathGeneratorFactory: PathGeneratorFactory,
863
770
  Plugin: Plugin
864
771
  });
865
772
 
@@ -1419,68 +1326,6 @@
1419
1326
  out[15] = (a20 * b03 - a21 * b01 + a22 * b00) * det;
1420
1327
  return out;
1421
1328
  }
1422
- /**
1423
- * Multiplies two mat4s
1424
- *
1425
- * @param {mat4} out the receiving matrix
1426
- * @param {ReadonlyMat4} a the first operand
1427
- * @param {ReadonlyMat4} b the second operand
1428
- * @returns {mat4} out
1429
- */
1430
-
1431
-
1432
- function multiply(out, a, b) {
1433
- var a00 = a[0],
1434
- a01 = a[1],
1435
- a02 = a[2],
1436
- a03 = a[3];
1437
- var a10 = a[4],
1438
- a11 = a[5],
1439
- a12 = a[6],
1440
- a13 = a[7];
1441
- var a20 = a[8],
1442
- a21 = a[9],
1443
- a22 = a[10],
1444
- a23 = a[11];
1445
- var a30 = a[12],
1446
- a31 = a[13],
1447
- a32 = a[14],
1448
- a33 = a[15]; // Cache only the current line of the second matrix
1449
-
1450
- var b0 = b[0],
1451
- b1 = b[1],
1452
- b2 = b[2],
1453
- b3 = b[3];
1454
- out[0] = b0 * a00 + b1 * a10 + b2 * a20 + b3 * a30;
1455
- out[1] = b0 * a01 + b1 * a11 + b2 * a21 + b3 * a31;
1456
- out[2] = b0 * a02 + b1 * a12 + b2 * a22 + b3 * a32;
1457
- out[3] = b0 * a03 + b1 * a13 + b2 * a23 + b3 * a33;
1458
- b0 = b[4];
1459
- b1 = b[5];
1460
- b2 = b[6];
1461
- b3 = b[7];
1462
- out[4] = b0 * a00 + b1 * a10 + b2 * a20 + b3 * a30;
1463
- out[5] = b0 * a01 + b1 * a11 + b2 * a21 + b3 * a31;
1464
- out[6] = b0 * a02 + b1 * a12 + b2 * a22 + b3 * a32;
1465
- out[7] = b0 * a03 + b1 * a13 + b2 * a23 + b3 * a33;
1466
- b0 = b[8];
1467
- b1 = b[9];
1468
- b2 = b[10];
1469
- b3 = b[11];
1470
- out[8] = b0 * a00 + b1 * a10 + b2 * a20 + b3 * a30;
1471
- out[9] = b0 * a01 + b1 * a11 + b2 * a21 + b3 * a31;
1472
- out[10] = b0 * a02 + b1 * a12 + b2 * a22 + b3 * a32;
1473
- out[11] = b0 * a03 + b1 * a13 + b2 * a23 + b3 * a33;
1474
- b0 = b[12];
1475
- b1 = b[13];
1476
- b2 = b[14];
1477
- b3 = b[15];
1478
- out[12] = b0 * a00 + b1 * a10 + b2 * a20 + b3 * a30;
1479
- out[13] = b0 * a01 + b1 * a11 + b2 * a21 + b3 * a31;
1480
- out[14] = b0 * a02 + b1 * a12 + b2 * a22 + b3 * a32;
1481
- out[15] = b0 * a03 + b1 * a13 + b2 * a23 + b3 * a33;
1482
- return out;
1483
- }
1484
1329
  /**
1485
1330
  * 3 Dimensional Vector
1486
1331
  * @module vec3
@@ -1703,10 +1548,6 @@
1703
1548
  };
1704
1549
  }();
1705
1550
 
1706
- var _class;
1707
-
1708
- var CanvasPickerPlugin_1;
1709
- var PointInPathPickerFactory = gLite.Syringe.defineToken('');
1710
1551
  var tmpVec3a = create$1();
1711
1552
  var tmpVec3b = create$1();
1712
1553
  var tmpVec3c = create$1();
@@ -1718,20 +1559,17 @@
1718
1559
  * 2. do math calculation with geometry in an accurate way
1719
1560
  */
1720
1561
 
1721
- var CanvasPickerPlugin = CanvasPickerPlugin_1 = (_class = /*#__PURE__*/function () {
1722
- function CanvasPickerPlugin(renderingContext, canvasConfig, offscreenCanvas, pathGeneratorFactory, pointInPathPickerFactory) {
1562
+ var CanvasPickerPlugin = /*#__PURE__*/function () {
1563
+ function CanvasPickerPlugin() {
1723
1564
  var _this = this;
1724
1565
 
1725
- this.renderingContext = void 0;
1726
1566
  this.canvasConfig = void 0;
1727
- this.offscreenCanvas = void 0;
1728
1567
  this.pathGeneratorFactory = void 0;
1729
1568
  this.pointInPathPickerFactory = void 0;
1730
- this.pathGeneratorFactoryCache = {};
1731
1569
 
1732
1570
  this.isHit = function (displayObject, position, worldTransform) {
1733
1571
  // use picker for current shape's type
1734
- var pick = _this.pointInPathPickerFactory(displayObject.nodeName);
1572
+ var pick = _this.pointInPathPickerFactory[displayObject.nodeName];
1735
1573
 
1736
1574
  if (pick) {
1737
1575
  // invert with world matrix
@@ -1755,13 +1593,8 @@
1755
1593
  };
1756
1594
 
1757
1595
  this.isPointInPath = function (displayObject, position) {
1758
- var context = _this.offscreenCanvas.getOrCreateContext(_this.canvasConfig.offscreenCanvas);
1759
-
1760
- if (_this.pathGeneratorFactoryCache[displayObject.nodeName] === undefined) {
1761
- _this.pathGeneratorFactoryCache[displayObject.nodeName] = _this.pathGeneratorFactory(displayObject.nodeName);
1762
- }
1763
-
1764
- var generatePath = _this.pathGeneratorFactoryCache[displayObject.nodeName];
1596
+ var context = gLite.runtime.offscreenCanvas.getOrCreateContext(_this.canvasConfig.offscreenCanvas);
1597
+ var generatePath = _this.pathGeneratorFactory[displayObject.nodeName];
1765
1598
 
1766
1599
  if (generatePath) {
1767
1600
  context.beginPath();
@@ -1771,22 +1604,24 @@
1771
1604
 
1772
1605
  return context.isPointInPath(position.x, position.y);
1773
1606
  };
1774
-
1775
- this.renderingContext = renderingContext;
1776
- this.canvasConfig = canvasConfig;
1777
- this.offscreenCanvas = offscreenCanvas;
1778
- this.pathGeneratorFactory = pathGeneratorFactory;
1779
- this.pointInPathPickerFactory = pointInPathPickerFactory;
1780
1607
  }
1781
1608
 
1782
1609
  var _proto = CanvasPickerPlugin.prototype;
1783
1610
 
1784
- _proto.apply = function apply(renderingService) {
1785
- var _this$renderingContex,
1611
+ _proto.apply = function apply(context) {
1612
+ var _renderingContext$roo,
1786
1613
  _this2 = this;
1787
1614
 
1788
- var document = (_this$renderingContex = this.renderingContext.root) === null || _this$renderingContex === void 0 ? void 0 : _this$renderingContex.ownerDocument;
1789
- renderingService.hooks.pick.tapPromise(CanvasPickerPlugin_1.tag, /*#__PURE__*/function () {
1615
+ var config = context.config,
1616
+ renderingService = context.renderingService,
1617
+ renderingContext = context.renderingContext,
1618
+ pathGeneratorFactory = context.pathGeneratorFactory,
1619
+ pointInPathPickerFactory = context.pointInPathPickerFactory;
1620
+ this.canvasConfig = config;
1621
+ this.pathGeneratorFactory = pathGeneratorFactory;
1622
+ this.pointInPathPickerFactory = pointInPathPickerFactory;
1623
+ var document = (_renderingContext$roo = renderingContext.root) === null || _renderingContext$roo === void 0 ? void 0 : _renderingContext$roo.ownerDocument;
1624
+ renderingService.hooks.pick.tapPromise(CanvasPickerPlugin.tag, /*#__PURE__*/function () {
1790
1625
  var _ref = _asyncToGenerator$1( /*#__PURE__*/_regeneratorRuntime$1().mark(function _callee(result) {
1791
1626
  return _regeneratorRuntime$1().wrap(function _callee$(_context) {
1792
1627
  while (1) {
@@ -1806,7 +1641,7 @@
1806
1641
  return _ref.apply(this, arguments);
1807
1642
  };
1808
1643
  }());
1809
- renderingService.hooks.pickSync.tap(CanvasPickerPlugin_1.tag, function (result) {
1644
+ renderingService.hooks.pickSync.tap(CanvasPickerPlugin.tag, function (result) {
1810
1645
  return _this2.pick(document, result);
1811
1646
  });
1812
1647
  };
@@ -1819,44 +1654,7 @@
1819
1654
 
1820
1655
  var position = set(tmpVec3a, x, y, 0); // query by AABB first with spatial index(r-tree)
1821
1656
 
1822
- var hitTestList = document.elementsFromBBox(position[0], position[1], position[0], position[1]); // const rBushNodes = this.rBush.search({
1823
- // minX: position[0],
1824
- // minY: position[1],
1825
- // maxX: position[0],
1826
- // maxY: position[1],
1827
- // });
1828
- // const queriedIds = rBushNodes.map((node) => node.id);
1829
- // const hitTestList: DisplayObject[] = [];
1830
- // rBushNodes.forEach(({ id }) => {
1831
- // const displayObject = this.displayObjectPool.getByEntity(id);
1832
- // const { pointerEvents } = displayObject.parsedStyle as ParsedBaseStyleProps;
1833
- // // account for `visibility`
1834
- // // @see https://developer.mozilla.org/en-US/docs/Web/CSS/pointer-events
1835
- // const isVisibilityAffected = [
1836
- // 'auto',
1837
- // 'visiblepainted',
1838
- // 'visiblefill',
1839
- // 'visiblestroke',
1840
- // 'visible',
1841
- // ].includes(pointerEvents);
1842
- // if (
1843
- // (!isVisibilityAffected || (isVisibilityAffected && displayObject.isVisible())) &&
1844
- // !displayObject.isCulled() &&
1845
- // displayObject.isInteractive()
1846
- // ) {
1847
- // // parent is not included, eg. parent is clipped
1848
- // if (
1849
- // displayObject.parentNode &&
1850
- // queriedIds.indexOf((displayObject.parentNode as Element).entity) === -1
1851
- // ) {
1852
- // return;
1853
- // }
1854
- // hitTestList.push(displayObject);
1855
- // }
1856
- // });
1857
- // // find group with max z-index
1858
- // hitTestList.sort((a, b) => b.sortable.renderOrder - a.sortable.renderOrder);
1859
- // test with clip path & origin shape
1657
+ var hitTestList = document.elementsFromBBox(position[0], position[1], position[0], position[1]); // test with clip path & origin shape
1860
1658
  // @see https://github.com/antvis/g/issues/1064
1861
1659
 
1862
1660
  var pickedDisplayObjects = [];
@@ -1871,9 +1669,8 @@
1871
1669
  var clipped = gLite.findClosestClipPathTarget(displayObject);
1872
1670
 
1873
1671
  if (clipped) {
1874
- var clipPath = clipped.style.clipPath;
1875
- worldTransform = multiply(tmpMat4, clipped === displayObject ? worldTransform : clipped.getWorldTransform(), clipPath.getLocalTransform());
1876
- var isHitClipPath = this.isHit(clipPath, position, worldTransform);
1672
+ var clipPath = clipped.parsedStyle.clipPath;
1673
+ var isHitClipPath = this.isHit(clipPath, position, clipPath.getWorldTransform());
1877
1674
 
1878
1675
  if (isHitClipPath) {
1879
1676
  if (topmost) {
@@ -1899,10 +1696,9 @@
1899
1696
  };
1900
1697
 
1901
1698
  return CanvasPickerPlugin;
1902
- }(), _class.tag = 'CanvasPicker', _class);
1903
- CanvasPickerPlugin = CanvasPickerPlugin_1 = __decorate([gLite.singleton({
1904
- contrib: gLite.RenderingPluginContribution
1905
- }), __param(0, gLite.inject(gLite.RenderingContext)), __param(1, gLite.inject(gLite.CanvasConfig)), __param(2, gLite.inject(gLite.OffscreenCanvasCreator)), __param(3, gLite.inject(PathGeneratorFactory)), __param(4, gLite.inject(PointInPathPickerFactory))], CanvasPickerPlugin);
1699
+ }();
1700
+
1701
+ CanvasPickerPlugin.tag = 'CanvasPicker';
1906
1702
  /**
1907
1703
  * 两点之间的距离
1908
1704
  * @param {number} x1 起始点 x
@@ -2735,39 +2531,6 @@
2735
2531
  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);
2736
2532
  }
2737
2533
 
2738
- var containerModule$1 = gLite.Module(function (register) {
2739
- register({
2740
- token: PointInPathPickerFactory,
2741
- useFactory: function useFactory(context) {
2742
- return function (tagName) {
2743
- if (tagName === gLite.Shape.CIRCLE) {
2744
- return isPointInPath;
2745
- } else if (tagName === gLite.Shape.ELLIPSE) {
2746
- return isPointInPath$1;
2747
- } else if (tagName === gLite.Shape.RECT) {
2748
- return isPointInPath$6;
2749
- } else if (tagName === gLite.Shape.LINE) {
2750
- return isPointInPath$2;
2751
- } else if (tagName === gLite.Shape.POLYLINE) {
2752
- return isPointInPath$5;
2753
- } else if (tagName === gLite.Shape.POLYGON) {
2754
- return isPointInPath$4;
2755
- } else if (tagName === gLite.Shape.PATH) {
2756
- return isPointInPath$3;
2757
- } else if (tagName === gLite.Shape.IMAGE || tagName === gLite.Shape.TEXT // tagName === Shape.GROUP
2758
- ) {
2759
- return function () {
2760
- return true;
2761
- };
2762
- }
2763
-
2764
- return null;
2765
- };
2766
- }
2767
- });
2768
- register(CanvasPickerPlugin);
2769
- });
2770
-
2771
2534
  var Plugin$1 = /*#__PURE__*/function (_AbstractRendererPlug) {
2772
2535
  _inheritsLoose$2(Plugin, _AbstractRendererPlug);
2773
2536
 
@@ -2786,11 +2549,22 @@
2786
2549
  var _proto = Plugin.prototype;
2787
2550
 
2788
2551
  _proto.init = function init() {
2789
- this.container.load(containerModule$1, true);
2552
+ var _pointInPathPickerFac;
2553
+
2554
+ var trueFunc = function trueFunc() {
2555
+ return true;
2556
+ };
2557
+
2558
+ var pointInPathPickerFactory = (_pointInPathPickerFac = {}, _pointInPathPickerFac[gLite.Shape.CIRCLE] = isPointInPath, _pointInPathPickerFac[gLite.Shape.ELLIPSE] = isPointInPath$1, _pointInPathPickerFac[gLite.Shape.RECT] = isPointInPath$6, _pointInPathPickerFac[gLite.Shape.LINE] = isPointInPath$2, _pointInPathPickerFac[gLite.Shape.POLYLINE] = isPointInPath$5, _pointInPathPickerFac[gLite.Shape.POLYGON] = isPointInPath$4, _pointInPathPickerFac[gLite.Shape.PATH] = isPointInPath$3, _pointInPathPickerFac[gLite.Shape.TEXT] = trueFunc, _pointInPathPickerFac[gLite.Shape.GROUP] = null, _pointInPathPickerFac[gLite.Shape.IMAGE] = trueFunc, _pointInPathPickerFac[gLite.Shape.HTML] = null, _pointInPathPickerFac[gLite.Shape.MESH] = null, _pointInPathPickerFac); // @ts-ignore
2559
+
2560
+ this.context.pointInPathPickerFactory = pointInPathPickerFactory;
2561
+ this.addRenderingPlugin(new CanvasPickerPlugin());
2790
2562
  };
2791
2563
 
2792
2564
  _proto.destroy = function destroy() {
2793
- this.container.unload(containerModule$1);
2565
+ // @ts-ignore
2566
+ delete this.context.pointInPathPickerFactory;
2567
+ this.removeAllRenderingPlugins();
2794
2568
  };
2795
2569
 
2796
2570
  return Plugin;
@@ -3187,6 +2961,23 @@
3187
2961
  };
3188
2962
  }
3189
2963
 
2964
+ function _extends() {
2965
+ _extends = Object.assign ? Object.assign.bind() : function (target) {
2966
+ for (var i = 1; i < arguments.length; i++) {
2967
+ var source = arguments[i];
2968
+
2969
+ for (var key in source) {
2970
+ if (Object.prototype.hasOwnProperty.call(source, key)) {
2971
+ target[key] = source[key];
2972
+ }
2973
+ }
2974
+ }
2975
+
2976
+ return target;
2977
+ };
2978
+ return _extends.apply(this, arguments);
2979
+ }
2980
+
3190
2981
  function _inheritsLoose$3(subClass, superClass) {
3191
2982
  subClass.prototype = Object.create(superClass.prototype);
3192
2983
  subClass.prototype.constructor = subClass;
@@ -3201,1081 +2992,834 @@
3201
2992
  };
3202
2993
  return _setPrototypeOf$3(o, p);
3203
2994
  }
2995
+ /**
2996
+ * Common utilities
2997
+ * @module glMatrix
2998
+ */
3204
2999
 
3205
- var ImagePool = /*#__PURE__*/function () {
3206
- function ImagePool(canvasConfig) {
3207
- this.canvasConfig = void 0;
3208
- this.imageCache = {};
3209
- this.gradientCache = {};
3210
- this.patternCache = {};
3211
- this.canvasConfig = canvasConfig;
3212
- }
3213
3000
 
3214
- var _proto = ImagePool.prototype;
3001
+ var ARRAY_TYPE$1 = typeof Float32Array !== 'undefined' ? Float32Array : Array;
3002
+ if (!Math.hypot) Math.hypot = function () {
3003
+ var y = 0,
3004
+ i = arguments.length;
3215
3005
 
3216
- _proto.getImageSync = function getImageSync(src, callback) {
3217
- if (!this.imageCache[src]) {
3218
- this.getOrCreateImage(src).then(function () {
3219
- if (callback) {
3220
- callback();
3221
- }
3222
- });
3223
- } else {
3224
- if (callback) {
3225
- callback();
3226
- }
3227
- }
3006
+ while (i--) {
3007
+ y += arguments[i] * arguments[i];
3008
+ }
3228
3009
 
3229
- return this.imageCache[src];
3230
- };
3010
+ return Math.sqrt(y);
3011
+ };
3012
+ /**
3013
+ * 4x4 Matrix<br>Format: column-major, when typed out it looks like row-major<br>The matrices are being post multiplied.
3014
+ * @module mat4
3015
+ */
3231
3016
 
3232
- _proto.getOrCreateImage = function getOrCreateImage(src) {
3233
- var _this = this;
3017
+ /**
3018
+ * Creates a new identity mat4
3019
+ *
3020
+ * @returns {mat4} a new 4x4 matrix
3021
+ */
3234
3022
 
3235
- if (this.imageCache[src]) {
3236
- return Promise.resolve(this.imageCache[src]);
3237
- } // @see https://github.com/antvis/g/issues/938
3023
+ function create$3() {
3024
+ var out = new ARRAY_TYPE$1(16);
3238
3025
 
3026
+ if (ARRAY_TYPE$1 != Float32Array) {
3027
+ out[1] = 0;
3028
+ out[2] = 0;
3029
+ out[3] = 0;
3030
+ out[4] = 0;
3031
+ out[6] = 0;
3032
+ out[7] = 0;
3033
+ out[8] = 0;
3034
+ out[9] = 0;
3035
+ out[11] = 0;
3036
+ out[12] = 0;
3037
+ out[13] = 0;
3038
+ out[14] = 0;
3039
+ }
3239
3040
 
3240
- var createImage = this.canvasConfig.createImage;
3241
- return new Promise(function (resolve, reject) {
3242
- var image;
3041
+ out[0] = 1;
3042
+ out[5] = 1;
3043
+ out[10] = 1;
3044
+ out[15] = 1;
3045
+ return out;
3046
+ }
3047
+ /**
3048
+ * Copy the values from one mat4 to another
3049
+ *
3050
+ * @param {mat4} out the receiving matrix
3051
+ * @param {ReadonlyMat4} a the source matrix
3052
+ * @returns {mat4} out
3053
+ */
3243
3054
 
3244
- if (createImage) {
3245
- image = createImage(src);
3246
- } else if (gLite.isBrowser) {
3247
- image = new window.Image();
3248
- }
3249
3055
 
3250
- if (image) {
3251
- image.onload = function () {
3252
- resolve(image);
3253
- };
3056
+ function copy(out, a) {
3057
+ out[0] = a[0];
3058
+ out[1] = a[1];
3059
+ out[2] = a[2];
3060
+ out[3] = a[3];
3061
+ out[4] = a[4];
3062
+ out[5] = a[5];
3063
+ out[6] = a[6];
3064
+ out[7] = a[7];
3065
+ out[8] = a[8];
3066
+ out[9] = a[9];
3067
+ out[10] = a[10];
3068
+ out[11] = a[11];
3069
+ out[12] = a[12];
3070
+ out[13] = a[13];
3071
+ out[14] = a[14];
3072
+ out[15] = a[15];
3073
+ return out;
3074
+ }
3075
+ /**
3076
+ * Multiplies two mat4s
3077
+ *
3078
+ * @param {mat4} out the receiving matrix
3079
+ * @param {ReadonlyMat4} a the first operand
3080
+ * @param {ReadonlyMat4} b the second operand
3081
+ * @returns {mat4} out
3082
+ */
3254
3083
 
3255
- image.onerror = function (ev) {
3256
- reject(ev);
3257
- };
3258
3084
 
3259
- image.crossOrigin = 'Anonymous';
3260
- image.src = src;
3261
- _this.imageCache[src] = image;
3262
- }
3263
- });
3264
- };
3265
-
3266
- _proto.getOrCreatePatternSync = function getOrCreatePatternSync(pattern, context, callback) {
3267
- var patternKey = this.generatePatternKey(pattern);
3268
-
3269
- if (patternKey && this.patternCache[patternKey]) {
3270
- return this.patternCache[patternKey];
3271
- }
3272
-
3273
- var image = pattern.image,
3274
- repetition = pattern.repetition;
3275
- var src; // Image URL
3276
-
3277
- if (isString(image)) {
3278
- src = this.getImageSync(image, callback);
3279
- } else {
3280
- src = image;
3281
- } // @see https://developer.mozilla.org/zh-CN/docs/Web/API/CanvasRenderingContext2D/createPattern
3282
-
3283
-
3284
- var canvasPattern = src && context.createPattern(src, repetition);
3285
-
3286
- if (patternKey && canvasPattern) {
3287
- this.patternCache[patternKey] = canvasPattern;
3288
- }
3289
-
3290
- return canvasPattern;
3291
- };
3292
-
3293
- _proto.getOrCreateGradient = function getOrCreateGradient(params, context) {
3294
- var key = this.generateGradientKey(params);
3295
- var type = params.type,
3296
- steps = params.steps,
3297
- width = params.width,
3298
- height = params.height,
3299
- angle = params.angle,
3300
- cx = params.cx,
3301
- cy = params.cy,
3302
- size = params.size;
3303
-
3304
- if (this.gradientCache[key]) {
3305
- return this.gradientCache[key];
3306
- }
3307
-
3308
- var gradient = null;
3309
-
3310
- if (type === gLite.GradientType.LinearGradient) {
3311
- var _computeLinearGradien = gLite.computeLinearGradient(width, height, angle),
3312
- x1 = _computeLinearGradien.x1,
3313
- y1 = _computeLinearGradien.y1,
3314
- x2 = _computeLinearGradien.x2,
3315
- y2 = _computeLinearGradien.y2; // @see https://developer.mozilla.org/zh-CN/docs/Web/API/CanvasRenderingContext2D/createLinearGradient
3316
-
3317
-
3318
- gradient = context.createLinearGradient(x1, y1, x2, y2);
3319
- } else if (type === gLite.GradientType.RadialGradient) {
3320
- var _computeRadialGradien = gLite.computeRadialGradient(width, height, cx, cy, size),
3321
- x = _computeRadialGradien.x,
3322
- y = _computeRadialGradien.y,
3323
- r = _computeRadialGradien.r; // @see https://developer.mozilla.org/zh-CN/docs/Web/API/CanvasRenderingContext2D/createRadialGradient
3324
-
3325
-
3326
- gradient = context.createRadialGradient(x, y, 0, x, y, r);
3327
- }
3328
-
3329
- if (gradient) {
3330
- steps.forEach(function (_ref) {
3331
- var offset = _ref.offset,
3332
- color = _ref.color;
3333
-
3334
- if (offset.unit === gLite.UnitType.kPercentage) {
3335
- var _gradient;
3336
-
3337
- (_gradient = gradient) === null || _gradient === void 0 ? void 0 : _gradient.addColorStop(offset.value / 100, color.toString());
3338
- }
3339
- });
3340
- this.gradientCache[key] = gradient;
3341
- }
3342
-
3343
- return this.gradientCache[key];
3344
- };
3345
-
3346
- _proto.generateGradientKey = function generateGradientKey(params) {
3347
- var type = params.type,
3348
- width = params.width,
3349
- height = params.height,
3350
- steps = params.steps,
3351
- angle = params.angle,
3352
- cx = params.cx,
3353
- cy = params.cy,
3354
- size = params.size;
3355
- return "gradient-" + type + "-" + ((angle === null || angle === void 0 ? void 0 : angle.toString()) || 0) + "-" + ((cx === null || cx === void 0 ? void 0 : cx.toString()) || 0) + "-" + ((cy === null || cy === void 0 ? void 0 : cy.toString()) || 0) + "-" + ((size === null || size === void 0 ? void 0 : size.toString()) || 0) + "-" + width + "-" + height + "-" + steps.map(function (_ref2) {
3356
- var offset = _ref2.offset,
3357
- color = _ref2.color;
3358
- return "" + offset + color;
3359
- }).join('-');
3360
- };
3361
-
3362
- _proto.generatePatternKey = function generatePatternKey(pattern) {
3363
- var image = pattern.image,
3364
- repetition = pattern.repetition; // only generate cache for Image
3365
-
3366
- if (isString(image)) {
3367
- return "pattern-" + image + "-" + repetition;
3368
- }
3369
- };
3370
-
3371
- return ImagePool;
3372
- }();
3373
-
3374
- ImagePool = __decorate([gLite.singleton(), __param(0, gLite.inject(gLite.CanvasConfig))], ImagePool);
3375
-
3376
- var _class$1;
3377
-
3378
- var LoadImagePlugin_1;
3379
- var LoadImagePlugin = LoadImagePlugin_1 = (_class$1 = /*#__PURE__*/function () {
3380
- function LoadImagePlugin(imagePool, renderingContext) {
3381
- this.imagePool = void 0;
3382
- this.renderingContext = void 0;
3383
- this.imagePool = imagePool;
3384
- this.renderingContext = renderingContext;
3385
- }
3386
-
3387
- var _proto = LoadImagePlugin.prototype;
3388
-
3389
- _proto.apply = function apply(renderingService) {
3390
- var _this = this;
3391
-
3392
- var handleMounted = function handleMounted(e) {
3393
- var object = e.target;
3394
- var nodeName = object.nodeName,
3395
- attributes = object.attributes;
3396
-
3397
- if (nodeName === gLite.Shape.IMAGE) {
3398
- var img = attributes.img;
3399
-
3400
- if (isString(img)) {
3401
- _this.imagePool.getImageSync(img, function () {
3402
- // set dirty rectangle flag
3403
- object.renderable.dirty = true;
3404
- renderingService.dirtify();
3405
- });
3406
- }
3407
- }
3408
- };
3409
-
3410
- var handleAttributeChanged = function handleAttributeChanged(e) {
3411
- var object = e.target;
3412
- var attrName = e.attrName,
3413
- newValue = e.newValue;
3414
-
3415
- if (object.nodeName === gLite.Shape.IMAGE) {
3416
- if (attrName === 'img') {
3417
- if (isString(newValue)) {
3418
- _this.imagePool.getOrCreateImage(newValue).then(function () {
3419
- // set dirty rectangle flag
3420
- object.renderable.dirty = true;
3421
- renderingService.dirtify();
3422
- });
3423
- }
3424
- }
3425
- }
3426
- };
3427
-
3428
- renderingService.hooks.init.tapPromise(LoadImagePlugin_1.tag, /*#__PURE__*/_asyncToGenerator$2( /*#__PURE__*/_regeneratorRuntime$2().mark(function _callee() {
3429
- return _regeneratorRuntime$2().wrap(function _callee$(_context) {
3430
- while (1) {
3431
- switch (_context.prev = _context.next) {
3432
- case 0:
3433
- _this.renderingContext.root.addEventListener(gLite.ElementEvent.MOUNTED, handleMounted);
3434
-
3435
- _this.renderingContext.root.addEventListener(gLite.ElementEvent.ATTR_MODIFIED, handleAttributeChanged);
3436
-
3437
- case 2:
3438
- case "end":
3439
- return _context.stop();
3440
- }
3441
- }
3442
- }, _callee);
3443
- })));
3444
- renderingService.hooks.destroy.tap(LoadImagePlugin_1.tag, function () {
3445
- _this.renderingContext.root.removeEventListener(gLite.ElementEvent.MOUNTED, handleMounted);
3446
-
3447
- _this.renderingContext.root.removeEventListener(gLite.ElementEvent.ATTR_MODIFIED, handleAttributeChanged);
3448
- });
3449
- };
3450
-
3451
- return LoadImagePlugin;
3452
- }(), _class$1.tag = 'LoadImage', _class$1);
3453
- LoadImagePlugin = LoadImagePlugin_1 = __decorate([gLite.singleton({
3454
- contrib: gLite.RenderingPluginContribution
3455
- }), __param(0, gLite.inject(ImagePool)), __param(1, gLite.inject(gLite.RenderingContext))], LoadImagePlugin);
3456
- var containerModule$2 = gLite.Module(function (register) {
3457
- register(ImagePool);
3458
- register(LoadImagePlugin);
3459
- });
3085
+ function multiply(out, a, b) {
3086
+ var a00 = a[0],
3087
+ a01 = a[1],
3088
+ a02 = a[2],
3089
+ a03 = a[3];
3090
+ var a10 = a[4],
3091
+ a11 = a[5],
3092
+ a12 = a[6],
3093
+ a13 = a[7];
3094
+ var a20 = a[8],
3095
+ a21 = a[9],
3096
+ a22 = a[10],
3097
+ a23 = a[11];
3098
+ var a30 = a[12],
3099
+ a31 = a[13],
3100
+ a32 = a[14],
3101
+ a33 = a[15]; // Cache only the current line of the second matrix
3460
3102
 
3461
- var Plugin$2 = /*#__PURE__*/function (_AbstractRendererPlug) {
3462
- _inheritsLoose$3(Plugin, _AbstractRendererPlug);
3103
+ var b0 = b[0],
3104
+ b1 = b[1],
3105
+ b2 = b[2],
3106
+ b3 = b[3];
3107
+ out[0] = b0 * a00 + b1 * a10 + b2 * a20 + b3 * a30;
3108
+ out[1] = b0 * a01 + b1 * a11 + b2 * a21 + b3 * a31;
3109
+ out[2] = b0 * a02 + b1 * a12 + b2 * a22 + b3 * a32;
3110
+ out[3] = b0 * a03 + b1 * a13 + b2 * a23 + b3 * a33;
3111
+ b0 = b[4];
3112
+ b1 = b[5];
3113
+ b2 = b[6];
3114
+ b3 = b[7];
3115
+ out[4] = b0 * a00 + b1 * a10 + b2 * a20 + b3 * a30;
3116
+ out[5] = b0 * a01 + b1 * a11 + b2 * a21 + b3 * a31;
3117
+ out[6] = b0 * a02 + b1 * a12 + b2 * a22 + b3 * a32;
3118
+ out[7] = b0 * a03 + b1 * a13 + b2 * a23 + b3 * a33;
3119
+ b0 = b[8];
3120
+ b1 = b[9];
3121
+ b2 = b[10];
3122
+ b3 = b[11];
3123
+ out[8] = b0 * a00 + b1 * a10 + b2 * a20 + b3 * a30;
3124
+ out[9] = b0 * a01 + b1 * a11 + b2 * a21 + b3 * a31;
3125
+ out[10] = b0 * a02 + b1 * a12 + b2 * a22 + b3 * a32;
3126
+ out[11] = b0 * a03 + b1 * a13 + b2 * a23 + b3 * a33;
3127
+ b0 = b[12];
3128
+ b1 = b[13];
3129
+ b2 = b[14];
3130
+ b3 = b[15];
3131
+ out[12] = b0 * a00 + b1 * a10 + b2 * a20 + b3 * a30;
3132
+ out[13] = b0 * a01 + b1 * a11 + b2 * a21 + b3 * a31;
3133
+ out[14] = b0 * a02 + b1 * a12 + b2 * a22 + b3 * a32;
3134
+ out[15] = b0 * a03 + b1 * a13 + b2 * a23 + b3 * a33;
3135
+ return out;
3136
+ }
3137
+ /**
3138
+ * Translate a mat4 by the given vector
3139
+ *
3140
+ * @param {mat4} out the receiving matrix
3141
+ * @param {ReadonlyMat4} a the matrix to translate
3142
+ * @param {ReadonlyVec3} v vector to translate by
3143
+ * @returns {mat4} out
3144
+ */
3463
3145
 
3464
- function Plugin() {
3465
- var _this;
3466
3146
 
3467
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
3468
- args[_key] = arguments[_key];
3469
- }
3147
+ function translate(out, a, v) {
3148
+ var x = v[0],
3149
+ y = v[1],
3150
+ z = v[2];
3151
+ var a00, a01, a02, a03;
3152
+ var a10, a11, a12, a13;
3153
+ var a20, a21, a22, a23;
3470
3154
 
3471
- _this = _AbstractRendererPlug.call.apply(_AbstractRendererPlug, [this].concat(args)) || this;
3472
- _this.name = 'image-loader';
3473
- return _this;
3155
+ if (a === out) {
3156
+ out[12] = a[0] * x + a[4] * y + a[8] * z + a[12];
3157
+ out[13] = a[1] * x + a[5] * y + a[9] * z + a[13];
3158
+ out[14] = a[2] * x + a[6] * y + a[10] * z + a[14];
3159
+ out[15] = a[3] * x + a[7] * y + a[11] * z + a[15];
3160
+ } else {
3161
+ a00 = a[0];
3162
+ a01 = a[1];
3163
+ a02 = a[2];
3164
+ a03 = a[3];
3165
+ a10 = a[4];
3166
+ a11 = a[5];
3167
+ a12 = a[6];
3168
+ a13 = a[7];
3169
+ a20 = a[8];
3170
+ a21 = a[9];
3171
+ a22 = a[10];
3172
+ a23 = a[11];
3173
+ out[0] = a00;
3174
+ out[1] = a01;
3175
+ out[2] = a02;
3176
+ out[3] = a03;
3177
+ out[4] = a10;
3178
+ out[5] = a11;
3179
+ out[6] = a12;
3180
+ out[7] = a13;
3181
+ out[8] = a20;
3182
+ out[9] = a21;
3183
+ out[10] = a22;
3184
+ out[11] = a23;
3185
+ out[12] = a00 * x + a10 * y + a20 * z + a[12];
3186
+ out[13] = a01 * x + a11 * y + a21 * z + a[13];
3187
+ out[14] = a02 * x + a12 * y + a22 * z + a[14];
3188
+ out[15] = a03 * x + a13 * y + a23 * z + a[15];
3474
3189
  }
3475
3190
 
3476
- var _proto = Plugin.prototype;
3477
-
3478
- _proto.init = function init() {
3479
- this.container.load(containerModule$2, true);
3480
- };
3481
-
3482
- _proto.destroy = function destroy() {
3483
- this.container.unload(containerModule$2);
3484
- };
3485
-
3486
- return Plugin;
3487
- }(gLite.AbstractRendererPlugin);
3191
+ return out;
3192
+ }
3193
+ /**
3194
+ * Creates a matrix from a vector scaling
3195
+ * This is equivalent to (but much faster than):
3196
+ *
3197
+ * mat4.identity(dest);
3198
+ * mat4.scale(dest, dest, vec);
3199
+ *
3200
+ * @param {mat4} out mat4 receiving operation result
3201
+ * @param {ReadonlyVec3} v Scaling vector
3202
+ * @returns {mat4} out
3203
+ */
3488
3204
 
3489
- var index_esm$2 = /*#__PURE__*/Object.freeze({
3490
- __proto__: null,
3491
- get ImagePool () { return ImagePool; },
3492
- Plugin: Plugin$2
3493
- });
3494
3205
 
3495
- function _regeneratorRuntime$3() {
3496
- /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */
3497
- _regeneratorRuntime$3 = function _regeneratorRuntime() {
3498
- return exports;
3499
- };
3206
+ function fromScaling(out, v) {
3207
+ out[0] = v[0];
3208
+ out[1] = 0;
3209
+ out[2] = 0;
3210
+ out[3] = 0;
3211
+ out[4] = 0;
3212
+ out[5] = v[1];
3213
+ out[6] = 0;
3214
+ out[7] = 0;
3215
+ out[8] = 0;
3216
+ out[9] = 0;
3217
+ out[10] = v[2];
3218
+ out[11] = 0;
3219
+ out[12] = 0;
3220
+ out[13] = 0;
3221
+ out[14] = 0;
3222
+ out[15] = 1;
3223
+ return out;
3224
+ }
3225
+ /**
3226
+ * 3 Dimensional Vector
3227
+ * @module vec3
3228
+ */
3500
3229
 
3501
- var exports = {},
3502
- Op = Object.prototype,
3503
- hasOwn = Op.hasOwnProperty,
3504
- $Symbol = "function" == typeof Symbol ? Symbol : {},
3505
- iteratorSymbol = $Symbol.iterator || "@@iterator",
3506
- asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator",
3507
- toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag";
3230
+ /**
3231
+ * Creates a new, empty vec3
3232
+ *
3233
+ * @returns {vec3} a new 3D vector
3234
+ */
3508
3235
 
3509
- function define(obj, key, value) {
3510
- return Object.defineProperty(obj, key, {
3511
- value: value,
3512
- enumerable: !0,
3513
- configurable: !0,
3514
- writable: !0
3515
- }), obj[key];
3516
- }
3517
3236
 
3518
- try {
3519
- define({}, "");
3520
- } catch (err) {
3521
- define = function define(obj, key, value) {
3522
- return obj[key] = value;
3523
- };
3524
- }
3237
+ function create$1$1() {
3238
+ var out = new ARRAY_TYPE$1(3);
3525
3239
 
3526
- function wrap(innerFn, outerFn, self, tryLocsList) {
3527
- var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator,
3528
- generator = Object.create(protoGenerator.prototype),
3529
- context = new Context(tryLocsList || []);
3530
- return generator._invoke = function (innerFn, self, context) {
3531
- var state = "suspendedStart";
3532
- return function (method, arg) {
3533
- if ("executing" === state) throw new Error("Generator is already running");
3240
+ if (ARRAY_TYPE$1 != Float32Array) {
3241
+ out[0] = 0;
3242
+ out[1] = 0;
3243
+ out[2] = 0;
3244
+ }
3534
3245
 
3535
- if ("completed" === state) {
3536
- if ("throw" === method) throw arg;
3537
- return doneResult();
3538
- }
3246
+ return out;
3247
+ }
3248
+ /**
3249
+ * Creates a new vec3 initialized with the given values
3250
+ *
3251
+ * @param {Number} x X component
3252
+ * @param {Number} y Y component
3253
+ * @param {Number} z Z component
3254
+ * @returns {vec3} a new 3D vector
3255
+ */
3539
3256
 
3540
- for (context.method = method, context.arg = arg;;) {
3541
- var delegate = context.delegate;
3542
3257
 
3543
- if (delegate) {
3544
- var delegateResult = maybeInvokeDelegate(delegate, context);
3258
+ function fromValues(x, y, z) {
3259
+ var out = new ARRAY_TYPE$1(3);
3260
+ out[0] = x;
3261
+ out[1] = y;
3262
+ out[2] = z;
3263
+ return out;
3264
+ }
3265
+ /**
3266
+ * Transforms the vec3 with a mat4.
3267
+ * 4th vector component is implicitly '1'
3268
+ *
3269
+ * @param {vec3} out the receiving vector
3270
+ * @param {ReadonlyVec3} a the vector to transform
3271
+ * @param {ReadonlyMat4} m matrix to transform with
3272
+ * @returns {vec3} out
3273
+ */
3545
3274
 
3546
- if (delegateResult) {
3547
- if (delegateResult === ContinueSentinel) continue;
3548
- return delegateResult;
3549
- }
3550
- }
3551
3275
 
3552
- if ("next" === context.method) context.sent = context._sent = context.arg;else if ("throw" === context.method) {
3553
- if ("suspendedStart" === state) throw state = "completed", context.arg;
3554
- context.dispatchException(context.arg);
3555
- } else "return" === context.method && context.abrupt("return", context.arg);
3556
- state = "executing";
3557
- var record = tryCatch(innerFn, self, context);
3276
+ function transformMat4$1(out, a, m) {
3277
+ var x = a[0],
3278
+ y = a[1],
3279
+ z = a[2];
3280
+ var w = m[3] * x + m[7] * y + m[11] * z + m[15];
3281
+ w = w || 1.0;
3282
+ out[0] = (m[0] * x + m[4] * y + m[8] * z + m[12]) / w;
3283
+ out[1] = (m[1] * x + m[5] * y + m[9] * z + m[13]) / w;
3284
+ out[2] = (m[2] * x + m[6] * y + m[10] * z + m[14]) / w;
3285
+ return out;
3286
+ }
3287
+ /**
3288
+ * Perform some operation over an array of vec3s.
3289
+ *
3290
+ * @param {Array} a the array of vectors to iterate over
3291
+ * @param {Number} stride Number of elements between the start of each vec3. If 0 assumes tightly packed
3292
+ * @param {Number} offset Number of elements to skip at the beginning of the array
3293
+ * @param {Number} count Number of vec3s to iterate over. If 0 iterates over entire array
3294
+ * @param {Function} fn Function to call for each vector in the array
3295
+ * @param {Object} [arg] additional argument to pass to fn
3296
+ * @returns {Array} a
3297
+ * @function
3298
+ */
3558
3299
 
3559
- if ("normal" === record.type) {
3560
- if (state = context.done ? "completed" : "suspendedYield", record.arg === ContinueSentinel) continue;
3561
- return {
3562
- value: record.arg,
3563
- done: context.done
3564
- };
3565
- }
3566
3300
 
3567
- "throw" === record.type && (state = "completed", context.method = "throw", context.arg = record.arg);
3568
- }
3569
- };
3570
- }(innerFn, self, context), generator;
3571
- }
3301
+ var forEach$2 = function () {
3302
+ var vec = create$1$1();
3303
+ return function (a, stride, offset, count, fn, arg) {
3304
+ var i, l;
3572
3305
 
3573
- function tryCatch(fn, obj, arg) {
3574
- try {
3575
- return {
3576
- type: "normal",
3577
- arg: fn.call(obj, arg)
3578
- };
3579
- } catch (err) {
3580
- return {
3581
- type: "throw",
3582
- arg: err
3583
- };
3306
+ if (!stride) {
3307
+ stride = 3;
3584
3308
  }
3585
- }
3586
3309
 
3587
- exports.wrap = wrap;
3588
- var ContinueSentinel = {};
3310
+ if (!offset) {
3311
+ offset = 0;
3312
+ }
3589
3313
 
3590
- function Generator() {}
3314
+ if (count) {
3315
+ l = Math.min(count * stride + offset, a.length);
3316
+ } else {
3317
+ l = a.length;
3318
+ }
3591
3319
 
3592
- function GeneratorFunction() {}
3320
+ for (i = offset; i < l; i += stride) {
3321
+ vec[0] = a[i];
3322
+ vec[1] = a[i + 1];
3323
+ vec[2] = a[i + 2];
3324
+ fn(vec, vec, arg);
3325
+ a[i] = vec[0];
3326
+ a[i + 1] = vec[1];
3327
+ a[i + 2] = vec[2];
3328
+ }
3593
3329
 
3594
- function GeneratorFunctionPrototype() {}
3330
+ return a;
3331
+ };
3332
+ }();
3333
+ /**
3334
+ * support 2 modes in rendering:
3335
+ * * immediate
3336
+ * * delayed: render at the end of frame with dirty-rectangle
3337
+ */
3595
3338
 
3596
- var IteratorPrototype = {};
3597
- define(IteratorPrototype, iteratorSymbol, function () {
3598
- return this;
3599
- });
3600
- var getProto = Object.getPrototypeOf,
3601
- NativeIteratorPrototype = getProto && getProto(getProto(values([])));
3602
- NativeIteratorPrototype && NativeIteratorPrototype !== Op && hasOwn.call(NativeIteratorPrototype, iteratorSymbol) && (IteratorPrototype = NativeIteratorPrototype);
3603
- var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(IteratorPrototype);
3604
3339
 
3605
- function defineIteratorMethods(prototype) {
3606
- ["next", "throw", "return"].forEach(function (method) {
3607
- define(prototype, method, function (arg) {
3608
- return this._invoke(method, arg);
3609
- });
3610
- });
3340
+ var CanvasRendererPlugin = /*#__PURE__*/function () {
3341
+ /**
3342
+ * RBush used in dirty rectangle rendering
3343
+ */
3344
+ function CanvasRendererPlugin(canvasRendererPluginOptions) {
3345
+ this.canvasRendererPluginOptions = void 0;
3346
+ this.context = void 0;
3347
+ this.pathGeneratorFactory = void 0;
3348
+ this.rBush = void 0;
3349
+ this.removedRBushNodeAABBs = [];
3350
+ this.renderQueue = [];
3351
+ this.restoreStack = [];
3352
+ this.clearFullScreen = false;
3353
+ this.vpMatrix = create$3();
3354
+ this.dprMatrix = create$3();
3355
+ this.tmpMat4 = create$3();
3356
+ this.vec3a = create$1$1();
3357
+ this.vec3b = create$1$1();
3358
+ this.vec3c = create$1$1();
3359
+ this.vec3d = create$1$1();
3360
+ this.canvasRendererPluginOptions = canvasRendererPluginOptions;
3611
3361
  }
3612
3362
 
3613
- function AsyncIterator(generator, PromiseImpl) {
3614
- function invoke(method, arg, resolve, reject) {
3615
- var record = tryCatch(generator[method], generator, arg);
3616
-
3617
- if ("throw" !== record.type) {
3618
- var result = record.arg,
3619
- value = result.value;
3620
- return value && "object" == typeof value && hasOwn.call(value, "__await") ? PromiseImpl.resolve(value.__await).then(function (value) {
3621
- invoke("next", value, resolve, reject);
3622
- }, function (err) {
3623
- invoke("throw", err, resolve, reject);
3624
- }) : PromiseImpl.resolve(value).then(function (unwrapped) {
3625
- result.value = unwrapped, resolve(result);
3626
- }, function (error) {
3627
- return invoke("throw", error, resolve, reject);
3628
- });
3629
- }
3363
+ var _proto = CanvasRendererPlugin.prototype;
3630
3364
 
3631
- reject(record.arg);
3632
- }
3365
+ _proto.apply = function apply(context) {
3366
+ var _this = this;
3633
3367
 
3634
- var previousPromise;
3368
+ this.context = context; // @ts-ignore
3635
3369
 
3636
- this._invoke = function (method, arg) {
3637
- function callInvokeWithMethodAndArg() {
3638
- return new PromiseImpl(function (resolve, reject) {
3639
- invoke(method, arg, resolve, reject);
3640
- });
3641
- }
3370
+ var config = context.config,
3371
+ camera = context.camera,
3372
+ renderingService = context.renderingService,
3373
+ renderingContext = context.renderingContext,
3374
+ rBushRoot = context.rBushRoot,
3375
+ pathGeneratorFactory = context.pathGeneratorFactory;
3376
+ this.rBush = rBushRoot;
3377
+ this.pathGeneratorFactory = pathGeneratorFactory;
3378
+ var contextService = context.contextService;
3379
+ var canvas = renderingContext.root.ownerDocument.defaultView;
3642
3380
 
3643
- return previousPromise = previousPromise ? previousPromise.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg();
3644
- };
3645
- }
3381
+ var handleUnmounted = function handleUnmounted(e) {
3382
+ var object = e.target; // remove r-bush node
3383
+ // @ts-ignore
3646
3384
 
3647
- function maybeInvokeDelegate(delegate, context) {
3648
- var method = delegate.iterator[context.method];
3385
+ var rBushNode = object.rBushNode;
3649
3386
 
3650
- if (undefined === method) {
3651
- if (context.delegate = null, "throw" === context.method) {
3652
- if (delegate.iterator.return && (context.method = "return", context.arg = undefined, maybeInvokeDelegate(delegate, context), "throw" === context.method)) return ContinueSentinel;
3653
- context.method = "throw", context.arg = new TypeError("The iterator does not provide a 'throw' method");
3387
+ if (rBushNode.aabb) {
3388
+ // save removed aabbs for dirty-rectangle rendering later
3389
+ _this.removedRBushNodeAABBs.push(rBushNode.aabb);
3654
3390
  }
3391
+ };
3655
3392
 
3656
- return ContinueSentinel;
3657
- }
3393
+ var handleCulled = function handleCulled(e) {
3394
+ var object = e.target; // @ts-ignore
3658
3395
 
3659
- var record = tryCatch(method, delegate.iterator, context.arg);
3660
- if ("throw" === record.type) return context.method = "throw", context.arg = record.arg, context.delegate = null, ContinueSentinel;
3661
- var info = record.arg;
3662
- return info ? info.done ? (context[delegate.resultName] = info.value, context.next = delegate.nextLoc, "return" !== context.method && (context.method = "next", context.arg = undefined), context.delegate = null, ContinueSentinel) : info : (context.method = "throw", context.arg = new TypeError("iterator result is not an object"), context.delegate = null, ContinueSentinel);
3663
- }
3396
+ var rBushNode = object.rBushNode;
3664
3397
 
3665
- function pushTryEntry(locs) {
3666
- var entry = {
3667
- tryLoc: locs[0]
3398
+ if (rBushNode.aabb) {
3399
+ // save removed aabbs for dirty-rectangle rendering later
3400
+ _this.removedRBushNodeAABBs.push(rBushNode.aabb);
3401
+ }
3668
3402
  };
3669
- 1 in locs && (entry.catchLoc = locs[1]), 2 in locs && (entry.finallyLoc = locs[2], entry.afterLoc = locs[3]), this.tryEntries.push(entry);
3670
- }
3671
3403
 
3672
- function resetTryEntry(entry) {
3673
- var record = entry.completion || {};
3674
- record.type = "normal", delete record.arg, entry.completion = record;
3675
- }
3404
+ renderingService.hooks.init.tapPromise(CanvasRendererPlugin.tag, /*#__PURE__*/_asyncToGenerator$2( /*#__PURE__*/_regeneratorRuntime$2().mark(function _callee() {
3405
+ var dpr, width, height, context;
3406
+ return _regeneratorRuntime$2().wrap(function _callee$(_context) {
3407
+ while (1) {
3408
+ switch (_context.prev = _context.next) {
3409
+ case 0:
3410
+ renderingContext.root.addEventListener(gLite.ElementEvent.UNMOUNTED, handleUnmounted);
3411
+ renderingContext.root.addEventListener(gLite.ElementEvent.CULLED, handleCulled); // clear fullscreen
3676
3412
 
3677
- function Context(tryLocsList) {
3678
- this.tryEntries = [{
3679
- tryLoc: "root"
3680
- }], tryLocsList.forEach(pushTryEntry, this), this.reset(!0);
3681
- }
3413
+ dpr = contextService.getDPR();
3414
+ width = config.width, height = config.height;
3415
+ context = contextService.getContext();
3682
3416
 
3683
- function values(iterable) {
3684
- if (iterable) {
3685
- var iteratorMethod = iterable[iteratorSymbol];
3686
- if (iteratorMethod) return iteratorMethod.call(iterable);
3687
- if ("function" == typeof iterable.next) return iterable;
3417
+ _this.clearRect(context, 0, 0, width * dpr, height * dpr, config.background);
3688
3418
 
3689
- if (!isNaN(iterable.length)) {
3690
- var i = -1,
3691
- next = function next() {
3692
- for (; ++i < iterable.length;) {
3693
- if (hasOwn.call(iterable, i)) return next.value = iterable[i], next.done = !1, next;
3419
+ case 6:
3420
+ case "end":
3421
+ return _context.stop();
3694
3422
  }
3423
+ }
3424
+ }, _callee);
3425
+ })));
3426
+ renderingService.hooks.destroy.tap(CanvasRendererPlugin.tag, function () {
3427
+ renderingContext.root.removeEventListener(gLite.ElementEvent.UNMOUNTED, handleUnmounted);
3428
+ renderingContext.root.removeEventListener(gLite.ElementEvent.CULLED, handleCulled);
3429
+ });
3430
+ renderingService.hooks.beginFrame.tap(CanvasRendererPlugin.tag, function () {
3431
+ var context = contextService.getContext();
3432
+ var dpr = contextService.getDPR();
3433
+ var width = config.width,
3434
+ height = config.height;
3435
+ var _this$canvasRendererP = _this.canvasRendererPluginOptions,
3436
+ dirtyObjectNumThreshold = _this$canvasRendererP.dirtyObjectNumThreshold,
3437
+ dirtyObjectRatioThreshold = _this$canvasRendererP.dirtyObjectRatioThreshold; // some heuristic conditions such as 80% object changed
3695
3438
 
3696
- return next.value = undefined, next.done = !0, next;
3697
- };
3698
-
3699
- return next.next = next;
3700
- }
3701
- }
3439
+ var _renderingService$get = renderingService.getStats(),
3440
+ total = _renderingService$get.total,
3441
+ rendered = _renderingService$get.rendered;
3702
3442
 
3703
- return {
3704
- next: doneResult
3705
- };
3706
- }
3443
+ var ratio = rendered / total;
3444
+ _this.clearFullScreen = renderingService.disableDirtyRectangleRendering() || rendered > dirtyObjectNumThreshold && ratio > dirtyObjectRatioThreshold;
3707
3445
 
3708
- function doneResult() {
3709
- return {
3710
- value: undefined,
3711
- done: !0
3712
- };
3713
- }
3446
+ if (context) {
3447
+ context.resetTransform();
3714
3448
 
3715
- return GeneratorFunction.prototype = GeneratorFunctionPrototype, define(Gp, "constructor", GeneratorFunctionPrototype), define(GeneratorFunctionPrototype, "constructor", GeneratorFunction), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, toStringTagSymbol, "GeneratorFunction"), exports.isGeneratorFunction = function (genFun) {
3716
- var ctor = "function" == typeof genFun && genFun.constructor;
3717
- return !!ctor && (ctor === GeneratorFunction || "GeneratorFunction" === (ctor.displayName || ctor.name));
3718
- }, exports.mark = function (genFun) {
3719
- return Object.setPrototypeOf ? Object.setPrototypeOf(genFun, GeneratorFunctionPrototype) : (genFun.__proto__ = GeneratorFunctionPrototype, define(genFun, toStringTagSymbol, "GeneratorFunction")), genFun.prototype = Object.create(Gp), genFun;
3720
- }, exports.awrap = function (arg) {
3721
- return {
3722
- __await: arg
3723
- };
3724
- }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, asyncIteratorSymbol, function () {
3725
- return this;
3726
- }), exports.AsyncIterator = AsyncIterator, exports.async = function (innerFn, outerFn, self, tryLocsList, PromiseImpl) {
3727
- void 0 === PromiseImpl && (PromiseImpl = Promise);
3728
- var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList), PromiseImpl);
3729
- return exports.isGeneratorFunction(outerFn) ? iter : iter.next().then(function (result) {
3730
- return result.done ? result.value : iter.next();
3449
+ if (_this.clearFullScreen) {
3450
+ _this.clearRect(context, 0, 0, width * dpr, height * dpr, config.background);
3451
+ }
3452
+ }
3731
3453
  });
3732
- }, defineIteratorMethods(Gp), define(Gp, toStringTagSymbol, "Generator"), define(Gp, iteratorSymbol, function () {
3733
- return this;
3734
- }), define(Gp, "toString", function () {
3735
- return "[object Generator]";
3736
- }), exports.keys = function (object) {
3737
- var keys = [];
3738
3454
 
3739
- for (var key in object) {
3740
- keys.push(key);
3741
- }
3455
+ var renderByZIndex = function renderByZIndex(object) {
3456
+ if (object.isVisible() && !object.isCulled()) {
3457
+ _this.renderDisplayObject(object, contextService, renderingService); // if we did a full screen rendering last frame
3742
3458
 
3743
- return keys.reverse(), function next() {
3744
- for (; keys.length;) {
3745
- var key = keys.pop();
3746
- if (key in object) return next.value = key, next.done = !1, next;
3747
- }
3748
3459
 
3749
- return next.done = !0, next;
3750
- };
3751
- }, exports.values = values, Context.prototype = {
3752
- constructor: Context,
3753
- reset: function reset(skipTempReset) {
3754
- if (this.prev = 0, this.next = 0, this.sent = this._sent = undefined, this.done = !1, this.delegate = null, this.method = "next", this.arg = undefined, this.tryEntries.forEach(resetTryEntry), !skipTempReset) for (var name in this) {
3755
- "t" === name.charAt(0) && hasOwn.call(this, name) && !isNaN(+name.slice(1)) && (this[name] = undefined);
3460
+ _this.saveDirtyAABB(object);
3756
3461
  }
3757
- },
3758
- stop: function stop() {
3759
- this.done = !0;
3760
- var rootRecord = this.tryEntries[0].completion;
3761
- if ("throw" === rootRecord.type) throw rootRecord.arg;
3762
- return this.rval;
3763
- },
3764
- dispatchException: function dispatchException(exception) {
3765
- if (this.done) throw exception;
3766
- var context = this;
3767
3462
 
3768
- function handle(loc, caught) {
3769
- return record.type = "throw", record.arg = exception, context.next = loc, caught && (context.method = "next", context.arg = undefined), !!caught;
3770
- }
3463
+ var sorted = object.sortable.sorted || object.childNodes; // should account for z-index
3771
3464
 
3772
- for (var i = this.tryEntries.length - 1; i >= 0; --i) {
3773
- var entry = this.tryEntries[i],
3774
- record = entry.completion;
3775
- if ("root" === entry.tryLoc) return handle("end");
3465
+ sorted.forEach(function (child) {
3466
+ renderByZIndex(child);
3467
+ });
3468
+ }; // render at the end of frame
3776
3469
 
3777
- if (entry.tryLoc <= this.prev) {
3778
- var hasCatch = hasOwn.call(entry, "catchLoc"),
3779
- hasFinally = hasOwn.call(entry, "finallyLoc");
3780
3470
 
3781
- if (hasCatch && hasFinally) {
3782
- if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0);
3783
- if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc);
3784
- } else if (hasCatch) {
3785
- if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0);
3786
- } else {
3787
- if (!hasFinally) throw new Error("try statement without catch or finally");
3788
- if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc);
3789
- }
3790
- }
3791
- }
3792
- },
3793
- abrupt: function abrupt(type, arg) {
3794
- for (var i = this.tryEntries.length - 1; i >= 0; --i) {
3795
- var entry = this.tryEntries[i];
3471
+ renderingService.hooks.endFrame.tap(CanvasRendererPlugin.tag, function () {
3472
+ var context = contextService.getContext(); // clear & clip dirty rectangle
3796
3473
 
3797
- if (entry.tryLoc <= this.prev && hasOwn.call(entry, "finallyLoc") && this.prev < entry.finallyLoc) {
3798
- var finallyEntry = entry;
3799
- break;
3474
+ var dpr = contextService.getDPR();
3475
+ fromScaling(_this.dprMatrix, fromValues(dpr, dpr, 1));
3476
+ multiply(_this.vpMatrix, _this.dprMatrix, camera.getOrthoMatrix());
3477
+
3478
+ if (_this.clearFullScreen) {
3479
+ renderByZIndex(renderingContext.root);
3480
+ } else {
3481
+ // merge removed AABB
3482
+ var dirtyRenderBounds = _this.safeMergeAABB.apply(_this, [_this.mergeDirtyAABBs(_this.renderQueue)].concat(_this.removedRBushNodeAABBs.map(function (_ref2) {
3483
+ var minX = _ref2.minX,
3484
+ minY = _ref2.minY,
3485
+ maxX = _ref2.maxX,
3486
+ maxY = _ref2.maxY;
3487
+ var aabb = new gLite.AABB();
3488
+ aabb.setMinMax(fromValues(minX, minY, 0), fromValues(maxX, maxY, 0));
3489
+ return aabb;
3490
+ })));
3491
+
3492
+ _this.removedRBushNodeAABBs = [];
3493
+
3494
+ if (gLite.AABB.isEmpty(dirtyRenderBounds)) {
3495
+ _this.renderQueue = [];
3496
+ return;
3800
3497
  }
3801
- }
3802
3498
 
3803
- finallyEntry && ("break" === type || "continue" === type) && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc && (finallyEntry = null);
3804
- var record = finallyEntry ? finallyEntry.completion : {};
3805
- return record.type = type, record.arg = arg, finallyEntry ? (this.method = "next", this.next = finallyEntry.finallyLoc, ContinueSentinel) : this.complete(record);
3806
- },
3807
- complete: function complete(record, afterLoc) {
3808
- if ("throw" === record.type) throw record.arg;
3809
- return "break" === record.type || "continue" === record.type ? this.next = record.arg : "return" === record.type ? (this.rval = this.arg = record.arg, this.method = "return", this.next = "end") : "normal" === record.type && afterLoc && (this.next = afterLoc), ContinueSentinel;
3810
- },
3811
- finish: function finish(finallyLoc) {
3812
- for (var i = this.tryEntries.length - 1; i >= 0; --i) {
3813
- var entry = this.tryEntries[i];
3814
- if (entry.finallyLoc === finallyLoc) return this.complete(entry.completion, entry.afterLoc), resetTryEntry(entry), ContinueSentinel;
3815
- }
3816
- },
3817
- catch: function _catch(tryLoc) {
3818
- for (var i = this.tryEntries.length - 1; i >= 0; --i) {
3819
- var entry = this.tryEntries[i];
3499
+ var dirtyRect = _this.convertAABB2Rect(dirtyRenderBounds);
3500
+
3501
+ var x = dirtyRect.x,
3502
+ y = dirtyRect.y,
3503
+ width = dirtyRect.width,
3504
+ height = dirtyRect.height;
3505
+ var tl = transformMat4$1(_this.vec3a, fromValues(x, y, 0), _this.vpMatrix);
3506
+ var tr = transformMat4$1(_this.vec3b, fromValues(x + width, y, 0), _this.vpMatrix);
3507
+ var bl = transformMat4$1(_this.vec3c, fromValues(x, y + height, 0), _this.vpMatrix);
3508
+ var br = transformMat4$1(_this.vec3d, fromValues(x + width, y + height, 0), _this.vpMatrix);
3509
+ var minx = Math.min(tl[0], tr[0], br[0], bl[0]);
3510
+ var miny = Math.min(tl[1], tr[1], br[1], bl[1]);
3511
+ var maxx = Math.max(tl[0], tr[0], br[0], bl[0]);
3512
+ var maxy = Math.max(tl[1], tr[1], br[1], bl[1]);
3513
+ var ix = Math.floor(minx);
3514
+ var iy = Math.floor(miny);
3515
+ var iwidth = Math.ceil(maxx - minx);
3516
+ var iheight = Math.ceil(maxy - miny);
3517
+ context.save();
3518
+
3519
+ _this.clearRect(context, ix, iy, iwidth, iheight, config.background);
3520
+
3521
+ context.beginPath();
3522
+ context.rect(ix, iy, iwidth, iheight);
3523
+ context.clip(); // @see https://developer.mozilla.org/en-US/docs/Web/API/Canvas_API/Tutorial/Transformations
3524
+
3525
+ context.setTransform(_this.vpMatrix[0], _this.vpMatrix[1], _this.vpMatrix[4], _this.vpMatrix[5], _this.vpMatrix[12], _this.vpMatrix[13]); // draw dirty rectangle
3526
+
3527
+ var _config$renderer$getC = config.renderer.getConfig(),
3528
+ enableDirtyRectangleRenderingDebug = _config$renderer$getC.enableDirtyRectangleRenderingDebug;
3529
+
3530
+ if (enableDirtyRectangleRenderingDebug) {
3531
+ canvas.dispatchEvent(new gLite.CustomEvent(gLite.CanvasEvent.DIRTY_RECTANGLE, {
3532
+ dirtyRect: {
3533
+ x: ix,
3534
+ y: iy,
3535
+ width: iwidth,
3536
+ height: iheight
3537
+ }
3538
+ }));
3539
+ } // search objects intersect with dirty rectangle
3820
3540
 
3821
- if (entry.tryLoc === tryLoc) {
3822
- var record = entry.completion;
3823
3541
 
3824
- if ("throw" === record.type) {
3825
- var thrown = record.arg;
3826
- resetTryEntry(entry);
3542
+ var dirtyObjects = _this.searchDirtyObjects(dirtyRenderBounds); // do rendering
3543
+
3544
+
3545
+ dirtyObjects // sort by z-index
3546
+ .sort(function (a, b) {
3547
+ return a.sortable.renderOrder - b.sortable.renderOrder;
3548
+ }).forEach(function (object) {
3549
+ // culled object should not be rendered
3550
+ if (object && object.isVisible() && !object.isCulled()) {
3551
+ _this.renderDisplayObject(object, contextService, renderingService);
3827
3552
  }
3553
+ });
3554
+ context.restore(); // save dirty AABBs in last frame
3828
3555
 
3829
- return thrown;
3830
- }
3831
- }
3556
+ _this.renderQueue.forEach(function (object) {
3557
+ _this.saveDirtyAABB(object);
3558
+ }); // clear queue
3832
3559
 
3833
- throw new Error("illegal catch attempt");
3834
- },
3835
- delegateYield: function delegateYield(iterable, resultName, nextLoc) {
3836
- return this.delegate = {
3837
- iterator: values(iterable),
3838
- resultName: resultName,
3839
- nextLoc: nextLoc
3840
- }, "next" === this.method && (this.arg = undefined), ContinueSentinel;
3841
- }
3842
- }, exports;
3843
- }
3844
3560
 
3845
- function asyncGeneratorStep$3(gen, resolve, reject, _next, _throw, key, arg) {
3846
- try {
3847
- var info = gen[key](arg);
3848
- var value = info.value;
3849
- } catch (error) {
3850
- reject(error);
3851
- return;
3852
- }
3561
+ _this.renderQueue = [];
3562
+ } // pop restore stack, eg. root -> parent -> child
3853
3563
 
3854
- if (info.done) {
3855
- resolve(value);
3856
- } else {
3857
- Promise.resolve(value).then(_next, _throw);
3858
- }
3859
- }
3860
3564
 
3861
- function _asyncToGenerator$3(fn) {
3862
- return function () {
3863
- var self = this,
3864
- args = arguments;
3865
- return new Promise(function (resolve, reject) {
3866
- var gen = fn.apply(self, args);
3565
+ _this.restoreStack.forEach(function () {
3566
+ context.restore();
3567
+ }); // clear restore stack
3867
3568
 
3868
- function _next(value) {
3869
- asyncGeneratorStep$3(gen, resolve, reject, _next, _throw, "next", value);
3870
- }
3871
3569
 
3872
- function _throw(err) {
3873
- asyncGeneratorStep$3(gen, resolve, reject, _next, _throw, "throw", err);
3570
+ _this.restoreStack = [];
3571
+ });
3572
+ renderingService.hooks.render.tap(CanvasRendererPlugin.tag, function (object) {
3573
+ if (!_this.clearFullScreen) {
3574
+ // render at the end of frame
3575
+ _this.renderQueue.push(object);
3874
3576
  }
3875
-
3876
- _next(undefined);
3877
3577
  });
3878
3578
  };
3879
- }
3880
3579
 
3881
- function _extends() {
3882
- _extends = Object.assign ? Object.assign.bind() : function (target) {
3883
- for (var i = 1; i < arguments.length; i++) {
3884
- var source = arguments[i];
3580
+ _proto.clearRect = function clearRect(context, x, y, width, height, background) {
3581
+ // clearRect is faster than fillRect @see https://stackoverflow.com/a/30830253
3582
+ context.clearRect(x, y, width, height);
3885
3583
 
3886
- for (var key in source) {
3887
- if (Object.prototype.hasOwnProperty.call(source, key)) {
3888
- target[key] = source[key];
3889
- }
3890
- }
3584
+ if (background) {
3585
+ context.fillStyle = background;
3586
+ context.fillRect(x, y, width, height);
3891
3587
  }
3892
-
3893
- return target;
3894
- };
3895
- return _extends.apply(this, arguments);
3896
- }
3897
-
3898
- function _inheritsLoose$4(subClass, superClass) {
3899
- subClass.prototype = Object.create(superClass.prototype);
3900
- subClass.prototype.constructor = subClass;
3901
-
3902
- _setPrototypeOf$4(subClass, superClass);
3903
- }
3904
-
3905
- function _setPrototypeOf$4(o, p) {
3906
- _setPrototypeOf$4 = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) {
3907
- o.__proto__ = p;
3908
- return o;
3909
3588
  };
3910
- return _setPrototypeOf$4(o, p);
3911
- }
3912
- /**
3913
- * Common utilities
3914
- * @module glMatrix
3915
- */
3916
-
3917
3589
 
3918
- var ARRAY_TYPE$1 = typeof Float32Array !== 'undefined' ? Float32Array : Array;
3919
- if (!Math.hypot) Math.hypot = function () {
3920
- var y = 0,
3921
- i = arguments.length;
3590
+ _proto.renderDisplayObject = function renderDisplayObject(object, contextService, renderingService) {
3591
+ var context = contextService.getContext();
3592
+ var nodeName = object.nodeName; // restore to its ancestor
3922
3593
 
3923
- while (i--) {
3924
- y += arguments[i] * arguments[i];
3925
- }
3594
+ var parent = this.restoreStack[this.restoreStack.length - 1];
3926
3595
 
3927
- return Math.sqrt(y);
3928
- };
3929
- /**
3930
- * 4x4 Matrix<br>Format: column-major, when typed out it looks like row-major<br>The matrices are being post multiplied.
3931
- * @module mat4
3932
- */
3596
+ if (parent && !(object.compareDocumentPosition(parent) & Node.DOCUMENT_POSITION_CONTAINS)) {
3597
+ context.restore();
3598
+ this.restoreStack.pop();
3599
+ } // @ts-ignore
3933
3600
 
3934
- /**
3935
- * Creates a new identity mat4
3936
- *
3937
- * @returns {mat4} a new 4x4 matrix
3938
- */
3939
3601
 
3940
- function create$3() {
3941
- var out = new ARRAY_TYPE$1(16);
3602
+ var styleRenderer = this.context.styleRendererFactory[nodeName];
3603
+ var generatePath = this.pathGeneratorFactory[nodeName]; // clip path
3942
3604
 
3943
- if (ARRAY_TYPE$1 != Float32Array) {
3944
- out[1] = 0;
3945
- out[2] = 0;
3946
- out[3] = 0;
3947
- out[4] = 0;
3948
- out[6] = 0;
3949
- out[7] = 0;
3950
- out[8] = 0;
3951
- out[9] = 0;
3952
- out[11] = 0;
3953
- out[12] = 0;
3954
- out[13] = 0;
3955
- out[14] = 0;
3956
- }
3605
+ var clipPath = object.parsedStyle.clipPath;
3957
3606
 
3958
- out[0] = 1;
3959
- out[5] = 1;
3960
- out[10] = 1;
3961
- out[15] = 1;
3962
- return out;
3963
- }
3964
- /**
3965
- * Copy the values from one mat4 to another
3966
- *
3967
- * @param {mat4} out the receiving matrix
3968
- * @param {ReadonlyMat4} a the source matrix
3969
- * @returns {mat4} out
3970
- */
3607
+ if (clipPath) {
3608
+ this.applyWorldTransform(context, clipPath); // generate path in local space
3971
3609
 
3610
+ var _generatePath = this.pathGeneratorFactory[clipPath.nodeName];
3972
3611
 
3973
- function copy(out, a) {
3974
- out[0] = a[0];
3975
- out[1] = a[1];
3976
- out[2] = a[2];
3977
- out[3] = a[3];
3978
- out[4] = a[4];
3979
- out[5] = a[5];
3980
- out[6] = a[6];
3981
- out[7] = a[7];
3982
- out[8] = a[8];
3983
- out[9] = a[9];
3984
- out[10] = a[10];
3985
- out[11] = a[11];
3986
- out[12] = a[12];
3987
- out[13] = a[13];
3988
- out[14] = a[14];
3989
- out[15] = a[15];
3990
- return out;
3991
- }
3992
- /**
3993
- * Multiplies two mat4s
3994
- *
3995
- * @param {mat4} out the receiving matrix
3996
- * @param {ReadonlyMat4} a the first operand
3997
- * @param {ReadonlyMat4} b the second operand
3998
- * @returns {mat4} out
3999
- */
3612
+ if (_generatePath) {
3613
+ context.save(); // save clip
4000
3614
 
3615
+ this.restoreStack.push(object);
3616
+ context.beginPath();
4001
3617
 
4002
- function multiply$1(out, a, b) {
4003
- var a00 = a[0],
4004
- a01 = a[1],
4005
- a02 = a[2],
4006
- a03 = a[3];
4007
- var a10 = a[4],
4008
- a11 = a[5],
4009
- a12 = a[6],
4010
- a13 = a[7];
4011
- var a20 = a[8],
4012
- a21 = a[9],
4013
- a22 = a[10],
4014
- a23 = a[11];
4015
- var a30 = a[12],
4016
- a31 = a[13],
4017
- a32 = a[14],
4018
- a33 = a[15]; // Cache only the current line of the second matrix
3618
+ _generatePath(context, clipPath.parsedStyle);
4019
3619
 
4020
- var b0 = b[0],
4021
- b1 = b[1],
4022
- b2 = b[2],
4023
- b3 = b[3];
4024
- out[0] = b0 * a00 + b1 * a10 + b2 * a20 + b3 * a30;
4025
- out[1] = b0 * a01 + b1 * a11 + b2 * a21 + b3 * a31;
4026
- out[2] = b0 * a02 + b1 * a12 + b2 * a22 + b3 * a32;
4027
- out[3] = b0 * a03 + b1 * a13 + b2 * a23 + b3 * a33;
4028
- b0 = b[4];
4029
- b1 = b[5];
4030
- b2 = b[6];
4031
- b3 = b[7];
4032
- out[4] = b0 * a00 + b1 * a10 + b2 * a20 + b3 * a30;
4033
- out[5] = b0 * a01 + b1 * a11 + b2 * a21 + b3 * a31;
4034
- out[6] = b0 * a02 + b1 * a12 + b2 * a22 + b3 * a32;
4035
- out[7] = b0 * a03 + b1 * a13 + b2 * a23 + b3 * a33;
4036
- b0 = b[8];
4037
- b1 = b[9];
4038
- b2 = b[10];
4039
- b3 = b[11];
4040
- out[8] = b0 * a00 + b1 * a10 + b2 * a20 + b3 * a30;
4041
- out[9] = b0 * a01 + b1 * a11 + b2 * a21 + b3 * a31;
4042
- out[10] = b0 * a02 + b1 * a12 + b2 * a22 + b3 * a32;
4043
- out[11] = b0 * a03 + b1 * a13 + b2 * a23 + b3 * a33;
4044
- b0 = b[12];
4045
- b1 = b[13];
4046
- b2 = b[14];
4047
- b3 = b[15];
4048
- out[12] = b0 * a00 + b1 * a10 + b2 * a20 + b3 * a30;
4049
- out[13] = b0 * a01 + b1 * a11 + b2 * a21 + b3 * a31;
4050
- out[14] = b0 * a02 + b1 * a12 + b2 * a22 + b3 * a32;
4051
- out[15] = b0 * a03 + b1 * a13 + b2 * a23 + b3 * a33;
4052
- return out;
4053
- }
4054
- /**
4055
- * Translate a mat4 by the given vector
4056
- *
4057
- * @param {mat4} out the receiving matrix
4058
- * @param {ReadonlyMat4} a the matrix to translate
4059
- * @param {ReadonlyVec3} v vector to translate by
4060
- * @returns {mat4} out
4061
- */
3620
+ context.closePath();
3621
+ context.clip();
3622
+ }
3623
+ } // fill & stroke
4062
3624
 
4063
3625
 
4064
- function translate(out, a, v) {
4065
- var x = v[0],
4066
- y = v[1],
4067
- z = v[2];
4068
- var a00, a01, a02, a03;
4069
- var a10, a11, a12, a13;
4070
- var a20, a21, a22, a23;
3626
+ if (styleRenderer) {
3627
+ this.applyWorldTransform(context, object);
3628
+ context.save(); // apply attributes to context
4071
3629
 
4072
- if (a === out) {
4073
- out[12] = a[0] * x + a[4] * y + a[8] * z + a[12];
4074
- out[13] = a[1] * x + a[5] * y + a[9] * z + a[13];
4075
- out[14] = a[2] * x + a[6] * y + a[10] * z + a[14];
4076
- out[15] = a[3] * x + a[7] * y + a[11] * z + a[15];
4077
- } else {
4078
- a00 = a[0];
4079
- a01 = a[1];
4080
- a02 = a[2];
4081
- a03 = a[3];
4082
- a10 = a[4];
4083
- a11 = a[5];
4084
- a12 = a[6];
4085
- a13 = a[7];
4086
- a20 = a[8];
4087
- a21 = a[9];
4088
- a22 = a[10];
4089
- a23 = a[11];
4090
- out[0] = a00;
4091
- out[1] = a01;
4092
- out[2] = a02;
4093
- out[3] = a03;
4094
- out[4] = a10;
4095
- out[5] = a11;
4096
- out[6] = a12;
4097
- out[7] = a13;
4098
- out[8] = a20;
4099
- out[9] = a21;
4100
- out[10] = a22;
4101
- out[11] = a23;
4102
- out[12] = a00 * x + a10 * y + a20 * z + a[12];
4103
- out[13] = a01 * x + a11 * y + a21 * z + a[13];
4104
- out[14] = a02 * x + a12 * y + a22 * z + a[14];
4105
- out[15] = a03 * x + a13 * y + a23 * z + a[15];
4106
- }
3630
+ this.applyAttributesToContext(context, object);
3631
+ }
4107
3632
 
4108
- return out;
4109
- }
4110
- /**
4111
- * Creates a matrix from a vector scaling
4112
- * This is equivalent to (but much faster than):
4113
- *
4114
- * mat4.identity(dest);
4115
- * mat4.scale(dest, dest, vec);
4116
- *
4117
- * @param {mat4} out mat4 receiving operation result
4118
- * @param {ReadonlyVec3} v Scaling vector
4119
- * @returns {mat4} out
4120
- */
3633
+ if (generatePath) {
3634
+ context.beginPath();
3635
+ generatePath(context, object.parsedStyle);
4121
3636
 
3637
+ if (object.nodeName !== gLite.Shape.LINE && object.nodeName !== gLite.Shape.PATH && object.nodeName !== gLite.Shape.POLYLINE) {
3638
+ context.closePath();
3639
+ }
3640
+ } // fill & stroke
4122
3641
 
4123
- function fromScaling(out, v) {
4124
- out[0] = v[0];
4125
- out[1] = 0;
4126
- out[2] = 0;
4127
- out[3] = 0;
4128
- out[4] = 0;
4129
- out[5] = v[1];
4130
- out[6] = 0;
4131
- out[7] = 0;
4132
- out[8] = 0;
4133
- out[9] = 0;
4134
- out[10] = v[2];
4135
- out[11] = 0;
4136
- out[12] = 0;
4137
- out[13] = 0;
4138
- out[14] = 0;
4139
- out[15] = 1;
4140
- return out;
4141
- }
4142
- /**
4143
- * 3 Dimensional Vector
4144
- * @module vec3
4145
- */
4146
3642
 
4147
- /**
4148
- * Creates a new, empty vec3
4149
- *
4150
- * @returns {vec3} a new 3D vector
4151
- */
3643
+ if (styleRenderer) {
3644
+ styleRenderer.render(context, object.parsedStyle, object, renderingService); // restore applied attributes, eg. shadowBlur shadowColor...
4152
3645
 
3646
+ context.restore();
3647
+ } // finish rendering, clear dirty flag
4153
3648
 
4154
- function create$1$1() {
4155
- var out = new ARRAY_TYPE$1(3);
4156
3649
 
4157
- if (ARRAY_TYPE$1 != Float32Array) {
4158
- out[0] = 0;
4159
- out[1] = 0;
4160
- out[2] = 0;
3650
+ object.renderable.dirty = false;
3651
+ };
3652
+
3653
+ _proto.convertAABB2Rect = function convertAABB2Rect(aabb) {
3654
+ var min = aabb.getMin();
3655
+ var max = aabb.getMax(); // expand the rectangle a bit to avoid artifacts
3656
+ // @see https://www.yuque.com/antv/ou292n/bi8nix#ExvCu
3657
+
3658
+ var minX = Math.floor(min[0]);
3659
+ var minY = Math.floor(min[1]);
3660
+ var maxX = Math.ceil(max[0]);
3661
+ var maxY = Math.ceil(max[1]);
3662
+ var width = maxX - minX;
3663
+ var height = maxY - minY;
3664
+ return {
3665
+ x: minX,
3666
+ y: minY,
3667
+ width: width,
3668
+ height: height
3669
+ };
4161
3670
  }
3671
+ /**
3672
+ * TODO: merge dirty rectangles with some strategies.
3673
+ * For now, we just simply merge all the rectangles into one.
3674
+ * @see https://idom.me/articles/841.html
3675
+ */
3676
+ ;
4162
3677
 
4163
- return out;
4164
- }
4165
- /**
4166
- * Creates a new vec3 initialized with the given values
4167
- *
4168
- * @param {Number} x X component
4169
- * @param {Number} y Y component
4170
- * @param {Number} z Z component
4171
- * @returns {vec3} a new 3D vector
4172
- */
3678
+ _proto.mergeDirtyAABBs = function mergeDirtyAABBs(dirtyObjects) {
3679
+ // merge into a big AABB
3680
+ // TODO: skip descendant if ancestor is caculated, but compareNodePosition is really slow
3681
+ var aabb = new gLite.AABB();
3682
+ dirtyObjects.forEach(function (object) {
3683
+ var renderBounds = object.getRenderBounds();
3684
+ aabb.add(renderBounds);
3685
+ var dirtyRenderBounds = object.renderable.dirtyRenderBounds;
4173
3686
 
3687
+ if (dirtyRenderBounds) {
3688
+ aabb.add(dirtyRenderBounds);
3689
+ }
3690
+ });
3691
+ return aabb;
3692
+ };
4174
3693
 
4175
- function fromValues(x, y, z) {
4176
- var out = new ARRAY_TYPE$1(3);
4177
- out[0] = x;
4178
- out[1] = y;
4179
- out[2] = z;
4180
- return out;
4181
- }
4182
- /**
4183
- * Transforms the vec3 with a mat4.
4184
- * 4th vector component is implicitly '1'
4185
- *
4186
- * @param {vec3} out the receiving vector
4187
- * @param {ReadonlyVec3} a the vector to transform
4188
- * @param {ReadonlyMat4} m matrix to transform with
4189
- * @returns {vec3} out
4190
- */
3694
+ _proto.searchDirtyObjects = function searchDirtyObjects(dirtyRectangle) {
3695
+ // search in r-tree, get all affected nodes
3696
+ var _dirtyRectangle$getMi = dirtyRectangle.getMin(),
3697
+ minX = _dirtyRectangle$getMi[0],
3698
+ minY = _dirtyRectangle$getMi[1];
4191
3699
 
3700
+ var _dirtyRectangle$getMa = dirtyRectangle.getMax(),
3701
+ maxX = _dirtyRectangle$getMa[0],
3702
+ maxY = _dirtyRectangle$getMa[1];
4192
3703
 
4193
- function transformMat4$1(out, a, m) {
4194
- var x = a[0],
4195
- y = a[1],
4196
- z = a[2];
4197
- var w = m[3] * x + m[7] * y + m[11] * z + m[15];
4198
- w = w || 1.0;
4199
- out[0] = (m[0] * x + m[4] * y + m[8] * z + m[12]) / w;
4200
- out[1] = (m[1] * x + m[5] * y + m[9] * z + m[13]) / w;
4201
- out[2] = (m[2] * x + m[6] * y + m[10] * z + m[14]) / w;
4202
- return out;
4203
- }
4204
- /**
4205
- * Perform some operation over an array of vec3s.
4206
- *
4207
- * @param {Array} a the array of vectors to iterate over
4208
- * @param {Number} stride Number of elements between the start of each vec3. If 0 assumes tightly packed
4209
- * @param {Number} offset Number of elements to skip at the beginning of the array
4210
- * @param {Number} count Number of vec3s to iterate over. If 0 iterates over entire array
4211
- * @param {Function} fn Function to call for each vector in the array
4212
- * @param {Object} [arg] additional argument to pass to fn
4213
- * @returns {Array} a
4214
- * @function
4215
- */
3704
+ var rBushNodes = this.rBush.search({
3705
+ minX: minX,
3706
+ minY: minY,
3707
+ maxX: maxX,
3708
+ maxY: maxY
3709
+ });
3710
+ return rBushNodes.map(function (_ref3) {
3711
+ var id = _ref3.id;
3712
+ return gLite.runtime.displayObjectPool.getByEntity(id);
3713
+ });
3714
+ };
3715
+
3716
+ _proto.saveDirtyAABB = function saveDirtyAABB(object) {
3717
+ var renderable = object.renderable;
4216
3718
 
3719
+ if (!renderable.dirtyRenderBounds) {
3720
+ renderable.dirtyRenderBounds = new gLite.AABB();
3721
+ }
4217
3722
 
4218
- var forEach$2 = function () {
4219
- var vec = create$1$1();
4220
- return function (a, stride, offset, count, fn, arg) {
4221
- var i, l;
3723
+ var renderBounds = object.getRenderBounds();
3724
+
3725
+ if (renderBounds) {
3726
+ // save last dirty aabb
3727
+ renderable.dirtyRenderBounds.update(renderBounds.center, renderBounds.halfExtents);
3728
+ }
3729
+ }
3730
+ /**
3731
+ * TODO: batch the same global attributes
3732
+ */
3733
+ ;
3734
+
3735
+ _proto.applyAttributesToContext = function applyAttributesToContext(context, object) {
3736
+ var _object$parsedStyle = object.parsedStyle,
3737
+ stroke = _object$parsedStyle.stroke,
3738
+ fill = _object$parsedStyle.fill,
3739
+ opacity = _object$parsedStyle.opacity,
3740
+ lineDash = _object$parsedStyle.lineDash,
3741
+ lineDashOffset = _object$parsedStyle.lineDashOffset; // @see https://developer.mozilla.org/zh-CN/docs/Web/API/CanvasRenderingContext2D/setLineDash
3742
+
3743
+ if (lineDash) {
3744
+ context.setLineDash(lineDash);
3745
+ } // @see https://developer.mozilla.org/zh-CN/docs/Web/API/CanvasRenderingContext2D/lineDashOffset
3746
+
3747
+
3748
+ if (!isNil(lineDashOffset)) {
3749
+ context.lineDashOffset = lineDashOffset;
3750
+ }
3751
+
3752
+ if (!isNil(opacity)) {
3753
+ context.globalAlpha *= opacity;
3754
+ }
4222
3755
 
4223
- if (!stride) {
4224
- stride = 3;
3756
+ if (!isNil(stroke) && !Array.isArray(stroke) && !stroke.isNone) {
3757
+ context.strokeStyle = object.attributes.stroke;
4225
3758
  }
4226
3759
 
4227
- if (!offset) {
4228
- offset = 0;
3760
+ if (!isNil(fill) && !Array.isArray(fill) && !fill.isNone) {
3761
+ context.fillStyle = object.attributes.fill;
4229
3762
  }
3763
+ };
4230
3764
 
4231
- if (count) {
4232
- l = Math.min(count * stride + offset, a.length);
3765
+ _proto.applyWorldTransform = function applyWorldTransform(context, object, matrix) {
3766
+ var tx = 0;
3767
+ var ty = 0;
3768
+
3769
+ var _ref4 = object.parsedStyle || {},
3770
+ anchor = _ref4.anchor;
3771
+
3772
+ var anchorX = anchor && anchor[0] || 0;
3773
+ var anchorY = anchor && anchor[1] || 0;
3774
+
3775
+ if (anchorX !== 0 || anchorY !== 0) {
3776
+ var bounds = object.getGeometryBounds();
3777
+ var width = bounds && bounds.halfExtents[0] * 2 || 0;
3778
+ var height = bounds && bounds.halfExtents[1] * 2 || 0;
3779
+ tx = -(anchorX * width);
3780
+ ty = -(anchorY * height);
3781
+ } // apply clip shape's RTS
3782
+
3783
+
3784
+ if (matrix) {
3785
+ copy(this.tmpMat4, object.getLocalTransform());
3786
+ this.vec3a[0] = tx;
3787
+ this.vec3a[1] = ty;
3788
+ this.vec3a[2] = 0;
3789
+ translate(this.tmpMat4, this.tmpMat4, this.vec3a);
3790
+ multiply(this.tmpMat4, matrix, this.tmpMat4);
3791
+ multiply(this.tmpMat4, this.vpMatrix, this.tmpMat4);
4233
3792
  } else {
4234
- l = a.length;
4235
- }
3793
+ // apply RTS transformation in world space
3794
+ copy(this.tmpMat4, object.getWorldTransform());
3795
+ this.vec3a[0] = tx;
3796
+ this.vec3a[1] = ty;
3797
+ this.vec3a[2] = 0;
3798
+ translate(this.tmpMat4, this.tmpMat4, this.vec3a);
3799
+ multiply(this.tmpMat4, this.vpMatrix, this.tmpMat4);
3800
+ } // @see https://developer.mozilla.org/en-US/docs/Web/API/Canvas_API/Tutorial/Transformations
4236
3801
 
4237
- for (i = offset; i < l; i += stride) {
4238
- vec[0] = a[i];
4239
- vec[1] = a[i + 1];
4240
- vec[2] = a[i + 2];
4241
- fn(vec, vec, arg);
4242
- a[i] = vec[0];
4243
- a[i + 1] = vec[1];
4244
- a[i + 2] = vec[2];
3802
+
3803
+ context.setTransform(this.tmpMat4[0], this.tmpMat4[1], this.tmpMat4[4], this.tmpMat4[5], this.tmpMat4[12], this.tmpMat4[13]);
3804
+ };
3805
+
3806
+ _proto.safeMergeAABB = function safeMergeAABB() {
3807
+ var merged = new gLite.AABB();
3808
+
3809
+ for (var _len = arguments.length, aabbs = new Array(_len), _key = 0; _key < _len; _key++) {
3810
+ aabbs[_key] = arguments[_key];
4245
3811
  }
4246
3812
 
4247
- return a;
3813
+ aabbs.forEach(function (aabb) {
3814
+ merged.add(aabb);
3815
+ });
3816
+ return merged;
4248
3817
  };
3818
+
3819
+ return CanvasRendererPlugin;
4249
3820
  }();
4250
3821
 
4251
- var StyleRendererFactory = gLite.Syringe.defineToken('');
4252
- var CircleRendererContribution = gLite.Syringe.defineToken('', {
4253
- multiple: false
4254
- });
4255
- var EllipseRendererContribution = gLite.Syringe.defineToken('', {
4256
- multiple: false
4257
- });
4258
- var RectRendererContribution = gLite.Syringe.defineToken('', {
4259
- multiple: false
4260
- });
4261
- var LineRendererContribution = gLite.Syringe.defineToken('', {
4262
- multiple: false
4263
- });
4264
- var PolylineRendererContribution = gLite.Syringe.defineToken('', {
4265
- multiple: false
4266
- });
4267
- var PolygonRendererContribution = gLite.Syringe.defineToken('', {
4268
- multiple: false
4269
- });
4270
- var PathRendererContribution = gLite.Syringe.defineToken('', {
4271
- multiple: false
4272
- });
4273
- var TextRendererContribution = gLite.Syringe.defineToken('', {
4274
- multiple: false
4275
- });
4276
- var ImageRendererContribution = gLite.Syringe.defineToken('', {
4277
- multiple: false
4278
- });
3822
+ CanvasRendererPlugin.tag = 'CanvasRenderer';
4279
3823
 
4280
3824
  var DefaultRenderer = /*#__PURE__*/function () {
4281
3825
  function DefaultRenderer(imagePool) {
@@ -4436,12 +3980,11 @@
4436
3980
 
4437
3981
  return DefaultRenderer;
4438
3982
  }();
4439
-
4440
- DefaultRenderer = __decorate([gLite.singleton(), __param(0, gLite.inject(ImagePool))], DefaultRenderer);
4441
3983
  /**
4442
3984
  * apply before fill and stroke but only once
4443
3985
  */
4444
3986
 
3987
+
4445
3988
  function setShadowAndFilter(object, context, hasShadow) {
4446
3989
  var _object$parsedStyle = object.parsedStyle,
4447
3990
  filter = _object$parsedStyle.filter,
@@ -4504,10 +4047,6 @@
4504
4047
  return ImageRenderer;
4505
4048
  }();
4506
4049
 
4507
- ImageRenderer = __decorate([gLite.singleton({
4508
- token: ImageRendererContribution
4509
- }), __param(0, gLite.inject(ImagePool))], ImageRenderer);
4510
-
4511
4050
  var TextRenderer = /*#__PURE__*/function () {
4512
4051
  function TextRenderer() {}
4513
4052
 
@@ -4659,12 +4198,8 @@
4659
4198
  return TextRenderer;
4660
4199
  }();
4661
4200
 
4662
- TextRenderer = __decorate([gLite.singleton({
4663
- token: TextRendererContribution
4664
- })], TextRenderer);
4665
-
4666
4201
  var RectRenderer = /*#__PURE__*/function (_DefaultRenderer) {
4667
- _inheritsLoose$4(RectRenderer, _DefaultRenderer);
4202
+ _inheritsLoose$3(RectRenderer, _DefaultRenderer);
4668
4203
 
4669
4204
  function RectRenderer() {
4670
4205
  return _DefaultRenderer.apply(this, arguments) || this;
@@ -4673,12 +4208,8 @@
4673
4208
  return RectRenderer;
4674
4209
  }(DefaultRenderer);
4675
4210
 
4676
- RectRenderer = __decorate([gLite.singleton({
4677
- token: RectRendererContribution
4678
- })], RectRenderer);
4679
-
4680
4211
  var CircleRenderer = /*#__PURE__*/function (_DefaultRenderer) {
4681
- _inheritsLoose$4(CircleRenderer, _DefaultRenderer);
4212
+ _inheritsLoose$3(CircleRenderer, _DefaultRenderer);
4682
4213
 
4683
4214
  function CircleRenderer() {
4684
4215
  return _DefaultRenderer.apply(this, arguments) || this;
@@ -4687,12 +4218,8 @@
4687
4218
  return CircleRenderer;
4688
4219
  }(DefaultRenderer);
4689
4220
 
4690
- CircleRenderer = __decorate([gLite.singleton({
4691
- token: CircleRendererContribution
4692
- })], CircleRenderer);
4693
-
4694
4221
  var EllipseRenderer = /*#__PURE__*/function (_DefaultRenderer) {
4695
- _inheritsLoose$4(EllipseRenderer, _DefaultRenderer);
4222
+ _inheritsLoose$3(EllipseRenderer, _DefaultRenderer);
4696
4223
 
4697
4224
  function EllipseRenderer() {
4698
4225
  return _DefaultRenderer.apply(this, arguments) || this;
@@ -4701,12 +4228,8 @@
4701
4228
  return EllipseRenderer;
4702
4229
  }(DefaultRenderer);
4703
4230
 
4704
- EllipseRenderer = __decorate([gLite.singleton({
4705
- token: EllipseRendererContribution
4706
- })], EllipseRenderer);
4707
-
4708
4231
  var LineRenderer = /*#__PURE__*/function (_DefaultRenderer) {
4709
- _inheritsLoose$4(LineRenderer, _DefaultRenderer);
4232
+ _inheritsLoose$3(LineRenderer, _DefaultRenderer);
4710
4233
 
4711
4234
  function LineRenderer() {
4712
4235
  return _DefaultRenderer.apply(this, arguments) || this;
@@ -4715,12 +4238,8 @@
4715
4238
  return LineRenderer;
4716
4239
  }(DefaultRenderer);
4717
4240
 
4718
- LineRenderer = __decorate([gLite.singleton({
4719
- token: LineRendererContribution
4720
- })], LineRenderer);
4721
-
4722
4241
  var PolylineRenderer = /*#__PURE__*/function (_DefaultRenderer) {
4723
- _inheritsLoose$4(PolylineRenderer, _DefaultRenderer);
4242
+ _inheritsLoose$3(PolylineRenderer, _DefaultRenderer);
4724
4243
 
4725
4244
  function PolylineRenderer() {
4726
4245
  return _DefaultRenderer.apply(this, arguments) || this;
@@ -4729,12 +4248,8 @@
4729
4248
  return PolylineRenderer;
4730
4249
  }(DefaultRenderer);
4731
4250
 
4732
- PolylineRenderer = __decorate([gLite.singleton({
4733
- token: PolylineRendererContribution
4734
- })], PolylineRenderer);
4735
-
4736
4251
  var PolygonRenderer = /*#__PURE__*/function (_DefaultRenderer) {
4737
- _inheritsLoose$4(PolygonRenderer, _DefaultRenderer);
4252
+ _inheritsLoose$3(PolygonRenderer, _DefaultRenderer);
4738
4253
 
4739
4254
  function PolygonRenderer() {
4740
4255
  return _DefaultRenderer.apply(this, arguments) || this;
@@ -4743,12 +4258,8 @@
4743
4258
  return PolygonRenderer;
4744
4259
  }(DefaultRenderer);
4745
4260
 
4746
- PolygonRenderer = __decorate([gLite.singleton({
4747
- token: PolygonRendererContribution
4748
- })], PolygonRenderer);
4749
-
4750
4261
  var PathRenderer = /*#__PURE__*/function (_DefaultRenderer) {
4751
- _inheritsLoose$4(PathRenderer, _DefaultRenderer);
4262
+ _inheritsLoose$3(PathRenderer, _DefaultRenderer);
4752
4263
 
4753
4264
  function PathRenderer() {
4754
4265
  return _DefaultRenderer.apply(this, arguments) || this;
@@ -4757,600 +4268,660 @@
4757
4268
  return PathRenderer;
4758
4269
  }(DefaultRenderer);
4759
4270
 
4760
- PathRenderer = __decorate([gLite.singleton({
4761
- token: PathRendererContribution
4762
- })], PathRenderer);
4763
- var CanvasRendererPluginOptions = gLite.Syringe.defineToken('');
4271
+ var Plugin$2 = /*#__PURE__*/function (_AbstractRendererPlug) {
4272
+ _inheritsLoose$3(Plugin, _AbstractRendererPlug);
4764
4273
 
4765
- var _class$2;
4274
+ function Plugin(options) {
4275
+ var _this;
4766
4276
 
4767
- var CanvasRendererPlugin_1;
4768
- /**
4769
- * support 2 modes in rendering:
4770
- * * immediate
4771
- * * delayed: render at the end of frame with dirty-rectangle
4772
- */
4277
+ if (options === void 0) {
4278
+ options = {};
4279
+ }
4773
4280
 
4774
- var CanvasRendererPlugin = CanvasRendererPlugin_1 = (_class$2 = /*#__PURE__*/function () {
4775
- function CanvasRendererPlugin(canvasConfig, camera, contextService, renderingContext, pathGeneratorFactory, styleRendererFactory, displayObjectPool, canvasRendererPluginOptions,
4776
- /**
4777
- * RBush used in dirty rectangle rendering
4778
- */
4779
- rBush) {
4780
- this.canvasConfig = void 0;
4781
- this.camera = void 0;
4782
- this.contextService = void 0;
4783
- this.renderingContext = void 0;
4784
- this.pathGeneratorFactory = void 0;
4785
- this.styleRendererFactory = void 0;
4786
- this.displayObjectPool = void 0;
4787
- this.canvasRendererPluginOptions = void 0;
4788
- this.rBush = void 0;
4789
- this.pathGeneratorFactoryCache = {};
4790
- this.styleRendererFactoryCache = {};
4791
- this.removedRBushNodeAABBs = [];
4792
- this.renderQueue = [];
4793
- this.restoreStack = [];
4794
- this.clearFullScreen = false;
4795
- this.vpMatrix = create$3();
4796
- this.dprMatrix = create$3();
4797
- this.tmpMat4 = create$3();
4798
- this.vec3a = create$1$1();
4799
- this.vec3b = create$1$1();
4800
- this.vec3c = create$1$1();
4801
- this.vec3d = create$1$1();
4802
- this.canvasConfig = canvasConfig;
4803
- this.camera = camera;
4804
- this.contextService = contextService;
4805
- this.renderingContext = renderingContext;
4806
- this.pathGeneratorFactory = pathGeneratorFactory;
4807
- this.styleRendererFactory = styleRendererFactory;
4808
- this.displayObjectPool = displayObjectPool;
4809
- this.canvasRendererPluginOptions = canvasRendererPluginOptions;
4810
- this.rBush = rBush;
4281
+ _this = _AbstractRendererPlug.call(this) || this;
4282
+ _this.options = void 0;
4283
+ _this.name = 'canvas-renderer';
4284
+ _this.options = options;
4285
+ return _this;
4811
4286
  }
4812
4287
 
4813
- var _proto = CanvasRendererPlugin.prototype;
4814
-
4815
- _proto.apply = function apply(renderingService) {
4816
- var _this = this;
4817
-
4818
- var canvas = this.renderingContext.root.ownerDocument.defaultView;
4819
-
4820
- var handleUnmounted = function handleUnmounted(e) {
4821
- var object = e.target; // remove r-bush node
4822
- // @ts-ignore
4823
-
4824
- var rBushNode = object.rBushNode;
4825
-
4826
- if (rBushNode.aabb) {
4827
- // save removed aabbs for dirty-rectangle rendering later
4828
- _this.removedRBushNodeAABBs.push(rBushNode.aabb);
4829
- }
4830
- };
4288
+ var _proto = Plugin.prototype;
4831
4289
 
4832
- var handleCulled = function handleCulled(e) {
4833
- var object = e.target; // @ts-ignore
4290
+ _proto.init = function init() {
4291
+ var _defaultStyleRenderer;
4834
4292
 
4835
- var rBushNode = object.rBushNode;
4293
+ var canvasRendererPluginOptions = _extends({
4294
+ dirtyObjectNumThreshold: 500,
4295
+ dirtyObjectRatioThreshold: 0.8
4296
+ }, this.options); // @ts-ignore
4836
4297
 
4837
- if (rBushNode.aabb) {
4838
- // save removed aabbs for dirty-rectangle rendering later
4839
- _this.removedRBushNodeAABBs.push(rBushNode.aabb);
4840
- }
4841
- };
4842
4298
 
4843
- renderingService.hooks.init.tapPromise(CanvasRendererPlugin_1.tag, /*#__PURE__*/_asyncToGenerator$3( /*#__PURE__*/_regeneratorRuntime$3().mark(function _callee() {
4844
- var dpr, _this$canvasConfig, width, height, context;
4299
+ var imagePool = this.context.imagePool;
4300
+ var defaultRenderer = new DefaultRenderer(imagePool);
4301
+ var defaultStyleRendererFactory = (_defaultStyleRenderer = {}, _defaultStyleRenderer[gLite.Shape.CIRCLE] = defaultRenderer, _defaultStyleRenderer[gLite.Shape.ELLIPSE] = defaultRenderer, _defaultStyleRenderer[gLite.Shape.RECT] = defaultRenderer, _defaultStyleRenderer[gLite.Shape.IMAGE] = new ImageRenderer(imagePool), _defaultStyleRenderer[gLite.Shape.TEXT] = new TextRenderer(), _defaultStyleRenderer[gLite.Shape.LINE] = defaultRenderer, _defaultStyleRenderer[gLite.Shape.POLYLINE] = defaultRenderer, _defaultStyleRenderer[gLite.Shape.POLYGON] = defaultRenderer, _defaultStyleRenderer[gLite.Shape.PATH] = defaultRenderer, _defaultStyleRenderer[gLite.Shape.GROUP] = undefined, _defaultStyleRenderer[gLite.Shape.HTML] = undefined, _defaultStyleRenderer[gLite.Shape.MESH] = undefined, _defaultStyleRenderer); // @ts-ignore
4845
4302
 
4846
- return _regeneratorRuntime$3().wrap(function _callee$(_context) {
4847
- while (1) {
4848
- switch (_context.prev = _context.next) {
4849
- case 0:
4850
- _this.renderingContext.root.addEventListener(gLite.ElementEvent.UNMOUNTED, handleUnmounted);
4303
+ this.context.defaultStyleRendererFactory = defaultStyleRendererFactory; // @ts-ignore
4851
4304
 
4852
- _this.renderingContext.root.addEventListener(gLite.ElementEvent.CULLED, handleCulled); // clear fullscreen
4305
+ this.context.styleRendererFactory = defaultStyleRendererFactory;
4306
+ this.addRenderingPlugin(new CanvasRendererPlugin(canvasRendererPluginOptions));
4307
+ };
4853
4308
 
4309
+ _proto.destroy = function destroy() {
4310
+ this.removeAllRenderingPlugins(); // @ts-ignore
4854
4311
 
4855
- dpr = _this.contextService.getDPR();
4856
- _this$canvasConfig = _this.canvasConfig, width = _this$canvasConfig.width, height = _this$canvasConfig.height;
4857
- context = _this.contextService.getContext();
4312
+ delete this.context.defaultStyleRendererFactory; // @ts-ignore
4858
4313
 
4859
- _this.clearRect(context, 0, 0, width * dpr, height * dpr);
4314
+ delete this.context.styleRendererFactory;
4315
+ };
4860
4316
 
4861
- case 6:
4862
- case "end":
4863
- return _context.stop();
4864
- }
4865
- }
4866
- }, _callee);
4867
- })));
4868
- renderingService.hooks.destroy.tap(CanvasRendererPlugin_1.tag, function () {
4869
- _this.renderingContext.root.removeEventListener(gLite.ElementEvent.UNMOUNTED, handleUnmounted);
4317
+ return Plugin;
4318
+ }(gLite.AbstractRendererPlugin);
4870
4319
 
4871
- _this.renderingContext.root.removeEventListener(gLite.ElementEvent.CULLED, handleCulled);
4872
- });
4873
- renderingService.hooks.beginFrame.tap(CanvasRendererPlugin_1.tag, function () {
4874
- var context = _this.contextService.getContext();
4320
+ var index_esm$2 = /*#__PURE__*/Object.freeze({
4321
+ __proto__: null,
4322
+ CircleRenderer: CircleRenderer,
4323
+ EllipseRenderer: EllipseRenderer,
4324
+ ImageRenderer: ImageRenderer,
4325
+ LineRenderer: LineRenderer,
4326
+ PathRenderer: PathRenderer,
4327
+ Plugin: Plugin$2,
4328
+ PolygonRenderer: PolygonRenderer,
4329
+ PolylineRenderer: PolylineRenderer,
4330
+ RectRenderer: RectRenderer,
4331
+ TextRenderer: TextRenderer
4332
+ });
4875
4333
 
4876
- var dpr = _this.contextService.getDPR();
4334
+ function _regeneratorRuntime$3() {
4335
+ /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */
4336
+ _regeneratorRuntime$3 = function _regeneratorRuntime() {
4337
+ return exports;
4338
+ };
4877
4339
 
4878
- var _this$canvasConfig2 = _this.canvasConfig,
4879
- width = _this$canvasConfig2.width,
4880
- height = _this$canvasConfig2.height;
4881
- var _this$canvasRendererP = _this.canvasRendererPluginOptions,
4882
- dirtyObjectNumThreshold = _this$canvasRendererP.dirtyObjectNumThreshold,
4883
- dirtyObjectRatioThreshold = _this$canvasRendererP.dirtyObjectRatioThreshold; // some heuristic conditions such as 80% object changed
4340
+ var exports = {},
4341
+ Op = Object.prototype,
4342
+ hasOwn = Op.hasOwnProperty,
4343
+ $Symbol = "function" == typeof Symbol ? Symbol : {},
4344
+ iteratorSymbol = $Symbol.iterator || "@@iterator",
4345
+ asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator",
4346
+ toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag";
4884
4347
 
4885
- var _renderingService$get = renderingService.getStats(),
4886
- total = _renderingService$get.total,
4887
- rendered = _renderingService$get.rendered;
4348
+ function define(obj, key, value) {
4349
+ return Object.defineProperty(obj, key, {
4350
+ value: value,
4351
+ enumerable: !0,
4352
+ configurable: !0,
4353
+ writable: !0
4354
+ }), obj[key];
4355
+ }
4888
4356
 
4889
- var ratio = rendered / total;
4890
- _this.clearFullScreen = renderingService.disableDirtyRectangleRendering() || rendered > dirtyObjectNumThreshold && ratio > dirtyObjectRatioThreshold;
4357
+ try {
4358
+ define({}, "");
4359
+ } catch (err) {
4360
+ define = function define(obj, key, value) {
4361
+ return obj[key] = value;
4362
+ };
4363
+ }
4891
4364
 
4892
- if (context) {
4893
- context.resetTransform();
4365
+ function wrap(innerFn, outerFn, self, tryLocsList) {
4366
+ var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator,
4367
+ generator = Object.create(protoGenerator.prototype),
4368
+ context = new Context(tryLocsList || []);
4369
+ return generator._invoke = function (innerFn, self, context) {
4370
+ var state = "suspendedStart";
4371
+ return function (method, arg) {
4372
+ if ("executing" === state) throw new Error("Generator is already running");
4894
4373
 
4895
- if (_this.clearFullScreen) {
4896
- _this.clearRect(context, 0, 0, width * dpr, height * dpr);
4374
+ if ("completed" === state) {
4375
+ if ("throw" === method) throw arg;
4376
+ return doneResult();
4897
4377
  }
4898
- }
4899
- });
4900
-
4901
- var renderByZIndex = function renderByZIndex(object) {
4902
- if (object.isVisible() && !object.isCulled()) {
4903
- _this.renderDisplayObject(object, renderingService); // if we did a full screen rendering last frame
4904
4378
 
4379
+ for (context.method = method, context.arg = arg;;) {
4380
+ var delegate = context.delegate;
4905
4381
 
4906
- _this.saveDirtyAABB(object);
4907
- }
4382
+ if (delegate) {
4383
+ var delegateResult = maybeInvokeDelegate(delegate, context);
4908
4384
 
4909
- var sorted = object.sortable.sorted || object.childNodes; // should account for z-index
4385
+ if (delegateResult) {
4386
+ if (delegateResult === ContinueSentinel) continue;
4387
+ return delegateResult;
4388
+ }
4389
+ }
4910
4390
 
4911
- sorted.forEach(function (child) {
4912
- renderByZIndex(child);
4913
- });
4914
- }; // render at the end of frame
4391
+ if ("next" === context.method) context.sent = context._sent = context.arg;else if ("throw" === context.method) {
4392
+ if ("suspendedStart" === state) throw state = "completed", context.arg;
4393
+ context.dispatchException(context.arg);
4394
+ } else "return" === context.method && context.abrupt("return", context.arg);
4395
+ state = "executing";
4396
+ var record = tryCatch(innerFn, self, context);
4915
4397
 
4398
+ if ("normal" === record.type) {
4399
+ if (state = context.done ? "completed" : "suspendedYield", record.arg === ContinueSentinel) continue;
4400
+ return {
4401
+ value: record.arg,
4402
+ done: context.done
4403
+ };
4404
+ }
4916
4405
 
4917
- renderingService.hooks.endFrame.tap(CanvasRendererPlugin_1.tag, function () {
4918
- var context = _this.contextService.getContext(); // clear & clip dirty rectangle
4406
+ "throw" === record.type && (state = "completed", context.method = "throw", context.arg = record.arg);
4407
+ }
4408
+ };
4409
+ }(innerFn, self, context), generator;
4410
+ }
4919
4411
 
4412
+ function tryCatch(fn, obj, arg) {
4413
+ try {
4414
+ return {
4415
+ type: "normal",
4416
+ arg: fn.call(obj, arg)
4417
+ };
4418
+ } catch (err) {
4419
+ return {
4420
+ type: "throw",
4421
+ arg: err
4422
+ };
4423
+ }
4424
+ }
4920
4425
 
4921
- var dpr = _this.contextService.getDPR();
4426
+ exports.wrap = wrap;
4427
+ var ContinueSentinel = {};
4922
4428
 
4923
- fromScaling(_this.dprMatrix, fromValues(dpr, dpr, 1));
4924
- multiply$1(_this.vpMatrix, _this.dprMatrix, _this.camera.getOrthoMatrix());
4429
+ function Generator() {}
4925
4430
 
4926
- if (_this.clearFullScreen) {
4927
- renderByZIndex(_this.renderingContext.root);
4928
- } else {
4929
- // merge removed AABB
4930
- var dirtyRenderBounds = _this.safeMergeAABB.apply(_this, [_this.mergeDirtyAABBs(_this.renderQueue)].concat(_this.removedRBushNodeAABBs.map(function (_ref2) {
4931
- var minX = _ref2.minX,
4932
- minY = _ref2.minY,
4933
- maxX = _ref2.maxX,
4934
- maxY = _ref2.maxY;
4935
- var aabb = new gLite.AABB();
4936
- aabb.setMinMax(fromValues(minX, minY, 0), fromValues(maxX, maxY, 0));
4937
- return aabb;
4938
- })));
4431
+ function GeneratorFunction() {}
4939
4432
 
4940
- _this.removedRBushNodeAABBs = [];
4433
+ function GeneratorFunctionPrototype() {}
4941
4434
 
4942
- if (gLite.AABB.isEmpty(dirtyRenderBounds)) {
4943
- _this.renderQueue = [];
4944
- return;
4945
- }
4435
+ var IteratorPrototype = {};
4436
+ define(IteratorPrototype, iteratorSymbol, function () {
4437
+ return this;
4438
+ });
4439
+ var getProto = Object.getPrototypeOf,
4440
+ NativeIteratorPrototype = getProto && getProto(getProto(values([])));
4441
+ NativeIteratorPrototype && NativeIteratorPrototype !== Op && hasOwn.call(NativeIteratorPrototype, iteratorSymbol) && (IteratorPrototype = NativeIteratorPrototype);
4442
+ var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(IteratorPrototype);
4946
4443
 
4947
- var dirtyRect = _this.convertAABB2Rect(dirtyRenderBounds);
4444
+ function defineIteratorMethods(prototype) {
4445
+ ["next", "throw", "return"].forEach(function (method) {
4446
+ define(prototype, method, function (arg) {
4447
+ return this._invoke(method, arg);
4448
+ });
4449
+ });
4450
+ }
4948
4451
 
4949
- var x = dirtyRect.x,
4950
- y = dirtyRect.y,
4951
- width = dirtyRect.width,
4952
- height = dirtyRect.height;
4953
- var tl = transformMat4$1(_this.vec3a, fromValues(x, y, 0), _this.vpMatrix);
4954
- var tr = transformMat4$1(_this.vec3b, fromValues(x + width, y, 0), _this.vpMatrix);
4955
- var bl = transformMat4$1(_this.vec3c, fromValues(x, y + height, 0), _this.vpMatrix);
4956
- var br = transformMat4$1(_this.vec3d, fromValues(x + width, y + height, 0), _this.vpMatrix);
4957
- var minx = Math.min(tl[0], tr[0], br[0], bl[0]);
4958
- var miny = Math.min(tl[1], tr[1], br[1], bl[1]);
4959
- var maxx = Math.max(tl[0], tr[0], br[0], bl[0]);
4960
- var maxy = Math.max(tl[1], tr[1], br[1], bl[1]);
4961
- var ix = Math.floor(minx);
4962
- var iy = Math.floor(miny);
4963
- var iwidth = Math.ceil(maxx - minx);
4964
- var iheight = Math.ceil(maxy - miny);
4965
- context.save();
4452
+ function AsyncIterator(generator, PromiseImpl) {
4453
+ function invoke(method, arg, resolve, reject) {
4454
+ var record = tryCatch(generator[method], generator, arg);
4966
4455
 
4967
- _this.clearRect(context, ix, iy, iwidth, iheight);
4456
+ if ("throw" !== record.type) {
4457
+ var result = record.arg,
4458
+ value = result.value;
4459
+ return value && "object" == typeof value && hasOwn.call(value, "__await") ? PromiseImpl.resolve(value.__await).then(function (value) {
4460
+ invoke("next", value, resolve, reject);
4461
+ }, function (err) {
4462
+ invoke("throw", err, resolve, reject);
4463
+ }) : PromiseImpl.resolve(value).then(function (unwrapped) {
4464
+ result.value = unwrapped, resolve(result);
4465
+ }, function (error) {
4466
+ return invoke("throw", error, resolve, reject);
4467
+ });
4468
+ }
4968
4469
 
4969
- context.beginPath();
4970
- context.rect(ix, iy, iwidth, iheight);
4971
- context.clip(); // @see https://developer.mozilla.org/en-US/docs/Web/API/Canvas_API/Tutorial/Transformations
4470
+ reject(record.arg);
4471
+ }
4972
4472
 
4973
- context.setTransform(_this.vpMatrix[0], _this.vpMatrix[1], _this.vpMatrix[4], _this.vpMatrix[5], _this.vpMatrix[12], _this.vpMatrix[13]); // draw dirty rectangle
4473
+ var previousPromise;
4974
4474
 
4975
- var _this$canvasConfig$re = _this.canvasConfig.renderer.getConfig(),
4976
- enableDirtyRectangleRenderingDebug = _this$canvasConfig$re.enableDirtyRectangleRenderingDebug;
4475
+ this._invoke = function (method, arg) {
4476
+ function callInvokeWithMethodAndArg() {
4477
+ return new PromiseImpl(function (resolve, reject) {
4478
+ invoke(method, arg, resolve, reject);
4479
+ });
4480
+ }
4977
4481
 
4978
- if (enableDirtyRectangleRenderingDebug) {
4979
- canvas.dispatchEvent(new gLite.CustomEvent(gLite.CanvasEvent.DIRTY_RECTANGLE, {
4980
- dirtyRect: {
4981
- x: ix,
4982
- y: iy,
4983
- width: iwidth,
4984
- height: iheight
4985
- }
4986
- }));
4987
- } // search objects intersect with dirty rectangle
4482
+ return previousPromise = previousPromise ? previousPromise.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg();
4483
+ };
4484
+ }
4988
4485
 
4486
+ function maybeInvokeDelegate(delegate, context) {
4487
+ var method = delegate.iterator[context.method];
4989
4488
 
4990
- var dirtyObjects = _this.searchDirtyObjects(dirtyRenderBounds); // do rendering
4489
+ if (undefined === method) {
4490
+ if (context.delegate = null, "throw" === context.method) {
4491
+ if (delegate.iterator.return && (context.method = "return", context.arg = undefined, maybeInvokeDelegate(delegate, context), "throw" === context.method)) return ContinueSentinel;
4492
+ context.method = "throw", context.arg = new TypeError("The iterator does not provide a 'throw' method");
4493
+ }
4991
4494
 
4495
+ return ContinueSentinel;
4496
+ }
4992
4497
 
4993
- dirtyObjects // sort by z-index
4994
- .sort(function (a, b) {
4995
- return a.sortable.renderOrder - b.sortable.renderOrder;
4996
- }).forEach(function (object) {
4997
- // culled object should not be rendered
4998
- if (object && object.isVisible() && !object.isCulled()) {
4999
- _this.renderDisplayObject(object, renderingService);
5000
- }
5001
- });
5002
- context.restore(); // save dirty AABBs in last frame
4498
+ var record = tryCatch(method, delegate.iterator, context.arg);
4499
+ if ("throw" === record.type) return context.method = "throw", context.arg = record.arg, context.delegate = null, ContinueSentinel;
4500
+ var info = record.arg;
4501
+ return info ? info.done ? (context[delegate.resultName] = info.value, context.next = delegate.nextLoc, "return" !== context.method && (context.method = "next", context.arg = undefined), context.delegate = null, ContinueSentinel) : info : (context.method = "throw", context.arg = new TypeError("iterator result is not an object"), context.delegate = null, ContinueSentinel);
4502
+ }
5003
4503
 
5004
- _this.renderQueue.forEach(function (object) {
5005
- _this.saveDirtyAABB(object);
5006
- }); // clear queue
4504
+ function pushTryEntry(locs) {
4505
+ var entry = {
4506
+ tryLoc: locs[0]
4507
+ };
4508
+ 1 in locs && (entry.catchLoc = locs[1]), 2 in locs && (entry.finallyLoc = locs[2], entry.afterLoc = locs[3]), this.tryEntries.push(entry);
4509
+ }
5007
4510
 
4511
+ function resetTryEntry(entry) {
4512
+ var record = entry.completion || {};
4513
+ record.type = "normal", delete record.arg, entry.completion = record;
4514
+ }
5008
4515
 
5009
- _this.renderQueue = [];
5010
- } // pop restore stack, eg. root -> parent -> child
4516
+ function Context(tryLocsList) {
4517
+ this.tryEntries = [{
4518
+ tryLoc: "root"
4519
+ }], tryLocsList.forEach(pushTryEntry, this), this.reset(!0);
4520
+ }
5011
4521
 
4522
+ function values(iterable) {
4523
+ if (iterable) {
4524
+ var iteratorMethod = iterable[iteratorSymbol];
4525
+ if (iteratorMethod) return iteratorMethod.call(iterable);
4526
+ if ("function" == typeof iterable.next) return iterable;
5012
4527
 
5013
- _this.restoreStack.forEach(function () {
5014
- context.restore();
5015
- }); // clear restore stack
4528
+ if (!isNaN(iterable.length)) {
4529
+ var i = -1,
4530
+ next = function next() {
4531
+ for (; ++i < iterable.length;) {
4532
+ if (hasOwn.call(iterable, i)) return next.value = iterable[i], next.done = !1, next;
4533
+ }
5016
4534
 
4535
+ return next.value = undefined, next.done = !0, next;
4536
+ };
5017
4537
 
5018
- _this.restoreStack = [];
5019
- });
5020
- renderingService.hooks.render.tap(CanvasRendererPlugin_1.tag, function (object) {
5021
- if (!_this.clearFullScreen) {
5022
- // render at the end of frame
5023
- _this.renderQueue.push(object);
4538
+ return next.next = next;
5024
4539
  }
5025
- });
5026
- };
5027
-
5028
- _proto.clearRect = function clearRect(context, x, y, width, height) {
5029
- // clearRect is faster than fillRect @see https://stackoverflow.com/a/30830253
5030
- context.clearRect(x, y, width, height);
5031
- var background = this.canvasConfig.background;
5032
-
5033
- if (background) {
5034
- context.fillStyle = background;
5035
- context.fillRect(x, y, width, height);
5036
4540
  }
5037
- };
5038
4541
 
5039
- _proto.renderDisplayObject = function renderDisplayObject(object, renderingService) {
5040
- var context = this.contextService.getContext();
5041
- var nodeName = object.nodeName; // restore to its ancestor
5042
-
5043
- var parent = this.restoreStack[this.restoreStack.length - 1];
4542
+ return {
4543
+ next: doneResult
4544
+ };
4545
+ }
5044
4546
 
5045
- if (parent && !(object.compareDocumentPosition(parent) & Node.DOCUMENT_POSITION_CONTAINS)) {
5046
- context.restore();
5047
- this.restoreStack.pop();
5048
- } // while (parent && object.parentNode !== parent) {
5049
- // context.restore();
5050
- // this.restoreStack.pop();
5051
- // parent = this.restoreStack[this.restoreStack.length - 1];
5052
- // }
4547
+ function doneResult() {
4548
+ return {
4549
+ value: undefined,
4550
+ done: !0
4551
+ };
4552
+ }
5053
4553
 
4554
+ return GeneratorFunction.prototype = GeneratorFunctionPrototype, define(Gp, "constructor", GeneratorFunctionPrototype), define(GeneratorFunctionPrototype, "constructor", GeneratorFunction), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, toStringTagSymbol, "GeneratorFunction"), exports.isGeneratorFunction = function (genFun) {
4555
+ var ctor = "function" == typeof genFun && genFun.constructor;
4556
+ return !!ctor && (ctor === GeneratorFunction || "GeneratorFunction" === (ctor.displayName || ctor.name));
4557
+ }, exports.mark = function (genFun) {
4558
+ return Object.setPrototypeOf ? Object.setPrototypeOf(genFun, GeneratorFunctionPrototype) : (genFun.__proto__ = GeneratorFunctionPrototype, define(genFun, toStringTagSymbol, "GeneratorFunction")), genFun.prototype = Object.create(Gp), genFun;
4559
+ }, exports.awrap = function (arg) {
4560
+ return {
4561
+ __await: arg
4562
+ };
4563
+ }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, asyncIteratorSymbol, function () {
4564
+ return this;
4565
+ }), exports.AsyncIterator = AsyncIterator, exports.async = function (innerFn, outerFn, self, tryLocsList, PromiseImpl) {
4566
+ void 0 === PromiseImpl && (PromiseImpl = Promise);
4567
+ var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList), PromiseImpl);
4568
+ return exports.isGeneratorFunction(outerFn) ? iter : iter.next().then(function (result) {
4569
+ return result.done ? result.value : iter.next();
4570
+ });
4571
+ }, defineIteratorMethods(Gp), define(Gp, toStringTagSymbol, "Generator"), define(Gp, iteratorSymbol, function () {
4572
+ return this;
4573
+ }), define(Gp, "toString", function () {
4574
+ return "[object Generator]";
4575
+ }), exports.keys = function (object) {
4576
+ var keys = [];
5054
4577
 
5055
- if (this.styleRendererFactoryCache[nodeName] === undefined) {
5056
- this.styleRendererFactoryCache[nodeName] = this.styleRendererFactory(nodeName);
4578
+ for (var key in object) {
4579
+ keys.push(key);
5057
4580
  }
5058
4581
 
5059
- var styleRenderer = this.styleRendererFactoryCache[nodeName];
4582
+ return keys.reverse(), function next() {
4583
+ for (; keys.length;) {
4584
+ var key = keys.pop();
4585
+ if (key in object) return next.value = key, next.done = !1, next;
4586
+ }
5060
4587
 
5061
- if (this.pathGeneratorFactoryCache[nodeName] === undefined) {
5062
- this.pathGeneratorFactoryCache[nodeName] = this.pathGeneratorFactory(nodeName);
5063
- }
4588
+ return next.done = !0, next;
4589
+ };
4590
+ }, exports.values = values, Context.prototype = {
4591
+ constructor: Context,
4592
+ reset: function reset(skipTempReset) {
4593
+ if (this.prev = 0, this.next = 0, this.sent = this._sent = undefined, this.done = !1, this.delegate = null, this.method = "next", this.arg = undefined, this.tryEntries.forEach(resetTryEntry), !skipTempReset) for (var name in this) {
4594
+ "t" === name.charAt(0) && hasOwn.call(this, name) && !isNaN(+name.slice(1)) && (this[name] = undefined);
4595
+ }
4596
+ },
4597
+ stop: function stop() {
4598
+ this.done = !0;
4599
+ var rootRecord = this.tryEntries[0].completion;
4600
+ if ("throw" === rootRecord.type) throw rootRecord.arg;
4601
+ return this.rval;
4602
+ },
4603
+ dispatchException: function dispatchException(exception) {
4604
+ if (this.done) throw exception;
4605
+ var context = this;
5064
4606
 
5065
- var generatePath = this.pathGeneratorFactoryCache[nodeName]; // clip path
4607
+ function handle(loc, caught) {
4608
+ return record.type = "throw", record.arg = exception, context.next = loc, caught && (context.method = "next", context.arg = undefined), !!caught;
4609
+ }
5066
4610
 
5067
- var clipPathShape = object.parsedStyle.clipPath;
4611
+ for (var i = this.tryEntries.length - 1; i >= 0; --i) {
4612
+ var entry = this.tryEntries[i],
4613
+ record = entry.completion;
4614
+ if ("root" === entry.tryLoc) return handle("end");
5068
4615
 
5069
- if (clipPathShape) {
5070
- this.applyWorldTransform(context, clipPathShape, object.getWorldTransform()); // generate path in local space
4616
+ if (entry.tryLoc <= this.prev) {
4617
+ var hasCatch = hasOwn.call(entry, "catchLoc"),
4618
+ hasFinally = hasOwn.call(entry, "finallyLoc");
5071
4619
 
5072
- if (this.pathGeneratorFactoryCache[clipPathShape.nodeName] === undefined) {
5073
- this.pathGeneratorFactoryCache[clipPathShape.nodeName] = this.pathGeneratorFactory(clipPathShape.nodeName);
4620
+ if (hasCatch && hasFinally) {
4621
+ if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0);
4622
+ if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc);
4623
+ } else if (hasCatch) {
4624
+ if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0);
4625
+ } else {
4626
+ if (!hasFinally) throw new Error("try statement without catch or finally");
4627
+ if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc);
4628
+ }
4629
+ }
5074
4630
  }
4631
+ },
4632
+ abrupt: function abrupt(type, arg) {
4633
+ for (var i = this.tryEntries.length - 1; i >= 0; --i) {
4634
+ var entry = this.tryEntries[i];
5075
4635
 
5076
- var _generatePath = this.pathGeneratorFactoryCache[clipPathShape.nodeName];
4636
+ if (entry.tryLoc <= this.prev && hasOwn.call(entry, "finallyLoc") && this.prev < entry.finallyLoc) {
4637
+ var finallyEntry = entry;
4638
+ break;
4639
+ }
4640
+ }
5077
4641
 
5078
- if (_generatePath) {
5079
- context.save(); // save clip
4642
+ finallyEntry && ("break" === type || "continue" === type) && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc && (finallyEntry = null);
4643
+ var record = finallyEntry ? finallyEntry.completion : {};
4644
+ return record.type = type, record.arg = arg, finallyEntry ? (this.method = "next", this.next = finallyEntry.finallyLoc, ContinueSentinel) : this.complete(record);
4645
+ },
4646
+ complete: function complete(record, afterLoc) {
4647
+ if ("throw" === record.type) throw record.arg;
4648
+ return "break" === record.type || "continue" === record.type ? this.next = record.arg : "return" === record.type ? (this.rval = this.arg = record.arg, this.method = "return", this.next = "end") : "normal" === record.type && afterLoc && (this.next = afterLoc), ContinueSentinel;
4649
+ },
4650
+ finish: function finish(finallyLoc) {
4651
+ for (var i = this.tryEntries.length - 1; i >= 0; --i) {
4652
+ var entry = this.tryEntries[i];
4653
+ if (entry.finallyLoc === finallyLoc) return this.complete(entry.completion, entry.afterLoc), resetTryEntry(entry), ContinueSentinel;
4654
+ }
4655
+ },
4656
+ catch: function _catch(tryLoc) {
4657
+ for (var i = this.tryEntries.length - 1; i >= 0; --i) {
4658
+ var entry = this.tryEntries[i];
5080
4659
 
5081
- this.restoreStack.push(object);
5082
- context.beginPath();
4660
+ if (entry.tryLoc === tryLoc) {
4661
+ var record = entry.completion;
5083
4662
 
5084
- _generatePath(context, clipPathShape.parsedStyle);
4663
+ if ("throw" === record.type) {
4664
+ var thrown = record.arg;
4665
+ resetTryEntry(entry);
4666
+ }
5085
4667
 
5086
- context.closePath();
5087
- context.clip();
4668
+ return thrown;
4669
+ }
5088
4670
  }
5089
- } // fill & stroke
5090
4671
 
4672
+ throw new Error("illegal catch attempt");
4673
+ },
4674
+ delegateYield: function delegateYield(iterable, resultName, nextLoc) {
4675
+ return this.delegate = {
4676
+ iterator: values(iterable),
4677
+ resultName: resultName,
4678
+ nextLoc: nextLoc
4679
+ }, "next" === this.method && (this.arg = undefined), ContinueSentinel;
4680
+ }
4681
+ }, exports;
4682
+ }
5091
4683
 
5092
- if (styleRenderer) {
5093
- this.applyWorldTransform(context, object);
5094
- context.save(); // apply attributes to context
4684
+ function asyncGeneratorStep$3(gen, resolve, reject, _next, _throw, key, arg) {
4685
+ try {
4686
+ var info = gen[key](arg);
4687
+ var value = info.value;
4688
+ } catch (error) {
4689
+ reject(error);
4690
+ return;
4691
+ }
5095
4692
 
5096
- this.applyAttributesToContext(context, object);
5097
- }
4693
+ if (info.done) {
4694
+ resolve(value);
4695
+ } else {
4696
+ Promise.resolve(value).then(_next, _throw);
4697
+ }
4698
+ }
5098
4699
 
5099
- if (generatePath) {
5100
- context.beginPath();
5101
- generatePath(context, object.parsedStyle);
4700
+ function _asyncToGenerator$3(fn) {
4701
+ return function () {
4702
+ var self = this,
4703
+ args = arguments;
4704
+ return new Promise(function (resolve, reject) {
4705
+ var gen = fn.apply(self, args);
5102
4706
 
5103
- if (object.nodeName !== gLite.Shape.LINE && object.nodeName !== gLite.Shape.PATH && object.nodeName !== gLite.Shape.POLYLINE) {
5104
- context.closePath();
4707
+ function _next(value) {
4708
+ asyncGeneratorStep$3(gen, resolve, reject, _next, _throw, "next", value);
5105
4709
  }
5106
- } // fill & stroke
5107
4710
 
4711
+ function _throw(err) {
4712
+ asyncGeneratorStep$3(gen, resolve, reject, _next, _throw, "throw", err);
4713
+ }
5108
4714
 
5109
- if (styleRenderer) {
5110
- styleRenderer.render(context, object.parsedStyle, object, renderingService); // restore applied attributes, eg. shadowBlur shadowColor...
4715
+ _next(undefined);
4716
+ });
4717
+ };
4718
+ }
5111
4719
 
5112
- context.restore();
5113
- } // finish rendering, clear dirty flag
4720
+ function _inheritsLoose$4(subClass, superClass) {
4721
+ subClass.prototype = Object.create(superClass.prototype);
4722
+ subClass.prototype.constructor = subClass;
5114
4723
 
4724
+ _setPrototypeOf$4(subClass, superClass);
4725
+ }
5115
4726
 
5116
- object.renderable.dirty = false;
4727
+ function _setPrototypeOf$4(o, p) {
4728
+ _setPrototypeOf$4 = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) {
4729
+ o.__proto__ = p;
4730
+ return o;
5117
4731
  };
4732
+ return _setPrototypeOf$4(o, p);
4733
+ } // const MOBILE_REGEX = /mobile|tablet|ip(ad|hone|od)|android/i;
5118
4734
 
5119
- _proto.convertAABB2Rect = function convertAABB2Rect(aabb) {
5120
- var min = aabb.getMin();
5121
- var max = aabb.getMax(); // expand the rectangle a bit to avoid artifacts
5122
- // @see https://www.yuque.com/antv/ou292n/bi8nix#ExvCu
4735
+ /**
4736
+ * listen to mouse/touch/pointer events on DOM wrapper, trigger pointer events
4737
+ */
5123
4738
 
5124
- var minX = Math.floor(min[0]);
5125
- var minY = Math.floor(min[1]);
5126
- var maxX = Math.ceil(max[0]);
5127
- var maxY = Math.ceil(max[1]);
5128
- var width = maxX - minX;
5129
- var height = maxY - minY;
5130
- return {
5131
- x: minX,
5132
- y: minY,
5133
- width: width,
5134
- height: height
5135
- };
4739
+
4740
+ var DOMInteractionPlugin = /*#__PURE__*/function () {
4741
+ function DOMInteractionPlugin() {
4742
+ this.context = void 0;
5136
4743
  }
5137
- /**
5138
- * TODO: merge dirty rectangles with some strategies.
5139
- * For now, we just simply merge all the rectangles into one.
5140
- * @see https://idom.me/articles/841.html
5141
- */
5142
- ;
5143
4744
 
5144
- _proto.mergeDirtyAABBs = function mergeDirtyAABBs(dirtyObjects) {
5145
- // merge into a big AABB
5146
- // TODO: skip descendant if ancestor is caculated, but compareNodePosition is really slow
5147
- var aabb = new gLite.AABB();
5148
- dirtyObjects.forEach(function (object) {
5149
- var renderBounds = object.getRenderBounds();
5150
- aabb.add(renderBounds);
5151
- var dirtyRenderBounds = object.renderable.dirtyRenderBounds;
4745
+ var _proto = DOMInteractionPlugin.prototype;
5152
4746
 
5153
- if (dirtyRenderBounds) {
5154
- aabb.add(dirtyRenderBounds);
5155
- }
5156
- });
5157
- return aabb;
5158
- };
4747
+ _proto.apply = function apply(context) {
4748
+ var _this = this;
5159
4749
 
5160
- _proto.searchDirtyObjects = function searchDirtyObjects(dirtyRectangle) {
5161
- var _this2 = this; // search in r-tree, get all affected nodes
4750
+ var renderingService = context.renderingService,
4751
+ renderingContext = context.renderingContext;
4752
+ this.context = context;
4753
+ var canvas = renderingContext.root.ownerDocument.defaultView; // const SUPPORT_ONLY_TOUCH = canvas.supportsTouchEvents && MOBILE_REGEX.test(navigator.userAgent);
5162
4754
 
4755
+ var onPointerMove = function onPointerMove(ev) {
4756
+ renderingService.hooks.pointerMove.call(ev);
4757
+ };
5163
4758
 
5164
- var _dirtyRectangle$getMi = dirtyRectangle.getMin(),
5165
- minX = _dirtyRectangle$getMi[0],
5166
- minY = _dirtyRectangle$getMi[1];
4759
+ var onPointerUp = function onPointerUp(ev) {
4760
+ renderingService.hooks.pointerUp.call(ev);
4761
+ };
5167
4762
 
5168
- var _dirtyRectangle$getMa = dirtyRectangle.getMax(),
5169
- maxX = _dirtyRectangle$getMa[0],
5170
- maxY = _dirtyRectangle$getMa[1];
4763
+ var onPointerDown = function onPointerDown(ev) {
4764
+ renderingService.hooks.pointerDown.call(ev);
4765
+ };
5171
4766
 
5172
- var rBushNodes = this.rBush.search({
5173
- minX: minX,
5174
- minY: minY,
5175
- maxX: maxX,
5176
- maxY: maxY
5177
- });
5178
- return rBushNodes.map(function (_ref3) {
5179
- var id = _ref3.id;
5180
- return _this2.displayObjectPool.getByEntity(id);
5181
- });
5182
- };
4767
+ var onPointerOver = function onPointerOver(ev) {
4768
+ renderingService.hooks.pointerOver.call(ev);
4769
+ };
5183
4770
 
5184
- _proto.saveDirtyAABB = function saveDirtyAABB(object) {
5185
- var renderable = object.renderable;
4771
+ var onPointerOut = function onPointerOut(ev) {
4772
+ renderingService.hooks.pointerOut.call(ev);
4773
+ };
5186
4774
 
5187
- if (!renderable.dirtyRenderBounds) {
5188
- renderable.dirtyRenderBounds = new gLite.AABB();
5189
- }
4775
+ var onPointerCancel = function onPointerCancel(ev) {
4776
+ renderingService.hooks.pointerCancel.call(ev);
4777
+ };
5190
4778
 
5191
- var renderBounds = object.getRenderBounds();
4779
+ var onPointerWheel = function onPointerWheel(ev) {
4780
+ renderingService.hooks.pointerWheel.call(ev);
4781
+ };
5192
4782
 
5193
- if (renderBounds) {
5194
- // save last dirty aabb
5195
- renderable.dirtyRenderBounds.update(renderBounds.center, renderBounds.halfExtents);
5196
- }
5197
- }
5198
- /**
5199
- * TODO: batch the same global attributes
5200
- */
5201
- ;
4783
+ var addPointerEventListener = function addPointerEventListener($el) {
4784
+ globalThis.document.addEventListener('pointermove', onPointerMove, true);
4785
+ $el.addEventListener('pointerdown', onPointerDown, true);
4786
+ $el.addEventListener('pointerleave', onPointerOut, true);
4787
+ $el.addEventListener('pointerover', onPointerOver, true);
4788
+ globalThis.addEventListener('pointerup', onPointerUp, true);
4789
+ };
5202
4790
 
5203
- _proto.applyAttributesToContext = function applyAttributesToContext(context, object) {
5204
- var _object$parsedStyle = object.parsedStyle,
5205
- stroke = _object$parsedStyle.stroke,
5206
- fill = _object$parsedStyle.fill,
5207
- opacity = _object$parsedStyle.opacity,
5208
- lineDash = _object$parsedStyle.lineDash,
5209
- lineDashOffset = _object$parsedStyle.lineDashOffset; // @see https://developer.mozilla.org/zh-CN/docs/Web/API/CanvasRenderingContext2D/setLineDash
4791
+ var addTouchEventListener = function addTouchEventListener($el) {
4792
+ $el.addEventListener('touchstart', onPointerDown, true);
4793
+ $el.addEventListener('touchend', onPointerUp, true);
4794
+ $el.addEventListener('touchmove', onPointerMove, true);
4795
+ $el.addEventListener('touchcancel', onPointerCancel, true);
4796
+ };
5210
4797
 
5211
- if (lineDash) {
5212
- context.setLineDash(lineDash);
5213
- } // @see https://developer.mozilla.org/zh-CN/docs/Web/API/CanvasRenderingContext2D/lineDashOffset
4798
+ var addMouseEventListener = function addMouseEventListener($el) {
4799
+ globalThis.document.addEventListener('mousemove', onPointerMove, true);
4800
+ $el.addEventListener('mousedown', onPointerDown, true);
4801
+ $el.addEventListener('mouseout', onPointerOut, true);
4802
+ $el.addEventListener('mouseover', onPointerOver, true);
4803
+ globalThis.addEventListener('mouseup', onPointerUp, true);
4804
+ };
4805
+
4806
+ var removePointerEventListener = function removePointerEventListener($el) {
4807
+ globalThis.document.removeEventListener('pointermove', onPointerMove, true);
4808
+ $el.removeEventListener('pointerdown', onPointerDown, true);
4809
+ $el.removeEventListener('pointerleave', onPointerOut, true);
4810
+ $el.removeEventListener('pointerover', onPointerOver, true);
4811
+ globalThis.removeEventListener('pointerup', onPointerUp, true);
4812
+ };
5214
4813
 
4814
+ var removeTouchEventListener = function removeTouchEventListener($el) {
4815
+ $el.removeEventListener('touchstart', onPointerDown, true);
4816
+ $el.removeEventListener('touchend', onPointerUp, true);
4817
+ $el.removeEventListener('touchmove', onPointerMove, true);
4818
+ $el.removeEventListener('touchcancel', onPointerCancel, true);
4819
+ };
5215
4820
 
5216
- if (!isNil(lineDashOffset)) {
5217
- context.lineDashOffset = lineDashOffset;
5218
- }
4821
+ var removeMouseEventListener = function removeMouseEventListener($el) {
4822
+ globalThis.document.removeEventListener('mousemove', onPointerMove, true);
4823
+ $el.removeEventListener('mousedown', onPointerDown, true);
4824
+ $el.removeEventListener('mouseout', onPointerOut, true);
4825
+ $el.removeEventListener('mouseover', onPointerOver, true);
4826
+ globalThis.removeEventListener('mouseup', onPointerUp, true);
4827
+ };
5219
4828
 
5220
- if (!isNil(opacity)) {
5221
- context.globalAlpha *= opacity;
5222
- }
4829
+ renderingService.hooks.init.tapPromise(DOMInteractionPlugin.tag, /*#__PURE__*/_asyncToGenerator$3( /*#__PURE__*/_regeneratorRuntime$3().mark(function _callee() {
4830
+ var $el;
4831
+ return _regeneratorRuntime$3().wrap(function _callee$(_context) {
4832
+ while (1) {
4833
+ switch (_context.prev = _context.next) {
4834
+ case 0:
4835
+ $el = _this.context.contextService.getDomElement(); // @ts-ignore
5223
4836
 
5224
- if (!isNil(stroke) && !Array.isArray(stroke) && !stroke.isNone) {
5225
- context.strokeStyle = object.attributes.stroke;
5226
- }
4837
+ if (globalThis.navigator.msPointerEnabled) {
4838
+ // @ts-ignore
4839
+ $el.style.msContentZooming = 'none'; // @ts-ignore
5227
4840
 
5228
- if (!isNil(fill) && !Array.isArray(fill) && !fill.isNone) {
5229
- context.fillStyle = object.attributes.fill;
5230
- }
5231
- };
4841
+ $el.style.msTouchAction = 'none';
4842
+ } else if (canvas.supportsPointerEvents) {
4843
+ $el.style.touchAction = 'none';
4844
+ }
5232
4845
 
5233
- _proto.applyWorldTransform = function applyWorldTransform(context, object, matrix) {
5234
- var tx = 0;
5235
- var ty = 0;
4846
+ if (canvas.supportsPointerEvents) {
4847
+ addPointerEventListener($el);
4848
+ } else {
4849
+ addMouseEventListener($el);
4850
+ }
5236
4851
 
5237
- var _ref4 = object.parsedStyle || {},
5238
- anchor = _ref4.anchor;
4852
+ if (canvas.supportsTouchEvents) {
4853
+ addTouchEventListener($el);
4854
+ } // use passive event listeners
4855
+ // @see https://zhuanlan.zhihu.com/p/24555031
5239
4856
 
5240
- var anchorX = anchor && anchor[0] || 0;
5241
- var anchorY = anchor && anchor[1] || 0;
5242
4857
 
5243
- if (anchorX !== 0 || anchorY !== 0) {
5244
- var bounds = object.getGeometryBounds();
5245
- var width = bounds && bounds.halfExtents[0] * 2 || 0;
5246
- var height = bounds && bounds.halfExtents[1] * 2 || 0;
5247
- tx = -(anchorX * width);
5248
- ty = -(anchorY * height);
5249
- } // apply clip shape's RTS
4858
+ $el.addEventListener('wheel', onPointerWheel, {
4859
+ passive: true,
4860
+ capture: true
4861
+ });
5250
4862
 
4863
+ case 5:
4864
+ case "end":
4865
+ return _context.stop();
4866
+ }
4867
+ }
4868
+ }, _callee);
4869
+ })));
4870
+ renderingService.hooks.destroy.tap(DOMInteractionPlugin.tag, function () {
4871
+ var $el = _this.context.contextService.getDomElement(); // @ts-ignore
5251
4872
 
5252
- if (matrix) {
5253
- copy(this.tmpMat4, object.getLocalTransform());
5254
- this.vec3a[0] = tx;
5255
- this.vec3a[1] = ty;
5256
- this.vec3a[2] = 0;
5257
- translate(this.tmpMat4, this.tmpMat4, this.vec3a);
5258
- multiply$1(this.tmpMat4, matrix, this.tmpMat4);
5259
- multiply$1(this.tmpMat4, this.vpMatrix, this.tmpMat4);
5260
- } else {
5261
- // apply RTS transformation in world space
5262
- copy(this.tmpMat4, object.getWorldTransform());
5263
- this.vec3a[0] = tx;
5264
- this.vec3a[1] = ty;
5265
- this.vec3a[2] = 0;
5266
- translate(this.tmpMat4, this.tmpMat4, this.vec3a);
5267
- multiply$1(this.tmpMat4, this.vpMatrix, this.tmpMat4);
5268
- } // @see https://developer.mozilla.org/en-US/docs/Web/API/Canvas_API/Tutorial/Transformations
5269
4873
 
4874
+ if (globalThis.navigator.msPointerEnabled) {
4875
+ // @ts-ignore
4876
+ $el.style.msContentZooming = ''; // @ts-ignore
5270
4877
 
5271
- context.setTransform(this.tmpMat4[0], this.tmpMat4[1], this.tmpMat4[4], this.tmpMat4[5], this.tmpMat4[12], this.tmpMat4[13]);
5272
- };
4878
+ $el.style.msTouchAction = '';
4879
+ } else if (canvas.supportsPointerEvents) {
4880
+ $el.style.touchAction = '';
4881
+ }
5273
4882
 
5274
- _proto.safeMergeAABB = function safeMergeAABB() {
5275
- var merged = new gLite.AABB();
4883
+ if (canvas.supportsPointerEvents) {
4884
+ removePointerEventListener($el);
4885
+ } else {
4886
+ removeMouseEventListener($el);
4887
+ }
5276
4888
 
5277
- for (var _len = arguments.length, aabbs = new Array(_len), _key = 0; _key < _len; _key++) {
5278
- aabbs[_key] = arguments[_key];
5279
- }
4889
+ if (canvas.supportsTouchEvents) {
4890
+ removeTouchEventListener($el);
4891
+ }
5280
4892
 
5281
- aabbs.forEach(function (aabb) {
5282
- merged.add(aabb);
4893
+ $el.removeEventListener('wheel', onPointerWheel, true);
5283
4894
  });
5284
- return merged;
5285
4895
  };
5286
4896
 
5287
- return CanvasRendererPlugin;
5288
- }(), _class$2.tag = 'CanvasRenderer', _class$2);
5289
- CanvasRendererPlugin = CanvasRendererPlugin_1 = __decorate([gLite.singleton({
5290
- contrib: gLite.RenderingPluginContribution
5291
- }), __param(0, gLite.inject(gLite.CanvasConfig)), __param(1, gLite.inject(gLite.DefaultCamera)), __param(2, gLite.inject(gLite.ContextService)), __param(3, gLite.inject(gLite.RenderingContext)), __param(4, gLite.inject(PathGeneratorFactory)), __param(5, gLite.inject(StyleRendererFactory)), __param(6, gLite.inject(gLite.DisplayObjectPool)), __param(7, gLite.inject(CanvasRendererPluginOptions)), __param(8, gLite.inject(gLite.RBushRoot))], CanvasRendererPlugin);
5292
- var containerModule$3 = gLite.Module(function (register) {
5293
- var _shape2Token;
5294
-
5295
- register(CircleRenderer);
5296
- register(EllipseRenderer);
5297
- register(RectRenderer);
5298
- register(ImageRenderer);
5299
- register(TextRenderer);
5300
- register(LineRenderer);
5301
- register(PolylineRenderer);
5302
- register(PolygonRenderer);
5303
- register(PathRenderer);
5304
- var shape2Token = (_shape2Token = {}, _shape2Token[gLite.Shape.CIRCLE] = CircleRendererContribution, _shape2Token[gLite.Shape.ELLIPSE] = EllipseRendererContribution, _shape2Token[gLite.Shape.RECT] = RectRendererContribution, _shape2Token[gLite.Shape.IMAGE] = ImageRendererContribution, _shape2Token[gLite.Shape.TEXT] = TextRendererContribution, _shape2Token[gLite.Shape.LINE] = LineRendererContribution, _shape2Token[gLite.Shape.POLYLINE] = PolylineRendererContribution, _shape2Token[gLite.Shape.POLYGON] = PolygonRendererContribution, _shape2Token[gLite.Shape.PATH] = PathRendererContribution, _shape2Token);
5305
- register({
5306
- token: StyleRendererFactory,
5307
- useFactory: function useFactory(ctx) {
5308
- return function (tagName) {
5309
- var token = shape2Token[tagName];
5310
-
5311
- if (token && ctx.container.isBound(token)) {
5312
- return ctx.container.get(token);
5313
- }
4897
+ return DOMInteractionPlugin;
4898
+ }();
5314
4899
 
5315
- return null;
5316
- };
5317
- }
5318
- });
5319
- register(CanvasRendererPlugin);
5320
- });
4900
+ DOMInteractionPlugin.tag = 'DOMInteraction';
5321
4901
 
5322
4902
  var Plugin$3 = /*#__PURE__*/function (_AbstractRendererPlug) {
5323
4903
  _inheritsLoose$4(Plugin, _AbstractRendererPlug);
5324
4904
 
5325
- function Plugin(options) {
4905
+ function Plugin() {
5326
4906
  var _this;
5327
4907
 
5328
- if (options === void 0) {
5329
- options = {};
4908
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
4909
+ args[_key] = arguments[_key];
5330
4910
  }
5331
4911
 
5332
- _this = _AbstractRendererPlug.call(this) || this;
5333
- _this.options = void 0;
5334
- _this.name = 'canvas-renderer';
5335
- _this.options = options;
4912
+ _this = _AbstractRendererPlug.call.apply(_AbstractRendererPlug, [this].concat(args)) || this;
4913
+ _this.name = 'dom-interaction';
5336
4914
  return _this;
5337
4915
  }
5338
4916
 
5339
4917
  var _proto = Plugin.prototype;
5340
4918
 
5341
4919
  _proto.init = function init() {
5342
- this.container.register(CanvasRendererPluginOptions, {
5343
- useValue: _extends({
5344
- dirtyObjectNumThreshold: 500,
5345
- dirtyObjectRatioThreshold: 0.8
5346
- }, this.options)
5347
- });
5348
- this.container.load(containerModule$3, true);
4920
+ this.addRenderingPlugin(new DOMInteractionPlugin());
5349
4921
  };
5350
4922
 
5351
4923
  _proto.destroy = function destroy() {
5352
- this.container.unload(containerModule$3);
5353
- this.container.remove(CanvasRendererPluginOptions);
4924
+ this.removeAllRenderingPlugins();
5354
4925
  };
5355
4926
 
5356
4927
  return Plugin;
@@ -5358,26 +4929,7 @@
5358
4929
 
5359
4930
  var index_esm$3 = /*#__PURE__*/Object.freeze({
5360
4931
  __proto__: null,
5361
- get CircleRenderer () { return CircleRenderer; },
5362
- CircleRendererContribution: CircleRendererContribution,
5363
- get EllipseRenderer () { return EllipseRenderer; },
5364
- EllipseRendererContribution: EllipseRendererContribution,
5365
- get ImageRenderer () { return ImageRenderer; },
5366
- ImageRendererContribution: ImageRendererContribution,
5367
- get LineRenderer () { return LineRenderer; },
5368
- LineRendererContribution: LineRendererContribution,
5369
- get PathRenderer () { return PathRenderer; },
5370
- PathRendererContribution: PathRendererContribution,
5371
- Plugin: Plugin$3,
5372
- get PolygonRenderer () { return PolygonRenderer; },
5373
- PolygonRendererContribution: PolygonRendererContribution,
5374
- get PolylineRenderer () { return PolylineRenderer; },
5375
- PolylineRendererContribution: PolylineRendererContribution,
5376
- get RectRenderer () { return RectRenderer; },
5377
- RectRendererContribution: RectRendererContribution,
5378
- StyleRendererFactory: StyleRendererFactory,
5379
- get TextRenderer () { return TextRenderer; },
5380
- TextRendererContribution: TextRendererContribution
4932
+ Plugin: Plugin$3
5381
4933
  });
5382
4934
 
5383
4935
  function _regeneratorRuntime$4() {
@@ -5781,178 +5333,316 @@
5781
5333
  return _setPrototypeOf$5(o, p);
5782
5334
  }
5783
5335
 
5784
- var _class$3;
5785
-
5786
- var DOMInteractionPlugin_1;
5787
- /**
5788
- * listen to mouse/touch/pointer events on DOM wrapper, trigger pointer events
5789
- */
5336
+ var HTML_PREFIX = 'g-html-';
5337
+ var CANVAS_CAMERA_ID = 'g_canvas_camera';
5790
5338
 
5791
- var DOMInteractionPlugin = DOMInteractionPlugin_1 = (_class$3 = /*#__PURE__*/function () {
5792
- function DOMInteractionPlugin(contextService, renderingContext) {
5793
- this.contextService = void 0;
5794
- this.renderingContext = void 0;
5795
- this.contextService = contextService;
5796
- this.renderingContext = renderingContext;
5339
+ var HTMLRenderingPlugin = /*#__PURE__*/function () {
5340
+ function HTMLRenderingPlugin() {
5341
+ this.context = void 0;
5342
+ this.$camera = void 0;
5797
5343
  }
5798
5344
 
5799
- var _proto = DOMInteractionPlugin.prototype;
5345
+ var _proto = HTMLRenderingPlugin.prototype;
5346
+
5347
+ _proto.joinTransformMatrix = function joinTransformMatrix(matrix) {
5348
+ return "matrix(" + [matrix[0], matrix[1], matrix[4], matrix[5], matrix[12], matrix[13]].join(',') + ")";
5349
+ };
5800
5350
 
5801
- _proto.apply = function apply(renderingService) {
5351
+ _proto.apply = function apply(context) {
5802
5352
  var _this = this;
5803
5353
 
5804
- var canvas = this.renderingContext.root.ownerDocument.defaultView; // const SUPPORT_ONLY_TOUCH = canvas.supportsTouchEvents && MOBILE_REGEX.test(navigator.userAgent);
5354
+ var camera = context.camera,
5355
+ renderingContext = context.renderingContext,
5356
+ renderingService = context.renderingService;
5357
+ this.context = context;
5358
+ var canvas = renderingContext.root.ownerDocument.defaultView;
5805
5359
 
5806
- var onPointerMove = function onPointerMove(ev) {
5807
- renderingService.hooks.pointerMove.call(ev);
5360
+ var setTransform = function setTransform(object, $el) {
5361
+ $el.style.transform = _this.joinTransformMatrix(object.getWorldTransform());
5808
5362
  };
5809
5363
 
5810
- var onPointerUp = function onPointerUp(ev) {
5811
- renderingService.hooks.pointerUp.call(ev);
5812
- };
5364
+ var handleMounted = function handleMounted(e) {
5365
+ var object = e.target;
5813
5366
 
5814
- var onPointerDown = function onPointerDown(ev) {
5815
- renderingService.hooks.pointerDown.call(ev);
5816
- };
5367
+ if (object.nodeName === gLite.Shape.HTML) {
5368
+ // create DOM element
5369
+ var $el = _this.getOrCreateEl(object);
5817
5370
 
5818
- var onPointerOver = function onPointerOver(ev) {
5819
- renderingService.hooks.pointerOver.call(ev);
5371
+ _this.$camera.appendChild($el); // apply documentElement's style
5372
+
5373
+
5374
+ var attributes = object.ownerDocument.documentElement.attributes;
5375
+ Object.keys(attributes).forEach(function (name) {
5376
+ $el.style[name] = attributes[name];
5377
+ });
5378
+ Object.keys(object.attributes).forEach(function (name) {
5379
+ _this.updateAttribute(name, object);
5380
+ });
5381
+ setTransform(object, $el);
5382
+ }
5820
5383
  };
5821
5384
 
5822
- var onPointerOut = function onPointerOut(ev) {
5823
- renderingService.hooks.pointerOut.call(ev);
5385
+ var handleUnmounted = function handleUnmounted(e) {
5386
+ var object = e.target;
5387
+
5388
+ if (object.nodeName === gLite.Shape.HTML && _this.$camera) {
5389
+ var $el = _this.getOrCreateEl(object);
5390
+
5391
+ if ($el) {
5392
+ $el.remove();
5393
+ } // const existedId = this.getId(object);
5394
+ // const $existedElement: HTMLElement | null = this.$camera.querySelector('#' + existedId);
5395
+ // if ($existedElement) {
5396
+ // this.$camera.removeChild($existedElement);
5397
+ // }
5398
+
5399
+ }
5824
5400
  };
5825
5401
 
5826
- var onPointerCancel = function onPointerCancel(ev) {
5827
- renderingService.hooks.pointerCancel.call(ev);
5402
+ var handleAttributeChanged = function handleAttributeChanged(e) {
5403
+ var object = e.target;
5404
+
5405
+ if (object.nodeName === gLite.Shape.HTML) {
5406
+ var attrName = e.attrName;
5407
+
5408
+ _this.updateAttribute(attrName, object);
5409
+ }
5828
5410
  };
5829
5411
 
5830
- var onPointerWheel = function onPointerWheel(ev) {
5831
- renderingService.hooks.pointerWheel.call(ev);
5412
+ var handleBoundsChanged = function handleBoundsChanged(e) {
5413
+ var object = e.target;
5414
+
5415
+ if (object.nodeName === gLite.Shape.HTML) {
5416
+ var $el = _this.getOrCreateEl(object);
5417
+
5418
+ setTransform(object, $el);
5419
+ }
5832
5420
  };
5833
5421
 
5834
- var addPointerEventListener = function addPointerEventListener($el) {
5835
- globalThis.document.addEventListener('pointermove', onPointerMove, true);
5836
- $el.addEventListener('pointerdown', onPointerDown, true);
5837
- $el.addEventListener('pointerleave', onPointerOut, true);
5838
- $el.addEventListener('pointerover', onPointerOver, true);
5839
- globalThis.addEventListener('pointerup', onPointerUp, true);
5422
+ var handleCanvasResize = function handleCanvasResize() {
5423
+ var _this$context$config = _this.context.config,
5424
+ width = _this$context$config.width,
5425
+ height = _this$context$config.height;
5426
+ _this.$camera.style.width = (width || 0) + "px";
5427
+ _this.$camera.style.height = (height || 0) + "px";
5840
5428
  };
5841
5429
 
5842
- var addTouchEventListener = function addTouchEventListener($el) {
5843
- $el.addEventListener('touchstart', onPointerDown, true);
5844
- $el.addEventListener('touchend', onPointerUp, true);
5845
- $el.addEventListener('touchmove', onPointerMove, true);
5846
- $el.addEventListener('touchcancel', onPointerCancel, true);
5847
- };
5430
+ renderingService.hooks.init.tapPromise(HTMLRenderingPlugin.tag, /*#__PURE__*/_asyncToGenerator$4( /*#__PURE__*/_regeneratorRuntime$4().mark(function _callee() {
5431
+ return _regeneratorRuntime$4().wrap(function _callee$(_context) {
5432
+ while (1) {
5433
+ switch (_context.prev = _context.next) {
5434
+ case 0:
5435
+ // append camera
5436
+ _this.$camera = _this.createCamera(camera);
5437
+ canvas.addEventListener(gLite.CanvasEvent.RESIZE, handleCanvasResize);
5438
+ renderingContext.root.addEventListener(gLite.ElementEvent.MOUNTED, handleMounted);
5439
+ renderingContext.root.addEventListener(gLite.ElementEvent.UNMOUNTED, handleUnmounted);
5440
+ renderingContext.root.addEventListener(gLite.ElementEvent.ATTR_MODIFIED, handleAttributeChanged);
5441
+ renderingContext.root.addEventListener(gLite.ElementEvent.BOUNDS_CHANGED, handleBoundsChanged);
5442
+
5443
+ case 6:
5444
+ case "end":
5445
+ return _context.stop();
5446
+ }
5447
+ }
5448
+ }, _callee);
5449
+ })));
5450
+ renderingService.hooks.endFrame.tap(HTMLRenderingPlugin.tag, function () {
5451
+ if (_this.$camera && renderingContext.renderReasons.has(gLite.RenderReason.CAMERA_CHANGED)) {
5452
+ _this.$camera.style.transform = _this.joinTransformMatrix(camera.getOrthoMatrix());
5453
+ }
5454
+ });
5455
+ renderingService.hooks.destroy.tap(HTMLRenderingPlugin.tag, function () {
5456
+ // remove camera
5457
+ if (_this.$camera) {
5458
+ _this.$camera.remove();
5459
+ }
5460
+
5461
+ canvas.removeEventListener(gLite.CanvasEvent.RESIZE, handleCanvasResize);
5462
+ renderingContext.root.removeEventListener(gLite.ElementEvent.MOUNTED, handleMounted);
5463
+ renderingContext.root.removeEventListener(gLite.ElementEvent.UNMOUNTED, handleUnmounted);
5464
+ renderingContext.root.removeEventListener(gLite.ElementEvent.ATTR_MODIFIED, handleAttributeChanged);
5465
+ renderingContext.root.removeEventListener(gLite.ElementEvent.BOUNDS_CHANGED, handleBoundsChanged);
5466
+ });
5467
+ };
5468
+
5469
+ _proto.getId = function getId(object) {
5470
+ return object.id || HTML_PREFIX + object.entity;
5471
+ };
5472
+
5473
+ _proto.createCamera = function createCamera(camera) {
5474
+ var _this$context$config2 = this.context.config,
5475
+ doc = _this$context$config2.document,
5476
+ width = _this$context$config2.width,
5477
+ height = _this$context$config2.height;
5478
+ var $canvas = this.context.contextService.getDomElement();
5479
+ var $container = $canvas.parentNode;
5480
+
5481
+ if ($container) {
5482
+ var cameraId = CANVAS_CAMERA_ID;
5483
+ var $existedCamera = $container.querySelector('#' + cameraId);
5484
+
5485
+ if (!$existedCamera) {
5486
+ var $camera = (doc || document).createElement('div');
5487
+ $existedCamera = $camera;
5488
+ $camera.id = cameraId; // use absolute position
5489
+
5490
+ $camera.style.position = 'absolute'; // account for DOM element's offset @see https://github.com/antvis/G/issues/1150
5491
+
5492
+ $camera.style.left = ($canvas.offsetLeft || 0) + "px";
5493
+ $camera.style.top = ($canvas.offsetTop || 0) + "px";
5494
+ $camera.style.transformOrigin = 'left top';
5495
+ $camera.style.transform = this.joinTransformMatrix(camera.getOrthoMatrix()); // HTML elements should not overflow with canvas @see https://github.com/antvis/G/issues/1163
5496
+
5497
+ $camera.style.overflow = 'hidden';
5498
+ $camera.style.pointerEvents = 'none';
5499
+ $camera.style.width = (width || 0) + "px";
5500
+ $camera.style.height = (height || 0) + "px";
5501
+ $container.appendChild($camera);
5502
+ }
5503
+
5504
+ return $existedCamera;
5505
+ }
5506
+
5507
+ return null;
5508
+ };
5509
+
5510
+ _proto.getOrCreateEl = function getOrCreateEl(object) {
5511
+ var doc = this.context.config.document;
5512
+ var existedId = this.getId(object);
5513
+ var $existedElement = this.$camera.querySelector('#' + existedId);
5514
+
5515
+ if (!$existedElement) {
5516
+ $existedElement = (doc || document).createElement('div');
5517
+ object.parsedStyle.$el = $existedElement;
5518
+ $existedElement.id = existedId;
5519
+
5520
+ if (object.name) {
5521
+ $existedElement.setAttribute('name', object.name);
5522
+ }
5523
+
5524
+ if (object.className) {
5525
+ $existedElement.className = object.className;
5526
+ } // use absolute position
5527
+
5528
+
5529
+ $existedElement.style.position = 'absolute'; // @see https://github.com/antvis/G/issues/1150
5530
+
5531
+ $existedElement.style.left = "0px";
5532
+ $existedElement.style.top = "0px";
5533
+ $existedElement.style['will-change'] = 'transform';
5534
+ $existedElement.style.transform = this.joinTransformMatrix(object.getWorldTransform());
5535
+ }
5536
+
5537
+ return $existedElement;
5538
+ };
5848
5539
 
5849
- var addMouseEventListener = function addMouseEventListener($el) {
5850
- globalThis.document.addEventListener('mousemove', onPointerMove, true);
5851
- $el.addEventListener('mousedown', onPointerDown, true);
5852
- $el.addEventListener('mouseout', onPointerOut, true);
5853
- $el.addEventListener('mouseover', onPointerOver, true);
5854
- globalThis.addEventListener('mouseup', onPointerUp, true);
5855
- };
5540
+ _proto.updateAttribute = function updateAttribute(name, object) {
5541
+ var $el = this.getOrCreateEl(object);
5856
5542
 
5857
- var removePointerEventListener = function removePointerEventListener($el) {
5858
- globalThis.document.removeEventListener('pointermove', onPointerMove, true);
5859
- $el.removeEventListener('pointerdown', onPointerDown, true);
5860
- $el.removeEventListener('pointerleave', onPointerOut, true);
5861
- $el.removeEventListener('pointerover', onPointerOver, true);
5862
- globalThis.removeEventListener('pointerup', onPointerUp, true);
5863
- };
5543
+ switch (name) {
5544
+ case 'innerHTML':
5545
+ var innerHTML = object.parsedStyle.innerHTML;
5864
5546
 
5865
- var removeTouchEventListener = function removeTouchEventListener($el) {
5866
- $el.removeEventListener('touchstart', onPointerDown, true);
5867
- $el.removeEventListener('touchend', onPointerUp, true);
5868
- $el.removeEventListener('touchmove', onPointerMove, true);
5869
- $el.removeEventListener('touchcancel', onPointerCancel, true);
5870
- };
5547
+ if (isString(innerHTML)) {
5548
+ $el.innerHTML = innerHTML;
5549
+ } else {
5550
+ $el.innerHTML = '';
5551
+ $el.appendChild(innerHTML);
5552
+ }
5871
5553
 
5872
- var removeMouseEventListener = function removeMouseEventListener($el) {
5873
- globalThis.document.removeEventListener('mousemove', onPointerMove, true);
5874
- $el.removeEventListener('mousedown', onPointerDown, true);
5875
- $el.removeEventListener('mouseout', onPointerOut, true);
5876
- $el.removeEventListener('mouseover', onPointerOver, true);
5877
- globalThis.removeEventListener('mouseup', onPointerUp, true);
5878
- };
5554
+ break;
5879
5555
 
5880
- renderingService.hooks.init.tapPromise(DOMInteractionPlugin_1.tag, /*#__PURE__*/_asyncToGenerator$4( /*#__PURE__*/_regeneratorRuntime$4().mark(function _callee() {
5881
- var $el;
5882
- return _regeneratorRuntime$4().wrap(function _callee$(_context) {
5883
- while (1) {
5884
- switch (_context.prev = _context.next) {
5885
- case 0:
5886
- $el = _this.contextService.getDomElement(); // @ts-ignore
5556
+ case 'transformOrigin':
5557
+ var transformOrigin = object.parsedStyle.transformOrigin;
5558
+ $el.style['transform-origin'] = transformOrigin[0].value + " " + transformOrigin[1].value;
5559
+ break;
5887
5560
 
5888
- if (globalThis.navigator.msPointerEnabled) {
5889
- // @ts-ignore
5890
- $el.style.msContentZooming = 'none'; // @ts-ignore
5561
+ case 'width':
5562
+ var width = object.computedStyleMap().get('width');
5563
+ $el.style.width = width.toString();
5564
+ break;
5891
5565
 
5892
- $el.style.msTouchAction = 'none';
5893
- } else if (canvas.supportsPointerEvents) {
5894
- $el.style.touchAction = 'none';
5895
- }
5566
+ case 'height':
5567
+ var height = object.computedStyleMap().get('height');
5568
+ $el.style.height = height.toString();
5569
+ break;
5896
5570
 
5897
- if (canvas.supportsPointerEvents) {
5898
- addPointerEventListener($el);
5899
- } else {
5900
- addMouseEventListener($el);
5901
- }
5571
+ case 'zIndex':
5572
+ var zIndex = object.parsedStyle.zIndex;
5573
+ $el.style['z-index'] = "" + zIndex;
5574
+ break;
5902
5575
 
5903
- if (canvas.supportsTouchEvents) {
5904
- addTouchEventListener($el);
5905
- } // use passive event listeners
5906
- // @see https://zhuanlan.zhihu.com/p/24555031
5576
+ case 'visibility':
5577
+ var visibility = object.parsedStyle.visibility;
5578
+ $el.style.visibility = visibility;
5579
+ break;
5907
5580
 
5581
+ case 'pointerEvents':
5582
+ var pointerEvents = object.parsedStyle.pointerEvents;
5583
+ $el.style.pointerEvents = pointerEvents;
5584
+ break;
5908
5585
 
5909
- $el.addEventListener('wheel', onPointerWheel, {
5910
- passive: true,
5911
- capture: true
5912
- });
5586
+ case 'opacity':
5587
+ var opacity = object.parsedStyle.opacity;
5588
+ $el.style.opacity = "" + opacity;
5589
+ break;
5913
5590
 
5914
- case 5:
5915
- case "end":
5916
- return _context.stop();
5591
+ case 'fill':
5592
+ var fill = object.parsedStyle.fill;
5593
+ var color = '';
5594
+
5595
+ if (fill instanceof gLite.CSSRGB) {
5596
+ if (fill.isNone) {
5597
+ color = 'transparent';
5598
+ } else {
5599
+ color = object.getAttribute('fill');
5917
5600
  }
5918
- }
5919
- }, _callee);
5920
- })));
5921
- renderingService.hooks.destroy.tap(DOMInteractionPlugin_1.tag, function () {
5922
- var $el = _this.contextService.getDomElement(); // @ts-ignore
5601
+ } else if (Array.isArray(fill)) {
5602
+ color = object.getAttribute('fill');
5603
+ } else if (gLite.isPattern(fill)) ;
5923
5604
 
5605
+ $el.style.background = color;
5606
+ break;
5924
5607
 
5925
- if (globalThis.navigator.msPointerEnabled) {
5926
- // @ts-ignore
5927
- $el.style.msContentZooming = ''; // @ts-ignore
5608
+ case 'stroke':
5609
+ var stroke = object.parsedStyle.stroke;
5610
+ var borderColor = '';
5928
5611
 
5929
- $el.style.msTouchAction = '';
5930
- } else if (canvas.supportsPointerEvents) {
5931
- $el.style.touchAction = '';
5932
- }
5612
+ if (stroke instanceof gLite.CSSRGB) {
5613
+ if (stroke.isNone) {
5614
+ borderColor = 'transparent';
5615
+ } else {
5616
+ borderColor = object.getAttribute('stroke');
5617
+ }
5618
+ } else if (Array.isArray(stroke)) {
5619
+ borderColor = object.getAttribute('stroke');
5620
+ } else if (gLite.isPattern(stroke)) ;
5933
5621
 
5934
- if (canvas.supportsPointerEvents) {
5935
- removePointerEventListener($el);
5936
- } else {
5937
- removeMouseEventListener($el);
5938
- }
5622
+ $el.style['border-color'] = borderColor;
5623
+ $el.style['border-style'] = 'solid';
5624
+ break;
5939
5625
 
5940
- if (canvas.supportsTouchEvents) {
5941
- removeTouchEventListener($el);
5942
- }
5626
+ case 'lineWidth':
5627
+ var lineWidth = object.parsedStyle.lineWidth;
5628
+ $el.style['border-width'] = (lineWidth || 0) + "px";
5629
+ break;
5943
5630
 
5944
- $el.removeEventListener('wheel', onPointerWheel, true);
5945
- });
5631
+ case 'lineDash':
5632
+ $el.style['border-style'] = 'dashed';
5633
+ break;
5634
+
5635
+ case 'filter':
5636
+ var filter = object.style.filter;
5637
+ $el.style.filter = filter;
5638
+ break;
5639
+ }
5946
5640
  };
5947
5641
 
5948
- return DOMInteractionPlugin;
5949
- }(), _class$3.tag = 'DOMInteraction', _class$3);
5950
- DOMInteractionPlugin = DOMInteractionPlugin_1 = __decorate([gLite.singleton({
5951
- contrib: gLite.RenderingPluginContribution
5952
- }), __param(0, gLite.inject(gLite.ContextService)), __param(1, gLite.inject(gLite.RenderingContext))], DOMInteractionPlugin);
5953
- var containerModule$4 = gLite.Module(function (register) {
5954
- register(DOMInteractionPlugin);
5955
- });
5642
+ return HTMLRenderingPlugin;
5643
+ }();
5644
+
5645
+ HTMLRenderingPlugin.tag = 'HTMLRendering';
5956
5646
 
5957
5647
  var Plugin$4 = /*#__PURE__*/function (_AbstractRendererPlug) {
5958
5648
  _inheritsLoose$5(Plugin, _AbstractRendererPlug);
@@ -5965,18 +5655,18 @@
5965
5655
  }
5966
5656
 
5967
5657
  _this = _AbstractRendererPlug.call.apply(_AbstractRendererPlug, [this].concat(args)) || this;
5968
- _this.name = 'dom-interaction';
5658
+ _this.name = 'html-renderer';
5969
5659
  return _this;
5970
5660
  }
5971
5661
 
5972
5662
  var _proto = Plugin.prototype;
5973
5663
 
5974
5664
  _proto.init = function init() {
5975
- this.container.load(containerModule$4, true);
5665
+ this.addRenderingPlugin(new HTMLRenderingPlugin());
5976
5666
  };
5977
5667
 
5978
5668
  _proto.destroy = function destroy() {
5979
- this.container.unload(containerModule$4);
5669
+ this.removeAllRenderingPlugins();
5980
5670
  };
5981
5671
 
5982
5672
  return Plugin;
@@ -6388,271 +6078,247 @@
6388
6078
  return _setPrototypeOf$6(o, p);
6389
6079
  }
6390
6080
 
6391
- var _class$4;
6392
-
6393
- var HTMLRenderingPlugin_1;
6394
- var HTML_PREFIX = 'g-html-';
6395
- var HTMLRenderingPlugin = HTMLRenderingPlugin_1 = (_class$4 = /*#__PURE__*/function () {
6396
- function HTMLRenderingPlugin(contextService, renderingContext, canvasConfig) {
6397
- this.contextService = void 0;
6398
- this.renderingContext = void 0;
6081
+ var ImagePool = /*#__PURE__*/function () {
6082
+ function ImagePool(canvasConfig) {
6399
6083
  this.canvasConfig = void 0;
6400
- this.$camera = void 0;
6401
- this.contextService = contextService;
6402
- this.renderingContext = renderingContext;
6084
+ this.imageCache = {};
6085
+ this.gradientCache = {};
6086
+ this.patternCache = {};
6403
6087
  this.canvasConfig = canvasConfig;
6404
6088
  }
6405
6089
 
6406
- var _proto = HTMLRenderingPlugin.prototype;
6407
-
6408
- _proto.apply = function apply(renderingService) {
6409
- var _this = this;
6410
-
6411
- var setTransform = function setTransform(object, $el) {
6412
- var worldTransform = object.getWorldTransform();
6413
- $el.style.transform = "matrix(" + [worldTransform[0], worldTransform[1], worldTransform[4], worldTransform[5], worldTransform[12], worldTransform[13]].join(',') + ")";
6414
- };
6415
-
6416
- var handleMounted = function handleMounted(e) {
6417
- var object = e.target;
6418
-
6419
- if (object.nodeName === gLite.Shape.HTML) {
6420
- var $el = _this.getOrCreateEl(object); // apply documentElement's style
6421
-
6090
+ var _proto = ImagePool.prototype;
6422
6091
 
6423
- var attributes = object.ownerDocument.documentElement.attributes;
6424
- Object.keys(attributes).forEach(function (name) {
6425
- $el.style[name] = attributes[name];
6426
- });
6427
- Object.keys(object.attributes).forEach(function (name) {
6428
- _this.updateAttribute(name, object);
6429
- });
6430
- setTransform(object, $el);
6092
+ _proto.getImageSync = function getImageSync(src, callback) {
6093
+ if (!this.imageCache[src]) {
6094
+ this.getOrCreateImage(src).then(function () {
6095
+ if (callback) {
6096
+ callback();
6097
+ }
6098
+ });
6099
+ } else {
6100
+ if (callback) {
6101
+ callback();
6431
6102
  }
6432
- };
6433
-
6434
- var handleUnmounted = function handleUnmounted(e) {
6435
- var object = e.target;
6436
-
6437
- if (object.nodeName === gLite.Shape.HTML) {
6438
- var existedId = _this.getId(object);
6103
+ }
6439
6104
 
6440
- var $container = _this.contextService.getDomElement().parentNode;
6105
+ return this.imageCache[src];
6106
+ };
6441
6107
 
6442
- if ($container) {
6443
- var $existedElement = $container.querySelector('#' + existedId);
6108
+ _proto.getOrCreateImage = function getOrCreateImage(src) {
6109
+ var _this = this;
6444
6110
 
6445
- if ($existedElement) {
6446
- $container.removeChild($existedElement);
6447
- }
6448
- }
6449
- }
6450
- };
6111
+ if (this.imageCache[src]) {
6112
+ return Promise.resolve(this.imageCache[src]);
6113
+ } // @see https://github.com/antvis/g/issues/938
6451
6114
 
6452
- var handleAttributeChanged = function handleAttributeChanged(e) {
6453
- var object = e.target;
6454
6115
 
6455
- if (object.nodeName === gLite.Shape.HTML) {
6456
- var attrName = e.attrName;
6116
+ var createImage = this.canvasConfig.createImage;
6117
+ return new Promise(function (resolve, reject) {
6118
+ var image;
6457
6119
 
6458
- _this.updateAttribute(attrName, object);
6120
+ if (createImage) {
6121
+ image = createImage(src);
6122
+ } else if (gLite.isBrowser) {
6123
+ image = new window.Image();
6459
6124
  }
6460
- };
6461
6125
 
6462
- var handleBoundsChanged = function handleBoundsChanged(e) {
6463
- var object = e.target;
6126
+ if (image) {
6127
+ image.onload = function () {
6128
+ resolve(image);
6129
+ };
6464
6130
 
6465
- if (object.nodeName === gLite.Shape.HTML) {
6466
- var $el = _this.getOrCreateEl(object);
6131
+ image.onerror = function (ev) {
6132
+ reject(ev);
6133
+ };
6467
6134
 
6468
- setTransform(object, $el);
6135
+ image.crossOrigin = 'Anonymous';
6136
+ image.src = src;
6137
+ _this.imageCache[src] = image;
6469
6138
  }
6470
- };
6471
-
6472
- renderingService.hooks.init.tapPromise(HTMLRenderingPlugin_1.tag, /*#__PURE__*/_asyncToGenerator$5( /*#__PURE__*/_regeneratorRuntime$5().mark(function _callee() {
6473
- return _regeneratorRuntime$5().wrap(function _callee$(_context) {
6474
- while (1) {
6475
- switch (_context.prev = _context.next) {
6476
- case 0:
6477
- _this.renderingContext.root.addEventListener(gLite.ElementEvent.MOUNTED, handleMounted);
6139
+ });
6140
+ };
6478
6141
 
6479
- _this.renderingContext.root.addEventListener(gLite.ElementEvent.UNMOUNTED, handleUnmounted);
6142
+ _proto.getOrCreatePatternSync = function getOrCreatePatternSync(pattern, context, callback) {
6143
+ var patternKey = this.generatePatternKey(pattern);
6480
6144
 
6481
- _this.renderingContext.root.addEventListener(gLite.ElementEvent.ATTR_MODIFIED, handleAttributeChanged);
6145
+ if (patternKey && this.patternCache[patternKey]) {
6146
+ return this.patternCache[patternKey];
6147
+ }
6482
6148
 
6483
- _this.renderingContext.root.addEventListener(gLite.ElementEvent.BOUNDS_CHANGED, handleBoundsChanged);
6149
+ var image = pattern.image,
6150
+ repetition = pattern.repetition;
6151
+ var src; // Image URL
6484
6152
 
6485
- case 4:
6486
- case "end":
6487
- return _context.stop();
6488
- }
6489
- }
6490
- }, _callee);
6491
- })));
6492
- renderingService.hooks.destroy.tap(HTMLRenderingPlugin_1.tag, function () {
6493
- _this.renderingContext.root.removeEventListener(gLite.ElementEvent.MOUNTED, handleMounted);
6153
+ if (isString(image)) {
6154
+ src = this.getImageSync(image, callback);
6155
+ } else {
6156
+ src = image;
6157
+ } // @see https://developer.mozilla.org/zh-CN/docs/Web/API/CanvasRenderingContext2D/createPattern
6494
6158
 
6495
- _this.renderingContext.root.removeEventListener(gLite.ElementEvent.UNMOUNTED, handleUnmounted);
6496
6159
 
6497
- _this.renderingContext.root.removeEventListener(gLite.ElementEvent.ATTR_MODIFIED, handleAttributeChanged);
6160
+ var canvasPattern = src && context.createPattern(src, repetition);
6498
6161
 
6499
- _this.renderingContext.root.removeEventListener(gLite.ElementEvent.BOUNDS_CHANGED, handleBoundsChanged);
6500
- });
6501
- };
6162
+ if (patternKey && canvasPattern) {
6163
+ this.patternCache[patternKey] = canvasPattern;
6164
+ }
6502
6165
 
6503
- _proto.getId = function getId(object) {
6504
- return object.id || HTML_PREFIX + object.entity;
6166
+ return canvasPattern;
6505
6167
  };
6506
6168
 
6507
- _proto.getOrCreateEl = function getOrCreateEl(object) {
6508
- var doc = this.canvasConfig.document;
6509
- var existedId = this.getId(object);
6510
- var $canvas = this.contextService.getDomElement();
6511
- var $container = $canvas.parentNode;
6512
-
6513
- if ($container) {
6514
- var $existedElement = $container.querySelector('#' + existedId);
6169
+ _proto.getOrCreateGradient = function getOrCreateGradient(params, context) {
6170
+ var key = this.generateGradientKey(params);
6171
+ var type = params.type,
6172
+ steps = params.steps,
6173
+ width = params.width,
6174
+ height = params.height,
6175
+ angle = params.angle,
6176
+ cx = params.cx,
6177
+ cy = params.cy,
6178
+ size = params.size;
6515
6179
 
6516
- if (!$existedElement) {
6517
- $existedElement = (doc || document).createElement('div');
6518
- object.parsedStyle.$el = $existedElement;
6519
- $existedElement.id = existedId;
6180
+ if (this.gradientCache[key]) {
6181
+ return this.gradientCache[key];
6182
+ }
6520
6183
 
6521
- if (object.name) {
6522
- $existedElement.setAttribute('name', object.name);
6523
- }
6184
+ var gradient = null;
6524
6185
 
6525
- if (object.className) {
6526
- $existedElement.className = object.className;
6527
- }
6186
+ if (type === gLite.GradientType.LinearGradient) {
6187
+ var _computeLinearGradien = gLite.computeLinearGradient(width, height, angle),
6188
+ x1 = _computeLinearGradien.x1,
6189
+ y1 = _computeLinearGradien.y1,
6190
+ x2 = _computeLinearGradien.x2,
6191
+ y2 = _computeLinearGradien.y2; // @see https://developer.mozilla.org/zh-CN/docs/Web/API/CanvasRenderingContext2D/createLinearGradient
6528
6192
 
6529
- $container.appendChild($existedElement); // use absolute position
6530
6193
 
6531
- $existedElement.style.position = 'absolute'; // @see https://github.com/antvis/G/issues/1150
6194
+ gradient = context.createLinearGradient(x1, y1, x2, y2);
6195
+ } else if (type === gLite.GradientType.RadialGradient) {
6196
+ var _computeRadialGradien = gLite.computeRadialGradient(width, height, cx, cy, size),
6197
+ x = _computeRadialGradien.x,
6198
+ y = _computeRadialGradien.y,
6199
+ r = _computeRadialGradien.r; // @see https://developer.mozilla.org/zh-CN/docs/Web/API/CanvasRenderingContext2D/createRadialGradient
6532
6200
 
6533
- $existedElement.style.left = ($canvas.offsetLeft || 0) + "px";
6534
- $existedElement.style.top = ($canvas.offsetTop || 0) + "px";
6535
- $existedElement.style['will-change'] = 'transform';
6536
- var worldTransform = object.getWorldTransform();
6537
- $existedElement.style.transform = "matrix(" + [worldTransform[0], worldTransform[1], worldTransform[4], worldTransform[5], worldTransform[12], worldTransform[13]].join(',') + ")";
6538
- }
6539
6201
 
6540
- return $existedElement;
6202
+ gradient = context.createRadialGradient(x, y, 0, x, y, r);
6541
6203
  }
6542
6204
 
6543
- return null;
6544
- };
6545
-
6546
- _proto.updateAttribute = function updateAttribute(name, object) {
6547
- var $el = this.getOrCreateEl(object);
6205
+ if (gradient) {
6206
+ steps.forEach(function (_ref) {
6207
+ var offset = _ref.offset,
6208
+ color = _ref.color;
6548
6209
 
6549
- switch (name) {
6550
- case 'innerHTML':
6551
- var innerHTML = object.parsedStyle.innerHTML;
6210
+ if (offset.unit === gLite.UnitType.kPercentage) {
6211
+ var _gradient;
6552
6212
 
6553
- if (isString(innerHTML)) {
6554
- $el.innerHTML = innerHTML;
6555
- } else {
6556
- $el.innerHTML = '';
6557
- $el.appendChild(innerHTML);
6213
+ (_gradient = gradient) === null || _gradient === void 0 ? void 0 : _gradient.addColorStop(offset.value / 100, color.toString());
6558
6214
  }
6215
+ });
6216
+ this.gradientCache[key] = gradient;
6217
+ }
6559
6218
 
6560
- break;
6219
+ return this.gradientCache[key];
6220
+ };
6561
6221
 
6562
- case 'transformOrigin':
6563
- var transformOrigin = object.parsedStyle.transformOrigin;
6564
- $el.style['transform-origin'] = transformOrigin[0].value + " " + transformOrigin[1].value;
6565
- break;
6222
+ _proto.generateGradientKey = function generateGradientKey(params) {
6223
+ var type = params.type,
6224
+ width = params.width,
6225
+ height = params.height,
6226
+ steps = params.steps,
6227
+ angle = params.angle,
6228
+ cx = params.cx,
6229
+ cy = params.cy,
6230
+ size = params.size;
6231
+ return "gradient-" + type + "-" + ((angle === null || angle === void 0 ? void 0 : angle.toString()) || 0) + "-" + ((cx === null || cx === void 0 ? void 0 : cx.toString()) || 0) + "-" + ((cy === null || cy === void 0 ? void 0 : cy.toString()) || 0) + "-" + ((size === null || size === void 0 ? void 0 : size.toString()) || 0) + "-" + width + "-" + height + "-" + steps.map(function (_ref2) {
6232
+ var offset = _ref2.offset,
6233
+ color = _ref2.color;
6234
+ return "" + offset + color;
6235
+ }).join('-');
6236
+ };
6566
6237
 
6567
- case 'width':
6568
- var width = object.computedStyleMap().get('width');
6569
- $el.style.width = width.toString();
6570
- break;
6238
+ _proto.generatePatternKey = function generatePatternKey(pattern) {
6239
+ var image = pattern.image,
6240
+ repetition = pattern.repetition; // only generate cache for Image
6571
6241
 
6572
- case 'height':
6573
- var height = object.computedStyleMap().get('height');
6574
- $el.style.height = height.toString();
6575
- break;
6242
+ if (isString(image)) {
6243
+ return "pattern-" + image + "-" + repetition;
6244
+ }
6245
+ };
6576
6246
 
6577
- case 'zIndex':
6578
- var zIndex = object.parsedStyle.zIndex;
6579
- $el.style['z-index'] = "" + zIndex;
6580
- break;
6247
+ return ImagePool;
6248
+ }();
6581
6249
 
6582
- case 'visibility':
6583
- var visibility = object.parsedStyle.visibility;
6584
- $el.style.visibility = visibility;
6585
- break;
6250
+ var LoadImagePlugin = /*#__PURE__*/function () {
6251
+ function LoadImagePlugin() {}
6586
6252
 
6587
- case 'pointerEvents':
6588
- var pointerEvents = object.parsedStyle.pointerEvents;
6589
- $el.style.pointerEvents = pointerEvents;
6590
- break;
6253
+ var _proto = LoadImagePlugin.prototype;
6591
6254
 
6592
- case 'opacity':
6593
- var opacity = object.parsedStyle.opacity;
6594
- $el.style.opacity = "" + opacity;
6595
- break;
6255
+ _proto.apply = function apply(context) {
6256
+ // @ts-ignore
6257
+ var renderingService = context.renderingService,
6258
+ renderingContext = context.renderingContext,
6259
+ imagePool = context.imagePool;
6596
6260
 
6597
- case 'fill':
6598
- var fill = object.parsedStyle.fill;
6599
- var color = '';
6261
+ var handleMounted = function handleMounted(e) {
6262
+ var object = e.target;
6263
+ var nodeName = object.nodeName,
6264
+ attributes = object.attributes;
6600
6265
 
6601
- if (fill instanceof gLite.CSSRGB) {
6602
- if (fill.isNone) {
6603
- color = 'transparent';
6604
- } else {
6605
- color = object.getAttribute('fill');
6606
- }
6607
- } else if (Array.isArray(fill)) {
6608
- color = object.getAttribute('fill');
6609
- } else if (gLite.isPattern(fill)) ;
6266
+ if (nodeName === gLite.Shape.IMAGE) {
6267
+ var img = attributes.img;
6610
6268
 
6611
- $el.style.background = color;
6612
- break;
6269
+ if (isString(img)) {
6270
+ imagePool.getImageSync(img, function () {
6271
+ // set dirty rectangle flag
6272
+ object.renderable.dirty = true;
6273
+ renderingService.dirtify();
6274
+ });
6275
+ }
6276
+ }
6277
+ };
6613
6278
 
6614
- case 'stroke':
6615
- var stroke = object.parsedStyle.stroke;
6616
- var borderColor = '';
6279
+ var handleAttributeChanged = function handleAttributeChanged(e) {
6280
+ var object = e.target;
6281
+ var attrName = e.attrName,
6282
+ newValue = e.newValue;
6617
6283
 
6618
- if (stroke instanceof gLite.CSSRGB) {
6619
- if (stroke.isNone) {
6620
- borderColor = 'transparent';
6621
- } else {
6622
- borderColor = object.getAttribute('stroke');
6284
+ if (object.nodeName === gLite.Shape.IMAGE) {
6285
+ if (attrName === 'img') {
6286
+ if (isString(newValue)) {
6287
+ imagePool.getOrCreateImage(newValue).then(function () {
6288
+ // set dirty rectangle flag
6289
+ object.renderable.dirty = true;
6290
+ renderingService.dirtify();
6291
+ });
6623
6292
  }
6624
- } else if (Array.isArray(stroke)) {
6625
- borderColor = object.getAttribute('stroke');
6626
- } else if (gLite.isPattern(stroke)) ;
6627
-
6628
- $el.style['border-color'] = borderColor;
6629
- $el.style['border-style'] = 'solid';
6630
- break;
6631
-
6632
- case 'lineWidth':
6633
- var lineWidth = object.parsedStyle.lineWidth;
6634
- $el.style['border-width'] = (lineWidth || 0) + "px";
6635
- break;
6293
+ }
6294
+ }
6295
+ };
6636
6296
 
6637
- case 'lineDash':
6638
- $el.style['border-style'] = 'dashed';
6639
- break;
6297
+ renderingService.hooks.init.tapPromise(LoadImagePlugin.tag, /*#__PURE__*/_asyncToGenerator$5( /*#__PURE__*/_regeneratorRuntime$5().mark(function _callee() {
6298
+ return _regeneratorRuntime$5().wrap(function _callee$(_context) {
6299
+ while (1) {
6300
+ switch (_context.prev = _context.next) {
6301
+ case 0:
6302
+ renderingContext.root.addEventListener(gLite.ElementEvent.MOUNTED, handleMounted);
6303
+ renderingContext.root.addEventListener(gLite.ElementEvent.ATTR_MODIFIED, handleAttributeChanged);
6640
6304
 
6641
- case 'filter':
6642
- var filter = object.style.filter;
6643
- $el.style.filter = filter;
6644
- break;
6645
- }
6305
+ case 2:
6306
+ case "end":
6307
+ return _context.stop();
6308
+ }
6309
+ }
6310
+ }, _callee);
6311
+ })));
6312
+ renderingService.hooks.destroy.tap(LoadImagePlugin.tag, function () {
6313
+ renderingContext.root.removeEventListener(gLite.ElementEvent.MOUNTED, handleMounted);
6314
+ renderingContext.root.removeEventListener(gLite.ElementEvent.ATTR_MODIFIED, handleAttributeChanged);
6315
+ });
6646
6316
  };
6647
6317
 
6648
- return HTMLRenderingPlugin;
6649
- }(), _class$4.tag = 'HTMLRendering', _class$4);
6650
- HTMLRenderingPlugin = HTMLRenderingPlugin_1 = __decorate([gLite.singleton({
6651
- contrib: gLite.RenderingPluginContribution
6652
- }), __param(0, gLite.inject(gLite.ContextService)), __param(1, gLite.inject(gLite.RenderingContext)), __param(2, gLite.inject(gLite.CanvasConfig))], HTMLRenderingPlugin);
6653
- var containerModule$5 = gLite.Module(function (register) {
6654
- register(HTMLRenderingPlugin);
6655
- });
6318
+ return LoadImagePlugin;
6319
+ }();
6320
+
6321
+ LoadImagePlugin.tag = 'LoadImage';
6656
6322
 
6657
6323
  var Plugin$5 = /*#__PURE__*/function (_AbstractRendererPlug) {
6658
6324
  _inheritsLoose$6(Plugin, _AbstractRendererPlug);
@@ -6665,18 +6331,20 @@
6665
6331
  }
6666
6332
 
6667
6333
  _this = _AbstractRendererPlug.call.apply(_AbstractRendererPlug, [this].concat(args)) || this;
6668
- _this.name = 'html-renderer';
6334
+ _this.name = 'image-loader';
6669
6335
  return _this;
6670
6336
  }
6671
6337
 
6672
6338
  var _proto = Plugin.prototype;
6673
6339
 
6674
6340
  _proto.init = function init() {
6675
- this.container.load(containerModule$5, true);
6341
+ // @ts-ignore
6342
+ this.context.imagePool = new ImagePool(this.context.config);
6343
+ this.addRenderingPlugin(new LoadImagePlugin());
6676
6344
  };
6677
6345
 
6678
6346
  _proto.destroy = function destroy() {
6679
- this.container.unload(containerModule$5);
6347
+ this.removeAllRenderingPlugins();
6680
6348
  };
6681
6349
 
6682
6350
  return Plugin;
@@ -6684,19 +6352,20 @@
6684
6352
 
6685
6353
  var index_esm$5 = /*#__PURE__*/Object.freeze({
6686
6354
  __proto__: null,
6355
+ ImagePool: ImagePool,
6687
6356
  Plugin: Plugin$5
6688
6357
  });
6689
6358
 
6690
6359
  var Canvas2DContextService = /*#__PURE__*/function () {
6691
- function Canvas2DContextService(canvasConfig, renderingContext) {
6692
- this.canvasConfig = void 0;
6693
- this.renderingContext = void 0;
6360
+ function Canvas2DContextService(context) {
6694
6361
  this.$container = void 0;
6695
6362
  this.$canvas = void 0;
6696
6363
  this.dpr = void 0;
6697
6364
  this.context = void 0;
6698
- this.canvasConfig = canvasConfig;
6699
- this.renderingContext = renderingContext;
6365
+ this.canvasConfig = void 0;
6366
+ this.renderingContext = void 0;
6367
+ this.renderingContext = context.renderingContext;
6368
+ this.canvasConfig = context.config;
6700
6369
  }
6701
6370
 
6702
6371
  var _proto = Canvas2DContextService.prototype;
@@ -6842,16 +6511,6 @@
6842
6511
  return Canvas2DContextService;
6843
6512
  }();
6844
6513
 
6845
- Canvas2DContextService = __decorate([gLite.singleton({
6846
- token: gLite.ContextService
6847
- }), __param(0, gLite.inject(gLite.CanvasConfig)), __param(1, gLite.inject(gLite.RenderingContext))], Canvas2DContextService);
6848
-
6849
- var containerModule$6 = gLite.Module(function (register) {
6850
- /**
6851
- * implements ContextService
6852
- */
6853
- register(Canvas2DContextService);
6854
- });
6855
6514
  var ContextRegisterPlugin = /*#__PURE__*/function (_AbstractRendererPlug) {
6856
6515
  _inheritsLoose(ContextRegisterPlugin, _AbstractRendererPlug);
6857
6516
 
@@ -6870,11 +6529,11 @@
6870
6529
  var _proto = ContextRegisterPlugin.prototype;
6871
6530
 
6872
6531
  _proto.init = function init() {
6873
- this.container.load(containerModule$6, true);
6532
+ this.context.ContextService = Canvas2DContextService;
6874
6533
  };
6875
6534
 
6876
6535
  _proto.destroy = function destroy() {
6877
- this.container.unload(containerModule$6);
6536
+ delete this.context.ContextService;
6878
6537
  };
6879
6538
 
6880
6539
  return ContextRegisterPlugin;
@@ -6890,20 +6549,20 @@
6890
6549
 
6891
6550
  _this.registerPlugin(new ContextRegisterPlugin());
6892
6551
 
6893
- _this.registerPlugin(new Plugin$2());
6552
+ _this.registerPlugin(new Plugin$5());
6894
6553
 
6895
6554
  _this.registerPlugin(new Plugin()); // enable rendering with Canvas2D API
6896
6555
 
6897
6556
 
6898
- _this.registerPlugin(new Plugin$3());
6557
+ _this.registerPlugin(new Plugin$2());
6899
6558
 
6900
- _this.registerPlugin(new Plugin$4()); // enable picking with Canvas2D API
6559
+ _this.registerPlugin(new Plugin$3()); // enable picking with Canvas2D API
6901
6560
 
6902
6561
 
6903
6562
  _this.registerPlugin(new Plugin$1()); // render HTML component
6904
6563
 
6905
6564
 
6906
- _this.registerPlugin(new Plugin$5());
6565
+ _this.registerPlugin(new Plugin$4());
6907
6566
 
6908
6567
  return _this;
6909
6568
  }
@@ -6913,10 +6572,10 @@
6913
6572
 
6914
6573
  exports.CanvasPathGenerator = index_esm;
6915
6574
  exports.CanvasPicker = index_esm$1;
6916
- exports.CanvasRenderer = index_esm$3;
6917
- exports.DomInteraction = index_esm$4;
6918
- exports.HTMLRenderer = index_esm$5;
6919
- exports.ImageLoader = index_esm$2;
6575
+ exports.CanvasRenderer = index_esm$2;
6576
+ exports.DomInteraction = index_esm$3;
6577
+ exports.HTMLRenderer = index_esm$4;
6578
+ exports.ImageLoader = index_esm$5;
6920
6579
  exports.Renderer = Renderer;
6921
6580
 
6922
6581
  Object.defineProperty(exports, '__esModule', { value: true });