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

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