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