@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.d.ts CHANGED
@@ -1,5 +1,12 @@
1
1
  import type { RendererConfig } from '@antv/g';
2
2
  import { AbstractRenderer } from '@antv/g';
3
+ import * as CanvasPathGenerator from '@antv/g-plugin-canvas-path-generator';
4
+ import * as CanvasPicker from '@antv/g-plugin-canvas-picker';
5
+ import * as CanvasRenderer from '@antv/g-plugin-canvas-renderer';
6
+ import * as DomInteraction from '@antv/g-plugin-dom-interaction';
7
+ import * as HTMLRenderer from '@antv/g-plugin-html-renderer';
8
+ import * as ImageLoader from '@antv/g-plugin-image-loader';
9
+ export { CanvasPathGenerator, CanvasPicker, CanvasRenderer, DomInteraction, HTMLRenderer, ImageLoader, };
3
10
  export declare class Renderer extends AbstractRenderer {
4
11
  constructor(config?: Partial<RendererConfig>);
5
12
  }
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAC9C,OAAO,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAS3C,qBAAa,QAAS,SAAQ,gBAAgB;gBAChC,MAAM,CAAC,EAAE,OAAO,CAAC,cAAc,CAAC;CAgB7C"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAC9C,OAAO,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAC3C,OAAO,KAAK,mBAAmB,MAAM,sCAAsC,CAAC;AAC5E,OAAO,KAAK,YAAY,MAAM,8BAA8B,CAAC;AAC7D,OAAO,KAAK,cAAc,MAAM,gCAAgC,CAAC;AACjE,OAAO,KAAK,cAAc,MAAM,gCAAgC,CAAC;AACjE,OAAO,KAAK,YAAY,MAAM,8BAA8B,CAAC;AAC7D,OAAO,KAAK,WAAW,MAAM,6BAA6B,CAAC;AAG3D,OAAO,EACL,mBAAmB,EACnB,YAAY,EACZ,cAAc,EACd,cAAc,EACd,YAAY,EACZ,WAAW,GACZ,CAAC;AAEF,qBAAa,QAAS,SAAQ,gBAAgB;gBAChC,MAAM,CAAC,EAAE,OAAO,CAAC,cAAc,CAAC;CAgB7C"}
package/dist/index.esm.js CHANGED
@@ -1,10 +1,22 @@
1
1
  import { inject, CanvasConfig, singleton, ContextService, setDOMSize, isString, isBrowser, Module, AbstractRenderer } from '@antv/g';
2
2
  import { Plugin as Plugin$1 } from '@antv/g-plugin-canvas-path-generator';
3
+ import * as CanvasPathGenerator from '@antv/g-plugin-canvas-path-generator';
4
+ export { CanvasPathGenerator };
3
5
  import { Plugin as Plugin$4 } from '@antv/g-plugin-canvas-picker';
6
+ import * as CanvasPicker from '@antv/g-plugin-canvas-picker';
7
+ export { CanvasPicker };
4
8
  import { Plugin as Plugin$2 } from '@antv/g-plugin-canvas-renderer';
9
+ import * as CanvasRenderer from '@antv/g-plugin-canvas-renderer';
10
+ export { CanvasRenderer };
5
11
  import { Plugin as Plugin$3 } from '@antv/g-plugin-dom-interaction';
12
+ import * as DomInteraction from '@antv/g-plugin-dom-interaction';
13
+ export { DomInteraction };
6
14
  import { Plugin as Plugin$5 } from '@antv/g-plugin-html-renderer';
15
+ import * as HTMLRenderer from '@antv/g-plugin-html-renderer';
16
+ export { HTMLRenderer };
7
17
  import { Plugin } from '@antv/g-plugin-image-loader';
18
+ import * as ImageLoader from '@antv/g-plugin-image-loader';
19
+ export { ImageLoader };
8
20
  import { __decorate, __metadata } from 'tslib';
9
21
 
10
22
  function _regeneratorRuntime() {
@@ -388,24 +400,118 @@ function _asyncToGenerator(fn) {
388
400
  };
389
401
  }
390
402
 
391
- function _inheritsLoose(subClass, superClass) {
392
- subClass.prototype = Object.create(superClass.prototype);
393
- 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
+ }
394
432
 
395
- _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);
396
451
  }
397
452
 
398
453
  function _setPrototypeOf(o, p) {
399
- _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) {
454
+ _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) {
400
455
  o.__proto__ = p;
401
456
  return o;
402
457
  };
403
-
404
458
  return _setPrototypeOf(o, p);
405
459
  }
406
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
+
407
511
  var Canvas2DContextService = /*#__PURE__*/function () {
408
512
  function Canvas2DContextService() {
513
+ _classCallCheck(this, Canvas2DContextService);
514
+
409
515
  this.$container = void 0;
410
516
  this.$canvas = void 0;
411
517
  this.dpr = void 0;
@@ -413,112 +519,120 @@ var Canvas2DContextService = /*#__PURE__*/function () {
413
519
  this.canvasConfig = void 0;
414
520
  }
415
521
 
416
- 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;
417
527
 
418
- _proto.init = /*#__PURE__*/function () {
419
- var _init = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
420
- 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;
421
533
 
422
- return _regeneratorRuntime().wrap(function _callee$(_context) {
423
- while (1) {
424
- switch (_context.prev = _context.next) {
425
- case 0:
426
- _this$canvasConfig = this.canvasConfig, container = _this$canvasConfig.container, canvas = _this$canvasConfig.canvas, devicePixelRatio = _this$canvasConfig.devicePixelRatio;
534
+ if (canvas) {
535
+ this.$canvas = canvas;
427
536
 
428
- if (canvas) {
429
- this.$canvas = canvas;
537
+ if (container && canvas.parentElement !== container) {
538
+ container.appendChild(canvas);
539
+ }
430
540
 
431
- if (container && canvas.parentElement !== container) {
432
- container.appendChild(canvas);
433
- }
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;
434
546
 
435
- this.$container = canvas.parentElement;
436
- this.canvasConfig.container = this.$container;
437
- } else if (container) {
438
- // create container
439
- 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);
440
551
 
441
- if (this.$container) {
442
- // create canvas
443
- $canvas = document.createElement('canvas');
444
- this.$container.appendChild($canvas);
552
+ if (!this.$container.style.position) {
553
+ this.$container.style.position = 'relative';
554
+ }
445
555
 
446
- if (!this.$container.style.position) {
447
- this.$container.style.position = 'relative';
556
+ this.$canvas = $canvas;
448
557
  }
449
-
450
- this.$canvas = $canvas;
451
558
  }
452
- }
453
559
 
454
- this.context = this.$canvas.getContext('2d'); // use user-defined dpr first
560
+ this.context = this.$canvas.getContext('2d'); // use user-defined dpr first
455
561
 
456
- dpr = devicePixelRatio || isBrowser && window.devicePixelRatio || 1;
457
- dpr = dpr >= 1 ? Math.ceil(dpr) : 1;
458
- this.dpr = dpr;
459
- 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);
460
566
 
461
- case 7:
462
- case "end":
463
- return _context.stop();
567
+ case 7:
568
+ case "end":
569
+ return _context.stop();
570
+ }
464
571
  }
465
- }
466
- }, _callee, this);
467
- }));
468
-
469
- function init() {
470
- return _init.apply(this, arguments);
471
- }
472
-
473
- return init;
474
- }();
475
-
476
- _proto.getContext = function getContext() {
477
- return this.context;
478
- };
572
+ }, _callee, this);
573
+ }));
479
574
 
480
- _proto.getDomElement = function getDomElement() {
481
- return this.$canvas;
482
- };
483
-
484
- _proto.getDPR = function getDPR() {
485
- return this.dpr;
486
- };
575
+ function init() {
576
+ return _init.apply(this, arguments);
577
+ }
487
578
 
488
- _proto.getBoundingClientRect = function getBoundingClientRect() {
489
- if (this.$canvas.getBoundingClientRect) {
490
- return this.$canvas.getBoundingClientRect();
579
+ return init;
580
+ }()
581
+ }, {
582
+ key: "getContext",
583
+ value: function getContext() {
584
+ return this.context;
491
585
  }
492
- };
493
-
494
- _proto.destroy = function destroy() {
495
- // @ts-ignore
496
- if (this.$container && this.$canvas && this.$canvas.parentNode) {
497
- // 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() {
498
606
  // @ts-ignore
499
- 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
+ }
500
612
  }
501
- };
502
-
503
- _proto.resize = function resize(width, height) {
504
- if (this.$canvas) {
505
- // set canvas width & height
506
- this.$canvas.width = this.dpr * width;
507
- this.$canvas.height = this.dpr * height; // set CSS style width & height
508
-
509
- setDOMSize(this.$canvas, width, height);
510
- var dpr = this.getDPR(); // scale all drawing operations by the dpr
511
- // @see https://www.html5rocks.com/en/tutorials/canvas/hidpi/
512
-
513
- 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
+ }
514
627
  }
515
- };
516
-
517
- _proto.applyCursorStyle = function applyCursorStyle(cursor) {
518
- if (this.$container && this.$container.style) {
519
- 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
+ }
520
634
  }
521
- };
635
+ }]);
522
636
 
523
637
  return Canvas2DContextService;
524
638
  }();
@@ -537,29 +651,37 @@ var containerModule = Module(function (register) {
537
651
  });
538
652
  var ContextRegisterPlugin = /*#__PURE__*/function () {
539
653
  function ContextRegisterPlugin() {
654
+ _classCallCheck(this, ContextRegisterPlugin);
655
+
540
656
  this.name = 'canvas-context-register';
541
657
  }
542
658
 
543
- var _proto = ContextRegisterPlugin.prototype;
544
-
545
- _proto.init = function init(container) {
546
- container.load(containerModule, true);
547
- };
548
-
549
- _proto.destroy = function destroy(container) {
550
- container.unload(containerModule);
551
- };
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
+ }]);
552
670
 
553
671
  return ContextRegisterPlugin;
554
672
  }();
555
673
 
556
674
  var Renderer = /*#__PURE__*/function (_AbstractRenderer) {
557
- _inheritsLoose(Renderer, _AbstractRenderer);
675
+ _inherits(Renderer, _AbstractRenderer);
676
+
677
+ var _super = _createSuper(Renderer);
558
678
 
559
679
  function Renderer(config) {
560
680
  var _this;
561
681
 
562
- _this = _AbstractRenderer.call(this, config) || this; // register Canvas2DContext
682
+ _classCallCheck(this, Renderer);
683
+
684
+ _this = _super.call(this, config); // register Canvas2DContext
563
685
 
564
686
  _this.registerPlugin(new ContextRegisterPlugin());
565
687
 
@@ -581,7 +703,7 @@ var Renderer = /*#__PURE__*/function (_AbstractRenderer) {
581
703
  return _this;
582
704
  }
583
705
 
584
- return Renderer;
706
+ return _createClass(Renderer);
585
707
  }(AbstractRenderer);
586
708
 
587
709
  export { Renderer };