@antv/g-canvas 1.2.1 → 1.2.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.esm.js CHANGED
@@ -400,54 +400,11 @@ function _asyncToGenerator(fn) {
400
400
  };
401
401
  }
402
402
 
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
- }
403
+ function _inheritsLoose(subClass, superClass) {
404
+ subClass.prototype = Object.create(superClass.prototype);
405
+ subClass.prototype.constructor = subClass;
432
406
 
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);
407
+ _setPrototypeOf(subClass, superClass);
451
408
  }
452
409
 
453
410
  function _setPrototypeOf(o, p) {
@@ -458,60 +415,8 @@ function _setPrototypeOf(o, p) {
458
415
  return _setPrototypeOf(o, p);
459
416
  }
460
417
 
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
-
511
418
  var Canvas2DContextService = /*#__PURE__*/function () {
512
419
  function Canvas2DContextService() {
513
- _classCallCheck(this, Canvas2DContextService);
514
-
515
420
  this.$container = void 0;
516
421
  this.$canvas = void 0;
517
422
  this.dpr = void 0;
@@ -519,120 +424,112 @@ var Canvas2DContextService = /*#__PURE__*/function () {
519
424
  this.canvasConfig = void 0;
520
425
  }
521
426
 
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;
427
+ var _proto = Canvas2DContextService.prototype;
527
428
 
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;
429
+ _proto.init = /*#__PURE__*/function () {
430
+ var _init = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
431
+ var _this$canvasConfig, container, canvas, devicePixelRatio, $canvas, dpr;
533
432
 
534
- if (canvas) {
535
- this.$canvas = canvas;
433
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
434
+ while (1) {
435
+ switch (_context.prev = _context.next) {
436
+ case 0:
437
+ _this$canvasConfig = this.canvasConfig, container = _this$canvasConfig.container, canvas = _this$canvasConfig.canvas, devicePixelRatio = _this$canvasConfig.devicePixelRatio;
536
438
 
537
- if (container && canvas.parentElement !== container) {
538
- container.appendChild(canvas);
539
- }
439
+ if (canvas) {
440
+ this.$canvas = canvas;
540
441
 
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;
442
+ if (container && canvas.parentElement !== container) {
443
+ container.appendChild(canvas);
444
+ }
546
445
 
547
- if (this.$container) {
548
- // create canvas
549
- $canvas = document.createElement('canvas');
550
- this.$container.appendChild($canvas);
446
+ this.$container = canvas.parentElement;
447
+ this.canvasConfig.container = this.$container;
448
+ } else if (container) {
449
+ // create container
450
+ this.$container = isString(container) ? document.getElementById(container) : container;
551
451
 
552
- if (!this.$container.style.position) {
553
- this.$container.style.position = 'relative';
554
- }
452
+ if (this.$container) {
453
+ // create canvas
454
+ $canvas = document.createElement('canvas');
455
+ this.$container.appendChild($canvas);
555
456
 
556
- this.$canvas = $canvas;
457
+ if (!this.$container.style.position) {
458
+ this.$container.style.position = 'relative';
557
459
  }
460
+
461
+ this.$canvas = $canvas;
558
462
  }
463
+ }
559
464
 
560
- this.context = this.$canvas.getContext('2d'); // use user-defined dpr first
465
+ this.context = this.$canvas.getContext('2d'); // use user-defined dpr first
561
466
 
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);
467
+ dpr = devicePixelRatio || isBrowser && window.devicePixelRatio || 1;
468
+ dpr = dpr >= 1 ? Math.ceil(dpr) : 1;
469
+ this.dpr = dpr;
470
+ this.resize(this.canvasConfig.width, this.canvasConfig.height);
566
471
 
567
- case 7:
568
- case "end":
569
- return _context.stop();
570
- }
472
+ case 7:
473
+ case "end":
474
+ return _context.stop();
571
475
  }
572
- }, _callee, this);
573
- }));
574
-
575
- function init() {
576
- return _init.apply(this, arguments);
577
- }
476
+ }
477
+ }, _callee, this);
478
+ }));
578
479
 
579
- return init;
580
- }()
581
- }, {
582
- key: "getContext",
583
- value: function getContext() {
584
- return this.context;
585
- }
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;
480
+ function init() {
481
+ return _init.apply(this, arguments);
595
482
  }
596
- }, {
597
- key: "getBoundingClientRect",
598
- value: function getBoundingClientRect() {
599
- if (this.$canvas.getBoundingClientRect) {
600
- return this.$canvas.getBoundingClientRect();
601
- }
483
+
484
+ return init;
485
+ }();
486
+
487
+ _proto.getContext = function getContext() {
488
+ return this.context;
489
+ };
490
+
491
+ _proto.getDomElement = function getDomElement() {
492
+ return this.$canvas;
493
+ };
494
+
495
+ _proto.getDPR = function getDPR() {
496
+ return this.dpr;
497
+ };
498
+
499
+ _proto.getBoundingClientRect = function getBoundingClientRect() {
500
+ if (this.$canvas.getBoundingClientRect) {
501
+ return this.$canvas.getBoundingClientRect();
602
502
  }
603
- }, {
604
- key: "destroy",
605
- value: function destroy() {
503
+ };
504
+
505
+ _proto.destroy = function destroy() {
506
+ // @ts-ignore
507
+ if (this.$container && this.$canvas && this.$canvas.parentNode) {
508
+ // destroy context
606
509
  // @ts-ignore
607
- if (this.$container && this.$canvas && this.$canvas.parentNode) {
608
- // destroy context
609
- // @ts-ignore
610
- this.$container.removeChild(this.$canvas);
611
- }
510
+ this.$container.removeChild(this.$canvas);
612
511
  }
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
- }
512
+ };
513
+
514
+ _proto.resize = function resize(width, height) {
515
+ if (this.$canvas) {
516
+ // set canvas width & height
517
+ this.$canvas.width = this.dpr * width;
518
+ this.$canvas.height = this.dpr * height; // set CSS style width & height
519
+
520
+ setDOMSize(this.$canvas, width, height);
521
+ var dpr = this.getDPR(); // scale all drawing operations by the dpr
522
+ // @see https://www.html5rocks.com/en/tutorials/canvas/hidpi/
523
+
524
+ this.context.scale(dpr, dpr);
627
525
  }
628
- }, {
629
- key: "applyCursorStyle",
630
- value: function applyCursorStyle(cursor) {
631
- if (this.$container && this.$container.style) {
632
- this.$container.style.cursor = cursor;
633
- }
526
+ };
527
+
528
+ _proto.applyCursorStyle = function applyCursorStyle(cursor) {
529
+ if (this.$container && this.$container.style) {
530
+ this.$container.style.cursor = cursor;
634
531
  }
635
- }]);
532
+ };
636
533
 
637
534
  return Canvas2DContextService;
638
535
  }();
@@ -651,37 +548,29 @@ var containerModule = Module(function (register) {
651
548
  });
652
549
  var ContextRegisterPlugin = /*#__PURE__*/function () {
653
550
  function ContextRegisterPlugin() {
654
- _classCallCheck(this, ContextRegisterPlugin);
655
-
656
551
  this.name = 'canvas-context-register';
657
552
  }
658
553
 
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
- }]);
554
+ var _proto = ContextRegisterPlugin.prototype;
555
+
556
+ _proto.init = function init(container) {
557
+ container.load(containerModule, true);
558
+ };
559
+
560
+ _proto.destroy = function destroy(container) {
561
+ container.unload(containerModule);
562
+ };
670
563
 
671
564
  return ContextRegisterPlugin;
672
565
  }();
673
566
 
674
567
  var Renderer = /*#__PURE__*/function (_AbstractRenderer) {
675
- _inherits(Renderer, _AbstractRenderer);
676
-
677
- var _super = _createSuper(Renderer);
568
+ _inheritsLoose(Renderer, _AbstractRenderer);
678
569
 
679
570
  function Renderer(config) {
680
571
  var _this;
681
572
 
682
- _classCallCheck(this, Renderer);
683
-
684
- _this = _super.call(this, config); // register Canvas2DContext
573
+ _this = _AbstractRenderer.call(this, config) || this; // register Canvas2DContext
685
574
 
686
575
  _this.registerPlugin(new ContextRegisterPlugin());
687
576
 
@@ -703,7 +592,7 @@ var Renderer = /*#__PURE__*/function (_AbstractRenderer) {
703
592
  return _this;
704
593
  }
705
594
 
706
- return _createClass(Renderer);
595
+ return Renderer;
707
596
  }(AbstractRenderer);
708
597
 
709
598
  export { Renderer };