@rosalana/sandbox 0.1.0 → 0.2.1

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, ModuleDefinition, SandboxOptions, UniformSchema, WebGLVersion } from "./types";
1
+ import type { AnyUniformValue, HookCallback, ModuleDefinition, SandboxOptions, TextureOptions, TextureSchema, TextureSource, UniformSchema, WebGLVersion } from "./types";
2
2
  export * from "./types";
3
3
  export * from "./errors";
4
4
  /**
@@ -111,6 +111,28 @@ export declare class Sandbox {
111
111
  * Get current uniform value.
112
112
  */
113
113
  getUniform<T extends AnyUniformValue>(name: string): T | undefined;
114
+ /**
115
+ * Set a texture for a sampler2D uniform.
116
+ * @example
117
+ * sandbox.setTexture("u_texture", imageElement);
118
+ * sandbox.setTexture("u_texture", imageElement, { wrap: "repeat" });
119
+ */
120
+ setTexture(name: string, source: TextureSource, options?: TextureOptions): this;
121
+ /**
122
+ * Set multiple textures at once.
123
+ * @example
124
+ * sandbox.setTextures({
125
+ * u_texture: imageElement,
126
+ * u_detail: { source: detailImg, wrap: "repeat" },
127
+ * });
128
+ */
129
+ setTextures(textures: TextureSchema): this;
130
+ /**
131
+ * Remove a texture and free its GPU resources.
132
+ * @example
133
+ * sandbox.removeTexture("u_texture");
134
+ */
135
+ removeTexture(name: string): this;
114
136
  /**
115
137
  * Update shaders.
116
138
  * @example
@@ -197,6 +219,40 @@ export declare class Sandbox {
197
219
  * Get canvas element.
198
220
  */
199
221
  get canvas(): HTMLCanvasElement;
222
+ /**
223
+ * Export current frame as a data URL string.
224
+ * Requires `preserveDrawingBuffer: true` if called while playing.
225
+ * @example
226
+ * const url = sandbox.renderAt(1.5).exportAsURL("image/png");
227
+ */
228
+ exportAsURL(type?: "image/png" | "image/jpeg", quality?: number): string;
229
+ /**
230
+ * Export current frame as a Blob.
231
+ * Requires `preserveDrawingBuffer: true` if called while playing.
232
+ * @example
233
+ * const blob = await sandbox.renderAt(1.5).exportAsBlob("image/png");
234
+ */
235
+ exportAsBlob(type?: "image/png" | "image/jpeg", quality?: number): Promise<Blob>;
236
+ /**
237
+ * Export current frame as an HTMLImageElement.
238
+ * Requires `preserveDrawingBuffer: true` if called while playing.
239
+ * @example
240
+ * const img = sandbox.renderAt(1.5).exportAsImage("image/png");
241
+ * img.onload = () => document.body.appendChild(img);
242
+ */
243
+ exportAsImage(type?: "image/png" | "image/jpeg", quality?: number): HTMLImageElement;
244
+ /**
245
+ * Capture the canvas as a MediaStream for video calls or recording.
246
+ * @example
247
+ * // WebRTC video call
248
+ * const stream = sandbox.stream(30);
249
+ * peerConnection.addTrack(stream.getVideoTracks()[0], stream);
250
+ *
251
+ * @example
252
+ * // Record to video file
253
+ * const recorder = new MediaRecorder(sandbox.stream(30));
254
+ */
255
+ stream(fps?: number): MediaStream;
200
256
  /**
201
257
  * Destroy sandbox and release all resources.
202
258
  * @example