@antv/g-canvas 1.2.1 → 1.3.0
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/Canvas2DContextService.d.ts +2 -1
- package/dist/Canvas2DContextService.d.ts.map +1 -1
- package/dist/index.esm.js +132 -213
- package/dist/index.js +132 -213
- package/dist/index.umd.js +1559 -2318
- package/dist/index.umd.min.js +7 -7
- package/package.json +8 -8
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { CanvasLike } from '@antv/g';
|
|
1
|
+
import type { CanvasLike, DataURLOptions } from '@antv/g';
|
|
2
2
|
import { ContextService } from '@antv/g';
|
|
3
3
|
export declare class Canvas2DContextService implements ContextService<CanvasRenderingContext2D> {
|
|
4
4
|
private $container;
|
|
@@ -14,5 +14,6 @@ export declare class Canvas2DContextService implements ContextService<CanvasRend
|
|
|
14
14
|
destroy(): void;
|
|
15
15
|
resize(width: number, height: number): void;
|
|
16
16
|
applyCursorStyle(cursor: string): void;
|
|
17
|
+
toDataURL(options?: Partial<DataURLOptions>): Promise<string>;
|
|
17
18
|
}
|
|
18
19
|
//# sourceMappingURL=Canvas2DContextService.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Canvas2DContextService.d.ts","sourceRoot":"","sources":["../src/Canvas2DContextService.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"Canvas2DContextService.d.ts","sourceRoot":"","sources":["../src/Canvas2DContextService.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAC1D,OAAO,EAEL,cAAc,EAMf,MAAM,SAAS,CAAC;AAEjB,qBACa,sBAAuB,YAAW,cAAc,CAAC,wBAAwB,CAAC;IACrF,OAAO,CAAC,UAAU,CAAqB;IACvC,OAAO,CAAC,OAAO,CAAoB;IACnC,OAAO,CAAC,GAAG,CAAS;IACpB,OAAO,CAAC,OAAO,CAAsE;IAGrF,OAAO,CAAC,YAAY,CAAe;IAE7B,IAAI;IAoCV,UAAU;IAIV,aAAa;IAIb,MAAM;IAIN,qBAAqB;IAMrB,OAAO;IASP,MAAM,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM;IAgBpC,gBAAgB,CAAC,MAAM,EAAE,MAAM;IAMzB,SAAS,CAAC,OAAO,GAAE,OAAO,CAAC,cAAc,CAAM;CAItD"}
|
package/dist/index.esm.js
CHANGED
|
@@ -400,54 +400,11 @@ function _asyncToGenerator(fn) {
|
|
|
400
400
|
};
|
|
401
401
|
}
|
|
402
402
|
|
|
403
|
-
function
|
|
404
|
-
|
|
405
|
-
|
|
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
|
-
}
|
|
432
|
-
|
|
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
|
-
}
|
|
403
|
+
function _inheritsLoose(subClass, superClass) {
|
|
404
|
+
subClass.prototype = Object.create(superClass.prototype);
|
|
405
|
+
subClass.prototype.constructor = subClass;
|
|
445
406
|
|
|
446
|
-
|
|
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,142 @@ var Canvas2DContextService = /*#__PURE__*/function () {
|
|
|
519
424
|
this.canvasConfig = void 0;
|
|
520
425
|
}
|
|
521
426
|
|
|
522
|
-
|
|
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
|
-
|
|
529
|
-
|
|
530
|
-
|
|
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
|
-
|
|
535
|
-
|
|
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
|
-
|
|
538
|
-
|
|
539
|
-
}
|
|
439
|
+
if (canvas) {
|
|
440
|
+
this.$canvas = canvas;
|
|
540
441
|
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
}
|
|
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
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
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
|
-
|
|
553
|
-
|
|
554
|
-
|
|
452
|
+
if (this.$container) {
|
|
453
|
+
// create canvas
|
|
454
|
+
$canvas = document.createElement('canvas');
|
|
455
|
+
this.$container.appendChild($canvas);
|
|
555
456
|
|
|
556
|
-
|
|
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
|
-
|
|
465
|
+
this.context = this.$canvas.getContext('2d'); // use user-defined dpr first
|
|
561
466
|
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
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
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
}
|
|
472
|
+
case 7:
|
|
473
|
+
case "end":
|
|
474
|
+
return _context.stop();
|
|
571
475
|
}
|
|
572
|
-
}
|
|
573
|
-
})
|
|
574
|
-
|
|
575
|
-
function init() {
|
|
576
|
-
return _init.apply(this, arguments);
|
|
577
|
-
}
|
|
476
|
+
}
|
|
477
|
+
}, _callee, this);
|
|
478
|
+
}));
|
|
578
479
|
|
|
579
|
-
|
|
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;
|
|
480
|
+
function init() {
|
|
481
|
+
return _init.apply(this, arguments);
|
|
590
482
|
}
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
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
|
-
|
|
605
|
-
|
|
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
|
-
|
|
608
|
-
// destroy context
|
|
609
|
-
// @ts-ignore
|
|
610
|
-
this.$container.removeChild(this.$canvas);
|
|
611
|
-
}
|
|
510
|
+
this.$container.removeChild(this.$canvas);
|
|
612
511
|
}
|
|
613
|
-
}
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
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
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
526
|
+
};
|
|
527
|
+
|
|
528
|
+
_proto.applyCursorStyle = function applyCursorStyle(cursor) {
|
|
529
|
+
if (this.$container && this.$container.style) {
|
|
530
|
+
this.$container.style.cursor = cursor;
|
|
531
|
+
}
|
|
532
|
+
};
|
|
533
|
+
|
|
534
|
+
_proto.toDataURL = /*#__PURE__*/function () {
|
|
535
|
+
var _toDataURL = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(options) {
|
|
536
|
+
var _options, type, encoderOptions;
|
|
537
|
+
|
|
538
|
+
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
539
|
+
while (1) {
|
|
540
|
+
switch (_context2.prev = _context2.next) {
|
|
541
|
+
case 0:
|
|
542
|
+
if (options === void 0) {
|
|
543
|
+
options = {};
|
|
544
|
+
}
|
|
545
|
+
|
|
546
|
+
_options = options, type = _options.type, encoderOptions = _options.encoderOptions;
|
|
547
|
+
return _context2.abrupt("return", this.context.canvas.toDataURL(type, encoderOptions));
|
|
548
|
+
|
|
549
|
+
case 3:
|
|
550
|
+
case "end":
|
|
551
|
+
return _context2.stop();
|
|
552
|
+
}
|
|
553
|
+
}
|
|
554
|
+
}, _callee2, this);
|
|
555
|
+
}));
|
|
556
|
+
|
|
557
|
+
function toDataURL(_x) {
|
|
558
|
+
return _toDataURL.apply(this, arguments);
|
|
634
559
|
}
|
|
635
|
-
|
|
560
|
+
|
|
561
|
+
return toDataURL;
|
|
562
|
+
}();
|
|
636
563
|
|
|
637
564
|
return Canvas2DContextService;
|
|
638
565
|
}();
|
|
@@ -651,37 +578,29 @@ var containerModule = Module(function (register) {
|
|
|
651
578
|
});
|
|
652
579
|
var ContextRegisterPlugin = /*#__PURE__*/function () {
|
|
653
580
|
function ContextRegisterPlugin() {
|
|
654
|
-
_classCallCheck(this, ContextRegisterPlugin);
|
|
655
|
-
|
|
656
581
|
this.name = 'canvas-context-register';
|
|
657
582
|
}
|
|
658
583
|
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
}
|
|
669
|
-
}]);
|
|
584
|
+
var _proto = ContextRegisterPlugin.prototype;
|
|
585
|
+
|
|
586
|
+
_proto.init = function init(container) {
|
|
587
|
+
container.load(containerModule, true);
|
|
588
|
+
};
|
|
589
|
+
|
|
590
|
+
_proto.destroy = function destroy(container) {
|
|
591
|
+
container.unload(containerModule);
|
|
592
|
+
};
|
|
670
593
|
|
|
671
594
|
return ContextRegisterPlugin;
|
|
672
595
|
}();
|
|
673
596
|
|
|
674
597
|
var Renderer = /*#__PURE__*/function (_AbstractRenderer) {
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
var _super = _createSuper(Renderer);
|
|
598
|
+
_inheritsLoose(Renderer, _AbstractRenderer);
|
|
678
599
|
|
|
679
600
|
function Renderer(config) {
|
|
680
601
|
var _this;
|
|
681
602
|
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
_this = _super.call(this, config); // register Canvas2DContext
|
|
603
|
+
_this = _AbstractRenderer.call(this, config) || this; // register Canvas2DContext
|
|
685
604
|
|
|
686
605
|
_this.registerPlugin(new ContextRegisterPlugin());
|
|
687
606
|
|
|
@@ -703,7 +622,7 @@ var Renderer = /*#__PURE__*/function (_AbstractRenderer) {
|
|
|
703
622
|
return _this;
|
|
704
623
|
}
|
|
705
624
|
|
|
706
|
-
return
|
|
625
|
+
return Renderer;
|
|
707
626
|
}(AbstractRenderer);
|
|
708
627
|
|
|
709
628
|
export { Renderer };
|