@antv/g-canvas 1.1.7 → 1.1.8-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -3,37 +3,395 @@
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var g = require('@antv/g');
6
- var DomInteraction = require('@antv/g-plugin-dom-interaction');
7
- var CanvasRenderer = require('@antv/g-plugin-canvas-renderer');
6
+ var CanvasPathGenerator = require('@antv/g-plugin-canvas-path-generator');
8
7
  var CanvasPicker = require('@antv/g-plugin-canvas-picker');
8
+ var CanvasRenderer = require('@antv/g-plugin-canvas-renderer');
9
+ var DomInteraction = require('@antv/g-plugin-dom-interaction');
9
10
  var HTMLRenderer = require('@antv/g-plugin-html-renderer');
11
+ var ImageLoader = require('@antv/g-plugin-image-loader');
10
12
  var manaSyringe = require('mana-syringe');
11
13
  var tslib = require('tslib');
12
14
 
13
- function _interopNamespace(e) {
14
- if (e && e.__esModule) return e;
15
- var n = Object.create(null);
16
- if (e) {
17
- Object.keys(e).forEach(function (k) {
18
- if (k !== 'default') {
19
- var d = Object.getOwnPropertyDescriptor(e, k);
20
- Object.defineProperty(n, k, d.get ? d : {
21
- enumerable: true,
22
- get: function () {
23
- return e[k];
15
+ function _regeneratorRuntime() {
16
+ /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */
17
+
18
+ _regeneratorRuntime = function () {
19
+ return exports;
20
+ };
21
+
22
+ var exports = {},
23
+ Op = Object.prototype,
24
+ hasOwn = Op.hasOwnProperty,
25
+ $Symbol = "function" == typeof Symbol ? Symbol : {},
26
+ iteratorSymbol = $Symbol.iterator || "@@iterator",
27
+ asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator",
28
+ toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag";
29
+
30
+ function define(obj, key, value) {
31
+ return Object.defineProperty(obj, key, {
32
+ value: value,
33
+ enumerable: !0,
34
+ configurable: !0,
35
+ writable: !0
36
+ }), obj[key];
37
+ }
38
+
39
+ try {
40
+ define({}, "");
41
+ } catch (err) {
42
+ define = function (obj, key, value) {
43
+ return obj[key] = value;
44
+ };
45
+ }
46
+
47
+ function wrap(innerFn, outerFn, self, tryLocsList) {
48
+ var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator,
49
+ generator = Object.create(protoGenerator.prototype),
50
+ context = new Context(tryLocsList || []);
51
+ return generator._invoke = function (innerFn, self, context) {
52
+ var state = "suspendedStart";
53
+ return function (method, arg) {
54
+ if ("executing" === state) throw new Error("Generator is already running");
55
+
56
+ if ("completed" === state) {
57
+ if ("throw" === method) throw arg;
58
+ return doneResult();
59
+ }
60
+
61
+ for (context.method = method, context.arg = arg;;) {
62
+ var delegate = context.delegate;
63
+
64
+ if (delegate) {
65
+ var delegateResult = maybeInvokeDelegate(delegate, context);
66
+
67
+ if (delegateResult) {
68
+ if (delegateResult === ContinueSentinel) continue;
69
+ return delegateResult;
70
+ }
71
+ }
72
+
73
+ if ("next" === context.method) context.sent = context._sent = context.arg;else if ("throw" === context.method) {
74
+ if ("suspendedStart" === state) throw state = "completed", context.arg;
75
+ context.dispatchException(context.arg);
76
+ } else "return" === context.method && context.abrupt("return", context.arg);
77
+ state = "executing";
78
+ var record = tryCatch(innerFn, self, context);
79
+
80
+ if ("normal" === record.type) {
81
+ if (state = context.done ? "completed" : "suspendedYield", record.arg === ContinueSentinel) continue;
82
+ return {
83
+ value: record.arg,
84
+ done: context.done
85
+ };
24
86
  }
87
+
88
+ "throw" === record.type && (state = "completed", context.method = "throw", context.arg = record.arg);
89
+ }
90
+ };
91
+ }(innerFn, self, context), generator;
92
+ }
93
+
94
+ function tryCatch(fn, obj, arg) {
95
+ try {
96
+ return {
97
+ type: "normal",
98
+ arg: fn.call(obj, arg)
99
+ };
100
+ } catch (err) {
101
+ return {
102
+ type: "throw",
103
+ arg: err
104
+ };
105
+ }
106
+ }
107
+
108
+ exports.wrap = wrap;
109
+ var ContinueSentinel = {};
110
+
111
+ function Generator() {}
112
+
113
+ function GeneratorFunction() {}
114
+
115
+ function GeneratorFunctionPrototype() {}
116
+
117
+ var IteratorPrototype = {};
118
+ define(IteratorPrototype, iteratorSymbol, function () {
119
+ return this;
120
+ });
121
+ var getProto = Object.getPrototypeOf,
122
+ NativeIteratorPrototype = getProto && getProto(getProto(values([])));
123
+ NativeIteratorPrototype && NativeIteratorPrototype !== Op && hasOwn.call(NativeIteratorPrototype, iteratorSymbol) && (IteratorPrototype = NativeIteratorPrototype);
124
+ var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(IteratorPrototype);
125
+
126
+ function defineIteratorMethods(prototype) {
127
+ ["next", "throw", "return"].forEach(function (method) {
128
+ define(prototype, method, function (arg) {
129
+ return this._invoke(method, arg);
130
+ });
131
+ });
132
+ }
133
+
134
+ function AsyncIterator(generator, PromiseImpl) {
135
+ function invoke(method, arg, resolve, reject) {
136
+ var record = tryCatch(generator[method], generator, arg);
137
+
138
+ if ("throw" !== record.type) {
139
+ var result = record.arg,
140
+ value = result.value;
141
+ return value && "object" == typeof value && hasOwn.call(value, "__await") ? PromiseImpl.resolve(value.__await).then(function (value) {
142
+ invoke("next", value, resolve, reject);
143
+ }, function (err) {
144
+ invoke("throw", err, resolve, reject);
145
+ }) : PromiseImpl.resolve(value).then(function (unwrapped) {
146
+ result.value = unwrapped, resolve(result);
147
+ }, function (error) {
148
+ return invoke("throw", error, resolve, reject);
149
+ });
150
+ }
151
+
152
+ reject(record.arg);
153
+ }
154
+
155
+ var previousPromise;
156
+
157
+ this._invoke = function (method, arg) {
158
+ function callInvokeWithMethodAndArg() {
159
+ return new PromiseImpl(function (resolve, reject) {
160
+ invoke(method, arg, resolve, reject);
25
161
  });
26
162
  }
163
+
164
+ return previousPromise = previousPromise ? previousPromise.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg();
165
+ };
166
+ }
167
+
168
+ function maybeInvokeDelegate(delegate, context) {
169
+ var method = delegate.iterator[context.method];
170
+
171
+ if (undefined === method) {
172
+ if (context.delegate = null, "throw" === context.method) {
173
+ if (delegate.iterator.return && (context.method = "return", context.arg = undefined, maybeInvokeDelegate(delegate, context), "throw" === context.method)) return ContinueSentinel;
174
+ context.method = "throw", context.arg = new TypeError("The iterator does not provide a 'throw' method");
175
+ }
176
+
177
+ return ContinueSentinel;
178
+ }
179
+
180
+ var record = tryCatch(method, delegate.iterator, context.arg);
181
+ if ("throw" === record.type) return context.method = "throw", context.arg = record.arg, context.delegate = null, ContinueSentinel;
182
+ var info = record.arg;
183
+ 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);
184
+ }
185
+
186
+ function pushTryEntry(locs) {
187
+ var entry = {
188
+ tryLoc: locs[0]
189
+ };
190
+ 1 in locs && (entry.catchLoc = locs[1]), 2 in locs && (entry.finallyLoc = locs[2], entry.afterLoc = locs[3]), this.tryEntries.push(entry);
191
+ }
192
+
193
+ function resetTryEntry(entry) {
194
+ var record = entry.completion || {};
195
+ record.type = "normal", delete record.arg, entry.completion = record;
196
+ }
197
+
198
+ function Context(tryLocsList) {
199
+ this.tryEntries = [{
200
+ tryLoc: "root"
201
+ }], tryLocsList.forEach(pushTryEntry, this), this.reset(!0);
202
+ }
203
+
204
+ function values(iterable) {
205
+ if (iterable) {
206
+ var iteratorMethod = iterable[iteratorSymbol];
207
+ if (iteratorMethod) return iteratorMethod.call(iterable);
208
+ if ("function" == typeof iterable.next) return iterable;
209
+
210
+ if (!isNaN(iterable.length)) {
211
+ var i = -1,
212
+ next = function next() {
213
+ for (; ++i < iterable.length;) if (hasOwn.call(iterable, i)) return next.value = iterable[i], next.done = !1, next;
214
+
215
+ return next.value = undefined, next.done = !0, next;
216
+ };
217
+
218
+ return next.next = next;
219
+ }
220
+ }
221
+
222
+ return {
223
+ next: doneResult
224
+ };
225
+ }
226
+
227
+ function doneResult() {
228
+ return {
229
+ value: undefined,
230
+ done: !0
231
+ };
232
+ }
233
+
234
+ return GeneratorFunction.prototype = GeneratorFunctionPrototype, define(Gp, "constructor", GeneratorFunctionPrototype), define(GeneratorFunctionPrototype, "constructor", GeneratorFunction), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, toStringTagSymbol, "GeneratorFunction"), exports.isGeneratorFunction = function (genFun) {
235
+ var ctor = "function" == typeof genFun && genFun.constructor;
236
+ return !!ctor && (ctor === GeneratorFunction || "GeneratorFunction" === (ctor.displayName || ctor.name));
237
+ }, exports.mark = function (genFun) {
238
+ return Object.setPrototypeOf ? Object.setPrototypeOf(genFun, GeneratorFunctionPrototype) : (genFun.__proto__ = GeneratorFunctionPrototype, define(genFun, toStringTagSymbol, "GeneratorFunction")), genFun.prototype = Object.create(Gp), genFun;
239
+ }, exports.awrap = function (arg) {
240
+ return {
241
+ __await: arg
242
+ };
243
+ }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, asyncIteratorSymbol, function () {
244
+ return this;
245
+ }), exports.AsyncIterator = AsyncIterator, exports.async = function (innerFn, outerFn, self, tryLocsList, PromiseImpl) {
246
+ void 0 === PromiseImpl && (PromiseImpl = Promise);
247
+ var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList), PromiseImpl);
248
+ return exports.isGeneratorFunction(outerFn) ? iter : iter.next().then(function (result) {
249
+ return result.done ? result.value : iter.next();
27
250
  });
251
+ }, defineIteratorMethods(Gp), define(Gp, toStringTagSymbol, "Generator"), define(Gp, iteratorSymbol, function () {
252
+ return this;
253
+ }), define(Gp, "toString", function () {
254
+ return "[object Generator]";
255
+ }), exports.keys = function (object) {
256
+ var keys = [];
257
+
258
+ for (var key in object) keys.push(key);
259
+
260
+ return keys.reverse(), function next() {
261
+ for (; keys.length;) {
262
+ var key = keys.pop();
263
+ if (key in object) return next.value = key, next.done = !1, next;
264
+ }
265
+
266
+ return next.done = !0, next;
267
+ };
268
+ }, exports.values = values, Context.prototype = {
269
+ constructor: Context,
270
+ reset: function (skipTempReset) {
271
+ 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);
272
+ },
273
+ stop: function () {
274
+ this.done = !0;
275
+ var rootRecord = this.tryEntries[0].completion;
276
+ if ("throw" === rootRecord.type) throw rootRecord.arg;
277
+ return this.rval;
278
+ },
279
+ dispatchException: function (exception) {
280
+ if (this.done) throw exception;
281
+ var context = this;
282
+
283
+ function handle(loc, caught) {
284
+ return record.type = "throw", record.arg = exception, context.next = loc, caught && (context.method = "next", context.arg = undefined), !!caught;
285
+ }
286
+
287
+ for (var i = this.tryEntries.length - 1; i >= 0; --i) {
288
+ var entry = this.tryEntries[i],
289
+ record = entry.completion;
290
+ if ("root" === entry.tryLoc) return handle("end");
291
+
292
+ if (entry.tryLoc <= this.prev) {
293
+ var hasCatch = hasOwn.call(entry, "catchLoc"),
294
+ hasFinally = hasOwn.call(entry, "finallyLoc");
295
+
296
+ if (hasCatch && hasFinally) {
297
+ if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0);
298
+ if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc);
299
+ } else if (hasCatch) {
300
+ if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0);
301
+ } else {
302
+ if (!hasFinally) throw new Error("try statement without catch or finally");
303
+ if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc);
304
+ }
305
+ }
306
+ }
307
+ },
308
+ abrupt: function (type, arg) {
309
+ for (var i = this.tryEntries.length - 1; i >= 0; --i) {
310
+ var entry = this.tryEntries[i];
311
+
312
+ if (entry.tryLoc <= this.prev && hasOwn.call(entry, "finallyLoc") && this.prev < entry.finallyLoc) {
313
+ var finallyEntry = entry;
314
+ break;
315
+ }
316
+ }
317
+
318
+ finallyEntry && ("break" === type || "continue" === type) && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc && (finallyEntry = null);
319
+ var record = finallyEntry ? finallyEntry.completion : {};
320
+ return record.type = type, record.arg = arg, finallyEntry ? (this.method = "next", this.next = finallyEntry.finallyLoc, ContinueSentinel) : this.complete(record);
321
+ },
322
+ complete: function (record, afterLoc) {
323
+ if ("throw" === record.type) throw record.arg;
324
+ 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;
325
+ },
326
+ finish: function (finallyLoc) {
327
+ for (var i = this.tryEntries.length - 1; i >= 0; --i) {
328
+ var entry = this.tryEntries[i];
329
+ if (entry.finallyLoc === finallyLoc) return this.complete(entry.completion, entry.afterLoc), resetTryEntry(entry), ContinueSentinel;
330
+ }
331
+ },
332
+ catch: function (tryLoc) {
333
+ for (var i = this.tryEntries.length - 1; i >= 0; --i) {
334
+ var entry = this.tryEntries[i];
335
+
336
+ if (entry.tryLoc === tryLoc) {
337
+ var record = entry.completion;
338
+
339
+ if ("throw" === record.type) {
340
+ var thrown = record.arg;
341
+ resetTryEntry(entry);
342
+ }
343
+
344
+ return thrown;
345
+ }
346
+ }
347
+
348
+ throw new Error("illegal catch attempt");
349
+ },
350
+ delegateYield: function (iterable, resultName, nextLoc) {
351
+ return this.delegate = {
352
+ iterator: values(iterable),
353
+ resultName: resultName,
354
+ nextLoc: nextLoc
355
+ }, "next" === this.method && (this.arg = undefined), ContinueSentinel;
356
+ }
357
+ }, exports;
358
+ }
359
+
360
+ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
361
+ try {
362
+ var info = gen[key](arg);
363
+ var value = info.value;
364
+ } catch (error) {
365
+ reject(error);
366
+ return;
367
+ }
368
+
369
+ if (info.done) {
370
+ resolve(value);
371
+ } else {
372
+ Promise.resolve(value).then(_next, _throw);
28
373
  }
29
- n['default'] = e;
30
- return Object.freeze(n);
31
374
  }
32
375
 
33
- var DomInteraction__namespace = /*#__PURE__*/_interopNamespace(DomInteraction);
34
- var CanvasRenderer__namespace = /*#__PURE__*/_interopNamespace(CanvasRenderer);
35
- var CanvasPicker__namespace = /*#__PURE__*/_interopNamespace(CanvasPicker);
36
- var HTMLRenderer__namespace = /*#__PURE__*/_interopNamespace(HTMLRenderer);
376
+ function _asyncToGenerator(fn) {
377
+ return function () {
378
+ var self = this,
379
+ args = arguments;
380
+ return new Promise(function (resolve, reject) {
381
+ var gen = fn.apply(self, args);
382
+
383
+ function _next(value) {
384
+ asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
385
+ }
386
+
387
+ function _throw(err) {
388
+ asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
389
+ }
390
+
391
+ _next(undefined);
392
+ });
393
+ };
394
+ }
37
395
 
38
396
  function _inheritsLoose(subClass, superClass) {
39
397
  subClass.prototype = Object.create(superClass.prototype);
@@ -62,45 +420,63 @@ var Canvas2DContextService = /*#__PURE__*/function () {
62
420
 
63
421
  var _proto = Canvas2DContextService.prototype;
64
422
 
65
- _proto.init = function init() {
66
- var _this$canvasConfig = this.canvasConfig,
67
- container = _this$canvasConfig.container,
68
- canvas = _this$canvasConfig.canvas,
69
- devicePixelRatio = _this$canvasConfig.devicePixelRatio;
423
+ _proto.init = /*#__PURE__*/function () {
424
+ var _init = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
425
+ var _this$canvasConfig, container, canvas, devicePixelRatio, $canvas, dpr;
70
426
 
71
- if (canvas) {
72
- this.$canvas = canvas;
427
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
428
+ while (1) {
429
+ switch (_context.prev = _context.next) {
430
+ case 0:
431
+ _this$canvasConfig = this.canvasConfig, container = _this$canvasConfig.container, canvas = _this$canvasConfig.canvas, devicePixelRatio = _this$canvasConfig.devicePixelRatio;
73
432
 
74
- if (container && canvas.parentElement !== container) {
75
- container.appendChild(canvas);
76
- }
433
+ if (canvas) {
434
+ this.$canvas = canvas;
435
+
436
+ if (container && canvas.parentElement !== container) {
437
+ container.appendChild(canvas);
438
+ }
439
+
440
+ this.$container = canvas.parentElement;
441
+ this.canvasConfig.container = this.$container;
442
+ } else if (container) {
443
+ // create container
444
+ this.$container = g.isString(container) ? document.getElementById(container) : container;
445
+
446
+ if (this.$container) {
447
+ // create canvas
448
+ $canvas = document.createElement('canvas');
449
+ this.$container.appendChild($canvas);
450
+
451
+ if (!this.$container.style.position) {
452
+ this.$container.style.position = 'relative';
453
+ }
454
+
455
+ this.$canvas = $canvas;
456
+ }
457
+ }
77
458
 
78
- this.$container = canvas.parentElement;
79
- this.canvasConfig.container = this.$container;
80
- } else if (container) {
81
- // create container
82
- this.$container = g.isString(container) ? document.getElementById(container) : container;
459
+ this.context = this.$canvas.getContext('2d'); // use user-defined dpr first
83
460
 
84
- if (this.$container) {
85
- // create canvas
86
- var $canvas = document.createElement('canvas');
87
- this.$container.appendChild($canvas);
461
+ dpr = devicePixelRatio || g.isBrowser && window.devicePixelRatio || 1;
462
+ dpr = dpr >= 1 ? Math.ceil(dpr) : 1;
463
+ this.dpr = dpr;
464
+ this.resize(this.canvasConfig.width, this.canvasConfig.height);
88
465
 
89
- if (!this.$container.style.position) {
90
- this.$container.style.position = 'relative';
466
+ case 7:
467
+ case "end":
468
+ return _context.stop();
469
+ }
91
470
  }
471
+ }, _callee, this);
472
+ }));
92
473
 
93
- this.$canvas = $canvas;
94
- }
474
+ function init() {
475
+ return _init.apply(this, arguments);
95
476
  }
96
477
 
97
- this.context = this.$canvas.getContext('2d'); // use user-defined dpr first
98
-
99
- var dpr = devicePixelRatio || g.isBrowser && window.devicePixelRatio || 1;
100
- dpr = dpr >= 1 ? Math.ceil(dpr) : 1;
101
- this.dpr = dpr;
102
- this.resize(this.canvasConfig.width, this.canvasConfig.height);
103
- };
478
+ return init;
479
+ }();
104
480
 
105
481
  _proto.getContext = function getContext() {
106
482
  return this.context;
@@ -190,7 +566,11 @@ var Renderer = /*#__PURE__*/function (_AbstractRenderer) {
190
566
 
191
567
  _this = _AbstractRenderer.call(this, config) || this; // register Canvas2DContext
192
568
 
193
- _this.registerPlugin(new ContextRegisterPlugin()); // enable rendering with Canvas2D API
569
+ _this.registerPlugin(new ContextRegisterPlugin());
570
+
571
+ _this.registerPlugin(new ImageLoader.Plugin());
572
+
573
+ _this.registerPlugin(new CanvasPathGenerator.Plugin()); // enable rendering with Canvas2D API
194
574
 
195
575
 
196
576
  _this.registerPlugin(new CanvasRenderer.Plugin());
@@ -209,8 +589,4 @@ var Renderer = /*#__PURE__*/function (_AbstractRenderer) {
209
589
  return Renderer;
210
590
  }(g.AbstractRenderer);
211
591
 
212
- exports.DomInteraction = DomInteraction__namespace;
213
- exports.CanvasRenderer = CanvasRenderer__namespace;
214
- exports.CanvasPicker = CanvasPicker__namespace;
215
- exports.HTMLRenderer = HTMLRenderer__namespace;
216
592
  exports.Renderer = Renderer;