plusui-native-core 0.1.4 → 0.1.5

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 (54) hide show
  1. package/Core/CMakeLists.txt +190 -7
  2. package/Core/Features/App/app.cpp +129 -0
  3. package/Core/Features/App/app.ts +126 -0
  4. package/Core/Features/Browser/browser.cpp +181 -0
  5. package/Core/Features/Browser/browser.ts +182 -0
  6. package/Core/Features/Clipboard/clipboard.cpp +234 -0
  7. package/Core/Features/Clipboard/clipboard.ts +113 -0
  8. package/Core/Features/Display/display.cpp +209 -0
  9. package/Core/Features/Display/display.ts +104 -0
  10. package/Core/Features/Event/Events.ts +166 -0
  11. package/Core/Features/Event/events.cpp +200 -0
  12. package/Core/Features/Keyboard/keyboard.cpp +186 -0
  13. package/Core/Features/Keyboard/keyboard.ts +175 -0
  14. package/Core/Features/Menu/context-menu.css +293 -0
  15. package/Core/Features/Menu/menu.cpp +481 -0
  16. package/Core/Features/Menu/menu.ts +439 -0
  17. package/Core/Features/Tray/tray.cpp +310 -0
  18. package/Core/Features/Tray/tray.ts +68 -0
  19. package/Core/Features/WebGPU/webgpu.cpp +937 -0
  20. package/Core/Features/WebGPU/webgpu.ts +1013 -0
  21. package/Core/Features/WebView/webview.cpp +1052 -0
  22. package/Core/Features/WebView/webview.ts +510 -0
  23. package/Core/Features/Window/window.cpp +664 -0
  24. package/Core/Features/Window/window.ts +142 -0
  25. package/Core/Features/WindowManager/window_manager.cpp +341 -0
  26. package/Core/include/plusui/app.hpp +73 -0
  27. package/Core/include/plusui/browser.hpp +66 -0
  28. package/Core/include/plusui/clipboard.hpp +41 -0
  29. package/Core/include/plusui/events.hpp +58 -0
  30. package/Core/include/{keyboard.hpp → plusui/keyboard.hpp} +21 -44
  31. package/Core/include/plusui/menu.hpp +153 -0
  32. package/Core/include/plusui/tray.hpp +93 -0
  33. package/Core/include/plusui/webgpu.hpp +434 -0
  34. package/Core/include/plusui/webview.hpp +142 -0
  35. package/Core/include/plusui/window.hpp +111 -0
  36. package/Core/include/plusui/window_manager.hpp +57 -0
  37. package/Core/vendor/WebView2EnvironmentOptions.h +406 -0
  38. package/Core/vendor/stb_image.h +7988 -0
  39. package/Core/vendor/webview.h +618 -510
  40. package/Core/vendor/webview2.h +52079 -0
  41. package/README.md +19 -0
  42. package/package.json +12 -15
  43. package/Core/include/app.hpp +0 -121
  44. package/Core/include/menu.hpp +0 -79
  45. package/Core/include/tray.hpp +0 -81
  46. package/Core/include/window.hpp +0 -106
  47. package/Core/src/app.cpp +0 -311
  48. package/Core/src/display.cpp +0 -424
  49. package/Core/src/tray.cpp +0 -275
  50. package/Core/src/window.cpp +0 -528
  51. package/dist/index.d.ts +0 -205
  52. package/dist/index.js +0 -198
  53. package/src/index.ts +0 -574
  54. /package/Core/include/{display.hpp → plusui/display.hpp} +0 -0
@@ -0,0 +1,1013 @@
1
+ /**
2
+ * WebGPU Frontend API Wrapper
3
+ *
4
+ * Provides TypeScript bindings for the WebGPU C++ backend.
5
+ * All operations are async and communicate via JSON-RPC with the native backend.
6
+ */
7
+
8
+ // ============================================================================
9
+ // Type Definitions matching WebGPU specification
10
+ // ============================================================================
11
+
12
+ export interface GPUAdapter {
13
+ requestDevice(descriptor?: GPUDeviceDescriptor): Promise<GPUDevice>;
14
+ features: Set<string>;
15
+ limits: Record<string, number>;
16
+ info?: GPUAdapterInfo;
17
+ }
18
+
19
+ export interface GPUAdapterInfo {
20
+ vendor?: string;
21
+ architecture?: string;
22
+ device?: string;
23
+ description?: string;
24
+ }
25
+
26
+ export interface GPUDevice {
27
+ createBuffer(descriptor: GPUBufferDescriptor): GPUBuffer;
28
+ createTexture(descriptor: GPUTextureDescriptor): GPUTexture;
29
+ createSampler(descriptor?: GPUSamplerDescriptor): GPUSampler;
30
+ createShaderModule(descriptor: GPUShaderModuleDescriptor): GPUShaderModule;
31
+ createRenderPipeline(descriptor: GPURenderPipelineDescriptor): GPURenderPipeline;
32
+ createComputePipeline(descriptor: GPUComputePipelineDescriptor): GPUComputePipeline;
33
+ createBindGroupLayout(descriptor: GPUBindGroupLayoutDescriptor): GPUBindGroupLayout;
34
+ createBindGroup(descriptor: GPUBindGroupDescriptor): GPUBindGroup;
35
+ createCommandEncoder(descriptor?: GPUCommandEncoderDescriptor): GPUCommandEncoder;
36
+ queue: GPUQueue;
37
+ destroy(): void;
38
+ lost?: Promise<GPUDeviceLostInfo>;
39
+ }
40
+
41
+ export interface GPUDeviceLostInfo {
42
+ reason: 'unknown' | 'destroyed';
43
+ message?: string;
44
+ }
45
+
46
+ export interface GPUBuffer {
47
+ mapAsync(mode: GPUMapModeFlags, offset?: number, size?: number): Promise<void>;
48
+ getMappedRange(offset?: number, size?: number): ArrayBuffer;
49
+ unmap(): void;
50
+ destroy(): void;
51
+ size: number;
52
+ usage: number;
53
+ mapState: 'unmapped' | 'pending' | 'mapped';
54
+ }
55
+
56
+ export interface GPUTexture {
57
+ createView(descriptor?: GPUTextureViewDescriptor): GPUTextureView;
58
+ destroy(): void;
59
+ width: number;
60
+ height: number;
61
+ depthOrArrayLayers: number;
62
+ mipLevelCount: number;
63
+ sampleCount: number;
64
+ dimension: GPUTextureDimension;
65
+ format: GPUTextureFormat;
66
+ usage: number;
67
+ }
68
+
69
+ export interface GPUTextureView {
70
+ // Opaque handle
71
+ }
72
+
73
+ export interface GPUSampler {
74
+ // Opaque handle
75
+ }
76
+
77
+ export interface GPUShaderModule {
78
+ getCompilationInfo(): Promise<GPUCompilationInfo>;
79
+ }
80
+
81
+ export interface GPUCompilationInfo {
82
+ messages: GPUCompilationMessage[];
83
+ }
84
+
85
+ export interface GPUCompilationMessage {
86
+ message: string;
87
+ type: 'error' | 'warning' | 'info';
88
+ lineNum?: number;
89
+ linePos?: number;
90
+ }
91
+
92
+ export interface GPURenderPipeline {
93
+ getBindGroupLayout(index: number): GPUBindGroupLayout;
94
+ }
95
+
96
+ export interface GPUComputePipeline {
97
+ getBindGroupLayout(index: number): GPUBindGroupLayout;
98
+ }
99
+
100
+ export interface GPUBindGroupLayout {
101
+ // Opaque handle
102
+ }
103
+
104
+ export interface GPUBindGroup {
105
+ // Opaque handle
106
+ }
107
+
108
+ export interface GPUQueue {
109
+ submit(commandBuffers: GPUCommandBuffer[]): void;
110
+ writeBuffer(buffer: GPUBuffer, bufferOffset: number, data: ArrayBuffer | ArrayBufferView, dataOffset?: number, size?: number): void;
111
+ writeTexture(destination: GPUImageCopyTexture, data: ArrayBuffer | ArrayBufferView, dataLayout: GPUImageDataLayout, size: GPUExtent3D): void;
112
+ copyExternalImageToTexture(source: GPUImageCopyExternalImage, destination: GPUImageCopyTextureTagged, copySize: GPUExtent3D): void;
113
+ onSubmittedWorkDone(): Promise<void>;
114
+ }
115
+
116
+ export interface GPUCommandBuffer {
117
+ // Opaque handle
118
+ }
119
+
120
+ export interface GPUCommandEncoder {
121
+ beginRenderPass(descriptor: GPURenderPassDescriptor): GPURenderPassEncoder;
122
+ beginComputePass(descriptor?: GPUComputePassDescriptor): GPUComputePassEncoder;
123
+ copyBufferToBuffer(source: GPUBuffer, sourceOffset: number, destination: GPUBuffer, destinationOffset: number, size: number): void;
124
+ copyBufferToTexture(source: GPUImageCopyBuffer, destination: GPUImageCopyTexture, copySize: GPUExtent3D): void;
125
+ copyTextureToBuffer(source: GPUImageCopyTexture, destination: GPUImageCopyBuffer, copySize: GPUExtent3D): void;
126
+ copyTextureToTexture(source: GPUImageCopyTexture, destination: GPUImageCopyTexture, copySize: GPUExtent3D): void;
127
+ clearBuffer(buffer: GPUBuffer, offset?: number, size?: number): void;
128
+ finish(descriptor?: GPUCommandBufferDescriptor): GPUCommandBuffer;
129
+ }
130
+
131
+ export interface GPURenderPassEncoder {
132
+ setPipeline(pipeline: GPURenderPipeline): void;
133
+ setIndexBuffer(buffer: GPUBuffer, indexFormat: GPUIndexFormat, offset?: number, size?: number): void;
134
+ setVertexBuffer(slot: number, buffer: GPUBuffer, offset?: number, size?: number): void;
135
+ setBindGroup(index: number, bindGroup: GPUBindGroup, dynamicOffsets?: number[]): void;
136
+ draw(vertexCount: number, instanceCount?: number, firstVertex?: number, firstInstance?: number): void;
137
+ drawIndexed(indexCount: number, instanceCount?: number, firstIndex?: number, baseVertex?: number, firstInstance?: number): void;
138
+ drawIndirect(indirectBuffer: GPUBuffer, indirectOffset: number): void;
139
+ drawIndexedIndirect(indirectBuffer: GPUBuffer, indirectOffset: number): void;
140
+ end(): void;
141
+ }
142
+
143
+ export interface GPUComputePassEncoder {
144
+ setPipeline(pipeline: GPUComputePipeline): void;
145
+ setBindGroup(index: number, bindGroup: GPUBindGroup, dynamicOffsets?: number[]): void;
146
+ dispatchWorkgroups(workgroupCountX: number, workgroupCountY?: number, workgroupCountZ?: number): void;
147
+ dispatchWorkgroupsIndirect(indirectBuffer: GPUBuffer, indirectOffset: number): void;
148
+ end(): void;
149
+ }
150
+
151
+ // Descriptor types
152
+ export interface GPUBufferDescriptor {
153
+ size: number;
154
+ usage: GPUBufferUsageFlags;
155
+ mappedAtCreation?: boolean;
156
+ label?: string;
157
+ }
158
+
159
+ export interface GPUTextureDescriptor {
160
+ size: GPUExtent3D;
161
+ mipLevelCount?: number;
162
+ sampleCount?: number;
163
+ dimension?: GPUTextureDimension;
164
+ format: GPUTextureFormat;
165
+ usage: GPUTextureUsageFlags;
166
+ viewFormats?: GPUTextureFormat[];
167
+ label?: string;
168
+ }
169
+
170
+ export interface GPUTextureViewDescriptor {
171
+ format?: GPUTextureFormat;
172
+ dimension?: GPUTextureViewDimension;
173
+ aspect?: GPUTextureAspect;
174
+ baseMipLevel?: number;
175
+ mipLevelCount?: number;
176
+ baseArrayLayer?: number;
177
+ arrayLayerCount?: number;
178
+ label?: string;
179
+ }
180
+
181
+ export interface GPUSamplerDescriptor {
182
+ addressModeU?: GPUAddressMode;
183
+ addressModeV?: GPUAddressMode;
184
+ addressModeW?: GPUAddressMode;
185
+ magFilter?: GPUFilterMode;
186
+ minFilter?: GPUFilterMode;
187
+ mipmapFilter?: GPUMipmapFilterMode;
188
+ lodMinClamp?: number;
189
+ lodMaxClamp?: number;
190
+ compare?: GPUCompareFunction;
191
+ maxAnisotropy?: number;
192
+ label?: string;
193
+ }
194
+
195
+ export interface GPUShaderModuleDescriptor {
196
+ code: string;
197
+ sourceMap?: object;
198
+ label?: string;
199
+ }
200
+
201
+ export interface GPURenderPipelineDescriptor {
202
+ layout?: GPUPipelineLayout;
203
+ vertex: GPUVertexState;
204
+ primitive?: GPUPrimitiveState;
205
+ depthStencil?: GPUDepthStencilState;
206
+ multisample?: GPUMultisampleState;
207
+ fragment?: GPUFragmentState;
208
+ label?: string;
209
+ }
210
+
211
+ export interface GPUComputePipelineDescriptor {
212
+ layout?: GPUPipelineLayout;
213
+ compute: GPUProgrammableStageDescriptor;
214
+ label?: string;
215
+ }
216
+
217
+ export interface GPUBindGroupLayoutDescriptor {
218
+ entries: GPUBindGroupLayoutEntry[];
219
+ label?: string;
220
+ }
221
+
222
+ export interface GPUBindGroupLayoutEntry {
223
+ binding: number;
224
+ visibility: GPUShaderStageFlags;
225
+ buffer?: GPUBufferBindingLayout;
226
+ sampler?: GPUSamplerBindingLayout;
227
+ texture?: GPUTextureBindingLayout;
228
+ storageTexture?: GPUStorageTextureBindingLayout;
229
+ }
230
+
231
+ export interface GPUBindGroupDescriptor {
232
+ layout: GPUBindGroupLayout;
233
+ entries: GPUBindGroupEntry[];
234
+ label?: string;
235
+ }
236
+
237
+ export interface GPUBindGroupEntry {
238
+ binding: number;
239
+ resource: GPUBindingResource;
240
+ }
241
+
242
+ export type GPUBindingResource = GPUBuffer | GPUSampler | GPUTextureView;
243
+
244
+ export interface GPUCommandEncoderDescriptor {
245
+ label?: string;
246
+ }
247
+
248
+ export interface GPURenderPassDescriptor {
249
+ colorAttachments: (GPURenderPassColorAttachment | null)[];
250
+ depthStencilAttachment?: GPURenderPassDepthStencilAttachment;
251
+ occlusionQuerySet?: GPUQuerySet;
252
+ timestampWrites?: GPURenderPassTimestampWrites;
253
+ label?: string;
254
+ }
255
+
256
+ export interface GPURenderPassColorAttachment {
257
+ view: GPUTextureView;
258
+ resolveTarget?: GPUTextureView;
259
+ clearValue?: GPUColor;
260
+ loadOp: GPULoadOp;
261
+ storeOp: GPUStoreOp;
262
+ }
263
+
264
+ export interface GPURenderPassDepthStencilAttachment {
265
+ view: GPUTextureView;
266
+ depthClearValue?: number;
267
+ depthLoadOp?: GPULoadOp;
268
+ depthStoreOp?: GPUStoreOp;
269
+ depthReadOnly?: boolean;
270
+ stencilClearValue?: number;
271
+ stencilLoadOp?: GPULoadOp;
272
+ stencilStoreOp?: GPUStoreOp;
273
+ stencilReadOnly?: boolean;
274
+ }
275
+
276
+ export interface GPUComputePassDescriptor {
277
+ timestampWrites?: GPUComputePassTimestampWrites;
278
+ label?: string;
279
+ }
280
+
281
+ export interface GPUImageCopyBuffer {
282
+ buffer: GPUBuffer;
283
+ offset?: number;
284
+ bytesPerRow?: number;
285
+ rowsPerImage?: number;
286
+ }
287
+
288
+ export interface GPUImageCopyTexture {
289
+ texture: GPUTexture;
290
+ mipLevel?: number;
291
+ origin?: GPUOrigin3D;
292
+ aspect?: GPUTextureAspect;
293
+ }
294
+
295
+ export interface GPUImageCopyTextureTagged extends GPUImageCopyTexture {
296
+ colorSpace?: 'srgb' | 'display-p3';
297
+ premultipliedAlpha?: boolean;
298
+ }
299
+
300
+ export interface GPUImageCopyExternalImage {
301
+ source: HTMLCanvasElement | OffscreenCanvas | HTMLVideoElement;
302
+ origin?: GPUOrigin2D;
303
+ }
304
+
305
+ export interface GPUImageDataLayout {
306
+ offset?: number;
307
+ bytesPerRow?: number;
308
+ rowsPerImage?: number;
309
+ }
310
+
311
+ export interface GPUVertexState {
312
+ module: GPUShaderModule;
313
+ entryPoint: string;
314
+ buffers?: (GPUVertexBufferLayout | null)[];
315
+ }
316
+
317
+ export interface GPUFragmentState {
318
+ module: GPUShaderModule;
319
+ entryPoint: string;
320
+ targets: (GPUColorTargetState | null)[];
321
+ }
322
+
323
+ export interface GPUVertexBufferLayout {
324
+ arrayStride: number;
325
+ stepMode?: GPUVertexStepMode;
326
+ attributes: GPUVertexAttribute[];
327
+ }
328
+
329
+ export interface GPUVertexAttribute {
330
+ format: GPUVertexFormat;
331
+ offset?: number;
332
+ shaderLocation: number;
333
+ }
334
+
335
+ export interface GPUColorTargetState {
336
+ format: GPUTextureFormat;
337
+ blend?: GPUBlendState;
338
+ writeMask?: GPUColorWriteFlags;
339
+ }
340
+
341
+ export interface GPUBlendState {
342
+ color: GPUBlendComponent;
343
+ alpha: GPUBlendComponent;
344
+ }
345
+
346
+ export interface GPUBlendComponent {
347
+ operation?: GPUBlendOperation;
348
+ srcFactor?: GPUBlendFactor;
349
+ dstFactor?: GPUBlendFactor;
350
+ }
351
+
352
+ export interface GPUPrimitiveState {
353
+ topology?: GPUPrimitiveTopology;
354
+ stripIndexFormat?: GPUIndexFormat;
355
+ frontFace?: GPUFrontFace;
356
+ cullMode?: GPUCullMode;
357
+ unclippedDepth?: boolean;
358
+ }
359
+
360
+ export interface GPUDepthStencilState {
361
+ format: GPUTextureFormat;
362
+ depthWriteEnabled?: boolean;
363
+ depthCompare?: GPUCompareFunction;
364
+ stencilFront?: GPUStencilFaceState;
365
+ stencilBack?: GPUStencilFaceState;
366
+ stencilReadMask?: number;
367
+ stencilWriteMask?: number;
368
+ depthBias?: number;
369
+ depthBiasSlopeScale?: number;
370
+ depthBiasClamp?: number;
371
+ }
372
+
373
+ export interface GPUStencilFaceState {
374
+ compare?: GPUCompareFunction;
375
+ failOp?: GPUStencilOperation;
376
+ depthFailOp?: GPUStencilOperation;
377
+ passOp?: GPUStencilOperation;
378
+ }
379
+
380
+ export interface GPUMultisampleState {
381
+ count?: number;
382
+ mask?: number;
383
+ alphaToCoverageEnabled?: boolean;
384
+ }
385
+
386
+ export interface GPUProgrammableStageDescriptor {
387
+ module: GPUShaderModule;
388
+ entryPoint: string;
389
+ constants?: Record<string, number>;
390
+ }
391
+
392
+ export interface GPUBufferBindingLayout {
393
+ type?: GPUBufferBindingType;
394
+ hasDynamicOffset?: boolean;
395
+ minBindingSize?: number;
396
+ }
397
+
398
+ export interface GPUSamplerBindingLayout {
399
+ type?: GPUSamplerBindingType;
400
+ }
401
+
402
+ export interface GPUTextureBindingLayout {
403
+ sampleType?: GPUTextureSampleType;
404
+ viewDimension?: GPUTextureViewDimension;
405
+ multisampled?: boolean;
406
+ }
407
+
408
+ export interface GPUStorageTextureBindingLayout {
409
+ access: GPUStorageTextureAccess;
410
+ format: GPUTextureFormat;
411
+ viewDimension?: GPUTextureViewDimension;
412
+ }
413
+
414
+ export interface GPUPipelineLayout {
415
+ // Opaque handle
416
+ }
417
+
418
+ export interface GPUQuerySet {
419
+ // Opaque handle
420
+ }
421
+
422
+ // Flags and Enums
423
+ export type GPUBufferUsageFlags = number;
424
+ export const GPUBufferUsage = {
425
+ MAP_READ: 0x0001,
426
+ MAP_WRITE: 0x0002,
427
+ COPY_SRC: 0x0004,
428
+ COPY_DST: 0x0008,
429
+ INDEX: 0x0010,
430
+ VERTEX: 0x0020,
431
+ UNIFORM: 0x0040,
432
+ STORAGE: 0x0080,
433
+ INDIRECT: 0x0100,
434
+ QUERY_RESOLVE: 0x0200,
435
+ };
436
+
437
+ export type GPUTextureUsageFlags = number;
438
+ export const GPUTextureUsage = {
439
+ COPY_SRC: 0x0001,
440
+ COPY_DST: 0x0002,
441
+ TEXTURE_BINDING: 0x0004,
442
+ STORAGE_BINDING: 0x0008,
443
+ RENDER_ATTACHMENT: 0x0010,
444
+ };
445
+
446
+ export type GPUMapModeFlags = number;
447
+ export const GPUMapMode = {
448
+ READ: 0x0001,
449
+ WRITE: 0x0002,
450
+ };
451
+
452
+ export type GPUShaderStageFlags = number;
453
+ export const GPUShaderStage = {
454
+ VERTEX: 0x0001,
455
+ FRAGMENT: 0x0002,
456
+ COMPUTE: 0x0004,
457
+ };
458
+
459
+ export type GPUColorWriteFlags = number;
460
+ export const GPUColorWrite = {
461
+ RED: 0x1,
462
+ GREEN: 0x2,
463
+ BLUE: 0x4,
464
+ ALPHA: 0x8,
465
+ ALL: 0xF,
466
+ };
467
+
468
+ export type GPUTextureDimension = '1d' | '2d' | '3d';
469
+ export type GPUTextureFormat = 'r8unorm' | 'r8snorm' | 'r8uint' | 'r8sint' | 'r16uint' | 'r16sint' | 'r16float' | 'rg8unorm' | 'rg8snorm' | 'rg8uint' | 'rg8sint' | 'r32uint' | 'r32sint' | 'r32float' | 'rg16uint' | 'rg16sint' | 'rg16float' | 'rgba8unorm' | 'rgba8unorm-srgb' | 'rgba8snorm' | 'rgba8uint' | 'rgba8sint' | 'bgra8unorm' | 'bgra8unorm-srgb' | 'rgb9e5ufloat' | 'rgb10a2unorm' | 'rg11b10ufloat' | 'rg32uint' | 'rg32sint' | 'rg32float' | 'rgba16uint' | 'rgba16sint' | 'rgba16float' | 'rgba32uint' | 'rgba32sint' | 'rgba32float' | 'stencil8' | 'depth16unorm' | 'depth24plus' | 'depth24plus-stencil8' | 'depth32float' | 'depth32float-stencil8' | 'bc1-rgba-unorm' | 'bc1-rgba-unorm-srgb' | 'bc2-rgba-unorm' | 'bc2-rgba-unorm-srgb' | 'bc3-rgba-unorm' | 'bc3-rgba-unorm-srgb' | 'bc4-r-unorm' | 'bc4-r-snorm' | 'bc5-rg-unorm' | 'bc5-rg-snorm' | 'bc6h-rgb-ufloat' | 'bc6h-rgb-float' | 'bc7-rgba-unorm' | 'bc7-rgba-unorm-srgb' | 'etc1-rgb8-unorm' | 'etc2-rgb8unorm' | 'etc2-rgb8unorm-srgb' | 'etc2-rgb8a1unorm' | 'etc2-rgb8a1unorm-srgb' | 'etc2-rgba8unorm' | 'etc2-rgba8unorm-srgb' | 'eacr11unorm' | 'eacr11snorm' | 'eacrg11unorm' | 'eacrg11snorm' | 'astc-4x4-unorm' | 'astc-4x4-unorm-srgb' | 'astc-5x4-unorm' | 'astc-5x4-unorm-srgb' | 'astc-5x5-unorm' | 'astc-5x5-unorm-srgb' | 'astc-6x5-unorm' | 'astc-6x5-unorm-srgb' | 'astc-6x6-unorm' | 'astc-6x6-unorm-srgb' | 'astc-8x5-unorm' | 'astc-8x5-unorm-srgb' | 'astc-8x6-unorm' | 'astc-8x6-unorm-srgb' | 'astc-8x8-unorm' | 'astc-8x8-unorm-srgb' | 'astc-10x5-unorm' | 'astc-10x5-unorm-srgb' | 'astc-10x6-unorm' | 'astc-10x6-unorm-srgb' | 'astc-10x8-unorm' | 'astc-10x8-unorm-srgb' | 'astc-10x10-unorm' | 'astc-10x10-unorm-srgb' | 'astc-12x10-unorm' | 'astc-12x10-unorm-srgb' | 'astc-12x12-unorm' | 'astc-12x12-unorm-srgb';
470
+ export type GPUTextureViewDimension = '1d' | '2d' | '2d-array' | 'cube' | 'cube-array' | '3d';
471
+ export type GPUTextureAspect = 'all' | 'stencil-only' | 'depth-only';
472
+ export type GPUAddressMode = 'clamp-to-edge' | 'repeat' | 'mirror-repeat';
473
+ export type GPUFilterMode = 'nearest' | 'linear';
474
+ export type GPUMipmapFilterMode = 'nearest' | 'linear';
475
+ export type GPUCompareFunction = 'never' | 'less' | 'equal' | 'less-equal' | 'greater' | 'not-equal' | 'greater-equal' | 'always';
476
+ export type GPUIndexFormat = 'uint16' | 'uint32';
477
+ export type GPUPrimitiveTopology = 'point-list' | 'line-list' | 'line-strip' | 'triangle-list' | 'triangle-strip';
478
+ export type GPUFrontFace = 'ccw' | 'cw';
479
+ export type GPUCullMode = 'none' | 'front' | 'back';
480
+ export type GPUBlendFactor = 'zero' | 'one' | 'src' | 'one-minus-src' | 'src-alpha' | 'one-minus-src-alpha' | 'dst' | 'one-minus-dst' | 'dst-alpha' | 'one-minus-dst-alpha' | 'src-alpha-saturated' | 'constant' | 'one-minus-constant';
481
+ export type GPUBlendOperation = 'add' | 'subtract' | 'reverse-subtract' | 'min' | 'max';
482
+ export type GPUVertexFormat = 'uint8x2' | 'uint8x4' | 'sint8x2' | 'sint8x4' | 'unorm8x2' | 'unorm8x4' | 'snorm8x2' | 'snorm8x4' | 'uint16x2' | 'uint16x4' | 'sint16x2' | 'sint16x4' | 'unorm16x2' | 'unorm16x4' | 'snorm16x2' | 'snorm16x4' | 'float16x2' | 'float16x4' | 'float32' | 'float32x2' | 'float32x3' | 'float32x4' | 'uint32' | 'uint32x2' | 'uint32x3' | 'uint32x4' | 'sint32' | 'sint32x2' | 'sint32x3' | 'sint32x4';
483
+ export type GPUVertexStepMode = 'vertex' | 'instance';
484
+ export type GPUBufferBindingType = 'uniform' | 'storage' | 'read-only-storage';
485
+ export type GPUSamplerBindingType = 'filtering' | 'non-filtering' | 'comparison';
486
+ export type GPUTextureSampleType = 'float' | 'unfilterable-float' | 'depth' | 'sint' | 'uint';
487
+ export type GPUStorageTextureAccess = 'write-only' | 'read-only' | 'read-write';
488
+ export type GPULoadOp = 'load' | 'clear';
489
+ export type GPUStoreOp = 'store' | 'discard';
490
+ export type GPUStencilOperation = 'keep' | 'zero' | 'replace' | 'invert' | 'increment-clamp' | 'decrement-clamp' | 'increment-wrap' | 'decrement-wrap';
491
+
492
+ // Colors
493
+ export interface GPUColor {
494
+ r: number;
495
+ g: number;
496
+ b: number;
497
+ a?: number;
498
+ }
499
+
500
+ export interface GPUExtent3D {
501
+ width: number;
502
+ height?: number;
503
+ depthOrArrayLayers?: number;
504
+ }
505
+
506
+ export interface GPUOrigin2D {
507
+ x?: number;
508
+ y?: number;
509
+ }
510
+
511
+ export interface GPUOrigin3D {
512
+ x?: number;
513
+ y?: number;
514
+ z?: number;
515
+ }
516
+
517
+ // Request options
518
+ export interface GPURequestAdapterOptions {
519
+ powerPreference?: 'low-power' | 'high-performance';
520
+ forceFallbackAdapter?: boolean;
521
+ }
522
+
523
+ export interface GPUDeviceDescriptor {
524
+ requiredFeatures?: string[];
525
+ requiredLimits?: Record<string, number>;
526
+ defaultQueue?: GPUQueueDescriptor;
527
+ label?: string;
528
+ }
529
+
530
+ export interface GPUQueueDescriptor {
531
+ label?: string;
532
+ }
533
+
534
+ export interface GPURenderPassTimestampWrites {
535
+ querySet: GPUQuerySet;
536
+ beginningOfPassWriteIndex?: number;
537
+ endOfPassWriteIndex?: number;
538
+ }
539
+
540
+ export interface GPUComputePassTimestampWrites {
541
+ querySet: GPUQuerySet;
542
+ beginningOfPassWriteIndex?: number;
543
+ endOfPassWriteIndex?: number;
544
+ }
545
+
546
+ // ============================================================================
547
+ // WebGPU Frontend Implementation
548
+ // ============================================================================
549
+
550
+ /**
551
+ * Factory function to create a WebGPU instance
552
+ */
553
+ export function createWebGPU(
554
+ invokeFn: (name: string, args?: unknown[]) => Promise<unknown>,
555
+ onFn: (event: string, callback: (data: unknown) => void) => () => void
556
+ ): WebGPUNamespace {
557
+ return new WebGPUNamespace(invokeFn, onFn);
558
+ }
559
+
560
+ /**
561
+ * Global WebGPU namespace (like navigator.gpu)
562
+ */
563
+ class WebGPUNamespace {
564
+ private invokeFn: (name: string, args?: unknown[]) => Promise<unknown>;
565
+ private onFn: (event: string, callback: (data: unknown) => void) => () => void;
566
+
567
+ constructor(
568
+ invokeFn: (name: string, args?: unknown[]) => Promise<unknown>,
569
+ onFn: (event: string, callback: (data: unknown) => void) => () => void
570
+ ) {
571
+ this.invokeFn = invokeFn;
572
+ this.onFn = onFn;
573
+ }
574
+
575
+ async requestAdapter(options?: GPURequestAdapterOptions): Promise<GPUAdapter | null> {
576
+ const result = await this.invokeFn('webgpu.requestAdapter', [options || {}]);
577
+ if (!result) {
578
+ return null;
579
+ }
580
+
581
+ const adapterData = result as any;
582
+ return new GPUAdapterImpl(
583
+ adapterData.id,
584
+ this.invokeFn,
585
+ this.onFn,
586
+ adapterData.features || [],
587
+ adapterData.limits || {}
588
+ );
589
+ }
590
+
591
+ getPreferredCanvasFormat(): GPUTextureFormat {
592
+ return 'bgra8unorm';
593
+ }
594
+ }
595
+
596
+ /**
597
+ * Adapter implementation
598
+ */
599
+ class GPUAdapterImpl implements GPUAdapter {
600
+ features: Set<string>;
601
+ limits: Record<string, number>;
602
+ info?: GPUAdapterInfo;
603
+
604
+ private adapterId: string;
605
+ private invokeFn: (name: string, args?: unknown[]) => Promise<unknown>;
606
+ private onFn: (event: string, callback: (data: unknown) => void) => () => void;
607
+
608
+ constructor(
609
+ adapterId: string,
610
+ invokeFn: (name: string, args?: unknown[]) => Promise<unknown>,
611
+ onFn: (event: string, callback: (data: unknown) => void) => () => void,
612
+ features: string[],
613
+ limits: Record<string, number>
614
+ ) {
615
+ this.adapterId = adapterId;
616
+ this.invokeFn = invokeFn;
617
+ this.onFn = onFn;
618
+ this.features = new Set(features);
619
+ this.limits = limits;
620
+ }
621
+
622
+ async requestDevice(descriptor?: GPUDeviceDescriptor): Promise<GPUDevice> {
623
+ const result = await this.invokeFn('webgpu.requestDevice', [
624
+ this.adapterId,
625
+ JSON.stringify(descriptor || {})
626
+ ]);
627
+
628
+ if (!result) {
629
+ throw new Error('Failed to create GPU device');
630
+ }
631
+
632
+ const deviceData = result as any;
633
+ return new GPUDeviceImpl(
634
+ deviceData.id,
635
+ this.invokeFn,
636
+ this.onFn,
637
+ deviceData.features || [],
638
+ deviceData.limits || {}
639
+ );
640
+ }
641
+ }
642
+
643
+ /**
644
+ * Device implementation
645
+ */
646
+ class GPUDeviceImpl implements GPUDevice {
647
+ queue: GPUQueue;
648
+ private deviceId: string;
649
+ private invokeFn: (name: string, args?: unknown[]) => Promise<unknown>;
650
+ private onFn: (event: string, callback: (data: unknown) => void) => () => void;
651
+
652
+ constructor(
653
+ deviceId: string,
654
+ invokeFn: (name: string, args?: unknown[]) => Promise<unknown>,
655
+ onFn: (event: string, callback: (data: unknown) => void) => () => void,
656
+ _features: string[],
657
+ _limits: Record<string, number>
658
+ ) {
659
+ this.deviceId = deviceId;
660
+ this.invokeFn = invokeFn;
661
+ this.onFn = onFn;
662
+ this.queue = new GPUQueueImpl(deviceId, invokeFn);
663
+ }
664
+
665
+ createBuffer(descriptor: GPUBufferDescriptor): GPUBuffer {
666
+ // Async operations handled via queue submission
667
+ return new GPUBufferImpl(this.deviceId, descriptor, this.invokeFn);
668
+ }
669
+
670
+ createTexture(descriptor: GPUTextureDescriptor): GPUTexture {
671
+ return new GPUTextureImpl(this.deviceId, descriptor, this.invokeFn);
672
+ }
673
+
674
+ createSampler(descriptor?: GPUSamplerDescriptor): GPUSampler {
675
+ return new GPUSamplerImpl(this.deviceId, descriptor, this.invokeFn);
676
+ }
677
+
678
+ createShaderModule(descriptor: GPUShaderModuleDescriptor): GPUShaderModule {
679
+ return new GPUShaderModuleImpl(this.deviceId, descriptor, this.invokeFn);
680
+ }
681
+
682
+ createRenderPipeline(descriptor: GPURenderPipelineDescriptor): GPURenderPipeline {
683
+ return new GPURenderPipelineImpl(this.deviceId, descriptor, this.invokeFn);
684
+ }
685
+
686
+ createComputePipeline(descriptor: GPUComputePipelineDescriptor): GPUComputePipeline {
687
+ return new GPUComputePipelineImpl(this.deviceId, descriptor, this.invokeFn);
688
+ }
689
+
690
+ createBindGroupLayout(descriptor: GPUBindGroupLayoutDescriptor): GPUBindGroupLayout {
691
+ return new GPUBindGroupLayoutImpl(this.deviceId, descriptor, this.invokeFn);
692
+ }
693
+
694
+ createBindGroup(descriptor: GPUBindGroupDescriptor): GPUBindGroup {
695
+ return new GPUBindGroupImpl(this.deviceId, descriptor, this.invokeFn);
696
+ }
697
+
698
+ createCommandEncoder(_descriptor?: GPUCommandEncoderDescriptor): GPUCommandEncoder {
699
+ return new GPUCommandEncoderImpl(this.deviceId, this.invokeFn);
700
+ }
701
+
702
+ destroy(): void {
703
+ this.invokeFn('webgpu.destroyDevice', [this.deviceId]);
704
+ }
705
+
706
+ get lost(): Promise<GPUDeviceLostInfo> {
707
+ return Promise.resolve({ reason: 'unknown' });
708
+ }
709
+ }
710
+
711
+ // Minimal implementations for remaining classes...
712
+ class GPUBufferImpl implements GPUBuffer {
713
+ size: number;
714
+ usage: number;
715
+ mapState: 'unmapped' | 'pending' | 'mapped' = 'unmapped';
716
+ private bufferId: string = '';
717
+ private invokeFn: (name: string, args?: unknown[]) => Promise<unknown>;
718
+
719
+ constructor(
720
+ deviceId: string,
721
+ descriptor: GPUBufferDescriptor,
722
+ invokeFn: (name: string, args?: unknown[]) => Promise<unknown>
723
+ ) {
724
+ this.size = descriptor.size;
725
+ this.usage = descriptor.usage;
726
+ this.invokeFn = invokeFn;
727
+ // Async buffer creation - handled lazily
728
+ }
729
+
730
+ async mapAsync(mode: GPUMapModeFlags, offset?: number, size?: number): Promise<void> {
731
+ this.mapState = 'pending';
732
+ await this.invokeFn('webgpu.mapBuffer', [this.bufferId, mode === GPUMapMode.READ ? 'read' : 'write']);
733
+ this.mapState = 'mapped';
734
+ }
735
+
736
+ getMappedRange(offset?: number, size?: number): ArrayBuffer {
737
+ return new ArrayBuffer(this.size);
738
+ }
739
+
740
+ unmap(): void {
741
+ this.invokeFn('webgpu.unmapBuffer', [this.bufferId]);
742
+ this.mapState = 'unmapped';
743
+ }
744
+
745
+ destroy(): void {
746
+ this.invokeFn('webgpu.destroyResource', [this.bufferId]);
747
+ }
748
+ }
749
+
750
+ class GPUTextureImpl implements GPUTexture {
751
+ width: number;
752
+ height: number;
753
+ depthOrArrayLayers: number;
754
+ mipLevelCount: number;
755
+ sampleCount: number;
756
+ dimension: GPUTextureDimension;
757
+ format: GPUTextureFormat;
758
+ usage: number;
759
+ private textureId: string = '';
760
+ private invokeFn: (name: string, args?: unknown[]) => Promise<unknown>;
761
+
762
+ constructor(
763
+ deviceId: string,
764
+ descriptor: GPUTextureDescriptor,
765
+ invokeFn: (name: string, args?: unknown[]) => Promise<unknown>
766
+ ) {
767
+ this.width = descriptor.size.width;
768
+ this.height = descriptor.size.height || 1;
769
+ this.depthOrArrayLayers = descriptor.size.depthOrArrayLayers || 1;
770
+ this.mipLevelCount = descriptor.mipLevelCount || 1;
771
+ this.sampleCount = descriptor.sampleCount || 1;
772
+ this.dimension = descriptor.dimension || '2d';
773
+ this.format = descriptor.format;
774
+ this.usage = descriptor.usage;
775
+ this.invokeFn = invokeFn;
776
+ }
777
+
778
+ createView(descriptor?: GPUTextureViewDescriptor): GPUTextureView {
779
+ return new GPUTextureViewImpl(this.textureId, descriptor, this.invokeFn);
780
+ }
781
+
782
+ destroy(): void {
783
+ this.invokeFn('webgpu.destroyResource', [this.textureId]);
784
+ }
785
+ }
786
+
787
+ class GPUTextureViewImpl implements GPUTextureView {
788
+ // Opaque
789
+ }
790
+
791
+ class GPUSamplerImpl implements GPUSampler {
792
+ private samplerId: string = '';
793
+ private invokeFn: (name: string, args?: unknown[]) => Promise<unknown>;
794
+
795
+ constructor(
796
+ deviceId: string,
797
+ descriptor: GPUSamplerDescriptor | undefined,
798
+ invokeFn: (name: string, args?: unknown[]) => Promise<unknown>
799
+ ) {
800
+ this.invokeFn = invokeFn;
801
+ }
802
+ }
803
+
804
+ class GPUShaderModuleImpl implements GPUShaderModule {
805
+ private shaderId: string = '';
806
+ private invokeFn: (name: string, args?: unknown[]) => Promise<unknown>;
807
+
808
+ constructor(
809
+ deviceId: string,
810
+ descriptor: GPUShaderModuleDescriptor,
811
+ invokeFn: (name: string, args?: unknown[]) => Promise<unknown>
812
+ ) {
813
+ this.invokeFn = invokeFn;
814
+ }
815
+
816
+ async getCompilationInfo(): Promise<GPUCompilationInfo> {
817
+ return { messages: [] };
818
+ }
819
+ }
820
+
821
+ class GPURenderPipelineImpl implements GPURenderPipeline {
822
+ private pipelineId: string = '';
823
+ private invokeFn: (name: string, args?: unknown[]) => Promise<unknown>;
824
+
825
+ constructor(
826
+ deviceId: string,
827
+ descriptor: GPURenderPipelineDescriptor,
828
+ invokeFn: (name: string, args?: unknown[]) => Promise<unknown>
829
+ ) {
830
+ this.invokeFn = invokeFn;
831
+ }
832
+
833
+ getBindGroupLayout(index: number): GPUBindGroupLayout {
834
+ return new GPUBindGroupLayoutImpl('', {}, this.invokeFn);
835
+ }
836
+ }
837
+
838
+ class GPUComputePipelineImpl implements GPUComputePipeline {
839
+ private pipelineId: string = '';
840
+ private invokeFn: (name: string, args?: unknown[]) => Promise<unknown>;
841
+
842
+ constructor(
843
+ deviceId: string,
844
+ descriptor: GPUComputePipelineDescriptor,
845
+ invokeFn: (name: string, args?: unknown[]) => Promise<unknown>
846
+ ) {
847
+ this.invokeFn = invokeFn;
848
+ }
849
+
850
+ getBindGroupLayout(index: number): GPUBindGroupLayout {
851
+ return new GPUBindGroupLayoutImpl('', {}, this.invokeFn);
852
+ }
853
+ }
854
+
855
+ class GPUBindGroupLayoutImpl implements GPUBindGroupLayout {
856
+ constructor(
857
+ deviceId: string,
858
+ descriptor: GPUBindGroupLayoutDescriptor | {},
859
+ invokeFn: (name: string, args?: unknown[]) => Promise<unknown>
860
+ ) {}
861
+ }
862
+
863
+ class GPUBindGroupImpl implements GPUBindGroup {
864
+ constructor(
865
+ deviceId: string,
866
+ descriptor: GPUBindGroupDescriptor,
867
+ invokeFn: (name: string, args?: unknown[]) => Promise<unknown>
868
+ ) {}
869
+ }
870
+
871
+ class GPUQueueImpl implements GPUQueue {
872
+ private deviceId: string;
873
+ private invokeFn: (name: string, args?: unknown[]) => Promise<unknown>;
874
+
875
+ constructor(
876
+ deviceId: string,
877
+ invokeFn: (name: string, args?: unknown[]) => Promise<unknown>
878
+ ) {
879
+ this.deviceId = deviceId;
880
+ this.invokeFn = invokeFn;
881
+ }
882
+
883
+ submit(commandBuffers: GPUCommandBuffer[]): void {
884
+ // Submit commands
885
+ }
886
+
887
+ writeBuffer(
888
+ buffer: GPUBuffer,
889
+ bufferOffset: number,
890
+ data: ArrayBuffer | ArrayBufferView,
891
+ dataOffset?: number,
892
+ size?: number
893
+ ): void {
894
+ // Write buffer data
895
+ }
896
+
897
+ writeTexture(
898
+ destination: GPUImageCopyTexture,
899
+ data: ArrayBuffer | ArrayBufferView,
900
+ dataLayout: GPUImageDataLayout,
901
+ size: GPUExtent3D
902
+ ): void {
903
+ // Write texture data
904
+ }
905
+
906
+ copyExternalImageToTexture(
907
+ source: GPUImageCopyExternalImage,
908
+ destination: GPUImageCopyTextureTagged,
909
+ copySize: GPUExtent3D
910
+ ): void {
911
+ // Copy from external image
912
+ }
913
+
914
+ async onSubmittedWorkDone(): Promise<void> {
915
+ // Wait for GPU work
916
+ }
917
+ }
918
+
919
+ class GPUCommandEncoderImpl implements GPUCommandEncoder {
920
+ private encoderId: string = '';
921
+ private invokeFn: (name: string, args?: unknown[]) => Promise<unknown>;
922
+
923
+ constructor(
924
+ deviceId: string,
925
+ invokeFn: (name: string, args?: unknown[]) => Promise<unknown>
926
+ ) {
927
+ this.invokeFn = invokeFn;
928
+ }
929
+
930
+ beginRenderPass(descriptor: GPURenderPassDescriptor): GPURenderPassEncoder {
931
+ return new GPURenderPassEncoderImpl(this.encoderId, this.invokeFn);
932
+ }
933
+
934
+ beginComputePass(descriptor?: GPUComputePassDescriptor): GPUComputePassEncoder {
935
+ return new GPUComputePassEncoderImpl(this.encoderId, this.invokeFn);
936
+ }
937
+
938
+ copyBufferToBuffer(
939
+ source: GPUBuffer,
940
+ sourceOffset: number,
941
+ destination: GPUBuffer,
942
+ destinationOffset: number,
943
+ size: number
944
+ ): void {}
945
+
946
+ copyBufferToTexture(
947
+ source: GPUImageCopyBuffer,
948
+ destination: GPUImageCopyTexture,
949
+ copySize: GPUExtent3D
950
+ ): void {}
951
+
952
+ copyTextureToBuffer(
953
+ source: GPUImageCopyTexture,
954
+ destination: GPUImageCopyBuffer,
955
+ copySize: GPUExtent3D
956
+ ): void {}
957
+
958
+ copyTextureToTexture(
959
+ source: GPUImageCopyTexture,
960
+ destination: GPUImageCopyTexture,
961
+ copySize: GPUExtent3D
962
+ ): void {}
963
+
964
+ clearBuffer(buffer: GPUBuffer, offset?: number, size?: number): void {}
965
+
966
+ finish(descriptor?: GPUCommandBufferDescriptor): GPUCommandBuffer {
967
+ const bufferId = '';
968
+ return bufferId as any;
969
+ }
970
+ }
971
+
972
+ class GPURenderPassEncoderImpl implements GPURenderPassEncoder {
973
+ constructor(
974
+ encoderId: string,
975
+ invokeFn: (name: string, args?: unknown[]) => Promise<unknown>
976
+ ) {}
977
+
978
+ setPipeline(pipeline: GPURenderPipeline): void {}
979
+ setIndexBuffer(buffer: GPUBuffer, indexFormat: GPUIndexFormat, offset?: number, size?: number): void {}
980
+ setVertexBuffer(slot: number, buffer: GPUBuffer, offset?: number, size?: number): void {}
981
+ setBindGroup(index: number, bindGroup: GPUBindGroup, dynamicOffsets?: number[]): void {}
982
+ draw(vertexCount: number, instanceCount?: number, firstVertex?: number, firstInstance?: number): void {}
983
+ drawIndexed(indexCount: number, instanceCount?: number, firstIndex?: number, baseVertex?: number, firstInstance?: number): void {}
984
+ drawIndirect(indirectBuffer: GPUBuffer, indirectOffset: number): void {}
985
+ drawIndexedIndirect(indirectBuffer: GPUBuffer, indirectOffset: number): void {}
986
+ end(): void {}
987
+ }
988
+
989
+ class GPUComputePassEncoderImpl implements GPUComputePassEncoder {
990
+ constructor(
991
+ encoderId: string,
992
+ invokeFn: (name: string, args?: unknown[]) => Promise<unknown>
993
+ ) {}
994
+
995
+ setPipeline(pipeline: GPUComputePipeline): void {}
996
+ setBindGroup(index: number, bindGroup: GPUBindGroup, dynamicOffsets?: number[]): void {}
997
+ dispatchWorkgroups(workgroupCountX: number, workgroupCountY?: number, workgroupCountZ?: number): void {}
998
+ dispatchWorkgroupsIndirect(indirectBuffer: GPUBuffer, indirectOffset: number): void {}
999
+ end(): void {}
1000
+ }
1001
+
1002
+ // Export the namespace
1003
+ export const gpu = new WebGPUNamespace(
1004
+ async (name: string, args?: unknown[]) => {
1005
+ // This will be replaced with actual invoke function when integrated
1006
+ console.warn('WebGPU not connected');
1007
+ return null;
1008
+ },
1009
+ (event: string, callback: (data: unknown) => void) => {
1010
+ // This will be replaced with actual onFn when integrated
1011
+ return () => {};
1012
+ }
1013
+ );