@antv/g-svg 1.2.1 → 1.3.0

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