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