@antv/g-webgpu 1.2.0 → 1.2.1

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
@@ -415,22 +415,114 @@ function _asyncToGenerator(fn) {
415
415
  };
416
416
  }
417
417
 
418
- function _inheritsLoose(subClass, superClass) {
419
- subClass.prototype = Object.create(superClass.prototype);
420
- subClass.prototype.constructor = subClass;
418
+ function _classCallCheck(instance, Constructor) {
419
+ if (!(instance instanceof Constructor)) {
420
+ throw new TypeError("Cannot call a class as a function");
421
+ }
422
+ }
423
+
424
+ function _defineProperties(target, props) {
425
+ for (var i = 0; i < props.length; i++) {
426
+ var descriptor = props[i];
427
+ descriptor.enumerable = descriptor.enumerable || false;
428
+ descriptor.configurable = true;
429
+ if ("value" in descriptor) descriptor.writable = true;
430
+ Object.defineProperty(target, descriptor.key, descriptor);
431
+ }
432
+ }
421
433
 
422
- _setPrototypeOf(subClass, superClass);
434
+ function _createClass(Constructor, protoProps, staticProps) {
435
+ if (protoProps) _defineProperties(Constructor.prototype, protoProps);
436
+ if (staticProps) _defineProperties(Constructor, staticProps);
437
+ Object.defineProperty(Constructor, "prototype", {
438
+ writable: false
439
+ });
440
+ return Constructor;
441
+ }
442
+
443
+ function _inherits(subClass, superClass) {
444
+ if (typeof superClass !== "function" && superClass !== null) {
445
+ throw new TypeError("Super expression must either be null or a function");
446
+ }
447
+
448
+ subClass.prototype = Object.create(superClass && superClass.prototype, {
449
+ constructor: {
450
+ value: subClass,
451
+ writable: true,
452
+ configurable: true
453
+ }
454
+ });
455
+ Object.defineProperty(subClass, "prototype", {
456
+ writable: false
457
+ });
458
+ if (superClass) _setPrototypeOf(subClass, superClass);
459
+ }
460
+
461
+ function _getPrototypeOf(o) {
462
+ _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) {
463
+ return o.__proto__ || Object.getPrototypeOf(o);
464
+ };
465
+ return _getPrototypeOf(o);
423
466
  }
424
467
 
425
468
  function _setPrototypeOf(o, p) {
426
- _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) {
469
+ _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) {
427
470
  o.__proto__ = p;
428
471
  return o;
429
472
  };
430
-
431
473
  return _setPrototypeOf(o, p);
432
474
  }
433
475
 
476
+ function _isNativeReflectConstruct() {
477
+ if (typeof Reflect === "undefined" || !Reflect.construct) return false;
478
+ if (Reflect.construct.sham) return false;
479
+ if (typeof Proxy === "function") return true;
480
+
481
+ try {
482
+ Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {}));
483
+ return true;
484
+ } catch (e) {
485
+ return false;
486
+ }
487
+ }
488
+
489
+ function _assertThisInitialized(self) {
490
+ if (self === void 0) {
491
+ throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
492
+ }
493
+
494
+ return self;
495
+ }
496
+
497
+ function _possibleConstructorReturn(self, call) {
498
+ if (call && (typeof call === "object" || typeof call === "function")) {
499
+ return call;
500
+ } else if (call !== void 0) {
501
+ throw new TypeError("Derived constructors may only return object or undefined");
502
+ }
503
+
504
+ return _assertThisInitialized(self);
505
+ }
506
+
507
+ function _createSuper(Derived) {
508
+ var hasNativeReflectConstruct = _isNativeReflectConstruct();
509
+
510
+ return function _createSuperInternal() {
511
+ var Super = _getPrototypeOf(Derived),
512
+ result;
513
+
514
+ if (hasNativeReflectConstruct) {
515
+ var NewTarget = _getPrototypeOf(this).constructor;
516
+
517
+ result = Reflect.construct(Super, arguments, NewTarget);
518
+ } else {
519
+ result = Super.apply(this, arguments);
520
+ }
521
+
522
+ return _possibleConstructorReturn(this, result);
523
+ };
524
+ }
525
+
434
526
  /******************************************************************************
435
527
  Copyright (c) Microsoft Corporation.
436
528
 
@@ -459,6 +551,8 @@ function __metadata(metadataKey, metadataValue) {
459
551
 
460
552
  var WebGLContextService = /*#__PURE__*/function () {
461
553
  function WebGLContextService() {
554
+ _classCallCheck(this, WebGLContextService);
555
+
462
556
  this.$container = void 0;
463
557
  this.$canvas = void 0;
464
558
  this.dpr = void 0;
@@ -466,106 +560,114 @@ var WebGLContextService = /*#__PURE__*/function () {
466
560
  this.canvasConfig = void 0;
467
561
  }
468
562
 
469
- var _proto = WebGLContextService.prototype;
563
+ _createClass(WebGLContextService, [{
564
+ key: "init",
565
+ value: function () {
566
+ var _init = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
567
+ var _this$canvasConfig, container, canvas, devicePixelRatio, $canvas, dpr;
470
568
 
471
- _proto.init = /*#__PURE__*/function () {
472
- var _init = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
473
- var _this$canvasConfig, container, canvas, devicePixelRatio, $canvas, dpr;
569
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
570
+ while (1) {
571
+ switch (_context.prev = _context.next) {
572
+ case 0:
573
+ _this$canvasConfig = this.canvasConfig, container = _this$canvasConfig.container, canvas = _this$canvasConfig.canvas, devicePixelRatio = _this$canvasConfig.devicePixelRatio;
474
574
 
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, devicePixelRatio = _this$canvasConfig.devicePixelRatio;
575
+ if (canvas) {
576
+ this.$canvas = canvas;
480
577
 
481
- if (canvas) {
482
- this.$canvas = canvas;
578
+ if (container && canvas.parentElement !== container) {
579
+ container.appendChild(canvas);
580
+ }
483
581
 
484
- if (container && canvas.parentElement !== container) {
485
- container.appendChild(canvas);
486
- }
582
+ this.$container = canvas.parentElement;
583
+ this.canvasConfig.container = this.$container;
584
+ } else if (container) {
585
+ // create container
586
+ this.$container = g.isString(container) ? document.getElementById(container) : container;
487
587
 
488
- this.$container = canvas.parentElement;
489
- this.canvasConfig.container = this.$container;
490
- } else if (container) {
491
- // create container
492
- this.$container = g.isString(container) ? document.getElementById(container) : container;
588
+ if (this.$container) {
589
+ // create canvas
590
+ $canvas = document.createElement('canvas');
591
+ this.$container.appendChild($canvas);
493
592
 
494
- if (this.$container) {
495
- // create canvas
496
- $canvas = document.createElement('canvas');
497
- this.$container.appendChild($canvas);
593
+ if (!this.$container.style.position) {
594
+ this.$container.style.position = 'relative';
595
+ }
498
596
 
499
- if (!this.$container.style.position) {
500
- this.$container.style.position = 'relative';
597
+ this.$canvas = $canvas;
501
598
  }
502
-
503
- this.$canvas = $canvas;
504
- }
505
- } // use user-defined dpr first
599
+ } // use user-defined dpr first
506
600
 
507
601
 
508
- dpr = devicePixelRatio || g.isBrowser && window.devicePixelRatio || 1;
509
- dpr = dpr >= 1 ? Math.ceil(dpr) : 1;
510
- this.dpr = dpr;
602
+ dpr = devicePixelRatio || g.isBrowser && window.devicePixelRatio || 1;
603
+ dpr = dpr >= 1 ? Math.ceil(dpr) : 1;
604
+ this.dpr = dpr;
511
605
 
512
- case 5:
513
- case "end":
514
- return _context.stop();
606
+ case 5:
607
+ case "end":
608
+ return _context.stop();
609
+ }
515
610
  }
516
- }
517
- }, _callee, this);
518
- }));
519
-
520
- function init() {
521
- return _init.apply(this, arguments);
522
- }
523
-
524
- return init;
525
- }();
526
-
527
- _proto.getDomElement = function getDomElement() {
528
- return this.$canvas;
529
- };
611
+ }, _callee, this);
612
+ }));
530
613
 
531
- _proto.getContext = function getContext() {
532
- return this.context;
533
- };
614
+ function init() {
615
+ return _init.apply(this, arguments);
616
+ }
534
617
 
535
- _proto.getBoundingClientRect = function getBoundingClientRect() {
536
- if (this.$canvas.getBoundingClientRect) {
537
- return this.$canvas.getBoundingClientRect();
618
+ return init;
619
+ }()
620
+ }, {
621
+ key: "getDomElement",
622
+ value: function getDomElement() {
623
+ return this.$canvas;
538
624
  }
539
- };
540
-
541
- _proto.destroy = function destroy() {
542
- // @ts-ignore
543
- if (this.$container && this.$canvas && this.$canvas.parentNode) {
625
+ }, {
626
+ key: "getContext",
627
+ value: function getContext() {
628
+ return this.context;
629
+ }
630
+ }, {
631
+ key: "getBoundingClientRect",
632
+ value: function getBoundingClientRect() {
633
+ if (this.$canvas.getBoundingClientRect) {
634
+ return this.$canvas.getBoundingClientRect();
635
+ }
636
+ }
637
+ }, {
638
+ key: "destroy",
639
+ value: function destroy() {
544
640
  // @ts-ignore
545
- this.$container.removeChild(this.$canvas);
641
+ if (this.$container && this.$canvas && this.$canvas.parentNode) {
642
+ // @ts-ignore
643
+ this.$container.removeChild(this.$canvas);
644
+ }
546
645
  }
547
- };
646
+ }, {
647
+ key: "resize",
648
+ value: function resize(width, height) {
649
+ if (this.$canvas) {
650
+ var dpr = this.getDPR(); // set canvas width & height
548
651
 
549
- _proto.resize = function resize(width, height) {
550
- if (this.$canvas) {
551
- var dpr = this.getDPR(); // set canvas width & height
652
+ this.$canvas.width = dpr * width;
653
+ this.$canvas.height = dpr * height; // set CSS style width & height
552
654
 
553
- this.$canvas.width = dpr * width;
554
- this.$canvas.height = dpr * height; // set CSS style width & height
555
-
556
- g.setDOMSize(this.$canvas, width, height);
655
+ g.setDOMSize(this.$canvas, width, height);
656
+ }
557
657
  }
558
- };
559
-
560
- _proto.getDPR = function getDPR() {
561
- return this.dpr;
562
- };
563
-
564
- _proto.applyCursorStyle = function applyCursorStyle(cursor) {
565
- if (this.$container && this.$container.style) {
566
- this.$container.style.cursor = cursor;
658
+ }, {
659
+ key: "getDPR",
660
+ value: function getDPR() {
661
+ return this.dpr;
567
662
  }
568
- };
663
+ }, {
664
+ key: "applyCursorStyle",
665
+ value: function applyCursorStyle(cursor) {
666
+ if (this.$container && this.$container.style) {
667
+ this.$container.style.cursor = cursor;
668
+ }
669
+ }
670
+ }]);
569
671
 
570
672
  return WebGLContextService;
571
673
  }();
@@ -584,29 +686,37 @@ var containerModule = g.Module(function (register) {
584
686
  });
585
687
  var ContextRegisterPlugin = /*#__PURE__*/function () {
586
688
  function ContextRegisterPlugin() {
689
+ _classCallCheck(this, ContextRegisterPlugin);
690
+
587
691
  this.name = 'webgpu-context-register';
588
692
  }
589
693
 
590
- var _proto = ContextRegisterPlugin.prototype;
591
-
592
- _proto.init = function init(container) {
593
- container.load(containerModule, true);
594
- };
595
-
596
- _proto.destroy = function destroy(container) {
597
- container.unload(containerModule);
598
- };
694
+ _createClass(ContextRegisterPlugin, [{
695
+ key: "init",
696
+ value: function init(container) {
697
+ container.load(containerModule, true);
698
+ }
699
+ }, {
700
+ key: "destroy",
701
+ value: function destroy(container) {
702
+ container.unload(containerModule);
703
+ }
704
+ }]);
599
705
 
600
706
  return ContextRegisterPlugin;
601
707
  }();
602
708
 
603
709
  var Renderer = /*#__PURE__*/function (_AbstractRenderer) {
604
- _inheritsLoose(Renderer, _AbstractRenderer);
710
+ _inherits(Renderer, _AbstractRenderer);
711
+
712
+ var _super = _createSuper(Renderer);
605
713
 
606
714
  function Renderer(config) {
607
715
  var _this;
608
716
 
609
- _this = _AbstractRenderer.call(this, config) || this;
717
+ _classCallCheck(this, Renderer);
718
+
719
+ _this = _super.call(this, config);
610
720
 
611
721
  _this.registerPlugin(new ContextRegisterPlugin());
612
722
 
@@ -623,7 +733,7 @@ var Renderer = /*#__PURE__*/function (_AbstractRenderer) {
623
733
  return _this;
624
734
  }
625
735
 
626
- return Renderer;
736
+ return _createClass(Renderer);
627
737
  }(g.AbstractRenderer);
628
738
 
629
739
  exports.DeviceRenderer = DeviceRenderer__namespace;