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