@rosalana/sandbox 0.0.4 → 0.1.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.
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { AnyUniformValue, HookCallback, SandboxOptions, UniformSchema, WebGLVersion } from "./types";
1
+ import type { AnyUniformValue, HookCallback, ModuleDefinition, SandboxOptions, UniformSchema, WebGLVersion } from "./types";
2
2
  export * from "./types";
3
3
  export * from "./errors";
4
4
  /**
@@ -23,11 +23,13 @@ export declare class Sandbox {
23
23
  /** Active event listeners */
24
24
  private listeners;
25
25
  /** HTML canvas element */
26
- private canvas;
26
+ private canvasEl;
27
27
  /** Resolved options */
28
28
  private options;
29
29
  /** WebGL engine */
30
30
  private engine;
31
+ /** User sets custom vertex shader */
32
+ private usingCustomVertex;
31
33
  constructor(canvas: HTMLCanvasElement, options?: SandboxOptions);
32
34
  /**
33
35
  * Sandbox - A lightweight WebGL wrapper for shader effects.
@@ -48,6 +50,34 @@ export declare class Sandbox {
48
50
  * });
49
51
  */
50
52
  static create(canvas: HTMLCanvasElement, options?: SandboxOptions): Sandbox;
53
+ /**
54
+ * Define a shader module that can be imported in shader source with `#import <function> from "module_name"`.
55
+ * @example
56
+ * Sandbox.defineModule("my_module", source, { options });
57
+ * // Then in shader:
58
+ * // #import myFunc from "my_module"
59
+ * // void main() {
60
+ * // myFunc();
61
+ * // }
62
+ */
63
+ static defineModule(name: ModuleDefinition["name"], source: ModuleDefinition["source"], options?: ModuleDefinition["options"]): void;
64
+ /**
65
+ * Get the list of available shader modules that can be used with `#import` in shader source.
66
+ */
67
+ static availableModules(): {
68
+ name: string;
69
+ methods: string[];
70
+ uniforms: {
71
+ name: string;
72
+ type: import("./types").GLSLType;
73
+ }[];
74
+ options: Record<string, Record<string, import("./types").ModuleMethodOption>> | undefined;
75
+ }[];
76
+ /**
77
+ * Compile a shader source with Sandbox's shader preprocessor and return the final GLSL code.
78
+ * This is useful for debugging shader code or precompiling shaders for production use.
79
+ */
80
+ static compile(shaderSource: string): string;
51
81
  private resolveOptions;
52
82
  private setupListeners;
53
83
  private destroyListeners;
@@ -93,10 +123,32 @@ export declare class Sandbox {
93
123
  * sandbox.setFragment(fragmentSource);
94
124
  */
95
125
  setFragment(fragment: string): this;
126
+ /**
127
+ * Get current fragment shader source.
128
+ */
129
+ getFragment(): string;
130
+ /**
131
+ * Get current vertex shader source.
132
+ */
133
+ getVertex(): string;
134
+ /**
135
+ * Set the max frame rate runtime
136
+ *
137
+ * @example
138
+ * sandbox.setFps(30); // Limit to 30 FPS
139
+ * sandbox.setFps(0); // Unlimited FPS
140
+ */
141
+ setFps(fps: number): this;
96
142
  /**
97
143
  * Add a runtime render hook.
98
144
  */
99
145
  hook(callback: HookCallback, when?: "before" | "after"): () => void;
146
+ /**
147
+ * Runtime configure the module behavior
148
+ * @example
149
+ * sandbox.module("my_module", { intensity: 0.5 });
150
+ */
151
+ module<T extends Record<string, AnyUniformValue>>(name: string, config: T): this;
100
152
  /**
101
153
  * Start animation loop.
102
154
  */
@@ -140,11 +192,11 @@ export declare class Sandbox {
140
192
  /**
141
193
  * Get WebGL version using (1 or 2).
142
194
  */
143
- webglVersion(): WebGLVersion;
195
+ get version(): WebGLVersion;
144
196
  /**
145
197
  * Get canvas element.
146
198
  */
147
- canvasElement(): HTMLCanvasElement;
199
+ get canvas(): HTMLCanvasElement;
148
200
  /**
149
201
  * Destroy sandbox and release all resources.
150
202
  * @example