@antv/g-canvas 1.2.0 → 1.2.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.esm.js CHANGED
@@ -400,24 +400,118 @@ function _asyncToGenerator(fn) {
400
400
  };
401
401
  }
402
402
 
403
- function _inheritsLoose(subClass, superClass) {
404
- subClass.prototype = Object.create(superClass.prototype);
405
- subClass.prototype.constructor = subClass;
403
+ function _classCallCheck(instance, Constructor) {
404
+ if (!(instance instanceof Constructor)) {
405
+ throw new TypeError("Cannot call a class as a function");
406
+ }
407
+ }
408
+
409
+ function _defineProperties(target, props) {
410
+ for (var i = 0; i < props.length; i++) {
411
+ var descriptor = props[i];
412
+ descriptor.enumerable = descriptor.enumerable || false;
413
+ descriptor.configurable = true;
414
+ if ("value" in descriptor) descriptor.writable = true;
415
+ Object.defineProperty(target, descriptor.key, descriptor);
416
+ }
417
+ }
418
+
419
+ function _createClass(Constructor, protoProps, staticProps) {
420
+ if (protoProps) _defineProperties(Constructor.prototype, protoProps);
421
+ if (staticProps) _defineProperties(Constructor, staticProps);
422
+ Object.defineProperty(Constructor, "prototype", {
423
+ writable: false
424
+ });
425
+ return Constructor;
426
+ }
427
+
428
+ function _inherits(subClass, superClass) {
429
+ if (typeof superClass !== "function" && superClass !== null) {
430
+ throw new TypeError("Super expression must either be null or a function");
431
+ }
406
432
 
407
- _setPrototypeOf(subClass, superClass);
433
+ subClass.prototype = Object.create(superClass && superClass.prototype, {
434
+ constructor: {
435
+ value: subClass,
436
+ writable: true,
437
+ configurable: true
438
+ }
439
+ });
440
+ Object.defineProperty(subClass, "prototype", {
441
+ writable: false
442
+ });
443
+ if (superClass) _setPrototypeOf(subClass, superClass);
444
+ }
445
+
446
+ function _getPrototypeOf(o) {
447
+ _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) {
448
+ return o.__proto__ || Object.getPrototypeOf(o);
449
+ };
450
+ return _getPrototypeOf(o);
408
451
  }
409
452
 
410
453
  function _setPrototypeOf(o, p) {
411
- _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) {
454
+ _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) {
412
455
  o.__proto__ = p;
413
456
  return o;
414
457
  };
415
-
416
458
  return _setPrototypeOf(o, p);
417
459
  }
418
460
 
461
+ function _isNativeReflectConstruct() {
462
+ if (typeof Reflect === "undefined" || !Reflect.construct) return false;
463
+ if (Reflect.construct.sham) return false;
464
+ if (typeof Proxy === "function") return true;
465
+
466
+ try {
467
+ Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {}));
468
+ return true;
469
+ } catch (e) {
470
+ return false;
471
+ }
472
+ }
473
+
474
+ function _assertThisInitialized(self) {
475
+ if (self === void 0) {
476
+ throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
477
+ }
478
+
479
+ return self;
480
+ }
481
+
482
+ function _possibleConstructorReturn(self, call) {
483
+ if (call && (typeof call === "object" || typeof call === "function")) {
484
+ return call;
485
+ } else if (call !== void 0) {
486
+ throw new TypeError("Derived constructors may only return object or undefined");
487
+ }
488
+
489
+ return _assertThisInitialized(self);
490
+ }
491
+
492
+ function _createSuper(Derived) {
493
+ var hasNativeReflectConstruct = _isNativeReflectConstruct();
494
+
495
+ return function _createSuperInternal() {
496
+ var Super = _getPrototypeOf(Derived),
497
+ result;
498
+
499
+ if (hasNativeReflectConstruct) {
500
+ var NewTarget = _getPrototypeOf(this).constructor;
501
+
502
+ result = Reflect.construct(Super, arguments, NewTarget);
503
+ } else {
504
+ result = Super.apply(this, arguments);
505
+ }
506
+
507
+ return _possibleConstructorReturn(this, result);
508
+ };
509
+ }
510
+
419
511
  var Canvas2DContextService = /*#__PURE__*/function () {
420
512
  function Canvas2DContextService() {
513
+ _classCallCheck(this, Canvas2DContextService);
514
+
421
515
  this.$container = void 0;
422
516
  this.$canvas = void 0;
423
517
  this.dpr = void 0;
@@ -425,112 +519,120 @@ var Canvas2DContextService = /*#__PURE__*/function () {
425
519
  this.canvasConfig = void 0;
426
520
  }
427
521
 
428
- var _proto = Canvas2DContextService.prototype;
522
+ _createClass(Canvas2DContextService, [{
523
+ key: "init",
524
+ value: function () {
525
+ var _init = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
526
+ var _this$canvasConfig, container, canvas, devicePixelRatio, $canvas, dpr;
429
527
 
430
- _proto.init = /*#__PURE__*/function () {
431
- var _init = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
432
- var _this$canvasConfig, container, canvas, devicePixelRatio, $canvas, dpr;
528
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
529
+ while (1) {
530
+ switch (_context.prev = _context.next) {
531
+ case 0:
532
+ _this$canvasConfig = this.canvasConfig, container = _this$canvasConfig.container, canvas = _this$canvasConfig.canvas, devicePixelRatio = _this$canvasConfig.devicePixelRatio;
433
533
 
434
- return _regeneratorRuntime().wrap(function _callee$(_context) {
435
- while (1) {
436
- switch (_context.prev = _context.next) {
437
- case 0:
438
- _this$canvasConfig = this.canvasConfig, container = _this$canvasConfig.container, canvas = _this$canvasConfig.canvas, devicePixelRatio = _this$canvasConfig.devicePixelRatio;
534
+ if (canvas) {
535
+ this.$canvas = canvas;
439
536
 
440
- if (canvas) {
441
- this.$canvas = canvas;
537
+ if (container && canvas.parentElement !== container) {
538
+ container.appendChild(canvas);
539
+ }
442
540
 
443
- if (container && canvas.parentElement !== container) {
444
- container.appendChild(canvas);
445
- }
541
+ this.$container = canvas.parentElement;
542
+ this.canvasConfig.container = this.$container;
543
+ } else if (container) {
544
+ // create container
545
+ this.$container = isString(container) ? document.getElementById(container) : container;
446
546
 
447
- this.$container = canvas.parentElement;
448
- this.canvasConfig.container = this.$container;
449
- } else if (container) {
450
- // create container
451
- this.$container = isString(container) ? document.getElementById(container) : container;
547
+ if (this.$container) {
548
+ // create canvas
549
+ $canvas = document.createElement('canvas');
550
+ this.$container.appendChild($canvas);
452
551
 
453
- if (this.$container) {
454
- // create canvas
455
- $canvas = document.createElement('canvas');
456
- this.$container.appendChild($canvas);
552
+ if (!this.$container.style.position) {
553
+ this.$container.style.position = 'relative';
554
+ }
457
555
 
458
- if (!this.$container.style.position) {
459
- this.$container.style.position = 'relative';
556
+ this.$canvas = $canvas;
460
557
  }
461
-
462
- this.$canvas = $canvas;
463
558
  }
464
- }
465
559
 
466
- this.context = this.$canvas.getContext('2d'); // use user-defined dpr first
560
+ this.context = this.$canvas.getContext('2d'); // use user-defined dpr first
467
561
 
468
- dpr = devicePixelRatio || isBrowser && window.devicePixelRatio || 1;
469
- dpr = dpr >= 1 ? Math.ceil(dpr) : 1;
470
- this.dpr = dpr;
471
- this.resize(this.canvasConfig.width, this.canvasConfig.height);
562
+ dpr = devicePixelRatio || isBrowser && window.devicePixelRatio || 1;
563
+ dpr = dpr >= 1 ? Math.ceil(dpr) : 1;
564
+ this.dpr = dpr;
565
+ this.resize(this.canvasConfig.width, this.canvasConfig.height);
472
566
 
473
- case 7:
474
- case "end":
475
- return _context.stop();
567
+ case 7:
568
+ case "end":
569
+ return _context.stop();
570
+ }
476
571
  }
477
- }
478
- }, _callee, this);
479
- }));
480
-
481
- function init() {
482
- return _init.apply(this, arguments);
483
- }
484
-
485
- return init;
486
- }();
487
-
488
- _proto.getContext = function getContext() {
489
- return this.context;
490
- };
572
+ }, _callee, this);
573
+ }));
491
574
 
492
- _proto.getDomElement = function getDomElement() {
493
- return this.$canvas;
494
- };
495
-
496
- _proto.getDPR = function getDPR() {
497
- return this.dpr;
498
- };
575
+ function init() {
576
+ return _init.apply(this, arguments);
577
+ }
499
578
 
500
- _proto.getBoundingClientRect = function getBoundingClientRect() {
501
- if (this.$canvas.getBoundingClientRect) {
502
- return this.$canvas.getBoundingClientRect();
579
+ return init;
580
+ }()
581
+ }, {
582
+ key: "getContext",
583
+ value: function getContext() {
584
+ return this.context;
503
585
  }
504
- };
505
-
506
- _proto.destroy = function destroy() {
507
- // @ts-ignore
508
- if (this.$container && this.$canvas && this.$canvas.parentNode) {
509
- // destroy context
586
+ }, {
587
+ key: "getDomElement",
588
+ value: function getDomElement() {
589
+ return this.$canvas;
590
+ }
591
+ }, {
592
+ key: "getDPR",
593
+ value: function getDPR() {
594
+ return this.dpr;
595
+ }
596
+ }, {
597
+ key: "getBoundingClientRect",
598
+ value: function getBoundingClientRect() {
599
+ if (this.$canvas.getBoundingClientRect) {
600
+ return this.$canvas.getBoundingClientRect();
601
+ }
602
+ }
603
+ }, {
604
+ key: "destroy",
605
+ value: function destroy() {
510
606
  // @ts-ignore
511
- this.$container.removeChild(this.$canvas);
607
+ if (this.$container && this.$canvas && this.$canvas.parentNode) {
608
+ // destroy context
609
+ // @ts-ignore
610
+ this.$container.removeChild(this.$canvas);
611
+ }
512
612
  }
513
- };
514
-
515
- _proto.resize = function resize(width, height) {
516
- if (this.$canvas) {
517
- // set canvas width & height
518
- this.$canvas.width = this.dpr * width;
519
- this.$canvas.height = this.dpr * height; // set CSS style width & height
520
-
521
- setDOMSize(this.$canvas, width, height);
522
- var dpr = this.getDPR(); // scale all drawing operations by the dpr
523
- // @see https://www.html5rocks.com/en/tutorials/canvas/hidpi/
524
-
525
- this.context.scale(dpr, dpr);
613
+ }, {
614
+ key: "resize",
615
+ value: function resize(width, height) {
616
+ if (this.$canvas) {
617
+ // set canvas width & height
618
+ this.$canvas.width = this.dpr * width;
619
+ this.$canvas.height = this.dpr * height; // set CSS style width & height
620
+
621
+ setDOMSize(this.$canvas, width, height);
622
+ var dpr = this.getDPR(); // scale all drawing operations by the dpr
623
+ // @see https://www.html5rocks.com/en/tutorials/canvas/hidpi/
624
+
625
+ this.context.scale(dpr, dpr);
626
+ }
526
627
  }
527
- };
528
-
529
- _proto.applyCursorStyle = function applyCursorStyle(cursor) {
530
- if (this.$container && this.$container.style) {
531
- this.$container.style.cursor = cursor;
628
+ }, {
629
+ key: "applyCursorStyle",
630
+ value: function applyCursorStyle(cursor) {
631
+ if (this.$container && this.$container.style) {
632
+ this.$container.style.cursor = cursor;
633
+ }
532
634
  }
533
- };
635
+ }]);
534
636
 
535
637
  return Canvas2DContextService;
536
638
  }();
@@ -549,29 +651,37 @@ var containerModule = Module(function (register) {
549
651
  });
550
652
  var ContextRegisterPlugin = /*#__PURE__*/function () {
551
653
  function ContextRegisterPlugin() {
654
+ _classCallCheck(this, ContextRegisterPlugin);
655
+
552
656
  this.name = 'canvas-context-register';
553
657
  }
554
658
 
555
- var _proto = ContextRegisterPlugin.prototype;
556
-
557
- _proto.init = function init(container) {
558
- container.load(containerModule, true);
559
- };
560
-
561
- _proto.destroy = function destroy(container) {
562
- container.unload(containerModule);
563
- };
659
+ _createClass(ContextRegisterPlugin, [{
660
+ key: "init",
661
+ value: function init(container) {
662
+ container.load(containerModule, true);
663
+ }
664
+ }, {
665
+ key: "destroy",
666
+ value: function destroy(container) {
667
+ container.unload(containerModule);
668
+ }
669
+ }]);
564
670
 
565
671
  return ContextRegisterPlugin;
566
672
  }();
567
673
 
568
674
  var Renderer = /*#__PURE__*/function (_AbstractRenderer) {
569
- _inheritsLoose(Renderer, _AbstractRenderer);
675
+ _inherits(Renderer, _AbstractRenderer);
676
+
677
+ var _super = _createSuper(Renderer);
570
678
 
571
679
  function Renderer(config) {
572
680
  var _this;
573
681
 
574
- _this = _AbstractRenderer.call(this, config) || this; // register Canvas2DContext
682
+ _classCallCheck(this, Renderer);
683
+
684
+ _this = _super.call(this, config); // register Canvas2DContext
575
685
 
576
686
  _this.registerPlugin(new ContextRegisterPlugin());
577
687
 
@@ -593,7 +703,7 @@ var Renderer = /*#__PURE__*/function (_AbstractRenderer) {
593
703
  return _this;
594
704
  }
595
705
 
596
- return Renderer;
706
+ return _createClass(Renderer);
597
707
  }(AbstractRenderer);
598
708
 
599
709
  export { Renderer };