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