@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 +214 -104
- package/dist/index.js +214 -104
- package/dist/index.umd.js +2295 -1509
- package/dist/index.umd.min.js +6 -6
- package/package.json +8 -8
package/dist/index.js
CHANGED
|
@@ -419,24 +419,118 @@ function _asyncToGenerator(fn) {
|
|
|
419
419
|
};
|
|
420
420
|
}
|
|
421
421
|
|
|
422
|
-
function
|
|
423
|
-
|
|
424
|
-
|
|
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
|
+
}
|
|
437
|
+
|
|
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
|
+
}
|
|
425
451
|
|
|
426
|
-
|
|
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);
|
|
427
470
|
}
|
|
428
471
|
|
|
429
472
|
function _setPrototypeOf(o, p) {
|
|
430
|
-
_setPrototypeOf = Object.setPrototypeOf
|
|
473
|
+
_setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) {
|
|
431
474
|
o.__proto__ = p;
|
|
432
475
|
return o;
|
|
433
476
|
};
|
|
434
|
-
|
|
435
477
|
return _setPrototypeOf(o, p);
|
|
436
478
|
}
|
|
437
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
|
+
|
|
438
530
|
var Canvas2DContextService = /*#__PURE__*/function () {
|
|
439
531
|
function Canvas2DContextService() {
|
|
532
|
+
_classCallCheck(this, Canvas2DContextService);
|
|
533
|
+
|
|
440
534
|
this.$container = void 0;
|
|
441
535
|
this.$canvas = void 0;
|
|
442
536
|
this.dpr = void 0;
|
|
@@ -444,112 +538,120 @@ var Canvas2DContextService = /*#__PURE__*/function () {
|
|
|
444
538
|
this.canvasConfig = void 0;
|
|
445
539
|
}
|
|
446
540
|
|
|
447
|
-
|
|
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;
|
|
448
546
|
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
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;
|
|
452
552
|
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
switch (_context.prev = _context.next) {
|
|
456
|
-
case 0:
|
|
457
|
-
_this$canvasConfig = this.canvasConfig, container = _this$canvasConfig.container, canvas = _this$canvasConfig.canvas, devicePixelRatio = _this$canvasConfig.devicePixelRatio;
|
|
553
|
+
if (canvas) {
|
|
554
|
+
this.$canvas = canvas;
|
|
458
555
|
|
|
459
|
-
|
|
460
|
-
|
|
556
|
+
if (container && canvas.parentElement !== container) {
|
|
557
|
+
container.appendChild(canvas);
|
|
558
|
+
}
|
|
461
559
|
|
|
462
|
-
|
|
463
|
-
container
|
|
464
|
-
}
|
|
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;
|
|
465
565
|
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
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);
|
|
471
570
|
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
this.$container.appendChild($canvas);
|
|
571
|
+
if (!this.$container.style.position) {
|
|
572
|
+
this.$container.style.position = 'relative';
|
|
573
|
+
}
|
|
476
574
|
|
|
477
|
-
|
|
478
|
-
this.$container.style.position = 'relative';
|
|
575
|
+
this.$canvas = $canvas;
|
|
479
576
|
}
|
|
480
|
-
|
|
481
|
-
this.$canvas = $canvas;
|
|
482
577
|
}
|
|
483
|
-
}
|
|
484
578
|
|
|
485
|
-
|
|
579
|
+
this.context = this.$canvas.getContext('2d'); // use user-defined dpr first
|
|
486
580
|
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
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);
|
|
491
585
|
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
586
|
+
case 7:
|
|
587
|
+
case "end":
|
|
588
|
+
return _context.stop();
|
|
589
|
+
}
|
|
495
590
|
}
|
|
496
|
-
}
|
|
497
|
-
}
|
|
498
|
-
}));
|
|
499
|
-
|
|
500
|
-
function init() {
|
|
501
|
-
return _init.apply(this, arguments);
|
|
502
|
-
}
|
|
503
|
-
|
|
504
|
-
return init;
|
|
505
|
-
}();
|
|
506
|
-
|
|
507
|
-
_proto.getContext = function getContext() {
|
|
508
|
-
return this.context;
|
|
509
|
-
};
|
|
591
|
+
}, _callee, this);
|
|
592
|
+
}));
|
|
510
593
|
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
_proto.getDPR = function getDPR() {
|
|
516
|
-
return this.dpr;
|
|
517
|
-
};
|
|
594
|
+
function init() {
|
|
595
|
+
return _init.apply(this, arguments);
|
|
596
|
+
}
|
|
518
597
|
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
598
|
+
return init;
|
|
599
|
+
}()
|
|
600
|
+
}, {
|
|
601
|
+
key: "getContext",
|
|
602
|
+
value: function getContext() {
|
|
603
|
+
return this.context;
|
|
522
604
|
}
|
|
523
|
-
}
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
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() {
|
|
529
625
|
// @ts-ignore
|
|
530
|
-
this.$container
|
|
626
|
+
if (this.$container && this.$canvas && this.$canvas.parentNode) {
|
|
627
|
+
// destroy context
|
|
628
|
+
// @ts-ignore
|
|
629
|
+
this.$container.removeChild(this.$canvas);
|
|
630
|
+
}
|
|
531
631
|
}
|
|
532
|
-
}
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
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
|
+
}
|
|
545
646
|
}
|
|
546
|
-
}
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
647
|
+
}, {
|
|
648
|
+
key: "applyCursorStyle",
|
|
649
|
+
value: function applyCursorStyle(cursor) {
|
|
650
|
+
if (this.$container && this.$container.style) {
|
|
651
|
+
this.$container.style.cursor = cursor;
|
|
652
|
+
}
|
|
551
653
|
}
|
|
552
|
-
};
|
|
654
|
+
}]);
|
|
553
655
|
|
|
554
656
|
return Canvas2DContextService;
|
|
555
657
|
}();
|
|
@@ -568,29 +670,37 @@ var containerModule = g.Module(function (register) {
|
|
|
568
670
|
});
|
|
569
671
|
var ContextRegisterPlugin = /*#__PURE__*/function () {
|
|
570
672
|
function ContextRegisterPlugin() {
|
|
673
|
+
_classCallCheck(this, ContextRegisterPlugin);
|
|
674
|
+
|
|
571
675
|
this.name = 'canvas-context-register';
|
|
572
676
|
}
|
|
573
677
|
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
container
|
|
582
|
-
|
|
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
|
+
}]);
|
|
583
689
|
|
|
584
690
|
return ContextRegisterPlugin;
|
|
585
691
|
}();
|
|
586
692
|
|
|
587
693
|
var Renderer = /*#__PURE__*/function (_AbstractRenderer) {
|
|
588
|
-
|
|
694
|
+
_inherits(Renderer, _AbstractRenderer);
|
|
695
|
+
|
|
696
|
+
var _super = _createSuper(Renderer);
|
|
589
697
|
|
|
590
698
|
function Renderer(config) {
|
|
591
699
|
var _this;
|
|
592
700
|
|
|
593
|
-
|
|
701
|
+
_classCallCheck(this, Renderer);
|
|
702
|
+
|
|
703
|
+
_this = _super.call(this, config); // register Canvas2DContext
|
|
594
704
|
|
|
595
705
|
_this.registerPlugin(new ContextRegisterPlugin());
|
|
596
706
|
|
|
@@ -612,7 +722,7 @@ var Renderer = /*#__PURE__*/function (_AbstractRenderer) {
|
|
|
612
722
|
return _this;
|
|
613
723
|
}
|
|
614
724
|
|
|
615
|
-
return Renderer;
|
|
725
|
+
return _createClass(Renderer);
|
|
616
726
|
}(g.AbstractRenderer);
|
|
617
727
|
|
|
618
728
|
exports.CanvasPathGenerator = CanvasPathGenerator__namespace;
|