@antv/g-svg 1.1.5 → 1.1.8-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.umd.js CHANGED
@@ -4,6 +4,387 @@
4
4
  (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory((global.G = global.G || {}, global.G.SVG = {}), global.window.G, global.window.G.ManaSyringe));
5
5
  }(this, (function (exports, g, manaSyringe) { 'use strict';
6
6
 
7
+ function _regeneratorRuntime() {
8
+ /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */
9
+
10
+ _regeneratorRuntime = function () {
11
+ return exports;
12
+ };
13
+
14
+ var exports = {},
15
+ Op = Object.prototype,
16
+ hasOwn = Op.hasOwnProperty,
17
+ $Symbol = "function" == typeof Symbol ? Symbol : {},
18
+ iteratorSymbol = $Symbol.iterator || "@@iterator",
19
+ asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator",
20
+ toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag";
21
+
22
+ function define(obj, key, value) {
23
+ return Object.defineProperty(obj, key, {
24
+ value: value,
25
+ enumerable: !0,
26
+ configurable: !0,
27
+ writable: !0
28
+ }), obj[key];
29
+ }
30
+
31
+ try {
32
+ define({}, "");
33
+ } catch (err) {
34
+ define = function (obj, key, value) {
35
+ return obj[key] = value;
36
+ };
37
+ }
38
+
39
+ function wrap(innerFn, outerFn, self, tryLocsList) {
40
+ var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator,
41
+ generator = Object.create(protoGenerator.prototype),
42
+ context = new Context(tryLocsList || []);
43
+ return generator._invoke = function (innerFn, self, context) {
44
+ var state = "suspendedStart";
45
+ return function (method, arg) {
46
+ if ("executing" === state) throw new Error("Generator is already running");
47
+
48
+ if ("completed" === state) {
49
+ if ("throw" === method) throw arg;
50
+ return doneResult();
51
+ }
52
+
53
+ for (context.method = method, context.arg = arg;;) {
54
+ var delegate = context.delegate;
55
+
56
+ if (delegate) {
57
+ var delegateResult = maybeInvokeDelegate(delegate, context);
58
+
59
+ if (delegateResult) {
60
+ if (delegateResult === ContinueSentinel) continue;
61
+ return delegateResult;
62
+ }
63
+ }
64
+
65
+ if ("next" === context.method) context.sent = context._sent = context.arg;else if ("throw" === context.method) {
66
+ if ("suspendedStart" === state) throw state = "completed", context.arg;
67
+ context.dispatchException(context.arg);
68
+ } else "return" === context.method && context.abrupt("return", context.arg);
69
+ state = "executing";
70
+ var record = tryCatch(innerFn, self, context);
71
+
72
+ if ("normal" === record.type) {
73
+ if (state = context.done ? "completed" : "suspendedYield", record.arg === ContinueSentinel) continue;
74
+ return {
75
+ value: record.arg,
76
+ done: context.done
77
+ };
78
+ }
79
+
80
+ "throw" === record.type && (state = "completed", context.method = "throw", context.arg = record.arg);
81
+ }
82
+ };
83
+ }(innerFn, self, context), generator;
84
+ }
85
+
86
+ function tryCatch(fn, obj, arg) {
87
+ try {
88
+ return {
89
+ type: "normal",
90
+ arg: fn.call(obj, arg)
91
+ };
92
+ } catch (err) {
93
+ return {
94
+ type: "throw",
95
+ arg: err
96
+ };
97
+ }
98
+ }
99
+
100
+ exports.wrap = wrap;
101
+ var ContinueSentinel = {};
102
+
103
+ function Generator() {}
104
+
105
+ function GeneratorFunction() {}
106
+
107
+ function GeneratorFunctionPrototype() {}
108
+
109
+ var IteratorPrototype = {};
110
+ define(IteratorPrototype, iteratorSymbol, function () {
111
+ return this;
112
+ });
113
+ var getProto = Object.getPrototypeOf,
114
+ NativeIteratorPrototype = getProto && getProto(getProto(values([])));
115
+ NativeIteratorPrototype && NativeIteratorPrototype !== Op && hasOwn.call(NativeIteratorPrototype, iteratorSymbol) && (IteratorPrototype = NativeIteratorPrototype);
116
+ var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(IteratorPrototype);
117
+
118
+ function defineIteratorMethods(prototype) {
119
+ ["next", "throw", "return"].forEach(function (method) {
120
+ define(prototype, method, function (arg) {
121
+ return this._invoke(method, arg);
122
+ });
123
+ });
124
+ }
125
+
126
+ function AsyncIterator(generator, PromiseImpl) {
127
+ function invoke(method, arg, resolve, reject) {
128
+ var record = tryCatch(generator[method], generator, arg);
129
+
130
+ if ("throw" !== record.type) {
131
+ var result = record.arg,
132
+ value = result.value;
133
+ return value && "object" == typeof value && hasOwn.call(value, "__await") ? PromiseImpl.resolve(value.__await).then(function (value) {
134
+ invoke("next", value, resolve, reject);
135
+ }, function (err) {
136
+ invoke("throw", err, resolve, reject);
137
+ }) : PromiseImpl.resolve(value).then(function (unwrapped) {
138
+ result.value = unwrapped, resolve(result);
139
+ }, function (error) {
140
+ return invoke("throw", error, resolve, reject);
141
+ });
142
+ }
143
+
144
+ reject(record.arg);
145
+ }
146
+
147
+ var previousPromise;
148
+
149
+ this._invoke = function (method, arg) {
150
+ function callInvokeWithMethodAndArg() {
151
+ return new PromiseImpl(function (resolve, reject) {
152
+ invoke(method, arg, resolve, reject);
153
+ });
154
+ }
155
+
156
+ return previousPromise = previousPromise ? previousPromise.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg();
157
+ };
158
+ }
159
+
160
+ function maybeInvokeDelegate(delegate, context) {
161
+ var method = delegate.iterator[context.method];
162
+
163
+ if (undefined === method) {
164
+ if (context.delegate = null, "throw" === context.method) {
165
+ if (delegate.iterator.return && (context.method = "return", context.arg = undefined, maybeInvokeDelegate(delegate, context), "throw" === context.method)) return ContinueSentinel;
166
+ context.method = "throw", context.arg = new TypeError("The iterator does not provide a 'throw' method");
167
+ }
168
+
169
+ return ContinueSentinel;
170
+ }
171
+
172
+ var record = tryCatch(method, delegate.iterator, context.arg);
173
+ if ("throw" === record.type) return context.method = "throw", context.arg = record.arg, context.delegate = null, ContinueSentinel;
174
+ var info = record.arg;
175
+ return info ? info.done ? (context[delegate.resultName] = info.value, context.next = delegate.nextLoc, "return" !== context.method && (context.method = "next", context.arg = undefined), context.delegate = null, ContinueSentinel) : info : (context.method = "throw", context.arg = new TypeError("iterator result is not an object"), context.delegate = null, ContinueSentinel);
176
+ }
177
+
178
+ function pushTryEntry(locs) {
179
+ var entry = {
180
+ tryLoc: locs[0]
181
+ };
182
+ 1 in locs && (entry.catchLoc = locs[1]), 2 in locs && (entry.finallyLoc = locs[2], entry.afterLoc = locs[3]), this.tryEntries.push(entry);
183
+ }
184
+
185
+ function resetTryEntry(entry) {
186
+ var record = entry.completion || {};
187
+ record.type = "normal", delete record.arg, entry.completion = record;
188
+ }
189
+
190
+ function Context(tryLocsList) {
191
+ this.tryEntries = [{
192
+ tryLoc: "root"
193
+ }], tryLocsList.forEach(pushTryEntry, this), this.reset(!0);
194
+ }
195
+
196
+ function values(iterable) {
197
+ if (iterable) {
198
+ var iteratorMethod = iterable[iteratorSymbol];
199
+ if (iteratorMethod) return iteratorMethod.call(iterable);
200
+ if ("function" == typeof iterable.next) return iterable;
201
+
202
+ if (!isNaN(iterable.length)) {
203
+ var i = -1,
204
+ next = function next() {
205
+ for (; ++i < iterable.length;) if (hasOwn.call(iterable, i)) return next.value = iterable[i], next.done = !1, next;
206
+
207
+ return next.value = undefined, next.done = !0, next;
208
+ };
209
+
210
+ return next.next = next;
211
+ }
212
+ }
213
+
214
+ return {
215
+ next: doneResult
216
+ };
217
+ }
218
+
219
+ function doneResult() {
220
+ return {
221
+ value: undefined,
222
+ done: !0
223
+ };
224
+ }
225
+
226
+ return GeneratorFunction.prototype = GeneratorFunctionPrototype, define(Gp, "constructor", GeneratorFunctionPrototype), define(GeneratorFunctionPrototype, "constructor", GeneratorFunction), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, toStringTagSymbol, "GeneratorFunction"), exports.isGeneratorFunction = function (genFun) {
227
+ var ctor = "function" == typeof genFun && genFun.constructor;
228
+ return !!ctor && (ctor === GeneratorFunction || "GeneratorFunction" === (ctor.displayName || ctor.name));
229
+ }, exports.mark = function (genFun) {
230
+ return Object.setPrototypeOf ? Object.setPrototypeOf(genFun, GeneratorFunctionPrototype) : (genFun.__proto__ = GeneratorFunctionPrototype, define(genFun, toStringTagSymbol, "GeneratorFunction")), genFun.prototype = Object.create(Gp), genFun;
231
+ }, exports.awrap = function (arg) {
232
+ return {
233
+ __await: arg
234
+ };
235
+ }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, asyncIteratorSymbol, function () {
236
+ return this;
237
+ }), exports.AsyncIterator = AsyncIterator, exports.async = function (innerFn, outerFn, self, tryLocsList, PromiseImpl) {
238
+ void 0 === PromiseImpl && (PromiseImpl = Promise);
239
+ var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList), PromiseImpl);
240
+ return exports.isGeneratorFunction(outerFn) ? iter : iter.next().then(function (result) {
241
+ return result.done ? result.value : iter.next();
242
+ });
243
+ }, defineIteratorMethods(Gp), define(Gp, toStringTagSymbol, "Generator"), define(Gp, iteratorSymbol, function () {
244
+ return this;
245
+ }), define(Gp, "toString", function () {
246
+ return "[object Generator]";
247
+ }), exports.keys = function (object) {
248
+ var keys = [];
249
+
250
+ for (var key in object) keys.push(key);
251
+
252
+ return keys.reverse(), function next() {
253
+ for (; keys.length;) {
254
+ var key = keys.pop();
255
+ if (key in object) return next.value = key, next.done = !1, next;
256
+ }
257
+
258
+ return next.done = !0, next;
259
+ };
260
+ }, exports.values = values, Context.prototype = {
261
+ constructor: Context,
262
+ reset: function (skipTempReset) {
263
+ if (this.prev = 0, this.next = 0, this.sent = this._sent = undefined, this.done = !1, this.delegate = null, this.method = "next", this.arg = undefined, this.tryEntries.forEach(resetTryEntry), !skipTempReset) for (var name in this) "t" === name.charAt(0) && hasOwn.call(this, name) && !isNaN(+name.slice(1)) && (this[name] = undefined);
264
+ },
265
+ stop: function () {
266
+ this.done = !0;
267
+ var rootRecord = this.tryEntries[0].completion;
268
+ if ("throw" === rootRecord.type) throw rootRecord.arg;
269
+ return this.rval;
270
+ },
271
+ dispatchException: function (exception) {
272
+ if (this.done) throw exception;
273
+ var context = this;
274
+
275
+ function handle(loc, caught) {
276
+ return record.type = "throw", record.arg = exception, context.next = loc, caught && (context.method = "next", context.arg = undefined), !!caught;
277
+ }
278
+
279
+ for (var i = this.tryEntries.length - 1; i >= 0; --i) {
280
+ var entry = this.tryEntries[i],
281
+ record = entry.completion;
282
+ if ("root" === entry.tryLoc) return handle("end");
283
+
284
+ if (entry.tryLoc <= this.prev) {
285
+ var hasCatch = hasOwn.call(entry, "catchLoc"),
286
+ hasFinally = hasOwn.call(entry, "finallyLoc");
287
+
288
+ if (hasCatch && hasFinally) {
289
+ if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0);
290
+ if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc);
291
+ } else if (hasCatch) {
292
+ if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0);
293
+ } else {
294
+ if (!hasFinally) throw new Error("try statement without catch or finally");
295
+ if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc);
296
+ }
297
+ }
298
+ }
299
+ },
300
+ abrupt: function (type, arg) {
301
+ for (var i = this.tryEntries.length - 1; i >= 0; --i) {
302
+ var entry = this.tryEntries[i];
303
+
304
+ if (entry.tryLoc <= this.prev && hasOwn.call(entry, "finallyLoc") && this.prev < entry.finallyLoc) {
305
+ var finallyEntry = entry;
306
+ break;
307
+ }
308
+ }
309
+
310
+ finallyEntry && ("break" === type || "continue" === type) && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc && (finallyEntry = null);
311
+ var record = finallyEntry ? finallyEntry.completion : {};
312
+ return record.type = type, record.arg = arg, finallyEntry ? (this.method = "next", this.next = finallyEntry.finallyLoc, ContinueSentinel) : this.complete(record);
313
+ },
314
+ complete: function (record, afterLoc) {
315
+ if ("throw" === record.type) throw record.arg;
316
+ return "break" === record.type || "continue" === record.type ? this.next = record.arg : "return" === record.type ? (this.rval = this.arg = record.arg, this.method = "return", this.next = "end") : "normal" === record.type && afterLoc && (this.next = afterLoc), ContinueSentinel;
317
+ },
318
+ finish: function (finallyLoc) {
319
+ for (var i = this.tryEntries.length - 1; i >= 0; --i) {
320
+ var entry = this.tryEntries[i];
321
+ if (entry.finallyLoc === finallyLoc) return this.complete(entry.completion, entry.afterLoc), resetTryEntry(entry), ContinueSentinel;
322
+ }
323
+ },
324
+ catch: function (tryLoc) {
325
+ for (var i = this.tryEntries.length - 1; i >= 0; --i) {
326
+ var entry = this.tryEntries[i];
327
+
328
+ if (entry.tryLoc === tryLoc) {
329
+ var record = entry.completion;
330
+
331
+ if ("throw" === record.type) {
332
+ var thrown = record.arg;
333
+ resetTryEntry(entry);
334
+ }
335
+
336
+ return thrown;
337
+ }
338
+ }
339
+
340
+ throw new Error("illegal catch attempt");
341
+ },
342
+ delegateYield: function (iterable, resultName, nextLoc) {
343
+ return this.delegate = {
344
+ iterator: values(iterable),
345
+ resultName: resultName,
346
+ nextLoc: nextLoc
347
+ }, "next" === this.method && (this.arg = undefined), ContinueSentinel;
348
+ }
349
+ }, exports;
350
+ }
351
+
352
+ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
353
+ try {
354
+ var info = gen[key](arg);
355
+ var value = info.value;
356
+ } catch (error) {
357
+ reject(error);
358
+ return;
359
+ }
360
+
361
+ if (info.done) {
362
+ resolve(value);
363
+ } else {
364
+ Promise.resolve(value).then(_next, _throw);
365
+ }
366
+ }
367
+
368
+ function _asyncToGenerator(fn) {
369
+ return function () {
370
+ var self = this,
371
+ args = arguments;
372
+ return new Promise(function (resolve, reject) {
373
+ var gen = fn.apply(self, args);
374
+
375
+ function _next(value) {
376
+ asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
377
+ }
378
+
379
+ function _throw(err) {
380
+ asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
381
+ }
382
+
383
+ _next(undefined);
384
+ });
385
+ };
386
+ }
387
+
7
388
  function _inheritsLoose(subClass, superClass) {
8
389
  subClass.prototype = Object.create(superClass.prototype);
9
390
  subClass.prototype.constructor = subClass;
@@ -46,9 +427,9 @@
46
427
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(metadataKey, metadataValue);
47
428
  }
48
429
 
49
- function _regeneratorRuntime() {
430
+ function _regeneratorRuntime$1() {
50
431
  /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */
51
- _regeneratorRuntime = function _regeneratorRuntime() {
432
+ _regeneratorRuntime$1 = function _regeneratorRuntime() {
52
433
  return exports;
53
434
  };
54
435
 
@@ -396,7 +777,7 @@
396
777
  }, exports;
397
778
  }
398
779
 
399
- function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
780
+ function asyncGeneratorStep$1(gen, resolve, reject, _next, _throw, key, arg) {
400
781
  try {
401
782
  var info = gen[key](arg);
402
783
  var value = info.value;
@@ -412,7 +793,7 @@
412
793
  }
413
794
  }
414
795
 
415
- function _asyncToGenerator(fn) {
796
+ function _asyncToGenerator$1(fn) {
416
797
  return function () {
417
798
  var self = this,
418
799
  args = arguments;
@@ -420,11 +801,11 @@
420
801
  var gen = fn.apply(self, args);
421
802
 
422
803
  function _next(value) {
423
- asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
804
+ asyncGeneratorStep$1(gen, resolve, reject, _next, _throw, "next", value);
424
805
  }
425
806
 
426
807
  function _throw(err) {
427
- asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
808
+ asyncGeneratorStep$1(gen, resolve, reject, _next, _throw, "throw", err);
428
809
  }
429
810
 
430
811
  _next(undefined);
@@ -525,9 +906,9 @@
525
906
  globalThis.removeEventListener('mouseup', onPointerUp, true);
526
907
  };
527
908
 
528
- renderingService.hooks.init.tapPromise(DOMInteractionPlugin_1.tag, /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
909
+ renderingService.hooks.init.tapPromise(DOMInteractionPlugin_1.tag, /*#__PURE__*/_asyncToGenerator$1( /*#__PURE__*/_regeneratorRuntime$1().mark(function _callee() {
529
910
  var $el;
530
- return _regeneratorRuntime().wrap(function _callee$(_context) {
911
+ return _regeneratorRuntime$1().wrap(function _callee$(_context) {
531
912
  while (1) {
532
913
  switch (_context.prev = _context.next) {
533
914
  case 0:
@@ -834,165 +1215,149 @@
834
1215
 
835
1216
  ElementSVG.tag = 'c-svg-element';
836
1217
 
837
- var RectRenderer = /*#__PURE__*/function () {
838
- function RectRenderer() {
839
- this.dependencies = ['radius', 'width', 'height'];
840
- }
841
-
842
- var _proto = RectRenderer.prototype;
843
-
844
- _proto.apply = function apply($el, parsedStyle) {
845
- var radius = parsedStyle.radius,
846
- width = parsedStyle.width,
847
- height = parsedStyle.height;
848
- var hasRadius = radius && radius.some(function (r) {
849
- return r.value !== 0;
850
- });
851
- var d = '';
852
-
853
- if (!hasRadius) {
854
- d = "M 0,0 l " + width.value + ",0 l 0," + height.value + " l" + -width.value + " 0 z";
855
- } else {
856
- var _radius$map = radius.map(function (r) {
857
- return r.value;
858
- }),
859
- tlr = _radius$map[0],
860
- trr = _radius$map[1],
861
- brr = _radius$map[2],
862
- blr = _radius$map[3];
863
-
864
- d = [["M " + tlr + ",0"], ["l " + (width.value - tlr - trr) + ",0"], ["a " + trr + "," + trr + ",0,0,1," + trr + "," + trr], ["l 0," + (height.value - trr - brr)], ["a " + brr + "," + brr + ",0,0,1," + -brr + "," + brr], ["l " + (brr + blr - width.value) + ",0"], ["a " + blr + "," + blr + ",0,0,1," + -blr + "," + -blr], ["l 0," + (blr + tlr - height.value)], ["a " + tlr + "," + tlr + ",0,0,1," + tlr + "," + -tlr], ['z']].join(' ');
1218
+ function updateImageElementAttribute($el, parsedStyle) {
1219
+ var _parsedStyle$img = parsedStyle.img,
1220
+ img = _parsedStyle$img === void 0 ? '' : _parsedStyle$img,
1221
+ width = parsedStyle.width,
1222
+ height = parsedStyle.height;
1223
+ $el.setAttribute('x', '0');
1224
+ $el.setAttribute('y', '0');
1225
+
1226
+ if (g.isString(img)) {
1227
+ $el.setAttribute('href', img);
1228
+ } else if (img instanceof Image) {
1229
+ if (!width) {
1230
+ $el.setAttribute('width', "" + img.width); // TODO: set renderable.boundsDirty
1231
+ // this.attr('width', img.width);
865
1232
  }
866
1233
 
867
- $el.setAttribute('d', d);
868
- };
869
-
870
- return RectRenderer;
871
- }();
1234
+ if (!height) {
1235
+ $el.setAttribute('height', "" + img.height); // this.attr('height', img.height);
1236
+ }
872
1237
 
873
- RectRenderer = __decorate([manaSyringe.singleton()], RectRenderer);
1238
+ $el.setAttribute('href', img.src);
1239
+ } else if ( // @ts-ignore
1240
+ img instanceof HTMLElement && g.isString(img.nodeName) && img.nodeName.toUpperCase() === 'CANVAS') {
1241
+ $el.setAttribute('href', img.toDataURL()); // @ts-ignore
1242
+ } else if (img instanceof ImageData) {
1243
+ var canvas = document.createElement('canvas'); // @ts-ignore
874
1244
 
875
- var ImageRenderer = /*#__PURE__*/function () {
876
- function ImageRenderer() {
877
- this.dependencies = ['img', 'width', 'height'];
878
- }
1245
+ canvas.setAttribute('width', "" + img.width); // @ts-ignore
879
1246
 
880
- var _proto = ImageRenderer.prototype;
1247
+ canvas.setAttribute('height', "" + img.height);
1248
+ var context = canvas.getContext('2d');
881
1249
 
882
- _proto.apply = function apply($el, parsedStyle) {
883
- var _parsedStyle$img = parsedStyle.img,
884
- img = _parsedStyle$img === void 0 ? '' : _parsedStyle$img,
885
- width = parsedStyle.width,
886
- height = parsedStyle.height;
887
- $el.setAttribute('x', '0');
888
- $el.setAttribute('y', '0');
1250
+ if (context) {
1251
+ context.putImageData(img, 0, 0);
889
1252
 
890
- if (g.isString(img)) {
891
- $el.setAttribute('href', img);
892
- } else if (img instanceof Image) {
893
1253
  if (!width) {
894
- $el.setAttribute('width', "" + img.width); // TODO: set renderable.boundsDirty
895
- // this.attr('width', img.width);
1254
+ // @ts-ignore
1255
+ $el.setAttribute('width', "" + img.width); // this.attr('width', img.width);
896
1256
  }
897
1257
 
898
1258
  if (!height) {
1259
+ // @ts-ignore
899
1260
  $el.setAttribute('height', "" + img.height); // this.attr('height', img.height);
900
1261
  }
901
1262
 
902
- $el.setAttribute('href', img.src);
903
- } else if ( // @ts-ignore
904
- img instanceof HTMLElement && g.isString(img.nodeName) && img.nodeName.toUpperCase() === 'CANVAS') {
905
- $el.setAttribute('href', img.toDataURL()); // @ts-ignore
906
- } else if (img instanceof ImageData) {
907
- var canvas = document.createElement('canvas'); // @ts-ignore
908
-
909
- canvas.setAttribute('width', "" + img.width); // @ts-ignore
910
-
911
- canvas.setAttribute('height', "" + img.height);
912
- var context = canvas.getContext('2d');
913
-
914
- if (context) {
915
- context.putImageData(img, 0, 0);
1263
+ $el.setAttribute('href', canvas.toDataURL());
1264
+ }
1265
+ }
1266
+ }
916
1267
 
917
- if (!width) {
918
- // @ts-ignore
919
- $el.setAttribute('width', "" + img.width); // this.attr('width', img.width);
920
- }
1268
+ function updateLineElementAttribute($el, parsedStyle) {
1269
+ var x1 = parsedStyle.x1,
1270
+ y1 = parsedStyle.y1,
1271
+ x2 = parsedStyle.x2,
1272
+ y2 = parsedStyle.y2,
1273
+ defX = parsedStyle.defX,
1274
+ defY = parsedStyle.defY;
1275
+ $el.setAttribute('x1', "" + (x1.value - defX));
1276
+ $el.setAttribute('y1', "" + (y1.value - defY));
1277
+ $el.setAttribute('x2', "" + (x2.value - defX));
1278
+ $el.setAttribute('y2', "" + (y2.value - defY));
1279
+ }
921
1280
 
922
- if (!height) {
923
- // @ts-ignore
924
- $el.setAttribute('height', "" + img.height); // this.attr('height', img.height);
925
- }
1281
+ function updatePathElementAttribute($el, parsedStyle) {
1282
+ var path = parsedStyle.path,
1283
+ _parsedStyle$defX = parsedStyle.defX,
1284
+ x = _parsedStyle$defX === void 0 ? 0 : _parsedStyle$defX,
1285
+ _parsedStyle$defY = parsedStyle.defY,
1286
+ y = _parsedStyle$defY === void 0 ? 0 : _parsedStyle$defY;
1287
+ $el.setAttribute('d', formatPath(path.absolutePath, x, y));
1288
+ }
926
1289
 
927
- $el.setAttribute('href', canvas.toDataURL());
928
- }
929
- }
930
- };
1290
+ function formatPath(value, x, y) {
1291
+ var newValue = value.map(function (params) {
1292
+ var command = params[0];
931
1293
 
932
- return ImageRenderer;
933
- }();
1294
+ switch (command) {
1295
+ case 'M':
1296
+ return "M " + (params[1] - x) + "," + (params[2] - y);
934
1297
 
935
- ImageRenderer = __decorate([manaSyringe.singleton()], ImageRenderer);
1298
+ case 'L':
1299
+ return "L " + (params[1] - x) + "," + (params[2] - y);
936
1300
 
937
- var LineRenderer = /*#__PURE__*/function () {
938
- function LineRenderer() {
939
- this.dependencies = ['x1', 'y1', 'x2', 'y2'];
940
- }
1301
+ case 'Q':
1302
+ return "Q " + (params[1] - x) + " " + (params[2] - y) + "," + (params[3] - x) + " " + (params[4] - y);
941
1303
 
942
- var _proto = LineRenderer.prototype;
1304
+ case 'C':
1305
+ return "C " + (params[1] - x) + " " + (params[2] - y) + "," + (params[3] - x) + " " + (params[4] - y) + "," + (params[5] - x) + " " + (params[6] - y);
943
1306
 
944
- _proto.apply = function apply($el, parsedStyle) {
945
- var x1 = parsedStyle.x1,
946
- y1 = parsedStyle.y1,
947
- x2 = parsedStyle.x2,
948
- y2 = parsedStyle.y2,
949
- _parsedStyle$defX = parsedStyle.defX,
950
- x = _parsedStyle$defX === void 0 ? 0 : _parsedStyle$defX,
951
- _parsedStyle$defY = parsedStyle.defY,
952
- y = _parsedStyle$defY === void 0 ? 0 : _parsedStyle$defY,
953
- stroke = parsedStyle.stroke;
954
- $el.setAttribute('x1', "" + (x1.value - x));
955
- $el.setAttribute('y1', "" + (y1.value - y));
956
- $el.setAttribute('x2', "" + (x2.value - x)); // fix horizontal line stroke url bug in Chrome
957
- // @see https://stackoverflow.com/questions/14680240/did-chrome-break-svg-stroke-url
1307
+ case 'A':
1308
+ return "A " + params[1] + " " + params[2] + " " + params[3] + " " + params[4] + " " + params[5] + " " + (params[6] - x) + " " + (params[7] - y);
958
1309
 
959
- if (y1.value === y2.value && stroke && !(stroke instanceof g.CSSRGB)) {
960
- $el.setAttribute('y2', "" + (y2.value - y + 0.00001));
961
- } else {
962
- $el.setAttribute('y2', "" + (y2.value - y));
1310
+ case 'Z':
1311
+ return 'Z';
963
1312
  }
964
- };
965
-
966
- return LineRenderer;
967
- }();
1313
+ }).join(' ');
968
1314
 
969
- LineRenderer = __decorate([manaSyringe.singleton()], LineRenderer);
970
-
971
- var PolylineRenderer = /*#__PURE__*/function () {
972
- function PolylineRenderer() {
973
- this.dependencies = ['points'];
1315
+ if (~newValue.indexOf('NaN')) {
1316
+ return '';
974
1317
  }
975
1318
 
976
- var _proto = PolylineRenderer.prototype;
1319
+ return newValue;
1320
+ }
977
1321
 
978
- _proto.apply = function apply($el, parsedStyle) {
979
- var points = parsedStyle.points,
980
- _parsedStyle$defX = parsedStyle.defX,
981
- x = _parsedStyle$defX === void 0 ? 0 : _parsedStyle$defX,
982
- _parsedStyle$defY = parsedStyle.defY,
983
- y = _parsedStyle$defY === void 0 ? 0 : _parsedStyle$defY;
1322
+ function updatePolylineElementAttribute($el, parsedStyle) {
1323
+ var points = parsedStyle.points,
1324
+ _parsedStyle$defX = parsedStyle.defX,
1325
+ x = _parsedStyle$defX === void 0 ? 0 : _parsedStyle$defX,
1326
+ _parsedStyle$defY = parsedStyle.defY,
1327
+ y = _parsedStyle$defY === void 0 ? 0 : _parsedStyle$defY;
984
1328
 
985
- if (points && points.points && points.points.length >= 2) {
986
- $el.setAttribute('points', points.points.map(function (point) {
987
- return point[0] - x + "," + (point[1] - y);
988
- }).join(' '));
989
- }
990
- };
1329
+ if (points && points.points && points.points.length >= 2) {
1330
+ $el.setAttribute('points', points.points.map(function (point) {
1331
+ return point[0] - x + "," + (point[1] - y);
1332
+ }).join(' '));
1333
+ }
1334
+ }
991
1335
 
992
- return PolylineRenderer;
993
- }();
1336
+ function updateRectElementAttribute($el, parsedStyle) {
1337
+ var radius = parsedStyle.radius,
1338
+ width = parsedStyle.width,
1339
+ height = parsedStyle.height;
1340
+ var hasRadius = radius && radius.some(function (r) {
1341
+ return r.value !== 0;
1342
+ });
1343
+ var d = '';
1344
+
1345
+ if (!hasRadius) {
1346
+ d = "M 0,0 l " + width.value + ",0 l 0," + height.value + " l" + -width.value + " 0 z";
1347
+ } else {
1348
+ var _radius$map = radius.map(function (r) {
1349
+ return r.value;
1350
+ }),
1351
+ tlr = _radius$map[0],
1352
+ trr = _radius$map[1],
1353
+ brr = _radius$map[2],
1354
+ blr = _radius$map[3];
1355
+
1356
+ d = [["M " + tlr + ",0"], ["l " + (width.value - tlr - trr) + ",0"], ["a " + trr + "," + trr + ",0,0,1," + trr + "," + trr], ["l 0," + (height.value - trr - brr)], ["a " + brr + "," + brr + ",0,0,1," + -brr + "," + brr], ["l " + (brr + blr - width.value) + ",0"], ["a " + blr + "," + blr + ",0,0,1," + -blr + "," + -blr], ["l 0," + (blr + tlr - height.value)], ["a " + tlr + "," + tlr + ",0,0,1," + tlr + "," + -tlr], ['z']].join(' ');
1357
+ }
994
1358
 
995
- PolylineRenderer = __decorate([manaSyringe.singleton()], PolylineRenderer);
1359
+ $el.setAttribute('d', d);
1360
+ }
996
1361
 
997
1362
  function numberToLongString(x) {
998
1363
  return x.toFixed(6).replace('.000000', '');
@@ -1034,125 +1399,144 @@
1034
1399
  hanging: 'hanging'
1035
1400
  };
1036
1401
 
1037
- var TextRenderer = /*#__PURE__*/function () {
1038
- function TextRenderer() {
1039
- this.dependencies = ['text', 'font', 'fontSize', 'fontFamily', 'fontStyle', 'fontWeight', 'fontVariant', 'lineHeight', 'letterSpacing', 'wordWrap', 'wordWrapWidth', 'leading', 'textBaseline', 'textAlign', 'textTransform', 'whiteSpace', 'dx', 'dy'];
1402
+ function updateTextElementAttribute($el, parsedStyle) {
1403
+ var textBaseline = parsedStyle.textBaseline,
1404
+ lineWidth = parsedStyle.lineWidth,
1405
+ metrics = parsedStyle.metrics,
1406
+ dx = parsedStyle.dx,
1407
+ dy = parsedStyle.dy;
1408
+ var browser = detect();
1409
+
1410
+ if (browser && browser.name === 'firefox') {
1411
+ // compatible with FireFox browser, ref: https://github.com/antvis/g/issues/119
1412
+ $el.setAttribute('dominant-baseline', BASELINE_MAP_FOR_FIREFOX[textBaseline.value] || 'alphabetic');
1413
+ } else {
1414
+ $el.setAttribute('dominant-baseline', BASELINE_MAP_FOR_FIREFOX[textBaseline.value]);
1415
+ $el.setAttribute('alignment-baseline', BASELINE_MAP[textBaseline.value]);
1040
1416
  }
1041
1417
 
1042
- var _proto = TextRenderer.prototype;
1418
+ $el.setAttribute('paint-order', 'stroke');
1419
+ var lines = metrics.lines,
1420
+ lineHeight = metrics.lineHeight,
1421
+ height = metrics.height;
1422
+ var lineNum = lines.length;
1423
+ $el.setAttribute('style', "transform:translate(" + dx.toString() + ", " + dy.toString() + ");");
1043
1424
 
1044
- _proto.apply = function apply($el, parsedStyle) {
1045
- var textBaseline = parsedStyle.textBaseline,
1046
- lineWidth = parsedStyle.lineWidth,
1047
- metrics = parsedStyle.metrics,
1048
- dx = parsedStyle.dx,
1049
- dy = parsedStyle.dy;
1050
- var browser = detect();
1051
-
1052
- if (browser && browser.name === 'firefox') {
1053
- // compatible with FireFox browser, ref: https://github.com/antvis/g/issues/119
1054
- $el.setAttribute('dominant-baseline', BASELINE_MAP_FOR_FIREFOX[textBaseline.value] || 'alphabetic');
1055
- } else {
1056
- $el.setAttribute('dominant-baseline', BASELINE_MAP_FOR_FIREFOX[textBaseline.value]);
1057
- $el.setAttribute('alignment-baseline', BASELINE_MAP[textBaseline.value]);
1058
- }
1425
+ if (lineNum === 1) {
1426
+ $el.innerHTML = convertHTML(lines[0]);
1427
+ $el.setAttribute('dx', "" + lineWidth.value / 2);
1428
+ } else {
1429
+ $el.innerHTML = lines.map(function (line, i) {
1430
+ var dx = lineWidth.value / 2;
1431
+ var dy = 0;
1432
+
1433
+ if (i === 0) {
1434
+ // TODO: handle other textBaseline values
1435
+ if (textBaseline.value === 'middle') {
1436
+ dy = lineHeight / 2 - height / 2;
1437
+ } else if (textBaseline.value === 'top' || textBaseline.value === 'hanging') {
1438
+ dy = 0;
1439
+ } else if (textBaseline.value === 'bottom' || textBaseline.value === 'alphabetic' || textBaseline.value === 'ideographic') {
1440
+ dy = -lineHeight * (lineNum - 1);
1441
+ }
1442
+ } else {
1443
+ dy = lineHeight;
1444
+ }
1059
1445
 
1060
- $el.setAttribute('paint-order', 'stroke');
1061
- var lines = metrics.lines,
1062
- lineHeight = metrics.lineHeight,
1063
- height = metrics.height;
1064
- var lineNum = lines.length;
1065
- $el.setAttribute('style', "transform:translate(" + dx.toString() + ", " + dy.toString() + ");");
1446
+ return "<tspan x=\"0\" dx=\"" + dx + "\" dy=\"" + dy + "\">" + convertHTML(line) + "</tspan>";
1447
+ }).join('');
1448
+ }
1449
+ }
1066
1450
 
1067
- if (lineNum === 1) {
1068
- $el.innerHTML = convertHTML(lines[0]);
1069
- $el.setAttribute('dx', "" + lineWidth.value / 2);
1070
- } else {
1071
- $el.innerHTML = lines.map(function (line, i) {
1072
- var dx = lineWidth.value / 2;
1073
- var dy = 0;
1074
-
1075
- if (i === 0) {
1076
- // TODO: handle other textBaseline values
1077
- if (textBaseline.value === 'middle') {
1078
- dy = lineHeight / 2 - height / 2;
1079
- } else if (textBaseline.value === 'top' || textBaseline.value === 'hanging') {
1080
- dy = 0;
1081
- } else if (textBaseline.value === 'bottom' || textBaseline.value === 'alphabetic' || textBaseline.value === 'ideographic') {
1082
- dy = -lineHeight * (lineNum - 1);
1083
- }
1084
- } else {
1085
- dy = lineHeight;
1086
- }
1451
+ var CreateElementContribution = manaSyringe.Syringe.defineToken('CreateElementContribution', {
1452
+ multiple: false
1453
+ });
1087
1454
 
1088
- return "<tspan x=\"0\" dx=\"" + dx + "\" dy=\"" + dy + "\">" + convertHTML(line) + "</tspan>";
1089
- }).join('');
1090
- }
1091
- };
1455
+ function createSVGElement(type, doc) {
1456
+ return (doc || document).createElementNS('http://www.w3.org/2000/svg', type);
1457
+ }
1092
1458
 
1093
- return TextRenderer;
1094
- }();
1459
+ var _SHAPE2TAGS, _SHAPE_UPDATE_DEPS;
1095
1460
 
1096
- TextRenderer = __decorate([manaSyringe.singleton()], TextRenderer);
1461
+ var SHAPE2TAGS = (_SHAPE2TAGS = {}, _SHAPE2TAGS[g.Shape.RECT] = 'path', _SHAPE2TAGS[g.Shape.CIRCLE] = 'circle', _SHAPE2TAGS[g.Shape.ELLIPSE] = 'ellipse', _SHAPE2TAGS[g.Shape.IMAGE] = 'image', _SHAPE2TAGS[g.Shape.GROUP] = 'g', _SHAPE2TAGS[g.Shape.LINE] = 'line', _SHAPE2TAGS[g.Shape.POLYLINE] = 'polyline', _SHAPE2TAGS[g.Shape.POLYGON] = 'polygon', _SHAPE2TAGS[g.Shape.TEXT] = 'text', _SHAPE2TAGS[g.Shape.PATH] = 'path', _SHAPE2TAGS[g.Shape.HTML] = 'foreignObject', _SHAPE2TAGS);
1462
+ var SHAPE_UPDATE_DEPS = (_SHAPE_UPDATE_DEPS = {}, _SHAPE_UPDATE_DEPS[g.Shape.CIRCLE] = ['r'], _SHAPE_UPDATE_DEPS[g.Shape.ELLIPSE] = ['rx', 'ry'], _SHAPE_UPDATE_DEPS[g.Shape.RECT] = ['width', 'height', 'radius'], _SHAPE_UPDATE_DEPS[g.Shape.IMAGE] = ['img', 'width', 'height'], _SHAPE_UPDATE_DEPS[g.Shape.LINE] = ['x1', 'y1', 'x2', 'y2'], _SHAPE_UPDATE_DEPS[g.Shape.POLYLINE] = ['points'], _SHAPE_UPDATE_DEPS[g.Shape.POLYGON] = ['points'], _SHAPE_UPDATE_DEPS[g.Shape.PATH] = ['path'], _SHAPE_UPDATE_DEPS[g.Shape.TEXT] = ['text', 'font', 'fontSize', 'fontFamily', 'fontStyle', 'fontWeight', 'fontVariant', 'lineHeight', 'letterSpacing', 'wordWrap', 'wordWrapWidth', 'leading', 'textBaseline', 'textAlign', 'textTransform', 'whiteSpace', 'dx', 'dy'], _SHAPE_UPDATE_DEPS);
1097
1463
 
1098
- var PathRenderer = /*#__PURE__*/function () {
1099
- function PathRenderer() {
1100
- this.dependencies = ['path'];
1464
+ var DefaultCreateElementContribution = /*#__PURE__*/function () {
1465
+ function DefaultCreateElementContribution() {
1466
+ this.canvasConfig = void 0;
1101
1467
  }
1102
1468
 
1103
- var _proto = PathRenderer.prototype;
1469
+ var _proto = DefaultCreateElementContribution.prototype;
1104
1470
 
1105
- _proto.apply = function apply($el, parsedStyle) {
1106
- var path = parsedStyle.path,
1107
- _parsedStyle$defX = parsedStyle.defX,
1108
- x = _parsedStyle$defX === void 0 ? 0 : _parsedStyle$defX,
1109
- _parsedStyle$defY = parsedStyle.defY,
1110
- y = _parsedStyle$defY === void 0 ? 0 : _parsedStyle$defY;
1111
- $el.setAttribute('d', this.formatPath(path.absolutePath, x, y));
1471
+ _proto.createElement = function createElement(object) {
1472
+ var doc = this.canvasConfig.document;
1473
+ var type = SHAPE2TAGS[object.nodeName] || 'g';
1474
+ return createSVGElement(type, doc || document);
1112
1475
  };
1113
1476
 
1114
- _proto.formatPath = function formatPath(value, x, y) {
1115
- var newValue = value.map(function (params) {
1116
- var command = params[0];
1117
-
1118
- switch (command) {
1119
- case 'M':
1120
- return "M " + (params[1] - x) + "," + (params[2] - y);
1477
+ _proto.shouldUpdateElementAttribute = function shouldUpdateElementAttribute(object, attributeName) {
1478
+ var nodeName = object.nodeName;
1479
+ return (SHAPE_UPDATE_DEPS[nodeName] || []).indexOf(attributeName) > -1;
1480
+ };
1121
1481
 
1122
- case 'L':
1123
- return "L " + (params[1] - x) + "," + (params[2] - y);
1482
+ _proto.updateElementAttribute = function updateElementAttribute(object) {
1483
+ // @ts-ignore
1484
+ var $el = object.elementSVG.$el;
1485
+ var nodeName = object.nodeName,
1486
+ parsedStyle = object.parsedStyle;
1487
+
1488
+ switch (nodeName) {
1489
+ case g.Shape.IMAGE:
1490
+ {
1491
+ updateImageElementAttribute($el, parsedStyle);
1492
+ break;
1493
+ }
1124
1494
 
1125
- case 'Q':
1126
- return "Q " + (params[1] - x) + " " + (params[2] - y) + "," + (params[3] - x) + " " + (params[4] - y);
1495
+ case g.Shape.RECT:
1496
+ {
1497
+ updateRectElementAttribute($el, parsedStyle);
1498
+ break;
1499
+ }
1127
1500
 
1128
- case 'C':
1129
- return "C " + (params[1] - x) + " " + (params[2] - y) + "," + (params[3] - x) + " " + (params[4] - y) + "," + (params[5] - x) + " " + (params[6] - y);
1501
+ case g.Shape.LINE:
1502
+ {
1503
+ updateLineElementAttribute($el, parsedStyle);
1504
+ break;
1505
+ }
1130
1506
 
1131
- case 'A':
1132
- return "A " + params[1] + " " + params[2] + " " + params[3] + " " + params[4] + " " + params[5] + " " + (params[6] - x) + " " + (params[7] - y);
1507
+ case g.Shape.POLYGON:
1508
+ case g.Shape.POLYLINE:
1509
+ {
1510
+ updatePolylineElementAttribute($el, parsedStyle);
1511
+ break;
1512
+ }
1133
1513
 
1134
- case 'Z':
1135
- return 'Z';
1136
- }
1137
- }).join(' ');
1514
+ case g.Shape.PATH:
1515
+ {
1516
+ updatePathElementAttribute($el, parsedStyle);
1517
+ break;
1518
+ }
1138
1519
 
1139
- if (~newValue.indexOf('NaN')) {
1140
- return '';
1520
+ case g.Shape.TEXT:
1521
+ {
1522
+ updateTextElementAttribute($el, parsedStyle);
1523
+ break;
1524
+ }
1141
1525
  }
1142
-
1143
- return newValue;
1144
1526
  };
1145
1527
 
1146
- return PathRenderer;
1528
+ return DefaultCreateElementContribution;
1147
1529
  }();
1148
1530
 
1149
- PathRenderer = __decorate([manaSyringe.singleton()], PathRenderer);
1150
- var ElementRendererFactory = manaSyringe.Syringe.defineToken('ElementRendererFactory');
1151
- var ElementRenderer = manaSyringe.Syringe.defineToken('ElementRenderer');
1531
+ __decorate([manaSyringe.inject(g.CanvasConfig), __metadata("design:type", Object)], DefaultCreateElementContribution.prototype, "canvasConfig", void 0);
1152
1532
 
1153
- function _regeneratorRuntime$1() {
1533
+ DefaultCreateElementContribution = __decorate([manaSyringe.singleton({
1534
+ token: CreateElementContribution
1535
+ })], DefaultCreateElementContribution);
1536
+
1537
+ function _regeneratorRuntime$2() {
1154
1538
  /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */
1155
- _regeneratorRuntime$1 = function _regeneratorRuntime() {
1539
+ _regeneratorRuntime$2 = function _regeneratorRuntime() {
1156
1540
  return exports;
1157
1541
  };
1158
1542
 
@@ -1500,7 +1884,7 @@
1500
1884
  }, exports;
1501
1885
  }
1502
1886
 
1503
- function asyncGeneratorStep$1(gen, resolve, reject, _next, _throw, key, arg) {
1887
+ function asyncGeneratorStep$2(gen, resolve, reject, _next, _throw, key, arg) {
1504
1888
  try {
1505
1889
  var info = gen[key](arg);
1506
1890
  var value = info.value;
@@ -1516,7 +1900,7 @@
1516
1900
  }
1517
1901
  }
1518
1902
 
1519
- function _asyncToGenerator$1(fn) {
1903
+ function _asyncToGenerator$2(fn) {
1520
1904
  return function () {
1521
1905
  var self = this,
1522
1906
  args = arguments;
@@ -1524,11 +1908,11 @@
1524
1908
  var gen = fn.apply(self, args);
1525
1909
 
1526
1910
  function _next(value) {
1527
- asyncGeneratorStep$1(gen, resolve, reject, _next, _throw, "next", value);
1911
+ asyncGeneratorStep$2(gen, resolve, reject, _next, _throw, "next", value);
1528
1912
  }
1529
1913
 
1530
1914
  function _throw(err) {
1531
- asyncGeneratorStep$1(gen, resolve, reject, _next, _throw, "throw", err);
1915
+ asyncGeneratorStep$2(gen, resolve, reject, _next, _throw, "throw", err);
1532
1916
  }
1533
1917
 
1534
1918
  _next(undefined);
@@ -2194,17 +2578,13 @@
2194
2578
  };
2195
2579
  }();
2196
2580
 
2197
- function createSVGElement(type) {
2198
- return document.createElementNS('http://www.w3.org/2000/svg', type);
2199
- }
2200
-
2201
2581
  var FILTER_PREFIX = 'g-filter-';
2202
2582
  /**
2203
2583
  * use SVG filters, eg. blur, brightness, contrast...
2204
2584
  * @see https://developer.mozilla.org/zh-CN/docs/Web/SVG/Element/filter
2205
2585
  */
2206
2586
 
2207
- function createOrUpdateFilter($def, object, $el, filters) {
2587
+ function createOrUpdateFilter(document, $def, object, $el, filters) {
2208
2588
  // eg. filter="url(#f1) url(#f2)"
2209
2589
  var filterName = FILTER_PREFIX + object.entity;
2210
2590
  var $existedFilters = $def.querySelectorAll("[name=" + filterName + "]");
@@ -2222,26 +2602,28 @@
2222
2602
  var filterIds = filters.map(function (_ref, i) {
2223
2603
  var name = _ref.name,
2224
2604
  params = _ref.params;
2225
- var $filter = createSVGElement('filter');
2605
+ var $filter = createSVGElement('filter', document); // @see https://github.com/antvis/g/issues/1025
2606
+
2607
+ $filter.setAttribute('filterUnits', 'userSpaceOnUse');
2226
2608
 
2227
2609
  if (name === 'blur') {
2228
- createBlur($filter, params);
2610
+ createBlur(document, $filter, params);
2229
2611
  } else if (name === 'brightness') {
2230
- createBrightness($filter, params);
2612
+ createBrightness(document, $filter, params);
2231
2613
  } else if (name === 'drop-shadow') {
2232
- createDropShadow($filter, params);
2614
+ createDropShadow(document, $filter, params);
2233
2615
  } else if (name === 'contrast') {
2234
- createContrast($filter, params);
2616
+ createContrast(document, $filter, params);
2235
2617
  } else if (name === 'grayscale') {
2236
- createGrayscale($filter, params);
2618
+ createGrayscale(document, $filter, params);
2237
2619
  } else if (name === 'sepia') {
2238
- createSepia($filter, params);
2620
+ createSepia(document, $filter, params);
2239
2621
  } else if (name === 'saturate') {
2240
- createSaturate($filter, params);
2622
+ createSaturate(document, $filter, params);
2241
2623
  } else if (name === 'hue-rotate') {
2242
- createHueRotate($filter, params);
2624
+ createHueRotate(document, $filter, params);
2243
2625
  } else if (name === 'invert') {
2244
- createInvert($filter, params);
2626
+ createInvert(document, $filter, params);
2245
2627
  }
2246
2628
 
2247
2629
  $filter.id = filterName + "-" + i;
@@ -2263,20 +2645,20 @@
2263
2645
  */
2264
2646
 
2265
2647
 
2266
- function createBlur($filter, params) {
2267
- var $feGaussianBlur = createSVGElement('feGaussianBlur');
2648
+ function createBlur(document, $filter, params) {
2649
+ var $feGaussianBlur = createSVGElement('feGaussianBlur', document);
2268
2650
  $feGaussianBlur.setAttribute('in', 'SourceGraphic');
2269
2651
  $feGaussianBlur.setAttribute('stdDeviation', "" + params[0].value);
2270
2652
  $filter.appendChild($feGaussianBlur);
2271
2653
  }
2272
2654
 
2273
- function createFeComponentTransfer($filter, _ref2) {
2655
+ function createFeComponentTransfer(document, $filter, _ref2) {
2274
2656
  var type = _ref2.type,
2275
2657
  slope = _ref2.slope,
2276
2658
  intercept = _ref2.intercept,
2277
2659
  tableValues = _ref2.tableValues;
2278
- var $feComponentTransfer = createSVGElement('feComponentTransfer');
2279
- [createSVGElement('feFuncR'), createSVGElement('feFuncG'), createSVGElement('feFuncB')].forEach(function ($feFunc) {
2660
+ var $feComponentTransfer = createSVGElement('feComponentTransfer', document);
2661
+ [createSVGElement('feFuncR', document), createSVGElement('feFuncG', document), createSVGElement('feFuncB', document)].forEach(function ($feFunc) {
2280
2662
  $feFunc.setAttribute('type', type);
2281
2663
 
2282
2664
  if (type === 'table') {
@@ -2291,80 +2673,80 @@
2291
2673
  $filter.appendChild($feComponentTransfer);
2292
2674
  }
2293
2675
 
2294
- function createContrast($filter, params) {
2676
+ function createContrast(document, $filter, params) {
2295
2677
  var slope = convertToAbsoluteValue(params[0]);
2296
- createFeComponentTransfer($filter, {
2678
+ createFeComponentTransfer(document, $filter, {
2297
2679
  type: 'linear',
2298
2680
  slope: slope,
2299
2681
  intercept: -(0.5 * slope) + 0.5
2300
2682
  });
2301
2683
  }
2302
2684
 
2303
- function createInvert($filter, params) {
2685
+ function createInvert(document, $filter, params) {
2304
2686
  var amount = convertToAbsoluteValue(params[0]);
2305
- createFeComponentTransfer($filter, {
2687
+ createFeComponentTransfer(document, $filter, {
2306
2688
  type: 'table',
2307
2689
  tableValues: amount + " " + (1 - amount)
2308
2690
  });
2309
2691
  }
2310
2692
 
2311
- function createBrightness($filter, params) {
2693
+ function createBrightness(document, $filter, params) {
2312
2694
  var slope = convertToAbsoluteValue(params[0]);
2313
- createFeComponentTransfer($filter, {
2695
+ createFeComponentTransfer(document, $filter, {
2314
2696
  type: 'linear',
2315
2697
  slope: slope,
2316
2698
  intercept: 0
2317
2699
  });
2318
2700
  }
2319
2701
 
2320
- function createSaturate($filter, params) {
2702
+ function createSaturate(document, $filter, params) {
2321
2703
  var amount = convertToAbsoluteValue(params[0]);
2322
- var $feColorMatrix = createSVGElement('feColorMatrix');
2704
+ var $feColorMatrix = createSVGElement('feColorMatrix', document);
2323
2705
  $feColorMatrix.setAttribute('type', 'saturate');
2324
2706
  $feColorMatrix.setAttribute('values', "" + amount);
2325
2707
  $filter.appendChild($feColorMatrix);
2326
2708
  }
2327
2709
 
2328
- function createHueRotate($filter, params) {
2329
- var $feColorMatrix = createSVGElement('feColorMatrix');
2710
+ function createHueRotate(document, $filter, params) {
2711
+ var $feColorMatrix = createSVGElement('feColorMatrix', document);
2330
2712
  $feColorMatrix.setAttribute('type', 'hueRotate');
2331
2713
  $feColorMatrix.setAttribute('values', "" + params[0].to(g.UnitType.kDegrees).value);
2332
2714
  $filter.appendChild($feColorMatrix);
2333
2715
  }
2334
2716
 
2335
- function createDropShadow($filter, params) {
2717
+ function createDropShadow(document, $filter, params) {
2336
2718
  var shadowOffsetX = params[0].value;
2337
2719
  var shadowOffsetY = params[1].value;
2338
2720
  var shadowBlur = params[2].value; // @ts-ignore
2339
2721
 
2340
2722
  var shadowColor = params[3].formatted;
2341
- var $feGaussianBlur = createSVGElement('feGaussianBlur');
2723
+ var $feGaussianBlur = createSVGElement('feGaussianBlur', document);
2342
2724
  $feGaussianBlur.setAttribute('in', 'SourceAlpha');
2343
2725
  $feGaussianBlur.setAttribute('stdDeviation', "" + shadowBlur);
2344
2726
  $filter.appendChild($feGaussianBlur);
2345
- var $feOffset = createSVGElement('feOffset');
2727
+ var $feOffset = createSVGElement('feOffset', document);
2346
2728
  $feOffset.setAttribute('dx', "" + shadowOffsetX);
2347
2729
  $feOffset.setAttribute('dy', "" + shadowOffsetY);
2348
2730
  $feOffset.setAttribute('result', 'offsetblur');
2349
2731
  $filter.appendChild($feOffset);
2350
- var $feFlood = createSVGElement('feFlood');
2732
+ var $feFlood = createSVGElement('feFlood', document);
2351
2733
  $feFlood.setAttribute('flood-color', shadowColor);
2352
2734
  $filter.appendChild($feFlood);
2353
- var $feComposite = createSVGElement('feComposite');
2735
+ var $feComposite = createSVGElement('feComposite', document);
2354
2736
  $feComposite.setAttribute('in2', 'offsetblur');
2355
2737
  $feComposite.setAttribute('operator', 'in');
2356
2738
  $filter.appendChild($feComposite);
2357
- var $feMerge = createSVGElement('feMerge');
2739
+ var $feMerge = createSVGElement('feMerge', document);
2358
2740
  $filter.appendChild($feMerge);
2359
- var $feMergeNode1 = createSVGElement('feMergeNode');
2360
- var $feMergeNode2 = createSVGElement('feMergeNode');
2741
+ var $feMergeNode1 = createSVGElement('feMergeNode', document);
2742
+ var $feMergeNode2 = createSVGElement('feMergeNode', document);
2361
2743
  $feMergeNode2.setAttribute('in', 'SourceGraphic');
2362
2744
  $feMerge.appendChild($feMergeNode1);
2363
2745
  $feMerge.appendChild($feMergeNode2);
2364
2746
  }
2365
2747
 
2366
- function createFeColorMatrix($filter, matrix) {
2367
- var $feColorMatrix = createSVGElement('feColorMatrix');
2748
+ function createFeColorMatrix(document, $filter, matrix) {
2749
+ var $feColorMatrix = createSVGElement('feColorMatrix', document);
2368
2750
  $feColorMatrix.setAttribute('type', 'matrix');
2369
2751
  $feColorMatrix.setAttribute('values', matrix.join(' '));
2370
2752
  $filter.appendChild($feColorMatrix);
@@ -2374,32 +2756,29 @@
2374
2756
  */
2375
2757
 
2376
2758
 
2377
- function createGrayscale($filter, params) {
2759
+ function createGrayscale(document, $filter, params) {
2378
2760
  var amount = convertToAbsoluteValue(params[0]);
2379
- createFeColorMatrix($filter, [0.2126 + 0.7874 * (1 - amount), 0.7152 - 0.7152 * (1 - amount), 0.0722 - 0.0722 * (1 - amount), 0, 0, 0.2126 - 0.2126 * (1 - amount), 0.7152 + 0.2848 * (1 - amount), 0.0722 - 0.0722 * (1 - amount), 0, 0, 0.2126 - 0.2126 * (1 - amount), 0.7152 - 0.7152 * (1 - amount), 0.0722 + 0.9278 * (1 - amount), 0, 0, 0, 0, 0, 1, 0]);
2761
+ 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]);
2380
2762
  }
2381
2763
  /**
2382
2764
  * @see https://drafts.fxtf.org/filter-effects/#sepiaEquivalent
2383
2765
  */
2384
2766
 
2385
2767
 
2386
- function createSepia($filter, params) {
2768
+ function createSepia(document, $filter, params) {
2387
2769
  var amount = convertToAbsoluteValue(params[0]);
2388
- createFeColorMatrix($filter, [0.393 + 0.607 * (1 - amount), 0.769 - 0.769 * (1 - amount), 0.189 - 0.189 * (1 - amount), 0, 0, 0.349 - 0.349 * (1 - amount), 0.686 + 0.314 * (1 - amount), 0.168 - 0.168 * (1 - amount), 0, 0, 0.272 - 0.272 * (1 - amount), 0.534 - 0.534 * (1 - amount), 0.131 + 0.869 * (1 - amount), 0, 0, 0, 0, 0, 1, 0]);
2770
+ 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]);
2389
2771
  }
2390
2772
 
2391
2773
  var cacheKey2IDMap = {};
2392
2774
  var counter = 0;
2393
2775
 
2394
- function createOrUpdateGradientAndPattern($def, object, $el, parsedColor, name) {
2776
+ function createOrUpdateGradientAndPattern(document, $def, object, $el, parsedColor, name) {
2395
2777
  // eg. clipPath don't have fill/stroke
2396
2778
  if (!parsedColor) {
2397
2779
  return;
2398
2780
  }
2399
2781
 
2400
- var gradientId = generateCacheKey(parsedColor);
2401
- var existed = $def.querySelector("#" + gradientId);
2402
-
2403
2782
  if (parsedColor instanceof g.CSSRGB) {
2404
2783
  // keep using currentColor @see https://github.com/d3/d3-axis/issues/49
2405
2784
  if (object.style[name] === 'currentColor') {
@@ -2410,17 +2789,9 @@
2410
2789
  }
2411
2790
  } else {
2412
2791
  if (parsedColor.type === g.GradientPatternType.Pattern) {
2413
- if (!existed) {
2414
- createPattern($def, parsedColor, gradientId);
2415
- }
2416
-
2417
- $el === null || $el === void 0 ? void 0 : $el.setAttribute(name, "url(#" + gradientId + ")");
2792
+ createOrUpdatePattern(document, $def, $el, name, parsedColor);
2418
2793
  } else {
2419
- if (!existed) {
2420
- createGradient($def, parsedColor, gradientId);
2421
- }
2422
-
2423
- $el === null || $el === void 0 ? void 0 : $el.setAttribute(name, "url(#" + gradientId + ")");
2794
+ createOrUpdateGradient(document, object, $def, $el, name, parsedColor);
2424
2795
  }
2425
2796
  }
2426
2797
  }
@@ -2458,43 +2829,71 @@
2458
2829
  return cacheKey2IDMap[cacheKey];
2459
2830
  }
2460
2831
 
2461
- function createPattern($def, parsedColor, patternId) {
2462
- var src = parsedColor.value.src; // @see https://developer.mozilla.org/zh-CN/docs/Web/SVG/Element/pattern
2832
+ function createOrUpdatePattern(document, $def, $el, name, parsedColor) {
2833
+ var patternId = generateCacheKey(parsedColor);
2834
+ var $existed = $def.querySelector("#" + patternId);
2835
+
2836
+ if (!$existed) {
2837
+ var src = parsedColor.value.src; // @see https://developer.mozilla.org/zh-CN/docs/Web/SVG/Element/pattern
2838
+
2839
+ var $pattern = createSVGElement('pattern', document);
2840
+ $pattern.setAttribute('patternUnits', 'userSpaceOnUse');
2841
+ var $image = createSVGElement('image', document);
2842
+ $pattern.appendChild($image);
2843
+ $pattern.id = patternId;
2844
+ $def.appendChild($pattern);
2845
+ $el === null || $el === void 0 ? void 0 : $el.setAttribute(name, "url(#" + patternId + ")");
2846
+ $image.setAttribute('href', src);
2847
+ var img = new window.Image();
2848
+
2849
+ if (!src.match(/^data:/i)) {
2850
+ img.crossOrigin = 'Anonymous';
2851
+ }
2463
2852
 
2464
- var $pattern = createSVGElement('pattern');
2465
- $pattern.setAttribute('patternUnits', 'userSpaceOnUse');
2466
- var $image = createSVGElement('image');
2467
- $pattern.appendChild($image);
2468
- $pattern.id = patternId;
2469
- $def.appendChild($pattern);
2470
- $image.setAttribute('href', src);
2471
- var img = new window.Image();
2853
+ img.src = src;
2472
2854
 
2473
- if (!src.match(/^data:/i)) {
2474
- img.crossOrigin = 'Anonymous';
2475
- }
2855
+ var onload = function onload() {
2856
+ $pattern.setAttribute('width', "" + img.width);
2857
+ $pattern.setAttribute('height', "" + img.height);
2858
+ };
2476
2859
 
2477
- img.src = src;
2860
+ if (img.complete) {
2861
+ onload();
2862
+ } else {
2863
+ img.onload = onload; // Fix onload() bug in IE9
2478
2864
 
2479
- function onload() {
2480
- $pattern.setAttribute('width', "" + img.width);
2481
- $pattern.setAttribute('height', "" + img.height);
2865
+ img.src = img.src;
2866
+ }
2482
2867
  }
2868
+ }
2483
2869
 
2484
- if (img.complete) {
2485
- onload();
2486
- } else {
2487
- img.onload = onload; // Fix onload() bug in IE9
2870
+ function createOrUpdateGradient(document, object, $def, $el, name, parsedColor) {
2871
+ var gradientId = generateCacheKey(parsedColor);
2872
+ var $existed = $def.querySelector("#" + gradientId);
2873
+
2874
+ if (!$existed) {
2875
+ // <linearGradient> <radialGradient>
2876
+ // @see https://developer.mozilla.org/zh-CN/docs/Web/SVG/Element/linearGradient
2877
+ // @see https://developer.mozilla.org/zh-CN/docs/Web/SVG/Element/radialGradient
2878
+ $existed = createSVGElement(parsedColor.type === g.GradientPatternType.LinearGradient ? 'linearGradient' : 'radialGradient', document); // @see https://github.com/antvis/g/issues/1025
2488
2879
 
2489
- img.src = img.src;
2880
+ $existed.setAttribute('gradientUnits', 'userSpaceOnUse'); // add stops
2881
+
2882
+ var innerHTML = '';
2883
+ parsedColor.value.steps.forEach(function (_ref) {
2884
+ var offset = _ref[0],
2885
+ color = _ref[1];
2886
+ innerHTML += "<stop offset=\"" + offset + "\" stop-color=\"" + color + "\"></stop>";
2887
+ });
2888
+ $existed.innerHTML = innerHTML;
2889
+ $existed.id = gradientId;
2890
+ $def.appendChild($existed);
2891
+ $el === null || $el === void 0 ? void 0 : $el.setAttribute(name, "url(#" + gradientId + ")");
2490
2892
  }
2491
- }
2492
2893
 
2493
- function createGradient($def, parsedColor, gradientId) {
2494
- // <linearGradient> <radialGradient>
2495
- // @see https://developer.mozilla.org/zh-CN/docs/Web/SVG/Element/linearGradient
2496
- // @see https://developer.mozilla.org/zh-CN/docs/Web/SVG/Element/radialGradient
2497
- var $gradient = createSVGElement(parsedColor.type === g.GradientPatternType.LinearGradient ? 'linearGradient' : 'radialGradient');
2894
+ var bounds = object.getGeometryBounds();
2895
+ var width = bounds && bounds.halfExtents[0] * 2 || 0;
2896
+ var height = bounds && bounds.halfExtents[1] * 2 || 0;
2498
2897
 
2499
2898
  if (parsedColor.type === g.GradientPatternType.LinearGradient) {
2500
2899
  var _parsedColor$value = parsedColor.value,
@@ -2502,30 +2901,20 @@
2502
2901
  y0 = _parsedColor$value.y0,
2503
2902
  x1 = _parsedColor$value.x1,
2504
2903
  y1 = _parsedColor$value.y1;
2505
- $gradient.setAttribute('x1', "" + x0);
2506
- $gradient.setAttribute('y1', "" + y0);
2507
- $gradient.setAttribute('x2', "" + x1);
2508
- $gradient.setAttribute('y2', "" + y1);
2904
+ $existed.setAttribute('x1', "" + x0 * width);
2905
+ $existed.setAttribute('y1', "" + y0 * height);
2906
+ $existed.setAttribute('x2', "" + x1 * width);
2907
+ $existed.setAttribute('y2', "" + y1 * height);
2509
2908
  } else {
2909
+ var r = Math.sqrt(width * width + height * height) / 2;
2510
2910
  var _parsedColor$value2 = parsedColor.value,
2511
2911
  _x = _parsedColor$value2.x0,
2512
2912
  _y = _parsedColor$value2.y0,
2513
2913
  r1 = _parsedColor$value2.r1;
2514
- $gradient.setAttribute('cx', "" + _x);
2515
- $gradient.setAttribute('cy', "" + _y);
2516
- $gradient.setAttribute('r', "" + r1 / 2);
2517
- } // add stops
2518
-
2519
-
2520
- var innerHTML = '';
2521
- parsedColor.value.steps.forEach(function (_ref) {
2522
- var offset = _ref[0],
2523
- color = _ref[1];
2524
- innerHTML += "<stop offset=\"" + offset + "\" stop-color=\"" + color + "\"></stop>";
2525
- });
2526
- $gradient.innerHTML = innerHTML;
2527
- $gradient.id = gradientId;
2528
- $def.appendChild($gradient);
2914
+ $existed.setAttribute('cx', "" + _x * width);
2915
+ $existed.setAttribute('cy', "" + _y * height);
2916
+ $existed.setAttribute('r', "" + r1 * r);
2917
+ }
2529
2918
  }
2530
2919
 
2531
2920
  var FILTER_DROPSHADOW_PREFIX = 'filter-dropshadow-';
@@ -2534,21 +2923,23 @@
2534
2923
  * @see https://developer.mozilla.org/zh-CN/docs/Web/SVG/Element/filter
2535
2924
  */
2536
2925
 
2537
- function createOrUpdateShadow($def, object, $el, name) {
2926
+ function createOrUpdateShadow(document, $def, object, $el, name) {
2538
2927
  var shadowId = FILTER_DROPSHADOW_PREFIX + object.entity;
2539
2928
  var $existedFilter = $def.querySelector("#" + shadowId);
2540
2929
 
2541
2930
  if (!$existedFilter) {
2542
- $existedFilter = createSVGElement('filter');
2931
+ $existedFilter = createSVGElement('filter', document);
2543
2932
 
2544
- var _$feDropShadow = createSVGElement('feDropShadow');
2933
+ var _$feDropShadow = createSVGElement('feDropShadow', document);
2545
2934
 
2546
2935
  _$feDropShadow.setAttribute('dx', '0');
2547
2936
 
2548
2937
  _$feDropShadow.setAttribute('dy', '0');
2549
2938
 
2550
2939
  $existedFilter.appendChild(_$feDropShadow);
2551
- $existedFilter.id = shadowId;
2940
+ $existedFilter.id = shadowId; // @see https://github.com/antvis/g/issues/1025
2941
+
2942
+ $existedFilter.setAttribute('filterUnits', 'userSpaceOnUse');
2552
2943
  $def.appendChild($existedFilter);
2553
2944
  }
2554
2945
 
@@ -2562,44 +2953,28 @@
2562
2953
  // @see https://drafts.csswg.org/css-backgrounds/#shadow-blur
2563
2954
  // @see https://css-tricks.com/breaking-css-box-shadow-vs-drop-shadow/
2564
2955
 
2565
- $feDropShadow.setAttribute('stdDeviation', "" + (shadowBlur && shadowBlur.value || 0) / 2);
2956
+ $feDropShadow.setAttribute('stdDeviation', "" + ((shadowBlur === null || shadowBlur === void 0 ? void 0 : shadowBlur.value) || 0) / 4);
2566
2957
  } else if (name === 'shadowOffsetX') {
2567
2958
  var shadowOffsetX = object.parsedStyle[name];
2568
- $feDropShadow.setAttribute('dx', "" + (shadowOffsetX && shadowOffsetX.value || 0) / 2);
2959
+ $feDropShadow.setAttribute('dx', "" + ((shadowOffsetX === null || shadowOffsetX === void 0 ? void 0 : shadowOffsetX.value) || 0) / 2);
2569
2960
  } else if (name === 'shadowOffsetY') {
2570
2961
  var shadowOffsetY = object.parsedStyle[name];
2571
- $feDropShadow.setAttribute('dy', "" + (shadowOffsetY && shadowOffsetY.value || 0) / 2);
2572
- } // use filter <feDropShadow>
2573
- // @see https://developer.mozilla.org/en-US/docs/Web/SVG/Element/feDropShadow
2962
+ $feDropShadow.setAttribute('dy', "" + ((shadowOffsetY === null || shadowOffsetY === void 0 ? void 0 : shadowOffsetY.value) || 0) / 2);
2963
+ } // only apply shadow when blur > 0
2574
2964
 
2575
2965
 
2576
- $el === null || $el === void 0 ? void 0 : $el.setAttribute('filter', "url(#" + shadowId + ")");
2966
+ if (!g.isNil(object.parsedStyle.shadowColor)) {
2967
+ // use filter <feDropShadow>
2968
+ // @see https://developer.mozilla.org/en-US/docs/Web/SVG/Element/feDropShadow
2969
+ $el === null || $el === void 0 ? void 0 : $el.setAttribute('filter', "url(#" + shadowId + ")");
2970
+ } else {
2971
+ $el === null || $el === void 0 ? void 0 : $el.removeAttribute('filter');
2972
+ }
2577
2973
  }
2578
2974
 
2579
- var CreateElementContribution = manaSyringe.Syringe.defineToken('CreateElementContribution', {
2580
- multiple: false
2581
- });
2582
-
2583
- var DefaultElementContribution = /*#__PURE__*/function () {
2584
- function DefaultElementContribution() {}
2585
-
2586
- var _proto = DefaultElementContribution.prototype;
2587
-
2588
- _proto.createElement = function createElement(object) {
2589
- return createSVGElement(object.nodeName);
2590
- };
2591
-
2592
- return DefaultElementContribution;
2593
- }();
2594
-
2595
- DefaultElementContribution = __decorate([manaSyringe.singleton({
2596
- token: CreateElementContribution
2597
- })], DefaultElementContribution);
2598
-
2599
- var _SHAPE2TAGS, _class$1;
2975
+ var _class$1;
2600
2976
 
2601
2977
  var SVGRendererPlugin_1;
2602
- var SHAPE2TAGS = (_SHAPE2TAGS = {}, _SHAPE2TAGS[g.Shape.RECT] = 'path', _SHAPE2TAGS[g.Shape.CIRCLE] = 'circle', _SHAPE2TAGS[g.Shape.ELLIPSE] = 'ellipse', _SHAPE2TAGS[g.Shape.IMAGE] = 'image', _SHAPE2TAGS[g.Shape.GROUP] = 'g', _SHAPE2TAGS[g.Shape.LINE] = 'line', _SHAPE2TAGS[g.Shape.POLYLINE] = 'polyline', _SHAPE2TAGS[g.Shape.POLYGON] = 'polygon', _SHAPE2TAGS[g.Shape.TEXT] = 'text', _SHAPE2TAGS[g.Shape.PATH] = 'path', _SHAPE2TAGS[g.Shape.HTML] = 'foreignObject', _SHAPE2TAGS);
2603
2978
  var SVG_ATTR_MAP = {
2604
2979
  opacity: 'opacity',
2605
2980
  fillStyle: 'fill',
@@ -2686,10 +3061,10 @@
2686
3061
  this.contextService = void 0;
2687
3062
  this.renderingContext = void 0;
2688
3063
  this.createElementContribution = void 0;
2689
- this.elementRendererFactory = void 0;
2690
3064
  this.$def = void 0;
2691
3065
  this.$camera = void 0;
2692
3066
  this.renderQueue = [];
3067
+ this.pendingReorderQueue = new Set();
2693
3068
  }
2694
3069
 
2695
3070
  var _proto = SVGRendererPlugin.prototype;
@@ -2697,10 +3072,12 @@
2697
3072
  _proto.apply = function apply(renderingService) {
2698
3073
  var _this = this;
2699
3074
 
3075
+ var document = this.canvasConfig.document;
3076
+
2700
3077
  var handleMounted = function handleMounted(e) {
2701
3078
  var object = e.target; // create SVG DOM Node
2702
3079
 
2703
- _this.createSVGDom(object, _this.$camera);
3080
+ _this.createSVGDom(document, object, _this.$camera);
2704
3081
  };
2705
3082
 
2706
3083
  var handleUnmounted = function handleUnmounted(e) {
@@ -2728,7 +3105,7 @@
2728
3105
  var children = ((parent === null || parent === void 0 ? void 0 : parent.children) || []).slice();
2729
3106
 
2730
3107
  if ($groupEl) {
2731
- _this.reorderChildren($groupEl, children);
3108
+ _this.reorderChildren(document, $groupEl, children);
2732
3109
  }
2733
3110
  } else if (attrName === 'increasedLineWidthForHitTesting') {
2734
3111
  // @ts-ignore
@@ -2740,15 +3117,36 @@
2740
3117
  _this.updateAttribute(object, [attrName]);
2741
3118
  };
2742
3119
 
2743
- renderingService.hooks.init.tapPromise(SVGRendererPlugin_1.tag, /*#__PURE__*/_asyncToGenerator$1( /*#__PURE__*/_regeneratorRuntime$1().mark(function _callee() {
2744
- var $svg, background;
2745
- return _regeneratorRuntime$1().wrap(function _callee$(_context) {
3120
+ var handleGeometryBoundsChanged = function handleGeometryBoundsChanged(e) {
3121
+ var _object$elementSVG;
3122
+
3123
+ var doc = _this.canvasConfig.document;
3124
+ var object = e.target; // @ts-ignore
3125
+
3126
+ var $el = (_object$elementSVG = object.elementSVG) === null || _object$elementSVG === void 0 ? void 0 : _object$elementSVG.$el;
3127
+ var _object$parsedStyle = object.parsedStyle,
3128
+ fill = _object$parsedStyle.fill,
3129
+ stroke = _object$parsedStyle.stroke;
3130
+
3131
+ if (fill && !(fill instanceof g.CSSRGB)) {
3132
+ createOrUpdateGradientAndPattern(doc || document, _this.$def, object, $el, fill, 'fill');
3133
+ }
3134
+
3135
+ if (stroke && !(stroke instanceof g.CSSRGB)) {
3136
+ createOrUpdateGradientAndPattern(doc || document, _this.$def, object, $el, stroke, 'stroke');
3137
+ }
3138
+ };
3139
+
3140
+ renderingService.hooks.init.tapPromise(SVGRendererPlugin_1.tag, /*#__PURE__*/_asyncToGenerator$2( /*#__PURE__*/_regeneratorRuntime$2().mark(function _callee() {
3141
+ var _this$canvasConfig, background, document, $svg;
3142
+
3143
+ return _regeneratorRuntime$2().wrap(function _callee$(_context) {
2746
3144
  while (1) {
2747
3145
  switch (_context.prev = _context.next) {
2748
3146
  case 0:
2749
- _this.$def = createSVGElement('defs');
3147
+ _this$canvasConfig = _this.canvasConfig, background = _this$canvasConfig.background, document = _this$canvasConfig.document;
3148
+ _this.$def = createSVGElement('defs', document);
2750
3149
  $svg = _this.contextService.getContext();
2751
- background = _this.canvasConfig.background;
2752
3150
 
2753
3151
  if (background) {
2754
3152
  $svg.style.background = background;
@@ -2757,7 +3155,7 @@
2757
3155
  $svg.appendChild(_this.$def); // @see https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/color-interpolation-filters
2758
3156
 
2759
3157
  $svg.setAttribute('color-interpolation-filters', 'sRGB');
2760
- _this.$camera = createSVGElement('g');
3158
+ _this.$camera = createSVGElement('g', document);
2761
3159
  _this.$camera.id = G_SVG_PREFIX + "_camera";
2762
3160
 
2763
3161
  _this.applyTransform(_this.$camera, _this.camera.getOrthoMatrix());
@@ -2770,7 +3168,9 @@
2770
3168
 
2771
3169
  _this.renderingContext.root.addEventListener(g.ElementEvent.ATTR_MODIFIED, handleAttributeChanged);
2772
3170
 
2773
- case 13:
3171
+ _this.renderingContext.root.addEventListener(g.ElementEvent.GEOMETRY_BOUNDS_CHANGED, handleGeometryBoundsChanged);
3172
+
3173
+ case 14:
2774
3174
  case "end":
2775
3175
  return _context.stop();
2776
3176
  }
@@ -2783,24 +3183,45 @@
2783
3183
  _this.renderingContext.root.removeEventListener(g.ElementEvent.UNMOUNTED, handleUnmounted);
2784
3184
 
2785
3185
  _this.renderingContext.root.removeEventListener(g.ElementEvent.ATTR_MODIFIED, handleAttributeChanged);
3186
+
3187
+ _this.renderingContext.root.removeEventListener(g.ElementEvent.GEOMETRY_BOUNDS_CHANGED, handleGeometryBoundsChanged);
2786
3188
  });
2787
3189
  renderingService.hooks.render.tap(SVGRendererPlugin_1.tag, function (object) {
2788
3190
  // if (!object.isCulled()) {
2789
3191
  _this.renderQueue.push(object); // }
2790
3192
 
2791
3193
  });
3194
+ renderingService.hooks.beginFrame.tap(SVGRendererPlugin_1.tag, function () {
3195
+ var doc = _this.canvasConfig.document;
3196
+
3197
+ if (_this.pendingReorderQueue.size) {
3198
+ _this.pendingReorderQueue.forEach(function (object) {
3199
+ var _object$elementSVG2;
3200
+
3201
+ var children = ((object === null || object === void 0 ? void 0 : object.children) || []).slice();
3202
+ var $parentGroupEl = // @ts-ignore
3203
+ object === null || object === void 0 ? void 0 : (_object$elementSVG2 = object.elementSVG) === null || _object$elementSVG2 === void 0 ? void 0 : _object$elementSVG2.$groupEl;
3204
+
3205
+ if ($parentGroupEl) {
3206
+ _this.reorderChildren(doc || document, $parentGroupEl, children || []);
3207
+ }
3208
+ });
3209
+
3210
+ _this.pendingReorderQueue.clear();
3211
+ }
3212
+ });
2792
3213
  renderingService.hooks.endFrame.tap(SVGRendererPlugin_1.tag, function () {
2793
3214
  if (_this.renderingContext.renderReasons.has(g.RenderReason.CAMERA_CHANGED)) {
2794
3215
  _this.applyTransform(_this.$camera, _this.camera.getOrthoMatrix());
2795
3216
  }
2796
3217
 
2797
3218
  _this.renderQueue.forEach(function (object) {
2798
- var _object$elementSVG, _object$elementSVG2; // @ts-ignore
3219
+ var _object$elementSVG3, _object$elementSVG4; // @ts-ignore
2799
3220
 
2800
3221
 
2801
- var $el = (_object$elementSVG = object.elementSVG) === null || _object$elementSVG === void 0 ? void 0 : _object$elementSVG.$el; // @ts-ignore
3222
+ var $el = (_object$elementSVG3 = object.elementSVG) === null || _object$elementSVG3 === void 0 ? void 0 : _object$elementSVG3.$el; // @ts-ignore
2802
3223
 
2803
- var $groupEl = (_object$elementSVG2 = object.elementSVG) === null || _object$elementSVG2 === void 0 ? void 0 : _object$elementSVG2.$groupEl;
3224
+ var $groupEl = (_object$elementSVG4 = object.elementSVG) === null || _object$elementSVG4 === void 0 ? void 0 : _object$elementSVG4.$groupEl;
2804
3225
 
2805
3226
  if ($el && $groupEl) {
2806
3227
  // apply local RTS transformation to <group> wrapper
@@ -2816,7 +3237,7 @@
2816
3237
  });
2817
3238
  };
2818
3239
 
2819
- _proto.reorderChildren = function reorderChildren($groupEl, children) {
3240
+ _proto.reorderChildren = function reorderChildren(doc, $groupEl, children) {
2820
3241
  // need to reorder parent's children
2821
3242
  children.sort(function (a, b) {
2822
3243
  return a.sortable.renderOrder - b.sortable.renderOrder;
@@ -2824,7 +3245,7 @@
2824
3245
 
2825
3246
  if (children.length) {
2826
3247
  // create empty fragment
2827
- var fragment = document.createDocumentFragment();
3248
+ var fragment = (doc || document).createDocumentFragment();
2828
3249
  children.forEach(function (child) {
2829
3250
  if (child.isConnected) {
2830
3251
  // @ts-ignore
@@ -2883,60 +3304,76 @@
2883
3304
  _proto.updateAttribute = function updateAttribute(object, attributes) {
2884
3305
  var _this2 = this;
2885
3306
 
2886
- var needGeneratePath = false; // @ts-ignore
3307
+ var document = this.canvasConfig.document; // @ts-ignore
2887
3308
 
2888
- var _object$elementSVG3 = object.elementSVG,
2889
- $el = _object$elementSVG3.$el,
2890
- $groupEl = _object$elementSVG3.$groupEl,
2891
- $hitTestingEl = _object$elementSVG3.$hitTestingEl;
3309
+ var _object$elementSVG5 = object.elementSVG,
3310
+ $el = _object$elementSVG5.$el,
3311
+ $groupEl = _object$elementSVG5.$groupEl,
3312
+ $hitTestingEl = _object$elementSVG5.$hitTestingEl;
2892
3313
  var parsedStyle = object.parsedStyle,
2893
3314
  computedStyle = object.computedStyle;
2894
- var elementRenderer = this.elementRendererFactory(object.nodeName);
3315
+ var shouldUpdateElementAttribute = attributes.some(function (name) {
3316
+ return _this2.createElementContribution.shouldUpdateElementAttribute(object, name);
3317
+ }); // need re-generate path
3318
+
3319
+ if (shouldUpdateElementAttribute && $el) {
3320
+ [$el, $hitTestingEl].forEach(function ($el) {
3321
+ if ($el) {
3322
+ _this2.createElementContribution.updateElementAttribute(object, $el);
3323
+
3324
+ if (object.nodeName !== g.Shape.TEXT) {
3325
+ _this2.updateAnchorWithTransform(object);
3326
+ }
3327
+ }
3328
+ });
3329
+ } // update common attributes
3330
+
3331
+
2895
3332
  attributes.forEach(function (name) {
2896
3333
  var usedName = SVG_ATTR_MAP[name];
2897
3334
  var computedValue = computedStyle[name];
2898
- var usedValue = parsedStyle[name]; // generate path only once
2899
-
2900
- if (!needGeneratePath && elementRenderer && elementRenderer.dependencies.indexOf(name) > -1) {
2901
- needGeneratePath = true;
2902
- } // <foreignObject>
2903
-
3335
+ var usedValue = parsedStyle[name]; // <foreignObject>
2904
3336
 
2905
3337
  if (object.nodeName === g.Shape.HTML) {
2906
- if (name === 'fill') {
2907
- $el.style.background = usedValue.toString();
2908
- } else if (name === 'stroke') {
2909
- $el.style['border-color'] = usedValue.toString();
2910
- $el.style['border-style'] = 'solid';
2911
- } else if (name === 'lineWidth') {
3338
+ if (name === 'lineWidth') {
2912
3339
  $el.style['border-width'] = (usedValue.value || 0) + "px";
2913
3340
  } else if (name === 'lineDash') {
2914
3341
  $el.style['border-style'] = 'dashed';
2915
3342
  }
2916
3343
  }
2917
3344
 
2918
- if (name === 'fill' || name === 'stroke') {
2919
- createOrUpdateGradientAndPattern(_this2.$def, object, $el, usedValue, usedName);
2920
- } else if (name === 'visibility') {
3345
+ if (name === 'fill') {
3346
+ if (object.nodeName === g.Shape.HTML) {
3347
+ $el.style.background = usedValue.toString();
3348
+ } else {
3349
+ createOrUpdateGradientAndPattern(document, _this2.$def, object, $el, usedValue, usedName);
3350
+ }
3351
+ } else if (name === 'stroke') {
3352
+ if (object.nodeName === g.Shape.HTML) {
3353
+ $el.style['border-color'] = usedValue.toString();
3354
+ $el.style['border-style'] = 'solid';
3355
+ } else {
3356
+ createOrUpdateGradientAndPattern(document, _this2.$def, object, $el, usedValue, usedName);
3357
+ }
3358
+ } else if (name === 'visibility' && computedValue.value !== 'unset') {
2921
3359
  // use computed value
2922
3360
  // update `visibility` on <group>
2923
3361
  $groupEl === null || $groupEl === void 0 ? void 0 : $groupEl.setAttribute(usedName, "" + computedValue.value);
2924
3362
  } else if (name === 'clipPath') {
2925
- _this2.createOrUpdateClipPath(usedValue, $groupEl);
3363
+ _this2.createOrUpdateClipPath(document, usedValue, $groupEl);
2926
3364
  } else if (name === 'shadowColor' || name === 'shadowBlur' || name === 'shadowOffsetX' || name === 'shadowOffsetY') {
2927
- createOrUpdateShadow(_this2.$def, object, $el, name);
3365
+ createOrUpdateShadow(document, _this2.$def, object, $el, name);
2928
3366
  } else if (name === 'filter') {
2929
- createOrUpdateFilter(_this2.$def, object, $el, usedValue);
3367
+ createOrUpdateFilter(document, _this2.$def, object, $el, usedValue);
2930
3368
  } else if (name === 'innerHTML') {
2931
- _this2.createOrUpdateInnerHTML($el, usedValue);
2932
- } else {
2933
- if ( // (!object.style.clipPathTargets) &&
2934
- object.nodeName !== g.Shape.TEXT && // text' anchor is controlled by `textAnchor` property
2935
- ['width', 'height', 'r', 'rx', 'ry', 'anchor'].indexOf(name) > -1) {
3369
+ _this2.createOrUpdateInnerHTML(document, $el, usedValue);
3370
+ } else if (name === 'anchor') {
3371
+ // text' anchor is controlled by `textAnchor` property
3372
+ if (object.nodeName !== g.Shape.TEXT) {
2936
3373
  _this2.updateAnchorWithTransform(object);
2937
3374
  }
2938
-
2939
- if (name !== 'anchor' && computedValue) {
3375
+ } else {
3376
+ if (computedValue) {
2940
3377
  // use computed value so that we can use cascaded effect in SVG
2941
3378
  var valueStr = computedValue.toString(); // ignore 'unset' and default value
2942
3379
 
@@ -2954,18 +3391,10 @@
2954
3391
  });
2955
3392
  }
2956
3393
  }
2957
- }); // need re-generate path
2958
-
2959
- if (needGeneratePath && $el) {
2960
- [$el, $hitTestingEl].forEach(function ($el) {
2961
- if ($el) {
2962
- elementRenderer.apply($el, object.parsedStyle);
2963
- }
2964
- });
2965
- }
3394
+ });
2966
3395
  };
2967
3396
 
2968
- _proto.createSVGDom = function createSVGDom(object, root, noWrapWithGroup) {
3397
+ _proto.createSVGDom = function createSVGDom(document, object, root, noWrapWithGroup) {
2969
3398
  if (noWrapWithGroup === void 0) {
2970
3399
  noWrapWithGroup = false;
2971
3400
  } // create svg element
@@ -2976,13 +3405,12 @@
2976
3405
 
2977
3406
  var svgElement = object.elementSVG; // use <group> as default, eg. CustomElement
2978
3407
 
2979
- var type = SHAPE2TAGS[object.nodeName] || 'g';
3408
+ var $el = this.createElementContribution.createElement(object);
2980
3409
 
2981
- if (type) {
3410
+ if ($el) {
2982
3411
  var _object$parentNode$el2;
2983
3412
 
2984
- var $groupEl;
2985
- var $el = createSVGElement(type); // save $el on parsedStyle, which will be returned in getDomElement()
3413
+ var $groupEl; // save $el on parsedStyle, which will be returned in getDomElement()
2986
3414
 
2987
3415
  if (object.nodeName === g.Shape.HTML) {
2988
3416
  object.parsedStyle.$el = $el;
@@ -2990,38 +3418,35 @@
2990
3418
 
2991
3419
  $el.id = G_SVG_PREFIX + "_" + object.nodeName + "_" + object.entity;
2992
3420
 
2993
- if (type !== 'g' && !noWrapWithGroup) {
2994
- $groupEl = createSVGElement('g');
3421
+ if (($el.hasAttribute('data-wrapgroup') || $el.nodeName !== 'g') && !noWrapWithGroup) {
3422
+ $groupEl = createSVGElement('g', document);
2995
3423
  $groupEl.appendChild($el);
2996
3424
  } else {
2997
3425
  $groupEl = $el;
2998
3426
  }
2999
3427
 
3000
3428
  svgElement.$el = $el;
3001
- svgElement.$groupEl = $groupEl;
3429
+ svgElement.$groupEl = $groupEl; // apply attributes at first time
3430
+
3431
+ this.applyAttributes(object); // create hitArea if necessary
3432
+
3433
+ this.createOrUpdateHitArea(object, $el, $groupEl);
3002
3434
  var $parentGroupEl = // @ts-ignore
3003
3435
  object.parentNode && ((_object$parentNode$el2 = object.parentNode.elementSVG) === null || _object$parentNode$el2 === void 0 ? void 0 : _object$parentNode$el2.$groupEl) || root;
3004
3436
 
3005
3437
  if ($parentGroupEl) {
3006
- var _object$parentNode2;
3007
-
3008
- $parentGroupEl.appendChild($groupEl);
3009
- var children = (((_object$parentNode2 = object.parentNode) === null || _object$parentNode2 === void 0 ? void 0 : _object$parentNode2.children) || []).slice();
3010
- this.reorderChildren($parentGroupEl, children || []);
3011
- } // apply attributes at first time
3012
-
3438
+ $parentGroupEl.appendChild($groupEl); // need reorder children later
3013
3439
 
3014
- this.applyAttributes(object); // create hitArea if necessary
3015
-
3016
- this.createOrUpdateHitArea(object, $el, $groupEl);
3440
+ this.pendingReorderQueue.add(object.parentNode);
3441
+ }
3017
3442
  }
3018
3443
  };
3019
3444
 
3020
3445
  _proto.removeSVGDom = function removeSVGDom(object) {
3021
- var _object$elementSVG4; // @ts-ignore
3446
+ var _object$elementSVG6; // @ts-ignore
3022
3447
 
3023
3448
 
3024
- var $groupEl = (_object$elementSVG4 = object.elementSVG) === null || _object$elementSVG4 === void 0 ? void 0 : _object$elementSVG4.$groupEl;
3449
+ var $groupEl = (_object$elementSVG6 = object.elementSVG) === null || _object$elementSVG6 === void 0 ? void 0 : _object$elementSVG6.$groupEl;
3025
3450
 
3026
3451
  if ($groupEl && $groupEl.parentNode) {
3027
3452
  $groupEl.parentNode.removeChild($groupEl); // object.entity.removeComponent(ElementSVG, true);
@@ -3065,8 +3490,8 @@
3065
3490
  }
3066
3491
  };
3067
3492
 
3068
- _proto.createOrUpdateInnerHTML = function createOrUpdateInnerHTML($el, usedValue) {
3069
- var $div = document.createElement('div');
3493
+ _proto.createOrUpdateInnerHTML = function createOrUpdateInnerHTML(doc, $el, usedValue) {
3494
+ var $div = (doc || document).createElement('div');
3070
3495
 
3071
3496
  if (typeof usedValue === 'string') {
3072
3497
  $div.innerHTML = usedValue;
@@ -3078,7 +3503,7 @@
3078
3503
  $el.appendChild($div);
3079
3504
  };
3080
3505
 
3081
- _proto.createOrUpdateClipPath = function createOrUpdateClipPath(clipPath, $groupEl) {
3506
+ _proto.createOrUpdateClipPath = function createOrUpdateClipPath(document, clipPath, $groupEl) {
3082
3507
  if (clipPath) {
3083
3508
  var _clipPath$elementSVG;
3084
3509
 
@@ -3087,11 +3512,11 @@
3087
3512
 
3088
3513
  if (!existed) {
3089
3514
  // create <clipPath> dom node, append it to <defs>
3090
- var $clipPath = createSVGElement('clipPath');
3515
+ var $clipPath = createSVGElement('clipPath', document);
3091
3516
  $clipPath.id = clipPathId;
3092
3517
  this.$def.appendChild($clipPath); // <clipPath><circle /></clipPath>
3093
3518
 
3094
- this.createSVGDom(clipPath, $clipPath, true); // @ts-ignore
3519
+ this.createSVGDom(document, clipPath, $clipPath, true); // @ts-ignore
3095
3520
 
3096
3521
  clipPath.elementSVG.$groupEl = $clipPath;
3097
3522
  } // @ts-ignore
@@ -3120,7 +3545,7 @@
3120
3545
  ;
3121
3546
 
3122
3547
  _proto.updateAnchorWithTransform = function updateAnchorWithTransform(object) {
3123
- var _object$elementSVG5, _object$elementSVG6;
3548
+ var _object$elementSVG7, _object$elementSVG8;
3124
3549
 
3125
3550
  var bounds = object.getGeometryBounds();
3126
3551
  var width = bounds && bounds.halfExtents[0] * 2 || 0;
@@ -3130,7 +3555,7 @@
3130
3555
  anchor = _ref2.anchor; // @ts-ignore
3131
3556
 
3132
3557
 
3133
- [(_object$elementSVG5 = object.elementSVG) === null || _object$elementSVG5 === void 0 ? void 0 : _object$elementSVG5.$el, (_object$elementSVG6 = object.elementSVG) === null || _object$elementSVG6 === void 0 ? void 0 : _object$elementSVG6.$hitTestingEl].forEach(function ($el) {
3558
+ [(_object$elementSVG7 = object.elementSVG) === null || _object$elementSVG7 === void 0 ? void 0 : _object$elementSVG7.$el, (_object$elementSVG8 = object.elementSVG) === null || _object$elementSVG8 === void 0 ? void 0 : _object$elementSVG8.$hitTestingEl].forEach(function ($el) {
3134
3559
  if ($el) {
3135
3560
  // apply anchor to element's `transform` property
3136
3561
  $el.setAttribute('transform', // can't use percent unit like translate(-50%, -50%)
@@ -3158,44 +3583,11 @@
3158
3583
 
3159
3584
  __decorate([manaSyringe.inject(CreateElementContribution), __metadata("design:type", Object)], SVGRendererPlugin.prototype, "createElementContribution", void 0);
3160
3585
 
3161
- __decorate([manaSyringe.inject(ElementRendererFactory), __metadata("design:type", Function)], SVGRendererPlugin.prototype, "elementRendererFactory", void 0);
3162
-
3163
3586
  SVGRendererPlugin = SVGRendererPlugin_1 = __decorate([manaSyringe.singleton({
3164
3587
  contrib: g.RenderingPluginContribution
3165
3588
  })], SVGRendererPlugin);
3166
3589
  var containerModule$1 = manaSyringe.Module(function (register) {
3167
- /**
3168
- * register shape renderers
3169
- */
3170
- register(RectRenderer);
3171
- register(ImageRenderer);
3172
- register(LineRenderer);
3173
- register(PolylineRenderer);
3174
- register(TextRenderer);
3175
- register(PathRenderer);
3176
- register({
3177
- token: ElementRendererFactory,
3178
- useFactory: function useFactory(ctx) {
3179
- return function (tagName) {
3180
- if (tagName === g.Shape.RECT) {
3181
- return ctx.container.get(RectRenderer);
3182
- } else if (tagName === g.Shape.IMAGE) {
3183
- return ctx.container.get(ImageRenderer);
3184
- } else if (tagName === g.Shape.LINE) {
3185
- return ctx.container.get(LineRenderer);
3186
- } else if (tagName === g.Shape.POLYLINE || tagName === g.Shape.POLYGON) {
3187
- return ctx.container.get(PolylineRenderer);
3188
- } else if (tagName === g.Shape.TEXT) {
3189
- return ctx.container.get(TextRenderer);
3190
- } else if (tagName === g.Shape.PATH) {
3191
- return ctx.container.get(PathRenderer);
3192
- }
3193
-
3194
- return null;
3195
- };
3196
- }
3197
- });
3198
- register(DefaultElementContribution);
3590
+ register(DefaultCreateElementContribution);
3199
3591
  register(SVGRendererPlugin);
3200
3592
  });
3201
3593
 
@@ -3219,20 +3611,29 @@
3219
3611
 
3220
3612
  var index_esm$1 = /*#__PURE__*/Object.freeze({
3221
3613
  __proto__: null,
3614
+ CreateElementContribution: CreateElementContribution,
3222
3615
  DEFAULT_VALUE_MAP: DEFAULT_VALUE_MAP,
3616
+ get DefaultCreateElementContribution () { return DefaultCreateElementContribution; },
3223
3617
  ElementSVG: ElementSVG,
3224
3618
  G_SVG_PREFIX: G_SVG_PREFIX,
3225
3619
  Plugin: Plugin$1,
3226
3620
  SHAPE2TAGS: SHAPE2TAGS,
3621
+ SHAPE_UPDATE_DEPS: SHAPE_UPDATE_DEPS,
3227
3622
  get SVGRendererPlugin () { return SVGRendererPlugin; },
3228
3623
  SVG_ATTR_MAP: SVG_ATTR_MAP,
3229
3624
  containerModule: containerModule$1,
3230
- createSVGElement: createSVGElement
3625
+ createSVGElement: createSVGElement,
3626
+ updateImageElementAttribute: updateImageElementAttribute,
3627
+ updateLineElementAttribute: updateLineElementAttribute,
3628
+ updatePathElementAttribute: updatePathElementAttribute,
3629
+ updatePolylineElementAttribute: updatePolylineElementAttribute,
3630
+ updateRectElementAttribute: updateRectElementAttribute,
3631
+ updateTextElementAttribute: updateTextElementAttribute
3231
3632
  });
3232
3633
 
3233
- function _regeneratorRuntime$2() {
3634
+ function _regeneratorRuntime$3() {
3234
3635
  /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */
3235
- _regeneratorRuntime$2 = function _regeneratorRuntime() {
3636
+ _regeneratorRuntime$3 = function _regeneratorRuntime() {
3236
3637
  return exports;
3237
3638
  };
3238
3639
 
@@ -3580,7 +3981,7 @@
3580
3981
  }, exports;
3581
3982
  }
3582
3983
 
3583
- function asyncGeneratorStep$2(gen, resolve, reject, _next, _throw, key, arg) {
3984
+ function asyncGeneratorStep$3(gen, resolve, reject, _next, _throw, key, arg) {
3584
3985
  try {
3585
3986
  var info = gen[key](arg);
3586
3987
  var value = info.value;
@@ -3596,7 +3997,7 @@
3596
3997
  }
3597
3998
  }
3598
3999
 
3599
- function _asyncToGenerator$2(fn) {
4000
+ function _asyncToGenerator$3(fn) {
3600
4001
  return function () {
3601
4002
  var self = this,
3602
4003
  args = arguments;
@@ -3604,11 +4005,11 @@
3604
4005
  var gen = fn.apply(self, args);
3605
4006
 
3606
4007
  function _next(value) {
3607
- asyncGeneratorStep$2(gen, resolve, reject, _next, _throw, "next", value);
4008
+ asyncGeneratorStep$3(gen, resolve, reject, _next, _throw, "next", value);
3608
4009
  }
3609
4010
 
3610
4011
  function _throw(err) {
3611
- asyncGeneratorStep$2(gen, resolve, reject, _next, _throw, "throw", err);
4012
+ asyncGeneratorStep$3(gen, resolve, reject, _next, _throw, "throw", err);
3612
4013
  }
3613
4014
 
3614
4015
  _next(undefined);
@@ -3668,7 +4069,7 @@
3668
4069
 
3669
4070
  var SVGPickerPlugin = SVGPickerPlugin_1 = (_class$2 = /*#__PURE__*/function () {
3670
4071
  function SVGPickerPlugin() {
3671
- this.sceneGraphService = void 0;
4072
+ this.canvasConfig = void 0;
3672
4073
  this.displayObjectPool = void 0;
3673
4074
  }
3674
4075
 
@@ -3677,11 +4078,12 @@
3677
4078
  _proto.apply = function apply(renderingService) {
3678
4079
  var _this = this;
3679
4080
 
4081
+ var doc = this.canvasConfig.document;
3680
4082
  renderingService.hooks.pick.tapPromise(SVGPickerPlugin_1.tag, /*#__PURE__*/function () {
3681
- var _ref = _asyncToGenerator$2( /*#__PURE__*/_regeneratorRuntime$2().mark(function _callee(result) {
4083
+ var _ref = _asyncToGenerator$3( /*#__PURE__*/_regeneratorRuntime$3().mark(function _callee(result) {
3682
4084
  var topmost, _result$position, clientX, clientY, targets, _iterator, _step, element, id, index, target;
3683
4085
 
3684
- return _regeneratorRuntime$2().wrap(function _callee$(_context) {
4086
+ return _regeneratorRuntime$3().wrap(function _callee$(_context) {
3685
4087
  while (1) {
3686
4088
  switch (_context.prev = _context.next) {
3687
4089
  case 0:
@@ -3689,7 +4091,7 @@
3689
4091
  _context.prev = 1;
3690
4092
  targets = []; // @see https://developer.mozilla.org/zh-CN/docs/Web/API/Document/elementsFromPoint
3691
4093
 
3692
- _iterator = _createForOfIteratorHelperLoose(document.elementsFromPoint(clientX, clientY));
4094
+ _iterator = _createForOfIteratorHelperLoose((doc || document).elementsFromPoint(clientX, clientY));
3693
4095
 
3694
4096
  case 4:
3695
4097
  if ((_step = _iterator()).done) {
@@ -3758,7 +4160,7 @@
3758
4160
  return SVGPickerPlugin;
3759
4161
  }(), _class$2.tag = 'SVGPicker', _class$2);
3760
4162
 
3761
- __decorate([manaSyringe.inject(g.SceneGraphService), __metadata("design:type", Object)], SVGPickerPlugin.prototype, "sceneGraphService", void 0);
4163
+ __decorate([manaSyringe.inject(g.CanvasConfig), __metadata("design:type", Object)], SVGPickerPlugin.prototype, "canvasConfig", void 0);
3762
4164
 
3763
4165
  __decorate([manaSyringe.inject(g.DisplayObjectPool), __metadata("design:type", g.DisplayObjectPool)], SVGPickerPlugin.prototype, "displayObjectPool", void 0);
3764
4166
 
@@ -3802,27 +4204,48 @@
3802
4204
 
3803
4205
  var _proto = SVGContextService.prototype;
3804
4206
 
3805
- _proto.init = function init() {
3806
- var container = this.canvasConfig.container; // create container
4207
+ _proto.init = /*#__PURE__*/function () {
4208
+ var _init = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
4209
+ var _this$canvasConfig, container, doc, $namespace, dpr;
3807
4210
 
3808
- this.$container = g.isString(container) ? document.getElementById(container) : container;
4211
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
4212
+ while (1) {
4213
+ switch (_context.prev = _context.next) {
4214
+ case 0:
4215
+ _this$canvasConfig = this.canvasConfig, container = _this$canvasConfig.container, doc = _this$canvasConfig.document; // create container
3809
4216
 
3810
- if (this.$container) {
3811
- if (!this.$container.style.position) {
3812
- this.$container.style.position = 'relative';
3813
- }
4217
+ this.$container = g.isString(container) ? (doc || document).getElementById(container) : container;
4218
+
4219
+ if (this.$container) {
4220
+ if (!this.$container.style.position) {
4221
+ this.$container.style.position = 'relative';
4222
+ }
4223
+
4224
+ $namespace = createSVGElement('svg', doc);
4225
+ $namespace.setAttribute('width', "" + this.canvasConfig.width);
4226
+ $namespace.setAttribute('height', "" + this.canvasConfig.height);
4227
+ this.$container.appendChild($namespace);
4228
+ this.$namespace = $namespace;
4229
+ }
4230
+
4231
+ dpr = window.devicePixelRatio || 1;
4232
+ dpr = dpr >= 1 ? Math.ceil(dpr) : 1;
4233
+ this.dpr = dpr;
4234
+
4235
+ case 6:
4236
+ case "end":
4237
+ return _context.stop();
4238
+ }
4239
+ }
4240
+ }, _callee, this);
4241
+ }));
3814
4242
 
3815
- var $namespace = createSVGElement('svg');
3816
- $namespace.setAttribute('width', "" + this.canvasConfig.width);
3817
- $namespace.setAttribute('height', "" + this.canvasConfig.height);
3818
- this.$container.appendChild($namespace);
3819
- this.$namespace = $namespace;
4243
+ function init() {
4244
+ return _init.apply(this, arguments);
3820
4245
  }
3821
4246
 
3822
- var dpr = window.devicePixelRatio || 1;
3823
- dpr = dpr >= 1 ? Math.ceil(dpr) : 1;
3824
- this.dpr = dpr;
3825
- } // @ts-ignore
4247
+ return init;
4248
+ }() // @ts-ignore
3826
4249
  ;
3827
4250
 
3828
4251
  _proto.getDomElement = function getDomElement() {