@antv/g-webgpu 1.2.1 → 1.3.0

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.
@@ -1,6 +1,9 @@
1
1
  import type { RendererPlugin, Syringe } from '@antv/g';
2
+ import type * as DeviceRenderer from '@antv/g-plugin-device-renderer';
2
3
  export declare class ContextRegisterPlugin implements RendererPlugin {
4
+ private rendererPlugin;
3
5
  name: string;
6
+ constructor(rendererPlugin: DeviceRenderer.Plugin);
4
7
  init(container: Syringe.Container): void;
5
8
  destroy(container: Syringe.Container): void;
6
9
  }
@@ -1 +1 @@
1
- {"version":3,"file":"ContextRegisterPlugin.d.ts","sourceRoot":"","sources":["../src/ContextRegisterPlugin.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAWvD,qBAAa,qBAAsB,YAAW,cAAc;IAC1D,IAAI,SAA6B;IACjC,IAAI,CAAC,SAAS,EAAE,OAAO,CAAC,SAAS,GAAG,IAAI;IAGxC,OAAO,CAAC,SAAS,EAAE,OAAO,CAAC,SAAS,GAAG,IAAI;CAG5C"}
1
+ {"version":3,"file":"ContextRegisterPlugin.d.ts","sourceRoot":"","sources":["../src/ContextRegisterPlugin.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAEvD,OAAO,KAAK,KAAK,cAAc,MAAM,gCAAgC,CAAC;AAWtE,qBAAa,qBAAsB,YAAW,cAAc;IAE9C,OAAO,CAAC,cAAc;IADlC,IAAI,SAA6B;gBACb,cAAc,EAAE,cAAc,CAAC,MAAM;IAEzD,IAAI,CAAC,SAAS,EAAE,OAAO,CAAC,SAAS,GAAG,IAAI;IAMxC,OAAO,CAAC,SAAS,EAAE,OAAO,CAAC,SAAS,GAAG,IAAI;CAI5C"}
@@ -0,0 +1,20 @@
1
+ /// <reference types="@webgpu/types" />
2
+ import type { CanvasLike, DataURLOptions } from '@antv/g';
3
+ import { ContextService } from '@antv/g';
4
+ export declare class WebGPUContextService implements ContextService<GPUCanvasContext> {
5
+ private $container;
6
+ private $canvas;
7
+ private dpr;
8
+ private canvasConfig;
9
+ private deviceRendererPlugin;
10
+ init(): Promise<void>;
11
+ getDomElement(): CanvasLike;
12
+ getContext(): GPUCanvasContext;
13
+ getBoundingClientRect(): DOMRect;
14
+ destroy(): void;
15
+ resize(width: number, height: number): void;
16
+ getDPR(): number;
17
+ applyCursorStyle(cursor: string): void;
18
+ toDataURL(options: Partial<DataURLOptions>): Promise<string>;
19
+ }
20
+ //# sourceMappingURL=WebGPUContextService.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"WebGPUContextService.d.ts","sourceRoot":"","sources":["../src/WebGPUContextService.ts"],"names":[],"mappings":";AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAC1D,OAAO,EAEL,cAAc,EAMf,MAAM,SAAS,CAAC;AAIjB,qBACa,oBAAqB,YAAW,cAAc,CAAC,gBAAgB,CAAC;IAC3E,OAAO,CAAC,UAAU,CAAqB;IACvC,OAAO,CAAC,OAAO,CAAoB;IACnC,OAAO,CAAC,GAAG,CAAS;IAGpB,OAAO,CAAC,YAAY,CAAe;IAGnC,OAAO,CAAC,oBAAoB,CAAwB;IAE9C,IAAI;IAgCV,aAAa;IAIb,UAAU;IAKV,qBAAqB;IAMrB,OAAO;IAQP,MAAM,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM;IAapC,MAAM;IAIN,gBAAgB,CAAC,MAAM,EAAE,MAAM;IAMzB,SAAS,CAAC,OAAO,EAAE,OAAO,CAAC,cAAc,CAAC;CAGjD"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAC9C,OAAO,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAC3C,OAAO,KAAK,cAAc,MAAM,gCAAgC,CAAC;AACjE,OAAO,KAAK,cAAc,MAAM,gCAAgC,CAAC;AACjE,OAAO,KAAK,YAAY,MAAM,8BAA8B,CAAC;AAE7D,OAAO,KAAK,YAAY,MAAM,8BAA8B,CAAC;AAG7D,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,YAAY,EAAE,YAAY,EAAE,CAAC;AAEtE,aAAK,oBAAoB,GAAG,cAAc,CAAC;AAE3C,qBAAa,QAAS,SAAQ,gBAAgB;gBAChC,MAAM,CAAC,EAAE,OAAO,CAAC,oBAAoB,CAAC;CAUnD"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAC9C,OAAO,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAC3C,OAAO,KAAK,cAAc,MAAM,gCAAgC,CAAC;AACjE,OAAO,KAAK,cAAc,MAAM,gCAAgC,CAAC;AACjE,OAAO,KAAK,YAAY,MAAM,8BAA8B,CAAC;AAE7D,OAAO,KAAK,YAAY,MAAM,8BAA8B,CAAC;AAG7D,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,YAAY,EAAE,YAAY,EAAE,CAAC;AAEtE,aAAK,oBAAoB,GAAG,cAAc,CAAC;AAE3C,qBAAa,QAAS,SAAQ,gBAAgB;gBAChC,MAAM,CAAC,EAAE,OAAO,CAAC,oBAAoB,CAAC;CAWnD"}
package/dist/index.esm.js CHANGED
@@ -1,5 +1,5 @@
1
- import { inject, CanvasConfig, singleton, ContextService, setDOMSize, isString, isBrowser, Module, AbstractRenderer } from '@antv/g';
2
- import { Plugin as Plugin$2 } from '@antv/g-plugin-device-renderer';
1
+ import { Syringe, inject, CanvasConfig, singleton, ContextService, setDOMSize, isString, isBrowser, Module, AbstractRenderer } from '@antv/g';
2
+ import { Plugin } from '@antv/g-plugin-device-renderer';
3
3
  import * as DeviceRenderer from '@antv/g-plugin-device-renderer';
4
4
  export { DeviceRenderer };
5
5
  import { Plugin as Plugin$3 } from '@antv/g-plugin-dom-interaction';
@@ -8,8 +8,8 @@ export { DomInteraction };
8
8
  import { Plugin as Plugin$4 } from '@antv/g-plugin-html-renderer';
9
9
  import * as HTMLRenderer from '@antv/g-plugin-html-renderer';
10
10
  export { HTMLRenderer };
11
- import { Plugin } from '@antv/g-plugin-image-loader';
12
- import { Plugin as Plugin$1 } from '@antv/g-plugin-webgpu-device';
11
+ import { Plugin as Plugin$1 } from '@antv/g-plugin-image-loader';
12
+ import { Plugin as Plugin$2 } from '@antv/g-plugin-webgpu-device';
13
13
  import * as WebGPUDevice from '@antv/g-plugin-webgpu-device';
14
14
  export { WebGPUDevice };
15
15
 
@@ -394,54 +394,11 @@ function _asyncToGenerator(fn) {
394
394
  };
395
395
  }
396
396
 
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
- }
397
+ function _inheritsLoose(subClass, superClass) {
398
+ subClass.prototype = Object.create(superClass.prototype);
399
+ subClass.prototype.constructor = subClass;
412
400
 
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);
401
+ _setPrototypeOf(subClass, superClass);
445
402
  }
446
403
 
447
404
  function _setPrototypeOf(o, p) {
@@ -452,55 +409,7 @@ function _setPrototypeOf(o, p) {
452
409
  return _setPrototypeOf(o, p);
453
410
  }
454
411
 
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
- }
412
+ var DeviceRendererPlugin = Syringe.defineToken('DeviceRendererPlugin');
504
413
 
505
414
  /******************************************************************************
506
415
  Copyright (c) Microsoft Corporation.
@@ -528,183 +437,198 @@ function __metadata(metadataKey, metadataValue) {
528
437
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(metadataKey, metadataValue);
529
438
  }
530
439
 
531
- var WebGLContextService = /*#__PURE__*/function () {
532
- function WebGLContextService() {
533
- _classCallCheck(this, WebGLContextService);
534
-
440
+ var WebGPUContextService = /*#__PURE__*/function () {
441
+ function WebGPUContextService() {
535
442
  this.$container = void 0;
536
443
  this.$canvas = void 0;
537
444
  this.dpr = void 0;
538
- this.context = void 0;
539
445
  this.canvasConfig = void 0;
446
+ this.deviceRendererPlugin = void 0;
540
447
  }
541
448
 
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
+ var _proto = WebGPUContextService.prototype;
547
450
 
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;
451
+ _proto.init = /*#__PURE__*/function () {
452
+ var _init = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
453
+ var _this$canvasConfig, container, canvas, devicePixelRatio, $canvas, dpr;
553
454
 
554
- if (canvas) {
555
- this.$canvas = canvas;
455
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
456
+ while (1) {
457
+ switch (_context.prev = _context.next) {
458
+ case 0:
459
+ _this$canvasConfig = this.canvasConfig, container = _this$canvasConfig.container, canvas = _this$canvasConfig.canvas, devicePixelRatio = _this$canvasConfig.devicePixelRatio;
556
460
 
557
- if (container && canvas.parentElement !== container) {
558
- container.appendChild(canvas);
559
- }
461
+ if (canvas) {
462
+ this.$canvas = canvas;
560
463
 
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;
464
+ if (container && canvas.parentElement !== container) {
465
+ container.appendChild(canvas);
466
+ }
566
467
 
567
- if (this.$container) {
568
- // create canvas
569
- $canvas = document.createElement('canvas');
570
- this.$container.appendChild($canvas);
468
+ this.$container = canvas.parentElement;
469
+ this.canvasConfig.container = this.$container;
470
+ } else if (container) {
471
+ // create container
472
+ this.$container = isString(container) ? document.getElementById(container) : container;
571
473
 
572
- if (!this.$container.style.position) {
573
- this.$container.style.position = 'relative';
574
- }
474
+ if (this.$container) {
475
+ // create canvas
476
+ $canvas = document.createElement('canvas');
477
+ this.$container.appendChild($canvas);
575
478
 
576
- this.$canvas = $canvas;
479
+ if (!this.$container.style.position) {
480
+ this.$container.style.position = 'relative';
577
481
  }
578
- } // use user-defined dpr first
579
482
 
483
+ this.$canvas = $canvas;
484
+ }
485
+ } // use user-defined dpr first
580
486
 
581
- dpr = devicePixelRatio || isBrowser && window.devicePixelRatio || 1;
582
- dpr = dpr >= 1 ? Math.ceil(dpr) : 1;
583
- this.dpr = dpr;
584
487
 
585
- case 5:
586
- case "end":
587
- return _context.stop();
588
- }
589
- }
590
- }, _callee, this);
591
- }));
488
+ dpr = devicePixelRatio || isBrowser && window.devicePixelRatio || 1;
489
+ dpr = dpr >= 1 ? Math.ceil(dpr) : 1;
490
+ this.dpr = dpr;
592
491
 
593
- function init() {
594
- return _init.apply(this, arguments);
595
- }
492
+ case 5:
493
+ case "end":
494
+ return _context.stop();
495
+ }
496
+ }
497
+ }, _callee, this);
498
+ }));
596
499
 
597
- return init;
598
- }()
599
- }, {
600
- key: "getDomElement",
601
- value: function getDomElement() {
602
- return this.$canvas;
603
- }
604
- }, {
605
- key: "getContext",
606
- value: function getContext() {
607
- return this.context;
500
+ function init() {
501
+ return _init.apply(this, arguments);
608
502
  }
609
- }, {
610
- key: "getBoundingClientRect",
611
- value: function getBoundingClientRect() {
612
- if (this.$canvas.getBoundingClientRect) {
613
- return this.$canvas.getBoundingClientRect();
614
- }
503
+
504
+ return init;
505
+ }();
506
+
507
+ _proto.getDomElement = function getDomElement() {
508
+ return this.$canvas;
509
+ };
510
+
511
+ _proto.getContext = function getContext() {
512
+ // @ts-ignore
513
+ return this.deviceRendererPlugin.getDevice().canvasContext;
514
+ };
515
+
516
+ _proto.getBoundingClientRect = function getBoundingClientRect() {
517
+ if (this.$canvas.getBoundingClientRect) {
518
+ return this.$canvas.getBoundingClientRect();
615
519
  }
616
- }, {
617
- key: "destroy",
618
- value: function destroy() {
520
+ };
521
+
522
+ _proto.destroy = function destroy() {
523
+ // @ts-ignore
524
+ if (this.$container && this.$canvas && this.$canvas.parentNode) {
619
525
  // @ts-ignore
620
- if (this.$container && this.$canvas && this.$canvas.parentNode) {
621
- // @ts-ignore
622
- this.$container.removeChild(this.$canvas);
623
- }
526
+ this.$container.removeChild(this.$canvas);
624
527
  }
625
- }, {
626
- key: "resize",
627
- value: function resize(width, height) {
628
- if (this.$canvas) {
629
- var dpr = this.getDPR(); // set canvas width & height
528
+ };
630
529
 
631
- this.$canvas.width = dpr * width;
632
- this.$canvas.height = dpr * height; // set CSS style width & height
530
+ _proto.resize = function resize(width, height) {
531
+ if (this.$canvas) {
532
+ var dpr = this.getDPR(); // set canvas width & height
633
533
 
634
- setDOMSize(this.$canvas, width, height);
635
- }
534
+ this.$canvas.width = dpr * width;
535
+ this.$canvas.height = dpr * height; // set CSS style width & height
536
+
537
+ setDOMSize(this.$canvas, width, height);
636
538
  }
637
- }, {
638
- key: "getDPR",
639
- value: function getDPR() {
640
- return this.dpr;
539
+ };
540
+
541
+ _proto.getDPR = function getDPR() {
542
+ return this.dpr;
543
+ };
544
+
545
+ _proto.applyCursorStyle = function applyCursorStyle(cursor) {
546
+ if (this.$container && this.$container.style) {
547
+ this.$container.style.cursor = cursor;
641
548
  }
642
- }, {
643
- key: "applyCursorStyle",
644
- value: function applyCursorStyle(cursor) {
645
- if (this.$container && this.$container.style) {
646
- this.$container.style.cursor = cursor;
647
- }
549
+ };
550
+
551
+ _proto.toDataURL = /*#__PURE__*/function () {
552
+ var _toDataURL = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(options) {
553
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
554
+ while (1) {
555
+ switch (_context2.prev = _context2.next) {
556
+ case 0:
557
+ return _context2.abrupt("return", '');
558
+
559
+ case 1:
560
+ case "end":
561
+ return _context2.stop();
562
+ }
563
+ }
564
+ }, _callee2);
565
+ }));
566
+
567
+ function toDataURL(_x) {
568
+ return _toDataURL.apply(this, arguments);
648
569
  }
649
- }]);
650
570
 
651
- return WebGLContextService;
571
+ return toDataURL;
572
+ }();
573
+
574
+ return WebGPUContextService;
652
575
  }();
653
576
 
654
- __decorate([inject(CanvasConfig), __metadata("design:type", Object)], WebGLContextService.prototype, "canvasConfig", void 0);
577
+ __decorate([inject(CanvasConfig), __metadata("design:type", Object)], WebGPUContextService.prototype, "canvasConfig", void 0);
578
+
579
+ __decorate([inject(DeviceRendererPlugin), __metadata("design:type", Plugin)], WebGPUContextService.prototype, "deviceRendererPlugin", void 0);
655
580
 
656
- WebGLContextService = __decorate([singleton({
581
+ WebGPUContextService = __decorate([singleton({
657
582
  token: ContextService
658
- })], WebGLContextService);
583
+ })], WebGPUContextService);
659
584
 
660
585
  var containerModule = Module(function (register) {
661
586
  /**
662
587
  * implements ContextService
663
588
  */
664
- register(WebGLContextService);
589
+ register(WebGPUContextService);
665
590
  });
666
591
  var ContextRegisterPlugin = /*#__PURE__*/function () {
667
- function ContextRegisterPlugin() {
668
- _classCallCheck(this, ContextRegisterPlugin);
669
-
592
+ function ContextRegisterPlugin(rendererPlugin) {
593
+ this.rendererPlugin = void 0;
670
594
  this.name = 'webgpu-context-register';
595
+ this.rendererPlugin = rendererPlugin;
671
596
  }
672
597
 
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
- }]);
598
+ var _proto = ContextRegisterPlugin.prototype;
599
+
600
+ _proto.init = function init(container) {
601
+ container.register(DeviceRendererPlugin, {
602
+ useValue: this.rendererPlugin
603
+ });
604
+ container.load(containerModule, true);
605
+ };
606
+
607
+ _proto.destroy = function destroy(container) {
608
+ container.unload(containerModule);
609
+ container.remove(DeviceRendererPlugin);
610
+ };
684
611
 
685
612
  return ContextRegisterPlugin;
686
613
  }();
687
614
 
688
615
  var Renderer = /*#__PURE__*/function (_AbstractRenderer) {
689
- _inherits(Renderer, _AbstractRenderer);
690
-
691
- var _super = _createSuper(Renderer);
616
+ _inheritsLoose(Renderer, _AbstractRenderer);
692
617
 
693
618
  function Renderer(config) {
694
619
  var _this;
695
620
 
696
- _classCallCheck(this, Renderer);
697
-
698
- _this = _super.call(this, config);
621
+ _this = _AbstractRenderer.call(this, config) || this;
622
+ var deviceRendererPlugin = new Plugin();
699
623
 
700
- _this.registerPlugin(new ContextRegisterPlugin());
701
-
702
- _this.registerPlugin(new Plugin());
624
+ _this.registerPlugin(new ContextRegisterPlugin(deviceRendererPlugin));
703
625
 
704
626
  _this.registerPlugin(new Plugin$1());
705
627
 
706
628
  _this.registerPlugin(new Plugin$2());
707
629
 
630
+ _this.registerPlugin(deviceRendererPlugin);
631
+
708
632
  _this.registerPlugin(new Plugin$3());
709
633
 
710
634
  _this.registerPlugin(new Plugin$4());
@@ -712,7 +636,7 @@ var Renderer = /*#__PURE__*/function (_AbstractRenderer) {
712
636
  return _this;
713
637
  }
714
638
 
715
- return _createClass(Renderer);
639
+ return Renderer;
716
640
  }(AbstractRenderer);
717
641
 
718
642
  export { Renderer };