wgsl-play 0.0.26 → 0.0.28

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 CHANGED
@@ -82,9 +82,11 @@ The `?raw` suffix imports the file as a string. This keeps shaders alongside you
82
82
  - `src` - URL to .wesl/.wgsl file
83
83
  - `shader-root` - Root path for internal imports (default: `/shaders`)
84
84
  - `autoplay` - Start animating on load (default: `true`). Set `autoplay="false"` to start paused
85
+ - `transparent` - Use premultiplied alpha for transparent backgrounds (default: opaque)
85
86
 
86
87
  ### Properties
87
88
  - `source: string` - Get/set shader source
89
+ - `conditions: Record<string, boolean>` - Get/set conditions for conditional compilation (`@if`/`@elif`/`@else`)
88
90
  - `project: WeslProject` - Set full project config (weslSrc, libs, conditions, constants)
89
91
  - `isPlaying: boolean` - Playback state (readonly)
90
92
  - `time: number` - Animation time in seconds (readonly)
@@ -192,4 +194,7 @@ import { WgslPlay } from "wgsl-play/element";
192
194
  import { defaults } from "wgsl-play";
193
195
 
194
196
  defaults({ shaderRoot: "/custom/shaders" });
197
+
198
+ // Pre-bundled, all deps included
199
+ import "wgsl-play/bundle";
195
200
  ```
@@ -0,0 +1,115 @@
1
+ import { Conditions, LinkParams } from "wesl";
2
+
3
+ //#region src/Config.d.ts
4
+ /** Configuration for wgsl-play. */
5
+ interface WgslPlayConfig {
6
+ /** Root path for internal imports (package::, super::). Default: "/shaders" */
7
+ shaderRoot: string;
8
+ }
9
+ /** Set global defaults for all wgsl-play instances. */
10
+ declare function defaults(config: Partial<WgslPlayConfig>): void;
11
+ /** Get resolved config, merging element overrides with global defaults. */
12
+ declare function getConfig(overrides?: Partial<WgslPlayConfig>): WgslPlayConfig;
13
+ /** Reset config to defaults (useful for testing). */
14
+ declare function resetConfig(): void;
15
+ //#endregion
16
+ //#region src/WgslPlay.d.ts
17
+ /** Project configuration for multi-file shaders (subset of wesl link() API). */
18
+ type WeslProject = Pick<LinkParams, "weslSrc" | "rootModuleName" | "conditions" | "constants" | "libs" | "packageName">;
19
+ /** One source location within a compile error. */
20
+ interface CompileErrorLocation {
21
+ file?: string;
22
+ line: number;
23
+ column: number;
24
+ length?: number;
25
+ severity: "error" | "warning" | "info";
26
+ message: string;
27
+ }
28
+ /** Compile error detail for events. */
29
+ interface CompileErrorDetail {
30
+ message: string;
31
+ source: "wesl" | "webgpu";
32
+ locations: CompileErrorLocation[];
33
+ }
34
+ /** <wgsl-play> web component for rendering WESL/WGSL fragment shaders. */
35
+ declare class WgslPlay extends HTMLElement {
36
+ static observedAttributes: string[];
37
+ private canvas;
38
+ private errorOverlay;
39
+ private controls;
40
+ private resizeObserver;
41
+ private stopRenderLoop?;
42
+ private renderState?;
43
+ private playback;
44
+ private _weslSrc;
45
+ private _rootModuleName;
46
+ private _libs?;
47
+ private _linkOptions;
48
+ private _fromFullProject;
49
+ private _initPromise?;
50
+ private _sourceEl;
51
+ private _sourceListener;
52
+ private _theme;
53
+ private _mediaQuery;
54
+ private _onFullscreenChange;
55
+ /** Get config overrides from element attributes. */
56
+ private getConfigOverrides;
57
+ constructor();
58
+ connectedCallback(): void;
59
+ disconnectedCallback(): void;
60
+ attributeChangedCallback(name: string, oldValue: string | null, newValue: string | null): void;
61
+ /** Current shader source code (main module). */
62
+ get source(): string;
63
+ /** Set shader source directly. */
64
+ set source(value: string);
65
+ /** Conditions for conditional compilation (@if/@elif/@else). */
66
+ get conditions(): Conditions;
67
+ set conditions(value: Conditions);
68
+ /** Set project configuration (mirrors wesl link() API). */
69
+ set project(value: WeslProject);
70
+ /** Set sources from a full project with weslSrc. */
71
+ private setProjectSources;
72
+ /** Whether autoplay is enabled (default: true). Set autoplay="false" to start paused. */
73
+ get autoplay(): boolean;
74
+ set autoplay(value: boolean | string);
75
+ /** Whether the shader is currently playing. */
76
+ get isPlaying(): boolean;
77
+ /** Current animation time in seconds. */
78
+ get time(): number;
79
+ /** Number of frames rendered (for testing/debugging). */
80
+ get frameCount(): number;
81
+ /** Whether there's a compilation error. */
82
+ get hasError(): boolean;
83
+ /** Current error message, or null if no error. */
84
+ get errorMessage(): string | null;
85
+ /** Start playback. */
86
+ play(): void;
87
+ /** Pause playback. */
88
+ pause(): void;
89
+ private setPlaying;
90
+ /** Reset animation to time 0 and pause. */
91
+ rewind(): void;
92
+ /** Display error message in overlay. Pass empty string to clear. */
93
+ showError(message: string): void;
94
+ /** Toggle fullscreen on this element. */
95
+ toggleFullscreen(): void;
96
+ private updateTheme;
97
+ /** Set up WebGPU and load initial shader. Returns true if successful. */
98
+ private initialize;
99
+ private doInitialize;
100
+ /** Load from source element, src URL, script child, or inline textContent. */
101
+ private loadInitialContent;
102
+ /** Connect to a source provider element (e.g., wgsl-edit). */
103
+ private connectToSource;
104
+ /** Fetch shader from URL, auto-fetching any imported dependencies. */
105
+ private loadFromUrl;
106
+ /** Rebuild GPU pipeline using stored state. For full projects with all sources. */
107
+ private rebuildPipeline;
108
+ /** Discover dependencies and rebuild. For HTTP/inline sources that may need fetching. */
109
+ private discoverAndRebuild;
110
+ private handleCompileError;
111
+ /** Extract source locations from a WESL parse error or GPU compilation error. */
112
+ private extractLocations;
113
+ }
114
+ //#endregion
115
+ export { WgslPlayConfig as a, resetConfig as c, WgslPlay as i, CompileErrorLocation as n, defaults as o, WeslProject as r, getConfig as s, CompileErrorDetail as t };