@antv/g-canvas 1.9.20 → 1.9.22

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
@@ -305,15 +305,6 @@
305
305
  }
306
306
  }, exports;
307
307
  }
308
- function _typeof(obj) {
309
- "@babel/helpers - typeof";
310
-
311
- return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) {
312
- return typeof obj;
313
- } : function (obj) {
314
- return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
315
- }, _typeof(obj);
316
- }
317
308
  function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
318
309
  try {
319
310
  var info = gen[key](arg);
@@ -344,49 +335,10 @@
344
335
  });
345
336
  };
346
337
  }
347
- function _classCallCheck(instance, Constructor) {
348
- if (!(instance instanceof Constructor)) {
349
- throw new TypeError("Cannot call a class as a function");
350
- }
351
- }
352
- function _defineProperties(target, props) {
353
- for (var i = 0; i < props.length; i++) {
354
- var descriptor = props[i];
355
- descriptor.enumerable = descriptor.enumerable || false;
356
- descriptor.configurable = true;
357
- if ("value" in descriptor) descriptor.writable = true;
358
- Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor);
359
- }
360
- }
361
- function _createClass(Constructor, protoProps, staticProps) {
362
- if (protoProps) _defineProperties(Constructor.prototype, protoProps);
363
- if (staticProps) _defineProperties(Constructor, staticProps);
364
- Object.defineProperty(Constructor, "prototype", {
365
- writable: false
366
- });
367
- return Constructor;
368
- }
369
- function _inherits(subClass, superClass) {
370
- if (typeof superClass !== "function" && superClass !== null) {
371
- throw new TypeError("Super expression must either be null or a function");
372
- }
373
- subClass.prototype = Object.create(superClass && superClass.prototype, {
374
- constructor: {
375
- value: subClass,
376
- writable: true,
377
- configurable: true
378
- }
379
- });
380
- Object.defineProperty(subClass, "prototype", {
381
- writable: false
382
- });
383
- if (superClass) _setPrototypeOf(subClass, superClass);
384
- }
385
- function _getPrototypeOf(o) {
386
- _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) {
387
- return o.__proto__ || Object.getPrototypeOf(o);
388
- };
389
- return _getPrototypeOf(o);
338
+ function _inheritsLoose(subClass, superClass) {
339
+ subClass.prototype = Object.create(superClass.prototype);
340
+ subClass.prototype.constructor = subClass;
341
+ _setPrototypeOf(subClass, superClass);
390
342
  }
391
343
  function _setPrototypeOf(o, p) {
392
344
  _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) {
@@ -395,59 +347,6 @@
395
347
  };
396
348
  return _setPrototypeOf(o, p);
397
349
  }
398
- function _isNativeReflectConstruct() {
399
- if (typeof Reflect === "undefined" || !Reflect.construct) return false;
400
- if (Reflect.construct.sham) return false;
401
- if (typeof Proxy === "function") return true;
402
- try {
403
- Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {}));
404
- return true;
405
- } catch (e) {
406
- return false;
407
- }
408
- }
409
- function _assertThisInitialized(self) {
410
- if (self === void 0) {
411
- throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
412
- }
413
- return self;
414
- }
415
- function _possibleConstructorReturn(self, call) {
416
- if (call && (typeof call === "object" || typeof call === "function")) {
417
- return call;
418
- } else if (call !== void 0) {
419
- throw new TypeError("Derived constructors may only return object or undefined");
420
- }
421
- return _assertThisInitialized(self);
422
- }
423
- function _createSuper(Derived) {
424
- var hasNativeReflectConstruct = _isNativeReflectConstruct();
425
- return function _createSuperInternal() {
426
- var Super = _getPrototypeOf(Derived),
427
- result;
428
- if (hasNativeReflectConstruct) {
429
- var NewTarget = _getPrototypeOf(this).constructor;
430
- result = Reflect.construct(Super, arguments, NewTarget);
431
- } else {
432
- result = Super.apply(this, arguments);
433
- }
434
- return _possibleConstructorReturn(this, result);
435
- };
436
- }
437
- function _toPrimitive(input, hint) {
438
- if (typeof input !== "object" || input === null) return input;
439
- var prim = input[Symbol.toPrimitive];
440
- if (prim !== undefined) {
441
- var res = prim.call(input, hint || "default");
442
- if (typeof res !== "object") return res;
443
- throw new TypeError("@@toPrimitive must return a primitive value.");
444
- }
445
- return (hint === "string" ? String : Number)(input);
446
- }
447
- function _toPropertyKey(arg) {
448
- var key = _toPrimitive(arg, "string");
449
- return typeof key === "symbol" ? key : String(key);
450
- }
451
350
 
452
351
  /**
453
352
  * Common utilities
@@ -1284,92 +1183,10 @@
1284
1183
  return a;
1285
1184
  };
1286
1185
 
1287
- function _iterableToArrayLimit(arr, i) {
1288
- var _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"];
1289
- if (null != _i) {
1290
- var _s,
1291
- _e,
1292
- _x,
1293
- _r,
1294
- _arr = [],
1295
- _n = !0,
1296
- _d = !1;
1297
- try {
1298
- if (_x = (_i = _i.call(arr)).next, 0 === i) {
1299
- if (Object(_i) !== _i) return;
1300
- _n = !1;
1301
- } else for (; !(_n = (_s = _x.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = !0) {
1302
- ;
1303
- }
1304
- } catch (err) {
1305
- _d = !0, _e = err;
1306
- } finally {
1307
- try {
1308
- if (!_n && null != _i.return && (_r = _i.return(), Object(_r) !== _r)) return;
1309
- } finally {
1310
- if (_d) throw _e;
1311
- }
1312
- }
1313
- return _arr;
1314
- }
1315
- }
1316
- function _classCallCheck$1(instance, Constructor) {
1317
- if (!(instance instanceof Constructor)) {
1318
- throw new TypeError("Cannot call a class as a function");
1319
- }
1320
- }
1321
- function _defineProperties$1(target, props) {
1322
- for (var i = 0; i < props.length; i++) {
1323
- var descriptor = props[i];
1324
- descriptor.enumerable = descriptor.enumerable || false;
1325
- descriptor.configurable = true;
1326
- if ("value" in descriptor) descriptor.writable = true;
1327
- Object.defineProperty(target, _toPropertyKey$1(descriptor.key), descriptor);
1328
- }
1329
- }
1330
- function _createClass$1(Constructor, protoProps, staticProps) {
1331
- if (protoProps) _defineProperties$1(Constructor.prototype, protoProps);
1332
- if (staticProps) _defineProperties$1(Constructor, staticProps);
1333
- Object.defineProperty(Constructor, "prototype", {
1334
- writable: false
1335
- });
1336
- return Constructor;
1337
- }
1338
- function _defineProperty(obj, key, value) {
1339
- key = _toPropertyKey$1(key);
1340
- if (key in obj) {
1341
- Object.defineProperty(obj, key, {
1342
- value: value,
1343
- enumerable: true,
1344
- configurable: true,
1345
- writable: true
1346
- });
1347
- } else {
1348
- obj[key] = value;
1349
- }
1350
- return obj;
1351
- }
1352
- function _inherits$1(subClass, superClass) {
1353
- if (typeof superClass !== "function" && superClass !== null) {
1354
- throw new TypeError("Super expression must either be null or a function");
1355
- }
1356
- subClass.prototype = Object.create(superClass && superClass.prototype, {
1357
- constructor: {
1358
- value: subClass,
1359
- writable: true,
1360
- configurable: true
1361
- }
1362
- });
1363
- Object.defineProperty(subClass, "prototype", {
1364
- writable: false
1365
- });
1366
- if (superClass) _setPrototypeOf$1(subClass, superClass);
1367
- }
1368
- function _getPrototypeOf$1(o) {
1369
- _getPrototypeOf$1 = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) {
1370
- return o.__proto__ || Object.getPrototypeOf(o);
1371
- };
1372
- return _getPrototypeOf$1(o);
1186
+ function _inheritsLoose$1(subClass, superClass) {
1187
+ subClass.prototype = Object.create(superClass.prototype);
1188
+ subClass.prototype.constructor = subClass;
1189
+ _setPrototypeOf$1(subClass, superClass);
1373
1190
  }
1374
1191
  function _setPrototypeOf$1(o, p) {
1375
1192
  _setPrototypeOf$1 = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) {
@@ -1378,83 +1195,6 @@
1378
1195
  };
1379
1196
  return _setPrototypeOf$1(o, p);
1380
1197
  }
1381
- function _isNativeReflectConstruct$1() {
1382
- if (typeof Reflect === "undefined" || !Reflect.construct) return false;
1383
- if (Reflect.construct.sham) return false;
1384
- if (typeof Proxy === "function") return true;
1385
- try {
1386
- Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {}));
1387
- return true;
1388
- } catch (e) {
1389
- return false;
1390
- }
1391
- }
1392
- function _assertThisInitialized$1(self) {
1393
- if (self === void 0) {
1394
- throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
1395
- }
1396
- return self;
1397
- }
1398
- function _possibleConstructorReturn$1(self, call) {
1399
- if (call && (_typeof(call) === "object" || typeof call === "function")) {
1400
- return call;
1401
- } else if (call !== void 0) {
1402
- throw new TypeError("Derived constructors may only return object or undefined");
1403
- }
1404
- return _assertThisInitialized$1(self);
1405
- }
1406
- function _createSuper$1(Derived) {
1407
- var hasNativeReflectConstruct = _isNativeReflectConstruct$1();
1408
- return function _createSuperInternal() {
1409
- var Super = _getPrototypeOf$1(Derived),
1410
- result;
1411
- if (hasNativeReflectConstruct) {
1412
- var NewTarget = _getPrototypeOf$1(this).constructor;
1413
- result = Reflect.construct(Super, arguments, NewTarget);
1414
- } else {
1415
- result = Super.apply(this, arguments);
1416
- }
1417
- return _possibleConstructorReturn$1(this, result);
1418
- };
1419
- }
1420
- function _slicedToArray(arr, i) {
1421
- return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest();
1422
- }
1423
- function _arrayWithHoles(arr) {
1424
- if (Array.isArray(arr)) return arr;
1425
- }
1426
- function _unsupportedIterableToArray(o, minLen) {
1427
- if (!o) return;
1428
- if (typeof o === "string") return _arrayLikeToArray(o, minLen);
1429
- var n = Object.prototype.toString.call(o).slice(8, -1);
1430
- if (n === "Object" && o.constructor) n = o.constructor.name;
1431
- if (n === "Map" || n === "Set") return Array.from(o);
1432
- if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
1433
- }
1434
- function _arrayLikeToArray(arr, len) {
1435
- if (len == null || len > arr.length) len = arr.length;
1436
- for (var i = 0, arr2 = new Array(len); i < len; i++) {
1437
- arr2[i] = arr[i];
1438
- }
1439
- return arr2;
1440
- }
1441
- function _nonIterableRest() {
1442
- throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
1443
- }
1444
- function _toPrimitive$1(input, hint) {
1445
- if (_typeof(input) !== "object" || input === null) return input;
1446
- var prim = input[Symbol.toPrimitive];
1447
- if (prim !== undefined) {
1448
- var res = prim.call(input, hint || "default");
1449
- if (_typeof(res) !== "object") return res;
1450
- throw new TypeError("@@toPrimitive must return a primitive value.");
1451
- }
1452
- return (hint === "string" ? String : Number)(input);
1453
- }
1454
- function _toPropertyKey$1(arg) {
1455
- var key = _toPrimitive$1(arg, "string");
1456
- return _typeof(key) === "symbol" ? key : String(key);
1457
- }
1458
1198
  function generatePath(context, parsedStyle) {
1459
1199
  var r = parsedStyle.r;
1460
1200
  context.arc(r, r, r, 0, Math.PI * 2, false);
@@ -1535,9 +1275,8 @@
1535
1275
  var y;
1536
1276
  if (markerStart && markerStart instanceof gLite.DisplayObject && markerStartOffset) {
1537
1277
  var _markerStart$parentNo = markerStart.parentNode.getStartTangent(),
1538
- _markerStart$parentNo2 = _slicedToArray(_markerStart$parentNo, 2),
1539
- p1 = _markerStart$parentNo2[0],
1540
- p2 = _markerStart$parentNo2[1];
1278
+ p1 = _markerStart$parentNo[0],
1279
+ p2 = _markerStart$parentNo[1];
1541
1280
  x = p1[0] - p2[0];
1542
1281
  y = p1[1] - p2[1];
1543
1282
  rad = Math.atan2(y, x);
@@ -1546,9 +1285,8 @@
1546
1285
  }
1547
1286
  if (markerEnd && markerEnd instanceof gLite.DisplayObject && markerEndOffset) {
1548
1287
  var _markerEnd$parentNode = markerEnd.parentNode.getEndTangent(),
1549
- _markerEnd$parentNode2 = _slicedToArray(_markerEnd$parentNode, 2),
1550
- _p = _markerEnd$parentNode2[0],
1551
- _p2 = _markerEnd$parentNode2[1];
1288
+ _p = _markerEnd$parentNode[0],
1289
+ _p2 = _markerEnd$parentNode[1];
1552
1290
  x = _p[0] - _p2[0];
1553
1291
  y = _p[1] - _p2[1];
1554
1292
  rad = Math.atan2(y, x);
@@ -1733,11 +1471,10 @@
1733
1471
  var _radius$map = radius.map(function (r) {
1734
1472
  return clamp(r, 0, Math.min(Math.abs(w) / 2, Math.abs(h) / 2));
1735
1473
  }),
1736
- _radius$map2 = _slicedToArray(_radius$map, 4),
1737
- tlr = _radius$map2[0],
1738
- trr = _radius$map2[1],
1739
- brr = _radius$map2[2],
1740
- blr = _radius$map2[3];
1474
+ tlr = _radius$map[0],
1475
+ trr = _radius$map[1],
1476
+ brr = _radius$map[2],
1477
+ blr = _radius$map[3];
1741
1478
  context.moveTo(signX * tlr, 0);
1742
1479
  context.lineTo(w - signX * trr, 0);
1743
1480
  if (trr !== 0) {
@@ -1758,33 +1495,27 @@
1758
1495
  }
1759
1496
  }
1760
1497
  var Plugin = /*#__PURE__*/function (_AbstractRendererPlug) {
1761
- _inherits$1(Plugin, _AbstractRendererPlug);
1762
- var _super = _createSuper$1(Plugin);
1498
+ _inheritsLoose$1(Plugin, _AbstractRendererPlug);
1763
1499
  function Plugin() {
1764
1500
  var _this;
1765
- _classCallCheck$1(this, Plugin);
1766
1501
  for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
1767
1502
  args[_key] = arguments[_key];
1768
1503
  }
1769
- _this = _super.call.apply(_super, [this].concat(args));
1504
+ _this = _AbstractRendererPlug.call.apply(_AbstractRendererPlug, [this].concat(args)) || this;
1770
1505
  _this.name = 'canvas-path-generator';
1771
1506
  return _this;
1772
1507
  }
1773
- _createClass$1(Plugin, [{
1774
- key: "init",
1775
- value: function init() {
1776
- var _pathGeneratorFactory;
1777
- var pathGeneratorFactory = (_pathGeneratorFactory = {}, _defineProperty(_pathGeneratorFactory, gLite.Shape.CIRCLE, generatePath), _defineProperty(_pathGeneratorFactory, gLite.Shape.ELLIPSE, generatePath$1), _defineProperty(_pathGeneratorFactory, gLite.Shape.RECT, generatePath$6), _defineProperty(_pathGeneratorFactory, gLite.Shape.LINE, generatePath$2), _defineProperty(_pathGeneratorFactory, gLite.Shape.POLYLINE, generatePath$5), _defineProperty(_pathGeneratorFactory, gLite.Shape.POLYGON, generatePath$4), _defineProperty(_pathGeneratorFactory, gLite.Shape.PATH, generatePath$3), _defineProperty(_pathGeneratorFactory, gLite.Shape.TEXT, undefined), _defineProperty(_pathGeneratorFactory, gLite.Shape.GROUP, undefined), _defineProperty(_pathGeneratorFactory, gLite.Shape.IMAGE, undefined), _defineProperty(_pathGeneratorFactory, gLite.Shape.HTML, undefined), _defineProperty(_pathGeneratorFactory, gLite.Shape.MESH, undefined), _pathGeneratorFactory);
1778
- // @ts-ignore
1779
- this.context.pathGeneratorFactory = pathGeneratorFactory;
1780
- }
1781
- }, {
1782
- key: "destroy",
1783
- value: function destroy() {
1784
- // @ts-ignore
1785
- delete this.context.pathGeneratorFactory;
1786
- }
1787
- }]);
1508
+ var _proto = Plugin.prototype;
1509
+ _proto.init = function init() {
1510
+ var _pathGeneratorFactory;
1511
+ 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);
1512
+ // @ts-ignore
1513
+ this.context.pathGeneratorFactory = pathGeneratorFactory;
1514
+ };
1515
+ _proto.destroy = function destroy() {
1516
+ // @ts-ignore
1517
+ delete this.context.pathGeneratorFactory;
1518
+ };
1788
1519
  return Plugin;
1789
1520
  }(gLite.AbstractRendererPlugin);
1790
1521
 
@@ -1793,35 +1524,6 @@
1793
1524
  Plugin: Plugin
1794
1525
  });
1795
1526
 
1796
- function _iterableToArrayLimit$1(arr, i) {
1797
- var _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"];
1798
- if (null != _i) {
1799
- var _s,
1800
- _e,
1801
- _x,
1802
- _r,
1803
- _arr = [],
1804
- _n = !0,
1805
- _d = !1;
1806
- try {
1807
- if (_x = (_i = _i.call(arr)).next, 0 === i) {
1808
- if (Object(_i) !== _i) return;
1809
- _n = !1;
1810
- } else for (; !(_n = (_s = _x.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = !0) {
1811
- ;
1812
- }
1813
- } catch (err) {
1814
- _d = !0, _e = err;
1815
- } finally {
1816
- try {
1817
- if (!_n && null != _i.return && (_r = _i.return(), Object(_r) !== _r)) return;
1818
- } finally {
1819
- if (_d) throw _e;
1820
- }
1821
- }
1822
- return _arr;
1823
- }
1824
- }
1825
1527
  function _regeneratorRuntime$1() {
1826
1528
  _regeneratorRuntime$1 = function _regeneratorRuntime() {
1827
1529
  return exports;
@@ -1898,7 +1600,7 @@
1898
1600
  if ("throw" !== record.type) {
1899
1601
  var result = record.arg,
1900
1602
  value = result.value;
1901
- return value && "object" == _typeof(value) && hasOwn.call(value, "__await") ? PromiseImpl.resolve(value.__await).then(function (value) {
1603
+ return value && "object" == typeof value && hasOwn.call(value, "__await") ? PromiseImpl.resolve(value.__await).then(function (value) {
1902
1604
  invoke("next", value, resolve, reject);
1903
1605
  }, function (err) {
1904
1606
  invoke("throw", err, resolve, reject);
@@ -2159,63 +1861,10 @@
2159
1861
  });
2160
1862
  };
2161
1863
  }
2162
- function _classCallCheck$2(instance, Constructor) {
2163
- if (!(instance instanceof Constructor)) {
2164
- throw new TypeError("Cannot call a class as a function");
2165
- }
2166
- }
2167
- function _defineProperties$2(target, props) {
2168
- for (var i = 0; i < props.length; i++) {
2169
- var descriptor = props[i];
2170
- descriptor.enumerable = descriptor.enumerable || false;
2171
- descriptor.configurable = true;
2172
- if ("value" in descriptor) descriptor.writable = true;
2173
- Object.defineProperty(target, _toPropertyKey$2(descriptor.key), descriptor);
2174
- }
2175
- }
2176
- function _createClass$2(Constructor, protoProps, staticProps) {
2177
- if (protoProps) _defineProperties$2(Constructor.prototype, protoProps);
2178
- if (staticProps) _defineProperties$2(Constructor, staticProps);
2179
- Object.defineProperty(Constructor, "prototype", {
2180
- writable: false
2181
- });
2182
- return Constructor;
2183
- }
2184
- function _defineProperty$1(obj, key, value) {
2185
- key = _toPropertyKey$2(key);
2186
- if (key in obj) {
2187
- Object.defineProperty(obj, key, {
2188
- value: value,
2189
- enumerable: true,
2190
- configurable: true,
2191
- writable: true
2192
- });
2193
- } else {
2194
- obj[key] = value;
2195
- }
2196
- return obj;
2197
- }
2198
- function _inherits$2(subClass, superClass) {
2199
- if (typeof superClass !== "function" && superClass !== null) {
2200
- throw new TypeError("Super expression must either be null or a function");
2201
- }
2202
- subClass.prototype = Object.create(superClass && superClass.prototype, {
2203
- constructor: {
2204
- value: subClass,
2205
- writable: true,
2206
- configurable: true
2207
- }
2208
- });
2209
- Object.defineProperty(subClass, "prototype", {
2210
- writable: false
2211
- });
2212
- if (superClass) _setPrototypeOf$2(subClass, superClass);
2213
- }
2214
- function _getPrototypeOf$2(o) {
2215
- _getPrototypeOf$2 = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) {
2216
- return o.__proto__ || Object.getPrototypeOf(o);
2217
- };
2218
- return _getPrototypeOf$2(o);
1864
+ function _inheritsLoose$2(subClass, superClass) {
1865
+ subClass.prototype = Object.create(superClass.prototype);
1866
+ subClass.prototype.constructor = subClass;
1867
+ _setPrototypeOf$2(subClass, superClass);
2219
1868
  }
2220
1869
  function _setPrototypeOf$2(o, p) {
2221
1870
  _setPrototypeOf$2 = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) {
@@ -2224,133 +1873,38 @@
2224
1873
  };
2225
1874
  return _setPrototypeOf$2(o, p);
2226
1875
  }
2227
- function _isNativeReflectConstruct$2() {
2228
- if (typeof Reflect === "undefined" || !Reflect.construct) return false;
2229
- if (Reflect.construct.sham) return false;
2230
- if (typeof Proxy === "function") return true;
2231
- try {
2232
- Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {}));
2233
- return true;
2234
- } catch (e) {
2235
- return false;
2236
- }
2237
- }
2238
- function _assertThisInitialized$2(self) {
2239
- if (self === void 0) {
2240
- throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
2241
- }
2242
- return self;
2243
- }
2244
- function _possibleConstructorReturn$2(self, call) {
2245
- if (call && (_typeof(call) === "object" || typeof call === "function")) {
2246
- return call;
2247
- } else if (call !== void 0) {
2248
- throw new TypeError("Derived constructors may only return object or undefined");
2249
- }
2250
- return _assertThisInitialized$2(self);
2251
- }
2252
- function _createSuper$2(Derived) {
2253
- var hasNativeReflectConstruct = _isNativeReflectConstruct$2();
2254
- return function _createSuperInternal() {
2255
- var Super = _getPrototypeOf$2(Derived),
2256
- result;
2257
- if (hasNativeReflectConstruct) {
2258
- var NewTarget = _getPrototypeOf$2(this).constructor;
2259
- result = Reflect.construct(Super, arguments, NewTarget);
2260
- } else {
2261
- result = Super.apply(this, arguments);
2262
- }
2263
- return _possibleConstructorReturn$2(this, result);
2264
- };
2265
- }
2266
- function _slicedToArray$1(arr, i) {
2267
- return _arrayWithHoles$1(arr) || _iterableToArrayLimit$1(arr, i) || _unsupportedIterableToArray$1(arr, i) || _nonIterableRest$1();
2268
- }
2269
- function _arrayWithHoles$1(arr) {
2270
- if (Array.isArray(arr)) return arr;
2271
- }
2272
- function _unsupportedIterableToArray$1(o, minLen) {
1876
+ function _unsupportedIterableToArray(o, minLen) {
2273
1877
  if (!o) return;
2274
- if (typeof o === "string") return _arrayLikeToArray$1(o, minLen);
1878
+ if (typeof o === "string") return _arrayLikeToArray(o, minLen);
2275
1879
  var n = Object.prototype.toString.call(o).slice(8, -1);
2276
1880
  if (n === "Object" && o.constructor) n = o.constructor.name;
2277
1881
  if (n === "Map" || n === "Set") return Array.from(o);
2278
- if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray$1(o, minLen);
1882
+ if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
2279
1883
  }
2280
- function _arrayLikeToArray$1(arr, len) {
1884
+ function _arrayLikeToArray(arr, len) {
2281
1885
  if (len == null || len > arr.length) len = arr.length;
2282
1886
  for (var i = 0, arr2 = new Array(len); i < len; i++) {
2283
1887
  arr2[i] = arr[i];
2284
1888
  }
2285
1889
  return arr2;
2286
1890
  }
2287
- function _nonIterableRest$1() {
2288
- throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
2289
- }
2290
- function _createForOfIteratorHelper(o, allowArrayLike) {
1891
+ function _createForOfIteratorHelperLoose(o, allowArrayLike) {
2291
1892
  var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"];
2292
- if (!it) {
2293
- if (Array.isArray(o) || (it = _unsupportedIterableToArray$1(o)) || allowArrayLike && o && typeof o.length === "number") {
2294
- if (it) o = it;
2295
- var i = 0;
2296
- var F = function F() {};
1893
+ if (it) return (it = it.call(o)).next.bind(it);
1894
+ if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") {
1895
+ if (it) o = it;
1896
+ var i = 0;
1897
+ return function () {
1898
+ if (i >= o.length) return {
1899
+ done: true
1900
+ };
2297
1901
  return {
2298
- s: F,
2299
- n: function n() {
2300
- if (i >= o.length) return {
2301
- done: true
2302
- };
2303
- return {
2304
- done: false,
2305
- value: o[i++]
2306
- };
2307
- },
2308
- e: function e(_e2) {
2309
- throw _e2;
2310
- },
2311
- f: F
1902
+ done: false,
1903
+ value: o[i++]
2312
1904
  };
2313
- }
2314
- throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
1905
+ };
2315
1906
  }
2316
- var normalCompletion = true,
2317
- didErr = false,
2318
- err;
2319
- return {
2320
- s: function s() {
2321
- it = it.call(o);
2322
- },
2323
- n: function n() {
2324
- var step = it.next();
2325
- normalCompletion = step.done;
2326
- return step;
2327
- },
2328
- e: function e(_e3) {
2329
- didErr = true;
2330
- err = _e3;
2331
- },
2332
- f: function f() {
2333
- try {
2334
- if (!normalCompletion && it.return != null) it.return();
2335
- } finally {
2336
- if (didErr) throw err;
2337
- }
2338
- }
2339
- };
2340
- }
2341
- function _toPrimitive$2(input, hint) {
2342
- if (_typeof(input) !== "object" || input === null) return input;
2343
- var prim = input[Symbol.toPrimitive];
2344
- if (prim !== undefined) {
2345
- var res = prim.call(input, hint || "default");
2346
- if (_typeof(res) !== "object") return res;
2347
- throw new TypeError("@@toPrimitive must return a primitive value.");
2348
- }
2349
- return (hint === "string" ? String : Number)(input);
2350
- }
2351
- function _toPropertyKey$2(arg) {
2352
- var key = _toPrimitive$2(arg, "string");
2353
- return _typeof(key) === "symbol" ? key : String(key);
1907
+ throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
2354
1908
  }
2355
1909
  var tmpVec3a = create$1();
2356
1910
  var tmpVec3b = create$1();
@@ -2365,7 +1919,6 @@
2365
1919
  var CanvasPickerPlugin = /*#__PURE__*/function () {
2366
1920
  function CanvasPickerPlugin() {
2367
1921
  var _this = this;
2368
- _classCallCheck$2(this, CanvasPickerPlugin);
2369
1922
  this.canvasConfig = void 0;
2370
1923
  this.pathGeneratorFactory = void 0;
2371
1924
  this.pointInPathPickerFactory = void 0;
@@ -2400,126 +1953,87 @@
2400
1953
  return context.isPointInPath(position.x, position.y);
2401
1954
  };
2402
1955
  }
2403
- _createClass$2(CanvasPickerPlugin, [{
2404
- key: "apply",
2405
- value: function apply(context) {
2406
- var _renderingContext$roo,
2407
- _this2 = this;
2408
- var config = context.config,
2409
- renderingService = context.renderingService,
2410
- renderingContext = context.renderingContext,
2411
- pathGeneratorFactory = context.pathGeneratorFactory,
2412
- pointInPathPickerFactory = context.pointInPathPickerFactory;
2413
- this.canvasConfig = config;
2414
- this.pathGeneratorFactory = pathGeneratorFactory;
2415
- this.pointInPathPickerFactory = pointInPathPickerFactory;
2416
- var document = (_renderingContext$roo = renderingContext.root) === null || _renderingContext$roo === void 0 ? void 0 : _renderingContext$roo.ownerDocument;
2417
- renderingService.hooks.pick.tapPromise(CanvasPickerPlugin.tag, /*#__PURE__*/function () {
2418
- var _ref = _asyncToGenerator$1( /*#__PURE__*/_regeneratorRuntime$1().mark(function _callee(result) {
2419
- return _regeneratorRuntime$1().wrap(function _callee$(_context) {
2420
- while (1) {
2421
- switch (_context.prev = _context.next) {
2422
- case 0:
2423
- return _context.abrupt("return", _this2.pick(document, result));
2424
- case 1:
2425
- case "end":
2426
- return _context.stop();
2427
- }
1956
+ var _proto = CanvasPickerPlugin.prototype;
1957
+ _proto.apply = function apply(context) {
1958
+ var _renderingContext$roo,
1959
+ _this2 = this;
1960
+ var config = context.config,
1961
+ renderingService = context.renderingService,
1962
+ renderingContext = context.renderingContext,
1963
+ pathGeneratorFactory = context.pathGeneratorFactory,
1964
+ pointInPathPickerFactory = context.pointInPathPickerFactory;
1965
+ this.canvasConfig = config;
1966
+ this.pathGeneratorFactory = pathGeneratorFactory;
1967
+ this.pointInPathPickerFactory = pointInPathPickerFactory;
1968
+ var document = (_renderingContext$roo = renderingContext.root) === null || _renderingContext$roo === void 0 ? void 0 : _renderingContext$roo.ownerDocument;
1969
+ renderingService.hooks.pick.tapPromise(CanvasPickerPlugin.tag, /*#__PURE__*/function () {
1970
+ var _ref = _asyncToGenerator$1( /*#__PURE__*/_regeneratorRuntime$1().mark(function _callee(result) {
1971
+ return _regeneratorRuntime$1().wrap(function _callee$(_context) {
1972
+ while (1) {
1973
+ switch (_context.prev = _context.next) {
1974
+ case 0:
1975
+ return _context.abrupt("return", _this2.pick(document, result));
1976
+ case 1:
1977
+ case "end":
1978
+ return _context.stop();
2428
1979
  }
2429
- }, _callee);
2430
- }));
2431
- return function (_x) {
2432
- return _ref.apply(this, arguments);
2433
- };
2434
- }());
2435
- renderingService.hooks.pickSync.tap(CanvasPickerPlugin.tag, function (result) {
2436
- return _this2.pick(document, result);
2437
- });
2438
- }
2439
- }, {
2440
- key: "pick",
2441
- value: function pick(document, result) {
2442
- var topmost = result.topmost,
2443
- _result$position = result.position,
2444
- x = _result$position.x,
2445
- y = _result$position.y;
2446
- // position in world space
2447
- var position = set(tmpVec3a, x, y, 0);
2448
- // query by AABB first with spatial index(r-tree)
2449
- var hitTestList = document.elementsFromBBox(position[0], position[1], position[0], position[1]);
2450
- // test with clip path & origin shape
2451
- // @see https://github.com/antvis/g/issues/1064
2452
- var pickedDisplayObjects = [];
2453
- var _iterator = _createForOfIteratorHelper(hitTestList),
2454
- _step;
2455
- try {
2456
- for (_iterator.s(); !(_step = _iterator.n()).done;) {
2457
- var displayObject = _step.value;
2458
- var worldTransform = displayObject.getWorldTransform();
2459
- var isHitOriginShape = this.isHit(displayObject, position, worldTransform, false);
2460
- if (isHitOriginShape) {
2461
- // should look up in the ancestor node
2462
- var clipped = gLite.findClosestClipPathTarget(displayObject);
2463
- if (clipped) {
2464
- var clipPath = clipped.parsedStyle.clipPath;
2465
- var isHitClipPath = this.isHit(clipPath, position, clipPath.getWorldTransform(), true);
2466
- if (isHitClipPath) {
2467
- if (topmost) {
2468
- result.picked = [displayObject];
2469
- return result;
2470
- } else {
2471
- pickedDisplayObjects.push(displayObject);
2472
- }
2473
- }
1980
+ }
1981
+ }, _callee);
1982
+ }));
1983
+ return function (_x) {
1984
+ return _ref.apply(this, arguments);
1985
+ };
1986
+ }());
1987
+ renderingService.hooks.pickSync.tap(CanvasPickerPlugin.tag, function (result) {
1988
+ return _this2.pick(document, result);
1989
+ });
1990
+ };
1991
+ _proto.pick = function pick(document, result) {
1992
+ var topmost = result.topmost,
1993
+ _result$position = result.position,
1994
+ x = _result$position.x,
1995
+ y = _result$position.y;
1996
+ // position in world space
1997
+ var position = set(tmpVec3a, x, y, 0);
1998
+ // query by AABB first with spatial index(r-tree)
1999
+ var hitTestList = document.elementsFromBBox(position[0], position[1], position[0], position[1]);
2000
+ // test with clip path & origin shape
2001
+ // @see https://github.com/antvis/g/issues/1064
2002
+ var pickedDisplayObjects = [];
2003
+ for (var _iterator = _createForOfIteratorHelperLoose(hitTestList), _step; !(_step = _iterator()).done;) {
2004
+ var displayObject = _step.value;
2005
+ var worldTransform = displayObject.getWorldTransform();
2006
+ var isHitOriginShape = this.isHit(displayObject, position, worldTransform, false);
2007
+ if (isHitOriginShape) {
2008
+ // should look up in the ancestor node
2009
+ var clipped = gLite.findClosestClipPathTarget(displayObject);
2010
+ if (clipped) {
2011
+ var clipPath = clipped.parsedStyle.clipPath;
2012
+ var isHitClipPath = this.isHit(clipPath, position, clipPath.getWorldTransform(), true);
2013
+ if (isHitClipPath) {
2014
+ if (topmost) {
2015
+ result.picked = [displayObject];
2016
+ return result;
2474
2017
  } else {
2475
- if (topmost) {
2476
- result.picked = [displayObject];
2477
- return result;
2478
- } else {
2479
- pickedDisplayObjects.push(displayObject);
2480
- }
2018
+ pickedDisplayObjects.push(displayObject);
2481
2019
  }
2482
2020
  }
2021
+ } else {
2022
+ if (topmost) {
2023
+ result.picked = [displayObject];
2024
+ return result;
2025
+ } else {
2026
+ pickedDisplayObjects.push(displayObject);
2027
+ }
2483
2028
  }
2484
- } catch (err) {
2485
- _iterator.e(err);
2486
- } finally {
2487
- _iterator.f();
2488
2029
  }
2489
- result.picked = pickedDisplayObjects;
2490
- return result;
2491
2030
  }
2492
- }]);
2031
+ result.picked = pickedDisplayObjects;
2032
+ return result;
2033
+ };
2493
2034
  return CanvasPickerPlugin;
2494
2035
  }();
2495
2036
  CanvasPickerPlugin.tag = 'CanvasPicker';
2496
- function _toConsumableArray(arr) {
2497
- return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray$1$1(arr) || _nonIterableSpread();
2498
- }
2499
- function _arrayWithoutHoles(arr) {
2500
- if (Array.isArray(arr)) return _arrayLikeToArray$1$1(arr);
2501
- }
2502
- function _iterableToArray(iter) {
2503
- if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
2504
- }
2505
- function _unsupportedIterableToArray$1$1(o, minLen) {
2506
- if (!o) return;
2507
- if (typeof o === "string") return _arrayLikeToArray$1$1(o, minLen);
2508
- var n = Object.prototype.toString.call(o).slice(8, -1);
2509
- if (n === "Object" && o.constructor) n = o.constructor.name;
2510
- if (n === "Map" || n === "Set") return Array.from(o);
2511
- if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray$1$1(o, minLen);
2512
- }
2513
- function _arrayLikeToArray$1$1(arr, len) {
2514
- if (len == null || len > arr.length) len = arr.length;
2515
- for (var i = 0, arr2 = new Array(len); i < len; i++) {
2516
- arr2[i] = arr[i];
2517
- }
2518
- return arr2;
2519
- }
2520
- function _nonIterableSpread() {
2521
- throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
2522
- }
2523
2037
 
2524
2038
  /**
2525
2039
  * 两点之间的距离
@@ -2538,10 +2052,10 @@
2538
2052
  return Math.abs(v1 - v2) < 0.001;
2539
2053
  }
2540
2054
  function getBBoxByArray(xArr, yArr) {
2541
- var minX = Math.min.apply(Math, _toConsumableArray(xArr));
2542
- var minY = Math.min.apply(Math, _toConsumableArray(yArr));
2543
- var maxX = Math.max.apply(Math, _toConsumableArray(xArr));
2544
- var maxY = Math.max.apply(Math, _toConsumableArray(yArr));
2055
+ var minX = Math.min.apply(Math, xArr);
2056
+ var minY = Math.min.apply(Math, yArr);
2057
+ var maxX = Math.max.apply(Math, xArr);
2058
+ var maxY = Math.max.apply(Math, yArr);
2545
2059
  return {
2546
2060
  x: minX,
2547
2061
  y: minY,
@@ -2667,7 +2181,7 @@
2667
2181
  var interval = increaseRate / 10;
2668
2182
  for (var i = 0; i <= segNum; i++) {
2669
2183
  var _t = i * increaseRate;
2670
- var v1 = [tCallback.apply(void 0, _toConsumableArray(xArr.concat([_t]))), tCallback.apply(void 0, _toConsumableArray(yArr.concat([_t])))];
2184
+ var v1 = [tCallback.apply(void 0, xArr.concat([_t])), tCallback.apply(void 0, yArr.concat([_t]))];
2671
2185
  var d1 = distance(v0[0], v0[1], v1[0], v1[1]);
2672
2186
  if (d1 < d) {
2673
2187
  t = _t;
@@ -2695,13 +2209,13 @@
2695
2209
  }
2696
2210
  var prev = t - interval;
2697
2211
  var next = t + interval;
2698
- var _v = [tCallback.apply(void 0, _toConsumableArray(xArr.concat([prev]))), tCallback.apply(void 0, _toConsumableArray(yArr.concat([prev])))];
2212
+ var _v = [tCallback.apply(void 0, xArr.concat([prev])), tCallback.apply(void 0, yArr.concat([prev]))];
2699
2213
  var _d = distance(v0[0], v0[1], _v[0], _v[1]);
2700
2214
  if (prev >= 0 && _d < d) {
2701
2215
  t = prev;
2702
2216
  d = _d;
2703
2217
  } else {
2704
- var v2 = [tCallback.apply(void 0, _toConsumableArray(xArr.concat([next]))), tCallback.apply(void 0, _toConsumableArray(yArr.concat([next])))];
2218
+ var v2 = [tCallback.apply(void 0, xArr.concat([next])), tCallback.apply(void 0, yArr.concat([next]))];
2705
2219
  var d2 = distance(v0[0], v0[1], v2[0], v2[1]);
2706
2220
  if (next <= 1 && d2 < d) {
2707
2221
  t = next;
@@ -2712,8 +2226,8 @@
2712
2226
  }
2713
2227
  }
2714
2228
  return {
2715
- x: tCallback.apply(void 0, _toConsumableArray(xArr.concat([t]))),
2716
- y: tCallback.apply(void 0, _toConsumableArray(yArr.concat([t])))
2229
+ x: tCallback.apply(void 0, xArr.concat([t])),
2230
+ y: tCallback.apply(void 0, yArr.concat([t]))
2717
2231
  };
2718
2232
  }
2719
2233
  // 近似求解 https://community.khronos.org/t/3d-cubic-bezier-segment-length/62363/2
@@ -2771,7 +2285,7 @@
2771
2285
  var right = quadratics[1];
2772
2286
  left.push(iterationCount - 1);
2773
2287
  right.push(iterationCount - 1);
2774
- return quadraticLength.apply(void 0, _toConsumableArray(left)) + quadraticLength.apply(void 0, _toConsumableArray(right));
2288
+ return quadraticLength.apply(void 0, left) + quadraticLength.apply(void 0, right);
2775
2289
  }
2776
2290
  var quadratic = {
2777
2291
  box: function box(x1, y1, x2, y2, x3, y3) {
@@ -2875,9 +2389,9 @@
2875
2389
  return snapLength([x1, x2, x3, x4], [y1, y2, y3, y4]);
2876
2390
  }
2877
2391
  var cubics = divideCubic(x1, y1, x2, y2, x3, y3, x4, y4, 0.5);
2878
- var left = [].concat(_toConsumableArray(cubics[0]), [iterationCount - 1]);
2879
- var right = [].concat(_toConsumableArray(cubics[1]), [iterationCount - 1]);
2880
- return cubicLength.apply(void 0, _toConsumableArray(left)) + cubicLength.apply(void 0, _toConsumableArray(right));
2392
+ var left = [].concat(cubics[0], [iterationCount - 1]);
2393
+ var right = [].concat(cubics[1], [iterationCount - 1]);
2394
+ return cubicLength.apply(void 0, left) + cubicLength.apply(void 0, right);
2881
2395
  }
2882
2396
  var cubic = {
2883
2397
  extrema: extrema$1,
@@ -3051,9 +2565,8 @@
3051
2565
  var halfLineWidth = ((lineWidth || 0) + (increasedLineWidthForHitTesting || 0)) / 2;
3052
2566
  var absDistance = distance$1(r, r, position.x, position.y);
3053
2567
  var _isFillOrStrokeAffect = gLite.isFillOrStrokeAffected(pointerEvents, fill, stroke),
3054
- _isFillOrStrokeAffect2 = _slicedToArray$1(_isFillOrStrokeAffect, 2),
3055
- hasFill = _isFillOrStrokeAffect2[0],
3056
- hasStroke = _isFillOrStrokeAffect2[1];
2568
+ hasFill = _isFillOrStrokeAffect[0],
2569
+ hasStroke = _isFillOrStrokeAffect[1];
3057
2570
  if (hasFill && hasStroke || isClipPath) {
3058
2571
  return absDistance <= r + halfLineWidth;
3059
2572
  }
@@ -3080,9 +2593,8 @@
3080
2593
  var x = position.x,
3081
2594
  y = position.y;
3082
2595
  var _isFillOrStrokeAffect = gLite.isFillOrStrokeAffected(pointerEvents, fill, stroke),
3083
- _isFillOrStrokeAffect2 = _slicedToArray$1(_isFillOrStrokeAffect, 2),
3084
- hasFill = _isFillOrStrokeAffect2[0],
3085
- hasStroke = _isFillOrStrokeAffect2[1];
2596
+ hasFill = _isFillOrStrokeAffect[0],
2597
+ hasStroke = _isFillOrStrokeAffect[1];
3086
2598
  var halfLineWith = ((lineWidth || 0) + (increasedLineWidthForHitTesting || 0)) / 2;
3087
2599
  var squareX = (x - rx) * (x - rx);
3088
2600
  var squareY = (y - ry) * (y - ry);
@@ -3113,11 +2625,9 @@
3113
2625
  pointerEvents = _displayObject$parsed.pointerEvents,
3114
2626
  fill = _displayObject$parsed.fill,
3115
2627
  stroke = _displayObject$parsed.stroke;
3116
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
3117
2628
  var _isFillOrStrokeAffect = gLite.isFillOrStrokeAffected(pointerEvents, fill, stroke),
3118
- _isFillOrStrokeAffect2 = _slicedToArray$1(_isFillOrStrokeAffect, 2),
3119
- _ = _isFillOrStrokeAffect2[0],
3120
- hasStroke = _isFillOrStrokeAffect2[1];
2629
+ _ = _isFillOrStrokeAffect[0],
2630
+ hasStroke = _isFillOrStrokeAffect[1];
3121
2631
  if (!hasStroke && !isClipPath || !lineWidth) {
3122
2632
  return false;
3123
2633
  }
@@ -3201,9 +2711,8 @@
3201
2711
  path = _displayObject$parsed.path,
3202
2712
  pointerEvents = _displayObject$parsed.pointerEvents;
3203
2713
  var _isFillOrStrokeAffect = gLite.isFillOrStrokeAffected(pointerEvents, fill, stroke),
3204
- _isFillOrStrokeAffect2 = _slicedToArray$1(_isFillOrStrokeAffect, 2),
3205
- hasFill = _isFillOrStrokeAffect2[0],
3206
- hasStroke = _isFillOrStrokeAffect2[1];
2714
+ hasFill = _isFillOrStrokeAffect[0],
2715
+ hasStroke = _isFillOrStrokeAffect[1];
3207
2716
  var segments = path.segments,
3208
2717
  hasArc = path.hasArc,
3209
2718
  polylines = path.polylines,
@@ -3237,9 +2746,8 @@
3237
2746
  y = _displayObject$parsed3 === void 0 ? 0 : _displayObject$parsed3,
3238
2747
  pointerEvents = _displayObject$parsed.pointerEvents;
3239
2748
  var _isFillOrStrokeAffect = gLite.isFillOrStrokeAffected(pointerEvents, fill, stroke),
3240
- _isFillOrStrokeAffect2 = _slicedToArray$1(_isFillOrStrokeAffect, 2),
3241
- hasFill = _isFillOrStrokeAffect2[0],
3242
- hasStroke = _isFillOrStrokeAffect2[1];
2749
+ hasFill = _isFillOrStrokeAffect[0],
2750
+ hasStroke = _isFillOrStrokeAffect[1];
3243
2751
  var isHit = false;
3244
2752
  if (hasStroke || isClipPath) {
3245
2753
  isHit = inPolyline(points.points, (lineWidth || 0) + (increasedLineWidthForHitTesting || 0), position.x + x, position.y + y, true);
@@ -3262,8 +2770,7 @@
3262
2770
  fill = _displayObject$parsed.fill,
3263
2771
  stroke = _displayObject$parsed.stroke;
3264
2772
  var _isFillOrStrokeAffect = gLite.isFillOrStrokeAffected(pointerEvents, fill, stroke),
3265
- _isFillOrStrokeAffect2 = _slicedToArray$1(_isFillOrStrokeAffect, 2),
3266
- hasStroke = _isFillOrStrokeAffect2[1];
2773
+ hasStroke = _isFillOrStrokeAffect[1];
3267
2774
  if (!hasStroke && !isClipPath || !lineWidth) {
3268
2775
  return false;
3269
2776
  }
@@ -3280,9 +2787,8 @@
3280
2787
  height = _displayObject$parsed.height,
3281
2788
  pointerEvents = _displayObject$parsed.pointerEvents;
3282
2789
  var _isFillOrStrokeAffect = gLite.isFillOrStrokeAffected(pointerEvents, fill, stroke),
3283
- _isFillOrStrokeAffect2 = _slicedToArray$1(_isFillOrStrokeAffect, 2),
3284
- hasFill = _isFillOrStrokeAffect2[0],
3285
- hasStroke = _isFillOrStrokeAffect2[1];
2790
+ hasFill = _isFillOrStrokeAffect[0],
2791
+ hasStroke = _isFillOrStrokeAffect[1];
3286
2792
  var hasRadius = radius && radius.some(function (r) {
3287
2793
  return r !== 0;
3288
2794
  });
@@ -3318,46 +2824,39 @@
3318
2824
  return false;
3319
2825
  }
3320
2826
  function inRectWithRadius(minX, minY, width, height, radiusArray, lineWidth, x, y) {
3321
- var _radiusArray = _slicedToArray$1(radiusArray, 4),
3322
- tlr = _radiusArray[0],
3323
- trr = _radiusArray[1],
3324
- brr = _radiusArray[2],
3325
- blr = _radiusArray[3];
2827
+ var tlr = radiusArray[0],
2828
+ trr = radiusArray[1],
2829
+ brr = radiusArray[2],
2830
+ blr = radiusArray[3];
3326
2831
  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);
3327
2832
  }
3328
2833
  var Plugin$1 = /*#__PURE__*/function (_AbstractRendererPlug) {
3329
- _inherits$2(Plugin, _AbstractRendererPlug);
3330
- var _super = _createSuper$2(Plugin);
2834
+ _inheritsLoose$2(Plugin, _AbstractRendererPlug);
3331
2835
  function Plugin() {
3332
2836
  var _this;
3333
- _classCallCheck$2(this, Plugin);
3334
2837
  for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
3335
2838
  args[_key] = arguments[_key];
3336
2839
  }
3337
- _this = _super.call.apply(_super, [this].concat(args));
2840
+ _this = _AbstractRendererPlug.call.apply(_AbstractRendererPlug, [this].concat(args)) || this;
3338
2841
  _this.name = 'canvas-picker';
3339
2842
  return _this;
3340
2843
  }
3341
- _createClass$2(Plugin, [{
3342
- key: "init",
3343
- value: function init() {
3344
- var _pointInPathPickerFac;
3345
- var trueFunc = function trueFunc() {
3346
- return true;
3347
- };
3348
- var pointInPathPickerFactory = (_pointInPathPickerFac = {}, _defineProperty$1(_pointInPathPickerFac, gLite.Shape.CIRCLE, isPointInPath), _defineProperty$1(_pointInPathPickerFac, gLite.Shape.ELLIPSE, isPointInPath$1), _defineProperty$1(_pointInPathPickerFac, gLite.Shape.RECT, isPointInPath$6), _defineProperty$1(_pointInPathPickerFac, gLite.Shape.LINE, isPointInPath$2), _defineProperty$1(_pointInPathPickerFac, gLite.Shape.POLYLINE, isPointInPath$5), _defineProperty$1(_pointInPathPickerFac, gLite.Shape.POLYGON, isPointInPath$4), _defineProperty$1(_pointInPathPickerFac, gLite.Shape.PATH, isPointInPath$3), _defineProperty$1(_pointInPathPickerFac, gLite.Shape.TEXT, trueFunc), _defineProperty$1(_pointInPathPickerFac, gLite.Shape.GROUP, null), _defineProperty$1(_pointInPathPickerFac, gLite.Shape.IMAGE, trueFunc), _defineProperty$1(_pointInPathPickerFac, gLite.Shape.HTML, null), _defineProperty$1(_pointInPathPickerFac, gLite.Shape.MESH, null), _pointInPathPickerFac);
3349
- // @ts-ignore
3350
- this.context.pointInPathPickerFactory = pointInPathPickerFactory;
3351
- this.addRenderingPlugin(new CanvasPickerPlugin());
3352
- }
3353
- }, {
3354
- key: "destroy",
3355
- value: function destroy() {
3356
- // @ts-ignore
3357
- delete this.context.pointInPathPickerFactory;
3358
- this.removeAllRenderingPlugins();
3359
- }
3360
- }]);
2844
+ var _proto = Plugin.prototype;
2845
+ _proto.init = function init() {
2846
+ var _pointInPathPickerFac;
2847
+ var trueFunc = function trueFunc() {
2848
+ return true;
2849
+ };
2850
+ 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);
2851
+ // @ts-ignore
2852
+ this.context.pointInPathPickerFactory = pointInPathPickerFactory;
2853
+ this.addRenderingPlugin(new CanvasPickerPlugin());
2854
+ };
2855
+ _proto.destroy = function destroy() {
2856
+ // @ts-ignore
2857
+ delete this.context.pointInPathPickerFactory;
2858
+ this.removeAllRenderingPlugins();
2859
+ };
3361
2860
  return Plugin;
3362
2861
  }(gLite.AbstractRendererPlugin);
3363
2862
 
@@ -3366,56 +2865,6 @@
3366
2865
  Plugin: Plugin$1
3367
2866
  });
3368
2867
 
3369
- function _iterableToArrayLimit$2(arr, i) {
3370
- var _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"];
3371
- if (null != _i) {
3372
- var _s,
3373
- _e,
3374
- _x,
3375
- _r,
3376
- _arr = [],
3377
- _n = !0,
3378
- _d = !1;
3379
- try {
3380
- if (_x = (_i = _i.call(arr)).next, 0 === i) {
3381
- if (Object(_i) !== _i) return;
3382
- _n = !1;
3383
- } else for (; !(_n = (_s = _x.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = !0) {
3384
- ;
3385
- }
3386
- } catch (err) {
3387
- _d = !0, _e = err;
3388
- } finally {
3389
- try {
3390
- if (!_n && null != _i.return && (_r = _i.return(), Object(_r) !== _r)) return;
3391
- } finally {
3392
- if (_d) throw _e;
3393
- }
3394
- }
3395
- return _arr;
3396
- }
3397
- }
3398
- function ownKeys(object, enumerableOnly) {
3399
- var keys = Object.keys(object);
3400
- if (Object.getOwnPropertySymbols) {
3401
- var symbols = Object.getOwnPropertySymbols(object);
3402
- enumerableOnly && (symbols = symbols.filter(function (sym) {
3403
- return Object.getOwnPropertyDescriptor(object, sym).enumerable;
3404
- })), keys.push.apply(keys, symbols);
3405
- }
3406
- return keys;
3407
- }
3408
- function _objectSpread2(target) {
3409
- for (var i = 1; i < arguments.length; i++) {
3410
- var source = null != arguments[i] ? arguments[i] : {};
3411
- i % 2 ? ownKeys(Object(source), !0).forEach(function (key) {
3412
- _defineProperty$2(target, key, source[key]);
3413
- }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) {
3414
- Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
3415
- });
3416
- }
3417
- return target;
3418
- }
3419
2868
  function _regeneratorRuntime$2() {
3420
2869
  _regeneratorRuntime$2 = function _regeneratorRuntime() {
3421
2870
  return exports;
@@ -3492,7 +2941,7 @@
3492
2941
  if ("throw" !== record.type) {
3493
2942
  var result = record.arg,
3494
2943
  value = result.value;
3495
- return value && "object" == _typeof(value) && hasOwn.call(value, "__await") ? PromiseImpl.resolve(value.__await).then(function (value) {
2944
+ return value && "object" == typeof value && hasOwn.call(value, "__await") ? PromiseImpl.resolve(value.__await).then(function (value) {
3496
2945
  invoke("next", value, resolve, reject);
3497
2946
  }, function (err) {
3498
2947
  invoke("throw", err, resolve, reject);
@@ -3753,63 +3202,24 @@
3753
3202
  });
3754
3203
  };
3755
3204
  }
3756
- function _classCallCheck$3(instance, Constructor) {
3757
- if (!(instance instanceof Constructor)) {
3758
- throw new TypeError("Cannot call a class as a function");
3759
- }
3760
- }
3761
- function _defineProperties$3(target, props) {
3762
- for (var i = 0; i < props.length; i++) {
3763
- var descriptor = props[i];
3764
- descriptor.enumerable = descriptor.enumerable || false;
3765
- descriptor.configurable = true;
3766
- if ("value" in descriptor) descriptor.writable = true;
3767
- Object.defineProperty(target, _toPropertyKey$3(descriptor.key), descriptor);
3768
- }
3769
- }
3770
- function _createClass$3(Constructor, protoProps, staticProps) {
3771
- if (protoProps) _defineProperties$3(Constructor.prototype, protoProps);
3772
- if (staticProps) _defineProperties$3(Constructor, staticProps);
3773
- Object.defineProperty(Constructor, "prototype", {
3774
- writable: false
3775
- });
3776
- return Constructor;
3777
- }
3778
- function _defineProperty$2(obj, key, value) {
3779
- key = _toPropertyKey$3(key);
3780
- if (key in obj) {
3781
- Object.defineProperty(obj, key, {
3782
- value: value,
3783
- enumerable: true,
3784
- configurable: true,
3785
- writable: true
3786
- });
3787
- } else {
3788
- obj[key] = value;
3789
- }
3790
- return obj;
3791
- }
3792
- function _inherits$3(subClass, superClass) {
3793
- if (typeof superClass !== "function" && superClass !== null) {
3794
- throw new TypeError("Super expression must either be null or a function");
3795
- }
3796
- subClass.prototype = Object.create(superClass && superClass.prototype, {
3797
- constructor: {
3798
- value: subClass,
3799
- writable: true,
3800
- configurable: true
3205
+ function _extends() {
3206
+ _extends = Object.assign ? Object.assign.bind() : function (target) {
3207
+ for (var i = 1; i < arguments.length; i++) {
3208
+ var source = arguments[i];
3209
+ for (var key in source) {
3210
+ if (Object.prototype.hasOwnProperty.call(source, key)) {
3211
+ target[key] = source[key];
3212
+ }
3213
+ }
3801
3214
  }
3802
- });
3803
- Object.defineProperty(subClass, "prototype", {
3804
- writable: false
3805
- });
3806
- if (superClass) _setPrototypeOf$3(subClass, superClass);
3807
- }
3808
- function _getPrototypeOf$3(o) {
3809
- _getPrototypeOf$3 = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) {
3810
- return o.__proto__ || Object.getPrototypeOf(o);
3215
+ return target;
3811
3216
  };
3812
- return _getPrototypeOf$3(o);
3217
+ return _extends.apply(this, arguments);
3218
+ }
3219
+ function _inheritsLoose$3(subClass, superClass) {
3220
+ subClass.prototype = Object.create(superClass.prototype);
3221
+ subClass.prototype.constructor = subClass;
3222
+ _setPrototypeOf$3(subClass, superClass);
3813
3223
  }
3814
3224
  function _setPrototypeOf$3(o, p) {
3815
3225
  _setPrototypeOf$3 = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) {
@@ -3818,95 +3228,6 @@
3818
3228
  };
3819
3229
  return _setPrototypeOf$3(o, p);
3820
3230
  }
3821
- function _isNativeReflectConstruct$3() {
3822
- if (typeof Reflect === "undefined" || !Reflect.construct) return false;
3823
- if (Reflect.construct.sham) return false;
3824
- if (typeof Proxy === "function") return true;
3825
- try {
3826
- Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {}));
3827
- return true;
3828
- } catch (e) {
3829
- return false;
3830
- }
3831
- }
3832
- function _assertThisInitialized$3(self) {
3833
- if (self === void 0) {
3834
- throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
3835
- }
3836
- return self;
3837
- }
3838
- function _possibleConstructorReturn$3(self, call) {
3839
- if (call && (_typeof(call) === "object" || typeof call === "function")) {
3840
- return call;
3841
- } else if (call !== void 0) {
3842
- throw new TypeError("Derived constructors may only return object or undefined");
3843
- }
3844
- return _assertThisInitialized$3(self);
3845
- }
3846
- function _createSuper$3(Derived) {
3847
- var hasNativeReflectConstruct = _isNativeReflectConstruct$3();
3848
- return function _createSuperInternal() {
3849
- var Super = _getPrototypeOf$3(Derived),
3850
- result;
3851
- if (hasNativeReflectConstruct) {
3852
- var NewTarget = _getPrototypeOf$3(this).constructor;
3853
- result = Reflect.construct(Super, arguments, NewTarget);
3854
- } else {
3855
- result = Super.apply(this, arguments);
3856
- }
3857
- return _possibleConstructorReturn$3(this, result);
3858
- };
3859
- }
3860
- function _slicedToArray$2(arr, i) {
3861
- return _arrayWithHoles$2(arr) || _iterableToArrayLimit$2(arr, i) || _unsupportedIterableToArray$2(arr, i) || _nonIterableRest$2();
3862
- }
3863
- function _toConsumableArray$1(arr) {
3864
- return _arrayWithoutHoles$1(arr) || _iterableToArray$1(arr) || _unsupportedIterableToArray$2(arr) || _nonIterableSpread$1();
3865
- }
3866
- function _arrayWithoutHoles$1(arr) {
3867
- if (Array.isArray(arr)) return _arrayLikeToArray$2(arr);
3868
- }
3869
- function _arrayWithHoles$2(arr) {
3870
- if (Array.isArray(arr)) return arr;
3871
- }
3872
- function _iterableToArray$1(iter) {
3873
- if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
3874
- }
3875
- function _unsupportedIterableToArray$2(o, minLen) {
3876
- if (!o) return;
3877
- if (typeof o === "string") return _arrayLikeToArray$2(o, minLen);
3878
- var n = Object.prototype.toString.call(o).slice(8, -1);
3879
- if (n === "Object" && o.constructor) n = o.constructor.name;
3880
- if (n === "Map" || n === "Set") return Array.from(o);
3881
- if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray$2(o, minLen);
3882
- }
3883
- function _arrayLikeToArray$2(arr, len) {
3884
- if (len == null || len > arr.length) len = arr.length;
3885
- for (var i = 0, arr2 = new Array(len); i < len; i++) {
3886
- arr2[i] = arr[i];
3887
- }
3888
- return arr2;
3889
- }
3890
- function _nonIterableSpread$1() {
3891
- throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
3892
- }
3893
- function _nonIterableRest$2() {
3894
- throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
3895
- }
3896
- function _toPrimitive$3(input, hint) {
3897
- if (_typeof(input) !== "object" || input === null) return input;
3898
- var prim = input[Symbol.toPrimitive];
3899
- if (prim !== undefined) {
3900
- var res = prim.call(input, hint || "default");
3901
- if (_typeof(res) !== "object") return res;
3902
- throw new TypeError("@@toPrimitive must return a primitive value.");
3903
- }
3904
- return (hint === "string" ? String : Number)(input);
3905
- }
3906
- function _toPropertyKey$3(arg) {
3907
- var key = _toPrimitive$3(arg, "string");
3908
- return _typeof(key) === "symbol" ? key : String(key);
3909
- }
3910
3231
 
3911
3232
  /**
3912
3233
  * support 2 modes in rendering:
@@ -3919,7 +3240,6 @@
3919
3240
  */
3920
3241
 
3921
3242
  function CanvasRendererPlugin(canvasRendererPluginOptions) {
3922
- _classCallCheck$3(this, CanvasRendererPlugin);
3923
3243
  this.canvasRendererPluginOptions = void 0;
3924
3244
  this.context = void 0;
3925
3245
  this.pathGeneratorFactory = void 0;
@@ -3937,579 +3257,544 @@
3937
3257
  this.vec3d = create$1();
3938
3258
  this.canvasRendererPluginOptions = canvasRendererPluginOptions;
3939
3259
  }
3940
- _createClass$3(CanvasRendererPlugin, [{
3941
- key: "apply",
3942
- value: function apply(context) {
3943
- var _this = this;
3944
- this.context = context;
3945
- var config = context.config,
3946
- camera = context.camera,
3947
- renderingService = context.renderingService,
3948
- renderingContext = context.renderingContext,
3949
- rBushRoot = context.rBushRoot,
3950
- pathGeneratorFactory = context.pathGeneratorFactory;
3951
- this.rBush = rBushRoot;
3952
- this.pathGeneratorFactory = pathGeneratorFactory;
3953
- var contextService = context.contextService;
3954
- var canvas = renderingContext.root.ownerDocument.defaultView;
3955
- var handleUnmounted = function handleUnmounted(e) {
3956
- var object = e.target;
3957
- // remove r-bush node
3958
- // @ts-ignore
3959
- var rBushNode = object.rBushNode;
3960
- if (rBushNode.aabb) {
3961
- // save removed aabbs for dirty-rectangle rendering later
3962
- _this.removedRBushNodeAABBs.push(rBushNode.aabb);
3963
- }
3964
- };
3965
- var handleCulled = function handleCulled(e) {
3966
- var object = e.target;
3967
- // @ts-ignore
3968
- var rBushNode = object.rBushNode;
3969
- if (rBushNode.aabb) {
3970
- // save removed aabbs for dirty-rectangle rendering later
3971
- _this.removedRBushNodeAABBs.push(rBushNode.aabb);
3972
- }
3973
- };
3974
- renderingService.hooks.init.tapPromise(CanvasRendererPlugin.tag, /*#__PURE__*/_asyncToGenerator$2( /*#__PURE__*/_regeneratorRuntime$2().mark(function _callee() {
3975
- var dpr, width, height, context;
3976
- return _regeneratorRuntime$2().wrap(function _callee$(_context) {
3977
- while (1) {
3978
- switch (_context.prev = _context.next) {
3979
- case 0:
3980
- canvas.addEventListener(gLite.ElementEvent.UNMOUNTED, handleUnmounted);
3981
- canvas.addEventListener(gLite.ElementEvent.CULLED, handleCulled);
3982
- // clear fullscreen
3983
- dpr = contextService.getDPR();
3984
- width = config.width, height = config.height;
3985
- context = contextService.getContext();
3986
- _this.clearRect(context, 0, 0, width * dpr, height * dpr, config.background);
3987
- case 6:
3988
- case "end":
3989
- return _context.stop();
3990
- }
3991
- }
3992
- }, _callee);
3993
- })));
3994
- renderingService.hooks.destroy.tap(CanvasRendererPlugin.tag, function () {
3995
- canvas.removeEventListener(gLite.ElementEvent.UNMOUNTED, handleUnmounted);
3996
- canvas.removeEventListener(gLite.ElementEvent.CULLED, handleCulled);
3997
- });
3998
- renderingService.hooks.beginFrame.tap(CanvasRendererPlugin.tag, function () {
3999
- var context = contextService.getContext();
4000
- var dpr = contextService.getDPR();
4001
- var width = config.width,
4002
- height = config.height;
4003
- var _this$canvasRendererP = _this.canvasRendererPluginOptions,
4004
- dirtyObjectNumThreshold = _this$canvasRendererP.dirtyObjectNumThreshold,
4005
- dirtyObjectRatioThreshold = _this$canvasRendererP.dirtyObjectRatioThreshold;
4006
- // some heuristic conditions such as 80% object changed
4007
- var _renderingService$get = renderingService.getStats(),
4008
- total = _renderingService$get.total,
4009
- rendered = _renderingService$get.rendered;
4010
- var ratio = rendered / total;
4011
- _this.clearFullScreen = renderingService.disableDirtyRectangleRendering() || rendered > dirtyObjectNumThreshold && ratio > dirtyObjectRatioThreshold;
4012
- if (context) {
4013
- context.resetTransform();
4014
- if (_this.clearFullScreen) {
4015
- _this.clearRect(context, 0, 0, width * dpr, height * dpr, config.background);
3260
+ var _proto = CanvasRendererPlugin.prototype;
3261
+ _proto.apply = function apply(context) {
3262
+ var _this = this;
3263
+ this.context = context;
3264
+ var config = context.config,
3265
+ camera = context.camera,
3266
+ renderingService = context.renderingService,
3267
+ renderingContext = context.renderingContext,
3268
+ rBushRoot = context.rBushRoot,
3269
+ pathGeneratorFactory = context.pathGeneratorFactory;
3270
+ this.rBush = rBushRoot;
3271
+ this.pathGeneratorFactory = pathGeneratorFactory;
3272
+ var contextService = context.contextService;
3273
+ var canvas = renderingContext.root.ownerDocument.defaultView;
3274
+ var handleUnmounted = function handleUnmounted(e) {
3275
+ var object = e.target;
3276
+ // remove r-bush node
3277
+ // @ts-ignore
3278
+ var rBushNode = object.rBushNode;
3279
+ if (rBushNode.aabb) {
3280
+ // save removed aabbs for dirty-rectangle rendering later
3281
+ _this.removedRBushNodeAABBs.push(rBushNode.aabb);
3282
+ }
3283
+ };
3284
+ var handleCulled = function handleCulled(e) {
3285
+ var object = e.target;
3286
+ // @ts-ignore
3287
+ var rBushNode = object.rBushNode;
3288
+ if (rBushNode.aabb) {
3289
+ // save removed aabbs for dirty-rectangle rendering later
3290
+ _this.removedRBushNodeAABBs.push(rBushNode.aabb);
3291
+ }
3292
+ };
3293
+ renderingService.hooks.init.tapPromise(CanvasRendererPlugin.tag, /*#__PURE__*/_asyncToGenerator$2( /*#__PURE__*/_regeneratorRuntime$2().mark(function _callee() {
3294
+ var dpr, width, height, context;
3295
+ return _regeneratorRuntime$2().wrap(function _callee$(_context) {
3296
+ while (1) {
3297
+ switch (_context.prev = _context.next) {
3298
+ case 0:
3299
+ canvas.addEventListener(gLite.ElementEvent.UNMOUNTED, handleUnmounted);
3300
+ canvas.addEventListener(gLite.ElementEvent.CULLED, handleCulled);
3301
+ // clear fullscreen
3302
+ dpr = contextService.getDPR();
3303
+ width = config.width, height = config.height;
3304
+ context = contextService.getContext();
3305
+ _this.clearRect(context, 0, 0, width * dpr, height * dpr, config.background);
3306
+ case 6:
3307
+ case "end":
3308
+ return _context.stop();
4016
3309
  }
4017
3310
  }
3311
+ }, _callee);
3312
+ })));
3313
+ renderingService.hooks.destroy.tap(CanvasRendererPlugin.tag, function () {
3314
+ canvas.removeEventListener(gLite.ElementEvent.UNMOUNTED, handleUnmounted);
3315
+ canvas.removeEventListener(gLite.ElementEvent.CULLED, handleCulled);
3316
+ });
3317
+ renderingService.hooks.beginFrame.tap(CanvasRendererPlugin.tag, function () {
3318
+ var context = contextService.getContext();
3319
+ var dpr = contextService.getDPR();
3320
+ var width = config.width,
3321
+ height = config.height;
3322
+ var _this$canvasRendererP = _this.canvasRendererPluginOptions,
3323
+ dirtyObjectNumThreshold = _this$canvasRendererP.dirtyObjectNumThreshold,
3324
+ dirtyObjectRatioThreshold = _this$canvasRendererP.dirtyObjectRatioThreshold;
3325
+ // some heuristic conditions such as 80% object changed
3326
+ var _renderingService$get = renderingService.getStats(),
3327
+ total = _renderingService$get.total,
3328
+ rendered = _renderingService$get.rendered;
3329
+ var ratio = rendered / total;
3330
+ _this.clearFullScreen = renderingService.disableDirtyRectangleRendering() || rendered > dirtyObjectNumThreshold && ratio > dirtyObjectRatioThreshold;
3331
+ if (context) {
3332
+ context.resetTransform();
3333
+ if (_this.clearFullScreen) {
3334
+ _this.clearRect(context, 0, 0, width * dpr, height * dpr, config.background);
3335
+ }
3336
+ }
3337
+ });
3338
+ var renderByZIndex = function renderByZIndex(object, context) {
3339
+ if (object.isVisible() && !object.isCulled()) {
3340
+ _this.renderDisplayObject(object, context, _this.context, _this.restoreStack);
3341
+ // if we did a full screen rendering last frame
3342
+ _this.saveDirtyAABB(object);
3343
+ }
3344
+ var sorted = object.sortable.sorted || object.childNodes;
3345
+ // should account for z-index
3346
+ sorted.forEach(function (child) {
3347
+ renderByZIndex(child, context);
4018
3348
  });
4019
- var renderByZIndex = function renderByZIndex(object, context) {
4020
- if (object.isVisible() && !object.isCulled()) {
4021
- _this.renderDisplayObject(object, context, _this.context, _this.restoreStack);
4022
- // if we did a full screen rendering last frame
4023
- _this.saveDirtyAABB(object);
3349
+ };
3350
+ // render at the end of frame
3351
+ renderingService.hooks.endFrame.tap(CanvasRendererPlugin.tag, function () {
3352
+ var context = contextService.getContext();
3353
+ // clear & clip dirty rectangle
3354
+ var dpr = contextService.getDPR();
3355
+ fromScaling(_this.dprMatrix, fromValues(dpr, dpr, 1));
3356
+ multiply(_this.vpMatrix, _this.dprMatrix, camera.getOrthoMatrix());
3357
+ if (_this.clearFullScreen) {
3358
+ renderByZIndex(renderingContext.root, context);
3359
+ } else {
3360
+ // merge removed AABB
3361
+ var dirtyRenderBounds = _this.safeMergeAABB.apply(_this, [_this.mergeDirtyAABBs(_this.renderQueue)].concat(_this.removedRBushNodeAABBs.map(function (_ref2) {
3362
+ var minX = _ref2.minX,
3363
+ minY = _ref2.minY,
3364
+ maxX = _ref2.maxX,
3365
+ maxY = _ref2.maxY;
3366
+ var aabb = new gLite.AABB();
3367
+ aabb.setMinMax(fromValues(minX, minY, 0), fromValues(maxX, maxY, 0));
3368
+ return aabb;
3369
+ })));
3370
+ _this.removedRBushNodeAABBs = [];
3371
+ if (gLite.AABB.isEmpty(dirtyRenderBounds)) {
3372
+ _this.renderQueue = [];
3373
+ return;
4024
3374
  }
4025
- var sorted = object.sortable.sorted || object.childNodes;
4026
- // should account for z-index
4027
- sorted.forEach(function (child) {
4028
- renderByZIndex(child, context);
4029
- });
4030
- };
4031
- // render at the end of frame
4032
- renderingService.hooks.endFrame.tap(CanvasRendererPlugin.tag, function () {
4033
- var context = contextService.getContext();
4034
- // clear & clip dirty rectangle
4035
- var dpr = contextService.getDPR();
4036
- fromScaling(_this.dprMatrix, fromValues(dpr, dpr, 1));
4037
- multiply(_this.vpMatrix, _this.dprMatrix, camera.getOrthoMatrix());
4038
- if (_this.clearFullScreen) {
4039
- renderByZIndex(renderingContext.root, context);
4040
- } else {
4041
- // merge removed AABB
4042
- var dirtyRenderBounds = _this.safeMergeAABB.apply(_this, [_this.mergeDirtyAABBs(_this.renderQueue)].concat(_toConsumableArray$1(_this.removedRBushNodeAABBs.map(function (_ref2) {
4043
- var minX = _ref2.minX,
4044
- minY = _ref2.minY,
4045
- maxX = _ref2.maxX,
4046
- maxY = _ref2.maxY;
4047
- var aabb = new gLite.AABB();
4048
- aabb.setMinMax(fromValues(minX, minY, 0), fromValues(maxX, maxY, 0));
4049
- return aabb;
4050
- }))));
4051
- _this.removedRBushNodeAABBs = [];
4052
- if (gLite.AABB.isEmpty(dirtyRenderBounds)) {
4053
- _this.renderQueue = [];
4054
- return;
4055
- }
4056
- var dirtyRect = _this.convertAABB2Rect(dirtyRenderBounds);
4057
- var x = dirtyRect.x,
4058
- y = dirtyRect.y,
4059
- width = dirtyRect.width,
4060
- height = dirtyRect.height;
4061
- var tl = transformMat4(_this.vec3a, fromValues(x, y, 0), _this.vpMatrix);
4062
- var tr = transformMat4(_this.vec3b, fromValues(x + width, y, 0), _this.vpMatrix);
4063
- var bl = transformMat4(_this.vec3c, fromValues(x, y + height, 0), _this.vpMatrix);
4064
- var br = transformMat4(_this.vec3d, fromValues(x + width, y + height, 0), _this.vpMatrix);
4065
- var minx = Math.min(tl[0], tr[0], br[0], bl[0]);
4066
- var miny = Math.min(tl[1], tr[1], br[1], bl[1]);
4067
- var maxx = Math.max(tl[0], tr[0], br[0], bl[0]);
4068
- var maxy = Math.max(tl[1], tr[1], br[1], bl[1]);
4069
- var ix = Math.floor(minx);
4070
- var iy = Math.floor(miny);
4071
- var iwidth = Math.ceil(maxx - minx);
4072
- var iheight = Math.ceil(maxy - miny);
4073
- context.save();
4074
- _this.clearRect(context, ix, iy, iwidth, iheight, config.background);
4075
- context.beginPath();
4076
- context.rect(ix, iy, iwidth, iheight);
4077
- context.clip();
4078
- // @see https://developer.mozilla.org/en-US/docs/Web/API/Canvas_API/Tutorial/Transformations
4079
- context.setTransform(_this.vpMatrix[0], _this.vpMatrix[1], _this.vpMatrix[4], _this.vpMatrix[5], _this.vpMatrix[12], _this.vpMatrix[13]);
4080
- // draw dirty rectangle
4081
- var _config$renderer$getC = config.renderer.getConfig(),
4082
- enableDirtyRectangleRenderingDebug = _config$renderer$getC.enableDirtyRectangleRenderingDebug;
4083
- if (enableDirtyRectangleRenderingDebug) {
4084
- canvas.dispatchEvent(new gLite.CustomEvent(gLite.CanvasEvent.DIRTY_RECTANGLE, {
4085
- dirtyRect: {
4086
- x: ix,
4087
- y: iy,
4088
- width: iwidth,
4089
- height: iheight
4090
- }
4091
- }));
4092
- }
4093
- // search objects intersect with dirty rectangle
4094
- var dirtyObjects = _this.searchDirtyObjects(dirtyRenderBounds);
4095
- // do rendering
4096
- dirtyObjects
4097
- // sort by z-index
4098
- .sort(function (a, b) {
4099
- return a.sortable.renderOrder - b.sortable.renderOrder;
4100
- }).forEach(function (object) {
4101
- // culled object should not be rendered
4102
- if (object && object.isVisible() && !object.isCulled()) {
4103
- _this.renderDisplayObject(object, context, _this.context, _this.restoreStack);
3375
+ var dirtyRect = _this.convertAABB2Rect(dirtyRenderBounds);
3376
+ var x = dirtyRect.x,
3377
+ y = dirtyRect.y,
3378
+ width = dirtyRect.width,
3379
+ height = dirtyRect.height;
3380
+ var tl = transformMat4(_this.vec3a, fromValues(x, y, 0), _this.vpMatrix);
3381
+ var tr = transformMat4(_this.vec3b, fromValues(x + width, y, 0), _this.vpMatrix);
3382
+ var bl = transformMat4(_this.vec3c, fromValues(x, y + height, 0), _this.vpMatrix);
3383
+ var br = transformMat4(_this.vec3d, fromValues(x + width, y + height, 0), _this.vpMatrix);
3384
+ var minx = Math.min(tl[0], tr[0], br[0], bl[0]);
3385
+ var miny = Math.min(tl[1], tr[1], br[1], bl[1]);
3386
+ var maxx = Math.max(tl[0], tr[0], br[0], bl[0]);
3387
+ var maxy = Math.max(tl[1], tr[1], br[1], bl[1]);
3388
+ var ix = Math.floor(minx);
3389
+ var iy = Math.floor(miny);
3390
+ var iwidth = Math.ceil(maxx - minx);
3391
+ var iheight = Math.ceil(maxy - miny);
3392
+ context.save();
3393
+ _this.clearRect(context, ix, iy, iwidth, iheight, config.background);
3394
+ context.beginPath();
3395
+ context.rect(ix, iy, iwidth, iheight);
3396
+ context.clip();
3397
+ // @see https://developer.mozilla.org/en-US/docs/Web/API/Canvas_API/Tutorial/Transformations
3398
+ context.setTransform(_this.vpMatrix[0], _this.vpMatrix[1], _this.vpMatrix[4], _this.vpMatrix[5], _this.vpMatrix[12], _this.vpMatrix[13]);
3399
+ // draw dirty rectangle
3400
+ var _config$renderer$getC = config.renderer.getConfig(),
3401
+ enableDirtyRectangleRenderingDebug = _config$renderer$getC.enableDirtyRectangleRenderingDebug;
3402
+ if (enableDirtyRectangleRenderingDebug) {
3403
+ canvas.dispatchEvent(new gLite.CustomEvent(gLite.CanvasEvent.DIRTY_RECTANGLE, {
3404
+ dirtyRect: {
3405
+ x: ix,
3406
+ y: iy,
3407
+ width: iwidth,
3408
+ height: iheight
4104
3409
  }
4105
- });
4106
- context.restore();
4107
- // save dirty AABBs in last frame
4108
- _this.renderQueue.forEach(function (object) {
4109
- _this.saveDirtyAABB(object);
4110
- });
4111
- // clear queue
4112
- _this.renderQueue = [];
3410
+ }));
4113
3411
  }
4114
- // pop restore stack, eg. root -> parent -> child
4115
- _this.restoreStack.forEach(function () {
4116
- context.restore();
3412
+ // search objects intersect with dirty rectangle
3413
+ var dirtyObjects = _this.searchDirtyObjects(dirtyRenderBounds);
3414
+ // do rendering
3415
+ dirtyObjects
3416
+ // sort by z-index
3417
+ .sort(function (a, b) {
3418
+ return a.sortable.renderOrder - b.sortable.renderOrder;
3419
+ }).forEach(function (object) {
3420
+ // culled object should not be rendered
3421
+ if (object && object.isVisible() && !object.isCulled()) {
3422
+ _this.renderDisplayObject(object, context, _this.context, _this.restoreStack);
3423
+ }
4117
3424
  });
4118
- // clear restore stack
4119
- _this.restoreStack = [];
4120
- });
4121
- renderingService.hooks.render.tap(CanvasRendererPlugin.tag, function (object) {
4122
- if (!_this.clearFullScreen) {
4123
- // render at the end of frame
4124
- _this.renderQueue.push(object);
4125
- }
4126
- });
4127
- }
4128
- }, {
4129
- key: "clearRect",
4130
- value: function clearRect(context, x, y, width, height, background) {
4131
- // clearRect is faster than fillRect @see https://stackoverflow.com/a/30830253
4132
- context.clearRect(x, y, width, height);
4133
- if (background) {
4134
- context.fillStyle = background;
4135
- context.fillRect(x, y, width, height);
4136
- }
4137
- }
4138
- }, {
4139
- key: "renderDisplayObject",
4140
- value: function renderDisplayObject(object, context, canvasContext, restoreStack) {
4141
- var nodeName = object.nodeName;
4142
- // restore to its ancestor
4143
- var parent = restoreStack[restoreStack.length - 1];
4144
- if (parent && !(object.compareDocumentPosition(parent) & Node.DOCUMENT_POSITION_CONTAINS)) {
4145
3425
  context.restore();
4146
- restoreStack.pop();
3426
+ // save dirty AABBs in last frame
3427
+ _this.renderQueue.forEach(function (object) {
3428
+ _this.saveDirtyAABB(object);
3429
+ });
3430
+ // clear queue
3431
+ _this.renderQueue = [];
4147
3432
  }
4148
- // @ts-ignore
4149
- var styleRenderer = this.context.styleRendererFactory[nodeName];
4150
- var generatePath = this.pathGeneratorFactory[nodeName];
4151
- // clip path
4152
- var clipPath = object.parsedStyle.clipPath;
4153
- if (clipPath) {
4154
- this.applyWorldTransform(context, clipPath);
4155
- // generate path in local space
4156
- var _generatePath = this.pathGeneratorFactory[clipPath.nodeName];
4157
- if (_generatePath) {
4158
- context.save();
4159
- // save clip
4160
- restoreStack.push(object);
4161
- context.beginPath();
4162
- _generatePath(context, clipPath.parsedStyle);
4163
- context.closePath();
4164
- context.clip();
4165
- }
3433
+ // pop restore stack, eg. root -> parent -> child
3434
+ _this.restoreStack.forEach(function () {
3435
+ context.restore();
3436
+ });
3437
+ // clear restore stack
3438
+ _this.restoreStack = [];
3439
+ });
3440
+ renderingService.hooks.render.tap(CanvasRendererPlugin.tag, function (object) {
3441
+ if (!_this.clearFullScreen) {
3442
+ // render at the end of frame
3443
+ _this.renderQueue.push(object);
4166
3444
  }
4167
- // fill & stroke
4168
- if (styleRenderer) {
4169
- this.applyWorldTransform(context, object);
3445
+ });
3446
+ };
3447
+ _proto.clearRect = function clearRect(context, x, y, width, height, background) {
3448
+ // clearRect is faster than fillRect @see https://stackoverflow.com/a/30830253
3449
+ context.clearRect(x, y, width, height);
3450
+ if (background) {
3451
+ context.fillStyle = background;
3452
+ context.fillRect(x, y, width, height);
3453
+ }
3454
+ };
3455
+ _proto.renderDisplayObject = function renderDisplayObject(object, context, canvasContext, restoreStack) {
3456
+ var nodeName = object.nodeName;
3457
+ // restore to its ancestor
3458
+ var parent = restoreStack[restoreStack.length - 1];
3459
+ if (parent && !(object.compareDocumentPosition(parent) & Node.DOCUMENT_POSITION_CONTAINS)) {
3460
+ context.restore();
3461
+ restoreStack.pop();
3462
+ }
3463
+ // @ts-ignore
3464
+ var styleRenderer = this.context.styleRendererFactory[nodeName];
3465
+ var generatePath = this.pathGeneratorFactory[nodeName];
3466
+ // clip path
3467
+ var clipPath = object.parsedStyle.clipPath;
3468
+ if (clipPath) {
3469
+ this.applyWorldTransform(context, clipPath);
3470
+ // generate path in local space
3471
+ var _generatePath = this.pathGeneratorFactory[clipPath.nodeName];
3472
+ if (_generatePath) {
4170
3473
  context.save();
4171
- // apply attributes to context
4172
- this.applyAttributesToContext(context, object);
4173
- }
4174
- if (generatePath) {
3474
+ // save clip
3475
+ restoreStack.push(object);
4175
3476
  context.beginPath();
4176
- generatePath(context, object.parsedStyle);
4177
- if (object.nodeName !== gLite.Shape.LINE && object.nodeName !== gLite.Shape.PATH && object.nodeName !== gLite.Shape.POLYLINE) {
4178
- context.closePath();
4179
- }
4180
- }
4181
- // fill & stroke
4182
- if (styleRenderer) {
4183
- styleRenderer.render(context, object.parsedStyle, object, canvasContext, this);
4184
- // restore applied attributes, eg. shadowBlur shadowColor...
4185
- context.restore();
3477
+ _generatePath(context, clipPath.parsedStyle);
3478
+ context.closePath();
3479
+ context.clip();
4186
3480
  }
4187
- // finish rendering, clear dirty flag
4188
- object.renderable.dirty = false;
4189
- }
4190
- }, {
4191
- key: "convertAABB2Rect",
4192
- value: function convertAABB2Rect(aabb) {
4193
- var min = aabb.getMin();
4194
- var max = aabb.getMax();
4195
- // expand the rectangle a bit to avoid artifacts
4196
- // @see https://www.yuque.com/antv/ou292n/bi8nix#ExvCu
4197
- var minX = Math.floor(min[0]);
4198
- var minY = Math.floor(min[1]);
4199
- var maxX = Math.ceil(max[0]);
4200
- var maxY = Math.ceil(max[1]);
4201
- var width = maxX - minX;
4202
- var height = maxY - minY;
4203
- return {
4204
- x: minX,
4205
- y: minY,
4206
- width: width,
4207
- height: height
4208
- };
4209
3481
  }
4210
- /**
4211
- * TODO: merge dirty rectangles with some strategies.
4212
- * For now, we just simply merge all the rectangles into one.
4213
- * @see https://idom.me/articles/841.html
4214
- */
4215
- }, {
4216
- key: "mergeDirtyAABBs",
4217
- value: function mergeDirtyAABBs(dirtyObjects) {
4218
- // merge into a big AABB
4219
- // TODO: skip descendant if ancestor is caculated, but compareNodePosition is really slow
4220
- var aabb = new gLite.AABB();
4221
- dirtyObjects.forEach(function (object) {
4222
- var renderBounds = object.getRenderBounds();
4223
- aabb.add(renderBounds);
4224
- var dirtyRenderBounds = object.renderable.dirtyRenderBounds;
4225
- if (dirtyRenderBounds) {
4226
- aabb.add(dirtyRenderBounds);
4227
- }
4228
- });
4229
- return aabb;
4230
- }
4231
- }, {
4232
- key: "searchDirtyObjects",
4233
- value: function searchDirtyObjects(dirtyRectangle) {
4234
- // search in r-tree, get all affected nodes
4235
- var _dirtyRectangle$getMi = dirtyRectangle.getMin(),
4236
- _dirtyRectangle$getMi2 = _slicedToArray$2(_dirtyRectangle$getMi, 2),
4237
- minX = _dirtyRectangle$getMi2[0],
4238
- minY = _dirtyRectangle$getMi2[1];
4239
- var _dirtyRectangle$getMa = dirtyRectangle.getMax(),
4240
- _dirtyRectangle$getMa2 = _slicedToArray$2(_dirtyRectangle$getMa, 2),
4241
- maxX = _dirtyRectangle$getMa2[0],
4242
- maxY = _dirtyRectangle$getMa2[1];
4243
- var rBushNodes = this.rBush.search({
4244
- minX: minX,
4245
- minY: minY,
4246
- maxX: maxX,
4247
- maxY: maxY
4248
- });
4249
- return rBushNodes.map(function (_ref3) {
4250
- var id = _ref3.id;
4251
- return gLite.runtime.displayObjectPool.getByEntity(id);
4252
- });
3482
+ // fill & stroke
3483
+ if (styleRenderer) {
3484
+ this.applyWorldTransform(context, object);
3485
+ context.save();
3486
+ // apply attributes to context
3487
+ this.applyAttributesToContext(context, object);
4253
3488
  }
4254
- }, {
4255
- key: "saveDirtyAABB",
4256
- value: function saveDirtyAABB(object) {
4257
- var renderable = object.renderable;
4258
- if (!renderable.dirtyRenderBounds) {
4259
- renderable.dirtyRenderBounds = new gLite.AABB();
3489
+ if (generatePath) {
3490
+ context.beginPath();
3491
+ generatePath(context, object.parsedStyle);
3492
+ if (object.nodeName !== gLite.Shape.LINE && object.nodeName !== gLite.Shape.PATH && object.nodeName !== gLite.Shape.POLYLINE) {
3493
+ context.closePath();
4260
3494
  }
3495
+ }
3496
+ // fill & stroke
3497
+ if (styleRenderer) {
3498
+ styleRenderer.render(context, object.parsedStyle, object, canvasContext, this);
3499
+ // restore applied attributes, eg. shadowBlur shadowColor...
3500
+ context.restore();
3501
+ }
3502
+ // finish rendering, clear dirty flag
3503
+ object.renderable.dirty = false;
3504
+ };
3505
+ _proto.convertAABB2Rect = function convertAABB2Rect(aabb) {
3506
+ var min = aabb.getMin();
3507
+ var max = aabb.getMax();
3508
+ // expand the rectangle a bit to avoid artifacts
3509
+ // @see https://www.yuque.com/antv/ou292n/bi8nix#ExvCu
3510
+ var minX = Math.floor(min[0]);
3511
+ var minY = Math.floor(min[1]);
3512
+ var maxX = Math.ceil(max[0]);
3513
+ var maxY = Math.ceil(max[1]);
3514
+ var width = maxX - minX;
3515
+ var height = maxY - minY;
3516
+ return {
3517
+ x: minX,
3518
+ y: minY,
3519
+ width: width,
3520
+ height: height
3521
+ };
3522
+ }
3523
+ /**
3524
+ * TODO: merge dirty rectangles with some strategies.
3525
+ * For now, we just simply merge all the rectangles into one.
3526
+ * @see https://idom.me/articles/841.html
3527
+ */;
3528
+ _proto.mergeDirtyAABBs = function mergeDirtyAABBs(dirtyObjects) {
3529
+ // merge into a big AABB
3530
+ // TODO: skip descendant if ancestor is caculated, but compareNodePosition is really slow
3531
+ var aabb = new gLite.AABB();
3532
+ dirtyObjects.forEach(function (object) {
4261
3533
  var renderBounds = object.getRenderBounds();
4262
- if (renderBounds) {
4263
- // save last dirty aabb
4264
- renderable.dirtyRenderBounds.update(renderBounds.center, renderBounds.halfExtents);
3534
+ aabb.add(renderBounds);
3535
+ var dirtyRenderBounds = object.renderable.dirtyRenderBounds;
3536
+ if (dirtyRenderBounds) {
3537
+ aabb.add(dirtyRenderBounds);
4265
3538
  }
3539
+ });
3540
+ return aabb;
3541
+ };
3542
+ _proto.searchDirtyObjects = function searchDirtyObjects(dirtyRectangle) {
3543
+ // search in r-tree, get all affected nodes
3544
+ var _dirtyRectangle$getMi = dirtyRectangle.getMin(),
3545
+ minX = _dirtyRectangle$getMi[0],
3546
+ minY = _dirtyRectangle$getMi[1];
3547
+ var _dirtyRectangle$getMa = dirtyRectangle.getMax(),
3548
+ maxX = _dirtyRectangle$getMa[0],
3549
+ maxY = _dirtyRectangle$getMa[1];
3550
+ var rBushNodes = this.rBush.search({
3551
+ minX: minX,
3552
+ minY: minY,
3553
+ maxX: maxX,
3554
+ maxY: maxY
3555
+ });
3556
+ return rBushNodes.map(function (_ref3) {
3557
+ var id = _ref3.id;
3558
+ return gLite.runtime.displayObjectPool.getByEntity(id);
3559
+ });
3560
+ };
3561
+ _proto.saveDirtyAABB = function saveDirtyAABB(object) {
3562
+ var renderable = object.renderable;
3563
+ if (!renderable.dirtyRenderBounds) {
3564
+ renderable.dirtyRenderBounds = new gLite.AABB();
4266
3565
  }
4267
- /**
4268
- * TODO: batch the same global attributes
4269
- */
4270
- }, {
4271
- key: "applyAttributesToContext",
4272
- value: function applyAttributesToContext(context, object) {
4273
- var _object$parsedStyle = object.parsedStyle,
4274
- stroke = _object$parsedStyle.stroke,
4275
- fill = _object$parsedStyle.fill,
4276
- opacity = _object$parsedStyle.opacity,
4277
- lineDash = _object$parsedStyle.lineDash,
4278
- lineDashOffset = _object$parsedStyle.lineDashOffset;
4279
- // @see https://developer.mozilla.org/zh-CN/docs/Web/API/CanvasRenderingContext2D/setLineDash
4280
- if (lineDash) {
4281
- context.setLineDash(lineDash);
4282
- }
4283
- // @see https://developer.mozilla.org/zh-CN/docs/Web/API/CanvasRenderingContext2D/lineDashOffset
4284
- if (!isNil(lineDashOffset)) {
4285
- context.lineDashOffset = lineDashOffset;
4286
- }
4287
- if (!isNil(opacity)) {
4288
- context.globalAlpha *= opacity;
4289
- }
4290
- if (!isNil(stroke) && !Array.isArray(stroke) && !stroke.isNone) {
4291
- context.strokeStyle = object.attributes.stroke;
4292
- }
4293
- if (!isNil(fill) && !Array.isArray(fill) && !fill.isNone) {
4294
- context.fillStyle = object.attributes.fill;
4295
- }
4296
- }
4297
- }, {
4298
- key: "applyWorldTransform",
4299
- value: function applyWorldTransform(context, object, matrix) {
4300
- var tx = 0;
4301
- var ty = 0;
4302
- var _ref4 = object.parsedStyle || {},
4303
- anchor = _ref4.anchor;
4304
- var anchorX = anchor && anchor[0] || 0;
4305
- var anchorY = anchor && anchor[1] || 0;
4306
- if (anchorX !== 0 || anchorY !== 0) {
4307
- var bounds = object.getGeometryBounds();
4308
- var width = bounds && bounds.halfExtents[0] * 2 || 0;
4309
- var height = bounds && bounds.halfExtents[1] * 2 || 0;
4310
- tx = -(anchorX * width);
4311
- ty = -(anchorY * height);
4312
- }
4313
- // apply clip shape's RTS
4314
- if (matrix) {
4315
- copy(this.tmpMat4, object.getLocalTransform());
4316
- this.vec3a[0] = tx;
4317
- this.vec3a[1] = ty;
4318
- this.vec3a[2] = 0;
4319
- translate(this.tmpMat4, this.tmpMat4, this.vec3a);
4320
- multiply(this.tmpMat4, matrix, this.tmpMat4);
4321
- multiply(this.tmpMat4, this.vpMatrix, this.tmpMat4);
4322
- } else {
4323
- // apply RTS transformation in world space
4324
- copy(this.tmpMat4, object.getWorldTransform());
4325
- this.vec3a[0] = tx;
4326
- this.vec3a[1] = ty;
4327
- this.vec3a[2] = 0;
4328
- translate(this.tmpMat4, this.tmpMat4, this.vec3a);
4329
- multiply(this.tmpMat4, this.vpMatrix, this.tmpMat4);
4330
- }
4331
- // @see https://developer.mozilla.org/en-US/docs/Web/API/Canvas_API/Tutorial/Transformations
4332
- context.setTransform(this.tmpMat4[0], this.tmpMat4[1], this.tmpMat4[4], this.tmpMat4[5], this.tmpMat4[12], this.tmpMat4[13]);
4333
- }
4334
- }, {
4335
- key: "safeMergeAABB",
4336
- value: function safeMergeAABB() {
4337
- var merged = new gLite.AABB();
4338
- for (var _len = arguments.length, aabbs = new Array(_len), _key = 0; _key < _len; _key++) {
4339
- aabbs[_key] = arguments[_key];
4340
- }
4341
- aabbs.forEach(function (aabb) {
4342
- merged.add(aabb);
4343
- });
4344
- return merged;
3566
+ var renderBounds = object.getRenderBounds();
3567
+ if (renderBounds) {
3568
+ // save last dirty aabb
3569
+ renderable.dirtyRenderBounds.update(renderBounds.center, renderBounds.halfExtents);
3570
+ }
3571
+ }
3572
+ /**
3573
+ * TODO: batch the same global attributes
3574
+ */;
3575
+ _proto.applyAttributesToContext = function applyAttributesToContext(context, object) {
3576
+ var _object$parsedStyle = object.parsedStyle,
3577
+ stroke = _object$parsedStyle.stroke,
3578
+ fill = _object$parsedStyle.fill,
3579
+ opacity = _object$parsedStyle.opacity,
3580
+ lineDash = _object$parsedStyle.lineDash,
3581
+ lineDashOffset = _object$parsedStyle.lineDashOffset;
3582
+ // @see https://developer.mozilla.org/zh-CN/docs/Web/API/CanvasRenderingContext2D/setLineDash
3583
+ if (lineDash) {
3584
+ context.setLineDash(lineDash);
3585
+ }
3586
+ // @see https://developer.mozilla.org/zh-CN/docs/Web/API/CanvasRenderingContext2D/lineDashOffset
3587
+ if (!isNil(lineDashOffset)) {
3588
+ context.lineDashOffset = lineDashOffset;
3589
+ }
3590
+ if (!isNil(opacity)) {
3591
+ context.globalAlpha *= opacity;
3592
+ }
3593
+ if (!isNil(stroke) && !Array.isArray(stroke) && !stroke.isNone) {
3594
+ context.strokeStyle = object.attributes.stroke;
3595
+ }
3596
+ if (!isNil(fill) && !Array.isArray(fill) && !fill.isNone) {
3597
+ context.fillStyle = object.attributes.fill;
3598
+ }
3599
+ };
3600
+ _proto.applyWorldTransform = function applyWorldTransform(context, object, matrix) {
3601
+ var tx = 0;
3602
+ var ty = 0;
3603
+ var _ref4 = object.parsedStyle || {},
3604
+ anchor = _ref4.anchor;
3605
+ var anchorX = anchor && anchor[0] || 0;
3606
+ var anchorY = anchor && anchor[1] || 0;
3607
+ if (anchorX !== 0 || anchorY !== 0) {
3608
+ var bounds = object.getGeometryBounds();
3609
+ var width = bounds && bounds.halfExtents[0] * 2 || 0;
3610
+ var height = bounds && bounds.halfExtents[1] * 2 || 0;
3611
+ tx = -(anchorX * width);
3612
+ ty = -(anchorY * height);
3613
+ }
3614
+ // apply clip shape's RTS
3615
+ if (matrix) {
3616
+ copy(this.tmpMat4, object.getLocalTransform());
3617
+ this.vec3a[0] = tx;
3618
+ this.vec3a[1] = ty;
3619
+ this.vec3a[2] = 0;
3620
+ translate(this.tmpMat4, this.tmpMat4, this.vec3a);
3621
+ multiply(this.tmpMat4, matrix, this.tmpMat4);
3622
+ multiply(this.tmpMat4, this.vpMatrix, this.tmpMat4);
3623
+ } else {
3624
+ // apply RTS transformation in world space
3625
+ copy(this.tmpMat4, object.getWorldTransform());
3626
+ this.vec3a[0] = tx;
3627
+ this.vec3a[1] = ty;
3628
+ this.vec3a[2] = 0;
3629
+ translate(this.tmpMat4, this.tmpMat4, this.vec3a);
3630
+ multiply(this.tmpMat4, this.vpMatrix, this.tmpMat4);
3631
+ }
3632
+ // @see https://developer.mozilla.org/en-US/docs/Web/API/Canvas_API/Tutorial/Transformations
3633
+ context.setTransform(this.tmpMat4[0], this.tmpMat4[1], this.tmpMat4[4], this.tmpMat4[5], this.tmpMat4[12], this.tmpMat4[13]);
3634
+ };
3635
+ _proto.safeMergeAABB = function safeMergeAABB() {
3636
+ var merged = new gLite.AABB();
3637
+ for (var _len = arguments.length, aabbs = new Array(_len), _key = 0; _key < _len; _key++) {
3638
+ aabbs[_key] = arguments[_key];
4345
3639
  }
4346
- }]);
3640
+ aabbs.forEach(function (aabb) {
3641
+ merged.add(aabb);
3642
+ });
3643
+ return merged;
3644
+ };
4347
3645
  return CanvasRendererPlugin;
4348
3646
  }();
4349
3647
  CanvasRendererPlugin.tag = 'CanvasRenderer';
4350
3648
  var DefaultRenderer = /*#__PURE__*/function () {
4351
3649
  function DefaultRenderer(imagePool) {
4352
- _classCallCheck$3(this, DefaultRenderer);
4353
3650
  this.imagePool = void 0;
4354
3651
  this.imagePool = imagePool;
4355
3652
  }
4356
- _createClass$3(DefaultRenderer, [{
4357
- key: "render",
4358
- value: function render(context, parsedStyle, object, canvasContext, plugin) {
4359
- var fill = parsedStyle.fill,
4360
- fillRule = parsedStyle.fillRule,
4361
- opacity = parsedStyle.opacity,
4362
- fillOpacity = parsedStyle.fillOpacity,
4363
- stroke = parsedStyle.stroke,
4364
- strokeOpacity = parsedStyle.strokeOpacity,
4365
- lineWidth = parsedStyle.lineWidth,
4366
- lineCap = parsedStyle.lineCap,
4367
- lineJoin = parsedStyle.lineJoin,
4368
- shadowType = parsedStyle.shadowType,
4369
- shadowColor = parsedStyle.shadowColor,
4370
- shadowBlur = parsedStyle.shadowBlur,
4371
- filter = parsedStyle.filter,
4372
- miterLimit = parsedStyle.miterLimit;
4373
- var hasFill = !isNil(fill) && !fill.isNone;
4374
- var hasStroke = !isNil(stroke) && !stroke.isNone && lineWidth > 0;
4375
- var isFillTransparent = fill.alpha === 0;
4376
- var hasFilter = !!(filter && filter.length);
4377
- var hasShadow = !isNil(shadowColor) && shadowBlur > 0;
4378
- var nodeName = object.nodeName;
4379
- var isInnerShadow = shadowType === 'inner';
4380
- var shouldDrawShadowWithStroke = hasStroke && hasShadow && (nodeName === gLite.Shape.PATH || nodeName === gLite.Shape.LINE || nodeName === gLite.Shape.POLYLINE || isFillTransparent || isInnerShadow);
4381
- if (hasFill) {
4382
- context.globalAlpha = opacity * fillOpacity;
4383
- if (!shouldDrawShadowWithStroke) {
4384
- setShadowAndFilter(object, context, hasShadow);
4385
- }
4386
- this.fill(context, object, fill, fillRule, canvasContext, plugin);
4387
- if (!shouldDrawShadowWithStroke) {
4388
- this.clearShadowAndFilter(context, hasFilter, hasShadow);
4389
- }
3653
+ var _proto = DefaultRenderer.prototype;
3654
+ _proto.render = function render(context, parsedStyle, object, canvasContext, plugin) {
3655
+ var fill = parsedStyle.fill,
3656
+ fillRule = parsedStyle.fillRule,
3657
+ opacity = parsedStyle.opacity,
3658
+ fillOpacity = parsedStyle.fillOpacity,
3659
+ stroke = parsedStyle.stroke,
3660
+ strokeOpacity = parsedStyle.strokeOpacity,
3661
+ lineWidth = parsedStyle.lineWidth,
3662
+ lineCap = parsedStyle.lineCap,
3663
+ lineJoin = parsedStyle.lineJoin,
3664
+ shadowType = parsedStyle.shadowType,
3665
+ shadowColor = parsedStyle.shadowColor,
3666
+ shadowBlur = parsedStyle.shadowBlur,
3667
+ filter = parsedStyle.filter,
3668
+ miterLimit = parsedStyle.miterLimit;
3669
+ var hasFill = !isNil(fill) && !fill.isNone;
3670
+ var hasStroke = !isNil(stroke) && !stroke.isNone && lineWidth > 0;
3671
+ var isFillTransparent = fill.alpha === 0;
3672
+ var hasFilter = !!(filter && filter.length);
3673
+ var hasShadow = !isNil(shadowColor) && shadowBlur > 0;
3674
+ var nodeName = object.nodeName;
3675
+ var isInnerShadow = shadowType === 'inner';
3676
+ var shouldDrawShadowWithStroke = hasStroke && hasShadow && (nodeName === gLite.Shape.PATH || nodeName === gLite.Shape.LINE || nodeName === gLite.Shape.POLYLINE || isFillTransparent || isInnerShadow);
3677
+ if (hasFill) {
3678
+ context.globalAlpha = opacity * fillOpacity;
3679
+ if (!shouldDrawShadowWithStroke) {
3680
+ setShadowAndFilter(object, context, hasShadow);
4390
3681
  }
4391
- if (hasStroke) {
4392
- context.globalAlpha = opacity * strokeOpacity;
4393
- context.lineWidth = lineWidth;
4394
- if (!isNil(miterLimit)) {
4395
- context.miterLimit = miterLimit;
4396
- }
4397
- if (!isNil(lineCap)) {
4398
- context.lineCap = lineCap;
4399
- }
4400
- if (!isNil(lineJoin)) {
4401
- context.lineJoin = lineJoin;
4402
- }
4403
- if (shouldDrawShadowWithStroke) {
4404
- if (isInnerShadow) {
4405
- context.globalCompositeOperation = 'source-atop';
4406
- }
4407
- setShadowAndFilter(object, context, true);
4408
- if (isInnerShadow) {
4409
- this.stroke(context, object, stroke, canvasContext, plugin);
4410
- context.globalCompositeOperation = 'source-over';
4411
- this.clearShadowAndFilter(context, hasFilter, true);
4412
- }
4413
- }
4414
- this.stroke(context, object, stroke, canvasContext, plugin);
3682
+ this.fill(context, object, fill, fillRule, canvasContext, plugin);
3683
+ if (!shouldDrawShadowWithStroke) {
3684
+ this.clearShadowAndFilter(context, hasFilter, hasShadow);
4415
3685
  }
4416
3686
  }
4417
- }, {
4418
- key: "clearShadowAndFilter",
4419
- value: function clearShadowAndFilter(context, hasFilter, hasShadow) {
4420
- if (hasShadow) {
4421
- context.shadowColor = 'transparent';
4422
- context.shadowBlur = 0;
3687
+ if (hasStroke) {
3688
+ context.globalAlpha = opacity * strokeOpacity;
3689
+ context.lineWidth = lineWidth;
3690
+ if (!isNil(miterLimit)) {
3691
+ context.miterLimit = miterLimit;
3692
+ }
3693
+ if (!isNil(lineCap)) {
3694
+ context.lineCap = lineCap;
4423
3695
  }
4424
- if (hasFilter) {
4425
- // save drop-shadow filter
4426
- var oldFilter = context.filter;
4427
- if (!isNil(oldFilter) && oldFilter.indexOf('drop-shadow') > -1) {
4428
- context.filter = oldFilter.replace(/drop-shadow\([^)]*\)/, '').trim() || 'none';
3696
+ if (!isNil(lineJoin)) {
3697
+ context.lineJoin = lineJoin;
3698
+ }
3699
+ if (shouldDrawShadowWithStroke) {
3700
+ if (isInnerShadow) {
3701
+ context.globalCompositeOperation = 'source-atop';
3702
+ }
3703
+ setShadowAndFilter(object, context, true);
3704
+ if (isInnerShadow) {
3705
+ this.stroke(context, object, stroke, canvasContext, plugin);
3706
+ context.globalCompositeOperation = 'source-over';
3707
+ this.clearShadowAndFilter(context, hasFilter, true);
4429
3708
  }
4430
3709
  }
3710
+ this.stroke(context, object, stroke, canvasContext, plugin);
4431
3711
  }
4432
- }, {
4433
- key: "fill",
4434
- value: function fill(context, object, _fill, fillRule, canvasContext, plugin) {
4435
- var _this = this;
4436
- if (Array.isArray(_fill)) {
4437
- _fill.forEach(function (gradient) {
4438
- context.fillStyle = _this.getColor(gradient, object, context);
4439
- context.fill(fillRule);
4440
- });
4441
- } else {
4442
- if (gLite.isPattern(_fill)) {
4443
- context.fillStyle = this.getPattern(_fill, object, context, canvasContext, plugin);
4444
- }
3712
+ };
3713
+ _proto.clearShadowAndFilter = function clearShadowAndFilter(context, hasFilter, hasShadow) {
3714
+ if (hasShadow) {
3715
+ context.shadowColor = 'transparent';
3716
+ context.shadowBlur = 0;
3717
+ }
3718
+ if (hasFilter) {
3719
+ // save drop-shadow filter
3720
+ var oldFilter = context.filter;
3721
+ if (!isNil(oldFilter) && oldFilter.indexOf('drop-shadow') > -1) {
3722
+ context.filter = oldFilter.replace(/drop-shadow\([^)]*\)/, '').trim() || 'none';
3723
+ }
3724
+ }
3725
+ };
3726
+ _proto.fill = function fill(context, object, _fill, fillRule, canvasContext, plugin) {
3727
+ var _this = this;
3728
+ if (Array.isArray(_fill)) {
3729
+ _fill.forEach(function (gradient) {
3730
+ context.fillStyle = _this.getColor(gradient, object, context);
4445
3731
  context.fill(fillRule);
3732
+ });
3733
+ } else {
3734
+ if (gLite.isPattern(_fill)) {
3735
+ context.fillStyle = this.getPattern(_fill, object, context, canvasContext, plugin);
4446
3736
  }
3737
+ context.fill(fillRule);
4447
3738
  }
4448
- }, {
4449
- key: "stroke",
4450
- value: function stroke(context, object, _stroke, canvasContext, plugin) {
4451
- var _this2 = this;
4452
- if (Array.isArray(_stroke)) {
4453
- _stroke.forEach(function (gradient) {
4454
- context.strokeStyle = _this2.getColor(gradient, object, context);
4455
- context.stroke();
4456
- });
4457
- } else {
4458
- if (gLite.isPattern(_stroke)) {
4459
- context.strokeStyle = this.getPattern(_stroke, object, context, canvasContext, plugin);
4460
- }
3739
+ };
3740
+ _proto.stroke = function stroke(context, object, _stroke, canvasContext, plugin) {
3741
+ var _this2 = this;
3742
+ if (Array.isArray(_stroke)) {
3743
+ _stroke.forEach(function (gradient) {
3744
+ context.strokeStyle = _this2.getColor(gradient, object, context);
4461
3745
  context.stroke();
3746
+ });
3747
+ } else {
3748
+ if (gLite.isPattern(_stroke)) {
3749
+ context.strokeStyle = this.getPattern(_stroke, object, context, canvasContext, plugin);
4462
3750
  }
3751
+ context.stroke();
4463
3752
  }
4464
- }, {
4465
- key: "getPattern",
4466
- value: function getPattern(pattern, object, context, canvasContext, plugin) {
4467
- var $offscreenCanvas;
4468
- var dpr;
4469
- if (pattern.image instanceof gLite.Rect) {
4470
- var _pattern$image$parsed = pattern.image.parsedStyle,
4471
- width = _pattern$image$parsed.width,
4472
- height = _pattern$image$parsed.height;
4473
- dpr = canvasContext.contextService.getDPR();
4474
- var offscreenCanvas = canvasContext.config.offscreenCanvas;
4475
- $offscreenCanvas = gLite.runtime.offscreenCanvas.getOrCreateCanvas(offscreenCanvas);
4476
- $offscreenCanvas.width = width * dpr;
4477
- $offscreenCanvas.height = height * dpr;
4478
- var offscreenCanvasContext = gLite.runtime.offscreenCanvas.getOrCreateContext(offscreenCanvas);
4479
- var restoreStack = [];
4480
- // offscreenCanvasContext.scale(1 / dpr, 1 / dpr);
4481
- pattern.image.forEach(function (object) {
4482
- plugin.renderDisplayObject(object, offscreenCanvasContext, canvasContext, restoreStack);
4483
- });
4484
- restoreStack.forEach(function () {
4485
- offscreenCanvasContext.restore();
4486
- });
4487
- }
4488
- var canvasPattern = this.imagePool.getOrCreatePatternSync(pattern, context, $offscreenCanvas, dpr, function () {
4489
- // set dirty rectangle flag
4490
- object.renderable.dirty = true;
4491
- canvasContext.renderingService.dirtify();
3753
+ };
3754
+ _proto.getPattern = function getPattern(pattern, object, context, canvasContext, plugin) {
3755
+ var $offscreenCanvas;
3756
+ var dpr;
3757
+ if (pattern.image instanceof gLite.Rect) {
3758
+ var _pattern$image$parsed = pattern.image.parsedStyle,
3759
+ width = _pattern$image$parsed.width,
3760
+ height = _pattern$image$parsed.height;
3761
+ dpr = canvasContext.contextService.getDPR();
3762
+ var offscreenCanvas = canvasContext.config.offscreenCanvas;
3763
+ $offscreenCanvas = gLite.runtime.offscreenCanvas.getOrCreateCanvas(offscreenCanvas);
3764
+ $offscreenCanvas.width = width * dpr;
3765
+ $offscreenCanvas.height = height * dpr;
3766
+ var offscreenCanvasContext = gLite.runtime.offscreenCanvas.getOrCreateContext(offscreenCanvas);
3767
+ var restoreStack = [];
3768
+ // offscreenCanvasContext.scale(1 / dpr, 1 / dpr);
3769
+ pattern.image.forEach(function (object) {
3770
+ plugin.renderDisplayObject(object, offscreenCanvasContext, canvasContext, restoreStack);
3771
+ });
3772
+ restoreStack.forEach(function () {
3773
+ offscreenCanvasContext.restore();
4492
3774
  });
4493
- return canvasPattern;
4494
- }
4495
- }, {
4496
- key: "getColor",
4497
- value: function getColor(parsedColor, object, context) {
4498
- var color;
4499
- if (parsedColor.type === gLite.GradientType.LinearGradient || parsedColor.type === gLite.GradientType.RadialGradient) {
4500
- var bounds = object.getGeometryBounds();
4501
- var width = bounds && bounds.halfExtents[0] * 2 || 1;
4502
- var height = bounds && bounds.halfExtents[1] * 2 || 1;
4503
- color = this.imagePool.getOrCreateGradient(_objectSpread2(_objectSpread2({
4504
- type: parsedColor.type
4505
- }, parsedColor.value), {}, {
4506
- width: width,
4507
- height: height
4508
- }), context);
4509
- }
4510
- return color;
4511
- }
4512
- }]);
3775
+ }
3776
+ var canvasPattern = this.imagePool.getOrCreatePatternSync(pattern, context, $offscreenCanvas, dpr, function () {
3777
+ // set dirty rectangle flag
3778
+ object.renderable.dirty = true;
3779
+ canvasContext.renderingService.dirtify();
3780
+ });
3781
+ return canvasPattern;
3782
+ };
3783
+ _proto.getColor = function getColor(parsedColor, object, context) {
3784
+ var color;
3785
+ if (parsedColor.type === gLite.GradientType.LinearGradient || parsedColor.type === gLite.GradientType.RadialGradient) {
3786
+ var bounds = object.getGeometryBounds();
3787
+ var width = bounds && bounds.halfExtents[0] * 2 || 1;
3788
+ var height = bounds && bounds.halfExtents[1] * 2 || 1;
3789
+ color = this.imagePool.getOrCreateGradient(_extends({
3790
+ type: parsedColor.type
3791
+ }, parsedColor.value, {
3792
+ width: width,
3793
+ height: height
3794
+ }), context);
3795
+ }
3796
+ return color;
3797
+ };
4513
3798
  return DefaultRenderer;
4514
3799
  }();
4515
3800
  /**
@@ -4535,275 +3820,246 @@
4535
3820
  }
4536
3821
  var ImageRenderer = /*#__PURE__*/function () {
4537
3822
  function ImageRenderer(imagePool) {
4538
- _classCallCheck$3(this, ImageRenderer);
4539
3823
  this.imagePool = void 0;
4540
3824
  this.imagePool = imagePool;
4541
3825
  }
4542
- _createClass$3(ImageRenderer, [{
4543
- key: "render",
4544
- value: function render(context, parsedStyle, object) {
4545
- var width = parsedStyle.width,
4546
- height = parsedStyle.height,
4547
- img = parsedStyle.img,
4548
- shadowColor = parsedStyle.shadowColor,
4549
- shadowBlur = parsedStyle.shadowBlur;
4550
- var image;
4551
- var iw = width;
4552
- var ih = height;
4553
- if (isString(img)) {
4554
- // image has been loaded in `mounted` hook
4555
- image = this.imagePool.getImageSync(img);
4556
- } else {
4557
- iw || (iw = img.width);
4558
- ih || (ih = img.height);
4559
- image = img;
4560
- }
4561
- if (image) {
4562
- var hasShadow = !isNil(shadowColor) && shadowBlur > 0;
4563
- setShadowAndFilter(object, context, hasShadow);
4564
- // node-canvas will throw the following err:
4565
- // Error: Image given has not completed loading
4566
- try {
4567
- context.drawImage(image, 0, 0, iw, ih);
4568
- } catch (e) {}
4569
- }
3826
+ var _proto = ImageRenderer.prototype;
3827
+ _proto.render = function render(context, parsedStyle, object) {
3828
+ var width = parsedStyle.width,
3829
+ height = parsedStyle.height,
3830
+ img = parsedStyle.img,
3831
+ shadowColor = parsedStyle.shadowColor,
3832
+ shadowBlur = parsedStyle.shadowBlur;
3833
+ var image;
3834
+ var iw = width;
3835
+ var ih = height;
3836
+ if (isString(img)) {
3837
+ // image has been loaded in `mounted` hook
3838
+ image = this.imagePool.getImageSync(img);
3839
+ } else {
3840
+ iw || (iw = img.width);
3841
+ ih || (ih = img.height);
3842
+ image = img;
4570
3843
  }
4571
- }]);
3844
+ if (image) {
3845
+ var hasShadow = !isNil(shadowColor) && shadowBlur > 0;
3846
+ setShadowAndFilter(object, context, hasShadow);
3847
+ // node-canvas will throw the following err:
3848
+ // Error: Image given has not completed loading
3849
+ try {
3850
+ context.drawImage(image, 0, 0, iw, ih);
3851
+ } catch (e) {}
3852
+ }
3853
+ };
4572
3854
  return ImageRenderer;
4573
3855
  }();
4574
3856
  var TextRenderer = /*#__PURE__*/function () {
4575
- function TextRenderer() {
4576
- _classCallCheck$3(this, TextRenderer);
4577
- }
4578
- _createClass$3(TextRenderer, [{
4579
- key: "render",
4580
- value: function render(context, parsedStyle, object) {
4581
- var lineWidth = parsedStyle.lineWidth,
4582
- textAlign = parsedStyle.textAlign,
4583
- textBaseline = parsedStyle.textBaseline,
4584
- lineJoin = parsedStyle.lineJoin,
4585
- miterLimit = parsedStyle.miterLimit,
4586
- letterSpacing = parsedStyle.letterSpacing,
4587
- stroke = parsedStyle.stroke,
4588
- fill = parsedStyle.fill,
4589
- fillOpacity = parsedStyle.fillOpacity,
4590
- strokeOpacity = parsedStyle.strokeOpacity,
4591
- opacity = parsedStyle.opacity,
4592
- metrics = parsedStyle.metrics,
4593
- dx = parsedStyle.dx,
4594
- dy = parsedStyle.dy,
4595
- shadowColor = parsedStyle.shadowColor,
4596
- shadowBlur = parsedStyle.shadowBlur;
4597
- var font = metrics.font,
4598
- lines = metrics.lines,
4599
- height = metrics.height,
4600
- lineHeight = metrics.lineHeight,
4601
- lineMetrics = metrics.lineMetrics;
4602
- context.font = font;
4603
- context.lineWidth = lineWidth;
4604
- context.textAlign = textAlign === 'middle' ? 'center' : textAlign;
4605
- context.textBaseline = textBaseline;
4606
- context.lineJoin = lineJoin;
4607
- if (!isNil(miterLimit)) {
4608
- context.miterLimit = miterLimit;
4609
- }
4610
- var linePositionY = 0;
4611
- // handle vertical text baseline
4612
- if (textBaseline === 'middle') {
4613
- linePositionY = -height / 2 - lineHeight / 2;
4614
- } else if (textBaseline === 'bottom' || textBaseline === 'alphabetic' || textBaseline === 'ideographic') {
4615
- linePositionY = -height;
4616
- } else if (textBaseline === 'top' || textBaseline === 'hanging') {
4617
- linePositionY = -lineHeight;
4618
- }
4619
- // account for dx & dy
4620
- var offsetX = dx || 0;
4621
- linePositionY += dy || 0;
4622
- var hasShadow = !isNil(shadowColor) && shadowBlur > 0;
4623
- setShadowAndFilter(object, context, hasShadow);
4624
- // draw lines line by line
4625
- for (var i = 0; i < lines.length; i++) {
4626
- var linePositionX = lineWidth / 2 + offsetX;
4627
- linePositionY += lineHeight;
4628
- // no need to re-position X, cause we already set text align
4629
- // @see https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/textAlign
4630
- if (!isNil(stroke) && !stroke.isNone && lineWidth) {
4631
- this.drawLetterSpacing(context, lines[i], lineMetrics[i], textAlign, linePositionX, linePositionY, letterSpacing, fillOpacity, strokeOpacity, opacity, true);
4632
- }
4633
- if (!isNil(fill)) {
4634
- this.drawLetterSpacing(context, lines[i], lineMetrics[i], textAlign, linePositionX, linePositionY, letterSpacing, fillOpacity, strokeOpacity, opacity);
4635
- }
3857
+ function TextRenderer() {}
3858
+ var _proto = TextRenderer.prototype;
3859
+ _proto.render = function render(context, parsedStyle, object) {
3860
+ var lineWidth = parsedStyle.lineWidth,
3861
+ textAlign = parsedStyle.textAlign,
3862
+ textBaseline = parsedStyle.textBaseline,
3863
+ lineJoin = parsedStyle.lineJoin,
3864
+ miterLimit = parsedStyle.miterLimit,
3865
+ letterSpacing = parsedStyle.letterSpacing,
3866
+ stroke = parsedStyle.stroke,
3867
+ fill = parsedStyle.fill,
3868
+ fillOpacity = parsedStyle.fillOpacity,
3869
+ strokeOpacity = parsedStyle.strokeOpacity,
3870
+ opacity = parsedStyle.opacity,
3871
+ metrics = parsedStyle.metrics,
3872
+ dx = parsedStyle.dx,
3873
+ dy = parsedStyle.dy,
3874
+ shadowColor = parsedStyle.shadowColor,
3875
+ shadowBlur = parsedStyle.shadowBlur;
3876
+ var font = metrics.font,
3877
+ lines = metrics.lines,
3878
+ height = metrics.height,
3879
+ lineHeight = metrics.lineHeight,
3880
+ lineMetrics = metrics.lineMetrics;
3881
+ context.font = font;
3882
+ context.lineWidth = lineWidth;
3883
+ context.textAlign = textAlign === 'middle' ? 'center' : textAlign;
3884
+ context.textBaseline = textBaseline;
3885
+ context.lineJoin = lineJoin;
3886
+ if (!isNil(miterLimit)) {
3887
+ context.miterLimit = miterLimit;
3888
+ }
3889
+ var linePositionY = 0;
3890
+ // handle vertical text baseline
3891
+ if (textBaseline === 'middle') {
3892
+ linePositionY = -height / 2 - lineHeight / 2;
3893
+ } else if (textBaseline === 'bottom' || textBaseline === 'alphabetic' || textBaseline === 'ideographic') {
3894
+ linePositionY = -height;
3895
+ } else if (textBaseline === 'top' || textBaseline === 'hanging') {
3896
+ linePositionY = -lineHeight;
3897
+ }
3898
+ // account for dx & dy
3899
+ var offsetX = dx || 0;
3900
+ linePositionY += dy || 0;
3901
+ var hasShadow = !isNil(shadowColor) && shadowBlur > 0;
3902
+ setShadowAndFilter(object, context, hasShadow);
3903
+ // draw lines line by line
3904
+ for (var i = 0; i < lines.length; i++) {
3905
+ var linePositionX = lineWidth / 2 + offsetX;
3906
+ linePositionY += lineHeight;
3907
+ // no need to re-position X, cause we already set text align
3908
+ // @see https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/textAlign
3909
+ if (!isNil(stroke) && !stroke.isNone && lineWidth) {
3910
+ this.drawLetterSpacing(context, lines[i], lineMetrics[i], textAlign, linePositionX, linePositionY, letterSpacing, fillOpacity, strokeOpacity, opacity, true);
3911
+ }
3912
+ if (!isNil(fill)) {
3913
+ this.drawLetterSpacing(context, lines[i], lineMetrics[i], textAlign, linePositionX, linePositionY, letterSpacing, fillOpacity, strokeOpacity, opacity);
4636
3914
  }
4637
3915
  }
4638
- }, {
4639
- key: "drawLetterSpacing",
4640
- value: function drawLetterSpacing(context, text, lineMetrics, textAlign, x, y, letterSpacing, fillOpacity, strokeOpacity, opacity) {
4641
- var isStroke = arguments.length > 10 && arguments[10] !== undefined ? arguments[10] : false;
4642
- // letterSpacing of 0 means normal, render all texts directly
4643
- if (letterSpacing === 0) {
4644
- if (isStroke) {
4645
- this.strokeText(context, text, x, y, strokeOpacity);
4646
- } else {
4647
- this.fillText(context, text, x, y, fillOpacity, opacity);
4648
- }
4649
- return;
4650
- }
4651
- // draw text using left align
4652
- var currentTextAlign = context.textAlign;
4653
- context.textAlign = 'left';
4654
- var currentPosition = x;
4655
- if (textAlign === 'center' || textAlign === 'middle') {
4656
- currentPosition = x - lineMetrics.width / 2;
4657
- } else if (textAlign === 'right' || textAlign === 'end') {
4658
- currentPosition = x - lineMetrics.width;
4659
- }
4660
- var stringArray = Array.from(text);
4661
- var previousWidth = context.measureText(text).width;
4662
- var currentWidth = 0;
4663
- for (var i = 0; i < stringArray.length; ++i) {
4664
- var currentChar = stringArray[i];
4665
- if (isStroke) {
4666
- this.strokeText(context, currentChar, currentPosition, y, strokeOpacity);
4667
- } else {
4668
- this.fillText(context, currentChar, currentPosition, y, fillOpacity, opacity);
4669
- }
4670
- currentWidth = context.measureText(text.substring(i + 1)).width;
4671
- currentPosition += previousWidth - currentWidth + letterSpacing;
4672
- previousWidth = currentWidth;
3916
+ };
3917
+ _proto.drawLetterSpacing = function drawLetterSpacing(context, text, lineMetrics, textAlign, x, y, letterSpacing, fillOpacity, strokeOpacity, opacity, isStroke) {
3918
+ if (isStroke === void 0) {
3919
+ isStroke = false;
3920
+ }
3921
+ // letterSpacing of 0 means normal, render all texts directly
3922
+ if (letterSpacing === 0) {
3923
+ if (isStroke) {
3924
+ this.strokeText(context, text, x, y, strokeOpacity);
3925
+ } else {
3926
+ this.fillText(context, text, x, y, fillOpacity, opacity);
3927
+ }
3928
+ return;
3929
+ }
3930
+ // draw text using left align
3931
+ var currentTextAlign = context.textAlign;
3932
+ context.textAlign = 'left';
3933
+ var currentPosition = x;
3934
+ if (textAlign === 'center' || textAlign === 'middle') {
3935
+ currentPosition = x - lineMetrics.width / 2;
3936
+ } else if (textAlign === 'right' || textAlign === 'end') {
3937
+ currentPosition = x - lineMetrics.width;
3938
+ }
3939
+ var stringArray = Array.from(text);
3940
+ var previousWidth = context.measureText(text).width;
3941
+ var currentWidth = 0;
3942
+ for (var i = 0; i < stringArray.length; ++i) {
3943
+ var currentChar = stringArray[i];
3944
+ if (isStroke) {
3945
+ this.strokeText(context, currentChar, currentPosition, y, strokeOpacity);
3946
+ } else {
3947
+ this.fillText(context, currentChar, currentPosition, y, fillOpacity, opacity);
4673
3948
  }
4674
- context.textAlign = currentTextAlign;
3949
+ currentWidth = context.measureText(text.substring(i + 1)).width;
3950
+ currentPosition += previousWidth - currentWidth + letterSpacing;
3951
+ previousWidth = currentWidth;
4675
3952
  }
4676
- }, {
4677
- key: "fillText",
4678
- value: function fillText(context, text, x, y, fillOpacity, opacity) {
4679
- var currentGlobalAlpha;
4680
- var applyOpacity = !isNil(fillOpacity) && fillOpacity !== 1;
4681
- if (applyOpacity) {
4682
- currentGlobalAlpha = context.globalAlpha;
4683
- context.globalAlpha = fillOpacity * opacity;
4684
- }
4685
- context.fillText(text, x, y);
4686
- if (applyOpacity) {
4687
- context.globalAlpha = currentGlobalAlpha;
4688
- }
3953
+ context.textAlign = currentTextAlign;
3954
+ };
3955
+ _proto.fillText = function fillText(context, text, x, y, fillOpacity, opacity) {
3956
+ var currentGlobalAlpha;
3957
+ var applyOpacity = !isNil(fillOpacity) && fillOpacity !== 1;
3958
+ if (applyOpacity) {
3959
+ currentGlobalAlpha = context.globalAlpha;
3960
+ context.globalAlpha = fillOpacity * opacity;
4689
3961
  }
4690
- }, {
4691
- key: "strokeText",
4692
- value: function strokeText(context, text, x, y, strokeOpacity) {
4693
- var currentGlobalAlpha;
4694
- var applyOpacity = !isNil(strokeOpacity) && strokeOpacity !== 1;
4695
- if (applyOpacity) {
4696
- currentGlobalAlpha = context.globalAlpha;
4697
- context.globalAlpha = strokeOpacity;
4698
- }
4699
- context.strokeText(text, x, y);
4700
- if (applyOpacity) {
4701
- context.globalAlpha = currentGlobalAlpha;
4702
- }
3962
+ context.fillText(text, x, y);
3963
+ if (applyOpacity) {
3964
+ context.globalAlpha = currentGlobalAlpha;
3965
+ }
3966
+ };
3967
+ _proto.strokeText = function strokeText(context, text, x, y, strokeOpacity) {
3968
+ var currentGlobalAlpha;
3969
+ var applyOpacity = !isNil(strokeOpacity) && strokeOpacity !== 1;
3970
+ if (applyOpacity) {
3971
+ currentGlobalAlpha = context.globalAlpha;
3972
+ context.globalAlpha = strokeOpacity;
4703
3973
  }
4704
- }]);
3974
+ context.strokeText(text, x, y);
3975
+ if (applyOpacity) {
3976
+ context.globalAlpha = currentGlobalAlpha;
3977
+ }
3978
+ };
4705
3979
  return TextRenderer;
4706
3980
  }();
4707
3981
  var RectRenderer = /*#__PURE__*/function (_DefaultRenderer) {
4708
- _inherits$3(RectRenderer, _DefaultRenderer);
4709
- var _super = _createSuper$3(RectRenderer);
3982
+ _inheritsLoose$3(RectRenderer, _DefaultRenderer);
4710
3983
  function RectRenderer() {
4711
- _classCallCheck$3(this, RectRenderer);
4712
- return _super.apply(this, arguments);
3984
+ return _DefaultRenderer.apply(this, arguments) || this;
4713
3985
  }
4714
- return _createClass$3(RectRenderer);
3986
+ return RectRenderer;
4715
3987
  }(DefaultRenderer);
4716
3988
  var CircleRenderer = /*#__PURE__*/function (_DefaultRenderer) {
4717
- _inherits$3(CircleRenderer, _DefaultRenderer);
4718
- var _super = _createSuper$3(CircleRenderer);
3989
+ _inheritsLoose$3(CircleRenderer, _DefaultRenderer);
4719
3990
  function CircleRenderer() {
4720
- _classCallCheck$3(this, CircleRenderer);
4721
- return _super.apply(this, arguments);
3991
+ return _DefaultRenderer.apply(this, arguments) || this;
4722
3992
  }
4723
- return _createClass$3(CircleRenderer);
3993
+ return CircleRenderer;
4724
3994
  }(DefaultRenderer);
4725
3995
  var EllipseRenderer = /*#__PURE__*/function (_DefaultRenderer) {
4726
- _inherits$3(EllipseRenderer, _DefaultRenderer);
4727
- var _super = _createSuper$3(EllipseRenderer);
3996
+ _inheritsLoose$3(EllipseRenderer, _DefaultRenderer);
4728
3997
  function EllipseRenderer() {
4729
- _classCallCheck$3(this, EllipseRenderer);
4730
- return _super.apply(this, arguments);
3998
+ return _DefaultRenderer.apply(this, arguments) || this;
4731
3999
  }
4732
- return _createClass$3(EllipseRenderer);
4000
+ return EllipseRenderer;
4733
4001
  }(DefaultRenderer);
4734
4002
  var LineRenderer = /*#__PURE__*/function (_DefaultRenderer) {
4735
- _inherits$3(LineRenderer, _DefaultRenderer);
4736
- var _super = _createSuper$3(LineRenderer);
4003
+ _inheritsLoose$3(LineRenderer, _DefaultRenderer);
4737
4004
  function LineRenderer() {
4738
- _classCallCheck$3(this, LineRenderer);
4739
- return _super.apply(this, arguments);
4005
+ return _DefaultRenderer.apply(this, arguments) || this;
4740
4006
  }
4741
- return _createClass$3(LineRenderer);
4007
+ return LineRenderer;
4742
4008
  }(DefaultRenderer);
4743
4009
  var PolylineRenderer = /*#__PURE__*/function (_DefaultRenderer) {
4744
- _inherits$3(PolylineRenderer, _DefaultRenderer);
4745
- var _super = _createSuper$3(PolylineRenderer);
4010
+ _inheritsLoose$3(PolylineRenderer, _DefaultRenderer);
4746
4011
  function PolylineRenderer() {
4747
- _classCallCheck$3(this, PolylineRenderer);
4748
- return _super.apply(this, arguments);
4012
+ return _DefaultRenderer.apply(this, arguments) || this;
4749
4013
  }
4750
- return _createClass$3(PolylineRenderer);
4014
+ return PolylineRenderer;
4751
4015
  }(DefaultRenderer);
4752
4016
  var PolygonRenderer = /*#__PURE__*/function (_DefaultRenderer) {
4753
- _inherits$3(PolygonRenderer, _DefaultRenderer);
4754
- var _super = _createSuper$3(PolygonRenderer);
4017
+ _inheritsLoose$3(PolygonRenderer, _DefaultRenderer);
4755
4018
  function PolygonRenderer() {
4756
- _classCallCheck$3(this, PolygonRenderer);
4757
- return _super.apply(this, arguments);
4019
+ return _DefaultRenderer.apply(this, arguments) || this;
4758
4020
  }
4759
- return _createClass$3(PolygonRenderer);
4021
+ return PolygonRenderer;
4760
4022
  }(DefaultRenderer);
4761
4023
  var PathRenderer = /*#__PURE__*/function (_DefaultRenderer) {
4762
- _inherits$3(PathRenderer, _DefaultRenderer);
4763
- var _super = _createSuper$3(PathRenderer);
4024
+ _inheritsLoose$3(PathRenderer, _DefaultRenderer);
4764
4025
  function PathRenderer() {
4765
- _classCallCheck$3(this, PathRenderer);
4766
- return _super.apply(this, arguments);
4026
+ return _DefaultRenderer.apply(this, arguments) || this;
4767
4027
  }
4768
- return _createClass$3(PathRenderer);
4028
+ return PathRenderer;
4769
4029
  }(DefaultRenderer);
4770
4030
  var Plugin$2 = /*#__PURE__*/function (_AbstractRendererPlug) {
4771
- _inherits$3(Plugin, _AbstractRendererPlug);
4772
- var _super = _createSuper$3(Plugin);
4773
- function Plugin() {
4031
+ _inheritsLoose$3(Plugin, _AbstractRendererPlug);
4032
+ function Plugin(options) {
4774
4033
  var _this;
4775
- var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
4776
- _classCallCheck$3(this, Plugin);
4777
- _this = _super.call(this);
4034
+ if (options === void 0) {
4035
+ options = {};
4036
+ }
4037
+ _this = _AbstractRendererPlug.call(this) || this;
4778
4038
  _this.options = void 0;
4779
4039
  _this.name = 'canvas-renderer';
4780
4040
  _this.options = options;
4781
4041
  return _this;
4782
4042
  }
4783
- _createClass$3(Plugin, [{
4784
- key: "init",
4785
- value: function init() {
4786
- var _defaultStyleRenderer;
4787
- var canvasRendererPluginOptions = _objectSpread2({
4788
- dirtyObjectNumThreshold: 500,
4789
- dirtyObjectRatioThreshold: 0.8
4790
- }, this.options);
4791
- // @ts-ignore
4792
- var imagePool = this.context.imagePool;
4793
- var defaultRenderer = new DefaultRenderer(imagePool);
4794
- var defaultStyleRendererFactory = (_defaultStyleRenderer = {}, _defineProperty$2(_defaultStyleRenderer, gLite.Shape.CIRCLE, defaultRenderer), _defineProperty$2(_defaultStyleRenderer, gLite.Shape.ELLIPSE, defaultRenderer), _defineProperty$2(_defaultStyleRenderer, gLite.Shape.RECT, defaultRenderer), _defineProperty$2(_defaultStyleRenderer, gLite.Shape.IMAGE, new ImageRenderer(imagePool)), _defineProperty$2(_defaultStyleRenderer, gLite.Shape.TEXT, new TextRenderer()), _defineProperty$2(_defaultStyleRenderer, gLite.Shape.LINE, defaultRenderer), _defineProperty$2(_defaultStyleRenderer, gLite.Shape.POLYLINE, defaultRenderer), _defineProperty$2(_defaultStyleRenderer, gLite.Shape.POLYGON, defaultRenderer), _defineProperty$2(_defaultStyleRenderer, gLite.Shape.PATH, defaultRenderer), _defineProperty$2(_defaultStyleRenderer, gLite.Shape.GROUP, undefined), _defineProperty$2(_defaultStyleRenderer, gLite.Shape.HTML, undefined), _defineProperty$2(_defaultStyleRenderer, gLite.Shape.MESH, undefined), _defaultStyleRenderer);
4795
- this.context.defaultStyleRendererFactory = defaultStyleRendererFactory;
4796
- this.context.styleRendererFactory = defaultStyleRendererFactory;
4797
- this.addRenderingPlugin(new CanvasRendererPlugin(canvasRendererPluginOptions));
4798
- }
4799
- }, {
4800
- key: "destroy",
4801
- value: function destroy() {
4802
- this.removeAllRenderingPlugins();
4803
- delete this.context.defaultStyleRendererFactory;
4804
- delete this.context.styleRendererFactory;
4805
- }
4806
- }]);
4043
+ var _proto = Plugin.prototype;
4044
+ _proto.init = function init() {
4045
+ var _defaultStyleRenderer;
4046
+ var canvasRendererPluginOptions = _extends({
4047
+ dirtyObjectNumThreshold: 500,
4048
+ dirtyObjectRatioThreshold: 0.8
4049
+ }, this.options);
4050
+ // @ts-ignore
4051
+ var imagePool = this.context.imagePool;
4052
+ var defaultRenderer = new DefaultRenderer(imagePool);
4053
+ 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);
4054
+ this.context.defaultStyleRendererFactory = defaultStyleRendererFactory;
4055
+ this.context.styleRendererFactory = defaultStyleRendererFactory;
4056
+ this.addRenderingPlugin(new CanvasRendererPlugin(canvasRendererPluginOptions));
4057
+ };
4058
+ _proto.destroy = function destroy() {
4059
+ this.removeAllRenderingPlugins();
4060
+ delete this.context.defaultStyleRendererFactory;
4061
+ delete this.context.styleRendererFactory;
4062
+ };
4807
4063
  return Plugin;
4808
4064
  }(gLite.AbstractRendererPlugin);
4809
4065
 
@@ -4897,7 +4153,7 @@
4897
4153
  if ("throw" !== record.type) {
4898
4154
  var result = record.arg,
4899
4155
  value = result.value;
4900
- return value && "object" == _typeof(value) && hasOwn.call(value, "__await") ? PromiseImpl.resolve(value.__await).then(function (value) {
4156
+ return value && "object" == typeof value && hasOwn.call(value, "__await") ? PromiseImpl.resolve(value.__await).then(function (value) {
4901
4157
  invoke("next", value, resolve, reject);
4902
4158
  }, function (err) {
4903
4159
  invoke("throw", err, resolve, reject);
@@ -5158,49 +4414,10 @@
5158
4414
  });
5159
4415
  };
5160
4416
  }
5161
- function _classCallCheck$4(instance, Constructor) {
5162
- if (!(instance instanceof Constructor)) {
5163
- throw new TypeError("Cannot call a class as a function");
5164
- }
5165
- }
5166
- function _defineProperties$4(target, props) {
5167
- for (var i = 0; i < props.length; i++) {
5168
- var descriptor = props[i];
5169
- descriptor.enumerable = descriptor.enumerable || false;
5170
- descriptor.configurable = true;
5171
- if ("value" in descriptor) descriptor.writable = true;
5172
- Object.defineProperty(target, _toPropertyKey$4(descriptor.key), descriptor);
5173
- }
5174
- }
5175
- function _createClass$4(Constructor, protoProps, staticProps) {
5176
- if (protoProps) _defineProperties$4(Constructor.prototype, protoProps);
5177
- if (staticProps) _defineProperties$4(Constructor, staticProps);
5178
- Object.defineProperty(Constructor, "prototype", {
5179
- writable: false
5180
- });
5181
- return Constructor;
5182
- }
5183
- function _inherits$4(subClass, superClass) {
5184
- if (typeof superClass !== "function" && superClass !== null) {
5185
- throw new TypeError("Super expression must either be null or a function");
5186
- }
5187
- subClass.prototype = Object.create(superClass && superClass.prototype, {
5188
- constructor: {
5189
- value: subClass,
5190
- writable: true,
5191
- configurable: true
5192
- }
5193
- });
5194
- Object.defineProperty(subClass, "prototype", {
5195
- writable: false
5196
- });
5197
- if (superClass) _setPrototypeOf$4(subClass, superClass);
5198
- }
5199
- function _getPrototypeOf$4(o) {
5200
- _getPrototypeOf$4 = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) {
5201
- return o.__proto__ || Object.getPrototypeOf(o);
5202
- };
5203
- return _getPrototypeOf$4(o);
4417
+ function _inheritsLoose$4(subClass, superClass) {
4418
+ subClass.prototype = Object.create(superClass.prototype);
4419
+ subClass.prototype.constructor = subClass;
4420
+ _setPrototypeOf$4(subClass, superClass);
5204
4421
  }
5205
4422
  function _setPrototypeOf$4(o, p) {
5206
4423
  _setPrototypeOf$4 = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) {
@@ -5209,59 +4426,6 @@
5209
4426
  };
5210
4427
  return _setPrototypeOf$4(o, p);
5211
4428
  }
5212
- function _isNativeReflectConstruct$4() {
5213
- if (typeof Reflect === "undefined" || !Reflect.construct) return false;
5214
- if (Reflect.construct.sham) return false;
5215
- if (typeof Proxy === "function") return true;
5216
- try {
5217
- Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {}));
5218
- return true;
5219
- } catch (e) {
5220
- return false;
5221
- }
5222
- }
5223
- function _assertThisInitialized$4(self) {
5224
- if (self === void 0) {
5225
- throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
5226
- }
5227
- return self;
5228
- }
5229
- function _possibleConstructorReturn$4(self, call) {
5230
- if (call && (_typeof(call) === "object" || typeof call === "function")) {
5231
- return call;
5232
- } else if (call !== void 0) {
5233
- throw new TypeError("Derived constructors may only return object or undefined");
5234
- }
5235
- return _assertThisInitialized$4(self);
5236
- }
5237
- function _createSuper$4(Derived) {
5238
- var hasNativeReflectConstruct = _isNativeReflectConstruct$4();
5239
- return function _createSuperInternal() {
5240
- var Super = _getPrototypeOf$4(Derived),
5241
- result;
5242
- if (hasNativeReflectConstruct) {
5243
- var NewTarget = _getPrototypeOf$4(this).constructor;
5244
- result = Reflect.construct(Super, arguments, NewTarget);
5245
- } else {
5246
- result = Super.apply(this, arguments);
5247
- }
5248
- return _possibleConstructorReturn$4(this, result);
5249
- };
5250
- }
5251
- function _toPrimitive$4(input, hint) {
5252
- if (_typeof(input) !== "object" || input === null) return input;
5253
- var prim = input[Symbol.toPrimitive];
5254
- if (prim !== undefined) {
5255
- var res = prim.call(input, hint || "default");
5256
- if (_typeof(res) !== "object") return res;
5257
- throw new TypeError("@@toPrimitive must return a primitive value.");
5258
- }
5259
- return (hint === "string" ? String : Number)(input);
5260
- }
5261
- function _toPropertyKey$4(arg) {
5262
- var key = _toPrimitive$4(arg, "string");
5263
- return _typeof(key) === "symbol" ? key : String(key);
5264
- }
5265
4429
 
5266
4430
  // const MOBILE_REGEX = /mobile|tablet|ip(ad|hone|od)|android/i;
5267
4431
  /**
@@ -5269,165 +4433,156 @@
5269
4433
  */
5270
4434
  var DOMInteractionPlugin = /*#__PURE__*/function () {
5271
4435
  function DOMInteractionPlugin() {
5272
- _classCallCheck$4(this, DOMInteractionPlugin);
5273
4436
  this.context = void 0;
5274
4437
  }
5275
- _createClass$4(DOMInteractionPlugin, [{
5276
- key: "apply",
5277
- value: function apply(context) {
5278
- var _this = this;
5279
- var renderingService = context.renderingService,
5280
- renderingContext = context.renderingContext;
5281
- this.context = context;
5282
- var canvas = renderingContext.root.ownerDocument.defaultView;
5283
- // const SUPPORT_ONLY_TOUCH = canvas.supportsTouchEvents && MOBILE_REGEX.test(navigator.userAgent);
5284
- var onPointerMove = function onPointerMove(ev) {
5285
- renderingService.hooks.pointerMove.call(ev);
5286
- };
5287
- var onPointerUp = function onPointerUp(ev) {
5288
- renderingService.hooks.pointerUp.call(ev);
5289
- };
5290
- var onPointerDown = function onPointerDown(ev) {
5291
- renderingService.hooks.pointerDown.call(ev);
5292
- };
5293
- var onPointerOver = function onPointerOver(ev) {
5294
- renderingService.hooks.pointerOver.call(ev);
5295
- };
5296
- var onPointerOut = function onPointerOut(ev) {
5297
- renderingService.hooks.pointerOut.call(ev);
5298
- };
5299
- var onPointerCancel = function onPointerCancel(ev) {
5300
- renderingService.hooks.pointerCancel.call(ev);
5301
- };
5302
- var onPointerWheel = function onPointerWheel(ev) {
5303
- renderingService.hooks.pointerWheel.call(ev);
5304
- };
5305
- var addPointerEventListener = function addPointerEventListener($el) {
5306
- globalThis.document.addEventListener('pointermove', onPointerMove, true);
5307
- $el.addEventListener('pointerdown', onPointerDown, true);
5308
- $el.addEventListener('pointerleave', onPointerOut, true);
5309
- $el.addEventListener('pointerover', onPointerOver, true);
5310
- globalThis.addEventListener('pointerup', onPointerUp, true);
5311
- };
5312
- var addTouchEventListener = function addTouchEventListener($el) {
5313
- $el.addEventListener('touchstart', onPointerDown, true);
5314
- $el.addEventListener('touchend', onPointerUp, true);
5315
- $el.addEventListener('touchmove', onPointerMove, true);
5316
- $el.addEventListener('touchcancel', onPointerCancel, true);
5317
- };
5318
- var addMouseEventListener = function addMouseEventListener($el) {
5319
- globalThis.document.addEventListener('mousemove', onPointerMove, true);
5320
- $el.addEventListener('mousedown', onPointerDown, true);
5321
- $el.addEventListener('mouseout', onPointerOut, true);
5322
- $el.addEventListener('mouseover', onPointerOver, true);
5323
- globalThis.addEventListener('mouseup', onPointerUp, true);
5324
- };
5325
- var removePointerEventListener = function removePointerEventListener($el) {
5326
- globalThis.document.removeEventListener('pointermove', onPointerMove, true);
5327
- $el.removeEventListener('pointerdown', onPointerDown, true);
5328
- $el.removeEventListener('pointerleave', onPointerOut, true);
5329
- $el.removeEventListener('pointerover', onPointerOver, true);
5330
- globalThis.removeEventListener('pointerup', onPointerUp, true);
5331
- };
5332
- var removeTouchEventListener = function removeTouchEventListener($el) {
5333
- $el.removeEventListener('touchstart', onPointerDown, true);
5334
- $el.removeEventListener('touchend', onPointerUp, true);
5335
- $el.removeEventListener('touchmove', onPointerMove, true);
5336
- $el.removeEventListener('touchcancel', onPointerCancel, true);
5337
- };
5338
- var removeMouseEventListener = function removeMouseEventListener($el) {
5339
- globalThis.document.removeEventListener('mousemove', onPointerMove, true);
5340
- $el.removeEventListener('mousedown', onPointerDown, true);
5341
- $el.removeEventListener('mouseout', onPointerOut, true);
5342
- $el.removeEventListener('mouseover', onPointerOver, true);
5343
- globalThis.removeEventListener('mouseup', onPointerUp, true);
5344
- };
5345
- renderingService.hooks.init.tapPromise(DOMInteractionPlugin.tag, /*#__PURE__*/_asyncToGenerator$3( /*#__PURE__*/_regeneratorRuntime$3().mark(function _callee() {
5346
- var $el;
5347
- return _regeneratorRuntime$3().wrap(function _callee$(_context) {
5348
- while (1) {
5349
- switch (_context.prev = _context.next) {
5350
- case 0:
5351
- $el = _this.context.contextService.getDomElement(); // @ts-ignore
5352
- if (globalThis.navigator.msPointerEnabled) {
5353
- // @ts-ignore
5354
- $el.style.msContentZooming = 'none';
5355
- // @ts-ignore
5356
- $el.style.msTouchAction = 'none';
5357
- } else if (canvas.supportsPointerEvents) {
5358
- $el.style.touchAction = 'none';
5359
- }
5360
- if (canvas.supportsPointerEvents) {
5361
- addPointerEventListener($el);
5362
- } else {
5363
- addMouseEventListener($el);
5364
- }
5365
- if (canvas.supportsTouchEvents) {
5366
- addTouchEventListener($el);
5367
- }
5368
- // use passive event listeners
5369
- // @see https://zhuanlan.zhihu.com/p/24555031
5370
- $el.addEventListener('wheel', onPointerWheel, {
5371
- passive: true,
5372
- capture: true
5373
- });
5374
- case 5:
5375
- case "end":
5376
- return _context.stop();
5377
- }
4438
+ var _proto = DOMInteractionPlugin.prototype;
4439
+ _proto.apply = function apply(context) {
4440
+ var _this = this;
4441
+ var renderingService = context.renderingService,
4442
+ renderingContext = context.renderingContext;
4443
+ this.context = context;
4444
+ var canvas = renderingContext.root.ownerDocument.defaultView;
4445
+ // const SUPPORT_ONLY_TOUCH = canvas.supportsTouchEvents && MOBILE_REGEX.test(navigator.userAgent);
4446
+ var onPointerMove = function onPointerMove(ev) {
4447
+ renderingService.hooks.pointerMove.call(ev);
4448
+ };
4449
+ var onPointerUp = function onPointerUp(ev) {
4450
+ renderingService.hooks.pointerUp.call(ev);
4451
+ };
4452
+ var onPointerDown = function onPointerDown(ev) {
4453
+ renderingService.hooks.pointerDown.call(ev);
4454
+ };
4455
+ var onPointerOver = function onPointerOver(ev) {
4456
+ renderingService.hooks.pointerOver.call(ev);
4457
+ };
4458
+ var onPointerOut = function onPointerOut(ev) {
4459
+ renderingService.hooks.pointerOut.call(ev);
4460
+ };
4461
+ var onPointerCancel = function onPointerCancel(ev) {
4462
+ renderingService.hooks.pointerCancel.call(ev);
4463
+ };
4464
+ var onPointerWheel = function onPointerWheel(ev) {
4465
+ renderingService.hooks.pointerWheel.call(ev);
4466
+ };
4467
+ var addPointerEventListener = function addPointerEventListener($el) {
4468
+ gLite.runtime.globalThis.document.addEventListener('pointermove', onPointerMove, true);
4469
+ $el.addEventListener('pointerdown', onPointerDown, true);
4470
+ $el.addEventListener('pointerleave', onPointerOut, true);
4471
+ $el.addEventListener('pointerover', onPointerOver, true);
4472
+ gLite.runtime.globalThis.addEventListener('pointerup', onPointerUp, true);
4473
+ };
4474
+ var addTouchEventListener = function addTouchEventListener($el) {
4475
+ $el.addEventListener('touchstart', onPointerDown, true);
4476
+ $el.addEventListener('touchend', onPointerUp, true);
4477
+ $el.addEventListener('touchmove', onPointerMove, true);
4478
+ $el.addEventListener('touchcancel', onPointerCancel, true);
4479
+ };
4480
+ var addMouseEventListener = function addMouseEventListener($el) {
4481
+ gLite.runtime.globalThis.document.addEventListener('mousemove', onPointerMove, true);
4482
+ $el.addEventListener('mousedown', onPointerDown, true);
4483
+ $el.addEventListener('mouseout', onPointerOut, true);
4484
+ $el.addEventListener('mouseover', onPointerOver, true);
4485
+ gLite.runtime.globalThis.addEventListener('mouseup', onPointerUp, true);
4486
+ };
4487
+ var removePointerEventListener = function removePointerEventListener($el) {
4488
+ gLite.runtime.globalThis.document.removeEventListener('pointermove', onPointerMove, true);
4489
+ $el.removeEventListener('pointerdown', onPointerDown, true);
4490
+ $el.removeEventListener('pointerleave', onPointerOut, true);
4491
+ $el.removeEventListener('pointerover', onPointerOver, true);
4492
+ gLite.runtime.globalThis.removeEventListener('pointerup', onPointerUp, true);
4493
+ };
4494
+ var removeTouchEventListener = function removeTouchEventListener($el) {
4495
+ $el.removeEventListener('touchstart', onPointerDown, true);
4496
+ $el.removeEventListener('touchend', onPointerUp, true);
4497
+ $el.removeEventListener('touchmove', onPointerMove, true);
4498
+ $el.removeEventListener('touchcancel', onPointerCancel, true);
4499
+ };
4500
+ var removeMouseEventListener = function removeMouseEventListener($el) {
4501
+ gLite.runtime.globalThis.document.removeEventListener('mousemove', onPointerMove, true);
4502
+ $el.removeEventListener('mousedown', onPointerDown, true);
4503
+ $el.removeEventListener('mouseout', onPointerOut, true);
4504
+ $el.removeEventListener('mouseover', onPointerOver, true);
4505
+ gLite.runtime.globalThis.removeEventListener('mouseup', onPointerUp, true);
4506
+ };
4507
+ renderingService.hooks.init.tapPromise(DOMInteractionPlugin.tag, /*#__PURE__*/_asyncToGenerator$3( /*#__PURE__*/_regeneratorRuntime$3().mark(function _callee() {
4508
+ var $el;
4509
+ return _regeneratorRuntime$3().wrap(function _callee$(_context) {
4510
+ while (1) {
4511
+ switch (_context.prev = _context.next) {
4512
+ case 0:
4513
+ $el = _this.context.contextService.getDomElement(); // @ts-ignore
4514
+ if (gLite.runtime.globalThis.navigator.msPointerEnabled) {
4515
+ // @ts-ignore
4516
+ $el.style.msContentZooming = 'none';
4517
+ // @ts-ignore
4518
+ $el.style.msTouchAction = 'none';
4519
+ } else if (canvas.supportsPointerEvents) {
4520
+ $el.style.touchAction = 'none';
4521
+ }
4522
+ if (canvas.supportsPointerEvents) {
4523
+ addPointerEventListener($el);
4524
+ } else {
4525
+ addMouseEventListener($el);
4526
+ }
4527
+ if (canvas.supportsTouchEvents) {
4528
+ addTouchEventListener($el);
4529
+ }
4530
+ // use passive event listeners
4531
+ // @see https://zhuanlan.zhihu.com/p/24555031
4532
+ $el.addEventListener('wheel', onPointerWheel, {
4533
+ passive: true,
4534
+ capture: true
4535
+ });
4536
+ case 5:
4537
+ case "end":
4538
+ return _context.stop();
5378
4539
  }
5379
- }, _callee);
5380
- })));
5381
- renderingService.hooks.destroy.tap(DOMInteractionPlugin.tag, function () {
5382
- var $el = _this.context.contextService.getDomElement();
5383
- // @ts-ignore
5384
- if (globalThis.navigator.msPointerEnabled) {
5385
- // @ts-ignore
5386
- $el.style.msContentZooming = '';
5387
- // @ts-ignore
5388
- $el.style.msTouchAction = '';
5389
- } else if (canvas.supportsPointerEvents) {
5390
- $el.style.touchAction = '';
5391
4540
  }
5392
- if (canvas.supportsPointerEvents) {
5393
- removePointerEventListener($el);
5394
- } else {
5395
- removeMouseEventListener($el);
5396
- }
5397
- if (canvas.supportsTouchEvents) {
5398
- removeTouchEventListener($el);
5399
- }
5400
- $el.removeEventListener('wheel', onPointerWheel, true);
5401
- });
5402
- }
5403
- }]);
4541
+ }, _callee);
4542
+ })));
4543
+ renderingService.hooks.destroy.tap(DOMInteractionPlugin.tag, function () {
4544
+ var $el = _this.context.contextService.getDomElement();
4545
+ // @ts-ignore
4546
+ if (gLite.runtime.globalThis.navigator.msPointerEnabled) {
4547
+ // @ts-ignore
4548
+ $el.style.msContentZooming = '';
4549
+ // @ts-ignore
4550
+ $el.style.msTouchAction = '';
4551
+ } else if (canvas.supportsPointerEvents) {
4552
+ $el.style.touchAction = '';
4553
+ }
4554
+ if (canvas.supportsPointerEvents) {
4555
+ removePointerEventListener($el);
4556
+ } else {
4557
+ removeMouseEventListener($el);
4558
+ }
4559
+ if (canvas.supportsTouchEvents) {
4560
+ removeTouchEventListener($el);
4561
+ }
4562
+ $el.removeEventListener('wheel', onPointerWheel, true);
4563
+ });
4564
+ };
5404
4565
  return DOMInteractionPlugin;
5405
4566
  }();
5406
4567
  DOMInteractionPlugin.tag = 'DOMInteraction';
5407
4568
  var Plugin$3 = /*#__PURE__*/function (_AbstractRendererPlug) {
5408
- _inherits$4(Plugin, _AbstractRendererPlug);
5409
- var _super = _createSuper$4(Plugin);
4569
+ _inheritsLoose$4(Plugin, _AbstractRendererPlug);
5410
4570
  function Plugin() {
5411
4571
  var _this;
5412
- _classCallCheck$4(this, Plugin);
5413
4572
  for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
5414
4573
  args[_key] = arguments[_key];
5415
4574
  }
5416
- _this = _super.call.apply(_super, [this].concat(args));
4575
+ _this = _AbstractRendererPlug.call.apply(_AbstractRendererPlug, [this].concat(args)) || this;
5417
4576
  _this.name = 'dom-interaction';
5418
4577
  return _this;
5419
4578
  }
5420
- _createClass$4(Plugin, [{
5421
- key: "init",
5422
- value: function init() {
5423
- this.addRenderingPlugin(new DOMInteractionPlugin());
5424
- }
5425
- }, {
5426
- key: "destroy",
5427
- value: function destroy() {
5428
- this.removeAllRenderingPlugins();
5429
- }
5430
- }]);
4579
+ var _proto = Plugin.prototype;
4580
+ _proto.init = function init() {
4581
+ this.addRenderingPlugin(new DOMInteractionPlugin());
4582
+ };
4583
+ _proto.destroy = function destroy() {
4584
+ this.removeAllRenderingPlugins();
4585
+ };
5431
4586
  return Plugin;
5432
4587
  }(gLite.AbstractRendererPlugin);
5433
4588
 
@@ -5512,7 +4667,7 @@
5512
4667
  if ("throw" !== record.type) {
5513
4668
  var result = record.arg,
5514
4669
  value = result.value;
5515
- return value && "object" == _typeof(value) && hasOwn.call(value, "__await") ? PromiseImpl.resolve(value.__await).then(function (value) {
4670
+ return value && "object" == typeof value && hasOwn.call(value, "__await") ? PromiseImpl.resolve(value.__await).then(function (value) {
5516
4671
  invoke("next", value, resolve, reject);
5517
4672
  }, function (err) {
5518
4673
  invoke("throw", err, resolve, reject);
@@ -5773,49 +4928,10 @@
5773
4928
  });
5774
4929
  };
5775
4930
  }
5776
- function _classCallCheck$5(instance, Constructor) {
5777
- if (!(instance instanceof Constructor)) {
5778
- throw new TypeError("Cannot call a class as a function");
5779
- }
5780
- }
5781
- function _defineProperties$5(target, props) {
5782
- for (var i = 0; i < props.length; i++) {
5783
- var descriptor = props[i];
5784
- descriptor.enumerable = descriptor.enumerable || false;
5785
- descriptor.configurable = true;
5786
- if ("value" in descriptor) descriptor.writable = true;
5787
- Object.defineProperty(target, _toPropertyKey$5(descriptor.key), descriptor);
5788
- }
5789
- }
5790
- function _createClass$5(Constructor, protoProps, staticProps) {
5791
- if (protoProps) _defineProperties$5(Constructor.prototype, protoProps);
5792
- if (staticProps) _defineProperties$5(Constructor, staticProps);
5793
- Object.defineProperty(Constructor, "prototype", {
5794
- writable: false
5795
- });
5796
- return Constructor;
5797
- }
5798
- function _inherits$5(subClass, superClass) {
5799
- if (typeof superClass !== "function" && superClass !== null) {
5800
- throw new TypeError("Super expression must either be null or a function");
5801
- }
5802
- subClass.prototype = Object.create(superClass && superClass.prototype, {
5803
- constructor: {
5804
- value: subClass,
5805
- writable: true,
5806
- configurable: true
5807
- }
5808
- });
5809
- Object.defineProperty(subClass, "prototype", {
5810
- writable: false
5811
- });
5812
- if (superClass) _setPrototypeOf$5(subClass, superClass);
5813
- }
5814
- function _getPrototypeOf$5(o) {
5815
- _getPrototypeOf$5 = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) {
5816
- return o.__proto__ || Object.getPrototypeOf(o);
5817
- };
5818
- return _getPrototypeOf$5(o);
4931
+ function _inheritsLoose$5(subClass, superClass) {
4932
+ subClass.prototype = Object.create(superClass.prototype);
4933
+ subClass.prototype.constructor = subClass;
4934
+ _setPrototypeOf$5(subClass, superClass);
5819
4935
  }
5820
4936
  function _setPrototypeOf$5(o, p) {
5821
4937
  _setPrototypeOf$5 = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) {
@@ -5824,358 +4940,286 @@
5824
4940
  };
5825
4941
  return _setPrototypeOf$5(o, p);
5826
4942
  }
5827
- function _isNativeReflectConstruct$5() {
5828
- if (typeof Reflect === "undefined" || !Reflect.construct) return false;
5829
- if (Reflect.construct.sham) return false;
5830
- if (typeof Proxy === "function") return true;
5831
- try {
5832
- Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {}));
5833
- return true;
5834
- } catch (e) {
5835
- return false;
5836
- }
5837
- }
5838
- function _assertThisInitialized$5(self) {
5839
- if (self === void 0) {
5840
- throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
5841
- }
5842
- return self;
5843
- }
5844
- function _possibleConstructorReturn$5(self, call) {
5845
- if (call && (_typeof(call) === "object" || typeof call === "function")) {
5846
- return call;
5847
- } else if (call !== void 0) {
5848
- throw new TypeError("Derived constructors may only return object or undefined");
5849
- }
5850
- return _assertThisInitialized$5(self);
5851
- }
5852
- function _createSuper$5(Derived) {
5853
- var hasNativeReflectConstruct = _isNativeReflectConstruct$5();
5854
- return function _createSuperInternal() {
5855
- var Super = _getPrototypeOf$5(Derived),
5856
- result;
5857
- if (hasNativeReflectConstruct) {
5858
- var NewTarget = _getPrototypeOf$5(this).constructor;
5859
- result = Reflect.construct(Super, arguments, NewTarget);
5860
- } else {
5861
- result = Super.apply(this, arguments);
5862
- }
5863
- return _possibleConstructorReturn$5(this, result);
5864
- };
5865
- }
5866
- function _toPrimitive$5(input, hint) {
5867
- if (_typeof(input) !== "object" || input === null) return input;
5868
- var prim = input[Symbol.toPrimitive];
5869
- if (prim !== undefined) {
5870
- var res = prim.call(input, hint || "default");
5871
- if (_typeof(res) !== "object") return res;
5872
- throw new TypeError("@@toPrimitive must return a primitive value.");
5873
- }
5874
- return (hint === "string" ? String : Number)(input);
5875
- }
5876
- function _toPropertyKey$5(arg) {
5877
- var key = _toPrimitive$5(arg, "string");
5878
- return _typeof(key) === "symbol" ? key : String(key);
5879
- }
5880
4943
  var HTML_PREFIX = 'g-html-';
5881
4944
  var CANVAS_CAMERA_ID = 'g-canvas-camera';
5882
4945
  var HTMLRenderingPlugin = /*#__PURE__*/function () {
5883
4946
  function HTMLRenderingPlugin() {
5884
- _classCallCheck$5(this, HTMLRenderingPlugin);
5885
4947
  this.context = void 0;
5886
4948
  this.$camera = void 0;
5887
4949
  }
5888
- _createClass$5(HTMLRenderingPlugin, [{
5889
- key: "joinTransformMatrix",
5890
- value: function joinTransformMatrix(matrix) {
5891
- return "matrix(".concat([matrix[0], matrix[1], matrix[4], matrix[5], matrix[12], matrix[13]].join(','), ")");
5892
- }
5893
- }, {
5894
- key: "apply",
5895
- value: function apply(context) {
5896
- var _this = this;
5897
- var camera = context.camera,
5898
- renderingContext = context.renderingContext,
5899
- renderingService = context.renderingService,
5900
- displayObjectPool = context.displayObjectPool;
5901
- this.context = context;
5902
- var canvas = renderingContext.root.ownerDocument.defaultView;
5903
- var setTransform = function setTransform(object, $el) {
5904
- $el.style.transform = _this.joinTransformMatrix(object.getWorldTransform());
5905
- };
5906
- var handleMounted = function handleMounted(e) {
5907
- var object = e.target;
5908
- if (object.nodeName === gLite.Shape.HTML) {
5909
- if (!_this.$camera) {
5910
- _this.$camera = _this.createCamera(camera);
5911
- }
5912
- // create DOM element
5913
- var $el = _this.getOrCreateEl(object);
5914
- _this.$camera.appendChild($el);
5915
- // apply documentElement's style
5916
- var attributes = object.ownerDocument.documentElement.attributes;
5917
- Object.keys(attributes).forEach(function (name) {
5918
- $el.style[name] = attributes[name];
5919
- });
5920
- Object.keys(object.attributes).forEach(function (name) {
5921
- _this.updateAttribute(name, object);
5922
- });
5923
- setTransform(object, $el);
4950
+ var _proto = HTMLRenderingPlugin.prototype;
4951
+ _proto.joinTransformMatrix = function joinTransformMatrix(matrix) {
4952
+ return "matrix(" + [matrix[0], matrix[1], matrix[4], matrix[5], matrix[12], matrix[13]].join(',') + ")";
4953
+ };
4954
+ _proto.apply = function apply(context) {
4955
+ var _this = this;
4956
+ var camera = context.camera,
4957
+ renderingContext = context.renderingContext,
4958
+ renderingService = context.renderingService,
4959
+ displayObjectPool = context.displayObjectPool;
4960
+ this.context = context;
4961
+ var canvas = renderingContext.root.ownerDocument.defaultView;
4962
+ var setTransform = function setTransform(object, $el) {
4963
+ $el.style.transform = _this.joinTransformMatrix(object.getWorldTransform());
4964
+ };
4965
+ var handleMounted = function handleMounted(e) {
4966
+ var object = e.target;
4967
+ if (object.nodeName === gLite.Shape.HTML) {
4968
+ if (!_this.$camera) {
4969
+ _this.$camera = _this.createCamera(camera);
5924
4970
  }
5925
- };
5926
- var handleUnmounted = function handleUnmounted(e) {
5927
- var object = e.target;
5928
- if (object.nodeName === gLite.Shape.HTML && _this.$camera) {
5929
- var $el = _this.getOrCreateEl(object);
5930
- if ($el) {
5931
- $el.remove();
5932
- }
5933
- // const existedId = this.getId(object);
5934
- // const $existedElement: HTMLElement | null = this.$camera.querySelector('#' + existedId);
5935
- // if ($existedElement) {
5936
- // this.$camera.removeChild($existedElement);
5937
- // }
4971
+ // create DOM element
4972
+ var $el = _this.getOrCreateEl(object);
4973
+ _this.$camera.appendChild($el);
4974
+ // apply documentElement's style
4975
+ var attributes = object.ownerDocument.documentElement.attributes;
4976
+ Object.keys(attributes).forEach(function (name) {
4977
+ $el.style[name] = attributes[name];
4978
+ });
4979
+ Object.keys(object.attributes).forEach(function (name) {
4980
+ _this.updateAttribute(name, object);
4981
+ });
4982
+ setTransform(object, $el);
4983
+ }
4984
+ };
4985
+ var handleUnmounted = function handleUnmounted(e) {
4986
+ var object = e.target;
4987
+ if (object.nodeName === gLite.Shape.HTML && _this.$camera) {
4988
+ var $el = _this.getOrCreateEl(object);
4989
+ if ($el) {
4990
+ $el.remove();
5938
4991
  }
5939
- };
4992
+ // const existedId = this.getId(object);
4993
+ // const $existedElement: HTMLElement | null = this.$camera.querySelector('#' + existedId);
4994
+ // if ($existedElement) {
4995
+ // this.$camera.removeChild($existedElement);
4996
+ // }
4997
+ }
4998
+ };
5940
4999
 
5941
- var handleAttributeChanged = function handleAttributeChanged(e) {
5942
- var object = e.target;
5943
- if (object.nodeName === gLite.Shape.HTML) {
5944
- var attrName = e.attrName;
5945
- _this.updateAttribute(attrName, object);
5946
- }
5947
- };
5948
- var handleBoundsChanged = function handleBoundsChanged(e) {
5949
- var object = e.target;
5950
- if (object.nodeName === gLite.Shape.HTML) {
5951
- var $el = _this.getOrCreateEl(object);
5952
- setTransform(object, $el);
5953
- }
5954
- };
5955
- var handleCanvasResize = function handleCanvasResize() {
5956
- if (_this.$camera) {
5957
- var _this$context$config = _this.context.config,
5958
- width = _this$context$config.width,
5959
- height = _this$context$config.height;
5960
- _this.$camera.style.width = "".concat(width || 0, "px");
5961
- _this.$camera.style.height = "".concat(height || 0, "px");
5962
- }
5963
- };
5964
- renderingService.hooks.init.tapPromise(HTMLRenderingPlugin.tag, /*#__PURE__*/_asyncToGenerator$4( /*#__PURE__*/_regeneratorRuntime$4().mark(function _callee() {
5965
- return _regeneratorRuntime$4().wrap(function _callee$(_context) {
5966
- while (1) {
5967
- switch (_context.prev = _context.next) {
5968
- case 0:
5969
- if (displayObjectPool.getHTMLs().length) {
5970
- // append camera
5971
- _this.$camera = _this.createCamera(camera);
5972
- }
5973
- canvas.addEventListener(gLite.CanvasEvent.RESIZE, handleCanvasResize);
5974
- canvas.addEventListener(gLite.ElementEvent.MOUNTED, handleMounted);
5975
- canvas.addEventListener(gLite.ElementEvent.UNMOUNTED, handleUnmounted);
5976
- canvas.addEventListener(gLite.ElementEvent.ATTR_MODIFIED, handleAttributeChanged);
5977
- canvas.addEventListener(gLite.ElementEvent.BOUNDS_CHANGED, handleBoundsChanged);
5978
- case 6:
5979
- case "end":
5980
- return _context.stop();
5981
- }
5000
+ var handleAttributeChanged = function handleAttributeChanged(e) {
5001
+ var object = e.target;
5002
+ if (object.nodeName === gLite.Shape.HTML) {
5003
+ var attrName = e.attrName;
5004
+ _this.updateAttribute(attrName, object);
5005
+ }
5006
+ };
5007
+ var handleBoundsChanged = function handleBoundsChanged(e) {
5008
+ var object = e.target;
5009
+ if (object.nodeName === gLite.Shape.HTML) {
5010
+ var $el = _this.getOrCreateEl(object);
5011
+ setTransform(object, $el);
5012
+ }
5013
+ };
5014
+ var handleCanvasResize = function handleCanvasResize() {
5015
+ if (_this.$camera) {
5016
+ var _this$context$config = _this.context.config,
5017
+ width = _this$context$config.width,
5018
+ height = _this$context$config.height;
5019
+ _this.$camera.style.width = (width || 0) + "px";
5020
+ _this.$camera.style.height = (height || 0) + "px";
5021
+ }
5022
+ };
5023
+ renderingService.hooks.init.tapPromise(HTMLRenderingPlugin.tag, /*#__PURE__*/_asyncToGenerator$4( /*#__PURE__*/_regeneratorRuntime$4().mark(function _callee() {
5024
+ return _regeneratorRuntime$4().wrap(function _callee$(_context) {
5025
+ while (1) {
5026
+ switch (_context.prev = _context.next) {
5027
+ case 0:
5028
+ if (displayObjectPool.getHTMLs().length) {
5029
+ // append camera
5030
+ _this.$camera = _this.createCamera(camera);
5031
+ }
5032
+ canvas.addEventListener(gLite.CanvasEvent.RESIZE, handleCanvasResize);
5033
+ canvas.addEventListener(gLite.ElementEvent.MOUNTED, handleMounted);
5034
+ canvas.addEventListener(gLite.ElementEvent.UNMOUNTED, handleUnmounted);
5035
+ canvas.addEventListener(gLite.ElementEvent.ATTR_MODIFIED, handleAttributeChanged);
5036
+ canvas.addEventListener(gLite.ElementEvent.BOUNDS_CHANGED, handleBoundsChanged);
5037
+ case 6:
5038
+ case "end":
5039
+ return _context.stop();
5982
5040
  }
5983
- }, _callee);
5984
- })));
5985
- renderingService.hooks.endFrame.tap(HTMLRenderingPlugin.tag, function () {
5986
- if (_this.$camera && renderingContext.renderReasons.has(gLite.RenderReason.CAMERA_CHANGED)) {
5987
- _this.$camera.style.transform = _this.joinTransformMatrix(camera.getOrthoMatrix());
5988
- }
5989
- });
5990
- renderingService.hooks.destroy.tap(HTMLRenderingPlugin.tag, function () {
5991
- // remove camera
5992
- if (_this.$camera) {
5993
- _this.$camera.remove();
5994
5041
  }
5995
- canvas.removeEventListener(gLite.CanvasEvent.RESIZE, handleCanvasResize);
5996
- canvas.removeEventListener(gLite.ElementEvent.MOUNTED, handleMounted);
5997
- canvas.removeEventListener(gLite.ElementEvent.UNMOUNTED, handleUnmounted);
5998
- canvas.removeEventListener(gLite.ElementEvent.ATTR_MODIFIED, handleAttributeChanged);
5999
- canvas.removeEventListener(gLite.ElementEvent.BOUNDS_CHANGED, handleBoundsChanged);
6000
- });
5042
+ }, _callee);
5043
+ })));
5044
+ renderingService.hooks.endFrame.tap(HTMLRenderingPlugin.tag, function () {
5045
+ if (_this.$camera && renderingContext.renderReasons.has(gLite.RenderReason.CAMERA_CHANGED)) {
5046
+ _this.$camera.style.transform = _this.joinTransformMatrix(camera.getOrthoMatrix());
5047
+ }
5048
+ });
5049
+ renderingService.hooks.destroy.tap(HTMLRenderingPlugin.tag, function () {
5050
+ // remove camera
5051
+ if (_this.$camera) {
5052
+ _this.$camera.remove();
5053
+ }
5054
+ canvas.removeEventListener(gLite.CanvasEvent.RESIZE, handleCanvasResize);
5055
+ canvas.removeEventListener(gLite.ElementEvent.MOUNTED, handleMounted);
5056
+ canvas.removeEventListener(gLite.ElementEvent.UNMOUNTED, handleUnmounted);
5057
+ canvas.removeEventListener(gLite.ElementEvent.ATTR_MODIFIED, handleAttributeChanged);
5058
+ canvas.removeEventListener(gLite.ElementEvent.BOUNDS_CHANGED, handleBoundsChanged);
5059
+ });
5060
+ };
5061
+ _proto.getId = function getId(object) {
5062
+ return object.id || HTML_PREFIX + object.entity;
5063
+ };
5064
+ _proto.createCamera = function createCamera(camera) {
5065
+ var _this$context$config2 = this.context.config,
5066
+ doc = _this$context$config2.document,
5067
+ width = _this$context$config2.width,
5068
+ height = _this$context$config2.height;
5069
+ var $canvas = this.context.contextService.getDomElement();
5070
+ var $container = $canvas.parentNode;
5071
+ if ($container) {
5072
+ var cameraId = CANVAS_CAMERA_ID;
5073
+ var $existedCamera = $container.querySelector('#' + cameraId);
5074
+ if (!$existedCamera) {
5075
+ var $camera = (doc || document).createElement('div');
5076
+ $existedCamera = $camera;
5077
+ $camera.id = cameraId;
5078
+ // use absolute position
5079
+ $camera.style.position = 'absolute';
5080
+ // account for DOM element's offset @see https://github.com/antvis/G/issues/1150
5081
+ $camera.style.left = ($canvas.offsetLeft || 0) + "px";
5082
+ $camera.style.top = ($canvas.offsetTop || 0) + "px";
5083
+ $camera.style.transformOrigin = 'left top';
5084
+ $camera.style.transform = this.joinTransformMatrix(camera.getOrthoMatrix());
5085
+ // HTML elements should not overflow with canvas @see https://github.com/antvis/G/issues/1163
5086
+ $camera.style.overflow = 'hidden';
5087
+ $camera.style.pointerEvents = 'none';
5088
+ $camera.style.width = (width || 0) + "px";
5089
+ $camera.style.height = (height || 0) + "px";
5090
+ $container.appendChild($camera);
5091
+ }
5092
+ return $existedCamera;
6001
5093
  }
6002
- }, {
6003
- key: "getId",
6004
- value: function getId(object) {
6005
- return object.id || HTML_PREFIX + object.entity;
6006
- }
6007
- }, {
6008
- key: "createCamera",
6009
- value: function createCamera(camera) {
6010
- var _this$context$config2 = this.context.config,
6011
- doc = _this$context$config2.document,
6012
- width = _this$context$config2.width,
6013
- height = _this$context$config2.height;
6014
- var $canvas = this.context.contextService.getDomElement();
6015
- var $container = $canvas.parentNode;
6016
- if ($container) {
6017
- var cameraId = CANVAS_CAMERA_ID;
6018
- var $existedCamera = $container.querySelector('#' + cameraId);
6019
- if (!$existedCamera) {
6020
- var $camera = (doc || document).createElement('div');
6021
- $existedCamera = $camera;
6022
- $camera.id = cameraId;
6023
- // use absolute position
6024
- $camera.style.position = 'absolute';
6025
- // account for DOM element's offset @see https://github.com/antvis/G/issues/1150
6026
- $camera.style.left = "".concat($canvas.offsetLeft || 0, "px");
6027
- $camera.style.top = "".concat($canvas.offsetTop || 0, "px");
6028
- $camera.style.transformOrigin = 'left top';
6029
- $camera.style.transform = this.joinTransformMatrix(camera.getOrthoMatrix());
6030
- // HTML elements should not overflow with canvas @see https://github.com/antvis/G/issues/1163
6031
- $camera.style.overflow = 'hidden';
6032
- $camera.style.pointerEvents = 'none';
6033
- $camera.style.width = "".concat(width || 0, "px");
6034
- $camera.style.height = "".concat(height || 0, "px");
6035
- $container.appendChild($camera);
6036
- }
6037
- return $existedCamera;
6038
- }
6039
- return null;
6040
- }
6041
- }, {
6042
- key: "getOrCreateEl",
6043
- value: function getOrCreateEl(object) {
6044
- var doc = this.context.config.document;
6045
- var existedId = this.getId(object);
6046
- var $existedElement = this.$camera.querySelector('#' + existedId);
6047
- if (!$existedElement) {
6048
- $existedElement = (doc || document).createElement('div');
6049
- object.parsedStyle.$el = $existedElement;
6050
- $existedElement.id = existedId;
6051
- if (object.name) {
6052
- $existedElement.setAttribute('name', object.name);
6053
- }
6054
- if (object.className) {
6055
- $existedElement.className = object.className;
5094
+ return null;
5095
+ };
5096
+ _proto.getOrCreateEl = function getOrCreateEl(object) {
5097
+ var doc = this.context.config.document;
5098
+ var existedId = this.getId(object);
5099
+ var $existedElement = this.$camera.querySelector('#' + existedId);
5100
+ if (!$existedElement) {
5101
+ $existedElement = (doc || document).createElement('div');
5102
+ object.parsedStyle.$el = $existedElement;
5103
+ $existedElement.id = existedId;
5104
+ if (object.name) {
5105
+ $existedElement.setAttribute('name', object.name);
5106
+ }
5107
+ if (object.className) {
5108
+ $existedElement.className = object.className;
5109
+ }
5110
+ // use absolute position
5111
+ $existedElement.style.position = 'absolute';
5112
+ // @see https://github.com/antvis/G/issues/1150
5113
+ $existedElement.style.left = "0px";
5114
+ $existedElement.style.top = "0px";
5115
+ $existedElement.style['will-change'] = 'transform';
5116
+ $existedElement.style.transform = this.joinTransformMatrix(object.getWorldTransform());
5117
+ }
5118
+ return $existedElement;
5119
+ };
5120
+ _proto.updateAttribute = function updateAttribute(name, object) {
5121
+ var $el = this.getOrCreateEl(object);
5122
+ switch (name) {
5123
+ case 'innerHTML':
5124
+ var innerHTML = object.parsedStyle.innerHTML;
5125
+ if (isString(innerHTML)) {
5126
+ $el.innerHTML = innerHTML;
5127
+ } else {
5128
+ $el.innerHTML = '';
5129
+ $el.appendChild(innerHTML);
6056
5130
  }
6057
- // use absolute position
6058
- $existedElement.style.position = 'absolute';
6059
- // @see https://github.com/antvis/G/issues/1150
6060
- $existedElement.style.left = "0px";
6061
- $existedElement.style.top = "0px";
6062
- $existedElement.style['will-change'] = 'transform';
6063
- $existedElement.style.transform = this.joinTransformMatrix(object.getWorldTransform());
6064
- }
6065
- return $existedElement;
6066
- }
6067
- }, {
6068
- key: "updateAttribute",
6069
- value: function updateAttribute(name, object) {
6070
- var $el = this.getOrCreateEl(object);
6071
- switch (name) {
6072
- case 'innerHTML':
6073
- var innerHTML = object.parsedStyle.innerHTML;
6074
- if (isString(innerHTML)) {
6075
- $el.innerHTML = innerHTML;
5131
+ break;
5132
+ case 'transformOrigin':
5133
+ var transformOrigin = object.parsedStyle.transformOrigin;
5134
+ $el.style['transform-origin'] = transformOrigin[0].value + " " + transformOrigin[1].value;
5135
+ break;
5136
+ case 'width':
5137
+ var width = object.computedStyleMap().get('width');
5138
+ $el.style.width = width.toString();
5139
+ break;
5140
+ case 'height':
5141
+ var height = object.computedStyleMap().get('height');
5142
+ $el.style.height = height.toString();
5143
+ break;
5144
+ case 'zIndex':
5145
+ var zIndex = object.parsedStyle.zIndex;
5146
+ $el.style['z-index'] = "" + zIndex;
5147
+ break;
5148
+ case 'visibility':
5149
+ var visibility = object.parsedStyle.visibility;
5150
+ $el.style.visibility = visibility;
5151
+ break;
5152
+ case 'pointerEvents':
5153
+ var pointerEvents = object.parsedStyle.pointerEvents;
5154
+ $el.style.pointerEvents = pointerEvents;
5155
+ break;
5156
+ case 'opacity':
5157
+ var opacity = object.parsedStyle.opacity;
5158
+ $el.style.opacity = "" + opacity;
5159
+ break;
5160
+ case 'fill':
5161
+ var fill = object.parsedStyle.fill;
5162
+ var color = '';
5163
+ if (fill instanceof gLite.CSSRGB) {
5164
+ if (fill.isNone) {
5165
+ color = 'transparent';
6076
5166
  } else {
6077
- $el.innerHTML = '';
6078
- $el.appendChild(innerHTML);
6079
- }
6080
- break;
6081
- case 'transformOrigin':
6082
- var transformOrigin = object.parsedStyle.transformOrigin;
6083
- $el.style['transform-origin'] = "".concat(transformOrigin[0].value, " ").concat(transformOrigin[1].value);
6084
- break;
6085
- case 'width':
6086
- var width = object.computedStyleMap().get('width');
6087
- $el.style.width = width.toString();
6088
- break;
6089
- case 'height':
6090
- var height = object.computedStyleMap().get('height');
6091
- $el.style.height = height.toString();
6092
- break;
6093
- case 'zIndex':
6094
- var zIndex = object.parsedStyle.zIndex;
6095
- $el.style['z-index'] = "".concat(zIndex);
6096
- break;
6097
- case 'visibility':
6098
- var visibility = object.parsedStyle.visibility;
6099
- $el.style.visibility = visibility;
6100
- break;
6101
- case 'pointerEvents':
6102
- var pointerEvents = object.parsedStyle.pointerEvents;
6103
- $el.style.pointerEvents = pointerEvents;
6104
- break;
6105
- case 'opacity':
6106
- var opacity = object.parsedStyle.opacity;
6107
- $el.style.opacity = "".concat(opacity);
6108
- break;
6109
- case 'fill':
6110
- var fill = object.parsedStyle.fill;
6111
- var color = '';
6112
- if (fill instanceof gLite.CSSRGB) {
6113
- if (fill.isNone) {
6114
- color = 'transparent';
6115
- } else {
6116
- color = object.getAttribute('fill');
6117
- }
6118
- } else if (Array.isArray(fill)) {
6119
5167
  color = object.getAttribute('fill');
6120
- } else if (gLite.isPattern(fill)) ;
6121
- $el.style.background = color;
6122
- break;
6123
- case 'stroke':
6124
- var stroke = object.parsedStyle.stroke;
6125
- var borderColor = '';
6126
- if (stroke instanceof gLite.CSSRGB) {
6127
- if (stroke.isNone) {
6128
- borderColor = 'transparent';
6129
- } else {
6130
- borderColor = object.getAttribute('stroke');
6131
- }
6132
- } else if (Array.isArray(stroke)) {
5168
+ }
5169
+ } else if (Array.isArray(fill)) {
5170
+ color = object.getAttribute('fill');
5171
+ } else if (gLite.isPattern(fill)) ;
5172
+ $el.style.background = color;
5173
+ break;
5174
+ case 'stroke':
5175
+ var stroke = object.parsedStyle.stroke;
5176
+ var borderColor = '';
5177
+ if (stroke instanceof gLite.CSSRGB) {
5178
+ if (stroke.isNone) {
5179
+ borderColor = 'transparent';
5180
+ } else {
6133
5181
  borderColor = object.getAttribute('stroke');
6134
- } else if (gLite.isPattern(stroke)) ;
6135
- $el.style['border-color'] = borderColor;
6136
- $el.style['border-style'] = 'solid';
6137
- break;
6138
- case 'lineWidth':
6139
- var lineWidth = object.parsedStyle.lineWidth;
6140
- $el.style['border-width'] = "".concat(lineWidth || 0, "px");
6141
- break;
6142
- case 'lineDash':
6143
- $el.style['border-style'] = 'dashed';
6144
- break;
6145
- case 'filter':
6146
- var filter = object.style.filter;
6147
- $el.style.filter = filter;
6148
- break;
6149
- }
5182
+ }
5183
+ } else if (Array.isArray(stroke)) {
5184
+ borderColor = object.getAttribute('stroke');
5185
+ } else if (gLite.isPattern(stroke)) ;
5186
+ $el.style['border-color'] = borderColor;
5187
+ $el.style['border-style'] = 'solid';
5188
+ break;
5189
+ case 'lineWidth':
5190
+ var lineWidth = object.parsedStyle.lineWidth;
5191
+ $el.style['border-width'] = (lineWidth || 0) + "px";
5192
+ break;
5193
+ case 'lineDash':
5194
+ $el.style['border-style'] = 'dashed';
5195
+ break;
5196
+ case 'filter':
5197
+ var filter = object.style.filter;
5198
+ $el.style.filter = filter;
5199
+ break;
6150
5200
  }
6151
- }]);
5201
+ };
6152
5202
  return HTMLRenderingPlugin;
6153
5203
  }();
6154
5204
  HTMLRenderingPlugin.tag = 'HTMLRendering';
6155
5205
  var Plugin$4 = /*#__PURE__*/function (_AbstractRendererPlug) {
6156
- _inherits$5(Plugin, _AbstractRendererPlug);
6157
- var _super = _createSuper$5(Plugin);
5206
+ _inheritsLoose$5(Plugin, _AbstractRendererPlug);
6158
5207
  function Plugin() {
6159
5208
  var _this;
6160
- _classCallCheck$5(this, Plugin);
6161
5209
  for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
6162
5210
  args[_key] = arguments[_key];
6163
5211
  }
6164
- _this = _super.call.apply(_super, [this].concat(args));
5212
+ _this = _AbstractRendererPlug.call.apply(_AbstractRendererPlug, [this].concat(args)) || this;
6165
5213
  _this.name = 'html-renderer';
6166
5214
  return _this;
6167
5215
  }
6168
- _createClass$5(Plugin, [{
6169
- key: "init",
6170
- value: function init() {
6171
- this.addRenderingPlugin(new HTMLRenderingPlugin());
6172
- }
6173
- }, {
6174
- key: "destroy",
6175
- value: function destroy() {
6176
- this.removeAllRenderingPlugins();
6177
- }
6178
- }]);
5216
+ var _proto = Plugin.prototype;
5217
+ _proto.init = function init() {
5218
+ this.addRenderingPlugin(new HTMLRenderingPlugin());
5219
+ };
5220
+ _proto.destroy = function destroy() {
5221
+ this.removeAllRenderingPlugins();
5222
+ };
6179
5223
  return Plugin;
6180
5224
  }(gLite.AbstractRendererPlugin);
6181
5225
 
@@ -6260,7 +5304,7 @@
6260
5304
  if ("throw" !== record.type) {
6261
5305
  var result = record.arg,
6262
5306
  value = result.value;
6263
- return value && "object" == _typeof(value) && hasOwn.call(value, "__await") ? PromiseImpl.resolve(value.__await).then(function (value) {
5307
+ return value && "object" == typeof value && hasOwn.call(value, "__await") ? PromiseImpl.resolve(value.__await).then(function (value) {
6264
5308
  invoke("next", value, resolve, reject);
6265
5309
  }, function (err) {
6266
5310
  invoke("throw", err, resolve, reject);
@@ -6521,49 +5565,10 @@
6521
5565
  });
6522
5566
  };
6523
5567
  }
6524
- function _classCallCheck$6(instance, Constructor) {
6525
- if (!(instance instanceof Constructor)) {
6526
- throw new TypeError("Cannot call a class as a function");
6527
- }
6528
- }
6529
- function _defineProperties$6(target, props) {
6530
- for (var i = 0; i < props.length; i++) {
6531
- var descriptor = props[i];
6532
- descriptor.enumerable = descriptor.enumerable || false;
6533
- descriptor.configurable = true;
6534
- if ("value" in descriptor) descriptor.writable = true;
6535
- Object.defineProperty(target, _toPropertyKey$6(descriptor.key), descriptor);
6536
- }
6537
- }
6538
- function _createClass$6(Constructor, protoProps, staticProps) {
6539
- if (protoProps) _defineProperties$6(Constructor.prototype, protoProps);
6540
- if (staticProps) _defineProperties$6(Constructor, staticProps);
6541
- Object.defineProperty(Constructor, "prototype", {
6542
- writable: false
6543
- });
6544
- return Constructor;
6545
- }
6546
- function _inherits$6(subClass, superClass) {
6547
- if (typeof superClass !== "function" && superClass !== null) {
6548
- throw new TypeError("Super expression must either be null or a function");
6549
- }
6550
- subClass.prototype = Object.create(superClass && superClass.prototype, {
6551
- constructor: {
6552
- value: subClass,
6553
- writable: true,
6554
- configurable: true
6555
- }
6556
- });
6557
- Object.defineProperty(subClass, "prototype", {
6558
- writable: false
6559
- });
6560
- if (superClass) _setPrototypeOf$6(subClass, superClass);
6561
- }
6562
- function _getPrototypeOf$6(o) {
6563
- _getPrototypeOf$6 = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) {
6564
- return o.__proto__ || Object.getPrototypeOf(o);
6565
- };
6566
- return _getPrototypeOf$6(o);
5568
+ function _inheritsLoose$6(subClass, superClass) {
5569
+ subClass.prototype = Object.create(superClass.prototype);
5570
+ subClass.prototype.constructor = subClass;
5571
+ _setPrototypeOf$6(subClass, superClass);
6567
5572
  }
6568
5573
  function _setPrototypeOf$6(o, p) {
6569
5574
  _setPrototypeOf$6 = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) {
@@ -6572,59 +5577,6 @@
6572
5577
  };
6573
5578
  return _setPrototypeOf$6(o, p);
6574
5579
  }
6575
- function _isNativeReflectConstruct$6() {
6576
- if (typeof Reflect === "undefined" || !Reflect.construct) return false;
6577
- if (Reflect.construct.sham) return false;
6578
- if (typeof Proxy === "function") return true;
6579
- try {
6580
- Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {}));
6581
- return true;
6582
- } catch (e) {
6583
- return false;
6584
- }
6585
- }
6586
- function _assertThisInitialized$6(self) {
6587
- if (self === void 0) {
6588
- throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
6589
- }
6590
- return self;
6591
- }
6592
- function _possibleConstructorReturn$6(self, call) {
6593
- if (call && (_typeof(call) === "object" || typeof call === "function")) {
6594
- return call;
6595
- } else if (call !== void 0) {
6596
- throw new TypeError("Derived constructors may only return object or undefined");
6597
- }
6598
- return _assertThisInitialized$6(self);
6599
- }
6600
- function _createSuper$6(Derived) {
6601
- var hasNativeReflectConstruct = _isNativeReflectConstruct$6();
6602
- return function _createSuperInternal() {
6603
- var Super = _getPrototypeOf$6(Derived),
6604
- result;
6605
- if (hasNativeReflectConstruct) {
6606
- var NewTarget = _getPrototypeOf$6(this).constructor;
6607
- result = Reflect.construct(Super, arguments, NewTarget);
6608
- } else {
6609
- result = Super.apply(this, arguments);
6610
- }
6611
- return _possibleConstructorReturn$6(this, result);
6612
- };
6613
- }
6614
- function _toPrimitive$6(input, hint) {
6615
- if (_typeof(input) !== "object" || input === null) return input;
6616
- var prim = input[Symbol.toPrimitive];
6617
- if (prim !== undefined) {
6618
- var res = prim.call(input, hint || "default");
6619
- if (_typeof(res) !== "object") return res;
6620
- throw new TypeError("@@toPrimitive must return a primitive value.");
6621
- }
6622
- return (hint === "string" ? String : Number)(input);
6623
- }
6624
- function _toPropertyKey$6(arg) {
6625
- var key = _toPrimitive$6(arg, "string");
6626
- return _typeof(key) === "symbol" ? key : String(key);
6627
- }
6628
5580
 
6629
5581
  /**
6630
5582
  * Common utilities
@@ -6732,275 +5684,252 @@
6732
5684
  }
6733
5685
  var ImagePool = /*#__PURE__*/function () {
6734
5686
  function ImagePool(canvasConfig) {
6735
- _classCallCheck$6(this, ImagePool);
6736
5687
  this.canvasConfig = void 0;
6737
5688
  this.imageCache = {};
6738
5689
  this.gradientCache = {};
6739
5690
  this.patternCache = {};
6740
5691
  this.canvasConfig = canvasConfig;
6741
5692
  }
6742
- _createClass$6(ImagePool, [{
6743
- key: "getImageSync",
6744
- value: function getImageSync(src, callback) {
6745
- if (!this.imageCache[src]) {
6746
- this.getOrCreateImage(src).then(function () {
6747
- if (callback) {
6748
- callback();
6749
- }
6750
- });
6751
- } else {
5693
+ var _proto = ImagePool.prototype;
5694
+ _proto.getImageSync = function getImageSync(src, callback) {
5695
+ if (!this.imageCache[src]) {
5696
+ this.getOrCreateImage(src).then(function () {
6752
5697
  if (callback) {
6753
5698
  callback();
6754
5699
  }
6755
- }
6756
- return this.imageCache[src];
6757
- }
6758
- }, {
6759
- key: "getOrCreateImage",
6760
- value: function getOrCreateImage(src) {
6761
- var _this = this;
6762
- if (this.imageCache[src]) {
6763
- return Promise.resolve(this.imageCache[src]);
6764
- }
6765
- // @see https://github.com/antvis/g/issues/938
6766
- var createImage = this.canvasConfig.createImage;
6767
- return new Promise(function (resolve, reject) {
6768
- var image;
6769
- if (createImage) {
6770
- image = createImage(src);
6771
- } else if (gLite.isBrowser) {
6772
- image = new window.Image();
6773
- }
6774
- if (image) {
6775
- image.onload = function () {
6776
- resolve(image);
6777
- };
6778
- image.onerror = function (ev) {
6779
- reject(ev);
6780
- };
6781
- image.crossOrigin = 'Anonymous';
6782
- image.src = src;
6783
- _this.imageCache[src] = image;
6784
- }
6785
5700
  });
5701
+ } else {
5702
+ if (callback) {
5703
+ callback();
5704
+ }
6786
5705
  }
6787
- }, {
6788
- key: "getOrCreatePatternSync",
6789
- value: function getOrCreatePatternSync(pattern, context, $offscreenCanvas, dpr, callback) {
6790
- var patternKey = this.generatePatternKey(pattern);
6791
- if (patternKey && this.patternCache[patternKey]) {
6792
- return this.patternCache[patternKey];
6793
- }
6794
- var image = pattern.image,
6795
- repetition = pattern.repetition,
6796
- transform = pattern.transform;
6797
- var src;
6798
- var needScaleWithDPR = false;
6799
- // Image URL
6800
- if (isString(image)) {
6801
- src = this.getImageSync(image, callback);
6802
- } else if ($offscreenCanvas) {
6803
- src = $offscreenCanvas;
6804
- needScaleWithDPR = true;
6805
- } else {
6806
- src = image;
6807
- }
6808
- // @see https://developer.mozilla.org/zh-CN/docs/Web/API/CanvasRenderingContext2D/createPattern
6809
- var canvasPattern = src && context.createPattern(src, repetition);
6810
- if (canvasPattern) {
6811
- var mat;
6812
- // @see https://developer.mozilla.org/en-US/docs/Web/API/CanvasPattern/setTransform
6813
- if (transform) {
6814
- mat = gLite.parsedTransformToMat4(gLite.parseTransform(transform));
6815
- } else {
6816
- mat = identity(create$3());
6817
- }
6818
- if (needScaleWithDPR) {
6819
- scale(mat, mat, [1 / dpr, 1 / dpr, 1]);
6820
- }
6821
- canvasPattern.setTransform({
6822
- a: mat[0],
6823
- b: mat[1],
6824
- c: mat[4],
6825
- d: mat[5],
6826
- e: mat[12],
6827
- f: mat[13]
6828
- });
5706
+ return this.imageCache[src];
5707
+ };
5708
+ _proto.getOrCreateImage = function getOrCreateImage(src) {
5709
+ var _this = this;
5710
+ if (this.imageCache[src]) {
5711
+ return Promise.resolve(this.imageCache[src]);
5712
+ }
5713
+ // @see https://github.com/antvis/g/issues/938
5714
+ var createImage = this.canvasConfig.createImage;
5715
+ return new Promise(function (resolve, reject) {
5716
+ var image;
5717
+ if (createImage) {
5718
+ image = createImage(src);
5719
+ } else if (gLite.isBrowser) {
5720
+ image = new window.Image();
6829
5721
  }
6830
- if (patternKey && canvasPattern) {
6831
- this.patternCache[patternKey] = canvasPattern;
6832
- }
6833
- return canvasPattern;
6834
- }
6835
- }, {
6836
- key: "getOrCreateGradient",
6837
- value: function getOrCreateGradient(params, context) {
6838
- var key = this.generateGradientKey(params);
6839
- var type = params.type,
6840
- steps = params.steps,
6841
- width = params.width,
6842
- height = params.height,
6843
- angle = params.angle,
6844
- cx = params.cx,
6845
- cy = params.cy,
6846
- size = params.size;
6847
- if (this.gradientCache[key]) {
6848
- return this.gradientCache[key];
6849
- }
6850
- var gradient = null;
6851
- if (type === gLite.GradientType.LinearGradient) {
6852
- var _computeLinearGradien = gLite.computeLinearGradient(width, height, angle),
6853
- x1 = _computeLinearGradien.x1,
6854
- y1 = _computeLinearGradien.y1,
6855
- x2 = _computeLinearGradien.x2,
6856
- y2 = _computeLinearGradien.y2;
6857
- // @see https://developer.mozilla.org/zh-CN/docs/Web/API/CanvasRenderingContext2D/createLinearGradient
6858
- gradient = context.createLinearGradient(x1, y1, x2, y2);
6859
- } else if (type === gLite.GradientType.RadialGradient) {
6860
- var _computeRadialGradien = gLite.computeRadialGradient(width, height, cx, cy, size),
6861
- x = _computeRadialGradien.x,
6862
- y = _computeRadialGradien.y,
6863
- r = _computeRadialGradien.r;
6864
- // @see https://developer.mozilla.org/zh-CN/docs/Web/API/CanvasRenderingContext2D/createRadialGradient
6865
- gradient = context.createRadialGradient(x, y, 0, x, y, r);
6866
- }
6867
- if (gradient) {
6868
- steps.forEach(function (_ref) {
6869
- var offset = _ref.offset,
6870
- color = _ref.color;
6871
- if (offset.unit === gLite.UnitType.kPercentage) {
6872
- var _gradient;
6873
- (_gradient = gradient) === null || _gradient === void 0 ? void 0 : _gradient.addColorStop(offset.value / 100, color.toString());
6874
- }
6875
- });
6876
- this.gradientCache[key] = gradient;
5722
+ if (image) {
5723
+ image.onload = function () {
5724
+ resolve(image);
5725
+ };
5726
+ image.onerror = function (ev) {
5727
+ reject(ev);
5728
+ };
5729
+ image.crossOrigin = 'Anonymous';
5730
+ image.src = src;
5731
+ _this.imageCache[src] = image;
6877
5732
  }
5733
+ });
5734
+ };
5735
+ _proto.getOrCreatePatternSync = function getOrCreatePatternSync(pattern, context, $offscreenCanvas, dpr, callback) {
5736
+ var patternKey = this.generatePatternKey(pattern);
5737
+ if (patternKey && this.patternCache[patternKey]) {
5738
+ return this.patternCache[patternKey];
5739
+ }
5740
+ var image = pattern.image,
5741
+ repetition = pattern.repetition,
5742
+ transform = pattern.transform;
5743
+ var src;
5744
+ var needScaleWithDPR = false;
5745
+ // Image URL
5746
+ if (isString(image)) {
5747
+ src = this.getImageSync(image, callback);
5748
+ } else if ($offscreenCanvas) {
5749
+ src = $offscreenCanvas;
5750
+ needScaleWithDPR = true;
5751
+ } else {
5752
+ src = image;
5753
+ }
5754
+ // @see https://developer.mozilla.org/zh-CN/docs/Web/API/CanvasRenderingContext2D/createPattern
5755
+ var canvasPattern = src && context.createPattern(src, repetition);
5756
+ if (canvasPattern) {
5757
+ var mat;
5758
+ // @see https://developer.mozilla.org/en-US/docs/Web/API/CanvasPattern/setTransform
5759
+ if (transform) {
5760
+ mat = gLite.parsedTransformToMat4(gLite.parseTransform(transform));
5761
+ } else {
5762
+ mat = identity(create$3());
5763
+ }
5764
+ if (needScaleWithDPR) {
5765
+ scale(mat, mat, [1 / dpr, 1 / dpr, 1]);
5766
+ }
5767
+ canvasPattern.setTransform({
5768
+ a: mat[0],
5769
+ b: mat[1],
5770
+ c: mat[4],
5771
+ d: mat[5],
5772
+ e: mat[12],
5773
+ f: mat[13]
5774
+ });
5775
+ }
5776
+ if (patternKey && canvasPattern) {
5777
+ this.patternCache[patternKey] = canvasPattern;
5778
+ }
5779
+ return canvasPattern;
5780
+ };
5781
+ _proto.getOrCreateGradient = function getOrCreateGradient(params, context) {
5782
+ var key = this.generateGradientKey(params);
5783
+ var type = params.type,
5784
+ steps = params.steps,
5785
+ width = params.width,
5786
+ height = params.height,
5787
+ angle = params.angle,
5788
+ cx = params.cx,
5789
+ cy = params.cy,
5790
+ size = params.size;
5791
+ if (this.gradientCache[key]) {
6878
5792
  return this.gradientCache[key];
6879
5793
  }
6880
- }, {
6881
- key: "generateGradientKey",
6882
- value: function generateGradientKey(params) {
6883
- var type = params.type,
6884
- width = params.width,
6885
- height = params.height,
6886
- steps = params.steps,
6887
- angle = params.angle,
6888
- cx = params.cx,
6889
- cy = params.cy,
6890
- size = params.size;
6891
- return "gradient-".concat(type, "-").concat((angle === null || angle === void 0 ? void 0 : angle.toString()) || 0, "-").concat((cx === null || cx === void 0 ? void 0 : cx.toString()) || 0, "-").concat((cy === null || cy === void 0 ? void 0 : cy.toString()) || 0, "-").concat((size === null || size === void 0 ? void 0 : size.toString()) || 0, "-").concat(width, "-").concat(height, "-").concat(steps.map(function (_ref2) {
6892
- var offset = _ref2.offset,
6893
- color = _ref2.color;
6894
- return "".concat(offset).concat(color);
6895
- }).join('-'));
6896
- }
6897
- }, {
6898
- key: "generatePatternKey",
6899
- value: function generatePatternKey(pattern) {
6900
- var image = pattern.image,
6901
- repetition = pattern.repetition;
6902
- // only generate cache for Image
6903
- if (isString(image)) {
6904
- return "pattern-".concat(image, "-").concat(repetition);
6905
- } else if (image instanceof gLite.Rect) {
6906
- return "pattern-".concat(image.entity, "-").concat(repetition);
6907
- }
6908
- }
6909
- }]);
5794
+ var gradient = null;
5795
+ if (type === gLite.GradientType.LinearGradient) {
5796
+ var _computeLinearGradien = gLite.computeLinearGradient(width, height, angle),
5797
+ x1 = _computeLinearGradien.x1,
5798
+ y1 = _computeLinearGradien.y1,
5799
+ x2 = _computeLinearGradien.x2,
5800
+ y2 = _computeLinearGradien.y2;
5801
+ // @see https://developer.mozilla.org/zh-CN/docs/Web/API/CanvasRenderingContext2D/createLinearGradient
5802
+ gradient = context.createLinearGradient(x1, y1, x2, y2);
5803
+ } else if (type === gLite.GradientType.RadialGradient) {
5804
+ var _computeRadialGradien = gLite.computeRadialGradient(width, height, cx, cy, size),
5805
+ x = _computeRadialGradien.x,
5806
+ y = _computeRadialGradien.y,
5807
+ r = _computeRadialGradien.r;
5808
+ // @see https://developer.mozilla.org/zh-CN/docs/Web/API/CanvasRenderingContext2D/createRadialGradient
5809
+ gradient = context.createRadialGradient(x, y, 0, x, y, r);
5810
+ }
5811
+ if (gradient) {
5812
+ steps.forEach(function (_ref) {
5813
+ var offset = _ref.offset,
5814
+ color = _ref.color;
5815
+ if (offset.unit === gLite.UnitType.kPercentage) {
5816
+ var _gradient;
5817
+ (_gradient = gradient) === null || _gradient === void 0 ? void 0 : _gradient.addColorStop(offset.value / 100, color.toString());
5818
+ }
5819
+ });
5820
+ this.gradientCache[key] = gradient;
5821
+ }
5822
+ return this.gradientCache[key];
5823
+ };
5824
+ _proto.generateGradientKey = function generateGradientKey(params) {
5825
+ var type = params.type,
5826
+ width = params.width,
5827
+ height = params.height,
5828
+ steps = params.steps,
5829
+ angle = params.angle,
5830
+ cx = params.cx,
5831
+ cy = params.cy,
5832
+ size = params.size;
5833
+ 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) {
5834
+ var offset = _ref2.offset,
5835
+ color = _ref2.color;
5836
+ return "" + offset + color;
5837
+ }).join('-');
5838
+ };
5839
+ _proto.generatePatternKey = function generatePatternKey(pattern) {
5840
+ var image = pattern.image,
5841
+ repetition = pattern.repetition;
5842
+ // only generate cache for Image
5843
+ if (isString(image)) {
5844
+ return "pattern-" + image + "-" + repetition;
5845
+ } else if (image instanceof gLite.Rect) {
5846
+ return "pattern-" + image.entity + "-" + repetition;
5847
+ }
5848
+ };
6910
5849
  return ImagePool;
6911
5850
  }();
6912
5851
  var LoadImagePlugin = /*#__PURE__*/function () {
6913
- function LoadImagePlugin() {
6914
- _classCallCheck$6(this, LoadImagePlugin);
6915
- }
6916
- _createClass$6(LoadImagePlugin, [{
6917
- key: "apply",
6918
- value: function apply(context) {
6919
- // @ts-ignore
6920
- var renderingService = context.renderingService,
6921
- renderingContext = context.renderingContext,
6922
- imagePool = context.imagePool;
6923
- var canvas = renderingContext.root.ownerDocument.defaultView;
6924
- var handleMounted = function handleMounted(e) {
6925
- var object = e.target;
6926
- var nodeName = object.nodeName,
6927
- attributes = object.attributes;
6928
- if (nodeName === gLite.Shape.IMAGE) {
6929
- var img = attributes.img;
6930
- if (isString(img)) {
6931
- imagePool.getImageSync(img, function () {
5852
+ function LoadImagePlugin() {}
5853
+ var _proto = LoadImagePlugin.prototype;
5854
+ _proto.apply = function apply(context) {
5855
+ // @ts-ignore
5856
+ var renderingService = context.renderingService,
5857
+ renderingContext = context.renderingContext,
5858
+ imagePool = context.imagePool;
5859
+ var canvas = renderingContext.root.ownerDocument.defaultView;
5860
+ var handleMounted = function handleMounted(e) {
5861
+ var object = e.target;
5862
+ var nodeName = object.nodeName,
5863
+ attributes = object.attributes;
5864
+ if (nodeName === gLite.Shape.IMAGE) {
5865
+ var img = attributes.img;
5866
+ if (isString(img)) {
5867
+ imagePool.getImageSync(img, function () {
5868
+ // set dirty rectangle flag
5869
+ object.renderable.dirty = true;
5870
+ renderingService.dirtify();
5871
+ });
5872
+ }
5873
+ }
5874
+ };
5875
+ var handleAttributeChanged = function handleAttributeChanged(e) {
5876
+ var object = e.target;
5877
+ var attrName = e.attrName,
5878
+ newValue = e.newValue;
5879
+ if (object.nodeName === gLite.Shape.IMAGE) {
5880
+ if (attrName === 'img') {
5881
+ if (isString(newValue)) {
5882
+ imagePool.getOrCreateImage(newValue).then(function () {
6932
5883
  // set dirty rectangle flag
6933
5884
  object.renderable.dirty = true;
6934
5885
  renderingService.dirtify();
6935
5886
  });
6936
5887
  }
6937
5888
  }
6938
- };
6939
- var handleAttributeChanged = function handleAttributeChanged(e) {
6940
- var object = e.target;
6941
- var attrName = e.attrName,
6942
- newValue = e.newValue;
6943
- if (object.nodeName === gLite.Shape.IMAGE) {
6944
- if (attrName === 'img') {
6945
- if (isString(newValue)) {
6946
- imagePool.getOrCreateImage(newValue).then(function () {
6947
- // set dirty rectangle flag
6948
- object.renderable.dirty = true;
6949
- renderingService.dirtify();
6950
- });
6951
- }
5889
+ }
5890
+ };
5891
+ renderingService.hooks.init.tapPromise(LoadImagePlugin.tag, /*#__PURE__*/_asyncToGenerator$5( /*#__PURE__*/_regeneratorRuntime$5().mark(function _callee() {
5892
+ return _regeneratorRuntime$5().wrap(function _callee$(_context) {
5893
+ while (1) {
5894
+ switch (_context.prev = _context.next) {
5895
+ case 0:
5896
+ canvas.addEventListener(gLite.ElementEvent.MOUNTED, handleMounted);
5897
+ canvas.addEventListener(gLite.ElementEvent.ATTR_MODIFIED, handleAttributeChanged);
5898
+ case 2:
5899
+ case "end":
5900
+ return _context.stop();
6952
5901
  }
6953
5902
  }
6954
- };
6955
- renderingService.hooks.init.tapPromise(LoadImagePlugin.tag, /*#__PURE__*/_asyncToGenerator$5( /*#__PURE__*/_regeneratorRuntime$5().mark(function _callee() {
6956
- return _regeneratorRuntime$5().wrap(function _callee$(_context) {
6957
- while (1) {
6958
- switch (_context.prev = _context.next) {
6959
- case 0:
6960
- canvas.addEventListener(gLite.ElementEvent.MOUNTED, handleMounted);
6961
- canvas.addEventListener(gLite.ElementEvent.ATTR_MODIFIED, handleAttributeChanged);
6962
- case 2:
6963
- case "end":
6964
- return _context.stop();
6965
- }
6966
- }
6967
- }, _callee);
6968
- })));
6969
- renderingService.hooks.destroy.tap(LoadImagePlugin.tag, function () {
6970
- canvas.removeEventListener(gLite.ElementEvent.MOUNTED, handleMounted);
6971
- canvas.removeEventListener(gLite.ElementEvent.ATTR_MODIFIED, handleAttributeChanged);
6972
- });
6973
- }
6974
- }]);
5903
+ }, _callee);
5904
+ })));
5905
+ renderingService.hooks.destroy.tap(LoadImagePlugin.tag, function () {
5906
+ canvas.removeEventListener(gLite.ElementEvent.MOUNTED, handleMounted);
5907
+ canvas.removeEventListener(gLite.ElementEvent.ATTR_MODIFIED, handleAttributeChanged);
5908
+ });
5909
+ };
6975
5910
  return LoadImagePlugin;
6976
5911
  }();
6977
5912
  LoadImagePlugin.tag = 'LoadImage';
6978
5913
  var Plugin$5 = /*#__PURE__*/function (_AbstractRendererPlug) {
6979
- _inherits$6(Plugin, _AbstractRendererPlug);
6980
- var _super = _createSuper$6(Plugin);
5914
+ _inheritsLoose$6(Plugin, _AbstractRendererPlug);
6981
5915
  function Plugin() {
6982
5916
  var _this;
6983
- _classCallCheck$6(this, Plugin);
6984
5917
  for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
6985
5918
  args[_key] = arguments[_key];
6986
5919
  }
6987
- _this = _super.call.apply(_super, [this].concat(args));
5920
+ _this = _AbstractRendererPlug.call.apply(_AbstractRendererPlug, [this].concat(args)) || this;
6988
5921
  _this.name = 'image-loader';
6989
5922
  return _this;
6990
5923
  }
6991
- _createClass$6(Plugin, [{
6992
- key: "init",
6993
- value: function init() {
6994
- // @ts-ignore
6995
- this.context.imagePool = new ImagePool(this.context.config);
6996
- this.addRenderingPlugin(new LoadImagePlugin());
6997
- }
6998
- }, {
6999
- key: "destroy",
7000
- value: function destroy() {
7001
- this.removeAllRenderingPlugins();
7002
- }
7003
- }]);
5924
+ var _proto = Plugin.prototype;
5925
+ _proto.init = function init() {
5926
+ // @ts-ignore
5927
+ this.context.imagePool = new ImagePool(this.context.config);
5928
+ this.addRenderingPlugin(new LoadImagePlugin());
5929
+ };
5930
+ _proto.destroy = function destroy() {
5931
+ this.removeAllRenderingPlugins();
5932
+ };
7004
5933
  return Plugin;
7005
5934
  }(gLite.AbstractRendererPlugin);
7006
5935
 
@@ -7012,7 +5941,6 @@
7012
5941
 
7013
5942
  var Canvas2DContextService = /*#__PURE__*/function () {
7014
5943
  function Canvas2DContextService(context) {
7015
- _classCallCheck(this, Canvas2DContextService);
7016
5944
  this.$container = void 0;
7017
5945
  this.$canvas = void 0;
7018
5946
  this.dpr = void 0;
@@ -7022,176 +5950,149 @@
7022
5950
  this.renderingContext = context.renderingContext;
7023
5951
  this.canvasConfig = context.config;
7024
5952
  }
7025
- _createClass(Canvas2DContextService, [{
7026
- key: "init",
7027
- value: function () {
7028
- var _init = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
7029
- var _this$canvasConfig, container, canvas, $canvas;
7030
- return _regeneratorRuntime().wrap(function _callee$(_context) {
7031
- while (1) {
7032
- switch (_context.prev = _context.next) {
7033
- case 0:
7034
- _this$canvasConfig = this.canvasConfig, container = _this$canvasConfig.container, canvas = _this$canvasConfig.canvas;
7035
- if (canvas) {
7036
- this.$canvas = canvas;
7037
- if (container && canvas.parentElement !== container) {
7038
- container.appendChild(canvas);
7039
- }
7040
- this.$container = canvas.parentElement;
7041
- this.canvasConfig.container = this.$container;
7042
- } else if (container) {
7043
- // create container
7044
- this.$container = isString(container) ? document.getElementById(container) : container;
7045
- if (this.$container) {
7046
- // create canvas
7047
- $canvas = document.createElement('canvas');
7048
- this.$container.appendChild($canvas);
7049
- if (!this.$container.style.position) {
7050
- this.$container.style.position = 'relative';
7051
- }
7052
- this.$canvas = $canvas;
5953
+ var _proto = Canvas2DContextService.prototype;
5954
+ _proto.init = /*#__PURE__*/function () {
5955
+ var _init = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
5956
+ var _this$canvasConfig, container, canvas, $canvas;
5957
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
5958
+ while (1) {
5959
+ switch (_context.prev = _context.next) {
5960
+ case 0:
5961
+ _this$canvasConfig = this.canvasConfig, container = _this$canvasConfig.container, canvas = _this$canvasConfig.canvas;
5962
+ if (canvas) {
5963
+ this.$canvas = canvas;
5964
+ if (container && canvas.parentElement !== container) {
5965
+ container.appendChild(canvas);
5966
+ }
5967
+ this.$container = canvas.parentElement;
5968
+ this.canvasConfig.container = this.$container;
5969
+ } else if (container) {
5970
+ // create container
5971
+ this.$container = isString(container) ? document.getElementById(container) : container;
5972
+ if (this.$container) {
5973
+ // create canvas
5974
+ $canvas = document.createElement('canvas');
5975
+ this.$container.appendChild($canvas);
5976
+ if (!this.$container.style.position) {
5977
+ this.$container.style.position = 'relative';
7053
5978
  }
5979
+ this.$canvas = $canvas;
7054
5980
  }
7055
- this.context = this.$canvas.getContext('2d');
7056
- this.resize(this.canvasConfig.width, this.canvasConfig.height);
7057
- case 4:
7058
- case "end":
7059
- return _context.stop();
7060
- }
5981
+ }
5982
+ this.context = this.$canvas.getContext('2d');
5983
+ this.resize(this.canvasConfig.width, this.canvasConfig.height);
5984
+ case 4:
5985
+ case "end":
5986
+ return _context.stop();
7061
5987
  }
7062
- }, _callee, this);
7063
- }));
7064
- function init() {
7065
- return _init.apply(this, arguments);
7066
- }
7067
- return init;
7068
- }()
7069
- }, {
7070
- key: "getContext",
7071
- value: function getContext() {
7072
- return this.context;
7073
- }
7074
- }, {
7075
- key: "getDomElement",
7076
- value: function getDomElement() {
7077
- return this.$canvas;
7078
- }
7079
- }, {
7080
- key: "getDPR",
7081
- value: function getDPR() {
7082
- return this.dpr;
7083
- }
7084
- }, {
7085
- key: "getBoundingClientRect",
7086
- value: function getBoundingClientRect() {
7087
- if (this.$canvas.getBoundingClientRect) {
7088
- return this.$canvas.getBoundingClientRect();
7089
- }
7090
- }
7091
- }, {
7092
- key: "destroy",
7093
- value: function destroy() {
5988
+ }
5989
+ }, _callee, this);
5990
+ }));
5991
+ function init() {
5992
+ return _init.apply(this, arguments);
5993
+ }
5994
+ return init;
5995
+ }();
5996
+ _proto.getContext = function getContext() {
5997
+ return this.context;
5998
+ };
5999
+ _proto.getDomElement = function getDomElement() {
6000
+ return this.$canvas;
6001
+ };
6002
+ _proto.getDPR = function getDPR() {
6003
+ return this.dpr;
6004
+ };
6005
+ _proto.getBoundingClientRect = function getBoundingClientRect() {
6006
+ if (this.$canvas.getBoundingClientRect) {
6007
+ return this.$canvas.getBoundingClientRect();
6008
+ }
6009
+ };
6010
+ _proto.destroy = function destroy() {
6011
+ // @ts-ignore
6012
+ if (this.$container && this.$canvas && this.$canvas.parentNode) {
6013
+ // destroy context
7094
6014
  // @ts-ignore
7095
- if (this.$container && this.$canvas && this.$canvas.parentNode) {
7096
- // destroy context
7097
- // @ts-ignore
7098
- this.$container.removeChild(this.$canvas);
7099
- }
7100
- }
7101
- }, {
7102
- key: "resize",
7103
- value: function resize(width, height) {
7104
- var devicePixelRatio = this.canvasConfig.devicePixelRatio;
7105
- // use user-defined dpr first
7106
- var dpr = devicePixelRatio || gLite.isBrowser && window.devicePixelRatio || 1;
7107
- dpr = dpr >= 1 ? Math.ceil(dpr) : 1;
7108
- this.dpr = dpr;
7109
- if (this.$canvas) {
7110
- // set canvas width & height
7111
- this.$canvas.width = this.dpr * width;
7112
- this.$canvas.height = this.dpr * height;
7113
- // set CSS style width & height
7114
- gLite.setDOMSize(this.$canvas, width, height);
7115
- // const dpr = this.getDPR();
7116
- // scale all drawing operations by the dpr
7117
- // @see https://www.html5rocks.com/en/tutorials/canvas/hidpi/
7118
- // this.context.scale(dpr, dpr);
7119
- }
6015
+ this.$container.removeChild(this.$canvas);
6016
+ }
6017
+ };
6018
+ _proto.resize = function resize(width, height) {
6019
+ var devicePixelRatio = this.canvasConfig.devicePixelRatio;
6020
+ // use user-defined dpr first
6021
+ var dpr = devicePixelRatio || gLite.isBrowser && window.devicePixelRatio || 1;
6022
+ dpr = dpr >= 1 ? Math.ceil(dpr) : 1;
6023
+ this.dpr = dpr;
6024
+ if (this.$canvas) {
6025
+ // set canvas width & height
6026
+ this.$canvas.width = this.dpr * width;
6027
+ this.$canvas.height = this.dpr * height;
6028
+ // set CSS style width & height
6029
+ gLite.setDOMSize(this.$canvas, width, height);
6030
+ // const dpr = this.getDPR();
6031
+ // scale all drawing operations by the dpr
6032
+ // @see https://www.html5rocks.com/en/tutorials/canvas/hidpi/
6033
+ // this.context.scale(dpr, dpr);
6034
+ }
7120
6035
 
7121
- this.renderingContext.renderReasons.add(gLite.RenderReason.CAMERA_CHANGED);
7122
- }
7123
- }, {
7124
- key: "applyCursorStyle",
7125
- value: function applyCursorStyle(cursor) {
7126
- if (this.$container && this.$container.style) {
7127
- this.$container.style.cursor = cursor;
7128
- }
7129
- }
7130
- }, {
7131
- key: "toDataURL",
7132
- value: function () {
7133
- var _toDataURL = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
7134
- var options,
7135
- type,
7136
- encoderOptions,
7137
- _args2 = arguments;
7138
- return _regeneratorRuntime().wrap(function _callee2$(_context2) {
7139
- while (1) {
7140
- switch (_context2.prev = _context2.next) {
7141
- case 0:
7142
- options = _args2.length > 0 && _args2[0] !== undefined ? _args2[0] : {};
7143
- type = options.type, encoderOptions = options.encoderOptions;
7144
- return _context2.abrupt("return", this.context.canvas.toDataURL(type, encoderOptions));
7145
- case 3:
7146
- case "end":
7147
- return _context2.stop();
7148
- }
6036
+ this.renderingContext.renderReasons.add(gLite.RenderReason.CAMERA_CHANGED);
6037
+ };
6038
+ _proto.applyCursorStyle = function applyCursorStyle(cursor) {
6039
+ if (this.$container && this.$container.style) {
6040
+ this.$container.style.cursor = cursor;
6041
+ }
6042
+ };
6043
+ _proto.toDataURL = /*#__PURE__*/function () {
6044
+ var _toDataURL = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(options) {
6045
+ var _options, type, encoderOptions;
6046
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
6047
+ while (1) {
6048
+ switch (_context2.prev = _context2.next) {
6049
+ case 0:
6050
+ if (options === void 0) {
6051
+ options = {};
6052
+ }
6053
+ _options = options, type = _options.type, encoderOptions = _options.encoderOptions;
6054
+ return _context2.abrupt("return", this.context.canvas.toDataURL(type, encoderOptions));
6055
+ case 3:
6056
+ case "end":
6057
+ return _context2.stop();
7149
6058
  }
7150
- }, _callee2, this);
7151
- }));
7152
- function toDataURL() {
7153
- return _toDataURL.apply(this, arguments);
7154
- }
7155
- return toDataURL;
7156
- }()
7157
- }]);
6059
+ }
6060
+ }, _callee2, this);
6061
+ }));
6062
+ function toDataURL(_x) {
6063
+ return _toDataURL.apply(this, arguments);
6064
+ }
6065
+ return toDataURL;
6066
+ }();
7158
6067
  return Canvas2DContextService;
7159
6068
  }();
7160
6069
 
7161
6070
  var ContextRegisterPlugin = /*#__PURE__*/function (_AbstractRendererPlug) {
7162
- _inherits(ContextRegisterPlugin, _AbstractRendererPlug);
7163
- var _super = _createSuper(ContextRegisterPlugin);
6071
+ _inheritsLoose(ContextRegisterPlugin, _AbstractRendererPlug);
7164
6072
  function ContextRegisterPlugin() {
7165
6073
  var _this;
7166
- _classCallCheck(this, ContextRegisterPlugin);
7167
6074
  for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
7168
6075
  args[_key] = arguments[_key];
7169
6076
  }
7170
- _this = _super.call.apply(_super, [this].concat(args));
6077
+ _this = _AbstractRendererPlug.call.apply(_AbstractRendererPlug, [this].concat(args)) || this;
7171
6078
  _this.name = 'canvas-context-register';
7172
6079
  return _this;
7173
6080
  }
7174
- _createClass(ContextRegisterPlugin, [{
7175
- key: "init",
7176
- value: function init() {
7177
- this.context.ContextService = Canvas2DContextService;
7178
- }
7179
- }, {
7180
- key: "destroy",
7181
- value: function destroy() {
7182
- delete this.context.ContextService;
7183
- }
7184
- }]);
6081
+ var _proto = ContextRegisterPlugin.prototype;
6082
+ _proto.init = function init() {
6083
+ this.context.ContextService = Canvas2DContextService;
6084
+ };
6085
+ _proto.destroy = function destroy() {
6086
+ delete this.context.ContextService;
6087
+ };
7185
6088
  return ContextRegisterPlugin;
7186
6089
  }(gLite.AbstractRendererPlugin);
7187
6090
 
7188
6091
  var Renderer = /*#__PURE__*/function (_AbstractRenderer) {
7189
- _inherits(Renderer, _AbstractRenderer);
7190
- var _super = _createSuper(Renderer);
6092
+ _inheritsLoose(Renderer, _AbstractRenderer);
7191
6093
  function Renderer(config) {
7192
6094
  var _this;
7193
- _classCallCheck(this, Renderer);
7194
- _this = _super.call(this, config);
6095
+ _this = _AbstractRenderer.call(this, config) || this;
7195
6096
  // register Canvas2DContext
7196
6097
  _this.registerPlugin(new ContextRegisterPlugin());
7197
6098
  _this.registerPlugin(new Plugin$5());
@@ -7205,7 +6106,7 @@
7205
6106
  _this.registerPlugin(new Plugin$4());
7206
6107
  return _this;
7207
6108
  }
7208
- return _createClass(Renderer);
6109
+ return Renderer;
7209
6110
  }(gLite.AbstractRenderer);
7210
6111
 
7211
6112
  exports.CanvasPathGenerator = index_esm;