@antv/g-svg 1.2.0 → 1.2.1

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
@@ -349,6 +349,16 @@
349
349
  }, exports;
350
350
  }
351
351
 
352
+ function _typeof(obj) {
353
+ "@babel/helpers - typeof";
354
+
355
+ return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) {
356
+ return typeof obj;
357
+ } : function (obj) {
358
+ return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
359
+ }, _typeof(obj);
360
+ }
361
+
352
362
  function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
353
363
  try {
354
364
  var info = gen[key](arg);
@@ -385,22 +395,114 @@
385
395
  };
386
396
  }
387
397
 
388
- function _inheritsLoose(subClass, superClass) {
389
- subClass.prototype = Object.create(superClass.prototype);
390
- subClass.prototype.constructor = subClass;
398
+ function _classCallCheck(instance, Constructor) {
399
+ if (!(instance instanceof Constructor)) {
400
+ throw new TypeError("Cannot call a class as a function");
401
+ }
402
+ }
403
+
404
+ function _defineProperties(target, props) {
405
+ for (var i = 0; i < props.length; i++) {
406
+ var descriptor = props[i];
407
+ descriptor.enumerable = descriptor.enumerable || false;
408
+ descriptor.configurable = true;
409
+ if ("value" in descriptor) descriptor.writable = true;
410
+ Object.defineProperty(target, descriptor.key, descriptor);
411
+ }
412
+ }
413
+
414
+ function _createClass(Constructor, protoProps, staticProps) {
415
+ if (protoProps) _defineProperties(Constructor.prototype, protoProps);
416
+ if (staticProps) _defineProperties(Constructor, staticProps);
417
+ Object.defineProperty(Constructor, "prototype", {
418
+ writable: false
419
+ });
420
+ return Constructor;
421
+ }
422
+
423
+ function _inherits(subClass, superClass) {
424
+ if (typeof superClass !== "function" && superClass !== null) {
425
+ throw new TypeError("Super expression must either be null or a function");
426
+ }
427
+
428
+ subClass.prototype = Object.create(superClass && superClass.prototype, {
429
+ constructor: {
430
+ value: subClass,
431
+ writable: true,
432
+ configurable: true
433
+ }
434
+ });
435
+ Object.defineProperty(subClass, "prototype", {
436
+ writable: false
437
+ });
438
+ if (superClass) _setPrototypeOf(subClass, superClass);
439
+ }
391
440
 
392
- _setPrototypeOf(subClass, superClass);
441
+ function _getPrototypeOf(o) {
442
+ _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) {
443
+ return o.__proto__ || Object.getPrototypeOf(o);
444
+ };
445
+ return _getPrototypeOf(o);
393
446
  }
394
447
 
395
448
  function _setPrototypeOf(o, p) {
396
- _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) {
449
+ _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) {
397
450
  o.__proto__ = p;
398
451
  return o;
399
452
  };
400
-
401
453
  return _setPrototypeOf(o, p);
402
454
  }
403
455
 
456
+ function _isNativeReflectConstruct() {
457
+ if (typeof Reflect === "undefined" || !Reflect.construct) return false;
458
+ if (Reflect.construct.sham) return false;
459
+ if (typeof Proxy === "function") return true;
460
+
461
+ try {
462
+ Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {}));
463
+ return true;
464
+ } catch (e) {
465
+ return false;
466
+ }
467
+ }
468
+
469
+ function _assertThisInitialized(self) {
470
+ if (self === void 0) {
471
+ throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
472
+ }
473
+
474
+ return self;
475
+ }
476
+
477
+ function _possibleConstructorReturn(self, call) {
478
+ if (call && (typeof call === "object" || typeof call === "function")) {
479
+ return call;
480
+ } else if (call !== void 0) {
481
+ throw new TypeError("Derived constructors may only return object or undefined");
482
+ }
483
+
484
+ return _assertThisInitialized(self);
485
+ }
486
+
487
+ function _createSuper(Derived) {
488
+ var hasNativeReflectConstruct = _isNativeReflectConstruct();
489
+
490
+ return function _createSuperInternal() {
491
+ var Super = _getPrototypeOf(Derived),
492
+ result;
493
+
494
+ if (hasNativeReflectConstruct) {
495
+ var NewTarget = _getPrototypeOf(this).constructor;
496
+
497
+ result = Reflect.construct(Super, arguments, NewTarget);
498
+ } else {
499
+ result = Super.apply(this, arguments);
500
+ }
501
+
502
+ return _possibleConstructorReturn(this, result);
503
+ };
504
+ }
505
+
404
506
  /******************************************************************************
405
507
  Copyright (c) Microsoft Corporation.
406
508
 
@@ -552,7 +654,7 @@
552
654
  if ("throw" !== record.type) {
553
655
  var result = record.arg,
554
656
  value = result.value;
555
- return value && "object" == typeof value && hasOwn.call(value, "__await") ? PromiseImpl.resolve(value.__await).then(function (value) {
657
+ return value && "object" == _typeof(value) && hasOwn.call(value, "__await") ? PromiseImpl.resolve(value.__await).then(function (value) {
556
658
  invoke("next", value, resolve, reject);
557
659
  }, function (err) {
558
660
  invoke("throw", err, resolve, reject);
@@ -813,6 +915,31 @@
813
915
  };
814
916
  }
815
917
 
918
+ function _classCallCheck$1(instance, Constructor) {
919
+ if (!(instance instanceof Constructor)) {
920
+ throw new TypeError("Cannot call a class as a function");
921
+ }
922
+ }
923
+
924
+ function _defineProperties$1(target, props) {
925
+ for (var i = 0; i < props.length; i++) {
926
+ var descriptor = props[i];
927
+ descriptor.enumerable = descriptor.enumerable || false;
928
+ descriptor.configurable = true;
929
+ if ("value" in descriptor) descriptor.writable = true;
930
+ Object.defineProperty(target, descriptor.key, descriptor);
931
+ }
932
+ }
933
+
934
+ function _createClass$1(Constructor, protoProps, staticProps) {
935
+ if (protoProps) _defineProperties$1(Constructor.prototype, protoProps);
936
+ if (staticProps) _defineProperties$1(Constructor, staticProps);
937
+ Object.defineProperty(Constructor, "prototype", {
938
+ writable: false
939
+ });
940
+ return Constructor;
941
+ }
942
+
816
943
  var _class;
817
944
 
818
945
  var DOMInteractionPlugin_1;
@@ -822,147 +949,150 @@
822
949
 
823
950
  var DOMInteractionPlugin = DOMInteractionPlugin_1 = (_class = /*#__PURE__*/function () {
824
951
  function DOMInteractionPlugin() {
952
+ _classCallCheck$1(this, DOMInteractionPlugin);
953
+
825
954
  this.contextService = void 0;
826
955
  this.renderingContext = void 0;
827
956
  }
828
957
 
829
- var _proto = DOMInteractionPlugin.prototype;
958
+ _createClass$1(DOMInteractionPlugin, [{
959
+ key: "apply",
960
+ value: function apply(renderingService) {
961
+ var _this = this;
830
962
 
831
- _proto.apply = function apply(renderingService) {
832
- var _this = this;
963
+ var canvas = this.renderingContext.root.ownerDocument.defaultView; // const SUPPORT_ONLY_TOUCH = canvas.supportsTouchEvents && MOBILE_REGEX.test(navigator.userAgent);
833
964
 
834
- var canvas = this.renderingContext.root.ownerDocument.defaultView; // const SUPPORT_ONLY_TOUCH = canvas.supportsTouchEvents && MOBILE_REGEX.test(navigator.userAgent);
965
+ var onPointerMove = function onPointerMove(ev) {
966
+ renderingService.hooks.pointerMove.call(ev);
967
+ };
835
968
 
836
- var onPointerMove = function onPointerMove(ev) {
837
- renderingService.hooks.pointerMove.call(ev);
838
- };
969
+ var onPointerUp = function onPointerUp(ev) {
970
+ renderingService.hooks.pointerUp.call(ev);
971
+ };
839
972
 
840
- var onPointerUp = function onPointerUp(ev) {
841
- renderingService.hooks.pointerUp.call(ev);
842
- };
973
+ var onPointerDown = function onPointerDown(ev) {
974
+ renderingService.hooks.pointerDown.call(ev);
975
+ };
843
976
 
844
- var onPointerDown = function onPointerDown(ev) {
845
- renderingService.hooks.pointerDown.call(ev);
846
- };
977
+ var onPointerOver = function onPointerOver(ev) {
978
+ renderingService.hooks.pointerOver.call(ev);
979
+ };
847
980
 
848
- var onPointerOver = function onPointerOver(ev) {
849
- renderingService.hooks.pointerOver.call(ev);
850
- };
981
+ var onPointerOut = function onPointerOut(ev) {
982
+ renderingService.hooks.pointerOut.call(ev);
983
+ };
851
984
 
852
- var onPointerOut = function onPointerOut(ev) {
853
- renderingService.hooks.pointerOut.call(ev);
854
- };
985
+ var onPointerCancel = function onPointerCancel(ev) {
986
+ renderingService.hooks.pointerCancel.call(ev);
987
+ };
855
988
 
856
- var onPointerCancel = function onPointerCancel(ev) {
857
- renderingService.hooks.pointerCancel.call(ev);
858
- };
989
+ var onPointerWheel = function onPointerWheel(ev) {
990
+ renderingService.hooks.pointerWheel.call(ev);
991
+ };
859
992
 
860
- var onPointerWheel = function onPointerWheel(ev) {
861
- renderingService.hooks.pointerWheel.call(ev);
862
- };
993
+ var addPointerEventListener = function addPointerEventListener($el) {
994
+ globalThis.document.addEventListener('pointermove', onPointerMove, true);
995
+ $el.addEventListener('pointerdown', onPointerDown, true);
996
+ $el.addEventListener('pointerleave', onPointerOut, true);
997
+ $el.addEventListener('pointerover', onPointerOver, true);
998
+ globalThis.addEventListener('pointerup', onPointerUp, true);
999
+ };
863
1000
 
864
- var addPointerEventListener = function addPointerEventListener($el) {
865
- globalThis.document.addEventListener('pointermove', onPointerMove, true);
866
- $el.addEventListener('pointerdown', onPointerDown, true);
867
- $el.addEventListener('pointerleave', onPointerOut, true);
868
- $el.addEventListener('pointerover', onPointerOver, true);
869
- globalThis.addEventListener('pointerup', onPointerUp, true);
870
- };
1001
+ var addTouchEventListener = function addTouchEventListener($el) {
1002
+ $el.addEventListener('touchstart', onPointerDown, true);
1003
+ $el.addEventListener('touchend', onPointerUp, true);
1004
+ $el.addEventListener('touchmove', onPointerMove, true);
1005
+ $el.addEventListener('touchcancel', onPointerCancel, true);
1006
+ };
871
1007
 
872
- var addTouchEventListener = function addTouchEventListener($el) {
873
- $el.addEventListener('touchstart', onPointerDown, true);
874
- $el.addEventListener('touchend', onPointerUp, true);
875
- $el.addEventListener('touchmove', onPointerMove, true);
876
- $el.addEventListener('touchcancel', onPointerCancel, true);
877
- };
1008
+ var addMouseEventListener = function addMouseEventListener($el) {
1009
+ globalThis.document.addEventListener('mousemove', onPointerMove, true);
1010
+ $el.addEventListener('mousedown', onPointerDown, true);
1011
+ $el.addEventListener('mouseout', onPointerOut, true);
1012
+ $el.addEventListener('mouseover', onPointerOver, true);
1013
+ globalThis.addEventListener('mouseup', onPointerUp, true);
1014
+ };
878
1015
 
879
- var addMouseEventListener = function addMouseEventListener($el) {
880
- globalThis.document.addEventListener('mousemove', onPointerMove, true);
881
- $el.addEventListener('mousedown', onPointerDown, true);
882
- $el.addEventListener('mouseout', onPointerOut, true);
883
- $el.addEventListener('mouseover', onPointerOver, true);
884
- globalThis.addEventListener('mouseup', onPointerUp, true);
885
- };
1016
+ var removePointerEventListener = function removePointerEventListener($el) {
1017
+ globalThis.document.removeEventListener('pointermove', onPointerMove, true);
1018
+ $el.removeEventListener('pointerdown', onPointerDown, true);
1019
+ $el.removeEventListener('pointerleave', onPointerOut, true);
1020
+ $el.removeEventListener('pointerover', onPointerOver, true);
1021
+ globalThis.removeEventListener('pointerup', onPointerUp, true);
1022
+ };
886
1023
 
887
- var removePointerEventListener = function removePointerEventListener($el) {
888
- globalThis.document.removeEventListener('pointermove', onPointerMove, true);
889
- $el.removeEventListener('pointerdown', onPointerDown, true);
890
- $el.removeEventListener('pointerleave', onPointerOut, true);
891
- $el.removeEventListener('pointerover', onPointerOver, true);
892
- globalThis.removeEventListener('pointerup', onPointerUp, true);
893
- };
1024
+ var removeTouchEventListener = function removeTouchEventListener($el) {
1025
+ $el.removeEventListener('touchstart', onPointerDown, true);
1026
+ $el.removeEventListener('touchend', onPointerUp, true);
1027
+ $el.removeEventListener('touchmove', onPointerMove, true);
1028
+ };
894
1029
 
895
- var removeTouchEventListener = function removeTouchEventListener($el) {
896
- $el.removeEventListener('touchstart', onPointerDown, true);
897
- $el.removeEventListener('touchend', onPointerUp, true);
898
- $el.removeEventListener('touchmove', onPointerMove, true);
899
- };
1030
+ var removeMouseEventListener = function removeMouseEventListener($el) {
1031
+ globalThis.document.removeEventListener('mousemove', onPointerMove, true);
1032
+ $el.removeEventListener('mousedown', onPointerDown, true);
1033
+ $el.removeEventListener('mouseout', onPointerOut, true);
1034
+ $el.removeEventListener('mouseover', onPointerOver, true);
1035
+ globalThis.removeEventListener('mouseup', onPointerUp, true);
1036
+ };
900
1037
 
901
- var removeMouseEventListener = function removeMouseEventListener($el) {
902
- globalThis.document.removeEventListener('mousemove', onPointerMove, true);
903
- $el.removeEventListener('mousedown', onPointerDown, true);
904
- $el.removeEventListener('mouseout', onPointerOut, true);
905
- $el.removeEventListener('mouseover', onPointerOver, true);
906
- globalThis.removeEventListener('mouseup', onPointerUp, true);
907
- };
1038
+ renderingService.hooks.init.tapPromise(DOMInteractionPlugin_1.tag, /*#__PURE__*/_asyncToGenerator$1( /*#__PURE__*/_regeneratorRuntime$1().mark(function _callee() {
1039
+ var $el;
1040
+ return _regeneratorRuntime$1().wrap(function _callee$(_context) {
1041
+ while (1) {
1042
+ switch (_context.prev = _context.next) {
1043
+ case 0:
1044
+ $el = _this.contextService.getDomElement(); // @ts-ignore
908
1045
 
909
- renderingService.hooks.init.tapPromise(DOMInteractionPlugin_1.tag, /*#__PURE__*/_asyncToGenerator$1( /*#__PURE__*/_regeneratorRuntime$1().mark(function _callee() {
910
- var $el;
911
- return _regeneratorRuntime$1().wrap(function _callee$(_context) {
912
- while (1) {
913
- switch (_context.prev = _context.next) {
914
- case 0:
915
- $el = _this.contextService.getDomElement(); // @ts-ignore
916
-
917
- if (globalThis.navigator.msPointerEnabled) {
918
- // @ts-ignore
919
- $el.style.msContentZooming = 'none'; // @ts-ignore
920
-
921
- $el.style.msTouchAction = 'none';
922
- } else if (canvas.supportsPointerEvents) {
923
- $el.style.touchAction = 'none';
924
- }
1046
+ if (globalThis.navigator.msPointerEnabled) {
1047
+ // @ts-ignore
1048
+ $el.style.msContentZooming = 'none'; // @ts-ignore
925
1049
 
926
- if (canvas.supportsPointerEvents) {
927
- addPointerEventListener($el);
928
- } else {
929
- addMouseEventListener($el);
930
- }
1050
+ $el.style.msTouchAction = 'none';
1051
+ } else if (canvas.supportsPointerEvents) {
1052
+ $el.style.touchAction = 'none';
1053
+ }
931
1054
 
932
- if (canvas.supportsTouchEvents) {
933
- addTouchEventListener($el);
934
- } // use passive event listeners
935
- // @see https://zhuanlan.zhihu.com/p/24555031
1055
+ if (canvas.supportsPointerEvents) {
1056
+ addPointerEventListener($el);
1057
+ } else {
1058
+ addMouseEventListener($el);
1059
+ }
1060
+
1061
+ if (canvas.supportsTouchEvents) {
1062
+ addTouchEventListener($el);
1063
+ } // use passive event listeners
1064
+ // @see https://zhuanlan.zhihu.com/p/24555031
936
1065
 
937
1066
 
938
- $el.addEventListener('wheel', onPointerWheel, {
939
- passive: true,
940
- capture: true
941
- });
1067
+ $el.addEventListener('wheel', onPointerWheel, {
1068
+ passive: true,
1069
+ capture: true
1070
+ });
942
1071
 
943
- case 5:
944
- case "end":
945
- return _context.stop();
1072
+ case 5:
1073
+ case "end":
1074
+ return _context.stop();
1075
+ }
946
1076
  }
947
- }
948
- }, _callee);
949
- })));
950
- renderingService.hooks.destroy.tap(DOMInteractionPlugin_1.tag, function () {
951
- var $el = _this.contextService.getDomElement();
1077
+ }, _callee);
1078
+ })));
1079
+ renderingService.hooks.destroy.tap(DOMInteractionPlugin_1.tag, function () {
1080
+ var $el = _this.contextService.getDomElement();
952
1081
 
953
- if (canvas.supportsPointerEvents) {
954
- removePointerEventListener($el);
955
- } else {
956
- removeMouseEventListener($el);
957
- }
1082
+ if (canvas.supportsPointerEvents) {
1083
+ removePointerEventListener($el);
1084
+ } else {
1085
+ removeMouseEventListener($el);
1086
+ }
958
1087
 
959
- if (canvas.supportsTouchEvents) {
960
- removeTouchEventListener($el);
961
- }
1088
+ if (canvas.supportsTouchEvents) {
1089
+ removeTouchEventListener($el);
1090
+ }
962
1091
 
963
- $el.removeEventListener('wheel', onPointerWheel, true);
964
- });
965
- };
1092
+ $el.removeEventListener('wheel', onPointerWheel, true);
1093
+ });
1094
+ }
1095
+ }]);
966
1096
 
967
1097
  return DOMInteractionPlugin;
968
1098
  }(), _class.tag = 'DOMInteraction', _class);
@@ -980,18 +1110,22 @@
980
1110
 
981
1111
  var Plugin = /*#__PURE__*/function () {
982
1112
  function Plugin() {
1113
+ _classCallCheck$1(this, Plugin);
1114
+
983
1115
  this.name = 'dom-interaction';
984
1116
  }
985
1117
 
986
- var _proto = Plugin.prototype;
987
-
988
- _proto.init = function init(container) {
989
- container.load(containerModule, true);
990
- };
991
-
992
- _proto.destroy = function destroy(container) {
993
- container.unload(containerModule);
994
- };
1118
+ _createClass$1(Plugin, [{
1119
+ key: "init",
1120
+ value: function init(container) {
1121
+ container.load(containerModule, true);
1122
+ }
1123
+ }, {
1124
+ key: "destroy",
1125
+ value: function destroy(container) {
1126
+ container.unload(containerModule);
1127
+ }
1128
+ }]);
995
1129
 
996
1130
  return Plugin;
997
1131
  }();
@@ -1207,1353 +1341,1472 @@
1207
1341
  return output;
1208
1342
  }
1209
1343
 
1210
- var ElementSVG = function ElementSVG() {
1211
- this.$el = void 0;
1212
- this.$groupEl = void 0;
1213
- this.$hitTestingEl = void 0;
1214
- };
1344
+ function _regeneratorRuntime$2() {
1345
+ /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */
1346
+ _regeneratorRuntime$2 = function _regeneratorRuntime() {
1347
+ return exports;
1348
+ };
1215
1349
 
1216
- ElementSVG.tag = 'c-svg-element';
1350
+ var exports = {},
1351
+ Op = Object.prototype,
1352
+ hasOwn = Op.hasOwnProperty,
1353
+ $Symbol = "function" == typeof Symbol ? Symbol : {},
1354
+ iteratorSymbol = $Symbol.iterator || "@@iterator",
1355
+ asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator",
1356
+ toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag";
1217
1357
 
1218
- function updateImageElementAttribute($el, parsedStyle) {
1219
- var _parsedStyle$img = parsedStyle.img,
1220
- img = _parsedStyle$img === void 0 ? '' : _parsedStyle$img,
1221
- width = parsedStyle.width,
1222
- height = parsedStyle.height;
1223
- $el.setAttribute('x', '0');
1224
- $el.setAttribute('y', '0');
1358
+ function define(obj, key, value) {
1359
+ return Object.defineProperty(obj, key, {
1360
+ value: value,
1361
+ enumerable: !0,
1362
+ configurable: !0,
1363
+ writable: !0
1364
+ }), obj[key];
1365
+ }
1225
1366
 
1226
- if (g.isString(img)) {
1227
- $el.setAttribute('href', img);
1228
- } else if (img instanceof Image) {
1229
- if (!width) {
1230
- $el.setAttribute('width', "" + img.width); // TODO: set renderable.boundsDirty
1231
- // this.attr('width', img.width);
1232
- }
1367
+ try {
1368
+ define({}, "");
1369
+ } catch (err) {
1370
+ define = function define(obj, key, value) {
1371
+ return obj[key] = value;
1372
+ };
1373
+ }
1233
1374
 
1234
- if (!height) {
1235
- $el.setAttribute('height', "" + img.height); // this.attr('height', img.height);
1236
- }
1375
+ function wrap(innerFn, outerFn, self, tryLocsList) {
1376
+ var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator,
1377
+ generator = Object.create(protoGenerator.prototype),
1378
+ context = new Context(tryLocsList || []);
1379
+ return generator._invoke = function (innerFn, self, context) {
1380
+ var state = "suspendedStart";
1381
+ return function (method, arg) {
1382
+ if ("executing" === state) throw new Error("Generator is already running");
1237
1383
 
1238
- $el.setAttribute('href', img.src);
1239
- } else if ( // @ts-ignore
1240
- img instanceof HTMLElement && g.isString(img.nodeName) && img.nodeName.toUpperCase() === 'CANVAS') {
1241
- $el.setAttribute('href', img.toDataURL()); // @ts-ignore
1242
- } else if (img instanceof ImageData) {
1243
- var canvas = document.createElement('canvas'); // @ts-ignore
1384
+ if ("completed" === state) {
1385
+ if ("throw" === method) throw arg;
1386
+ return doneResult();
1387
+ }
1244
1388
 
1245
- canvas.setAttribute('width', "" + img.width); // @ts-ignore
1389
+ for (context.method = method, context.arg = arg;;) {
1390
+ var delegate = context.delegate;
1246
1391
 
1247
- canvas.setAttribute('height', "" + img.height);
1248
- var context = canvas.getContext('2d');
1392
+ if (delegate) {
1393
+ var delegateResult = maybeInvokeDelegate(delegate, context);
1249
1394
 
1250
- if (context) {
1251
- context.putImageData(img, 0, 0);
1395
+ if (delegateResult) {
1396
+ if (delegateResult === ContinueSentinel) continue;
1397
+ return delegateResult;
1398
+ }
1399
+ }
1252
1400
 
1253
- if (!width) {
1254
- // @ts-ignore
1255
- $el.setAttribute('width', "" + img.width); // this.attr('width', img.width);
1256
- }
1401
+ if ("next" === context.method) context.sent = context._sent = context.arg;else if ("throw" === context.method) {
1402
+ if ("suspendedStart" === state) throw state = "completed", context.arg;
1403
+ context.dispatchException(context.arg);
1404
+ } else "return" === context.method && context.abrupt("return", context.arg);
1405
+ state = "executing";
1406
+ var record = tryCatch(innerFn, self, context);
1257
1407
 
1258
- if (!height) {
1259
- // @ts-ignore
1260
- $el.setAttribute('height', "" + img.height); // this.attr('height', img.height);
1261
- }
1408
+ if ("normal" === record.type) {
1409
+ if (state = context.done ? "completed" : "suspendedYield", record.arg === ContinueSentinel) continue;
1410
+ return {
1411
+ value: record.arg,
1412
+ done: context.done
1413
+ };
1414
+ }
1262
1415
 
1263
- $el.setAttribute('href', canvas.toDataURL());
1264
- }
1416
+ "throw" === record.type && (state = "completed", context.method = "throw", context.arg = record.arg);
1417
+ }
1418
+ };
1419
+ }(innerFn, self, context), generator;
1265
1420
  }
1266
- }
1267
-
1268
- function updateLineElementAttribute($el, parsedStyle) {
1269
- var x1 = parsedStyle.x1,
1270
- y1 = parsedStyle.y1,
1271
- x2 = parsedStyle.x2,
1272
- y2 = parsedStyle.y2,
1273
- defX = parsedStyle.defX,
1274
- defY = parsedStyle.defY;
1275
- $el.setAttribute('x1', "" + (x1.value - defX));
1276
- $el.setAttribute('y1', "" + (y1.value - defY));
1277
- $el.setAttribute('x2', "" + (x2.value - defX));
1278
- $el.setAttribute('y2', "" + (y2.value - defY));
1279
- }
1280
-
1281
- function updatePathElementAttribute($el, parsedStyle) {
1282
- var path = parsedStyle.path,
1283
- _parsedStyle$defX = parsedStyle.defX,
1284
- x = _parsedStyle$defX === void 0 ? 0 : _parsedStyle$defX,
1285
- _parsedStyle$defY = parsedStyle.defY,
1286
- y = _parsedStyle$defY === void 0 ? 0 : _parsedStyle$defY;
1287
- $el.setAttribute('d', formatPath(path.absolutePath, x, y));
1288
- }
1289
-
1290
- function formatPath(value, x, y) {
1291
- var newValue = value.map(function (params) {
1292
- var command = params[0];
1293
1421
 
1294
- switch (command) {
1295
- case 'M':
1296
- return "M " + (params[1] - x) + "," + (params[2] - y);
1422
+ function tryCatch(fn, obj, arg) {
1423
+ try {
1424
+ return {
1425
+ type: "normal",
1426
+ arg: fn.call(obj, arg)
1427
+ };
1428
+ } catch (err) {
1429
+ return {
1430
+ type: "throw",
1431
+ arg: err
1432
+ };
1433
+ }
1434
+ }
1297
1435
 
1298
- case 'L':
1299
- return "L " + (params[1] - x) + "," + (params[2] - y);
1436
+ exports.wrap = wrap;
1437
+ var ContinueSentinel = {};
1300
1438
 
1301
- case 'Q':
1302
- return "Q " + (params[1] - x) + " " + (params[2] - y) + "," + (params[3] - x) + " " + (params[4] - y);
1439
+ function Generator() {}
1303
1440
 
1304
- case 'C':
1305
- return "C " + (params[1] - x) + " " + (params[2] - y) + "," + (params[3] - x) + " " + (params[4] - y) + "," + (params[5] - x) + " " + (params[6] - y);
1441
+ function GeneratorFunction() {}
1306
1442
 
1307
- case 'A':
1308
- return "A " + params[1] + " " + params[2] + " " + params[3] + " " + params[4] + " " + params[5] + " " + (params[6] - x) + " " + (params[7] - y);
1443
+ function GeneratorFunctionPrototype() {}
1309
1444
 
1310
- case 'Z':
1311
- return 'Z';
1312
- }
1313
- }).join(' ');
1314
-
1315
- if (~newValue.indexOf('NaN')) {
1316
- return '';
1317
- }
1318
-
1319
- return newValue;
1320
- }
1321
-
1322
- function updatePolylineElementAttribute($el, parsedStyle) {
1323
- var points = parsedStyle.points,
1324
- _parsedStyle$defX = parsedStyle.defX,
1325
- x = _parsedStyle$defX === void 0 ? 0 : _parsedStyle$defX,
1326
- _parsedStyle$defY = parsedStyle.defY,
1327
- y = _parsedStyle$defY === void 0 ? 0 : _parsedStyle$defY;
1445
+ var IteratorPrototype = {};
1446
+ define(IteratorPrototype, iteratorSymbol, function () {
1447
+ return this;
1448
+ });
1449
+ var getProto = Object.getPrototypeOf,
1450
+ NativeIteratorPrototype = getProto && getProto(getProto(values([])));
1451
+ NativeIteratorPrototype && NativeIteratorPrototype !== Op && hasOwn.call(NativeIteratorPrototype, iteratorSymbol) && (IteratorPrototype = NativeIteratorPrototype);
1452
+ var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(IteratorPrototype);
1328
1453
 
1329
- if (points && points.points && points.points.length >= 2) {
1330
- $el.setAttribute('points', points.points.map(function (point) {
1331
- return point[0] - x + "," + (point[1] - y);
1332
- }).join(' '));
1454
+ function defineIteratorMethods(prototype) {
1455
+ ["next", "throw", "return"].forEach(function (method) {
1456
+ define(prototype, method, function (arg) {
1457
+ return this._invoke(method, arg);
1458
+ });
1459
+ });
1333
1460
  }
1334
- }
1335
1461
 
1336
- function updateRectElementAttribute($el, parsedStyle) {
1337
- var radius = parsedStyle.radius,
1338
- width = parsedStyle.width,
1339
- height = parsedStyle.height; // CSSKeyword: auto
1462
+ function AsyncIterator(generator, PromiseImpl) {
1463
+ function invoke(method, arg, resolve, reject) {
1464
+ var record = tryCatch(generator[method], generator, arg);
1340
1465
 
1341
- if (!isFinite(width.value) || !isFinite(height.value)) {
1342
- return;
1343
- }
1466
+ if ("throw" !== record.type) {
1467
+ var result = record.arg,
1468
+ value = result.value;
1469
+ return value && "object" == _typeof(value) && hasOwn.call(value, "__await") ? PromiseImpl.resolve(value.__await).then(function (value) {
1470
+ invoke("next", value, resolve, reject);
1471
+ }, function (err) {
1472
+ invoke("throw", err, resolve, reject);
1473
+ }) : PromiseImpl.resolve(value).then(function (unwrapped) {
1474
+ result.value = unwrapped, resolve(result);
1475
+ }, function (error) {
1476
+ return invoke("throw", error, resolve, reject);
1477
+ });
1478
+ }
1344
1479
 
1345
- var hasRadius = radius && radius.some(function (r) {
1346
- return r.value !== 0;
1347
- });
1348
- var d = '';
1480
+ reject(record.arg);
1481
+ }
1349
1482
 
1350
- if (!hasRadius) {
1351
- d = "M 0,0 l " + width.value + ",0 l 0," + height.value + " l" + -width.value + " 0 z";
1352
- } else {
1353
- var _radius$map = radius.map(function (r) {
1354
- return g.clamp(r.value, 0, Math.min(Math.abs(width.value) / 2, Math.abs(height.value) / 2));
1355
- }),
1356
- tlr = _radius$map[0],
1357
- trr = _radius$map[1],
1358
- brr = _radius$map[2],
1359
- blr = _radius$map[3];
1483
+ var previousPromise;
1360
1484
 
1361
- var signX = width.value > 0 ? 1 : -1;
1362
- var signY = height.value > 0 ? 1 : -1; // sweep-flag @see https://developer.mozilla.org/zh-CN/docs/Web/SVG/Tutorial/Paths#arcs
1485
+ this._invoke = function (method, arg) {
1486
+ function callInvokeWithMethodAndArg() {
1487
+ return new PromiseImpl(function (resolve, reject) {
1488
+ invoke(method, arg, resolve, reject);
1489
+ });
1490
+ }
1363
1491
 
1364
- var sweepFlag = signX + signY !== 0 ? 1 : 0;
1365
- d = [["M " + signX * tlr + ",0"], ["l " + (width.value - signX * (tlr + trr)) + ",0"], ["a " + trr + "," + trr + ",0,0," + sweepFlag + "," + signX * trr + "," + signY * trr], ["l 0," + (height.value - signY * (trr + brr))], ["a " + brr + "," + brr + ",0,0," + sweepFlag + "," + -signX * brr + "," + signY * brr], ["l " + (signX * (brr + blr) - width.value) + ",0"], ["a " + blr + "," + blr + ",0,0," + sweepFlag + "," + -signX * blr + "," + -signY * blr], ["l 0," + (signY * (blr + tlr) - height.value)], ["a " + tlr + "," + tlr + ",0,0," + sweepFlag + "," + signX * tlr + "," + -signY * tlr], ['z']].join(' ');
1492
+ return previousPromise = previousPromise ? previousPromise.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg();
1493
+ };
1366
1494
  }
1367
1495
 
1368
- $el.setAttribute('d', d);
1369
- }
1496
+ function maybeInvokeDelegate(delegate, context) {
1497
+ var method = delegate.iterator[context.method];
1370
1498
 
1371
- function numberToLongString(x) {
1372
- return x.toFixed(6).replace('.000000', '');
1373
- }
1499
+ if (undefined === method) {
1500
+ if (context.delegate = null, "throw" === context.method) {
1501
+ if (delegate.iterator.return && (context.method = "return", context.arg = undefined, maybeInvokeDelegate(delegate, context), "throw" === context.method)) return ContinueSentinel;
1502
+ context.method = "throw", context.arg = new TypeError("The iterator does not provide a 'throw' method");
1503
+ }
1374
1504
 
1375
- function convertHTML(str) {
1376
- var regex = /[&|<|>|"|']/g;
1377
- return str.replace(regex, function (match) {
1378
- if (match === '&') {
1379
- return '&amp;';
1380
- } else if (match === '<') {
1381
- return '&lt;';
1382
- } else if (match === '>') {
1383
- return '&gt;';
1384
- } else if (match === '"') {
1385
- return '&quot;';
1386
- } else {
1387
- return '&apos;';
1505
+ return ContinueSentinel;
1388
1506
  }
1389
- });
1390
- }
1391
1507
 
1392
- var BASELINE_MAP = {
1393
- top: 'before-edge',
1394
- middle: 'central',
1395
- bottom: 'after-edge',
1396
- alphabetic: 'alphabetic',
1397
- ideographic: 'ideographic',
1398
- hanging: 'hanging'
1399
- }; // for FireFox
1400
- // @see https://github.com/plouc/nivo/issues/164
1508
+ var record = tryCatch(method, delegate.iterator, context.arg);
1509
+ if ("throw" === record.type) return context.method = "throw", context.arg = record.arg, context.delegate = null, ContinueSentinel;
1510
+ var info = record.arg;
1511
+ return info ? info.done ? (context[delegate.resultName] = info.value, context.next = delegate.nextLoc, "return" !== context.method && (context.method = "next", context.arg = undefined), context.delegate = null, ContinueSentinel) : info : (context.method = "throw", context.arg = new TypeError("iterator result is not an object"), context.delegate = null, ContinueSentinel);
1512
+ }
1401
1513
 
1402
- var BASELINE_MAP_FOR_FIREFOX = {
1403
- top: 'text-before-edge',
1404
- middle: 'central',
1405
- bottom: 'text-after-edge',
1406
- alphabetic: 'alphabetic',
1407
- ideographic: 'ideographic',
1408
- hanging: 'hanging'
1409
- };
1514
+ function pushTryEntry(locs) {
1515
+ var entry = {
1516
+ tryLoc: locs[0]
1517
+ };
1518
+ 1 in locs && (entry.catchLoc = locs[1]), 2 in locs && (entry.finallyLoc = locs[2], entry.afterLoc = locs[3]), this.tryEntries.push(entry);
1519
+ }
1410
1520
 
1411
- function updateTextElementAttribute($el, parsedStyle) {
1412
- var textBaseline = parsedStyle.textBaseline,
1413
- lineWidth = parsedStyle.lineWidth,
1414
- metrics = parsedStyle.metrics,
1415
- dx = parsedStyle.dx,
1416
- dy = parsedStyle.dy;
1417
- var browser = detect();
1521
+ function resetTryEntry(entry) {
1522
+ var record = entry.completion || {};
1523
+ record.type = "normal", delete record.arg, entry.completion = record;
1524
+ }
1418
1525
 
1419
- if (browser && browser.name === 'firefox') {
1420
- // compatible with FireFox browser, ref: https://github.com/antvis/g/issues/119
1421
- $el.setAttribute('dominant-baseline', BASELINE_MAP_FOR_FIREFOX[textBaseline.value] || 'alphabetic');
1422
- } else {
1423
- $el.setAttribute('dominant-baseline', BASELINE_MAP_FOR_FIREFOX[textBaseline.value]);
1424
- $el.setAttribute('alignment-baseline', BASELINE_MAP[textBaseline.value]);
1526
+ function Context(tryLocsList) {
1527
+ this.tryEntries = [{
1528
+ tryLoc: "root"
1529
+ }], tryLocsList.forEach(pushTryEntry, this), this.reset(!0);
1425
1530
  }
1426
1531
 
1427
- $el.setAttribute('paint-order', 'stroke');
1428
- var lines = metrics.lines,
1429
- lineHeight = metrics.lineHeight,
1430
- height = metrics.height;
1431
- var lineNum = lines.length;
1432
- $el.setAttribute('style', "transform:translate(" + dx.toString() + ", " + dy.toString() + ");");
1532
+ function values(iterable) {
1533
+ if (iterable) {
1534
+ var iteratorMethod = iterable[iteratorSymbol];
1535
+ if (iteratorMethod) return iteratorMethod.call(iterable);
1536
+ if ("function" == typeof iterable.next) return iterable;
1433
1537
 
1434
- if (lineNum === 1) {
1435
- $el.innerHTML = convertHTML(lines[0]);
1436
- $el.setAttribute('dx', "" + lineWidth.value / 2);
1437
- } else {
1438
- $el.innerHTML = lines.map(function (line, i) {
1439
- var dx = lineWidth.value / 2;
1440
- var dy = 0;
1538
+ if (!isNaN(iterable.length)) {
1539
+ var i = -1,
1540
+ next = function next() {
1541
+ for (; ++i < iterable.length;) {
1542
+ if (hasOwn.call(iterable, i)) return next.value = iterable[i], next.done = !1, next;
1543
+ }
1441
1544
 
1442
- if (i === 0) {
1443
- // TODO: handle other textBaseline values
1444
- if (textBaseline.value === 'middle') {
1445
- dy = lineHeight / 2 - height / 2;
1446
- } else if (textBaseline.value === 'top' || textBaseline.value === 'hanging') {
1447
- dy = 0;
1448
- } else if (textBaseline.value === 'bottom' || textBaseline.value === 'alphabetic' || textBaseline.value === 'ideographic') {
1449
- dy = -lineHeight * (lineNum - 1);
1450
- }
1451
- } else {
1452
- dy = lineHeight;
1545
+ return next.value = undefined, next.done = !0, next;
1546
+ };
1547
+
1548
+ return next.next = next;
1453
1549
  }
1550
+ }
1454
1551
 
1455
- return "<tspan x=\"0\" dx=\"" + dx + "\" dy=\"" + dy + "\">" + convertHTML(line) + "</tspan>";
1456
- }).join('');
1552
+ return {
1553
+ next: doneResult
1554
+ };
1457
1555
  }
1458
- }
1459
-
1460
- var CreateElementContribution = g.Syringe.defineToken('CreateElementContribution', {
1461
- multiple: false
1462
- });
1463
1556
 
1464
- function createSVGElement(type, doc) {
1465
- return (doc || document).createElementNS('http://www.w3.org/2000/svg', type);
1466
- }
1557
+ function doneResult() {
1558
+ return {
1559
+ value: undefined,
1560
+ done: !0
1561
+ };
1562
+ }
1467
1563
 
1468
- var _SHAPE2TAGS, _SHAPE_UPDATE_DEPS;
1564
+ return GeneratorFunction.prototype = GeneratorFunctionPrototype, define(Gp, "constructor", GeneratorFunctionPrototype), define(GeneratorFunctionPrototype, "constructor", GeneratorFunction), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, toStringTagSymbol, "GeneratorFunction"), exports.isGeneratorFunction = function (genFun) {
1565
+ var ctor = "function" == typeof genFun && genFun.constructor;
1566
+ return !!ctor && (ctor === GeneratorFunction || "GeneratorFunction" === (ctor.displayName || ctor.name));
1567
+ }, exports.mark = function (genFun) {
1568
+ return Object.setPrototypeOf ? Object.setPrototypeOf(genFun, GeneratorFunctionPrototype) : (genFun.__proto__ = GeneratorFunctionPrototype, define(genFun, toStringTagSymbol, "GeneratorFunction")), genFun.prototype = Object.create(Gp), genFun;
1569
+ }, exports.awrap = function (arg) {
1570
+ return {
1571
+ __await: arg
1572
+ };
1573
+ }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, asyncIteratorSymbol, function () {
1574
+ return this;
1575
+ }), exports.AsyncIterator = AsyncIterator, exports.async = function (innerFn, outerFn, self, tryLocsList, PromiseImpl) {
1576
+ void 0 === PromiseImpl && (PromiseImpl = Promise);
1577
+ var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList), PromiseImpl);
1578
+ return exports.isGeneratorFunction(outerFn) ? iter : iter.next().then(function (result) {
1579
+ return result.done ? result.value : iter.next();
1580
+ });
1581
+ }, defineIteratorMethods(Gp), define(Gp, toStringTagSymbol, "Generator"), define(Gp, iteratorSymbol, function () {
1582
+ return this;
1583
+ }), define(Gp, "toString", function () {
1584
+ return "[object Generator]";
1585
+ }), exports.keys = function (object) {
1586
+ var keys = [];
1469
1587
 
1470
- var SHAPE2TAGS = (_SHAPE2TAGS = {}, _SHAPE2TAGS[g.Shape.RECT] = 'path', _SHAPE2TAGS[g.Shape.CIRCLE] = 'circle', _SHAPE2TAGS[g.Shape.ELLIPSE] = 'ellipse', _SHAPE2TAGS[g.Shape.IMAGE] = 'image', _SHAPE2TAGS[g.Shape.GROUP] = 'g', _SHAPE2TAGS[g.Shape.LINE] = 'line', _SHAPE2TAGS[g.Shape.POLYLINE] = 'polyline', _SHAPE2TAGS[g.Shape.POLYGON] = 'polygon', _SHAPE2TAGS[g.Shape.TEXT] = 'text', _SHAPE2TAGS[g.Shape.PATH] = 'path', _SHAPE2TAGS[g.Shape.HTML] = 'foreignObject', _SHAPE2TAGS);
1471
- var SHAPE_UPDATE_DEPS = (_SHAPE_UPDATE_DEPS = {}, _SHAPE_UPDATE_DEPS[g.Shape.CIRCLE] = ['r'], _SHAPE_UPDATE_DEPS[g.Shape.ELLIPSE] = ['rx', 'ry'], _SHAPE_UPDATE_DEPS[g.Shape.RECT] = ['width', 'height', 'radius'], _SHAPE_UPDATE_DEPS[g.Shape.IMAGE] = ['img', 'width', 'height'], _SHAPE_UPDATE_DEPS[g.Shape.LINE] = ['x1', 'y1', 'x2', 'y2'], _SHAPE_UPDATE_DEPS[g.Shape.POLYLINE] = ['points'], _SHAPE_UPDATE_DEPS[g.Shape.POLYGON] = ['points'], _SHAPE_UPDATE_DEPS[g.Shape.PATH] = ['path'], _SHAPE_UPDATE_DEPS[g.Shape.TEXT] = ['text', 'font', 'fontSize', 'fontFamily', 'fontStyle', 'fontWeight', 'fontVariant', 'lineHeight', 'letterSpacing', 'wordWrap', 'wordWrapWidth', 'leading', 'textBaseline', 'textAlign', 'textTransform', 'whiteSpace', 'dx', 'dy'], _SHAPE_UPDATE_DEPS);
1588
+ for (var key in object) {
1589
+ keys.push(key);
1590
+ }
1472
1591
 
1473
- var DefaultCreateElementContribution = /*#__PURE__*/function () {
1474
- function DefaultCreateElementContribution() {
1475
- this.canvasConfig = void 0;
1476
- }
1592
+ return keys.reverse(), function next() {
1593
+ for (; keys.length;) {
1594
+ var key = keys.pop();
1595
+ if (key in object) return next.value = key, next.done = !1, next;
1596
+ }
1477
1597
 
1478
- var _proto = DefaultCreateElementContribution.prototype;
1598
+ return next.done = !0, next;
1599
+ };
1600
+ }, exports.values = values, Context.prototype = {
1601
+ constructor: Context,
1602
+ reset: function reset(skipTempReset) {
1603
+ if (this.prev = 0, this.next = 0, this.sent = this._sent = undefined, this.done = !1, this.delegate = null, this.method = "next", this.arg = undefined, this.tryEntries.forEach(resetTryEntry), !skipTempReset) for (var name in this) {
1604
+ "t" === name.charAt(0) && hasOwn.call(this, name) && !isNaN(+name.slice(1)) && (this[name] = undefined);
1605
+ }
1606
+ },
1607
+ stop: function stop() {
1608
+ this.done = !0;
1609
+ var rootRecord = this.tryEntries[0].completion;
1610
+ if ("throw" === rootRecord.type) throw rootRecord.arg;
1611
+ return this.rval;
1612
+ },
1613
+ dispatchException: function dispatchException(exception) {
1614
+ if (this.done) throw exception;
1615
+ var context = this;
1479
1616
 
1480
- _proto.createElement = function createElement(object) {
1481
- var doc = this.canvasConfig.document;
1482
- var type = SHAPE2TAGS[object.nodeName] || 'g';
1483
- return createSVGElement(type, doc || document);
1484
- };
1617
+ function handle(loc, caught) {
1618
+ return record.type = "throw", record.arg = exception, context.next = loc, caught && (context.method = "next", context.arg = undefined), !!caught;
1619
+ }
1485
1620
 
1486
- _proto.shouldUpdateElementAttribute = function shouldUpdateElementAttribute(object, attributeName) {
1487
- var nodeName = object.nodeName;
1488
- return (SHAPE_UPDATE_DEPS[nodeName] || []).indexOf(attributeName) > -1;
1489
- };
1621
+ for (var i = this.tryEntries.length - 1; i >= 0; --i) {
1622
+ var entry = this.tryEntries[i],
1623
+ record = entry.completion;
1624
+ if ("root" === entry.tryLoc) return handle("end");
1490
1625
 
1491
- _proto.updateElementAttribute = function updateElementAttribute(object) {
1492
- // @ts-ignore
1493
- var $el = object.elementSVG.$el;
1494
- var nodeName = object.nodeName,
1495
- parsedStyle = object.parsedStyle;
1626
+ if (entry.tryLoc <= this.prev) {
1627
+ var hasCatch = hasOwn.call(entry, "catchLoc"),
1628
+ hasFinally = hasOwn.call(entry, "finallyLoc");
1496
1629
 
1497
- switch (nodeName) {
1498
- case g.Shape.IMAGE:
1499
- {
1500
- updateImageElementAttribute($el, parsedStyle);
1501
- break;
1630
+ if (hasCatch && hasFinally) {
1631
+ if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0);
1632
+ if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc);
1633
+ } else if (hasCatch) {
1634
+ if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0);
1635
+ } else {
1636
+ if (!hasFinally) throw new Error("try statement without catch or finally");
1637
+ if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc);
1638
+ }
1502
1639
  }
1640
+ }
1641
+ },
1642
+ abrupt: function abrupt(type, arg) {
1643
+ for (var i = this.tryEntries.length - 1; i >= 0; --i) {
1644
+ var entry = this.tryEntries[i];
1503
1645
 
1504
- case g.Shape.RECT:
1505
- {
1506
- updateRectElementAttribute($el, parsedStyle);
1646
+ if (entry.tryLoc <= this.prev && hasOwn.call(entry, "finallyLoc") && this.prev < entry.finallyLoc) {
1647
+ var finallyEntry = entry;
1507
1648
  break;
1508
1649
  }
1650
+ }
1509
1651
 
1510
- case g.Shape.LINE:
1511
- {
1512
- updateLineElementAttribute($el, parsedStyle);
1513
- break;
1514
- }
1652
+ finallyEntry && ("break" === type || "continue" === type) && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc && (finallyEntry = null);
1653
+ var record = finallyEntry ? finallyEntry.completion : {};
1654
+ return record.type = type, record.arg = arg, finallyEntry ? (this.method = "next", this.next = finallyEntry.finallyLoc, ContinueSentinel) : this.complete(record);
1655
+ },
1656
+ complete: function complete(record, afterLoc) {
1657
+ if ("throw" === record.type) throw record.arg;
1658
+ return "break" === record.type || "continue" === record.type ? this.next = record.arg : "return" === record.type ? (this.rval = this.arg = record.arg, this.method = "return", this.next = "end") : "normal" === record.type && afterLoc && (this.next = afterLoc), ContinueSentinel;
1659
+ },
1660
+ finish: function finish(finallyLoc) {
1661
+ for (var i = this.tryEntries.length - 1; i >= 0; --i) {
1662
+ var entry = this.tryEntries[i];
1663
+ if (entry.finallyLoc === finallyLoc) return this.complete(entry.completion, entry.afterLoc), resetTryEntry(entry), ContinueSentinel;
1664
+ }
1665
+ },
1666
+ catch: function _catch(tryLoc) {
1667
+ for (var i = this.tryEntries.length - 1; i >= 0; --i) {
1668
+ var entry = this.tryEntries[i];
1515
1669
 
1516
- case g.Shape.POLYGON:
1517
- case g.Shape.POLYLINE:
1518
- {
1519
- updatePolylineElementAttribute($el, parsedStyle);
1520
- break;
1521
- }
1670
+ if (entry.tryLoc === tryLoc) {
1671
+ var record = entry.completion;
1522
1672
 
1523
- case g.Shape.PATH:
1524
- {
1525
- updatePathElementAttribute($el, parsedStyle);
1526
- break;
1527
- }
1673
+ if ("throw" === record.type) {
1674
+ var thrown = record.arg;
1675
+ resetTryEntry(entry);
1676
+ }
1528
1677
 
1529
- case g.Shape.TEXT:
1530
- {
1531
- updateTextElementAttribute($el, parsedStyle);
1532
- break;
1678
+ return thrown;
1533
1679
  }
1680
+ }
1681
+
1682
+ throw new Error("illegal catch attempt");
1683
+ },
1684
+ delegateYield: function delegateYield(iterable, resultName, nextLoc) {
1685
+ return this.delegate = {
1686
+ iterator: values(iterable),
1687
+ resultName: resultName,
1688
+ nextLoc: nextLoc
1689
+ }, "next" === this.method && (this.arg = undefined), ContinueSentinel;
1534
1690
  }
1535
- };
1691
+ }, exports;
1692
+ }
1536
1693
 
1537
- return DefaultCreateElementContribution;
1538
- }();
1694
+ function asyncGeneratorStep$2(gen, resolve, reject, _next, _throw, key, arg) {
1695
+ try {
1696
+ var info = gen[key](arg);
1697
+ var value = info.value;
1698
+ } catch (error) {
1699
+ reject(error);
1700
+ return;
1701
+ }
1539
1702
 
1540
- __decorate([g.inject(g.CanvasConfig), __metadata("design:type", Object)], DefaultCreateElementContribution.prototype, "canvasConfig", void 0);
1703
+ if (info.done) {
1704
+ resolve(value);
1705
+ } else {
1706
+ Promise.resolve(value).then(_next, _throw);
1707
+ }
1708
+ }
1541
1709
 
1542
- DefaultCreateElementContribution = __decorate([g.singleton({
1543
- token: CreateElementContribution
1544
- })], DefaultCreateElementContribution);
1545
- var FILTER_PREFIX = 'g-filter-';
1546
- /**
1547
- * use SVG filters, eg. blur, brightness, contrast...
1548
- * @see https://developer.mozilla.org/zh-CN/docs/Web/SVG/Element/filter
1549
- */
1710
+ function _asyncToGenerator$2(fn) {
1711
+ return function () {
1712
+ var self = this,
1713
+ args = arguments;
1714
+ return new Promise(function (resolve, reject) {
1715
+ var gen = fn.apply(self, args);
1550
1716
 
1551
- function createOrUpdateFilter(document, $def, object, $el, filters) {
1552
- // eg. filter="url(#f1) url(#f2)"
1553
- var filterName = FILTER_PREFIX + object.entity;
1554
- var $existedFilters = $def.querySelectorAll("[name=" + filterName + "]");
1717
+ function _next(value) {
1718
+ asyncGeneratorStep$2(gen, resolve, reject, _next, _throw, "next", value);
1719
+ }
1555
1720
 
1556
- if ($existedFilters.length) {
1557
- $existedFilters.forEach(function ($filter) {
1558
- $def.removeChild($filter);
1721
+ function _throw(err) {
1722
+ asyncGeneratorStep$2(gen, resolve, reject, _next, _throw, "throw", err);
1723
+ }
1724
+
1725
+ _next(undefined);
1559
1726
  });
1727
+ };
1728
+ }
1729
+
1730
+ function _classCallCheck$2(instance, Constructor) {
1731
+ if (!(instance instanceof Constructor)) {
1732
+ throw new TypeError("Cannot call a class as a function");
1560
1733
  }
1734
+ }
1561
1735
 
1562
- if (filters.length === 0) {
1563
- // 'none'
1564
- $el === null || $el === void 0 ? void 0 : $el.removeAttribute('filter');
1736
+ function _defineProperties$2(target, props) {
1737
+ for (var i = 0; i < props.length; i++) {
1738
+ var descriptor = props[i];
1739
+ descriptor.enumerable = descriptor.enumerable || false;
1740
+ descriptor.configurable = true;
1741
+ if ("value" in descriptor) descriptor.writable = true;
1742
+ Object.defineProperty(target, descriptor.key, descriptor);
1743
+ }
1744
+ }
1745
+
1746
+ function _createClass$2(Constructor, protoProps, staticProps) {
1747
+ if (protoProps) _defineProperties$2(Constructor.prototype, protoProps);
1748
+ if (staticProps) _defineProperties$2(Constructor, staticProps);
1749
+ Object.defineProperty(Constructor, "prototype", {
1750
+ writable: false
1751
+ });
1752
+ return Constructor;
1753
+ }
1754
+
1755
+ function _defineProperty(obj, key, value) {
1756
+ if (key in obj) {
1757
+ Object.defineProperty(obj, key, {
1758
+ value: value,
1759
+ enumerable: true,
1760
+ configurable: true,
1761
+ writable: true
1762
+ });
1565
1763
  } else {
1566
- var filterIds = filters.map(function (_ref, i) {
1567
- var name = _ref.name,
1568
- params = _ref.params;
1569
- var $filter = createSVGElement('filter', document); // @see https://github.com/antvis/g/issues/1025
1764
+ obj[key] = value;
1765
+ }
1570
1766
 
1571
- $filter.setAttribute('filterUnits', 'userSpaceOnUse');
1767
+ return obj;
1768
+ }
1572
1769
 
1573
- if (name === 'blur') {
1574
- createBlur(document, $filter, params);
1575
- } else if (name === 'brightness') {
1576
- createBrightness(document, $filter, params);
1577
- } else if (name === 'drop-shadow') {
1578
- createDropShadow(document, $filter, params);
1579
- } else if (name === 'contrast') {
1580
- createContrast(document, $filter, params);
1581
- } else if (name === 'grayscale') {
1582
- createGrayscale(document, $filter, params);
1583
- } else if (name === 'sepia') {
1584
- createSepia(document, $filter, params);
1585
- } else if (name === 'saturate') {
1586
- createSaturate(document, $filter, params);
1587
- } else if (name === 'hue-rotate') {
1588
- createHueRotate(document, $filter, params);
1589
- } else if (name === 'invert') {
1590
- createInvert(document, $filter, params);
1591
- }
1770
+ function _slicedToArray(arr, i) {
1771
+ return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest();
1772
+ }
1592
1773
 
1593
- $filter.id = filterName + "-" + i;
1594
- $filter.setAttribute('name', filterName);
1595
- $def.appendChild($filter);
1596
- return $filter.id;
1597
- });
1598
- $el === null || $el === void 0 ? void 0 : $el.setAttribute('filter', filterIds.map(function (filterId) {
1599
- return "url(#" + filterId + ")";
1600
- }).join(' '));
1774
+ function _arrayWithHoles(arr) {
1775
+ if (Array.isArray(arr)) return arr;
1776
+ }
1777
+
1778
+ function _iterableToArrayLimit(arr, i) {
1779
+ var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
1780
+
1781
+ if (_i == null) return;
1782
+ var _arr = [];
1783
+ var _n = true;
1784
+ var _d = false;
1785
+
1786
+ var _s, _e;
1787
+
1788
+ try {
1789
+ for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) {
1790
+ _arr.push(_s.value);
1791
+
1792
+ if (i && _arr.length === i) break;
1793
+ }
1794
+ } catch (err) {
1795
+ _d = true;
1796
+ _e = err;
1797
+ } finally {
1798
+ try {
1799
+ if (!_n && _i["return"] != null) _i["return"]();
1800
+ } finally {
1801
+ if (_d) throw _e;
1802
+ }
1601
1803
  }
1804
+
1805
+ return _arr;
1602
1806
  }
1603
1807
 
1604
- function convertToAbsoluteValue(param) {
1605
- return param.unit === g.UnitType.kPercentage ? param.value / 100 : param.value;
1808
+ function _unsupportedIterableToArray(o, minLen) {
1809
+ if (!o) return;
1810
+ if (typeof o === "string") return _arrayLikeToArray(o, minLen);
1811
+ var n = Object.prototype.toString.call(o).slice(8, -1);
1812
+ if (n === "Object" && o.constructor) n = o.constructor.name;
1813
+ if (n === "Map" || n === "Set") return Array.from(o);
1814
+ if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
1606
1815
  }
1607
- /**
1608
- * @see https://drafts.fxtf.org/filter-effects/#blurEquivalent
1609
- */
1610
1816
 
1817
+ function _arrayLikeToArray(arr, len) {
1818
+ if (len == null || len > arr.length) len = arr.length;
1611
1819
 
1612
- function createBlur(document, $filter, params) {
1613
- var $feGaussianBlur = createSVGElement('feGaussianBlur', document);
1614
- $feGaussianBlur.setAttribute('in', 'SourceGraphic');
1615
- $feGaussianBlur.setAttribute('stdDeviation', "" + params[0].value);
1616
- $filter.appendChild($feGaussianBlur);
1820
+ for (var i = 0, arr2 = new Array(len); i < len; i++) {
1821
+ arr2[i] = arr[i];
1822
+ }
1823
+
1824
+ return arr2;
1617
1825
  }
1618
1826
 
1619
- function createFeComponentTransfer(document, $filter, _ref2) {
1620
- var type = _ref2.type,
1621
- slope = _ref2.slope,
1622
- intercept = _ref2.intercept,
1623
- tableValues = _ref2.tableValues;
1624
- var $feComponentTransfer = createSVGElement('feComponentTransfer', document);
1625
- [createSVGElement('feFuncR', document), createSVGElement('feFuncG', document), createSVGElement('feFuncB', document)].forEach(function ($feFunc) {
1626
- $feFunc.setAttribute('type', type);
1827
+ function _nonIterableRest() {
1828
+ throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
1829
+ }
1830
+
1831
+ var ElementSVG = /*#__PURE__*/_createClass$2(function ElementSVG() {
1832
+ _classCallCheck$2(this, ElementSVG);
1833
+
1834
+ this.$el = void 0;
1835
+ this.$groupEl = void 0;
1836
+ this.$hitTestingEl = void 0;
1837
+ });
1838
+
1839
+ ElementSVG.tag = 'c-svg-element';
1840
+
1841
+ function updateImageElementAttribute($el, parsedStyle) {
1842
+ var _parsedStyle$img = parsedStyle.img,
1843
+ img = _parsedStyle$img === void 0 ? '' : _parsedStyle$img,
1844
+ width = parsedStyle.width,
1845
+ height = parsedStyle.height;
1846
+ $el.setAttribute('x', '0');
1847
+ $el.setAttribute('y', '0');
1848
+
1849
+ if (g.isString(img)) {
1850
+ $el.setAttribute('href', img);
1851
+ } else if (img instanceof Image) {
1852
+ if (!width) {
1853
+ $el.setAttribute('width', "".concat(img.width)); // TODO: set renderable.boundsDirty
1854
+ // this.attr('width', img.width);
1855
+ }
1627
1856
 
1628
- if (type === 'table') {
1629
- $feFunc.setAttribute('tableValues', "" + tableValues);
1630
- } else {
1631
- $feFunc.setAttribute('slope', "" + slope);
1632
- $feFunc.setAttribute('intercept', "" + intercept);
1857
+ if (!height) {
1858
+ $el.setAttribute('height', "".concat(img.height)); // this.attr('height', img.height);
1633
1859
  }
1634
1860
 
1635
- $feComponentTransfer.appendChild($feFunc);
1636
- });
1637
- $filter.appendChild($feComponentTransfer);
1638
- }
1861
+ $el.setAttribute('href', img.src);
1862
+ } else if ( // @ts-ignore
1863
+ img instanceof HTMLElement && g.isString(img.nodeName) && img.nodeName.toUpperCase() === 'CANVAS') {
1864
+ $el.setAttribute('href', img.toDataURL()); // @ts-ignore
1865
+ } else if (img instanceof ImageData) {
1866
+ var canvas = document.createElement('canvas'); // @ts-ignore
1639
1867
 
1640
- function createContrast(document, $filter, params) {
1641
- var slope = convertToAbsoluteValue(params[0]);
1642
- createFeComponentTransfer(document, $filter, {
1643
- type: 'linear',
1644
- slope: slope,
1645
- intercept: -(0.5 * slope) + 0.5
1646
- });
1647
- }
1868
+ canvas.setAttribute('width', "".concat(img.width)); // @ts-ignore
1648
1869
 
1649
- function createInvert(document, $filter, params) {
1650
- var amount = convertToAbsoluteValue(params[0]);
1651
- createFeComponentTransfer(document, $filter, {
1652
- type: 'table',
1653
- tableValues: amount + " " + (1 - amount)
1654
- });
1655
- }
1870
+ canvas.setAttribute('height', "".concat(img.height));
1871
+ var context = canvas.getContext('2d');
1656
1872
 
1657
- function createBrightness(document, $filter, params) {
1658
- var slope = convertToAbsoluteValue(params[0]);
1659
- createFeComponentTransfer(document, $filter, {
1660
- type: 'linear',
1661
- slope: slope,
1662
- intercept: 0
1663
- });
1664
- }
1873
+ if (context) {
1874
+ context.putImageData(img, 0, 0);
1665
1875
 
1666
- function createSaturate(document, $filter, params) {
1667
- var amount = convertToAbsoluteValue(params[0]);
1668
- var $feColorMatrix = createSVGElement('feColorMatrix', document);
1669
- $feColorMatrix.setAttribute('type', 'saturate');
1670
- $feColorMatrix.setAttribute('values', "" + amount);
1671
- $filter.appendChild($feColorMatrix);
1672
- }
1876
+ if (!width) {
1877
+ // @ts-ignore
1878
+ $el.setAttribute('width', "".concat(img.width)); // this.attr('width', img.width);
1879
+ }
1673
1880
 
1674
- function createHueRotate(document, $filter, params) {
1675
- var $feColorMatrix = createSVGElement('feColorMatrix', document);
1676
- $feColorMatrix.setAttribute('type', 'hueRotate');
1677
- $feColorMatrix.setAttribute('values', "" + params[0].to(g.UnitType.kDegrees).value);
1678
- $filter.appendChild($feColorMatrix);
1679
- }
1881
+ if (!height) {
1882
+ // @ts-ignore
1883
+ $el.setAttribute('height', "".concat(img.height)); // this.attr('height', img.height);
1884
+ }
1680
1885
 
1681
- function createDropShadow(document, $filter, params) {
1682
- var shadowOffsetX = params[0].value;
1683
- var shadowOffsetY = params[1].value;
1684
- var shadowBlur = params[2].value; // @ts-ignore
1886
+ $el.setAttribute('href', canvas.toDataURL());
1887
+ }
1888
+ }
1889
+ }
1685
1890
 
1686
- var shadowColor = params[3].formatted;
1687
- var $feGaussianBlur = createSVGElement('feGaussianBlur', document);
1688
- $feGaussianBlur.setAttribute('in', 'SourceAlpha');
1689
- $feGaussianBlur.setAttribute('stdDeviation', "" + shadowBlur);
1690
- $filter.appendChild($feGaussianBlur);
1691
- var $feOffset = createSVGElement('feOffset', document);
1692
- $feOffset.setAttribute('dx', "" + shadowOffsetX);
1693
- $feOffset.setAttribute('dy', "" + shadowOffsetY);
1694
- $feOffset.setAttribute('result', 'offsetblur');
1695
- $filter.appendChild($feOffset);
1696
- var $feFlood = createSVGElement('feFlood', document);
1697
- $feFlood.setAttribute('flood-color', shadowColor);
1698
- $filter.appendChild($feFlood);
1699
- var $feComposite = createSVGElement('feComposite', document);
1700
- $feComposite.setAttribute('in2', 'offsetblur');
1701
- $feComposite.setAttribute('operator', 'in');
1702
- $filter.appendChild($feComposite);
1703
- var $feMerge = createSVGElement('feMerge', document);
1704
- $filter.appendChild($feMerge);
1705
- var $feMergeNode1 = createSVGElement('feMergeNode', document);
1706
- var $feMergeNode2 = createSVGElement('feMergeNode', document);
1707
- $feMergeNode2.setAttribute('in', 'SourceGraphic');
1708
- $feMerge.appendChild($feMergeNode1);
1709
- $feMerge.appendChild($feMergeNode2);
1891
+ function updateLineElementAttribute($el, parsedStyle) {
1892
+ var x1 = parsedStyle.x1,
1893
+ y1 = parsedStyle.y1,
1894
+ x2 = parsedStyle.x2,
1895
+ y2 = parsedStyle.y2,
1896
+ defX = parsedStyle.defX,
1897
+ defY = parsedStyle.defY;
1898
+ $el.setAttribute('x1', "".concat(x1.value - defX));
1899
+ $el.setAttribute('y1', "".concat(y1.value - defY));
1900
+ $el.setAttribute('x2', "".concat(x2.value - defX));
1901
+ $el.setAttribute('y2', "".concat(y2.value - defY));
1710
1902
  }
1711
1903
 
1712
- function createFeColorMatrix(document, $filter, matrix) {
1713
- var $feColorMatrix = createSVGElement('feColorMatrix', document);
1714
- $feColorMatrix.setAttribute('type', 'matrix');
1715
- $feColorMatrix.setAttribute('values', matrix.join(' '));
1716
- $filter.appendChild($feColorMatrix);
1904
+ function updatePathElementAttribute($el, parsedStyle) {
1905
+ var path = parsedStyle.path,
1906
+ _parsedStyle$defX = parsedStyle.defX,
1907
+ x = _parsedStyle$defX === void 0 ? 0 : _parsedStyle$defX,
1908
+ _parsedStyle$defY = parsedStyle.defY,
1909
+ y = _parsedStyle$defY === void 0 ? 0 : _parsedStyle$defY;
1910
+ $el.setAttribute('d', formatPath(path.absolutePath, x, y));
1717
1911
  }
1718
- /**
1719
- * @see https://drafts.fxtf.org/filter-effects/#grayscaleEquivalent
1720
- */
1721
1912
 
1913
+ function formatPath(value, x, y) {
1914
+ var newValue = value.map(function (params) {
1915
+ var command = params[0];
1722
1916
 
1723
- function createGrayscale(document, $filter, params) {
1724
- var amount = convertToAbsoluteValue(params[0]);
1725
- createFeColorMatrix(document, $filter, [0.2126 + 0.7874 * (1 - amount), 0.7152 - 0.7152 * (1 - amount), 0.0722 - 0.0722 * (1 - amount), 0, 0, 0.2126 - 0.2126 * (1 - amount), 0.7152 + 0.2848 * (1 - amount), 0.0722 - 0.0722 * (1 - amount), 0, 0, 0.2126 - 0.2126 * (1 - amount), 0.7152 - 0.7152 * (1 - amount), 0.0722 + 0.9278 * (1 - amount), 0, 0, 0, 0, 0, 1, 0]);
1726
- }
1727
- /**
1728
- * @see https://drafts.fxtf.org/filter-effects/#sepiaEquivalent
1729
- */
1917
+ switch (command) {
1918
+ case 'M':
1919
+ return "M ".concat(params[1] - x, ",").concat(params[2] - y);
1730
1920
 
1921
+ case 'L':
1922
+ return "L ".concat(params[1] - x, ",").concat(params[2] - y);
1731
1923
 
1732
- function createSepia(document, $filter, params) {
1733
- var amount = convertToAbsoluteValue(params[0]);
1734
- createFeColorMatrix(document, $filter, [0.393 + 0.607 * (1 - amount), 0.769 - 0.769 * (1 - amount), 0.189 - 0.189 * (1 - amount), 0, 0, 0.349 - 0.349 * (1 - amount), 0.686 + 0.314 * (1 - amount), 0.168 - 0.168 * (1 - amount), 0, 0, 0.272 - 0.272 * (1 - amount), 0.534 - 0.534 * (1 - amount), 0.131 + 0.869 * (1 - amount), 0, 0, 0, 0, 0, 1, 0]);
1735
- }
1924
+ case 'Q':
1925
+ return "Q ".concat(params[1] - x, " ").concat(params[2] - y, ",").concat(params[3] - x, " ").concat(params[4] - y);
1736
1926
 
1737
- var PATTERN_PREFIX = 'g-pattern-';
1738
- var cacheKey2IDMap = {};
1739
- var counter = 0;
1927
+ case 'C':
1928
+ return "C ".concat(params[1] - x, " ").concat(params[2] - y, ",").concat(params[3] - x, " ").concat(params[4] - y, ",").concat(params[5] - x, " ").concat(params[6] - y);
1740
1929
 
1741
- function createOrUpdateGradientAndPattern(document, $def, object, $el, parsedColor, name, createImage) {
1742
- // eg. clipPath don't have fill/stroke
1743
- if (!parsedColor) {
1744
- return '';
1745
- }
1930
+ case 'A':
1931
+ return "A ".concat(params[1], " ").concat(params[2], " ").concat(params[3], " ").concat(params[4], " ").concat(params[5], " ").concat(params[6] - x, " ").concat(params[7] - y);
1746
1932
 
1747
- if (parsedColor instanceof g.CSSRGB) {
1748
- // keep using currentColor @see https://github.com/d3/d3-axis/issues/49
1749
- if (object.style[name] === 'currentColor') {
1750
- $el === null || $el === void 0 ? void 0 : $el.setAttribute(name, 'currentColor');
1751
- } else {
1752
- // constant value, eg. '#fff'
1753
- $el === null || $el === void 0 ? void 0 : $el.setAttribute(name, parsedColor.isNone ? 'none' : parsedColor.toString());
1933
+ case 'Z':
1934
+ return 'Z';
1754
1935
  }
1755
- } else if (g.isPattern(parsedColor)) {
1756
- var patternId = createOrUpdatePattern(document, $def, object, parsedColor, createImage); // use style instead of attribute when applying <pattern>
1757
- // @see https://stackoverflow.com/a/7723115
1936
+ }).join(' ');
1758
1937
 
1759
- $el.style[name] = "url(#" + patternId + ")";
1760
- return patternId;
1761
- } else {
1762
- if (parsedColor.length === 1) {
1763
- var gradientId = createOrUpdateGradient(document, object, $def, $el, parsedColor[0]);
1764
- $el === null || $el === void 0 ? void 0 : $el.setAttribute(name, "url(#" + gradientId + ")");
1765
- return gradientId;
1766
- } else {
1767
- // @see https://stackoverflow.com/questions/20671502/can-i-blend-gradients-in-svg
1768
- var filterId = createOrUpdateMultiGradient(document, object, $def, $el, parsedColor);
1769
- $el === null || $el === void 0 ? void 0 : $el.setAttribute('filter', "url(#" + filterId + ")");
1770
- $el === null || $el === void 0 ? void 0 : $el.setAttribute('fill', 'black');
1771
- return filterId;
1772
- }
1938
+ if (~newValue.indexOf('NaN')) {
1939
+ return '';
1773
1940
  }
1774
1941
 
1775
- return '';
1942
+ return newValue;
1776
1943
  }
1777
1944
 
1778
- function generateCacheKey(src) {
1779
- var cacheKey = '';
1780
-
1781
- if (src instanceof g.CSSGradientValue) {
1782
- var type = src.type,
1783
- value = src.value;
1784
-
1785
- if (type === g.GradientType.LinearGradient || type === g.GradientType.RadialGradient) {
1786
- // @ts-ignore
1787
- var _type = value.type,
1788
- width = value.width,
1789
- height = value.height,
1790
- steps = value.steps,
1791
- angle = value.angle,
1792
- cx = value.cx,
1793
- cy = value.cy;
1794
- cacheKey = "" + _type + width + height + (angle || 0) + (cx || 0) + (cy || 0) + steps.map(function (step) {
1795
- return step.join('');
1796
- }).join('');
1797
- }
1798
- } else if (g.isPattern(src)) {
1799
- if (g.isString(src.image)) {
1800
- cacheKey = "pattern-" + src.image + "-" + src.repetition;
1801
- } else {
1802
- cacheKey = "pattern-" + counter;
1803
- }
1804
- }
1945
+ function updatePolylineElementAttribute($el, parsedStyle) {
1946
+ var points = parsedStyle.points,
1947
+ _parsedStyle$defX = parsedStyle.defX,
1948
+ x = _parsedStyle$defX === void 0 ? 0 : _parsedStyle$defX,
1949
+ _parsedStyle$defY = parsedStyle.defY,
1950
+ y = _parsedStyle$defY === void 0 ? 0 : _parsedStyle$defY;
1805
1951
 
1806
- if (cacheKey) {
1807
- if (!cacheKey2IDMap[cacheKey]) {
1808
- cacheKey2IDMap[cacheKey] = PATTERN_PREFIX + ("" + counter++);
1809
- }
1952
+ if (points && points.points && points.points.length >= 2) {
1953
+ $el.setAttribute('points', points.points.map(function (point) {
1954
+ return "".concat(point[0] - x, ",").concat(point[1] - y);
1955
+ }).join(' '));
1810
1956
  }
1811
-
1812
- return cacheKey2IDMap[cacheKey];
1813
1957
  }
1814
1958
 
1815
- function createOrUpdatePattern(document, $def, object, pattern, createImage) {
1816
- var patternId = generateCacheKey(pattern);
1817
- var $existed = $def.querySelector("#" + patternId);
1959
+ function updateRectElementAttribute($el, parsedStyle) {
1960
+ var radius = parsedStyle.radius,
1961
+ width = parsedStyle.width,
1962
+ height = parsedStyle.height; // CSSKeyword: auto
1818
1963
 
1819
- if (!$existed) {
1820
- var image = pattern.image,
1821
- repetition = pattern.repetition;
1822
- var imageURL = '';
1964
+ if (!isFinite(width.value) || !isFinite(height.value)) {
1965
+ return;
1966
+ }
1823
1967
 
1824
- if (g.isString(image)) {
1825
- imageURL = image;
1826
- } else {
1827
- if (g.isBrowser) {
1828
- if (image instanceof HTMLImageElement) {
1829
- imageURL = image.src;
1830
- } else if (image instanceof HTMLCanvasElement) {
1831
- imageURL = image.toDataURL();
1832
- } else ;
1833
- }
1834
- }
1968
+ var hasRadius = radius && radius.some(function (r) {
1969
+ return r.value !== 0;
1970
+ });
1971
+ var d = '';
1835
1972
 
1836
- if (imageURL) {
1837
- // @see https://developer.mozilla.org/zh-CN/docs/Web/SVG/Element/pattern
1838
- var $pattern = createSVGElement('pattern', document);
1839
- $pattern.setAttribute('patternUnits', 'userSpaceOnUse');
1840
- var $image = createSVGElement('image', document);
1841
- $pattern.appendChild($image);
1842
- $pattern.id = patternId;
1843
- $def.appendChild($pattern); // use href instead of xlink:href
1844
- // @see https://stackoverflow.com/a/13379007
1973
+ if (!hasRadius) {
1974
+ d = "M 0,0 l ".concat(width.value, ",0 l 0,").concat(height.value, " l").concat(-width.value, " 0 z");
1975
+ } else {
1976
+ var _radius$map = radius.map(function (r) {
1977
+ return g.clamp(r.value, 0, Math.min(Math.abs(width.value) / 2, Math.abs(height.value) / 2));
1978
+ }),
1979
+ _radius$map2 = _slicedToArray(_radius$map, 4),
1980
+ tlr = _radius$map2[0],
1981
+ trr = _radius$map2[1],
1982
+ brr = _radius$map2[2],
1983
+ blr = _radius$map2[3];
1845
1984
 
1846
- $image.setAttribute('href', imageURL);
1847
- var img;
1985
+ var signX = width.value > 0 ? 1 : -1;
1986
+ var signY = height.value > 0 ? 1 : -1; // sweep-flag @see https://developer.mozilla.org/zh-CN/docs/Web/SVG/Tutorial/Paths#arcs
1848
1987
 
1849
- if (createImage) {
1850
- img = createImage(imageURL);
1851
- } else if (g.isBrowser) {
1852
- img = new window.Image();
1853
- }
1988
+ var sweepFlag = signX + signY !== 0 ? 1 : 0;
1989
+ d = [["M ".concat(signX * tlr, ",0")], ["l ".concat(width.value - signX * (tlr + trr), ",0")], ["a ".concat(trr, ",").concat(trr, ",0,0,").concat(sweepFlag, ",").concat(signX * trr, ",").concat(signY * trr)], ["l 0,".concat(height.value - signY * (trr + brr))], ["a ".concat(brr, ",").concat(brr, ",0,0,").concat(sweepFlag, ",").concat(-signX * brr, ",").concat(signY * brr)], ["l ".concat(signX * (brr + blr) - width.value, ",0")], ["a ".concat(blr, ",").concat(blr, ",0,0,").concat(sweepFlag, ",").concat(-signX * blr, ",").concat(-signY * blr)], ["l 0,".concat(signY * (blr + tlr) - height.value)], ["a ".concat(tlr, ",").concat(tlr, ",0,0,").concat(sweepFlag, ",").concat(signX * tlr, ",").concat(-signY * tlr)], ['z']].join(' ');
1990
+ }
1854
1991
 
1855
- if (!imageURL.match(/^data:/i)) {
1856
- img.crossOrigin = 'Anonymous';
1857
- $image.setAttribute('crossorigin', 'anonymous');
1858
- }
1992
+ $el.setAttribute('d', d);
1993
+ }
1859
1994
 
1860
- img.src = imageURL;
1995
+ function numberToLongString(x) {
1996
+ return x.toFixed(6).replace('.000000', '');
1997
+ }
1861
1998
 
1862
- var onload = function onload() {
1863
- $pattern.setAttribute('x', '0');
1864
- $pattern.setAttribute('y', '0');
1999
+ function convertHTML(str) {
2000
+ var regex = /[&|<|>|"|']/g;
2001
+ return str.replace(regex, function (match) {
2002
+ if (match === '&') {
2003
+ return '&amp;';
2004
+ } else if (match === '<') {
2005
+ return '&lt;';
2006
+ } else if (match === '>') {
2007
+ return '&gt;';
2008
+ } else if (match === '"') {
2009
+ return '&quot;';
2010
+ } else {
2011
+ return '&apos;';
2012
+ }
2013
+ });
2014
+ }
1865
2015
 
1866
- var _object$getGeometryBo = object.getGeometryBounds(),
1867
- halfExtents = _object$getGeometryBo.halfExtents; // There is no equivalent to CSS no-repeat for SVG patterns
1868
- // @see https://stackoverflow.com/a/33481956
2016
+ var BASELINE_MAP = {
2017
+ top: 'before-edge',
2018
+ middle: 'central',
2019
+ bottom: 'after-edge',
2020
+ alphabetic: 'alphabetic',
2021
+ ideographic: 'ideographic',
2022
+ hanging: 'hanging'
2023
+ }; // for FireFox
2024
+ // @see https://github.com/plouc/nivo/issues/164
1869
2025
 
2026
+ var BASELINE_MAP_FOR_FIREFOX = {
2027
+ top: 'text-before-edge',
2028
+ middle: 'central',
2029
+ bottom: 'text-after-edge',
2030
+ alphabetic: 'alphabetic',
2031
+ ideographic: 'ideographic',
2032
+ hanging: 'hanging'
2033
+ };
1870
2034
 
1871
- var patternWidth = img.width;
1872
- var patternHeight = img.height;
2035
+ function updateTextElementAttribute($el, parsedStyle) {
2036
+ var textBaseline = parsedStyle.textBaseline,
2037
+ lineWidth = parsedStyle.lineWidth,
2038
+ metrics = parsedStyle.metrics,
2039
+ dx = parsedStyle.dx,
2040
+ dy = parsedStyle.dy;
2041
+ var browser = detect();
1873
2042
 
1874
- if (repetition === 'repeat-x') {
1875
- patternHeight = halfExtents[1] * 2;
1876
- } else if (repetition === 'repeat-y') {
1877
- patternWidth = halfExtents[0] * 2;
1878
- } else if (repetition === 'no-repeat') {
1879
- patternWidth = halfExtents[0] * 2;
1880
- patternHeight = halfExtents[1] * 2;
1881
- }
2043
+ if (browser && browser.name === 'firefox') {
2044
+ // compatible with FireFox browser, ref: https://github.com/antvis/g/issues/119
2045
+ $el.setAttribute('dominant-baseline', BASELINE_MAP_FOR_FIREFOX[textBaseline.value] || 'alphabetic');
2046
+ } else {
2047
+ $el.setAttribute('dominant-baseline', BASELINE_MAP_FOR_FIREFOX[textBaseline.value]);
2048
+ $el.setAttribute('alignment-baseline', BASELINE_MAP[textBaseline.value]);
2049
+ }
1882
2050
 
1883
- $pattern.setAttribute('width', "" + patternWidth);
1884
- $pattern.setAttribute('height', "" + patternHeight);
1885
- $image.setAttribute('x', '0');
1886
- $image.setAttribute('y', '0');
1887
- $image.setAttribute('width', "" + img.width);
1888
- $image.setAttribute('height', "" + img.height);
1889
- };
2051
+ $el.setAttribute('paint-order', 'stroke');
2052
+ var lines = metrics.lines,
2053
+ lineHeight = metrics.lineHeight,
2054
+ height = metrics.height;
2055
+ var lineNum = lines.length;
2056
+ $el.setAttribute('style', "transform:translate(".concat(dx.toString(), ", ").concat(dy.toString(), ");"));
1890
2057
 
1891
- if (img.complete) {
1892
- onload();
1893
- } else {
1894
- img.onload = onload; // Fix onload() bug in IE9
2058
+ if (lineNum === 1) {
2059
+ $el.innerHTML = convertHTML(lines[0]);
2060
+ $el.setAttribute('dx', "".concat(lineWidth.value / 2));
2061
+ } else {
2062
+ $el.innerHTML = lines.map(function (line, i) {
2063
+ var dx = lineWidth.value / 2;
2064
+ var dy = 0;
1895
2065
 
1896
- img.src = img.src;
2066
+ if (i === 0) {
2067
+ // TODO: handle other textBaseline values
2068
+ if (textBaseline.value === 'middle') {
2069
+ dy = lineHeight / 2 - height / 2;
2070
+ } else if (textBaseline.value === 'top' || textBaseline.value === 'hanging') {
2071
+ dy = 0;
2072
+ } else if (textBaseline.value === 'bottom' || textBaseline.value === 'alphabetic' || textBaseline.value === 'ideographic') {
2073
+ dy = -lineHeight * (lineNum - 1);
2074
+ }
2075
+ } else {
2076
+ dy = lineHeight;
1897
2077
  }
1898
- }
2078
+
2079
+ return "<tspan x=\"0\" dx=\"".concat(dx, "\" dy=\"").concat(dy, "\">").concat(convertHTML(line), "</tspan>");
2080
+ }).join('');
1899
2081
  }
2082
+ }
1900
2083
 
1901
- return patternId;
2084
+ var CreateElementContribution = g.Syringe.defineToken('CreateElementContribution', {
2085
+ multiple: false
2086
+ });
2087
+
2088
+ function createSVGElement(type, doc) {
2089
+ return (doc || document).createElementNS('http://www.w3.org/2000/svg', type);
1902
2090
  }
1903
2091
 
1904
- function createOrUpdateGradient(document, object, $def, $el, parsedColor) {
1905
- var gradientId = generateCacheKey(parsedColor);
1906
- var $existed = $def.querySelector("#" + gradientId);
2092
+ var _SHAPE2TAGS, _SHAPE_UPDATE_DEPS;
1907
2093
 
1908
- if (!$existed) {
1909
- // <linearGradient> <radialGradient>
1910
- // @see https://developer.mozilla.org/zh-CN/docs/Web/SVG/Element/linearGradient
1911
- // @see https://developer.mozilla.org/zh-CN/docs/Web/SVG/Element/radialGradient
1912
- $existed = createSVGElement(parsedColor.type === g.GradientType.LinearGradient ? 'linearGradient' : 'radialGradient', document); // @see https://github.com/antvis/g/issues/1025
2094
+ var SHAPE2TAGS = (_SHAPE2TAGS = {}, _defineProperty(_SHAPE2TAGS, g.Shape.RECT, 'path'), _defineProperty(_SHAPE2TAGS, g.Shape.CIRCLE, 'circle'), _defineProperty(_SHAPE2TAGS, g.Shape.ELLIPSE, 'ellipse'), _defineProperty(_SHAPE2TAGS, g.Shape.IMAGE, 'image'), _defineProperty(_SHAPE2TAGS, g.Shape.GROUP, 'g'), _defineProperty(_SHAPE2TAGS, g.Shape.LINE, 'line'), _defineProperty(_SHAPE2TAGS, g.Shape.POLYLINE, 'polyline'), _defineProperty(_SHAPE2TAGS, g.Shape.POLYGON, 'polygon'), _defineProperty(_SHAPE2TAGS, g.Shape.TEXT, 'text'), _defineProperty(_SHAPE2TAGS, g.Shape.PATH, 'path'), _defineProperty(_SHAPE2TAGS, g.Shape.HTML, 'foreignObject'), _SHAPE2TAGS);
2095
+ var SHAPE_UPDATE_DEPS = (_SHAPE_UPDATE_DEPS = {}, _defineProperty(_SHAPE_UPDATE_DEPS, g.Shape.CIRCLE, ['r']), _defineProperty(_SHAPE_UPDATE_DEPS, g.Shape.ELLIPSE, ['rx', 'ry']), _defineProperty(_SHAPE_UPDATE_DEPS, g.Shape.RECT, ['width', 'height', 'radius']), _defineProperty(_SHAPE_UPDATE_DEPS, g.Shape.IMAGE, ['img', 'width', 'height']), _defineProperty(_SHAPE_UPDATE_DEPS, g.Shape.LINE, ['x1', 'y1', 'x2', 'y2']), _defineProperty(_SHAPE_UPDATE_DEPS, g.Shape.POLYLINE, ['points']), _defineProperty(_SHAPE_UPDATE_DEPS, g.Shape.POLYGON, ['points']), _defineProperty(_SHAPE_UPDATE_DEPS, g.Shape.PATH, ['path']), _defineProperty(_SHAPE_UPDATE_DEPS, g.Shape.TEXT, ['text', 'font', 'fontSize', 'fontFamily', 'fontStyle', 'fontWeight', 'fontVariant', 'lineHeight', 'letterSpacing', 'wordWrap', 'wordWrapWidth', 'leading', 'textBaseline', 'textAlign', 'textTransform', 'whiteSpace', 'dx', 'dy']), _SHAPE_UPDATE_DEPS);
1913
2096
 
1914
- $existed.setAttribute('gradientUnits', 'userSpaceOnUse'); // add stops
2097
+ var DefaultCreateElementContribution = /*#__PURE__*/function () {
2098
+ function DefaultCreateElementContribution() {
2099
+ _classCallCheck$2(this, DefaultCreateElementContribution);
1915
2100
 
1916
- var innerHTML = '';
1917
- parsedColor.value.steps.forEach(function (_ref) {
1918
- var offset = _ref[0],
1919
- color = _ref[1];
1920
- innerHTML += "<stop offset=\"" + offset + "\" stop-color=\"" + color + "\"></stop>";
1921
- });
1922
- $existed.innerHTML = innerHTML;
1923
- $existed.id = gradientId;
1924
- $def.appendChild($existed);
2101
+ this.canvasConfig = void 0;
1925
2102
  }
1926
2103
 
1927
- var bounds = object.getGeometryBounds();
1928
- var width = bounds && bounds.halfExtents[0] * 2 || 0;
1929
- var height = bounds && bounds.halfExtents[1] * 2 || 0;
2104
+ _createClass$2(DefaultCreateElementContribution, [{
2105
+ key: "createElement",
2106
+ value: function createElement(object) {
2107
+ var doc = this.canvasConfig.document;
2108
+ var type = SHAPE2TAGS[object.nodeName] || 'g';
2109
+ return createSVGElement(type, doc || document);
2110
+ }
2111
+ }, {
2112
+ key: "shouldUpdateElementAttribute",
2113
+ value: function shouldUpdateElementAttribute(object, attributeName) {
2114
+ var nodeName = object.nodeName;
2115
+ return (SHAPE_UPDATE_DEPS[nodeName] || []).indexOf(attributeName) > -1;
2116
+ }
2117
+ }, {
2118
+ key: "updateElementAttribute",
2119
+ value: function updateElementAttribute(object) {
2120
+ // @ts-ignore
2121
+ var $el = object.elementSVG.$el;
2122
+ var nodeName = object.nodeName,
2123
+ parsedStyle = object.parsedStyle;
1930
2124
 
1931
- if (parsedColor.type === g.GradientType.LinearGradient) {
1932
- var angle = parsedColor.value.angle;
2125
+ switch (nodeName) {
2126
+ case g.Shape.IMAGE:
2127
+ {
2128
+ updateImageElementAttribute($el, parsedStyle);
2129
+ break;
2130
+ }
1933
2131
 
1934
- var _computeLinearGradien = g.computeLinearGradient(width, height, angle),
1935
- x1 = _computeLinearGradien.x1,
1936
- y1 = _computeLinearGradien.y1,
1937
- x2 = _computeLinearGradien.x2,
1938
- y2 = _computeLinearGradien.y2;
2132
+ case g.Shape.RECT:
2133
+ {
2134
+ updateRectElementAttribute($el, parsedStyle);
2135
+ break;
2136
+ }
1939
2137
 
1940
- $existed.setAttribute('x1', "" + x1);
1941
- $existed.setAttribute('y1', "" + y1);
1942
- $existed.setAttribute('x2', "" + x2);
1943
- $existed.setAttribute('y2', "" + y2); // $existed.setAttribute('gradientTransform', `rotate(${angle})`);
1944
- } else {
1945
- var _parsedColor$value = parsedColor.value,
1946
- cx = _parsedColor$value.cx,
1947
- cy = _parsedColor$value.cy;
2138
+ case g.Shape.LINE:
2139
+ {
2140
+ updateLineElementAttribute($el, parsedStyle);
2141
+ break;
2142
+ }
1948
2143
 
1949
- var _computeRadialGradien = g.computeRadialGradient(width, height, cx, cy),
1950
- x = _computeRadialGradien.x,
1951
- y = _computeRadialGradien.y,
1952
- r = _computeRadialGradien.r;
2144
+ case g.Shape.POLYGON:
2145
+ case g.Shape.POLYLINE:
2146
+ {
2147
+ updatePolylineElementAttribute($el, parsedStyle);
2148
+ break;
2149
+ }
1953
2150
 
1954
- $existed.setAttribute('cx', "" + x);
1955
- $existed.setAttribute('cy', "" + y);
1956
- $existed.setAttribute('r', "" + r);
1957
- }
2151
+ case g.Shape.PATH:
2152
+ {
2153
+ updatePathElementAttribute($el, parsedStyle);
2154
+ break;
2155
+ }
1958
2156
 
1959
- return gradientId;
1960
- }
2157
+ case g.Shape.TEXT:
2158
+ {
2159
+ updateTextElementAttribute($el, parsedStyle);
2160
+ break;
2161
+ }
2162
+ }
2163
+ }
2164
+ }]);
1961
2165
 
1962
- function createOrUpdateMultiGradient(document, object, $def, $el, gradients) {
1963
- var filterId = FILTER_PREFIX + object.entity + '-gradient';
1964
- var $existed = $def.querySelector("#" + filterId);
2166
+ return DefaultCreateElementContribution;
2167
+ }();
1965
2168
 
1966
- if (!$existed) {
1967
- $existed = createSVGElement('filter', document);
1968
- $existed.setAttribute('filterUnits', 'userSpaceOnUse'); // @see https://github.com/antvis/g/issues/1025
2169
+ __decorate([g.inject(g.CanvasConfig), __metadata("design:type", Object)], DefaultCreateElementContribution.prototype, "canvasConfig", void 0);
1969
2170
 
1970
- $existed.setAttribute('x', '0%');
1971
- $existed.setAttribute('y', '0%');
1972
- $existed.setAttribute('width', '100%');
1973
- $existed.setAttribute('height', '100%');
1974
- $existed.id = filterId;
1975
- $def.appendChild($existed);
2171
+ DefaultCreateElementContribution = __decorate([g.singleton({
2172
+ token: CreateElementContribution
2173
+ })], DefaultCreateElementContribution);
2174
+ var FILTER_PREFIX = 'g-filter-';
2175
+ /**
2176
+ * use SVG filters, eg. blur, brightness, contrast...
2177
+ * @see https://developer.mozilla.org/zh-CN/docs/Web/SVG/Element/filter
2178
+ */
2179
+
2180
+ function createOrUpdateFilter(document, $def, object, $el, filters) {
2181
+ // eg. filter="url(#f1) url(#f2)"
2182
+ var filterName = FILTER_PREFIX + object.entity;
2183
+ var $existedFilters = $def.querySelectorAll("[name=".concat(filterName, "]"));
2184
+
2185
+ if ($existedFilters.length) {
2186
+ $existedFilters.forEach(function ($filter) {
2187
+ $def.removeChild($filter);
2188
+ });
1976
2189
  }
1977
- /**
1978
- * <rect id="wave-rect" x="0" y="0" width="100%" height="100%" fill="url(#wave)"></rect>
1979
- * <filter id="blend-it" x="0%" y="0%" width="100%" height="100%">
1980
- <feImage xlink:href="#wave-rect" result="myWave" x="100" y="100"/>
1981
- <feImage xlink:href="#ry-rect" result="myRY" x="100" y="100"/>
1982
- <feBlend in="myWave" in2="myRY" mode="multiply" result="blendedGrad"/>
1983
- <feComposite in="blendedGrad" in2="SourceGraphic" operator="in"/>
1984
- </filter>
1985
- */
1986
2190
 
2191
+ if (filters.length === 0) {
2192
+ // 'none'
2193
+ $el === null || $el === void 0 ? void 0 : $el.removeAttribute('filter');
2194
+ } else {
2195
+ var filterIds = filters.map(function (_ref, i) {
2196
+ var name = _ref.name,
2197
+ params = _ref.params;
2198
+ var $filter = createSVGElement('filter', document); // @see https://github.com/antvis/g/issues/1025
1987
2199
 
1988
- var blended = 0;
1989
- gradients.forEach(function (gradient, i) {
1990
- var gradientId = createOrUpdateGradient(document, object, $def, $el, gradient);
1991
- var rectId = gradientId + '_rect';
1992
- var $rect = createSVGElement('rect', document);
1993
- $rect.setAttribute('x', '0');
1994
- $rect.setAttribute('y', '0');
1995
- $rect.setAttribute('width', '100%');
1996
- $rect.setAttribute('height', '100%');
1997
- $rect.setAttribute('fill', "url(#" + gradientId + ")");
1998
- $rect.id = rectId;
1999
- $def.appendChild($rect);
2000
- var $feImage = createSVGElement('feImage', document);
2001
- $feImage.setAttribute('href', "#" + rectId);
2002
- $feImage.setAttribute('result', filterId + "-" + i);
2003
- $existed.appendChild($feImage);
2200
+ $filter.setAttribute('filterUnits', 'userSpaceOnUse');
2004
2201
 
2005
- if (i > 0) {
2006
- var $feBlend = createSVGElement('feBlend', document);
2007
- $feBlend.setAttribute('in', i === 1 ? filterId + "-" + (i - 1) : filterId + "-blended-" + (blended - 1));
2008
- $feBlend.setAttribute('in2', filterId + "-" + i);
2009
- $feBlend.setAttribute('result', filterId + "-blended-" + blended++); // @see https://developer.mozilla.org/zh-CN/docs/Web/CSS/blend-mode
2202
+ if (name === 'blur') {
2203
+ createBlur(document, $filter, params);
2204
+ } else if (name === 'brightness') {
2205
+ createBrightness(document, $filter, params);
2206
+ } else if (name === 'drop-shadow') {
2207
+ createDropShadow(document, $filter, params);
2208
+ } else if (name === 'contrast') {
2209
+ createContrast(document, $filter, params);
2210
+ } else if (name === 'grayscale') {
2211
+ createGrayscale(document, $filter, params);
2212
+ } else if (name === 'sepia') {
2213
+ createSepia(document, $filter, params);
2214
+ } else if (name === 'saturate') {
2215
+ createSaturate(document, $filter, params);
2216
+ } else if (name === 'hue-rotate') {
2217
+ createHueRotate(document, $filter, params);
2218
+ } else if (name === 'invert') {
2219
+ createInvert(document, $filter, params);
2220
+ }
2010
2221
 
2011
- $feBlend.setAttribute('mode', 'multiply');
2012
- $existed.appendChild($feBlend);
2013
- }
2014
- });
2015
- var $feComposite = createSVGElement('feComposite', document);
2016
- $feComposite.setAttribute('in', filterId + "-blended-" + blended);
2017
- $feComposite.setAttribute('in2', 'SourceGraphic');
2018
- $feComposite.setAttribute('operator', 'in');
2019
- $existed.appendChild($feComposite);
2020
- return filterId;
2222
+ $filter.id = "".concat(filterName, "-").concat(i);
2223
+ $filter.setAttribute('name', filterName);
2224
+ $def.appendChild($filter);
2225
+ return $filter.id;
2226
+ });
2227
+ $el === null || $el === void 0 ? void 0 : $el.setAttribute('filter', filterIds.map(function (filterId) {
2228
+ return "url(#".concat(filterId, ")");
2229
+ }).join(' '));
2230
+ }
2021
2231
  }
2022
2232
 
2023
- var FILTER_DROPSHADOW_PREFIX = 'g-filter-dropshadow-';
2233
+ function convertToAbsoluteValue(param) {
2234
+ return param.unit === g.UnitType.kPercentage ? param.value / 100 : param.value;
2235
+ }
2024
2236
  /**
2025
- * use SVG filters
2026
- * @see https://developer.mozilla.org/zh-CN/docs/Web/SVG/Element/filter
2237
+ * @see https://drafts.fxtf.org/filter-effects/#blurEquivalent
2027
2238
  */
2028
2239
 
2029
- function createOrUpdateShadow(document, $def, object, $el, name) {
2030
- var _object$parsedStyle$s;
2031
-
2032
- var shadowId = FILTER_DROPSHADOW_PREFIX + object.entity;
2033
- var $existedFilter = $def.querySelector("#" + shadowId);
2034
2240
 
2035
- if (!$existedFilter) {
2036
- $existedFilter = createSVGElement('filter', document);
2241
+ function createBlur(document, $filter, params) {
2242
+ var $feGaussianBlur = createSVGElement('feGaussianBlur', document);
2243
+ $feGaussianBlur.setAttribute('in', 'SourceGraphic');
2244
+ $feGaussianBlur.setAttribute('stdDeviation', "".concat(params[0].value));
2245
+ $filter.appendChild($feGaussianBlur);
2246
+ }
2037
2247
 
2038
- var _$feDropShadow = createSVGElement('feDropShadow', document);
2248
+ function createFeComponentTransfer(document, $filter, _ref2) {
2249
+ var type = _ref2.type,
2250
+ slope = _ref2.slope,
2251
+ intercept = _ref2.intercept,
2252
+ tableValues = _ref2.tableValues;
2253
+ var $feComponentTransfer = createSVGElement('feComponentTransfer', document);
2254
+ [createSVGElement('feFuncR', document), createSVGElement('feFuncG', document), createSVGElement('feFuncB', document)].forEach(function ($feFunc) {
2255
+ $feFunc.setAttribute('type', type);
2039
2256
 
2040
- _$feDropShadow.setAttribute('dx', '0');
2257
+ if (type === 'table') {
2258
+ $feFunc.setAttribute('tableValues', "".concat(tableValues));
2259
+ } else {
2260
+ $feFunc.setAttribute('slope', "".concat(slope));
2261
+ $feFunc.setAttribute('intercept', "".concat(intercept));
2262
+ }
2041
2263
 
2042
- _$feDropShadow.setAttribute('dy', '0');
2264
+ $feComponentTransfer.appendChild($feFunc);
2265
+ });
2266
+ $filter.appendChild($feComponentTransfer);
2267
+ }
2043
2268
 
2044
- $existedFilter.appendChild(_$feDropShadow);
2045
- $existedFilter.id = shadowId; // @see https://github.com/antvis/g/issues/1025
2269
+ function createContrast(document, $filter, params) {
2270
+ var slope = convertToAbsoluteValue(params[0]);
2271
+ createFeComponentTransfer(document, $filter, {
2272
+ type: 'linear',
2273
+ slope: slope,
2274
+ intercept: -(0.5 * slope) + 0.5
2275
+ });
2276
+ }
2046
2277
 
2047
- $existedFilter.setAttribute('filterUnits', 'userSpaceOnUse');
2048
- $def.appendChild($existedFilter);
2049
- }
2278
+ function createInvert(document, $filter, params) {
2279
+ var amount = convertToAbsoluteValue(params[0]);
2280
+ createFeComponentTransfer(document, $filter, {
2281
+ type: 'table',
2282
+ tableValues: "".concat(amount, " ").concat(1 - amount)
2283
+ });
2284
+ }
2050
2285
 
2051
- var $feDropShadow = $existedFilter.children[0];
2286
+ function createBrightness(document, $filter, params) {
2287
+ var slope = convertToAbsoluteValue(params[0]);
2288
+ createFeComponentTransfer(document, $filter, {
2289
+ type: 'linear',
2290
+ slope: slope,
2291
+ intercept: 0
2292
+ });
2293
+ }
2052
2294
 
2053
- if (name === 'shadowColor') {
2054
- var parsedColor = object.parsedStyle[name];
2055
- $feDropShadow.setAttribute('flood-color', parsedColor.toString());
2056
- } else if (name === 'shadowBlur') {
2057
- var shadowBlur = object.parsedStyle[name]; // half the blur radius
2058
- // @see https://drafts.csswg.org/css-backgrounds/#shadow-blur
2059
- // @see https://css-tricks.com/breaking-css-box-shadow-vs-drop-shadow/
2295
+ function createSaturate(document, $filter, params) {
2296
+ var amount = convertToAbsoluteValue(params[0]);
2297
+ var $feColorMatrix = createSVGElement('feColorMatrix', document);
2298
+ $feColorMatrix.setAttribute('type', 'saturate');
2299
+ $feColorMatrix.setAttribute('values', "".concat(amount));
2300
+ $filter.appendChild($feColorMatrix);
2301
+ }
2060
2302
 
2061
- $feDropShadow.setAttribute('stdDeviation', "" + ((shadowBlur === null || shadowBlur === void 0 ? void 0 : shadowBlur.value) || 0) / 4);
2062
- } else if (name === 'shadowOffsetX') {
2063
- var shadowOffsetX = object.parsedStyle[name];
2064
- $feDropShadow.setAttribute('dx', "" + ((shadowOffsetX === null || shadowOffsetX === void 0 ? void 0 : shadowOffsetX.value) || 0) / 2);
2065
- } else if (name === 'shadowOffsetY') {
2066
- var shadowOffsetY = object.parsedStyle[name];
2067
- $feDropShadow.setAttribute('dy', "" + ((shadowOffsetY === null || shadowOffsetY === void 0 ? void 0 : shadowOffsetY.value) || 0) / 2);
2068
- } // only apply shadow when blur > 0
2303
+ function createHueRotate(document, $filter, params) {
2304
+ var $feColorMatrix = createSVGElement('feColorMatrix', document);
2305
+ $feColorMatrix.setAttribute('type', 'hueRotate');
2306
+ $feColorMatrix.setAttribute('values', "".concat(params[0].to(g.UnitType.kDegrees).value));
2307
+ $filter.appendChild($feColorMatrix);
2308
+ }
2069
2309
 
2310
+ function createDropShadow(document, $filter, params) {
2311
+ var shadowOffsetX = params[0].value;
2312
+ var shadowOffsetY = params[1].value;
2313
+ var shadowBlur = params[2].value; // @ts-ignore
2070
2314
 
2071
- if (!g.isNil(object.parsedStyle.shadowColor) && ((_object$parsedStyle$s = object.parsedStyle.shadowBlur) === null || _object$parsedStyle$s === void 0 ? void 0 : _object$parsedStyle$s.value) > 0) {
2072
- // use filter <feDropShadow>
2073
- // @see https://developer.mozilla.org/en-US/docs/Web/SVG/Element/feDropShadow
2074
- $el === null || $el === void 0 ? void 0 : $el.setAttribute('filter', "url(#" + shadowId + ")");
2075
- } else {
2076
- $el === null || $el === void 0 ? void 0 : $el.removeAttribute('filter');
2077
- }
2315
+ var shadowColor = params[3].formatted;
2316
+ var $feGaussianBlur = createSVGElement('feGaussianBlur', document);
2317
+ $feGaussianBlur.setAttribute('in', 'SourceAlpha');
2318
+ $feGaussianBlur.setAttribute('stdDeviation', "".concat(shadowBlur));
2319
+ $filter.appendChild($feGaussianBlur);
2320
+ var $feOffset = createSVGElement('feOffset', document);
2321
+ $feOffset.setAttribute('dx', "".concat(shadowOffsetX));
2322
+ $feOffset.setAttribute('dy', "".concat(shadowOffsetY));
2323
+ $feOffset.setAttribute('result', 'offsetblur');
2324
+ $filter.appendChild($feOffset);
2325
+ var $feFlood = createSVGElement('feFlood', document);
2326
+ $feFlood.setAttribute('flood-color', shadowColor);
2327
+ $filter.appendChild($feFlood);
2328
+ var $feComposite = createSVGElement('feComposite', document);
2329
+ $feComposite.setAttribute('in2', 'offsetblur');
2330
+ $feComposite.setAttribute('operator', 'in');
2331
+ $filter.appendChild($feComposite);
2332
+ var $feMerge = createSVGElement('feMerge', document);
2333
+ $filter.appendChild($feMerge);
2334
+ var $feMergeNode1 = createSVGElement('feMergeNode', document);
2335
+ var $feMergeNode2 = createSVGElement('feMergeNode', document);
2336
+ $feMergeNode2.setAttribute('in', 'SourceGraphic');
2337
+ $feMerge.appendChild($feMergeNode1);
2338
+ $feMerge.appendChild($feMergeNode2);
2078
2339
  }
2079
2340
 
2080
- var urlRegexp = /url\(#(.*)\)/;
2081
-
2082
- var DefElementManager = /*#__PURE__*/function () {
2083
- function DefElementManager() {
2084
- this.canvasConfig = void 0;
2085
- this.contextService = void 0;
2086
- this.$def = void 0;
2087
- this.gradientCache = {};
2088
- }
2341
+ function createFeColorMatrix(document, $filter, matrix) {
2342
+ var $feColorMatrix = createSVGElement('feColorMatrix', document);
2343
+ $feColorMatrix.setAttribute('type', 'matrix');
2344
+ $feColorMatrix.setAttribute('values', matrix.join(' '));
2345
+ $filter.appendChild($feColorMatrix);
2346
+ }
2347
+ /**
2348
+ * @see https://drafts.fxtf.org/filter-effects/#grayscaleEquivalent
2349
+ */
2089
2350
 
2090
- var _proto = DefElementManager.prototype;
2091
2351
 
2092
- _proto.getDefElement = function getDefElement() {
2093
- return this.$def;
2094
- };
2352
+ function createGrayscale(document, $filter, params) {
2353
+ var amount = convertToAbsoluteValue(params[0]);
2354
+ createFeColorMatrix(document, $filter, [0.2126 + 0.7874 * (1 - amount), 0.7152 - 0.7152 * (1 - amount), 0.0722 - 0.0722 * (1 - amount), 0, 0, 0.2126 - 0.2126 * (1 - amount), 0.7152 + 0.2848 * (1 - amount), 0.0722 - 0.0722 * (1 - amount), 0, 0, 0.2126 - 0.2126 * (1 - amount), 0.7152 - 0.7152 * (1 - amount), 0.0722 + 0.9278 * (1 - amount), 0, 0, 0, 0, 0, 1, 0]);
2355
+ }
2356
+ /**
2357
+ * @see https://drafts.fxtf.org/filter-effects/#sepiaEquivalent
2358
+ */
2095
2359
 
2096
- _proto.init = function init() {
2097
- var document = this.canvasConfig.document;
2098
- var $svg = this.contextService.getContext();
2099
- this.$def = createSVGElement('defs', document);
2100
- $svg.appendChild(this.$def);
2101
- };
2102
2360
 
2103
- _proto.clear = function clear(entity) {
2104
- var _this = this;
2361
+ function createSepia(document, $filter, params) {
2362
+ var amount = convertToAbsoluteValue(params[0]);
2363
+ createFeColorMatrix(document, $filter, [0.393 + 0.607 * (1 - amount), 0.769 - 0.769 * (1 - amount), 0.189 - 0.189 * (1 - amount), 0, 0, 0.349 - 0.349 * (1 - amount), 0.686 + 0.314 * (1 - amount), 0.168 - 0.168 * (1 - amount), 0, 0, 0.272 - 0.272 * (1 - amount), 0.534 - 0.534 * (1 - amount), 0.131 + 0.869 * (1 - amount), 0, 0, 0, 0, 0, 1, 0]);
2364
+ }
2105
2365
 
2106
- Object.keys(this.gradientCache).forEach(function (id) {
2107
- _this.clearUnusedDefElement(_this.gradientCache, id, entity);
2108
- });
2109
- };
2366
+ var PATTERN_PREFIX = 'g-pattern-';
2367
+ var cacheKey2IDMap = {};
2368
+ var counter = 0;
2110
2369
 
2111
- _proto.clearUnusedDefElement = function clearUnusedDefElement(cache, id, entity) {
2112
- if (cache[id].size === 1 && cache[id].has(entity)) {
2113
- var targetElement = this.$def.querySelector("#" + id);
2370
+ function createOrUpdateGradientAndPattern(document, $def, object, $el, parsedColor, name, createImage) {
2371
+ // eg. clipPath don't have fill/stroke
2372
+ if (!parsedColor) {
2373
+ return '';
2374
+ }
2114
2375
 
2115
- if (targetElement) {
2116
- this.$def.removeChild(targetElement);
2117
- }
2376
+ if (parsedColor instanceof g.CSSRGB) {
2377
+ // keep using currentColor @see https://github.com/d3/d3-axis/issues/49
2378
+ if (object.style[name] === 'currentColor') {
2379
+ $el === null || $el === void 0 ? void 0 : $el.setAttribute(name, 'currentColor');
2380
+ } else {
2381
+ // constant value, eg. '#fff'
2382
+ $el === null || $el === void 0 ? void 0 : $el.setAttribute(name, parsedColor.isNone ? 'none' : parsedColor.toString());
2118
2383
  }
2119
- };
2120
-
2121
- _proto.createOrUpdateGradientAndPattern = function createOrUpdateGradientAndPattern$1(object, $el, parsedColor, name) {
2122
- var _this$canvasConfig = this.canvasConfig,
2123
- doc = _this$canvasConfig.document,
2124
- createImage = _this$canvasConfig.createImage;
2125
-
2126
- if ($el) {
2127
- var _$el$getAttribute; // `url(#${gradientId})`
2128
-
2384
+ } else if (g.isPattern(parsedColor)) {
2385
+ var patternId = createOrUpdatePattern(document, $def, object, parsedColor, createImage); // use style instead of attribute when applying <pattern>
2386
+ // @see https://stackoverflow.com/a/7723115
2129
2387
 
2130
- var matches = (_$el$getAttribute = $el.getAttribute(name)) === null || _$el$getAttribute === void 0 ? void 0 : _$el$getAttribute.match(urlRegexp);
2388
+ $el.style[name] = "url(#".concat(patternId, ")");
2389
+ return patternId;
2390
+ } else {
2391
+ if (parsedColor.length === 1) {
2392
+ var gradientId = createOrUpdateGradient(document, object, $def, $el, parsedColor[0]);
2393
+ $el === null || $el === void 0 ? void 0 : $el.setAttribute(name, "url(#".concat(gradientId, ")"));
2394
+ return gradientId;
2395
+ } else {
2396
+ // @see https://stackoverflow.com/questions/20671502/can-i-blend-gradients-in-svg
2397
+ var filterId = createOrUpdateMultiGradient(document, object, $def, $el, parsedColor);
2398
+ $el === null || $el === void 0 ? void 0 : $el.setAttribute('filter', "url(#".concat(filterId, ")"));
2399
+ $el === null || $el === void 0 ? void 0 : $el.setAttribute('fill', 'black');
2400
+ return filterId;
2401
+ }
2402
+ }
2131
2403
 
2132
- if (matches && matches.length > 1) {
2133
- this.clearUnusedDefElement(this.gradientCache, matches[1], object.entity);
2134
- }
2404
+ return '';
2405
+ }
2135
2406
 
2136
- var newDefElementId = createOrUpdateGradientAndPattern(doc || document, this.$def, object, $el, parsedColor, name, createImage);
2407
+ function generateCacheKey(src) {
2408
+ var cacheKey = '';
2137
2409
 
2138
- if (!this.gradientCache[newDefElementId]) {
2139
- this.gradientCache[newDefElementId] = new Set();
2140
- }
2410
+ if (src instanceof g.CSSGradientValue) {
2411
+ var type = src.type,
2412
+ value = src.value;
2141
2413
 
2142
- this.gradientCache[newDefElementId].add(object.entity);
2414
+ if (type === g.GradientType.LinearGradient || type === g.GradientType.RadialGradient) {
2415
+ // @ts-ignore
2416
+ var _type = value.type,
2417
+ width = value.width,
2418
+ height = value.height,
2419
+ steps = value.steps,
2420
+ angle = value.angle,
2421
+ cx = value.cx,
2422
+ cy = value.cy;
2423
+ cacheKey = "".concat(_type).concat(width).concat(height).concat(angle || 0).concat(cx || 0).concat(cy || 0).concat(steps.map(function (step) {
2424
+ return step.join('');
2425
+ }).join(''));
2143
2426
  }
2144
- };
2145
-
2146
- _proto.createOrUpdateShadow = function createOrUpdateShadow$1(object, $el, name) {
2147
- var doc = this.canvasConfig.document;
2148
- createOrUpdateShadow(doc || document, this.$def, object, $el, name);
2149
- };
2150
-
2151
- _proto.createOrUpdateFilter = function createOrUpdateFilter$1(object, $el, filters) {
2152
- var doc = this.canvasConfig.document;
2153
- createOrUpdateFilter(doc || document, this.$def, object, $el, filters);
2154
- };
2155
-
2156
- return DefElementManager;
2157
- }();
2427
+ } else if (g.isPattern(src)) {
2428
+ if (g.isString(src.image)) {
2429
+ cacheKey = "pattern-".concat(src.image, "-").concat(src.repetition);
2430
+ } else {
2431
+ cacheKey = "pattern-".concat(counter);
2432
+ }
2433
+ }
2158
2434
 
2159
- __decorate([g.inject(g.CanvasConfig), __metadata("design:type", Object)], DefElementManager.prototype, "canvasConfig", void 0);
2435
+ if (cacheKey) {
2436
+ if (!cacheKey2IDMap[cacheKey]) {
2437
+ cacheKey2IDMap[cacheKey] = PATTERN_PREFIX + "".concat(counter++);
2438
+ }
2439
+ }
2160
2440
 
2161
- __decorate([g.inject(g.ContextService), __metadata("design:type", Object)], DefElementManager.prototype, "contextService", void 0);
2441
+ return cacheKey2IDMap[cacheKey];
2442
+ }
2162
2443
 
2163
- DefElementManager = __decorate([g.singleton()], DefElementManager);
2444
+ function createOrUpdatePattern(document, $def, object, pattern, createImage) {
2445
+ var patternId = generateCacheKey(pattern);
2446
+ var $existed = $def.querySelector("#".concat(patternId));
2164
2447
 
2165
- function _regeneratorRuntime$2() {
2166
- /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */
2167
- _regeneratorRuntime$2 = function _regeneratorRuntime() {
2168
- return exports;
2169
- };
2448
+ if (!$existed) {
2449
+ var image = pattern.image,
2450
+ repetition = pattern.repetition;
2451
+ var imageURL = '';
2170
2452
 
2171
- var exports = {},
2172
- Op = Object.prototype,
2173
- hasOwn = Op.hasOwnProperty,
2174
- $Symbol = "function" == typeof Symbol ? Symbol : {},
2175
- iteratorSymbol = $Symbol.iterator || "@@iterator",
2176
- asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator",
2177
- toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag";
2453
+ if (g.isString(image)) {
2454
+ imageURL = image;
2455
+ } else {
2456
+ if (g.isBrowser) {
2457
+ if (image instanceof HTMLImageElement) {
2458
+ imageURL = image.src;
2459
+ } else if (image instanceof HTMLCanvasElement) {
2460
+ imageURL = image.toDataURL();
2461
+ } else ;
2462
+ }
2463
+ }
2178
2464
 
2179
- function define(obj, key, value) {
2180
- return Object.defineProperty(obj, key, {
2181
- value: value,
2182
- enumerable: !0,
2183
- configurable: !0,
2184
- writable: !0
2185
- }), obj[key];
2186
- }
2465
+ if (imageURL) {
2466
+ // @see https://developer.mozilla.org/zh-CN/docs/Web/SVG/Element/pattern
2467
+ var $pattern = createSVGElement('pattern', document);
2468
+ $pattern.setAttribute('patternUnits', 'userSpaceOnUse');
2469
+ var $image = createSVGElement('image', document);
2470
+ $pattern.appendChild($image);
2471
+ $pattern.id = patternId;
2472
+ $def.appendChild($pattern); // use href instead of xlink:href
2473
+ // @see https://stackoverflow.com/a/13379007
2187
2474
 
2188
- try {
2189
- define({}, "");
2190
- } catch (err) {
2191
- define = function define(obj, key, value) {
2192
- return obj[key] = value;
2193
- };
2194
- }
2475
+ $image.setAttribute('href', imageURL);
2476
+ var img;
2195
2477
 
2196
- function wrap(innerFn, outerFn, self, tryLocsList) {
2197
- var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator,
2198
- generator = Object.create(protoGenerator.prototype),
2199
- context = new Context(tryLocsList || []);
2200
- return generator._invoke = function (innerFn, self, context) {
2201
- var state = "suspendedStart";
2202
- return function (method, arg) {
2203
- if ("executing" === state) throw new Error("Generator is already running");
2478
+ if (createImage) {
2479
+ img = createImage(imageURL);
2480
+ } else if (g.isBrowser) {
2481
+ img = new window.Image();
2482
+ }
2204
2483
 
2205
- if ("completed" === state) {
2206
- if ("throw" === method) throw arg;
2207
- return doneResult();
2208
- }
2484
+ if (!imageURL.match(/^data:/i)) {
2485
+ img.crossOrigin = 'Anonymous';
2486
+ $image.setAttribute('crossorigin', 'anonymous');
2487
+ }
2209
2488
 
2210
- for (context.method = method, context.arg = arg;;) {
2211
- var delegate = context.delegate;
2489
+ img.src = imageURL;
2212
2490
 
2213
- if (delegate) {
2214
- var delegateResult = maybeInvokeDelegate(delegate, context);
2491
+ var onload = function onload() {
2492
+ $pattern.setAttribute('x', '0');
2493
+ $pattern.setAttribute('y', '0');
2215
2494
 
2216
- if (delegateResult) {
2217
- if (delegateResult === ContinueSentinel) continue;
2218
- return delegateResult;
2219
- }
2220
- }
2495
+ var _object$getGeometryBo = object.getGeometryBounds(),
2496
+ halfExtents = _object$getGeometryBo.halfExtents; // There is no equivalent to CSS no-repeat for SVG patterns
2497
+ // @see https://stackoverflow.com/a/33481956
2221
2498
 
2222
- if ("next" === context.method) context.sent = context._sent = context.arg;else if ("throw" === context.method) {
2223
- if ("suspendedStart" === state) throw state = "completed", context.arg;
2224
- context.dispatchException(context.arg);
2225
- } else "return" === context.method && context.abrupt("return", context.arg);
2226
- state = "executing";
2227
- var record = tryCatch(innerFn, self, context);
2228
2499
 
2229
- if ("normal" === record.type) {
2230
- if (state = context.done ? "completed" : "suspendedYield", record.arg === ContinueSentinel) continue;
2231
- return {
2232
- value: record.arg,
2233
- done: context.done
2234
- };
2235
- }
2500
+ var patternWidth = img.width;
2501
+ var patternHeight = img.height;
2236
2502
 
2237
- "throw" === record.type && (state = "completed", context.method = "throw", context.arg = record.arg);
2503
+ if (repetition === 'repeat-x') {
2504
+ patternHeight = halfExtents[1] * 2;
2505
+ } else if (repetition === 'repeat-y') {
2506
+ patternWidth = halfExtents[0] * 2;
2507
+ } else if (repetition === 'no-repeat') {
2508
+ patternWidth = halfExtents[0] * 2;
2509
+ patternHeight = halfExtents[1] * 2;
2238
2510
  }
2239
- };
2240
- }(innerFn, self, context), generator;
2241
- }
2242
2511
 
2243
- function tryCatch(fn, obj, arg) {
2244
- try {
2245
- return {
2246
- type: "normal",
2247
- arg: fn.call(obj, arg)
2248
- };
2249
- } catch (err) {
2250
- return {
2251
- type: "throw",
2252
- arg: err
2512
+ $pattern.setAttribute('width', "".concat(patternWidth));
2513
+ $pattern.setAttribute('height', "".concat(patternHeight));
2514
+ $image.setAttribute('x', '0');
2515
+ $image.setAttribute('y', '0');
2516
+ $image.setAttribute('width', "".concat(img.width));
2517
+ $image.setAttribute('height', "".concat(img.height));
2253
2518
  };
2519
+
2520
+ if (img.complete) {
2521
+ onload();
2522
+ } else {
2523
+ img.onload = onload; // Fix onload() bug in IE9
2524
+
2525
+ img.src = img.src;
2526
+ }
2254
2527
  }
2255
2528
  }
2256
2529
 
2257
- exports.wrap = wrap;
2258
- var ContinueSentinel = {};
2530
+ return patternId;
2531
+ }
2259
2532
 
2260
- function Generator() {}
2533
+ function createOrUpdateGradient(document, object, $def, $el, parsedColor) {
2534
+ var gradientId = generateCacheKey(parsedColor);
2535
+ var $existed = $def.querySelector("#".concat(gradientId));
2261
2536
 
2262
- function GeneratorFunction() {}
2537
+ if (!$existed) {
2538
+ // <linearGradient> <radialGradient>
2539
+ // @see https://developer.mozilla.org/zh-CN/docs/Web/SVG/Element/linearGradient
2540
+ // @see https://developer.mozilla.org/zh-CN/docs/Web/SVG/Element/radialGradient
2541
+ $existed = createSVGElement(parsedColor.type === g.GradientType.LinearGradient ? 'linearGradient' : 'radialGradient', document); // @see https://github.com/antvis/g/issues/1025
2263
2542
 
2264
- function GeneratorFunctionPrototype() {}
2543
+ $existed.setAttribute('gradientUnits', 'userSpaceOnUse'); // add stops
2265
2544
 
2266
- var IteratorPrototype = {};
2267
- define(IteratorPrototype, iteratorSymbol, function () {
2268
- return this;
2269
- });
2270
- var getProto = Object.getPrototypeOf,
2271
- NativeIteratorPrototype = getProto && getProto(getProto(values([])));
2272
- NativeIteratorPrototype && NativeIteratorPrototype !== Op && hasOwn.call(NativeIteratorPrototype, iteratorSymbol) && (IteratorPrototype = NativeIteratorPrototype);
2273
- var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(IteratorPrototype);
2545
+ var innerHTML = '';
2546
+ parsedColor.value.steps.forEach(function (_ref) {
2547
+ var _ref2 = _slicedToArray(_ref, 2),
2548
+ offset = _ref2[0],
2549
+ color = _ref2[1];
2274
2550
 
2275
- function defineIteratorMethods(prototype) {
2276
- ["next", "throw", "return"].forEach(function (method) {
2277
- define(prototype, method, function (arg) {
2278
- return this._invoke(method, arg);
2279
- });
2551
+ innerHTML += "<stop offset=\"".concat(offset, "\" stop-color=\"").concat(color, "\"></stop>");
2280
2552
  });
2553
+ $existed.innerHTML = innerHTML;
2554
+ $existed.id = gradientId;
2555
+ $def.appendChild($existed);
2281
2556
  }
2282
2557
 
2283
- function AsyncIterator(generator, PromiseImpl) {
2284
- function invoke(method, arg, resolve, reject) {
2285
- var record = tryCatch(generator[method], generator, arg);
2558
+ var bounds = object.getGeometryBounds();
2559
+ var width = bounds && bounds.halfExtents[0] * 2 || 0;
2560
+ var height = bounds && bounds.halfExtents[1] * 2 || 0;
2286
2561
 
2287
- if ("throw" !== record.type) {
2288
- var result = record.arg,
2289
- value = result.value;
2290
- return value && "object" == typeof value && hasOwn.call(value, "__await") ? PromiseImpl.resolve(value.__await).then(function (value) {
2291
- invoke("next", value, resolve, reject);
2292
- }, function (err) {
2293
- invoke("throw", err, resolve, reject);
2294
- }) : PromiseImpl.resolve(value).then(function (unwrapped) {
2295
- result.value = unwrapped, resolve(result);
2296
- }, function (error) {
2297
- return invoke("throw", error, resolve, reject);
2298
- });
2299
- }
2562
+ if (parsedColor.type === g.GradientType.LinearGradient) {
2563
+ var angle = parsedColor.value.angle;
2300
2564
 
2301
- reject(record.arg);
2302
- }
2565
+ var _computeLinearGradien = g.computeLinearGradient(width, height, angle),
2566
+ x1 = _computeLinearGradien.x1,
2567
+ y1 = _computeLinearGradien.y1,
2568
+ x2 = _computeLinearGradien.x2,
2569
+ y2 = _computeLinearGradien.y2;
2303
2570
 
2304
- var previousPromise;
2571
+ $existed.setAttribute('x1', "".concat(x1));
2572
+ $existed.setAttribute('y1', "".concat(y1));
2573
+ $existed.setAttribute('x2', "".concat(x2));
2574
+ $existed.setAttribute('y2', "".concat(y2)); // $existed.setAttribute('gradientTransform', `rotate(${angle})`);
2575
+ } else {
2576
+ var _parsedColor$value = parsedColor.value,
2577
+ cx = _parsedColor$value.cx,
2578
+ cy = _parsedColor$value.cy;
2305
2579
 
2306
- this._invoke = function (method, arg) {
2307
- function callInvokeWithMethodAndArg() {
2308
- return new PromiseImpl(function (resolve, reject) {
2309
- invoke(method, arg, resolve, reject);
2310
- });
2311
- }
2580
+ var _computeRadialGradien = g.computeRadialGradient(width, height, cx, cy),
2581
+ x = _computeRadialGradien.x,
2582
+ y = _computeRadialGradien.y,
2583
+ r = _computeRadialGradien.r;
2312
2584
 
2313
- return previousPromise = previousPromise ? previousPromise.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg();
2314
- };
2585
+ $existed.setAttribute('cx', "".concat(x));
2586
+ $existed.setAttribute('cy', "".concat(y));
2587
+ $existed.setAttribute('r', "".concat(r));
2315
2588
  }
2316
2589
 
2317
- function maybeInvokeDelegate(delegate, context) {
2318
- var method = delegate.iterator[context.method];
2590
+ return gradientId;
2591
+ }
2319
2592
 
2320
- if (undefined === method) {
2321
- if (context.delegate = null, "throw" === context.method) {
2322
- if (delegate.iterator.return && (context.method = "return", context.arg = undefined, maybeInvokeDelegate(delegate, context), "throw" === context.method)) return ContinueSentinel;
2323
- context.method = "throw", context.arg = new TypeError("The iterator does not provide a 'throw' method");
2324
- }
2593
+ function createOrUpdateMultiGradient(document, object, $def, $el, gradients) {
2594
+ var filterId = FILTER_PREFIX + object.entity + '-gradient';
2595
+ var $existed = $def.querySelector("#".concat(filterId));
2325
2596
 
2326
- return ContinueSentinel;
2327
- }
2597
+ if (!$existed) {
2598
+ $existed = createSVGElement('filter', document);
2599
+ $existed.setAttribute('filterUnits', 'userSpaceOnUse'); // @see https://github.com/antvis/g/issues/1025
2328
2600
 
2329
- var record = tryCatch(method, delegate.iterator, context.arg);
2330
- if ("throw" === record.type) return context.method = "throw", context.arg = record.arg, context.delegate = null, ContinueSentinel;
2331
- var info = record.arg;
2332
- return info ? info.done ? (context[delegate.resultName] = info.value, context.next = delegate.nextLoc, "return" !== context.method && (context.method = "next", context.arg = undefined), context.delegate = null, ContinueSentinel) : info : (context.method = "throw", context.arg = new TypeError("iterator result is not an object"), context.delegate = null, ContinueSentinel);
2601
+ $existed.setAttribute('x', '0%');
2602
+ $existed.setAttribute('y', '0%');
2603
+ $existed.setAttribute('width', '100%');
2604
+ $existed.setAttribute('height', '100%');
2605
+ $existed.id = filterId;
2606
+ $def.appendChild($existed);
2333
2607
  }
2608
+ /**
2609
+ * <rect id="wave-rect" x="0" y="0" width="100%" height="100%" fill="url(#wave)"></rect>
2610
+ * <filter id="blend-it" x="0%" y="0%" width="100%" height="100%">
2611
+ <feImage xlink:href="#wave-rect" result="myWave" x="100" y="100"/>
2612
+ <feImage xlink:href="#ry-rect" result="myRY" x="100" y="100"/>
2613
+ <feBlend in="myWave" in2="myRY" mode="multiply" result="blendedGrad"/>
2614
+ <feComposite in="blendedGrad" in2="SourceGraphic" operator="in"/>
2615
+ </filter>
2616
+ */
2617
+
2618
+
2619
+ var blended = 0;
2620
+ gradients.forEach(function (gradient, i) {
2621
+ var gradientId = createOrUpdateGradient(document, object, $def, $el, gradient);
2622
+ var rectId = gradientId + '_rect';
2623
+ var $rect = createSVGElement('rect', document);
2624
+ $rect.setAttribute('x', '0');
2625
+ $rect.setAttribute('y', '0');
2626
+ $rect.setAttribute('width', '100%');
2627
+ $rect.setAttribute('height', '100%');
2628
+ $rect.setAttribute('fill', "url(#".concat(gradientId, ")"));
2629
+ $rect.id = rectId;
2630
+ $def.appendChild($rect);
2631
+ var $feImage = createSVGElement('feImage', document);
2632
+ $feImage.setAttribute('href', "#".concat(rectId));
2633
+ $feImage.setAttribute('result', "".concat(filterId, "-").concat(i));
2634
+ $existed.appendChild($feImage);
2635
+
2636
+ if (i > 0) {
2637
+ var $feBlend = createSVGElement('feBlend', document);
2638
+ $feBlend.setAttribute('in', i === 1 ? "".concat(filterId, "-").concat(i - 1) : "".concat(filterId, "-blended-").concat(blended - 1));
2639
+ $feBlend.setAttribute('in2', "".concat(filterId, "-").concat(i));
2640
+ $feBlend.setAttribute('result', "".concat(filterId, "-blended-").concat(blended++)); // @see https://developer.mozilla.org/zh-CN/docs/Web/CSS/blend-mode
2641
+
2642
+ $feBlend.setAttribute('mode', 'multiply');
2643
+ $existed.appendChild($feBlend);
2644
+ }
2645
+ });
2646
+ var $feComposite = createSVGElement('feComposite', document);
2647
+ $feComposite.setAttribute('in', "".concat(filterId, "-blended-").concat(blended));
2648
+ $feComposite.setAttribute('in2', 'SourceGraphic');
2649
+ $feComposite.setAttribute('operator', 'in');
2650
+ $existed.appendChild($feComposite);
2651
+ return filterId;
2652
+ }
2653
+
2654
+ var FILTER_DROPSHADOW_PREFIX = 'g-filter-dropshadow-';
2655
+ /**
2656
+ * use SVG filters
2657
+ * @see https://developer.mozilla.org/zh-CN/docs/Web/SVG/Element/filter
2658
+ */
2334
2659
 
2335
- function pushTryEntry(locs) {
2336
- var entry = {
2337
- tryLoc: locs[0]
2338
- };
2339
- 1 in locs && (entry.catchLoc = locs[1]), 2 in locs && (entry.finallyLoc = locs[2], entry.afterLoc = locs[3]), this.tryEntries.push(entry);
2340
- }
2660
+ function createOrUpdateShadow(document, $def, object, $el, name) {
2661
+ var _object$parsedStyle$s;
2341
2662
 
2342
- function resetTryEntry(entry) {
2343
- var record = entry.completion || {};
2344
- record.type = "normal", delete record.arg, entry.completion = record;
2345
- }
2663
+ var shadowId = FILTER_DROPSHADOW_PREFIX + object.entity;
2664
+ var $existedFilter = $def.querySelector("#".concat(shadowId));
2346
2665
 
2347
- function Context(tryLocsList) {
2348
- this.tryEntries = [{
2349
- tryLoc: "root"
2350
- }], tryLocsList.forEach(pushTryEntry, this), this.reset(!0);
2351
- }
2666
+ if (!$existedFilter) {
2667
+ $existedFilter = createSVGElement('filter', document);
2352
2668
 
2353
- function values(iterable) {
2354
- if (iterable) {
2355
- var iteratorMethod = iterable[iteratorSymbol];
2356
- if (iteratorMethod) return iteratorMethod.call(iterable);
2357
- if ("function" == typeof iterable.next) return iterable;
2669
+ var _$feDropShadow = createSVGElement('feDropShadow', document);
2358
2670
 
2359
- if (!isNaN(iterable.length)) {
2360
- var i = -1,
2361
- next = function next() {
2362
- for (; ++i < iterable.length;) {
2363
- if (hasOwn.call(iterable, i)) return next.value = iterable[i], next.done = !1, next;
2364
- }
2671
+ _$feDropShadow.setAttribute('dx', '0');
2365
2672
 
2366
- return next.value = undefined, next.done = !0, next;
2367
- };
2673
+ _$feDropShadow.setAttribute('dy', '0');
2368
2674
 
2369
- return next.next = next;
2370
- }
2371
- }
2675
+ $existedFilter.appendChild(_$feDropShadow);
2676
+ $existedFilter.id = shadowId; // @see https://github.com/antvis/g/issues/1025
2372
2677
 
2373
- return {
2374
- next: doneResult
2375
- };
2678
+ $existedFilter.setAttribute('filterUnits', 'userSpaceOnUse');
2679
+ $def.appendChild($existedFilter);
2376
2680
  }
2377
2681
 
2378
- function doneResult() {
2379
- return {
2380
- value: undefined,
2381
- done: !0
2382
- };
2383
- }
2682
+ var $feDropShadow = $existedFilter.children[0];
2384
2683
 
2385
- return GeneratorFunction.prototype = GeneratorFunctionPrototype, define(Gp, "constructor", GeneratorFunctionPrototype), define(GeneratorFunctionPrototype, "constructor", GeneratorFunction), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, toStringTagSymbol, "GeneratorFunction"), exports.isGeneratorFunction = function (genFun) {
2386
- var ctor = "function" == typeof genFun && genFun.constructor;
2387
- return !!ctor && (ctor === GeneratorFunction || "GeneratorFunction" === (ctor.displayName || ctor.name));
2388
- }, exports.mark = function (genFun) {
2389
- return Object.setPrototypeOf ? Object.setPrototypeOf(genFun, GeneratorFunctionPrototype) : (genFun.__proto__ = GeneratorFunctionPrototype, define(genFun, toStringTagSymbol, "GeneratorFunction")), genFun.prototype = Object.create(Gp), genFun;
2390
- }, exports.awrap = function (arg) {
2391
- return {
2392
- __await: arg
2393
- };
2394
- }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, asyncIteratorSymbol, function () {
2395
- return this;
2396
- }), exports.AsyncIterator = AsyncIterator, exports.async = function (innerFn, outerFn, self, tryLocsList, PromiseImpl) {
2397
- void 0 === PromiseImpl && (PromiseImpl = Promise);
2398
- var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList), PromiseImpl);
2399
- return exports.isGeneratorFunction(outerFn) ? iter : iter.next().then(function (result) {
2400
- return result.done ? result.value : iter.next();
2401
- });
2402
- }, defineIteratorMethods(Gp), define(Gp, toStringTagSymbol, "Generator"), define(Gp, iteratorSymbol, function () {
2403
- return this;
2404
- }), define(Gp, "toString", function () {
2405
- return "[object Generator]";
2406
- }), exports.keys = function (object) {
2407
- var keys = [];
2684
+ if (name === 'shadowColor') {
2685
+ var parsedColor = object.parsedStyle[name];
2686
+ $feDropShadow.setAttribute('flood-color', parsedColor.toString());
2687
+ } else if (name === 'shadowBlur') {
2688
+ var shadowBlur = object.parsedStyle[name]; // half the blur radius
2689
+ // @see https://drafts.csswg.org/css-backgrounds/#shadow-blur
2690
+ // @see https://css-tricks.com/breaking-css-box-shadow-vs-drop-shadow/
2408
2691
 
2409
- for (var key in object) {
2410
- keys.push(key);
2411
- }
2692
+ $feDropShadow.setAttribute('stdDeviation', "".concat(((shadowBlur === null || shadowBlur === void 0 ? void 0 : shadowBlur.value) || 0) / 4));
2693
+ } else if (name === 'shadowOffsetX') {
2694
+ var shadowOffsetX = object.parsedStyle[name];
2695
+ $feDropShadow.setAttribute('dx', "".concat(((shadowOffsetX === null || shadowOffsetX === void 0 ? void 0 : shadowOffsetX.value) || 0) / 2));
2696
+ } else if (name === 'shadowOffsetY') {
2697
+ var shadowOffsetY = object.parsedStyle[name];
2698
+ $feDropShadow.setAttribute('dy', "".concat(((shadowOffsetY === null || shadowOffsetY === void 0 ? void 0 : shadowOffsetY.value) || 0) / 2));
2699
+ } // only apply shadow when blur > 0
2412
2700
 
2413
- return keys.reverse(), function next() {
2414
- for (; keys.length;) {
2415
- var key = keys.pop();
2416
- if (key in object) return next.value = key, next.done = !1, next;
2417
- }
2418
2701
 
2419
- return next.done = !0, next;
2420
- };
2421
- }, exports.values = values, Context.prototype = {
2422
- constructor: Context,
2423
- reset: function reset(skipTempReset) {
2424
- if (this.prev = 0, this.next = 0, this.sent = this._sent = undefined, this.done = !1, this.delegate = null, this.method = "next", this.arg = undefined, this.tryEntries.forEach(resetTryEntry), !skipTempReset) for (var name in this) {
2425
- "t" === name.charAt(0) && hasOwn.call(this, name) && !isNaN(+name.slice(1)) && (this[name] = undefined);
2426
- }
2427
- },
2428
- stop: function stop() {
2429
- this.done = !0;
2430
- var rootRecord = this.tryEntries[0].completion;
2431
- if ("throw" === rootRecord.type) throw rootRecord.arg;
2432
- return this.rval;
2433
- },
2434
- dispatchException: function dispatchException(exception) {
2435
- if (this.done) throw exception;
2436
- var context = this;
2702
+ if (!g.isNil(object.parsedStyle.shadowColor) && ((_object$parsedStyle$s = object.parsedStyle.shadowBlur) === null || _object$parsedStyle$s === void 0 ? void 0 : _object$parsedStyle$s.value) > 0) {
2703
+ // use filter <feDropShadow>
2704
+ // @see https://developer.mozilla.org/en-US/docs/Web/SVG/Element/feDropShadow
2705
+ $el === null || $el === void 0 ? void 0 : $el.setAttribute('filter', "url(#".concat(shadowId, ")"));
2706
+ } else {
2707
+ $el === null || $el === void 0 ? void 0 : $el.removeAttribute('filter');
2708
+ }
2709
+ }
2437
2710
 
2438
- function handle(loc, caught) {
2439
- return record.type = "throw", record.arg = exception, context.next = loc, caught && (context.method = "next", context.arg = undefined), !!caught;
2440
- }
2711
+ var urlRegexp = /url\(#(.*)\)/;
2441
2712
 
2442
- for (var i = this.tryEntries.length - 1; i >= 0; --i) {
2443
- var entry = this.tryEntries[i],
2444
- record = entry.completion;
2445
- if ("root" === entry.tryLoc) return handle("end");
2713
+ var DefElementManager = /*#__PURE__*/function () {
2714
+ function DefElementManager() {
2715
+ _classCallCheck$2(this, DefElementManager);
2446
2716
 
2447
- if (entry.tryLoc <= this.prev) {
2448
- var hasCatch = hasOwn.call(entry, "catchLoc"),
2449
- hasFinally = hasOwn.call(entry, "finallyLoc");
2717
+ this.canvasConfig = void 0;
2718
+ this.contextService = void 0;
2719
+ this.$def = void 0;
2720
+ this.gradientCache = {};
2721
+ }
2450
2722
 
2451
- if (hasCatch && hasFinally) {
2452
- if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0);
2453
- if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc);
2454
- } else if (hasCatch) {
2455
- if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0);
2456
- } else {
2457
- if (!hasFinally) throw new Error("try statement without catch or finally");
2458
- if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc);
2459
- }
2460
- }
2461
- }
2462
- },
2463
- abrupt: function abrupt(type, arg) {
2464
- for (var i = this.tryEntries.length - 1; i >= 0; --i) {
2465
- var entry = this.tryEntries[i];
2723
+ _createClass$2(DefElementManager, [{
2724
+ key: "getDefElement",
2725
+ value: function getDefElement() {
2726
+ return this.$def;
2727
+ }
2728
+ }, {
2729
+ key: "init",
2730
+ value: function init() {
2731
+ var document = this.canvasConfig.document;
2732
+ var $svg = this.contextService.getContext();
2733
+ this.$def = createSVGElement('defs', document);
2734
+ $svg.appendChild(this.$def);
2735
+ }
2736
+ }, {
2737
+ key: "clear",
2738
+ value: function clear(entity) {
2739
+ var _this = this;
2466
2740
 
2467
- if (entry.tryLoc <= this.prev && hasOwn.call(entry, "finallyLoc") && this.prev < entry.finallyLoc) {
2468
- var finallyEntry = entry;
2469
- break;
2741
+ Object.keys(this.gradientCache).forEach(function (id) {
2742
+ _this.clearUnusedDefElement(_this.gradientCache, id, entity);
2743
+ });
2744
+ }
2745
+ }, {
2746
+ key: "clearUnusedDefElement",
2747
+ value: function clearUnusedDefElement(cache, id, entity) {
2748
+ if (cache[id].size === 1 && cache[id].has(entity)) {
2749
+ var targetElement = this.$def.querySelector("#".concat(id));
2750
+
2751
+ if (targetElement) {
2752
+ this.$def.removeChild(targetElement);
2470
2753
  }
2471
2754
  }
2755
+ }
2756
+ }, {
2757
+ key: "createOrUpdateGradientAndPattern",
2758
+ value: function createOrUpdateGradientAndPattern$1(object, $el, parsedColor, name) {
2759
+ var _this$canvasConfig = this.canvasConfig,
2760
+ doc = _this$canvasConfig.document,
2761
+ createImage = _this$canvasConfig.createImage;
2472
2762
 
2473
- finallyEntry && ("break" === type || "continue" === type) && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc && (finallyEntry = null);
2474
- var record = finallyEntry ? finallyEntry.completion : {};
2475
- return record.type = type, record.arg = arg, finallyEntry ? (this.method = "next", this.next = finallyEntry.finallyLoc, ContinueSentinel) : this.complete(record);
2476
- },
2477
- complete: function complete(record, afterLoc) {
2478
- if ("throw" === record.type) throw record.arg;
2479
- return "break" === record.type || "continue" === record.type ? this.next = record.arg : "return" === record.type ? (this.rval = this.arg = record.arg, this.method = "return", this.next = "end") : "normal" === record.type && afterLoc && (this.next = afterLoc), ContinueSentinel;
2480
- },
2481
- finish: function finish(finallyLoc) {
2482
- for (var i = this.tryEntries.length - 1; i >= 0; --i) {
2483
- var entry = this.tryEntries[i];
2484
- if (entry.finallyLoc === finallyLoc) return this.complete(entry.completion, entry.afterLoc), resetTryEntry(entry), ContinueSentinel;
2485
- }
2486
- },
2487
- catch: function _catch(tryLoc) {
2488
- for (var i = this.tryEntries.length - 1; i >= 0; --i) {
2489
- var entry = this.tryEntries[i];
2763
+ if ($el) {
2764
+ var _$el$getAttribute; // `url(#${gradientId})`
2490
2765
 
2491
- if (entry.tryLoc === tryLoc) {
2492
- var record = entry.completion;
2493
2766
 
2494
- if ("throw" === record.type) {
2495
- var thrown = record.arg;
2496
- resetTryEntry(entry);
2497
- }
2767
+ var matches = (_$el$getAttribute = $el.getAttribute(name)) === null || _$el$getAttribute === void 0 ? void 0 : _$el$getAttribute.match(urlRegexp);
2498
2768
 
2499
- return thrown;
2769
+ if (matches && matches.length > 1) {
2770
+ this.clearUnusedDefElement(this.gradientCache, matches[1], object.entity);
2500
2771
  }
2501
- }
2502
2772
 
2503
- throw new Error("illegal catch attempt");
2504
- },
2505
- delegateYield: function delegateYield(iterable, resultName, nextLoc) {
2506
- return this.delegate = {
2507
- iterator: values(iterable),
2508
- resultName: resultName,
2509
- nextLoc: nextLoc
2510
- }, "next" === this.method && (this.arg = undefined), ContinueSentinel;
2511
- }
2512
- }, exports;
2513
- }
2773
+ var newDefElementId = createOrUpdateGradientAndPattern(doc || document, this.$def, object, $el, parsedColor, name, createImage);
2514
2774
 
2515
- function asyncGeneratorStep$2(gen, resolve, reject, _next, _throw, key, arg) {
2516
- try {
2517
- var info = gen[key](arg);
2518
- var value = info.value;
2519
- } catch (error) {
2520
- reject(error);
2521
- return;
2522
- }
2775
+ if (!this.gradientCache[newDefElementId]) {
2776
+ this.gradientCache[newDefElementId] = new Set();
2777
+ }
2523
2778
 
2524
- if (info.done) {
2525
- resolve(value);
2526
- } else {
2527
- Promise.resolve(value).then(_next, _throw);
2528
- }
2529
- }
2779
+ this.gradientCache[newDefElementId].add(object.entity);
2780
+ }
2781
+ }
2782
+ }, {
2783
+ key: "createOrUpdateShadow",
2784
+ value: function createOrUpdateShadow$1(object, $el, name) {
2785
+ var doc = this.canvasConfig.document;
2786
+ createOrUpdateShadow(doc || document, this.$def, object, $el, name);
2787
+ }
2788
+ }, {
2789
+ key: "createOrUpdateFilter",
2790
+ value: function createOrUpdateFilter$1(object, $el, filters) {
2791
+ var doc = this.canvasConfig.document;
2792
+ createOrUpdateFilter(doc || document, this.$def, object, $el, filters);
2793
+ }
2794
+ }]);
2530
2795
 
2531
- function _asyncToGenerator$2(fn) {
2532
- return function () {
2533
- var self = this,
2534
- args = arguments;
2535
- return new Promise(function (resolve, reject) {
2536
- var gen = fn.apply(self, args);
2796
+ return DefElementManager;
2797
+ }();
2537
2798
 
2538
- function _next(value) {
2539
- asyncGeneratorStep$2(gen, resolve, reject, _next, _throw, "next", value);
2540
- }
2799
+ __decorate([g.inject(g.CanvasConfig), __metadata("design:type", Object)], DefElementManager.prototype, "canvasConfig", void 0);
2541
2800
 
2542
- function _throw(err) {
2543
- asyncGeneratorStep$2(gen, resolve, reject, _next, _throw, "throw", err);
2544
- }
2801
+ __decorate([g.inject(g.ContextService), __metadata("design:type", Object)], DefElementManager.prototype, "contextService", void 0);
2545
2802
 
2546
- _next(undefined);
2547
- });
2548
- };
2549
- }
2803
+ DefElementManager = __decorate([g.singleton()], DefElementManager);
2550
2804
  /**
2551
2805
  * Common utilities
2552
2806
  * @module glMatrix
2553
2807
  */
2554
2808
  // Configuration Constants
2555
2809
 
2556
-
2557
2810
  var EPSILON = 0.000001;
2558
2811
  var ARRAY_TYPE = typeof Float32Array !== 'undefined' ? Float32Array : Array;
2559
2812
  if (!Math.hypot) Math.hypot = function () {
@@ -3290,6 +3543,8 @@
3290
3543
  var CLIP_PATH_PREFIX = 'clip-path-';
3291
3544
  var SVGRendererPlugin = SVGRendererPlugin_1 = (_class$1 = /*#__PURE__*/function () {
3292
3545
  function SVGRendererPlugin() {
3546
+ _classCallCheck$2(this, SVGRendererPlugin);
3547
+
3293
3548
  this.canvasConfig = void 0;
3294
3549
  this.camera = void 0;
3295
3550
  this.contextService = void 0;
@@ -3298,516 +3553,530 @@
3298
3553
  this.defElementManager = void 0;
3299
3554
  this.$camera = void 0;
3300
3555
  this.renderQueue = [];
3301
- this.pendingReorderQueue = new Set();
3302
- }
3303
-
3304
- var _proto = SVGRendererPlugin.prototype;
3305
-
3306
- _proto.apply = function apply(renderingService) {
3307
- var _this = this;
3308
-
3309
- var document = this.canvasConfig.document;
3310
-
3311
- var handleMounted = function handleMounted(e) {
3312
- var object = e.target; // create SVG DOM Node
3313
-
3314
- _this.createSVGDom(document, object, _this.$camera);
3315
- };
3316
-
3317
- var handleUnmounted = function handleUnmounted(e) {
3318
- var object = e.target;
3319
-
3320
- _this.defElementManager.clear(object.entity);
3556
+ this.pendingReorderQueue = new Set();
3557
+ }
3321
3558
 
3322
- _this.removeSVGDom(object);
3323
- };
3559
+ _createClass$2(SVGRendererPlugin, [{
3560
+ key: "apply",
3561
+ value: function apply(renderingService) {
3562
+ var _this = this;
3324
3563
 
3325
- var handleAttributeChanged = function handleAttributeChanged(e) {
3326
- var object = e.target; // @see https://github.com/antvis/g/issues/994
3327
- // @ts-ignore
3564
+ var document = this.canvasConfig.document;
3328
3565
 
3329
- if (!object.elementSVG) {
3330
- return;
3331
- }
3566
+ var handleMounted = function handleMounted(e) {
3567
+ var object = e.target; // create SVG DOM Node
3332
3568
 
3333
- var attrName = e.attrName;
3569
+ _this.createSVGDom(document, object, _this.$camera);
3570
+ };
3334
3571
 
3335
- if (attrName === 'zIndex') {
3336
- var _object$parentNode, _object$parentNode$el;
3572
+ var handleUnmounted = function handleUnmounted(e) {
3573
+ var object = e.target;
3337
3574
 
3338
- var parent = object.parentNode; // @ts-ignore
3575
+ _this.defElementManager.clear(object.entity);
3339
3576
 
3340
- var $groupEl = (_object$parentNode = object.parentNode) === null || _object$parentNode === void 0 ? void 0 : (_object$parentNode$el = _object$parentNode.elementSVG) === null || _object$parentNode$el === void 0 ? void 0 : _object$parentNode$el.$groupEl;
3341
- var children = ((parent === null || parent === void 0 ? void 0 : parent.children) || []).slice();
3577
+ _this.removeSVGDom(object);
3578
+ };
3342
3579
 
3343
- if ($groupEl) {
3344
- _this.reorderChildren(document, $groupEl, children);
3345
- }
3346
- } else if (attrName === 'increasedLineWidthForHitTesting') {
3580
+ var handleAttributeChanged = function handleAttributeChanged(e) {
3581
+ var object = e.target; // @see https://github.com/antvis/g/issues/994
3347
3582
  // @ts-ignore
3348
- var svgElement = object.elementSVG;
3349
3583
 
3350
- _this.createOrUpdateHitArea(object, svgElement.$el, svgElement.$groupEl);
3351
- }
3352
-
3353
- _this.updateAttribute(object, [attrName]);
3354
- };
3584
+ if (!object.elementSVG) {
3585
+ return;
3586
+ }
3355
3587
 
3356
- var handleGeometryBoundsChanged = function handleGeometryBoundsChanged(e) {
3357
- var _object$elementSVG;
3588
+ var attrName = e.attrName;
3358
3589
 
3359
- var object = e.target; // @ts-ignore
3590
+ if (attrName === 'zIndex') {
3591
+ var _object$parentNode, _object$parentNode$el;
3360
3592
 
3361
- var $el = (_object$elementSVG = object.elementSVG) === null || _object$elementSVG === void 0 ? void 0 : _object$elementSVG.$el;
3362
- var _object$parsedStyle = object.parsedStyle,
3363
- fill = _object$parsedStyle.fill,
3364
- stroke = _object$parsedStyle.stroke;
3593
+ var parent = object.parentNode; // @ts-ignore
3365
3594
 
3366
- if (fill && !(fill instanceof g.CSSRGB)) {
3367
- _this.defElementManager.createOrUpdateGradientAndPattern(object, $el, fill, 'fill');
3368
- }
3595
+ var $groupEl = (_object$parentNode = object.parentNode) === null || _object$parentNode === void 0 ? void 0 : (_object$parentNode$el = _object$parentNode.elementSVG) === null || _object$parentNode$el === void 0 ? void 0 : _object$parentNode$el.$groupEl;
3596
+ var children = ((parent === null || parent === void 0 ? void 0 : parent.children) || []).slice();
3369
3597
 
3370
- if (stroke && !(stroke instanceof g.CSSRGB)) {
3371
- _this.defElementManager.createOrUpdateGradientAndPattern(object, $el, stroke, 'stroke');
3372
- }
3373
- };
3598
+ if ($groupEl) {
3599
+ _this.reorderChildren(document, $groupEl, children);
3600
+ }
3601
+ } else if (attrName === 'increasedLineWidthForHitTesting') {
3602
+ // @ts-ignore
3603
+ var svgElement = object.elementSVG;
3374
3604
 
3375
- renderingService.hooks.init.tapPromise(SVGRendererPlugin_1.tag, /*#__PURE__*/_asyncToGenerator$2( /*#__PURE__*/_regeneratorRuntime$2().mark(function _callee() {
3376
- var _this$canvasConfig, background, document, $svg;
3605
+ _this.createOrUpdateHitArea(object, svgElement.$el, svgElement.$groupEl);
3606
+ }
3377
3607
 
3378
- return _regeneratorRuntime$2().wrap(function _callee$(_context) {
3379
- while (1) {
3380
- switch (_context.prev = _context.next) {
3381
- case 0:
3382
- _this$canvasConfig = _this.canvasConfig, background = _this$canvasConfig.background, document = _this$canvasConfig.document; // <defs>
3608
+ _this.updateAttribute(object, [attrName]);
3609
+ };
3383
3610
 
3384
- _this.defElementManager.init();
3611
+ var handleGeometryBoundsChanged = function handleGeometryBoundsChanged(e) {
3612
+ var _object$elementSVG;
3385
3613
 
3386
- $svg = _this.contextService.getContext();
3614
+ var object = e.target; // @ts-ignore
3387
3615
 
3388
- if (background) {
3389
- $svg.style.background = background;
3390
- } // @see https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/color-interpolation-filters
3616
+ var $el = (_object$elementSVG = object.elementSVG) === null || _object$elementSVG === void 0 ? void 0 : _object$elementSVG.$el;
3617
+ var _object$parsedStyle = object.parsedStyle,
3618
+ fill = _object$parsedStyle.fill,
3619
+ stroke = _object$parsedStyle.stroke;
3391
3620
 
3621
+ if (fill && !(fill instanceof g.CSSRGB)) {
3622
+ _this.defElementManager.createOrUpdateGradientAndPattern(object, $el, fill, 'fill');
3623
+ }
3392
3624
 
3393
- $svg.setAttribute('color-interpolation-filters', 'sRGB');
3394
- _this.$camera = createSVGElement('g', document);
3395
- _this.$camera.id = G_SVG_PREFIX + "_camera";
3625
+ if (stroke && !(stroke instanceof g.CSSRGB)) {
3626
+ _this.defElementManager.createOrUpdateGradientAndPattern(object, $el, stroke, 'stroke');
3627
+ }
3628
+ };
3396
3629
 
3397
- _this.applyTransform(_this.$camera, _this.camera.getOrthoMatrix());
3630
+ renderingService.hooks.init.tapPromise(SVGRendererPlugin_1.tag, /*#__PURE__*/_asyncToGenerator$2( /*#__PURE__*/_regeneratorRuntime$2().mark(function _callee() {
3631
+ var _this$canvasConfig, background, document, $svg;
3398
3632
 
3399
- $svg.appendChild(_this.$camera);
3633
+ return _regeneratorRuntime$2().wrap(function _callee$(_context) {
3634
+ while (1) {
3635
+ switch (_context.prev = _context.next) {
3636
+ case 0:
3637
+ _this$canvasConfig = _this.canvasConfig, background = _this$canvasConfig.background, document = _this$canvasConfig.document; // <defs>
3400
3638
 
3401
- _this.renderingContext.root.addEventListener(g.ElementEvent.MOUNTED, handleMounted);
3639
+ _this.defElementManager.init();
3402
3640
 
3403
- _this.renderingContext.root.addEventListener(g.ElementEvent.UNMOUNTED, handleUnmounted);
3641
+ $svg = _this.contextService.getContext();
3404
3642
 
3405
- _this.renderingContext.root.addEventListener(g.ElementEvent.ATTR_MODIFIED, handleAttributeChanged);
3643
+ if (background) {
3644
+ $svg.style.background = background;
3645
+ } // @see https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/color-interpolation-filters
3406
3646
 
3407
- _this.renderingContext.root.addEventListener(g.ElementEvent.GEOMETRY_BOUNDS_CHANGED, handleGeometryBoundsChanged);
3408
3647
 
3409
- case 13:
3410
- case "end":
3411
- return _context.stop();
3412
- }
3413
- }
3414
- }, _callee);
3415
- })));
3416
- renderingService.hooks.destroy.tap(SVGRendererPlugin_1.tag, function () {
3417
- _this.renderingContext.root.removeEventListener(g.ElementEvent.MOUNTED, handleMounted);
3648
+ $svg.setAttribute('color-interpolation-filters', 'sRGB');
3649
+ _this.$camera = createSVGElement('g', document);
3650
+ _this.$camera.id = "".concat(G_SVG_PREFIX, "_camera");
3418
3651
 
3419
- _this.renderingContext.root.removeEventListener(g.ElementEvent.UNMOUNTED, handleUnmounted);
3652
+ _this.applyTransform(_this.$camera, _this.camera.getOrthoMatrix());
3420
3653
 
3421
- _this.renderingContext.root.removeEventListener(g.ElementEvent.ATTR_MODIFIED, handleAttributeChanged);
3654
+ $svg.appendChild(_this.$camera);
3422
3655
 
3423
- _this.renderingContext.root.removeEventListener(g.ElementEvent.GEOMETRY_BOUNDS_CHANGED, handleGeometryBoundsChanged);
3424
- });
3425
- renderingService.hooks.render.tap(SVGRendererPlugin_1.tag, function (object) {
3426
- // if (!object.isCulled()) {
3427
- _this.renderQueue.push(object); // }
3656
+ _this.renderingContext.root.addEventListener(g.ElementEvent.MOUNTED, handleMounted);
3428
3657
 
3429
- });
3430
- renderingService.hooks.beginFrame.tap(SVGRendererPlugin_1.tag, function () {
3431
- var doc = _this.canvasConfig.document;
3658
+ _this.renderingContext.root.addEventListener(g.ElementEvent.UNMOUNTED, handleUnmounted);
3432
3659
 
3433
- if (_this.pendingReorderQueue.size) {
3434
- _this.pendingReorderQueue.forEach(function (object) {
3435
- var _object$elementSVG2;
3660
+ _this.renderingContext.root.addEventListener(g.ElementEvent.ATTR_MODIFIED, handleAttributeChanged);
3436
3661
 
3437
- var children = ((object === null || object === void 0 ? void 0 : object.children) || []).slice();
3438
- var $parentGroupEl = // @ts-ignore
3439
- object === null || object === void 0 ? void 0 : (_object$elementSVG2 = object.elementSVG) === null || _object$elementSVG2 === void 0 ? void 0 : _object$elementSVG2.$groupEl;
3662
+ _this.renderingContext.root.addEventListener(g.ElementEvent.GEOMETRY_BOUNDS_CHANGED, handleGeometryBoundsChanged);
3440
3663
 
3441
- if ($parentGroupEl) {
3442
- _this.reorderChildren(doc || document, $parentGroupEl, children || []);
3664
+ case 13:
3665
+ case "end":
3666
+ return _context.stop();
3667
+ }
3443
3668
  }
3444
- });
3669
+ }, _callee);
3670
+ })));
3671
+ renderingService.hooks.destroy.tap(SVGRendererPlugin_1.tag, function () {
3672
+ _this.renderingContext.root.removeEventListener(g.ElementEvent.MOUNTED, handleMounted);
3445
3673
 
3446
- _this.pendingReorderQueue.clear();
3447
- }
3448
- });
3449
- renderingService.hooks.endFrame.tap(SVGRendererPlugin_1.tag, function () {
3450
- if (_this.renderingContext.renderReasons.has(g.RenderReason.CAMERA_CHANGED)) {
3451
- _this.applyTransform(_this.$camera, _this.camera.getOrthoMatrix());
3452
- }
3674
+ _this.renderingContext.root.removeEventListener(g.ElementEvent.UNMOUNTED, handleUnmounted);
3453
3675
 
3454
- _this.renderQueue.forEach(function (object) {
3455
- var _object$elementSVG3, _object$elementSVG4; // @ts-ignore
3676
+ _this.renderingContext.root.removeEventListener(g.ElementEvent.ATTR_MODIFIED, handleAttributeChanged);
3456
3677
 
3678
+ _this.renderingContext.root.removeEventListener(g.ElementEvent.GEOMETRY_BOUNDS_CHANGED, handleGeometryBoundsChanged);
3679
+ });
3680
+ renderingService.hooks.render.tap(SVGRendererPlugin_1.tag, function (object) {
3681
+ // if (!object.isCulled()) {
3682
+ _this.renderQueue.push(object); // }
3457
3683
 
3458
- var $el = (_object$elementSVG3 = object.elementSVG) === null || _object$elementSVG3 === void 0 ? void 0 : _object$elementSVG3.$el; // @ts-ignore
3684
+ });
3685
+ renderingService.hooks.beginFrame.tap(SVGRendererPlugin_1.tag, function () {
3686
+ var doc = _this.canvasConfig.document;
3459
3687
 
3460
- var $groupEl = (_object$elementSVG4 = object.elementSVG) === null || _object$elementSVG4 === void 0 ? void 0 : _object$elementSVG4.$groupEl;
3688
+ if (_this.pendingReorderQueue.size) {
3689
+ _this.pendingReorderQueue.forEach(function (object) {
3690
+ var _object$elementSVG2;
3461
3691
 
3462
- if ($el && $groupEl) {
3463
- // apply local RTS transformation to <group> wrapper
3464
- // account for anchor
3465
- _this.applyTransform($groupEl, object.getLocalTransform()); // finish rendering, clear dirty flag
3692
+ var children = ((object === null || object === void 0 ? void 0 : object.children) || []).slice();
3693
+ var $parentGroupEl = // @ts-ignore
3694
+ object === null || object === void 0 ? void 0 : (_object$elementSVG2 = object.elementSVG) === null || _object$elementSVG2 === void 0 ? void 0 : _object$elementSVG2.$groupEl;
3466
3695
 
3696
+ if ($parentGroupEl) {
3697
+ _this.reorderChildren(doc || document, $parentGroupEl, children || []);
3698
+ }
3699
+ });
3467
3700
 
3468
- object.renderable.dirty = false;
3701
+ _this.pendingReorderQueue.clear();
3469
3702
  }
3470
3703
  });
3704
+ renderingService.hooks.endFrame.tap(SVGRendererPlugin_1.tag, function () {
3705
+ if (_this.renderingContext.renderReasons.has(g.RenderReason.CAMERA_CHANGED)) {
3706
+ _this.applyTransform(_this.$camera, _this.camera.getOrthoMatrix());
3707
+ }
3471
3708
 
3472
- _this.renderQueue = [];
3473
- });
3474
- };
3709
+ _this.renderQueue.forEach(function (object) {
3710
+ var _object$elementSVG3, _object$elementSVG4; // @ts-ignore
3475
3711
 
3476
- _proto.reorderChildren = function reorderChildren(doc, $groupEl, children) {
3477
- // need to reorder parent's children
3478
- children.sort(function (a, b) {
3479
- return a.sortable.renderOrder - b.sortable.renderOrder;
3480
- });
3481
3712
 
3482
- if (children.length) {
3483
- // create empty fragment
3484
- var fragment = (doc || document).createDocumentFragment();
3485
- children.forEach(function (child) {
3486
- if (child.isConnected) {
3487
- // @ts-ignore
3488
- var $el = child.elementSVG.$groupEl;
3713
+ var $el = (_object$elementSVG3 = object.elementSVG) === null || _object$elementSVG3 === void 0 ? void 0 : _object$elementSVG3.$el; // @ts-ignore
3489
3714
 
3490
- if ($el) {
3491
- fragment.appendChild($el);
3715
+ var $groupEl = (_object$elementSVG4 = object.elementSVG) === null || _object$elementSVG4 === void 0 ? void 0 : _object$elementSVG4.$groupEl;
3716
+
3717
+ if ($el && $groupEl) {
3718
+ // apply local RTS transformation to <group> wrapper
3719
+ // account for anchor
3720
+ _this.applyTransform($groupEl, object.getLocalTransform()); // finish rendering, clear dirty flag
3721
+
3722
+
3723
+ object.renderable.dirty = false;
3492
3724
  }
3493
- }
3725
+ });
3726
+
3727
+ _this.renderQueue = [];
3494
3728
  });
3495
- $groupEl.appendChild(fragment);
3496
3729
  }
3497
- };
3498
-
3499
- _proto.applyTransform = function applyTransform($el, transform) {
3500
- var translation = getTranslation(create$1(), transform);
3501
- var scaling = getScaling(create$1(), transform);
3502
- var rotation = getRotation(create$3(), transform);
3503
- var x = translation[0],
3504
- y = translation[1];
3505
- var scaleX = scaling[0],
3506
- scaleY = scaling[1]; // eslint-disable-next-line @typescript-eslint/no-unused-vars
3730
+ }, {
3731
+ key: "reorderChildren",
3732
+ value: function reorderChildren(doc, $groupEl, children) {
3733
+ // need to reorder parent's children
3734
+ children.sort(function (a, b) {
3735
+ return a.sortable.renderOrder - b.sortable.renderOrder;
3736
+ });
3507
3737
 
3508
- var _getEuler = g.getEuler(create$1(), rotation),
3509
- ex = _getEuler[0],
3510
- ey = _getEuler[1],
3511
- ez = _getEuler[2]; // gimbal lock at 90 degrees
3738
+ if (children.length) {
3739
+ // create empty fragment
3740
+ var fragment = (doc || document).createDocumentFragment();
3741
+ children.forEach(function (child) {
3742
+ if (child.isConnected) {
3743
+ // @ts-ignore
3744
+ var $el = child.elementSVG.$groupEl;
3512
3745
 
3746
+ if ($el) {
3747
+ fragment.appendChild($el);
3748
+ }
3749
+ }
3750
+ });
3751
+ $groupEl.appendChild(fragment);
3752
+ }
3753
+ }
3754
+ }, {
3755
+ key: "applyTransform",
3756
+ value: function applyTransform($el, transform) {
3757
+ var translation = getTranslation(create$1(), transform);
3758
+ var scaling = getScaling(create$1(), transform);
3759
+ var rotation = getRotation(create$3(), transform);
3513
3760
 
3514
- var rts = g.fromRotationTranslationScale(ex || ez, x, y, scaleX, scaleY); // use proper precision avoiding too long string in `transform`
3515
- // @see https://developer.mozilla.org/en-US/docs/Web/API/Canvas_API/Tutorial/Transformations
3761
+ var _translation = _slicedToArray(translation, 2),
3762
+ x = _translation[0],
3763
+ y = _translation[1];
3516
3764
 
3517
- $el.setAttribute('transform', "matrix(" + numberToLongString(rts[0]) + "," + numberToLongString(rts[1]) + "," + numberToLongString(rts[3]) + "," + numberToLongString(rts[4]) + "," + numberToLongString(rts[6]) + "," + numberToLongString(rts[7]) + ")");
3518
- };
3765
+ var _scaling = _slicedToArray(scaling, 2),
3766
+ scaleX = _scaling[0],
3767
+ scaleY = _scaling[1]; // eslint-disable-next-line @typescript-eslint/no-unused-vars
3519
3768
 
3520
- _proto.applyAttributes = function applyAttributes(object) {
3521
- // @ts-ignore
3522
- var elementSVG = object.elementSVG;
3523
- var $el = elementSVG === null || elementSVG === void 0 ? void 0 : elementSVG.$el;
3524
- var $groupEl = elementSVG === null || elementSVG === void 0 ? void 0 : elementSVG.$groupEl;
3525
3769
 
3526
- if ($el && $groupEl) {
3527
- var nodeName = object.nodeName,
3528
- attributes = object.attributes;
3529
- $el.setAttribute('fill', 'none');
3770
+ var _getEuler = g.getEuler(create$1(), rotation),
3771
+ _getEuler2 = _slicedToArray(_getEuler, 3),
3772
+ ex = _getEuler2[0],
3773
+ ey = _getEuler2[1],
3774
+ ez = _getEuler2[2]; // gimbal lock at 90 degrees
3530
3775
 
3531
- if (nodeName === g.Shape.IMAGE) {
3532
- $el.setAttribute('preserveAspectRatio', 'none');
3533
- } // apply attributes
3534
3776
 
3777
+ var rts = g.fromRotationTranslationScale(ex || ez, x, y, scaleX, scaleY); // use proper precision avoiding too long string in `transform`
3778
+ // @see https://developer.mozilla.org/en-US/docs/Web/API/Canvas_API/Tutorial/Transformations
3535
3779
 
3536
- this.updateAttribute(object, Object.keys(attributes));
3780
+ $el.setAttribute('transform', "matrix(".concat(numberToLongString(rts[0]), ",").concat(numberToLongString(rts[1]), ",").concat(numberToLongString(rts[3]), ",").concat(numberToLongString(rts[4]), ",").concat(numberToLongString(rts[6]), ",").concat(numberToLongString(rts[7]), ")"));
3537
3781
  }
3538
- };
3782
+ }, {
3783
+ key: "applyAttributes",
3784
+ value: function applyAttributes(object) {
3785
+ // @ts-ignore
3786
+ var elementSVG = object.elementSVG;
3787
+ var $el = elementSVG === null || elementSVG === void 0 ? void 0 : elementSVG.$el;
3788
+ var $groupEl = elementSVG === null || elementSVG === void 0 ? void 0 : elementSVG.$groupEl;
3539
3789
 
3540
- _proto.updateAttribute = function updateAttribute(object, attributes) {
3541
- var _this2 = this;
3790
+ if ($el && $groupEl) {
3791
+ var nodeName = object.nodeName,
3792
+ attributes = object.attributes;
3793
+ $el.setAttribute('fill', 'none');
3542
3794
 
3543
- var document = this.canvasConfig.document; // @ts-ignore
3795
+ if (nodeName === g.Shape.IMAGE) {
3796
+ $el.setAttribute('preserveAspectRatio', 'none');
3797
+ } // apply attributes
3544
3798
 
3545
- var _object$elementSVG5 = object.elementSVG,
3546
- $el = _object$elementSVG5.$el,
3547
- $groupEl = _object$elementSVG5.$groupEl,
3548
- $hitTestingEl = _object$elementSVG5.$hitTestingEl;
3549
- var parsedStyle = object.parsedStyle,
3550
- computedStyle = object.computedStyle;
3551
- var shouldUpdateElementAttribute = attributes.some(function (name) {
3552
- return _this2.createElementContribution.shouldUpdateElementAttribute(object, name);
3553
- }); // need re-generate path
3554
3799
 
3555
- if (shouldUpdateElementAttribute && $el) {
3556
- [$el, $hitTestingEl].forEach(function ($el) {
3557
- if ($el) {
3558
- _this2.createElementContribution.updateElementAttribute(object, $el);
3800
+ this.updateAttribute(object, Object.keys(attributes));
3801
+ }
3802
+ }
3803
+ }, {
3804
+ key: "updateAttribute",
3805
+ value: function updateAttribute(object, attributes) {
3806
+ var _this2 = this;
3807
+
3808
+ var document = this.canvasConfig.document; // @ts-ignore
3809
+
3810
+ var _object$elementSVG5 = object.elementSVG,
3811
+ $el = _object$elementSVG5.$el,
3812
+ $groupEl = _object$elementSVG5.$groupEl,
3813
+ $hitTestingEl = _object$elementSVG5.$hitTestingEl;
3814
+ var parsedStyle = object.parsedStyle,
3815
+ computedStyle = object.computedStyle;
3816
+ var shouldUpdateElementAttribute = attributes.some(function (name) {
3817
+ return _this2.createElementContribution.shouldUpdateElementAttribute(object, name);
3818
+ }); // need re-generate path
3819
+
3820
+ if (shouldUpdateElementAttribute && $el) {
3821
+ [$el, $hitTestingEl].forEach(function ($el) {
3822
+ if ($el) {
3823
+ _this2.createElementContribution.updateElementAttribute(object, $el);
3559
3824
 
3560
- if (object.nodeName !== g.Shape.TEXT) {
3561
- _this2.updateAnchorWithTransform(object);
3825
+ if (object.nodeName !== g.Shape.TEXT) {
3826
+ _this2.updateAnchorWithTransform(object);
3827
+ }
3562
3828
  }
3563
- }
3564
- });
3565
- } // update common attributes
3566
-
3829
+ });
3830
+ } // update common attributes
3567
3831
 
3568
- attributes.forEach(function (name) {
3569
- var usedName = SVG_ATTR_MAP[name];
3570
- var computedValue = computedStyle[name];
3571
- var usedValue = parsedStyle[name]; // <foreignObject>
3572
3832
 
3573
- if (object.nodeName === g.Shape.HTML) {
3574
- if (name === 'lineWidth') {
3575
- $el.style['border-width'] = (usedValue.value || 0) + "px";
3576
- } else if (name === 'lineDash') {
3577
- $el.style['border-style'] = 'dashed';
3578
- }
3579
- }
3833
+ attributes.forEach(function (name) {
3834
+ var usedName = SVG_ATTR_MAP[name];
3835
+ var computedValue = computedStyle[name];
3836
+ var usedValue = parsedStyle[name]; // <foreignObject>
3580
3837
 
3581
- if (name === 'fill') {
3582
3838
  if (object.nodeName === g.Shape.HTML) {
3583
- $el.style.background = usedValue.toString();
3584
- } else {
3585
- _this2.defElementManager.createOrUpdateGradientAndPattern(object, $el, usedValue, usedName);
3839
+ if (name === 'lineWidth') {
3840
+ $el.style['border-width'] = "".concat(usedValue.value || 0, "px");
3841
+ } else if (name === 'lineDash') {
3842
+ $el.style['border-style'] = 'dashed';
3843
+ }
3586
3844
  }
3587
- } else if (name === 'stroke') {
3588
- if (object.nodeName === g.Shape.HTML) {
3589
- $el.style['border-color'] = usedValue.toString();
3590
- $el.style['border-style'] = 'solid';
3845
+
3846
+ if (name === 'fill') {
3847
+ if (object.nodeName === g.Shape.HTML) {
3848
+ $el.style.background = usedValue.toString();
3849
+ } else {
3850
+ _this2.defElementManager.createOrUpdateGradientAndPattern(object, $el, usedValue, usedName);
3851
+ }
3852
+ } else if (name === 'stroke') {
3853
+ if (object.nodeName === g.Shape.HTML) {
3854
+ $el.style['border-color'] = usedValue.toString();
3855
+ $el.style['border-style'] = 'solid';
3856
+ } else {
3857
+ _this2.defElementManager.createOrUpdateGradientAndPattern(object, $el, usedValue, usedName);
3858
+ }
3859
+ } else if (name === 'visibility' && computedValue.value !== 'unset') {
3860
+ // use computed value
3861
+ // update `visibility` on <group>
3862
+ $groupEl === null || $groupEl === void 0 ? void 0 : $groupEl.setAttribute(usedName, "".concat(computedValue.value));
3863
+ } else if (name === 'clipPath') {
3864
+ _this2.createOrUpdateClipPath(document, usedValue, $groupEl);
3865
+ } else if (name === 'shadowColor' || name === 'shadowBlur' || name === 'shadowOffsetX' || name === 'shadowOffsetY') {
3866
+ _this2.defElementManager.createOrUpdateShadow(object, $el, name);
3867
+ } else if (name === 'filter') {
3868
+ _this2.defElementManager.createOrUpdateFilter(object, $el, usedValue);
3869
+ } else if (name === 'innerHTML') {
3870
+ _this2.createOrUpdateInnerHTML(document, $el, usedValue);
3871
+ } else if (name === 'anchor') {
3872
+ // text' anchor is controlled by `textAnchor` property
3873
+ if (object.nodeName !== g.Shape.TEXT) {
3874
+ _this2.updateAnchorWithTransform(object);
3875
+ }
3591
3876
  } else {
3592
- _this2.defElementManager.createOrUpdateGradientAndPattern(object, $el, usedValue, usedName);
3593
- }
3594
- } else if (name === 'visibility' && computedValue.value !== 'unset') {
3595
- // use computed value
3596
- // update `visibility` on <group>
3597
- $groupEl === null || $groupEl === void 0 ? void 0 : $groupEl.setAttribute(usedName, "" + computedValue.value);
3598
- } else if (name === 'clipPath') {
3599
- _this2.createOrUpdateClipPath(document, usedValue, $groupEl);
3600
- } else if (name === 'shadowColor' || name === 'shadowBlur' || name === 'shadowOffsetX' || name === 'shadowOffsetY') {
3601
- _this2.defElementManager.createOrUpdateShadow(object, $el, name);
3602
- } else if (name === 'filter') {
3603
- _this2.defElementManager.createOrUpdateFilter(object, $el, usedValue);
3604
- } else if (name === 'innerHTML') {
3605
- _this2.createOrUpdateInnerHTML(document, $el, usedValue);
3606
- } else if (name === 'anchor') {
3607
- // text' anchor is controlled by `textAnchor` property
3608
- if (object.nodeName !== g.Shape.TEXT) {
3609
- _this2.updateAnchorWithTransform(object);
3610
- }
3611
- } else {
3612
- if (computedValue) {
3613
- // use computed value so that we can use cascaded effect in SVG
3614
- var valueStr = computedValue.toString(); // ignore 'unset' and default value
3615
-
3616
- [$el, $hitTestingEl].forEach(function ($el) {
3617
- if ($el && usedName) {
3618
- if (valueStr !== 'unset' && valueStr !== DEFAULT_VALUE_MAP[name]) {
3619
- var _FORMAT_VALUE_MAP$nam;
3620
-
3621
- var formattedValueStr = ((_FORMAT_VALUE_MAP$nam = FORMAT_VALUE_MAP[name]) === null || _FORMAT_VALUE_MAP$nam === void 0 ? void 0 : _FORMAT_VALUE_MAP$nam[valueStr]) || valueStr;
3622
- $el.setAttribute(usedName, formattedValueStr);
3623
- } else {
3624
- $el.removeAttribute(usedName);
3877
+ if (computedValue) {
3878
+ // use computed value so that we can use cascaded effect in SVG
3879
+ var valueStr = computedValue.toString(); // ignore 'unset' and default value
3880
+
3881
+ [$el, $hitTestingEl].forEach(function ($el) {
3882
+ if ($el && usedName) {
3883
+ if (valueStr !== 'unset' && valueStr !== DEFAULT_VALUE_MAP[name]) {
3884
+ var _FORMAT_VALUE_MAP$nam;
3885
+
3886
+ var formattedValueStr = ((_FORMAT_VALUE_MAP$nam = FORMAT_VALUE_MAP[name]) === null || _FORMAT_VALUE_MAP$nam === void 0 ? void 0 : _FORMAT_VALUE_MAP$nam[valueStr]) || valueStr;
3887
+ $el.setAttribute(usedName, formattedValueStr);
3888
+ } else {
3889
+ $el.removeAttribute(usedName);
3890
+ }
3625
3891
  }
3626
- }
3627
- });
3892
+ });
3893
+ }
3628
3894
  }
3629
- }
3630
- });
3631
- };
3632
-
3633
- _proto.createSVGDom = function createSVGDom(document, object, root, noWrapWithGroup) {
3634
- if (noWrapWithGroup === void 0) {
3635
- noWrapWithGroup = false;
3636
- } // create svg element
3637
- // @ts-ignore
3638
-
3895
+ });
3896
+ }
3897
+ }, {
3898
+ key: "createSVGDom",
3899
+ value: function createSVGDom(document, object, root) {
3900
+ var noWrapWithGroup = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false; // create svg element
3901
+ // @ts-ignore
3639
3902
 
3640
- object.elementSVG = new ElementSVG(); // @ts-ignore
3903
+ object.elementSVG = new ElementSVG(); // @ts-ignore
3641
3904
 
3642
- var svgElement = object.elementSVG; // use <group> as default, eg. CustomElement
3905
+ var svgElement = object.elementSVG; // use <group> as default, eg. CustomElement
3643
3906
 
3644
- var $el = this.createElementContribution.createElement(object);
3907
+ var $el = this.createElementContribution.createElement(object);
3645
3908
 
3646
- if ($el) {
3647
- var _object$parentNode$el2;
3909
+ if ($el) {
3910
+ var _object$parentNode$el2;
3648
3911
 
3649
- var $groupEl; // save $el on parsedStyle, which will be returned in getDomElement()
3912
+ var $groupEl; // save $el on parsedStyle, which will be returned in getDomElement()
3650
3913
 
3651
- if (object.nodeName === g.Shape.HTML) {
3652
- object.parsedStyle.$el = $el;
3653
- }
3914
+ if (object.nodeName === g.Shape.HTML) {
3915
+ object.parsedStyle.$el = $el;
3916
+ }
3654
3917
 
3655
- $el.id = G_SVG_PREFIX + "_" + object.nodeName + "_" + object.entity;
3918
+ $el.id = "".concat(G_SVG_PREFIX, "_").concat(object.nodeName, "_").concat(object.entity);
3656
3919
 
3657
- if (($el.hasAttribute('data-wrapgroup') || $el.nodeName !== 'g') && !noWrapWithGroup) {
3658
- $groupEl = createSVGElement('g', document);
3659
- $groupEl.appendChild($el);
3660
- } else {
3661
- $groupEl = $el;
3662
- }
3920
+ if (($el.hasAttribute('data-wrapgroup') || $el.nodeName !== 'g') && !noWrapWithGroup) {
3921
+ $groupEl = createSVGElement('g', document);
3922
+ $groupEl.appendChild($el);
3923
+ } else {
3924
+ $groupEl = $el;
3925
+ }
3663
3926
 
3664
- svgElement.$el = $el;
3665
- svgElement.$groupEl = $groupEl; // apply attributes at first time
3927
+ svgElement.$el = $el;
3928
+ svgElement.$groupEl = $groupEl; // apply attributes at first time
3666
3929
 
3667
- this.applyAttributes(object); // create hitArea if necessary
3930
+ this.applyAttributes(object); // create hitArea if necessary
3668
3931
 
3669
- this.createOrUpdateHitArea(object, $el, $groupEl);
3670
- var $parentGroupEl = // @ts-ignore
3671
- object.parentNode && ((_object$parentNode$el2 = object.parentNode.elementSVG) === null || _object$parentNode$el2 === void 0 ? void 0 : _object$parentNode$el2.$groupEl) || root;
3932
+ this.createOrUpdateHitArea(object, $el, $groupEl);
3933
+ var $parentGroupEl = // @ts-ignore
3934
+ object.parentNode && ((_object$parentNode$el2 = object.parentNode.elementSVG) === null || _object$parentNode$el2 === void 0 ? void 0 : _object$parentNode$el2.$groupEl) || root;
3672
3935
 
3673
- if ($parentGroupEl) {
3674
- $parentGroupEl.appendChild($groupEl); // need reorder children later
3936
+ if ($parentGroupEl) {
3937
+ $parentGroupEl.appendChild($groupEl); // need reorder children later
3675
3938
 
3676
- this.pendingReorderQueue.add(object.parentNode);
3939
+ this.pendingReorderQueue.add(object.parentNode);
3940
+ }
3677
3941
  }
3678
3942
  }
3679
- };
3943
+ }, {
3944
+ key: "removeSVGDom",
3945
+ value: function removeSVGDom(object) {
3946
+ var _object$elementSVG6; // @ts-ignore
3680
3947
 
3681
- _proto.removeSVGDom = function removeSVGDom(object) {
3682
- var _object$elementSVG6; // @ts-ignore
3683
3948
 
3949
+ var $groupEl = (_object$elementSVG6 = object.elementSVG) === null || _object$elementSVG6 === void 0 ? void 0 : _object$elementSVG6.$groupEl;
3684
3950
 
3685
- var $groupEl = (_object$elementSVG6 = object.elementSVG) === null || _object$elementSVG6 === void 0 ? void 0 : _object$elementSVG6.$groupEl;
3686
-
3687
- if ($groupEl && $groupEl.parentNode) {
3688
- $groupEl.parentNode.removeChild($groupEl); // object.entity.removeComponent(ElementSVG, true);
3951
+ if ($groupEl && $groupEl.parentNode) {
3952
+ $groupEl.parentNode.removeChild($groupEl); // object.entity.removeComponent(ElementSVG, true);
3953
+ }
3689
3954
  }
3690
- };
3691
-
3692
- _proto.createOrUpdateHitArea = function createOrUpdateHitArea(object, $el, $groupEl) {
3693
- var _object$parsedStyle$i; // @ts-ignore
3955
+ }, {
3956
+ key: "createOrUpdateHitArea",
3957
+ value: function createOrUpdateHitArea(object, $el, $groupEl) {
3958
+ var _object$parsedStyle$i; // @ts-ignore
3694
3959
 
3695
3960
 
3696
- var svgElement = object.elementSVG;
3697
- var $hitTestingEl = svgElement.$hitTestingEl;
3698
- var increasedLineWidthForHitTesting = (_object$parsedStyle$i = object.parsedStyle.increasedLineWidthForHitTesting) === null || _object$parsedStyle$i === void 0 ? void 0 : _object$parsedStyle$i.value; // account for hitArea
3961
+ var svgElement = object.elementSVG;
3962
+ var $hitTestingEl = svgElement.$hitTestingEl;
3963
+ var increasedLineWidthForHitTesting = (_object$parsedStyle$i = object.parsedStyle.increasedLineWidthForHitTesting) === null || _object$parsedStyle$i === void 0 ? void 0 : _object$parsedStyle$i.value; // account for hitArea
3699
3964
 
3700
- if (increasedLineWidthForHitTesting) {
3701
- var _object$parsedStyle$l;
3965
+ if (increasedLineWidthForHitTesting) {
3966
+ var _object$parsedStyle$l;
3702
3967
 
3703
- if (!$hitTestingEl) {
3704
- $hitTestingEl = $el.cloneNode(); // use the entity suffix, so that `g-plugin-svg-picker` can extract
3968
+ if (!$hitTestingEl) {
3969
+ $hitTestingEl = $el.cloneNode(); // use the entity suffix, so that `g-plugin-svg-picker` can extract
3705
3970
 
3706
- $hitTestingEl.id = G_SVG_PREFIX + "_" + object.nodeName + "_hittesting_" + object.entity; // clear attributes like `filter` `font-size`
3971
+ $hitTestingEl.id = "".concat(G_SVG_PREFIX, "_").concat(object.nodeName, "_hittesting_").concat(object.entity); // clear attributes like `filter` `font-size`
3707
3972
 
3708
- ['filter'].forEach(function (attribute) {
3709
- $hitTestingEl.removeAttribute(attribute);
3710
- }); // hitArea should be 'transparent' but not 'none'
3973
+ ['filter'].forEach(function (attribute) {
3974
+ $hitTestingEl.removeAttribute(attribute);
3975
+ }); // hitArea should be 'transparent' but not 'none'
3711
3976
 
3712
- var hasFill = $el.getAttribute('fill') !== 'none';
3713
- $hitTestingEl.setAttribute('fill', hasFill ? 'transparent' : 'none');
3714
- $hitTestingEl.setAttribute('stroke', 'transparent');
3715
- $groupEl.appendChild($hitTestingEl);
3716
- svgElement.$hitTestingEl = $hitTestingEl;
3717
- } // increase interactive line width
3977
+ var hasFill = $el.getAttribute('fill') !== 'none';
3978
+ $hitTestingEl.setAttribute('fill', hasFill ? 'transparent' : 'none');
3979
+ $hitTestingEl.setAttribute('stroke', 'transparent');
3980
+ $groupEl.appendChild($hitTestingEl);
3981
+ svgElement.$hitTestingEl = $hitTestingEl;
3982
+ } // increase interactive line width
3718
3983
 
3719
3984
 
3720
- $hitTestingEl.setAttribute('stroke-width', "" + (increasedLineWidthForHitTesting + ((_object$parsedStyle$l = object.parsedStyle.lineWidth) === null || _object$parsedStyle$l === void 0 ? void 0 : _object$parsedStyle$l.value)));
3721
- } else {
3722
- if ($hitTestingEl) {
3723
- $groupEl.removeChild($hitTestingEl);
3724
- svgElement.$hitTestingEl = null;
3985
+ $hitTestingEl.setAttribute('stroke-width', "".concat(increasedLineWidthForHitTesting + ((_object$parsedStyle$l = object.parsedStyle.lineWidth) === null || _object$parsedStyle$l === void 0 ? void 0 : _object$parsedStyle$l.value)));
3986
+ } else {
3987
+ if ($hitTestingEl) {
3988
+ $groupEl.removeChild($hitTestingEl);
3989
+ svgElement.$hitTestingEl = null;
3990
+ }
3725
3991
  }
3726
3992
  }
3727
- };
3993
+ }, {
3994
+ key: "createOrUpdateInnerHTML",
3995
+ value: function createOrUpdateInnerHTML(doc, $el, usedValue) {
3996
+ var $div = (doc || document).createElement('div');
3728
3997
 
3729
- _proto.createOrUpdateInnerHTML = function createOrUpdateInnerHTML(doc, $el, usedValue) {
3730
- var $div = (doc || document).createElement('div');
3998
+ if (typeof usedValue === 'string') {
3999
+ $div.innerHTML = usedValue;
4000
+ } else {
4001
+ $div.appendChild(usedValue);
4002
+ }
3731
4003
 
3732
- if (typeof usedValue === 'string') {
3733
- $div.innerHTML = usedValue;
3734
- } else {
3735
- $div.appendChild(usedValue);
4004
+ $el.innerHTML = '';
4005
+ $el.appendChild($div);
3736
4006
  }
4007
+ }, {
4008
+ key: "createOrUpdateClipPath",
4009
+ value: function createOrUpdateClipPath(document, clipPath, $groupEl) {
4010
+ if (clipPath) {
4011
+ var _clipPath$elementSVG;
3737
4012
 
3738
- $el.innerHTML = '';
3739
- $el.appendChild($div);
3740
- };
3741
-
3742
- _proto.createOrUpdateClipPath = function createOrUpdateClipPath(document, clipPath, $groupEl) {
3743
- if (clipPath) {
3744
- var _clipPath$elementSVG;
3745
-
3746
- var clipPathId = CLIP_PATH_PREFIX + clipPath.entity;
3747
- var $def = this.defElementManager.getDefElement();
3748
- var existed = $def.querySelector("#" + clipPathId);
4013
+ var clipPathId = CLIP_PATH_PREFIX + clipPath.entity;
4014
+ var $def = this.defElementManager.getDefElement();
4015
+ var existed = $def.querySelector("#".concat(clipPathId));
3749
4016
 
3750
- if (!existed) {
3751
- // create <clipPath> dom node, append it to <defs>
3752
- var $clipPath = createSVGElement('clipPath', document);
3753
- $clipPath.id = clipPathId;
3754
- $def.appendChild($clipPath); // <clipPath><circle /></clipPath>
4017
+ if (!existed) {
4018
+ // create <clipPath> dom node, append it to <defs>
4019
+ var $clipPath = createSVGElement('clipPath', document);
4020
+ $clipPath.id = clipPathId;
4021
+ $def.appendChild($clipPath); // <clipPath><circle /></clipPath>
3755
4022
 
3756
- this.createSVGDom(document, clipPath, $clipPath, true); // @ts-ignore
4023
+ this.createSVGDom(document, clipPath, $clipPath, true); // @ts-ignore
3757
4024
 
3758
- clipPath.elementSVG.$groupEl = $clipPath;
3759
- } // @ts-ignore
4025
+ clipPath.elementSVG.$groupEl = $clipPath;
4026
+ } // @ts-ignore
3760
4027
 
3761
4028
 
3762
- var $clipPathGroupEl = (_clipPath$elementSVG = clipPath.elementSVG) === null || _clipPath$elementSVG === void 0 ? void 0 : _clipPath$elementSVG.$groupEl;
4029
+ var $clipPathGroupEl = (_clipPath$elementSVG = clipPath.elementSVG) === null || _clipPath$elementSVG === void 0 ? void 0 : _clipPath$elementSVG.$groupEl;
3763
4030
 
3764
- if ($clipPathGroupEl) {
3765
- // apply local RTS transformation to <group> wrapper
3766
- this.applyTransform($clipPathGroupEl, clipPath.getLocalTransform());
3767
- } // apply attributes
4031
+ if ($clipPathGroupEl) {
4032
+ // apply local RTS transformation to <group> wrapper
4033
+ this.applyTransform($clipPathGroupEl, clipPath.getLocalTransform());
4034
+ } // apply attributes
3768
4035
 
3769
4036
 
3770
- this.applyAttributes(clipPath); // apply clipPath to $group
3771
- // @see https://github.com/antvis/g/issues/961
4037
+ this.applyAttributes(clipPath); // apply clipPath to $group
4038
+ // @see https://github.com/antvis/g/issues/961
3772
4039
 
3773
- $groupEl.setAttribute('clip-path', "url(#" + clipPathId + ")");
3774
- } else {
3775
- // remove clip path
3776
- $groupEl.removeAttribute('clip-path');
4040
+ $groupEl.setAttribute('clip-path', "url(#".concat(clipPathId, ")"));
4041
+ } else {
4042
+ // remove clip path
4043
+ $groupEl.removeAttribute('clip-path');
4044
+ }
3777
4045
  }
3778
- }
3779
- /**
3780
- * the origin is bounding box's top left corner
3781
- */
3782
- ;
4046
+ /**
4047
+ * the origin is bounding box's top left corner
4048
+ */
3783
4049
 
3784
- _proto.updateAnchorWithTransform = function updateAnchorWithTransform(object) {
3785
- var _object$elementSVG7, _object$elementSVG8;
4050
+ }, {
4051
+ key: "updateAnchorWithTransform",
4052
+ value: function updateAnchorWithTransform(object) {
4053
+ var _object$elementSVG7, _object$elementSVG8;
3786
4054
 
3787
- var bounds = object.getGeometryBounds();
3788
- var width = bounds && bounds.halfExtents[0] * 2 || 0;
3789
- var height = bounds && bounds.halfExtents[1] * 2 || 0;
4055
+ var bounds = object.getGeometryBounds();
4056
+ var width = bounds && bounds.halfExtents[0] * 2 || 0;
4057
+ var height = bounds && bounds.halfExtents[1] * 2 || 0;
3790
4058
 
3791
- var _ref2 = object.parsedStyle || {},
3792
- anchor = _ref2.anchor; // @ts-ignore
4059
+ var _ref2 = object.parsedStyle || {},
4060
+ anchor = _ref2.anchor; // @ts-ignore
3793
4061
 
3794
4062
 
3795
- [(_object$elementSVG7 = object.elementSVG) === null || _object$elementSVG7 === void 0 ? void 0 : _object$elementSVG7.$el, (_object$elementSVG8 = object.elementSVG) === null || _object$elementSVG8 === void 0 ? void 0 : _object$elementSVG8.$hitTestingEl].forEach(function ($el) {
3796
- if ($el) {
3797
- if (anchor[0].value !== 0 || anchor[1].value !== 0) {
3798
- // apply anchor to element's `transform` property
3799
- $el.setAttribute('transform', // can't use percent unit like translate(-50%, -50%)
3800
- // @see https://developer.mozilla.org/zh-CN/docs/Web/SVG/Attribute/transform#translate
3801
- "translate(-" + anchor[0].value * width + ",-" + anchor[1].value * height + ")");
3802
- }
4063
+ [(_object$elementSVG7 = object.elementSVG) === null || _object$elementSVG7 === void 0 ? void 0 : _object$elementSVG7.$el, (_object$elementSVG8 = object.elementSVG) === null || _object$elementSVG8 === void 0 ? void 0 : _object$elementSVG8.$hitTestingEl].forEach(function ($el) {
4064
+ if ($el) {
4065
+ if (anchor[0].value !== 0 || anchor[1].value !== 0) {
4066
+ // apply anchor to element's `transform` property
4067
+ $el.setAttribute('transform', // can't use percent unit like translate(-50%, -50%)
4068
+ // @see https://developer.mozilla.org/zh-CN/docs/Web/SVG/Attribute/transform#translate
4069
+ "translate(-".concat(anchor[0].value * width, ",-").concat(anchor[1].value * height, ")"));
4070
+ }
3803
4071
 
3804
- if (object.nodeName === g.Shape.CIRCLE || object.nodeName === g.Shape.ELLIPSE) {
3805
- $el.setAttribute('cx', "" + width / 2);
3806
- $el.setAttribute('cy', "" + height / 2);
4072
+ if (object.nodeName === g.Shape.CIRCLE || object.nodeName === g.Shape.ELLIPSE) {
4073
+ $el.setAttribute('cx', "".concat(width / 2));
4074
+ $el.setAttribute('cy', "".concat(height / 2));
4075
+ }
3807
4076
  }
3808
- }
3809
- });
3810
- };
4077
+ });
4078
+ }
4079
+ }]);
3811
4080
 
3812
4081
  return SVGRendererPlugin;
3813
4082
  }(), _class$1.tag = 'SVGRenderer', _class$1);
@@ -3835,18 +4104,22 @@
3835
4104
 
3836
4105
  var Plugin$1 = /*#__PURE__*/function () {
3837
4106
  function Plugin() {
4107
+ _classCallCheck$2(this, Plugin);
4108
+
3838
4109
  this.name = 'svg-renderer';
3839
4110
  }
3840
4111
 
3841
- var _proto = Plugin.prototype;
3842
-
3843
- _proto.init = function init(container) {
3844
- container.load(containerModule$1, true);
3845
- };
3846
-
3847
- _proto.destroy = function destroy(container) {
3848
- container.unload(containerModule$1);
3849
- };
4112
+ _createClass$2(Plugin, [{
4113
+ key: "init",
4114
+ value: function init(container) {
4115
+ container.load(containerModule$1, true);
4116
+ }
4117
+ }, {
4118
+ key: "destroy",
4119
+ value: function destroy(container) {
4120
+ container.unload(containerModule$1);
4121
+ }
4122
+ }]);
3850
4123
 
3851
4124
  return Plugin;
3852
4125
  }();
@@ -3998,7 +4271,7 @@
3998
4271
  if ("throw" !== record.type) {
3999
4272
  var result = record.arg,
4000
4273
  value = result.value;
4001
- return value && "object" == typeof value && hasOwn.call(value, "__await") ? PromiseImpl.resolve(value.__await).then(function (value) {
4274
+ return value && "object" == _typeof(value) && hasOwn.call(value, "__await") ? PromiseImpl.resolve(value.__await).then(function (value) {
4002
4275
  invoke("next", value, resolve, reject);
4003
4276
  }, function (err) {
4004
4277
  invoke("throw", err, resolve, reject);
@@ -4259,16 +4532,41 @@
4259
4532
  };
4260
4533
  }
4261
4534
 
4262
- function _unsupportedIterableToArray(o, minLen) {
4535
+ function _classCallCheck$3(instance, Constructor) {
4536
+ if (!(instance instanceof Constructor)) {
4537
+ throw new TypeError("Cannot call a class as a function");
4538
+ }
4539
+ }
4540
+
4541
+ function _defineProperties$3(target, props) {
4542
+ for (var i = 0; i < props.length; i++) {
4543
+ var descriptor = props[i];
4544
+ descriptor.enumerable = descriptor.enumerable || false;
4545
+ descriptor.configurable = true;
4546
+ if ("value" in descriptor) descriptor.writable = true;
4547
+ Object.defineProperty(target, descriptor.key, descriptor);
4548
+ }
4549
+ }
4550
+
4551
+ function _createClass$3(Constructor, protoProps, staticProps) {
4552
+ if (protoProps) _defineProperties$3(Constructor.prototype, protoProps);
4553
+ if (staticProps) _defineProperties$3(Constructor, staticProps);
4554
+ Object.defineProperty(Constructor, "prototype", {
4555
+ writable: false
4556
+ });
4557
+ return Constructor;
4558
+ }
4559
+
4560
+ function _unsupportedIterableToArray$1(o, minLen) {
4263
4561
  if (!o) return;
4264
- if (typeof o === "string") return _arrayLikeToArray(o, minLen);
4562
+ if (typeof o === "string") return _arrayLikeToArray$1(o, minLen);
4265
4563
  var n = Object.prototype.toString.call(o).slice(8, -1);
4266
4564
  if (n === "Object" && o.constructor) n = o.constructor.name;
4267
4565
  if (n === "Map" || n === "Set") return Array.from(o);
4268
- if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
4566
+ if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray$1(o, minLen);
4269
4567
  }
4270
4568
 
4271
- function _arrayLikeToArray(arr, len) {
4569
+ function _arrayLikeToArray$1(arr, len) {
4272
4570
  if (len == null || len > arr.length) len = arr.length;
4273
4571
 
4274
4572
  for (var i = 0, arr2 = new Array(len); i < len; i++) {
@@ -4278,25 +4576,61 @@
4278
4576
  return arr2;
4279
4577
  }
4280
4578
 
4281
- function _createForOfIteratorHelperLoose(o, allowArrayLike) {
4579
+ function _createForOfIteratorHelper(o, allowArrayLike) {
4282
4580
  var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"];
4283
- if (it) return (it = it.call(o)).next.bind(it);
4284
4581
 
4285
- if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") {
4286
- if (it) o = it;
4287
- var i = 0;
4288
- return function () {
4289
- if (i >= o.length) return {
4290
- done: true
4291
- };
4582
+ if (!it) {
4583
+ if (Array.isArray(o) || (it = _unsupportedIterableToArray$1(o)) || allowArrayLike && o && typeof o.length === "number") {
4584
+ if (it) o = it;
4585
+ var i = 0;
4586
+
4587
+ var F = function F() {};
4588
+
4292
4589
  return {
4293
- done: false,
4294
- value: o[i++]
4590
+ s: F,
4591
+ n: function n() {
4592
+ if (i >= o.length) return {
4593
+ done: true
4594
+ };
4595
+ return {
4596
+ done: false,
4597
+ value: o[i++]
4598
+ };
4599
+ },
4600
+ e: function e(_e) {
4601
+ throw _e;
4602
+ },
4603
+ f: F
4295
4604
  };
4296
- };
4605
+ }
4606
+
4607
+ throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
4297
4608
  }
4298
4609
 
4299
- throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
4610
+ var normalCompletion = true,
4611
+ didErr = false,
4612
+ err;
4613
+ return {
4614
+ s: function s() {
4615
+ it = it.call(o);
4616
+ },
4617
+ n: function n() {
4618
+ var step = it.next();
4619
+ normalCompletion = step.done;
4620
+ return step;
4621
+ },
4622
+ e: function e(_e2) {
4623
+ didErr = true;
4624
+ err = _e2;
4625
+ },
4626
+ f: function f() {
4627
+ try {
4628
+ if (!normalCompletion && it.return != null) it.return();
4629
+ } finally {
4630
+ if (didErr) throw err;
4631
+ }
4632
+ }
4633
+ };
4300
4634
  }
4301
4635
 
4302
4636
  var _class$2;
@@ -4311,93 +4645,116 @@
4311
4645
 
4312
4646
  var SVGPickerPlugin = SVGPickerPlugin_1 = (_class$2 = /*#__PURE__*/function () {
4313
4647
  function SVGPickerPlugin() {
4648
+ _classCallCheck$3(this, SVGPickerPlugin);
4649
+
4314
4650
  this.canvasConfig = void 0;
4315
4651
  this.displayObjectPool = void 0;
4316
4652
  }
4317
4653
 
4318
- var _proto = SVGPickerPlugin.prototype;
4654
+ _createClass$3(SVGPickerPlugin, [{
4655
+ key: "apply",
4656
+ value: function apply(renderingService) {
4657
+ var _this = this;
4319
4658
 
4320
- _proto.apply = function apply(renderingService) {
4321
- var _this = this;
4659
+ var doc = this.canvasConfig.document;
4660
+ renderingService.hooks.pick.tapPromise(SVGPickerPlugin_1.tag, /*#__PURE__*/function () {
4661
+ var _ref = _asyncToGenerator$3( /*#__PURE__*/_regeneratorRuntime$3().mark(function _callee(result) {
4662
+ var topmost, _result$position, clientX, clientY, targets, _iterator, _step, element, id, index, target;
4322
4663
 
4323
- var doc = this.canvasConfig.document;
4324
- renderingService.hooks.pick.tapPromise(SVGPickerPlugin_1.tag, /*#__PURE__*/function () {
4325
- var _ref = _asyncToGenerator$3( /*#__PURE__*/_regeneratorRuntime$3().mark(function _callee(result) {
4326
- var topmost, _result$position, clientX, clientY, targets, _iterator, _step, element, id, index, target;
4664
+ return _regeneratorRuntime$3().wrap(function _callee$(_context) {
4665
+ while (1) {
4666
+ switch (_context.prev = _context.next) {
4667
+ case 0:
4668
+ topmost = result.topmost, _result$position = result.position, clientX = _result$position.clientX, clientY = _result$position.clientY;
4669
+ _context.prev = 1;
4670
+ targets = []; // @see https://developer.mozilla.org/zh-CN/docs/Web/API/Document/elementsFromPoint
4327
4671
 
4328
- return _regeneratorRuntime$3().wrap(function _callee$(_context) {
4329
- while (1) {
4330
- switch (_context.prev = _context.next) {
4331
- case 0:
4332
- topmost = result.topmost, _result$position = result.position, clientX = _result$position.clientX, clientY = _result$position.clientY;
4333
- _context.prev = 1;
4334
- targets = []; // @see https://developer.mozilla.org/zh-CN/docs/Web/API/Document/elementsFromPoint
4672
+ _iterator = _createForOfIteratorHelper((doc || document).elementsFromPoint(clientX, clientY));
4673
+ _context.prev = 4;
4335
4674
 
4336
- _iterator = _createForOfIteratorHelperLoose((doc || document).elementsFromPoint(clientX, clientY));
4675
+ _iterator.s();
4337
4676
 
4338
- case 4:
4339
- if ((_step = _iterator()).done) {
4340
- _context.next = 17;
4341
- break;
4342
- }
4677
+ case 6:
4678
+ if ((_step = _iterator.n()).done) {
4679
+ _context.next = 19;
4680
+ break;
4681
+ }
4343
4682
 
4344
- element = _step.value; // eg. g_svg_circle_345
4683
+ element = _step.value; // eg. g_svg_circle_345
4345
4684
 
4346
- id = element && element.getAttribute('id');
4685
+ id = element && element.getAttribute('id');
4347
4686
 
4348
- if (!(id && id.startsWith(G_SVG_PREFIX))) {
4349
- _context.next = 15;
4350
- break;
4351
- }
4687
+ if (!(id && id.startsWith(G_SVG_PREFIX))) {
4688
+ _context.next = 17;
4689
+ break;
4690
+ }
4352
4691
 
4353
- index = id.lastIndexOf('_');
4354
- target = _this.displayObjectPool.getByEntity(Number(id.substring(index + 1))); // don't need to account for `visibility` since DOM API already does
4692
+ index = id.lastIndexOf('_');
4693
+ target = _this.displayObjectPool.getByEntity(Number(id.substring(index + 1))); // don't need to account for `visibility` since DOM API already does
4355
4694
 
4356
- if (!(target && target.isInteractive())) {
4357
- _context.next = 15;
4358
- break;
4359
- }
4695
+ if (!(target && target.isInteractive())) {
4696
+ _context.next = 17;
4697
+ break;
4698
+ }
4699
+
4700
+ targets.push(target);
4360
4701
 
4361
- targets.push(target);
4702
+ if (!topmost) {
4703
+ _context.next = 17;
4704
+ break;
4705
+ }
4362
4706
 
4363
- if (!topmost) {
4364
- _context.next = 15;
4707
+ result.picked = targets;
4708
+ return _context.abrupt("return", result);
4709
+
4710
+ case 17:
4711
+ _context.next = 6;
4365
4712
  break;
4366
- }
4367
4713
 
4368
- result.picked = targets;
4369
- return _context.abrupt("return", result);
4714
+ case 19:
4715
+ _context.next = 24;
4716
+ break;
4370
4717
 
4371
- case 15:
4372
- _context.next = 4;
4373
- break;
4718
+ case 21:
4719
+ _context.prev = 21;
4720
+ _context.t0 = _context["catch"](4);
4374
4721
 
4375
- case 17:
4376
- result.picked = targets;
4377
- _context.next = 23;
4378
- break;
4722
+ _iterator.e(_context.t0);
4379
4723
 
4380
- case 20:
4381
- _context.prev = 20;
4382
- _context.t0 = _context["catch"](1);
4383
- result.picked = [];
4724
+ case 24:
4725
+ _context.prev = 24;
4384
4726
 
4385
- case 23:
4386
- return _context.abrupt("return", result);
4727
+ _iterator.f();
4387
4728
 
4388
- case 24:
4389
- case "end":
4390
- return _context.stop();
4729
+ return _context.finish(24);
4730
+
4731
+ case 27:
4732
+ result.picked = targets;
4733
+ _context.next = 33;
4734
+ break;
4735
+
4736
+ case 30:
4737
+ _context.prev = 30;
4738
+ _context.t1 = _context["catch"](1);
4739
+ result.picked = [];
4740
+
4741
+ case 33:
4742
+ return _context.abrupt("return", result);
4743
+
4744
+ case 34:
4745
+ case "end":
4746
+ return _context.stop();
4747
+ }
4391
4748
  }
4392
- }
4393
- }, _callee, null, [[1, 20]]);
4394
- }));
4749
+ }, _callee, null, [[1, 30], [4, 21, 24, 27]]);
4750
+ }));
4395
4751
 
4396
- return function (_x) {
4397
- return _ref.apply(this, arguments);
4398
- };
4399
- }());
4400
- };
4752
+ return function (_x) {
4753
+ return _ref.apply(this, arguments);
4754
+ };
4755
+ }());
4756
+ }
4757
+ }]);
4401
4758
 
4402
4759
  return SVGPickerPlugin;
4403
4760
  }(), _class$2.tag = 'SVGPicker', _class$2);
@@ -4415,18 +4772,22 @@
4415
4772
 
4416
4773
  var Plugin$2 = /*#__PURE__*/function () {
4417
4774
  function Plugin() {
4775
+ _classCallCheck$3(this, Plugin);
4776
+
4418
4777
  this.name = 'svg-picker';
4419
4778
  }
4420
4779
 
4421
- var _proto = Plugin.prototype;
4422
-
4423
- _proto.init = function init(container) {
4424
- container.load(containerModule$2, true);
4425
- };
4426
-
4427
- _proto.destroy = function destroy(container) {
4428
- container.unload(containerModule$2);
4429
- };
4780
+ _createClass$3(Plugin, [{
4781
+ key: "init",
4782
+ value: function init(container) {
4783
+ container.load(containerModule$2, true);
4784
+ }
4785
+ }, {
4786
+ key: "destroy",
4787
+ value: function destroy(container) {
4788
+ container.unload(containerModule$2);
4789
+ }
4790
+ }]);
4430
4791
 
4431
4792
  return Plugin;
4432
4793
  }();
@@ -4438,95 +4799,105 @@
4438
4799
 
4439
4800
  var SVGContextService = /*#__PURE__*/function () {
4440
4801
  function SVGContextService() {
4802
+ _classCallCheck(this, SVGContextService);
4803
+
4441
4804
  this.$container = void 0;
4442
4805
  this.$namespace = void 0;
4443
4806
  this.dpr = void 0;
4444
4807
  this.canvasConfig = void 0;
4445
4808
  }
4446
4809
 
4447
- var _proto = SVGContextService.prototype;
4810
+ _createClass(SVGContextService, [{
4811
+ key: "init",
4812
+ value: function () {
4813
+ var _init = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
4814
+ var _this$canvasConfig, container, doc, $namespace, dpr;
4448
4815
 
4449
- _proto.init = /*#__PURE__*/function () {
4450
- var _init = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
4451
- var _this$canvasConfig, container, doc, $namespace, dpr;
4816
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
4817
+ while (1) {
4818
+ switch (_context.prev = _context.next) {
4819
+ case 0:
4820
+ _this$canvasConfig = this.canvasConfig, container = _this$canvasConfig.container, doc = _this$canvasConfig.document; // create container
4452
4821
 
4453
- return _regeneratorRuntime().wrap(function _callee$(_context) {
4454
- while (1) {
4455
- switch (_context.prev = _context.next) {
4456
- case 0:
4457
- _this$canvasConfig = this.canvasConfig, container = _this$canvasConfig.container, doc = _this$canvasConfig.document; // create container
4822
+ this.$container = g.isString(container) ? (doc || document).getElementById(container) : container;
4458
4823
 
4459
- this.$container = g.isString(container) ? (doc || document).getElementById(container) : container;
4824
+ if (this.$container) {
4825
+ if (!this.$container.style.position) {
4826
+ this.$container.style.position = 'relative';
4827
+ }
4460
4828
 
4461
- if (this.$container) {
4462
- if (!this.$container.style.position) {
4463
- this.$container.style.position = 'relative';
4829
+ $namespace = createSVGElement('svg', doc);
4830
+ $namespace.setAttribute('width', "".concat(this.canvasConfig.width));
4831
+ $namespace.setAttribute('height', "".concat(this.canvasConfig.height));
4832
+ this.$container.appendChild($namespace);
4833
+ this.$namespace = $namespace;
4464
4834
  }
4465
4835
 
4466
- $namespace = createSVGElement('svg', doc);
4467
- $namespace.setAttribute('width', "" + this.canvasConfig.width);
4468
- $namespace.setAttribute('height', "" + this.canvasConfig.height);
4469
- this.$container.appendChild($namespace);
4470
- this.$namespace = $namespace;
4471
- }
4472
-
4473
- dpr = window.devicePixelRatio || 1;
4474
- dpr = dpr >= 1 ? Math.ceil(dpr) : 1;
4475
- this.dpr = dpr;
4836
+ dpr = window.devicePixelRatio || 1;
4837
+ dpr = dpr >= 1 ? Math.ceil(dpr) : 1;
4838
+ this.dpr = dpr;
4476
4839
 
4477
- case 6:
4478
- case "end":
4479
- return _context.stop();
4840
+ case 6:
4841
+ case "end":
4842
+ return _context.stop();
4843
+ }
4480
4844
  }
4481
- }
4482
- }, _callee, this);
4483
- }));
4484
-
4485
- function init() {
4486
- return _init.apply(this, arguments);
4487
- }
4488
-
4489
- return init;
4490
- }() // @ts-ignore
4491
- ;
4492
-
4493
- _proto.getDomElement = function getDomElement() {
4494
- return this.$namespace;
4495
- };
4496
-
4497
- _proto.getContext = function getContext() {
4498
- return this.$namespace;
4499
- };
4500
-
4501
- _proto.getDPR = function getDPR() {
4502
- return this.dpr;
4503
- };
4845
+ }, _callee, this);
4846
+ }));
4504
4847
 
4505
- _proto.getBoundingClientRect = function getBoundingClientRect() {
4506
- var _this$$namespace;
4848
+ function init() {
4849
+ return _init.apply(this, arguments);
4850
+ }
4507
4851
 
4508
- return (_this$$namespace = this.$namespace) === null || _this$$namespace === void 0 ? void 0 : _this$$namespace.getBoundingClientRect();
4509
- };
4852
+ return init;
4853
+ }() // @ts-ignore
4510
4854
 
4511
- _proto.destroy = function destroy() {
4512
- // destroy context
4513
- if (this.$container && this.$namespace && this.$namespace.parentNode) {
4514
- this.$container.removeChild(this.$namespace);
4855
+ }, {
4856
+ key: "getDomElement",
4857
+ value: function getDomElement() {
4858
+ return this.$namespace;
4515
4859
  }
4516
- };
4517
-
4518
- _proto.resize = function resize(width, height) {
4519
- if (this.$namespace) {
4520
- this.$namespace.setAttribute('width', "" + width);
4521
- this.$namespace.setAttribute('height', "" + height);
4860
+ }, {
4861
+ key: "getContext",
4862
+ value: function getContext() {
4863
+ return this.$namespace;
4522
4864
  }
4523
- };
4865
+ }, {
4866
+ key: "getDPR",
4867
+ value: function getDPR() {
4868
+ return this.dpr;
4869
+ }
4870
+ }, {
4871
+ key: "getBoundingClientRect",
4872
+ value: function getBoundingClientRect() {
4873
+ var _this$$namespace;
4524
4874
 
4525
- _proto.applyCursorStyle = function applyCursorStyle(cursor) {
4526
- if (this.$container) {
4527
- this.$container.style.cursor = cursor;
4875
+ return (_this$$namespace = this.$namespace) === null || _this$$namespace === void 0 ? void 0 : _this$$namespace.getBoundingClientRect();
4528
4876
  }
4529
- };
4877
+ }, {
4878
+ key: "destroy",
4879
+ value: function destroy() {
4880
+ // destroy context
4881
+ if (this.$container && this.$namespace && this.$namespace.parentNode) {
4882
+ this.$container.removeChild(this.$namespace);
4883
+ }
4884
+ }
4885
+ }, {
4886
+ key: "resize",
4887
+ value: function resize(width, height) {
4888
+ if (this.$namespace) {
4889
+ this.$namespace.setAttribute('width', "".concat(width));
4890
+ this.$namespace.setAttribute('height', "".concat(height));
4891
+ }
4892
+ }
4893
+ }, {
4894
+ key: "applyCursorStyle",
4895
+ value: function applyCursorStyle(cursor) {
4896
+ if (this.$container) {
4897
+ this.$container.style.cursor = cursor;
4898
+ }
4899
+ }
4900
+ }]);
4530
4901
 
4531
4902
  return SVGContextService;
4532
4903
  }();
@@ -4545,29 +4916,37 @@
4545
4916
  });
4546
4917
  var ContextRegisterPlugin = /*#__PURE__*/function () {
4547
4918
  function ContextRegisterPlugin() {
4919
+ _classCallCheck(this, ContextRegisterPlugin);
4920
+
4548
4921
  this.name = 'svg-context-register';
4549
4922
  }
4550
4923
 
4551
- var _proto = ContextRegisterPlugin.prototype;
4552
-
4553
- _proto.init = function init(container) {
4554
- container.load(containerModule$3, true);
4555
- };
4556
-
4557
- _proto.destroy = function destroy(container) {
4558
- container.unload(containerModule$3);
4559
- };
4924
+ _createClass(ContextRegisterPlugin, [{
4925
+ key: "init",
4926
+ value: function init(container) {
4927
+ container.load(containerModule$3, true);
4928
+ }
4929
+ }, {
4930
+ key: "destroy",
4931
+ value: function destroy(container) {
4932
+ container.unload(containerModule$3);
4933
+ }
4934
+ }]);
4560
4935
 
4561
4936
  return ContextRegisterPlugin;
4562
4937
  }();
4563
4938
 
4564
4939
  var Renderer = /*#__PURE__*/function (_AbstractRenderer) {
4565
- _inheritsLoose(Renderer, _AbstractRenderer);
4940
+ _inherits(Renderer, _AbstractRenderer);
4941
+
4942
+ var _super = _createSuper(Renderer);
4566
4943
 
4567
4944
  function Renderer(config) {
4568
4945
  var _this;
4569
4946
 
4570
- _this = _AbstractRenderer.call(this, config) || this;
4947
+ _classCallCheck(this, Renderer);
4948
+
4949
+ _this = _super.call(this, config);
4571
4950
 
4572
4951
  _this.registerPlugin(new ContextRegisterPlugin());
4573
4952
 
@@ -4580,7 +4959,7 @@
4580
4959
  return _this;
4581
4960
  }
4582
4961
 
4583
- return Renderer;
4962
+ return _createClass(Renderer);
4584
4963
  }(g.AbstractRenderer);
4585
4964
 
4586
4965
  exports.DomInteraction = index_esm;