@antv/g-canvas 1.9.18 → 1.9.20

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
@@ -173,14 +173,9 @@ function _regeneratorRuntime() {
173
173
  };
174
174
  }
175
175
  function maybeInvokeDelegate(delegate, context) {
176
- var method = delegate.iterator[context.method];
177
- if (undefined === method) {
178
- if (context.delegate = null, "throw" === context.method) {
179
- if (delegate.iterator.return && (context.method = "return", context.arg = undefined, maybeInvokeDelegate(delegate, context), "throw" === context.method)) return ContinueSentinel;
180
- context.method = "throw", context.arg = new TypeError("The iterator does not provide a 'throw' method");
181
- }
182
- return ContinueSentinel;
183
- }
176
+ var methodName = context.method,
177
+ method = delegate.iterator[methodName];
178
+ 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;
184
179
  var record = tryCatch(method, delegate.iterator, context.arg);
185
180
  if ("throw" === record.type) return context.method = "throw", context.arg = record.arg, context.delegate = null, ContinueSentinel;
186
181
  var info = record.arg;
@@ -374,10 +369,49 @@ function _asyncToGenerator(fn) {
374
369
  });
375
370
  };
376
371
  }
377
- function _inheritsLoose(subClass, superClass) {
378
- subClass.prototype = Object.create(superClass.prototype);
379
- subClass.prototype.constructor = subClass;
380
- _setPrototypeOf(subClass, superClass);
372
+ function _classCallCheck(instance, Constructor) {
373
+ if (!(instance instanceof Constructor)) {
374
+ throw new TypeError("Cannot call a class as a function");
375
+ }
376
+ }
377
+ function _defineProperties(target, props) {
378
+ for (var i = 0; i < props.length; i++) {
379
+ var descriptor = props[i];
380
+ descriptor.enumerable = descriptor.enumerable || false;
381
+ descriptor.configurable = true;
382
+ if ("value" in descriptor) descriptor.writable = true;
383
+ Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor);
384
+ }
385
+ }
386
+ function _createClass(Constructor, protoProps, staticProps) {
387
+ if (protoProps) _defineProperties(Constructor.prototype, protoProps);
388
+ if (staticProps) _defineProperties(Constructor, staticProps);
389
+ Object.defineProperty(Constructor, "prototype", {
390
+ writable: false
391
+ });
392
+ return Constructor;
393
+ }
394
+ function _inherits(subClass, superClass) {
395
+ if (typeof superClass !== "function" && superClass !== null) {
396
+ throw new TypeError("Super expression must either be null or a function");
397
+ }
398
+ subClass.prototype = Object.create(superClass && superClass.prototype, {
399
+ constructor: {
400
+ value: subClass,
401
+ writable: true,
402
+ configurable: true
403
+ }
404
+ });
405
+ Object.defineProperty(subClass, "prototype", {
406
+ writable: false
407
+ });
408
+ if (superClass) _setPrototypeOf(subClass, superClass);
409
+ }
410
+ function _getPrototypeOf(o) {
411
+ _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) {
412
+ return o.__proto__ || Object.getPrototypeOf(o);
413
+ };
414
+ return _getPrototypeOf(o);
381
415
  }
382
416
  function _setPrototypeOf(o, p) {
383
417
  _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) {
@@ -386,9 +420,63 @@ function _setPrototypeOf(o, p) {
386
420
  };
387
421
  return _setPrototypeOf(o, p);
388
422
  }
423
+ function _isNativeReflectConstruct() {
424
+ if (typeof Reflect === "undefined" || !Reflect.construct) return false;
425
+ if (Reflect.construct.sham) return false;
426
+ if (typeof Proxy === "function") return true;
427
+ try {
428
+ Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {}));
429
+ return true;
430
+ } catch (e) {
431
+ return false;
432
+ }
433
+ }
434
+ function _assertThisInitialized(self) {
435
+ if (self === void 0) {
436
+ throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
437
+ }
438
+ return self;
439
+ }
440
+ function _possibleConstructorReturn(self, call) {
441
+ if (call && (typeof call === "object" || typeof call === "function")) {
442
+ return call;
443
+ } else if (call !== void 0) {
444
+ throw new TypeError("Derived constructors may only return object or undefined");
445
+ }
446
+ return _assertThisInitialized(self);
447
+ }
448
+ function _createSuper(Derived) {
449
+ var hasNativeReflectConstruct = _isNativeReflectConstruct();
450
+ return function _createSuperInternal() {
451
+ var Super = _getPrototypeOf(Derived),
452
+ result;
453
+ if (hasNativeReflectConstruct) {
454
+ var NewTarget = _getPrototypeOf(this).constructor;
455
+ result = Reflect.construct(Super, arguments, NewTarget);
456
+ } else {
457
+ result = Super.apply(this, arguments);
458
+ }
459
+ return _possibleConstructorReturn(this, result);
460
+ };
461
+ }
462
+ function _toPrimitive(input, hint) {
463
+ if (typeof input !== "object" || input === null) return input;
464
+ var prim = input[Symbol.toPrimitive];
465
+ if (prim !== undefined) {
466
+ var res = prim.call(input, hint || "default");
467
+ if (typeof res !== "object") return res;
468
+ throw new TypeError("@@toPrimitive must return a primitive value.");
469
+ }
470
+ return (hint === "string" ? String : Number)(input);
471
+ }
472
+ function _toPropertyKey(arg) {
473
+ var key = _toPrimitive(arg, "string");
474
+ return typeof key === "symbol" ? key : String(key);
475
+ }
389
476
 
390
477
  var Canvas2DContextService = /*#__PURE__*/function () {
391
478
  function Canvas2DContextService(context) {
479
+ _classCallCheck(this, Canvas2DContextService);
392
480
  this.$container = void 0;
393
481
  this.$canvas = void 0;
394
482
  this.dpr = void 0;
@@ -398,149 +486,176 @@ var Canvas2DContextService = /*#__PURE__*/function () {
398
486
  this.renderingContext = context.renderingContext;
399
487
  this.canvasConfig = context.config;
400
488
  }
401
- var _proto = Canvas2DContextService.prototype;
402
- _proto.init = /*#__PURE__*/function () {
403
- var _init = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
404
- var _this$canvasConfig, container, canvas, $canvas;
405
- return _regeneratorRuntime().wrap(function _callee$(_context) {
406
- while (1) {
407
- switch (_context.prev = _context.next) {
408
- case 0:
409
- _this$canvasConfig = this.canvasConfig, container = _this$canvasConfig.container, canvas = _this$canvasConfig.canvas;
410
- if (canvas) {
411
- this.$canvas = canvas;
412
- if (container && canvas.parentElement !== container) {
413
- container.appendChild(canvas);
414
- }
415
- this.$container = canvas.parentElement;
416
- this.canvasConfig.container = this.$container;
417
- } else if (container) {
418
- // create container
419
- this.$container = util.isString(container) ? document.getElementById(container) : container;
420
- if (this.$container) {
421
- // create canvas
422
- $canvas = document.createElement('canvas');
423
- this.$container.appendChild($canvas);
424
- if (!this.$container.style.position) {
425
- this.$container.style.position = 'relative';
489
+ _createClass(Canvas2DContextService, [{
490
+ key: "init",
491
+ value: function () {
492
+ var _init = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
493
+ var _this$canvasConfig, container, canvas, $canvas;
494
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
495
+ while (1) {
496
+ switch (_context.prev = _context.next) {
497
+ case 0:
498
+ _this$canvasConfig = this.canvasConfig, container = _this$canvasConfig.container, canvas = _this$canvasConfig.canvas;
499
+ if (canvas) {
500
+ this.$canvas = canvas;
501
+ if (container && canvas.parentElement !== container) {
502
+ container.appendChild(canvas);
503
+ }
504
+ this.$container = canvas.parentElement;
505
+ this.canvasConfig.container = this.$container;
506
+ } else if (container) {
507
+ // create container
508
+ this.$container = util.isString(container) ? document.getElementById(container) : container;
509
+ if (this.$container) {
510
+ // create canvas
511
+ $canvas = document.createElement('canvas');
512
+ this.$container.appendChild($canvas);
513
+ if (!this.$container.style.position) {
514
+ this.$container.style.position = 'relative';
515
+ }
516
+ this.$canvas = $canvas;
426
517
  }
427
- this.$canvas = $canvas;
428
518
  }
429
- }
430
- this.context = this.$canvas.getContext('2d');
431
- this.resize(this.canvasConfig.width, this.canvasConfig.height);
432
- case 4:
433
- case "end":
434
- return _context.stop();
519
+ this.context = this.$canvas.getContext('2d');
520
+ this.resize(this.canvasConfig.width, this.canvasConfig.height);
521
+ case 4:
522
+ case "end":
523
+ return _context.stop();
524
+ }
435
525
  }
436
- }
437
- }, _callee, this);
438
- }));
439
- function init() {
440
- return _init.apply(this, arguments);
526
+ }, _callee, this);
527
+ }));
528
+ function init() {
529
+ return _init.apply(this, arguments);
530
+ }
531
+ return init;
532
+ }()
533
+ }, {
534
+ key: "getContext",
535
+ value: function getContext() {
536
+ return this.context;
441
537
  }
442
- return init;
443
- }();
444
- _proto.getContext = function getContext() {
445
- return this.context;
446
- };
447
- _proto.getDomElement = function getDomElement() {
448
- return this.$canvas;
449
- };
450
- _proto.getDPR = function getDPR() {
451
- return this.dpr;
452
- };
453
- _proto.getBoundingClientRect = function getBoundingClientRect() {
454
- if (this.$canvas.getBoundingClientRect) {
455
- return this.$canvas.getBoundingClientRect();
538
+ }, {
539
+ key: "getDomElement",
540
+ value: function getDomElement() {
541
+ return this.$canvas;
456
542
  }
457
- };
458
- _proto.destroy = function destroy() {
459
- // @ts-ignore
460
- if (this.$container && this.$canvas && this.$canvas.parentNode) {
461
- // destroy context
462
- // @ts-ignore
463
- this.$container.removeChild(this.$canvas);
543
+ }, {
544
+ key: "getDPR",
545
+ value: function getDPR() {
546
+ return this.dpr;
464
547
  }
465
- };
466
- _proto.resize = function resize(width, height) {
467
- var devicePixelRatio = this.canvasConfig.devicePixelRatio;
468
- // use user-defined dpr first
469
- var dpr = devicePixelRatio || gLite.isBrowser && window.devicePixelRatio || 1;
470
- dpr = dpr >= 1 ? Math.ceil(dpr) : 1;
471
- this.dpr = dpr;
472
- if (this.$canvas) {
473
- // set canvas width & height
474
- this.$canvas.width = this.dpr * width;
475
- this.$canvas.height = this.dpr * height;
476
- // set CSS style width & height
477
- gLite.setDOMSize(this.$canvas, width, height);
478
- // const dpr = this.getDPR();
479
- // scale all drawing operations by the dpr
480
- // @see https://www.html5rocks.com/en/tutorials/canvas/hidpi/
481
- // this.context.scale(dpr, dpr);
548
+ }, {
549
+ key: "getBoundingClientRect",
550
+ value: function getBoundingClientRect() {
551
+ if (this.$canvas.getBoundingClientRect) {
552
+ return this.$canvas.getBoundingClientRect();
553
+ }
554
+ }
555
+ }, {
556
+ key: "destroy",
557
+ value: function destroy() {
558
+ // @ts-ignore
559
+ if (this.$container && this.$canvas && this.$canvas.parentNode) {
560
+ // destroy context
561
+ // @ts-ignore
562
+ this.$container.removeChild(this.$canvas);
563
+ }
482
564
  }
565
+ }, {
566
+ key: "resize",
567
+ value: function resize(width, height) {
568
+ var devicePixelRatio = this.canvasConfig.devicePixelRatio;
569
+ // use user-defined dpr first
570
+ var dpr = devicePixelRatio || gLite.isBrowser && window.devicePixelRatio || 1;
571
+ dpr = dpr >= 1 ? Math.ceil(dpr) : 1;
572
+ this.dpr = dpr;
573
+ if (this.$canvas) {
574
+ // set canvas width & height
575
+ this.$canvas.width = this.dpr * width;
576
+ this.$canvas.height = this.dpr * height;
577
+ // set CSS style width & height
578
+ gLite.setDOMSize(this.$canvas, width, height);
579
+ // const dpr = this.getDPR();
580
+ // scale all drawing operations by the dpr
581
+ // @see https://www.html5rocks.com/en/tutorials/canvas/hidpi/
582
+ // this.context.scale(dpr, dpr);
583
+ }
483
584
 
484
- this.renderingContext.renderReasons.add(gLite.RenderReason.CAMERA_CHANGED);
485
- };
486
- _proto.applyCursorStyle = function applyCursorStyle(cursor) {
487
- if (this.$container && this.$container.style) {
488
- this.$container.style.cursor = cursor;
585
+ this.renderingContext.renderReasons.add(gLite.RenderReason.CAMERA_CHANGED);
489
586
  }
490
- };
491
- _proto.toDataURL = /*#__PURE__*/function () {
492
- var _toDataURL = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(options) {
493
- var _options, type, encoderOptions;
494
- return _regeneratorRuntime().wrap(function _callee2$(_context2) {
495
- while (1) {
496
- switch (_context2.prev = _context2.next) {
497
- case 0:
498
- if (options === void 0) {
499
- options = {};
500
- }
501
- _options = options, type = _options.type, encoderOptions = _options.encoderOptions;
502
- return _context2.abrupt("return", this.context.canvas.toDataURL(type, encoderOptions));
503
- case 3:
504
- case "end":
505
- return _context2.stop();
506
- }
507
- }
508
- }, _callee2, this);
509
- }));
510
- function toDataURL(_x) {
511
- return _toDataURL.apply(this, arguments);
587
+ }, {
588
+ key: "applyCursorStyle",
589
+ value: function applyCursorStyle(cursor) {
590
+ if (this.$container && this.$container.style) {
591
+ this.$container.style.cursor = cursor;
592
+ }
512
593
  }
513
- return toDataURL;
514
- }();
594
+ }, {
595
+ key: "toDataURL",
596
+ value: function () {
597
+ var _toDataURL = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
598
+ var options,
599
+ type,
600
+ encoderOptions,
601
+ _args2 = arguments;
602
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
603
+ while (1) {
604
+ switch (_context2.prev = _context2.next) {
605
+ case 0:
606
+ options = _args2.length > 0 && _args2[0] !== undefined ? _args2[0] : {};
607
+ type = options.type, encoderOptions = options.encoderOptions;
608
+ return _context2.abrupt("return", this.context.canvas.toDataURL(type, encoderOptions));
609
+ case 3:
610
+ case "end":
611
+ return _context2.stop();
612
+ }
613
+ }
614
+ }, _callee2, this);
615
+ }));
616
+ function toDataURL() {
617
+ return _toDataURL.apply(this, arguments);
618
+ }
619
+ return toDataURL;
620
+ }()
621
+ }]);
515
622
  return Canvas2DContextService;
516
623
  }();
517
624
 
518
625
  var ContextRegisterPlugin = /*#__PURE__*/function (_AbstractRendererPlug) {
519
- _inheritsLoose(ContextRegisterPlugin, _AbstractRendererPlug);
626
+ _inherits(ContextRegisterPlugin, _AbstractRendererPlug);
627
+ var _super = _createSuper(ContextRegisterPlugin);
520
628
  function ContextRegisterPlugin() {
521
629
  var _this;
630
+ _classCallCheck(this, ContextRegisterPlugin);
522
631
  for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
523
632
  args[_key] = arguments[_key];
524
633
  }
525
- _this = _AbstractRendererPlug.call.apply(_AbstractRendererPlug, [this].concat(args)) || this;
634
+ _this = _super.call.apply(_super, [this].concat(args));
526
635
  _this.name = 'canvas-context-register';
527
636
  return _this;
528
637
  }
529
- var _proto = ContextRegisterPlugin.prototype;
530
- _proto.init = function init() {
531
- this.context.ContextService = Canvas2DContextService;
532
- };
533
- _proto.destroy = function destroy() {
534
- delete this.context.ContextService;
535
- };
638
+ _createClass(ContextRegisterPlugin, [{
639
+ key: "init",
640
+ value: function init() {
641
+ this.context.ContextService = Canvas2DContextService;
642
+ }
643
+ }, {
644
+ key: "destroy",
645
+ value: function destroy() {
646
+ delete this.context.ContextService;
647
+ }
648
+ }]);
536
649
  return ContextRegisterPlugin;
537
650
  }(gLite.AbstractRendererPlugin);
538
651
 
539
652
  var Renderer = /*#__PURE__*/function (_AbstractRenderer) {
540
- _inheritsLoose(Renderer, _AbstractRenderer);
653
+ _inherits(Renderer, _AbstractRenderer);
654
+ var _super = _createSuper(Renderer);
541
655
  function Renderer(config) {
542
656
  var _this;
543
- _this = _AbstractRenderer.call(this, config) || this;
657
+ _classCallCheck(this, Renderer);
658
+ _this = _super.call(this, config);
544
659
  // register Canvas2DContext
545
660
  _this.registerPlugin(new ContextRegisterPlugin());
546
661
  _this.registerPlugin(new ImageLoader.Plugin());
@@ -554,7 +669,7 @@ var Renderer = /*#__PURE__*/function (_AbstractRenderer) {
554
669
  _this.registerPlugin(new HTMLRenderer.Plugin());
555
670
  return _this;
556
671
  }
557
- return Renderer;
672
+ return _createClass(Renderer);
558
673
  }(gLite.AbstractRenderer);
559
674
 
560
675
  exports.CanvasPathGenerator = CanvasPathGenerator__namespace;