@antv/g-svg 2.0.45 → 2.1.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.
Files changed (51) hide show
  1. package/dist/index.esm.js +2036 -14
  2. package/dist/index.esm.js.map +1 -1
  3. package/dist/index.js +2037 -28
  4. package/dist/index.js.map +1 -1
  5. package/dist/index.umd.min.js +4 -28
  6. package/dist/index.umd.min.js.map +1 -1
  7. package/package.json +6 -8
  8. package/types/index.d.ts +6 -5
  9. package/types/index.d.ts.map +1 -1
  10. package/types/plugins/picker/SVGPickerPlugin.d.ts +13 -0
  11. package/types/plugins/picker/SVGPickerPlugin.d.ts.map +1 -0
  12. package/types/plugins/picker/index.d.ts +7 -0
  13. package/types/plugins/picker/index.d.ts.map +1 -0
  14. package/types/plugins/svg-renderer/DefaultElementLifeCycleContribution.d.ts +15 -0
  15. package/types/plugins/svg-renderer/DefaultElementLifeCycleContribution.d.ts.map +1 -0
  16. package/types/plugins/svg-renderer/SVGRendererPlugin.d.ts +64 -0
  17. package/types/plugins/svg-renderer/SVGRendererPlugin.d.ts.map +1 -0
  18. package/types/plugins/svg-renderer/components/ElementSVG.d.ts +19 -0
  19. package/types/plugins/svg-renderer/components/ElementSVG.d.ts.map +1 -0
  20. package/types/plugins/svg-renderer/index.d.ts +17 -0
  21. package/types/plugins/svg-renderer/index.d.ts.map +1 -0
  22. package/types/plugins/svg-renderer/interfaces.d.ts +12 -0
  23. package/types/plugins/svg-renderer/interfaces.d.ts.map +1 -0
  24. package/types/plugins/svg-renderer/shapes/defs/DefElementManager.d.ts +19 -0
  25. package/types/plugins/svg-renderer/shapes/defs/DefElementManager.d.ts.map +1 -0
  26. package/types/plugins/svg-renderer/shapes/defs/Filter.d.ts +8 -0
  27. package/types/plugins/svg-renderer/shapes/defs/Filter.d.ts.map +1 -0
  28. package/types/plugins/svg-renderer/shapes/defs/Pattern.d.ts +7 -0
  29. package/types/plugins/svg-renderer/shapes/defs/Pattern.d.ts.map +1 -0
  30. package/types/plugins/svg-renderer/shapes/defs/Shadow.d.ts +7 -0
  31. package/types/plugins/svg-renderer/shapes/defs/Shadow.d.ts.map +1 -0
  32. package/types/plugins/svg-renderer/shapes/defs/index.d.ts +5 -0
  33. package/types/plugins/svg-renderer/shapes/defs/index.d.ts.map +1 -0
  34. package/types/plugins/svg-renderer/shapes/paths/Image.d.ts +3 -0
  35. package/types/plugins/svg-renderer/shapes/paths/Image.d.ts.map +1 -0
  36. package/types/plugins/svg-renderer/shapes/paths/Line.d.ts +3 -0
  37. package/types/plugins/svg-renderer/shapes/paths/Line.d.ts.map +1 -0
  38. package/types/plugins/svg-renderer/shapes/paths/Path.d.ts +3 -0
  39. package/types/plugins/svg-renderer/shapes/paths/Path.d.ts.map +1 -0
  40. package/types/plugins/svg-renderer/shapes/paths/Polyline.d.ts +3 -0
  41. package/types/plugins/svg-renderer/shapes/paths/Polyline.d.ts.map +1 -0
  42. package/types/plugins/svg-renderer/shapes/paths/Rect.d.ts +3 -0
  43. package/types/plugins/svg-renderer/shapes/paths/Rect.d.ts.map +1 -0
  44. package/types/plugins/svg-renderer/shapes/paths/Text.d.ts +3 -0
  45. package/types/plugins/svg-renderer/shapes/paths/Text.d.ts.map +1 -0
  46. package/types/plugins/svg-renderer/shapes/paths/index.d.ts +7 -0
  47. package/types/plugins/svg-renderer/shapes/paths/index.d.ts.map +1 -0
  48. package/types/plugins/svg-renderer/utils/dom.d.ts +2 -0
  49. package/types/plugins/svg-renderer/utils/dom.d.ts.map +1 -0
  50. package/types/plugins/svg-renderer/utils/format.d.ts +3 -0
  51. package/types/plugins/svg-renderer/utils/format.d.ts.map +1 -0
package/dist/index.js CHANGED
@@ -1,8 +1,8 @@
1
1
  /*!
2
2
  * @antv/g-svg
3
3
  * @description A renderer implemented by SVG
4
- * @version 2.0.45
5
- * @date 12/10/2025, 8:45:20 AM
4
+ * @version 2.1.0
5
+ * @date 12/22/2025, 3:04:35 AM
6
6
  * @author AntVis
7
7
  * @docs https://g.antv.antgroup.com/
8
8
  */
@@ -13,34 +13,2038 @@ var _classCallCheck = require('@babel/runtime/helpers/classCallCheck');
13
13
  var _callSuper = require('@babel/runtime/helpers/callSuper');
14
14
  var _inherits = require('@babel/runtime/helpers/inherits');
15
15
  var gLite = require('@antv/g-lite');
16
- var DomInteraction = require('@antv/g-plugin-dom-interaction');
17
- var SVGPicker = require('@antv/g-plugin-svg-picker');
18
- var SVGRenderer = require('@antv/g-plugin-svg-renderer');
16
+ var util = require('@antv/util');
17
+ var _defineProperty = require('@babel/runtime/helpers/defineProperty');
18
+ var _slicedToArray = require('@babel/runtime/helpers/slicedToArray');
19
+ var glMatrix = require('gl-matrix');
20
+ var _objectSpread = require('@babel/runtime/helpers/objectSpread2');
21
+ var _createForOfIteratorHelper = require('@babel/runtime/helpers/createForOfIteratorHelper');
19
22
  var _regeneratorRuntime = require('@babel/runtime/helpers/regeneratorRuntime');
20
23
  var _asyncToGenerator = require('@babel/runtime/helpers/asyncToGenerator');
21
24
  var _objectWithoutProperties = require('@babel/runtime/helpers/objectWithoutProperties');
22
- var util = require('@antv/util');
23
25
 
24
- function _interopNamespaceDefault(e) {
25
- var n = Object.create(null);
26
- if (e) {
27
- Object.keys(e).forEach(function (k) {
28
- if (k !== 'default') {
29
- var d = Object.getOwnPropertyDescriptor(e, k);
30
- Object.defineProperty(n, k, d.get ? d : {
31
- enumerable: true,
32
- get: function () { return e[k]; }
33
- });
26
+ var ElementSVG = /*#__PURE__*/_createClass(function ElementSVG() {
27
+ _classCallCheck(this, ElementSVG);
28
+ });
29
+ ElementSVG.tag = 'c-svg-element';
30
+
31
+ function updateImageElementAttribute($el, parsedStyle) {
32
+ var _parsedStyle$src = parsedStyle.src,
33
+ src = _parsedStyle$src === void 0 ? '' : _parsedStyle$src,
34
+ _parsedStyle$x = parsedStyle.x,
35
+ x = _parsedStyle$x === void 0 ? 0 : _parsedStyle$x,
36
+ _parsedStyle$y = parsedStyle.y,
37
+ y = _parsedStyle$y === void 0 ? 0 : _parsedStyle$y,
38
+ width = parsedStyle.width,
39
+ height = parsedStyle.height;
40
+ $el.setAttribute('x', "".concat(x));
41
+ $el.setAttribute('y', "".concat(y));
42
+ if (util.isString(src)) {
43
+ $el.setAttribute('href', src);
44
+ } else if (src instanceof Image) {
45
+ if (!width) {
46
+ $el.setAttribute('width', "".concat(src.width));
47
+ }
48
+ if (!height) {
49
+ $el.setAttribute('height', "".concat(src.height));
50
+ }
51
+ $el.setAttribute('href', src.src);
52
+ } else if (
53
+ // @ts-ignore
54
+ src instanceof HTMLElement && util.isString(src.nodeName) && src.nodeName.toUpperCase() === 'CANVAS') {
55
+ $el.setAttribute('href', src.toDataURL());
56
+ // @ts-ignore
57
+ } else if (src instanceof ImageData) {
58
+ var canvas = document.createElement('canvas');
59
+ // @ts-ignore
60
+ canvas.setAttribute('width', "".concat(src.width));
61
+ // @ts-ignore
62
+ canvas.setAttribute('height', "".concat(src.height));
63
+ var context = canvas.getContext('2d');
64
+ if (context) {
65
+ context.putImageData(src, 0, 0);
66
+ if (!width) {
67
+ // @ts-ignore
68
+ $el.setAttribute('width', "".concat(src.width));
69
+ }
70
+ if (!height) {
71
+ // @ts-ignore
72
+ $el.setAttribute('height', "".concat(src.height));
73
+ }
74
+ $el.setAttribute('href', canvas.toDataURL());
75
+ }
76
+ }
77
+ }
78
+
79
+ function updateLineElementAttribute($el, parsedStyle) {
80
+ var x1 = parsedStyle.x1,
81
+ y1 = parsedStyle.y1,
82
+ x2 = parsedStyle.x2,
83
+ y2 = parsedStyle.y2,
84
+ markerStart = parsedStyle.markerStart,
85
+ markerEnd = parsedStyle.markerEnd,
86
+ markerStartOffset = parsedStyle.markerStartOffset,
87
+ markerEndOffset = parsedStyle.markerEndOffset;
88
+ var startOffsetX = 0;
89
+ var startOffsetY = 0;
90
+ var endOffsetX = 0;
91
+ var endOffsetY = 0;
92
+ var rad = 0;
93
+ var x;
94
+ var y;
95
+ if (markerStart && gLite.isDisplayObject(markerStart) && markerStartOffset) {
96
+ x = x2 - x1;
97
+ y = y2 - y1;
98
+ rad = Math.atan2(y, x);
99
+ startOffsetX = Math.cos(rad) * (markerStartOffset || 0);
100
+ startOffsetY = Math.sin(rad) * (markerStartOffset || 0);
101
+ }
102
+ if (markerEnd && gLite.isDisplayObject(markerEnd) && markerEndOffset) {
103
+ x = x1 - x2;
104
+ y = y1 - y2;
105
+ rad = Math.atan2(y, x);
106
+ endOffsetX = Math.cos(rad) * (markerEndOffset || 0);
107
+ endOffsetY = Math.sin(rad) * (markerEndOffset || 0);
108
+ }
109
+
110
+ // @see https://github.com/antvis/g/issues/1038
111
+ $el.setAttribute('x1', "".concat(x1 + startOffsetX));
112
+ $el.setAttribute('y1', "".concat(y1 + startOffsetY));
113
+ $el.setAttribute('x2', "".concat(x2 + endOffsetX));
114
+ $el.setAttribute('y2', "".concat(y2 + endOffsetY));
115
+ }
116
+
117
+ function updatePathElementAttribute($el, parsedStyle) {
118
+ var d = parsedStyle.d,
119
+ markerStart = parsedStyle.markerStart,
120
+ markerEnd = parsedStyle.markerEnd,
121
+ markerStartOffset = parsedStyle.markerStartOffset,
122
+ markerEndOffset = parsedStyle.markerEndOffset;
123
+ var startOffsetX = 0;
124
+ var startOffsetY = 0;
125
+ var endOffsetX = 0;
126
+ var endOffsetY = 0;
127
+ var rad = 0;
128
+ var x;
129
+ var y;
130
+ if (markerStart && gLite.isDisplayObject(markerStart) && markerStartOffset) {
131
+ var _getStartTangent = markerStart.parentNode.getStartTangent(),
132
+ _getStartTangent2 = _slicedToArray(_getStartTangent, 2),
133
+ p1 = _getStartTangent2[0],
134
+ p2 = _getStartTangent2[1];
135
+ x = p1[0] - p2[0];
136
+ y = p1[1] - p2[1];
137
+ rad = Math.atan2(y, x);
138
+ startOffsetX = Math.cos(rad) * (markerStartOffset || 0);
139
+ startOffsetY = Math.sin(rad) * (markerStartOffset || 0);
140
+ }
141
+ if (markerEnd && gLite.isDisplayObject(markerEnd) && markerEndOffset) {
142
+ var _getEndTangent = markerEnd.parentNode.getEndTangent(),
143
+ _getEndTangent2 = _slicedToArray(_getEndTangent, 2),
144
+ _p = _getEndTangent2[0],
145
+ _p2 = _getEndTangent2[1];
146
+ x = _p[0] - _p2[0];
147
+ y = _p[1] - _p2[1];
148
+ rad = Math.atan2(y, x);
149
+ endOffsetX = Math.cos(rad) * (markerEndOffset || 0);
150
+ endOffsetY = Math.sin(rad) * (markerEndOffset || 0);
151
+ }
152
+ $el.setAttribute('d', gLite.translatePathToString(d.absolutePath, startOffsetX, startOffsetY, endOffsetX, endOffsetY));
153
+ }
154
+
155
+ function updatePolylineElementAttribute($el, parsedStyle) {
156
+ var points = parsedStyle.points.points,
157
+ markerStart = parsedStyle.markerStart,
158
+ markerStartOffset = parsedStyle.markerStartOffset,
159
+ markerEnd = parsedStyle.markerEnd,
160
+ markerEndOffset = parsedStyle.markerEndOffset;
161
+ var length = points.length;
162
+ if (points && length >= 2) {
163
+ var startOffsetX = 0;
164
+ var startOffsetY = 0;
165
+ var endOffsetX = 0;
166
+ var endOffsetY = 0;
167
+ var rad = 0;
168
+ var x;
169
+ var y;
170
+ if (markerStart && gLite.isDisplayObject(markerStart) && markerStartOffset) {
171
+ x = points[1][0] - points[0][0];
172
+ y = points[1][1] - points[0][1];
173
+ rad = Math.atan2(y, x);
174
+ startOffsetX = Math.cos(rad) * (markerStartOffset || 0);
175
+ startOffsetY = Math.sin(rad) * (markerStartOffset || 0);
176
+ }
177
+ if (markerEnd && gLite.isDisplayObject(markerEnd) && markerEndOffset) {
178
+ x = points[length - 2][0] - points[length - 1][0];
179
+ y = points[length - 2][1] - points[length - 1][1];
180
+ rad = Math.atan2(y, x);
181
+ endOffsetX = Math.cos(rad) * (markerEndOffset || 0);
182
+ endOffsetY = Math.sin(rad) * (markerEndOffset || 0);
183
+ }
184
+ $el.setAttribute('points', points.map(function (point, i) {
185
+ var offsetX = 0;
186
+ var offsetY = 0;
187
+ if (i === 0) {
188
+ offsetX = startOffsetX;
189
+ offsetY = startOffsetY;
190
+ } else if (i === length - 1) {
191
+ offsetX = endOffsetX;
192
+ offsetY = endOffsetY;
193
+ }
194
+ return "".concat(point[0] + offsetX, ",").concat(point[1] + offsetY);
195
+ }).join(' '));
196
+ }
197
+ }
198
+
199
+ function updateRectElementAttribute($el, parsedStyle) {
200
+ var radius = parsedStyle.radius,
201
+ _parsedStyle$x = parsedStyle.x,
202
+ x = _parsedStyle$x === void 0 ? 0 : _parsedStyle$x,
203
+ _parsedStyle$y = parsedStyle.y,
204
+ y = _parsedStyle$y === void 0 ? 0 : _parsedStyle$y,
205
+ width = parsedStyle.width,
206
+ height = parsedStyle.height;
207
+
208
+ // CSSKeyword: auto
209
+ if (!isFinite(width) || !isFinite(height)) {
210
+ return;
211
+ }
212
+ var hasRadius = radius && radius.some(function (r) {
213
+ return r !== 0;
214
+ });
215
+ var d = '';
216
+ if (!hasRadius) {
217
+ d = "M ".concat(x, ",").concat(y, " l ").concat(width, ",0 l 0,").concat(height, " l").concat(-width, " 0 z");
218
+ } else {
219
+ var _radius$map = radius.map(function (r) {
220
+ return util.clamp(r, 0, Math.min(Math.abs(width) / 2, Math.abs(height) / 2));
221
+ }),
222
+ _radius$map2 = _slicedToArray(_radius$map, 4),
223
+ tlr = _radius$map2[0],
224
+ trr = _radius$map2[1],
225
+ brr = _radius$map2[2],
226
+ blr = _radius$map2[3];
227
+ var signX = width > 0 ? 1 : -1;
228
+ var signY = height > 0 ? 1 : -1;
229
+ // sweep-flag @see https://developer.mozilla.org/zh-CN/docs/Web/SVG/Tutorial/Paths#arcs
230
+ var sweepFlag = signX + signY !== 0 ? 1 : 0;
231
+ d = [["M ".concat(signX * tlr + x, ",").concat(y)], ["l ".concat(width - signX * (tlr + trr), ",0")], ["a ".concat(trr, ",").concat(trr, ",0,0,").concat(sweepFlag, ",").concat(signX * trr, ",").concat(signY * trr)], ["l 0,".concat(height - signY * (trr + brr))], ["a ".concat(brr, ",").concat(brr, ",0,0,").concat(sweepFlag, ",").concat(-signX * brr, ",").concat(signY * brr)], ["l ".concat(signX * (brr + blr) - width, ",0")], ["a ".concat(blr, ",").concat(blr, ",0,0,").concat(sweepFlag, ",").concat(-signX * blr, ",").concat(-signY * blr)], ["l 0,".concat(signY * (blr + tlr) - height)], ["a ".concat(tlr, ",").concat(tlr, ",0,0,").concat(sweepFlag, ",").concat(signX * tlr, ",").concat(-signY * tlr)], ['z']].join(' ');
232
+ }
233
+ $el.setAttribute('d', d);
234
+ }
235
+
236
+ function createSVGElement(type, doc) {
237
+ return (doc || document).createElementNS('http://www.w3.org/2000/svg', type);
238
+ }
239
+
240
+ var FILTER_PREFIX = 'g-filter-';
241
+
242
+ /**
243
+ * use SVG filters, eg. blur, brightness, contrast...
244
+ * @see https://developer.mozilla.org/zh-CN/docs/Web/SVG/Element/filter
245
+ */
246
+ function createOrUpdateFilter(document, $def, object, $el, filters) {
247
+ // eg. filter="url(#f1) url(#f2)"
248
+ var filterName = FILTER_PREFIX + object.entity;
249
+ var $existedFilters = $def.querySelectorAll("[name=".concat(filterName, "]"));
250
+ if ($existedFilters.length) {
251
+ $existedFilters.forEach(function ($filter) {
252
+ $def.removeChild($filter);
253
+ });
254
+ }
255
+ if (filters.length === 0) {
256
+ // 'none'
257
+ $el === null || $el === void 0 || $el.removeAttribute('filter');
258
+ } else {
259
+ var filterIds = filters.map(function (_ref, i) {
260
+ var name = _ref.name,
261
+ params = _ref.params;
262
+ var $filter = createSVGElement('filter', document);
263
+ // @see https://github.com/antvis/g/issues/1025
264
+ $filter.setAttribute('filterUnits', 'userSpaceOnUse');
265
+ if (name === 'blur') {
266
+ createBlur(document, $filter, params);
267
+ } else if (name === 'brightness') {
268
+ createBrightness(document, $filter, params);
269
+ } else if (name === 'drop-shadow') {
270
+ createDropShadow(document, $filter, params);
271
+ } else if (name === 'contrast') {
272
+ createContrast(document, $filter, params);
273
+ } else if (name === 'grayscale') {
274
+ createGrayscale(document, $filter, params);
275
+ } else if (name === 'sepia') {
276
+ createSepia(document, $filter, params);
277
+ } else if (name === 'saturate') {
278
+ createSaturate(document, $filter, params);
279
+ } else if (name === 'hue-rotate') {
280
+ createHueRotate(document, $filter, params);
281
+ } else if (name === 'invert') {
282
+ createInvert(document, $filter, params);
34
283
  }
284
+ $filter.id = "".concat(filterName, "-").concat(i);
285
+ $filter.setAttribute('name', filterName);
286
+ $def.appendChild($filter);
287
+ return $filter.id;
35
288
  });
289
+
290
+ // @see https://github.com/antvis/G/issues/1114
291
+ setTimeout(function () {
292
+ $el === null || $el === void 0 || $el.setAttribute('filter', filterIds.map(function (filterId) {
293
+ return "url(#".concat(filterId, ")");
294
+ }).join(' '));
295
+ });
296
+ }
297
+ }
298
+ function convertToAbsoluteValue(param) {
299
+ return param.unit === gLite.UnitType.kPercentage ? param.value / 100 : param.value;
300
+ }
301
+
302
+ /**
303
+ * @see https://drafts.fxtf.org/filter-effects/#blurEquivalent
304
+ */
305
+ function createBlur(document, $filter, params) {
306
+ var $feGaussianBlur = createSVGElement('feGaussianBlur', document);
307
+ $feGaussianBlur.setAttribute('in', 'SourceGraphic');
308
+ $feGaussianBlur.setAttribute('stdDeviation', "".concat(params[0].value));
309
+ $filter.appendChild($feGaussianBlur);
310
+ }
311
+ function createFeComponentTransfer(document, $filter, _ref2) {
312
+ var type = _ref2.type,
313
+ slope = _ref2.slope,
314
+ intercept = _ref2.intercept,
315
+ tableValues = _ref2.tableValues;
316
+ var $feComponentTransfer = createSVGElement('feComponentTransfer', document);
317
+ [createSVGElement('feFuncR', document), createSVGElement('feFuncG', document), createSVGElement('feFuncB', document)].forEach(function ($feFunc) {
318
+ $feFunc.setAttribute('type', type);
319
+ if (type === 'table') {
320
+ $feFunc.setAttribute('tableValues', "".concat(tableValues));
321
+ } else {
322
+ $feFunc.setAttribute('slope', "".concat(slope));
323
+ $feFunc.setAttribute('intercept', "".concat(intercept));
324
+ }
325
+ $feComponentTransfer.appendChild($feFunc);
326
+ });
327
+ $filter.appendChild($feComponentTransfer);
328
+ }
329
+ function createContrast(document, $filter, params) {
330
+ var slope = convertToAbsoluteValue(params[0]);
331
+ createFeComponentTransfer(document, $filter, {
332
+ type: 'linear',
333
+ slope: slope,
334
+ intercept: -(0.5 * slope) + 0.5
335
+ });
336
+ }
337
+ function createInvert(document, $filter, params) {
338
+ var amount = convertToAbsoluteValue(params[0]);
339
+ createFeComponentTransfer(document, $filter, {
340
+ type: 'table',
341
+ tableValues: "".concat(amount, " ").concat(1 - amount)
342
+ });
343
+ }
344
+ function createBrightness(document, $filter, params) {
345
+ var slope = convertToAbsoluteValue(params[0]);
346
+ createFeComponentTransfer(document, $filter, {
347
+ type: 'linear',
348
+ slope: slope,
349
+ intercept: 0
350
+ });
351
+ }
352
+ function createSaturate(document, $filter, params) {
353
+ var amount = convertToAbsoluteValue(params[0]);
354
+ var $feColorMatrix = createSVGElement('feColorMatrix', document);
355
+ $feColorMatrix.setAttribute('type', 'saturate');
356
+ $feColorMatrix.setAttribute('values', "".concat(amount));
357
+ $filter.appendChild($feColorMatrix);
358
+ }
359
+ function createHueRotate(document, $filter, params) {
360
+ var $feColorMatrix = createSVGElement('feColorMatrix', document);
361
+ $feColorMatrix.setAttribute('type', 'hueRotate');
362
+ // $feColorMatrix.setAttribute('values', `${params[0].to(UnitType.kDegrees).value}`);
363
+ // FIXME: convert to degrees
364
+ $feColorMatrix.setAttribute('values', "".concat(params[0].value));
365
+ $filter.appendChild($feColorMatrix);
366
+ }
367
+ function createDropShadow(document, $filter, params) {
368
+ var shadowOffsetX = params[0].value;
369
+ var shadowOffsetY = params[1].value;
370
+ var shadowBlur = params[2].value;
371
+ // @ts-ignore
372
+ var shadowColor = params[3].formatted;
373
+ var $feGaussianBlur = createSVGElement('feGaussianBlur', document);
374
+ $feGaussianBlur.setAttribute('in', 'SourceAlpha');
375
+ $feGaussianBlur.setAttribute('stdDeviation', "".concat(shadowBlur));
376
+ $filter.appendChild($feGaussianBlur);
377
+ var $feOffset = createSVGElement('feOffset', document);
378
+ $feOffset.setAttribute('dx', "".concat(shadowOffsetX));
379
+ $feOffset.setAttribute('dy', "".concat(shadowOffsetY));
380
+ $feOffset.setAttribute('result', 'offsetblur');
381
+ $filter.appendChild($feOffset);
382
+ var $feFlood = createSVGElement('feFlood', document);
383
+ $feFlood.setAttribute('flood-color', shadowColor);
384
+ $filter.appendChild($feFlood);
385
+ var $feComposite = createSVGElement('feComposite', document);
386
+ $feComposite.setAttribute('in2', 'offsetblur');
387
+ $feComposite.setAttribute('operator', 'in');
388
+ $filter.appendChild($feComposite);
389
+ var $feMerge = createSVGElement('feMerge', document);
390
+ $filter.appendChild($feMerge);
391
+ var $feMergeNode1 = createSVGElement('feMergeNode', document);
392
+ var $feMergeNode2 = createSVGElement('feMergeNode', document);
393
+ $feMergeNode2.setAttribute('in', 'SourceGraphic');
394
+ $feMerge.appendChild($feMergeNode1);
395
+ $feMerge.appendChild($feMergeNode2);
396
+ }
397
+ function createFeColorMatrix(document, $filter, matrix) {
398
+ var $feColorMatrix = createSVGElement('feColorMatrix', document);
399
+ $feColorMatrix.setAttribute('type', 'matrix');
400
+ $feColorMatrix.setAttribute('values', matrix.join(' '));
401
+ $filter.appendChild($feColorMatrix);
402
+ }
403
+
404
+ /**
405
+ * @see https://drafts.fxtf.org/filter-effects/#grayscaleEquivalent
406
+ */
407
+ function createGrayscale(document, $filter, params) {
408
+ var amount = convertToAbsoluteValue(params[0]);
409
+ 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]);
410
+ }
411
+
412
+ /**
413
+ * @see https://drafts.fxtf.org/filter-effects/#sepiaEquivalent
414
+ */
415
+ function createSepia(document, $filter, params) {
416
+ var amount = convertToAbsoluteValue(params[0]);
417
+ 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]);
418
+ }
419
+
420
+ var PATTERN_PREFIX = 'g-pattern-';
421
+ var cacheKey2IDMap = {};
422
+ var counter = 0;
423
+ function resetPatternCounter() {
424
+ counter = 0;
425
+ cacheKey2IDMap = {};
426
+ }
427
+ function createOrUpdateGradientAndPattern(document, $def, object, $el, parsedColor, name, createImage, plugin) {
428
+ // eg. clipPath don't have fill/stroke
429
+ if (!parsedColor) {
430
+ return '';
36
431
  }
37
- n.default = e;
38
- return Object.freeze(n);
432
+ if (gLite.isCSSRGB(parsedColor)) {
433
+ // keep using currentColor @see https://github.com/d3/d3-axis/issues/49
434
+ if (object.style[name] === 'currentColor') {
435
+ $el === null || $el === void 0 || $el.setAttribute(name, 'currentColor');
436
+ } else {
437
+ // constant value, eg. '#fff'
438
+ $el === null || $el === void 0 || $el.setAttribute(name, parsedColor.isNone ? 'none' : parsedColor.toString());
439
+ }
440
+ } else if (gLite.isPattern(parsedColor)) {
441
+ var patternId = createOrUpdatePattern(document, $def, object, parsedColor, createImage, plugin);
442
+ // use style instead of attribute when applying <pattern>
443
+ // @see https://stackoverflow.com/a/7723115
444
+ $el.style[name] = "url(#".concat(patternId, ")");
445
+ return patternId;
446
+ } else {
447
+ if (parsedColor.length === 1) {
448
+ var gradientId = createOrUpdateGradient(document, object, $def, $el, parsedColor[0]);
449
+ $el === null || $el === void 0 || $el.setAttribute(name, "url(#".concat(gradientId, ")"));
450
+ return gradientId;
451
+ }
452
+ // @see https://stackoverflow.com/questions/20671502/can-i-blend-gradients-in-svg
453
+ var filterId = createOrUpdateMultiGradient(document, object, $def, $el, parsedColor);
454
+ $el === null || $el === void 0 || $el.setAttribute('filter', "url(#".concat(filterId, ")"));
455
+ $el === null || $el === void 0 || $el.setAttribute('fill', 'black');
456
+ return filterId;
457
+ }
458
+ return '';
459
+ }
460
+ function generateCacheKey(src) {
461
+ var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
462
+ var cacheKey = '';
463
+ if (gLite.isCSSGradientValue(src)) {
464
+ var type = src.type,
465
+ value = src.value;
466
+ if (type === gLite.GradientType.LinearGradient || type === gLite.GradientType.RadialGradient) {
467
+ // @ts-ignore
468
+ var _value$options = _objectSpread(_objectSpread({}, value), options),
469
+ _type = _value$options.type,
470
+ x = _value$options.x,
471
+ y = _value$options.y,
472
+ width = _value$options.width,
473
+ height = _value$options.height,
474
+ steps = _value$options.steps,
475
+ angle = _value$options.angle,
476
+ cx = _value$options.cx,
477
+ cy = _value$options.cy,
478
+ size = _value$options.size;
479
+ cacheKey = "gradient-".concat(_type, "-").concat((x === null || x === void 0 ? void 0 : x.toString()) || 0, "-").concat((y === null || y === void 0 ? void 0 : y.toString()) || 0, "-").concat((angle === null || angle === void 0 ? void 0 : angle.toString()) || 0, "-").concat((cx === null || cx === void 0 ? void 0 : cx.toString()) || 0, "-").concat((cy === null || cy === void 0 ? void 0 : cy.toString()) || 0, "-").concat((size === null || size === void 0 ? void 0 : size.toString()) || 0, "-").concat(width, "-").concat(height, "-").concat(steps.map(function (_ref) {
480
+ var offset = _ref.offset,
481
+ color = _ref.color;
482
+ return "".concat(offset).concat(color);
483
+ }).join('-'));
484
+ }
485
+ } else if (gLite.isPattern(src)) {
486
+ if (util.isString(src.image)) {
487
+ cacheKey = "pattern-".concat(src.image, "-").concat(src.repetition);
488
+ } else if (src.image.nodeName === 'rect') {
489
+ // use rect's entity as key
490
+ cacheKey = "pattern-rect-".concat(src.image.entity);
491
+ } else {
492
+ cacheKey = "pattern-".concat(counter);
493
+ }
494
+ }
495
+ if (cacheKey) {
496
+ if (!cacheKey2IDMap[cacheKey]) {
497
+ cacheKey2IDMap[cacheKey] = "".concat(PATTERN_PREFIX).concat(counter++);
498
+ }
499
+ }
500
+ return cacheKey2IDMap[cacheKey];
501
+ }
502
+ function formatTransform(transform) {
503
+ // @see https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/patternTransform
504
+ // should remove unit: rotate(20deg) -> rotate(20)
505
+ return gLite.parseTransform(transform).map(function (parsed) {
506
+ var t = parsed.t,
507
+ d = parsed.d;
508
+ if (t === 'translate') {
509
+ return "translate(".concat(d[0].value, " ").concat(d[1].value, ")");
510
+ }
511
+ if (t === 'translateX') {
512
+ return "translate(".concat(d[0].value, " 0)");
513
+ }
514
+ if (t === 'translateY') {
515
+ return "translate(0 ".concat(d[0].value, ")");
516
+ }
517
+ if (t === 'rotate') {
518
+ return "rotate(".concat(d[0].value, ")");
519
+ }
520
+ if (t === 'scale') {
521
+ // scale(1) scale(1, 1)
522
+ var newScale = (d === null || d === void 0 ? void 0 : d.map(function (s) {
523
+ return s.value;
524
+ })) || [1, 1];
525
+ return "scale(".concat(newScale[0], ", ").concat(newScale[1], ")");
526
+ }
527
+ if (t === 'scaleX') {
528
+ var _newScale = (d === null || d === void 0 ? void 0 : d.map(function (s) {
529
+ return s.value;
530
+ })) || [1];
531
+ return "scale(".concat(_newScale[0], ", 1)");
532
+ }
533
+ if (t === 'scaleY') {
534
+ var _newScale2 = (d === null || d === void 0 ? void 0 : d.map(function (s) {
535
+ return s.value;
536
+ })) || [1];
537
+ return "scale(1, ".concat(_newScale2[0], ")");
538
+ }
539
+ if (t === 'skew') {
540
+ var newSkew = (d === null || d === void 0 ? void 0 : d.map(function (s) {
541
+ return s.value;
542
+ })) || [0, 0];
543
+ return "skewX(".concat(newSkew[0], ") skewY(").concat(newSkew[1], ")");
544
+ }
545
+ if (t === 'skewZ') {
546
+ var _newSkew = (d === null || d === void 0 ? void 0 : d.map(function (s) {
547
+ return s.value;
548
+ })) || [0];
549
+ return "skewX(".concat(_newSkew[0], ")");
550
+ }
551
+ if (t === 'skewY') {
552
+ var _newSkew2 = (d === null || d === void 0 ? void 0 : d.map(function (s) {
553
+ return s.value;
554
+ })) || [0];
555
+ return "skewY(".concat(_newSkew2[0], ")");
556
+ }
557
+ if (t === 'matrix') {
558
+ var _d$map = d.map(function (s) {
559
+ return s.value;
560
+ }),
561
+ _d$map2 = _slicedToArray(_d$map, 6),
562
+ a = _d$map2[0],
563
+ b = _d$map2[1],
564
+ c = _d$map2[2],
565
+ dd = _d$map2[3],
566
+ tx = _d$map2[4],
567
+ ty = _d$map2[5];
568
+ return "matrix(".concat(a, " ").concat(b, " ").concat(c, " ").concat(dd, " ").concat(tx, " ").concat(ty, ")");
569
+ }
570
+ return null;
571
+ }).filter(function (item) {
572
+ return item !== null;
573
+ }).join(' ');
39
574
  }
575
+ function create$Pattern(document, $def, object, pattern, patternId, width, height) {
576
+ var repetition = pattern.repetition,
577
+ transform = pattern.transform;
578
+
579
+ // @see https://developer.mozilla.org/zh-CN/docs/Web/SVG/Element/pattern
580
+ var $pattern = createSVGElement('pattern', document);
581
+ if (transform) {
582
+ $pattern.setAttribute('patternTransform', formatTransform(transform));
583
+ }
584
+ $pattern.setAttribute('patternUnits', 'userSpaceOnUse');
585
+ $pattern.id = patternId;
586
+ $def.appendChild($pattern);
587
+ var _object$getGeometryBo = object.getGeometryBounds(),
588
+ halfExtents = _object$getGeometryBo.halfExtents,
589
+ min = _object$getGeometryBo.min;
590
+ $pattern.setAttribute('x', "".concat(min[0]));
591
+ $pattern.setAttribute('y', "".concat(min[1]));
592
+
593
+ // There is no equivalent to CSS no-repeat for SVG patterns
594
+ // @see https://stackoverflow.com/a/33481956
595
+ var patternWidth = width;
596
+ var patternHeight = height;
597
+ if (repetition === 'repeat-x') {
598
+ patternHeight = halfExtents[1] * 2;
599
+ } else if (repetition === 'repeat-y') {
600
+ patternWidth = halfExtents[0] * 2;
601
+ } else if (repetition === 'no-repeat') {
602
+ patternWidth = halfExtents[0] * 2;
603
+ patternHeight = halfExtents[1] * 2;
604
+ }
605
+ $pattern.setAttribute('width', "".concat(patternWidth));
606
+ $pattern.setAttribute('height', "".concat(patternHeight));
607
+ return $pattern;
608
+ }
609
+ function createOrUpdatePattern(document, $def, object, pattern, createImage, plugin) {
610
+ var patternId = generateCacheKey(pattern);
611
+ var $existed = $def.querySelector("#".concat(patternId));
612
+ if (!$existed) {
613
+ var image = pattern.image;
614
+ var imageURL = '';
615
+ if (util.isString(image)) {
616
+ imageURL = image;
617
+ } else if (gLite.isBrowser) {
618
+ if (image instanceof HTMLImageElement) {
619
+ imageURL = image.src;
620
+ } else if (image instanceof HTMLCanvasElement) {
621
+ imageURL = image.toDataURL();
622
+ } else ;
623
+ }
624
+ if (imageURL) {
625
+ var $image = createSVGElement('image', document);
626
+ // use href instead of xlink:href
627
+ // @see https://stackoverflow.com/a/13379007
628
+ $image.setAttribute('href', imageURL);
629
+ var img = createImage();
630
+ if (!imageURL.match(/^data:/i)) {
631
+ img.crossOrigin = 'Anonymous';
632
+ $image.setAttribute('crossorigin', 'anonymous');
633
+ }
634
+ img.src = imageURL;
635
+ var onload = function onload() {
636
+ var $pattern = create$Pattern(document, $def, object, pattern, patternId, img.width, img.height);
637
+ $def.appendChild($pattern);
638
+ $pattern.appendChild($image);
639
+ $image.setAttribute('x', '0');
640
+ $image.setAttribute('y', '0');
641
+ $image.setAttribute('width', "".concat(img.width));
642
+ $image.setAttribute('height', "".concat(img.height));
643
+ };
644
+ if (img.complete) {
645
+ onload();
646
+ } else {
647
+ img.onload = onload;
648
+ // Fix onload() bug in IE9
649
+ // img.src = img.src;
650
+ }
651
+ }
652
+ if (image.nodeName === 'rect') {
653
+ var _parsedStyle = image.parsedStyle,
654
+ width = _parsedStyle.width,
655
+ height = _parsedStyle.height;
656
+ var $pattern = create$Pattern(document, $def, image, pattern, patternId, width, height);
657
+
658
+ // traverse subtree of pattern
659
+ image.forEach(function (object) {
660
+ plugin.createSVGDom(document, object, null);
661
+
662
+ // @ts-ignore
663
+ var svgElement = object.elementSVG;
664
+
665
+ // apply local RTS transformation to <group> wrapper
666
+ var localTransform = object.getLocalTransform();
667
+ plugin.applyTransform(svgElement.$groupEl, localTransform);
668
+ });
669
+
670
+ // @ts-ignore
671
+ var svgElement = image.elementSVG;
672
+ $pattern.appendChild(svgElement.$groupEl);
673
+ }
674
+ }
675
+ return patternId;
676
+ }
677
+ function createOrUpdateGradient(document, object, $def, $el, parsedColor) {
678
+ var bounds = object.getGeometryBounds();
679
+ var width = bounds && bounds.halfExtents[0] * 2 || 0;
680
+ var height = bounds && bounds.halfExtents[1] * 2 || 0;
681
+ var min = bounds && bounds.min || [0, 0];
682
+ var gradientId = generateCacheKey(parsedColor, {
683
+ x: min[0],
684
+ y: min[1],
685
+ width: width,
686
+ height: height
687
+ });
688
+ var $existed = $def.querySelector("#".concat(gradientId));
689
+ if (!$existed) {
690
+ // <linearGradient> <radialGradient>
691
+ // @see https://developer.mozilla.org/zh-CN/docs/Web/SVG/Element/linearGradient
692
+ // @see https://developer.mozilla.org/zh-CN/docs/Web/SVG/Element/radialGradient
693
+ $existed = createSVGElement(parsedColor.type === gLite.GradientType.LinearGradient ? 'linearGradient' : 'radialGradient', document);
694
+ // @see https://github.com/antvis/g/issues/1025
695
+ $existed.setAttribute('gradientUnits', 'userSpaceOnUse');
696
+ // add stops
697
+ var innerHTML = '';
698
+ parsedColor.value.steps
699
+ // sort by offset @see https://github.com/antvis/G/issues/1171
700
+ .sort(function (a, b) {
701
+ return a.offset.value - b.offset.value;
702
+ }).forEach(function (_ref2) {
703
+ var offset = _ref2.offset,
704
+ color = _ref2.color;
705
+ // TODO: support absolute unit like `px`
706
+ innerHTML += "<stop offset=\"".concat(offset.value / 100, "\" stop-color=\"").concat(color, "\"></stop>");
707
+ });
708
+ $existed.innerHTML = innerHTML;
709
+ $existed.id = gradientId;
710
+ $def.appendChild($existed);
711
+ }
712
+ if (parsedColor.type === gLite.GradientType.LinearGradient) {
713
+ var _ref3 = parsedColor.value,
714
+ angle = _ref3.angle;
715
+ var _computeLinearGradien = gLite.computeLinearGradient([min[0], min[1]], width, height, angle),
716
+ x1 = _computeLinearGradien.x1,
717
+ y1 = _computeLinearGradien.y1,
718
+ x2 = _computeLinearGradien.x2,
719
+ y2 = _computeLinearGradien.y2;
720
+ $existed.setAttribute('x1', "".concat(x1));
721
+ $existed.setAttribute('y1', "".concat(y1));
722
+ $existed.setAttribute('x2', "".concat(x2));
723
+ $existed.setAttribute('y2', "".concat(y2));
724
+
725
+ // $existed.setAttribute('gradientTransform', `rotate(${angle})`);
726
+ } else {
727
+ var _ref4 = parsedColor.value,
728
+ cx = _ref4.cx,
729
+ cy = _ref4.cy,
730
+ size = _ref4.size;
731
+ var _computeRadialGradien = gLite.computeRadialGradient([min[0], min[1]], width, height, cx, cy, size),
732
+ x = _computeRadialGradien.x,
733
+ y = _computeRadialGradien.y,
734
+ r = _computeRadialGradien.r;
735
+ $existed.setAttribute('cx', "".concat(x));
736
+ $existed.setAttribute('cy', "".concat(y));
737
+ $existed.setAttribute('r', "".concat(r));
738
+ }
739
+ return gradientId;
740
+ }
741
+ function createOrUpdateMultiGradient(document, object, $def, $el, gradients) {
742
+ var filterId = "".concat(FILTER_PREFIX + object.entity, "-gradient");
743
+ var $existed = $def.querySelector("#".concat(filterId));
744
+ if (!$existed) {
745
+ $existed = createSVGElement('filter', document);
746
+ $existed.setAttribute('filterUnits', 'userSpaceOnUse');
747
+ // @see https://github.com/antvis/g/issues/1025
748
+ $existed.setAttribute('x', '0%');
749
+ $existed.setAttribute('y', '0%');
750
+ $existed.setAttribute('width', '100%');
751
+ $existed.setAttribute('height', '100%');
752
+ $existed.id = filterId;
753
+ $def.appendChild($existed);
754
+ }
755
+
756
+ /**
757
+ * <rect id="wave-rect" x="0" y="0" width="100%" height="100%" fill="url(#wave)"></rect>
758
+ * <filter id="blend-it" x="0%" y="0%" width="100%" height="100%">
759
+ <feImage xlink:href="#wave-rect" result="myWave" x="100" y="100"/>
760
+ <feImage xlink:href="#ry-rect" result="myRY" x="100" y="100"/>
761
+ <feBlend in="myWave" in2="myRY" mode="multiply" result="blendedGrad"/>
762
+ <feComposite in="blendedGrad" in2="SourceGraphic" operator="in"/>
763
+ </filter>
764
+ */
765
+
766
+ var blended = 0;
767
+ gradients.forEach(function (gradient, i) {
768
+ var gradientId = createOrUpdateGradient(document, object, $def, $el, gradient);
769
+ var rectId = "".concat(gradientId, "_rect");
770
+ var $rect = createSVGElement('rect', document);
771
+ $rect.setAttribute('x', '0');
772
+ $rect.setAttribute('y', '0');
773
+ $rect.setAttribute('width', '100%');
774
+ $rect.setAttribute('height', '100%');
775
+ $rect.setAttribute('fill', "url(#".concat(gradientId, ")"));
776
+ $rect.id = rectId;
777
+ $def.appendChild($rect);
778
+ var $feImage = createSVGElement('feImage', document);
779
+ $feImage.setAttribute('href', "#".concat(rectId));
780
+ $feImage.setAttribute('result', "".concat(filterId, "-").concat(i));
781
+ $existed.appendChild($feImage);
782
+ if (i > 0) {
783
+ var $feBlend = createSVGElement('feBlend', document);
784
+ $feBlend.setAttribute('in', i === 1 ? "".concat(filterId, "-").concat(i - 1) : "".concat(filterId, "-blended-").concat(blended - 1));
785
+ $feBlend.setAttribute('in2', "".concat(filterId, "-").concat(i));
786
+ $feBlend.setAttribute('result', "".concat(filterId, "-blended-").concat(blended++));
787
+ // @see https://developer.mozilla.org/zh-CN/docs/Web/CSS/blend-mode
788
+ $feBlend.setAttribute('mode', 'multiply');
789
+ $existed.appendChild($feBlend);
790
+ }
791
+ });
792
+ var $feComposite = createSVGElement('feComposite', document);
793
+ $feComposite.setAttribute('in', "".concat(filterId, "-blended-").concat(blended));
794
+ $feComposite.setAttribute('in2', 'SourceGraphic');
795
+ $feComposite.setAttribute('operator', 'in');
796
+ $existed.appendChild($feComposite);
797
+ return filterId;
798
+ }
799
+
800
+ var FILTER_DROPSHADOW_PREFIX = 'g-filter-dropshadow-';
801
+
802
+ /**
803
+ * use SVG filters
804
+ * @see https://developer.mozilla.org/zh-CN/docs/Web/SVG/Element/filter
805
+ */
806
+ function createOrUpdateShadow(document, $def, object, $el, name) {
807
+ var _object$parsedStyle = object.parsedStyle,
808
+ _object$parsedStyle$s = _object$parsedStyle.shadowType,
809
+ shadowType = _object$parsedStyle$s === void 0 ? 'outer' : _object$parsedStyle$s,
810
+ shadowBlur = _object$parsedStyle.shadowBlur,
811
+ shadowColor = _object$parsedStyle.shadowColor,
812
+ shadowOffsetX = _object$parsedStyle.shadowOffsetX,
813
+ shadowOffsetY = _object$parsedStyle.shadowOffsetY;
814
+ var hasShadow = !util.isNil(shadowColor) && shadowBlur > 0;
815
+ var shadowId = FILTER_DROPSHADOW_PREFIX + object.entity;
816
+ var $existedFilter = $def.querySelector("#".concat(shadowId));
817
+ if ($existedFilter) {
818
+ var existedShadowType = $existedFilter.getAttribute('data-type');
819
+ if (existedShadowType !== shadowType || !hasShadow) {
820
+ // remove existed shadow
821
+ $existedFilter.remove();
822
+ $existedFilter = null;
823
+ }
824
+ }
825
+
826
+ // <Group> also has shadowType as its default value
827
+ // only apply shadow when blur > 0
828
+ if (hasShadow) {
829
+ // use filter <feDropShadow>
830
+ // @see https://developer.mozilla.org/en-US/docs/Web/SVG/Element/feDropShadow
831
+ $el === null || $el === void 0 || $el.setAttribute('filter', "url(#".concat(shadowId, ")"));
832
+ } else {
833
+ $el === null || $el === void 0 || $el.removeAttribute('filter');
834
+ return;
835
+ }
836
+ if (!$existedFilter) {
837
+ $existedFilter = createSVGElement('filter', document);
838
+ $existedFilter.setAttribute('data-type', shadowType);
839
+ if (shadowType === 'outer') {
840
+ var $feDropShadow = createSVGElement('feDropShadow', document);
841
+ $feDropShadow.setAttribute('dx', "".concat((shadowOffsetX || 0) / 2));
842
+ $feDropShadow.setAttribute('dy', "".concat((shadowOffsetY || 0) / 2));
843
+ $feDropShadow.setAttribute('stdDeviation', "".concat((shadowBlur || 0) / 4));
844
+ $feDropShadow.setAttribute('flood-color', shadowColor.toString());
845
+ $existedFilter.appendChild($feDropShadow);
846
+ } else if (shadowType === 'inner') {
847
+ var $feComponentTransfer = createSVGElement('feComponentTransfer', document);
848
+ $feComponentTransfer.setAttribute('in', 'SourceAlpha');
849
+ var $feFuncA = createSVGElement('feFuncA', document);
850
+ $feFuncA.setAttribute('type', 'table');
851
+ $feFuncA.setAttribute('tableValues', '1 0');
852
+ $feComponentTransfer.appendChild($feFuncA);
853
+ $existedFilter.appendChild($feComponentTransfer);
854
+ var $feGaussianBlur = createSVGElement('feGaussianBlur', document);
855
+ $feGaussianBlur.setAttribute('stdDeviation', "".concat((shadowBlur || 0) / 4));
856
+ $existedFilter.appendChild($feGaussianBlur);
857
+ var $feOffset = createSVGElement('feOffset', document);
858
+ $feOffset.setAttribute('dx', "".concat((shadowOffsetX || 0) / 2));
859
+ $feOffset.setAttribute('dy', "".concat((shadowOffsetY || 0) / 2));
860
+ $feOffset.setAttribute('result', 'offsetblur');
861
+ $existedFilter.appendChild($feOffset);
862
+ var $feFlood = createSVGElement('feFlood', document);
863
+ $feFlood.setAttribute('flood-color', shadowColor.toString());
864
+ $feFlood.setAttribute('result', 'color');
865
+ $existedFilter.appendChild($feFlood);
866
+ var $feComposite = createSVGElement('feComposite', document);
867
+ $feComposite.setAttribute('in2', 'offsetblur');
868
+ $feComposite.setAttribute('operator', 'in');
869
+ $existedFilter.appendChild($feComposite);
870
+ var $feComposite2 = createSVGElement('feComposite', document);
871
+ $feComposite2.setAttribute('in2', 'SourceAlpha');
872
+ $feComposite2.setAttribute('operator', 'in');
873
+ $existedFilter.appendChild($feComposite2);
874
+ var $feMerge = createSVGElement('feMerge', document);
875
+ $existedFilter.appendChild($feMerge);
876
+ var $feMergeNode = createSVGElement('feMergeNode', document);
877
+ $feMergeNode.setAttribute('in', 'SourceGraphic');
878
+ var $feMergeNode2 = createSVGElement('feMergeNode', document);
879
+ $feMerge.appendChild($feMergeNode);
880
+ $feMerge.appendChild($feMergeNode2);
881
+ }
882
+ $existedFilter.id = shadowId;
883
+ // @see https://github.com/antvis/g/issues/1025
884
+ $existedFilter.setAttribute('filterUnits', 'userSpaceOnUse');
885
+ $def.appendChild($existedFilter);
886
+ return;
887
+ }
888
+ if (shadowType === 'inner') {
889
+ var _$feGaussianBlur = $existedFilter.children[1];
890
+ var _$feOffset = $existedFilter.children[2];
891
+ var _$feFlood = $existedFilter.children[3];
892
+ if (name === 'shadowColor') {
893
+ _$feFlood.setAttribute('flood-color', shadowColor.toString());
894
+ } else if (name === 'shadowBlur') {
895
+ // half the blur radius
896
+ // @see https://drafts.csswg.org/css-backgrounds/#shadow-blur
897
+ // @see https://css-tricks.com/breaking-css-box-shadow-vs-drop-shadow/
898
+ _$feGaussianBlur.setAttribute('stdDeviation', "".concat((shadowBlur || 0) / 4));
899
+ } else if (name === 'shadowOffsetX') {
900
+ _$feOffset.setAttribute('dx', "".concat((shadowOffsetX || 0) / 2));
901
+ } else if (name === 'shadowOffsetY') {
902
+ _$feOffset.setAttribute('dy', "".concat((shadowOffsetY || 0) / 2));
903
+ }
904
+ } else if (shadowType === 'outer') {
905
+ var _$feDropShadow = $existedFilter.children[0];
906
+ if (name === 'shadowColor') {
907
+ _$feDropShadow.setAttribute('flood-color', shadowColor.toString());
908
+ } else if (name === 'shadowBlur') {
909
+ // half the blur radius
910
+ // @see https://drafts.csswg.org/css-backgrounds/#shadow-blur
911
+ // @see https://css-tricks.com/breaking-css-box-shadow-vs-drop-shadow/
912
+ _$feDropShadow.setAttribute('stdDeviation', "".concat((shadowBlur || 0) / 4));
913
+ } else if (name === 'shadowOffsetX') {
914
+ _$feDropShadow.setAttribute('dx', "".concat((shadowOffsetX || 0) / 2));
915
+ } else if (name === 'shadowOffsetY') {
916
+ _$feDropShadow.setAttribute('dy', "".concat((shadowOffsetY || 0) / 2));
917
+ }
918
+ }
919
+ }
920
+
921
+ var urlRegexp = /url\("?#(.*)\)/;
922
+ var DefElementManager = /*#__PURE__*/function () {
923
+ function DefElementManager(context) {
924
+ _classCallCheck(this, DefElementManager);
925
+ this.gradientCache = {};
926
+ this.context = context;
927
+ }
928
+
929
+ /**
930
+ * container for <gradient> <clipPath>...
931
+ */
932
+ return _createClass(DefElementManager, [{
933
+ key: "getDefElement",
934
+ value: function getDefElement() {
935
+ return this.$def;
936
+ }
937
+ }, {
938
+ key: "init",
939
+ value: function init() {
940
+ var document = this.context.config.document;
941
+ var $svg = this.context.contextService.getContext();
942
+ this.$def = createSVGElement('defs', document);
943
+ $svg.appendChild(this.$def);
944
+ }
945
+ }, {
946
+ key: "clear",
947
+ value: function clear(entity) {
948
+ var _this = this;
949
+ Object.keys(this.gradientCache).forEach(function (id) {
950
+ _this.clearUnusedDefElement(_this.gradientCache, id, entity);
951
+ });
952
+ }
953
+ }, {
954
+ key: "clearUnusedDefElement",
955
+ value: function clearUnusedDefElement(cache, id, entity) {
956
+ if (cache[id] && cache[id].size === 1 && cache[id].has(entity)) {
957
+ var targetElement = this.$def.querySelector("#".concat(id));
958
+ if (targetElement) {
959
+ this.$def.removeChild(targetElement);
960
+ }
961
+ }
962
+ }
963
+ }, {
964
+ key: "createOrUpdateGradientAndPattern",
965
+ value: function createOrUpdateGradientAndPattern$1(object, $el, parsedColor, name, plugin) {
966
+ var _this$context$config = this.context.config,
967
+ doc = _this$context$config.document,
968
+ createImage = _this$context$config.createImage;
969
+ if ($el) {
970
+ var attributeValue = '';
971
+ if (gLite.isPattern(parsedColor)) {
972
+ // `fill: url(#${patternId})`
973
+ attributeValue = $el.style[name];
974
+ } else {
975
+ // `url(#${gradientId})`
976
+ attributeValue = $el.getAttribute(name) || '';
977
+ }
978
+ var matches = attributeValue.match(urlRegexp);
979
+ if (matches && matches.length > 1) {
980
+ this.clearUnusedDefElement(this.gradientCache, matches[1].replace('"', ''), object.entity);
981
+ }
982
+ var newDefElementId = createOrUpdateGradientAndPattern(doc || document, this.$def, object, $el, parsedColor, name, createImage, plugin);
983
+ if (newDefElementId) {
984
+ if (!this.gradientCache[newDefElementId]) {
985
+ this.gradientCache[newDefElementId] = new Set();
986
+ }
987
+ this.gradientCache[newDefElementId].add(object.entity);
988
+ }
989
+ }
990
+ }
991
+ }, {
992
+ key: "createOrUpdateShadow",
993
+ value: function createOrUpdateShadow$1(object, $el, name) {
994
+ var doc = this.context.config.document;
995
+ createOrUpdateShadow(doc || document, this.$def, object, $el, name);
996
+ }
997
+ }, {
998
+ key: "createOrUpdateFilter",
999
+ value: function createOrUpdateFilter$1(object, $el, filters) {
1000
+ var doc = this.context.config.document;
1001
+ createOrUpdateFilter(doc || document, this.$def, object, $el, filters);
1002
+ }
1003
+ }]);
1004
+ }();
1005
+
1006
+ function numberToLongString(x) {
1007
+ return x.toFixed(6).replace('.000000', '');
1008
+ }
1009
+ function convertHTML(str) {
1010
+ var regex = /[&|<|>|"|']/g;
1011
+ return str.replace(regex, function (match) {
1012
+ if (match === '&') {
1013
+ return '&amp;';
1014
+ }
1015
+ if (match === '<') {
1016
+ return '&lt;';
1017
+ }
1018
+ if (match === '>') {
1019
+ return '&gt;';
1020
+ }
1021
+ if (match === '"') {
1022
+ return '&quot;';
1023
+ }
1024
+ return '&apos;';
1025
+ });
1026
+ }
1027
+
1028
+ var SVG_ATTR_MAP = {
1029
+ opacity: 'opacity',
1030
+ fillStyle: 'fill',
1031
+ fill: 'fill',
1032
+ fillRule: 'fill-rule',
1033
+ fillOpacity: 'fill-opacity',
1034
+ strokeStyle: 'stroke',
1035
+ strokeOpacity: 'stroke-opacity',
1036
+ stroke: 'stroke',
1037
+ clipPath: 'clip-path',
1038
+ textPath: 'text-path',
1039
+ r: 'r',
1040
+ cx: 'cx',
1041
+ cy: 'cy',
1042
+ rx: 'rx',
1043
+ ry: 'ry',
1044
+ x: 'x',
1045
+ y: 'y',
1046
+ width: 'width',
1047
+ height: 'height',
1048
+ lineCap: 'stroke-linecap',
1049
+ lineJoin: 'stroke-linejoin',
1050
+ lineWidth: 'stroke-width',
1051
+ lineDash: 'stroke-dasharray',
1052
+ lineDashOffset: 'stroke-dashoffset',
1053
+ miterLimit: 'stroke-miterlimit',
1054
+ font: 'font',
1055
+ fontSize: 'font-size',
1056
+ fontStyle: 'font-style',
1057
+ fontVariant: 'font-variant',
1058
+ fontWeight: 'font-weight',
1059
+ fontFamily: 'font-family',
1060
+ letterSpacing: 'letter-spacing',
1061
+ startArrow: 'marker-start',
1062
+ endArrow: 'marker-end',
1063
+ "class": 'class',
1064
+ id: 'id',
1065
+ // style: 'style',
1066
+ preserveAspectRatio: 'preserveAspectRatio',
1067
+ visibility: 'visibility',
1068
+ shadowColor: 'flood-color',
1069
+ shadowBlur: 'stdDeviation',
1070
+ shadowOffsetX: 'dx',
1071
+ shadowOffsetY: 'dy',
1072
+ filter: 'filter',
1073
+ innerHTML: 'innerHTML',
1074
+ textAlign: 'text-anchor',
1075
+ pointerEvents: 'pointer-events'
1076
+ };
1077
+ var FORMAT_VALUE_MAP = {
1078
+ textAlign: {
1079
+ inherit: 'inherit',
1080
+ left: 'left',
1081
+ start: 'left',
1082
+ center: 'middle',
1083
+ right: 'end',
1084
+ end: 'end'
1085
+ }
1086
+ };
1087
+ var DEFAULT_VALUE_MAP = {
1088
+ textAlign: 'inherit',
1089
+ // textBaseline: 'alphabetic',
1090
+ // @see https://www.w3.org/TR/SVG/painting.html#LineCaps
1091
+ lineCap: 'butt',
1092
+ // @see https://www.w3.org/TR/SVG/painting.html#LineJoin
1093
+ lineJoin: 'miter',
1094
+ // @see https://developer.mozilla.org/zh-CN/docs/Web/SVG/Attribute/stroke-width
1095
+ lineWidth: '1px',
1096
+ opacity: '1',
1097
+ fillOpacity: '1',
1098
+ fillRule: 'nonzero',
1099
+ strokeOpacity: '1',
1100
+ strokeWidth: '0',
1101
+ strokeMiterLimit: '4',
1102
+ letterSpacing: '0',
1103
+ fontSize: 'inherit',
1104
+ fontFamily: 'inherit',
1105
+ pointerEvents: 'auto',
1106
+ transform: 'matrix(1,0,0,1,0,0)'
1107
+ };
1108
+ /**
1109
+ * G_SVG_PREFIX + nodeName + entity
1110
+ *
1111
+ * eg. g_svg_circle_345
1112
+ */
1113
+ var G_SVG_PREFIX = 'g-svg';
1114
+ var CLIP_PATH_PREFIX = 'clip-path-';
1115
+ var TEXT_PATH_PREFIX = 'text-path-';
1116
+ var SVGRendererPlugin = /*#__PURE__*/function () {
1117
+ function SVGRendererPlugin(pluginOptions, defElementManager, context) {
1118
+ _classCallCheck(this, SVGRendererPlugin);
1119
+ /**
1120
+ * Will be used in svg-picker for finding relative SVG element of current DisplayObject.
1121
+ */
1122
+ this.svgElementMap = new WeakMap();
1123
+ /**
1124
+ * render at the end of frame
1125
+ */
1126
+ this.renderQueue = [];
1127
+ /**
1128
+ * dirty attributes at the end of frame
1129
+ */
1130
+ this.dirtyAttributes = new WeakMap();
1131
+ /**
1132
+ * reorder after mounted
1133
+ */
1134
+ this.pendingReorderQueue = new Set();
1135
+ /**
1136
+ * <use> elements in <clipPath>, which should be sync with clipPath
1137
+ *
1138
+ * @example
1139
+ * <clipPath transform="matrix(1,0,0,1,-100,-155)" id="clip-path-0-2">
1140
+ * <use href="#g_svg_circle_0" transform="matrix(1.477115,0,0,1.477115,150,150)">
1141
+ * </use>
1142
+ * </clipPath>
1143
+ */
1144
+ this.clipPathUseMap = new WeakMap();
1145
+ this.pluginOptions = pluginOptions;
1146
+ this.defElementManager = defElementManager;
1147
+ this.context = context;
1148
+ }
1149
+ return _createClass(SVGRendererPlugin, [{
1150
+ key: "apply",
1151
+ value: function apply(context) {
1152
+ var _this = this;
1153
+ var renderingService = context.renderingService,
1154
+ renderingContext = context.renderingContext;
1155
+ this.context = context;
1156
+ // @ts-ignore
1157
+ this.context.svgElementMap = this.svgElementMap;
1158
+ var canvas = renderingContext.root.ownerDocument.defaultView;
1159
+ var document = this.context.config.document;
1160
+ var handleMounted = function handleMounted(e) {
1161
+ var object = e.target;
1162
+
1163
+ // should remove clipPath already existed in <defs>
1164
+ var $useRefs = _this.clipPathUseMap.get(object);
1165
+ if ($useRefs) {
1166
+ var $def = _this.defElementManager.getDefElement();
1167
+ var existed = $def.querySelector("#".concat(_this.getId(object)));
1168
+ if (existed) {
1169
+ existed.remove();
1170
+ }
1171
+ }
1172
+
1173
+ // create SVG DOM Node
1174
+ _this.createSVGDom(document, object, _this.$camera);
1175
+ };
1176
+ var handleUnmounted = function handleUnmounted(e) {
1177
+ var object = e.target;
1178
+ _this.defElementManager.clear(object.entity);
1179
+ _this.clipPathUseMap["delete"](object);
1180
+ _this.removeSVGDom(object);
1181
+ };
1182
+ var reorderChildren = function reorderChildren(object) {
1183
+ var _object$parentNode;
1184
+ var parent = object.parentNode;
1185
+ // @ts-ignore
1186
+ var $groupEl = (_object$parentNode = object.parentNode) === null || _object$parentNode === void 0 || (_object$parentNode = _object$parentNode.elementSVG) === null || _object$parentNode === void 0 ? void 0 : _object$parentNode.$groupEl;
1187
+ var children = ((parent === null || parent === void 0 ? void 0 : parent.children) || []).slice();
1188
+ if ($groupEl) {
1189
+ _this.reorderChildren(document, $groupEl, children);
1190
+ }
1191
+ };
1192
+ var handleReparent = function handleReparent(e) {
1193
+ var object = e.target;
1194
+ reorderChildren(object);
1195
+ };
1196
+ var handleAttributeChanged = function handleAttributeChanged(e) {
1197
+ var object = e.target;
1198
+
1199
+ // @see https://github.com/antvis/g/issues/994
1200
+ // @ts-ignore
1201
+ if (!object.elementSVG) {
1202
+ return;
1203
+ }
1204
+ var attrName = e.attrName;
1205
+ var attribtues = _this.dirtyAttributes.get(object);
1206
+ if (!attribtues) {
1207
+ _this.dirtyAttributes.set(object, []);
1208
+ attribtues = _this.dirtyAttributes.get(object);
1209
+ }
1210
+ attribtues.push(attrName);
1211
+ };
1212
+ var handleGeometryBoundsChanged = function handleGeometryBoundsChanged(e) {
1213
+ var records = e.detail;
1214
+ var _loop = function _loop() {
1215
+ var record = records[i];
1216
+ var object = record.target;
1217
+ var nodes = object.nodeName === gLite.Shape.FRAGMENT ? object.childNodes : [object];
1218
+ nodes.forEach(function (node) {
1219
+ var _object$elementSVG;
1220
+ // @ts-ignore
1221
+ var $el = (_object$elementSVG = object.elementSVG) === null || _object$elementSVG === void 0 ? void 0 : _object$elementSVG.$el;
1222
+ var _object$parsedStyle = object.parsedStyle,
1223
+ fill = _object$parsedStyle.fill,
1224
+ stroke = _object$parsedStyle.stroke,
1225
+ clipPath = _object$parsedStyle.clipPath;
1226
+ if (fill && !gLite.isCSSRGB(fill)) {
1227
+ _this.defElementManager.createOrUpdateGradientAndPattern(object, $el, fill, 'fill', _this);
1228
+ }
1229
+ if (stroke && !gLite.isCSSRGB(stroke)) {
1230
+ _this.defElementManager.createOrUpdateGradientAndPattern(object, $el, stroke, 'stroke', _this);
1231
+ }
1232
+ if (clipPath) {
1233
+ var parentInvert = glMatrix.mat4.invert(glMatrix.mat4.create(), object.getWorldTransform());
1234
+ var clipPathId = "".concat(CLIP_PATH_PREFIX + clipPath.entity, "-").concat(object.entity);
1235
+ var $def = _this.defElementManager.getDefElement();
1236
+ var $existed = $def.querySelector("#".concat(clipPathId));
1237
+ if ($existed) {
1238
+ _this.applyTransform($existed, parentInvert);
1239
+ }
1240
+ }
1241
+ });
1242
+ };
1243
+ for (var i = 0; i < records.length; i++) {
1244
+ _loop();
1245
+ }
1246
+ };
1247
+ renderingService.hooks.init.tap(SVGRendererPlugin.tag, function () {
1248
+ var _this$context$config = _this.context.config,
1249
+ background = _this$context$config.background,
1250
+ document = _this$context$config.document;
1251
+
1252
+ // <defs>
1253
+ _this.defElementManager.init();
1254
+ var $svg = _this.context.contextService.getContext();
1255
+ if (background) {
1256
+ $svg.style.background = background;
1257
+ }
1258
+
1259
+ // @see https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/color-interpolation-filters
1260
+ $svg.setAttribute('color-interpolation-filters', 'sRGB');
1261
+ _this.$camera = createSVGElement('g', document);
1262
+ _this.$camera.id = "".concat(G_SVG_PREFIX, "-camera");
1263
+ _this.applyTransform(_this.$camera, _this.context.camera.getOrthoMatrix());
1264
+ $svg.appendChild(_this.$camera);
1265
+ canvas.addEventListener(gLite.ElementEvent.MOUNTED, handleMounted);
1266
+ canvas.addEventListener(gLite.ElementEvent.UNMOUNTED, handleUnmounted);
1267
+ canvas.addEventListener(gLite.ElementEvent.REPARENT, handleReparent);
1268
+ canvas.addEventListener(gLite.ElementEvent.ATTR_MODIFIED, handleAttributeChanged);
1269
+ canvas.addEventListener(gLite.ElementEvent.BOUNDS_CHANGED, handleGeometryBoundsChanged);
1270
+ });
1271
+ renderingService.hooks.destroy.tap(SVGRendererPlugin.tag, function () {
1272
+ canvas.removeEventListener(gLite.ElementEvent.MOUNTED, handleMounted);
1273
+ canvas.removeEventListener(gLite.ElementEvent.UNMOUNTED, handleUnmounted);
1274
+ canvas.removeEventListener(gLite.ElementEvent.REPARENT, handleReparent);
1275
+ canvas.removeEventListener(gLite.ElementEvent.ATTR_MODIFIED, handleAttributeChanged);
1276
+ canvas.removeEventListener(gLite.ElementEvent.BOUNDS_CHANGED, handleGeometryBoundsChanged);
1277
+ resetPatternCounter();
1278
+ });
1279
+ renderingService.hooks.render.tap(SVGRendererPlugin.tag, function (object) {
1280
+ _this.renderQueue.push(object);
1281
+ });
1282
+ renderingService.hooks.beginFrame.tap(SVGRendererPlugin.tag, function () {
1283
+ var doc = _this.context.config.document;
1284
+ if (_this.pendingReorderQueue.size) {
1285
+ _this.pendingReorderQueue.forEach(function (object) {
1286
+ var _object$elementSVG2;
1287
+ var children = ((object === null || object === void 0 ? void 0 : object.children) || []).slice();
1288
+ var $parentGroupEl = // @ts-ignore
1289
+ object === null || object === void 0 || (_object$elementSVG2 = object.elementSVG) === null || _object$elementSVG2 === void 0 ? void 0 : _object$elementSVG2.$groupEl;
1290
+ if ($parentGroupEl) {
1291
+ _this.reorderChildren(doc || document, $parentGroupEl, children || []);
1292
+ }
1293
+ });
1294
+ _this.pendingReorderQueue.clear();
1295
+ }
1296
+ });
1297
+ renderingService.hooks.endFrame.tap(SVGRendererPlugin.tag, function () {
1298
+ if (renderingContext.renderReasons.has(gLite.RenderReason.CAMERA_CHANGED)) {
1299
+ _this.applyTransform(_this.$camera, _this.context.camera.getOrthoMatrix());
1300
+ }
1301
+ _this.renderQueue.forEach(function (object) {
1302
+ var _elementSVG, _elementSVG2;
1303
+ var $el = (_elementSVG = object.elementSVG) === null || _elementSVG === void 0 ? void 0 : _elementSVG.$el;
1304
+ var $groupEl = (_elementSVG2 = object.elementSVG) === null || _elementSVG2 === void 0 ? void 0 : _elementSVG2.$groupEl;
1305
+ if ($el && $groupEl) {
1306
+ // apply local RTS transformation to <group> wrapper
1307
+ // account for anchor
1308
+ var localTransform = object.getLocalTransform();
1309
+ _this.applyTransform($groupEl, localTransform);
1310
+
1311
+ // clipped shapes should also be informed
1312
+
1313
+ var $useRefs = _this.clipPathUseMap.get(object);
1314
+ if ($useRefs && $useRefs.length) {
1315
+ $useRefs.forEach(function ($use) {
1316
+ // <clipPath transform="matrix()"><circle /></clipPath>
1317
+ _this.applyTransform($use, object.getWorldTransform());
1318
+ // const parentInvert = mat4.invert(
1319
+ // mat4.create(),
1320
+ // (object as DisplayObject).getWorldTransform(),
1321
+ // );
1322
+ // this.applyTransform($clipPath, parentInvert);
1323
+ });
1324
+ }
1325
+
1326
+ // finish rendering, clear dirty flag
1327
+ object.renderable.dirty = false;
1328
+ }
1329
+
1330
+ // update dirty attributes
1331
+ var attributes = _this.dirtyAttributes.get(object);
1332
+ if (attributes) {
1333
+ attributes.forEach(function (attrName) {
1334
+ if (attrName === 'zIndex') {
1335
+ reorderChildren(object);
1336
+ } else if (attrName === 'increasedLineWidthForHitTesting') {
1337
+ _this.createOrUpdateHitArea(object, $el, $groupEl);
1338
+ }
1339
+ _this.updateAttribute(object, [attrName]);
1340
+ });
1341
+ _this.dirtyAttributes["delete"](object);
1342
+ }
1343
+ });
1344
+ _this.renderQueue = [];
1345
+ });
1346
+ }
1347
+ }, {
1348
+ key: "getId",
1349
+ value: function getId(object) {
1350
+ return object.id || "".concat(G_SVG_PREFIX, "-").concat(object.entity);
1351
+ }
1352
+ }, {
1353
+ key: "reorderChildren",
1354
+ value: function reorderChildren(doc, $groupEl, children) {
1355
+ // need to reorder parent's children
1356
+ children.sort(function (a, b) {
1357
+ return a.sortable.renderOrder - b.sortable.renderOrder;
1358
+ });
1359
+ if (children.length) {
1360
+ // create empty fragment
1361
+ var fragment = (doc || document).createDocumentFragment();
1362
+ children.forEach(function (child) {
1363
+ if (child.isConnected) {
1364
+ var $el = child.elementSVG.$groupEl;
1365
+ if ($el) {
1366
+ fragment.appendChild($el);
1367
+ }
1368
+ }
1369
+ });
1370
+ $groupEl.appendChild(fragment);
1371
+ }
1372
+ }
1373
+ }, {
1374
+ key: "applyTransform",
1375
+ value: function applyTransform($el, rts) {
1376
+ var matrix = "matrix(".concat(numberToLongString(rts[0]), ",").concat(numberToLongString(rts[1]), ",").concat(numberToLongString(rts[4]), ",").concat(numberToLongString(rts[5]), ",").concat(numberToLongString(rts[12]), ",").concat(numberToLongString(rts[13]), ")");
1377
+ if (matrix !== $el.getAttribute('transform')) {
1378
+ // use proper precision avoiding too long string in `transform`
1379
+ // @see https://developer.mozilla.org/en-US/docs/Web/API/Canvas_API/Tutorial/Transformations
1380
+ $el.setAttribute('transform', matrix);
1381
+ }
1382
+ if (matrix === DEFAULT_VALUE_MAP.transform) {
1383
+ $el.removeAttribute('transform');
1384
+ }
1385
+ }
1386
+ }, {
1387
+ key: "applyAttributes",
1388
+ value: function applyAttributes(object) {
1389
+ var elementSVG = object.elementSVG;
1390
+ var $el = elementSVG === null || elementSVG === void 0 ? void 0 : elementSVG.$el;
1391
+ var $groupEl = elementSVG === null || elementSVG === void 0 ? void 0 : elementSVG.$groupEl;
1392
+ if ($el && $groupEl) {
1393
+ var nodeName = object.nodeName,
1394
+ attributes = object.attributes;
1395
+ if (nodeName !== gLite.Shape.HTML) {
1396
+ $el.setAttribute('fill', 'none');
1397
+ }
1398
+ if (nodeName === gLite.Shape.IMAGE) {
1399
+ $el.setAttribute('preserveAspectRatio', 'none');
1400
+ }
1401
+
1402
+ // apply attributes
1403
+ this.updateAttribute(object, Object.keys(attributes));
1404
+ }
1405
+ }
1406
+ }, {
1407
+ key: "updateAttribute",
1408
+ value: function updateAttribute(object, attributes) {
1409
+ var _this2 = this;
1410
+ var document = this.context.config.document;
1411
+ var _ref = object.elementSVG,
1412
+ $el = _ref.$el,
1413
+ $hitTestingEl = _ref.$hitTestingEl;
1414
+ var parsedStyle = object.parsedStyle,
1415
+ nodeName = object.nodeName;
1416
+ var shouldUpdateElementAttribute = attributes.some(function (name) {
1417
+ return (
1418
+ // @ts-ignore
1419
+ _this2.context.SVGElementLifeCycleContribution.shouldUpdateElementAttribute(object, name)
1420
+ );
1421
+ });
1422
+
1423
+ // need re-generate path
1424
+ if (shouldUpdateElementAttribute && $el) {
1425
+ [$el, $hitTestingEl].forEach(function ($el) {
1426
+ if ($el) {
1427
+ // @ts-ignore
1428
+ _this2.context.SVGElementLifeCycleContribution.updateElementAttribute(object, $el, _this2.svgElementMap);
1429
+ }
1430
+ });
1431
+ }
1432
+
1433
+ // update common attributes
1434
+ attributes.forEach(function (name) {
1435
+ var _FORMAT_VALUE_MAP$nam, _propertyMetadataCach;
1436
+ var usedName = SVG_ATTR_MAP[name];
1437
+ var computedValue = parsedStyle[name];
1438
+ var computedValueStr = !util.isNil(computedValue) && computedValue.toString();
1439
+ var formattedValueStr = ((_FORMAT_VALUE_MAP$nam = FORMAT_VALUE_MAP[name]) === null || _FORMAT_VALUE_MAP$nam === void 0 ? void 0 : _FORMAT_VALUE_MAP$nam[computedValueStr]) || computedValueStr;
1440
+ var usedValue = parsedStyle[name];
1441
+ var inherited = usedName && !!((_propertyMetadataCach = gLite.propertyMetadataCache[name]) !== null && _propertyMetadataCach !== void 0 && _propertyMetadataCach.inh);
1442
+
1443
+ // <foreignObject>
1444
+ if (nodeName === gLite.Shape.HTML) {
1445
+ if (name === 'fill') {
1446
+ $el.style.background = usedValue.toString();
1447
+ } else if (name === 'stroke') {
1448
+ $el.style['border-color'] = usedValue.toString();
1449
+ $el.style['border-style'] = 'solid';
1450
+ } else if (name === 'lineWidth') {
1451
+ $el.style['border-width'] = "".concat(usedValue || 0, "px");
1452
+ } else if (name === 'lineDash') {
1453
+ $el.style['border-style'] = 'dashed';
1454
+ } else if (name === 'innerHTML') {
1455
+ _this2.createOrUpdateInnerHTML(document, $el, usedValue);
1456
+ } else if (name === 'width' || name === 'height' || name === 'class' || name === 'x' || name === 'y') {
1457
+ // width & height are both required for <foreignObject> and cannot be used as style.
1458
+ $el.setAttribute(name, usedValue.toString());
1459
+ } else if (!util.isNil(object.style[name]) && object.style[name] !== '') {
1460
+ $el.style[name] = object.style[name];
1461
+ }
1462
+ } else {
1463
+ if (!usedName || (nodeName === gLite.Shape.GROUP || object.isCustomElement) && (inherited || usedName === 'fill' || usedName === 'stroke')) {
1464
+ return;
1465
+ }
1466
+ if (name === 'fill') {
1467
+ _this2.defElementManager.createOrUpdateGradientAndPattern(object, $el, usedValue, usedName, _this2);
1468
+ } else if (name === 'stroke') {
1469
+ _this2.defElementManager.createOrUpdateGradientAndPattern(object, $el, usedValue, usedName, _this2);
1470
+ } else if (name === 'clipPath') {
1471
+ _this2.createOrUpdateClipOrTextPath(document, usedValue, object);
1472
+ } else if (name === 'textPath') {
1473
+ _this2.createOrUpdateClipOrTextPath(document, usedValue, object, true);
1474
+ } else if (name === 'shadowType' || name === 'shadowColor' || name === 'shadowBlur' || name === 'shadowOffsetX' || name === 'shadowOffsetY') {
1475
+ _this2.defElementManager.createOrUpdateShadow(object, $el, name);
1476
+ } else if (name === 'filter') {
1477
+ _this2.defElementManager.createOrUpdateFilter(object, $el, usedValue);
1478
+ } else if (!util.isNil(computedValue)) {
1479
+ // use computed value so that we can use cascaded effect in SVG
1480
+ // ignore 'unset' and default value
1481
+ [$el, $hitTestingEl].forEach(function ($el) {
1482
+ if ($el && usedName) {
1483
+ if (computedValueStr !== 'unset' && computedValueStr !== DEFAULT_VALUE_MAP[name]) {
1484
+ $el.setAttribute(usedName, formattedValueStr);
1485
+ } else {
1486
+ $el.removeAttribute(usedName);
1487
+ }
1488
+ }
1489
+ });
1490
+ }
1491
+ }
1492
+ });
1493
+ }
1494
+ }, {
1495
+ key: "createSVGDom",
1496
+ value: function createSVGDom(document, object, root) {
1497
+ var noWrapWithGroup = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
1498
+ // create svg element
1499
+ // @ts-ignore
1500
+ object.elementSVG = new ElementSVG();
1501
+ // @ts-ignore
1502
+ var svgElement = object.elementSVG;
1503
+
1504
+ // use <group> as default, eg. CustomElement
1505
+ var $el =
1506
+ // @ts-ignore
1507
+ this.context.SVGElementLifeCycleContribution.createElement(object, this.svgElementMap);
1508
+ if ($el) {
1509
+ var _object$parentNode$el;
1510
+ var $groupEl;
1511
+
1512
+ // save $el on parsedStyle, which will be returned in getDomElement()
1513
+ if (object.nodeName === gLite.Shape.HTML) {
1514
+ object.parsedStyle.$el = $el;
1515
+ }
1516
+ if (this.pluginOptions.outputSVGElementId) {
1517
+ // use user-defined id first.
1518
+ $el.id = this.getId(object);
1519
+ }
1520
+ if (this.pluginOptions.outputSVGElementName && object.name) {
1521
+ $el.setAttribute('name', object.name);
1522
+ }
1523
+ if (($el.hasAttribute('data-wrapgroup') || $el.nodeName !== 'g') && !noWrapWithGroup) {
1524
+ $groupEl = createSVGElement('g', document);
1525
+ // if (this.pluginOptions.outputSVGElementId) {
1526
+ // $groupEl.id = $el.id + '-g';
1527
+ // }
1528
+ $groupEl.appendChild($el);
1529
+ } else {
1530
+ $groupEl = $el;
1531
+ }
1532
+ svgElement.$el = $el;
1533
+ svgElement.$groupEl = $groupEl;
1534
+
1535
+ // apply attributes at first time
1536
+ this.applyAttributes(object);
1537
+
1538
+ // create hitArea if necessary
1539
+ this.createOrUpdateHitArea(object, $el, $groupEl);
1540
+ var $parentGroupEl = root ||
1541
+ // @ts-ignore
1542
+ object.parentNode && ((_object$parentNode$el = object.parentNode.elementSVG) === null || _object$parentNode$el === void 0 ? void 0 : _object$parentNode$el.$groupEl);
1543
+ if ($parentGroupEl) {
1544
+ $parentGroupEl.appendChild($groupEl);
1545
+
1546
+ // need reorder children later
1547
+ this.pendingReorderQueue.add(object.parentNode);
1548
+ }
1549
+ }
1550
+ }
1551
+ }, {
1552
+ key: "removeSVGDom",
1553
+ value: function removeSVGDom(object) {
1554
+ var _object$elementSVG3;
1555
+ // @ts-ignore
1556
+ var $groupEl = (_object$elementSVG3 = object.elementSVG) === null || _object$elementSVG3 === void 0 ? void 0 : _object$elementSVG3.$groupEl;
1557
+ if ($groupEl && $groupEl.parentNode) {
1558
+ $groupEl.parentNode.removeChild($groupEl);
1559
+
1560
+ // @ts-ignore
1561
+ this.context.SVGElementLifeCycleContribution.destroyElement(object, $groupEl);
1562
+ // object.entity.removeComponent(ElementSVG, true);
1563
+ }
1564
+ }
1565
+ }, {
1566
+ key: "createOrUpdateHitArea",
1567
+ value: function createOrUpdateHitArea(object, $el, $groupEl) {
1568
+ var svgElement = object.elementSVG;
1569
+ var $hitTestingEl = svgElement.$hitTestingEl;
1570
+ var increasedLineWidthForHitTesting = Number(object.parsedStyle.increasedLineWidthForHitTesting);
1571
+
1572
+ // account for hitArea
1573
+ if (increasedLineWidthForHitTesting) {
1574
+ if (!$hitTestingEl) {
1575
+ $hitTestingEl = $el.cloneNode();
1576
+ // clear attributes like `filter` `font-size`
1577
+ ['filter'].forEach(function (attribute) {
1578
+ $hitTestingEl.removeAttribute(attribute);
1579
+ });
1580
+ // hitArea should be 'transparent' but not 'none'
1581
+ var hasFill = $el.getAttribute('fill') !== 'none';
1582
+ $hitTestingEl.setAttribute('fill', hasFill ? 'transparent' : 'none');
1583
+ $hitTestingEl.setAttribute('stroke', 'transparent');
1584
+ $groupEl.appendChild($hitTestingEl);
1585
+ svgElement.$hitTestingEl = $hitTestingEl;
1586
+
1587
+ // svg-picker will use this map to find target object
1588
+ this.svgElementMap.set($hitTestingEl, object);
1589
+ }
1590
+
1591
+ // increase interactive line width
1592
+ $hitTestingEl.setAttribute('stroke-width', "".concat(increasedLineWidthForHitTesting + object.parsedStyle.lineWidth));
1593
+ } else if ($hitTestingEl) {
1594
+ $groupEl.removeChild($hitTestingEl);
1595
+ svgElement.$hitTestingEl = null;
1596
+ }
1597
+ }
1598
+ }, {
1599
+ key: "createOrUpdateInnerHTML",
1600
+ value: function createOrUpdateInnerHTML(doc, $el, usedValue) {
1601
+ var $div = (doc || document).createElement('div');
1602
+ if (typeof usedValue === 'string') {
1603
+ $div.innerHTML = usedValue;
1604
+ } else {
1605
+ $div.appendChild(usedValue);
1606
+ }
1607
+ $el.innerHTML = '';
1608
+ $el.appendChild($div);
1609
+ }
1610
+ }, {
1611
+ key: "createOrUpdateClipOrTextPath",
1612
+ value: function createOrUpdateClipOrTextPath(document, clipPath, object) {
1613
+ var isTextPath = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
1614
+ var _ref2 = object.elementSVG,
1615
+ $groupEl = _ref2.$groupEl;
1616
+ var PREFIX = isTextPath ? TEXT_PATH_PREFIX : CLIP_PATH_PREFIX;
1617
+ var attributeNameCamel = isTextPath ? 'g' : 'clipPath';
1618
+ var attributeNameHyphen = isTextPath ? 'text-path' : 'clip-path';
1619
+ if (clipPath) {
1620
+ var clipPathId = "".concat(PREFIX + clipPath.entity, "-").concat(object.entity);
1621
+ var $def = this.defElementManager.getDefElement();
1622
+ var existed = $def.querySelector("#".concat(clipPathId));
1623
+ if (!existed) {
1624
+ var $clipPath;
1625
+ if (isTextPath) {
1626
+ // use <path> directly instead of wrapping with <g>
1627
+ this.createSVGDom(document, clipPath, null, true);
1628
+ // @ts-ignore
1629
+ $clipPath = clipPath.elementSVG.$el;
1630
+ } else {
1631
+ // the clipPath is allowed to be detached from canvas
1632
+ if (!clipPath.isConnected) {
1633
+ var $existedClipPath = $def.querySelector("#".concat(this.getId(clipPath)));
1634
+ if (!$existedClipPath) {
1635
+ this.createSVGDom(document, clipPath, $def, true);
1636
+ }
1637
+ }
1638
+
1639
+ // create <clipPath> dom node
1640
+ $clipPath = createSVGElement(attributeNameCamel, document);
1641
+ var $use = createSVGElement('use', document);
1642
+ // @ts-ignore
1643
+ $use.setAttribute('href', "#".concat(clipPath.elementSVG.$el.id));
1644
+ $clipPath.appendChild($use);
1645
+ var $useRefs = this.clipPathUseMap.get(clipPath);
1646
+ if (!$useRefs) {
1647
+ this.clipPathUseMap.set(clipPath, []);
1648
+ $useRefs = this.clipPathUseMap.get(clipPath);
1649
+ }
1650
+ $useRefs.push($use);
1651
+
1652
+ // <clipPath transform="matrix()"><circle /></clipPath>
1653
+ this.applyTransform($use, clipPath.getWorldTransform());
1654
+ var parentInvert = glMatrix.mat4.invert(glMatrix.mat4.create(), object.getWorldTransform());
1655
+ this.applyTransform($clipPath, parentInvert);
1656
+ }
1657
+ if (this.pluginOptions.outputSVGElementId) {
1658
+ $clipPath.id = clipPathId;
1659
+ }
1660
+ // append it to <defs>
1661
+ $def.appendChild($clipPath);
1662
+ }
1663
+
1664
+ // apply attributes
1665
+ this.applyAttributes(clipPath);
1666
+ if (!isTextPath) {
1667
+ // apply clipPath to $group
1668
+ // @see https://github.com/antvis/g/issues/961
1669
+ $groupEl.setAttribute(attributeNameHyphen, "url(#".concat(clipPathId, ")"));
1670
+ }
1671
+ } else if (!isTextPath) {
1672
+ // remove clip path
1673
+ $groupEl.removeAttribute(attributeNameHyphen);
1674
+ }
1675
+ }
1676
+ }]);
1677
+ }();
1678
+ SVGRendererPlugin.tag = 'SVGRenderer';
1679
+
1680
+ // @see https://github.com/plouc/nivo/issues/164
1681
+ var BASELINE_MAP = {
1682
+ top: 'hanging',
1683
+ // Use hanging here.
1684
+ middle: 'central',
1685
+ bottom: 'text-after-edge',
1686
+ // FIXME: It is not a standard property.
1687
+ alphabetic: 'alphabetic',
1688
+ ideographic: 'ideographic',
1689
+ hanging: 'hanging'
1690
+ };
1691
+ function updateTextElementAttribute($el, parsedStyle, text, runtime) {
1692
+ // Trigger text geometry calculation.
1693
+ text.getBounds();
1694
+ var _parsedStyle$lineWidt = parsedStyle.lineWidth,
1695
+ lineWidth = _parsedStyle$lineWidt === void 0 ? 1 : _parsedStyle$lineWidt,
1696
+ _parsedStyle$x = parsedStyle.x,
1697
+ x = _parsedStyle$x === void 0 ? 0 : _parsedStyle$x,
1698
+ _parsedStyle$y = parsedStyle.y,
1699
+ y = _parsedStyle$y === void 0 ? 0 : _parsedStyle$y,
1700
+ _parsedStyle$dx = parsedStyle.dx,
1701
+ dx = _parsedStyle$dx === void 0 ? 0 : _parsedStyle$dx,
1702
+ _parsedStyle$dy = parsedStyle.dy,
1703
+ dy = _parsedStyle$dy === void 0 ? 0 : _parsedStyle$dy,
1704
+ textPath = parsedStyle.textPath,
1705
+ _parsedStyle$textPath = parsedStyle.textPathSide,
1706
+ textPathSide = _parsedStyle$textPath === void 0 ? 'left' : _parsedStyle$textPath,
1707
+ _parsedStyle$textPath2 = parsedStyle.textPathStartOffset,
1708
+ textPathStartOffset = _parsedStyle$textPath2 === void 0 ? 0 : _parsedStyle$textPath2,
1709
+ _parsedStyle$textDeco = parsedStyle.textDecorationLine,
1710
+ textDecorationLine = _parsedStyle$textDeco === void 0 ? '' : _parsedStyle$textDeco,
1711
+ _parsedStyle$textDeco2 = parsedStyle.textDecorationColor,
1712
+ textDecorationColor = _parsedStyle$textDeco2 === void 0 ? '' : _parsedStyle$textDeco2,
1713
+ _parsedStyle$textDeco3 = parsedStyle.textDecorationStyle,
1714
+ textDecorationStyle = _parsedStyle$textDeco3 === void 0 ? '' : _parsedStyle$textDeco3,
1715
+ _parsedStyle$textDeco4 = parsedStyle.textDecorationThickness,
1716
+ textDecorationThickness = _parsedStyle$textDeco4 === void 0 ? 1 : _parsedStyle$textDeco4,
1717
+ metrics = parsedStyle.metrics;
1718
+ var _parsedStyle$textBase = parsedStyle.textBaseline,
1719
+ textBaseline = _parsedStyle$textBase === void 0 ? 'alphabetic' : _parsedStyle$textBase;
1720
+ if (textBaseline === 'alphabetic') {
1721
+ textBaseline = 'bottom';
1722
+ }
1723
+ $el.setAttribute('dominant-baseline', BASELINE_MAP[textBaseline]);
1724
+ $el.setAttribute('paint-order', 'stroke');
1725
+ var lines = metrics.lines,
1726
+ lineHeight = metrics.lineHeight,
1727
+ height = metrics.height;
1728
+ var lineNum = lines.length;
1729
+ var styleCSSText = "transform:translate(".concat(dx, "px, ").concat(dy, "px);");
1730
+ if (textDecorationLine && textDecorationLine !== 'none') {
1731
+ // Use CSS text-decoration for basic support
1732
+ styleCSSText += "text-decoration:".concat(textDecorationLine, " ").concat(textDecorationStyle, " ").concat(textDecorationColor, ";text-decoration-thickness:").concat(textDecorationThickness, ";");
1733
+ }
1734
+ if (styleCSSText) {
1735
+ $el.setAttribute('style', styleCSSText);
1736
+ }
1737
+ if (x !== 0) {
1738
+ $el.setAttribute('x', "".concat(x));
1739
+ }
1740
+ if (y !== 0) {
1741
+ $el.setAttribute('y', "".concat(y));
1742
+ }
1743
+ if (lineNum === 1) {
1744
+ var textContent = convertHTML(lines[0]);
1745
+ $el.setAttribute('dx', "".concat(lineWidth / 2));
1746
+
1747
+ // Since `text-after-edge` is not a standard property value, we use `dy` instead.
1748
+ if (textBaseline === 'bottom' || textBaseline === 'top') {
1749
+ $el.setAttribute('dominant-baseline', BASELINE_MAP.middle);
1750
+ $el.setAttribute('dy', textBaseline === 'bottom' ? "-".concat(height / 2, "px") : "".concat(height / 2, "px"));
1751
+ } else {
1752
+ $el.setAttribute('dy', '0px');
1753
+ }
1754
+
1755
+ // <textPath> only support one line
1756
+ // @see https://developer.mozilla.org/en-US/docs/Web/SVG/Element/textPath
1757
+ if (textPath) {
1758
+ // clear existed text content first
1759
+ $el.innerHTML = '';
1760
+
1761
+ // append <textPath href="#MyPath">text</textPath>
1762
+ var $textPath = createSVGElement('textPath', $el.ownerDocument);
1763
+ $textPath.setAttribute('href', "#".concat(TEXT_PATH_PREFIX + textPath.entity));
1764
+ if (textPathSide !== 'left') {
1765
+ $textPath.setAttribute('side', textPathSide);
1766
+ }
1767
+ if (textPathStartOffset !== 0) {
1768
+ $textPath.setAttribute('startOffset', "".concat(textPathStartOffset));
1769
+ }
1770
+ $textPath.innerHTML = textContent;
1771
+ $el.appendChild($textPath);
1772
+ } else {
1773
+ $el.innerHTML = textContent;
1774
+ }
1775
+ } else {
1776
+ $el.innerHTML = lines.map(function (line, i) {
1777
+ var dx = lineWidth / 2;
1778
+ var dy = 0;
1779
+ if (i === 0) {
1780
+ // TODO: handle other textBaseline values
1781
+ if (textBaseline === 'middle') {
1782
+ dy = lineHeight / 2 - height / 2;
1783
+ } else if (textBaseline === 'top' || textBaseline === 'hanging') {
1784
+ dy = 0;
1785
+ } else if (textBaseline === 'bottom' || textBaseline === 'ideographic') {
1786
+ dy = -lineHeight * (lineNum - 1);
1787
+ }
1788
+ } else {
1789
+ dy = lineHeight;
1790
+ }
1791
+ return "<tspan x=".concat(x, " dx=\"").concat(dx, "\" dy=\"").concat(dy, "\">").concat(convertHTML(line), "</tspan>");
1792
+ }).join('');
1793
+ }
1794
+ }
1795
+
1796
+ var _SHAPE2TAGS;
1797
+ var SHAPE2TAGS = (_SHAPE2TAGS = {}, _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_SHAPE2TAGS, gLite.Shape.RECT, 'path'), gLite.Shape.CIRCLE, 'circle'), gLite.Shape.ELLIPSE, 'ellipse'), gLite.Shape.IMAGE, 'image'), gLite.Shape.GROUP, 'g'), gLite.Shape.LINE, 'line'), gLite.Shape.POLYLINE, 'polyline'), gLite.Shape.POLYGON, 'polygon'), gLite.Shape.TEXT, 'text'), gLite.Shape.PATH, 'path'), _defineProperty(_SHAPE2TAGS, gLite.Shape.HTML, 'foreignObject'));
1798
+ var SHAPE_UPDATE_DEPS = _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty({}, gLite.Shape.CIRCLE, ['cx', 'cy', 'r']), gLite.Shape.ELLIPSE, ['cx', 'cy', 'rx', 'ry']), gLite.Shape.RECT, ['x', 'y', 'width', 'height', 'radius']), gLite.Shape.IMAGE, ['x', 'y', 'src', 'width', 'height']), gLite.Shape.LINE, ['x1', 'y1', 'x2', 'y2', 'markerStart', 'markerEnd', 'markerStartOffset', 'markerEndOffset']), gLite.Shape.POLYLINE, ['points', 'markerStart', 'markerEnd', 'markerMid', 'markerStartOffset', 'markerEndOffset']), gLite.Shape.POLYGON, ['points', 'markerStart', 'markerEnd', 'markerMid', 'markerStartOffset', 'markerEndOffset']), gLite.Shape.PATH, ['d', 'markerStart', 'markerEnd', 'markerMid', 'markerStartOffset', 'markerEndOffset']), gLite.Shape.TEXT, ['text', 'font', 'fontSize', 'fontFamily', 'fontStyle', 'fontWeight', 'fontVariant', 'lineHeight', 'letterSpacing', 'wordWrap', 'wordWrapWidth', 'maxLines', 'leading', 'textBaseline', 'textAlign', 'textTransform', 'textOverflow', 'textPath', 'textPathSide', 'textPathStartOffset', 'textDecorationLine', 'textDecorationColor', 'textDecorationStyle',
1799
+ // 'whiteSpace',
1800
+ 'dx', 'dy']);
1801
+ var DefaultElementLifeCycleContribution = /*#__PURE__*/function () {
1802
+ function DefaultElementLifeCycleContribution(context, runtime) {
1803
+ _classCallCheck(this, DefaultElementLifeCycleContribution);
1804
+ this.context = context;
1805
+ this.runtime = runtime;
1806
+ }
1807
+ return _createClass(DefaultElementLifeCycleContribution, [{
1808
+ key: "createElement",
1809
+ value: function createElement(object, svgElementMap) {
1810
+ var doc = this.context.config.document;
1811
+ var type = SHAPE2TAGS[object.nodeName] || 'g';
1812
+ var $el = createSVGElement(type, doc || document);
1813
+ svgElementMap.set($el, object);
1814
+ return $el;
1815
+ }
1816
+ }, {
1817
+ key: "destroyElement",
1818
+ value: function destroyElement(object, $el) {}
1819
+ }, {
1820
+ key: "shouldUpdateElementAttribute",
1821
+ value: function shouldUpdateElementAttribute(object, attributeName) {
1822
+ var nodeName = object.nodeName;
1823
+ return (SHAPE_UPDATE_DEPS[nodeName] || []).indexOf(attributeName) > -1;
1824
+ }
1825
+ }, {
1826
+ key: "updateElementAttribute",
1827
+ value: function updateElementAttribute(object) {
1828
+ // @ts-ignore
1829
+ var _ref = object.elementSVG,
1830
+ $el = _ref.$el;
1831
+ var nodeName = object.nodeName,
1832
+ parsedStyle = object.parsedStyle;
1833
+ switch (nodeName) {
1834
+ case gLite.Shape.IMAGE:
1835
+ {
1836
+ updateImageElementAttribute($el, parsedStyle);
1837
+ break;
1838
+ }
1839
+ case gLite.Shape.RECT:
1840
+ {
1841
+ updateRectElementAttribute($el, parsedStyle);
1842
+ break;
1843
+ }
1844
+ case gLite.Shape.LINE:
1845
+ {
1846
+ updateLineElementAttribute($el, parsedStyle);
1847
+ break;
1848
+ }
1849
+ case gLite.Shape.POLYGON:
1850
+ case gLite.Shape.POLYLINE:
1851
+ {
1852
+ updatePolylineElementAttribute($el, parsedStyle);
1853
+ break;
1854
+ }
1855
+ case gLite.Shape.PATH:
1856
+ {
1857
+ updatePathElementAttribute($el, parsedStyle);
1858
+ break;
1859
+ }
1860
+ case gLite.Shape.TEXT:
1861
+ {
1862
+ updateTextElementAttribute($el, parsedStyle, object, this.runtime);
1863
+ break;
1864
+ }
1865
+ }
1866
+ }
1867
+ }]);
1868
+ }();
1869
+
1870
+ var Plugin$1 = /*#__PURE__*/function (_AbstractRendererPlug) {
1871
+ function Plugin() {
1872
+ var _this;
1873
+ var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
1874
+ _classCallCheck(this, Plugin);
1875
+ _this = _callSuper(this, Plugin);
1876
+ _this.name = 'svg-renderer';
1877
+ _this.options = options;
1878
+ return _this;
1879
+ }
1880
+ _inherits(Plugin, _AbstractRendererPlug);
1881
+ return _createClass(Plugin, [{
1882
+ key: "init",
1883
+ value: function init(runtime) {
1884
+ var _this$options = this.options,
1885
+ outputSVGElementId = _this$options.outputSVGElementId,
1886
+ outputSVGElementName = _this$options.outputSVGElementName;
1887
+ var defElementManager = new DefElementManager(this.context);
1888
+
1889
+ // default implementation
1890
+ var defaultElementLifeCycleContribution = new DefaultElementLifeCycleContribution(this.context, runtime);
1891
+ // @ts-ignore
1892
+ this.context.defaultElementLifeCycleContribution = defaultElementLifeCycleContribution;
1893
+
1894
+ // @ts-ignore
1895
+ this.context.SVGElementLifeCycleContribution = defaultElementLifeCycleContribution;
1896
+ var SVGRendererPluginOptions = {
1897
+ outputSVGElementId: !util.isNil(outputSVGElementId) ? !!outputSVGElementId : true,
1898
+ outputSVGElementName: !util.isNil(outputSVGElementName) ? !!outputSVGElementName : true
1899
+ };
1900
+ this.addRenderingPlugin(
1901
+ // @ts-ignore
1902
+ new SVGRendererPlugin(SVGRendererPluginOptions, defElementManager, this.context));
1903
+ }
1904
+ }, {
1905
+ key: "destroy",
1906
+ value: function destroy() {
1907
+ this.removeAllRenderingPlugins();
1908
+
1909
+ // @ts-ignore
1910
+ delete this.context.defaultElementLifeCycleContribution;
1911
+ // @ts-ignore
1912
+ delete this.context.SVGElementLifeCycleContribution;
1913
+ }
1914
+ }]);
1915
+ }(gLite.AbstractRendererPlugin);
1916
+
1917
+ var index$1 = /*#__PURE__*/Object.freeze({
1918
+ __proto__: null,
1919
+ CLIP_PATH_PREFIX: CLIP_PATH_PREFIX,
1920
+ DEFAULT_VALUE_MAP: DEFAULT_VALUE_MAP,
1921
+ DefaultElementLifeCycleContribution: DefaultElementLifeCycleContribution,
1922
+ ElementSVG: ElementSVG,
1923
+ G_SVG_PREFIX: G_SVG_PREFIX,
1924
+ Plugin: Plugin$1,
1925
+ SHAPE2TAGS: SHAPE2TAGS,
1926
+ SHAPE_UPDATE_DEPS: SHAPE_UPDATE_DEPS,
1927
+ SVGRendererPlugin: SVGRendererPlugin,
1928
+ SVG_ATTR_MAP: SVG_ATTR_MAP,
1929
+ TEXT_PATH_PREFIX: TEXT_PATH_PREFIX,
1930
+ createSVGElement: createSVGElement,
1931
+ updateImageElementAttribute: updateImageElementAttribute,
1932
+ updateLineElementAttribute: updateLineElementAttribute,
1933
+ updatePathElementAttribute: updatePathElementAttribute,
1934
+ updatePolylineElementAttribute: updatePolylineElementAttribute,
1935
+ updateRectElementAttribute: updateRectElementAttribute,
1936
+ updateTextElementAttribute: updateTextElementAttribute
1937
+ });
1938
+
1939
+ /**
1940
+ * pick shape(s) with Mouse/Touch event
1941
+ *
1942
+ * 1. find AABB with r-tree
1943
+ * 2. use elementFromPoint
1944
+ */
1945
+ var SVGPickerPlugin = /*#__PURE__*/function () {
1946
+ function SVGPickerPlugin() {
1947
+ _classCallCheck(this, SVGPickerPlugin);
1948
+ }
1949
+ return _createClass(SVGPickerPlugin, [{
1950
+ key: "apply",
1951
+ value: function apply(context, runtime) {
1952
+ var _this = this;
1953
+ var doc = context.config.document,
1954
+ renderingService = context.renderingService,
1955
+ svgElementMap = context.svgElementMap;
1956
+ renderingService.hooks.pick.tapPromise(SVGPickerPlugin.tag, /*#__PURE__*/function () {
1957
+ var _ref = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(result) {
1958
+ return _regeneratorRuntime().wrap(function (_context) {
1959
+ while (1) switch (_context.prev = _context.next) {
1960
+ case 0:
1961
+ return _context.abrupt("return", _this.pick(svgElementMap, doc, result));
1962
+ case 1:
1963
+ case "end":
1964
+ return _context.stop();
1965
+ }
1966
+ }, _callee);
1967
+ }));
1968
+ return function (_x) {
1969
+ return _ref.apply(this, arguments);
1970
+ };
1971
+ }());
1972
+ renderingService.hooks.pickSync.tap(SVGPickerPlugin.tag, function (result) {
1973
+ return _this.pick(svgElementMap, doc, result);
1974
+ });
1975
+ }
1976
+ }, {
1977
+ key: "pick",
1978
+ value: function pick(svgElementMap, doc, result) {
1979
+ var topmost = result.topmost,
1980
+ _result$position = result.position,
1981
+ clientX = _result$position.clientX,
1982
+ clientY = _result$position.clientY;
1983
+ try {
1984
+ var targets = [];
1985
+ // @see https://developer.mozilla.org/zh-CN/docs/Web/API/Document/elementsFromPoint
1986
+ var _iterator = _createForOfIteratorHelper((doc || document).elementsFromPoint(clientX, clientY)),
1987
+ _step;
1988
+ try {
1989
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
1990
+ var element = _step.value;
1991
+ if (element.shadowRoot && element.shadowRoot !== doc) {
1992
+ return this.pick(svgElementMap, element.shadowRoot, result);
1993
+ }
1994
+ var target = svgElementMap.get(element);
1995
+ // don't need to account for `visibility` since DOM API already does
1996
+ if (target && target.isInteractive()) {
1997
+ targets.push(target);
1998
+ if (topmost) {
1999
+ result.picked = targets;
2000
+ return result;
2001
+ }
2002
+ }
2003
+ }
2004
+ } catch (err) {
2005
+ _iterator.e(err);
2006
+ } finally {
2007
+ _iterator.f();
2008
+ }
2009
+ result.picked = targets;
2010
+ } catch (_unused) {
2011
+ result.picked = [];
2012
+ }
2013
+ return result;
2014
+ }
2015
+ }]);
2016
+ }();
2017
+ SVGPickerPlugin.tag = 'SVGPicker';
2018
+
2019
+ var Plugin = /*#__PURE__*/function (_AbstractRendererPlug) {
2020
+ function Plugin() {
2021
+ var _this;
2022
+ _classCallCheck(this, Plugin);
2023
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
2024
+ args[_key] = arguments[_key];
2025
+ }
2026
+ _this = _callSuper(this, Plugin, [].concat(args));
2027
+ _this.name = 'svg-picker';
2028
+ return _this;
2029
+ }
2030
+ _inherits(Plugin, _AbstractRendererPlug);
2031
+ return _createClass(Plugin, [{
2032
+ key: "init",
2033
+ value: function init() {
2034
+ this.addRenderingPlugin(new SVGPickerPlugin());
2035
+ }
2036
+ }, {
2037
+ key: "destroy",
2038
+ value: function destroy() {
2039
+ this.removeAllRenderingPlugins();
2040
+ }
2041
+ }]);
2042
+ }(gLite.AbstractRendererPlugin);
40
2043
 
41
- var DomInteraction__namespace = /*#__PURE__*/_interopNamespaceDefault(DomInteraction);
42
- var SVGPicker__namespace = /*#__PURE__*/_interopNamespaceDefault(SVGPicker);
43
- var SVGRenderer__namespace = /*#__PURE__*/_interopNamespaceDefault(SVGRenderer);
2044
+ var index = /*#__PURE__*/Object.freeze({
2045
+ __proto__: null,
2046
+ Plugin: Plugin
2047
+ });
44
2048
 
45
2049
  var _excluded = ["offset", "composite", "computedOffset", "easing"],
46
2050
  _excluded2 = ["offset", "composite", "computedOffset", "easing", "transformOrigin"],
@@ -66,7 +2070,7 @@ var SVGContextService = /*#__PURE__*/function () {
66
2070
  if (!this.$container.style.position) {
67
2071
  this.$container.style.position = 'relative';
68
2072
  }
69
- var $namespace = SVGRenderer.createSVGElement('svg', doc);
2073
+ var $namespace = createSVGElement('svg', doc);
70
2074
  $namespace.setAttribute('width', "".concat(this.canvasConfig.width));
71
2075
  $namespace.setAttribute('height', "".concat(this.canvasConfig.height));
72
2076
  this.$container.appendChild($namespace);
@@ -306,19 +2310,24 @@ var Renderer = /*#__PURE__*/function (_AbstractRenderer) {
306
2310
  _classCallCheck(this, Renderer);
307
2311
  _this = _callSuper(this, Renderer, [config]);
308
2312
  _this.registerPlugin(new ContextRegisterPlugin());
309
- _this.registerPlugin(new SVGRenderer__namespace.Plugin({
2313
+ _this.registerPlugin(new Plugin$1({
310
2314
  outputSVGElementId: config.outputSVGElementId
311
2315
  }));
312
- _this.registerPlugin(new DomInteraction__namespace.Plugin());
313
- _this.registerPlugin(new SVGPicker__namespace.Plugin());
2316
+ _this.registerPlugin(new gLite.DomInteraction.Plugin());
2317
+ _this.registerPlugin(new Plugin());
314
2318
  return _this;
315
2319
  }
316
2320
  _inherits(Renderer, _AbstractRenderer);
317
2321
  return _createClass(Renderer);
318
2322
  }(gLite.AbstractRenderer);
319
2323
 
320
- exports.DomInteraction = DomInteraction__namespace;
321
- exports.SVGPicker = SVGPicker__namespace;
322
- exports.SVGRenderer = SVGRenderer__namespace;
2324
+ Object.defineProperty(exports, 'DomInteraction', {
2325
+ enumerable: true,
2326
+ get: function () { return gLite.DomInteraction; }
2327
+ });
2328
+ exports.G_SVG_PREFIX = G_SVG_PREFIX;
323
2329
  exports.Renderer = Renderer;
2330
+ exports.SVGPicker = index;
2331
+ exports.SVGRenderer = index$1;
2332
+ exports.createSVGElement = createSVGElement;
324
2333
  //# sourceMappingURL=index.js.map