@antv/g-svg 1.1.4 → 1.1.7

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
@@ -435,7 +435,6 @@
435
435
  var _class;
436
436
 
437
437
  var DOMInteractionPlugin_1;
438
- var MOBILE_REGEX = /mobile|tablet|ip(ad|hone|od)|android/i;
439
438
  /**
440
439
  * listen to mouse/touch/pointer events on DOM wrapper, trigger pointer events
441
440
  */
@@ -451,8 +450,7 @@
451
450
  _proto.apply = function apply(renderingService) {
452
451
  var _this = this;
453
452
 
454
- var canvas = this.renderingContext.root.ownerDocument.defaultView;
455
- var SUPPORT_ONLY_TOUCH = canvas.supportsTouchEvents && MOBILE_REGEX.test(navigator.userAgent);
453
+ var canvas = this.renderingContext.root.ownerDocument.defaultView; // const SUPPORT_ONLY_TOUCH = canvas.supportsTouchEvents && MOBILE_REGEX.test(navigator.userAgent);
456
454
 
457
455
  var onPointerMove = function onPointerMove(ev) {
458
456
  renderingService.hooks.pointerMove.call(ev);
@@ -836,165 +834,158 @@
836
834
 
837
835
  ElementSVG.tag = 'c-svg-element';
838
836
 
839
- var RectRenderer = /*#__PURE__*/function () {
840
- function RectRenderer() {
841
- this.dependencies = ['radius', 'width', 'height'];
842
- }
843
-
844
- var _proto = RectRenderer.prototype;
845
-
846
- _proto.apply = function apply($el, parsedStyle) {
847
- var radius = parsedStyle.radius,
848
- width = parsedStyle.width,
849
- height = parsedStyle.height;
850
- var hasRadius = radius && radius.some(function (r) {
851
- return r.value !== 0;
852
- });
853
- var d = '';
854
-
855
- if (!hasRadius) {
856
- d = "M 0,0 l " + width.value + ",0 l 0," + height.value + " l" + -width.value + " 0 z";
857
- } else {
858
- var _radius$map = radius.map(function (r) {
859
- return r.value;
860
- }),
861
- tlr = _radius$map[0],
862
- trr = _radius$map[1],
863
- brr = _radius$map[2],
864
- blr = _radius$map[3];
837
+ function updateImageElementAttribute($el, parsedStyle) {
838
+ var _parsedStyle$img = parsedStyle.img,
839
+ img = _parsedStyle$img === void 0 ? '' : _parsedStyle$img,
840
+ width = parsedStyle.width,
841
+ height = parsedStyle.height;
842
+ $el.setAttribute('x', '0');
843
+ $el.setAttribute('y', '0');
865
844
 
866
- d = [["M " + tlr + ",0"], ["l " + (width.value - tlr - trr) + ",0"], ["a " + trr + "," + trr + ",0,0,1," + trr + "," + trr], ["l 0," + (height.value - trr - brr)], ["a " + brr + "," + brr + ",0,0,1," + -brr + "," + brr], ["l " + (brr + blr - width.value) + ",0"], ["a " + blr + "," + blr + ",0,0,1," + -blr + "," + -blr], ["l 0," + (blr + tlr - height.value)], ["a " + tlr + "," + tlr + ",0,0,1," + tlr + "," + -tlr], ['z']].join(' ');
845
+ if (g.isString(img)) {
846
+ $el.setAttribute('href', img);
847
+ } else if (img instanceof Image) {
848
+ if (!width) {
849
+ $el.setAttribute('width', "" + img.width); // TODO: set renderable.boundsDirty
850
+ // this.attr('width', img.width);
867
851
  }
868
852
 
869
- $el.setAttribute('d', d);
870
- };
853
+ if (!height) {
854
+ $el.setAttribute('height', "" + img.height); // this.attr('height', img.height);
855
+ }
871
856
 
872
- return RectRenderer;
873
- }();
857
+ $el.setAttribute('href', img.src);
858
+ } else if ( // @ts-ignore
859
+ img instanceof HTMLElement && g.isString(img.nodeName) && img.nodeName.toUpperCase() === 'CANVAS') {
860
+ $el.setAttribute('href', img.toDataURL()); // @ts-ignore
861
+ } else if (img instanceof ImageData) {
862
+ var canvas = document.createElement('canvas'); // @ts-ignore
874
863
 
875
- RectRenderer = __decorate([manaSyringe.singleton()], RectRenderer);
864
+ canvas.setAttribute('width', "" + img.width); // @ts-ignore
876
865
 
877
- var ImageRenderer = /*#__PURE__*/function () {
878
- function ImageRenderer() {
879
- this.dependencies = ['img', 'width', 'height'];
880
- }
866
+ canvas.setAttribute('height', "" + img.height);
867
+ var context = canvas.getContext('2d');
881
868
 
882
- var _proto = ImageRenderer.prototype;
869
+ if (context) {
870
+ context.putImageData(img, 0, 0);
883
871
 
884
- _proto.apply = function apply($el, parsedStyle) {
885
- var _parsedStyle$img = parsedStyle.img,
886
- img = _parsedStyle$img === void 0 ? '' : _parsedStyle$img,
887
- width = parsedStyle.width,
888
- height = parsedStyle.height;
889
- $el.setAttribute('x', '0');
890
- $el.setAttribute('y', '0');
891
-
892
- if (g.isString(img)) {
893
- $el.setAttribute('href', img);
894
- } else if (img instanceof Image) {
895
872
  if (!width) {
896
- $el.setAttribute('width', "" + img.width); // TODO: set renderable.boundsDirty
897
- // this.attr('width', img.width);
873
+ // @ts-ignore
874
+ $el.setAttribute('width', "" + img.width); // this.attr('width', img.width);
898
875
  }
899
876
 
900
877
  if (!height) {
878
+ // @ts-ignore
901
879
  $el.setAttribute('height', "" + img.height); // this.attr('height', img.height);
902
880
  }
903
881
 
904
- $el.setAttribute('href', img.src);
905
- } else if ( // @ts-ignore
906
- img instanceof HTMLElement && g.isString(img.nodeName) && img.nodeName.toUpperCase() === 'CANVAS') {
907
- $el.setAttribute('href', img.toDataURL()); // @ts-ignore
908
- } else if (img instanceof ImageData) {
909
- var canvas = document.createElement('canvas'); // @ts-ignore
910
-
911
- canvas.setAttribute('width', "" + img.width); // @ts-ignore
912
-
913
- canvas.setAttribute('height', "" + img.height);
914
- var context = canvas.getContext('2d');
915
-
916
- if (context) {
917
- context.putImageData(img, 0, 0);
882
+ $el.setAttribute('href', canvas.toDataURL());
883
+ }
884
+ }
885
+ }
918
886
 
919
- if (!width) {
920
- // @ts-ignore
921
- $el.setAttribute('width', "" + img.width); // this.attr('width', img.width);
922
- }
887
+ function updateLineElementAttribute($el, parsedStyle) {
888
+ var x1 = parsedStyle.x1,
889
+ y1 = parsedStyle.y1,
890
+ x2 = parsedStyle.x2,
891
+ y2 = parsedStyle.y2,
892
+ _parsedStyle$defX = parsedStyle.defX,
893
+ x = _parsedStyle$defX === void 0 ? 0 : _parsedStyle$defX,
894
+ _parsedStyle$defY = parsedStyle.defY,
895
+ y = _parsedStyle$defY === void 0 ? 0 : _parsedStyle$defY,
896
+ stroke = parsedStyle.stroke;
897
+ $el.setAttribute('x1', "" + (x1.value - x));
898
+ $el.setAttribute('y1', "" + (y1.value - y));
899
+ $el.setAttribute('x2', "" + (x2.value - x)); // fix horizontal line stroke url bug in Chrome
900
+ // @see https://stackoverflow.com/questions/14680240/did-chrome-break-svg-stroke-url
901
+
902
+ if (y1.value === y2.value && stroke && !(stroke instanceof g.CSSRGB)) {
903
+ $el.setAttribute('y2', "" + (y2.value - y + 0.00001));
904
+ } else {
905
+ $el.setAttribute('y2', "" + (y2.value - y));
906
+ }
907
+ }
923
908
 
924
- if (!height) {
925
- // @ts-ignore
926
- $el.setAttribute('height', "" + img.height); // this.attr('height', img.height);
927
- }
909
+ function updatePathElementAttribute($el, parsedStyle) {
910
+ var path = parsedStyle.path,
911
+ _parsedStyle$defX = parsedStyle.defX,
912
+ x = _parsedStyle$defX === void 0 ? 0 : _parsedStyle$defX,
913
+ _parsedStyle$defY = parsedStyle.defY,
914
+ y = _parsedStyle$defY === void 0 ? 0 : _parsedStyle$defY;
915
+ $el.setAttribute('d', formatPath(path.absolutePath, x, y));
916
+ }
928
917
 
929
- $el.setAttribute('href', canvas.toDataURL());
930
- }
931
- }
932
- };
918
+ function formatPath(value, x, y) {
919
+ var newValue = value.map(function (params) {
920
+ var command = params[0];
933
921
 
934
- return ImageRenderer;
935
- }();
922
+ switch (command) {
923
+ case 'M':
924
+ return "M " + (params[1] - x) + "," + (params[2] - y);
936
925
 
937
- ImageRenderer = __decorate([manaSyringe.singleton()], ImageRenderer);
926
+ case 'L':
927
+ return "L " + (params[1] - x) + "," + (params[2] - y);
938
928
 
939
- var LineRenderer = /*#__PURE__*/function () {
940
- function LineRenderer() {
941
- this.dependencies = ['x1', 'y1', 'x2', 'y2'];
942
- }
929
+ case 'Q':
930
+ return "Q " + (params[1] - x) + " " + (params[2] - y) + "," + (params[3] - x) + " " + (params[4] - y);
943
931
 
944
- var _proto = LineRenderer.prototype;
932
+ case 'C':
933
+ return "C " + (params[1] - x) + " " + (params[2] - y) + "," + (params[3] - x) + " " + (params[4] - y) + "," + (params[5] - x) + " " + (params[6] - y);
945
934
 
946
- _proto.apply = function apply($el, parsedStyle) {
947
- var x1 = parsedStyle.x1,
948
- y1 = parsedStyle.y1,
949
- x2 = parsedStyle.x2,
950
- y2 = parsedStyle.y2,
951
- _parsedStyle$defX = parsedStyle.defX,
952
- x = _parsedStyle$defX === void 0 ? 0 : _parsedStyle$defX,
953
- _parsedStyle$defY = parsedStyle.defY,
954
- y = _parsedStyle$defY === void 0 ? 0 : _parsedStyle$defY,
955
- stroke = parsedStyle.stroke;
956
- $el.setAttribute('x1', "" + (x1.value - x));
957
- $el.setAttribute('y1', "" + (y1.value - y));
958
- $el.setAttribute('x2', "" + (x2.value - x)); // fix horizontal line stroke url bug in Chrome
959
- // @see https://stackoverflow.com/questions/14680240/did-chrome-break-svg-stroke-url
935
+ case 'A':
936
+ return "A " + params[1] + " " + params[2] + " " + params[3] + " " + params[4] + " " + params[5] + " " + (params[6] - x) + " " + (params[7] - y);
960
937
 
961
- if (y1.value === y2.value && stroke && !(stroke instanceof g.CSSRGB)) {
962
- $el.setAttribute('y2', "" + (y2.value - y + 0.00001));
963
- } else {
964
- $el.setAttribute('y2', "" + (y2.value - y));
938
+ case 'Z':
939
+ return 'Z';
965
940
  }
966
- };
941
+ }).join(' ');
967
942
 
968
- return LineRenderer;
969
- }();
943
+ if (~newValue.indexOf('NaN')) {
944
+ return '';
945
+ }
970
946
 
971
- LineRenderer = __decorate([manaSyringe.singleton()], LineRenderer);
947
+ return newValue;
948
+ }
972
949
 
973
- var PolylineRenderer = /*#__PURE__*/function () {
974
- function PolylineRenderer() {
975
- this.dependencies = ['points'];
976
- }
950
+ function updatePolylineElementAttribute($el, parsedStyle) {
951
+ var points = parsedStyle.points,
952
+ _parsedStyle$defX = parsedStyle.defX,
953
+ x = _parsedStyle$defX === void 0 ? 0 : _parsedStyle$defX,
954
+ _parsedStyle$defY = parsedStyle.defY,
955
+ y = _parsedStyle$defY === void 0 ? 0 : _parsedStyle$defY;
977
956
 
978
- var _proto = PolylineRenderer.prototype;
957
+ if (points && points.points && points.points.length >= 2) {
958
+ $el.setAttribute('points', points.points.map(function (point) {
959
+ return point[0] - x + "," + (point[1] - y);
960
+ }).join(' '));
961
+ }
962
+ }
979
963
 
980
- _proto.apply = function apply($el, parsedStyle) {
981
- var points = parsedStyle.points,
982
- _parsedStyle$defX = parsedStyle.defX,
983
- x = _parsedStyle$defX === void 0 ? 0 : _parsedStyle$defX,
984
- _parsedStyle$defY = parsedStyle.defY,
985
- y = _parsedStyle$defY === void 0 ? 0 : _parsedStyle$defY;
964
+ function updateRectElementAttribute($el, parsedStyle) {
965
+ var radius = parsedStyle.radius,
966
+ width = parsedStyle.width,
967
+ height = parsedStyle.height;
968
+ var hasRadius = radius && radius.some(function (r) {
969
+ return r.value !== 0;
970
+ });
971
+ var d = '';
986
972
 
987
- if (points && points.points && points.points.length >= 2) {
988
- $el.setAttribute('points', points.points.map(function (point) {
989
- return point[0] - x + "," + (point[1] - y);
990
- }).join(' '));
991
- }
992
- };
973
+ if (!hasRadius) {
974
+ d = "M 0,0 l " + width.value + ",0 l 0," + height.value + " l" + -width.value + " 0 z";
975
+ } else {
976
+ var _radius$map = radius.map(function (r) {
977
+ return r.value;
978
+ }),
979
+ tlr = _radius$map[0],
980
+ trr = _radius$map[1],
981
+ brr = _radius$map[2],
982
+ blr = _radius$map[3];
993
983
 
994
- return PolylineRenderer;
995
- }();
984
+ d = [["M " + tlr + ",0"], ["l " + (width.value - tlr - trr) + ",0"], ["a " + trr + "," + trr + ",0,0,1," + trr + "," + trr], ["l 0," + (height.value - trr - brr)], ["a " + brr + "," + brr + ",0,0,1," + -brr + "," + brr], ["l " + (brr + blr - width.value) + ",0"], ["a " + blr + "," + blr + ",0,0,1," + -blr + "," + -blr], ["l 0," + (blr + tlr - height.value)], ["a " + tlr + "," + tlr + ",0,0,1," + tlr + "," + -tlr], ['z']].join(' ');
985
+ }
996
986
 
997
- PolylineRenderer = __decorate([manaSyringe.singleton()], PolylineRenderer);
987
+ $el.setAttribute('d', d);
988
+ }
998
989
 
999
990
  function numberToLongString(x) {
1000
991
  return x.toFixed(6).replace('.000000', '');
@@ -1036,121 +1027,140 @@
1036
1027
  hanging: 'hanging'
1037
1028
  };
1038
1029
 
1039
- var TextRenderer = /*#__PURE__*/function () {
1040
- function TextRenderer() {
1041
- this.dependencies = ['text', 'font', 'fontSize', 'fontFamily', 'fontStyle', 'fontWeight', 'fontVariant', 'lineHeight', 'letterSpacing', 'wordWrap', 'wordWrapWidth', 'leading', 'textBaseline', 'textAlign', 'textTransform', 'whiteSpace', 'dx', 'dy'];
1030
+ function updateTextElementAttribute($el, parsedStyle) {
1031
+ var textBaseline = parsedStyle.textBaseline,
1032
+ lineWidth = parsedStyle.lineWidth,
1033
+ metrics = parsedStyle.metrics,
1034
+ dx = parsedStyle.dx,
1035
+ dy = parsedStyle.dy;
1036
+ var browser = detect();
1037
+
1038
+ if (browser && browser.name === 'firefox') {
1039
+ // compatible with FireFox browser, ref: https://github.com/antvis/g/issues/119
1040
+ $el.setAttribute('dominant-baseline', BASELINE_MAP_FOR_FIREFOX[textBaseline.value] || 'alphabetic');
1041
+ } else {
1042
+ $el.setAttribute('dominant-baseline', BASELINE_MAP_FOR_FIREFOX[textBaseline.value]);
1043
+ $el.setAttribute('alignment-baseline', BASELINE_MAP[textBaseline.value]);
1042
1044
  }
1043
1045
 
1044
- var _proto = TextRenderer.prototype;
1046
+ $el.setAttribute('paint-order', 'stroke');
1047
+ var lines = metrics.lines,
1048
+ lineHeight = metrics.lineHeight,
1049
+ height = metrics.height;
1050
+ var lineNum = lines.length;
1051
+ $el.setAttribute('style', "transform:translate(" + dx.toString() + ", " + dy.toString() + ");");
1045
1052
 
1046
- _proto.apply = function apply($el, parsedStyle) {
1047
- var textBaseline = parsedStyle.textBaseline,
1048
- lineWidth = parsedStyle.lineWidth,
1049
- metrics = parsedStyle.metrics,
1050
- dx = parsedStyle.dx,
1051
- dy = parsedStyle.dy;
1052
- var browser = detect();
1053
-
1054
- if (browser && browser.name === 'firefox') {
1055
- // compatible with FireFox browser, ref: https://github.com/antvis/g/issues/119
1056
- $el.setAttribute('dominant-baseline', BASELINE_MAP_FOR_FIREFOX[textBaseline.value] || 'alphabetic');
1057
- } else {
1058
- $el.setAttribute('dominant-baseline', BASELINE_MAP_FOR_FIREFOX[textBaseline.value]);
1059
- $el.setAttribute('alignment-baseline', BASELINE_MAP[textBaseline.value]);
1060
- }
1053
+ if (lineNum === 1) {
1054
+ $el.innerHTML = convertHTML(lines[0]);
1055
+ $el.setAttribute('dx', "" + lineWidth.value / 2);
1056
+ } else {
1057
+ $el.innerHTML = lines.map(function (line, i) {
1058
+ var dx = lineWidth.value / 2;
1059
+ var dy = 0;
1060
+
1061
+ if (i === 0) {
1062
+ // TODO: handle other textBaseline values
1063
+ if (textBaseline.value === 'middle') {
1064
+ dy = lineHeight / 2 - height / 2;
1065
+ } else if (textBaseline.value === 'top' || textBaseline.value === 'hanging') {
1066
+ dy = 0;
1067
+ } else if (textBaseline.value === 'bottom' || textBaseline.value === 'alphabetic' || textBaseline.value === 'ideographic') {
1068
+ dy = -lineHeight * (lineNum - 1);
1069
+ }
1070
+ } else {
1071
+ dy = lineHeight;
1072
+ }
1061
1073
 
1062
- $el.setAttribute('paint-order', 'stroke');
1063
- var lines = metrics.lines,
1064
- lineHeight = metrics.lineHeight,
1065
- height = metrics.height;
1066
- var lineNum = lines.length;
1067
- $el.setAttribute('style', "transform:translate(" + dx.toString() + ", " + dy.toString() + ");");
1074
+ return "<tspan x=\"0\" dx=\"" + dx + "\" dy=\"" + dy + "\">" + convertHTML(line) + "</tspan>";
1075
+ }).join('');
1076
+ }
1077
+ }
1068
1078
 
1069
- if (lineNum === 1) {
1070
- $el.innerHTML = convertHTML(lines[0]);
1071
- $el.setAttribute('dx', "" + lineWidth.value / 2);
1072
- } else {
1073
- $el.innerHTML = lines.map(function (line, i) {
1074
- var dx = lineWidth.value / 2;
1075
- var dy = 0;
1076
-
1077
- if (i === 0) {
1078
- // TODO: handle other textBaseline values
1079
- if (textBaseline.value === 'middle') {
1080
- dy = lineHeight / 2 - height / 2;
1081
- } else if (textBaseline.value === 'top' || textBaseline.value === 'hanging') {
1082
- dy = 0;
1083
- } else if (textBaseline.value === 'bottom' || textBaseline.value === 'alphabetic' || textBaseline.value === 'ideographic') {
1084
- dy = -lineHeight * (lineNum - 1);
1085
- }
1086
- } else {
1087
- dy = lineHeight;
1088
- }
1079
+ var CreateElementContribution = manaSyringe.Syringe.defineToken('CreateElementContribution', {
1080
+ multiple: false
1081
+ });
1089
1082
 
1090
- return "<tspan x=\"0\" dx=\"" + dx + "\" dy=\"" + dy + "\">" + convertHTML(line) + "</tspan>";
1091
- }).join('');
1092
- }
1093
- };
1083
+ function createSVGElement(type, doc) {
1084
+ return (doc || document).createElementNS('http://www.w3.org/2000/svg', type);
1085
+ }
1094
1086
 
1095
- return TextRenderer;
1096
- }();
1087
+ var _SHAPE2TAGS, _SHAPE_UPDATE_DEPS;
1097
1088
 
1098
- TextRenderer = __decorate([manaSyringe.singleton()], TextRenderer);
1089
+ 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);
1090
+ 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);
1099
1091
 
1100
- var PathRenderer = /*#__PURE__*/function () {
1101
- function PathRenderer() {
1102
- this.dependencies = ['path'];
1092
+ var DefaultCreateElementContribution = /*#__PURE__*/function () {
1093
+ function DefaultCreateElementContribution() {
1094
+ this.canvasConfig = void 0;
1103
1095
  }
1104
1096
 
1105
- var _proto = PathRenderer.prototype;
1097
+ var _proto = DefaultCreateElementContribution.prototype;
1106
1098
 
1107
- _proto.apply = function apply($el, parsedStyle) {
1108
- var path = parsedStyle.path,
1109
- _parsedStyle$defX = parsedStyle.defX,
1110
- x = _parsedStyle$defX === void 0 ? 0 : _parsedStyle$defX,
1111
- _parsedStyle$defY = parsedStyle.defY,
1112
- y = _parsedStyle$defY === void 0 ? 0 : _parsedStyle$defY;
1113
- $el.setAttribute('d', this.formatPath(path.absolutePath, x, y));
1099
+ _proto.createElement = function createElement(object) {
1100
+ var doc = this.canvasConfig.document;
1101
+ var type = SHAPE2TAGS[object.nodeName] || 'g';
1102
+ return createSVGElement(type, doc || document);
1114
1103
  };
1115
1104
 
1116
- _proto.formatPath = function formatPath(value, x, y) {
1117
- var newValue = value.map(function (params) {
1118
- var command = params[0];
1119
-
1120
- switch (command) {
1121
- case 'M':
1122
- return "M " + (params[1] - x) + "," + (params[2] - y);
1105
+ _proto.shouldUpdateElementAttribute = function shouldUpdateElementAttribute(object, attributeName) {
1106
+ var nodeName = object.nodeName;
1107
+ return (SHAPE_UPDATE_DEPS[nodeName] || []).indexOf(attributeName) > -1;
1108
+ };
1123
1109
 
1124
- case 'L':
1125
- return "L " + (params[1] - x) + "," + (params[2] - y);
1110
+ _proto.updateElementAttribute = function updateElementAttribute(object) {
1111
+ // @ts-ignore
1112
+ var $el = object.elementSVG.$el;
1113
+ var nodeName = object.nodeName,
1114
+ parsedStyle = object.parsedStyle;
1115
+
1116
+ switch (nodeName) {
1117
+ case g.Shape.IMAGE:
1118
+ {
1119
+ updateImageElementAttribute($el, parsedStyle);
1120
+ break;
1121
+ }
1126
1122
 
1127
- case 'Q':
1128
- return "Q " + (params[1] - x) + " " + (params[2] - y) + "," + (params[3] - x) + " " + (params[4] - y);
1123
+ case g.Shape.RECT:
1124
+ {
1125
+ updateRectElementAttribute($el, parsedStyle);
1126
+ break;
1127
+ }
1129
1128
 
1130
- case 'C':
1131
- return "C " + (params[1] - x) + " " + (params[2] - y) + "," + (params[3] - x) + " " + (params[4] - y) + "," + (params[5] - x) + " " + (params[6] - y);
1129
+ case g.Shape.LINE:
1130
+ {
1131
+ updateLineElementAttribute($el, parsedStyle);
1132
+ break;
1133
+ }
1132
1134
 
1133
- case 'A':
1134
- return "A " + params[1] + " " + params[2] + " " + params[3] + " " + params[4] + " " + params[5] + " " + (params[6] - x) + " " + (params[7] - y);
1135
+ case g.Shape.POLYGON:
1136
+ case g.Shape.POLYLINE:
1137
+ {
1138
+ updatePolylineElementAttribute($el, parsedStyle);
1139
+ break;
1140
+ }
1135
1141
 
1136
- case 'Z':
1137
- return 'Z';
1138
- }
1139
- }).join(' ');
1142
+ case g.Shape.PATH:
1143
+ {
1144
+ updatePathElementAttribute($el, parsedStyle);
1145
+ break;
1146
+ }
1140
1147
 
1141
- if (~newValue.indexOf('NaN')) {
1142
- return '';
1148
+ case g.Shape.TEXT:
1149
+ {
1150
+ updateTextElementAttribute($el, parsedStyle);
1151
+ break;
1152
+ }
1143
1153
  }
1144
-
1145
- return newValue;
1146
1154
  };
1147
1155
 
1148
- return PathRenderer;
1156
+ return DefaultCreateElementContribution;
1149
1157
  }();
1150
1158
 
1151
- PathRenderer = __decorate([manaSyringe.singleton()], PathRenderer);
1152
- var ElementRendererFactory = manaSyringe.Syringe.defineToken('ElementRendererFactory');
1153
- var ElementRenderer = manaSyringe.Syringe.defineToken('ElementRenderer');
1159
+ __decorate([manaSyringe.inject(g.CanvasConfig), __metadata("design:type", Object)], DefaultCreateElementContribution.prototype, "canvasConfig", void 0);
1160
+
1161
+ DefaultCreateElementContribution = __decorate([manaSyringe.singleton({
1162
+ token: CreateElementContribution
1163
+ })], DefaultCreateElementContribution);
1154
1164
 
1155
1165
  function _regeneratorRuntime$1() {
1156
1166
  /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */
@@ -2196,17 +2206,13 @@
2196
2206
  };
2197
2207
  }();
2198
2208
 
2199
- function createSVGElement(type) {
2200
- return document.createElementNS('http://www.w3.org/2000/svg', type);
2201
- }
2202
-
2203
2209
  var FILTER_PREFIX = 'g-filter-';
2204
2210
  /**
2205
2211
  * use SVG filters, eg. blur, brightness, contrast...
2206
2212
  * @see https://developer.mozilla.org/zh-CN/docs/Web/SVG/Element/filter
2207
2213
  */
2208
2214
 
2209
- function createOrUpdateFilter($def, object, $el, filters) {
2215
+ function createOrUpdateFilter(document, $def, object, $el, filters) {
2210
2216
  // eg. filter="url(#f1) url(#f2)"
2211
2217
  var filterName = FILTER_PREFIX + object.entity;
2212
2218
  var $existedFilters = $def.querySelectorAll("[name=" + filterName + "]");
@@ -2224,26 +2230,26 @@
2224
2230
  var filterIds = filters.map(function (_ref, i) {
2225
2231
  var name = _ref.name,
2226
2232
  params = _ref.params;
2227
- var $filter = createSVGElement('filter');
2233
+ var $filter = createSVGElement('filter', document);
2228
2234
 
2229
2235
  if (name === 'blur') {
2230
- createBlur($filter, params);
2236
+ createBlur(document, $filter, params);
2231
2237
  } else if (name === 'brightness') {
2232
- createBrightness($filter, params);
2238
+ createBrightness(document, $filter, params);
2233
2239
  } else if (name === 'drop-shadow') {
2234
- createDropShadow($filter, params);
2240
+ createDropShadow(document, $filter, params);
2235
2241
  } else if (name === 'contrast') {
2236
- createContrast($filter, params);
2242
+ createContrast(document, $filter, params);
2237
2243
  } else if (name === 'grayscale') {
2238
- createGrayscale($filter, params);
2244
+ createGrayscale(document, $filter, params);
2239
2245
  } else if (name === 'sepia') {
2240
- createSepia($filter, params);
2246
+ createSepia(document, $filter, params);
2241
2247
  } else if (name === 'saturate') {
2242
- createSaturate($filter, params);
2248
+ createSaturate(document, $filter, params);
2243
2249
  } else if (name === 'hue-rotate') {
2244
- createHueRotate($filter, params);
2250
+ createHueRotate(document, $filter, params);
2245
2251
  } else if (name === 'invert') {
2246
- createInvert($filter, params);
2252
+ createInvert(document, $filter, params);
2247
2253
  }
2248
2254
 
2249
2255
  $filter.id = filterName + "-" + i;
@@ -2265,20 +2271,20 @@
2265
2271
  */
2266
2272
 
2267
2273
 
2268
- function createBlur($filter, params) {
2269
- var $feGaussianBlur = createSVGElement('feGaussianBlur');
2274
+ function createBlur(document, $filter, params) {
2275
+ var $feGaussianBlur = createSVGElement('feGaussianBlur', document);
2270
2276
  $feGaussianBlur.setAttribute('in', 'SourceGraphic');
2271
2277
  $feGaussianBlur.setAttribute('stdDeviation', "" + params[0].value);
2272
2278
  $filter.appendChild($feGaussianBlur);
2273
2279
  }
2274
2280
 
2275
- function createFeComponentTransfer($filter, _ref2) {
2281
+ function createFeComponentTransfer(document, $filter, _ref2) {
2276
2282
  var type = _ref2.type,
2277
2283
  slope = _ref2.slope,
2278
2284
  intercept = _ref2.intercept,
2279
2285
  tableValues = _ref2.tableValues;
2280
- var $feComponentTransfer = createSVGElement('feComponentTransfer');
2281
- [createSVGElement('feFuncR'), createSVGElement('feFuncG'), createSVGElement('feFuncB')].forEach(function ($feFunc) {
2286
+ var $feComponentTransfer = createSVGElement('feComponentTransfer', document);
2287
+ [createSVGElement('feFuncR', document), createSVGElement('feFuncG', document), createSVGElement('feFuncB', document)].forEach(function ($feFunc) {
2282
2288
  $feFunc.setAttribute('type', type);
2283
2289
 
2284
2290
  if (type === 'table') {
@@ -2293,80 +2299,80 @@
2293
2299
  $filter.appendChild($feComponentTransfer);
2294
2300
  }
2295
2301
 
2296
- function createContrast($filter, params) {
2302
+ function createContrast(document, $filter, params) {
2297
2303
  var slope = convertToAbsoluteValue(params[0]);
2298
- createFeComponentTransfer($filter, {
2304
+ createFeComponentTransfer(document, $filter, {
2299
2305
  type: 'linear',
2300
2306
  slope: slope,
2301
2307
  intercept: -(0.5 * slope) + 0.5
2302
2308
  });
2303
2309
  }
2304
2310
 
2305
- function createInvert($filter, params) {
2311
+ function createInvert(document, $filter, params) {
2306
2312
  var amount = convertToAbsoluteValue(params[0]);
2307
- createFeComponentTransfer($filter, {
2313
+ createFeComponentTransfer(document, $filter, {
2308
2314
  type: 'table',
2309
2315
  tableValues: amount + " " + (1 - amount)
2310
2316
  });
2311
2317
  }
2312
2318
 
2313
- function createBrightness($filter, params) {
2319
+ function createBrightness(document, $filter, params) {
2314
2320
  var slope = convertToAbsoluteValue(params[0]);
2315
- createFeComponentTransfer($filter, {
2321
+ createFeComponentTransfer(document, $filter, {
2316
2322
  type: 'linear',
2317
2323
  slope: slope,
2318
2324
  intercept: 0
2319
2325
  });
2320
2326
  }
2321
2327
 
2322
- function createSaturate($filter, params) {
2328
+ function createSaturate(document, $filter, params) {
2323
2329
  var amount = convertToAbsoluteValue(params[0]);
2324
- var $feColorMatrix = createSVGElement('feColorMatrix');
2330
+ var $feColorMatrix = createSVGElement('feColorMatrix', document);
2325
2331
  $feColorMatrix.setAttribute('type', 'saturate');
2326
2332
  $feColorMatrix.setAttribute('values', "" + amount);
2327
2333
  $filter.appendChild($feColorMatrix);
2328
2334
  }
2329
2335
 
2330
- function createHueRotate($filter, params) {
2331
- var $feColorMatrix = createSVGElement('feColorMatrix');
2336
+ function createHueRotate(document, $filter, params) {
2337
+ var $feColorMatrix = createSVGElement('feColorMatrix', document);
2332
2338
  $feColorMatrix.setAttribute('type', 'hueRotate');
2333
2339
  $feColorMatrix.setAttribute('values', "" + params[0].to(g.UnitType.kDegrees).value);
2334
2340
  $filter.appendChild($feColorMatrix);
2335
2341
  }
2336
2342
 
2337
- function createDropShadow($filter, params) {
2343
+ function createDropShadow(document, $filter, params) {
2338
2344
  var shadowOffsetX = params[0].value;
2339
2345
  var shadowOffsetY = params[1].value;
2340
2346
  var shadowBlur = params[2].value; // @ts-ignore
2341
2347
 
2342
2348
  var shadowColor = params[3].formatted;
2343
- var $feGaussianBlur = createSVGElement('feGaussianBlur');
2349
+ var $feGaussianBlur = createSVGElement('feGaussianBlur', document);
2344
2350
  $feGaussianBlur.setAttribute('in', 'SourceAlpha');
2345
2351
  $feGaussianBlur.setAttribute('stdDeviation', "" + shadowBlur);
2346
2352
  $filter.appendChild($feGaussianBlur);
2347
- var $feOffset = createSVGElement('feOffset');
2353
+ var $feOffset = createSVGElement('feOffset', document);
2348
2354
  $feOffset.setAttribute('dx', "" + shadowOffsetX);
2349
2355
  $feOffset.setAttribute('dy', "" + shadowOffsetY);
2350
2356
  $feOffset.setAttribute('result', 'offsetblur');
2351
2357
  $filter.appendChild($feOffset);
2352
- var $feFlood = createSVGElement('feFlood');
2358
+ var $feFlood = createSVGElement('feFlood', document);
2353
2359
  $feFlood.setAttribute('flood-color', shadowColor);
2354
2360
  $filter.appendChild($feFlood);
2355
- var $feComposite = createSVGElement('feComposite');
2361
+ var $feComposite = createSVGElement('feComposite', document);
2356
2362
  $feComposite.setAttribute('in2', 'offsetblur');
2357
2363
  $feComposite.setAttribute('operator', 'in');
2358
2364
  $filter.appendChild($feComposite);
2359
- var $feMerge = createSVGElement('feMerge');
2365
+ var $feMerge = createSVGElement('feMerge', document);
2360
2366
  $filter.appendChild($feMerge);
2361
- var $feMergeNode1 = createSVGElement('feMergeNode');
2362
- var $feMergeNode2 = createSVGElement('feMergeNode');
2367
+ var $feMergeNode1 = createSVGElement('feMergeNode', document);
2368
+ var $feMergeNode2 = createSVGElement('feMergeNode', document);
2363
2369
  $feMergeNode2.setAttribute('in', 'SourceGraphic');
2364
2370
  $feMerge.appendChild($feMergeNode1);
2365
2371
  $feMerge.appendChild($feMergeNode2);
2366
2372
  }
2367
2373
 
2368
- function createFeColorMatrix($filter, matrix) {
2369
- var $feColorMatrix = createSVGElement('feColorMatrix');
2374
+ function createFeColorMatrix(document, $filter, matrix) {
2375
+ var $feColorMatrix = createSVGElement('feColorMatrix', document);
2370
2376
  $feColorMatrix.setAttribute('type', 'matrix');
2371
2377
  $feColorMatrix.setAttribute('values', matrix.join(' '));
2372
2378
  $filter.appendChild($feColorMatrix);
@@ -2376,24 +2382,24 @@
2376
2382
  */
2377
2383
 
2378
2384
 
2379
- function createGrayscale($filter, params) {
2385
+ function createGrayscale(document, $filter, params) {
2380
2386
  var amount = convertToAbsoluteValue(params[0]);
2381
- createFeColorMatrix($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]);
2387
+ 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]);
2382
2388
  }
2383
2389
  /**
2384
2390
  * @see https://drafts.fxtf.org/filter-effects/#sepiaEquivalent
2385
2391
  */
2386
2392
 
2387
2393
 
2388
- function createSepia($filter, params) {
2394
+ function createSepia(document, $filter, params) {
2389
2395
  var amount = convertToAbsoluteValue(params[0]);
2390
- createFeColorMatrix($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]);
2396
+ 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]);
2391
2397
  }
2392
2398
 
2393
2399
  var cacheKey2IDMap = {};
2394
2400
  var counter = 0;
2395
2401
 
2396
- function createOrUpdateGradientAndPattern($def, object, $el, parsedColor, name) {
2402
+ function createOrUpdateGradientAndPattern(document, $def, object, $el, parsedColor, name) {
2397
2403
  // eg. clipPath don't have fill/stroke
2398
2404
  if (!parsedColor) {
2399
2405
  return;
@@ -2413,13 +2419,13 @@
2413
2419
  } else {
2414
2420
  if (parsedColor.type === g.GradientPatternType.Pattern) {
2415
2421
  if (!existed) {
2416
- createPattern($def, parsedColor, gradientId);
2422
+ createPattern(document, $def, parsedColor, gradientId);
2417
2423
  }
2418
2424
 
2419
2425
  $el === null || $el === void 0 ? void 0 : $el.setAttribute(name, "url(#" + gradientId + ")");
2420
2426
  } else {
2421
2427
  if (!existed) {
2422
- createGradient($def, parsedColor, gradientId);
2428
+ createGradient(document, $def, parsedColor, gradientId);
2423
2429
  }
2424
2430
 
2425
2431
  $el === null || $el === void 0 ? void 0 : $el.setAttribute(name, "url(#" + gradientId + ")");
@@ -2460,12 +2466,12 @@
2460
2466
  return cacheKey2IDMap[cacheKey];
2461
2467
  }
2462
2468
 
2463
- function createPattern($def, parsedColor, patternId) {
2469
+ function createPattern(document, $def, parsedColor, patternId) {
2464
2470
  var src = parsedColor.value.src; // @see https://developer.mozilla.org/zh-CN/docs/Web/SVG/Element/pattern
2465
2471
 
2466
- var $pattern = createSVGElement('pattern');
2472
+ var $pattern = createSVGElement('pattern', document);
2467
2473
  $pattern.setAttribute('patternUnits', 'userSpaceOnUse');
2468
- var $image = createSVGElement('image');
2474
+ var $image = createSVGElement('image', document);
2469
2475
  $pattern.appendChild($image);
2470
2476
  $pattern.id = patternId;
2471
2477
  $def.appendChild($pattern);
@@ -2492,11 +2498,11 @@
2492
2498
  }
2493
2499
  }
2494
2500
 
2495
- function createGradient($def, parsedColor, gradientId) {
2501
+ function createGradient(document, $def, parsedColor, gradientId) {
2496
2502
  // <linearGradient> <radialGradient>
2497
2503
  // @see https://developer.mozilla.org/zh-CN/docs/Web/SVG/Element/linearGradient
2498
2504
  // @see https://developer.mozilla.org/zh-CN/docs/Web/SVG/Element/radialGradient
2499
- var $gradient = createSVGElement(parsedColor.type === g.GradientPatternType.LinearGradient ? 'linearGradient' : 'radialGradient');
2505
+ var $gradient = createSVGElement(parsedColor.type === g.GradientPatternType.LinearGradient ? 'linearGradient' : 'radialGradient', document);
2500
2506
 
2501
2507
  if (parsedColor.type === g.GradientPatternType.LinearGradient) {
2502
2508
  var _parsedColor$value = parsedColor.value,
@@ -2536,14 +2542,14 @@
2536
2542
  * @see https://developer.mozilla.org/zh-CN/docs/Web/SVG/Element/filter
2537
2543
  */
2538
2544
 
2539
- function createOrUpdateShadow($def, object, $el, name) {
2545
+ function createOrUpdateShadow(document, $def, object, $el, name) {
2540
2546
  var shadowId = FILTER_DROPSHADOW_PREFIX + object.entity;
2541
2547
  var $existedFilter = $def.querySelector("#" + shadowId);
2542
2548
 
2543
2549
  if (!$existedFilter) {
2544
- $existedFilter = createSVGElement('filter');
2550
+ $existedFilter = createSVGElement('filter', document);
2545
2551
 
2546
- var _$feDropShadow = createSVGElement('feDropShadow');
2552
+ var _$feDropShadow = createSVGElement('feDropShadow', document);
2547
2553
 
2548
2554
  _$feDropShadow.setAttribute('dx', '0');
2549
2555
 
@@ -2571,17 +2577,21 @@
2571
2577
  } else if (name === 'shadowOffsetY') {
2572
2578
  var shadowOffsetY = object.parsedStyle[name];
2573
2579
  $feDropShadow.setAttribute('dy', "" + (shadowOffsetY && shadowOffsetY.value || 0) / 2);
2574
- } // use filter <feDropShadow>
2575
- // @see https://developer.mozilla.org/en-US/docs/Web/SVG/Element/feDropShadow
2580
+ } // only apply shadow when blur > 0
2576
2581
 
2577
2582
 
2578
- $el === null || $el === void 0 ? void 0 : $el.setAttribute('filter', "url(#" + shadowId + ")");
2583
+ if (object.parsedStyle.shadowBlur && object.parsedStyle.shadowBlur.value > 0) {
2584
+ // use filter <feDropShadow>
2585
+ // @see https://developer.mozilla.org/en-US/docs/Web/SVG/Element/feDropShadow
2586
+ $el === null || $el === void 0 ? void 0 : $el.setAttribute('filter', "url(#" + shadowId + ")");
2587
+ } else {
2588
+ $el === null || $el === void 0 ? void 0 : $el.removeAttribute('filter');
2589
+ }
2579
2590
  }
2580
2591
 
2581
- var _SHAPE2TAGS, _class$1;
2592
+ var _class$1;
2582
2593
 
2583
2594
  var SVGRendererPlugin_1;
2584
- 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);
2585
2595
  var SVG_ATTR_MAP = {
2586
2596
  opacity: 'opacity',
2587
2597
  fillStyle: 'fill',
@@ -2667,7 +2677,7 @@
2667
2677
  this.camera = void 0;
2668
2678
  this.contextService = void 0;
2669
2679
  this.renderingContext = void 0;
2670
- this.elementRendererFactory = void 0;
2680
+ this.createElementContribution = void 0;
2671
2681
  this.$def = void 0;
2672
2682
  this.$camera = void 0;
2673
2683
  this.renderQueue = [];
@@ -2678,10 +2688,12 @@
2678
2688
  _proto.apply = function apply(renderingService) {
2679
2689
  var _this = this;
2680
2690
 
2691
+ var document = this.canvasConfig.document;
2692
+
2681
2693
  var handleMounted = function handleMounted(e) {
2682
2694
  var object = e.target; // create SVG DOM Node
2683
2695
 
2684
- _this.createSVGDom(object, _this.$camera);
2696
+ _this.createSVGDom(document, object, _this.$camera);
2685
2697
  };
2686
2698
 
2687
2699
  var handleUnmounted = function handleUnmounted(e) {
@@ -2709,7 +2721,7 @@
2709
2721
  var children = ((parent === null || parent === void 0 ? void 0 : parent.children) || []).slice();
2710
2722
 
2711
2723
  if ($groupEl) {
2712
- _this.reorderChildren($groupEl, children);
2724
+ _this.reorderChildren(document, $groupEl, children);
2713
2725
  }
2714
2726
  } else if (attrName === 'increasedLineWidthForHitTesting') {
2715
2727
  // @ts-ignore
@@ -2722,14 +2734,15 @@
2722
2734
  };
2723
2735
 
2724
2736
  renderingService.hooks.init.tapPromise(SVGRendererPlugin_1.tag, /*#__PURE__*/_asyncToGenerator$1( /*#__PURE__*/_regeneratorRuntime$1().mark(function _callee() {
2725
- var $svg, background;
2737
+ var _this$canvasConfig, background, document, $svg;
2738
+
2726
2739
  return _regeneratorRuntime$1().wrap(function _callee$(_context) {
2727
2740
  while (1) {
2728
2741
  switch (_context.prev = _context.next) {
2729
2742
  case 0:
2730
- _this.$def = createSVGElement('defs');
2743
+ _this$canvasConfig = _this.canvasConfig, background = _this$canvasConfig.background, document = _this$canvasConfig.document;
2744
+ _this.$def = createSVGElement('defs', document);
2731
2745
  $svg = _this.contextService.getContext();
2732
- background = _this.canvasConfig.background;
2733
2746
 
2734
2747
  if (background) {
2735
2748
  $svg.style.background = background;
@@ -2738,7 +2751,7 @@
2738
2751
  $svg.appendChild(_this.$def); // @see https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/color-interpolation-filters
2739
2752
 
2740
2753
  $svg.setAttribute('color-interpolation-filters', 'sRGB');
2741
- _this.$camera = createSVGElement('g');
2754
+ _this.$camera = createSVGElement('g', document);
2742
2755
  _this.$camera.id = G_SVG_PREFIX + "_camera";
2743
2756
 
2744
2757
  _this.applyTransform(_this.$camera, _this.camera.getOrthoMatrix());
@@ -2786,11 +2799,7 @@
2786
2799
  if ($el && $groupEl) {
2787
2800
  // apply local RTS transformation to <group> wrapper
2788
2801
  // account for anchor
2789
- _this.applyTransform($groupEl, object.getLocalTransform());
2790
-
2791
- var children = ((object === null || object === void 0 ? void 0 : object.children) || []).slice();
2792
-
2793
- _this.reorderChildren($groupEl, children || []); // finish rendering, clear dirty flag
2802
+ _this.applyTransform($groupEl, object.getLocalTransform()); // finish rendering, clear dirty flag
2794
2803
 
2795
2804
 
2796
2805
  object.renderable.dirty = false;
@@ -2801,7 +2810,7 @@
2801
2810
  });
2802
2811
  };
2803
2812
 
2804
- _proto.reorderChildren = function reorderChildren($groupEl, children) {
2813
+ _proto.reorderChildren = function reorderChildren(doc, $groupEl, children) {
2805
2814
  // need to reorder parent's children
2806
2815
  children.sort(function (a, b) {
2807
2816
  return a.sortable.renderOrder - b.sortable.renderOrder;
@@ -2809,13 +2818,15 @@
2809
2818
 
2810
2819
  if (children.length) {
2811
2820
  // create empty fragment
2812
- var fragment = document.createDocumentFragment();
2821
+ var fragment = (doc || document).createDocumentFragment();
2813
2822
  children.forEach(function (child) {
2814
- // @ts-ignore
2815
- var $el = child.elementSVG.$groupEl;
2823
+ if (child.isConnected) {
2824
+ // @ts-ignore
2825
+ var $el = child.elementSVG.$groupEl;
2816
2826
 
2817
- if ($el) {
2818
- fragment.appendChild($el);
2827
+ if ($el) {
2828
+ fragment.appendChild($el);
2829
+ }
2819
2830
  }
2820
2831
  });
2821
2832
  $groupEl.appendChild(fragment);
@@ -2866,7 +2877,7 @@
2866
2877
  _proto.updateAttribute = function updateAttribute(object, attributes) {
2867
2878
  var _this2 = this;
2868
2879
 
2869
- var needGeneratePath = false; // @ts-ignore
2880
+ var document = this.canvasConfig.document; // @ts-ignore
2870
2881
 
2871
2882
  var _object$elementSVG3 = object.elementSVG,
2872
2883
  $el = _object$elementSVG3.$el,
@@ -2874,16 +2885,27 @@
2874
2885
  $hitTestingEl = _object$elementSVG3.$hitTestingEl;
2875
2886
  var parsedStyle = object.parsedStyle,
2876
2887
  computedStyle = object.computedStyle;
2877
- var elementRenderer = this.elementRendererFactory(object.nodeName);
2888
+ var shouldUpdateElementAttribute = attributes.some(function (name) {
2889
+ return _this2.createElementContribution.shouldUpdateElementAttribute(object, name);
2890
+ }); // need re-generate path
2891
+
2892
+ if (shouldUpdateElementAttribute && $el) {
2893
+ [$el, $hitTestingEl].forEach(function ($el) {
2894
+ if ($el) {
2895
+ _this2.createElementContribution.updateElementAttribute(object, $el);
2896
+
2897
+ if (object.nodeName !== g.Shape.TEXT) {
2898
+ _this2.updateAnchorWithTransform(object);
2899
+ }
2900
+ }
2901
+ });
2902
+ } // update common attributes
2903
+
2904
+
2878
2905
  attributes.forEach(function (name) {
2879
2906
  var usedName = SVG_ATTR_MAP[name];
2880
2907
  var computedValue = computedStyle[name];
2881
- var usedValue = parsedStyle[name]; // generate path only once
2882
-
2883
- if (!needGeneratePath && elementRenderer && elementRenderer.dependencies.indexOf(name) > -1) {
2884
- needGeneratePath = true;
2885
- } // <foreignObject>
2886
-
2908
+ var usedValue = parsedStyle[name]; // <foreignObject>
2887
2909
 
2888
2910
  if (object.nodeName === g.Shape.HTML) {
2889
2911
  if (name === 'fill') {
@@ -2899,27 +2921,26 @@
2899
2921
  }
2900
2922
 
2901
2923
  if (name === 'fill' || name === 'stroke') {
2902
- createOrUpdateGradientAndPattern(_this2.$def, object, $el, usedValue, usedName);
2903
- } else if (name === 'visibility') {
2924
+ createOrUpdateGradientAndPattern(document, _this2.$def, object, $el, usedValue, usedName);
2925
+ } else if (name === 'visibility' && computedValue.value !== 'unset') {
2904
2926
  // use computed value
2905
2927
  // update `visibility` on <group>
2906
2928
  $groupEl === null || $groupEl === void 0 ? void 0 : $groupEl.setAttribute(usedName, "" + computedValue.value);
2907
2929
  } else if (name === 'clipPath') {
2908
- _this2.createOrUpdateClipPath(usedValue, $groupEl);
2930
+ _this2.createOrUpdateClipPath(document, usedValue, $groupEl);
2909
2931
  } else if (name === 'shadowColor' || name === 'shadowBlur' || name === 'shadowOffsetX' || name === 'shadowOffsetY') {
2910
- createOrUpdateShadow(_this2.$def, object, $el, name);
2932
+ createOrUpdateShadow(document, _this2.$def, object, $el, name);
2911
2933
  } else if (name === 'filter') {
2912
- createOrUpdateFilter(_this2.$def, object, $el, usedValue);
2934
+ createOrUpdateFilter(document, _this2.$def, object, $el, usedValue);
2913
2935
  } else if (name === 'innerHTML') {
2914
- _this2.createOrUpdateInnerHTML($el, usedValue);
2915
- } else {
2916
- if ( // (!object.style.clipPathTargets) &&
2917
- object.nodeName !== g.Shape.TEXT && // text' anchor is controlled by `textAnchor` property
2918
- ['width', 'height', 'r', 'rx', 'ry', 'anchor'].indexOf(name) > -1) {
2936
+ _this2.createOrUpdateInnerHTML(document, $el, usedValue);
2937
+ } else if (name === 'anchor') {
2938
+ // text' anchor is controlled by `textAnchor` property
2939
+ if (object.nodeName !== g.Shape.TEXT) {
2919
2940
  _this2.updateAnchorWithTransform(object);
2920
2941
  }
2921
-
2922
- if (name !== 'anchor' && computedValue) {
2942
+ } else {
2943
+ if (computedValue) {
2923
2944
  // use computed value so that we can use cascaded effect in SVG
2924
2945
  var valueStr = computedValue.toString(); // ignore 'unset' and default value
2925
2946
 
@@ -2937,18 +2958,10 @@
2937
2958
  });
2938
2959
  }
2939
2960
  }
2940
- }); // need re-generate path
2941
-
2942
- if (needGeneratePath && $el) {
2943
- [$el, $hitTestingEl].forEach(function ($el) {
2944
- if ($el) {
2945
- elementRenderer.apply($el, object.parsedStyle);
2946
- }
2947
- });
2948
- }
2961
+ });
2949
2962
  };
2950
2963
 
2951
- _proto.createSVGDom = function createSVGDom(object, root, noWrapWithGroup) {
2964
+ _proto.createSVGDom = function createSVGDom(document, object, root, noWrapWithGroup) {
2952
2965
  if (noWrapWithGroup === void 0) {
2953
2966
  noWrapWithGroup = false;
2954
2967
  } // create svg element
@@ -2959,13 +2972,12 @@
2959
2972
 
2960
2973
  var svgElement = object.elementSVG; // use <group> as default, eg. CustomElement
2961
2974
 
2962
- var type = SHAPE2TAGS[object.nodeName] || 'g';
2975
+ var $el = this.createElementContribution.createElement(object);
2963
2976
 
2964
- if (type) {
2977
+ if ($el) {
2965
2978
  var _object$parentNode$el2;
2966
2979
 
2967
- var $groupEl;
2968
- var $el = createSVGElement(type); // save $el on parsedStyle, which will be returned in getDomElement()
2980
+ var $groupEl; // save $el on parsedStyle, which will be returned in getDomElement()
2969
2981
 
2970
2982
  if (object.nodeName === g.Shape.HTML) {
2971
2983
  object.parsedStyle.$el = $el;
@@ -2973,26 +2985,29 @@
2973
2985
 
2974
2986
  $el.id = G_SVG_PREFIX + "_" + object.nodeName + "_" + object.entity;
2975
2987
 
2976
- if (type !== 'g' && !noWrapWithGroup) {
2977
- $groupEl = createSVGElement('g');
2988
+ if (($el.hasAttribute('data-wrapgroup') || $el.nodeName !== 'g') && !noWrapWithGroup) {
2989
+ $groupEl = createSVGElement('g', document);
2978
2990
  $groupEl.appendChild($el);
2979
2991
  } else {
2980
2992
  $groupEl = $el;
2981
2993
  }
2982
2994
 
2983
2995
  svgElement.$el = $el;
2984
- svgElement.$groupEl = $groupEl;
2996
+ svgElement.$groupEl = $groupEl; // apply attributes at first time
2997
+
2998
+ this.applyAttributes(object); // create hitArea if necessary
2999
+
3000
+ this.createOrUpdateHitArea(object, $el, $groupEl);
2985
3001
  var $parentGroupEl = // @ts-ignore
2986
3002
  object.parentNode && ((_object$parentNode$el2 = object.parentNode.elementSVG) === null || _object$parentNode$el2 === void 0 ? void 0 : _object$parentNode$el2.$groupEl) || root;
2987
3003
 
2988
3004
  if ($parentGroupEl) {
2989
- $parentGroupEl.appendChild($groupEl);
2990
- } // apply attributes at first time
3005
+ var _object$parentNode2;
2991
3006
 
2992
-
2993
- this.applyAttributes(object); // create hitArea if necessary
2994
-
2995
- this.createOrUpdateHitArea(object, $el, $groupEl);
3007
+ $parentGroupEl.appendChild($groupEl);
3008
+ var children = (((_object$parentNode2 = object.parentNode) === null || _object$parentNode2 === void 0 ? void 0 : _object$parentNode2.children) || []).slice();
3009
+ this.reorderChildren(document, $parentGroupEl, children || []);
3010
+ }
2996
3011
  }
2997
3012
  };
2998
3013
 
@@ -3044,8 +3059,8 @@
3044
3059
  }
3045
3060
  };
3046
3061
 
3047
- _proto.createOrUpdateInnerHTML = function createOrUpdateInnerHTML($el, usedValue) {
3048
- var $div = document.createElement('div');
3062
+ _proto.createOrUpdateInnerHTML = function createOrUpdateInnerHTML(doc, $el, usedValue) {
3063
+ var $div = (doc || document).createElement('div');
3049
3064
 
3050
3065
  if (typeof usedValue === 'string') {
3051
3066
  $div.innerHTML = usedValue;
@@ -3057,7 +3072,7 @@
3057
3072
  $el.appendChild($div);
3058
3073
  };
3059
3074
 
3060
- _proto.createOrUpdateClipPath = function createOrUpdateClipPath(clipPath, $groupEl) {
3075
+ _proto.createOrUpdateClipPath = function createOrUpdateClipPath(document, clipPath, $groupEl) {
3061
3076
  if (clipPath) {
3062
3077
  var _clipPath$elementSVG;
3063
3078
 
@@ -3066,11 +3081,11 @@
3066
3081
 
3067
3082
  if (!existed) {
3068
3083
  // create <clipPath> dom node, append it to <defs>
3069
- var $clipPath = createSVGElement('clipPath');
3084
+ var $clipPath = createSVGElement('clipPath', document);
3070
3085
  $clipPath.id = clipPathId;
3071
3086
  this.$def.appendChild($clipPath); // <clipPath><circle /></clipPath>
3072
3087
 
3073
- this.createSVGDom(clipPath, $clipPath, true); // @ts-ignore
3088
+ this.createSVGDom(document, clipPath, $clipPath, true); // @ts-ignore
3074
3089
 
3075
3090
  clipPath.elementSVG.$groupEl = $clipPath;
3076
3091
  } // @ts-ignore
@@ -3135,43 +3150,13 @@
3135
3150
 
3136
3151
  __decorate([manaSyringe.inject(g.RenderingContext), __metadata("design:type", Object)], SVGRendererPlugin.prototype, "renderingContext", void 0);
3137
3152
 
3138
- __decorate([manaSyringe.inject(ElementRendererFactory), __metadata("design:type", Function)], SVGRendererPlugin.prototype, "elementRendererFactory", void 0);
3153
+ __decorate([manaSyringe.inject(CreateElementContribution), __metadata("design:type", Object)], SVGRendererPlugin.prototype, "createElementContribution", void 0);
3139
3154
 
3140
3155
  SVGRendererPlugin = SVGRendererPlugin_1 = __decorate([manaSyringe.singleton({
3141
3156
  contrib: g.RenderingPluginContribution
3142
3157
  })], SVGRendererPlugin);
3143
3158
  var containerModule$1 = manaSyringe.Module(function (register) {
3144
- /**
3145
- * register shape renderers
3146
- */
3147
- register(RectRenderer);
3148
- register(ImageRenderer);
3149
- register(LineRenderer);
3150
- register(PolylineRenderer);
3151
- register(TextRenderer);
3152
- register(PathRenderer);
3153
- register({
3154
- token: ElementRendererFactory,
3155
- useFactory: function useFactory(ctx) {
3156
- return function (tagName) {
3157
- if (tagName === g.Shape.RECT) {
3158
- return ctx.container.get(RectRenderer);
3159
- } else if (tagName === g.Shape.IMAGE) {
3160
- return ctx.container.get(ImageRenderer);
3161
- } else if (tagName === g.Shape.LINE) {
3162
- return ctx.container.get(LineRenderer);
3163
- } else if (tagName === g.Shape.POLYLINE || tagName === g.Shape.POLYGON) {
3164
- return ctx.container.get(PolylineRenderer);
3165
- } else if (tagName === g.Shape.TEXT) {
3166
- return ctx.container.get(TextRenderer);
3167
- } else if (tagName === g.Shape.PATH) {
3168
- return ctx.container.get(PathRenderer);
3169
- }
3170
-
3171
- return null;
3172
- };
3173
- }
3174
- });
3159
+ register(DefaultCreateElementContribution);
3175
3160
  register(SVGRendererPlugin);
3176
3161
  });
3177
3162
 
@@ -3195,15 +3180,24 @@
3195
3180
 
3196
3181
  var index_esm$1 = /*#__PURE__*/Object.freeze({
3197
3182
  __proto__: null,
3183
+ CreateElementContribution: CreateElementContribution,
3198
3184
  DEFAULT_VALUE_MAP: DEFAULT_VALUE_MAP,
3185
+ get DefaultCreateElementContribution () { return DefaultCreateElementContribution; },
3199
3186
  ElementSVG: ElementSVG,
3200
3187
  G_SVG_PREFIX: G_SVG_PREFIX,
3201
3188
  Plugin: Plugin$1,
3202
3189
  SHAPE2TAGS: SHAPE2TAGS,
3190
+ SHAPE_UPDATE_DEPS: SHAPE_UPDATE_DEPS,
3203
3191
  get SVGRendererPlugin () { return SVGRendererPlugin; },
3204
3192
  SVG_ATTR_MAP: SVG_ATTR_MAP,
3205
3193
  containerModule: containerModule$1,
3206
- createSVGElement: createSVGElement
3194
+ createSVGElement: createSVGElement,
3195
+ updateImageElementAttribute: updateImageElementAttribute,
3196
+ updateLineElementAttribute: updateLineElementAttribute,
3197
+ updatePathElementAttribute: updatePathElementAttribute,
3198
+ updatePolylineElementAttribute: updatePolylineElementAttribute,
3199
+ updateRectElementAttribute: updateRectElementAttribute,
3200
+ updateTextElementAttribute: updateTextElementAttribute
3207
3201
  });
3208
3202
 
3209
3203
  function _regeneratorRuntime$2() {
@@ -3644,7 +3638,7 @@
3644
3638
 
3645
3639
  var SVGPickerPlugin = SVGPickerPlugin_1 = (_class$2 = /*#__PURE__*/function () {
3646
3640
  function SVGPickerPlugin() {
3647
- this.sceneGraphService = void 0;
3641
+ this.canvasConfig = void 0;
3648
3642
  this.displayObjectPool = void 0;
3649
3643
  }
3650
3644
 
@@ -3653,6 +3647,7 @@
3653
3647
  _proto.apply = function apply(renderingService) {
3654
3648
  var _this = this;
3655
3649
 
3650
+ var doc = this.canvasConfig.document;
3656
3651
  renderingService.hooks.pick.tapPromise(SVGPickerPlugin_1.tag, /*#__PURE__*/function () {
3657
3652
  var _ref = _asyncToGenerator$2( /*#__PURE__*/_regeneratorRuntime$2().mark(function _callee(result) {
3658
3653
  var topmost, _result$position, clientX, clientY, targets, _iterator, _step, element, id, index, target;
@@ -3665,7 +3660,7 @@
3665
3660
  _context.prev = 1;
3666
3661
  targets = []; // @see https://developer.mozilla.org/zh-CN/docs/Web/API/Document/elementsFromPoint
3667
3662
 
3668
- _iterator = _createForOfIteratorHelperLoose(document.elementsFromPoint(clientX, clientY));
3663
+ _iterator = _createForOfIteratorHelperLoose((doc || document).elementsFromPoint(clientX, clientY));
3669
3664
 
3670
3665
  case 4:
3671
3666
  if ((_step = _iterator()).done) {
@@ -3734,7 +3729,7 @@
3734
3729
  return SVGPickerPlugin;
3735
3730
  }(), _class$2.tag = 'SVGPicker', _class$2);
3736
3731
 
3737
- __decorate([manaSyringe.inject(g.SceneGraphService), __metadata("design:type", Object)], SVGPickerPlugin.prototype, "sceneGraphService", void 0);
3732
+ __decorate([manaSyringe.inject(g.CanvasConfig), __metadata("design:type", Object)], SVGPickerPlugin.prototype, "canvasConfig", void 0);
3738
3733
 
3739
3734
  __decorate([manaSyringe.inject(g.DisplayObjectPool), __metadata("design:type", g.DisplayObjectPool)], SVGPickerPlugin.prototype, "displayObjectPool", void 0);
3740
3735
 
@@ -3779,16 +3774,18 @@
3779
3774
  var _proto = SVGContextService.prototype;
3780
3775
 
3781
3776
  _proto.init = function init() {
3782
- var container = this.canvasConfig.container; // create container
3777
+ var _this$canvasConfig = this.canvasConfig,
3778
+ container = _this$canvasConfig.container,
3779
+ doc = _this$canvasConfig.document; // create container
3783
3780
 
3784
- this.$container = g.isString(container) ? document.getElementById(container) : container;
3781
+ this.$container = g.isString(container) ? (doc || document).getElementById(container) : container;
3785
3782
 
3786
3783
  if (this.$container) {
3787
3784
  if (!this.$container.style.position) {
3788
3785
  this.$container.style.position = 'relative';
3789
3786
  }
3790
3787
 
3791
- var $namespace = createSVGElement('svg');
3788
+ var $namespace = createSVGElement('svg', doc);
3792
3789
  $namespace.setAttribute('width', "" + this.canvasConfig.width);
3793
3790
  $namespace.setAttribute('height', "" + this.canvasConfig.height);
3794
3791
  this.$container.appendChild($namespace);