react-native-wgpu 0.3.2 → 0.4.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.
Files changed (112) hide show
  1. package/README.md +7 -5
  2. package/lib/commonjs/Canvas.js +14 -6
  3. package/lib/commonjs/Canvas.js.map +1 -1
  4. package/lib/commonjs/WebGPUViewNativeComponent.web.js +99 -0
  5. package/lib/commonjs/WebGPUViewNativeComponent.web.js.map +1 -0
  6. package/lib/commonjs/WebPolyfillGPUModule.js +40 -0
  7. package/lib/commonjs/WebPolyfillGPUModule.js.map +1 -0
  8. package/lib/commonjs/hooks.js +3 -2
  9. package/lib/commonjs/hooks.js.map +1 -1
  10. package/lib/commonjs/index.js +4 -208
  11. package/lib/commonjs/index.js.map +1 -1
  12. package/lib/commonjs/main/index.js +227 -0
  13. package/lib/commonjs/main/index.js.map +1 -0
  14. package/lib/commonjs/main/index.web.js +51 -0
  15. package/lib/commonjs/main/index.web.js.map +1 -0
  16. package/lib/commonjs/types.js +2 -0
  17. package/lib/commonjs/types.js.map +1 -0
  18. package/lib/commonjs/utils.js +11 -0
  19. package/lib/commonjs/utils.js.map +1 -0
  20. package/lib/module/Canvas.js +12 -5
  21. package/lib/module/Canvas.js.map +1 -1
  22. package/lib/module/WebGPUViewNativeComponent.web.js +93 -0
  23. package/lib/module/WebGPUViewNativeComponent.web.js.map +1 -0
  24. package/lib/module/WebPolyfillGPUModule.js +38 -0
  25. package/lib/module/WebPolyfillGPUModule.js.map +1 -0
  26. package/lib/module/hooks.js +1 -1
  27. package/lib/module/hooks.js.map +1 -1
  28. package/lib/module/index.js +3 -160
  29. package/lib/module/index.js.map +1 -1
  30. package/lib/module/main/index.js +168 -0
  31. package/lib/module/main/index.js.map +1 -0
  32. package/lib/module/main/index.web.js +8 -0
  33. package/lib/module/main/index.web.js.map +1 -0
  34. package/lib/module/types.js +2 -0
  35. package/lib/module/types.js.map +1 -0
  36. package/lib/module/utils.js +5 -0
  37. package/lib/module/utils.js.map +1 -0
  38. package/lib/typescript/lib/commonjs/Canvas.d.ts +1 -2
  39. package/lib/typescript/lib/commonjs/WebGPUViewNativeComponent.web.d.ts +5 -0
  40. package/lib/typescript/lib/commonjs/WebGPUViewNativeComponent.web.d.ts.map +1 -0
  41. package/lib/typescript/lib/commonjs/WebPolyfillGPUModule.d.ts +2 -0
  42. package/lib/typescript/lib/commonjs/WebPolyfillGPUModule.d.ts.map +1 -0
  43. package/lib/typescript/lib/commonjs/hooks.d.ts +5 -6
  44. package/lib/typescript/lib/commonjs/hooks.d.ts.map +1 -1
  45. package/lib/typescript/lib/commonjs/index.d.ts +0 -1
  46. package/lib/typescript/lib/commonjs/main/index.d.ts +3 -0
  47. package/lib/typescript/lib/commonjs/main/index.d.ts.map +1 -0
  48. package/lib/typescript/lib/commonjs/main/index.web.d.ts +2 -0
  49. package/lib/typescript/lib/commonjs/main/index.web.d.ts.map +1 -0
  50. package/lib/typescript/lib/commonjs/types.d.ts +1 -0
  51. package/lib/typescript/lib/commonjs/types.d.ts.map +1 -0
  52. package/lib/typescript/lib/commonjs/utils.d.ts +3 -0
  53. package/lib/typescript/lib/commonjs/utils.d.ts.map +1 -0
  54. package/lib/typescript/lib/module/Canvas.d.ts +2 -1
  55. package/lib/typescript/lib/module/Canvas.d.ts.map +1 -1
  56. package/lib/typescript/lib/module/WebGPUViewNativeComponent.web.d.ts +2 -0
  57. package/lib/typescript/lib/module/WebGPUViewNativeComponent.web.d.ts.map +1 -0
  58. package/lib/typescript/lib/module/WebPolyfillGPUModule.d.ts +2 -0
  59. package/lib/typescript/lib/module/WebPolyfillGPUModule.d.ts.map +1 -0
  60. package/lib/typescript/lib/module/hooks.d.ts +4 -3
  61. package/lib/typescript/lib/module/hooks.d.ts.map +1 -1
  62. package/lib/typescript/lib/module/index.d.ts +1 -5
  63. package/lib/typescript/lib/module/main/index.d.ts +6 -0
  64. package/lib/typescript/lib/module/main/index.d.ts.map +1 -0
  65. package/lib/typescript/lib/module/main/index.web.d.ts +5 -0
  66. package/lib/typescript/lib/module/main/index.web.d.ts.map +1 -0
  67. package/lib/typescript/lib/module/types.d.ts +1 -0
  68. package/lib/typescript/lib/module/types.d.ts.map +1 -0
  69. package/lib/typescript/lib/module/utils.d.ts +2 -0
  70. package/lib/typescript/lib/module/utils.d.ts.map +1 -0
  71. package/lib/typescript/src/Canvas.d.ts +3 -2
  72. package/lib/typescript/src/Canvas.d.ts.map +1 -1
  73. package/lib/typescript/src/WebGPUViewNativeComponent.d.ts +1 -1
  74. package/lib/typescript/src/WebGPUViewNativeComponent.d.ts.map +1 -1
  75. package/lib/typescript/src/WebGPUViewNativeComponent.web.d.ts +118 -0
  76. package/lib/typescript/src/WebGPUViewNativeComponent.web.d.ts.map +1 -0
  77. package/lib/typescript/src/WebPolyfillGPUModule.d.ts +2 -0
  78. package/lib/typescript/src/WebPolyfillGPUModule.d.ts.map +1 -0
  79. package/lib/typescript/src/hooks.d.ts +5 -4
  80. package/lib/typescript/src/hooks.d.ts.map +1 -1
  81. package/lib/typescript/src/index.d.ts +16 -5
  82. package/lib/typescript/src/index.d.ts.map +1 -1
  83. package/lib/typescript/src/main/index.d.ts +6 -0
  84. package/lib/typescript/src/main/index.d.ts.map +1 -0
  85. package/lib/typescript/src/main/index.web.d.ts +6 -0
  86. package/lib/typescript/src/main/index.web.d.ts.map +1 -0
  87. package/lib/typescript/src/types.d.ts +19 -0
  88. package/lib/typescript/src/types.d.ts.map +1 -0
  89. package/lib/typescript/src/utils.d.ts +2 -0
  90. package/lib/typescript/src/utils.d.ts.map +1 -0
  91. package/package.json +2 -1
  92. package/src/Canvas.tsx +18 -5
  93. package/src/WebGPUViewNativeComponent.ts +1 -1
  94. package/src/WebGPUViewNativeComponent.web.ts +108 -0
  95. package/src/WebPolyfillGPUModule.ts +53 -0
  96. package/src/hooks.tsx +2 -2
  97. package/src/index.tsx +25 -196
  98. package/src/main/index.tsx +204 -0
  99. package/src/main/index.web.tsx +8 -0
  100. package/src/types.ts +20 -0
  101. package/src/utils.ts +4 -0
  102. package/lib/commonjs/WebGPUView.js +0 -2
  103. package/lib/commonjs/WebGPUView.js.map +0 -1
  104. package/lib/module/WebGPUView.js +0 -2
  105. package/lib/module/WebGPUView.js.map +0 -1
  106. package/lib/typescript/lib/commonjs/WebGPUView.d.ts +0 -1
  107. package/lib/typescript/lib/commonjs/WebGPUView.d.ts.map +0 -1
  108. package/lib/typescript/lib/module/WebGPUView.d.ts +0 -1
  109. package/lib/typescript/lib/module/WebGPUView.d.ts.map +0 -1
  110. package/lib/typescript/src/WebGPUView.d.ts +0 -1
  111. package/lib/typescript/src/WebGPUView.d.ts.map +0 -1
  112. package/src/WebGPUView.tsx +0 -0
package/src/index.tsx CHANGED
@@ -1,197 +1,26 @@
1
- /* eslint-disable @typescript-eslint/no-explicit-any */
2
- import WebGPUNativeModule from "./NativeWebGPUModule";
3
-
4
- export * from "./Canvas";
5
- export * from "./Offscreen";
6
- export * from "./WebGPUViewNativeComponent";
7
- export * from "./hooks";
8
- export { default as WebGPUModule } from "./NativeWebGPUModule";
9
-
10
- const GPU: any = {};
11
- GPU[Symbol.hasInstance] = function (instance: object) {
12
- return "__brand" in instance && instance.__brand === "GPU";
13
- };
14
-
15
- const GPUAdapter: any = {};
16
- GPUAdapter[Symbol.hasInstance] = function (instance: object) {
17
- return "__brand" in instance && instance.__brand === "GPUAdapter";
18
- };
19
-
20
- const GPUAdapterInfo: any = {};
21
- GPUAdapterInfo[Symbol.hasInstance] = function (instance: object) {
22
- return "__brand" in instance && instance.__brand === "GPUAdapterInfo";
23
- };
24
-
25
- const GPUBindGroup: any = {};
26
- GPUBindGroup[Symbol.hasInstance] = function (instance: object) {
27
- return "__brand" in instance && instance.__brand === "GPUBindGroup";
28
- };
29
-
30
- const GPUBindGroupLayout: any = {};
31
- GPUBindGroupLayout[Symbol.hasInstance] = function (instance: object) {
32
- return "__brand" in instance && instance.__brand === "GPUBindGroupLayout";
33
- };
34
-
35
- const GPUBuffer: any = {};
36
- GPUBuffer[Symbol.hasInstance] = function (instance: object) {
37
- return "__brand" in instance && instance.__brand === "GPUBuffer";
38
- };
39
-
40
- const GPUCanvasContext: any = {};
41
- GPUCanvasContext[Symbol.hasInstance] = function (instance: object) {
42
- return "__brand" in instance && instance.__brand === "GPUCanvasContext";
43
- };
44
-
45
- const GPUCommandBuffer: any = {};
46
- GPUCommandBuffer[Symbol.hasInstance] = function (instance: object) {
47
- return "__brand" in instance && instance.__brand === "GPUCommandBuffer";
48
- };
49
-
50
- const GPUCommandEncoder: any = {};
51
- GPUCommandEncoder[Symbol.hasInstance] = function (instance: object) {
52
- return "__brand" in instance && instance.__brand === "GPUCommandEncoder";
53
- };
54
-
55
- const GPUCompilationInfo: any = {};
56
- GPUCompilationInfo[Symbol.hasInstance] = function (instance: object) {
57
- return "__brand" in instance && instance.__brand === "GPUCompilationInfo";
58
- };
59
-
60
- const GPUCompilationMessage: any = {};
61
- GPUCompilationMessage[Symbol.hasInstance] = function (instance: object) {
62
- return "__brand" in instance && instance.__brand === "GPUCompilationMessage";
63
- };
64
-
65
- const GPUComputePassEncoder: any = {};
66
- GPUComputePassEncoder[Symbol.hasInstance] = function (instance: object) {
67
- return "__brand" in instance && instance.__brand === "GPUComputePassEncoder";
68
- };
69
-
70
- const GPUComputePipeline: any = {};
71
- GPUComputePipeline[Symbol.hasInstance] = function (instance: object) {
72
- return "__brand" in instance && instance.__brand === "GPUComputePipeline";
73
- };
74
-
75
- const GPUDevice: any = {};
76
- GPUDevice[Symbol.hasInstance] = function (instance: object) {
77
- return "__brand" in instance && instance.__brand === "GPUDevice";
78
- };
79
-
80
- const GPUDeviceLostInfo: any = {};
81
- GPUDeviceLostInfo[Symbol.hasInstance] = function (instance: object) {
82
- return "__brand" in instance && instance.__brand === "GPUDeviceLostInfo";
83
- };
84
-
85
- const GPUError: any = {};
86
- GPUError[Symbol.hasInstance] = function (instance: object) {
87
- return "__brand" in instance && instance.__brand === "GPUError";
88
- };
89
-
90
- const GPUExternalTexture: any = {};
91
- GPUExternalTexture[Symbol.hasInstance] = function (instance: object) {
92
- return "__brand" in instance && instance.__brand === "GPUExternalTexture";
93
- };
94
-
95
- const GPUPipelineLayout: any = {};
96
- GPUPipelineLayout[Symbol.hasInstance] = function (instance: object) {
97
- return "__brand" in instance && instance.__brand === "GPUPipelineLayout";
98
- };
99
-
100
- const GPUQuerySet: any = {};
101
- GPUQuerySet[Symbol.hasInstance] = function (instance: object) {
102
- return "__brand" in instance && instance.__brand === "GPUQuerySet";
103
- };
104
-
105
- const GPUQueue: any = {};
106
- GPUQueue[Symbol.hasInstance] = function (instance: object) {
107
- return "__brand" in instance && instance.__brand === "GPUQueue";
108
- };
109
-
110
- const GPURenderBundle: any = {};
111
- GPURenderBundle[Symbol.hasInstance] = function (instance: object) {
112
- return "__brand" in instance && instance.__brand === "GPURenderBundle";
113
- };
114
-
115
- const GPURenderBundleEncoder: any = {};
116
- GPURenderBundleEncoder[Symbol.hasInstance] = function (instance: object) {
117
- return "__brand" in instance && instance.__brand === "GPURenderBundleEncoder";
118
- };
119
-
120
- const GPURenderPassEncoder: any = {};
121
- GPURenderPassEncoder[Symbol.hasInstance] = function (instance: object) {
122
- return "__brand" in instance && instance.__brand === "GPURenderPassEncoder";
123
- };
124
-
125
- const GPURenderPipeline: any = {};
126
- GPURenderPipeline[Symbol.hasInstance] = function (instance: object) {
127
- return "__brand" in instance && instance.__brand === "GPURenderPipeline";
128
- };
129
-
130
- const GPUSampler: any = {};
131
- GPUSampler[Symbol.hasInstance] = function (instance: object) {
132
- return "__brand" in instance && instance.__brand === "GPUSampler";
133
- };
134
-
135
- const GPUShaderModule: any = {};
136
- GPUShaderModule[Symbol.hasInstance] = function (instance: object) {
137
- return "__brand" in instance && instance.__brand === "GPUShaderModule";
138
- };
139
-
140
- const GPUTexture: any = {};
141
- GPUTexture[Symbol.hasInstance] = function (instance: object) {
142
- return "__brand" in instance && instance.__brand === "GPUTexture";
143
- };
144
-
145
- const GPUTextureView: any = {};
146
- GPUTextureView[Symbol.hasInstance] = function (instance: object) {
147
- return "__brand" in instance && instance.__brand === "GPUTextureView";
148
- };
149
-
150
- global.GPU = GPU;
151
- global.GPUAdapter = GPUAdapter;
152
- global.GPUAdapterInfo = GPUAdapterInfo;
153
- global.GPUBindGroup = GPUBindGroup;
154
- global.GPUBindGroupLayout = GPUBindGroupLayout;
155
- global.GPUBuffer = GPUBuffer;
156
- global.GPUCanvasContext = GPUCanvasContext;
157
- global.GPUCommandBuffer = GPUCommandBuffer;
158
- global.GPUCommandEncoder = GPUCommandEncoder;
159
- global.GPUCompilationInfo = GPUCompilationInfo;
160
- global.GPUCompilationMessage = GPUCompilationMessage;
161
- global.GPUComputePassEncoder = GPUComputePassEncoder;
162
- global.GPUComputePipeline = GPUComputePipeline;
163
- global.GPUDevice = GPUDevice;
164
- global.GPUDeviceLostInfo = GPUDeviceLostInfo;
165
- global.GPUError = GPUError;
166
- global.GPUExternalTexture = GPUExternalTexture;
167
- global.GPUPipelineLayout = GPUPipelineLayout;
168
- global.GPUQuerySet = GPUQuerySet;
169
- global.GPUQueue = GPUQueue;
170
- global.GPURenderBundle = GPURenderBundle;
171
- global.GPURenderBundleEncoder = GPURenderBundleEncoder;
172
- global.GPURenderPassEncoder = GPURenderPassEncoder;
173
- global.GPURenderPipeline = GPURenderPipeline;
174
- global.GPUSampler = GPUSampler;
175
- global.GPUShaderModule = GPUShaderModule;
176
- global.GPUTexture = GPUTexture;
177
- global.GPUTextureView = GPUTextureView;
178
-
179
- WebGPUNativeModule.install();
180
-
181
- if (!navigator) {
182
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
183
- // @ts-expect-error
184
- navigator = {};
1
+ /// <reference types="@webgpu/types" />
2
+
3
+ import type { NativeCanvas, RNCanvasContext } from "./types";
4
+
5
+ export * from "./main";
6
+
7
+ declare global {
8
+ interface Navigator {
9
+ gpu: GPU;
10
+ }
11
+
12
+ var navigator: Navigator;
13
+
14
+ var RNWebGPU: {
15
+ gpu: GPU;
16
+ fabric: boolean;
17
+ getNativeSurface: (contextId: number) => NativeCanvas;
18
+ MakeWebGPUCanvasContext: (
19
+ contextId: number,
20
+ width: number,
21
+ height: number,
22
+ ) => RNCanvasContext;
23
+ DecodeToUTF8: (buffer: NodeJS.ArrayBufferView | ArrayBuffer) => string;
24
+ createImageBitmap: typeof createImageBitmap;
25
+ };
185
26
  }
186
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
187
- // @ts-expect-error
188
- navigator.gpu = RNWebGPU.gpu;
189
-
190
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
191
- // @ts-ignore
192
- navigator.userAgent = "react-native";
193
-
194
- global.createImageBitmap =
195
- global.createImageBitmap ??
196
- ((...params: Parameters<typeof createImageBitmap>) =>
197
- new Promise((resolve) => resolve(RNWebGPU.createImageBitmap(...params))));
@@ -0,0 +1,204 @@
1
+ /* eslint-disable @typescript-eslint/no-explicit-any */
2
+ import WebGPUModule from "../NativeWebGPUModule";
3
+
4
+ export * from "../Canvas";
5
+ export * from "../Offscreen";
6
+ export * from "../WebGPUViewNativeComponent";
7
+ export * from "../hooks";
8
+
9
+ export { default as WebGPUModule } from "../NativeWebGPUModule";
10
+
11
+ const GPU: any = {};
12
+ GPU[Symbol.hasInstance] = function (instance: object) {
13
+ return "__brand" in instance && instance.__brand === "GPU";
14
+ };
15
+
16
+ const GPUAdapter: any = {};
17
+ GPUAdapter[Symbol.hasInstance] = function (instance: object) {
18
+ return "__brand" in instance && instance.__brand === "GPUAdapter";
19
+ };
20
+
21
+ const GPUAdapterInfo: any = {};
22
+ GPUAdapterInfo[Symbol.hasInstance] = function (instance: object) {
23
+ return "__brand" in instance && instance.__brand === "GPUAdapterInfo";
24
+ };
25
+
26
+ const GPUBindGroup: any = {};
27
+ GPUBindGroup[Symbol.hasInstance] = function (instance: object) {
28
+ return "__brand" in instance && instance.__brand === "GPUBindGroup";
29
+ };
30
+
31
+ const GPUBindGroupLayout: any = {};
32
+ GPUBindGroupLayout[Symbol.hasInstance] = function (instance: object) {
33
+ return "__brand" in instance && instance.__brand === "GPUBindGroupLayout";
34
+ };
35
+
36
+ const GPUBuffer: any = {};
37
+ GPUBuffer[Symbol.hasInstance] = function (instance: object) {
38
+ return "__brand" in instance && instance.__brand === "GPUBuffer";
39
+ };
40
+
41
+ const GPUCanvasContext: any = {};
42
+ GPUCanvasContext[Symbol.hasInstance] = function (instance: object) {
43
+ return "__brand" in instance && instance.__brand === "GPUCanvasContext";
44
+ };
45
+
46
+ const GPUCommandBuffer: any = {};
47
+ GPUCommandBuffer[Symbol.hasInstance] = function (instance: object) {
48
+ return "__brand" in instance && instance.__brand === "GPUCommandBuffer";
49
+ };
50
+
51
+ const GPUCommandEncoder: any = {};
52
+ GPUCommandEncoder[Symbol.hasInstance] = function (instance: object) {
53
+ return "__brand" in instance && instance.__brand === "GPUCommandEncoder";
54
+ };
55
+
56
+ const GPUCompilationInfo: any = {};
57
+ GPUCompilationInfo[Symbol.hasInstance] = function (instance: object) {
58
+ return "__brand" in instance && instance.__brand === "GPUCompilationInfo";
59
+ };
60
+
61
+ const GPUCompilationMessage: any = {};
62
+ GPUCompilationMessage[Symbol.hasInstance] = function (instance: object) {
63
+ return "__brand" in instance && instance.__brand === "GPUCompilationMessage";
64
+ };
65
+
66
+ const GPUComputePassEncoder: any = {};
67
+ GPUComputePassEncoder[Symbol.hasInstance] = function (instance: object) {
68
+ return "__brand" in instance && instance.__brand === "GPUComputePassEncoder";
69
+ };
70
+
71
+ const GPUComputePipeline: any = {};
72
+ GPUComputePipeline[Symbol.hasInstance] = function (instance: object) {
73
+ return "__brand" in instance && instance.__brand === "GPUComputePipeline";
74
+ };
75
+
76
+ const GPUDevice: any = {};
77
+ GPUDevice[Symbol.hasInstance] = function (instance: object) {
78
+ return "__brand" in instance && instance.__brand === "GPUDevice";
79
+ };
80
+
81
+ const GPUDeviceLostInfo: any = {};
82
+ GPUDeviceLostInfo[Symbol.hasInstance] = function (instance: object) {
83
+ return "__brand" in instance && instance.__brand === "GPUDeviceLostInfo";
84
+ };
85
+
86
+ const GPUError: any = {};
87
+ GPUError[Symbol.hasInstance] = function (instance: object) {
88
+ return "__brand" in instance && instance.__brand === "GPUError";
89
+ };
90
+
91
+ const GPUExternalTexture: any = {};
92
+ GPUExternalTexture[Symbol.hasInstance] = function (instance: object) {
93
+ return "__brand" in instance && instance.__brand === "GPUExternalTexture";
94
+ };
95
+
96
+ const GPUPipelineLayout: any = {};
97
+ GPUPipelineLayout[Symbol.hasInstance] = function (instance: object) {
98
+ return "__brand" in instance && instance.__brand === "GPUPipelineLayout";
99
+ };
100
+
101
+ const GPUQuerySet: any = {};
102
+ GPUQuerySet[Symbol.hasInstance] = function (instance: object) {
103
+ return "__brand" in instance && instance.__brand === "GPUQuerySet";
104
+ };
105
+
106
+ const GPUQueue: any = {};
107
+ GPUQueue[Symbol.hasInstance] = function (instance: object) {
108
+ return "__brand" in instance && instance.__brand === "GPUQueue";
109
+ };
110
+
111
+ const GPURenderBundle: any = {};
112
+ GPURenderBundle[Symbol.hasInstance] = function (instance: object) {
113
+ return "__brand" in instance && instance.__brand === "GPURenderBundle";
114
+ };
115
+
116
+ const GPURenderBundleEncoder: any = {};
117
+ GPURenderBundleEncoder[Symbol.hasInstance] = function (instance: object) {
118
+ return "__brand" in instance && instance.__brand === "GPURenderBundleEncoder";
119
+ };
120
+
121
+ const GPURenderPassEncoder: any = {};
122
+ GPURenderPassEncoder[Symbol.hasInstance] = function (instance: object) {
123
+ return "__brand" in instance && instance.__brand === "GPURenderPassEncoder";
124
+ };
125
+
126
+ const GPURenderPipeline: any = {};
127
+ GPURenderPipeline[Symbol.hasInstance] = function (instance: object) {
128
+ return "__brand" in instance && instance.__brand === "GPURenderPipeline";
129
+ };
130
+
131
+ const GPUSampler: any = {};
132
+ GPUSampler[Symbol.hasInstance] = function (instance: object) {
133
+ return "__brand" in instance && instance.__brand === "GPUSampler";
134
+ };
135
+
136
+ const GPUShaderModule: any = {};
137
+ GPUShaderModule[Symbol.hasInstance] = function (instance: object) {
138
+ return "__brand" in instance && instance.__brand === "GPUShaderModule";
139
+ };
140
+
141
+ const GPUTexture: any = {};
142
+ GPUTexture[Symbol.hasInstance] = function (instance: object) {
143
+ return "__brand" in instance && instance.__brand === "GPUTexture";
144
+ };
145
+
146
+ const GPUTextureView: any = {};
147
+ GPUTextureView[Symbol.hasInstance] = function (instance: object) {
148
+ return "__brand" in instance && instance.__brand === "GPUTextureView";
149
+ };
150
+
151
+ global.GPU = GPU;
152
+ global.GPUAdapter = GPUAdapter;
153
+ global.GPUAdapterInfo = GPUAdapterInfo;
154
+ global.GPUBindGroup = GPUBindGroup;
155
+ global.GPUBindGroupLayout = GPUBindGroupLayout;
156
+ global.GPUBuffer = GPUBuffer;
157
+ global.GPUCanvasContext = GPUCanvasContext;
158
+ global.GPUCommandBuffer = GPUCommandBuffer;
159
+ global.GPUCommandEncoder = GPUCommandEncoder;
160
+ global.GPUCompilationInfo = GPUCompilationInfo;
161
+ global.GPUCompilationMessage = GPUCompilationMessage;
162
+ global.GPUComputePassEncoder = GPUComputePassEncoder;
163
+ global.GPUComputePipeline = GPUComputePipeline;
164
+ global.GPUDevice = GPUDevice;
165
+ global.GPUDeviceLostInfo = GPUDeviceLostInfo;
166
+ global.GPUError = GPUError;
167
+ global.GPUExternalTexture = GPUExternalTexture;
168
+ global.GPUPipelineLayout = GPUPipelineLayout;
169
+ global.GPUQuerySet = GPUQuerySet;
170
+ global.GPUQueue = GPUQueue;
171
+ global.GPURenderBundle = GPURenderBundle;
172
+ global.GPURenderBundleEncoder = GPURenderBundleEncoder;
173
+ global.GPURenderPassEncoder = GPURenderPassEncoder;
174
+ global.GPURenderPipeline = GPURenderPipeline;
175
+ global.GPUSampler = GPUSampler;
176
+ global.GPUShaderModule = GPUShaderModule;
177
+ global.GPUTexture = GPUTexture;
178
+ global.GPUTextureView = GPUTextureView;
179
+
180
+ WebGPUModule.install();
181
+
182
+ if (!navigator) {
183
+ // @ts-expect-error Navigation object is more complex than this, setting it to an empty object to add gpu property
184
+ navigator = {
185
+ gpu: RNWebGPU.gpu,
186
+ userAgent: "react-native",
187
+ };
188
+ } else {
189
+ navigator.gpu = RNWebGPU.gpu;
190
+ if (typeof navigator.userAgent !== "string") {
191
+ try {
192
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
193
+ // @ts-ignore - Hermes navigator may not include a userAgent, align with the polyfill if needed
194
+ navigator.userAgent = "react-native";
195
+ } catch {
196
+ // navigator.userAgent can be read-only; ignore if assignment fails
197
+ }
198
+ }
199
+ }
200
+
201
+ global.createImageBitmap =
202
+ global.createImageBitmap ??
203
+ ((...params: Parameters<typeof createImageBitmap>) =>
204
+ new Promise((resolve) => resolve(RNWebGPU.createImageBitmap(...params))));
@@ -0,0 +1,8 @@
1
+ import "../WebPolyfillGPUModule";
2
+
3
+ export * from "../Canvas";
4
+ export * from "../Offscreen";
5
+ export * from "../WebGPUViewNativeComponent";
6
+ export * from "../hooks";
7
+
8
+ // We don't need to set all global properties on web, webgpu is already available globally
package/src/types.ts ADDED
@@ -0,0 +1,20 @@
1
+ type SurfacePointer = bigint;
2
+
3
+ export interface NativeCanvas {
4
+ surface: SurfacePointer;
5
+ width: number;
6
+ height: number;
7
+ clientWidth: number;
8
+ clientHeight: number;
9
+ }
10
+
11
+ export type RNCanvasContext = GPUCanvasContext & {
12
+ present: () => void;
13
+ };
14
+
15
+ export interface CanvasRef {
16
+ getContextId: () => number;
17
+ getContext(contextName: "webgpu"): RNCanvasContext | null;
18
+ getNativeSurface: () => NativeCanvas;
19
+ whenReady: (callback: () => void) => void;
20
+ }
package/src/utils.ts ADDED
@@ -0,0 +1,4 @@
1
+ // Only used on the web
2
+ export function contextIdToId(contextId: number) {
3
+ return "rnwgpu-canvas-" + contextId;
4
+ }
@@ -1,2 +0,0 @@
1
- "use strict";
2
- //# sourceMappingURL=WebGPUView.js.map
@@ -1 +0,0 @@
1
- {"version":3,"names":[],"sourceRoot":"../../src","sources":["WebGPUView.tsx"],"mappings":"","ignoreList":[]}
@@ -1,2 +0,0 @@
1
-
2
- //# sourceMappingURL=WebGPUView.js.map
@@ -1 +0,0 @@
1
- {"version":3,"names":[],"sourceRoot":"../../src","sources":["WebGPUView.tsx"],"mappings":"","ignoreList":[]}
@@ -1 +0,0 @@
1
- //# sourceMappingURL=WebGPUView.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"WebGPUView.d.ts","sourceRoot":"","sources":["../../../commonjs/WebGPUView.js"],"names":[],"mappings":""}
@@ -1 +0,0 @@
1
- //# sourceMappingURL=WebGPUView.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"WebGPUView.d.ts","sourceRoot":"","sources":["../../../module/WebGPUView.js"],"names":[],"mappings":""}
@@ -1 +0,0 @@
1
- //# sourceMappingURL=WebGPUView.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"WebGPUView.d.ts","sourceRoot":"","sources":["../../../src/WebGPUView.tsx"],"names":[],"mappings":""}
File without changes