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