@antv/g-canvas 1.9.43 → 1.9.44

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.js CHANGED
@@ -369,10 +369,49 @@ function _asyncToGenerator(fn) {
369
369
  });
370
370
  };
371
371
  }
372
- function _inheritsLoose(subClass, superClass) {
373
- subClass.prototype = Object.create(superClass.prototype);
374
- subClass.prototype.constructor = subClass;
375
- _setPrototypeOf(subClass, superClass);
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,145 +486,172 @@ var Canvas2DContextService = /*#__PURE__*/function () {
393
486
  this.renderingContext = context.renderingContext;
394
487
  this.canvasConfig = context.config;
395
488
  }
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';
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) switch (_context.prev = _context.next) {
496
+ case 0:
497
+ _this$canvasConfig = this.canvasConfig, container = _this$canvasConfig.container, canvas = _this$canvasConfig.canvas;
498
+ if (canvas) {
499
+ this.$canvas = canvas;
500
+ if (container && canvas.parentElement !== container) {
501
+ container.appendChild(canvas);
502
+ }
503
+ this.$container = canvas.parentElement;
504
+ this.canvasConfig.container = this.$container;
505
+ } else if (container) {
506
+ // create container
507
+ this.$container = util.isString(container) ? document.getElementById(container) : container;
508
+ if (this.$container) {
509
+ // create canvas
510
+ $canvas = document.createElement('canvas');
511
+ this.$container.appendChild($canvas);
512
+ if (!this.$container.style.position) {
513
+ this.$container.style.position = 'relative';
514
+ }
515
+ this.$canvas = $canvas;
420
516
  }
421
- this.$canvas = $canvas;
422
517
  }
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);
518
+ this.context = this.$canvas.getContext('2d');
519
+ this.resize(this.canvasConfig.width, this.canvasConfig.height);
520
+ case 4:
521
+ case "end":
522
+ return _context.stop();
523
+ }
524
+ }, _callee, this);
525
+ }));
526
+ function init() {
527
+ return _init.apply(this, arguments);
528
+ }
529
+ return init;
530
+ }()
531
+ }, {
532
+ key: "getContext",
533
+ value: function getContext() {
534
+ return this.context;
434
535
  }
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();
536
+ }, {
537
+ key: "getDomElement",
538
+ value: function getDomElement() {
539
+ return this.$canvas;
449
540
  }
450
- };
451
- _proto.destroy = function destroy() {
452
- // @ts-ignore
453
- if (this.$container && this.$canvas && this.$canvas.parentNode) {
454
- // destroy context
455
- // @ts-ignore
456
- this.$container.removeChild(this.$canvas);
541
+ }, {
542
+ key: "getDPR",
543
+ value: function getDPR() {
544
+ return this.dpr;
457
545
  }
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);
546
+ }, {
547
+ key: "getBoundingClientRect",
548
+ value: function getBoundingClientRect() {
549
+ if (this.$canvas.getBoundingClientRect) {
550
+ return this.$canvas.getBoundingClientRect();
551
+ }
475
552
  }
553
+ }, {
554
+ key: "destroy",
555
+ value: function destroy() {
556
+ // @ts-ignore
557
+ if (this.$container && this.$canvas && this.$canvas.parentNode) {
558
+ // destroy context
559
+ // @ts-ignore
560
+ this.$container.removeChild(this.$canvas);
561
+ }
562
+ }
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
+ }
476
582
 
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;
583
+ this.renderingContext.renderReasons.add(gLite.RenderReason.CAMERA_CHANGED);
482
584
  }
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);
585
+ }, {
586
+ key: "applyCursorStyle",
587
+ value: function applyCursorStyle(cursor) {
588
+ if (this.$container && this.$container.style) {
589
+ this.$container.style.cursor = cursor;
590
+ }
503
591
  }
504
- return toDataURL;
505
- }();
592
+ }, {
593
+ key: "toDataURL",
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
+ }]);
506
618
  return Canvas2DContextService;
507
619
  }();
508
620
 
509
621
  var ContextRegisterPlugin = /*#__PURE__*/function (_AbstractRendererPlug) {
510
- _inheritsLoose(ContextRegisterPlugin, _AbstractRendererPlug);
622
+ _inherits(ContextRegisterPlugin, _AbstractRendererPlug);
623
+ var _super = _createSuper(ContextRegisterPlugin);
511
624
  function ContextRegisterPlugin() {
512
625
  var _this;
626
+ _classCallCheck(this, ContextRegisterPlugin);
513
627
  for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
514
628
  args[_key] = arguments[_key];
515
629
  }
516
- _this = _AbstractRendererPlug.call.apply(_AbstractRendererPlug, [this].concat(args)) || this;
630
+ _this = _super.call.apply(_super, [this].concat(args));
517
631
  _this.name = 'canvas-context-register';
518
632
  return _this;
519
633
  }
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
- };
634
+ _createClass(ContextRegisterPlugin, [{
635
+ key: "init",
636
+ value: function init() {
637
+ this.context.ContextService = Canvas2DContextService;
638
+ }
639
+ }, {
640
+ key: "destroy",
641
+ value: function destroy() {
642
+ delete this.context.ContextService;
643
+ }
644
+ }]);
527
645
  return ContextRegisterPlugin;
528
646
  }(gLite.AbstractRendererPlugin);
529
647
 
530
648
  var Renderer = /*#__PURE__*/function (_AbstractRenderer) {
531
- _inheritsLoose(Renderer, _AbstractRenderer);
649
+ _inherits(Renderer, _AbstractRenderer);
650
+ var _super = _createSuper(Renderer);
532
651
  function Renderer(config) {
533
652
  var _this;
534
- _this = _AbstractRenderer.call(this, config) || this;
653
+ _classCallCheck(this, Renderer);
654
+ _this = _super.call(this, config);
535
655
  // register Canvas2DContext
536
656
  _this.registerPlugin(new ContextRegisterPlugin());
537
657
  _this.registerPlugin(new ImageLoader.Plugin());
@@ -545,7 +665,7 @@ var Renderer = /*#__PURE__*/function (_AbstractRenderer) {
545
665
  _this.registerPlugin(new HTMLRenderer.Plugin());
546
666
  return _this;
547
667
  }
548
- return Renderer;
668
+ return _createClass(Renderer);
549
669
  }(gLite.AbstractRenderer);
550
670
 
551
671
  exports.CanvasPathGenerator = CanvasPathGenerator__namespace;