@antv/g-webgpu 1.7.34 → 1.7.35

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