@antv/g-svg 1.8.60 → 1.9.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/ContextRegisterPlugin.d.ts +6 -7
- package/dist/SVGContextService.d.ts +19 -20
- package/dist/index.d.ts +15 -16
- package/dist/index.esm.js +176 -595
- package/dist/index.esm.js.map +1 -0
- package/dist/index.js +191 -613
- package/dist/index.js.map +1 -0
- package/dist/index.umd.min.js +2 -1
- package/dist/index.umd.min.js.map +1 -0
- package/package.json +19 -15
- package/dist/ContextRegisterPlugin.d.ts.map +0 -1
- package/dist/SVGContextService.d.ts.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/index.umd.js +0 -3271
package/dist/index.umd.js
DELETED
|
@@ -1,3271 +0,0 @@
|
|
|
1
|
-
(function (global, factory) {
|
|
2
|
-
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@antv/g-lite')) :
|
|
3
|
-
typeof define === 'function' && define.amd ? define(['exports', '@antv/g-lite'], factory) :
|
|
4
|
-
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory((global.G = global.G || {}, global.G.SVG = {}), global.window.G));
|
|
5
|
-
}(this, (function (exports, gLite) { 'use strict';
|
|
6
|
-
|
|
7
|
-
function _regeneratorRuntime() {
|
|
8
|
-
_regeneratorRuntime = function () {
|
|
9
|
-
return exports;
|
|
10
|
-
};
|
|
11
|
-
var exports = {},
|
|
12
|
-
Op = Object.prototype,
|
|
13
|
-
hasOwn = Op.hasOwnProperty,
|
|
14
|
-
defineProperty = Object.defineProperty || function (obj, key, desc) {
|
|
15
|
-
obj[key] = desc.value;
|
|
16
|
-
},
|
|
17
|
-
$Symbol = "function" == typeof Symbol ? Symbol : {},
|
|
18
|
-
iteratorSymbol = $Symbol.iterator || "@@iterator",
|
|
19
|
-
asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator",
|
|
20
|
-
toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag";
|
|
21
|
-
function define(obj, key, value) {
|
|
22
|
-
return Object.defineProperty(obj, key, {
|
|
23
|
-
value: value,
|
|
24
|
-
enumerable: !0,
|
|
25
|
-
configurable: !0,
|
|
26
|
-
writable: !0
|
|
27
|
-
}), obj[key];
|
|
28
|
-
}
|
|
29
|
-
try {
|
|
30
|
-
define({}, "");
|
|
31
|
-
} catch (err) {
|
|
32
|
-
define = function (obj, key, value) {
|
|
33
|
-
return obj[key] = value;
|
|
34
|
-
};
|
|
35
|
-
}
|
|
36
|
-
function wrap(innerFn, outerFn, self, tryLocsList) {
|
|
37
|
-
var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator,
|
|
38
|
-
generator = Object.create(protoGenerator.prototype),
|
|
39
|
-
context = new Context(tryLocsList || []);
|
|
40
|
-
return defineProperty(generator, "_invoke", {
|
|
41
|
-
value: makeInvokeMethod(innerFn, self, context)
|
|
42
|
-
}), generator;
|
|
43
|
-
}
|
|
44
|
-
function tryCatch(fn, obj, arg) {
|
|
45
|
-
try {
|
|
46
|
-
return {
|
|
47
|
-
type: "normal",
|
|
48
|
-
arg: fn.call(obj, arg)
|
|
49
|
-
};
|
|
50
|
-
} catch (err) {
|
|
51
|
-
return {
|
|
52
|
-
type: "throw",
|
|
53
|
-
arg: err
|
|
54
|
-
};
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
exports.wrap = wrap;
|
|
58
|
-
var ContinueSentinel = {};
|
|
59
|
-
function Generator() {}
|
|
60
|
-
function GeneratorFunction() {}
|
|
61
|
-
function GeneratorFunctionPrototype() {}
|
|
62
|
-
var IteratorPrototype = {};
|
|
63
|
-
define(IteratorPrototype, iteratorSymbol, function () {
|
|
64
|
-
return this;
|
|
65
|
-
});
|
|
66
|
-
var getProto = Object.getPrototypeOf,
|
|
67
|
-
NativeIteratorPrototype = getProto && getProto(getProto(values([])));
|
|
68
|
-
NativeIteratorPrototype && NativeIteratorPrototype !== Op && hasOwn.call(NativeIteratorPrototype, iteratorSymbol) && (IteratorPrototype = NativeIteratorPrototype);
|
|
69
|
-
var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(IteratorPrototype);
|
|
70
|
-
function defineIteratorMethods(prototype) {
|
|
71
|
-
["next", "throw", "return"].forEach(function (method) {
|
|
72
|
-
define(prototype, method, function (arg) {
|
|
73
|
-
return this._invoke(method, arg);
|
|
74
|
-
});
|
|
75
|
-
});
|
|
76
|
-
}
|
|
77
|
-
function AsyncIterator(generator, PromiseImpl) {
|
|
78
|
-
function invoke(method, arg, resolve, reject) {
|
|
79
|
-
var record = tryCatch(generator[method], generator, arg);
|
|
80
|
-
if ("throw" !== record.type) {
|
|
81
|
-
var result = record.arg,
|
|
82
|
-
value = result.value;
|
|
83
|
-
return value && "object" == typeof value && hasOwn.call(value, "__await") ? PromiseImpl.resolve(value.__await).then(function (value) {
|
|
84
|
-
invoke("next", value, resolve, reject);
|
|
85
|
-
}, function (err) {
|
|
86
|
-
invoke("throw", err, resolve, reject);
|
|
87
|
-
}) : PromiseImpl.resolve(value).then(function (unwrapped) {
|
|
88
|
-
result.value = unwrapped, resolve(result);
|
|
89
|
-
}, function (error) {
|
|
90
|
-
return invoke("throw", error, resolve, reject);
|
|
91
|
-
});
|
|
92
|
-
}
|
|
93
|
-
reject(record.arg);
|
|
94
|
-
}
|
|
95
|
-
var previousPromise;
|
|
96
|
-
defineProperty(this, "_invoke", {
|
|
97
|
-
value: function (method, arg) {
|
|
98
|
-
function callInvokeWithMethodAndArg() {
|
|
99
|
-
return new PromiseImpl(function (resolve, reject) {
|
|
100
|
-
invoke(method, arg, resolve, reject);
|
|
101
|
-
});
|
|
102
|
-
}
|
|
103
|
-
return previousPromise = previousPromise ? previousPromise.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg();
|
|
104
|
-
}
|
|
105
|
-
});
|
|
106
|
-
}
|
|
107
|
-
function makeInvokeMethod(innerFn, self, context) {
|
|
108
|
-
var state = "suspendedStart";
|
|
109
|
-
return function (method, arg) {
|
|
110
|
-
if ("executing" === state) throw new Error("Generator is already running");
|
|
111
|
-
if ("completed" === state) {
|
|
112
|
-
if ("throw" === method) throw arg;
|
|
113
|
-
return doneResult();
|
|
114
|
-
}
|
|
115
|
-
for (context.method = method, context.arg = arg;;) {
|
|
116
|
-
var delegate = context.delegate;
|
|
117
|
-
if (delegate) {
|
|
118
|
-
var delegateResult = maybeInvokeDelegate(delegate, context);
|
|
119
|
-
if (delegateResult) {
|
|
120
|
-
if (delegateResult === ContinueSentinel) continue;
|
|
121
|
-
return delegateResult;
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
if ("next" === context.method) context.sent = context._sent = context.arg;else if ("throw" === context.method) {
|
|
125
|
-
if ("suspendedStart" === state) throw state = "completed", context.arg;
|
|
126
|
-
context.dispatchException(context.arg);
|
|
127
|
-
} else "return" === context.method && context.abrupt("return", context.arg);
|
|
128
|
-
state = "executing";
|
|
129
|
-
var record = tryCatch(innerFn, self, context);
|
|
130
|
-
if ("normal" === record.type) {
|
|
131
|
-
if (state = context.done ? "completed" : "suspendedYield", record.arg === ContinueSentinel) continue;
|
|
132
|
-
return {
|
|
133
|
-
value: record.arg,
|
|
134
|
-
done: context.done
|
|
135
|
-
};
|
|
136
|
-
}
|
|
137
|
-
"throw" === record.type && (state = "completed", context.method = "throw", context.arg = record.arg);
|
|
138
|
-
}
|
|
139
|
-
};
|
|
140
|
-
}
|
|
141
|
-
function maybeInvokeDelegate(delegate, context) {
|
|
142
|
-
var methodName = context.method,
|
|
143
|
-
method = delegate.iterator[methodName];
|
|
144
|
-
if (undefined === method) return context.delegate = null, "throw" === methodName && delegate.iterator.return && (context.method = "return", context.arg = undefined, maybeInvokeDelegate(delegate, context), "throw" === context.method) || "return" !== methodName && (context.method = "throw", context.arg = new TypeError("The iterator does not provide a '" + methodName + "' method")), ContinueSentinel;
|
|
145
|
-
var record = tryCatch(method, delegate.iterator, context.arg);
|
|
146
|
-
if ("throw" === record.type) return context.method = "throw", context.arg = record.arg, context.delegate = null, ContinueSentinel;
|
|
147
|
-
var info = record.arg;
|
|
148
|
-
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);
|
|
149
|
-
}
|
|
150
|
-
function pushTryEntry(locs) {
|
|
151
|
-
var entry = {
|
|
152
|
-
tryLoc: locs[0]
|
|
153
|
-
};
|
|
154
|
-
1 in locs && (entry.catchLoc = locs[1]), 2 in locs && (entry.finallyLoc = locs[2], entry.afterLoc = locs[3]), this.tryEntries.push(entry);
|
|
155
|
-
}
|
|
156
|
-
function resetTryEntry(entry) {
|
|
157
|
-
var record = entry.completion || {};
|
|
158
|
-
record.type = "normal", delete record.arg, entry.completion = record;
|
|
159
|
-
}
|
|
160
|
-
function Context(tryLocsList) {
|
|
161
|
-
this.tryEntries = [{
|
|
162
|
-
tryLoc: "root"
|
|
163
|
-
}], tryLocsList.forEach(pushTryEntry, this), this.reset(!0);
|
|
164
|
-
}
|
|
165
|
-
function values(iterable) {
|
|
166
|
-
if (iterable) {
|
|
167
|
-
var iteratorMethod = iterable[iteratorSymbol];
|
|
168
|
-
if (iteratorMethod) return iteratorMethod.call(iterable);
|
|
169
|
-
if ("function" == typeof iterable.next) return iterable;
|
|
170
|
-
if (!isNaN(iterable.length)) {
|
|
171
|
-
var i = -1,
|
|
172
|
-
next = function next() {
|
|
173
|
-
for (; ++i < iterable.length;) if (hasOwn.call(iterable, i)) return next.value = iterable[i], next.done = !1, next;
|
|
174
|
-
return next.value = undefined, next.done = !0, next;
|
|
175
|
-
};
|
|
176
|
-
return next.next = next;
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
return {
|
|
180
|
-
next: doneResult
|
|
181
|
-
};
|
|
182
|
-
}
|
|
183
|
-
function doneResult() {
|
|
184
|
-
return {
|
|
185
|
-
value: undefined,
|
|
186
|
-
done: !0
|
|
187
|
-
};
|
|
188
|
-
}
|
|
189
|
-
return GeneratorFunction.prototype = GeneratorFunctionPrototype, defineProperty(Gp, "constructor", {
|
|
190
|
-
value: GeneratorFunctionPrototype,
|
|
191
|
-
configurable: !0
|
|
192
|
-
}), defineProperty(GeneratorFunctionPrototype, "constructor", {
|
|
193
|
-
value: GeneratorFunction,
|
|
194
|
-
configurable: !0
|
|
195
|
-
}), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, toStringTagSymbol, "GeneratorFunction"), exports.isGeneratorFunction = function (genFun) {
|
|
196
|
-
var ctor = "function" == typeof genFun && genFun.constructor;
|
|
197
|
-
return !!ctor && (ctor === GeneratorFunction || "GeneratorFunction" === (ctor.displayName || ctor.name));
|
|
198
|
-
}, exports.mark = function (genFun) {
|
|
199
|
-
return Object.setPrototypeOf ? Object.setPrototypeOf(genFun, GeneratorFunctionPrototype) : (genFun.__proto__ = GeneratorFunctionPrototype, define(genFun, toStringTagSymbol, "GeneratorFunction")), genFun.prototype = Object.create(Gp), genFun;
|
|
200
|
-
}, exports.awrap = function (arg) {
|
|
201
|
-
return {
|
|
202
|
-
__await: arg
|
|
203
|
-
};
|
|
204
|
-
}, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, asyncIteratorSymbol, function () {
|
|
205
|
-
return this;
|
|
206
|
-
}), exports.AsyncIterator = AsyncIterator, exports.async = function (innerFn, outerFn, self, tryLocsList, PromiseImpl) {
|
|
207
|
-
void 0 === PromiseImpl && (PromiseImpl = Promise);
|
|
208
|
-
var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList), PromiseImpl);
|
|
209
|
-
return exports.isGeneratorFunction(outerFn) ? iter : iter.next().then(function (result) {
|
|
210
|
-
return result.done ? result.value : iter.next();
|
|
211
|
-
});
|
|
212
|
-
}, defineIteratorMethods(Gp), define(Gp, toStringTagSymbol, "Generator"), define(Gp, iteratorSymbol, function () {
|
|
213
|
-
return this;
|
|
214
|
-
}), define(Gp, "toString", function () {
|
|
215
|
-
return "[object Generator]";
|
|
216
|
-
}), exports.keys = function (val) {
|
|
217
|
-
var object = Object(val),
|
|
218
|
-
keys = [];
|
|
219
|
-
for (var key in object) keys.push(key);
|
|
220
|
-
return keys.reverse(), function next() {
|
|
221
|
-
for (; keys.length;) {
|
|
222
|
-
var key = keys.pop();
|
|
223
|
-
if (key in object) return next.value = key, next.done = !1, next;
|
|
224
|
-
}
|
|
225
|
-
return next.done = !0, next;
|
|
226
|
-
};
|
|
227
|
-
}, exports.values = values, Context.prototype = {
|
|
228
|
-
constructor: Context,
|
|
229
|
-
reset: function (skipTempReset) {
|
|
230
|
-
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);
|
|
231
|
-
},
|
|
232
|
-
stop: function () {
|
|
233
|
-
this.done = !0;
|
|
234
|
-
var rootRecord = this.tryEntries[0].completion;
|
|
235
|
-
if ("throw" === rootRecord.type) throw rootRecord.arg;
|
|
236
|
-
return this.rval;
|
|
237
|
-
},
|
|
238
|
-
dispatchException: function (exception) {
|
|
239
|
-
if (this.done) throw exception;
|
|
240
|
-
var context = this;
|
|
241
|
-
function handle(loc, caught) {
|
|
242
|
-
return record.type = "throw", record.arg = exception, context.next = loc, caught && (context.method = "next", context.arg = undefined), !!caught;
|
|
243
|
-
}
|
|
244
|
-
for (var i = this.tryEntries.length - 1; i >= 0; --i) {
|
|
245
|
-
var entry = this.tryEntries[i],
|
|
246
|
-
record = entry.completion;
|
|
247
|
-
if ("root" === entry.tryLoc) return handle("end");
|
|
248
|
-
if (entry.tryLoc <= this.prev) {
|
|
249
|
-
var hasCatch = hasOwn.call(entry, "catchLoc"),
|
|
250
|
-
hasFinally = hasOwn.call(entry, "finallyLoc");
|
|
251
|
-
if (hasCatch && hasFinally) {
|
|
252
|
-
if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0);
|
|
253
|
-
if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc);
|
|
254
|
-
} else if (hasCatch) {
|
|
255
|
-
if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0);
|
|
256
|
-
} else {
|
|
257
|
-
if (!hasFinally) throw new Error("try statement without catch or finally");
|
|
258
|
-
if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc);
|
|
259
|
-
}
|
|
260
|
-
}
|
|
261
|
-
}
|
|
262
|
-
},
|
|
263
|
-
abrupt: function (type, arg) {
|
|
264
|
-
for (var i = this.tryEntries.length - 1; i >= 0; --i) {
|
|
265
|
-
var entry = this.tryEntries[i];
|
|
266
|
-
if (entry.tryLoc <= this.prev && hasOwn.call(entry, "finallyLoc") && this.prev < entry.finallyLoc) {
|
|
267
|
-
var finallyEntry = entry;
|
|
268
|
-
break;
|
|
269
|
-
}
|
|
270
|
-
}
|
|
271
|
-
finallyEntry && ("break" === type || "continue" === type) && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc && (finallyEntry = null);
|
|
272
|
-
var record = finallyEntry ? finallyEntry.completion : {};
|
|
273
|
-
return record.type = type, record.arg = arg, finallyEntry ? (this.method = "next", this.next = finallyEntry.finallyLoc, ContinueSentinel) : this.complete(record);
|
|
274
|
-
},
|
|
275
|
-
complete: function (record, afterLoc) {
|
|
276
|
-
if ("throw" === record.type) throw record.arg;
|
|
277
|
-
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;
|
|
278
|
-
},
|
|
279
|
-
finish: function (finallyLoc) {
|
|
280
|
-
for (var i = this.tryEntries.length - 1; i >= 0; --i) {
|
|
281
|
-
var entry = this.tryEntries[i];
|
|
282
|
-
if (entry.finallyLoc === finallyLoc) return this.complete(entry.completion, entry.afterLoc), resetTryEntry(entry), ContinueSentinel;
|
|
283
|
-
}
|
|
284
|
-
},
|
|
285
|
-
catch: function (tryLoc) {
|
|
286
|
-
for (var i = this.tryEntries.length - 1; i >= 0; --i) {
|
|
287
|
-
var entry = this.tryEntries[i];
|
|
288
|
-
if (entry.tryLoc === tryLoc) {
|
|
289
|
-
var record = entry.completion;
|
|
290
|
-
if ("throw" === record.type) {
|
|
291
|
-
var thrown = record.arg;
|
|
292
|
-
resetTryEntry(entry);
|
|
293
|
-
}
|
|
294
|
-
return thrown;
|
|
295
|
-
}
|
|
296
|
-
}
|
|
297
|
-
throw new Error("illegal catch attempt");
|
|
298
|
-
},
|
|
299
|
-
delegateYield: function (iterable, resultName, nextLoc) {
|
|
300
|
-
return this.delegate = {
|
|
301
|
-
iterator: values(iterable),
|
|
302
|
-
resultName: resultName,
|
|
303
|
-
nextLoc: nextLoc
|
|
304
|
-
}, "next" === this.method && (this.arg = undefined), ContinueSentinel;
|
|
305
|
-
}
|
|
306
|
-
}, exports;
|
|
307
|
-
}
|
|
308
|
-
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
|
309
|
-
try {
|
|
310
|
-
var info = gen[key](arg);
|
|
311
|
-
var value = info.value;
|
|
312
|
-
} catch (error) {
|
|
313
|
-
reject(error);
|
|
314
|
-
return;
|
|
315
|
-
}
|
|
316
|
-
if (info.done) {
|
|
317
|
-
resolve(value);
|
|
318
|
-
} else {
|
|
319
|
-
Promise.resolve(value).then(_next, _throw);
|
|
320
|
-
}
|
|
321
|
-
}
|
|
322
|
-
function _asyncToGenerator(fn) {
|
|
323
|
-
return function () {
|
|
324
|
-
var self = this,
|
|
325
|
-
args = arguments;
|
|
326
|
-
return new Promise(function (resolve, reject) {
|
|
327
|
-
var gen = fn.apply(self, args);
|
|
328
|
-
function _next(value) {
|
|
329
|
-
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
|
|
330
|
-
}
|
|
331
|
-
function _throw(err) {
|
|
332
|
-
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
|
|
333
|
-
}
|
|
334
|
-
_next(undefined);
|
|
335
|
-
});
|
|
336
|
-
};
|
|
337
|
-
}
|
|
338
|
-
function _inheritsLoose(subClass, superClass) {
|
|
339
|
-
subClass.prototype = Object.create(superClass.prototype);
|
|
340
|
-
subClass.prototype.constructor = subClass;
|
|
341
|
-
_setPrototypeOf(subClass, superClass);
|
|
342
|
-
}
|
|
343
|
-
function _setPrototypeOf(o, p) {
|
|
344
|
-
_setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) {
|
|
345
|
-
o.__proto__ = p;
|
|
346
|
-
return o;
|
|
347
|
-
};
|
|
348
|
-
return _setPrototypeOf(o, p);
|
|
349
|
-
}
|
|
350
|
-
function _objectWithoutPropertiesLoose(source, excluded) {
|
|
351
|
-
if (source == null) return {};
|
|
352
|
-
var target = {};
|
|
353
|
-
var sourceKeys = Object.keys(source);
|
|
354
|
-
var key, i;
|
|
355
|
-
for (i = 0; i < sourceKeys.length; i++) {
|
|
356
|
-
key = sourceKeys[i];
|
|
357
|
-
if (excluded.indexOf(key) >= 0) continue;
|
|
358
|
-
target[key] = source[key];
|
|
359
|
-
}
|
|
360
|
-
return target;
|
|
361
|
-
}
|
|
362
|
-
|
|
363
|
-
function _inheritsLoose$1(subClass, superClass) {
|
|
364
|
-
subClass.prototype = Object.create(superClass.prototype);
|
|
365
|
-
subClass.prototype.constructor = subClass;
|
|
366
|
-
_setPrototypeOf$1(subClass, superClass);
|
|
367
|
-
}
|
|
368
|
-
function _setPrototypeOf$1(o, p) {
|
|
369
|
-
_setPrototypeOf$1 = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) {
|
|
370
|
-
o.__proto__ = p;
|
|
371
|
-
return o;
|
|
372
|
-
};
|
|
373
|
-
return _setPrototypeOf$1(o, p);
|
|
374
|
-
}
|
|
375
|
-
|
|
376
|
-
// const MOBILE_REGEX = /mobile|tablet|ip(ad|hone|od)|android/i;
|
|
377
|
-
/**
|
|
378
|
-
* listen to mouse/touch/pointer events on DOM wrapper, trigger pointer events
|
|
379
|
-
*/
|
|
380
|
-
var DOMInteractionPlugin = /*#__PURE__*/function () {
|
|
381
|
-
function DOMInteractionPlugin() {
|
|
382
|
-
this.context = void 0;
|
|
383
|
-
}
|
|
384
|
-
var _proto = DOMInteractionPlugin.prototype;
|
|
385
|
-
_proto.apply = function apply(context, runtime) {
|
|
386
|
-
var _this = this;
|
|
387
|
-
var renderingService = context.renderingService,
|
|
388
|
-
renderingContext = context.renderingContext,
|
|
389
|
-
config = context.config;
|
|
390
|
-
this.context = context;
|
|
391
|
-
var canvas = renderingContext.root.ownerDocument.defaultView;
|
|
392
|
-
// const SUPPORT_ONLY_TOUCH = canvas.supportsTouchEvents && MOBILE_REGEX.test(navigator.userAgent);
|
|
393
|
-
var onPointerMove = function onPointerMove(ev) {
|
|
394
|
-
renderingService.hooks.pointerMove.call(ev);
|
|
395
|
-
};
|
|
396
|
-
var onPointerUp = function onPointerUp(ev) {
|
|
397
|
-
renderingService.hooks.pointerUp.call(ev);
|
|
398
|
-
};
|
|
399
|
-
var onPointerDown = function onPointerDown(ev) {
|
|
400
|
-
renderingService.hooks.pointerDown.call(ev);
|
|
401
|
-
};
|
|
402
|
-
var onPointerOver = function onPointerOver(ev) {
|
|
403
|
-
renderingService.hooks.pointerOver.call(ev);
|
|
404
|
-
};
|
|
405
|
-
var onPointerOut = function onPointerOut(ev) {
|
|
406
|
-
renderingService.hooks.pointerOut.call(ev);
|
|
407
|
-
};
|
|
408
|
-
var onPointerCancel = function onPointerCancel(ev) {
|
|
409
|
-
renderingService.hooks.pointerCancel.call(ev);
|
|
410
|
-
};
|
|
411
|
-
var onPointerWheel = function onPointerWheel(ev) {
|
|
412
|
-
renderingService.hooks.pointerWheel.call(ev);
|
|
413
|
-
};
|
|
414
|
-
var onClick = function onClick(ev) {
|
|
415
|
-
renderingService.hooks.click.call(ev);
|
|
416
|
-
};
|
|
417
|
-
var addPointerEventListener = function addPointerEventListener($el) {
|
|
418
|
-
runtime.globalThis.document.addEventListener('pointermove', onPointerMove, true);
|
|
419
|
-
$el.addEventListener('pointerdown', onPointerDown, true);
|
|
420
|
-
$el.addEventListener('pointerleave', onPointerOut, true);
|
|
421
|
-
$el.addEventListener('pointerover', onPointerOver, true);
|
|
422
|
-
runtime.globalThis.addEventListener('pointerup', onPointerUp, true);
|
|
423
|
-
runtime.globalThis.addEventListener('pointercancel', onPointerCancel, true);
|
|
424
|
-
};
|
|
425
|
-
var addTouchEventListener = function addTouchEventListener($el) {
|
|
426
|
-
$el.addEventListener('touchstart', onPointerDown, true);
|
|
427
|
-
$el.addEventListener('touchend', onPointerUp, true);
|
|
428
|
-
$el.addEventListener('touchmove', onPointerMove, true);
|
|
429
|
-
$el.addEventListener('touchcancel', onPointerCancel, true);
|
|
430
|
-
};
|
|
431
|
-
var addMouseEventListener = function addMouseEventListener($el) {
|
|
432
|
-
runtime.globalThis.document.addEventListener('mousemove', onPointerMove, true);
|
|
433
|
-
$el.addEventListener('mousedown', onPointerDown, true);
|
|
434
|
-
$el.addEventListener('mouseout', onPointerOut, true);
|
|
435
|
-
$el.addEventListener('mouseover', onPointerOver, true);
|
|
436
|
-
runtime.globalThis.addEventListener('mouseup', onPointerUp, true);
|
|
437
|
-
};
|
|
438
|
-
var removePointerEventListener = function removePointerEventListener($el) {
|
|
439
|
-
runtime.globalThis.document.removeEventListener('pointermove', onPointerMove, true);
|
|
440
|
-
$el.removeEventListener('pointerdown', onPointerDown, true);
|
|
441
|
-
$el.removeEventListener('pointerleave', onPointerOut, true);
|
|
442
|
-
$el.removeEventListener('pointerover', onPointerOver, true);
|
|
443
|
-
runtime.globalThis.removeEventListener('pointerup', onPointerUp, true);
|
|
444
|
-
};
|
|
445
|
-
var removeTouchEventListener = function removeTouchEventListener($el) {
|
|
446
|
-
$el.removeEventListener('touchstart', onPointerDown, true);
|
|
447
|
-
$el.removeEventListener('touchend', onPointerUp, true);
|
|
448
|
-
$el.removeEventListener('touchmove', onPointerMove, true);
|
|
449
|
-
$el.removeEventListener('touchcancel', onPointerCancel, true);
|
|
450
|
-
};
|
|
451
|
-
var removeMouseEventListener = function removeMouseEventListener($el) {
|
|
452
|
-
runtime.globalThis.document.removeEventListener('mousemove', onPointerMove, true);
|
|
453
|
-
$el.removeEventListener('mousedown', onPointerDown, true);
|
|
454
|
-
$el.removeEventListener('mouseout', onPointerOut, true);
|
|
455
|
-
$el.removeEventListener('mouseover', onPointerOver, true);
|
|
456
|
-
runtime.globalThis.removeEventListener('mouseup', onPointerUp, true);
|
|
457
|
-
};
|
|
458
|
-
renderingService.hooks.init.tap(DOMInteractionPlugin.tag, function () {
|
|
459
|
-
var $el = _this.context.contextService.getDomElement();
|
|
460
|
-
// @ts-ignore
|
|
461
|
-
if (runtime.globalThis.navigator.msPointerEnabled) {
|
|
462
|
-
// @ts-ignore
|
|
463
|
-
$el.style.msContentZooming = 'none';
|
|
464
|
-
// @ts-ignore
|
|
465
|
-
$el.style.msTouchAction = 'none';
|
|
466
|
-
} else if (canvas.supportsPointerEvents) {
|
|
467
|
-
$el.style.touchAction = 'none';
|
|
468
|
-
}
|
|
469
|
-
if (canvas.supportsPointerEvents) {
|
|
470
|
-
addPointerEventListener($el);
|
|
471
|
-
} else {
|
|
472
|
-
addMouseEventListener($el);
|
|
473
|
-
}
|
|
474
|
-
if (canvas.supportsTouchEvents) {
|
|
475
|
-
addTouchEventListener($el);
|
|
476
|
-
}
|
|
477
|
-
if (config.useNativeClickEvent) {
|
|
478
|
-
$el.addEventListener('click', onClick, true);
|
|
479
|
-
}
|
|
480
|
-
// use passive event listeners
|
|
481
|
-
// @see https://zhuanlan.zhihu.com/p/24555031
|
|
482
|
-
$el.addEventListener('wheel', onPointerWheel, {
|
|
483
|
-
passive: true,
|
|
484
|
-
capture: true
|
|
485
|
-
});
|
|
486
|
-
});
|
|
487
|
-
renderingService.hooks.destroy.tap(DOMInteractionPlugin.tag, function () {
|
|
488
|
-
var $el = _this.context.contextService.getDomElement();
|
|
489
|
-
// @ts-ignore
|
|
490
|
-
if (runtime.globalThis.navigator.msPointerEnabled) {
|
|
491
|
-
// @ts-ignore
|
|
492
|
-
$el.style.msContentZooming = '';
|
|
493
|
-
// @ts-ignore
|
|
494
|
-
$el.style.msTouchAction = '';
|
|
495
|
-
} else if (canvas.supportsPointerEvents) {
|
|
496
|
-
$el.style.touchAction = '';
|
|
497
|
-
}
|
|
498
|
-
if (canvas.supportsPointerEvents) {
|
|
499
|
-
removePointerEventListener($el);
|
|
500
|
-
} else {
|
|
501
|
-
removeMouseEventListener($el);
|
|
502
|
-
}
|
|
503
|
-
if (canvas.supportsTouchEvents) {
|
|
504
|
-
removeTouchEventListener($el);
|
|
505
|
-
}
|
|
506
|
-
if (config.useNativeClickEvent) {
|
|
507
|
-
$el.removeEventListener('click', onClick, true);
|
|
508
|
-
}
|
|
509
|
-
$el.removeEventListener('wheel', onPointerWheel, true);
|
|
510
|
-
});
|
|
511
|
-
};
|
|
512
|
-
return DOMInteractionPlugin;
|
|
513
|
-
}();
|
|
514
|
-
DOMInteractionPlugin.tag = 'DOMInteraction';
|
|
515
|
-
var Plugin = /*#__PURE__*/function (_AbstractRendererPlug) {
|
|
516
|
-
_inheritsLoose$1(Plugin, _AbstractRendererPlug);
|
|
517
|
-
function Plugin() {
|
|
518
|
-
var _this;
|
|
519
|
-
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
520
|
-
args[_key] = arguments[_key];
|
|
521
|
-
}
|
|
522
|
-
_this = _AbstractRendererPlug.call.apply(_AbstractRendererPlug, [this].concat(args)) || this;
|
|
523
|
-
_this.name = 'dom-interaction';
|
|
524
|
-
return _this;
|
|
525
|
-
}
|
|
526
|
-
var _proto = Plugin.prototype;
|
|
527
|
-
_proto.init = function init() {
|
|
528
|
-
this.addRenderingPlugin(new DOMInteractionPlugin());
|
|
529
|
-
};
|
|
530
|
-
_proto.destroy = function destroy() {
|
|
531
|
-
this.removeAllRenderingPlugins();
|
|
532
|
-
};
|
|
533
|
-
return Plugin;
|
|
534
|
-
}(gLite.AbstractRendererPlugin);
|
|
535
|
-
|
|
536
|
-
var index_esm = /*#__PURE__*/Object.freeze({
|
|
537
|
-
__proto__: null,
|
|
538
|
-
Plugin: Plugin
|
|
539
|
-
});
|
|
540
|
-
|
|
541
|
-
function _regeneratorRuntime$1() {
|
|
542
|
-
_regeneratorRuntime$1 = function _regeneratorRuntime() {
|
|
543
|
-
return exports;
|
|
544
|
-
};
|
|
545
|
-
var exports = {},
|
|
546
|
-
Op = Object.prototype,
|
|
547
|
-
hasOwn = Op.hasOwnProperty,
|
|
548
|
-
defineProperty = Object.defineProperty || function (obj, key, desc) {
|
|
549
|
-
obj[key] = desc.value;
|
|
550
|
-
},
|
|
551
|
-
$Symbol = "function" == typeof Symbol ? Symbol : {},
|
|
552
|
-
iteratorSymbol = $Symbol.iterator || "@@iterator",
|
|
553
|
-
asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator",
|
|
554
|
-
toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag";
|
|
555
|
-
function define(obj, key, value) {
|
|
556
|
-
return Object.defineProperty(obj, key, {
|
|
557
|
-
value: value,
|
|
558
|
-
enumerable: !0,
|
|
559
|
-
configurable: !0,
|
|
560
|
-
writable: !0
|
|
561
|
-
}), obj[key];
|
|
562
|
-
}
|
|
563
|
-
try {
|
|
564
|
-
define({}, "");
|
|
565
|
-
} catch (err) {
|
|
566
|
-
define = function define(obj, key, value) {
|
|
567
|
-
return obj[key] = value;
|
|
568
|
-
};
|
|
569
|
-
}
|
|
570
|
-
function wrap(innerFn, outerFn, self, tryLocsList) {
|
|
571
|
-
var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator,
|
|
572
|
-
generator = Object.create(protoGenerator.prototype),
|
|
573
|
-
context = new Context(tryLocsList || []);
|
|
574
|
-
return defineProperty(generator, "_invoke", {
|
|
575
|
-
value: makeInvokeMethod(innerFn, self, context)
|
|
576
|
-
}), generator;
|
|
577
|
-
}
|
|
578
|
-
function tryCatch(fn, obj, arg) {
|
|
579
|
-
try {
|
|
580
|
-
return {
|
|
581
|
-
type: "normal",
|
|
582
|
-
arg: fn.call(obj, arg)
|
|
583
|
-
};
|
|
584
|
-
} catch (err) {
|
|
585
|
-
return {
|
|
586
|
-
type: "throw",
|
|
587
|
-
arg: err
|
|
588
|
-
};
|
|
589
|
-
}
|
|
590
|
-
}
|
|
591
|
-
exports.wrap = wrap;
|
|
592
|
-
var ContinueSentinel = {};
|
|
593
|
-
function Generator() {}
|
|
594
|
-
function GeneratorFunction() {}
|
|
595
|
-
function GeneratorFunctionPrototype() {}
|
|
596
|
-
var IteratorPrototype = {};
|
|
597
|
-
define(IteratorPrototype, iteratorSymbol, function () {
|
|
598
|
-
return this;
|
|
599
|
-
});
|
|
600
|
-
var getProto = Object.getPrototypeOf,
|
|
601
|
-
NativeIteratorPrototype = getProto && getProto(getProto(values([])));
|
|
602
|
-
NativeIteratorPrototype && NativeIteratorPrototype !== Op && hasOwn.call(NativeIteratorPrototype, iteratorSymbol) && (IteratorPrototype = NativeIteratorPrototype);
|
|
603
|
-
var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(IteratorPrototype);
|
|
604
|
-
function defineIteratorMethods(prototype) {
|
|
605
|
-
["next", "throw", "return"].forEach(function (method) {
|
|
606
|
-
define(prototype, method, function (arg) {
|
|
607
|
-
return this._invoke(method, arg);
|
|
608
|
-
});
|
|
609
|
-
});
|
|
610
|
-
}
|
|
611
|
-
function AsyncIterator(generator, PromiseImpl) {
|
|
612
|
-
function invoke(method, arg, resolve, reject) {
|
|
613
|
-
var record = tryCatch(generator[method], generator, arg);
|
|
614
|
-
if ("throw" !== record.type) {
|
|
615
|
-
var result = record.arg,
|
|
616
|
-
value = result.value;
|
|
617
|
-
return value && "object" == typeof value && hasOwn.call(value, "__await") ? PromiseImpl.resolve(value.__await).then(function (value) {
|
|
618
|
-
invoke("next", value, resolve, reject);
|
|
619
|
-
}, function (err) {
|
|
620
|
-
invoke("throw", err, resolve, reject);
|
|
621
|
-
}) : PromiseImpl.resolve(value).then(function (unwrapped) {
|
|
622
|
-
result.value = unwrapped, resolve(result);
|
|
623
|
-
}, function (error) {
|
|
624
|
-
return invoke("throw", error, resolve, reject);
|
|
625
|
-
});
|
|
626
|
-
}
|
|
627
|
-
reject(record.arg);
|
|
628
|
-
}
|
|
629
|
-
var previousPromise;
|
|
630
|
-
defineProperty(this, "_invoke", {
|
|
631
|
-
value: function value(method, arg) {
|
|
632
|
-
function callInvokeWithMethodAndArg() {
|
|
633
|
-
return new PromiseImpl(function (resolve, reject) {
|
|
634
|
-
invoke(method, arg, resolve, reject);
|
|
635
|
-
});
|
|
636
|
-
}
|
|
637
|
-
return previousPromise = previousPromise ? previousPromise.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg();
|
|
638
|
-
}
|
|
639
|
-
});
|
|
640
|
-
}
|
|
641
|
-
function makeInvokeMethod(innerFn, self, context) {
|
|
642
|
-
var state = "suspendedStart";
|
|
643
|
-
return function (method, arg) {
|
|
644
|
-
if ("executing" === state) throw new Error("Generator is already running");
|
|
645
|
-
if ("completed" === state) {
|
|
646
|
-
if ("throw" === method) throw arg;
|
|
647
|
-
return doneResult();
|
|
648
|
-
}
|
|
649
|
-
for (context.method = method, context.arg = arg;;) {
|
|
650
|
-
var delegate = context.delegate;
|
|
651
|
-
if (delegate) {
|
|
652
|
-
var delegateResult = maybeInvokeDelegate(delegate, context);
|
|
653
|
-
if (delegateResult) {
|
|
654
|
-
if (delegateResult === ContinueSentinel) continue;
|
|
655
|
-
return delegateResult;
|
|
656
|
-
}
|
|
657
|
-
}
|
|
658
|
-
if ("next" === context.method) context.sent = context._sent = context.arg;else if ("throw" === context.method) {
|
|
659
|
-
if ("suspendedStart" === state) throw state = "completed", context.arg;
|
|
660
|
-
context.dispatchException(context.arg);
|
|
661
|
-
} else "return" === context.method && context.abrupt("return", context.arg);
|
|
662
|
-
state = "executing";
|
|
663
|
-
var record = tryCatch(innerFn, self, context);
|
|
664
|
-
if ("normal" === record.type) {
|
|
665
|
-
if (state = context.done ? "completed" : "suspendedYield", record.arg === ContinueSentinel) continue;
|
|
666
|
-
return {
|
|
667
|
-
value: record.arg,
|
|
668
|
-
done: context.done
|
|
669
|
-
};
|
|
670
|
-
}
|
|
671
|
-
"throw" === record.type && (state = "completed", context.method = "throw", context.arg = record.arg);
|
|
672
|
-
}
|
|
673
|
-
};
|
|
674
|
-
}
|
|
675
|
-
function maybeInvokeDelegate(delegate, context) {
|
|
676
|
-
var methodName = context.method,
|
|
677
|
-
method = delegate.iterator[methodName];
|
|
678
|
-
if (undefined === method) return context.delegate = null, "throw" === methodName && delegate.iterator.return && (context.method = "return", context.arg = undefined, maybeInvokeDelegate(delegate, context), "throw" === context.method) || "return" !== methodName && (context.method = "throw", context.arg = new TypeError("The iterator does not provide a '" + methodName + "' method")), ContinueSentinel;
|
|
679
|
-
var record = tryCatch(method, delegate.iterator, context.arg);
|
|
680
|
-
if ("throw" === record.type) return context.method = "throw", context.arg = record.arg, context.delegate = null, ContinueSentinel;
|
|
681
|
-
var info = record.arg;
|
|
682
|
-
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);
|
|
683
|
-
}
|
|
684
|
-
function pushTryEntry(locs) {
|
|
685
|
-
var entry = {
|
|
686
|
-
tryLoc: locs[0]
|
|
687
|
-
};
|
|
688
|
-
1 in locs && (entry.catchLoc = locs[1]), 2 in locs && (entry.finallyLoc = locs[2], entry.afterLoc = locs[3]), this.tryEntries.push(entry);
|
|
689
|
-
}
|
|
690
|
-
function resetTryEntry(entry) {
|
|
691
|
-
var record = entry.completion || {};
|
|
692
|
-
record.type = "normal", delete record.arg, entry.completion = record;
|
|
693
|
-
}
|
|
694
|
-
function Context(tryLocsList) {
|
|
695
|
-
this.tryEntries = [{
|
|
696
|
-
tryLoc: "root"
|
|
697
|
-
}], tryLocsList.forEach(pushTryEntry, this), this.reset(!0);
|
|
698
|
-
}
|
|
699
|
-
function values(iterable) {
|
|
700
|
-
if (iterable) {
|
|
701
|
-
var iteratorMethod = iterable[iteratorSymbol];
|
|
702
|
-
if (iteratorMethod) return iteratorMethod.call(iterable);
|
|
703
|
-
if ("function" == typeof iterable.next) return iterable;
|
|
704
|
-
if (!isNaN(iterable.length)) {
|
|
705
|
-
var i = -1,
|
|
706
|
-
next = function next() {
|
|
707
|
-
for (; ++i < iterable.length;) if (hasOwn.call(iterable, i)) return next.value = iterable[i], next.done = !1, next;
|
|
708
|
-
return next.value = undefined, next.done = !0, next;
|
|
709
|
-
};
|
|
710
|
-
return next.next = next;
|
|
711
|
-
}
|
|
712
|
-
}
|
|
713
|
-
return {
|
|
714
|
-
next: doneResult
|
|
715
|
-
};
|
|
716
|
-
}
|
|
717
|
-
function doneResult() {
|
|
718
|
-
return {
|
|
719
|
-
value: undefined,
|
|
720
|
-
done: !0
|
|
721
|
-
};
|
|
722
|
-
}
|
|
723
|
-
return GeneratorFunction.prototype = GeneratorFunctionPrototype, defineProperty(Gp, "constructor", {
|
|
724
|
-
value: GeneratorFunctionPrototype,
|
|
725
|
-
configurable: !0
|
|
726
|
-
}), defineProperty(GeneratorFunctionPrototype, "constructor", {
|
|
727
|
-
value: GeneratorFunction,
|
|
728
|
-
configurable: !0
|
|
729
|
-
}), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, toStringTagSymbol, "GeneratorFunction"), exports.isGeneratorFunction = function (genFun) {
|
|
730
|
-
var ctor = "function" == typeof genFun && genFun.constructor;
|
|
731
|
-
return !!ctor && (ctor === GeneratorFunction || "GeneratorFunction" === (ctor.displayName || ctor.name));
|
|
732
|
-
}, exports.mark = function (genFun) {
|
|
733
|
-
return Object.setPrototypeOf ? Object.setPrototypeOf(genFun, GeneratorFunctionPrototype) : (genFun.__proto__ = GeneratorFunctionPrototype, define(genFun, toStringTagSymbol, "GeneratorFunction")), genFun.prototype = Object.create(Gp), genFun;
|
|
734
|
-
}, exports.awrap = function (arg) {
|
|
735
|
-
return {
|
|
736
|
-
__await: arg
|
|
737
|
-
};
|
|
738
|
-
}, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, asyncIteratorSymbol, function () {
|
|
739
|
-
return this;
|
|
740
|
-
}), exports.AsyncIterator = AsyncIterator, exports.async = function (innerFn, outerFn, self, tryLocsList, PromiseImpl) {
|
|
741
|
-
void 0 === PromiseImpl && (PromiseImpl = Promise);
|
|
742
|
-
var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList), PromiseImpl);
|
|
743
|
-
return exports.isGeneratorFunction(outerFn) ? iter : iter.next().then(function (result) {
|
|
744
|
-
return result.done ? result.value : iter.next();
|
|
745
|
-
});
|
|
746
|
-
}, defineIteratorMethods(Gp), define(Gp, toStringTagSymbol, "Generator"), define(Gp, iteratorSymbol, function () {
|
|
747
|
-
return this;
|
|
748
|
-
}), define(Gp, "toString", function () {
|
|
749
|
-
return "[object Generator]";
|
|
750
|
-
}), exports.keys = function (val) {
|
|
751
|
-
var object = Object(val),
|
|
752
|
-
keys = [];
|
|
753
|
-
for (var key in object) keys.push(key);
|
|
754
|
-
return keys.reverse(), function next() {
|
|
755
|
-
for (; keys.length;) {
|
|
756
|
-
var key = keys.pop();
|
|
757
|
-
if (key in object) return next.value = key, next.done = !1, next;
|
|
758
|
-
}
|
|
759
|
-
return next.done = !0, next;
|
|
760
|
-
};
|
|
761
|
-
}, exports.values = values, Context.prototype = {
|
|
762
|
-
constructor: Context,
|
|
763
|
-
reset: function reset(skipTempReset) {
|
|
764
|
-
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);
|
|
765
|
-
},
|
|
766
|
-
stop: function stop() {
|
|
767
|
-
this.done = !0;
|
|
768
|
-
var rootRecord = this.tryEntries[0].completion;
|
|
769
|
-
if ("throw" === rootRecord.type) throw rootRecord.arg;
|
|
770
|
-
return this.rval;
|
|
771
|
-
},
|
|
772
|
-
dispatchException: function dispatchException(exception) {
|
|
773
|
-
if (this.done) throw exception;
|
|
774
|
-
var context = this;
|
|
775
|
-
function handle(loc, caught) {
|
|
776
|
-
return record.type = "throw", record.arg = exception, context.next = loc, caught && (context.method = "next", context.arg = undefined), !!caught;
|
|
777
|
-
}
|
|
778
|
-
for (var i = this.tryEntries.length - 1; i >= 0; --i) {
|
|
779
|
-
var entry = this.tryEntries[i],
|
|
780
|
-
record = entry.completion;
|
|
781
|
-
if ("root" === entry.tryLoc) return handle("end");
|
|
782
|
-
if (entry.tryLoc <= this.prev) {
|
|
783
|
-
var hasCatch = hasOwn.call(entry, "catchLoc"),
|
|
784
|
-
hasFinally = hasOwn.call(entry, "finallyLoc");
|
|
785
|
-
if (hasCatch && hasFinally) {
|
|
786
|
-
if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0);
|
|
787
|
-
if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc);
|
|
788
|
-
} else if (hasCatch) {
|
|
789
|
-
if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0);
|
|
790
|
-
} else {
|
|
791
|
-
if (!hasFinally) throw new Error("try statement without catch or finally");
|
|
792
|
-
if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc);
|
|
793
|
-
}
|
|
794
|
-
}
|
|
795
|
-
}
|
|
796
|
-
},
|
|
797
|
-
abrupt: function abrupt(type, arg) {
|
|
798
|
-
for (var i = this.tryEntries.length - 1; i >= 0; --i) {
|
|
799
|
-
var entry = this.tryEntries[i];
|
|
800
|
-
if (entry.tryLoc <= this.prev && hasOwn.call(entry, "finallyLoc") && this.prev < entry.finallyLoc) {
|
|
801
|
-
var finallyEntry = entry;
|
|
802
|
-
break;
|
|
803
|
-
}
|
|
804
|
-
}
|
|
805
|
-
finallyEntry && ("break" === type || "continue" === type) && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc && (finallyEntry = null);
|
|
806
|
-
var record = finallyEntry ? finallyEntry.completion : {};
|
|
807
|
-
return record.type = type, record.arg = arg, finallyEntry ? (this.method = "next", this.next = finallyEntry.finallyLoc, ContinueSentinel) : this.complete(record);
|
|
808
|
-
},
|
|
809
|
-
complete: function complete(record, afterLoc) {
|
|
810
|
-
if ("throw" === record.type) throw record.arg;
|
|
811
|
-
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;
|
|
812
|
-
},
|
|
813
|
-
finish: function finish(finallyLoc) {
|
|
814
|
-
for (var i = this.tryEntries.length - 1; i >= 0; --i) {
|
|
815
|
-
var entry = this.tryEntries[i];
|
|
816
|
-
if (entry.finallyLoc === finallyLoc) return this.complete(entry.completion, entry.afterLoc), resetTryEntry(entry), ContinueSentinel;
|
|
817
|
-
}
|
|
818
|
-
},
|
|
819
|
-
catch: function _catch(tryLoc) {
|
|
820
|
-
for (var i = this.tryEntries.length - 1; i >= 0; --i) {
|
|
821
|
-
var entry = this.tryEntries[i];
|
|
822
|
-
if (entry.tryLoc === tryLoc) {
|
|
823
|
-
var record = entry.completion;
|
|
824
|
-
if ("throw" === record.type) {
|
|
825
|
-
var thrown = record.arg;
|
|
826
|
-
resetTryEntry(entry);
|
|
827
|
-
}
|
|
828
|
-
return thrown;
|
|
829
|
-
}
|
|
830
|
-
}
|
|
831
|
-
throw new Error("illegal catch attempt");
|
|
832
|
-
},
|
|
833
|
-
delegateYield: function delegateYield(iterable, resultName, nextLoc) {
|
|
834
|
-
return this.delegate = {
|
|
835
|
-
iterator: values(iterable),
|
|
836
|
-
resultName: resultName,
|
|
837
|
-
nextLoc: nextLoc
|
|
838
|
-
}, "next" === this.method && (this.arg = undefined), ContinueSentinel;
|
|
839
|
-
}
|
|
840
|
-
}, exports;
|
|
841
|
-
}
|
|
842
|
-
function asyncGeneratorStep$1(gen, resolve, reject, _next, _throw, key, arg) {
|
|
843
|
-
try {
|
|
844
|
-
var info = gen[key](arg);
|
|
845
|
-
var value = info.value;
|
|
846
|
-
} catch (error) {
|
|
847
|
-
reject(error);
|
|
848
|
-
return;
|
|
849
|
-
}
|
|
850
|
-
if (info.done) {
|
|
851
|
-
resolve(value);
|
|
852
|
-
} else {
|
|
853
|
-
Promise.resolve(value).then(_next, _throw);
|
|
854
|
-
}
|
|
855
|
-
}
|
|
856
|
-
function _asyncToGenerator$1(fn) {
|
|
857
|
-
return function () {
|
|
858
|
-
var self = this,
|
|
859
|
-
args = arguments;
|
|
860
|
-
return new Promise(function (resolve, reject) {
|
|
861
|
-
var gen = fn.apply(self, args);
|
|
862
|
-
function _next(value) {
|
|
863
|
-
asyncGeneratorStep$1(gen, resolve, reject, _next, _throw, "next", value);
|
|
864
|
-
}
|
|
865
|
-
function _throw(err) {
|
|
866
|
-
asyncGeneratorStep$1(gen, resolve, reject, _next, _throw, "throw", err);
|
|
867
|
-
}
|
|
868
|
-
_next(undefined);
|
|
869
|
-
});
|
|
870
|
-
};
|
|
871
|
-
}
|
|
872
|
-
function _inheritsLoose$2(subClass, superClass) {
|
|
873
|
-
subClass.prototype = Object.create(superClass.prototype);
|
|
874
|
-
subClass.prototype.constructor = subClass;
|
|
875
|
-
_setPrototypeOf$2(subClass, superClass);
|
|
876
|
-
}
|
|
877
|
-
function _setPrototypeOf$2(o, p) {
|
|
878
|
-
_setPrototypeOf$2 = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) {
|
|
879
|
-
o.__proto__ = p;
|
|
880
|
-
return o;
|
|
881
|
-
};
|
|
882
|
-
return _setPrototypeOf$2(o, p);
|
|
883
|
-
}
|
|
884
|
-
function _unsupportedIterableToArray(o, minLen) {
|
|
885
|
-
if (!o) return;
|
|
886
|
-
if (typeof o === "string") return _arrayLikeToArray(o, minLen);
|
|
887
|
-
var n = Object.prototype.toString.call(o).slice(8, -1);
|
|
888
|
-
if (n === "Object" && o.constructor) n = o.constructor.name;
|
|
889
|
-
if (n === "Map" || n === "Set") return Array.from(o);
|
|
890
|
-
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
|
|
891
|
-
}
|
|
892
|
-
function _arrayLikeToArray(arr, len) {
|
|
893
|
-
if (len == null || len > arr.length) len = arr.length;
|
|
894
|
-
for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
|
|
895
|
-
return arr2;
|
|
896
|
-
}
|
|
897
|
-
function _createForOfIteratorHelperLoose(o, allowArrayLike) {
|
|
898
|
-
var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"];
|
|
899
|
-
if (it) return (it = it.call(o)).next.bind(it);
|
|
900
|
-
if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") {
|
|
901
|
-
if (it) o = it;
|
|
902
|
-
var i = 0;
|
|
903
|
-
return function () {
|
|
904
|
-
if (i >= o.length) return {
|
|
905
|
-
done: true
|
|
906
|
-
};
|
|
907
|
-
return {
|
|
908
|
-
done: false,
|
|
909
|
-
value: o[i++]
|
|
910
|
-
};
|
|
911
|
-
};
|
|
912
|
-
}
|
|
913
|
-
throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
914
|
-
}
|
|
915
|
-
|
|
916
|
-
/**
|
|
917
|
-
* pick shape(s) with Mouse/Touch event
|
|
918
|
-
*
|
|
919
|
-
* 1. find AABB with r-tree
|
|
920
|
-
* 2. use elementFromPoint
|
|
921
|
-
*/
|
|
922
|
-
var SVGPickerPlugin = /*#__PURE__*/function () {
|
|
923
|
-
function SVGPickerPlugin() {}
|
|
924
|
-
var _proto = SVGPickerPlugin.prototype;
|
|
925
|
-
_proto.apply = function apply(context, runtime) {
|
|
926
|
-
var _this = this;
|
|
927
|
-
var doc = context.config.document,
|
|
928
|
-
renderingService = context.renderingService,
|
|
929
|
-
svgElementMap = context.svgElementMap;
|
|
930
|
-
renderingService.hooks.pick.tapPromise(SVGPickerPlugin.tag, /*#__PURE__*/function () {
|
|
931
|
-
var _ref = _asyncToGenerator$1( /*#__PURE__*/_regeneratorRuntime$1().mark(function _callee(result) {
|
|
932
|
-
return _regeneratorRuntime$1().wrap(function _callee$(_context) {
|
|
933
|
-
while (1) switch (_context.prev = _context.next) {
|
|
934
|
-
case 0:
|
|
935
|
-
return _context.abrupt("return", _this.pick(svgElementMap, doc, result));
|
|
936
|
-
case 1:
|
|
937
|
-
case "end":
|
|
938
|
-
return _context.stop();
|
|
939
|
-
}
|
|
940
|
-
}, _callee);
|
|
941
|
-
}));
|
|
942
|
-
return function (_x) {
|
|
943
|
-
return _ref.apply(this, arguments);
|
|
944
|
-
};
|
|
945
|
-
}());
|
|
946
|
-
renderingService.hooks.pickSync.tap(SVGPickerPlugin.tag, function (result) {
|
|
947
|
-
return _this.pick(svgElementMap, doc, result);
|
|
948
|
-
});
|
|
949
|
-
};
|
|
950
|
-
_proto.pick = function pick(svgElementMap, doc, result) {
|
|
951
|
-
var topmost = result.topmost,
|
|
952
|
-
_result$position = result.position,
|
|
953
|
-
clientX = _result$position.clientX,
|
|
954
|
-
clientY = _result$position.clientY;
|
|
955
|
-
try {
|
|
956
|
-
var targets = [];
|
|
957
|
-
// @see https://developer.mozilla.org/zh-CN/docs/Web/API/Document/elementsFromPoint
|
|
958
|
-
for (var _iterator = _createForOfIteratorHelperLoose((doc || document).elementsFromPoint(clientX, clientY)), _step; !(_step = _iterator()).done;) {
|
|
959
|
-
var element = _step.value;
|
|
960
|
-
var target = svgElementMap.get(element);
|
|
961
|
-
// don't need to account for `visibility` since DOM API already does
|
|
962
|
-
if (target && target.isInteractive()) {
|
|
963
|
-
targets.push(target);
|
|
964
|
-
if (topmost) {
|
|
965
|
-
result.picked = targets;
|
|
966
|
-
return result;
|
|
967
|
-
}
|
|
968
|
-
}
|
|
969
|
-
}
|
|
970
|
-
result.picked = targets;
|
|
971
|
-
} catch (e) {
|
|
972
|
-
result.picked = [];
|
|
973
|
-
}
|
|
974
|
-
return result;
|
|
975
|
-
};
|
|
976
|
-
return SVGPickerPlugin;
|
|
977
|
-
}();
|
|
978
|
-
SVGPickerPlugin.tag = 'SVGPicker';
|
|
979
|
-
var Plugin$1 = /*#__PURE__*/function (_AbstractRendererPlug) {
|
|
980
|
-
_inheritsLoose$2(Plugin, _AbstractRendererPlug);
|
|
981
|
-
function Plugin() {
|
|
982
|
-
var _this;
|
|
983
|
-
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
984
|
-
args[_key] = arguments[_key];
|
|
985
|
-
}
|
|
986
|
-
_this = _AbstractRendererPlug.call.apply(_AbstractRendererPlug, [this].concat(args)) || this;
|
|
987
|
-
_this.name = 'svg-picker';
|
|
988
|
-
return _this;
|
|
989
|
-
}
|
|
990
|
-
var _proto = Plugin.prototype;
|
|
991
|
-
_proto.init = function init() {
|
|
992
|
-
this.addRenderingPlugin(new SVGPickerPlugin());
|
|
993
|
-
};
|
|
994
|
-
_proto.destroy = function destroy() {
|
|
995
|
-
this.removeAllRenderingPlugins();
|
|
996
|
-
};
|
|
997
|
-
return Plugin;
|
|
998
|
-
}(gLite.AbstractRendererPlugin);
|
|
999
|
-
|
|
1000
|
-
var index_esm$1 = /*#__PURE__*/Object.freeze({
|
|
1001
|
-
__proto__: null,
|
|
1002
|
-
Plugin: Plugin$1
|
|
1003
|
-
});
|
|
1004
|
-
|
|
1005
|
-
/**
|
|
1006
|
-
* Common utilities
|
|
1007
|
-
* @module glMatrix
|
|
1008
|
-
*/
|
|
1009
|
-
var ARRAY_TYPE = typeof Float32Array !== 'undefined' ? Float32Array : Array;
|
|
1010
|
-
if (!Math.hypot) Math.hypot = function () {
|
|
1011
|
-
var y = 0,
|
|
1012
|
-
i = arguments.length;
|
|
1013
|
-
|
|
1014
|
-
while (i--) {
|
|
1015
|
-
y += arguments[i] * arguments[i];
|
|
1016
|
-
}
|
|
1017
|
-
|
|
1018
|
-
return Math.sqrt(y);
|
|
1019
|
-
};
|
|
1020
|
-
|
|
1021
|
-
/**
|
|
1022
|
-
* 4x4 Matrix<br>Format: column-major, when typed out it looks like row-major<br>The matrices are being post multiplied.
|
|
1023
|
-
* @module mat4
|
|
1024
|
-
*/
|
|
1025
|
-
|
|
1026
|
-
/**
|
|
1027
|
-
* Creates a new identity mat4
|
|
1028
|
-
*
|
|
1029
|
-
* @returns {mat4} a new 4x4 matrix
|
|
1030
|
-
*/
|
|
1031
|
-
|
|
1032
|
-
function create() {
|
|
1033
|
-
var out = new ARRAY_TYPE(16);
|
|
1034
|
-
|
|
1035
|
-
if (ARRAY_TYPE != Float32Array) {
|
|
1036
|
-
out[1] = 0;
|
|
1037
|
-
out[2] = 0;
|
|
1038
|
-
out[3] = 0;
|
|
1039
|
-
out[4] = 0;
|
|
1040
|
-
out[6] = 0;
|
|
1041
|
-
out[7] = 0;
|
|
1042
|
-
out[8] = 0;
|
|
1043
|
-
out[9] = 0;
|
|
1044
|
-
out[11] = 0;
|
|
1045
|
-
out[12] = 0;
|
|
1046
|
-
out[13] = 0;
|
|
1047
|
-
out[14] = 0;
|
|
1048
|
-
}
|
|
1049
|
-
|
|
1050
|
-
out[0] = 1;
|
|
1051
|
-
out[5] = 1;
|
|
1052
|
-
out[10] = 1;
|
|
1053
|
-
out[15] = 1;
|
|
1054
|
-
return out;
|
|
1055
|
-
}
|
|
1056
|
-
/**
|
|
1057
|
-
* Inverts a mat4
|
|
1058
|
-
*
|
|
1059
|
-
* @param {mat4} out the receiving matrix
|
|
1060
|
-
* @param {ReadonlyMat4} a the source matrix
|
|
1061
|
-
* @returns {mat4} out
|
|
1062
|
-
*/
|
|
1063
|
-
|
|
1064
|
-
function invert(out, a) {
|
|
1065
|
-
var a00 = a[0],
|
|
1066
|
-
a01 = a[1],
|
|
1067
|
-
a02 = a[2],
|
|
1068
|
-
a03 = a[3];
|
|
1069
|
-
var a10 = a[4],
|
|
1070
|
-
a11 = a[5],
|
|
1071
|
-
a12 = a[6],
|
|
1072
|
-
a13 = a[7];
|
|
1073
|
-
var a20 = a[8],
|
|
1074
|
-
a21 = a[9],
|
|
1075
|
-
a22 = a[10],
|
|
1076
|
-
a23 = a[11];
|
|
1077
|
-
var a30 = a[12],
|
|
1078
|
-
a31 = a[13],
|
|
1079
|
-
a32 = a[14],
|
|
1080
|
-
a33 = a[15];
|
|
1081
|
-
var b00 = a00 * a11 - a01 * a10;
|
|
1082
|
-
var b01 = a00 * a12 - a02 * a10;
|
|
1083
|
-
var b02 = a00 * a13 - a03 * a10;
|
|
1084
|
-
var b03 = a01 * a12 - a02 * a11;
|
|
1085
|
-
var b04 = a01 * a13 - a03 * a11;
|
|
1086
|
-
var b05 = a02 * a13 - a03 * a12;
|
|
1087
|
-
var b06 = a20 * a31 - a21 * a30;
|
|
1088
|
-
var b07 = a20 * a32 - a22 * a30;
|
|
1089
|
-
var b08 = a20 * a33 - a23 * a30;
|
|
1090
|
-
var b09 = a21 * a32 - a22 * a31;
|
|
1091
|
-
var b10 = a21 * a33 - a23 * a31;
|
|
1092
|
-
var b11 = a22 * a33 - a23 * a32; // Calculate the determinant
|
|
1093
|
-
|
|
1094
|
-
var det = b00 * b11 - b01 * b10 + b02 * b09 + b03 * b08 - b04 * b07 + b05 * b06;
|
|
1095
|
-
|
|
1096
|
-
if (!det) {
|
|
1097
|
-
return null;
|
|
1098
|
-
}
|
|
1099
|
-
|
|
1100
|
-
det = 1.0 / det;
|
|
1101
|
-
out[0] = (a11 * b11 - a12 * b10 + a13 * b09) * det;
|
|
1102
|
-
out[1] = (a02 * b10 - a01 * b11 - a03 * b09) * det;
|
|
1103
|
-
out[2] = (a31 * b05 - a32 * b04 + a33 * b03) * det;
|
|
1104
|
-
out[3] = (a22 * b04 - a21 * b05 - a23 * b03) * det;
|
|
1105
|
-
out[4] = (a12 * b08 - a10 * b11 - a13 * b07) * det;
|
|
1106
|
-
out[5] = (a00 * b11 - a02 * b08 + a03 * b07) * det;
|
|
1107
|
-
out[6] = (a32 * b02 - a30 * b05 - a33 * b01) * det;
|
|
1108
|
-
out[7] = (a20 * b05 - a22 * b02 + a23 * b01) * det;
|
|
1109
|
-
out[8] = (a10 * b10 - a11 * b08 + a13 * b06) * det;
|
|
1110
|
-
out[9] = (a01 * b08 - a00 * b10 - a03 * b06) * det;
|
|
1111
|
-
out[10] = (a30 * b04 - a31 * b02 + a33 * b00) * det;
|
|
1112
|
-
out[11] = (a21 * b02 - a20 * b04 - a23 * b00) * det;
|
|
1113
|
-
out[12] = (a11 * b07 - a10 * b09 - a12 * b06) * det;
|
|
1114
|
-
out[13] = (a00 * b09 - a01 * b07 + a02 * b06) * det;
|
|
1115
|
-
out[14] = (a31 * b01 - a30 * b03 - a32 * b00) * det;
|
|
1116
|
-
out[15] = (a20 * b03 - a21 * b01 + a22 * b00) * det;
|
|
1117
|
-
return out;
|
|
1118
|
-
}
|
|
1119
|
-
|
|
1120
|
-
// isFinite,
|
|
1121
|
-
var isNil = function (value) {
|
|
1122
|
-
/**
|
|
1123
|
-
* isNil(null) => true
|
|
1124
|
-
* isNil() => true
|
|
1125
|
-
*/
|
|
1126
|
-
return value === null || value === undefined;
|
|
1127
|
-
};
|
|
1128
|
-
|
|
1129
|
-
var toString = {}.toString;
|
|
1130
|
-
var isType = function (value, type) { return toString.call(value) === '[object ' + type + ']'; };
|
|
1131
|
-
|
|
1132
|
-
var isString = (function (str) {
|
|
1133
|
-
return isType(str, 'String');
|
|
1134
|
-
});
|
|
1135
|
-
|
|
1136
|
-
var clamp = function (a, min, max) {
|
|
1137
|
-
if (a < min) {
|
|
1138
|
-
return min;
|
|
1139
|
-
}
|
|
1140
|
-
else if (a > max) {
|
|
1141
|
-
return max;
|
|
1142
|
-
}
|
|
1143
|
-
return a;
|
|
1144
|
-
};
|
|
1145
|
-
|
|
1146
|
-
function _extends() {
|
|
1147
|
-
_extends = Object.assign ? Object.assign.bind() : function (target) {
|
|
1148
|
-
for (var i = 1; i < arguments.length; i++) {
|
|
1149
|
-
var source = arguments[i];
|
|
1150
|
-
for (var key in source) {
|
|
1151
|
-
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
|
1152
|
-
target[key] = source[key];
|
|
1153
|
-
}
|
|
1154
|
-
}
|
|
1155
|
-
}
|
|
1156
|
-
return target;
|
|
1157
|
-
};
|
|
1158
|
-
return _extends.apply(this, arguments);
|
|
1159
|
-
}
|
|
1160
|
-
function _inheritsLoose$3(subClass, superClass) {
|
|
1161
|
-
subClass.prototype = Object.create(superClass.prototype);
|
|
1162
|
-
subClass.prototype.constructor = subClass;
|
|
1163
|
-
_setPrototypeOf$3(subClass, superClass);
|
|
1164
|
-
}
|
|
1165
|
-
function _setPrototypeOf$3(o, p) {
|
|
1166
|
-
_setPrototypeOf$3 = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) {
|
|
1167
|
-
o.__proto__ = p;
|
|
1168
|
-
return o;
|
|
1169
|
-
};
|
|
1170
|
-
return _setPrototypeOf$3(o, p);
|
|
1171
|
-
}
|
|
1172
|
-
var ElementSVG = function ElementSVG() {
|
|
1173
|
-
/**
|
|
1174
|
-
* basic element, eg. <circle>|<ellipse>
|
|
1175
|
-
*/
|
|
1176
|
-
this.$el = void 0;
|
|
1177
|
-
/**
|
|
1178
|
-
* group wrapper for basic element, eg. <g><circle /></g>.
|
|
1179
|
-
* if current element is <g>, same as `$el`
|
|
1180
|
-
*/
|
|
1181
|
-
this.$groupEl = void 0;
|
|
1182
|
-
/**
|
|
1183
|
-
* hitArea:
|
|
1184
|
-
* $groupEl -> $el
|
|
1185
|
-
* -> $hitTestingEl
|
|
1186
|
-
*/
|
|
1187
|
-
this.$hitTestingEl = void 0;
|
|
1188
|
-
};
|
|
1189
|
-
ElementSVG.tag = 'c-svg-element';
|
|
1190
|
-
function updateImageElementAttribute($el, parsedStyle) {
|
|
1191
|
-
var _parsedStyle$img = parsedStyle.img,
|
|
1192
|
-
img = _parsedStyle$img === void 0 ? '' : _parsedStyle$img,
|
|
1193
|
-
width = parsedStyle.width,
|
|
1194
|
-
height = parsedStyle.height;
|
|
1195
|
-
$el.setAttribute('x', '0');
|
|
1196
|
-
$el.setAttribute('y', '0');
|
|
1197
|
-
if (isString(img)) {
|
|
1198
|
-
$el.setAttribute('href', img);
|
|
1199
|
-
} else if (img instanceof Image) {
|
|
1200
|
-
if (!width) {
|
|
1201
|
-
$el.setAttribute('width', "" + img.width);
|
|
1202
|
-
// TODO: set renderable.boundsDirty
|
|
1203
|
-
// this.attr('width', img.width);
|
|
1204
|
-
}
|
|
1205
|
-
|
|
1206
|
-
if (!height) {
|
|
1207
|
-
$el.setAttribute('height', "" + img.height);
|
|
1208
|
-
// this.attr('height', img.height);
|
|
1209
|
-
}
|
|
1210
|
-
|
|
1211
|
-
$el.setAttribute('href', img.src);
|
|
1212
|
-
} else if (
|
|
1213
|
-
// @ts-ignore
|
|
1214
|
-
img instanceof HTMLElement && isString(img.nodeName) && img.nodeName.toUpperCase() === 'CANVAS') {
|
|
1215
|
-
$el.setAttribute('href', img.toDataURL());
|
|
1216
|
-
// @ts-ignore
|
|
1217
|
-
} else if (img instanceof ImageData) {
|
|
1218
|
-
var canvas = document.createElement('canvas');
|
|
1219
|
-
// @ts-ignore
|
|
1220
|
-
canvas.setAttribute('width', "" + img.width);
|
|
1221
|
-
// @ts-ignore
|
|
1222
|
-
canvas.setAttribute('height', "" + img.height);
|
|
1223
|
-
var context = canvas.getContext('2d');
|
|
1224
|
-
if (context) {
|
|
1225
|
-
context.putImageData(img, 0, 0);
|
|
1226
|
-
if (!width) {
|
|
1227
|
-
// @ts-ignore
|
|
1228
|
-
$el.setAttribute('width', "" + img.width);
|
|
1229
|
-
// this.attr('width', img.width);
|
|
1230
|
-
}
|
|
1231
|
-
|
|
1232
|
-
if (!height) {
|
|
1233
|
-
// @ts-ignore
|
|
1234
|
-
$el.setAttribute('height', "" + img.height);
|
|
1235
|
-
// this.attr('height', img.height);
|
|
1236
|
-
}
|
|
1237
|
-
|
|
1238
|
-
$el.setAttribute('href', canvas.toDataURL());
|
|
1239
|
-
}
|
|
1240
|
-
}
|
|
1241
|
-
}
|
|
1242
|
-
function updateLineElementAttribute($el, parsedStyle) {
|
|
1243
|
-
var x1 = parsedStyle.x1,
|
|
1244
|
-
y1 = parsedStyle.y1,
|
|
1245
|
-
x2 = parsedStyle.x2,
|
|
1246
|
-
y2 = parsedStyle.y2,
|
|
1247
|
-
_parsedStyle$defX = parsedStyle.defX,
|
|
1248
|
-
defX = _parsedStyle$defX === void 0 ? 0 : _parsedStyle$defX,
|
|
1249
|
-
_parsedStyle$defY = parsedStyle.defY,
|
|
1250
|
-
defY = _parsedStyle$defY === void 0 ? 0 : _parsedStyle$defY,
|
|
1251
|
-
markerStart = parsedStyle.markerStart,
|
|
1252
|
-
markerEnd = parsedStyle.markerEnd,
|
|
1253
|
-
markerStartOffset = parsedStyle.markerStartOffset,
|
|
1254
|
-
markerEndOffset = parsedStyle.markerEndOffset;
|
|
1255
|
-
var startOffsetX = 0;
|
|
1256
|
-
var startOffsetY = 0;
|
|
1257
|
-
var endOffsetX = 0;
|
|
1258
|
-
var endOffsetY = 0;
|
|
1259
|
-
var rad = 0;
|
|
1260
|
-
var x;
|
|
1261
|
-
var y;
|
|
1262
|
-
if (markerStart && gLite.isDisplayObject(markerStart) && markerStartOffset) {
|
|
1263
|
-
x = x2 - x1;
|
|
1264
|
-
y = y2 - y1;
|
|
1265
|
-
rad = Math.atan2(y, x);
|
|
1266
|
-
startOffsetX = Math.cos(rad) * (markerStartOffset || 0);
|
|
1267
|
-
startOffsetY = Math.sin(rad) * (markerStartOffset || 0);
|
|
1268
|
-
}
|
|
1269
|
-
if (markerEnd && gLite.isDisplayObject(markerEnd) && markerEndOffset) {
|
|
1270
|
-
x = x1 - x2;
|
|
1271
|
-
y = y1 - y2;
|
|
1272
|
-
rad = Math.atan2(y, x);
|
|
1273
|
-
endOffsetX = Math.cos(rad) * (markerEndOffset || 0);
|
|
1274
|
-
endOffsetY = Math.sin(rad) * (markerEndOffset || 0);
|
|
1275
|
-
}
|
|
1276
|
-
// @see https://github.com/antvis/g/issues/1038
|
|
1277
|
-
$el.setAttribute('x1', "" + (x1 - defX + startOffsetX));
|
|
1278
|
-
$el.setAttribute('y1', "" + (y1 - defY + startOffsetY));
|
|
1279
|
-
$el.setAttribute('x2', "" + (x2 - defX + endOffsetX));
|
|
1280
|
-
$el.setAttribute('y2', "" + (y2 - defY + endOffsetY));
|
|
1281
|
-
}
|
|
1282
|
-
function updatePathElementAttribute($el, parsedStyle) {
|
|
1283
|
-
var path = parsedStyle.path,
|
|
1284
|
-
_parsedStyle$defX = parsedStyle.defX,
|
|
1285
|
-
defX = _parsedStyle$defX === void 0 ? 0 : _parsedStyle$defX,
|
|
1286
|
-
_parsedStyle$defY = parsedStyle.defY,
|
|
1287
|
-
defY = _parsedStyle$defY === void 0 ? 0 : _parsedStyle$defY,
|
|
1288
|
-
markerStart = parsedStyle.markerStart,
|
|
1289
|
-
markerEnd = parsedStyle.markerEnd,
|
|
1290
|
-
markerStartOffset = parsedStyle.markerStartOffset,
|
|
1291
|
-
markerEndOffset = parsedStyle.markerEndOffset;
|
|
1292
|
-
var startOffsetX = 0;
|
|
1293
|
-
var startOffsetY = 0;
|
|
1294
|
-
var endOffsetX = 0;
|
|
1295
|
-
var endOffsetY = 0;
|
|
1296
|
-
var rad = 0;
|
|
1297
|
-
var x;
|
|
1298
|
-
var y;
|
|
1299
|
-
if (markerStart && gLite.isDisplayObject(markerStart) && markerStartOffset) {
|
|
1300
|
-
var _markerStart$parentNo = markerStart.parentNode.getStartTangent(),
|
|
1301
|
-
p1 = _markerStart$parentNo[0],
|
|
1302
|
-
p2 = _markerStart$parentNo[1];
|
|
1303
|
-
x = p1[0] - p2[0];
|
|
1304
|
-
y = p1[1] - p2[1];
|
|
1305
|
-
rad = Math.atan2(y, x);
|
|
1306
|
-
startOffsetX = Math.cos(rad) * (markerStartOffset || 0);
|
|
1307
|
-
startOffsetY = Math.sin(rad) * (markerStartOffset || 0);
|
|
1308
|
-
}
|
|
1309
|
-
if (markerEnd && gLite.isDisplayObject(markerEnd) && markerEndOffset) {
|
|
1310
|
-
var _markerEnd$parentNode = markerEnd.parentNode.getEndTangent(),
|
|
1311
|
-
_p = _markerEnd$parentNode[0],
|
|
1312
|
-
_p2 = _markerEnd$parentNode[1];
|
|
1313
|
-
x = _p[0] - _p2[0];
|
|
1314
|
-
y = _p[1] - _p2[1];
|
|
1315
|
-
rad = Math.atan2(y, x);
|
|
1316
|
-
endOffsetX = Math.cos(rad) * (markerEndOffset || 0);
|
|
1317
|
-
endOffsetY = Math.sin(rad) * (markerEndOffset || 0);
|
|
1318
|
-
}
|
|
1319
|
-
$el.setAttribute('d', gLite.translatePathToString(path.absolutePath, defX, defY, startOffsetX, startOffsetY, endOffsetX, endOffsetY));
|
|
1320
|
-
}
|
|
1321
|
-
function updatePolylineElementAttribute($el, parsedStyle) {
|
|
1322
|
-
var points = parsedStyle.points.points,
|
|
1323
|
-
_parsedStyle$defX = parsedStyle.defX,
|
|
1324
|
-
defX = _parsedStyle$defX === void 0 ? 0 : _parsedStyle$defX,
|
|
1325
|
-
_parsedStyle$defY = parsedStyle.defY,
|
|
1326
|
-
defY = _parsedStyle$defY === void 0 ? 0 : _parsedStyle$defY,
|
|
1327
|
-
markerStart = parsedStyle.markerStart,
|
|
1328
|
-
markerStartOffset = parsedStyle.markerStartOffset,
|
|
1329
|
-
markerEnd = parsedStyle.markerEnd,
|
|
1330
|
-
markerEndOffset = parsedStyle.markerEndOffset;
|
|
1331
|
-
var length = points.length;
|
|
1332
|
-
if (points && length >= 2) {
|
|
1333
|
-
var startOffsetX = 0;
|
|
1334
|
-
var startOffsetY = 0;
|
|
1335
|
-
var endOffsetX = 0;
|
|
1336
|
-
var endOffsetY = 0;
|
|
1337
|
-
var rad = 0;
|
|
1338
|
-
var x;
|
|
1339
|
-
var y;
|
|
1340
|
-
if (markerStart && gLite.isDisplayObject(markerStart) && markerStartOffset) {
|
|
1341
|
-
x = points[1][0] - points[0][0];
|
|
1342
|
-
y = points[1][1] - points[0][1];
|
|
1343
|
-
rad = Math.atan2(y, x);
|
|
1344
|
-
startOffsetX = Math.cos(rad) * (markerStartOffset || 0);
|
|
1345
|
-
startOffsetY = Math.sin(rad) * (markerStartOffset || 0);
|
|
1346
|
-
}
|
|
1347
|
-
if (markerEnd && gLite.isDisplayObject(markerEnd) && markerEndOffset) {
|
|
1348
|
-
x = points[length - 2][0] - points[length - 1][0];
|
|
1349
|
-
y = points[length - 2][1] - points[length - 1][1];
|
|
1350
|
-
rad = Math.atan2(y, x);
|
|
1351
|
-
endOffsetX = Math.cos(rad) * (markerEndOffset || 0);
|
|
1352
|
-
endOffsetY = Math.sin(rad) * (markerEndOffset || 0);
|
|
1353
|
-
}
|
|
1354
|
-
$el.setAttribute('points', points.map(function (point, i) {
|
|
1355
|
-
var offsetX = 0;
|
|
1356
|
-
var offsetY = 0;
|
|
1357
|
-
if (i === 0) {
|
|
1358
|
-
offsetX = startOffsetX;
|
|
1359
|
-
offsetY = startOffsetY;
|
|
1360
|
-
} else if (i === length - 1) {
|
|
1361
|
-
offsetX = endOffsetX;
|
|
1362
|
-
offsetY = endOffsetY;
|
|
1363
|
-
}
|
|
1364
|
-
return point[0] - defX + offsetX + "," + (point[1] - defY + offsetY);
|
|
1365
|
-
}).join(' '));
|
|
1366
|
-
}
|
|
1367
|
-
}
|
|
1368
|
-
function updateRectElementAttribute($el, parsedStyle) {
|
|
1369
|
-
var radius = parsedStyle.radius,
|
|
1370
|
-
width = parsedStyle.width,
|
|
1371
|
-
height = parsedStyle.height;
|
|
1372
|
-
// CSSKeyword: auto
|
|
1373
|
-
if (!isFinite(width) || !isFinite(height)) {
|
|
1374
|
-
return;
|
|
1375
|
-
}
|
|
1376
|
-
var hasRadius = radius && radius.some(function (r) {
|
|
1377
|
-
return r !== 0;
|
|
1378
|
-
});
|
|
1379
|
-
var d = '';
|
|
1380
|
-
if (!hasRadius) {
|
|
1381
|
-
d = "M 0,0 l " + width + ",0 l 0," + height + " l" + -width + " 0 z";
|
|
1382
|
-
} else {
|
|
1383
|
-
var _radius$map = radius.map(function (r) {
|
|
1384
|
-
return clamp(r, 0, Math.min(Math.abs(width) / 2, Math.abs(height) / 2));
|
|
1385
|
-
}),
|
|
1386
|
-
tlr = _radius$map[0],
|
|
1387
|
-
trr = _radius$map[1],
|
|
1388
|
-
brr = _radius$map[2],
|
|
1389
|
-
blr = _radius$map[3];
|
|
1390
|
-
var signX = width > 0 ? 1 : -1;
|
|
1391
|
-
var signY = height > 0 ? 1 : -1;
|
|
1392
|
-
// sweep-flag @see https://developer.mozilla.org/zh-CN/docs/Web/SVG/Tutorial/Paths#arcs
|
|
1393
|
-
var sweepFlag = signX + signY !== 0 ? 1 : 0;
|
|
1394
|
-
d = [["M " + signX * tlr + ",0"], ["l " + (width - signX * (tlr + trr)) + ",0"], ["a " + trr + "," + trr + ",0,0," + sweepFlag + "," + signX * trr + "," + signY * trr], ["l 0," + (height - signY * (trr + brr))], ["a " + brr + "," + brr + ",0,0," + sweepFlag + "," + -signX * brr + "," + signY * brr], ["l " + (signX * (brr + blr) - width) + ",0"], ["a " + blr + "," + blr + ",0,0," + sweepFlag + "," + -signX * blr + "," + -signY * blr], ["l 0," + (signY * (blr + tlr) - height)], ["a " + tlr + "," + tlr + ",0,0," + sweepFlag + "," + signX * tlr + "," + -signY * tlr], ['z']].join(' ');
|
|
1395
|
-
}
|
|
1396
|
-
$el.setAttribute('d', d);
|
|
1397
|
-
}
|
|
1398
|
-
function createSVGElement(type, doc) {
|
|
1399
|
-
return (doc || document).createElementNS('http://www.w3.org/2000/svg', type);
|
|
1400
|
-
}
|
|
1401
|
-
function numberToLongString(x) {
|
|
1402
|
-
return x.toFixed(6).replace('.000000', '');
|
|
1403
|
-
}
|
|
1404
|
-
function convertHTML(str) {
|
|
1405
|
-
var regex = /[&|<|>|"|']/g;
|
|
1406
|
-
return str.replace(regex, function (match) {
|
|
1407
|
-
if (match === '&') {
|
|
1408
|
-
return '&';
|
|
1409
|
-
} else if (match === '<') {
|
|
1410
|
-
return '<';
|
|
1411
|
-
} else if (match === '>') {
|
|
1412
|
-
return '>';
|
|
1413
|
-
} else if (match === '"') {
|
|
1414
|
-
return '"';
|
|
1415
|
-
} else {
|
|
1416
|
-
return ''';
|
|
1417
|
-
}
|
|
1418
|
-
});
|
|
1419
|
-
}
|
|
1420
|
-
var SVG_ATTR_MAP = {
|
|
1421
|
-
opacity: 'opacity',
|
|
1422
|
-
fillStyle: 'fill',
|
|
1423
|
-
fill: 'fill',
|
|
1424
|
-
fillRule: 'fill-rule',
|
|
1425
|
-
fillOpacity: 'fill-opacity',
|
|
1426
|
-
strokeStyle: 'stroke',
|
|
1427
|
-
strokeOpacity: 'stroke-opacity',
|
|
1428
|
-
stroke: 'stroke',
|
|
1429
|
-
clipPath: 'clip-path',
|
|
1430
|
-
textPath: 'text-path',
|
|
1431
|
-
r: 'r',
|
|
1432
|
-
rx: 'rx',
|
|
1433
|
-
ry: 'ry',
|
|
1434
|
-
width: 'width',
|
|
1435
|
-
height: 'height',
|
|
1436
|
-
lineCap: 'stroke-linecap',
|
|
1437
|
-
lineJoin: 'stroke-linejoin',
|
|
1438
|
-
lineWidth: 'stroke-width',
|
|
1439
|
-
lineDash: 'stroke-dasharray',
|
|
1440
|
-
lineDashOffset: 'stroke-dashoffset',
|
|
1441
|
-
miterLimit: 'stroke-miterlimit',
|
|
1442
|
-
font: 'font',
|
|
1443
|
-
fontSize: 'font-size',
|
|
1444
|
-
fontStyle: 'font-style',
|
|
1445
|
-
fontVariant: 'font-variant',
|
|
1446
|
-
fontWeight: 'font-weight',
|
|
1447
|
-
fontFamily: 'font-family',
|
|
1448
|
-
letterSpacing: 'letter-spacing',
|
|
1449
|
-
startArrow: 'marker-start',
|
|
1450
|
-
endArrow: 'marker-end',
|
|
1451
|
-
class: 'class',
|
|
1452
|
-
id: 'id',
|
|
1453
|
-
// style: 'style',
|
|
1454
|
-
preserveAspectRatio: 'preserveAspectRatio',
|
|
1455
|
-
visibility: 'visibility',
|
|
1456
|
-
anchor: 'anchor',
|
|
1457
|
-
shadowColor: 'flood-color',
|
|
1458
|
-
shadowBlur: 'stdDeviation',
|
|
1459
|
-
shadowOffsetX: 'dx',
|
|
1460
|
-
shadowOffsetY: 'dy',
|
|
1461
|
-
filter: 'filter',
|
|
1462
|
-
innerHTML: 'innerHTML',
|
|
1463
|
-
textAlign: 'text-anchor',
|
|
1464
|
-
pointerEvents: 'pointer-events'
|
|
1465
|
-
};
|
|
1466
|
-
var FORMAT_VALUE_MAP = {
|
|
1467
|
-
textAlign: {
|
|
1468
|
-
inherit: 'inherit',
|
|
1469
|
-
left: 'left',
|
|
1470
|
-
start: 'left',
|
|
1471
|
-
center: 'middle',
|
|
1472
|
-
right: 'end',
|
|
1473
|
-
end: 'end'
|
|
1474
|
-
}
|
|
1475
|
-
};
|
|
1476
|
-
var DEFAULT_VALUE_MAP = {
|
|
1477
|
-
textAlign: 'inherit',
|
|
1478
|
-
// textBaseline: 'alphabetic',
|
|
1479
|
-
// @see https://www.w3.org/TR/SVG/painting.html#LineCaps
|
|
1480
|
-
lineCap: 'butt',
|
|
1481
|
-
// @see https://www.w3.org/TR/SVG/painting.html#LineJoin
|
|
1482
|
-
lineJoin: 'miter',
|
|
1483
|
-
// @see https://developer.mozilla.org/zh-CN/docs/Web/SVG/Attribute/stroke-width
|
|
1484
|
-
lineWidth: '1px',
|
|
1485
|
-
opacity: '1',
|
|
1486
|
-
fillOpacity: '1',
|
|
1487
|
-
fillRule: 'nonzero',
|
|
1488
|
-
strokeOpacity: '1',
|
|
1489
|
-
strokeWidth: '0',
|
|
1490
|
-
strokeMiterLimit: '4',
|
|
1491
|
-
letterSpacing: '0',
|
|
1492
|
-
fontSize: 'inherit',
|
|
1493
|
-
fontFamily: 'inherit',
|
|
1494
|
-
pointerEvents: 'auto'
|
|
1495
|
-
};
|
|
1496
|
-
/**
|
|
1497
|
-
* G_SVG_PREFIX + nodeName + entity
|
|
1498
|
-
*
|
|
1499
|
-
* eg. g_svg_circle_345
|
|
1500
|
-
*/
|
|
1501
|
-
var G_SVG_PREFIX = 'g-svg';
|
|
1502
|
-
var CLIP_PATH_PREFIX = 'clip-path-';
|
|
1503
|
-
var TEXT_PATH_PREFIX = 'text-path-';
|
|
1504
|
-
var SVGRendererPlugin = /*#__PURE__*/function () {
|
|
1505
|
-
function SVGRendererPlugin(pluginOptions, defElementManager, context) {
|
|
1506
|
-
this.pluginOptions = void 0;
|
|
1507
|
-
this.defElementManager = void 0;
|
|
1508
|
-
this.context = void 0;
|
|
1509
|
-
/**
|
|
1510
|
-
* Will be used in g-plugin-svg-picker for finding relative SVG element of current DisplayObject.
|
|
1511
|
-
*/
|
|
1512
|
-
this.svgElementMap = new WeakMap();
|
|
1513
|
-
/**
|
|
1514
|
-
* <camera>
|
|
1515
|
-
*/
|
|
1516
|
-
this.$camera = void 0;
|
|
1517
|
-
/**
|
|
1518
|
-
* render at the end of frame
|
|
1519
|
-
*/
|
|
1520
|
-
this.renderQueue = [];
|
|
1521
|
-
/**
|
|
1522
|
-
* dirty attributes at the end of frame
|
|
1523
|
-
*/
|
|
1524
|
-
this.dirtyAttributes = new WeakMap();
|
|
1525
|
-
/**
|
|
1526
|
-
* reorder after mounted
|
|
1527
|
-
*/
|
|
1528
|
-
this.pendingReorderQueue = new Set();
|
|
1529
|
-
/**
|
|
1530
|
-
* <use> elements in <clipPath>, which should be sync with clipPath
|
|
1531
|
-
*
|
|
1532
|
-
* @example
|
|
1533
|
-
* <clipPath transform="matrix(1,0,0,1,-100,-155)" id="clip-path-0-2">
|
|
1534
|
-
* <use href="#g_svg_circle_0" transform="matrix(1.477115,0,0,1.477115,150,150)">
|
|
1535
|
-
* </use>
|
|
1536
|
-
* </clipPath>
|
|
1537
|
-
*/
|
|
1538
|
-
this.clipPathUseMap = new WeakMap();
|
|
1539
|
-
this.pluginOptions = pluginOptions;
|
|
1540
|
-
this.defElementManager = defElementManager;
|
|
1541
|
-
this.context = context;
|
|
1542
|
-
}
|
|
1543
|
-
var _proto = SVGRendererPlugin.prototype;
|
|
1544
|
-
_proto.apply = function apply(context) {
|
|
1545
|
-
var _this = this;
|
|
1546
|
-
var renderingService = context.renderingService,
|
|
1547
|
-
renderingContext = context.renderingContext;
|
|
1548
|
-
this.context = context;
|
|
1549
|
-
// @ts-ignore
|
|
1550
|
-
this.context.svgElementMap = this.svgElementMap;
|
|
1551
|
-
var canvas = renderingContext.root.ownerDocument.defaultView;
|
|
1552
|
-
var document = this.context.config.document;
|
|
1553
|
-
var handleMounted = function handleMounted(e) {
|
|
1554
|
-
var object = e.target;
|
|
1555
|
-
// should remove clipPath already existed in <defs>
|
|
1556
|
-
var $useRefs = _this.clipPathUseMap.get(object);
|
|
1557
|
-
if ($useRefs) {
|
|
1558
|
-
var $def = _this.defElementManager.getDefElement();
|
|
1559
|
-
var existed = $def.querySelector("#" + _this.getId(object));
|
|
1560
|
-
if (existed) {
|
|
1561
|
-
existed.remove();
|
|
1562
|
-
}
|
|
1563
|
-
}
|
|
1564
|
-
// create SVG DOM Node
|
|
1565
|
-
_this.createSVGDom(document, object, _this.$camera);
|
|
1566
|
-
};
|
|
1567
|
-
var handleUnmounted = function handleUnmounted(e) {
|
|
1568
|
-
var object = e.target;
|
|
1569
|
-
_this.defElementManager.clear(object.entity);
|
|
1570
|
-
_this.clipPathUseMap.delete(object);
|
|
1571
|
-
_this.removeSVGDom(object);
|
|
1572
|
-
};
|
|
1573
|
-
var reorderChildren = function reorderChildren(object) {
|
|
1574
|
-
var _object$parentNode, _object$parentNode$el;
|
|
1575
|
-
var parent = object.parentNode;
|
|
1576
|
-
// @ts-ignore
|
|
1577
|
-
var $groupEl = (_object$parentNode = object.parentNode) === null || _object$parentNode === void 0 ? void 0 : (_object$parentNode$el = _object$parentNode.elementSVG) === null || _object$parentNode$el === void 0 ? void 0 : _object$parentNode$el.$groupEl;
|
|
1578
|
-
var children = ((parent === null || parent === void 0 ? void 0 : parent.children) || []).slice();
|
|
1579
|
-
if ($groupEl) {
|
|
1580
|
-
_this.reorderChildren(document, $groupEl, children);
|
|
1581
|
-
}
|
|
1582
|
-
};
|
|
1583
|
-
var handleReparent = function handleReparent(e) {
|
|
1584
|
-
var object = e.target;
|
|
1585
|
-
reorderChildren(object);
|
|
1586
|
-
};
|
|
1587
|
-
var handleAttributeChanged = function handleAttributeChanged(e) {
|
|
1588
|
-
var object = e.target;
|
|
1589
|
-
// @see https://github.com/antvis/g/issues/994
|
|
1590
|
-
// @ts-ignore
|
|
1591
|
-
if (!object.elementSVG) {
|
|
1592
|
-
return;
|
|
1593
|
-
}
|
|
1594
|
-
var attrName = e.attrName;
|
|
1595
|
-
var attribtues = _this.dirtyAttributes.get(object);
|
|
1596
|
-
if (!attribtues) {
|
|
1597
|
-
_this.dirtyAttributes.set(object, []);
|
|
1598
|
-
attribtues = _this.dirtyAttributes.get(object);
|
|
1599
|
-
}
|
|
1600
|
-
attribtues.push(attrName);
|
|
1601
|
-
};
|
|
1602
|
-
var handleGeometryBoundsChanged = function handleGeometryBoundsChanged(e) {
|
|
1603
|
-
var _object$elementSVG;
|
|
1604
|
-
var object = e.target;
|
|
1605
|
-
// @ts-ignore
|
|
1606
|
-
var $el = (_object$elementSVG = object.elementSVG) === null || _object$elementSVG === void 0 ? void 0 : _object$elementSVG.$el;
|
|
1607
|
-
var _object$parsedStyle = object.parsedStyle,
|
|
1608
|
-
fill = _object$parsedStyle.fill,
|
|
1609
|
-
stroke = _object$parsedStyle.stroke,
|
|
1610
|
-
clipPath = _object$parsedStyle.clipPath;
|
|
1611
|
-
if (fill && !gLite.isCSSRGB(fill)) {
|
|
1612
|
-
_this.defElementManager.createOrUpdateGradientAndPattern(object, $el, fill, 'fill', _this);
|
|
1613
|
-
}
|
|
1614
|
-
if (stroke && !gLite.isCSSRGB(stroke)) {
|
|
1615
|
-
_this.defElementManager.createOrUpdateGradientAndPattern(object, $el, stroke, 'stroke', _this);
|
|
1616
|
-
}
|
|
1617
|
-
if (clipPath) {
|
|
1618
|
-
var parentInvert = invert(create(), object.getWorldTransform());
|
|
1619
|
-
var clipPathId = CLIP_PATH_PREFIX + clipPath.entity + '-' + object.entity;
|
|
1620
|
-
var $def = _this.defElementManager.getDefElement();
|
|
1621
|
-
var $existed = $def.querySelector("#" + clipPathId);
|
|
1622
|
-
if ($existed) {
|
|
1623
|
-
_this.applyTransform($existed, parentInvert);
|
|
1624
|
-
}
|
|
1625
|
-
}
|
|
1626
|
-
};
|
|
1627
|
-
renderingService.hooks.init.tap(SVGRendererPlugin.tag, function () {
|
|
1628
|
-
var _this$context$config = _this.context.config,
|
|
1629
|
-
background = _this$context$config.background,
|
|
1630
|
-
document = _this$context$config.document;
|
|
1631
|
-
// <defs>
|
|
1632
|
-
_this.defElementManager.init();
|
|
1633
|
-
var $svg = _this.context.contextService.getContext();
|
|
1634
|
-
if (background) {
|
|
1635
|
-
$svg.style.background = background;
|
|
1636
|
-
}
|
|
1637
|
-
// @see https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/color-interpolation-filters
|
|
1638
|
-
$svg.setAttribute('color-interpolation-filters', 'sRGB');
|
|
1639
|
-
_this.$camera = createSVGElement('g', document);
|
|
1640
|
-
_this.$camera.id = G_SVG_PREFIX + "-camera";
|
|
1641
|
-
_this.applyTransform(_this.$camera, _this.context.camera.getOrthoMatrix());
|
|
1642
|
-
$svg.appendChild(_this.$camera);
|
|
1643
|
-
canvas.addEventListener(gLite.ElementEvent.MOUNTED, handleMounted);
|
|
1644
|
-
canvas.addEventListener(gLite.ElementEvent.UNMOUNTED, handleUnmounted);
|
|
1645
|
-
canvas.addEventListener(gLite.ElementEvent.REPARENT, handleReparent);
|
|
1646
|
-
canvas.addEventListener(gLite.ElementEvent.ATTR_MODIFIED, handleAttributeChanged);
|
|
1647
|
-
canvas.addEventListener(gLite.ElementEvent.BOUNDS_CHANGED, handleGeometryBoundsChanged);
|
|
1648
|
-
});
|
|
1649
|
-
renderingService.hooks.destroy.tap(SVGRendererPlugin.tag, function () {
|
|
1650
|
-
canvas.removeEventListener(gLite.ElementEvent.MOUNTED, handleMounted);
|
|
1651
|
-
canvas.removeEventListener(gLite.ElementEvent.UNMOUNTED, handleUnmounted);
|
|
1652
|
-
canvas.removeEventListener(gLite.ElementEvent.REPARENT, handleReparent);
|
|
1653
|
-
canvas.removeEventListener(gLite.ElementEvent.ATTR_MODIFIED, handleAttributeChanged);
|
|
1654
|
-
canvas.removeEventListener(gLite.ElementEvent.BOUNDS_CHANGED, handleGeometryBoundsChanged);
|
|
1655
|
-
});
|
|
1656
|
-
renderingService.hooks.render.tap(SVGRendererPlugin.tag, function (object) {
|
|
1657
|
-
_this.renderQueue.push(object);
|
|
1658
|
-
});
|
|
1659
|
-
renderingService.hooks.beginFrame.tap(SVGRendererPlugin.tag, function () {
|
|
1660
|
-
var doc = _this.context.config.document;
|
|
1661
|
-
if (_this.pendingReorderQueue.size) {
|
|
1662
|
-
_this.pendingReorderQueue.forEach(function (object) {
|
|
1663
|
-
var _object$elementSVG2;
|
|
1664
|
-
var children = ((object === null || object === void 0 ? void 0 : object.children) || []).slice();
|
|
1665
|
-
var $parentGroupEl =
|
|
1666
|
-
// @ts-ignore
|
|
1667
|
-
object === null || object === void 0 ? void 0 : (_object$elementSVG2 = object.elementSVG) === null || _object$elementSVG2 === void 0 ? void 0 : _object$elementSVG2.$groupEl;
|
|
1668
|
-
if ($parentGroupEl) {
|
|
1669
|
-
_this.reorderChildren(doc || document, $parentGroupEl, children || []);
|
|
1670
|
-
}
|
|
1671
|
-
});
|
|
1672
|
-
_this.pendingReorderQueue.clear();
|
|
1673
|
-
}
|
|
1674
|
-
});
|
|
1675
|
-
renderingService.hooks.endFrame.tap(SVGRendererPlugin.tag, function () {
|
|
1676
|
-
if (renderingContext.renderReasons.has(gLite.RenderReason.CAMERA_CHANGED)) {
|
|
1677
|
-
_this.applyTransform(_this.$camera, _this.context.camera.getOrthoMatrix());
|
|
1678
|
-
}
|
|
1679
|
-
_this.renderQueue.forEach(function (object) {
|
|
1680
|
-
var _object$elementSVG3, _object$elementSVG4;
|
|
1681
|
-
// @ts-ignore
|
|
1682
|
-
var $el = (_object$elementSVG3 = object.elementSVG) === null || _object$elementSVG3 === void 0 ? void 0 : _object$elementSVG3.$el;
|
|
1683
|
-
// @ts-ignore
|
|
1684
|
-
var $groupEl = (_object$elementSVG4 = object.elementSVG) === null || _object$elementSVG4 === void 0 ? void 0 : _object$elementSVG4.$groupEl;
|
|
1685
|
-
if ($el && $groupEl) {
|
|
1686
|
-
// apply local RTS transformation to <group> wrapper
|
|
1687
|
-
// account for anchor
|
|
1688
|
-
var localTransform = object.getLocalTransform();
|
|
1689
|
-
_this.applyTransform($groupEl, localTransform);
|
|
1690
|
-
// clipped shapes should also be informed
|
|
1691
|
-
var $useRefs = _this.clipPathUseMap.get(object);
|
|
1692
|
-
if ($useRefs && $useRefs.length) {
|
|
1693
|
-
$useRefs.forEach(function ($use) {
|
|
1694
|
-
// <clipPath transform="matrix()"><circle /></clipPath>
|
|
1695
|
-
_this.applyTransform($use, object.getWorldTransform());
|
|
1696
|
-
// const parentInvert = mat4.invert(
|
|
1697
|
-
// mat4.create(),
|
|
1698
|
-
// (object as DisplayObject).getWorldTransform(),
|
|
1699
|
-
// );
|
|
1700
|
-
// this.applyTransform($clipPath, parentInvert);
|
|
1701
|
-
});
|
|
1702
|
-
}
|
|
1703
|
-
// finish rendering, clear dirty flag
|
|
1704
|
-
object.renderable.dirty = false;
|
|
1705
|
-
}
|
|
1706
|
-
// update dirty attributes
|
|
1707
|
-
var attributes = _this.dirtyAttributes.get(object);
|
|
1708
|
-
if (attributes) {
|
|
1709
|
-
attributes.forEach(function (attrName) {
|
|
1710
|
-
if (attrName === 'zIndex') {
|
|
1711
|
-
reorderChildren(object);
|
|
1712
|
-
} else if (attrName === 'increasedLineWidthForHitTesting') {
|
|
1713
|
-
_this.createOrUpdateHitArea(object, $el, $groupEl);
|
|
1714
|
-
}
|
|
1715
|
-
_this.updateAttribute(object, [attrName]);
|
|
1716
|
-
});
|
|
1717
|
-
_this.dirtyAttributes.delete(object);
|
|
1718
|
-
}
|
|
1719
|
-
});
|
|
1720
|
-
_this.renderQueue = [];
|
|
1721
|
-
});
|
|
1722
|
-
};
|
|
1723
|
-
_proto.getId = function getId(object) {
|
|
1724
|
-
return G_SVG_PREFIX + "-" + object.entity;
|
|
1725
|
-
};
|
|
1726
|
-
_proto.reorderChildren = function reorderChildren(doc, $groupEl, children) {
|
|
1727
|
-
// need to reorder parent's children
|
|
1728
|
-
children.sort(function (a, b) {
|
|
1729
|
-
return a.sortable.renderOrder - b.sortable.renderOrder;
|
|
1730
|
-
});
|
|
1731
|
-
if (children.length) {
|
|
1732
|
-
// create empty fragment
|
|
1733
|
-
var fragment = (doc || document).createDocumentFragment();
|
|
1734
|
-
children.forEach(function (child) {
|
|
1735
|
-
if (child.isConnected) {
|
|
1736
|
-
// @ts-ignore
|
|
1737
|
-
var $el = child.elementSVG.$groupEl;
|
|
1738
|
-
if ($el) {
|
|
1739
|
-
fragment.appendChild($el);
|
|
1740
|
-
}
|
|
1741
|
-
}
|
|
1742
|
-
});
|
|
1743
|
-
$groupEl.appendChild(fragment);
|
|
1744
|
-
}
|
|
1745
|
-
};
|
|
1746
|
-
_proto.applyTransform = function applyTransform($el, rts) {
|
|
1747
|
-
// use proper precision avoiding too long string in `transform`
|
|
1748
|
-
// @see https://developer.mozilla.org/en-US/docs/Web/API/Canvas_API/Tutorial/Transformations
|
|
1749
|
-
$el.setAttribute('transform', "matrix(" + numberToLongString(rts[0]) + "," + numberToLongString(rts[1]) + "," + numberToLongString(rts[4]) + "," + numberToLongString(rts[5]) + "," + numberToLongString(rts[12]) + "," + numberToLongString(rts[13]) + ")");
|
|
1750
|
-
};
|
|
1751
|
-
_proto.applyAttributes = function applyAttributes(object) {
|
|
1752
|
-
// @ts-ignore
|
|
1753
|
-
var elementSVG = object.elementSVG;
|
|
1754
|
-
var $el = elementSVG === null || elementSVG === void 0 ? void 0 : elementSVG.$el;
|
|
1755
|
-
var $groupEl = elementSVG === null || elementSVG === void 0 ? void 0 : elementSVG.$groupEl;
|
|
1756
|
-
if ($el && $groupEl) {
|
|
1757
|
-
var nodeName = object.nodeName,
|
|
1758
|
-
attributes = object.attributes;
|
|
1759
|
-
$el.setAttribute('fill', 'none');
|
|
1760
|
-
if (nodeName === gLite.Shape.IMAGE) {
|
|
1761
|
-
$el.setAttribute('preserveAspectRatio', 'none');
|
|
1762
|
-
}
|
|
1763
|
-
// apply attributes
|
|
1764
|
-
this.updateAttribute(object, Object.keys(attributes));
|
|
1765
|
-
}
|
|
1766
|
-
};
|
|
1767
|
-
_proto.updateAttribute = function updateAttribute(object, attributes) {
|
|
1768
|
-
var _this2 = this;
|
|
1769
|
-
var document = this.context.config.document;
|
|
1770
|
-
// @ts-ignore
|
|
1771
|
-
var _object$elementSVG5 = object.elementSVG,
|
|
1772
|
-
$el = _object$elementSVG5.$el,
|
|
1773
|
-
$groupEl = _object$elementSVG5.$groupEl,
|
|
1774
|
-
$hitTestingEl = _object$elementSVG5.$hitTestingEl;
|
|
1775
|
-
var parsedStyle = object.parsedStyle,
|
|
1776
|
-
computedStyle = object.computedStyle,
|
|
1777
|
-
nodeName = object.nodeName;
|
|
1778
|
-
var shouldUpdateElementAttribute = attributes.some(function (name) {
|
|
1779
|
-
return (
|
|
1780
|
-
// @ts-ignore
|
|
1781
|
-
_this2.context.SVGElementLifeCycleContribution.shouldUpdateElementAttribute(object, name)
|
|
1782
|
-
);
|
|
1783
|
-
});
|
|
1784
|
-
// need re-generate path
|
|
1785
|
-
if (shouldUpdateElementAttribute && $el) {
|
|
1786
|
-
[$el, $hitTestingEl].forEach(function ($el) {
|
|
1787
|
-
if ($el) {
|
|
1788
|
-
// @ts-ignore
|
|
1789
|
-
_this2.context.SVGElementLifeCycleContribution.updateElementAttribute(object, $el, _this2.svgElementMap);
|
|
1790
|
-
if (object.nodeName !== gLite.Shape.TEXT) {
|
|
1791
|
-
_this2.updateAnchorWithTransform(object);
|
|
1792
|
-
}
|
|
1793
|
-
}
|
|
1794
|
-
});
|
|
1795
|
-
}
|
|
1796
|
-
// update common attributes
|
|
1797
|
-
attributes.forEach(function (name) {
|
|
1798
|
-
var _FORMAT_VALUE_MAP$nam, _propertyMetadataCach;
|
|
1799
|
-
var usedName = SVG_ATTR_MAP[name];
|
|
1800
|
-
var computedValue = gLite.runtime.enableCSSParsing ? computedStyle[name] : parsedStyle[name];
|
|
1801
|
-
var computedValueStr = !isNil(computedValue) && computedValue.toString();
|
|
1802
|
-
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;
|
|
1803
|
-
var usedValue = parsedStyle[name];
|
|
1804
|
-
var inherited = usedName && !!((_propertyMetadataCach = gLite.propertyMetadataCache[name]) === null || _propertyMetadataCach === void 0 ? void 0 : _propertyMetadataCach.inh);
|
|
1805
|
-
if (!usedName || (nodeName === gLite.Shape.GROUP || object.isCustomElement) && !gLite.runtime.enableCSSParsing && (inherited || usedName === 'fill' || usedName === 'stroke')) {
|
|
1806
|
-
return;
|
|
1807
|
-
}
|
|
1808
|
-
// <foreignObject>
|
|
1809
|
-
if (nodeName === gLite.Shape.HTML) {
|
|
1810
|
-
if (name === 'lineWidth') {
|
|
1811
|
-
$el.style['border-width'] = (usedValue || 0) + "px";
|
|
1812
|
-
} else if (name === 'lineDash') {
|
|
1813
|
-
$el.style['border-style'] = 'dashed';
|
|
1814
|
-
}
|
|
1815
|
-
}
|
|
1816
|
-
if (name === 'fill') {
|
|
1817
|
-
if (nodeName === gLite.Shape.HTML) {
|
|
1818
|
-
$el.style.background = usedValue.toString();
|
|
1819
|
-
} else {
|
|
1820
|
-
_this2.defElementManager.createOrUpdateGradientAndPattern(object, $el, usedValue, usedName, _this2);
|
|
1821
|
-
}
|
|
1822
|
-
} else if (name === 'stroke') {
|
|
1823
|
-
if (nodeName === gLite.Shape.HTML) {
|
|
1824
|
-
$el.style['border-color'] = usedValue.toString();
|
|
1825
|
-
$el.style['border-style'] = 'solid';
|
|
1826
|
-
} else {
|
|
1827
|
-
_this2.defElementManager.createOrUpdateGradientAndPattern(object, $el, usedValue, usedName, _this2);
|
|
1828
|
-
}
|
|
1829
|
-
} else if (gLite.runtime.enableCSSParsing && inherited) {
|
|
1830
|
-
// use computed value
|
|
1831
|
-
// update `visibility` on <group>
|
|
1832
|
-
if (computedValueStr !== 'unset' && computedValueStr !== DEFAULT_VALUE_MAP[name]) {
|
|
1833
|
-
$groupEl === null || $groupEl === void 0 ? void 0 : $groupEl.setAttribute(usedName, formattedValueStr);
|
|
1834
|
-
} else {
|
|
1835
|
-
$groupEl === null || $groupEl === void 0 ? void 0 : $groupEl.removeAttribute(usedName);
|
|
1836
|
-
}
|
|
1837
|
-
} else if (name === 'clipPath') {
|
|
1838
|
-
_this2.createOrUpdateClipOrTextPath(document, usedValue, object);
|
|
1839
|
-
} else if (name === 'textPath') {
|
|
1840
|
-
_this2.createOrUpdateClipOrTextPath(document, usedValue, object, true);
|
|
1841
|
-
} else if (name === 'shadowType' || name === 'shadowColor' || name === 'shadowBlur' || name === 'shadowOffsetX' || name === 'shadowOffsetY') {
|
|
1842
|
-
_this2.defElementManager.createOrUpdateShadow(object, $el, name);
|
|
1843
|
-
} else if (name === 'filter') {
|
|
1844
|
-
_this2.defElementManager.createOrUpdateFilter(object, $el, usedValue);
|
|
1845
|
-
} else if (name === 'innerHTML') {
|
|
1846
|
-
_this2.createOrUpdateInnerHTML(document, $el, usedValue);
|
|
1847
|
-
} else if (name === 'anchor') {
|
|
1848
|
-
// text' anchor is controlled by `textAnchor` property
|
|
1849
|
-
if (nodeName !== gLite.Shape.TEXT) {
|
|
1850
|
-
_this2.updateAnchorWithTransform(object);
|
|
1851
|
-
}
|
|
1852
|
-
} else {
|
|
1853
|
-
if (!isNil(computedValue)) {
|
|
1854
|
-
// use computed value so that we can use cascaded effect in SVG
|
|
1855
|
-
// ignore 'unset' and default value
|
|
1856
|
-
[$el, $hitTestingEl].forEach(function ($el) {
|
|
1857
|
-
if ($el && usedName) {
|
|
1858
|
-
if (computedValueStr !== 'unset' && computedValueStr !== DEFAULT_VALUE_MAP[name]) {
|
|
1859
|
-
$el.setAttribute(usedName, formattedValueStr);
|
|
1860
|
-
} else {
|
|
1861
|
-
$el.removeAttribute(usedName);
|
|
1862
|
-
}
|
|
1863
|
-
}
|
|
1864
|
-
});
|
|
1865
|
-
}
|
|
1866
|
-
}
|
|
1867
|
-
});
|
|
1868
|
-
};
|
|
1869
|
-
_proto.createSVGDom = function createSVGDom(document, object, root, noWrapWithGroup) {
|
|
1870
|
-
if (noWrapWithGroup === void 0) {
|
|
1871
|
-
noWrapWithGroup = false;
|
|
1872
|
-
}
|
|
1873
|
-
// create svg element
|
|
1874
|
-
// @ts-ignore
|
|
1875
|
-
object.elementSVG = new ElementSVG();
|
|
1876
|
-
// @ts-ignore
|
|
1877
|
-
var svgElement = object.elementSVG;
|
|
1878
|
-
// use <group> as default, eg. CustomElement
|
|
1879
|
-
var $el =
|
|
1880
|
-
// @ts-ignore
|
|
1881
|
-
this.context.SVGElementLifeCycleContribution.createElement(object, this.svgElementMap);
|
|
1882
|
-
if ($el) {
|
|
1883
|
-
var _object$parentNode$el2;
|
|
1884
|
-
var $groupEl;
|
|
1885
|
-
// save $el on parsedStyle, which will be returned in getDomElement()
|
|
1886
|
-
if (object.nodeName === gLite.Shape.HTML) {
|
|
1887
|
-
object.parsedStyle.$el = $el;
|
|
1888
|
-
}
|
|
1889
|
-
if (this.pluginOptions.outputSVGElementId) {
|
|
1890
|
-
$el.id = this.getId(object);
|
|
1891
|
-
}
|
|
1892
|
-
if (this.pluginOptions.outputSVGElementName && object.name) {
|
|
1893
|
-
$el.setAttribute('name', object.name);
|
|
1894
|
-
}
|
|
1895
|
-
if (($el.hasAttribute('data-wrapgroup') || $el.nodeName !== 'g') && !noWrapWithGroup) {
|
|
1896
|
-
$groupEl = createSVGElement('g', document);
|
|
1897
|
-
$groupEl.id = $el.id + '-g';
|
|
1898
|
-
$groupEl.appendChild($el);
|
|
1899
|
-
} else {
|
|
1900
|
-
$groupEl = $el;
|
|
1901
|
-
}
|
|
1902
|
-
svgElement.$el = $el;
|
|
1903
|
-
svgElement.$groupEl = $groupEl;
|
|
1904
|
-
// apply attributes at first time
|
|
1905
|
-
this.applyAttributes(object);
|
|
1906
|
-
// create hitArea if necessary
|
|
1907
|
-
this.createOrUpdateHitArea(object, $el, $groupEl);
|
|
1908
|
-
var $parentGroupEl = root ||
|
|
1909
|
-
// @ts-ignore
|
|
1910
|
-
object.parentNode && ((_object$parentNode$el2 = object.parentNode.elementSVG) === null || _object$parentNode$el2 === void 0 ? void 0 : _object$parentNode$el2.$groupEl);
|
|
1911
|
-
if ($parentGroupEl) {
|
|
1912
|
-
$parentGroupEl.appendChild($groupEl);
|
|
1913
|
-
// need reorder children later
|
|
1914
|
-
this.pendingReorderQueue.add(object.parentNode);
|
|
1915
|
-
}
|
|
1916
|
-
}
|
|
1917
|
-
};
|
|
1918
|
-
_proto.removeSVGDom = function removeSVGDom(object) {
|
|
1919
|
-
var _object$elementSVG6;
|
|
1920
|
-
// @ts-ignore
|
|
1921
|
-
var $groupEl = (_object$elementSVG6 = object.elementSVG) === null || _object$elementSVG6 === void 0 ? void 0 : _object$elementSVG6.$groupEl;
|
|
1922
|
-
if ($groupEl && $groupEl.parentNode) {
|
|
1923
|
-
$groupEl.parentNode.removeChild($groupEl);
|
|
1924
|
-
// @ts-ignore
|
|
1925
|
-
this.context.SVGElementLifeCycleContribution.destroyElement(object, $groupEl);
|
|
1926
|
-
// object.entity.removeComponent(ElementSVG, true);
|
|
1927
|
-
}
|
|
1928
|
-
};
|
|
1929
|
-
|
|
1930
|
-
_proto.createOrUpdateHitArea = function createOrUpdateHitArea(object, $el, $groupEl) {
|
|
1931
|
-
// @ts-ignore
|
|
1932
|
-
var svgElement = object.elementSVG;
|
|
1933
|
-
var $hitTestingEl = svgElement.$hitTestingEl;
|
|
1934
|
-
var increasedLineWidthForHitTesting = object.parsedStyle.increasedLineWidthForHitTesting;
|
|
1935
|
-
// account for hitArea
|
|
1936
|
-
if (increasedLineWidthForHitTesting) {
|
|
1937
|
-
if (!$hitTestingEl) {
|
|
1938
|
-
$hitTestingEl = $el.cloneNode();
|
|
1939
|
-
if (this.pluginOptions.outputSVGElementId) {
|
|
1940
|
-
// use the entity suffix, so that `g-plugin-svg-picker` can extract
|
|
1941
|
-
$hitTestingEl.id = G_SVG_PREFIX + "-" + object.nodeName + "-hittesting-" + object.entity;
|
|
1942
|
-
}
|
|
1943
|
-
// clear attributes like `filter` `font-size`
|
|
1944
|
-
['filter'].forEach(function (attribute) {
|
|
1945
|
-
$hitTestingEl.removeAttribute(attribute);
|
|
1946
|
-
});
|
|
1947
|
-
// hitArea should be 'transparent' but not 'none'
|
|
1948
|
-
var hasFill = $el.getAttribute('fill') !== 'none';
|
|
1949
|
-
$hitTestingEl.setAttribute('fill', hasFill ? 'transparent' : 'none');
|
|
1950
|
-
$hitTestingEl.setAttribute('stroke', 'transparent');
|
|
1951
|
-
$groupEl.appendChild($hitTestingEl);
|
|
1952
|
-
svgElement.$hitTestingEl = $hitTestingEl;
|
|
1953
|
-
}
|
|
1954
|
-
// increase interactive line width
|
|
1955
|
-
$hitTestingEl.setAttribute('stroke-width', "" + (increasedLineWidthForHitTesting + object.parsedStyle.lineWidth));
|
|
1956
|
-
} else {
|
|
1957
|
-
if ($hitTestingEl) {
|
|
1958
|
-
$groupEl.removeChild($hitTestingEl);
|
|
1959
|
-
svgElement.$hitTestingEl = null;
|
|
1960
|
-
}
|
|
1961
|
-
}
|
|
1962
|
-
};
|
|
1963
|
-
_proto.createOrUpdateInnerHTML = function createOrUpdateInnerHTML(doc, $el, usedValue) {
|
|
1964
|
-
var $div = (doc || document).createElement('div');
|
|
1965
|
-
if (typeof usedValue === 'string') {
|
|
1966
|
-
$div.innerHTML = usedValue;
|
|
1967
|
-
} else {
|
|
1968
|
-
$div.appendChild(usedValue);
|
|
1969
|
-
}
|
|
1970
|
-
$el.innerHTML = '';
|
|
1971
|
-
$el.appendChild($div);
|
|
1972
|
-
};
|
|
1973
|
-
_proto.createOrUpdateClipOrTextPath = function createOrUpdateClipOrTextPath(document, clipPath, object, isTextPath) {
|
|
1974
|
-
if (isTextPath === void 0) {
|
|
1975
|
-
isTextPath = false;
|
|
1976
|
-
}
|
|
1977
|
-
// @ts-ignore
|
|
1978
|
-
var $groupEl = object.elementSVG.$groupEl;
|
|
1979
|
-
var PREFIX = isTextPath ? TEXT_PATH_PREFIX : CLIP_PATH_PREFIX;
|
|
1980
|
-
var attributeNameCamel = isTextPath ? 'g' : 'clipPath';
|
|
1981
|
-
var attributeNameHyphen = isTextPath ? 'text-path' : 'clip-path';
|
|
1982
|
-
if (clipPath) {
|
|
1983
|
-
var clipPathId = PREFIX + clipPath.entity + '-' + object.entity;
|
|
1984
|
-
var $def = this.defElementManager.getDefElement();
|
|
1985
|
-
var existed = $def.querySelector("#" + clipPathId);
|
|
1986
|
-
if (!existed) {
|
|
1987
|
-
var $clipPath;
|
|
1988
|
-
if (isTextPath) {
|
|
1989
|
-
// use <path> directly instead of wrapping with <g>
|
|
1990
|
-
this.createSVGDom(document, clipPath, null, true);
|
|
1991
|
-
// @ts-ignore
|
|
1992
|
-
$clipPath = clipPath.elementSVG.$el;
|
|
1993
|
-
} else {
|
|
1994
|
-
// the clipPath is allowed to be detached from canvas
|
|
1995
|
-
if (!clipPath.isConnected) {
|
|
1996
|
-
var $existedClipPath = $def.querySelector("#" + this.getId(clipPath));
|
|
1997
|
-
if (!$existedClipPath) {
|
|
1998
|
-
this.createSVGDom(document, clipPath, $def, true);
|
|
1999
|
-
}
|
|
2000
|
-
}
|
|
2001
|
-
// create <clipPath> dom node
|
|
2002
|
-
$clipPath = createSVGElement(attributeNameCamel, document);
|
|
2003
|
-
var $use = createSVGElement('use', document);
|
|
2004
|
-
// @ts-ignore
|
|
2005
|
-
$use.setAttribute('href', "#" + clipPath.elementSVG.$el.id);
|
|
2006
|
-
$clipPath.appendChild($use);
|
|
2007
|
-
var $useRefs = this.clipPathUseMap.get(clipPath);
|
|
2008
|
-
if (!$useRefs) {
|
|
2009
|
-
this.clipPathUseMap.set(clipPath, []);
|
|
2010
|
-
$useRefs = this.clipPathUseMap.get(clipPath);
|
|
2011
|
-
}
|
|
2012
|
-
$useRefs.push($use);
|
|
2013
|
-
// <clipPath transform="matrix()"><circle /></clipPath>
|
|
2014
|
-
this.applyTransform($use, clipPath.getWorldTransform());
|
|
2015
|
-
var parentInvert = invert(create(), object.getWorldTransform());
|
|
2016
|
-
this.applyTransform($clipPath, parentInvert);
|
|
2017
|
-
}
|
|
2018
|
-
$clipPath.id = clipPathId;
|
|
2019
|
-
// append it to <defs>
|
|
2020
|
-
$def.appendChild($clipPath);
|
|
2021
|
-
}
|
|
2022
|
-
// apply attributes
|
|
2023
|
-
this.applyAttributes(clipPath);
|
|
2024
|
-
if (!isTextPath) {
|
|
2025
|
-
// apply clipPath to $group
|
|
2026
|
-
// @see https://github.com/antvis/g/issues/961
|
|
2027
|
-
$groupEl.setAttribute(attributeNameHyphen, "url(#" + clipPathId + ")");
|
|
2028
|
-
}
|
|
2029
|
-
} else {
|
|
2030
|
-
if (!isTextPath) {
|
|
2031
|
-
// remove clip path
|
|
2032
|
-
$groupEl.removeAttribute(attributeNameHyphen);
|
|
2033
|
-
}
|
|
2034
|
-
}
|
|
2035
|
-
}
|
|
2036
|
-
/**
|
|
2037
|
-
* the origin is bounding box's top left corner
|
|
2038
|
-
*/;
|
|
2039
|
-
_proto.updateAnchorWithTransform = function updateAnchorWithTransform(object) {
|
|
2040
|
-
var _object$elementSVG7, _object$elementSVG8;
|
|
2041
|
-
var bounds = object.getGeometryBounds();
|
|
2042
|
-
var width = bounds && bounds.halfExtents[0] * 2 || 0;
|
|
2043
|
-
var height = bounds && bounds.halfExtents[1] * 2 || 0;
|
|
2044
|
-
var _ref = object.parsedStyle || {},
|
|
2045
|
-
anchor = _ref.anchor;
|
|
2046
|
-
// @ts-ignore
|
|
2047
|
-
[(_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) {
|
|
2048
|
-
if ($el) {
|
|
2049
|
-
var tx = -(anchor[0] * width);
|
|
2050
|
-
var ty = -(anchor[1] * height);
|
|
2051
|
-
if (tx !== 0 || ty !== 0) {
|
|
2052
|
-
// apply anchor to element's `transform` property
|
|
2053
|
-
$el.setAttribute('transform',
|
|
2054
|
-
// can't use percent unit like translate(-50%, -50%)
|
|
2055
|
-
// @see https://developer.mozilla.org/zh-CN/docs/Web/SVG/Attribute/transform#translate
|
|
2056
|
-
"translate(" + tx + "," + ty + ")");
|
|
2057
|
-
}
|
|
2058
|
-
if (object.nodeName === gLite.Shape.CIRCLE || object.nodeName === gLite.Shape.ELLIPSE) {
|
|
2059
|
-
$el.setAttribute('cx', "" + width / 2);
|
|
2060
|
-
$el.setAttribute('cy', "" + height / 2);
|
|
2061
|
-
}
|
|
2062
|
-
}
|
|
2063
|
-
});
|
|
2064
|
-
};
|
|
2065
|
-
return SVGRendererPlugin;
|
|
2066
|
-
}();
|
|
2067
|
-
SVGRendererPlugin.tag = 'SVGRenderer';
|
|
2068
|
-
|
|
2069
|
-
// @see https://github.com/plouc/nivo/issues/164
|
|
2070
|
-
var BASELINE_MAP = {
|
|
2071
|
-
top: 'hanging',
|
|
2072
|
-
middle: 'central',
|
|
2073
|
-
bottom: 'text-after-edge',
|
|
2074
|
-
alphabetic: 'alphabetic',
|
|
2075
|
-
ideographic: 'ideographic',
|
|
2076
|
-
hanging: 'hanging'
|
|
2077
|
-
};
|
|
2078
|
-
function updateTextElementAttribute($el, parsedStyle, text) {
|
|
2079
|
-
var lineWidth = parsedStyle.lineWidth,
|
|
2080
|
-
dx = parsedStyle.dx,
|
|
2081
|
-
dy = parsedStyle.dy,
|
|
2082
|
-
textPath = parsedStyle.textPath,
|
|
2083
|
-
_parsedStyle$textPath = parsedStyle.textPathSide,
|
|
2084
|
-
textPathSide = _parsedStyle$textPath === void 0 ? 'left' : _parsedStyle$textPath,
|
|
2085
|
-
_parsedStyle$textPath2 = parsedStyle.textPathStartOffset,
|
|
2086
|
-
textPathStartOffset = _parsedStyle$textPath2 === void 0 ? 0 : _parsedStyle$textPath2,
|
|
2087
|
-
_parsedStyle$textDeco = parsedStyle.textDecorationLine,
|
|
2088
|
-
textDecorationLine = _parsedStyle$textDeco === void 0 ? '' : _parsedStyle$textDeco,
|
|
2089
|
-
_parsedStyle$textDeco2 = parsedStyle.textDecorationColor,
|
|
2090
|
-
textDecorationColor = _parsedStyle$textDeco2 === void 0 ? '' : _parsedStyle$textDeco2,
|
|
2091
|
-
_parsedStyle$textDeco3 = parsedStyle.textDecorationStyle,
|
|
2092
|
-
textDecorationStyle = _parsedStyle$textDeco3 === void 0 ? '' : _parsedStyle$textDeco3,
|
|
2093
|
-
metrics = parsedStyle.metrics;
|
|
2094
|
-
var textBaseline = parsedStyle.textBaseline;
|
|
2095
|
-
if (!gLite.runtime.enableCSSParsing && textBaseline === 'alphabetic') {
|
|
2096
|
-
textBaseline = 'bottom';
|
|
2097
|
-
}
|
|
2098
|
-
$el.setAttribute('dominant-baseline', BASELINE_MAP[textBaseline]);
|
|
2099
|
-
$el.setAttribute('paint-order', 'stroke');
|
|
2100
|
-
var lines = metrics.lines,
|
|
2101
|
-
lineHeight = metrics.lineHeight,
|
|
2102
|
-
height = metrics.height;
|
|
2103
|
-
var lineNum = lines.length;
|
|
2104
|
-
var styleCSSText = '';
|
|
2105
|
-
if (dx !== 0 || dy !== 0) {
|
|
2106
|
-
styleCSSText += "transform:translate(" + dx + "px, " + dy + "px);";
|
|
2107
|
-
}
|
|
2108
|
-
if (textDecorationLine && textDecorationLine !== 'none') {
|
|
2109
|
-
// use CSS text-decoration since the implementation in SVG is not good enough
|
|
2110
|
-
styleCSSText += "text-decoration:" + textDecorationLine + " " + textDecorationStyle + " " + textDecorationColor + ";";
|
|
2111
|
-
}
|
|
2112
|
-
if (styleCSSText) {
|
|
2113
|
-
$el.setAttribute('style', styleCSSText);
|
|
2114
|
-
}
|
|
2115
|
-
if (lineNum === 1) {
|
|
2116
|
-
var textContent = convertHTML(lines[0]);
|
|
2117
|
-
$el.setAttribute('dx', "" + lineWidth / 2);
|
|
2118
|
-
// Since `text-after-edge` is not a standard property value, we use `dy` instead.
|
|
2119
|
-
if (textBaseline === 'bottom' || textBaseline === 'top') {
|
|
2120
|
-
$el.setAttribute('dominant-baseline', 'middle');
|
|
2121
|
-
$el.setAttribute('dy', textBaseline === 'bottom' ? "-0.5em" : '0.5em');
|
|
2122
|
-
}
|
|
2123
|
-
// <textPath> only support one line
|
|
2124
|
-
// @see https://developer.mozilla.org/en-US/docs/Web/SVG/Element/textPath
|
|
2125
|
-
if (textPath) {
|
|
2126
|
-
// clear existed text content first
|
|
2127
|
-
$el.innerHTML = '';
|
|
2128
|
-
// append <textPath href="#MyPath">text</textPath>
|
|
2129
|
-
var $textPath = createSVGElement('textPath', $el.ownerDocument);
|
|
2130
|
-
$textPath.setAttribute('href', "#" + (TEXT_PATH_PREFIX + textPath.entity));
|
|
2131
|
-
if (textPathSide !== 'left') {
|
|
2132
|
-
$textPath.setAttribute('side', textPathSide);
|
|
2133
|
-
}
|
|
2134
|
-
if (textPathStartOffset !== 0) {
|
|
2135
|
-
$textPath.setAttribute('startOffset', "" + textPathStartOffset);
|
|
2136
|
-
}
|
|
2137
|
-
$textPath.innerHTML = textContent;
|
|
2138
|
-
$el.appendChild($textPath);
|
|
2139
|
-
} else {
|
|
2140
|
-
$el.innerHTML = textContent;
|
|
2141
|
-
}
|
|
2142
|
-
} else {
|
|
2143
|
-
$el.innerHTML = lines.map(function (line, i) {
|
|
2144
|
-
var dx = lineWidth / 2;
|
|
2145
|
-
var dy = 0;
|
|
2146
|
-
if (i === 0) {
|
|
2147
|
-
// TODO: handle other textBaseline values
|
|
2148
|
-
if (textBaseline === 'middle') {
|
|
2149
|
-
dy = lineHeight / 2 - height / 2;
|
|
2150
|
-
} else if (textBaseline === 'top' || textBaseline === 'hanging') {
|
|
2151
|
-
dy = 0;
|
|
2152
|
-
} else if (textBaseline === 'bottom' || textBaseline === 'alphabetic' || textBaseline === 'ideographic') {
|
|
2153
|
-
dy = -lineHeight * (lineNum - 1);
|
|
2154
|
-
}
|
|
2155
|
-
} else {
|
|
2156
|
-
dy = lineHeight;
|
|
2157
|
-
}
|
|
2158
|
-
return "<tspan x=\"0\" dx=\"" + dx + "\" dy=\"" + dy + "\">" + convertHTML(line) + "</tspan>";
|
|
2159
|
-
}).join('');
|
|
2160
|
-
}
|
|
2161
|
-
}
|
|
2162
|
-
var _SHAPE2TAGS, _SHAPE_UPDATE_DEPS;
|
|
2163
|
-
var SHAPE2TAGS = (_SHAPE2TAGS = {}, _SHAPE2TAGS[gLite.Shape.RECT] = 'path', _SHAPE2TAGS[gLite.Shape.CIRCLE] = 'circle', _SHAPE2TAGS[gLite.Shape.ELLIPSE] = 'ellipse', _SHAPE2TAGS[gLite.Shape.IMAGE] = 'image', _SHAPE2TAGS[gLite.Shape.GROUP] = 'g', _SHAPE2TAGS[gLite.Shape.LINE] = 'line', _SHAPE2TAGS[gLite.Shape.POLYLINE] = 'polyline', _SHAPE2TAGS[gLite.Shape.POLYGON] = 'polygon', _SHAPE2TAGS[gLite.Shape.TEXT] = 'text', _SHAPE2TAGS[gLite.Shape.PATH] = 'path', _SHAPE2TAGS[gLite.Shape.HTML] = 'foreignObject', _SHAPE2TAGS);
|
|
2164
|
-
var SHAPE_UPDATE_DEPS = (_SHAPE_UPDATE_DEPS = {}, _SHAPE_UPDATE_DEPS[gLite.Shape.CIRCLE] = ['r'], _SHAPE_UPDATE_DEPS[gLite.Shape.ELLIPSE] = ['rx', 'ry'], _SHAPE_UPDATE_DEPS[gLite.Shape.RECT] = ['width', 'height', 'radius'], _SHAPE_UPDATE_DEPS[gLite.Shape.IMAGE] = ['img', 'width', 'height'], _SHAPE_UPDATE_DEPS[gLite.Shape.LINE] = ['x1', 'y1', 'x2', 'y2', 'markerStart', 'markerEnd', 'markerStartOffset', 'markerEndOffset'], _SHAPE_UPDATE_DEPS[gLite.Shape.POLYLINE] = ['points', 'markerStart', 'markerEnd', 'markerMid', 'markerStartOffset', 'markerEndOffset'], _SHAPE_UPDATE_DEPS[gLite.Shape.POLYGON] = ['points', 'markerStart', 'markerEnd', 'markerMid', 'markerStartOffset', 'markerEndOffset'], _SHAPE_UPDATE_DEPS[gLite.Shape.PATH] = ['path', 'markerStart', 'markerEnd', 'markerMid', 'markerStartOffset', 'markerEndOffset'], _SHAPE_UPDATE_DEPS[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',
|
|
2165
|
-
// 'whiteSpace',
|
|
2166
|
-
'dx', 'dy'], _SHAPE_UPDATE_DEPS);
|
|
2167
|
-
var DefaultElementLifeCycleContribution = /*#__PURE__*/function () {
|
|
2168
|
-
function DefaultElementLifeCycleContribution(context) {
|
|
2169
|
-
this.context = void 0;
|
|
2170
|
-
this.context = context;
|
|
2171
|
-
}
|
|
2172
|
-
var _proto = DefaultElementLifeCycleContribution.prototype;
|
|
2173
|
-
_proto.createElement = function createElement(object, svgElementMap) {
|
|
2174
|
-
var doc = this.context.config.document;
|
|
2175
|
-
var type = SHAPE2TAGS[object.nodeName] || 'g';
|
|
2176
|
-
var $el = createSVGElement(type, doc || document);
|
|
2177
|
-
svgElementMap.set($el, object);
|
|
2178
|
-
return $el;
|
|
2179
|
-
};
|
|
2180
|
-
_proto.destroyElement = function destroyElement(object, $el) {};
|
|
2181
|
-
_proto.shouldUpdateElementAttribute = function shouldUpdateElementAttribute(object, attributeName) {
|
|
2182
|
-
var nodeName = object.nodeName;
|
|
2183
|
-
return (SHAPE_UPDATE_DEPS[nodeName] || []).indexOf(attributeName) > -1;
|
|
2184
|
-
};
|
|
2185
|
-
_proto.updateElementAttribute = function updateElementAttribute(object) {
|
|
2186
|
-
// @ts-ignore
|
|
2187
|
-
var $el = object.elementSVG.$el;
|
|
2188
|
-
var nodeName = object.nodeName,
|
|
2189
|
-
parsedStyle = object.parsedStyle;
|
|
2190
|
-
switch (nodeName) {
|
|
2191
|
-
case gLite.Shape.IMAGE:
|
|
2192
|
-
{
|
|
2193
|
-
updateImageElementAttribute($el, parsedStyle);
|
|
2194
|
-
break;
|
|
2195
|
-
}
|
|
2196
|
-
case gLite.Shape.RECT:
|
|
2197
|
-
{
|
|
2198
|
-
updateRectElementAttribute($el, parsedStyle);
|
|
2199
|
-
break;
|
|
2200
|
-
}
|
|
2201
|
-
case gLite.Shape.LINE:
|
|
2202
|
-
{
|
|
2203
|
-
updateLineElementAttribute($el, parsedStyle);
|
|
2204
|
-
break;
|
|
2205
|
-
}
|
|
2206
|
-
case gLite.Shape.POLYGON:
|
|
2207
|
-
case gLite.Shape.POLYLINE:
|
|
2208
|
-
{
|
|
2209
|
-
updatePolylineElementAttribute($el, parsedStyle);
|
|
2210
|
-
break;
|
|
2211
|
-
}
|
|
2212
|
-
case gLite.Shape.PATH:
|
|
2213
|
-
{
|
|
2214
|
-
updatePathElementAttribute($el, parsedStyle);
|
|
2215
|
-
break;
|
|
2216
|
-
}
|
|
2217
|
-
case gLite.Shape.TEXT:
|
|
2218
|
-
{
|
|
2219
|
-
updateTextElementAttribute($el, parsedStyle);
|
|
2220
|
-
break;
|
|
2221
|
-
}
|
|
2222
|
-
}
|
|
2223
|
-
};
|
|
2224
|
-
return DefaultElementLifeCycleContribution;
|
|
2225
|
-
}();
|
|
2226
|
-
var FILTER_PREFIX = 'g-filter-';
|
|
2227
|
-
/**
|
|
2228
|
-
* use SVG filters, eg. blur, brightness, contrast...
|
|
2229
|
-
* @see https://developer.mozilla.org/zh-CN/docs/Web/SVG/Element/filter
|
|
2230
|
-
*/
|
|
2231
|
-
function createOrUpdateFilter(document, $def, object, $el, filters) {
|
|
2232
|
-
// eg. filter="url(#f1) url(#f2)"
|
|
2233
|
-
var filterName = FILTER_PREFIX + object.entity;
|
|
2234
|
-
var $existedFilters = $def.querySelectorAll("[name=" + filterName + "]");
|
|
2235
|
-
if ($existedFilters.length) {
|
|
2236
|
-
$existedFilters.forEach(function ($filter) {
|
|
2237
|
-
$def.removeChild($filter);
|
|
2238
|
-
});
|
|
2239
|
-
}
|
|
2240
|
-
if (filters.length === 0) {
|
|
2241
|
-
// 'none'
|
|
2242
|
-
$el === null || $el === void 0 ? void 0 : $el.removeAttribute('filter');
|
|
2243
|
-
} else {
|
|
2244
|
-
var filterIds = filters.map(function (_ref, i) {
|
|
2245
|
-
var name = _ref.name,
|
|
2246
|
-
params = _ref.params;
|
|
2247
|
-
var $filter = createSVGElement('filter', document);
|
|
2248
|
-
// @see https://github.com/antvis/g/issues/1025
|
|
2249
|
-
$filter.setAttribute('filterUnits', 'userSpaceOnUse');
|
|
2250
|
-
if (name === 'blur') {
|
|
2251
|
-
createBlur(document, $filter, params);
|
|
2252
|
-
} else if (name === 'brightness') {
|
|
2253
|
-
createBrightness(document, $filter, params);
|
|
2254
|
-
} else if (name === 'drop-shadow') {
|
|
2255
|
-
createDropShadow(document, $filter, params);
|
|
2256
|
-
} else if (name === 'contrast') {
|
|
2257
|
-
createContrast(document, $filter, params);
|
|
2258
|
-
} else if (name === 'grayscale') {
|
|
2259
|
-
createGrayscale(document, $filter, params);
|
|
2260
|
-
} else if (name === 'sepia') {
|
|
2261
|
-
createSepia(document, $filter, params);
|
|
2262
|
-
} else if (name === 'saturate') {
|
|
2263
|
-
createSaturate(document, $filter, params);
|
|
2264
|
-
} else if (name === 'hue-rotate') {
|
|
2265
|
-
createHueRotate(document, $filter, params);
|
|
2266
|
-
} else if (name === 'invert') {
|
|
2267
|
-
createInvert(document, $filter, params);
|
|
2268
|
-
}
|
|
2269
|
-
$filter.id = filterName + "-" + i;
|
|
2270
|
-
$filter.setAttribute('name', filterName);
|
|
2271
|
-
$def.appendChild($filter);
|
|
2272
|
-
return $filter.id;
|
|
2273
|
-
});
|
|
2274
|
-
// @see https://github.com/antvis/G/issues/1114
|
|
2275
|
-
setTimeout(function () {
|
|
2276
|
-
$el === null || $el === void 0 ? void 0 : $el.setAttribute('filter', filterIds.map(function (filterId) {
|
|
2277
|
-
return "url(#" + filterId + ")";
|
|
2278
|
-
}).join(' '));
|
|
2279
|
-
});
|
|
2280
|
-
}
|
|
2281
|
-
}
|
|
2282
|
-
function convertToAbsoluteValue(param) {
|
|
2283
|
-
return param.unit === gLite.UnitType.kPercentage ? param.value / 100 : param.value;
|
|
2284
|
-
}
|
|
2285
|
-
/**
|
|
2286
|
-
* @see https://drafts.fxtf.org/filter-effects/#blurEquivalent
|
|
2287
|
-
*/
|
|
2288
|
-
function createBlur(document, $filter, params) {
|
|
2289
|
-
var $feGaussianBlur = createSVGElement('feGaussianBlur', document);
|
|
2290
|
-
$feGaussianBlur.setAttribute('in', 'SourceGraphic');
|
|
2291
|
-
$feGaussianBlur.setAttribute('stdDeviation', "" + params[0].value);
|
|
2292
|
-
$filter.appendChild($feGaussianBlur);
|
|
2293
|
-
}
|
|
2294
|
-
function createFeComponentTransfer(document, $filter, _ref2) {
|
|
2295
|
-
var type = _ref2.type,
|
|
2296
|
-
slope = _ref2.slope,
|
|
2297
|
-
intercept = _ref2.intercept,
|
|
2298
|
-
tableValues = _ref2.tableValues;
|
|
2299
|
-
var $feComponentTransfer = createSVGElement('feComponentTransfer', document);
|
|
2300
|
-
[createSVGElement('feFuncR', document), createSVGElement('feFuncG', document), createSVGElement('feFuncB', document)].forEach(function ($feFunc) {
|
|
2301
|
-
$feFunc.setAttribute('type', type);
|
|
2302
|
-
if (type === 'table') {
|
|
2303
|
-
$feFunc.setAttribute('tableValues', "" + tableValues);
|
|
2304
|
-
} else {
|
|
2305
|
-
$feFunc.setAttribute('slope', "" + slope);
|
|
2306
|
-
$feFunc.setAttribute('intercept', "" + intercept);
|
|
2307
|
-
}
|
|
2308
|
-
$feComponentTransfer.appendChild($feFunc);
|
|
2309
|
-
});
|
|
2310
|
-
$filter.appendChild($feComponentTransfer);
|
|
2311
|
-
}
|
|
2312
|
-
function createContrast(document, $filter, params) {
|
|
2313
|
-
var slope = convertToAbsoluteValue(params[0]);
|
|
2314
|
-
createFeComponentTransfer(document, $filter, {
|
|
2315
|
-
type: 'linear',
|
|
2316
|
-
slope: slope,
|
|
2317
|
-
intercept: -(0.5 * slope) + 0.5
|
|
2318
|
-
});
|
|
2319
|
-
}
|
|
2320
|
-
function createInvert(document, $filter, params) {
|
|
2321
|
-
var amount = convertToAbsoluteValue(params[0]);
|
|
2322
|
-
createFeComponentTransfer(document, $filter, {
|
|
2323
|
-
type: 'table',
|
|
2324
|
-
tableValues: amount + " " + (1 - amount)
|
|
2325
|
-
});
|
|
2326
|
-
}
|
|
2327
|
-
function createBrightness(document, $filter, params) {
|
|
2328
|
-
var slope = convertToAbsoluteValue(params[0]);
|
|
2329
|
-
createFeComponentTransfer(document, $filter, {
|
|
2330
|
-
type: 'linear',
|
|
2331
|
-
slope: slope,
|
|
2332
|
-
intercept: 0
|
|
2333
|
-
});
|
|
2334
|
-
}
|
|
2335
|
-
function createSaturate(document, $filter, params) {
|
|
2336
|
-
var amount = convertToAbsoluteValue(params[0]);
|
|
2337
|
-
var $feColorMatrix = createSVGElement('feColorMatrix', document);
|
|
2338
|
-
$feColorMatrix.setAttribute('type', 'saturate');
|
|
2339
|
-
$feColorMatrix.setAttribute('values', "" + amount);
|
|
2340
|
-
$filter.appendChild($feColorMatrix);
|
|
2341
|
-
}
|
|
2342
|
-
function createHueRotate(document, $filter, params) {
|
|
2343
|
-
var $feColorMatrix = createSVGElement('feColorMatrix', document);
|
|
2344
|
-
$feColorMatrix.setAttribute('type', 'hueRotate');
|
|
2345
|
-
// $feColorMatrix.setAttribute('values', `${params[0].to(UnitType.kDegrees).value}`);
|
|
2346
|
-
// FIXME: convert to degrees
|
|
2347
|
-
$feColorMatrix.setAttribute('values', "" + params[0].value);
|
|
2348
|
-
$filter.appendChild($feColorMatrix);
|
|
2349
|
-
}
|
|
2350
|
-
function createDropShadow(document, $filter, params) {
|
|
2351
|
-
var shadowOffsetX = params[0].value;
|
|
2352
|
-
var shadowOffsetY = params[1].value;
|
|
2353
|
-
var shadowBlur = params[2].value;
|
|
2354
|
-
// @ts-ignore
|
|
2355
|
-
var shadowColor = params[3].formatted;
|
|
2356
|
-
var $feGaussianBlur = createSVGElement('feGaussianBlur', document);
|
|
2357
|
-
$feGaussianBlur.setAttribute('in', 'SourceAlpha');
|
|
2358
|
-
$feGaussianBlur.setAttribute('stdDeviation', "" + shadowBlur);
|
|
2359
|
-
$filter.appendChild($feGaussianBlur);
|
|
2360
|
-
var $feOffset = createSVGElement('feOffset', document);
|
|
2361
|
-
$feOffset.setAttribute('dx', "" + shadowOffsetX);
|
|
2362
|
-
$feOffset.setAttribute('dy', "" + shadowOffsetY);
|
|
2363
|
-
$feOffset.setAttribute('result', 'offsetblur');
|
|
2364
|
-
$filter.appendChild($feOffset);
|
|
2365
|
-
var $feFlood = createSVGElement('feFlood', document);
|
|
2366
|
-
$feFlood.setAttribute('flood-color', shadowColor);
|
|
2367
|
-
$filter.appendChild($feFlood);
|
|
2368
|
-
var $feComposite = createSVGElement('feComposite', document);
|
|
2369
|
-
$feComposite.setAttribute('in2', 'offsetblur');
|
|
2370
|
-
$feComposite.setAttribute('operator', 'in');
|
|
2371
|
-
$filter.appendChild($feComposite);
|
|
2372
|
-
var $feMerge = createSVGElement('feMerge', document);
|
|
2373
|
-
$filter.appendChild($feMerge);
|
|
2374
|
-
var $feMergeNode1 = createSVGElement('feMergeNode', document);
|
|
2375
|
-
var $feMergeNode2 = createSVGElement('feMergeNode', document);
|
|
2376
|
-
$feMergeNode2.setAttribute('in', 'SourceGraphic');
|
|
2377
|
-
$feMerge.appendChild($feMergeNode1);
|
|
2378
|
-
$feMerge.appendChild($feMergeNode2);
|
|
2379
|
-
}
|
|
2380
|
-
function createFeColorMatrix(document, $filter, matrix) {
|
|
2381
|
-
var $feColorMatrix = createSVGElement('feColorMatrix', document);
|
|
2382
|
-
$feColorMatrix.setAttribute('type', 'matrix');
|
|
2383
|
-
$feColorMatrix.setAttribute('values', matrix.join(' '));
|
|
2384
|
-
$filter.appendChild($feColorMatrix);
|
|
2385
|
-
}
|
|
2386
|
-
/**
|
|
2387
|
-
* @see https://drafts.fxtf.org/filter-effects/#grayscaleEquivalent
|
|
2388
|
-
*/
|
|
2389
|
-
function createGrayscale(document, $filter, params) {
|
|
2390
|
-
var amount = convertToAbsoluteValue(params[0]);
|
|
2391
|
-
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]);
|
|
2392
|
-
}
|
|
2393
|
-
/**
|
|
2394
|
-
* @see https://drafts.fxtf.org/filter-effects/#sepiaEquivalent
|
|
2395
|
-
*/
|
|
2396
|
-
function createSepia(document, $filter, params) {
|
|
2397
|
-
var amount = convertToAbsoluteValue(params[0]);
|
|
2398
|
-
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]);
|
|
2399
|
-
}
|
|
2400
|
-
var PATTERN_PREFIX = 'g-pattern-';
|
|
2401
|
-
var cacheKey2IDMap = {};
|
|
2402
|
-
var counter = 0;
|
|
2403
|
-
function createOrUpdateGradientAndPattern(document, $def, object, $el, parsedColor, name, createImage, plugin) {
|
|
2404
|
-
// eg. clipPath don't have fill/stroke
|
|
2405
|
-
if (!parsedColor) {
|
|
2406
|
-
return '';
|
|
2407
|
-
}
|
|
2408
|
-
if (gLite.isCSSRGB(parsedColor)) {
|
|
2409
|
-
// keep using currentColor @see https://github.com/d3/d3-axis/issues/49
|
|
2410
|
-
if (object.style[name] === 'currentColor') {
|
|
2411
|
-
$el === null || $el === void 0 ? void 0 : $el.setAttribute(name, 'currentColor');
|
|
2412
|
-
} else {
|
|
2413
|
-
// constant value, eg. '#fff'
|
|
2414
|
-
$el === null || $el === void 0 ? void 0 : $el.setAttribute(name, parsedColor.isNone ? 'none' : parsedColor.toString());
|
|
2415
|
-
}
|
|
2416
|
-
} else if (gLite.isPattern(parsedColor)) {
|
|
2417
|
-
var patternId = createOrUpdatePattern(document, $def, object, parsedColor, createImage, plugin);
|
|
2418
|
-
// use style instead of attribute when applying <pattern>
|
|
2419
|
-
// @see https://stackoverflow.com/a/7723115
|
|
2420
|
-
$el.style[name] = "url(#" + patternId + ")";
|
|
2421
|
-
return patternId;
|
|
2422
|
-
} else {
|
|
2423
|
-
if (parsedColor.length === 1) {
|
|
2424
|
-
var gradientId = createOrUpdateGradient(document, object, $def, $el, parsedColor[0]);
|
|
2425
|
-
$el === null || $el === void 0 ? void 0 : $el.setAttribute(name, "url(#" + gradientId + ")");
|
|
2426
|
-
return gradientId;
|
|
2427
|
-
} else {
|
|
2428
|
-
// @see https://stackoverflow.com/questions/20671502/can-i-blend-gradients-in-svg
|
|
2429
|
-
var filterId = createOrUpdateMultiGradient(document, object, $def, $el, parsedColor);
|
|
2430
|
-
$el === null || $el === void 0 ? void 0 : $el.setAttribute('filter', "url(#" + filterId + ")");
|
|
2431
|
-
$el === null || $el === void 0 ? void 0 : $el.setAttribute('fill', 'black');
|
|
2432
|
-
return filterId;
|
|
2433
|
-
}
|
|
2434
|
-
}
|
|
2435
|
-
return '';
|
|
2436
|
-
}
|
|
2437
|
-
function generateCacheKey(src, options) {
|
|
2438
|
-
if (options === void 0) {
|
|
2439
|
-
options = {};
|
|
2440
|
-
}
|
|
2441
|
-
var cacheKey = '';
|
|
2442
|
-
if (gLite.isCSSGradientValue(src)) {
|
|
2443
|
-
var type = src.type,
|
|
2444
|
-
value = src.value;
|
|
2445
|
-
if (type === gLite.GradientType.LinearGradient || type === gLite.GradientType.RadialGradient) {
|
|
2446
|
-
// @ts-ignore
|
|
2447
|
-
var _value$options = _extends({}, value, options),
|
|
2448
|
-
_type = _value$options.type,
|
|
2449
|
-
width = _value$options.width,
|
|
2450
|
-
height = _value$options.height,
|
|
2451
|
-
steps = _value$options.steps,
|
|
2452
|
-
angle = _value$options.angle,
|
|
2453
|
-
cx = _value$options.cx,
|
|
2454
|
-
cy = _value$options.cy,
|
|
2455
|
-
size = _value$options.size;
|
|
2456
|
-
cacheKey = "gradient-" + _type + "-" + ((angle === null || angle === void 0 ? void 0 : angle.toString()) || 0) + "-" + ((cx === null || cx === void 0 ? void 0 : cx.toString()) || 0) + "-" + ((cy === null || cy === void 0 ? void 0 : cy.toString()) || 0) + "-" + ((size === null || size === void 0 ? void 0 : size.toString()) || 0) + "-" + width + "-" + height + "-" + steps.map(function (_ref) {
|
|
2457
|
-
var offset = _ref.offset,
|
|
2458
|
-
color = _ref.color;
|
|
2459
|
-
return "" + offset + color;
|
|
2460
|
-
}).join('-');
|
|
2461
|
-
}
|
|
2462
|
-
} else if (gLite.isPattern(src)) {
|
|
2463
|
-
if (isString(src.image)) {
|
|
2464
|
-
cacheKey = "pattern-" + src.image + "-" + src.repetition;
|
|
2465
|
-
} else if (src.image.nodeName === 'rect') {
|
|
2466
|
-
// use rect's entity as key
|
|
2467
|
-
cacheKey = "pattern-rect-" + src.image.entity;
|
|
2468
|
-
} else {
|
|
2469
|
-
cacheKey = "pattern-" + counter;
|
|
2470
|
-
}
|
|
2471
|
-
}
|
|
2472
|
-
if (cacheKey) {
|
|
2473
|
-
if (!cacheKey2IDMap[cacheKey]) {
|
|
2474
|
-
cacheKey2IDMap[cacheKey] = PATTERN_PREFIX + ("" + counter++);
|
|
2475
|
-
}
|
|
2476
|
-
}
|
|
2477
|
-
return cacheKey2IDMap[cacheKey];
|
|
2478
|
-
}
|
|
2479
|
-
function formatTransform(transform) {
|
|
2480
|
-
// @see https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/patternTransform
|
|
2481
|
-
// should remove unit: rotate(20deg) -> rotate(20)
|
|
2482
|
-
return gLite.parseTransform(transform).map(function (parsed) {
|
|
2483
|
-
var t = parsed.t,
|
|
2484
|
-
d = parsed.d;
|
|
2485
|
-
if (t === 'translate') {
|
|
2486
|
-
return "translate(" + d[0].value + " " + d[1].value + ")";
|
|
2487
|
-
} else if (t === 'translatex') {
|
|
2488
|
-
return "translate(" + d[0].value + " 0)";
|
|
2489
|
-
} else if (t === 'translatey') {
|
|
2490
|
-
return "translate(0 " + d[0].value + ")";
|
|
2491
|
-
} else if (t === 'rotate') {
|
|
2492
|
-
return "rotate(" + d[0].value + ")";
|
|
2493
|
-
} else if (t === 'scale') {
|
|
2494
|
-
// scale(1) scale(1, 1)
|
|
2495
|
-
var newScale = (d === null || d === void 0 ? void 0 : d.map(function (s) {
|
|
2496
|
-
return s.value;
|
|
2497
|
-
})) || [1, 1];
|
|
2498
|
-
return "scale(" + newScale[0] + ", " + newScale[1] + ")";
|
|
2499
|
-
} else if (t === 'scalex') {
|
|
2500
|
-
var _newScale = (d === null || d === void 0 ? void 0 : d.map(function (s) {
|
|
2501
|
-
return s.value;
|
|
2502
|
-
})) || [1];
|
|
2503
|
-
return "scale(" + _newScale[0] + ", 1)";
|
|
2504
|
-
} else if (t === 'scaley') {
|
|
2505
|
-
var _newScale2 = (d === null || d === void 0 ? void 0 : d.map(function (s) {
|
|
2506
|
-
return s.value;
|
|
2507
|
-
})) || [1];
|
|
2508
|
-
return "scale(1, " + _newScale2[0] + ")";
|
|
2509
|
-
} else if (t === 'skew') {
|
|
2510
|
-
var newSkew = (d === null || d === void 0 ? void 0 : d.map(function (s) {
|
|
2511
|
-
return s.value;
|
|
2512
|
-
})) || [0, 0];
|
|
2513
|
-
return "skewX(" + newSkew[0] + ") skewY(" + newSkew[1] + ")";
|
|
2514
|
-
} else if (t === 'skewx') {
|
|
2515
|
-
var _newSkew = (d === null || d === void 0 ? void 0 : d.map(function (s) {
|
|
2516
|
-
return s.value;
|
|
2517
|
-
})) || [0];
|
|
2518
|
-
return "skewX(" + _newSkew[0] + ")";
|
|
2519
|
-
} else if (t === 'skewy') {
|
|
2520
|
-
var _newSkew2 = (d === null || d === void 0 ? void 0 : d.map(function (s) {
|
|
2521
|
-
return s.value;
|
|
2522
|
-
})) || [0];
|
|
2523
|
-
return "skewY(" + _newSkew2[0] + ")";
|
|
2524
|
-
} else if (t === 'matrix') {
|
|
2525
|
-
var _d$map = d.map(function (s) {
|
|
2526
|
-
return s.value;
|
|
2527
|
-
}),
|
|
2528
|
-
a = _d$map[0],
|
|
2529
|
-
b = _d$map[1],
|
|
2530
|
-
c = _d$map[2],
|
|
2531
|
-
dd = _d$map[3],
|
|
2532
|
-
tx = _d$map[4],
|
|
2533
|
-
ty = _d$map[5];
|
|
2534
|
-
return "matrix(" + a + " " + b + " " + c + " " + dd + " " + tx + " " + ty + ")";
|
|
2535
|
-
}
|
|
2536
|
-
}).join(' ');
|
|
2537
|
-
}
|
|
2538
|
-
function create$Pattern(document, $def, object, pattern, patternId, width, height) {
|
|
2539
|
-
var repetition = pattern.repetition,
|
|
2540
|
-
transform = pattern.transform;
|
|
2541
|
-
// @see https://developer.mozilla.org/zh-CN/docs/Web/SVG/Element/pattern
|
|
2542
|
-
var $pattern = createSVGElement('pattern', document);
|
|
2543
|
-
if (transform) {
|
|
2544
|
-
$pattern.setAttribute('patternTransform', formatTransform(transform));
|
|
2545
|
-
}
|
|
2546
|
-
$pattern.setAttribute('patternUnits', 'userSpaceOnUse');
|
|
2547
|
-
$pattern.id = patternId;
|
|
2548
|
-
$def.appendChild($pattern);
|
|
2549
|
-
$pattern.setAttribute('x', '0');
|
|
2550
|
-
$pattern.setAttribute('y', '0');
|
|
2551
|
-
var _object$getGeometryBo = object.getGeometryBounds(),
|
|
2552
|
-
halfExtents = _object$getGeometryBo.halfExtents;
|
|
2553
|
-
// There is no equivalent to CSS no-repeat for SVG patterns
|
|
2554
|
-
// @see https://stackoverflow.com/a/33481956
|
|
2555
|
-
var patternWidth = width;
|
|
2556
|
-
var patternHeight = height;
|
|
2557
|
-
if (repetition === 'repeat-x') {
|
|
2558
|
-
patternHeight = halfExtents[1] * 2;
|
|
2559
|
-
} else if (repetition === 'repeat-y') {
|
|
2560
|
-
patternWidth = halfExtents[0] * 2;
|
|
2561
|
-
} else if (repetition === 'no-repeat') {
|
|
2562
|
-
patternWidth = halfExtents[0] * 2;
|
|
2563
|
-
patternHeight = halfExtents[1] * 2;
|
|
2564
|
-
}
|
|
2565
|
-
$pattern.setAttribute('width', "" + patternWidth);
|
|
2566
|
-
$pattern.setAttribute('height', "" + patternHeight);
|
|
2567
|
-
return $pattern;
|
|
2568
|
-
}
|
|
2569
|
-
function createOrUpdatePattern(document, $def, object, pattern, createImage, plugin) {
|
|
2570
|
-
var patternId = generateCacheKey(pattern);
|
|
2571
|
-
var $existed = $def.querySelector("#" + patternId);
|
|
2572
|
-
if (!$existed) {
|
|
2573
|
-
var image = pattern.image;
|
|
2574
|
-
var imageURL = '';
|
|
2575
|
-
if (isString(image)) {
|
|
2576
|
-
imageURL = image;
|
|
2577
|
-
} else {
|
|
2578
|
-
if (gLite.isBrowser) {
|
|
2579
|
-
if (image instanceof HTMLImageElement) {
|
|
2580
|
-
imageURL = image.src;
|
|
2581
|
-
} else if (image instanceof HTMLCanvasElement) {
|
|
2582
|
-
imageURL = image.toDataURL();
|
|
2583
|
-
} else ;
|
|
2584
|
-
}
|
|
2585
|
-
}
|
|
2586
|
-
if (imageURL) {
|
|
2587
|
-
var $image = createSVGElement('image', document);
|
|
2588
|
-
// use href instead of xlink:href
|
|
2589
|
-
// @see https://stackoverflow.com/a/13379007
|
|
2590
|
-
$image.setAttribute('href', imageURL);
|
|
2591
|
-
var img;
|
|
2592
|
-
if (createImage) {
|
|
2593
|
-
img = createImage(imageURL);
|
|
2594
|
-
} else if (gLite.isBrowser) {
|
|
2595
|
-
img = new window.Image();
|
|
2596
|
-
}
|
|
2597
|
-
if (!imageURL.match(/^data:/i)) {
|
|
2598
|
-
img.crossOrigin = 'Anonymous';
|
|
2599
|
-
$image.setAttribute('crossorigin', 'anonymous');
|
|
2600
|
-
}
|
|
2601
|
-
img.src = imageURL;
|
|
2602
|
-
var onload = function onload() {
|
|
2603
|
-
var $pattern = create$Pattern(document, $def, object, pattern, patternId, img.width, img.height);
|
|
2604
|
-
$def.appendChild($pattern);
|
|
2605
|
-
$pattern.appendChild($image);
|
|
2606
|
-
$image.setAttribute('x', '0');
|
|
2607
|
-
$image.setAttribute('y', '0');
|
|
2608
|
-
$image.setAttribute('width', "" + img.width);
|
|
2609
|
-
$image.setAttribute('height', "" + img.height);
|
|
2610
|
-
};
|
|
2611
|
-
if (img.complete) {
|
|
2612
|
-
onload();
|
|
2613
|
-
} else {
|
|
2614
|
-
img.onload = onload;
|
|
2615
|
-
// Fix onload() bug in IE9
|
|
2616
|
-
// img.src = img.src;
|
|
2617
|
-
}
|
|
2618
|
-
}
|
|
2619
|
-
|
|
2620
|
-
if (image.nodeName === 'rect') {
|
|
2621
|
-
var _image$parsedStyle = image.parsedStyle,
|
|
2622
|
-
width = _image$parsedStyle.width,
|
|
2623
|
-
height = _image$parsedStyle.height;
|
|
2624
|
-
var $pattern = create$Pattern(document, $def, image, pattern, patternId, width, height);
|
|
2625
|
-
// traverse subtree of pattern
|
|
2626
|
-
image.forEach(function (object) {
|
|
2627
|
-
plugin.createSVGDom(document, object, null);
|
|
2628
|
-
// @ts-ignore
|
|
2629
|
-
var svgElement = object.elementSVG;
|
|
2630
|
-
// apply local RTS transformation to <group> wrapper
|
|
2631
|
-
// account for anchor
|
|
2632
|
-
var localTransform = object.getLocalTransform();
|
|
2633
|
-
plugin.applyTransform(svgElement.$groupEl, localTransform);
|
|
2634
|
-
});
|
|
2635
|
-
// @ts-ignore
|
|
2636
|
-
var svgElement = image.elementSVG;
|
|
2637
|
-
$pattern.appendChild(svgElement.$groupEl);
|
|
2638
|
-
}
|
|
2639
|
-
}
|
|
2640
|
-
return patternId;
|
|
2641
|
-
}
|
|
2642
|
-
function createOrUpdateGradient(document, object, $def, $el, parsedColor) {
|
|
2643
|
-
var bounds = object.getGeometryBounds();
|
|
2644
|
-
var width = bounds && bounds.halfExtents[0] * 2 || 0;
|
|
2645
|
-
var height = bounds && bounds.halfExtents[1] * 2 || 0;
|
|
2646
|
-
var gradientId = generateCacheKey(parsedColor, {
|
|
2647
|
-
width: width,
|
|
2648
|
-
height: height
|
|
2649
|
-
});
|
|
2650
|
-
var $existed = $def.querySelector("#" + gradientId);
|
|
2651
|
-
if (!$existed) {
|
|
2652
|
-
// <linearGradient> <radialGradient>
|
|
2653
|
-
// @see https://developer.mozilla.org/zh-CN/docs/Web/SVG/Element/linearGradient
|
|
2654
|
-
// @see https://developer.mozilla.org/zh-CN/docs/Web/SVG/Element/radialGradient
|
|
2655
|
-
$existed = createSVGElement(parsedColor.type === gLite.GradientType.LinearGradient ? 'linearGradient' : 'radialGradient', document);
|
|
2656
|
-
// @see https://github.com/antvis/g/issues/1025
|
|
2657
|
-
$existed.setAttribute('gradientUnits', 'userSpaceOnUse');
|
|
2658
|
-
// add stops
|
|
2659
|
-
var innerHTML = '';
|
|
2660
|
-
parsedColor.value.steps
|
|
2661
|
-
// sort by offset @see https://github.com/antvis/G/issues/1171
|
|
2662
|
-
.sort(function (a, b) {
|
|
2663
|
-
return a.offset.value - b.offset.value;
|
|
2664
|
-
}).forEach(function (_ref2) {
|
|
2665
|
-
var offset = _ref2.offset,
|
|
2666
|
-
color = _ref2.color;
|
|
2667
|
-
// TODO: support absolute unit like `px`
|
|
2668
|
-
innerHTML += "<stop offset=\"" + offset.value / 100 + "\" stop-color=\"" + color + "\"></stop>";
|
|
2669
|
-
});
|
|
2670
|
-
$existed.innerHTML = innerHTML;
|
|
2671
|
-
$existed.id = gradientId;
|
|
2672
|
-
$def.appendChild($existed);
|
|
2673
|
-
}
|
|
2674
|
-
if (parsedColor.type === gLite.GradientType.LinearGradient) {
|
|
2675
|
-
var angle = parsedColor.value.angle;
|
|
2676
|
-
var _computeLinearGradien = gLite.computeLinearGradient(width, height, angle),
|
|
2677
|
-
x1 = _computeLinearGradien.x1,
|
|
2678
|
-
y1 = _computeLinearGradien.y1,
|
|
2679
|
-
x2 = _computeLinearGradien.x2,
|
|
2680
|
-
y2 = _computeLinearGradien.y2;
|
|
2681
|
-
$existed.setAttribute('x1', "" + x1);
|
|
2682
|
-
$existed.setAttribute('y1', "" + y1);
|
|
2683
|
-
$existed.setAttribute('x2', "" + x2);
|
|
2684
|
-
$existed.setAttribute('y2', "" + y2);
|
|
2685
|
-
// $existed.setAttribute('gradientTransform', `rotate(${angle})`);
|
|
2686
|
-
} else {
|
|
2687
|
-
var _parsedColor$value = parsedColor.value,
|
|
2688
|
-
cx = _parsedColor$value.cx,
|
|
2689
|
-
cy = _parsedColor$value.cy,
|
|
2690
|
-
size = _parsedColor$value.size;
|
|
2691
|
-
var _computeRadialGradien = gLite.computeRadialGradient(width, height, cx, cy, size),
|
|
2692
|
-
x = _computeRadialGradien.x,
|
|
2693
|
-
y = _computeRadialGradien.y,
|
|
2694
|
-
r = _computeRadialGradien.r;
|
|
2695
|
-
$existed.setAttribute('cx', "" + x);
|
|
2696
|
-
$existed.setAttribute('cy', "" + y);
|
|
2697
|
-
$existed.setAttribute('r', "" + r);
|
|
2698
|
-
}
|
|
2699
|
-
return gradientId;
|
|
2700
|
-
}
|
|
2701
|
-
function createOrUpdateMultiGradient(document, object, $def, $el, gradients) {
|
|
2702
|
-
var filterId = FILTER_PREFIX + object.entity + '-gradient';
|
|
2703
|
-
var $existed = $def.querySelector("#" + filterId);
|
|
2704
|
-
if (!$existed) {
|
|
2705
|
-
$existed = createSVGElement('filter', document);
|
|
2706
|
-
$existed.setAttribute('filterUnits', 'userSpaceOnUse');
|
|
2707
|
-
// @see https://github.com/antvis/g/issues/1025
|
|
2708
|
-
$existed.setAttribute('x', '0%');
|
|
2709
|
-
$existed.setAttribute('y', '0%');
|
|
2710
|
-
$existed.setAttribute('width', '100%');
|
|
2711
|
-
$existed.setAttribute('height', '100%');
|
|
2712
|
-
$existed.id = filterId;
|
|
2713
|
-
$def.appendChild($existed);
|
|
2714
|
-
}
|
|
2715
|
-
/**
|
|
2716
|
-
* <rect id="wave-rect" x="0" y="0" width="100%" height="100%" fill="url(#wave)"></rect>
|
|
2717
|
-
* <filter id="blend-it" x="0%" y="0%" width="100%" height="100%">
|
|
2718
|
-
<feImage xlink:href="#wave-rect" result="myWave" x="100" y="100"/>
|
|
2719
|
-
<feImage xlink:href="#ry-rect" result="myRY" x="100" y="100"/>
|
|
2720
|
-
<feBlend in="myWave" in2="myRY" mode="multiply" result="blendedGrad"/>
|
|
2721
|
-
<feComposite in="blendedGrad" in2="SourceGraphic" operator="in"/>
|
|
2722
|
-
</filter>
|
|
2723
|
-
*/
|
|
2724
|
-
var blended = 0;
|
|
2725
|
-
gradients.forEach(function (gradient, i) {
|
|
2726
|
-
var gradientId = createOrUpdateGradient(document, object, $def, $el, gradient);
|
|
2727
|
-
var rectId = gradientId + '_rect';
|
|
2728
|
-
var $rect = createSVGElement('rect', document);
|
|
2729
|
-
$rect.setAttribute('x', '0');
|
|
2730
|
-
$rect.setAttribute('y', '0');
|
|
2731
|
-
$rect.setAttribute('width', '100%');
|
|
2732
|
-
$rect.setAttribute('height', '100%');
|
|
2733
|
-
$rect.setAttribute('fill', "url(#" + gradientId + ")");
|
|
2734
|
-
$rect.id = rectId;
|
|
2735
|
-
$def.appendChild($rect);
|
|
2736
|
-
var $feImage = createSVGElement('feImage', document);
|
|
2737
|
-
$feImage.setAttribute('href', "#" + rectId);
|
|
2738
|
-
$feImage.setAttribute('result', filterId + "-" + i);
|
|
2739
|
-
$existed.appendChild($feImage);
|
|
2740
|
-
if (i > 0) {
|
|
2741
|
-
var $feBlend = createSVGElement('feBlend', document);
|
|
2742
|
-
$feBlend.setAttribute('in', i === 1 ? filterId + "-" + (i - 1) : filterId + "-blended-" + (blended - 1));
|
|
2743
|
-
$feBlend.setAttribute('in2', filterId + "-" + i);
|
|
2744
|
-
$feBlend.setAttribute('result', filterId + "-blended-" + blended++);
|
|
2745
|
-
// @see https://developer.mozilla.org/zh-CN/docs/Web/CSS/blend-mode
|
|
2746
|
-
$feBlend.setAttribute('mode', 'multiply');
|
|
2747
|
-
$existed.appendChild($feBlend);
|
|
2748
|
-
}
|
|
2749
|
-
});
|
|
2750
|
-
var $feComposite = createSVGElement('feComposite', document);
|
|
2751
|
-
$feComposite.setAttribute('in', filterId + "-blended-" + blended);
|
|
2752
|
-
$feComposite.setAttribute('in2', 'SourceGraphic');
|
|
2753
|
-
$feComposite.setAttribute('operator', 'in');
|
|
2754
|
-
$existed.appendChild($feComposite);
|
|
2755
|
-
return filterId;
|
|
2756
|
-
}
|
|
2757
|
-
var FILTER_DROPSHADOW_PREFIX = 'g-filter-dropshadow-';
|
|
2758
|
-
/**
|
|
2759
|
-
* use SVG filters
|
|
2760
|
-
* @see https://developer.mozilla.org/zh-CN/docs/Web/SVG/Element/filter
|
|
2761
|
-
*/
|
|
2762
|
-
function createOrUpdateShadow(document, $def, object, $el, name) {
|
|
2763
|
-
var _object$parsedStyle = object.parsedStyle,
|
|
2764
|
-
shadowType = _object$parsedStyle.shadowType,
|
|
2765
|
-
shadowBlur = _object$parsedStyle.shadowBlur,
|
|
2766
|
-
shadowColor = _object$parsedStyle.shadowColor,
|
|
2767
|
-
shadowOffsetX = _object$parsedStyle.shadowOffsetX,
|
|
2768
|
-
shadowOffsetY = _object$parsedStyle.shadowOffsetY;
|
|
2769
|
-
var hasShadow = !isNil(shadowColor) && shadowBlur > 0;
|
|
2770
|
-
var shadowId = FILTER_DROPSHADOW_PREFIX + object.entity;
|
|
2771
|
-
var $existedFilter = $def.querySelector("#" + shadowId);
|
|
2772
|
-
if ($existedFilter) {
|
|
2773
|
-
var existedShadowType = $existedFilter.getAttribute('data-type');
|
|
2774
|
-
if (existedShadowType !== shadowType || !hasShadow) {
|
|
2775
|
-
// remove existed shadow
|
|
2776
|
-
$existedFilter.remove();
|
|
2777
|
-
$existedFilter = null;
|
|
2778
|
-
}
|
|
2779
|
-
}
|
|
2780
|
-
// <Group> also has shadowType as its default value
|
|
2781
|
-
// only apply shadow when blur > 0
|
|
2782
|
-
if (hasShadow) {
|
|
2783
|
-
// use filter <feDropShadow>
|
|
2784
|
-
// @see https://developer.mozilla.org/en-US/docs/Web/SVG/Element/feDropShadow
|
|
2785
|
-
$el === null || $el === void 0 ? void 0 : $el.setAttribute('filter', "url(#" + shadowId + ")");
|
|
2786
|
-
} else {
|
|
2787
|
-
$el === null || $el === void 0 ? void 0 : $el.removeAttribute('filter');
|
|
2788
|
-
return;
|
|
2789
|
-
}
|
|
2790
|
-
if (!$existedFilter) {
|
|
2791
|
-
$existedFilter = createSVGElement('filter', document);
|
|
2792
|
-
$existedFilter.setAttribute('data-type', shadowType);
|
|
2793
|
-
if (shadowType === 'outer') {
|
|
2794
|
-
var $feDropShadow = createSVGElement('feDropShadow', document);
|
|
2795
|
-
$feDropShadow.setAttribute('dx', "" + (shadowOffsetX || 0) / 2);
|
|
2796
|
-
$feDropShadow.setAttribute('dy', "" + (shadowOffsetY || 0) / 2);
|
|
2797
|
-
$feDropShadow.setAttribute('stdDeviation', "" + (shadowBlur || 0) / 4);
|
|
2798
|
-
$feDropShadow.setAttribute('flood-color', shadowColor.toString());
|
|
2799
|
-
$existedFilter.appendChild($feDropShadow);
|
|
2800
|
-
} else if (shadowType === 'inner') {
|
|
2801
|
-
var $feComponentTransfer = createSVGElement('feComponentTransfer', document);
|
|
2802
|
-
$feComponentTransfer.setAttribute('in', 'SourceAlpha');
|
|
2803
|
-
var $feFuncA = createSVGElement('feFuncA', document);
|
|
2804
|
-
$feFuncA.setAttribute('type', 'table');
|
|
2805
|
-
$feFuncA.setAttribute('tableValues', '1 0');
|
|
2806
|
-
$feComponentTransfer.appendChild($feFuncA);
|
|
2807
|
-
$existedFilter.appendChild($feComponentTransfer);
|
|
2808
|
-
var $feGaussianBlur = createSVGElement('feGaussianBlur', document);
|
|
2809
|
-
$feGaussianBlur.setAttribute('stdDeviation', "" + (shadowBlur || 0) / 4);
|
|
2810
|
-
$existedFilter.appendChild($feGaussianBlur);
|
|
2811
|
-
var $feOffset = createSVGElement('feOffset', document);
|
|
2812
|
-
$feOffset.setAttribute('dx', "" + (shadowOffsetX || 0) / 2);
|
|
2813
|
-
$feOffset.setAttribute('dy', "" + (shadowOffsetY || 0) / 2);
|
|
2814
|
-
$feOffset.setAttribute('result', 'offsetblur');
|
|
2815
|
-
$existedFilter.appendChild($feOffset);
|
|
2816
|
-
var $feFlood = createSVGElement('feFlood', document);
|
|
2817
|
-
$feFlood.setAttribute('flood-color', shadowColor.toString());
|
|
2818
|
-
$feFlood.setAttribute('result', 'color');
|
|
2819
|
-
$existedFilter.appendChild($feFlood);
|
|
2820
|
-
var $feComposite = createSVGElement('feComposite', document);
|
|
2821
|
-
$feComposite.setAttribute('in2', 'offsetblur');
|
|
2822
|
-
$feComposite.setAttribute('operator', 'in');
|
|
2823
|
-
$existedFilter.appendChild($feComposite);
|
|
2824
|
-
var $feComposite2 = createSVGElement('feComposite', document);
|
|
2825
|
-
$feComposite2.setAttribute('in2', 'SourceAlpha');
|
|
2826
|
-
$feComposite2.setAttribute('operator', 'in');
|
|
2827
|
-
$existedFilter.appendChild($feComposite2);
|
|
2828
|
-
var $feMerge = createSVGElement('feMerge', document);
|
|
2829
|
-
$existedFilter.appendChild($feMerge);
|
|
2830
|
-
var $feMergeNode = createSVGElement('feMergeNode', document);
|
|
2831
|
-
$feMergeNode.setAttribute('in', 'SourceGraphic');
|
|
2832
|
-
var $feMergeNode2 = createSVGElement('feMergeNode', document);
|
|
2833
|
-
$feMerge.appendChild($feMergeNode);
|
|
2834
|
-
$feMerge.appendChild($feMergeNode2);
|
|
2835
|
-
}
|
|
2836
|
-
$existedFilter.id = shadowId;
|
|
2837
|
-
// @see https://github.com/antvis/g/issues/1025
|
|
2838
|
-
$existedFilter.setAttribute('filterUnits', 'userSpaceOnUse');
|
|
2839
|
-
$def.appendChild($existedFilter);
|
|
2840
|
-
return;
|
|
2841
|
-
}
|
|
2842
|
-
if (shadowType === 'inner') {
|
|
2843
|
-
var _$feGaussianBlur = $existedFilter.children[1];
|
|
2844
|
-
var _$feOffset = $existedFilter.children[2];
|
|
2845
|
-
var _$feFlood = $existedFilter.children[3];
|
|
2846
|
-
if (name === 'shadowColor') {
|
|
2847
|
-
_$feFlood.setAttribute('flood-color', shadowColor.toString());
|
|
2848
|
-
} else if (name === 'shadowBlur') {
|
|
2849
|
-
// half the blur radius
|
|
2850
|
-
// @see https://drafts.csswg.org/css-backgrounds/#shadow-blur
|
|
2851
|
-
// @see https://css-tricks.com/breaking-css-box-shadow-vs-drop-shadow/
|
|
2852
|
-
_$feGaussianBlur.setAttribute('stdDeviation', "" + (shadowBlur || 0) / 4);
|
|
2853
|
-
} else if (name === 'shadowOffsetX') {
|
|
2854
|
-
_$feOffset.setAttribute('dx', "" + (shadowOffsetX || 0) / 2);
|
|
2855
|
-
} else if (name === 'shadowOffsetY') {
|
|
2856
|
-
_$feOffset.setAttribute('dy', "" + (shadowOffsetY || 0) / 2);
|
|
2857
|
-
}
|
|
2858
|
-
} else if (shadowType === 'outer') {
|
|
2859
|
-
var _$feDropShadow = $existedFilter.children[0];
|
|
2860
|
-
if (name === 'shadowColor') {
|
|
2861
|
-
_$feDropShadow.setAttribute('flood-color', shadowColor.toString());
|
|
2862
|
-
} else if (name === 'shadowBlur') {
|
|
2863
|
-
// half the blur radius
|
|
2864
|
-
// @see https://drafts.csswg.org/css-backgrounds/#shadow-blur
|
|
2865
|
-
// @see https://css-tricks.com/breaking-css-box-shadow-vs-drop-shadow/
|
|
2866
|
-
_$feDropShadow.setAttribute('stdDeviation', "" + (shadowBlur || 0) / 4);
|
|
2867
|
-
} else if (name === 'shadowOffsetX') {
|
|
2868
|
-
_$feDropShadow.setAttribute('dx', "" + (shadowOffsetX || 0) / 2);
|
|
2869
|
-
} else if (name === 'shadowOffsetY') {
|
|
2870
|
-
_$feDropShadow.setAttribute('dy', "" + (shadowOffsetY || 0) / 2);
|
|
2871
|
-
}
|
|
2872
|
-
}
|
|
2873
|
-
}
|
|
2874
|
-
var urlRegexp = /url\("?#(.*)\)/;
|
|
2875
|
-
var DefElementManager = /*#__PURE__*/function () {
|
|
2876
|
-
function DefElementManager(context) {
|
|
2877
|
-
this.context = void 0;
|
|
2878
|
-
/**
|
|
2879
|
-
* container for <gradient> <clipPath>...
|
|
2880
|
-
*/
|
|
2881
|
-
this.$def = void 0;
|
|
2882
|
-
this.gradientCache = {};
|
|
2883
|
-
this.context = context;
|
|
2884
|
-
}
|
|
2885
|
-
var _proto = DefElementManager.prototype;
|
|
2886
|
-
_proto.getDefElement = function getDefElement() {
|
|
2887
|
-
return this.$def;
|
|
2888
|
-
};
|
|
2889
|
-
_proto.init = function init() {
|
|
2890
|
-
var document = this.context.config.document;
|
|
2891
|
-
var $svg = this.context.contextService.getContext();
|
|
2892
|
-
this.$def = createSVGElement('defs', document);
|
|
2893
|
-
$svg.appendChild(this.$def);
|
|
2894
|
-
};
|
|
2895
|
-
_proto.clear = function clear(entity) {
|
|
2896
|
-
var _this = this;
|
|
2897
|
-
Object.keys(this.gradientCache).forEach(function (id) {
|
|
2898
|
-
_this.clearUnusedDefElement(_this.gradientCache, id, entity);
|
|
2899
|
-
});
|
|
2900
|
-
};
|
|
2901
|
-
_proto.clearUnusedDefElement = function clearUnusedDefElement(cache, id, entity) {
|
|
2902
|
-
if (cache[id] && cache[id].size === 1 && cache[id].has(entity)) {
|
|
2903
|
-
var targetElement = this.$def.querySelector("#" + id);
|
|
2904
|
-
if (targetElement) {
|
|
2905
|
-
this.$def.removeChild(targetElement);
|
|
2906
|
-
}
|
|
2907
|
-
}
|
|
2908
|
-
};
|
|
2909
|
-
_proto.createOrUpdateGradientAndPattern = function createOrUpdateGradientAndPattern$1(object, $el, parsedColor, name, plugin) {
|
|
2910
|
-
var _this$context$config = this.context.config,
|
|
2911
|
-
doc = _this$context$config.document,
|
|
2912
|
-
createImage = _this$context$config.createImage;
|
|
2913
|
-
if ($el) {
|
|
2914
|
-
var attributeValue = '';
|
|
2915
|
-
if (gLite.isPattern(parsedColor)) {
|
|
2916
|
-
// `fill: url(#${patternId})`
|
|
2917
|
-
attributeValue = $el.style[name];
|
|
2918
|
-
} else {
|
|
2919
|
-
// `url(#${gradientId})`
|
|
2920
|
-
attributeValue = $el.getAttribute(name) || '';
|
|
2921
|
-
}
|
|
2922
|
-
var matches = attributeValue.match(urlRegexp);
|
|
2923
|
-
if (matches && matches.length > 1) {
|
|
2924
|
-
this.clearUnusedDefElement(this.gradientCache, matches[1].replace('"', ''), object.entity);
|
|
2925
|
-
}
|
|
2926
|
-
var newDefElementId = createOrUpdateGradientAndPattern(doc || document, this.$def, object, $el, parsedColor, name, createImage, plugin);
|
|
2927
|
-
if (newDefElementId) {
|
|
2928
|
-
if (!this.gradientCache[newDefElementId]) {
|
|
2929
|
-
this.gradientCache[newDefElementId] = new Set();
|
|
2930
|
-
}
|
|
2931
|
-
this.gradientCache[newDefElementId].add(object.entity);
|
|
2932
|
-
}
|
|
2933
|
-
}
|
|
2934
|
-
};
|
|
2935
|
-
_proto.createOrUpdateShadow = function createOrUpdateShadow$1(object, $el, name) {
|
|
2936
|
-
var doc = this.context.config.document;
|
|
2937
|
-
createOrUpdateShadow(doc || document, this.$def, object, $el, name);
|
|
2938
|
-
};
|
|
2939
|
-
_proto.createOrUpdateFilter = function createOrUpdateFilter$1(object, $el, filters) {
|
|
2940
|
-
var doc = this.context.config.document;
|
|
2941
|
-
createOrUpdateFilter(doc || document, this.$def, object, $el, filters);
|
|
2942
|
-
};
|
|
2943
|
-
return DefElementManager;
|
|
2944
|
-
}();
|
|
2945
|
-
var Plugin$2 = /*#__PURE__*/function (_AbstractRendererPlug) {
|
|
2946
|
-
_inheritsLoose$3(Plugin, _AbstractRendererPlug);
|
|
2947
|
-
function Plugin(options) {
|
|
2948
|
-
var _this;
|
|
2949
|
-
if (options === void 0) {
|
|
2950
|
-
options = {};
|
|
2951
|
-
}
|
|
2952
|
-
_this = _AbstractRendererPlug.call(this) || this;
|
|
2953
|
-
_this.options = void 0;
|
|
2954
|
-
_this.name = 'svg-renderer';
|
|
2955
|
-
_this.options = options;
|
|
2956
|
-
return _this;
|
|
2957
|
-
}
|
|
2958
|
-
var _proto = Plugin.prototype;
|
|
2959
|
-
_proto.init = function init() {
|
|
2960
|
-
var _this$options = this.options,
|
|
2961
|
-
outputSVGElementId = _this$options.outputSVGElementId,
|
|
2962
|
-
outputSVGElementName = _this$options.outputSVGElementName;
|
|
2963
|
-
var defElementManager = new DefElementManager(this.context);
|
|
2964
|
-
// default implementation
|
|
2965
|
-
var defaultElementLifeCycleContribution = new DefaultElementLifeCycleContribution(this.context);
|
|
2966
|
-
// @ts-ignore
|
|
2967
|
-
this.context.defaultElementLifeCycleContribution = defaultElementLifeCycleContribution;
|
|
2968
|
-
// @ts-ignore
|
|
2969
|
-
this.context.SVGElementLifeCycleContribution = defaultElementLifeCycleContribution;
|
|
2970
|
-
var SVGRendererPluginOptions = {
|
|
2971
|
-
outputSVGElementId: !isNil(outputSVGElementId) ? !!outputSVGElementId : true,
|
|
2972
|
-
outputSVGElementName: !isNil(outputSVGElementName) ? !!outputSVGElementName : true
|
|
2973
|
-
};
|
|
2974
|
-
this.addRenderingPlugin(
|
|
2975
|
-
// @ts-ignore
|
|
2976
|
-
new SVGRendererPlugin(SVGRendererPluginOptions, defElementManager, this.context));
|
|
2977
|
-
};
|
|
2978
|
-
_proto.destroy = function destroy() {
|
|
2979
|
-
this.removeAllRenderingPlugins();
|
|
2980
|
-
// @ts-ignore
|
|
2981
|
-
delete this.context.defaultElementLifeCycleContribution;
|
|
2982
|
-
// @ts-ignore
|
|
2983
|
-
delete this.context.SVGElementLifeCycleContribution;
|
|
2984
|
-
};
|
|
2985
|
-
return Plugin;
|
|
2986
|
-
}(gLite.AbstractRendererPlugin);
|
|
2987
|
-
|
|
2988
|
-
var index_esm$2 = /*#__PURE__*/Object.freeze({
|
|
2989
|
-
__proto__: null,
|
|
2990
|
-
CLIP_PATH_PREFIX: CLIP_PATH_PREFIX,
|
|
2991
|
-
DEFAULT_VALUE_MAP: DEFAULT_VALUE_MAP,
|
|
2992
|
-
DefaultElementLifeCycleContribution: DefaultElementLifeCycleContribution,
|
|
2993
|
-
ElementSVG: ElementSVG,
|
|
2994
|
-
G_SVG_PREFIX: G_SVG_PREFIX,
|
|
2995
|
-
Plugin: Plugin$2,
|
|
2996
|
-
SHAPE2TAGS: SHAPE2TAGS,
|
|
2997
|
-
SHAPE_UPDATE_DEPS: SHAPE_UPDATE_DEPS,
|
|
2998
|
-
SVGRendererPlugin: SVGRendererPlugin,
|
|
2999
|
-
SVG_ATTR_MAP: SVG_ATTR_MAP,
|
|
3000
|
-
TEXT_PATH_PREFIX: TEXT_PATH_PREFIX,
|
|
3001
|
-
createSVGElement: createSVGElement,
|
|
3002
|
-
updateImageElementAttribute: updateImageElementAttribute,
|
|
3003
|
-
updateLineElementAttribute: updateLineElementAttribute,
|
|
3004
|
-
updatePathElementAttribute: updatePathElementAttribute,
|
|
3005
|
-
updatePolylineElementAttribute: updatePolylineElementAttribute,
|
|
3006
|
-
updateRectElementAttribute: updateRectElementAttribute,
|
|
3007
|
-
updateTextElementAttribute: updateTextElementAttribute
|
|
3008
|
-
});
|
|
3009
|
-
|
|
3010
|
-
var _excluded = ["offset", "composite", "computedOffset", "easing"],
|
|
3011
|
-
_excluded2 = ["offset", "composite", "computedOffset", "easing", "transformOrigin"],
|
|
3012
|
-
_excluded3 = ["offset", "composite", "computedOffset", "easing", "transformOrigin"],
|
|
3013
|
-
_excluded4 = ["offset", "composite", "computedOffset", "easing", "transformOrigin"];
|
|
3014
|
-
var SVGContextService = /*#__PURE__*/function () {
|
|
3015
|
-
function SVGContextService(context) {
|
|
3016
|
-
this.context = void 0;
|
|
3017
|
-
this.$container = void 0;
|
|
3018
|
-
this.$namespace = void 0;
|
|
3019
|
-
this.dpr = void 0;
|
|
3020
|
-
this.canvasConfig = void 0;
|
|
3021
|
-
this.context = context;
|
|
3022
|
-
this.canvasConfig = context.config;
|
|
3023
|
-
}
|
|
3024
|
-
var _proto = SVGContextService.prototype;
|
|
3025
|
-
_proto.init = function init() {
|
|
3026
|
-
var _this$canvasConfig = this.canvasConfig,
|
|
3027
|
-
container = _this$canvasConfig.container,
|
|
3028
|
-
doc = _this$canvasConfig.document,
|
|
3029
|
-
devicePixelRatio = _this$canvasConfig.devicePixelRatio;
|
|
3030
|
-
// create container
|
|
3031
|
-
this.$container = isString(container) ? (doc || document).getElementById(container) : container;
|
|
3032
|
-
if (this.$container) {
|
|
3033
|
-
if (!this.$container.style.position) {
|
|
3034
|
-
this.$container.style.position = 'relative';
|
|
3035
|
-
}
|
|
3036
|
-
var $namespace = createSVGElement('svg', doc);
|
|
3037
|
-
$namespace.setAttribute('width', "" + this.canvasConfig.width);
|
|
3038
|
-
$namespace.setAttribute('height', "" + this.canvasConfig.height);
|
|
3039
|
-
this.$container.appendChild($namespace);
|
|
3040
|
-
this.$namespace = $namespace;
|
|
3041
|
-
}
|
|
3042
|
-
// use user-defined dpr first
|
|
3043
|
-
var dpr = devicePixelRatio || gLite.isBrowser && window.devicePixelRatio || 1;
|
|
3044
|
-
dpr = dpr >= 1 ? Math.ceil(dpr) : 1;
|
|
3045
|
-
this.dpr = dpr;
|
|
3046
|
-
}
|
|
3047
|
-
// @ts-ignore
|
|
3048
|
-
;
|
|
3049
|
-
_proto.getDomElement = function getDomElement() {
|
|
3050
|
-
return this.$namespace;
|
|
3051
|
-
};
|
|
3052
|
-
_proto.getContext = function getContext() {
|
|
3053
|
-
return this.$namespace;
|
|
3054
|
-
};
|
|
3055
|
-
_proto.getDPR = function getDPR() {
|
|
3056
|
-
return this.dpr;
|
|
3057
|
-
};
|
|
3058
|
-
_proto.getBoundingClientRect = function getBoundingClientRect() {
|
|
3059
|
-
var _this$$namespace;
|
|
3060
|
-
return (_this$$namespace = this.$namespace) === null || _this$$namespace === void 0 ? void 0 : _this$$namespace.getBoundingClientRect();
|
|
3061
|
-
};
|
|
3062
|
-
_proto.destroy = function destroy() {
|
|
3063
|
-
// destroy context
|
|
3064
|
-
if (this.$container && this.$namespace && this.$namespace.parentNode) {
|
|
3065
|
-
this.$container.removeChild(this.$namespace);
|
|
3066
|
-
}
|
|
3067
|
-
};
|
|
3068
|
-
_proto.resize = function resize(width, height) {
|
|
3069
|
-
// SVG should ignore DPR
|
|
3070
|
-
if (this.$namespace) {
|
|
3071
|
-
this.$namespace.setAttribute('width', "" + width);
|
|
3072
|
-
this.$namespace.setAttribute('height', "" + height);
|
|
3073
|
-
}
|
|
3074
|
-
};
|
|
3075
|
-
_proto.applyCursorStyle = function applyCursorStyle(cursor) {
|
|
3076
|
-
if (this.$container) {
|
|
3077
|
-
this.$container.style.cursor = cursor;
|
|
3078
|
-
}
|
|
3079
|
-
};
|
|
3080
|
-
_proto.generateCSSText = function generateCSSText(animationName, selector, keyframes, timing, prefixes) {
|
|
3081
|
-
if (prefixes === void 0) {
|
|
3082
|
-
prefixes = {};
|
|
3083
|
-
}
|
|
3084
|
-
var duration = timing.duration,
|
|
3085
|
-
easing = timing.easing,
|
|
3086
|
-
delay = timing.delay,
|
|
3087
|
-
direction = timing.direction,
|
|
3088
|
-
iterations = timing.iterations,
|
|
3089
|
-
fill = timing.fill;
|
|
3090
|
-
return "@keyframes " + animationName + "{" + keyframes.map(function (keyframe) {
|
|
3091
|
-
var offset = keyframe.offset,
|
|
3092
|
-
composite = keyframe.composite,
|
|
3093
|
-
computedOffset = keyframe.computedOffset,
|
|
3094
|
-
easing = keyframe.easing,
|
|
3095
|
-
rest = _objectWithoutPropertiesLoose(keyframe, _excluded);
|
|
3096
|
-
var rules = Object.keys(rest).map(function (attributeName) {
|
|
3097
|
-
return attributeName + ":" + (prefixes[attributeName] || '') + rest[attributeName] + ";";
|
|
3098
|
-
}).join('');
|
|
3099
|
-
return computedOffset * 100 + "%{" + rules + "}";
|
|
3100
|
-
}).join('') + "}" + (selector + " {animation: " + animationName + " " + duration + "ms " + easing + " " + delay + "ms " + (iterations === Infinity ? 'infinite' : iterations) + " " + direction + " " + fill + ";}");
|
|
3101
|
-
};
|
|
3102
|
-
_proto.toDataURL = /*#__PURE__*/function () {
|
|
3103
|
-
var _toDataURL = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(options) {
|
|
3104
|
-
var _this = this;
|
|
3105
|
-
var cloneNode, doc, animationCounter, $style, svgDocType, svgDoc;
|
|
3106
|
-
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
3107
|
-
while (1) switch (_context.prev = _context.next) {
|
|
3108
|
-
case 0:
|
|
3109
|
-
cloneNode = this.$namespace.cloneNode(true);
|
|
3110
|
-
doc = this.canvasConfig.document;
|
|
3111
|
-
animationCounter = 0;
|
|
3112
|
-
$style = null;
|
|
3113
|
-
this.context.renderingContext.root.forEach(function (object) {
|
|
3114
|
-
var animations = object.getAnimations();
|
|
3115
|
-
if (animations.length) {
|
|
3116
|
-
if (!$style) {
|
|
3117
|
-
// export animations to <style>, using CSS Transformation
|
|
3118
|
-
$style = (doc || document).createElement('style');
|
|
3119
|
-
cloneNode.appendChild($style);
|
|
3120
|
-
}
|
|
3121
|
-
// @ts-ignore
|
|
3122
|
-
var svgElement = object.elementSVG;
|
|
3123
|
-
var selfSelector = "#" + svgElement.$el.id;
|
|
3124
|
-
var groupSelector = "#" + svgElement.$groupEl.id;
|
|
3125
|
-
var selfCssText = '';
|
|
3126
|
-
var groupCssText = '';
|
|
3127
|
-
animations.forEach(function (animation) {
|
|
3128
|
-
var keyframes = animation.effect.getKeyframes();
|
|
3129
|
-
// split attributes into self and group
|
|
3130
|
-
if (keyframes.length) {
|
|
3131
|
-
var selfAttributes = [];
|
|
3132
|
-
var groupAttributes = [];
|
|
3133
|
-
var _keyframes$ = keyframes[0],
|
|
3134
|
-
offset = _keyframes$.offset,
|
|
3135
|
-
composite = _keyframes$.composite,
|
|
3136
|
-
computedOffset = _keyframes$.computedOffset,
|
|
3137
|
-
easing = _keyframes$.easing,
|
|
3138
|
-
transformOrigin = _keyframes$.transformOrigin,
|
|
3139
|
-
rest = _objectWithoutPropertiesLoose(_keyframes$, _excluded2);
|
|
3140
|
-
Object.keys(rest).forEach(function (attributeName) {
|
|
3141
|
-
var _propertyMetadataCach;
|
|
3142
|
-
if (attributeName === 'transform') {
|
|
3143
|
-
groupAttributes.push(attributeName);
|
|
3144
|
-
}
|
|
3145
|
-
var inherited = !!((_propertyMetadataCach = gLite.propertyMetadataCache[attributeName]) === null || _propertyMetadataCach === void 0 ? void 0 : _propertyMetadataCach.inh);
|
|
3146
|
-
if (inherited) {
|
|
3147
|
-
groupAttributes.push(attributeName);
|
|
3148
|
-
} else if (attributeName !== 'transform') {
|
|
3149
|
-
selfAttributes.push(attributeName);
|
|
3150
|
-
}
|
|
3151
|
-
});
|
|
3152
|
-
if (groupAttributes.length) {
|
|
3153
|
-
var keyframesWithGroup = keyframes.map(function (keyframe) {
|
|
3154
|
-
var offset = keyframe.offset,
|
|
3155
|
-
composite = keyframe.composite,
|
|
3156
|
-
computedOffset = keyframe.computedOffset,
|
|
3157
|
-
easing = keyframe.easing,
|
|
3158
|
-
transformOrigin = keyframe.transformOrigin,
|
|
3159
|
-
rest = _objectWithoutPropertiesLoose(keyframe, _excluded3);
|
|
3160
|
-
var ret = {
|
|
3161
|
-
offset: offset,
|
|
3162
|
-
composite: composite,
|
|
3163
|
-
computedOffset: computedOffset,
|
|
3164
|
-
easing: easing
|
|
3165
|
-
};
|
|
3166
|
-
Object.keys(rest).forEach(function (attributeName) {
|
|
3167
|
-
if (groupAttributes.includes(attributeName)) {
|
|
3168
|
-
ret[attributeName] = keyframe[attributeName];
|
|
3169
|
-
}
|
|
3170
|
-
});
|
|
3171
|
-
return ret;
|
|
3172
|
-
});
|
|
3173
|
-
groupCssText += _this.generateCSSText("a" + animationCounter++, groupSelector, keyframesWithGroup, animation.effect.getComputedTiming(), {
|
|
3174
|
-
transform: svgElement.$groupEl.getAttribute('transform')
|
|
3175
|
-
});
|
|
3176
|
-
}
|
|
3177
|
-
if (selfAttributes.length) {
|
|
3178
|
-
var keyframesWithSelf = keyframes.map(function (keyframe) {
|
|
3179
|
-
var offset = keyframe.offset,
|
|
3180
|
-
composite = keyframe.composite,
|
|
3181
|
-
computedOffset = keyframe.computedOffset,
|
|
3182
|
-
easing = keyframe.easing,
|
|
3183
|
-
transformOrigin = keyframe.transformOrigin,
|
|
3184
|
-
rest = _objectWithoutPropertiesLoose(keyframe, _excluded4);
|
|
3185
|
-
var ret = {
|
|
3186
|
-
offset: offset,
|
|
3187
|
-
composite: composite,
|
|
3188
|
-
computedOffset: computedOffset,
|
|
3189
|
-
easing: easing
|
|
3190
|
-
};
|
|
3191
|
-
Object.keys(rest).forEach(function (attributeName) {
|
|
3192
|
-
if (selfAttributes.includes(attributeName)) {
|
|
3193
|
-
ret[attributeName] = keyframe[attributeName];
|
|
3194
|
-
}
|
|
3195
|
-
});
|
|
3196
|
-
return ret;
|
|
3197
|
-
});
|
|
3198
|
-
selfCssText += _this.generateCSSText("a" + animationCounter++, selfSelector, keyframesWithSelf, animation.effect.getComputedTiming());
|
|
3199
|
-
}
|
|
3200
|
-
}
|
|
3201
|
-
});
|
|
3202
|
-
$style.textContent += selfCssText + groupCssText;
|
|
3203
|
-
}
|
|
3204
|
-
});
|
|
3205
|
-
svgDocType = document.implementation.createDocumentType('svg', '-//W3C//DTD SVG 1.1//EN', 'http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd');
|
|
3206
|
-
svgDoc = document.implementation.createDocument('http://www.w3.org/2000/svg', 'svg', svgDocType);
|
|
3207
|
-
svgDoc.replaceChild(cloneNode, svgDoc.documentElement);
|
|
3208
|
-
return _context.abrupt("return", "data:image/svg+xml;charset=utf8," + encodeURIComponent(new XMLSerializer().serializeToString(svgDoc)));
|
|
3209
|
-
case 10:
|
|
3210
|
-
case "end":
|
|
3211
|
-
return _context.stop();
|
|
3212
|
-
}
|
|
3213
|
-
}, _callee, this);
|
|
3214
|
-
}));
|
|
3215
|
-
function toDataURL(_x) {
|
|
3216
|
-
return _toDataURL.apply(this, arguments);
|
|
3217
|
-
}
|
|
3218
|
-
return toDataURL;
|
|
3219
|
-
}();
|
|
3220
|
-
return SVGContextService;
|
|
3221
|
-
}();
|
|
3222
|
-
|
|
3223
|
-
var ContextRegisterPlugin = /*#__PURE__*/function (_AbstractRendererPlug) {
|
|
3224
|
-
_inheritsLoose(ContextRegisterPlugin, _AbstractRendererPlug);
|
|
3225
|
-
function ContextRegisterPlugin() {
|
|
3226
|
-
var _this;
|
|
3227
|
-
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
3228
|
-
args[_key] = arguments[_key];
|
|
3229
|
-
}
|
|
3230
|
-
_this = _AbstractRendererPlug.call.apply(_AbstractRendererPlug, [this].concat(args)) || this;
|
|
3231
|
-
_this.name = 'svg-context-register';
|
|
3232
|
-
return _this;
|
|
3233
|
-
}
|
|
3234
|
-
var _proto = ContextRegisterPlugin.prototype;
|
|
3235
|
-
_proto.init = function init() {
|
|
3236
|
-
// @ts-ignore
|
|
3237
|
-
this.context.ContextService = SVGContextService;
|
|
3238
|
-
};
|
|
3239
|
-
_proto.destroy = function destroy() {
|
|
3240
|
-
delete this.context.ContextService;
|
|
3241
|
-
};
|
|
3242
|
-
return ContextRegisterPlugin;
|
|
3243
|
-
}(gLite.AbstractRendererPlugin);
|
|
3244
|
-
|
|
3245
|
-
var Renderer = /*#__PURE__*/function (_AbstractRenderer) {
|
|
3246
|
-
_inheritsLoose(Renderer, _AbstractRenderer);
|
|
3247
|
-
function Renderer(config) {
|
|
3248
|
-
var _this;
|
|
3249
|
-
if (config === void 0) {
|
|
3250
|
-
config = {};
|
|
3251
|
-
}
|
|
3252
|
-
_this = _AbstractRenderer.call(this, config) || this;
|
|
3253
|
-
_this.registerPlugin(new ContextRegisterPlugin());
|
|
3254
|
-
_this.registerPlugin(new Plugin$2({
|
|
3255
|
-
outputSVGElementId: config.outputSVGElementId
|
|
3256
|
-
}));
|
|
3257
|
-
_this.registerPlugin(new Plugin());
|
|
3258
|
-
_this.registerPlugin(new Plugin$1());
|
|
3259
|
-
return _this;
|
|
3260
|
-
}
|
|
3261
|
-
return Renderer;
|
|
3262
|
-
}(gLite.AbstractRenderer);
|
|
3263
|
-
|
|
3264
|
-
exports.DomInteraction = index_esm;
|
|
3265
|
-
exports.Renderer = Renderer;
|
|
3266
|
-
exports.SVGPicker = index_esm$1;
|
|
3267
|
-
exports.SVGRenderer = index_esm$2;
|
|
3268
|
-
|
|
3269
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
3270
|
-
|
|
3271
|
-
})));
|