@antv/g-canvas 1.9.19 → 1.9.20
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 +240 -120
- package/dist/index.js +240 -120
- package/dist/index.umd.js +2720 -1622
- package/dist/index.umd.min.js +1 -1
- package/package.json +8 -8
package/dist/index.js
CHANGED
|
@@ -369,10 +369,49 @@ function _asyncToGenerator(fn) {
|
|
|
369
369
|
});
|
|
370
370
|
};
|
|
371
371
|
}
|
|
372
|
-
function
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
372
|
+
function _classCallCheck(instance, Constructor) {
|
|
373
|
+
if (!(instance instanceof Constructor)) {
|
|
374
|
+
throw new TypeError("Cannot call a class as a function");
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
function _defineProperties(target, props) {
|
|
378
|
+
for (var i = 0; i < props.length; i++) {
|
|
379
|
+
var descriptor = props[i];
|
|
380
|
+
descriptor.enumerable = descriptor.enumerable || false;
|
|
381
|
+
descriptor.configurable = true;
|
|
382
|
+
if ("value" in descriptor) descriptor.writable = true;
|
|
383
|
+
Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor);
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
function _createClass(Constructor, protoProps, staticProps) {
|
|
387
|
+
if (protoProps) _defineProperties(Constructor.prototype, protoProps);
|
|
388
|
+
if (staticProps) _defineProperties(Constructor, staticProps);
|
|
389
|
+
Object.defineProperty(Constructor, "prototype", {
|
|
390
|
+
writable: false
|
|
391
|
+
});
|
|
392
|
+
return Constructor;
|
|
393
|
+
}
|
|
394
|
+
function _inherits(subClass, superClass) {
|
|
395
|
+
if (typeof superClass !== "function" && superClass !== null) {
|
|
396
|
+
throw new TypeError("Super expression must either be null or a function");
|
|
397
|
+
}
|
|
398
|
+
subClass.prototype = Object.create(superClass && superClass.prototype, {
|
|
399
|
+
constructor: {
|
|
400
|
+
value: subClass,
|
|
401
|
+
writable: true,
|
|
402
|
+
configurable: true
|
|
403
|
+
}
|
|
404
|
+
});
|
|
405
|
+
Object.defineProperty(subClass, "prototype", {
|
|
406
|
+
writable: false
|
|
407
|
+
});
|
|
408
|
+
if (superClass) _setPrototypeOf(subClass, superClass);
|
|
409
|
+
}
|
|
410
|
+
function _getPrototypeOf(o) {
|
|
411
|
+
_getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) {
|
|
412
|
+
return o.__proto__ || Object.getPrototypeOf(o);
|
|
413
|
+
};
|
|
414
|
+
return _getPrototypeOf(o);
|
|
376
415
|
}
|
|
377
416
|
function _setPrototypeOf(o, p) {
|
|
378
417
|
_setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) {
|
|
@@ -381,9 +420,63 @@ function _setPrototypeOf(o, p) {
|
|
|
381
420
|
};
|
|
382
421
|
return _setPrototypeOf(o, p);
|
|
383
422
|
}
|
|
423
|
+
function _isNativeReflectConstruct() {
|
|
424
|
+
if (typeof Reflect === "undefined" || !Reflect.construct) return false;
|
|
425
|
+
if (Reflect.construct.sham) return false;
|
|
426
|
+
if (typeof Proxy === "function") return true;
|
|
427
|
+
try {
|
|
428
|
+
Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {}));
|
|
429
|
+
return true;
|
|
430
|
+
} catch (e) {
|
|
431
|
+
return false;
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
function _assertThisInitialized(self) {
|
|
435
|
+
if (self === void 0) {
|
|
436
|
+
throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
|
|
437
|
+
}
|
|
438
|
+
return self;
|
|
439
|
+
}
|
|
440
|
+
function _possibleConstructorReturn(self, call) {
|
|
441
|
+
if (call && (typeof call === "object" || typeof call === "function")) {
|
|
442
|
+
return call;
|
|
443
|
+
} else if (call !== void 0) {
|
|
444
|
+
throw new TypeError("Derived constructors may only return object or undefined");
|
|
445
|
+
}
|
|
446
|
+
return _assertThisInitialized(self);
|
|
447
|
+
}
|
|
448
|
+
function _createSuper(Derived) {
|
|
449
|
+
var hasNativeReflectConstruct = _isNativeReflectConstruct();
|
|
450
|
+
return function _createSuperInternal() {
|
|
451
|
+
var Super = _getPrototypeOf(Derived),
|
|
452
|
+
result;
|
|
453
|
+
if (hasNativeReflectConstruct) {
|
|
454
|
+
var NewTarget = _getPrototypeOf(this).constructor;
|
|
455
|
+
result = Reflect.construct(Super, arguments, NewTarget);
|
|
456
|
+
} else {
|
|
457
|
+
result = Super.apply(this, arguments);
|
|
458
|
+
}
|
|
459
|
+
return _possibleConstructorReturn(this, result);
|
|
460
|
+
};
|
|
461
|
+
}
|
|
462
|
+
function _toPrimitive(input, hint) {
|
|
463
|
+
if (typeof input !== "object" || input === null) return input;
|
|
464
|
+
var prim = input[Symbol.toPrimitive];
|
|
465
|
+
if (prim !== undefined) {
|
|
466
|
+
var res = prim.call(input, hint || "default");
|
|
467
|
+
if (typeof res !== "object") return res;
|
|
468
|
+
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
469
|
+
}
|
|
470
|
+
return (hint === "string" ? String : Number)(input);
|
|
471
|
+
}
|
|
472
|
+
function _toPropertyKey(arg) {
|
|
473
|
+
var key = _toPrimitive(arg, "string");
|
|
474
|
+
return typeof key === "symbol" ? key : String(key);
|
|
475
|
+
}
|
|
384
476
|
|
|
385
477
|
var Canvas2DContextService = /*#__PURE__*/function () {
|
|
386
478
|
function Canvas2DContextService(context) {
|
|
479
|
+
_classCallCheck(this, Canvas2DContextService);
|
|
387
480
|
this.$container = void 0;
|
|
388
481
|
this.$canvas = void 0;
|
|
389
482
|
this.dpr = void 0;
|
|
@@ -393,149 +486,176 @@ var Canvas2DContextService = /*#__PURE__*/function () {
|
|
|
393
486
|
this.renderingContext = context.renderingContext;
|
|
394
487
|
this.canvasConfig = context.config;
|
|
395
488
|
}
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
var
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
container.
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
this.$container.style.position
|
|
489
|
+
_createClass(Canvas2DContextService, [{
|
|
490
|
+
key: "init",
|
|
491
|
+
value: function () {
|
|
492
|
+
var _init = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
|
|
493
|
+
var _this$canvasConfig, container, canvas, $canvas;
|
|
494
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
495
|
+
while (1) {
|
|
496
|
+
switch (_context.prev = _context.next) {
|
|
497
|
+
case 0:
|
|
498
|
+
_this$canvasConfig = this.canvasConfig, container = _this$canvasConfig.container, canvas = _this$canvasConfig.canvas;
|
|
499
|
+
if (canvas) {
|
|
500
|
+
this.$canvas = canvas;
|
|
501
|
+
if (container && canvas.parentElement !== container) {
|
|
502
|
+
container.appendChild(canvas);
|
|
503
|
+
}
|
|
504
|
+
this.$container = canvas.parentElement;
|
|
505
|
+
this.canvasConfig.container = this.$container;
|
|
506
|
+
} else if (container) {
|
|
507
|
+
// create container
|
|
508
|
+
this.$container = util.isString(container) ? document.getElementById(container) : container;
|
|
509
|
+
if (this.$container) {
|
|
510
|
+
// create canvas
|
|
511
|
+
$canvas = document.createElement('canvas');
|
|
512
|
+
this.$container.appendChild($canvas);
|
|
513
|
+
if (!this.$container.style.position) {
|
|
514
|
+
this.$container.style.position = 'relative';
|
|
515
|
+
}
|
|
516
|
+
this.$canvas = $canvas;
|
|
421
517
|
}
|
|
422
|
-
this.$canvas = $canvas;
|
|
423
518
|
}
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
519
|
+
this.context = this.$canvas.getContext('2d');
|
|
520
|
+
this.resize(this.canvasConfig.width, this.canvasConfig.height);
|
|
521
|
+
case 4:
|
|
522
|
+
case "end":
|
|
523
|
+
return _context.stop();
|
|
524
|
+
}
|
|
430
525
|
}
|
|
431
|
-
}
|
|
432
|
-
}
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
526
|
+
}, _callee, this);
|
|
527
|
+
}));
|
|
528
|
+
function init() {
|
|
529
|
+
return _init.apply(this, arguments);
|
|
530
|
+
}
|
|
531
|
+
return init;
|
|
532
|
+
}()
|
|
533
|
+
}, {
|
|
534
|
+
key: "getContext",
|
|
535
|
+
value: function getContext() {
|
|
536
|
+
return this.context;
|
|
436
537
|
}
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
};
|
|
442
|
-
_proto.getDomElement = function getDomElement() {
|
|
443
|
-
return this.$canvas;
|
|
444
|
-
};
|
|
445
|
-
_proto.getDPR = function getDPR() {
|
|
446
|
-
return this.dpr;
|
|
447
|
-
};
|
|
448
|
-
_proto.getBoundingClientRect = function getBoundingClientRect() {
|
|
449
|
-
if (this.$canvas.getBoundingClientRect) {
|
|
450
|
-
return this.$canvas.getBoundingClientRect();
|
|
538
|
+
}, {
|
|
539
|
+
key: "getDomElement",
|
|
540
|
+
value: function getDomElement() {
|
|
541
|
+
return this.$canvas;
|
|
451
542
|
}
|
|
452
|
-
}
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
// destroy context
|
|
457
|
-
// @ts-ignore
|
|
458
|
-
this.$container.removeChild(this.$canvas);
|
|
543
|
+
}, {
|
|
544
|
+
key: "getDPR",
|
|
545
|
+
value: function getDPR() {
|
|
546
|
+
return this.dpr;
|
|
459
547
|
}
|
|
460
|
-
}
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
// this.context.scale(dpr, dpr);
|
|
548
|
+
}, {
|
|
549
|
+
key: "getBoundingClientRect",
|
|
550
|
+
value: function getBoundingClientRect() {
|
|
551
|
+
if (this.$canvas.getBoundingClientRect) {
|
|
552
|
+
return this.$canvas.getBoundingClientRect();
|
|
553
|
+
}
|
|
554
|
+
}
|
|
555
|
+
}, {
|
|
556
|
+
key: "destroy",
|
|
557
|
+
value: function destroy() {
|
|
558
|
+
// @ts-ignore
|
|
559
|
+
if (this.$container && this.$canvas && this.$canvas.parentNode) {
|
|
560
|
+
// destroy context
|
|
561
|
+
// @ts-ignore
|
|
562
|
+
this.$container.removeChild(this.$canvas);
|
|
563
|
+
}
|
|
477
564
|
}
|
|
565
|
+
}, {
|
|
566
|
+
key: "resize",
|
|
567
|
+
value: function resize(width, height) {
|
|
568
|
+
var devicePixelRatio = this.canvasConfig.devicePixelRatio;
|
|
569
|
+
// use user-defined dpr first
|
|
570
|
+
var dpr = devicePixelRatio || gLite.isBrowser && window.devicePixelRatio || 1;
|
|
571
|
+
dpr = dpr >= 1 ? Math.ceil(dpr) : 1;
|
|
572
|
+
this.dpr = dpr;
|
|
573
|
+
if (this.$canvas) {
|
|
574
|
+
// set canvas width & height
|
|
575
|
+
this.$canvas.width = this.dpr * width;
|
|
576
|
+
this.$canvas.height = this.dpr * height;
|
|
577
|
+
// set CSS style width & height
|
|
578
|
+
gLite.setDOMSize(this.$canvas, width, height);
|
|
579
|
+
// const dpr = this.getDPR();
|
|
580
|
+
// scale all drawing operations by the dpr
|
|
581
|
+
// @see https://www.html5rocks.com/en/tutorials/canvas/hidpi/
|
|
582
|
+
// this.context.scale(dpr, dpr);
|
|
583
|
+
}
|
|
478
584
|
|
|
479
|
-
|
|
480
|
-
};
|
|
481
|
-
_proto.applyCursorStyle = function applyCursorStyle(cursor) {
|
|
482
|
-
if (this.$container && this.$container.style) {
|
|
483
|
-
this.$container.style.cursor = cursor;
|
|
585
|
+
this.renderingContext.renderReasons.add(gLite.RenderReason.CAMERA_CHANGED);
|
|
484
586
|
}
|
|
485
|
-
}
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
switch (_context2.prev = _context2.next) {
|
|
492
|
-
case 0:
|
|
493
|
-
if (options === void 0) {
|
|
494
|
-
options = {};
|
|
495
|
-
}
|
|
496
|
-
_options = options, type = _options.type, encoderOptions = _options.encoderOptions;
|
|
497
|
-
return _context2.abrupt("return", this.context.canvas.toDataURL(type, encoderOptions));
|
|
498
|
-
case 3:
|
|
499
|
-
case "end":
|
|
500
|
-
return _context2.stop();
|
|
501
|
-
}
|
|
502
|
-
}
|
|
503
|
-
}, _callee2, this);
|
|
504
|
-
}));
|
|
505
|
-
function toDataURL(_x) {
|
|
506
|
-
return _toDataURL.apply(this, arguments);
|
|
587
|
+
}, {
|
|
588
|
+
key: "applyCursorStyle",
|
|
589
|
+
value: function applyCursorStyle(cursor) {
|
|
590
|
+
if (this.$container && this.$container.style) {
|
|
591
|
+
this.$container.style.cursor = cursor;
|
|
592
|
+
}
|
|
507
593
|
}
|
|
508
|
-
|
|
509
|
-
|
|
594
|
+
}, {
|
|
595
|
+
key: "toDataURL",
|
|
596
|
+
value: function () {
|
|
597
|
+
var _toDataURL = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
|
|
598
|
+
var options,
|
|
599
|
+
type,
|
|
600
|
+
encoderOptions,
|
|
601
|
+
_args2 = arguments;
|
|
602
|
+
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
603
|
+
while (1) {
|
|
604
|
+
switch (_context2.prev = _context2.next) {
|
|
605
|
+
case 0:
|
|
606
|
+
options = _args2.length > 0 && _args2[0] !== undefined ? _args2[0] : {};
|
|
607
|
+
type = options.type, encoderOptions = options.encoderOptions;
|
|
608
|
+
return _context2.abrupt("return", this.context.canvas.toDataURL(type, encoderOptions));
|
|
609
|
+
case 3:
|
|
610
|
+
case "end":
|
|
611
|
+
return _context2.stop();
|
|
612
|
+
}
|
|
613
|
+
}
|
|
614
|
+
}, _callee2, this);
|
|
615
|
+
}));
|
|
616
|
+
function toDataURL() {
|
|
617
|
+
return _toDataURL.apply(this, arguments);
|
|
618
|
+
}
|
|
619
|
+
return toDataURL;
|
|
620
|
+
}()
|
|
621
|
+
}]);
|
|
510
622
|
return Canvas2DContextService;
|
|
511
623
|
}();
|
|
512
624
|
|
|
513
625
|
var ContextRegisterPlugin = /*#__PURE__*/function (_AbstractRendererPlug) {
|
|
514
|
-
|
|
626
|
+
_inherits(ContextRegisterPlugin, _AbstractRendererPlug);
|
|
627
|
+
var _super = _createSuper(ContextRegisterPlugin);
|
|
515
628
|
function ContextRegisterPlugin() {
|
|
516
629
|
var _this;
|
|
630
|
+
_classCallCheck(this, ContextRegisterPlugin);
|
|
517
631
|
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
518
632
|
args[_key] = arguments[_key];
|
|
519
633
|
}
|
|
520
|
-
_this =
|
|
634
|
+
_this = _super.call.apply(_super, [this].concat(args));
|
|
521
635
|
_this.name = 'canvas-context-register';
|
|
522
636
|
return _this;
|
|
523
637
|
}
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
638
|
+
_createClass(ContextRegisterPlugin, [{
|
|
639
|
+
key: "init",
|
|
640
|
+
value: function init() {
|
|
641
|
+
this.context.ContextService = Canvas2DContextService;
|
|
642
|
+
}
|
|
643
|
+
}, {
|
|
644
|
+
key: "destroy",
|
|
645
|
+
value: function destroy() {
|
|
646
|
+
delete this.context.ContextService;
|
|
647
|
+
}
|
|
648
|
+
}]);
|
|
531
649
|
return ContextRegisterPlugin;
|
|
532
650
|
}(gLite.AbstractRendererPlugin);
|
|
533
651
|
|
|
534
652
|
var Renderer = /*#__PURE__*/function (_AbstractRenderer) {
|
|
535
|
-
|
|
653
|
+
_inherits(Renderer, _AbstractRenderer);
|
|
654
|
+
var _super = _createSuper(Renderer);
|
|
536
655
|
function Renderer(config) {
|
|
537
656
|
var _this;
|
|
538
|
-
|
|
657
|
+
_classCallCheck(this, Renderer);
|
|
658
|
+
_this = _super.call(this, config);
|
|
539
659
|
// register Canvas2DContext
|
|
540
660
|
_this.registerPlugin(new ContextRegisterPlugin());
|
|
541
661
|
_this.registerPlugin(new ImageLoader.Plugin());
|
|
@@ -549,7 +669,7 @@ var Renderer = /*#__PURE__*/function (_AbstractRenderer) {
|
|
|
549
669
|
_this.registerPlugin(new HTMLRenderer.Plugin());
|
|
550
670
|
return _this;
|
|
551
671
|
}
|
|
552
|
-
return Renderer;
|
|
672
|
+
return _createClass(Renderer);
|
|
553
673
|
}(gLite.AbstractRenderer);
|
|
554
674
|
|
|
555
675
|
exports.CanvasPathGenerator = CanvasPathGenerator__namespace;
|