wgsl-play 0.0.2
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/README.md +80 -0
- package/package.json +25 -0
- package/playwright-report/index.html +81 -0
- package/playwright.config.ts +33 -0
- package/playwright.port.ts +2 -0
- package/src/BundleHydrator.ts +187 -0
- package/src/BundleLoader.ts +119 -0
- package/src/ErrorOverlay.ts +32 -0
- package/src/PackageLoader.ts +83 -0
- package/src/Renderer.ts +144 -0
- package/src/WgslPlay.css +28 -0
- package/src/WgslPlay.ts +308 -0
- package/src/index.ts +11 -0
- package/src/test/BundleHydrator.test.ts +122 -0
- package/src/test/WgslPlay.e2e.ts +38 -0
- package/src/test/WgslPlay.e2e.ts-snapshots/gradient-t0-chromium-darwin.png +0 -0
- package/src/vite-env.d.ts +1 -0
- package/test-page/index.html +28 -0
- package/test-page/main.ts +12 -0
- package/test-results/.last-run.json +4 -0
- package/tsconfig.json +4 -0
- package/vitest.config.ts +8 -0
package/README.md
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
# wgsl-play
|
|
2
|
+
|
|
3
|
+
Web component for rendering WESL/WGSL fragment shaders.
|
|
4
|
+
|
|
5
|
+
## Usage
|
|
6
|
+
|
|
7
|
+
```html
|
|
8
|
+
<script type="module">import "wgsl-play";</script>
|
|
9
|
+
|
|
10
|
+
<wgsl-play src="./shader.wesl"></wgsl-play>
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
That's it. The component auto-fetches dependencies and starts animating.
|
|
14
|
+
|
|
15
|
+
### Inline source
|
|
16
|
+
|
|
17
|
+
```html
|
|
18
|
+
<wgsl-play>
|
|
19
|
+
@fragment fn fs_main() -> @location(0) vec4f {
|
|
20
|
+
return vec4f(1.0, 0.0, 0.0, 1.0);
|
|
21
|
+
}
|
|
22
|
+
</wgsl-play>
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
### Programmatic control
|
|
26
|
+
|
|
27
|
+
```typescript
|
|
28
|
+
const player = document.querySelector("wgsl-play");
|
|
29
|
+
player.source = shaderCode;
|
|
30
|
+
player.pause();
|
|
31
|
+
player.rewind();
|
|
32
|
+
player.play();
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
## API
|
|
36
|
+
|
|
37
|
+
### Attributes
|
|
38
|
+
- `src` - URL to .wesl/.wgsl file
|
|
39
|
+
|
|
40
|
+
### Properties
|
|
41
|
+
- `source: string` - Get/set shader source
|
|
42
|
+
- `project: WeslProject` - Set full project config (weslSrc, libs, conditions, constants)
|
|
43
|
+
- `isPlaying: boolean` - Playback state (readonly)
|
|
44
|
+
- `time: number` - Animation time in seconds (readonly)
|
|
45
|
+
- `hasError: boolean` - Compilation error state (readonly)
|
|
46
|
+
- `errorMessage: string | null` - Error message (readonly)
|
|
47
|
+
|
|
48
|
+
### Methods
|
|
49
|
+
- `play()` - Start/resume animation
|
|
50
|
+
- `pause()` - Pause animation
|
|
51
|
+
- `rewind()` - Reset to t=0
|
|
52
|
+
- `showError(message)` - Display error (empty string clears)
|
|
53
|
+
|
|
54
|
+
### Events
|
|
55
|
+
- `compile-error` - `{ message: string }`
|
|
56
|
+
- `init-error` - `{ message: string }` (WebGPU init failed)
|
|
57
|
+
- `playback-change` - `{ isPlaying: boolean }`
|
|
58
|
+
|
|
59
|
+
## Styling
|
|
60
|
+
|
|
61
|
+
```css
|
|
62
|
+
wgsl-play {
|
|
63
|
+
width: 512px;
|
|
64
|
+
height: 512px;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
wgsl-play::part(canvas) {
|
|
68
|
+
image-rendering: pixelated;
|
|
69
|
+
}
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
## Exports
|
|
73
|
+
|
|
74
|
+
```typescript
|
|
75
|
+
// Default - auto-registers element
|
|
76
|
+
import "wgsl-play";
|
|
77
|
+
|
|
78
|
+
// Element class only (manual registration)
|
|
79
|
+
import { WgslPlay } from "wgsl-play/element";
|
|
80
|
+
```
|
package/package.json
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "wgsl-play",
|
|
3
|
+
"version": "0.0.2",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"exports": {
|
|
6
|
+
".": "./src/index.ts",
|
|
7
|
+
"./element": "./src/WgslPlay.ts"
|
|
8
|
+
},
|
|
9
|
+
"dependencies": {
|
|
10
|
+
"es-module-lexer": "^1.7.0",
|
|
11
|
+
"fflate": "^0.8.2",
|
|
12
|
+
"nanotar": "^0.2.0",
|
|
13
|
+
"wesl-gpu": "0.1.1",
|
|
14
|
+
"wesl": "0.6.47"
|
|
15
|
+
},
|
|
16
|
+
"devDependencies": {
|
|
17
|
+
"@playwright/test": "^1.53.2"
|
|
18
|
+
},
|
|
19
|
+
"scripts": {
|
|
20
|
+
"dev": "vite test-page",
|
|
21
|
+
"test": "vitest",
|
|
22
|
+
"test:e2e": "playwright test",
|
|
23
|
+
"typecheck": "tsgo"
|
|
24
|
+
}
|
|
25
|
+
}
|