@rosalana/sandbox 0.0.5 → 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
  /**
@@ -50,6 +50,34 @@ export declare class Sandbox {
50
50
  * });
51
51
  */
52
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;
53
81
  private resolveOptions;
54
82
  private setupListeners;
55
83
  private destroyListeners;
@@ -95,6 +123,14 @@ export declare class Sandbox {
95
123
  * sandbox.setFragment(fragmentSource);
96
124
  */
97
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;
98
134
  /**
99
135
  * Set the max frame rate runtime
100
136
  *
@@ -107,6 +143,12 @@ export declare class Sandbox {
107
143
  * Add a runtime render hook.
108
144
  */
109
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;
110
152
  /**
111
153
  * Start animation loop.
112
154
  */