@antv/g-canvas 1.9.48 → 1.10.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/index.umd.js DELETED
@@ -1,4776 +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.Canvas2D = {}), 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
-
351
- /**
352
- * Common utilities
353
- * @module glMatrix
354
- */
355
- var ARRAY_TYPE = typeof Float32Array !== 'undefined' ? Float32Array : Array;
356
- if (!Math.hypot) Math.hypot = function () {
357
- var y = 0,
358
- i = arguments.length;
359
-
360
- while (i--) {
361
- y += arguments[i] * arguments[i];
362
- }
363
-
364
- return Math.sqrt(y);
365
- };
366
-
367
- /**
368
- * 4x4 Matrix<br>Format: column-major, when typed out it looks like row-major<br>The matrices are being post multiplied.
369
- * @module mat4
370
- */
371
-
372
- /**
373
- * Creates a new identity mat4
374
- *
375
- * @returns {mat4} a new 4x4 matrix
376
- */
377
-
378
- function create() {
379
- var out = new ARRAY_TYPE(16);
380
-
381
- if (ARRAY_TYPE != Float32Array) {
382
- out[1] = 0;
383
- out[2] = 0;
384
- out[3] = 0;
385
- out[4] = 0;
386
- out[6] = 0;
387
- out[7] = 0;
388
- out[8] = 0;
389
- out[9] = 0;
390
- out[11] = 0;
391
- out[12] = 0;
392
- out[13] = 0;
393
- out[14] = 0;
394
- }
395
-
396
- out[0] = 1;
397
- out[5] = 1;
398
- out[10] = 1;
399
- out[15] = 1;
400
- return out;
401
- }
402
- /**
403
- * Copy the values from one mat4 to another
404
- *
405
- * @param {mat4} out the receiving matrix
406
- * @param {ReadonlyMat4} a the source matrix
407
- * @returns {mat4} out
408
- */
409
-
410
- function copy(out, a) {
411
- out[0] = a[0];
412
- out[1] = a[1];
413
- out[2] = a[2];
414
- out[3] = a[3];
415
- out[4] = a[4];
416
- out[5] = a[5];
417
- out[6] = a[6];
418
- out[7] = a[7];
419
- out[8] = a[8];
420
- out[9] = a[9];
421
- out[10] = a[10];
422
- out[11] = a[11];
423
- out[12] = a[12];
424
- out[13] = a[13];
425
- out[14] = a[14];
426
- out[15] = a[15];
427
- return out;
428
- }
429
- /**
430
- * Inverts a mat4
431
- *
432
- * @param {mat4} out the receiving matrix
433
- * @param {ReadonlyMat4} a the source matrix
434
- * @returns {mat4} out
435
- */
436
-
437
- function invert(out, a) {
438
- var a00 = a[0],
439
- a01 = a[1],
440
- a02 = a[2],
441
- a03 = a[3];
442
- var a10 = a[4],
443
- a11 = a[5],
444
- a12 = a[6],
445
- a13 = a[7];
446
- var a20 = a[8],
447
- a21 = a[9],
448
- a22 = a[10],
449
- a23 = a[11];
450
- var a30 = a[12],
451
- a31 = a[13],
452
- a32 = a[14],
453
- a33 = a[15];
454
- var b00 = a00 * a11 - a01 * a10;
455
- var b01 = a00 * a12 - a02 * a10;
456
- var b02 = a00 * a13 - a03 * a10;
457
- var b03 = a01 * a12 - a02 * a11;
458
- var b04 = a01 * a13 - a03 * a11;
459
- var b05 = a02 * a13 - a03 * a12;
460
- var b06 = a20 * a31 - a21 * a30;
461
- var b07 = a20 * a32 - a22 * a30;
462
- var b08 = a20 * a33 - a23 * a30;
463
- var b09 = a21 * a32 - a22 * a31;
464
- var b10 = a21 * a33 - a23 * a31;
465
- var b11 = a22 * a33 - a23 * a32; // Calculate the determinant
466
-
467
- var det = b00 * b11 - b01 * b10 + b02 * b09 + b03 * b08 - b04 * b07 + b05 * b06;
468
-
469
- if (!det) {
470
- return null;
471
- }
472
-
473
- det = 1.0 / det;
474
- out[0] = (a11 * b11 - a12 * b10 + a13 * b09) * det;
475
- out[1] = (a02 * b10 - a01 * b11 - a03 * b09) * det;
476
- out[2] = (a31 * b05 - a32 * b04 + a33 * b03) * det;
477
- out[3] = (a22 * b04 - a21 * b05 - a23 * b03) * det;
478
- out[4] = (a12 * b08 - a10 * b11 - a13 * b07) * det;
479
- out[5] = (a00 * b11 - a02 * b08 + a03 * b07) * det;
480
- out[6] = (a32 * b02 - a30 * b05 - a33 * b01) * det;
481
- out[7] = (a20 * b05 - a22 * b02 + a23 * b01) * det;
482
- out[8] = (a10 * b10 - a11 * b08 + a13 * b06) * det;
483
- out[9] = (a01 * b08 - a00 * b10 - a03 * b06) * det;
484
- out[10] = (a30 * b04 - a31 * b02 + a33 * b00) * det;
485
- out[11] = (a21 * b02 - a20 * b04 - a23 * b00) * det;
486
- out[12] = (a11 * b07 - a10 * b09 - a12 * b06) * det;
487
- out[13] = (a00 * b09 - a01 * b07 + a02 * b06) * det;
488
- out[14] = (a31 * b01 - a30 * b03 - a32 * b00) * det;
489
- out[15] = (a20 * b03 - a21 * b01 + a22 * b00) * det;
490
- return out;
491
- }
492
- /**
493
- * Multiplies two mat4s
494
- *
495
- * @param {mat4} out the receiving matrix
496
- * @param {ReadonlyMat4} a the first operand
497
- * @param {ReadonlyMat4} b the second operand
498
- * @returns {mat4} out
499
- */
500
-
501
- function multiply(out, a, b) {
502
- var a00 = a[0],
503
- a01 = a[1],
504
- a02 = a[2],
505
- a03 = a[3];
506
- var a10 = a[4],
507
- a11 = a[5],
508
- a12 = a[6],
509
- a13 = a[7];
510
- var a20 = a[8],
511
- a21 = a[9],
512
- a22 = a[10],
513
- a23 = a[11];
514
- var a30 = a[12],
515
- a31 = a[13],
516
- a32 = a[14],
517
- a33 = a[15]; // Cache only the current line of the second matrix
518
-
519
- var b0 = b[0],
520
- b1 = b[1],
521
- b2 = b[2],
522
- b3 = b[3];
523
- out[0] = b0 * a00 + b1 * a10 + b2 * a20 + b3 * a30;
524
- out[1] = b0 * a01 + b1 * a11 + b2 * a21 + b3 * a31;
525
- out[2] = b0 * a02 + b1 * a12 + b2 * a22 + b3 * a32;
526
- out[3] = b0 * a03 + b1 * a13 + b2 * a23 + b3 * a33;
527
- b0 = b[4];
528
- b1 = b[5];
529
- b2 = b[6];
530
- b3 = b[7];
531
- out[4] = b0 * a00 + b1 * a10 + b2 * a20 + b3 * a30;
532
- out[5] = b0 * a01 + b1 * a11 + b2 * a21 + b3 * a31;
533
- out[6] = b0 * a02 + b1 * a12 + b2 * a22 + b3 * a32;
534
- out[7] = b0 * a03 + b1 * a13 + b2 * a23 + b3 * a33;
535
- b0 = b[8];
536
- b1 = b[9];
537
- b2 = b[10];
538
- b3 = b[11];
539
- out[8] = b0 * a00 + b1 * a10 + b2 * a20 + b3 * a30;
540
- out[9] = b0 * a01 + b1 * a11 + b2 * a21 + b3 * a31;
541
- out[10] = b0 * a02 + b1 * a12 + b2 * a22 + b3 * a32;
542
- out[11] = b0 * a03 + b1 * a13 + b2 * a23 + b3 * a33;
543
- b0 = b[12];
544
- b1 = b[13];
545
- b2 = b[14];
546
- b3 = b[15];
547
- out[12] = b0 * a00 + b1 * a10 + b2 * a20 + b3 * a30;
548
- out[13] = b0 * a01 + b1 * a11 + b2 * a21 + b3 * a31;
549
- out[14] = b0 * a02 + b1 * a12 + b2 * a22 + b3 * a32;
550
- out[15] = b0 * a03 + b1 * a13 + b2 * a23 + b3 * a33;
551
- return out;
552
- }
553
- /**
554
- * Translate a mat4 by the given vector
555
- *
556
- * @param {mat4} out the receiving matrix
557
- * @param {ReadonlyMat4} a the matrix to translate
558
- * @param {ReadonlyVec3} v vector to translate by
559
- * @returns {mat4} out
560
- */
561
-
562
- function translate(out, a, v) {
563
- var x = v[0],
564
- y = v[1],
565
- z = v[2];
566
- var a00, a01, a02, a03;
567
- var a10, a11, a12, a13;
568
- var a20, a21, a22, a23;
569
-
570
- if (a === out) {
571
- out[12] = a[0] * x + a[4] * y + a[8] * z + a[12];
572
- out[13] = a[1] * x + a[5] * y + a[9] * z + a[13];
573
- out[14] = a[2] * x + a[6] * y + a[10] * z + a[14];
574
- out[15] = a[3] * x + a[7] * y + a[11] * z + a[15];
575
- } else {
576
- a00 = a[0];
577
- a01 = a[1];
578
- a02 = a[2];
579
- a03 = a[3];
580
- a10 = a[4];
581
- a11 = a[5];
582
- a12 = a[6];
583
- a13 = a[7];
584
- a20 = a[8];
585
- a21 = a[9];
586
- a22 = a[10];
587
- a23 = a[11];
588
- out[0] = a00;
589
- out[1] = a01;
590
- out[2] = a02;
591
- out[3] = a03;
592
- out[4] = a10;
593
- out[5] = a11;
594
- out[6] = a12;
595
- out[7] = a13;
596
- out[8] = a20;
597
- out[9] = a21;
598
- out[10] = a22;
599
- out[11] = a23;
600
- out[12] = a00 * x + a10 * y + a20 * z + a[12];
601
- out[13] = a01 * x + a11 * y + a21 * z + a[13];
602
- out[14] = a02 * x + a12 * y + a22 * z + a[14];
603
- out[15] = a03 * x + a13 * y + a23 * z + a[15];
604
- }
605
-
606
- return out;
607
- }
608
- /**
609
- * Creates a matrix from a vector scaling
610
- * This is equivalent to (but much faster than):
611
- *
612
- * mat4.identity(dest);
613
- * mat4.scale(dest, dest, vec);
614
- *
615
- * @param {mat4} out mat4 receiving operation result
616
- * @param {ReadonlyVec3} v Scaling vector
617
- * @returns {mat4} out
618
- */
619
-
620
- function fromScaling(out, v) {
621
- out[0] = v[0];
622
- out[1] = 0;
623
- out[2] = 0;
624
- out[3] = 0;
625
- out[4] = 0;
626
- out[5] = v[1];
627
- out[6] = 0;
628
- out[7] = 0;
629
- out[8] = 0;
630
- out[9] = 0;
631
- out[10] = v[2];
632
- out[11] = 0;
633
- out[12] = 0;
634
- out[13] = 0;
635
- out[14] = 0;
636
- out[15] = 1;
637
- return out;
638
- }
639
-
640
- /**
641
- * 3 Dimensional Vector
642
- * @module vec3
643
- */
644
-
645
- /**
646
- * Creates a new, empty vec3
647
- *
648
- * @returns {vec3} a new 3D vector
649
- */
650
-
651
- function create$1() {
652
- var out = new ARRAY_TYPE(3);
653
-
654
- if (ARRAY_TYPE != Float32Array) {
655
- out[0] = 0;
656
- out[1] = 0;
657
- out[2] = 0;
658
- }
659
-
660
- return out;
661
- }
662
- /**
663
- * Set the components of a vec3 to the given values
664
- *
665
- * @param {vec3} out the receiving vector
666
- * @param {Number} x X component
667
- * @param {Number} y Y component
668
- * @param {Number} z Z component
669
- * @returns {vec3} out
670
- */
671
-
672
- function set(out, x, y, z) {
673
- out[0] = x;
674
- out[1] = y;
675
- out[2] = z;
676
- return out;
677
- }
678
- /**
679
- * Transforms the vec3 with a mat4.
680
- * 4th vector component is implicitly '1'
681
- *
682
- * @param {vec3} out the receiving vector
683
- * @param {ReadonlyVec3} a the vector to transform
684
- * @param {ReadonlyMat4} m matrix to transform with
685
- * @returns {vec3} out
686
- */
687
-
688
- function transformMat4(out, a, m) {
689
- var x = a[0],
690
- y = a[1],
691
- z = a[2];
692
- var w = m[3] * x + m[7] * y + m[11] * z + m[15];
693
- w = w || 1.0;
694
- out[0] = (m[0] * x + m[4] * y + m[8] * z + m[12]) / w;
695
- out[1] = (m[1] * x + m[5] * y + m[9] * z + m[13]) / w;
696
- out[2] = (m[2] * x + m[6] * y + m[10] * z + m[14]) / w;
697
- return out;
698
- }
699
- /**
700
- * Perform some operation over an array of vec3s.
701
- *
702
- * @param {Array} a the array of vectors to iterate over
703
- * @param {Number} stride Number of elements between the start of each vec3. If 0 assumes tightly packed
704
- * @param {Number} offset Number of elements to skip at the beginning of the array
705
- * @param {Number} count Number of vec3s to iterate over. If 0 iterates over entire array
706
- * @param {Function} fn Function to call for each vector in the array
707
- * @param {Object} [arg] additional argument to pass to fn
708
- * @returns {Array} a
709
- * @function
710
- */
711
-
712
- var forEach = function () {
713
- var vec = create$1();
714
- return function (a, stride, offset, count, fn, arg) {
715
- var i, l;
716
-
717
- if (!stride) {
718
- stride = 3;
719
- }
720
-
721
- if (!offset) {
722
- offset = 0;
723
- }
724
-
725
- if (count) {
726
- l = Math.min(count * stride + offset, a.length);
727
- } else {
728
- l = a.length;
729
- }
730
-
731
- for (i = offset; i < l; i += stride) {
732
- vec[0] = a[i];
733
- vec[1] = a[i + 1];
734
- vec[2] = a[i + 2];
735
- fn(vec, vec, arg);
736
- a[i] = vec[0];
737
- a[i + 1] = vec[1];
738
- a[i + 2] = vec[2];
739
- }
740
-
741
- return a;
742
- };
743
- }();
744
-
745
- /**
746
- * 2 Dimensional Vector
747
- * @module vec2
748
- */
749
-
750
- /**
751
- * Creates a new, empty vec2
752
- *
753
- * @returns {vec2} a new 2D vector
754
- */
755
-
756
- function create$2() {
757
- var out = new ARRAY_TYPE(2);
758
-
759
- if (ARRAY_TYPE != Float32Array) {
760
- out[0] = 0;
761
- out[1] = 0;
762
- }
763
-
764
- return out;
765
- }
766
- /**
767
- * Normalize a vec2
768
- *
769
- * @param {vec2} out the receiving vector
770
- * @param {ReadonlyVec2} a vector to normalize
771
- * @returns {vec2} out
772
- */
773
-
774
- function normalize(out, a) {
775
- var x = a[0],
776
- y = a[1];
777
- var len = x * x + y * y;
778
-
779
- if (len > 0) {
780
- //TODO: evaluate use of glm_invsqrt here?
781
- len = 1 / Math.sqrt(len);
782
- }
783
-
784
- out[0] = a[0] * len;
785
- out[1] = a[1] * len;
786
- return out;
787
- }
788
- /**
789
- * Calculates the dot product of two vec2's
790
- *
791
- * @param {ReadonlyVec2} a the first operand
792
- * @param {ReadonlyVec2} b the second operand
793
- * @returns {Number} dot product of a and b
794
- */
795
-
796
- function dot(a, b) {
797
- return a[0] * b[0] + a[1] * b[1];
798
- }
799
- /**
800
- * Returns whether or not the vectors exactly have the same elements in the same position (when compared with ===)
801
- *
802
- * @param {ReadonlyVec2} a The first vector.
803
- * @param {ReadonlyVec2} b The second vector.
804
- * @returns {Boolean} True if the vectors are equal, false otherwise.
805
- */
806
-
807
- function exactEquals(a, b) {
808
- return a[0] === b[0] && a[1] === b[1];
809
- }
810
- /**
811
- * Perform some operation over an array of vec2s.
812
- *
813
- * @param {Array} a the array of vectors to iterate over
814
- * @param {Number} stride Number of elements between the start of each vec2. If 0 assumes tightly packed
815
- * @param {Number} offset Number of elements to skip at the beginning of the array
816
- * @param {Number} count Number of vec2s to iterate over. If 0 iterates over entire array
817
- * @param {Function} fn Function to call for each vector in the array
818
- * @param {Object} [arg] additional argument to pass to fn
819
- * @returns {Array} a
820
- * @function
821
- */
822
-
823
- var forEach$1 = function () {
824
- var vec = create$2();
825
- return function (a, stride, offset, count, fn, arg) {
826
- var i, l;
827
-
828
- if (!stride) {
829
- stride = 2;
830
- }
831
-
832
- if (!offset) {
833
- offset = 0;
834
- }
835
-
836
- if (count) {
837
- l = Math.min(count * stride + offset, a.length);
838
- } else {
839
- l = a.length;
840
- }
841
-
842
- for (i = offset; i < l; i += stride) {
843
- vec[0] = a[i];
844
- vec[1] = a[i + 1];
845
- fn(vec, vec, arg);
846
- a[i] = vec[0];
847
- a[i + 1] = vec[1];
848
- }
849
-
850
- return a;
851
- };
852
- }();
853
-
854
- function rotateVector(x, y, rad) {
855
- var X = x * Math.cos(rad) - y * Math.sin(rad);
856
- var Y = x * Math.sin(rad) + y * Math.cos(rad);
857
- return { x: X, y: Y };
858
- }
859
-
860
- /**
861
- * Converts A (arc-to) segments to C (cubic-bezier-to).
862
- *
863
- * For more information of where this math came from visit:
864
- * http://www.w3.org/TR/SVG11/implnote.html#ArcImplementationNotes
865
- */
866
- function arcToCubic(X1, Y1, RX, RY, angle, LAF, SF, X2, Y2, recursive) {
867
- var x1 = X1;
868
- var y1 = Y1;
869
- var rx = RX;
870
- var ry = RY;
871
- var x2 = X2;
872
- var y2 = Y2;
873
- // for more information of where this Math came from visit:
874
- // http://www.w3.org/TR/SVG11/implnote.html#ArcImplementationNotes
875
- var d120 = (Math.PI * 120) / 180;
876
- var rad = (Math.PI / 180) * (+angle || 0);
877
- /** @type {number[]} */
878
- var res = [];
879
- var xy;
880
- var f1;
881
- var f2;
882
- var cx;
883
- var cy;
884
- if (!recursive) {
885
- xy = rotateVector(x1, y1, -rad);
886
- x1 = xy.x;
887
- y1 = xy.y;
888
- xy = rotateVector(x2, y2, -rad);
889
- x2 = xy.x;
890
- y2 = xy.y;
891
- var x = (x1 - x2) / 2;
892
- var y = (y1 - y2) / 2;
893
- var h = (x * x) / (rx * rx) + (y * y) / (ry * ry);
894
- if (h > 1) {
895
- h = Math.sqrt(h);
896
- rx *= h;
897
- ry *= h;
898
- }
899
- var rx2 = rx * rx;
900
- var ry2 = ry * ry;
901
- var k = (LAF === SF ? -1 : 1) *
902
- Math.sqrt(Math.abs((rx2 * ry2 - rx2 * y * y - ry2 * x * x) / (rx2 * y * y + ry2 * x * x)));
903
- cx = (k * rx * y) / ry + (x1 + x2) / 2;
904
- cy = (k * -ry * x) / rx + (y1 + y2) / 2;
905
- // eslint-disable-next-line no-bitwise -- Impossible to satisfy no-bitwise
906
- f1 = Math.asin(((((y1 - cy) / ry) * Math.pow(10, 9)) >> 0) / Math.pow(10, 9));
907
- // eslint-disable-next-line no-bitwise -- Impossible to satisfy no-bitwise
908
- f2 = Math.asin(((((y2 - cy) / ry) * Math.pow(10, 9)) >> 0) / Math.pow(10, 9));
909
- f1 = x1 < cx ? Math.PI - f1 : f1;
910
- f2 = x2 < cx ? Math.PI - f2 : f2;
911
- if (f1 < 0)
912
- f1 = Math.PI * 2 + f1;
913
- if (f2 < 0)
914
- f2 = Math.PI * 2 + f2;
915
- if (SF && f1 > f2) {
916
- f1 -= Math.PI * 2;
917
- }
918
- if (!SF && f2 > f1) {
919
- f2 -= Math.PI * 2;
920
- }
921
- }
922
- else {
923
- f1 = recursive[0], f2 = recursive[1], cx = recursive[2], cy = recursive[3];
924
- }
925
- var df = f2 - f1;
926
- if (Math.abs(df) > d120) {
927
- var f2old = f2;
928
- var x2old = x2;
929
- var y2old = y2;
930
- f2 = f1 + d120 * (SF && f2 > f1 ? 1 : -1);
931
- x2 = cx + rx * Math.cos(f2);
932
- y2 = cy + ry * Math.sin(f2);
933
- res = arcToCubic(x2, y2, rx, ry, angle, 0, SF, x2old, y2old, [f2, f2old, cx, cy]);
934
- }
935
- df = f2 - f1;
936
- var c1 = Math.cos(f1);
937
- var s1 = Math.sin(f1);
938
- var c2 = Math.cos(f2);
939
- var s2 = Math.sin(f2);
940
- var t = Math.tan(df / 4);
941
- var hx = (4 / 3) * rx * t;
942
- var hy = (4 / 3) * ry * t;
943
- var m1 = [x1, y1];
944
- var m2 = [x1 + hx * s1, y1 - hy * c1];
945
- var m3 = [x2 + hx * s2, y2 - hy * c2];
946
- var m4 = [x2, y2];
947
- m2[0] = 2 * m1[0] - m2[0];
948
- m2[1] = 2 * m1[1] - m2[1];
949
- if (recursive) {
950
- return m2.concat(m3, m4, res);
951
- // return [...m2, ...m3, ...m4, ...res];
952
- }
953
- res = m2.concat(m3, m4, res);
954
- // res = [...m2, ...m3, ...m4, ...res];
955
- var newres = [];
956
- for (var i = 0, ii = res.length; i < ii; i += 1) {
957
- newres[i] = i % 2 ? rotateVector(res[i - 1], res[i], rad).y : rotateVector(res[i], res[i + 1], rad).x;
958
- }
959
- return newres;
960
- }
961
- // const TAU = Math.PI * 2;
962
- // const mapToEllipse = (
963
- // { x, y }: { x: number; y: number },
964
- // rx: number,
965
- // ry: number,
966
- // cosphi: number,
967
- // sinphi: number,
968
- // centerx: number,
969
- // centery: number,
970
- // ) => {
971
- // x *= rx;
972
- // y *= ry;
973
- // const xp = cosphi * x - sinphi * y;
974
- // const yp = sinphi * x + cosphi * y;
975
- // return {
976
- // x: xp + centerx,
977
- // y: yp + centery,
978
- // };
979
- // };
980
- // const approxUnitArc = (ang1: number, ang2: number) => {
981
- // // If 90 degree circular arc, use a constant
982
- // // as derived from http://spencermortensen.com/articles/bezier-circle
983
- // const a =
984
- // ang2 === 1.5707963267948966
985
- // ? 0.551915024494
986
- // : ang2 === -1.5707963267948966
987
- // ? -0.551915024494
988
- // : (4 / 3) * Math.tan(ang2 / 4);
989
- // const x1 = Math.cos(ang1);
990
- // const y1 = Math.sin(ang1);
991
- // const x2 = Math.cos(ang1 + ang2);
992
- // const y2 = Math.sin(ang1 + ang2);
993
- // return [
994
- // {
995
- // x: x1 - y1 * a,
996
- // y: y1 + x1 * a,
997
- // },
998
- // {
999
- // x: x2 + y2 * a,
1000
- // y: y2 - x2 * a,
1001
- // },
1002
- // {
1003
- // x: x2,
1004
- // y: y2,
1005
- // },
1006
- // ];
1007
- // };
1008
- // const vectorAngle = (ux: number, uy: number, vx: number, vy: number) => {
1009
- // const sign = ux * vy - uy * vx < 0 ? -1 : 1;
1010
- // let dot = ux * vx + uy * vy;
1011
- // if (dot > 1) {
1012
- // dot = 1;
1013
- // }
1014
- // if (dot < -1) {
1015
- // dot = -1;
1016
- // }
1017
- // return sign * Math.acos(dot);
1018
- // };
1019
- // const getArcCenter = (
1020
- // px: any,
1021
- // py: any,
1022
- // cx: any,
1023
- // cy: any,
1024
- // rx: number,
1025
- // ry: number,
1026
- // largeArcFlag: number,
1027
- // sweepFlag: number,
1028
- // sinphi: number,
1029
- // cosphi: number,
1030
- // pxp: number,
1031
- // pyp: number,
1032
- // ) => {
1033
- // const rxsq = Math.pow(rx, 2);
1034
- // const rysq = Math.pow(ry, 2);
1035
- // const pxpsq = Math.pow(pxp, 2);
1036
- // const pypsq = Math.pow(pyp, 2);
1037
- // let radicant = rxsq * rysq - rxsq * pypsq - rysq * pxpsq;
1038
- // if (radicant < 0) {
1039
- // radicant = 0;
1040
- // }
1041
- // radicant /= rxsq * pypsq + rysq * pxpsq;
1042
- // radicant = Math.sqrt(radicant) * (largeArcFlag === sweepFlag ? -1 : 1);
1043
- // const centerxp = ((radicant * rx) / ry) * pyp;
1044
- // const centeryp = ((radicant * -ry) / rx) * pxp;
1045
- // const centerx = cosphi * centerxp - sinphi * centeryp + (px + cx) / 2;
1046
- // const centery = sinphi * centerxp + cosphi * centeryp + (py + cy) / 2;
1047
- // const vx1 = (pxp - centerxp) / rx;
1048
- // const vy1 = (pyp - centeryp) / ry;
1049
- // const vx2 = (-pxp - centerxp) / rx;
1050
- // const vy2 = (-pyp - centeryp) / ry;
1051
- // const ang1 = vectorAngle(1, 0, vx1, vy1);
1052
- // let ang2 = vectorAngle(vx1, vy1, vx2, vy2);
1053
- // if (sweepFlag === 0 && ang2 > 0) {
1054
- // ang2 -= TAU;
1055
- // }
1056
- // if (sweepFlag === 1 && ang2 < 0) {
1057
- // ang2 += TAU;
1058
- // }
1059
- // return [centerx, centery, ang1, ang2];
1060
- // };
1061
- // const arcToBezier = ({ px, py, cx, cy, rx, ry, xAxisRotation = 0, largeArcFlag = 0, sweepFlag = 0 }) => {
1062
- // const curves = [];
1063
- // if (rx === 0 || ry === 0) {
1064
- // return [{ x1: 0, y1: 0, x2: 0, y2: 0, x: cx, y: cy }];
1065
- // }
1066
- // const sinphi = Math.sin((xAxisRotation * TAU) / 360);
1067
- // const cosphi = Math.cos((xAxisRotation * TAU) / 360);
1068
- // const pxp = (cosphi * (px - cx)) / 2 + (sinphi * (py - cy)) / 2;
1069
- // const pyp = (-sinphi * (px - cx)) / 2 + (cosphi * (py - cy)) / 2;
1070
- // if (pxp === 0 && pyp === 0) {
1071
- // return [{ x1: 0, y1: 0, x2: 0, y2: 0, x: cx, y: cy }];
1072
- // }
1073
- // rx = Math.abs(rx);
1074
- // ry = Math.abs(ry);
1075
- // const lambda = Math.pow(pxp, 2) / Math.pow(rx, 2) + Math.pow(pyp, 2) / Math.pow(ry, 2);
1076
- // if (lambda > 1) {
1077
- // rx *= Math.sqrt(lambda);
1078
- // ry *= Math.sqrt(lambda);
1079
- // }
1080
- // let [centerx, centery, ang1, ang2] = getArcCenter(
1081
- // px,
1082
- // py,
1083
- // cx,
1084
- // cy,
1085
- // rx,
1086
- // ry,
1087
- // largeArcFlag,
1088
- // sweepFlag,
1089
- // sinphi,
1090
- // cosphi,
1091
- // pxp,
1092
- // pyp,
1093
- // );
1094
- // // If 'ang2' == 90.0000000001, then `ratio` will evaluate to
1095
- // // 1.0000000001. This causes `segments` to be greater than one, which is an
1096
- // // unecessary split, and adds extra points to the bezier curve. To alleviate
1097
- // // this issue, we round to 1.0 when the ratio is close to 1.0.
1098
- // let ratio = Math.abs(ang2) / (TAU / 4);
1099
- // if (Math.abs(1.0 - ratio) < 0.0000001) {
1100
- // ratio = 1.0;
1101
- // }
1102
- // const segments = Math.max(Math.ceil(ratio), 1);
1103
- // ang2 /= segments;
1104
- // for (let i = 0; i < segments; i++) {
1105
- // curves.push(approxUnitArc(ang1, ang2));
1106
- // ang1 += ang2;
1107
- // }
1108
- // return curves.map((curve) => {
1109
- // const { x: x1, y: y1 } = mapToEllipse(curve[0], rx, ry, cosphi, sinphi, centerx, centery);
1110
- // const { x: x2, y: y2 } = mapToEllipse(curve[1], rx, ry, cosphi, sinphi, centerx, centery);
1111
- // const { x, y } = mapToEllipse(curve[2], rx, ry, cosphi, sinphi, centerx, centery);
1112
- // return { x1, y1, x2, y2, x, y };
1113
- // });
1114
- // };
1115
- // export function arcToCubic(
1116
- // x1: number,
1117
- // y1: number,
1118
- // rx: number,
1119
- // ry: number,
1120
- // angle: number,
1121
- // LAF: number,
1122
- // SF: number,
1123
- // x2: number,
1124
- // y2: number,
1125
- // ) {
1126
- // const curves = arcToBezier({
1127
- // px: x1,
1128
- // py: y1,
1129
- // cx: x2,
1130
- // cy: y2,
1131
- // rx,
1132
- // ry,
1133
- // xAxisRotation: angle,
1134
- // largeArcFlag: LAF,
1135
- // sweepFlag: SF,
1136
- // });
1137
- // return curves.reduce((prev, cur) => {
1138
- // const { x1, y1, x2, y2, x, y } = cur;
1139
- // prev.push(x1, y1, x2, y2, x, y);
1140
- // return prev;
1141
- // }, [] as number[]);
1142
- // }
1143
-
1144
- // isFinite,
1145
- var isNil = function (value) {
1146
- /**
1147
- * isNil(null) => true
1148
- * isNil() => true
1149
- */
1150
- return value === null || value === undefined;
1151
- };
1152
-
1153
- var toString = {}.toString;
1154
- var isType = function (value, type) { return toString.call(value) === '[object ' + type + ']'; };
1155
-
1156
- var isString = (function (str) {
1157
- return isType(str, 'String');
1158
- });
1159
-
1160
- var clamp = function (a, min, max) {
1161
- if (a < min) {
1162
- return min;
1163
- }
1164
- else if (a > max) {
1165
- return max;
1166
- }
1167
- return a;
1168
- };
1169
-
1170
- /**
1171
- * 判断是否数字
1172
- * @return {Boolean} 是否数字
1173
- */
1174
- var isNumber = function (value) {
1175
- return isType(value, 'Number');
1176
- };
1177
-
1178
- function _inheritsLoose$1(subClass, superClass) {
1179
- subClass.prototype = Object.create(superClass.prototype);
1180
- subClass.prototype.constructor = subClass;
1181
- _setPrototypeOf$1(subClass, superClass);
1182
- }
1183
- function _setPrototypeOf$1(o, p) {
1184
- _setPrototypeOf$1 = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) {
1185
- o.__proto__ = p;
1186
- return o;
1187
- };
1188
- return _setPrototypeOf$1(o, p);
1189
- }
1190
- function generatePath(context, parsedStyle) {
1191
- var r = parsedStyle.r;
1192
- context.arc(r, r, r, 0, Math.PI * 2, false);
1193
- }
1194
- function generatePath$1(context, parsedStyle) {
1195
- var rxInPixels = parsedStyle.rx,
1196
- ryInPixels = parsedStyle.ry;
1197
- var rx = rxInPixels;
1198
- var ry = ryInPixels;
1199
- // @see https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/ellipse
1200
- if (context.ellipse) {
1201
- context.ellipse(rx, ry, rx, ry, 0, 0, Math.PI * 2, false);
1202
- } else {
1203
- // 如果不支持,则使用圆来绘制,进行变形
1204
- var r = rx > ry ? rx : ry;
1205
- var scaleX = rx > ry ? 1 : rx / ry;
1206
- var scaleY = rx > ry ? ry / rx : 1;
1207
- context.save();
1208
- context.scale(scaleX, scaleY);
1209
- context.arc(0, 0, r, 0, Math.PI * 2);
1210
- }
1211
- }
1212
- function generatePath$2(context, parsedStyle) {
1213
- var x1 = parsedStyle.x1,
1214
- y1 = parsedStyle.y1,
1215
- x2 = parsedStyle.x2,
1216
- y2 = parsedStyle.y2,
1217
- _parsedStyle$defX = parsedStyle.defX,
1218
- defX = _parsedStyle$defX === void 0 ? 0 : _parsedStyle$defX,
1219
- _parsedStyle$defY = parsedStyle.defY,
1220
- defY = _parsedStyle$defY === void 0 ? 0 : _parsedStyle$defY,
1221
- markerStart = parsedStyle.markerStart,
1222
- markerEnd = parsedStyle.markerEnd,
1223
- markerStartOffset = parsedStyle.markerStartOffset,
1224
- markerEndOffset = parsedStyle.markerEndOffset;
1225
- var startOffsetX = 0;
1226
- var startOffsetY = 0;
1227
- var endOffsetX = 0;
1228
- var endOffsetY = 0;
1229
- var rad = 0;
1230
- var x;
1231
- var y;
1232
- if (markerStart && gLite.isDisplayObject(markerStart) && markerStartOffset) {
1233
- x = x2 - x1;
1234
- y = y2 - y1;
1235
- rad = Math.atan2(y, x);
1236
- startOffsetX = Math.cos(rad) * (markerStartOffset || 0);
1237
- startOffsetY = Math.sin(rad) * (markerStartOffset || 0);
1238
- }
1239
- if (markerEnd && gLite.isDisplayObject(markerEnd) && markerEndOffset) {
1240
- x = x1 - x2;
1241
- y = y1 - y2;
1242
- rad = Math.atan2(y, x);
1243
- endOffsetX = Math.cos(rad) * (markerEndOffset || 0);
1244
- endOffsetY = Math.sin(rad) * (markerEndOffset || 0);
1245
- }
1246
- context.moveTo(x1 - defX + startOffsetX, y1 - defY + startOffsetY);
1247
- context.lineTo(x2 - defX + endOffsetX, y2 - defY + endOffsetY);
1248
- }
1249
- function generatePath$3(context, parsedStyle) {
1250
- var _parsedStyle$defX = parsedStyle.defX,
1251
- defX = _parsedStyle$defX === void 0 ? 0 : _parsedStyle$defX,
1252
- _parsedStyle$defY = parsedStyle.defY,
1253
- defY = _parsedStyle$defY === void 0 ? 0 : _parsedStyle$defY,
1254
- markerStart = parsedStyle.markerStart,
1255
- markerEnd = parsedStyle.markerEnd,
1256
- markerStartOffset = parsedStyle.markerStartOffset,
1257
- markerEndOffset = parsedStyle.markerEndOffset;
1258
- var _parsedStyle$path = parsedStyle.path,
1259
- absolutePath = _parsedStyle$path.absolutePath,
1260
- segments = _parsedStyle$path.segments;
1261
- var startOffsetX = 0;
1262
- var startOffsetY = 0;
1263
- var endOffsetX = 0;
1264
- var endOffsetY = 0;
1265
- var rad = 0;
1266
- var x;
1267
- var y;
1268
- if (markerStart && gLite.isDisplayObject(markerStart) && markerStartOffset) {
1269
- var _markerStart$parentNo = markerStart.parentNode.getStartTangent(),
1270
- p1 = _markerStart$parentNo[0],
1271
- p2 = _markerStart$parentNo[1];
1272
- x = p1[0] - p2[0];
1273
- y = p1[1] - p2[1];
1274
- rad = Math.atan2(y, x);
1275
- startOffsetX = Math.cos(rad) * (markerStartOffset || 0);
1276
- startOffsetY = Math.sin(rad) * (markerStartOffset || 0);
1277
- }
1278
- if (markerEnd && gLite.isDisplayObject(markerEnd) && markerEndOffset) {
1279
- var _markerEnd$parentNode = markerEnd.parentNode.getEndTangent(),
1280
- _p = _markerEnd$parentNode[0],
1281
- _p2 = _markerEnd$parentNode[1];
1282
- x = _p[0] - _p2[0];
1283
- y = _p[1] - _p2[1];
1284
- rad = Math.atan2(y, x);
1285
- endOffsetX = Math.cos(rad) * (markerEndOffset || 0);
1286
- endOffsetY = Math.sin(rad) * (markerEndOffset || 0);
1287
- }
1288
- for (var i = 0; i < absolutePath.length; i++) {
1289
- var params = absolutePath[i];
1290
- var command = params[0];
1291
- var nextSegment = absolutePath[i + 1];
1292
- var useStartOffset = i === 0 && (startOffsetX !== 0 || startOffsetY !== 0);
1293
- var useEndOffset = (i === absolutePath.length - 1 || nextSegment && (nextSegment[0] === 'M' || nextSegment[0] === 'Z')) && endOffsetX !== 0 && endOffsetY !== 0;
1294
- switch (command) {
1295
- case 'M':
1296
- // Use start marker offset
1297
- if (useStartOffset) {
1298
- context.moveTo(params[1] - defX + startOffsetX, params[2] - defY + startOffsetY);
1299
- context.lineTo(params[1] - defX, params[2] - defY);
1300
- } else {
1301
- context.moveTo(params[1] - defX, params[2] - defY);
1302
- }
1303
- break;
1304
- case 'L':
1305
- if (useEndOffset) {
1306
- context.lineTo(params[1] - defX + endOffsetX, params[2] - defY + endOffsetY);
1307
- } else {
1308
- context.lineTo(params[1] - defX, params[2] - defY);
1309
- }
1310
- break;
1311
- case 'Q':
1312
- context.quadraticCurveTo(params[1] - defX, params[2] - defY, params[3] - defX, params[4] - defY);
1313
- if (useEndOffset) {
1314
- context.lineTo(params[3] - defX + endOffsetX, params[4] - defY + endOffsetY);
1315
- }
1316
- break;
1317
- case 'C':
1318
- context.bezierCurveTo(params[1] - defX, params[2] - defY, params[3] - defX, params[4] - defY, params[5] - defX, params[6] - defY);
1319
- if (useEndOffset) {
1320
- context.lineTo(params[5] - defX + endOffsetX, params[6] - defY + endOffsetY);
1321
- }
1322
- break;
1323
- case 'A':
1324
- {
1325
- var arcParams = segments[i].arcParams;
1326
- var cx = arcParams.cx,
1327
- cy = arcParams.cy,
1328
- rx = arcParams.rx,
1329
- ry = arcParams.ry,
1330
- startAngle = arcParams.startAngle,
1331
- endAngle = arcParams.endAngle,
1332
- xRotation = arcParams.xRotation,
1333
- sweepFlag = arcParams.sweepFlag;
1334
- // @see https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/ellipse
1335
- if (context.ellipse) {
1336
- context.ellipse(cx - defX, cy - defY, rx, ry, xRotation, startAngle, endAngle, !!(1 - sweepFlag));
1337
- } else {
1338
- // @see https://stackoverflow.com/a/47494351
1339
- var r = rx > ry ? rx : ry;
1340
- var scaleX = rx > ry ? 1 : rx / ry;
1341
- var scaleY = rx > ry ? ry / rx : 1;
1342
- context.translate(cx - defX, cy - defY);
1343
- context.rotate(xRotation);
1344
- context.scale(scaleX, scaleY);
1345
- context.arc(0, 0, r, startAngle, endAngle, !!(1 - sweepFlag));
1346
- context.scale(1 / scaleX, 1 / scaleY);
1347
- context.rotate(-xRotation);
1348
- context.translate(-(cx - defX), -(cy - defY));
1349
- }
1350
- if (useEndOffset) {
1351
- context.lineTo(params[6] - defX + endOffsetX, params[7] - defY + endOffsetY);
1352
- }
1353
- break;
1354
- }
1355
- case 'Z':
1356
- context.closePath();
1357
- break;
1358
- }
1359
- }
1360
- }
1361
- function generatePath$4(context, parsedStyle) {
1362
- var _parsedStyle$defX = parsedStyle.defX,
1363
- defX = _parsedStyle$defX === void 0 ? 0 : _parsedStyle$defX,
1364
- _parsedStyle$defY = parsedStyle.defY,
1365
- defY = _parsedStyle$defY === void 0 ? 0 : _parsedStyle$defY,
1366
- markerStart = parsedStyle.markerStart,
1367
- markerEnd = parsedStyle.markerEnd,
1368
- markerStartOffset = parsedStyle.markerStartOffset,
1369
- markerEndOffset = parsedStyle.markerEndOffset;
1370
- var points = parsedStyle.points.points;
1371
- var length = points.length;
1372
- var x1 = points[0][0] - defX;
1373
- var y1 = points[0][1] - defY;
1374
- var x2 = points[length - 1][0] - defX;
1375
- var y2 = points[length - 1][1] - defY;
1376
- var startOffsetX = 0;
1377
- var startOffsetY = 0;
1378
- var endOffsetX = 0;
1379
- var endOffsetY = 0;
1380
- var rad = 0;
1381
- var x;
1382
- var y;
1383
- if (markerStart && gLite.isDisplayObject(markerStart) && markerStartOffset) {
1384
- x = points[1][0] - points[0][0];
1385
- y = points[1][1] - points[0][1];
1386
- rad = Math.atan2(y, x);
1387
- startOffsetX = Math.cos(rad) * (markerStartOffset || 0);
1388
- startOffsetY = Math.sin(rad) * (markerStartOffset || 0);
1389
- }
1390
- if (markerEnd && gLite.isDisplayObject(markerEnd) && markerEndOffset) {
1391
- x = points[length - 1][0] - points[0][0];
1392
- y = points[length - 1][1] - points[0][1];
1393
- rad = Math.atan2(y, x);
1394
- endOffsetX = Math.cos(rad) * (markerEndOffset || 0);
1395
- endOffsetY = Math.sin(rad) * (markerEndOffset || 0);
1396
- }
1397
- context.moveTo(x1 + (startOffsetX || endOffsetX), y1 + (startOffsetY || endOffsetY));
1398
- for (var i = 1; i < length - 1; i++) {
1399
- var point = points[i];
1400
- context.lineTo(point[0] - defX, point[1] - defY);
1401
- }
1402
- context.lineTo(x2, y2);
1403
- }
1404
- function generatePath$5(context, parsedStyle) {
1405
- var _parsedStyle$defX = parsedStyle.defX,
1406
- defX = _parsedStyle$defX === void 0 ? 0 : _parsedStyle$defX,
1407
- _parsedStyle$defY = parsedStyle.defY,
1408
- defY = _parsedStyle$defY === void 0 ? 0 : _parsedStyle$defY,
1409
- markerStart = parsedStyle.markerStart,
1410
- markerEnd = parsedStyle.markerEnd,
1411
- markerStartOffset = parsedStyle.markerStartOffset,
1412
- markerEndOffset = parsedStyle.markerEndOffset;
1413
- var points = parsedStyle.points.points;
1414
- var length = points.length;
1415
- var x1 = points[0][0] - defX;
1416
- var y1 = points[0][1] - defY;
1417
- var x2 = points[length - 1][0] - defX;
1418
- var y2 = points[length - 1][1] - defY;
1419
- var startOffsetX = 0;
1420
- var startOffsetY = 0;
1421
- var endOffsetX = 0;
1422
- var endOffsetY = 0;
1423
- var rad = 0;
1424
- var x;
1425
- var y;
1426
- if (markerStart && gLite.isDisplayObject(markerStart) && markerStartOffset) {
1427
- x = points[1][0] - points[0][0];
1428
- y = points[1][1] - points[0][1];
1429
- rad = Math.atan2(y, x);
1430
- startOffsetX = Math.cos(rad) * (markerStartOffset || 0);
1431
- startOffsetY = Math.sin(rad) * (markerStartOffset || 0);
1432
- }
1433
- if (markerEnd && gLite.isDisplayObject(markerEnd) && markerEndOffset) {
1434
- x = points[length - 2][0] - points[length - 1][0];
1435
- y = points[length - 2][1] - points[length - 1][1];
1436
- rad = Math.atan2(y, x);
1437
- endOffsetX = Math.cos(rad) * (markerEndOffset || 0);
1438
- endOffsetY = Math.sin(rad) * (markerEndOffset || 0);
1439
- }
1440
- context.moveTo(x1 + startOffsetX, y1 + startOffsetY);
1441
- for (var i = 1; i < length - 1; i++) {
1442
- var point = points[i];
1443
- context.lineTo(point[0] - defX, point[1] - defY);
1444
- }
1445
- context.lineTo(x2 + endOffsetX, y2 + endOffsetY);
1446
- }
1447
- function generatePath$6(context, parsedStyle) {
1448
- var radius = parsedStyle.radius,
1449
- width = parsedStyle.width,
1450
- height = parsedStyle.height;
1451
- var w = width;
1452
- var h = height;
1453
- var hasRadius = radius && radius.some(function (r) {
1454
- return r !== 0;
1455
- });
1456
- if (!hasRadius) {
1457
- // Canvas support negative width/height of rect
1458
- context.rect(0, 0, w, h);
1459
- } else {
1460
- var signX = width > 0 ? 1 : -1;
1461
- var signY = height > 0 ? 1 : -1;
1462
- var sweepFlag = signX + signY === 0;
1463
- var _radius$map = radius.map(function (r) {
1464
- return clamp(r, 0, Math.min(Math.abs(w) / 2, Math.abs(h) / 2));
1465
- }),
1466
- tlr = _radius$map[0],
1467
- trr = _radius$map[1],
1468
- brr = _radius$map[2],
1469
- blr = _radius$map[3];
1470
- context.moveTo(signX * tlr, 0);
1471
- context.lineTo(w - signX * trr, 0);
1472
- if (trr !== 0) {
1473
- context.arc(w - signX * trr, signY * trr, trr, -signY * Math.PI / 2, signX > 0 ? 0 : Math.PI, sweepFlag);
1474
- }
1475
- context.lineTo(w, h - signY * brr);
1476
- if (brr !== 0) {
1477
- context.arc(w - signX * brr, h - signY * brr, brr, signX > 0 ? 0 : Math.PI, signY > 0 ? Math.PI / 2 : 1.5 * Math.PI, sweepFlag);
1478
- }
1479
- context.lineTo(signX * blr, h);
1480
- if (blr !== 0) {
1481
- context.arc(signX * blr, h - signY * blr, blr, signY > 0 ? Math.PI / 2 : -Math.PI / 2, signX > 0 ? Math.PI : 0, sweepFlag);
1482
- }
1483
- context.lineTo(0, signY * tlr);
1484
- if (tlr !== 0) {
1485
- context.arc(signX * tlr, signY * tlr, tlr, signX > 0 ? Math.PI : 0, signY > 0 ? Math.PI * 1.5 : Math.PI / 2, sweepFlag);
1486
- }
1487
- }
1488
- }
1489
- var Plugin = /*#__PURE__*/function (_AbstractRendererPlug) {
1490
- _inheritsLoose$1(Plugin, _AbstractRendererPlug);
1491
- function Plugin() {
1492
- var _this;
1493
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
1494
- args[_key] = arguments[_key];
1495
- }
1496
- _this = _AbstractRendererPlug.call.apply(_AbstractRendererPlug, [this].concat(args)) || this;
1497
- _this.name = 'canvas-path-generator';
1498
- return _this;
1499
- }
1500
- var _proto = Plugin.prototype;
1501
- _proto.init = function init() {
1502
- var _pathGeneratorFactory;
1503
- var pathGeneratorFactory = (_pathGeneratorFactory = {}, _pathGeneratorFactory[gLite.Shape.CIRCLE] = generatePath, _pathGeneratorFactory[gLite.Shape.ELLIPSE] = generatePath$1, _pathGeneratorFactory[gLite.Shape.RECT] = generatePath$6, _pathGeneratorFactory[gLite.Shape.LINE] = generatePath$2, _pathGeneratorFactory[gLite.Shape.POLYLINE] = generatePath$5, _pathGeneratorFactory[gLite.Shape.POLYGON] = generatePath$4, _pathGeneratorFactory[gLite.Shape.PATH] = generatePath$3, _pathGeneratorFactory[gLite.Shape.TEXT] = undefined, _pathGeneratorFactory[gLite.Shape.GROUP] = undefined, _pathGeneratorFactory[gLite.Shape.IMAGE] = undefined, _pathGeneratorFactory[gLite.Shape.HTML] = undefined, _pathGeneratorFactory[gLite.Shape.MESH] = undefined, _pathGeneratorFactory);
1504
- // @ts-ignore
1505
- this.context.pathGeneratorFactory = pathGeneratorFactory;
1506
- };
1507
- _proto.destroy = function destroy() {
1508
- // @ts-ignore
1509
- delete this.context.pathGeneratorFactory;
1510
- };
1511
- return Plugin;
1512
- }(gLite.AbstractRendererPlugin);
1513
-
1514
- var index_esm = /*#__PURE__*/Object.freeze({
1515
- __proto__: null,
1516
- Plugin: Plugin
1517
- });
1518
-
1519
- function _regeneratorRuntime$1() {
1520
- _regeneratorRuntime$1 = function _regeneratorRuntime() {
1521
- return exports;
1522
- };
1523
- var exports = {},
1524
- Op = Object.prototype,
1525
- hasOwn = Op.hasOwnProperty,
1526
- defineProperty = Object.defineProperty || function (obj, key, desc) {
1527
- obj[key] = desc.value;
1528
- },
1529
- $Symbol = "function" == typeof Symbol ? Symbol : {},
1530
- iteratorSymbol = $Symbol.iterator || "@@iterator",
1531
- asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator",
1532
- toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag";
1533
- function define(obj, key, value) {
1534
- return Object.defineProperty(obj, key, {
1535
- value: value,
1536
- enumerable: !0,
1537
- configurable: !0,
1538
- writable: !0
1539
- }), obj[key];
1540
- }
1541
- try {
1542
- define({}, "");
1543
- } catch (err) {
1544
- define = function define(obj, key, value) {
1545
- return obj[key] = value;
1546
- };
1547
- }
1548
- function wrap(innerFn, outerFn, self, tryLocsList) {
1549
- var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator,
1550
- generator = Object.create(protoGenerator.prototype),
1551
- context = new Context(tryLocsList || []);
1552
- return defineProperty(generator, "_invoke", {
1553
- value: makeInvokeMethod(innerFn, self, context)
1554
- }), generator;
1555
- }
1556
- function tryCatch(fn, obj, arg) {
1557
- try {
1558
- return {
1559
- type: "normal",
1560
- arg: fn.call(obj, arg)
1561
- };
1562
- } catch (err) {
1563
- return {
1564
- type: "throw",
1565
- arg: err
1566
- };
1567
- }
1568
- }
1569
- exports.wrap = wrap;
1570
- var ContinueSentinel = {};
1571
- function Generator() {}
1572
- function GeneratorFunction() {}
1573
- function GeneratorFunctionPrototype() {}
1574
- var IteratorPrototype = {};
1575
- define(IteratorPrototype, iteratorSymbol, function () {
1576
- return this;
1577
- });
1578
- var getProto = Object.getPrototypeOf,
1579
- NativeIteratorPrototype = getProto && getProto(getProto(values([])));
1580
- NativeIteratorPrototype && NativeIteratorPrototype !== Op && hasOwn.call(NativeIteratorPrototype, iteratorSymbol) && (IteratorPrototype = NativeIteratorPrototype);
1581
- var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(IteratorPrototype);
1582
- function defineIteratorMethods(prototype) {
1583
- ["next", "throw", "return"].forEach(function (method) {
1584
- define(prototype, method, function (arg) {
1585
- return this._invoke(method, arg);
1586
- });
1587
- });
1588
- }
1589
- function AsyncIterator(generator, PromiseImpl) {
1590
- function invoke(method, arg, resolve, reject) {
1591
- var record = tryCatch(generator[method], generator, arg);
1592
- if ("throw" !== record.type) {
1593
- var result = record.arg,
1594
- value = result.value;
1595
- return value && "object" == typeof value && hasOwn.call(value, "__await") ? PromiseImpl.resolve(value.__await).then(function (value) {
1596
- invoke("next", value, resolve, reject);
1597
- }, function (err) {
1598
- invoke("throw", err, resolve, reject);
1599
- }) : PromiseImpl.resolve(value).then(function (unwrapped) {
1600
- result.value = unwrapped, resolve(result);
1601
- }, function (error) {
1602
- return invoke("throw", error, resolve, reject);
1603
- });
1604
- }
1605
- reject(record.arg);
1606
- }
1607
- var previousPromise;
1608
- defineProperty(this, "_invoke", {
1609
- value: function value(method, arg) {
1610
- function callInvokeWithMethodAndArg() {
1611
- return new PromiseImpl(function (resolve, reject) {
1612
- invoke(method, arg, resolve, reject);
1613
- });
1614
- }
1615
- return previousPromise = previousPromise ? previousPromise.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg();
1616
- }
1617
- });
1618
- }
1619
- function makeInvokeMethod(innerFn, self, context) {
1620
- var state = "suspendedStart";
1621
- return function (method, arg) {
1622
- if ("executing" === state) throw new Error("Generator is already running");
1623
- if ("completed" === state) {
1624
- if ("throw" === method) throw arg;
1625
- return doneResult();
1626
- }
1627
- for (context.method = method, context.arg = arg;;) {
1628
- var delegate = context.delegate;
1629
- if (delegate) {
1630
- var delegateResult = maybeInvokeDelegate(delegate, context);
1631
- if (delegateResult) {
1632
- if (delegateResult === ContinueSentinel) continue;
1633
- return delegateResult;
1634
- }
1635
- }
1636
- if ("next" === context.method) context.sent = context._sent = context.arg;else if ("throw" === context.method) {
1637
- if ("suspendedStart" === state) throw state = "completed", context.arg;
1638
- context.dispatchException(context.arg);
1639
- } else "return" === context.method && context.abrupt("return", context.arg);
1640
- state = "executing";
1641
- var record = tryCatch(innerFn, self, context);
1642
- if ("normal" === record.type) {
1643
- if (state = context.done ? "completed" : "suspendedYield", record.arg === ContinueSentinel) continue;
1644
- return {
1645
- value: record.arg,
1646
- done: context.done
1647
- };
1648
- }
1649
- "throw" === record.type && (state = "completed", context.method = "throw", context.arg = record.arg);
1650
- }
1651
- };
1652
- }
1653
- function maybeInvokeDelegate(delegate, context) {
1654
- var methodName = context.method,
1655
- method = delegate.iterator[methodName];
1656
- 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;
1657
- var record = tryCatch(method, delegate.iterator, context.arg);
1658
- if ("throw" === record.type) return context.method = "throw", context.arg = record.arg, context.delegate = null, ContinueSentinel;
1659
- var info = record.arg;
1660
- 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);
1661
- }
1662
- function pushTryEntry(locs) {
1663
- var entry = {
1664
- tryLoc: locs[0]
1665
- };
1666
- 1 in locs && (entry.catchLoc = locs[1]), 2 in locs && (entry.finallyLoc = locs[2], entry.afterLoc = locs[3]), this.tryEntries.push(entry);
1667
- }
1668
- function resetTryEntry(entry) {
1669
- var record = entry.completion || {};
1670
- record.type = "normal", delete record.arg, entry.completion = record;
1671
- }
1672
- function Context(tryLocsList) {
1673
- this.tryEntries = [{
1674
- tryLoc: "root"
1675
- }], tryLocsList.forEach(pushTryEntry, this), this.reset(!0);
1676
- }
1677
- function values(iterable) {
1678
- if (iterable) {
1679
- var iteratorMethod = iterable[iteratorSymbol];
1680
- if (iteratorMethod) return iteratorMethod.call(iterable);
1681
- if ("function" == typeof iterable.next) return iterable;
1682
- if (!isNaN(iterable.length)) {
1683
- var i = -1,
1684
- next = function next() {
1685
- for (; ++i < iterable.length;) if (hasOwn.call(iterable, i)) return next.value = iterable[i], next.done = !1, next;
1686
- return next.value = undefined, next.done = !0, next;
1687
- };
1688
- return next.next = next;
1689
- }
1690
- }
1691
- return {
1692
- next: doneResult
1693
- };
1694
- }
1695
- function doneResult() {
1696
- return {
1697
- value: undefined,
1698
- done: !0
1699
- };
1700
- }
1701
- return GeneratorFunction.prototype = GeneratorFunctionPrototype, defineProperty(Gp, "constructor", {
1702
- value: GeneratorFunctionPrototype,
1703
- configurable: !0
1704
- }), defineProperty(GeneratorFunctionPrototype, "constructor", {
1705
- value: GeneratorFunction,
1706
- configurable: !0
1707
- }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, toStringTagSymbol, "GeneratorFunction"), exports.isGeneratorFunction = function (genFun) {
1708
- var ctor = "function" == typeof genFun && genFun.constructor;
1709
- return !!ctor && (ctor === GeneratorFunction || "GeneratorFunction" === (ctor.displayName || ctor.name));
1710
- }, exports.mark = function (genFun) {
1711
- return Object.setPrototypeOf ? Object.setPrototypeOf(genFun, GeneratorFunctionPrototype) : (genFun.__proto__ = GeneratorFunctionPrototype, define(genFun, toStringTagSymbol, "GeneratorFunction")), genFun.prototype = Object.create(Gp), genFun;
1712
- }, exports.awrap = function (arg) {
1713
- return {
1714
- __await: arg
1715
- };
1716
- }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, asyncIteratorSymbol, function () {
1717
- return this;
1718
- }), exports.AsyncIterator = AsyncIterator, exports.async = function (innerFn, outerFn, self, tryLocsList, PromiseImpl) {
1719
- void 0 === PromiseImpl && (PromiseImpl = Promise);
1720
- var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList), PromiseImpl);
1721
- return exports.isGeneratorFunction(outerFn) ? iter : iter.next().then(function (result) {
1722
- return result.done ? result.value : iter.next();
1723
- });
1724
- }, defineIteratorMethods(Gp), define(Gp, toStringTagSymbol, "Generator"), define(Gp, iteratorSymbol, function () {
1725
- return this;
1726
- }), define(Gp, "toString", function () {
1727
- return "[object Generator]";
1728
- }), exports.keys = function (val) {
1729
- var object = Object(val),
1730
- keys = [];
1731
- for (var key in object) keys.push(key);
1732
- return keys.reverse(), function next() {
1733
- for (; keys.length;) {
1734
- var key = keys.pop();
1735
- if (key in object) return next.value = key, next.done = !1, next;
1736
- }
1737
- return next.done = !0, next;
1738
- };
1739
- }, exports.values = values, Context.prototype = {
1740
- constructor: Context,
1741
- reset: function reset(skipTempReset) {
1742
- 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);
1743
- },
1744
- stop: function stop() {
1745
- this.done = !0;
1746
- var rootRecord = this.tryEntries[0].completion;
1747
- if ("throw" === rootRecord.type) throw rootRecord.arg;
1748
- return this.rval;
1749
- },
1750
- dispatchException: function dispatchException(exception) {
1751
- if (this.done) throw exception;
1752
- var context = this;
1753
- function handle(loc, caught) {
1754
- return record.type = "throw", record.arg = exception, context.next = loc, caught && (context.method = "next", context.arg = undefined), !!caught;
1755
- }
1756
- for (var i = this.tryEntries.length - 1; i >= 0; --i) {
1757
- var entry = this.tryEntries[i],
1758
- record = entry.completion;
1759
- if ("root" === entry.tryLoc) return handle("end");
1760
- if (entry.tryLoc <= this.prev) {
1761
- var hasCatch = hasOwn.call(entry, "catchLoc"),
1762
- hasFinally = hasOwn.call(entry, "finallyLoc");
1763
- if (hasCatch && hasFinally) {
1764
- if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0);
1765
- if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc);
1766
- } else if (hasCatch) {
1767
- if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0);
1768
- } else {
1769
- if (!hasFinally) throw new Error("try statement without catch or finally");
1770
- if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc);
1771
- }
1772
- }
1773
- }
1774
- },
1775
- abrupt: function abrupt(type, arg) {
1776
- for (var i = this.tryEntries.length - 1; i >= 0; --i) {
1777
- var entry = this.tryEntries[i];
1778
- if (entry.tryLoc <= this.prev && hasOwn.call(entry, "finallyLoc") && this.prev < entry.finallyLoc) {
1779
- var finallyEntry = entry;
1780
- break;
1781
- }
1782
- }
1783
- finallyEntry && ("break" === type || "continue" === type) && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc && (finallyEntry = null);
1784
- var record = finallyEntry ? finallyEntry.completion : {};
1785
- return record.type = type, record.arg = arg, finallyEntry ? (this.method = "next", this.next = finallyEntry.finallyLoc, ContinueSentinel) : this.complete(record);
1786
- },
1787
- complete: function complete(record, afterLoc) {
1788
- if ("throw" === record.type) throw record.arg;
1789
- 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;
1790
- },
1791
- finish: function finish(finallyLoc) {
1792
- for (var i = this.tryEntries.length - 1; i >= 0; --i) {
1793
- var entry = this.tryEntries[i];
1794
- if (entry.finallyLoc === finallyLoc) return this.complete(entry.completion, entry.afterLoc), resetTryEntry(entry), ContinueSentinel;
1795
- }
1796
- },
1797
- catch: function _catch(tryLoc) {
1798
- for (var i = this.tryEntries.length - 1; i >= 0; --i) {
1799
- var entry = this.tryEntries[i];
1800
- if (entry.tryLoc === tryLoc) {
1801
- var record = entry.completion;
1802
- if ("throw" === record.type) {
1803
- var thrown = record.arg;
1804
- resetTryEntry(entry);
1805
- }
1806
- return thrown;
1807
- }
1808
- }
1809
- throw new Error("illegal catch attempt");
1810
- },
1811
- delegateYield: function delegateYield(iterable, resultName, nextLoc) {
1812
- return this.delegate = {
1813
- iterator: values(iterable),
1814
- resultName: resultName,
1815
- nextLoc: nextLoc
1816
- }, "next" === this.method && (this.arg = undefined), ContinueSentinel;
1817
- }
1818
- }, exports;
1819
- }
1820
- function asyncGeneratorStep$1(gen, resolve, reject, _next, _throw, key, arg) {
1821
- try {
1822
- var info = gen[key](arg);
1823
- var value = info.value;
1824
- } catch (error) {
1825
- reject(error);
1826
- return;
1827
- }
1828
- if (info.done) {
1829
- resolve(value);
1830
- } else {
1831
- Promise.resolve(value).then(_next, _throw);
1832
- }
1833
- }
1834
- function _asyncToGenerator$1(fn) {
1835
- return function () {
1836
- var self = this,
1837
- args = arguments;
1838
- return new Promise(function (resolve, reject) {
1839
- var gen = fn.apply(self, args);
1840
- function _next(value) {
1841
- asyncGeneratorStep$1(gen, resolve, reject, _next, _throw, "next", value);
1842
- }
1843
- function _throw(err) {
1844
- asyncGeneratorStep$1(gen, resolve, reject, _next, _throw, "throw", err);
1845
- }
1846
- _next(undefined);
1847
- });
1848
- };
1849
- }
1850
- function _inheritsLoose$2(subClass, superClass) {
1851
- subClass.prototype = Object.create(superClass.prototype);
1852
- subClass.prototype.constructor = subClass;
1853
- _setPrototypeOf$2(subClass, superClass);
1854
- }
1855
- function _setPrototypeOf$2(o, p) {
1856
- _setPrototypeOf$2 = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) {
1857
- o.__proto__ = p;
1858
- return o;
1859
- };
1860
- return _setPrototypeOf$2(o, p);
1861
- }
1862
- function _unsupportedIterableToArray(o, minLen) {
1863
- if (!o) return;
1864
- if (typeof o === "string") return _arrayLikeToArray(o, minLen);
1865
- var n = Object.prototype.toString.call(o).slice(8, -1);
1866
- if (n === "Object" && o.constructor) n = o.constructor.name;
1867
- if (n === "Map" || n === "Set") return Array.from(o);
1868
- if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
1869
- }
1870
- function _arrayLikeToArray(arr, len) {
1871
- if (len == null || len > arr.length) len = arr.length;
1872
- for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
1873
- return arr2;
1874
- }
1875
- function _createForOfIteratorHelperLoose(o, allowArrayLike) {
1876
- var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"];
1877
- if (it) return (it = it.call(o)).next.bind(it);
1878
- if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") {
1879
- if (it) o = it;
1880
- var i = 0;
1881
- return function () {
1882
- if (i >= o.length) return {
1883
- done: true
1884
- };
1885
- return {
1886
- done: false,
1887
- value: o[i++]
1888
- };
1889
- };
1890
- }
1891
- throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
1892
- }
1893
- var tmpVec3a = create$1();
1894
- var tmpVec3b = create$1();
1895
- var tmpVec3c = create$1();
1896
- var tmpMat4 = create();
1897
- /**
1898
- * pick shape(s) with Mouse/Touch event
1899
- *
1900
- * 1. find AABB with r-tree
1901
- * 2. do math calculation with geometry in an accurate way
1902
- */
1903
- var CanvasPickerPlugin = /*#__PURE__*/function () {
1904
- function CanvasPickerPlugin() {
1905
- var _this = this;
1906
- this.context = void 0;
1907
- this.runtime = void 0;
1908
- this.isHit = function (displayObject, position, worldTransform, isClipPath) {
1909
- // use picker for current shape's type
1910
- var pick = _this.context.pointInPathPickerFactory[displayObject.nodeName];
1911
- if (pick) {
1912
- // invert with world matrix
1913
- var invertWorldMat = invert(tmpMat4, worldTransform);
1914
- // transform client position to local space, do picking in local space
1915
- var localPosition = transformMat4(tmpVec3b, set(tmpVec3c, position[0], position[1], 0), invertWorldMat);
1916
- // account for anchor
1917
- var _displayObject$getGeo = displayObject.getGeometryBounds(),
1918
- halfExtents = _displayObject$getGeo.halfExtents;
1919
- var anchor = displayObject.parsedStyle.anchor;
1920
- localPosition[0] += (anchor && anchor[0] || 0) * halfExtents[0] * 2;
1921
- localPosition[1] += (anchor && anchor[1] || 0) * halfExtents[1] * 2;
1922
- if (pick(displayObject, new gLite.Point(localPosition[0], localPosition[1]), isClipPath, _this.isPointInPath, _this.context, _this.runtime)) {
1923
- return true;
1924
- }
1925
- }
1926
- return false;
1927
- };
1928
- /**
1929
- * use native picking method
1930
- * @see https://developer.mozilla.org/zh-CN/docs/Web/API/CanvasRenderingContext2D/isPointInPath
1931
- */
1932
- this.isPointInPath = function (displayObject, position) {
1933
- var context = _this.runtime.offscreenCanvas.getOrCreateContext(_this.context.config.offscreenCanvas);
1934
- var generatePath = _this.context.pathGeneratorFactory[displayObject.nodeName];
1935
- if (generatePath) {
1936
- context.beginPath();
1937
- generatePath(context, displayObject.parsedStyle);
1938
- context.closePath();
1939
- }
1940
- return context.isPointInPath(position.x, position.y);
1941
- };
1942
- }
1943
- var _proto = CanvasPickerPlugin.prototype;
1944
- _proto.apply = function apply(context, runtime) {
1945
- var _renderingContext$roo,
1946
- _this2 = this;
1947
- var renderingService = context.renderingService,
1948
- renderingContext = context.renderingContext;
1949
- this.context = context;
1950
- this.runtime = runtime;
1951
- var document = (_renderingContext$roo = renderingContext.root) === null || _renderingContext$roo === void 0 ? void 0 : _renderingContext$roo.ownerDocument;
1952
- renderingService.hooks.pick.tapPromise(CanvasPickerPlugin.tag, /*#__PURE__*/function () {
1953
- var _ref = _asyncToGenerator$1( /*#__PURE__*/_regeneratorRuntime$1().mark(function _callee(result) {
1954
- return _regeneratorRuntime$1().wrap(function _callee$(_context) {
1955
- while (1) switch (_context.prev = _context.next) {
1956
- case 0:
1957
- return _context.abrupt("return", _this2.pick(document, result));
1958
- case 1:
1959
- case "end":
1960
- return _context.stop();
1961
- }
1962
- }, _callee);
1963
- }));
1964
- return function (_x) {
1965
- return _ref.apply(this, arguments);
1966
- };
1967
- }());
1968
- renderingService.hooks.pickSync.tap(CanvasPickerPlugin.tag, function (result) {
1969
- return _this2.pick(document, result);
1970
- });
1971
- };
1972
- _proto.pick = function pick(document, result) {
1973
- var topmost = result.topmost,
1974
- _result$position = result.position,
1975
- x = _result$position.x,
1976
- y = _result$position.y;
1977
- // position in world space
1978
- var position = set(tmpVec3a, x, y, 0);
1979
- // query by AABB first with spatial index(r-tree)
1980
- var hitTestList = document.elementsFromBBox(position[0], position[1], position[0], position[1]);
1981
- // test with clip path & origin shape
1982
- // @see https://github.com/antvis/g/issues/1064
1983
- var pickedDisplayObjects = [];
1984
- for (var _iterator = _createForOfIteratorHelperLoose(hitTestList), _step; !(_step = _iterator()).done;) {
1985
- var displayObject = _step.value;
1986
- var worldTransform = displayObject.getWorldTransform();
1987
- var isHitOriginShape = this.isHit(displayObject, position, worldTransform, false);
1988
- if (isHitOriginShape) {
1989
- // should look up in the ancestor node
1990
- var clipped = gLite.findClosestClipPathTarget(displayObject);
1991
- if (clipped) {
1992
- var clipPath = clipped.parsedStyle.clipPath;
1993
- var isHitClipPath = this.isHit(clipPath, position, clipPath.getWorldTransform(), true);
1994
- if (isHitClipPath) {
1995
- if (topmost) {
1996
- result.picked = [displayObject];
1997
- return result;
1998
- } else {
1999
- pickedDisplayObjects.push(displayObject);
2000
- }
2001
- }
2002
- } else {
2003
- if (topmost) {
2004
- result.picked = [displayObject];
2005
- return result;
2006
- } else {
2007
- pickedDisplayObjects.push(displayObject);
2008
- }
2009
- }
2010
- }
2011
- }
2012
- result.picked = pickedDisplayObjects;
2013
- return result;
2014
- };
2015
- return CanvasPickerPlugin;
2016
- }();
2017
- CanvasPickerPlugin.tag = 'CanvasPicker';
2018
-
2019
- /**
2020
- * 两点之间的距离
2021
- * @param {number} x1 起始点 x
2022
- * @param {number} y1 起始点 y
2023
- * @param {number} x2 结束点 x
2024
- * @param {number} y2 结束点 y
2025
- * @return {number} 距离
2026
- */
2027
- function distance(x1, y1, x2, y2) {
2028
- var dx = x1 - x2;
2029
- var dy = y1 - y2;
2030
- return Math.sqrt(dx * dx + dy * dy);
2031
- }
2032
- function isNumberEqual(v1, v2) {
2033
- return Math.abs(v1 - v2) < 0.001;
2034
- }
2035
- function getBBoxByArray(xArr, yArr) {
2036
- var minX = Math.min.apply(Math, xArr);
2037
- var minY = Math.min.apply(Math, yArr);
2038
- var maxX = Math.max.apply(Math, xArr);
2039
- var maxY = Math.max.apply(Math, yArr);
2040
- return {
2041
- x: minX,
2042
- y: minY,
2043
- width: maxX - minX,
2044
- height: maxY - minY
2045
- };
2046
- }
2047
- function piMod(angle) {
2048
- return (angle + Math.PI * 2) % (Math.PI * 2);
2049
- }
2050
- var line = {
2051
- /**
2052
- * 计算线段的包围盒
2053
- * @param {number} x1 起始点 x
2054
- * @param {number} y1 起始点 y
2055
- * @param {number} x2 结束点 x
2056
- * @param {number} y2 结束点 y
2057
- * @return {object} 包围盒对象
2058
- */
2059
- box: function box(x1, y1, x2, y2) {
2060
- return getBBoxByArray([x1, x2], [y1, y2]);
2061
- },
2062
- /**
2063
- * 线段的长度
2064
- * @param {number} x1 起始点 x
2065
- * @param {number} y1 起始点 y
2066
- * @param {number} x2 结束点 x
2067
- * @param {number} y2 结束点 y
2068
- * @return {number} 距离
2069
- */
2070
- length: function length(x1, y1, x2, y2) {
2071
- return distance(x1, y1, x2, y2);
2072
- },
2073
- /**
2074
- * 根据比例获取点
2075
- * @param {number} x1 起始点 x
2076
- * @param {number} y1 起始点 y
2077
- * @param {number} x2 结束点 x
2078
- * @param {number} y2 结束点 y
2079
- * @param {number} t 指定比例
2080
- * @return {object} 包含 x, y 的点
2081
- */
2082
- pointAt: function pointAt(x1, y1, x2, y2, t) {
2083
- return {
2084
- x: (1 - t) * x1 + t * x2,
2085
- y: (1 - t) * y1 + t * y2
2086
- };
2087
- },
2088
- /**
2089
- * 点到线段的距离
2090
- * @param {number} x1 起始点 x
2091
- * @param {number} y1 起始点 y
2092
- * @param {number} x2 结束点 x
2093
- * @param {number} y2 结束点 y
2094
- * @param {number} x 测试点 x
2095
- * @param {number} y 测试点 y
2096
- * @return {number} 距离
2097
- */
2098
- pointDistance: function pointDistance(x1, y1, x2, y2, x, y) {
2099
- // 投影距离 x1, y1 的向量,假设 p, p1, p2 三个点,投影点为 a
2100
- // p1a = p1p.p1p2/|p1p2| * (p1p 的单位向量)
2101
- var cross = (x2 - x1) * (x - x1) + (y2 - y1) * (y - y1);
2102
- if (cross < 0) {
2103
- return distance(x1, y1, x, y);
2104
- }
2105
- var lengthSquare = (x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1);
2106
- if (cross > lengthSquare) {
2107
- return distance(x2, y2, x, y);
2108
- }
2109
- return this.pointToLine(x1, y1, x2, y2, x, y);
2110
- },
2111
- /**
2112
- * 点到直线的距离,而不是点到线段的距离
2113
- * @param {number} x1 起始点 x
2114
- * @param {number} y1 起始点 y
2115
- * @param {number} x2 结束点 x
2116
- * @param {number} y2 结束点 y
2117
- * @param {number} x 测试点 x
2118
- * @param {number} y 测试点 y
2119
- * @return {number} 距离
2120
- */
2121
- pointToLine: function pointToLine(x1, y1, x2, y2, x, y) {
2122
- var d = [x2 - x1, y2 - y1];
2123
- // 如果端点相等,则判定点到点的距离
2124
- if (exactEquals(d, [0, 0])) {
2125
- return Math.sqrt((x - x1) * (x - x1) + (y - y1) * (y - y1));
2126
- }
2127
- var u = [-d[1], d[0]];
2128
- normalize(u, u);
2129
- var a = [x - x1, y - y1];
2130
- return Math.abs(dot(a, u));
2131
- },
2132
- /**
2133
- * 线段的角度
2134
- * @param {number} x1 起始点 x
2135
- * @param {number} y1 起始点 y
2136
- * @param {number} x2 结束点 x
2137
- * @param {number} y2 结束点 y
2138
- * @return {number} 导数
2139
- */
2140
- tangentAngle: function tangentAngle(x1, y1, x2, y2) {
2141
- return Math.atan2(y2 - y1, x2 - x1);
2142
- }
2143
- };
2144
- var EPSILON = 0.0001;
2145
- /**
2146
- * 使用牛顿切割法求最近的点
2147
- * @param {number[]} xArr 点的 x 数组
2148
- * @param {number[]} yArr 点的 y 数组
2149
- * @param {number} x 指定的点 x
2150
- * @param {number} y 指定的点 y
2151
- * @param {Function} tCallback 差值函数
2152
- */
2153
- function nearestPoint(xArr, yArr, x, y, tCallback, length) {
2154
- var t = -1;
2155
- var d = Infinity;
2156
- var v0 = [x, y];
2157
- var segNum = 20;
2158
- if (length && length > 200) {
2159
- segNum = length / 10;
2160
- }
2161
- var increaseRate = 1 / segNum;
2162
- var interval = increaseRate / 10;
2163
- for (var i = 0; i <= segNum; i++) {
2164
- var _t = i * increaseRate;
2165
- var v1 = [tCallback.apply(void 0, xArr.concat([_t])), tCallback.apply(void 0, yArr.concat([_t]))];
2166
- var d1 = distance(v0[0], v0[1], v1[0], v1[1]);
2167
- if (d1 < d) {
2168
- t = _t;
2169
- d = d1;
2170
- }
2171
- }
2172
- // 提前终止
2173
- if (t === 0) {
2174
- return {
2175
- x: xArr[0],
2176
- y: yArr[0]
2177
- };
2178
- }
2179
- if (t === 1) {
2180
- var count = xArr.length;
2181
- return {
2182
- x: xArr[count - 1],
2183
- y: yArr[count - 1]
2184
- };
2185
- }
2186
- d = Infinity;
2187
- for (var _i = 0; _i < 32; _i++) {
2188
- if (interval < EPSILON) {
2189
- break;
2190
- }
2191
- var prev = t - interval;
2192
- var next = t + interval;
2193
- var _v = [tCallback.apply(void 0, xArr.concat([prev])), tCallback.apply(void 0, yArr.concat([prev]))];
2194
- var _d = distance(v0[0], v0[1], _v[0], _v[1]);
2195
- if (prev >= 0 && _d < d) {
2196
- t = prev;
2197
- d = _d;
2198
- } else {
2199
- var v2 = [tCallback.apply(void 0, xArr.concat([next])), tCallback.apply(void 0, yArr.concat([next]))];
2200
- var d2 = distance(v0[0], v0[1], v2[0], v2[1]);
2201
- if (next <= 1 && d2 < d) {
2202
- t = next;
2203
- d = d2;
2204
- } else {
2205
- interval *= 0.5;
2206
- }
2207
- }
2208
- }
2209
- return {
2210
- x: tCallback.apply(void 0, xArr.concat([t])),
2211
- y: tCallback.apply(void 0, yArr.concat([t]))
2212
- };
2213
- }
2214
- // 近似求解 https://community.khronos.org/t/3d-cubic-bezier-segment-length/62363/2
2215
- function snapLength(xArr, yArr) {
2216
- var totalLength = 0;
2217
- var count = xArr.length;
2218
- for (var i = 0; i < count; i++) {
2219
- var x = xArr[i];
2220
- var y = yArr[i];
2221
- var nextX = xArr[(i + 1) % count];
2222
- var nextY = yArr[(i + 1) % count];
2223
- totalLength += distance(x, y, nextX, nextY);
2224
- }
2225
- return totalLength / 2;
2226
- }
2227
-
2228
- // 差值公式
2229
- function quadraticAt(p0, p1, p2, t) {
2230
- var onet = 1 - t;
2231
- return onet * onet * p0 + 2 * t * onet * p1 + t * t * p2;
2232
- }
2233
- // 求极值
2234
- function extrema(p0, p1, p2) {
2235
- var a = p0 + p2 - 2 * p1;
2236
- if (isNumberEqual(a, 0)) {
2237
- return [0.5];
2238
- }
2239
- var rst = (p0 - p1) / a;
2240
- if (rst <= 1 && rst >= 0) {
2241
- return [rst];
2242
- }
2243
- return [];
2244
- }
2245
- function derivativeAt(p0, p1, p2, t) {
2246
- return 2 * (1 - t) * (p1 - p0) + 2 * t * (p2 - p1);
2247
- }
2248
- // 分割贝塞尔曲线
2249
- function divideQuadratic(x1, y1, x2, y2, x3, y3, t) {
2250
- // 划分点
2251
- var xt = quadraticAt(x1, x2, x3, t);
2252
- var yt = quadraticAt(y1, y2, y3, t);
2253
- // 分割的第一条曲线的控制点
2254
- var controlPoint1 = line.pointAt(x1, y1, x2, y2, t);
2255
- // 分割的第二条曲线的控制点
2256
- var controlPoint2 = line.pointAt(x2, y2, x3, y3, t);
2257
- return [[x1, y1, controlPoint1.x, controlPoint1.y, xt, yt], [xt, yt, controlPoint2.x, controlPoint2.y, x3, y3]];
2258
- }
2259
- // 使用迭代法取贝塞尔曲线的长度
2260
- function quadraticLength(x1, y1, x2, y2, x3, y3, iterationCount) {
2261
- if (iterationCount === 0) {
2262
- return (distance(x1, y1, x2, y2) + distance(x2, y2, x3, y3) + distance(x1, y1, x3, y3)) / 2;
2263
- }
2264
- var quadratics = divideQuadratic(x1, y1, x2, y2, x3, y3, 0.5);
2265
- var left = quadratics[0];
2266
- var right = quadratics[1];
2267
- left.push(iterationCount - 1);
2268
- right.push(iterationCount - 1);
2269
- return quadraticLength.apply(void 0, left) + quadraticLength.apply(void 0, right);
2270
- }
2271
- var quadratic = {
2272
- box: function box(x1, y1, x2, y2, x3, y3) {
2273
- var xExtrema = extrema(x1, x2, x3)[0];
2274
- var yExtrema = extrema(y1, y2, y3)[0];
2275
- // 控制点不加入 box 的计算
2276
- var xArr = [x1, x3];
2277
- var yArr = [y1, y3];
2278
- if (xExtrema !== undefined) {
2279
- xArr.push(quadraticAt(x1, x2, x3, xExtrema));
2280
- }
2281
- if (yExtrema !== undefined) {
2282
- yArr.push(quadraticAt(y1, y2, y3, yExtrema));
2283
- }
2284
- return getBBoxByArray(xArr, yArr);
2285
- },
2286
- length: function length(x1, y1, x2, y2, x3, y3) {
2287
- return quadraticLength(x1, y1, x2, y2, x3, y3, 3);
2288
- },
2289
- nearestPoint: function nearestPoint$1(x1, y1, x2, y2, x3, y3, x0, y0) {
2290
- return nearestPoint([x1, x2, x3], [y1, y2, y3], x0, y0, quadraticAt);
2291
- },
2292
- pointDistance: function pointDistance(x1, y1, x2, y2, x3, y3, x0, y0) {
2293
- var point = this.nearestPoint(x1, y1, x2, y2, x3, y3, x0, y0);
2294
- return distance(point.x, point.y, x0, y0);
2295
- },
2296
- interpolationAt: quadraticAt,
2297
- pointAt: function pointAt(x1, y1, x2, y2, x3, y3, t) {
2298
- return {
2299
- x: quadraticAt(x1, x2, x3, t),
2300
- y: quadraticAt(y1, y2, y3, t)
2301
- };
2302
- },
2303
- divide: function divide(x1, y1, x2, y2, x3, y3, t) {
2304
- return divideQuadratic(x1, y1, x2, y2, x3, y3, t);
2305
- },
2306
- tangentAngle: function tangentAngle(x1, y1, x2, y2, x3, y3, t) {
2307
- var dx = derivativeAt(x1, x2, x3, t);
2308
- var dy = derivativeAt(y1, y2, y3, t);
2309
- var angle = Math.atan2(dy, dx);
2310
- return piMod(angle);
2311
- }
2312
- };
2313
- function cubicAt(p0, p1, p2, p3, t) {
2314
- var onet = 1 - t; // t * t * t 的性能大概是 Math.pow(t, 3) 的三倍
2315
- return onet * onet * onet * p0 + 3 * p1 * t * onet * onet + 3 * p2 * t * t * onet + p3 * t * t * t;
2316
- }
2317
- function derivativeAt$1(p0, p1, p2, p3, t) {
2318
- var onet = 1 - t;
2319
- return 3 * (onet * onet * (p1 - p0) + 2 * onet * t * (p2 - p1) + t * t * (p3 - p2));
2320
- }
2321
- function extrema$1(p0, p1, p2, p3) {
2322
- var a = -3 * p0 + 9 * p1 - 9 * p2 + 3 * p3;
2323
- var b = 6 * p0 - 12 * p1 + 6 * p2;
2324
- var c = 3 * p1 - 3 * p0;
2325
- var extremas = [];
2326
- var t1;
2327
- var t2;
2328
- var discSqrt;
2329
- if (isNumberEqual(a, 0)) {
2330
- if (!isNumberEqual(b, 0)) {
2331
- t1 = -c / b;
2332
- if (t1 >= 0 && t1 <= 1) {
2333
- extremas.push(t1);
2334
- }
2335
- }
2336
- } else {
2337
- var disc = b * b - 4 * a * c;
2338
- if (isNumberEqual(disc, 0)) {
2339
- extremas.push(-b / (2 * a));
2340
- } else if (disc > 0) {
2341
- discSqrt = Math.sqrt(disc);
2342
- t1 = (-b + discSqrt) / (2 * a);
2343
- t2 = (-b - discSqrt) / (2 * a);
2344
- if (t1 >= 0 && t1 <= 1) {
2345
- extremas.push(t1);
2346
- }
2347
- if (t2 >= 0 && t2 <= 1) {
2348
- extremas.push(t2);
2349
- }
2350
- }
2351
- }
2352
- return extremas;
2353
- }
2354
- // 分割贝塞尔曲线
2355
- function divideCubic(x1, y1, x2, y2, x3, y3, x4, y4, t) {
2356
- // 划分点
2357
- var xt = cubicAt(x1, x2, x3, x4, t);
2358
- var yt = cubicAt(y1, y2, y3, y4, t);
2359
- // 计算两点之间的差值点
2360
- var c1 = line.pointAt(x1, y1, x2, y2, t);
2361
- var c2 = line.pointAt(x2, y2, x3, y3, t);
2362
- var c3 = line.pointAt(x3, y3, x4, y4, t);
2363
- var c12 = line.pointAt(c1.x, c1.y, c2.x, c2.y, t);
2364
- var c23 = line.pointAt(c2.x, c2.y, c3.x, c3.y, t);
2365
- return [[x1, y1, c1.x, c1.y, c12.x, c12.y, xt, yt], [xt, yt, c23.x, c23.y, c3.x, c3.y, x4, y4]];
2366
- }
2367
- // 使用迭代法取贝塞尔曲线的长度,二阶和三阶分开写,更清晰和便于调试
2368
- function cubicLength(x1, y1, x2, y2, x3, y3, x4, y4, iterationCount) {
2369
- if (iterationCount === 0) {
2370
- return snapLength([x1, x2, x3, x4], [y1, y2, y3, y4]);
2371
- }
2372
- var cubics = divideCubic(x1, y1, x2, y2, x3, y3, x4, y4, 0.5);
2373
- var left = [].concat(cubics[0], [iterationCount - 1]);
2374
- var right = [].concat(cubics[1], [iterationCount - 1]);
2375
- return cubicLength.apply(void 0, left) + cubicLength.apply(void 0, right);
2376
- }
2377
- var cubic = {
2378
- extrema: extrema$1,
2379
- box: function box(x1, y1, x2, y2, x3, y3, x4, y4) {
2380
- var xArr = [x1, x4];
2381
- var yArr = [y1, y4];
2382
- var xExtrema = extrema$1(x1, x2, x3, x4);
2383
- var yExtrema = extrema$1(y1, y2, y3, y4);
2384
- for (var i = 0; i < xExtrema.length; i++) {
2385
- xArr.push(cubicAt(x1, x2, x3, x4, xExtrema[i]));
2386
- }
2387
- for (var _i = 0; _i < yExtrema.length; _i++) {
2388
- yArr.push(cubicAt(y1, y2, y3, y4, yExtrema[_i]));
2389
- }
2390
- return getBBoxByArray(xArr, yArr);
2391
- },
2392
- length: function length(x1, y1, x2, y2, x3, y3, x4, y4) {
2393
- // 迭代三次,划分成 8 段求长度
2394
- return cubicLength(x1, y1, x2, y2, x3, y3, x4, y4, 3);
2395
- },
2396
- nearestPoint: function nearestPoint$1(x1, y1, x2, y2, x3, y3, x4, y4, x0, y0, length) {
2397
- return nearestPoint([x1, x2, x3, x4], [y1, y2, y3, y4], x0, y0, cubicAt, length);
2398
- },
2399
- pointDistance: function pointDistance(x1, y1, x2, y2, x3, y3, x4, y4, x0, y0, length) {
2400
- var point = this.nearestPoint(x1, y1, x2, y2, x3, y3, x4, y4, x0, y0, length);
2401
- return distance(point.x, point.y, x0, y0);
2402
- },
2403
- interpolationAt: cubicAt,
2404
- pointAt: function pointAt(x1, y1, x2, y2, x3, y3, x4, y4, t) {
2405
- return {
2406
- x: cubicAt(x1, x2, x3, x4, t),
2407
- y: cubicAt(y1, y2, y3, y4, t)
2408
- };
2409
- },
2410
- divide: function divide(x1, y1, x2, y2, x3, y3, x4, y4, t) {
2411
- return divideCubic(x1, y1, x2, y2, x3, y3, x4, y4, t);
2412
- },
2413
- tangentAngle: function tangentAngle(x1, y1, x2, y2, x3, y3, x4, y4, t) {
2414
- var dx = derivativeAt$1(x1, x2, x3, x4, t);
2415
- var dy = derivativeAt$1(y1, y2, y3, y4, t);
2416
- return piMod(Math.atan2(dy, dx));
2417
- }
2418
- };
2419
- function distance$1(x1, y1, x2, y2) {
2420
- var dx = x1 - x2;
2421
- var dy = y1 - y2;
2422
- return Math.sqrt(dx * dx + dy * dy);
2423
- }
2424
- function inBox(minX, minY, width, height, x, y) {
2425
- return x >= minX && x <= minX + width && y >= minY && y <= minY + height;
2426
- }
2427
- function inRect(minX, minY, width, height, lineWidth, x, y) {
2428
- var halfWidth = lineWidth / 2;
2429
- // 将四个边看做矩形来检测,比边的检测算法要快
2430
- return inBox(minX - halfWidth, minY - halfWidth, width, lineWidth, x, y) ||
2431
- // 上边
2432
- inBox(minX + width - halfWidth, minY - halfWidth, lineWidth, height, x, y) ||
2433
- // 右边
2434
- inBox(minX + halfWidth, minY + height - halfWidth, width, lineWidth, x, y) ||
2435
- // 下边
2436
- inBox(minX - halfWidth, minY + halfWidth, lineWidth, height, x, y); // 左边
2437
- }
2438
-
2439
- function inArc(cx, cy, r, startAngle, endAngle, lineWidth, x, y) {
2440
- var angle = (Math.atan2(y - cy, x - cx) + Math.PI * 2) % (Math.PI * 2); // 转换到 0 - 2 * Math.PI 之间
2441
- // if (angle < startAngle || angle > endAngle) {
2442
- // return false;
2443
- // }
2444
- var point = {
2445
- x: cx + r * Math.cos(angle),
2446
- y: cy + r * Math.sin(angle)
2447
- };
2448
- return distance$1(point.x, point.y, x, y) <= lineWidth / 2;
2449
- }
2450
- function inLine(x1, y1, x2, y2, lineWidth, x, y) {
2451
- var minX = Math.min(x1, x2);
2452
- var maxX = Math.max(x1, x2);
2453
- var minY = Math.min(y1, y2);
2454
- var maxY = Math.max(y1, y2);
2455
- var halfWidth = lineWidth / 2;
2456
- // 因为目前的方案是计算点到直线的距离,而有可能会在延长线上,所以要先判断是否在包围盒内
2457
- // 这种方案会在水平或者竖直的情况下载线的延长线上有半 lineWidth 的误差
2458
- if (!(x >= minX - halfWidth && x <= maxX + halfWidth && y >= minY - halfWidth && y <= maxY + halfWidth)) {
2459
- return false;
2460
- }
2461
- // 因为已经计算了包围盒,所以仅需要计算到直线的距离即可,可以显著提升性能
2462
- return line.pointToLine(x1, y1, x2, y2, x, y) <= lineWidth / 2;
2463
- }
2464
- function inPolyline(points, lineWidth, x, y, isClose) {
2465
- var count = points.length;
2466
- if (count < 2) {
2467
- return false;
2468
- }
2469
- for (var i = 0; i < count - 1; i++) {
2470
- var x1 = points[i][0];
2471
- var y1 = points[i][1];
2472
- var x2 = points[i + 1][0];
2473
- var y2 = points[i + 1][1];
2474
- if (inLine(x1, y1, x2, y2, lineWidth, x, y)) {
2475
- return true;
2476
- }
2477
- }
2478
- // 如果封闭,则计算起始点和结束点的边
2479
- if (isClose) {
2480
- var first = points[0];
2481
- var last = points[count - 1];
2482
- if (inLine(first[0], first[1], last[0], last[1], lineWidth, x, y)) {
2483
- return true;
2484
- }
2485
- }
2486
- return false;
2487
- }
2488
- // 多边形的射线检测,参考:https://blog.csdn.net/WilliamSun0122/article/details/77994526
2489
- var tolerance = 1e-6;
2490
- // 三态函数,判断两个double在eps精度下的大小关系
2491
- function dcmp(x) {
2492
- if (Math.abs(x) < tolerance) {
2493
- return 0;
2494
- }
2495
- return x < 0 ? -1 : 1;
2496
- }
2497
- // 判断点Q是否在p1和p2的线段上
2498
- function onSegment(p1, p2, q) {
2499
- if ((q[0] - p1[0]) * (p2[1] - p1[1]) === (p2[0] - p1[0]) * (q[1] - p1[1]) && Math.min(p1[0], p2[0]) <= q[0] && q[0] <= Math.max(p1[0], p2[0]) && Math.min(p1[1], p2[1]) <= q[1] && q[1] <= Math.max(p1[1], p2[1])) {
2500
- return true;
2501
- }
2502
- return false;
2503
- }
2504
- // 判断点P在多边形内-射线法
2505
- function inPolygon(points, x, y) {
2506
- var isHit = false;
2507
- var n = points.length;
2508
- if (n <= 2) {
2509
- // svg 中点小于 3 个时,不显示,也无法被拾取
2510
- return false;
2511
- }
2512
- for (var i = 0; i < n; i++) {
2513
- var p1 = points[i];
2514
- var p2 = points[(i + 1) % n];
2515
- if (onSegment(p1, p2, [x, y])) {
2516
- // 点在多边形一条边上
2517
- return true;
2518
- }
2519
- // 前一个判断min(p1[1],p2[1])<P.y<=max(p1[1],p2[1])
2520
- // 后一个判断被测点 在 射线与边交点 的左边
2521
- if (dcmp(p1[1] - y) > 0 !== dcmp(p2[1] - y) > 0 && dcmp(x - (y - p1[1]) * (p1[0] - p2[0]) / (p1[1] - p2[1]) - p1[0]) < 0) {
2522
- isHit = !isHit;
2523
- }
2524
- }
2525
- return isHit;
2526
- }
2527
- function inPolygons(polygons, x, y) {
2528
- var isHit = false;
2529
- for (var i = 0; i < polygons.length; i++) {
2530
- var points = polygons[i];
2531
- isHit = inPolygon(points, x, y);
2532
- if (isHit) {
2533
- break;
2534
- }
2535
- }
2536
- return isHit;
2537
- }
2538
- function isPointInPath(displayObject, position, isClipPath) {
2539
- var _displayObject$parsed = displayObject.parsedStyle,
2540
- r = _displayObject$parsed.r,
2541
- fill = _displayObject$parsed.fill,
2542
- stroke = _displayObject$parsed.stroke,
2543
- lineWidth = _displayObject$parsed.lineWidth,
2544
- increasedLineWidthForHitTesting = _displayObject$parsed.increasedLineWidthForHitTesting,
2545
- pointerEvents = _displayObject$parsed.pointerEvents;
2546
- var halfLineWidth = ((lineWidth || 0) + (increasedLineWidthForHitTesting || 0)) / 2;
2547
- var absDistance = distance$1(r, r, position.x, position.y);
2548
- var _isFillOrStrokeAffect = gLite.isFillOrStrokeAffected(pointerEvents, fill, stroke),
2549
- hasFill = _isFillOrStrokeAffect[0],
2550
- hasStroke = _isFillOrStrokeAffect[1];
2551
- if (hasFill && hasStroke || isClipPath) {
2552
- return absDistance <= r + halfLineWidth;
2553
- }
2554
- if (hasFill) {
2555
- return absDistance <= r;
2556
- }
2557
- if (hasStroke) {
2558
- return absDistance >= r - halfLineWidth && absDistance <= r + halfLineWidth;
2559
- }
2560
- return false;
2561
- }
2562
- function ellipseDistance(squareX, squareY, rx, ry) {
2563
- return squareX / (rx * rx) + squareY / (ry * ry);
2564
- }
2565
- function isPointInPath$1(displayObject, position, isClipPath) {
2566
- var _displayObject$parsed = displayObject.parsedStyle,
2567
- rx = _displayObject$parsed.rx,
2568
- ry = _displayObject$parsed.ry,
2569
- fill = _displayObject$parsed.fill,
2570
- stroke = _displayObject$parsed.stroke,
2571
- lineWidth = _displayObject$parsed.lineWidth,
2572
- increasedLineWidthForHitTesting = _displayObject$parsed.increasedLineWidthForHitTesting,
2573
- pointerEvents = _displayObject$parsed.pointerEvents;
2574
- var x = position.x,
2575
- y = position.y;
2576
- var _isFillOrStrokeAffect = gLite.isFillOrStrokeAffected(pointerEvents, fill, stroke),
2577
- hasFill = _isFillOrStrokeAffect[0],
2578
- hasStroke = _isFillOrStrokeAffect[1];
2579
- var halfLineWith = ((lineWidth || 0) + (increasedLineWidthForHitTesting || 0)) / 2;
2580
- var squareX = (x - rx) * (x - rx);
2581
- var squareY = (y - ry) * (y - ry);
2582
- // 使用椭圆的公式: x*x/rx*rx + y*y/ry*ry = 1;
2583
- if (hasFill && hasStroke || isClipPath) {
2584
- return ellipseDistance(squareX, squareY, rx + halfLineWith, ry + halfLineWith) <= 1;
2585
- }
2586
- if (hasFill) {
2587
- return ellipseDistance(squareX, squareY, rx, ry) <= 1;
2588
- }
2589
- if (hasStroke) {
2590
- return ellipseDistance(squareX, squareY, rx - halfLineWith, ry - halfLineWith) >= 1 && ellipseDistance(squareX, squareY, rx + halfLineWith, ry + halfLineWith) <= 1;
2591
- }
2592
- return false;
2593
- }
2594
- function isPointInPath$2(displayObject, position, isClipPath) {
2595
- var _displayObject$parsed = displayObject.parsedStyle,
2596
- x1 = _displayObject$parsed.x1,
2597
- y1 = _displayObject$parsed.y1,
2598
- x2 = _displayObject$parsed.x2,
2599
- y2 = _displayObject$parsed.y2,
2600
- lineWidth = _displayObject$parsed.lineWidth,
2601
- increasedLineWidthForHitTesting = _displayObject$parsed.increasedLineWidthForHitTesting,
2602
- _displayObject$parsed2 = _displayObject$parsed.defX,
2603
- x = _displayObject$parsed2 === void 0 ? 0 : _displayObject$parsed2,
2604
- _displayObject$parsed3 = _displayObject$parsed.defY,
2605
- y = _displayObject$parsed3 === void 0 ? 0 : _displayObject$parsed3,
2606
- pointerEvents = _displayObject$parsed.pointerEvents,
2607
- fill = _displayObject$parsed.fill,
2608
- stroke = _displayObject$parsed.stroke;
2609
- var _isFillOrStrokeAffect = gLite.isFillOrStrokeAffected(pointerEvents, fill, stroke),
2610
- hasStroke = _isFillOrStrokeAffect[1];
2611
- if (!hasStroke && !isClipPath || !lineWidth) {
2612
- return false;
2613
- }
2614
- return inLine(x1, y1, x2, y2, (lineWidth || 0) + (increasedLineWidthForHitTesting || 0), position.x + x, position.y + y);
2615
- }
2616
-
2617
- // TODO: replace it with method in @antv/util
2618
- function isPointInStroke(segments, lineWidth, px, py, length) {
2619
- var isHit = false;
2620
- var halfWidth = lineWidth / 2;
2621
- for (var i = 0; i < segments.length; i++) {
2622
- var segment = segments[i];
2623
- var currentPoint = segment.currentPoint,
2624
- params = segment.params,
2625
- prePoint = segment.prePoint,
2626
- box = segment.box;
2627
- // 如果在前面已经生成过包围盒,直接按照包围盒计算
2628
- if (box && !inBox(box.x - halfWidth, box.y - halfWidth, box.width + lineWidth, box.height + lineWidth, px, py)) {
2629
- continue;
2630
- }
2631
- switch (segment.command) {
2632
- // L 和 Z 都是直线, M 不进行拾取
2633
- case 'L':
2634
- case 'Z':
2635
- isHit = inLine(prePoint[0], prePoint[1], currentPoint[0], currentPoint[1], lineWidth, px, py);
2636
- if (isHit) {
2637
- return true;
2638
- }
2639
- break;
2640
- case 'Q':
2641
- var qDistance = quadratic.pointDistance(prePoint[0], prePoint[1], params[1], params[2], params[3], params[4], px, py);
2642
- isHit = qDistance <= lineWidth / 2;
2643
- if (isHit) {
2644
- return true;
2645
- }
2646
- break;
2647
- case 'C':
2648
- var cDistance = cubic.pointDistance(prePoint[0],
2649
- // 上一段结束位置, 即 C 的起始点
2650
- prePoint[1], params[1],
2651
- // 'C' 的参数,1、2 为第一个控制点,3、4 为第二个控制点,5、6 为结束点
2652
- params[2], params[3], params[4], params[5], params[6], px, py, length);
2653
- isHit = cDistance <= lineWidth / 2;
2654
- if (isHit) {
2655
- return true;
2656
- }
2657
- break;
2658
- case 'A':
2659
- // cache conversion result
2660
- if (!segment.cubicParams) {
2661
- segment.cubicParams = arcToCubic(prePoint[0], prePoint[1], params[1], params[2], params[3], params[4], params[5], params[6], params[7], undefined);
2662
- }
2663
- var args = segment.cubicParams;
2664
- // fixArc
2665
- var prePointInCubic = prePoint;
2666
- for (var _i = 0; _i < args.length; _i += 6) {
2667
- var _cDistance = cubic.pointDistance(prePointInCubic[0],
2668
- // 上一段结束位置, 即 C 的起始点
2669
- prePointInCubic[1], args[_i], args[_i + 1], args[_i + 2], args[_i + 3], args[_i + 4], args[_i + 5], px, py, length);
2670
- prePointInCubic = [args[_i + 4], args[_i + 5]];
2671
- isHit = _cDistance <= lineWidth / 2;
2672
- if (isHit) {
2673
- return true;
2674
- }
2675
- }
2676
- break;
2677
- }
2678
- }
2679
- return isHit;
2680
- }
2681
- function isPointInPath$3(displayObject, position, isClipPath, isPointInPath, renderingPluginContext, runtime) {
2682
- var _displayObject$parsed = displayObject.parsedStyle,
2683
- lineWidth = _displayObject$parsed.lineWidth,
2684
- increasedLineWidthForHitTesting = _displayObject$parsed.increasedLineWidthForHitTesting,
2685
- stroke = _displayObject$parsed.stroke,
2686
- fill = _displayObject$parsed.fill,
2687
- _displayObject$parsed2 = _displayObject$parsed.defX,
2688
- x = _displayObject$parsed2 === void 0 ? 0 : _displayObject$parsed2,
2689
- _displayObject$parsed3 = _displayObject$parsed.defY,
2690
- y = _displayObject$parsed3 === void 0 ? 0 : _displayObject$parsed3,
2691
- path = _displayObject$parsed.path,
2692
- pointerEvents = _displayObject$parsed.pointerEvents;
2693
- var segments = path.segments,
2694
- hasArc = path.hasArc,
2695
- polylines = path.polylines,
2696
- polygons = path.polygons;
2697
- var _isFillOrStrokeAffect = gLite.isFillOrStrokeAffected(pointerEvents,
2698
- // Only a closed path can be filled.
2699
- (polygons === null || polygons === void 0 ? void 0 : polygons.length) && fill, stroke),
2700
- hasFill = _isFillOrStrokeAffect[0],
2701
- hasStroke = _isFillOrStrokeAffect[1];
2702
- var totalLength = gLite.getOrCalculatePathTotalLength(displayObject);
2703
- var isHit = false;
2704
- if (hasFill || isClipPath) {
2705
- if (hasArc) {
2706
- // 存在曲线时,暂时使用 canvas 的 api 计算,后续可以进行多边形切割
2707
- isHit = isPointInPath(displayObject, position);
2708
- } else {
2709
- // 提取出来的多边形包含闭合的和非闭合的,在这里统一按照多边形处理
2710
- isHit = inPolygons(polygons, position.x + x, position.y + y) || inPolygons(polylines, position.x + x, position.y + y);
2711
- }
2712
- return isHit;
2713
- } else if (hasStroke || isClipPath) {
2714
- isHit = isPointInStroke(segments, (lineWidth || 0) + (increasedLineWidthForHitTesting || 0), position.x + x, position.y + y, totalLength);
2715
- }
2716
- return isHit;
2717
- }
2718
- function isPointInPath$4(displayObject, position, isClipPath) {
2719
- var _displayObject$parsed = displayObject.parsedStyle,
2720
- stroke = _displayObject$parsed.stroke,
2721
- fill = _displayObject$parsed.fill,
2722
- lineWidth = _displayObject$parsed.lineWidth,
2723
- increasedLineWidthForHitTesting = _displayObject$parsed.increasedLineWidthForHitTesting,
2724
- points = _displayObject$parsed.points,
2725
- _displayObject$parsed2 = _displayObject$parsed.defX,
2726
- x = _displayObject$parsed2 === void 0 ? 0 : _displayObject$parsed2,
2727
- _displayObject$parsed3 = _displayObject$parsed.defY,
2728
- y = _displayObject$parsed3 === void 0 ? 0 : _displayObject$parsed3,
2729
- pointerEvents = _displayObject$parsed.pointerEvents;
2730
- var _isFillOrStrokeAffect = gLite.isFillOrStrokeAffected(pointerEvents, fill, stroke),
2731
- hasFill = _isFillOrStrokeAffect[0],
2732
- hasStroke = _isFillOrStrokeAffect[1];
2733
- var isHit = false;
2734
- if (hasStroke || isClipPath) {
2735
- isHit = inPolyline(points.points, (lineWidth || 0) + (increasedLineWidthForHitTesting || 0), position.x + x, position.y + y, true);
2736
- }
2737
- if (!isHit && (hasFill || isClipPath)) {
2738
- isHit = inPolygon(points.points, position.x + x, position.y + y);
2739
- }
2740
- return isHit;
2741
- }
2742
- function isPointInPath$5(displayObject, position, isClipPath) {
2743
- var _displayObject$parsed = displayObject.parsedStyle,
2744
- lineWidth = _displayObject$parsed.lineWidth,
2745
- increasedLineWidthForHitTesting = _displayObject$parsed.increasedLineWidthForHitTesting,
2746
- points = _displayObject$parsed.points,
2747
- _displayObject$parsed2 = _displayObject$parsed.defX,
2748
- x = _displayObject$parsed2 === void 0 ? 0 : _displayObject$parsed2,
2749
- _displayObject$parsed3 = _displayObject$parsed.defY,
2750
- y = _displayObject$parsed3 === void 0 ? 0 : _displayObject$parsed3,
2751
- pointerEvents = _displayObject$parsed.pointerEvents,
2752
- fill = _displayObject$parsed.fill,
2753
- stroke = _displayObject$parsed.stroke;
2754
- var _isFillOrStrokeAffect = gLite.isFillOrStrokeAffected(pointerEvents, fill, stroke),
2755
- hasStroke = _isFillOrStrokeAffect[1];
2756
- if (!hasStroke && !isClipPath || !lineWidth) {
2757
- return false;
2758
- }
2759
- return inPolyline(points.points, (lineWidth || 0) + (increasedLineWidthForHitTesting || 0), position.x + x, position.y + y, false);
2760
- }
2761
- function isPointInPath$6(displayObject, position, isClipPath, isPointInPath, runtime) {
2762
- var _displayObject$parsed = displayObject.parsedStyle,
2763
- radius = _displayObject$parsed.radius,
2764
- fill = _displayObject$parsed.fill,
2765
- stroke = _displayObject$parsed.stroke,
2766
- lineWidth = _displayObject$parsed.lineWidth,
2767
- increasedLineWidthForHitTesting = _displayObject$parsed.increasedLineWidthForHitTesting,
2768
- width = _displayObject$parsed.width,
2769
- height = _displayObject$parsed.height,
2770
- pointerEvents = _displayObject$parsed.pointerEvents;
2771
- var _isFillOrStrokeAffect = gLite.isFillOrStrokeAffected(pointerEvents, fill, stroke),
2772
- hasFill = _isFillOrStrokeAffect[0],
2773
- hasStroke = _isFillOrStrokeAffect[1];
2774
- var hasRadius = radius && radius.some(function (r) {
2775
- return r !== 0;
2776
- });
2777
- var lineWidthForHitTesting = (lineWidth || 0) + (increasedLineWidthForHitTesting || 0);
2778
- // 无圆角时的策略
2779
- if (!hasRadius) {
2780
- var halfWidth = lineWidthForHitTesting / 2;
2781
- // 同时填充和带有边框
2782
- if (hasFill && hasStroke || isClipPath) {
2783
- return inBox(0 - halfWidth, 0 - halfWidth, width + halfWidth, height + halfWidth, position.x, position.y);
2784
- }
2785
- // 仅填充
2786
- if (hasFill) {
2787
- return inBox(0, 0, width, height, position.x, position.y);
2788
- }
2789
- if (hasStroke) {
2790
- return inRect(0, 0, width, height, lineWidthForHitTesting, position.x, position.y);
2791
- }
2792
- } else {
2793
- var isHit = false;
2794
- if (hasStroke || isClipPath) {
2795
- isHit = inRectWithRadius(0, 0, width, height, radius.map(function (r) {
2796
- return clamp(r, 0, Math.min(Math.abs(width) / 2, Math.abs(height) / 2));
2797
- }), lineWidthForHitTesting, position.x, position.y);
2798
- }
2799
- // 仅填充时带有圆角的矩形直接通过图形拾取
2800
- // 以后可以改成纯数学的近似拾取,将圆弧切割成多边形
2801
- if (!isHit && (hasFill || isClipPath)) {
2802
- isHit = isPointInPath(displayObject, position);
2803
- }
2804
- return isHit;
2805
- }
2806
- return false;
2807
- }
2808
- function inRectWithRadius(minX, minY, width, height, radiusArray, lineWidth, x, y) {
2809
- var tlr = radiusArray[0],
2810
- trr = radiusArray[1],
2811
- brr = radiusArray[2],
2812
- blr = radiusArray[3];
2813
- return inLine(minX + tlr, minY, minX + width - trr, minY, lineWidth, x, y) || inLine(minX + width, minY + trr, minX + width, minY + height - brr, lineWidth, x, y) || inLine(minX + width - brr, minY + height, minX + blr, minY + height, lineWidth, x, y) || inLine(minX, minY + height - blr, minX, minY + tlr, lineWidth, x, y) || inArc(minX + width - trr, minY + trr, trr, 1.5 * Math.PI, 2 * Math.PI, lineWidth, x, y) || inArc(minX + width - brr, minY + height - brr, brr, 0, 0.5 * Math.PI, lineWidth, x, y) || inArc(minX + blr, minY + height - blr, blr, 0.5 * Math.PI, Math.PI, lineWidth, x, y) || inArc(minX + tlr, minY + tlr, tlr, Math.PI, 1.5 * Math.PI, lineWidth, x, y);
2814
- }
2815
- function isPointInPath$7(displayObject, position, isClipPath, isPointInPath, renderingPluginContext, runtime) {
2816
- var _displayObject$parsed = displayObject.parsedStyle,
2817
- pointerEvents = _displayObject$parsed.pointerEvents,
2818
- width = _displayObject$parsed.width,
2819
- height = _displayObject$parsed.height;
2820
- if (pointerEvents === 'non-transparent-pixel') {
2821
- var offscreenCanvas = renderingPluginContext.config.offscreenCanvas;
2822
- var canvas = runtime.offscreenCanvas.getOrCreateCanvas(offscreenCanvas);
2823
- var context = runtime.offscreenCanvas.getOrCreateContext(offscreenCanvas, {
2824
- willReadFrequently: true
2825
- });
2826
- canvas.width = width;
2827
- canvas.height = height;
2828
- renderingPluginContext.defaultStyleRendererFactory[gLite.Shape.IMAGE].render(context, displayObject.parsedStyle, displayObject, undefined, undefined, undefined);
2829
- var imagedata = context.getImageData(position.x, position.y, 1, 1).data;
2830
- return imagedata.every(function (component) {
2831
- return component !== 0;
2832
- });
2833
- }
2834
- return true;
2835
- }
2836
- var Plugin$1 = /*#__PURE__*/function (_AbstractRendererPlug) {
2837
- _inheritsLoose$2(Plugin, _AbstractRendererPlug);
2838
- function Plugin() {
2839
- var _this;
2840
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
2841
- args[_key] = arguments[_key];
2842
- }
2843
- _this = _AbstractRendererPlug.call.apply(_AbstractRendererPlug, [this].concat(args)) || this;
2844
- _this.name = 'canvas-picker';
2845
- return _this;
2846
- }
2847
- var _proto = Plugin.prototype;
2848
- _proto.init = function init() {
2849
- var _pointInPathPickerFac;
2850
- var trueFunc = function trueFunc() {
2851
- return true;
2852
- };
2853
- var pointInPathPickerFactory = (_pointInPathPickerFac = {}, _pointInPathPickerFac[gLite.Shape.CIRCLE] = isPointInPath, _pointInPathPickerFac[gLite.Shape.ELLIPSE] = isPointInPath$1, _pointInPathPickerFac[gLite.Shape.RECT] = isPointInPath$6, _pointInPathPickerFac[gLite.Shape.LINE] = isPointInPath$2, _pointInPathPickerFac[gLite.Shape.POLYLINE] = isPointInPath$5, _pointInPathPickerFac[gLite.Shape.POLYGON] = isPointInPath$4, _pointInPathPickerFac[gLite.Shape.PATH] = isPointInPath$3, _pointInPathPickerFac[gLite.Shape.TEXT] = trueFunc, _pointInPathPickerFac[gLite.Shape.GROUP] = null, _pointInPathPickerFac[gLite.Shape.IMAGE] = isPointInPath$7, _pointInPathPickerFac[gLite.Shape.HTML] = null, _pointInPathPickerFac[gLite.Shape.MESH] = null, _pointInPathPickerFac);
2854
- // @ts-ignore
2855
- this.context.pointInPathPickerFactory = pointInPathPickerFactory;
2856
- this.addRenderingPlugin(new CanvasPickerPlugin());
2857
- };
2858
- _proto.destroy = function destroy() {
2859
- // @ts-ignore
2860
- delete this.context.pointInPathPickerFactory;
2861
- this.removeAllRenderingPlugins();
2862
- };
2863
- return Plugin;
2864
- }(gLite.AbstractRendererPlugin);
2865
-
2866
- var index_esm$1 = /*#__PURE__*/Object.freeze({
2867
- __proto__: null,
2868
- Plugin: Plugin$1
2869
- });
2870
-
2871
- function _extends() {
2872
- _extends = Object.assign ? Object.assign.bind() : function (target) {
2873
- for (var i = 1; i < arguments.length; i++) {
2874
- var source = arguments[i];
2875
- for (var key in source) {
2876
- if (Object.prototype.hasOwnProperty.call(source, key)) {
2877
- target[key] = source[key];
2878
- }
2879
- }
2880
- }
2881
- return target;
2882
- };
2883
- return _extends.apply(this, arguments);
2884
- }
2885
- function _inheritsLoose$3(subClass, superClass) {
2886
- subClass.prototype = Object.create(superClass.prototype);
2887
- subClass.prototype.constructor = subClass;
2888
- _setPrototypeOf$3(subClass, superClass);
2889
- }
2890
- function _setPrototypeOf$3(o, p) {
2891
- _setPrototypeOf$3 = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) {
2892
- o.__proto__ = p;
2893
- return o;
2894
- };
2895
- return _setPrototypeOf$3(o, p);
2896
- }
2897
-
2898
- /**
2899
- * support 2 modes in rendering:
2900
- * * immediate
2901
- * * delayed: render at the end of frame with dirty-rectangle
2902
- */
2903
- var CanvasRendererPlugin = /*#__PURE__*/function () {
2904
- function CanvasRendererPlugin(canvasRendererPluginOptions) {
2905
- this.canvasRendererPluginOptions = void 0;
2906
- this.context = void 0;
2907
- this.pathGeneratorFactory = void 0;
2908
- /**
2909
- * RBush used in dirty rectangle rendering
2910
- */
2911
- this.rBush = void 0;
2912
- this.removedRBushNodeAABBs = [];
2913
- this.renderQueue = [];
2914
- /**
2915
- * This stack is only used by clipPath for now.
2916
- */
2917
- this.restoreStack = [];
2918
- this.clearFullScreen = false;
2919
- /**
2920
- * view projection matrix
2921
- */
2922
- this.vpMatrix = create();
2923
- this.dprMatrix = create();
2924
- this.tmpMat4 = create();
2925
- this.vec3a = create$1();
2926
- this.vec3b = create$1();
2927
- this.vec3c = create$1();
2928
- this.vec3d = create$1();
2929
- this.canvasRendererPluginOptions = canvasRendererPluginOptions;
2930
- }
2931
- var _proto = CanvasRendererPlugin.prototype;
2932
- _proto.apply = function apply(context, runtime) {
2933
- var _this = this;
2934
- this.context = context;
2935
- var config = context.config,
2936
- camera = context.camera,
2937
- renderingService = context.renderingService,
2938
- renderingContext = context.renderingContext,
2939
- rBushRoot = context.rBushRoot,
2940
- pathGeneratorFactory = context.pathGeneratorFactory;
2941
- this.rBush = rBushRoot;
2942
- this.pathGeneratorFactory = pathGeneratorFactory;
2943
- var contextService = context.contextService;
2944
- var canvas = renderingContext.root.ownerDocument.defaultView;
2945
- var handleUnmounted = function handleUnmounted(e) {
2946
- var object = e.target;
2947
- // remove r-bush node
2948
- // @ts-ignore
2949
- var rBushNode = object.rBushNode;
2950
- if (rBushNode.aabb) {
2951
- // save removed aabbs for dirty-rectangle rendering later
2952
- _this.removedRBushNodeAABBs.push(rBushNode.aabb);
2953
- }
2954
- };
2955
- var handleCulled = function handleCulled(e) {
2956
- var object = e.target;
2957
- // @ts-ignore
2958
- var rBushNode = object.rBushNode;
2959
- if (rBushNode.aabb) {
2960
- // save removed aabbs for dirty-rectangle rendering later
2961
- _this.removedRBushNodeAABBs.push(rBushNode.aabb);
2962
- }
2963
- };
2964
- renderingService.hooks.init.tap(CanvasRendererPlugin.tag, function () {
2965
- canvas.addEventListener(gLite.ElementEvent.UNMOUNTED, handleUnmounted);
2966
- canvas.addEventListener(gLite.ElementEvent.CULLED, handleCulled);
2967
- // clear fullscreen
2968
- var dpr = contextService.getDPR();
2969
- var width = config.width,
2970
- height = config.height;
2971
- var context = contextService.getContext();
2972
- _this.clearRect(context, 0, 0, width * dpr, height * dpr, config.background);
2973
- });
2974
- renderingService.hooks.destroy.tap(CanvasRendererPlugin.tag, function () {
2975
- canvas.removeEventListener(gLite.ElementEvent.UNMOUNTED, handleUnmounted);
2976
- canvas.removeEventListener(gLite.ElementEvent.CULLED, handleCulled);
2977
- // this.renderQueue = [];
2978
- // this.removedRBushNodeAABBs = [];
2979
- // this.restoreStack = [];
2980
- });
2981
-
2982
- renderingService.hooks.beginFrame.tap(CanvasRendererPlugin.tag, function () {
2983
- var context = contextService.getContext();
2984
- var dpr = contextService.getDPR();
2985
- var width = config.width,
2986
- height = config.height;
2987
- var _this$canvasRendererP = _this.canvasRendererPluginOptions,
2988
- dirtyObjectNumThreshold = _this$canvasRendererP.dirtyObjectNumThreshold,
2989
- dirtyObjectRatioThreshold = _this$canvasRendererP.dirtyObjectRatioThreshold;
2990
- // some heuristic conditions such as 80% object changed
2991
- var _renderingService$get = renderingService.getStats(),
2992
- total = _renderingService$get.total,
2993
- rendered = _renderingService$get.rendered;
2994
- var ratio = rendered / total;
2995
- _this.clearFullScreen = renderingService.disableDirtyRectangleRendering() || rendered > dirtyObjectNumThreshold && ratio > dirtyObjectRatioThreshold;
2996
- if (context) {
2997
- context.resetTransform ? context.resetTransform() : context.setTransform(1, 0, 0, 1, 0, 0);
2998
- if (_this.clearFullScreen) {
2999
- _this.clearRect(context, 0, 0, width * dpr, height * dpr, config.background);
3000
- }
3001
- }
3002
- });
3003
- var renderByZIndex = function renderByZIndex(object, context) {
3004
- if (object.isVisible() && !object.isCulled()) {
3005
- _this.renderDisplayObject(object, context, _this.context, _this.restoreStack, runtime);
3006
- // if (object.renderable.) {
3007
- // if we did a full screen rendering last frame
3008
- _this.saveDirtyAABB(object);
3009
- // }
3010
- }
3011
-
3012
- var sorted = object.sortable.sorted || object.childNodes;
3013
- // should account for z-index
3014
- sorted.forEach(function (child) {
3015
- renderByZIndex(child, context);
3016
- });
3017
- };
3018
- // render at the end of frame
3019
- renderingService.hooks.endFrame.tap(CanvasRendererPlugin.tag, function () {
3020
- var context = contextService.getContext();
3021
- // clear & clip dirty rectangle
3022
- var dpr = contextService.getDPR();
3023
- fromScaling(_this.dprMatrix, [dpr, dpr, 1]);
3024
- multiply(_this.vpMatrix, _this.dprMatrix, camera.getOrthoMatrix());
3025
- // if (this.clearFullScreen) {
3026
- if (_this.clearFullScreen) {
3027
- // console.log('canvas renderer fcp...');
3028
- renderByZIndex(renderingContext.root, context);
3029
- } else {
3030
- // console.log('canvas renderer next...');
3031
- // merge removed AABB
3032
- var dirtyRenderBounds = _this.safeMergeAABB.apply(_this, [_this.mergeDirtyAABBs(_this.renderQueue)].concat(_this.removedRBushNodeAABBs.map(function (_ref) {
3033
- var minX = _ref.minX,
3034
- minY = _ref.minY,
3035
- maxX = _ref.maxX,
3036
- maxY = _ref.maxY;
3037
- var aabb = new gLite.AABB();
3038
- aabb.setMinMax(
3039
- // vec3.fromValues(minX, minY, 0),
3040
- // vec3.fromValues(maxX, maxY, 0),
3041
- [minX, minY, 0], [maxX, maxY, 0]);
3042
- return aabb;
3043
- })));
3044
- _this.removedRBushNodeAABBs = [];
3045
- if (gLite.AABB.isEmpty(dirtyRenderBounds)) {
3046
- _this.renderQueue = [];
3047
- return;
3048
- }
3049
- var dirtyRect = _this.convertAABB2Rect(dirtyRenderBounds);
3050
- var x = dirtyRect.x,
3051
- y = dirtyRect.y,
3052
- width = dirtyRect.width,
3053
- height = dirtyRect.height;
3054
- var tl = transformMat4(_this.vec3a, [x, y, 0], _this.vpMatrix);
3055
- var tr = transformMat4(_this.vec3b, [x + width, y, 0], _this.vpMatrix);
3056
- var bl = transformMat4(_this.vec3c, [x, y + height, 0], _this.vpMatrix);
3057
- var br = transformMat4(_this.vec3d, [x + width, y + height, 0], _this.vpMatrix);
3058
- var minx = Math.min(tl[0], tr[0], br[0], bl[0]);
3059
- var miny = Math.min(tl[1], tr[1], br[1], bl[1]);
3060
- var maxx = Math.max(tl[0], tr[0], br[0], bl[0]);
3061
- var maxy = Math.max(tl[1], tr[1], br[1], bl[1]);
3062
- var ix = Math.floor(minx);
3063
- var iy = Math.floor(miny);
3064
- var iwidth = Math.ceil(maxx - minx);
3065
- var iheight = Math.ceil(maxy - miny);
3066
- context.save();
3067
- _this.clearRect(context, ix, iy, iwidth, iheight, config.background);
3068
- context.beginPath();
3069
- context.rect(ix, iy, iwidth, iheight);
3070
- context.clip();
3071
- // @see https://developer.mozilla.org/en-US/docs/Web/API/Canvas_API/Tutorial/Transformations
3072
- context.setTransform(_this.vpMatrix[0], _this.vpMatrix[1], _this.vpMatrix[4], _this.vpMatrix[5], _this.vpMatrix[12], _this.vpMatrix[13]);
3073
- // draw dirty rectangle
3074
- var _config$renderer$getC = config.renderer.getConfig(),
3075
- enableDirtyRectangleRenderingDebug = _config$renderer$getC.enableDirtyRectangleRenderingDebug;
3076
- if (enableDirtyRectangleRenderingDebug) {
3077
- canvas.dispatchEvent(new gLite.CustomEvent(gLite.CanvasEvent.DIRTY_RECTANGLE, {
3078
- dirtyRect: {
3079
- x: ix,
3080
- y: iy,
3081
- width: iwidth,
3082
- height: iheight
3083
- }
3084
- }));
3085
- }
3086
- // search objects intersect with dirty rectangle
3087
- var dirtyObjects = _this.searchDirtyObjects(dirtyRenderBounds);
3088
- // do rendering
3089
- dirtyObjects
3090
- // sort by z-index
3091
- .sort(function (a, b) {
3092
- return a.sortable.renderOrder - b.sortable.renderOrder;
3093
- }).forEach(function (object) {
3094
- // culled object should not be rendered
3095
- if (object && object.isVisible() && !object.isCulled()) {
3096
- _this.renderDisplayObject(object, context, _this.context, _this.restoreStack, runtime);
3097
- }
3098
- });
3099
- context.restore();
3100
- // save dirty AABBs in last frame
3101
- _this.renderQueue.forEach(function (object) {
3102
- _this.saveDirtyAABB(object);
3103
- });
3104
- // clear queue
3105
- _this.renderQueue = [];
3106
- }
3107
- // pop restore stack, eg. root -> parent -> child
3108
- _this.restoreStack.forEach(function () {
3109
- context.restore();
3110
- });
3111
- // clear restore stack
3112
- _this.restoreStack = [];
3113
- });
3114
- renderingService.hooks.render.tap(CanvasRendererPlugin.tag, function (object) {
3115
- if (!_this.clearFullScreen) {
3116
- // render at the end of frame
3117
- _this.renderQueue.push(object);
3118
- }
3119
- });
3120
- };
3121
- _proto.clearRect = function clearRect(context, x, y, width, height, background) {
3122
- // clearRect is faster than fillRect @see https://stackoverflow.com/a/30830253
3123
- context.clearRect(x, y, width, height);
3124
- if (background) {
3125
- context.fillStyle = background;
3126
- context.fillRect(x, y, width, height);
3127
- }
3128
- };
3129
- _proto.renderDisplayObject = function renderDisplayObject(object, context, canvasContext, restoreStack, runtime) {
3130
- var nodeName = object.nodeName;
3131
- // console.log('canvas render:', object);
3132
- // restore to its ancestor
3133
- var parent = restoreStack[restoreStack.length - 1];
3134
- if (parent && !(object.compareDocumentPosition(parent) & Node.DOCUMENT_POSITION_CONTAINS)) {
3135
- context.restore();
3136
- restoreStack.pop();
3137
- }
3138
- // @ts-ignore
3139
- var styleRenderer = this.context.styleRendererFactory[nodeName];
3140
- var generatePath = this.pathGeneratorFactory[nodeName];
3141
- // clip path
3142
- var clipPath = object.parsedStyle.clipPath;
3143
- if (clipPath) {
3144
- this.applyWorldTransform(context, clipPath);
3145
- // generate path in local space
3146
- var _generatePath = this.pathGeneratorFactory[clipPath.nodeName];
3147
- if (_generatePath) {
3148
- context.save();
3149
- // save clip
3150
- restoreStack.push(object);
3151
- context.beginPath();
3152
- _generatePath(context, clipPath.parsedStyle);
3153
- context.closePath();
3154
- context.clip();
3155
- }
3156
- }
3157
- // fill & stroke
3158
- if (styleRenderer) {
3159
- this.applyWorldTransform(context, object);
3160
- context.save();
3161
- // apply attributes to context
3162
- this.applyAttributesToContext(context, object);
3163
- }
3164
- if (generatePath) {
3165
- context.beginPath();
3166
- generatePath(context, object.parsedStyle);
3167
- if (object.nodeName !== gLite.Shape.LINE && object.nodeName !== gLite.Shape.PATH && object.nodeName !== gLite.Shape.POLYLINE) {
3168
- context.closePath();
3169
- }
3170
- }
3171
- // fill & stroke
3172
- if (styleRenderer) {
3173
- styleRenderer.render(context, object.parsedStyle, object, canvasContext, this, runtime);
3174
- // restore applied attributes, eg. shadowBlur shadowColor...
3175
- context.restore();
3176
- }
3177
- // finish rendering, clear dirty flag
3178
- object.renderable.dirty = false;
3179
- };
3180
- _proto.convertAABB2Rect = function convertAABB2Rect(aabb) {
3181
- var min = aabb.getMin();
3182
- var max = aabb.getMax();
3183
- // expand the rectangle a bit to avoid artifacts
3184
- // @see https://www.yuque.com/antv/ou292n/bi8nix#ExvCu
3185
- var minX = Math.floor(min[0]);
3186
- var minY = Math.floor(min[1]);
3187
- var maxX = Math.ceil(max[0]);
3188
- var maxY = Math.ceil(max[1]);
3189
- var width = maxX - minX;
3190
- var height = maxY - minY;
3191
- return {
3192
- x: minX,
3193
- y: minY,
3194
- width: width,
3195
- height: height
3196
- };
3197
- }
3198
- /**
3199
- * TODO: merge dirty rectangles with some strategies.
3200
- * For now, we just simply merge all the rectangles into one.
3201
- * @see https://idom.me/articles/841.html
3202
- */;
3203
- _proto.mergeDirtyAABBs = function mergeDirtyAABBs(dirtyObjects) {
3204
- // merge into a big AABB
3205
- // TODO: skip descendant if ancestor is caculated, but compareNodePosition is really slow
3206
- var aabb = new gLite.AABB();
3207
- dirtyObjects.forEach(function (object) {
3208
- var renderBounds = object.getRenderBounds();
3209
- aabb.add(renderBounds);
3210
- var dirtyRenderBounds = object.renderable.dirtyRenderBounds;
3211
- if (dirtyRenderBounds) {
3212
- aabb.add(dirtyRenderBounds);
3213
- }
3214
- });
3215
- return aabb;
3216
- };
3217
- _proto.searchDirtyObjects = function searchDirtyObjects(dirtyRectangle) {
3218
- // search in r-tree, get all affected nodes
3219
- var _dirtyRectangle$getMi = dirtyRectangle.getMin(),
3220
- minX = _dirtyRectangle$getMi[0],
3221
- minY = _dirtyRectangle$getMi[1];
3222
- var _dirtyRectangle$getMa = dirtyRectangle.getMax(),
3223
- maxX = _dirtyRectangle$getMa[0],
3224
- maxY = _dirtyRectangle$getMa[1];
3225
- var rBushNodes = this.rBush.search({
3226
- minX: minX,
3227
- minY: minY,
3228
- maxX: maxX,
3229
- maxY: maxY
3230
- });
3231
- return rBushNodes.map(function (_ref2) {
3232
- var displayObject = _ref2.displayObject;
3233
- return displayObject;
3234
- });
3235
- };
3236
- _proto.saveDirtyAABB = function saveDirtyAABB(object) {
3237
- var renderable = object.renderable;
3238
- if (!renderable.dirtyRenderBounds) {
3239
- renderable.dirtyRenderBounds = new gLite.AABB();
3240
- }
3241
- var renderBounds = object.getRenderBounds();
3242
- if (renderBounds) {
3243
- // save last dirty aabb
3244
- renderable.dirtyRenderBounds.update(renderBounds.center, renderBounds.halfExtents);
3245
- }
3246
- }
3247
- /**
3248
- * TODO: batch the same global attributes
3249
- */;
3250
- _proto.applyAttributesToContext = function applyAttributesToContext(context, object) {
3251
- var _object$parsedStyle = object.parsedStyle,
3252
- stroke = _object$parsedStyle.stroke,
3253
- fill = _object$parsedStyle.fill,
3254
- opacity = _object$parsedStyle.opacity,
3255
- lineDash = _object$parsedStyle.lineDash,
3256
- lineDashOffset = _object$parsedStyle.lineDashOffset;
3257
- // @see https://developer.mozilla.org/zh-CN/docs/Web/API/CanvasRenderingContext2D/setLineDash
3258
- if (lineDash) {
3259
- context.setLineDash(lineDash);
3260
- }
3261
- // @see https://developer.mozilla.org/zh-CN/docs/Web/API/CanvasRenderingContext2D/lineDashOffset
3262
- if (!isNil(lineDashOffset)) {
3263
- context.lineDashOffset = lineDashOffset;
3264
- }
3265
- if (!isNil(opacity)) {
3266
- context.globalAlpha *= opacity;
3267
- }
3268
- if (!isNil(stroke) && !Array.isArray(stroke) && !stroke.isNone) {
3269
- context.strokeStyle = object.attributes.stroke;
3270
- }
3271
- if (!isNil(fill) && !Array.isArray(fill) && !fill.isNone) {
3272
- context.fillStyle = object.attributes.fill;
3273
- }
3274
- };
3275
- _proto.applyWorldTransform = function applyWorldTransform(context, object, matrix) {
3276
- var tx = 0;
3277
- var ty = 0;
3278
- var _ref3 = object.parsedStyle || {},
3279
- anchor = _ref3.anchor;
3280
- var anchorX = anchor && anchor[0] || 0;
3281
- var anchorY = anchor && anchor[1] || 0;
3282
- if (anchorX !== 0 || anchorY !== 0) {
3283
- // const bounds = object.getGeometryBounds();
3284
- var bounds = object.geometry.contentBounds;
3285
- var width = bounds && bounds.halfExtents[0] * 2 || 0;
3286
- var height = bounds && bounds.halfExtents[1] * 2 || 0;
3287
- tx = -(anchorX * width);
3288
- ty = -(anchorY * height);
3289
- }
3290
- // apply clip shape's RTS
3291
- if (matrix) {
3292
- copy(this.tmpMat4, object.getLocalTransform());
3293
- this.vec3a[0] = tx;
3294
- this.vec3a[1] = ty;
3295
- this.vec3a[2] = 0;
3296
- translate(this.tmpMat4, this.tmpMat4, this.vec3a);
3297
- multiply(this.tmpMat4, matrix, this.tmpMat4);
3298
- multiply(this.tmpMat4, this.vpMatrix, this.tmpMat4);
3299
- } else {
3300
- // apply RTS transformation in world space
3301
- copy(this.tmpMat4, object.getWorldTransform());
3302
- this.vec3a[0] = tx;
3303
- this.vec3a[1] = ty;
3304
- this.vec3a[2] = 0;
3305
- translate(this.tmpMat4, this.tmpMat4, this.vec3a);
3306
- multiply(this.tmpMat4, this.vpMatrix, this.tmpMat4);
3307
- }
3308
- // @see https://developer.mozilla.org/en-US/docs/Web/API/Canvas_API/Tutorial/Transformations
3309
- context.setTransform(this.tmpMat4[0], this.tmpMat4[1], this.tmpMat4[4], this.tmpMat4[5], this.tmpMat4[12], this.tmpMat4[13]);
3310
- };
3311
- _proto.safeMergeAABB = function safeMergeAABB() {
3312
- var merged = new gLite.AABB();
3313
- for (var _len = arguments.length, aabbs = new Array(_len), _key = 0; _key < _len; _key++) {
3314
- aabbs[_key] = arguments[_key];
3315
- }
3316
- aabbs.forEach(function (aabb) {
3317
- merged.add(aabb);
3318
- });
3319
- return merged;
3320
- };
3321
- return CanvasRendererPlugin;
3322
- }();
3323
- CanvasRendererPlugin.tag = 'CanvasRenderer';
3324
- var DefaultRenderer = /*#__PURE__*/function () {
3325
- function DefaultRenderer(imagePool) {
3326
- this.imagePool = void 0;
3327
- this.imagePool = imagePool;
3328
- }
3329
- var _proto = DefaultRenderer.prototype;
3330
- _proto.render = function render(context, parsedStyle, object, canvasContext, plugin, runtime) {
3331
- var fill = parsedStyle.fill,
3332
- fillRule = parsedStyle.fillRule,
3333
- opacity = parsedStyle.opacity,
3334
- fillOpacity = parsedStyle.fillOpacity,
3335
- stroke = parsedStyle.stroke,
3336
- strokeOpacity = parsedStyle.strokeOpacity,
3337
- lineWidth = parsedStyle.lineWidth,
3338
- lineCap = parsedStyle.lineCap,
3339
- lineJoin = parsedStyle.lineJoin,
3340
- shadowType = parsedStyle.shadowType,
3341
- shadowColor = parsedStyle.shadowColor,
3342
- shadowBlur = parsedStyle.shadowBlur,
3343
- filter = parsedStyle.filter,
3344
- miterLimit = parsedStyle.miterLimit;
3345
- var hasFill = !isNil(fill) && !fill.isNone;
3346
- var hasStroke = !isNil(stroke) && !stroke.isNone && lineWidth > 0;
3347
- var isFillTransparent = fill.alpha === 0;
3348
- var hasFilter = !!(filter && filter.length);
3349
- var hasShadow = !isNil(shadowColor) && shadowBlur > 0;
3350
- var nodeName = object.nodeName;
3351
- var isInnerShadow = shadowType === 'inner';
3352
- var shouldDrawShadowWithStroke = hasStroke && hasShadow && (nodeName === gLite.Shape.PATH || nodeName === gLite.Shape.LINE || nodeName === gLite.Shape.POLYLINE || isFillTransparent || isInnerShadow);
3353
- if (hasFill) {
3354
- context.globalAlpha = opacity * fillOpacity;
3355
- if (!shouldDrawShadowWithStroke) {
3356
- setShadowAndFilter(object, context, hasShadow);
3357
- }
3358
- this.fill(context, object, fill, fillRule, canvasContext, plugin, runtime);
3359
- if (!shouldDrawShadowWithStroke) {
3360
- this.clearShadowAndFilter(context, hasFilter, hasShadow);
3361
- }
3362
- }
3363
- if (hasStroke) {
3364
- context.globalAlpha = opacity * strokeOpacity;
3365
- context.lineWidth = lineWidth;
3366
- if (!isNil(miterLimit)) {
3367
- context.miterLimit = miterLimit;
3368
- }
3369
- if (!isNil(lineCap)) {
3370
- context.lineCap = lineCap;
3371
- }
3372
- if (!isNil(lineJoin)) {
3373
- context.lineJoin = lineJoin;
3374
- }
3375
- if (shouldDrawShadowWithStroke) {
3376
- if (isInnerShadow) {
3377
- context.globalCompositeOperation = 'source-atop';
3378
- }
3379
- setShadowAndFilter(object, context, true);
3380
- if (isInnerShadow) {
3381
- this.stroke(context, object, stroke, canvasContext, plugin, runtime);
3382
- context.globalCompositeOperation = 'source-over';
3383
- this.clearShadowAndFilter(context, hasFilter, true);
3384
- }
3385
- }
3386
- this.stroke(context, object, stroke, canvasContext, plugin, runtime);
3387
- }
3388
- };
3389
- _proto.clearShadowAndFilter = function clearShadowAndFilter(context, hasFilter, hasShadow) {
3390
- if (hasShadow) {
3391
- context.shadowColor = 'transparent';
3392
- context.shadowBlur = 0;
3393
- }
3394
- if (hasFilter) {
3395
- // save drop-shadow filter
3396
- var oldFilter = context.filter;
3397
- if (!isNil(oldFilter) && oldFilter.indexOf('drop-shadow') > -1) {
3398
- context.filter = oldFilter.replace(/drop-shadow\([^)]*\)/, '').trim() || 'none';
3399
- }
3400
- }
3401
- };
3402
- _proto.fill = function fill(context, object, _fill, fillRule, canvasContext, plugin, runtime) {
3403
- var _this = this;
3404
- if (Array.isArray(_fill)) {
3405
- _fill.forEach(function (gradient) {
3406
- context.fillStyle = _this.getColor(gradient, object, context);
3407
- fillRule ? context.fill(fillRule) : context.fill();
3408
- });
3409
- } else {
3410
- if (gLite.isPattern(_fill)) {
3411
- context.fillStyle = this.getPattern(_fill, object, context, canvasContext, plugin, runtime);
3412
- }
3413
- fillRule ? context.fill(fillRule) : context.fill();
3414
- }
3415
- };
3416
- _proto.stroke = function stroke(context, object, _stroke, canvasContext, plugin, runtime) {
3417
- var _this2 = this;
3418
- if (Array.isArray(_stroke)) {
3419
- _stroke.forEach(function (gradient) {
3420
- context.strokeStyle = _this2.getColor(gradient, object, context);
3421
- context.stroke();
3422
- });
3423
- } else {
3424
- if (gLite.isPattern(_stroke)) {
3425
- context.strokeStyle = this.getPattern(_stroke, object, context, canvasContext, plugin, runtime);
3426
- }
3427
- context.stroke();
3428
- }
3429
- };
3430
- _proto.getPattern = function getPattern(pattern, object, context, canvasContext, plugin, runtime) {
3431
- var $offscreenCanvas;
3432
- var dpr;
3433
- if (pattern.image.nodeName === 'rect') {
3434
- var _pattern$image$parsed = pattern.image.parsedStyle,
3435
- width = _pattern$image$parsed.width,
3436
- height = _pattern$image$parsed.height;
3437
- dpr = canvasContext.contextService.getDPR();
3438
- var offscreenCanvas = canvasContext.config.offscreenCanvas;
3439
- $offscreenCanvas = runtime.offscreenCanvas.getOrCreateCanvas(offscreenCanvas);
3440
- $offscreenCanvas.width = width * dpr;
3441
- $offscreenCanvas.height = height * dpr;
3442
- var offscreenCanvasContext = runtime.offscreenCanvas.getOrCreateContext(offscreenCanvas);
3443
- var restoreStack = [];
3444
- // offscreenCanvasContext.scale(1 / dpr, 1 / dpr);
3445
- pattern.image.forEach(function (object) {
3446
- plugin.renderDisplayObject(object, offscreenCanvasContext, canvasContext, restoreStack, runtime);
3447
- });
3448
- restoreStack.forEach(function () {
3449
- offscreenCanvasContext.restore();
3450
- });
3451
- }
3452
- var canvasPattern = this.imagePool.getOrCreatePatternSync(pattern, context, $offscreenCanvas, dpr, function () {
3453
- // set dirty rectangle flag
3454
- object.renderable.dirty = true;
3455
- canvasContext.renderingService.dirtify();
3456
- });
3457
- return canvasPattern;
3458
- };
3459
- _proto.getColor = function getColor(parsedColor, object, context) {
3460
- var color;
3461
- if (parsedColor.type === gLite.GradientType.LinearGradient || parsedColor.type === gLite.GradientType.RadialGradient) {
3462
- var bounds = object.getGeometryBounds();
3463
- var width = bounds && bounds.halfExtents[0] * 2 || 1;
3464
- var height = bounds && bounds.halfExtents[1] * 2 || 1;
3465
- color = this.imagePool.getOrCreateGradient(_extends({
3466
- type: parsedColor.type
3467
- }, parsedColor.value, {
3468
- width: width,
3469
- height: height
3470
- }), context);
3471
- }
3472
- return color;
3473
- };
3474
- return DefaultRenderer;
3475
- }();
3476
- /**
3477
- * apply before fill and stroke but only once
3478
- */
3479
- function setShadowAndFilter(object, context, hasShadow) {
3480
- var _object$parsedStyle = object.parsedStyle,
3481
- filter = _object$parsedStyle.filter,
3482
- shadowColor = _object$parsedStyle.shadowColor,
3483
- shadowBlur = _object$parsedStyle.shadowBlur,
3484
- shadowOffsetX = _object$parsedStyle.shadowOffsetX,
3485
- shadowOffsetY = _object$parsedStyle.shadowOffsetY;
3486
- if (filter && filter.length) {
3487
- // use raw filter string
3488
- context.filter = object.style.filter;
3489
- }
3490
- if (hasShadow) {
3491
- context.shadowColor = shadowColor.toString();
3492
- context.shadowBlur = shadowBlur || 0;
3493
- context.shadowOffsetX = shadowOffsetX || 0;
3494
- context.shadowOffsetY = shadowOffsetY || 0;
3495
- }
3496
- }
3497
- var ImageRenderer = /*#__PURE__*/function () {
3498
- function ImageRenderer(imagePool) {
3499
- this.imagePool = void 0;
3500
- this.imagePool = imagePool;
3501
- }
3502
- var _proto = ImageRenderer.prototype;
3503
- _proto.render = function render(context, parsedStyle, object) {
3504
- var width = parsedStyle.width,
3505
- height = parsedStyle.height,
3506
- img = parsedStyle.img,
3507
- shadowColor = parsedStyle.shadowColor,
3508
- shadowBlur = parsedStyle.shadowBlur;
3509
- var image;
3510
- var iw = width;
3511
- var ih = height;
3512
- if (isString(img)) {
3513
- // image has been loaded in `mounted` hook
3514
- image = this.imagePool.getImageSync(img);
3515
- } else {
3516
- iw || (iw = img.width);
3517
- ih || (ih = img.height);
3518
- image = img;
3519
- }
3520
- if (image) {
3521
- var hasShadow = !isNil(shadowColor) && shadowBlur > 0;
3522
- setShadowAndFilter(object, context, hasShadow);
3523
- // node-canvas will throw the following err:
3524
- // Error: Image given has not completed loading
3525
- try {
3526
- context.drawImage(image, 0, 0, iw, ih);
3527
- } catch (e) {}
3528
- }
3529
- };
3530
- return ImageRenderer;
3531
- }();
3532
- var TextRenderer = /*#__PURE__*/function () {
3533
- function TextRenderer() {}
3534
- var _proto = TextRenderer.prototype;
3535
- _proto.render = function render(context, parsedStyle, object) {
3536
- var lineWidth = parsedStyle.lineWidth,
3537
- textAlign = parsedStyle.textAlign,
3538
- textBaseline = parsedStyle.textBaseline,
3539
- lineJoin = parsedStyle.lineJoin,
3540
- miterLimit = parsedStyle.miterLimit,
3541
- letterSpacing = parsedStyle.letterSpacing,
3542
- stroke = parsedStyle.stroke,
3543
- fill = parsedStyle.fill,
3544
- fillOpacity = parsedStyle.fillOpacity,
3545
- strokeOpacity = parsedStyle.strokeOpacity,
3546
- opacity = parsedStyle.opacity,
3547
- metrics = parsedStyle.metrics,
3548
- dx = parsedStyle.dx,
3549
- dy = parsedStyle.dy,
3550
- shadowColor = parsedStyle.shadowColor,
3551
- shadowBlur = parsedStyle.shadowBlur;
3552
- var font = metrics.font,
3553
- lines = metrics.lines,
3554
- height = metrics.height,
3555
- lineHeight = metrics.lineHeight,
3556
- lineMetrics = metrics.lineMetrics;
3557
- context.font = font;
3558
- context.lineWidth = lineWidth;
3559
- context.textAlign = textAlign === 'middle' ? 'center' : textAlign;
3560
- var formattedTextBaseline = textBaseline;
3561
- if (
3562
- // formattedTextBaseline === 'bottom' ||
3563
- !gLite.runtime.enableCSSParsing && formattedTextBaseline === 'alphabetic') {
3564
- formattedTextBaseline = 'bottom';
3565
- }
3566
- context.lineJoin = lineJoin;
3567
- if (!isNil(miterLimit)) {
3568
- context.miterLimit = miterLimit;
3569
- }
3570
- var linePositionY = 0;
3571
- // handle vertical text baseline
3572
- if (textBaseline === 'middle') {
3573
- linePositionY = -height / 2 - lineHeight / 2;
3574
- } else if (textBaseline === 'bottom' || textBaseline === 'alphabetic' || textBaseline === 'ideographic') {
3575
- linePositionY = -height;
3576
- } else if (textBaseline === 'top' || textBaseline === 'hanging') {
3577
- linePositionY = -lineHeight;
3578
- }
3579
- // account for dx & dy
3580
- var offsetX = dx || 0;
3581
- linePositionY += dy || 0;
3582
- if (lines.length === 1) {
3583
- if (formattedTextBaseline === 'bottom') {
3584
- formattedTextBaseline = 'middle';
3585
- linePositionY -= 0.5 * height;
3586
- } else if (formattedTextBaseline === 'top') {
3587
- formattedTextBaseline = 'middle';
3588
- linePositionY += 0.5 * height;
3589
- }
3590
- }
3591
- context.textBaseline = formattedTextBaseline;
3592
- var hasShadow = !isNil(shadowColor) && shadowBlur > 0;
3593
- setShadowAndFilter(object, context, hasShadow);
3594
- // draw lines line by line
3595
- for (var i = 0; i < lines.length; i++) {
3596
- var linePositionX = lineWidth / 2 + offsetX;
3597
- linePositionY += lineHeight;
3598
- // no need to re-position X, cause we already set text align
3599
- // @see https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/textAlign
3600
- if (!isNil(stroke) && !stroke.isNone && lineWidth) {
3601
- this.drawLetterSpacing(context, lines[i], lineMetrics[i], textAlign, linePositionX, linePositionY, letterSpacing, fillOpacity, strokeOpacity, opacity, true);
3602
- }
3603
- if (!isNil(fill)) {
3604
- this.drawLetterSpacing(context, lines[i], lineMetrics[i], textAlign, linePositionX, linePositionY, letterSpacing, fillOpacity, strokeOpacity, opacity);
3605
- }
3606
- }
3607
- };
3608
- _proto.drawLetterSpacing = function drawLetterSpacing(context, text, lineMetrics, textAlign, x, y, letterSpacing, fillOpacity, strokeOpacity, opacity, isStroke) {
3609
- if (isStroke === void 0) {
3610
- isStroke = false;
3611
- }
3612
- // letterSpacing of 0 means normal, render all texts directly
3613
- if (letterSpacing === 0) {
3614
- if (isStroke) {
3615
- this.strokeText(context, text, x, y, strokeOpacity);
3616
- } else {
3617
- this.fillText(context, text, x, y, fillOpacity, opacity);
3618
- }
3619
- return;
3620
- }
3621
- // draw text using left align
3622
- var currentTextAlign = context.textAlign;
3623
- context.textAlign = 'left';
3624
- var currentPosition = x;
3625
- if (textAlign === 'center' || textAlign === 'middle') {
3626
- currentPosition = x - lineMetrics.width / 2;
3627
- } else if (textAlign === 'right' || textAlign === 'end') {
3628
- currentPosition = x - lineMetrics.width;
3629
- }
3630
- var stringArray = Array.from(text);
3631
- var previousWidth = context.measureText(text).width;
3632
- var currentWidth = 0;
3633
- for (var i = 0; i < stringArray.length; ++i) {
3634
- var currentChar = stringArray[i];
3635
- if (isStroke) {
3636
- this.strokeText(context, currentChar, currentPosition, y, strokeOpacity);
3637
- } else {
3638
- this.fillText(context, currentChar, currentPosition, y, fillOpacity, opacity);
3639
- }
3640
- currentWidth = context.measureText(text.substring(i + 1)).width;
3641
- currentPosition += previousWidth - currentWidth + letterSpacing;
3642
- previousWidth = currentWidth;
3643
- }
3644
- context.textAlign = currentTextAlign;
3645
- };
3646
- _proto.fillText = function fillText(context, text, x, y, fillOpacity, opacity) {
3647
- var currentGlobalAlpha;
3648
- var applyOpacity = !isNil(fillOpacity) && fillOpacity !== 1;
3649
- if (applyOpacity) {
3650
- currentGlobalAlpha = context.globalAlpha;
3651
- context.globalAlpha = fillOpacity * opacity;
3652
- }
3653
- context.fillText(text, x, y);
3654
- if (applyOpacity) {
3655
- context.globalAlpha = currentGlobalAlpha;
3656
- }
3657
- };
3658
- _proto.strokeText = function strokeText(context, text, x, y, strokeOpacity) {
3659
- var currentGlobalAlpha;
3660
- var applyOpacity = !isNil(strokeOpacity) && strokeOpacity !== 1;
3661
- if (applyOpacity) {
3662
- currentGlobalAlpha = context.globalAlpha;
3663
- context.globalAlpha = strokeOpacity;
3664
- }
3665
- context.strokeText(text, x, y);
3666
- if (applyOpacity) {
3667
- context.globalAlpha = currentGlobalAlpha;
3668
- }
3669
- };
3670
- return TextRenderer;
3671
- }();
3672
- var RectRenderer = /*#__PURE__*/function (_DefaultRenderer) {
3673
- _inheritsLoose$3(RectRenderer, _DefaultRenderer);
3674
- function RectRenderer() {
3675
- return _DefaultRenderer.apply(this, arguments) || this;
3676
- }
3677
- return RectRenderer;
3678
- }(DefaultRenderer);
3679
- var CircleRenderer = /*#__PURE__*/function (_DefaultRenderer) {
3680
- _inheritsLoose$3(CircleRenderer, _DefaultRenderer);
3681
- function CircleRenderer() {
3682
- return _DefaultRenderer.apply(this, arguments) || this;
3683
- }
3684
- return CircleRenderer;
3685
- }(DefaultRenderer);
3686
- var EllipseRenderer = /*#__PURE__*/function (_DefaultRenderer) {
3687
- _inheritsLoose$3(EllipseRenderer, _DefaultRenderer);
3688
- function EllipseRenderer() {
3689
- return _DefaultRenderer.apply(this, arguments) || this;
3690
- }
3691
- return EllipseRenderer;
3692
- }(DefaultRenderer);
3693
- var LineRenderer = /*#__PURE__*/function (_DefaultRenderer) {
3694
- _inheritsLoose$3(LineRenderer, _DefaultRenderer);
3695
- function LineRenderer() {
3696
- return _DefaultRenderer.apply(this, arguments) || this;
3697
- }
3698
- return LineRenderer;
3699
- }(DefaultRenderer);
3700
- var PolylineRenderer = /*#__PURE__*/function (_DefaultRenderer) {
3701
- _inheritsLoose$3(PolylineRenderer, _DefaultRenderer);
3702
- function PolylineRenderer() {
3703
- return _DefaultRenderer.apply(this, arguments) || this;
3704
- }
3705
- return PolylineRenderer;
3706
- }(DefaultRenderer);
3707
- var PolygonRenderer = /*#__PURE__*/function (_DefaultRenderer) {
3708
- _inheritsLoose$3(PolygonRenderer, _DefaultRenderer);
3709
- function PolygonRenderer() {
3710
- return _DefaultRenderer.apply(this, arguments) || this;
3711
- }
3712
- return PolygonRenderer;
3713
- }(DefaultRenderer);
3714
- var PathRenderer = /*#__PURE__*/function (_DefaultRenderer) {
3715
- _inheritsLoose$3(PathRenderer, _DefaultRenderer);
3716
- function PathRenderer() {
3717
- return _DefaultRenderer.apply(this, arguments) || this;
3718
- }
3719
- return PathRenderer;
3720
- }(DefaultRenderer);
3721
- var Plugin$2 = /*#__PURE__*/function (_AbstractRendererPlug) {
3722
- _inheritsLoose$3(Plugin, _AbstractRendererPlug);
3723
- function Plugin(options) {
3724
- var _this;
3725
- if (options === void 0) {
3726
- options = {};
3727
- }
3728
- _this = _AbstractRendererPlug.call(this) || this;
3729
- _this.options = void 0;
3730
- _this.name = 'canvas-renderer';
3731
- _this.options = options;
3732
- return _this;
3733
- }
3734
- var _proto = Plugin.prototype;
3735
- _proto.init = function init() {
3736
- var _defaultStyleRenderer;
3737
- var canvasRendererPluginOptions = _extends({
3738
- dirtyObjectNumThreshold: 500,
3739
- dirtyObjectRatioThreshold: 0.8
3740
- }, this.options);
3741
- // @ts-ignore
3742
- var imagePool = this.context.imagePool;
3743
- var defaultRenderer = new DefaultRenderer(imagePool);
3744
- var defaultStyleRendererFactory = (_defaultStyleRenderer = {}, _defaultStyleRenderer[gLite.Shape.CIRCLE] = defaultRenderer, _defaultStyleRenderer[gLite.Shape.ELLIPSE] = defaultRenderer, _defaultStyleRenderer[gLite.Shape.RECT] = defaultRenderer, _defaultStyleRenderer[gLite.Shape.IMAGE] = new ImageRenderer(imagePool), _defaultStyleRenderer[gLite.Shape.TEXT] = new TextRenderer(), _defaultStyleRenderer[gLite.Shape.LINE] = defaultRenderer, _defaultStyleRenderer[gLite.Shape.POLYLINE] = defaultRenderer, _defaultStyleRenderer[gLite.Shape.POLYGON] = defaultRenderer, _defaultStyleRenderer[gLite.Shape.PATH] = defaultRenderer, _defaultStyleRenderer[gLite.Shape.GROUP] = undefined, _defaultStyleRenderer[gLite.Shape.HTML] = undefined, _defaultStyleRenderer[gLite.Shape.MESH] = undefined, _defaultStyleRenderer);
3745
- this.context.defaultStyleRendererFactory = defaultStyleRendererFactory;
3746
- this.context.styleRendererFactory = defaultStyleRendererFactory;
3747
- this.addRenderingPlugin(new CanvasRendererPlugin(canvasRendererPluginOptions));
3748
- };
3749
- _proto.destroy = function destroy() {
3750
- this.removeAllRenderingPlugins();
3751
- delete this.context.defaultStyleRendererFactory;
3752
- delete this.context.styleRendererFactory;
3753
- };
3754
- return Plugin;
3755
- }(gLite.AbstractRendererPlugin);
3756
-
3757
- var index_esm$2 = /*#__PURE__*/Object.freeze({
3758
- __proto__: null,
3759
- CircleRenderer: CircleRenderer,
3760
- EllipseRenderer: EllipseRenderer,
3761
- ImageRenderer: ImageRenderer,
3762
- LineRenderer: LineRenderer,
3763
- PathRenderer: PathRenderer,
3764
- Plugin: Plugin$2,
3765
- PolygonRenderer: PolygonRenderer,
3766
- PolylineRenderer: PolylineRenderer,
3767
- RectRenderer: RectRenderer,
3768
- TextRenderer: TextRenderer
3769
- });
3770
-
3771
- function _inheritsLoose$4(subClass, superClass) {
3772
- subClass.prototype = Object.create(superClass.prototype);
3773
- subClass.prototype.constructor = subClass;
3774
- _setPrototypeOf$4(subClass, superClass);
3775
- }
3776
- function _setPrototypeOf$4(o, p) {
3777
- _setPrototypeOf$4 = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) {
3778
- o.__proto__ = p;
3779
- return o;
3780
- };
3781
- return _setPrototypeOf$4(o, p);
3782
- }
3783
-
3784
- // const MOBILE_REGEX = /mobile|tablet|ip(ad|hone|od)|android/i;
3785
- /**
3786
- * listen to mouse/touch/pointer events on DOM wrapper, trigger pointer events
3787
- */
3788
- var DOMInteractionPlugin = /*#__PURE__*/function () {
3789
- function DOMInteractionPlugin() {
3790
- this.context = void 0;
3791
- }
3792
- var _proto = DOMInteractionPlugin.prototype;
3793
- _proto.apply = function apply(context, runtime) {
3794
- var _this = this;
3795
- var renderingService = context.renderingService,
3796
- renderingContext = context.renderingContext,
3797
- config = context.config;
3798
- this.context = context;
3799
- var canvas = renderingContext.root.ownerDocument.defaultView;
3800
- // const SUPPORT_ONLY_TOUCH = canvas.supportsTouchEvents && MOBILE_REGEX.test(navigator.userAgent);
3801
- var onPointerMove = function onPointerMove(ev) {
3802
- renderingService.hooks.pointerMove.call(ev);
3803
- };
3804
- var onPointerUp = function onPointerUp(ev) {
3805
- renderingService.hooks.pointerUp.call(ev);
3806
- };
3807
- var onPointerDown = function onPointerDown(ev) {
3808
- renderingService.hooks.pointerDown.call(ev);
3809
- };
3810
- var onPointerOver = function onPointerOver(ev) {
3811
- renderingService.hooks.pointerOver.call(ev);
3812
- };
3813
- var onPointerOut = function onPointerOut(ev) {
3814
- renderingService.hooks.pointerOut.call(ev);
3815
- };
3816
- var onPointerCancel = function onPointerCancel(ev) {
3817
- renderingService.hooks.pointerCancel.call(ev);
3818
- };
3819
- var onPointerWheel = function onPointerWheel(ev) {
3820
- renderingService.hooks.pointerWheel.call(ev);
3821
- };
3822
- var onClick = function onClick(ev) {
3823
- renderingService.hooks.click.call(ev);
3824
- };
3825
- var addPointerEventListener = function addPointerEventListener($el) {
3826
- runtime.globalThis.document.addEventListener('pointermove', onPointerMove, true);
3827
- $el.addEventListener('pointerdown', onPointerDown, true);
3828
- $el.addEventListener('pointerleave', onPointerOut, true);
3829
- $el.addEventListener('pointerover', onPointerOver, true);
3830
- runtime.globalThis.addEventListener('pointerup', onPointerUp, true);
3831
- runtime.globalThis.addEventListener('pointercancel', onPointerCancel, true);
3832
- };
3833
- var addTouchEventListener = function addTouchEventListener($el) {
3834
- $el.addEventListener('touchstart', onPointerDown, true);
3835
- $el.addEventListener('touchend', onPointerUp, true);
3836
- $el.addEventListener('touchmove', onPointerMove, true);
3837
- $el.addEventListener('touchcancel', onPointerCancel, true);
3838
- };
3839
- var addMouseEventListener = function addMouseEventListener($el) {
3840
- runtime.globalThis.document.addEventListener('mousemove', onPointerMove, true);
3841
- $el.addEventListener('mousedown', onPointerDown, true);
3842
- $el.addEventListener('mouseout', onPointerOut, true);
3843
- $el.addEventListener('mouseover', onPointerOver, true);
3844
- runtime.globalThis.addEventListener('mouseup', onPointerUp, true);
3845
- };
3846
- var removePointerEventListener = function removePointerEventListener($el) {
3847
- runtime.globalThis.document.removeEventListener('pointermove', onPointerMove, true);
3848
- $el.removeEventListener('pointerdown', onPointerDown, true);
3849
- $el.removeEventListener('pointerleave', onPointerOut, true);
3850
- $el.removeEventListener('pointerover', onPointerOver, true);
3851
- runtime.globalThis.removeEventListener('pointerup', onPointerUp, true);
3852
- };
3853
- var removeTouchEventListener = function removeTouchEventListener($el) {
3854
- $el.removeEventListener('touchstart', onPointerDown, true);
3855
- $el.removeEventListener('touchend', onPointerUp, true);
3856
- $el.removeEventListener('touchmove', onPointerMove, true);
3857
- $el.removeEventListener('touchcancel', onPointerCancel, true);
3858
- };
3859
- var removeMouseEventListener = function removeMouseEventListener($el) {
3860
- runtime.globalThis.document.removeEventListener('mousemove', onPointerMove, true);
3861
- $el.removeEventListener('mousedown', onPointerDown, true);
3862
- $el.removeEventListener('mouseout', onPointerOut, true);
3863
- $el.removeEventListener('mouseover', onPointerOver, true);
3864
- runtime.globalThis.removeEventListener('mouseup', onPointerUp, true);
3865
- };
3866
- renderingService.hooks.init.tap(DOMInteractionPlugin.tag, function () {
3867
- var $el = _this.context.contextService.getDomElement();
3868
- // @ts-ignore
3869
- if (runtime.globalThis.navigator.msPointerEnabled) {
3870
- // @ts-ignore
3871
- $el.style.msContentZooming = 'none';
3872
- // @ts-ignore
3873
- $el.style.msTouchAction = 'none';
3874
- } else if (canvas.supportsPointerEvents) {
3875
- $el.style.touchAction = 'none';
3876
- }
3877
- if (canvas.supportsPointerEvents) {
3878
- addPointerEventListener($el);
3879
- } else {
3880
- addMouseEventListener($el);
3881
- }
3882
- if (canvas.supportsTouchEvents) {
3883
- addTouchEventListener($el);
3884
- }
3885
- if (config.useNativeClickEvent) {
3886
- $el.addEventListener('click', onClick, true);
3887
- }
3888
- // use passive event listeners
3889
- // @see https://zhuanlan.zhihu.com/p/24555031
3890
- $el.addEventListener('wheel', onPointerWheel, {
3891
- passive: true,
3892
- capture: true
3893
- });
3894
- });
3895
- renderingService.hooks.destroy.tap(DOMInteractionPlugin.tag, function () {
3896
- var $el = _this.context.contextService.getDomElement();
3897
- // @ts-ignore
3898
- if (runtime.globalThis.navigator.msPointerEnabled) {
3899
- // @ts-ignore
3900
- $el.style.msContentZooming = '';
3901
- // @ts-ignore
3902
- $el.style.msTouchAction = '';
3903
- } else if (canvas.supportsPointerEvents) {
3904
- $el.style.touchAction = '';
3905
- }
3906
- if (canvas.supportsPointerEvents) {
3907
- removePointerEventListener($el);
3908
- } else {
3909
- removeMouseEventListener($el);
3910
- }
3911
- if (canvas.supportsTouchEvents) {
3912
- removeTouchEventListener($el);
3913
- }
3914
- if (config.useNativeClickEvent) {
3915
- $el.removeEventListener('click', onClick, true);
3916
- }
3917
- $el.removeEventListener('wheel', onPointerWheel, true);
3918
- });
3919
- };
3920
- return DOMInteractionPlugin;
3921
- }();
3922
- DOMInteractionPlugin.tag = 'DOMInteraction';
3923
- var Plugin$3 = /*#__PURE__*/function (_AbstractRendererPlug) {
3924
- _inheritsLoose$4(Plugin, _AbstractRendererPlug);
3925
- function Plugin() {
3926
- var _this;
3927
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
3928
- args[_key] = arguments[_key];
3929
- }
3930
- _this = _AbstractRendererPlug.call.apply(_AbstractRendererPlug, [this].concat(args)) || this;
3931
- _this.name = 'dom-interaction';
3932
- return _this;
3933
- }
3934
- var _proto = Plugin.prototype;
3935
- _proto.init = function init() {
3936
- this.addRenderingPlugin(new DOMInteractionPlugin());
3937
- };
3938
- _proto.destroy = function destroy() {
3939
- this.removeAllRenderingPlugins();
3940
- };
3941
- return Plugin;
3942
- }(gLite.AbstractRendererPlugin);
3943
-
3944
- var index_esm$3 = /*#__PURE__*/Object.freeze({
3945
- __proto__: null,
3946
- Plugin: Plugin$3
3947
- });
3948
-
3949
- function _inheritsLoose$5(subClass, superClass) {
3950
- subClass.prototype = Object.create(superClass.prototype);
3951
- subClass.prototype.constructor = subClass;
3952
- _setPrototypeOf$5(subClass, superClass);
3953
- }
3954
- function _setPrototypeOf$5(o, p) {
3955
- _setPrototypeOf$5 = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) {
3956
- o.__proto__ = p;
3957
- return o;
3958
- };
3959
- return _setPrototypeOf$5(o, p);
3960
- }
3961
- var HTML_PREFIX = 'g-html-';
3962
- var CANVAS_CAMERA_ID = 'g-canvas-camera';
3963
- var HTMLRenderingPlugin = /*#__PURE__*/function () {
3964
- function HTMLRenderingPlugin() {
3965
- this.context = void 0;
3966
- /**
3967
- * wrapper for camera
3968
- */
3969
- this.$camera = void 0;
3970
- }
3971
- var _proto = HTMLRenderingPlugin.prototype;
3972
- _proto.joinTransformMatrix = function joinTransformMatrix(matrix) {
3973
- return "matrix(" + [matrix[0], matrix[1], matrix[4], matrix[5], matrix[12], matrix[13]].join(',') + ")";
3974
- };
3975
- _proto.apply = function apply(context) {
3976
- var _this = this;
3977
- var camera = context.camera,
3978
- renderingContext = context.renderingContext,
3979
- renderingService = context.renderingService;
3980
- this.context = context;
3981
- var canvas = renderingContext.root.ownerDocument.defaultView;
3982
- var setTransform = function setTransform(object, $el) {
3983
- $el.style.transform = _this.joinTransformMatrix(object.getWorldTransform());
3984
- };
3985
- var handleMounted = function handleMounted(e) {
3986
- var object = e.target;
3987
- if (object.nodeName === gLite.Shape.HTML) {
3988
- if (!_this.$camera) {
3989
- _this.$camera = _this.createCamera(camera);
3990
- }
3991
- // create DOM element
3992
- var $el = _this.getOrCreateEl(object);
3993
- _this.$camera.appendChild($el);
3994
- // apply documentElement's style
3995
- var attributes = object.ownerDocument.documentElement.attributes;
3996
- Object.keys(attributes).forEach(function (name) {
3997
- $el.style[name] = attributes[name];
3998
- });
3999
- Object.keys(object.attributes).forEach(function (name) {
4000
- _this.updateAttribute(name, object);
4001
- });
4002
- setTransform(object, $el);
4003
- gLite.runtime.nativeHTMLMap.set($el, object);
4004
- }
4005
- };
4006
- var handleUnmounted = function handleUnmounted(e) {
4007
- var object = e.target;
4008
- if (object.nodeName === gLite.Shape.HTML && _this.$camera) {
4009
- var $el = _this.getOrCreateEl(object);
4010
- if ($el) {
4011
- $el.remove();
4012
- gLite.runtime.nativeHTMLMap.delete($el);
4013
- }
4014
- // const existedId = this.getId(object);
4015
- // const $existedElement: HTMLElement | null = this.$camera.querySelector('#' + existedId);
4016
- // if ($existedElement) {
4017
- // this.$camera.removeChild($existedElement);
4018
- // }
4019
- }
4020
- };
4021
-
4022
- var handleAttributeChanged = function handleAttributeChanged(e) {
4023
- var object = e.target;
4024
- if (object.nodeName === gLite.Shape.HTML) {
4025
- var attrName = e.attrName;
4026
- _this.updateAttribute(attrName, object);
4027
- }
4028
- };
4029
- var handleBoundsChanged = function handleBoundsChanged(e) {
4030
- var object = e.target;
4031
- if (object.nodeName === gLite.Shape.HTML) {
4032
- var $el = _this.getOrCreateEl(object);
4033
- setTransform(object, $el);
4034
- }
4035
- };
4036
- var handleCanvasResize = function handleCanvasResize() {
4037
- if (_this.$camera) {
4038
- var _this$context$config = _this.context.config,
4039
- width = _this$context$config.width,
4040
- height = _this$context$config.height;
4041
- _this.$camera.style.width = (width || 0) + "px";
4042
- _this.$camera.style.height = (height || 0) + "px";
4043
- }
4044
- };
4045
- renderingService.hooks.init.tap(HTMLRenderingPlugin.tag, function () {
4046
- canvas.addEventListener(gLite.CanvasEvent.RESIZE, handleCanvasResize);
4047
- canvas.addEventListener(gLite.ElementEvent.MOUNTED, handleMounted);
4048
- canvas.addEventListener(gLite.ElementEvent.UNMOUNTED, handleUnmounted);
4049
- canvas.addEventListener(gLite.ElementEvent.ATTR_MODIFIED, handleAttributeChanged);
4050
- canvas.addEventListener(gLite.ElementEvent.BOUNDS_CHANGED, handleBoundsChanged);
4051
- });
4052
- renderingService.hooks.endFrame.tap(HTMLRenderingPlugin.tag, function () {
4053
- if (_this.$camera && renderingContext.renderReasons.has(gLite.RenderReason.CAMERA_CHANGED)) {
4054
- _this.$camera.style.transform = _this.joinTransformMatrix(camera.getOrthoMatrix());
4055
- }
4056
- });
4057
- renderingService.hooks.destroy.tap(HTMLRenderingPlugin.tag, function () {
4058
- // remove camera
4059
- if (_this.$camera) {
4060
- _this.$camera.remove();
4061
- }
4062
- canvas.removeEventListener(gLite.CanvasEvent.RESIZE, handleCanvasResize);
4063
- canvas.removeEventListener(gLite.ElementEvent.MOUNTED, handleMounted);
4064
- canvas.removeEventListener(gLite.ElementEvent.UNMOUNTED, handleUnmounted);
4065
- canvas.removeEventListener(gLite.ElementEvent.ATTR_MODIFIED, handleAttributeChanged);
4066
- canvas.removeEventListener(gLite.ElementEvent.BOUNDS_CHANGED, handleBoundsChanged);
4067
- });
4068
- };
4069
- _proto.getId = function getId(object) {
4070
- return object.id || HTML_PREFIX + object.entity;
4071
- };
4072
- _proto.createCamera = function createCamera(camera) {
4073
- var _this$context$config2 = this.context.config,
4074
- doc = _this$context$config2.document,
4075
- width = _this$context$config2.width,
4076
- height = _this$context$config2.height;
4077
- var $canvas = this.context.contextService.getDomElement();
4078
- var $container = $canvas.parentNode;
4079
- if ($container) {
4080
- var cameraId = CANVAS_CAMERA_ID;
4081
- var $existedCamera = $container.querySelector('#' + cameraId);
4082
- if (!$existedCamera) {
4083
- var $camera = (doc || document).createElement('div');
4084
- $existedCamera = $camera;
4085
- $camera.id = cameraId;
4086
- // use absolute position
4087
- $camera.style.position = 'absolute';
4088
- // account for DOM element's offset @see https://github.com/antvis/G/issues/1150
4089
- $camera.style.left = ($canvas.offsetLeft || 0) + "px";
4090
- $camera.style.top = ($canvas.offsetTop || 0) + "px";
4091
- $camera.style.transformOrigin = 'left top';
4092
- $camera.style.transform = this.joinTransformMatrix(camera.getOrthoMatrix());
4093
- // HTML elements should not overflow with canvas @see https://github.com/antvis/G/issues/1163
4094
- $camera.style.overflow = 'hidden';
4095
- $camera.style.pointerEvents = 'none';
4096
- $camera.style.width = (width || 0) + "px";
4097
- $camera.style.height = (height || 0) + "px";
4098
- $container.appendChild($camera);
4099
- }
4100
- return $existedCamera;
4101
- }
4102
- return null;
4103
- };
4104
- _proto.getOrCreateEl = function getOrCreateEl(object) {
4105
- var doc = this.context.config.document;
4106
- var existedId = this.getId(object);
4107
- var $existedElement = this.$camera.querySelector('#' + existedId);
4108
- if (!$existedElement) {
4109
- $existedElement = (doc || document).createElement('div');
4110
- object.parsedStyle.$el = $existedElement;
4111
- $existedElement.id = existedId;
4112
- if (object.name) {
4113
- $existedElement.setAttribute('name', object.name);
4114
- }
4115
- if (object.className) {
4116
- $existedElement.className = object.className;
4117
- }
4118
- // use absolute position
4119
- $existedElement.style.position = 'absolute';
4120
- // @see https://github.com/antvis/G/issues/1150
4121
- $existedElement.style.left = "0px";
4122
- $existedElement.style.top = "0px";
4123
- $existedElement.style['will-change'] = 'transform';
4124
- $existedElement.style.transform = this.joinTransformMatrix(object.getWorldTransform());
4125
- }
4126
- return $existedElement;
4127
- };
4128
- _proto.updateAttribute = function updateAttribute(name, object) {
4129
- var $el = this.getOrCreateEl(object);
4130
- switch (name) {
4131
- case 'innerHTML':
4132
- var innerHTML = object.parsedStyle.innerHTML;
4133
- if (isString(innerHTML)) {
4134
- $el.innerHTML = innerHTML;
4135
- } else {
4136
- $el.innerHTML = '';
4137
- $el.appendChild(innerHTML);
4138
- }
4139
- break;
4140
- case 'transformOrigin':
4141
- var transformOrigin = object.parsedStyle.transformOrigin;
4142
- $el.style['transform-origin'] = transformOrigin[0].value + " " + transformOrigin[1].value;
4143
- break;
4144
- case 'width':
4145
- if (gLite.runtime.enableCSSParsing) {
4146
- var width = object.computedStyleMap().get('width');
4147
- $el.style.width = width.toString();
4148
- } else {
4149
- var _width = object.parsedStyle.width;
4150
- $el.style.width = isNumber(_width) ? _width + "px" : _width.toString();
4151
- }
4152
- break;
4153
- case 'height':
4154
- if (gLite.runtime.enableCSSParsing) {
4155
- var height = object.computedStyleMap().get('height');
4156
- $el.style.height = height.toString();
4157
- } else {
4158
- var _height = object.parsedStyle.height;
4159
- $el.style.height = isNumber(_height) ? _height + "px" : _height.toString();
4160
- }
4161
- break;
4162
- case 'zIndex':
4163
- var zIndex = object.parsedStyle.zIndex;
4164
- $el.style['z-index'] = "" + zIndex;
4165
- break;
4166
- case 'visibility':
4167
- var visibility = object.parsedStyle.visibility;
4168
- $el.style.visibility = visibility;
4169
- break;
4170
- case 'pointerEvents':
4171
- var pointerEvents = object.parsedStyle.pointerEvents;
4172
- $el.style.pointerEvents = pointerEvents;
4173
- break;
4174
- case 'opacity':
4175
- var opacity = object.parsedStyle.opacity;
4176
- $el.style.opacity = "" + opacity;
4177
- break;
4178
- case 'fill':
4179
- var fill = object.parsedStyle.fill;
4180
- var color = '';
4181
- if (gLite.isCSSRGB(fill)) {
4182
- if (fill.isNone) {
4183
- color = 'transparent';
4184
- } else {
4185
- color = object.getAttribute('fill');
4186
- }
4187
- } else if (Array.isArray(fill)) {
4188
- color = object.getAttribute('fill');
4189
- } else if (gLite.isPattern(fill)) ;
4190
- $el.style.background = color;
4191
- break;
4192
- case 'stroke':
4193
- var stroke = object.parsedStyle.stroke;
4194
- var borderColor = '';
4195
- if (gLite.isCSSRGB(stroke)) {
4196
- if (stroke.isNone) {
4197
- borderColor = 'transparent';
4198
- } else {
4199
- borderColor = object.getAttribute('stroke');
4200
- }
4201
- } else if (Array.isArray(stroke)) {
4202
- borderColor = object.getAttribute('stroke');
4203
- } else if (gLite.isPattern(stroke)) ;
4204
- $el.style['border-color'] = borderColor;
4205
- $el.style['border-style'] = 'solid';
4206
- break;
4207
- case 'lineWidth':
4208
- var lineWidth = object.parsedStyle.lineWidth;
4209
- $el.style['border-width'] = (lineWidth || 0) + "px";
4210
- break;
4211
- case 'lineDash':
4212
- $el.style['border-style'] = 'dashed';
4213
- break;
4214
- case 'filter':
4215
- var filter = object.style.filter;
4216
- $el.style.filter = filter;
4217
- break;
4218
- }
4219
- };
4220
- return HTMLRenderingPlugin;
4221
- }();
4222
- HTMLRenderingPlugin.tag = 'HTMLRendering';
4223
- var Plugin$4 = /*#__PURE__*/function (_AbstractRendererPlug) {
4224
- _inheritsLoose$5(Plugin, _AbstractRendererPlug);
4225
- function Plugin() {
4226
- var _this;
4227
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
4228
- args[_key] = arguments[_key];
4229
- }
4230
- _this = _AbstractRendererPlug.call.apply(_AbstractRendererPlug, [this].concat(args)) || this;
4231
- _this.name = 'html-renderer';
4232
- return _this;
4233
- }
4234
- var _proto = Plugin.prototype;
4235
- _proto.init = function init() {
4236
- this.addRenderingPlugin(new HTMLRenderingPlugin());
4237
- };
4238
- _proto.destroy = function destroy() {
4239
- this.removeAllRenderingPlugins();
4240
- };
4241
- return Plugin;
4242
- }(gLite.AbstractRendererPlugin);
4243
-
4244
- var index_esm$4 = /*#__PURE__*/Object.freeze({
4245
- __proto__: null,
4246
- Plugin: Plugin$4
4247
- });
4248
-
4249
- function _inheritsLoose$6(subClass, superClass) {
4250
- subClass.prototype = Object.create(superClass.prototype);
4251
- subClass.prototype.constructor = subClass;
4252
- _setPrototypeOf$6(subClass, superClass);
4253
- }
4254
- function _setPrototypeOf$6(o, p) {
4255
- _setPrototypeOf$6 = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) {
4256
- o.__proto__ = p;
4257
- return o;
4258
- };
4259
- return _setPrototypeOf$6(o, p);
4260
- }
4261
-
4262
- /**
4263
- * Common utilities
4264
- * @module glMatrix
4265
- */
4266
- var ARRAY_TYPE$1 = typeof Float32Array !== 'undefined' ? Float32Array : Array;
4267
- if (!Math.hypot) Math.hypot = function () {
4268
- var y = 0,
4269
- i = arguments.length;
4270
- while (i--) {
4271
- y += arguments[i] * arguments[i];
4272
- }
4273
- return Math.sqrt(y);
4274
- };
4275
-
4276
- /**
4277
- * 4x4 Matrix<br>Format: column-major, when typed out it looks like row-major<br>The matrices are being post multiplied.
4278
- * @module mat4
4279
- */
4280
-
4281
- /**
4282
- * Creates a new identity mat4
4283
- *
4284
- * @returns {mat4} a new 4x4 matrix
4285
- */
4286
-
4287
- function create$3() {
4288
- var out = new ARRAY_TYPE$1(16);
4289
- if (ARRAY_TYPE$1 != Float32Array) {
4290
- out[1] = 0;
4291
- out[2] = 0;
4292
- out[3] = 0;
4293
- out[4] = 0;
4294
- out[6] = 0;
4295
- out[7] = 0;
4296
- out[8] = 0;
4297
- out[9] = 0;
4298
- out[11] = 0;
4299
- out[12] = 0;
4300
- out[13] = 0;
4301
- out[14] = 0;
4302
- }
4303
- out[0] = 1;
4304
- out[5] = 1;
4305
- out[10] = 1;
4306
- out[15] = 1;
4307
- return out;
4308
- }
4309
- /**
4310
- * Set a mat4 to the identity matrix
4311
- *
4312
- * @param {mat4} out the receiving matrix
4313
- * @returns {mat4} out
4314
- */
4315
-
4316
- function identity(out) {
4317
- out[0] = 1;
4318
- out[1] = 0;
4319
- out[2] = 0;
4320
- out[3] = 0;
4321
- out[4] = 0;
4322
- out[5] = 1;
4323
- out[6] = 0;
4324
- out[7] = 0;
4325
- out[8] = 0;
4326
- out[9] = 0;
4327
- out[10] = 1;
4328
- out[11] = 0;
4329
- out[12] = 0;
4330
- out[13] = 0;
4331
- out[14] = 0;
4332
- out[15] = 1;
4333
- return out;
4334
- }
4335
- /**
4336
- * Scales the mat4 by the dimensions in the given vec3 not using vectorization
4337
- *
4338
- * @param {mat4} out the receiving matrix
4339
- * @param {ReadonlyMat4} a the matrix to scale
4340
- * @param {ReadonlyVec3} v the vec3 to scale the matrix by
4341
- * @returns {mat4} out
4342
- **/
4343
-
4344
- function scale(out, a, v) {
4345
- var x = v[0],
4346
- y = v[1],
4347
- z = v[2];
4348
- out[0] = a[0] * x;
4349
- out[1] = a[1] * x;
4350
- out[2] = a[2] * x;
4351
- out[3] = a[3] * x;
4352
- out[4] = a[4] * y;
4353
- out[5] = a[5] * y;
4354
- out[6] = a[6] * y;
4355
- out[7] = a[7] * y;
4356
- out[8] = a[8] * z;
4357
- out[9] = a[9] * z;
4358
- out[10] = a[10] * z;
4359
- out[11] = a[11] * z;
4360
- out[12] = a[12];
4361
- out[13] = a[13];
4362
- out[14] = a[14];
4363
- out[15] = a[15];
4364
- return out;
4365
- }
4366
- var ImagePool = /*#__PURE__*/function () {
4367
- function ImagePool(canvasConfig) {
4368
- this.canvasConfig = void 0;
4369
- this.imageCache = {};
4370
- this.gradientCache = {};
4371
- this.patternCache = {};
4372
- this.canvasConfig = canvasConfig;
4373
- }
4374
- var _proto = ImagePool.prototype;
4375
- _proto.getImageSync = function getImageSync(src, callback) {
4376
- if (!this.imageCache[src]) {
4377
- this.getOrCreateImage(src).then(function () {
4378
- if (callback) {
4379
- callback();
4380
- }
4381
- });
4382
- } else {
4383
- if (callback) {
4384
- callback();
4385
- }
4386
- }
4387
- return this.imageCache[src];
4388
- };
4389
- _proto.getOrCreateImage = function getOrCreateImage(src) {
4390
- var _this = this;
4391
- if (this.imageCache[src]) {
4392
- return Promise.resolve(this.imageCache[src]);
4393
- }
4394
- // @see https://github.com/antvis/g/issues/938
4395
- var createImage = this.canvasConfig.createImage;
4396
- return new Promise(function (resolve, reject) {
4397
- var image;
4398
- if (createImage) {
4399
- image = createImage(src);
4400
- } else if (gLite.isBrowser) {
4401
- image = new window.Image();
4402
- }
4403
- if (image) {
4404
- image.onload = function () {
4405
- _this.imageCache[src] = image;
4406
- resolve(image);
4407
- };
4408
- image.onerror = function (ev) {
4409
- reject(ev);
4410
- };
4411
- image.crossOrigin = 'Anonymous';
4412
- image.src = src;
4413
- }
4414
- });
4415
- };
4416
- _proto.getOrCreatePatternSync = function getOrCreatePatternSync(pattern, context, $offscreenCanvas, dpr, callback) {
4417
- var patternKey = this.generatePatternKey(pattern);
4418
- if (patternKey && this.patternCache[patternKey]) {
4419
- return this.patternCache[patternKey];
4420
- }
4421
- var image = pattern.image,
4422
- repetition = pattern.repetition,
4423
- transform = pattern.transform;
4424
- var src;
4425
- var needScaleWithDPR = false;
4426
- // Image URL
4427
- if (isString(image)) {
4428
- src = this.getImageSync(image, callback);
4429
- } else if ($offscreenCanvas) {
4430
- src = $offscreenCanvas;
4431
- needScaleWithDPR = true;
4432
- } else {
4433
- src = image;
4434
- }
4435
- // @see https://developer.mozilla.org/zh-CN/docs/Web/API/CanvasRenderingContext2D/createPattern
4436
- var canvasPattern = src && context.createPattern(src, repetition);
4437
- if (canvasPattern) {
4438
- var mat;
4439
- // @see https://developer.mozilla.org/en-US/docs/Web/API/CanvasPattern/setTransform
4440
- if (transform) {
4441
- mat = gLite.parsedTransformToMat4(gLite.parseTransform(transform));
4442
- } else {
4443
- mat = identity(create$3());
4444
- }
4445
- if (needScaleWithDPR) {
4446
- scale(mat, mat, [1 / dpr, 1 / dpr, 1]);
4447
- }
4448
- canvasPattern.setTransform({
4449
- a: mat[0],
4450
- b: mat[1],
4451
- c: mat[4],
4452
- d: mat[5],
4453
- e: mat[12],
4454
- f: mat[13]
4455
- });
4456
- }
4457
- if (patternKey && canvasPattern) {
4458
- this.patternCache[patternKey] = canvasPattern;
4459
- }
4460
- return canvasPattern;
4461
- };
4462
- _proto.getOrCreateGradient = function getOrCreateGradient(params, context) {
4463
- var key = this.generateGradientKey(params);
4464
- var type = params.type,
4465
- steps = params.steps,
4466
- width = params.width,
4467
- height = params.height,
4468
- angle = params.angle,
4469
- cx = params.cx,
4470
- cy = params.cy,
4471
- size = params.size;
4472
- if (this.gradientCache[key]) {
4473
- return this.gradientCache[key];
4474
- }
4475
- var gradient = null;
4476
- if (type === gLite.GradientType.LinearGradient) {
4477
- var _computeLinearGradien = gLite.computeLinearGradient(width, height, angle),
4478
- x1 = _computeLinearGradien.x1,
4479
- y1 = _computeLinearGradien.y1,
4480
- x2 = _computeLinearGradien.x2,
4481
- y2 = _computeLinearGradien.y2;
4482
- // @see https://developer.mozilla.org/zh-CN/docs/Web/API/CanvasRenderingContext2D/createLinearGradient
4483
- gradient = context.createLinearGradient(x1, y1, x2, y2);
4484
- } else if (type === gLite.GradientType.RadialGradient) {
4485
- var _computeRadialGradien = gLite.computeRadialGradient(width, height, cx, cy, size),
4486
- x = _computeRadialGradien.x,
4487
- y = _computeRadialGradien.y,
4488
- r = _computeRadialGradien.r;
4489
- // @see https://developer.mozilla.org/zh-CN/docs/Web/API/CanvasRenderingContext2D/createRadialGradient
4490
- gradient = context.createRadialGradient(x, y, 0, x, y, r);
4491
- }
4492
- if (gradient) {
4493
- steps.forEach(function (_ref) {
4494
- var offset = _ref.offset,
4495
- color = _ref.color;
4496
- if (offset.unit === gLite.UnitType.kPercentage) {
4497
- var _gradient;
4498
- (_gradient = gradient) === null || _gradient === void 0 ? void 0 : _gradient.addColorStop(offset.value / 100, color.toString());
4499
- }
4500
- });
4501
- this.gradientCache[key] = gradient;
4502
- }
4503
- return this.gradientCache[key];
4504
- };
4505
- _proto.generateGradientKey = function generateGradientKey(params) {
4506
- var type = params.type,
4507
- width = params.width,
4508
- height = params.height,
4509
- steps = params.steps,
4510
- angle = params.angle,
4511
- cx = params.cx,
4512
- cy = params.cy,
4513
- size = params.size;
4514
- return "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 (_ref2) {
4515
- var offset = _ref2.offset,
4516
- color = _ref2.color;
4517
- return "" + offset + color;
4518
- }).join('-');
4519
- };
4520
- _proto.generatePatternKey = function generatePatternKey(pattern) {
4521
- var image = pattern.image,
4522
- repetition = pattern.repetition;
4523
- // only generate cache for Image
4524
- if (isString(image)) {
4525
- return "pattern-" + image + "-" + repetition;
4526
- } else if (image.nodeName === 'rect') {
4527
- return "pattern-" + image.entity + "-" + repetition;
4528
- }
4529
- };
4530
- return ImagePool;
4531
- }();
4532
- var LoadImagePlugin = /*#__PURE__*/function () {
4533
- function LoadImagePlugin() {}
4534
- var _proto = LoadImagePlugin.prototype;
4535
- _proto.apply = function apply(context) {
4536
- // @ts-ignore
4537
- var renderingService = context.renderingService,
4538
- renderingContext = context.renderingContext,
4539
- imagePool = context.imagePool;
4540
- var canvas = renderingContext.root.ownerDocument.defaultView;
4541
- var handleMounted = function handleMounted(e) {
4542
- var object = e.target;
4543
- var nodeName = object.nodeName,
4544
- attributes = object.attributes;
4545
- if (nodeName === gLite.Shape.IMAGE) {
4546
- var img = attributes.img;
4547
- if (isString(img)) {
4548
- imagePool.getImageSync(img, function () {
4549
- // set dirty rectangle flag
4550
- object.renderable.dirty = true;
4551
- renderingService.dirtify();
4552
- });
4553
- }
4554
- }
4555
- };
4556
- var handleAttributeChanged = function handleAttributeChanged(e) {
4557
- var object = e.target;
4558
- var attrName = e.attrName,
4559
- newValue = e.newValue;
4560
- if (object.nodeName === gLite.Shape.IMAGE) {
4561
- if (attrName === 'img') {
4562
- if (isString(newValue)) {
4563
- imagePool.getOrCreateImage(newValue).then(function () {
4564
- // set dirty rectangle flag
4565
- object.renderable.dirty = true;
4566
- renderingService.dirtify();
4567
- });
4568
- }
4569
- }
4570
- }
4571
- };
4572
- renderingService.hooks.init.tap(LoadImagePlugin.tag, function () {
4573
- canvas.addEventListener(gLite.ElementEvent.MOUNTED, handleMounted);
4574
- canvas.addEventListener(gLite.ElementEvent.ATTR_MODIFIED, handleAttributeChanged);
4575
- });
4576
- renderingService.hooks.destroy.tap(LoadImagePlugin.tag, function () {
4577
- canvas.removeEventListener(gLite.ElementEvent.MOUNTED, handleMounted);
4578
- canvas.removeEventListener(gLite.ElementEvent.ATTR_MODIFIED, handleAttributeChanged);
4579
- });
4580
- };
4581
- return LoadImagePlugin;
4582
- }();
4583
- LoadImagePlugin.tag = 'LoadImage';
4584
- var Plugin$5 = /*#__PURE__*/function (_AbstractRendererPlug) {
4585
- _inheritsLoose$6(Plugin, _AbstractRendererPlug);
4586
- function Plugin() {
4587
- var _this;
4588
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
4589
- args[_key] = arguments[_key];
4590
- }
4591
- _this = _AbstractRendererPlug.call.apply(_AbstractRendererPlug, [this].concat(args)) || this;
4592
- _this.name = 'image-loader';
4593
- return _this;
4594
- }
4595
- var _proto = Plugin.prototype;
4596
- _proto.init = function init() {
4597
- // @ts-ignore
4598
- this.context.imagePool = new ImagePool(this.context.config);
4599
- this.addRenderingPlugin(new LoadImagePlugin());
4600
- };
4601
- _proto.destroy = function destroy() {
4602
- this.removeAllRenderingPlugins();
4603
- };
4604
- return Plugin;
4605
- }(gLite.AbstractRendererPlugin);
4606
-
4607
- var index_esm$5 = /*#__PURE__*/Object.freeze({
4608
- __proto__: null,
4609
- ImagePool: ImagePool,
4610
- Plugin: Plugin$5
4611
- });
4612
-
4613
- var Canvas2DContextService = /*#__PURE__*/function () {
4614
- function Canvas2DContextService(context) {
4615
- this.$container = void 0;
4616
- this.$canvas = void 0;
4617
- this.dpr = void 0;
4618
- this.context = void 0;
4619
- this.canvasConfig = void 0;
4620
- this.renderingContext = void 0;
4621
- this.renderingContext = context.renderingContext;
4622
- this.canvasConfig = context.config;
4623
- }
4624
- var _proto = Canvas2DContextService.prototype;
4625
- _proto.init = function init() {
4626
- var _this$canvasConfig = this.canvasConfig,
4627
- container = _this$canvasConfig.container,
4628
- canvas = _this$canvasConfig.canvas;
4629
- if (canvas) {
4630
- this.$canvas = canvas;
4631
- if (container && canvas.parentElement !== container) {
4632
- container.appendChild(canvas);
4633
- }
4634
- this.$container = canvas.parentElement;
4635
- this.canvasConfig.container = this.$container;
4636
- } else if (container) {
4637
- // create container
4638
- this.$container = isString(container) ? document.getElementById(container) : container;
4639
- if (this.$container) {
4640
- // create canvas
4641
- var $canvas = document.createElement('canvas');
4642
- this.$container.appendChild($canvas);
4643
- if (!this.$container.style.position) {
4644
- this.$container.style.position = 'relative';
4645
- }
4646
- this.$canvas = $canvas;
4647
- }
4648
- }
4649
- this.context = this.$canvas.getContext('2d');
4650
- this.resize(this.canvasConfig.width, this.canvasConfig.height);
4651
- };
4652
- _proto.getContext = function getContext() {
4653
- return this.context;
4654
- };
4655
- _proto.getDomElement = function getDomElement() {
4656
- return this.$canvas;
4657
- };
4658
- _proto.getDPR = function getDPR() {
4659
- return this.dpr;
4660
- };
4661
- _proto.getBoundingClientRect = function getBoundingClientRect() {
4662
- if (this.$canvas.getBoundingClientRect) {
4663
- return this.$canvas.getBoundingClientRect();
4664
- }
4665
- };
4666
- _proto.destroy = function destroy() {
4667
- // @ts-ignore
4668
- if (this.$container && this.$canvas && this.$canvas.parentNode) {
4669
- // destroy context
4670
- // @ts-ignore
4671
- this.$container.removeChild(this.$canvas);
4672
- }
4673
- };
4674
- _proto.resize = function resize(width, height) {
4675
- var devicePixelRatio = this.canvasConfig.devicePixelRatio;
4676
- // use user-defined dpr first
4677
- var dpr = devicePixelRatio || gLite.isBrowser && window.devicePixelRatio || 1;
4678
- dpr = dpr >= 1 ? Math.ceil(dpr) : 1;
4679
- this.dpr = dpr;
4680
- if (this.$canvas) {
4681
- // set canvas width & height
4682
- this.$canvas.width = this.dpr * width;
4683
- this.$canvas.height = this.dpr * height;
4684
- // set CSS style width & height
4685
- gLite.setDOMSize(this.$canvas, width, height);
4686
- // const dpr = this.getDPR();
4687
- // scale all drawing operations by the dpr
4688
- // @see https://www.html5rocks.com/en/tutorials/canvas/hidpi/
4689
- // this.context.scale(dpr, dpr);
4690
- }
4691
-
4692
- this.renderingContext.renderReasons.add(gLite.RenderReason.CAMERA_CHANGED);
4693
- };
4694
- _proto.applyCursorStyle = function applyCursorStyle(cursor) {
4695
- if (this.$container && this.$container.style) {
4696
- this.$container.style.cursor = cursor;
4697
- }
4698
- };
4699
- _proto.toDataURL = /*#__PURE__*/function () {
4700
- var _toDataURL = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(options) {
4701
- var _options, type, encoderOptions;
4702
- return _regeneratorRuntime().wrap(function _callee$(_context) {
4703
- while (1) switch (_context.prev = _context.next) {
4704
- case 0:
4705
- if (options === void 0) {
4706
- options = {};
4707
- }
4708
- _options = options, type = _options.type, encoderOptions = _options.encoderOptions;
4709
- return _context.abrupt("return", this.context.canvas.toDataURL(type, encoderOptions));
4710
- case 3:
4711
- case "end":
4712
- return _context.stop();
4713
- }
4714
- }, _callee, this);
4715
- }));
4716
- function toDataURL(_x) {
4717
- return _toDataURL.apply(this, arguments);
4718
- }
4719
- return toDataURL;
4720
- }();
4721
- return Canvas2DContextService;
4722
- }();
4723
-
4724
- var ContextRegisterPlugin = /*#__PURE__*/function (_AbstractRendererPlug) {
4725
- _inheritsLoose(ContextRegisterPlugin, _AbstractRendererPlug);
4726
- function ContextRegisterPlugin() {
4727
- var _this;
4728
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
4729
- args[_key] = arguments[_key];
4730
- }
4731
- _this = _AbstractRendererPlug.call.apply(_AbstractRendererPlug, [this].concat(args)) || this;
4732
- _this.name = 'canvas-context-register';
4733
- return _this;
4734
- }
4735
- var _proto = ContextRegisterPlugin.prototype;
4736
- _proto.init = function init() {
4737
- this.context.ContextService = Canvas2DContextService;
4738
- };
4739
- _proto.destroy = function destroy() {
4740
- delete this.context.ContextService;
4741
- };
4742
- return ContextRegisterPlugin;
4743
- }(gLite.AbstractRendererPlugin);
4744
-
4745
- var Renderer = /*#__PURE__*/function (_AbstractRenderer) {
4746
- _inheritsLoose(Renderer, _AbstractRenderer);
4747
- function Renderer(config) {
4748
- var _this;
4749
- _this = _AbstractRenderer.call(this, config) || this;
4750
- // register Canvas2DContext
4751
- _this.registerPlugin(new ContextRegisterPlugin());
4752
- _this.registerPlugin(new Plugin$5());
4753
- _this.registerPlugin(new Plugin());
4754
- // enable rendering with Canvas2D API
4755
- _this.registerPlugin(new Plugin$2());
4756
- _this.registerPlugin(new Plugin$3());
4757
- // enable picking with Canvas2D API
4758
- _this.registerPlugin(new Plugin$1());
4759
- // render HTML component
4760
- _this.registerPlugin(new Plugin$4());
4761
- return _this;
4762
- }
4763
- return Renderer;
4764
- }(gLite.AbstractRenderer);
4765
-
4766
- exports.CanvasPathGenerator = index_esm;
4767
- exports.CanvasPicker = index_esm$1;
4768
- exports.CanvasRenderer = index_esm$2;
4769
- exports.DomInteraction = index_esm$3;
4770
- exports.HTMLRenderer = index_esm$4;
4771
- exports.ImageLoader = index_esm$5;
4772
- exports.Renderer = Renderer;
4773
-
4774
- Object.defineProperty(exports, '__esModule', { value: true });
4775
-
4776
- })));