@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 +102 -213
- package/dist/index.js +102 -213
- package/dist/index.umd.js +1538 -2330
- package/dist/index.umd.min.js +6 -6
- package/package.json +8 -8
package/dist/index.js
CHANGED
|
@@ -419,54 +419,11 @@ function _asyncToGenerator(fn) {
|
|
|
419
419
|
};
|
|
420
420
|
}
|
|
421
421
|
|
|
422
|
-
function
|
|
423
|
-
|
|
424
|
-
|
|
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
|
-
}
|
|
422
|
+
function _inheritsLoose(subClass, superClass) {
|
|
423
|
+
subClass.prototype = Object.create(superClass.prototype);
|
|
424
|
+
subClass.prototype.constructor = subClass;
|
|
451
425
|
|
|
452
|
-
subClass
|
|
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);
|
|
426
|
+
_setPrototypeOf(subClass, superClass);
|
|
470
427
|
}
|
|
471
428
|
|
|
472
429
|
function _setPrototypeOf(o, p) {
|
|
@@ -477,60 +434,8 @@ function _setPrototypeOf(o, p) {
|
|
|
477
434
|
return _setPrototypeOf(o, p);
|
|
478
435
|
}
|
|
479
436
|
|
|
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
|
-
|
|
530
437
|
var Canvas2DContextService = /*#__PURE__*/function () {
|
|
531
438
|
function Canvas2DContextService() {
|
|
532
|
-
_classCallCheck(this, Canvas2DContextService);
|
|
533
|
-
|
|
534
439
|
this.$container = void 0;
|
|
535
440
|
this.$canvas = void 0;
|
|
536
441
|
this.dpr = void 0;
|
|
@@ -538,120 +443,112 @@ var Canvas2DContextService = /*#__PURE__*/function () {
|
|
|
538
443
|
this.canvasConfig = void 0;
|
|
539
444
|
}
|
|
540
445
|
|
|
541
|
-
|
|
542
|
-
key: "init",
|
|
543
|
-
value: function () {
|
|
544
|
-
var _init = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
|
|
545
|
-
var _this$canvasConfig, container, canvas, devicePixelRatio, $canvas, dpr;
|
|
446
|
+
var _proto = Canvas2DContextService.prototype;
|
|
546
447
|
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
case 0:
|
|
551
|
-
_this$canvasConfig = this.canvasConfig, container = _this$canvasConfig.container, canvas = _this$canvasConfig.canvas, devicePixelRatio = _this$canvasConfig.devicePixelRatio;
|
|
448
|
+
_proto.init = /*#__PURE__*/function () {
|
|
449
|
+
var _init = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
|
|
450
|
+
var _this$canvasConfig, container, canvas, devicePixelRatio, $canvas, dpr;
|
|
552
451
|
|
|
553
|
-
|
|
554
|
-
|
|
452
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
453
|
+
while (1) {
|
|
454
|
+
switch (_context.prev = _context.next) {
|
|
455
|
+
case 0:
|
|
456
|
+
_this$canvasConfig = this.canvasConfig, container = _this$canvasConfig.container, canvas = _this$canvasConfig.canvas, devicePixelRatio = _this$canvasConfig.devicePixelRatio;
|
|
555
457
|
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
}
|
|
458
|
+
if (canvas) {
|
|
459
|
+
this.$canvas = canvas;
|
|
559
460
|
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
}
|
|
563
|
-
// create container
|
|
564
|
-
this.$container = g.isString(container) ? document.getElementById(container) : container;
|
|
461
|
+
if (container && canvas.parentElement !== container) {
|
|
462
|
+
container.appendChild(canvas);
|
|
463
|
+
}
|
|
565
464
|
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
465
|
+
this.$container = canvas.parentElement;
|
|
466
|
+
this.canvasConfig.container = this.$container;
|
|
467
|
+
} else if (container) {
|
|
468
|
+
// create container
|
|
469
|
+
this.$container = g.isString(container) ? document.getElementById(container) : container;
|
|
570
470
|
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
471
|
+
if (this.$container) {
|
|
472
|
+
// create canvas
|
|
473
|
+
$canvas = document.createElement('canvas');
|
|
474
|
+
this.$container.appendChild($canvas);
|
|
574
475
|
|
|
575
|
-
|
|
476
|
+
if (!this.$container.style.position) {
|
|
477
|
+
this.$container.style.position = 'relative';
|
|
576
478
|
}
|
|
479
|
+
|
|
480
|
+
this.$canvas = $canvas;
|
|
577
481
|
}
|
|
482
|
+
}
|
|
578
483
|
|
|
579
|
-
|
|
484
|
+
this.context = this.$canvas.getContext('2d'); // use user-defined dpr first
|
|
580
485
|
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
486
|
+
dpr = devicePixelRatio || g.isBrowser && window.devicePixelRatio || 1;
|
|
487
|
+
dpr = dpr >= 1 ? Math.ceil(dpr) : 1;
|
|
488
|
+
this.dpr = dpr;
|
|
489
|
+
this.resize(this.canvasConfig.width, this.canvasConfig.height);
|
|
585
490
|
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
}
|
|
491
|
+
case 7:
|
|
492
|
+
case "end":
|
|
493
|
+
return _context.stop();
|
|
590
494
|
}
|
|
591
|
-
}
|
|
592
|
-
})
|
|
593
|
-
|
|
594
|
-
function init() {
|
|
595
|
-
return _init.apply(this, arguments);
|
|
596
|
-
}
|
|
495
|
+
}
|
|
496
|
+
}, _callee, this);
|
|
497
|
+
}));
|
|
597
498
|
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
}, {
|
|
601
|
-
key: "getContext",
|
|
602
|
-
value: function getContext() {
|
|
603
|
-
return this.context;
|
|
604
|
-
}
|
|
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;
|
|
499
|
+
function init() {
|
|
500
|
+
return _init.apply(this, arguments);
|
|
614
501
|
}
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
502
|
+
|
|
503
|
+
return init;
|
|
504
|
+
}();
|
|
505
|
+
|
|
506
|
+
_proto.getContext = function getContext() {
|
|
507
|
+
return this.context;
|
|
508
|
+
};
|
|
509
|
+
|
|
510
|
+
_proto.getDomElement = function getDomElement() {
|
|
511
|
+
return this.$canvas;
|
|
512
|
+
};
|
|
513
|
+
|
|
514
|
+
_proto.getDPR = function getDPR() {
|
|
515
|
+
return this.dpr;
|
|
516
|
+
};
|
|
517
|
+
|
|
518
|
+
_proto.getBoundingClientRect = function getBoundingClientRect() {
|
|
519
|
+
if (this.$canvas.getBoundingClientRect) {
|
|
520
|
+
return this.$canvas.getBoundingClientRect();
|
|
621
521
|
}
|
|
622
|
-
}
|
|
623
|
-
|
|
624
|
-
|
|
522
|
+
};
|
|
523
|
+
|
|
524
|
+
_proto.destroy = function destroy() {
|
|
525
|
+
// @ts-ignore
|
|
526
|
+
if (this.$container && this.$canvas && this.$canvas.parentNode) {
|
|
527
|
+
// destroy context
|
|
625
528
|
// @ts-ignore
|
|
626
|
-
|
|
627
|
-
// destroy context
|
|
628
|
-
// @ts-ignore
|
|
629
|
-
this.$container.removeChild(this.$canvas);
|
|
630
|
-
}
|
|
529
|
+
this.$container.removeChild(this.$canvas);
|
|
631
530
|
}
|
|
632
|
-
}
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
}
|
|
531
|
+
};
|
|
532
|
+
|
|
533
|
+
_proto.resize = function resize(width, height) {
|
|
534
|
+
if (this.$canvas) {
|
|
535
|
+
// set canvas width & height
|
|
536
|
+
this.$canvas.width = this.dpr * width;
|
|
537
|
+
this.$canvas.height = this.dpr * height; // set CSS style width & height
|
|
538
|
+
|
|
539
|
+
g.setDOMSize(this.$canvas, width, height);
|
|
540
|
+
var dpr = this.getDPR(); // scale all drawing operations by the dpr
|
|
541
|
+
// @see https://www.html5rocks.com/en/tutorials/canvas/hidpi/
|
|
542
|
+
|
|
543
|
+
this.context.scale(dpr, dpr);
|
|
646
544
|
}
|
|
647
|
-
}
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
}
|
|
545
|
+
};
|
|
546
|
+
|
|
547
|
+
_proto.applyCursorStyle = function applyCursorStyle(cursor) {
|
|
548
|
+
if (this.$container && this.$container.style) {
|
|
549
|
+
this.$container.style.cursor = cursor;
|
|
653
550
|
}
|
|
654
|
-
}
|
|
551
|
+
};
|
|
655
552
|
|
|
656
553
|
return Canvas2DContextService;
|
|
657
554
|
}();
|
|
@@ -670,37 +567,29 @@ var containerModule = g.Module(function (register) {
|
|
|
670
567
|
});
|
|
671
568
|
var ContextRegisterPlugin = /*#__PURE__*/function () {
|
|
672
569
|
function ContextRegisterPlugin() {
|
|
673
|
-
_classCallCheck(this, ContextRegisterPlugin);
|
|
674
|
-
|
|
675
570
|
this.name = 'canvas-context-register';
|
|
676
571
|
}
|
|
677
572
|
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
}
|
|
688
|
-
}]);
|
|
573
|
+
var _proto = ContextRegisterPlugin.prototype;
|
|
574
|
+
|
|
575
|
+
_proto.init = function init(container) {
|
|
576
|
+
container.load(containerModule, true);
|
|
577
|
+
};
|
|
578
|
+
|
|
579
|
+
_proto.destroy = function destroy(container) {
|
|
580
|
+
container.unload(containerModule);
|
|
581
|
+
};
|
|
689
582
|
|
|
690
583
|
return ContextRegisterPlugin;
|
|
691
584
|
}();
|
|
692
585
|
|
|
693
586
|
var Renderer = /*#__PURE__*/function (_AbstractRenderer) {
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
var _super = _createSuper(Renderer);
|
|
587
|
+
_inheritsLoose(Renderer, _AbstractRenderer);
|
|
697
588
|
|
|
698
589
|
function Renderer(config) {
|
|
699
590
|
var _this;
|
|
700
591
|
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
_this = _super.call(this, config); // register Canvas2DContext
|
|
592
|
+
_this = _AbstractRenderer.call(this, config) || this; // register Canvas2DContext
|
|
704
593
|
|
|
705
594
|
_this.registerPlugin(new ContextRegisterPlugin());
|
|
706
595
|
|
|
@@ -722,7 +611,7 @@ var Renderer = /*#__PURE__*/function (_AbstractRenderer) {
|
|
|
722
611
|
return _this;
|
|
723
612
|
}
|
|
724
613
|
|
|
725
|
-
return
|
|
614
|
+
return Renderer;
|
|
726
615
|
}(g.AbstractRenderer);
|
|
727
616
|
|
|
728
617
|
exports.CanvasPathGenerator = CanvasPathGenerator__namespace;
|