@antv/g-canvas 1.1.8-alpha.2 → 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.js CHANGED
@@ -11,6 +11,33 @@ var HTMLRenderer = require('@antv/g-plugin-html-renderer');
11
11
  var ImageLoader = require('@antv/g-plugin-image-loader');
12
12
  var tslib = require('tslib');
13
13
 
14
+ function _interopNamespace(e) {
15
+ if (e && e.__esModule) return e;
16
+ var n = Object.create(null);
17
+ if (e) {
18
+ Object.keys(e).forEach(function (k) {
19
+ if (k !== 'default') {
20
+ var d = Object.getOwnPropertyDescriptor(e, k);
21
+ Object.defineProperty(n, k, d.get ? d : {
22
+ enumerable: true,
23
+ get: function () {
24
+ return e[k];
25
+ }
26
+ });
27
+ }
28
+ });
29
+ }
30
+ n['default'] = e;
31
+ return Object.freeze(n);
32
+ }
33
+
34
+ var CanvasPathGenerator__namespace = /*#__PURE__*/_interopNamespace(CanvasPathGenerator);
35
+ var CanvasPicker__namespace = /*#__PURE__*/_interopNamespace(CanvasPicker);
36
+ var CanvasRenderer__namespace = /*#__PURE__*/_interopNamespace(CanvasRenderer);
37
+ var DomInteraction__namespace = /*#__PURE__*/_interopNamespace(DomInteraction);
38
+ var HTMLRenderer__namespace = /*#__PURE__*/_interopNamespace(HTMLRenderer);
39
+ var ImageLoader__namespace = /*#__PURE__*/_interopNamespace(ImageLoader);
40
+
14
41
  function _regeneratorRuntime() {
15
42
  /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */
16
43
 
@@ -392,24 +419,118 @@ function _asyncToGenerator(fn) {
392
419
  };
393
420
  }
394
421
 
395
- function _inheritsLoose(subClass, superClass) {
396
- subClass.prototype = Object.create(superClass.prototype);
397
- subClass.prototype.constructor = subClass;
422
+ function _classCallCheck(instance, Constructor) {
423
+ if (!(instance instanceof Constructor)) {
424
+ throw new TypeError("Cannot call a class as a function");
425
+ }
426
+ }
427
+
428
+ function _defineProperties(target, props) {
429
+ for (var i = 0; i < props.length; i++) {
430
+ var descriptor = props[i];
431
+ descriptor.enumerable = descriptor.enumerable || false;
432
+ descriptor.configurable = true;
433
+ if ("value" in descriptor) descriptor.writable = true;
434
+ Object.defineProperty(target, descriptor.key, descriptor);
435
+ }
436
+ }
398
437
 
399
- _setPrototypeOf(subClass, superClass);
438
+ function _createClass(Constructor, protoProps, staticProps) {
439
+ if (protoProps) _defineProperties(Constructor.prototype, protoProps);
440
+ if (staticProps) _defineProperties(Constructor, staticProps);
441
+ Object.defineProperty(Constructor, "prototype", {
442
+ writable: false
443
+ });
444
+ return Constructor;
445
+ }
446
+
447
+ function _inherits(subClass, superClass) {
448
+ if (typeof superClass !== "function" && superClass !== null) {
449
+ throw new TypeError("Super expression must either be null or a function");
450
+ }
451
+
452
+ subClass.prototype = Object.create(superClass && superClass.prototype, {
453
+ constructor: {
454
+ value: subClass,
455
+ writable: true,
456
+ configurable: true
457
+ }
458
+ });
459
+ Object.defineProperty(subClass, "prototype", {
460
+ writable: false
461
+ });
462
+ if (superClass) _setPrototypeOf(subClass, superClass);
463
+ }
464
+
465
+ function _getPrototypeOf(o) {
466
+ _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) {
467
+ return o.__proto__ || Object.getPrototypeOf(o);
468
+ };
469
+ return _getPrototypeOf(o);
400
470
  }
401
471
 
402
472
  function _setPrototypeOf(o, p) {
403
- _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) {
473
+ _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) {
404
474
  o.__proto__ = p;
405
475
  return o;
406
476
  };
407
-
408
477
  return _setPrototypeOf(o, p);
409
478
  }
410
479
 
480
+ function _isNativeReflectConstruct() {
481
+ if (typeof Reflect === "undefined" || !Reflect.construct) return false;
482
+ if (Reflect.construct.sham) return false;
483
+ if (typeof Proxy === "function") return true;
484
+
485
+ try {
486
+ Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {}));
487
+ return true;
488
+ } catch (e) {
489
+ return false;
490
+ }
491
+ }
492
+
493
+ function _assertThisInitialized(self) {
494
+ if (self === void 0) {
495
+ throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
496
+ }
497
+
498
+ return self;
499
+ }
500
+
501
+ function _possibleConstructorReturn(self, call) {
502
+ if (call && (typeof call === "object" || typeof call === "function")) {
503
+ return call;
504
+ } else if (call !== void 0) {
505
+ throw new TypeError("Derived constructors may only return object or undefined");
506
+ }
507
+
508
+ return _assertThisInitialized(self);
509
+ }
510
+
511
+ function _createSuper(Derived) {
512
+ var hasNativeReflectConstruct = _isNativeReflectConstruct();
513
+
514
+ return function _createSuperInternal() {
515
+ var Super = _getPrototypeOf(Derived),
516
+ result;
517
+
518
+ if (hasNativeReflectConstruct) {
519
+ var NewTarget = _getPrototypeOf(this).constructor;
520
+
521
+ result = Reflect.construct(Super, arguments, NewTarget);
522
+ } else {
523
+ result = Super.apply(this, arguments);
524
+ }
525
+
526
+ return _possibleConstructorReturn(this, result);
527
+ };
528
+ }
529
+
411
530
  var Canvas2DContextService = /*#__PURE__*/function () {
412
531
  function Canvas2DContextService() {
532
+ _classCallCheck(this, Canvas2DContextService);
533
+
413
534
  this.$container = void 0;
414
535
  this.$canvas = void 0;
415
536
  this.dpr = void 0;
@@ -417,112 +538,120 @@ var Canvas2DContextService = /*#__PURE__*/function () {
417
538
  this.canvasConfig = void 0;
418
539
  }
419
540
 
420
- var _proto = Canvas2DContextService.prototype;
541
+ _createClass(Canvas2DContextService, [{
542
+ key: "init",
543
+ value: function () {
544
+ var _init = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
545
+ var _this$canvasConfig, container, canvas, devicePixelRatio, $canvas, dpr;
421
546
 
422
- _proto.init = /*#__PURE__*/function () {
423
- var _init = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
424
- var _this$canvasConfig, container, canvas, devicePixelRatio, $canvas, dpr;
547
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
548
+ while (1) {
549
+ switch (_context.prev = _context.next) {
550
+ case 0:
551
+ _this$canvasConfig = this.canvasConfig, container = _this$canvasConfig.container, canvas = _this$canvasConfig.canvas, devicePixelRatio = _this$canvasConfig.devicePixelRatio;
425
552
 
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;
553
+ if (canvas) {
554
+ this.$canvas = canvas;
431
555
 
432
- if (canvas) {
433
- this.$canvas = canvas;
556
+ if (container && canvas.parentElement !== container) {
557
+ container.appendChild(canvas);
558
+ }
434
559
 
435
- if (container && canvas.parentElement !== container) {
436
- container.appendChild(canvas);
437
- }
560
+ this.$container = canvas.parentElement;
561
+ this.canvasConfig.container = this.$container;
562
+ } else if (container) {
563
+ // create container
564
+ this.$container = g.isString(container) ? document.getElementById(container) : container;
438
565
 
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;
566
+ if (this.$container) {
567
+ // create canvas
568
+ $canvas = document.createElement('canvas');
569
+ this.$container.appendChild($canvas);
444
570
 
445
- if (this.$container) {
446
- // create canvas
447
- $canvas = document.createElement('canvas');
448
- this.$container.appendChild($canvas);
571
+ if (!this.$container.style.position) {
572
+ this.$container.style.position = 'relative';
573
+ }
449
574
 
450
- if (!this.$container.style.position) {
451
- this.$container.style.position = 'relative';
575
+ this.$canvas = $canvas;
452
576
  }
453
-
454
- this.$canvas = $canvas;
455
577
  }
456
- }
457
578
 
458
- this.context = this.$canvas.getContext('2d'); // use user-defined dpr first
579
+ this.context = this.$canvas.getContext('2d'); // use user-defined dpr first
459
580
 
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);
581
+ dpr = devicePixelRatio || g.isBrowser && window.devicePixelRatio || 1;
582
+ dpr = dpr >= 1 ? Math.ceil(dpr) : 1;
583
+ this.dpr = dpr;
584
+ this.resize(this.canvasConfig.width, this.canvasConfig.height);
464
585
 
465
- case 7:
466
- case "end":
467
- return _context.stop();
586
+ case 7:
587
+ case "end":
588
+ return _context.stop();
589
+ }
468
590
  }
469
- }
470
- }, _callee, this);
471
- }));
472
-
473
- function init() {
474
- return _init.apply(this, arguments);
475
- }
591
+ }, _callee, this);
592
+ }));
476
593
 
477
- return init;
478
- }();
479
-
480
- _proto.getContext = function getContext() {
481
- return this.context;
482
- };
483
-
484
- _proto.getDomElement = function getDomElement() {
485
- return this.$canvas;
486
- };
487
-
488
- _proto.getDPR = function getDPR() {
489
- return this.dpr;
490
- };
594
+ function init() {
595
+ return _init.apply(this, arguments);
596
+ }
491
597
 
492
- _proto.getBoundingClientRect = function getBoundingClientRect() {
493
- if (this.$canvas.getBoundingClientRect) {
494
- return this.$canvas.getBoundingClientRect();
598
+ return init;
599
+ }()
600
+ }, {
601
+ key: "getContext",
602
+ value: function getContext() {
603
+ return this.context;
495
604
  }
496
- };
497
-
498
- _proto.destroy = function destroy() {
499
- // @ts-ignore
500
- if (this.$container && this.$canvas && this.$canvas.parentNode) {
501
- // destroy context
605
+ }, {
606
+ key: "getDomElement",
607
+ value: function getDomElement() {
608
+ return this.$canvas;
609
+ }
610
+ }, {
611
+ key: "getDPR",
612
+ value: function getDPR() {
613
+ return this.dpr;
614
+ }
615
+ }, {
616
+ key: "getBoundingClientRect",
617
+ value: function getBoundingClientRect() {
618
+ if (this.$canvas.getBoundingClientRect) {
619
+ return this.$canvas.getBoundingClientRect();
620
+ }
621
+ }
622
+ }, {
623
+ key: "destroy",
624
+ value: function destroy() {
502
625
  // @ts-ignore
503
- this.$container.removeChild(this.$canvas);
626
+ if (this.$container && this.$canvas && this.$canvas.parentNode) {
627
+ // destroy context
628
+ // @ts-ignore
629
+ this.$container.removeChild(this.$canvas);
630
+ }
504
631
  }
505
- };
506
-
507
- _proto.resize = function resize(width, height) {
508
- if (this.$canvas) {
509
- // set canvas width & height
510
- this.$canvas.width = this.dpr * width;
511
- this.$canvas.height = this.dpr * height; // set CSS style width & height
512
-
513
- g.setDOMSize(this.$canvas, width, height);
514
- var dpr = this.getDPR(); // scale all drawing operations by the dpr
515
- // @see https://www.html5rocks.com/en/tutorials/canvas/hidpi/
516
-
517
- this.context.scale(dpr, dpr);
632
+ }, {
633
+ key: "resize",
634
+ value: function resize(width, height) {
635
+ if (this.$canvas) {
636
+ // set canvas width & height
637
+ this.$canvas.width = this.dpr * width;
638
+ this.$canvas.height = this.dpr * height; // set CSS style width & height
639
+
640
+ g.setDOMSize(this.$canvas, width, height);
641
+ var dpr = this.getDPR(); // scale all drawing operations by the dpr
642
+ // @see https://www.html5rocks.com/en/tutorials/canvas/hidpi/
643
+
644
+ this.context.scale(dpr, dpr);
645
+ }
518
646
  }
519
- };
520
-
521
- _proto.applyCursorStyle = function applyCursorStyle(cursor) {
522
- if (this.$container && this.$container.style) {
523
- this.$container.style.cursor = cursor;
647
+ }, {
648
+ key: "applyCursorStyle",
649
+ value: function applyCursorStyle(cursor) {
650
+ if (this.$container && this.$container.style) {
651
+ this.$container.style.cursor = cursor;
652
+ }
524
653
  }
525
- };
654
+ }]);
526
655
 
527
656
  return Canvas2DContextService;
528
657
  }();
@@ -541,29 +670,37 @@ var containerModule = g.Module(function (register) {
541
670
  });
542
671
  var ContextRegisterPlugin = /*#__PURE__*/function () {
543
672
  function ContextRegisterPlugin() {
673
+ _classCallCheck(this, ContextRegisterPlugin);
674
+
544
675
  this.name = 'canvas-context-register';
545
676
  }
546
677
 
547
- var _proto = ContextRegisterPlugin.prototype;
548
-
549
- _proto.init = function init(container) {
550
- container.load(containerModule, true);
551
- };
552
-
553
- _proto.destroy = function destroy(container) {
554
- container.unload(containerModule);
555
- };
678
+ _createClass(ContextRegisterPlugin, [{
679
+ key: "init",
680
+ value: function init(container) {
681
+ container.load(containerModule, true);
682
+ }
683
+ }, {
684
+ key: "destroy",
685
+ value: function destroy(container) {
686
+ container.unload(containerModule);
687
+ }
688
+ }]);
556
689
 
557
690
  return ContextRegisterPlugin;
558
691
  }();
559
692
 
560
693
  var Renderer = /*#__PURE__*/function (_AbstractRenderer) {
561
- _inheritsLoose(Renderer, _AbstractRenderer);
694
+ _inherits(Renderer, _AbstractRenderer);
695
+
696
+ var _super = _createSuper(Renderer);
562
697
 
563
698
  function Renderer(config) {
564
699
  var _this;
565
700
 
566
- _this = _AbstractRenderer.call(this, config) || this; // register Canvas2DContext
701
+ _classCallCheck(this, Renderer);
702
+
703
+ _this = _super.call(this, config); // register Canvas2DContext
567
704
 
568
705
  _this.registerPlugin(new ContextRegisterPlugin());
569
706
 
@@ -585,7 +722,13 @@ var Renderer = /*#__PURE__*/function (_AbstractRenderer) {
585
722
  return _this;
586
723
  }
587
724
 
588
- return Renderer;
725
+ return _createClass(Renderer);
589
726
  }(g.AbstractRenderer);
590
727
 
728
+ exports.CanvasPathGenerator = CanvasPathGenerator__namespace;
729
+ exports.CanvasPicker = CanvasPicker__namespace;
730
+ exports.CanvasRenderer = CanvasRenderer__namespace;
731
+ exports.DomInteraction = DomInteraction__namespace;
732
+ exports.HTMLRenderer = HTMLRenderer__namespace;
733
+ exports.ImageLoader = ImageLoader__namespace;
591
734
  exports.Renderer = Renderer;