@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/README.md +153 -46
- package/dist/errors/base.d.ts +6 -0
- package/dist/errors/context.d.ts +7 -0
- package/dist/errors/index.d.ts +6 -0
- package/dist/errors/module.d.ts +42 -0
- package/dist/errors/program.d.ts +5 -0
- package/dist/errors/shader.d.ts +34 -0
- package/dist/errors/unknown.d.ts +7 -0
- package/dist/globals.d.ts +17 -0
- package/dist/index.cjs.js +834 -8
- package/dist/index.d.ts +43 -1
- package/dist/index.es.js +2292 -387
- package/dist/tools/compilable.d.ts +79 -0
- package/dist/tools/module.d.ts +46 -0
- package/dist/tools/module_registry.d.ts +63 -0
- package/dist/tools/parser.d.ts +32 -0
- package/dist/tools/program.d.ts +1 -12
- package/dist/tools/shader.d.ts +4 -0
- package/dist/tools/uniforms.d.ts +0 -2
- package/dist/tools/web_gl.d.ts +2 -1
- package/dist/types.d.ts +90 -1
- package/package.json +8 -5
- package/dist/errors.d.ts +0 -32
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
|
*/
|