@viewscript/wasm 0.1.0-202605140639
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/package.json +16 -0
- package/vsc_wasm.d.ts +373 -0
- package/vsc_wasm.js +1725 -0
- package/vsc_wasm_bg.wasm +0 -0
package/package.json
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@viewscript/wasm",
|
|
3
|
+
"type": "module",
|
|
4
|
+
"version": "0.1.0-202605140639",
|
|
5
|
+
"license": "MIT OR Apache-2.0",
|
|
6
|
+
"files": [
|
|
7
|
+
"vsc_wasm_bg.wasm",
|
|
8
|
+
"vsc_wasm.js",
|
|
9
|
+
"vsc_wasm.d.ts"
|
|
10
|
+
],
|
|
11
|
+
"main": "vsc_wasm.js",
|
|
12
|
+
"types": "vsc_wasm.d.ts",
|
|
13
|
+
"sideEffects": [
|
|
14
|
+
"./snippets/*"
|
|
15
|
+
]
|
|
16
|
+
}
|
package/vsc_wasm.d.ts
ADDED
|
@@ -0,0 +1,373 @@
|
|
|
1
|
+
/* tslint:disable */
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* WebGPU surface manager for browser environment.
|
|
6
|
+
*
|
|
7
|
+
* This struct manages the WebGPU surface lifecycle for browser rendering.
|
|
8
|
+
* It does NOT contain a `GpuRenderer` - rendering is delegated to `WebTarget`.
|
|
9
|
+
*
|
|
10
|
+
* ## Responsibilities
|
|
11
|
+
*
|
|
12
|
+
* - Surface creation and configuration
|
|
13
|
+
* - Surface texture acquisition (`surface_texture_view()`)
|
|
14
|
+
* - Resize handling
|
|
15
|
+
* - Device/queue sharing with `WebTarget`
|
|
16
|
+
*/
|
|
17
|
+
export class WasmGpuRenderer {
|
|
18
|
+
private constructor();
|
|
19
|
+
free(): void;
|
|
20
|
+
[Symbol.dispose](): void;
|
|
21
|
+
/**
|
|
22
|
+
* Create a new WebGPU renderer bound to a canvas element.
|
|
23
|
+
*
|
|
24
|
+
* This is an async operation that:
|
|
25
|
+
* 1. Requests a GPU adapter from the browser
|
|
26
|
+
* 2. Requests a device and queue from the adapter
|
|
27
|
+
* 3. Creates a surface from the canvas element
|
|
28
|
+
* 4. Configures the surface for rendering
|
|
29
|
+
*
|
|
30
|
+
* # Arguments
|
|
31
|
+
*
|
|
32
|
+
* * `canvas` - The HTML canvas element to render to
|
|
33
|
+
*
|
|
34
|
+
* # Returns
|
|
35
|
+
*
|
|
36
|
+
* A `Promise` that resolves to `WasmGpuRenderer` or rejects with an error.
|
|
37
|
+
*/
|
|
38
|
+
static create(canvas: HTMLCanvasElement): Promise<WasmGpuRenderer>;
|
|
39
|
+
/**
|
|
40
|
+
* Resize the rendering surface.
|
|
41
|
+
*
|
|
42
|
+
* Call this when the canvas element is resized.
|
|
43
|
+
*
|
|
44
|
+
* # Arguments
|
|
45
|
+
*
|
|
46
|
+
* * `width` - New width in device pixels
|
|
47
|
+
* * `height` - New height in device pixels
|
|
48
|
+
*/
|
|
49
|
+
resize(width: number, height: number): void;
|
|
50
|
+
/**
|
|
51
|
+
* Get the current height in device pixels.
|
|
52
|
+
*/
|
|
53
|
+
readonly height: number;
|
|
54
|
+
/**
|
|
55
|
+
* Get the current width in device pixels.
|
|
56
|
+
*/
|
|
57
|
+
readonly width: number;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* ViewScript rendering engine for browser environment.
|
|
62
|
+
*
|
|
63
|
+
* This struct integrates the full rendering pipeline:
|
|
64
|
+
* - `ConstraintSolver`: Evaluates P-dimension constraints
|
|
65
|
+
* - `VsBuildInfo`: Event-sourcing ledger for constraint operations
|
|
66
|
+
* - `SceneBuilder`: Converts solver output to scene graph
|
|
67
|
+
* - `SceneConverter`: Converts scene graph to canvas nodes with topology rounding
|
|
68
|
+
* - `WasmGpuRenderer`: WebGPU-based rendering to canvas
|
|
69
|
+
*
|
|
70
|
+
* ## Architecture
|
|
71
|
+
*
|
|
72
|
+
* ```text
|
|
73
|
+
* TypeScript WASM Boundary Rust
|
|
74
|
+
* ─────────────────────────────────────────────────────────────────────────────
|
|
75
|
+
* const engine = wasm-bindgen
|
|
76
|
+
* await WasmViewScriptEngine ─────────────► WasmViewScriptEngine::create()
|
|
77
|
+
* .create(canvas, dpr); │
|
|
78
|
+
* ▼
|
|
79
|
+
* engine.add_component(...) ─────────────► add_component() → VsBuildInfo
|
|
80
|
+
* │
|
|
81
|
+
* ▼
|
|
82
|
+
* engine.tick(mutations_json) ─────────────► tick()
|
|
83
|
+
* │
|
|
84
|
+
* ├─► Apply mutations (T-vector)
|
|
85
|
+
* ├─► ConstraintSolver.solve()
|
|
86
|
+
* ├─► SceneBuilder.build_scene()
|
|
87
|
+
* ├─► SceneConverter.convert_with_rounding()
|
|
88
|
+
* └─► WasmGpuRenderer.render_nodes()
|
|
89
|
+
* ```
|
|
90
|
+
*
|
|
91
|
+
* ## Mutation Format (JSON)
|
|
92
|
+
*
|
|
93
|
+
* ```typescript
|
|
94
|
+
* // Translate: move component by delta
|
|
95
|
+
* engine.tick(JSON.stringify([
|
|
96
|
+
* { type: "Translate", entity_id: 1000, dx: 10, dy: 5 }
|
|
97
|
+
* ]));
|
|
98
|
+
*
|
|
99
|
+
* // SetPosition: move component to absolute position
|
|
100
|
+
* engine.tick(JSON.stringify([
|
|
101
|
+
* { type: "SetPosition", entity_id: 1000, x: 200, y: 150 }
|
|
102
|
+
* ]));
|
|
103
|
+
* ```
|
|
104
|
+
*
|
|
105
|
+
* ## Usage (TypeScript)
|
|
106
|
+
*
|
|
107
|
+
* ```typescript
|
|
108
|
+
* import init, { WasmViewScriptEngine } from 'vsc-wasm';
|
|
109
|
+
*
|
|
110
|
+
* await init();
|
|
111
|
+
*
|
|
112
|
+
* const canvas = document.getElementById('viewport') as HTMLCanvasElement;
|
|
113
|
+
* const engine = await WasmViewScriptEngine.create(canvas, window.devicePixelRatio);
|
|
114
|
+
*
|
|
115
|
+
* // Add a rounded rectangle component
|
|
116
|
+
* engine.add_component('RoundedRect', JSON.stringify({
|
|
117
|
+
* x: 100, y: 100, width: 200, height: 150, radius: 20, fill: '#ff0000'
|
|
118
|
+
* }));
|
|
119
|
+
*
|
|
120
|
+
* // Animation loop
|
|
121
|
+
* function animate() {
|
|
122
|
+
* engine.tick('[]'); // Empty mutations for static content
|
|
123
|
+
* requestAnimationFrame(animate);
|
|
124
|
+
* }
|
|
125
|
+
* animate();
|
|
126
|
+
* ```
|
|
127
|
+
*/
|
|
128
|
+
export class WasmViewScriptEngine {
|
|
129
|
+
private constructor();
|
|
130
|
+
free(): void;
|
|
131
|
+
[Symbol.dispose](): void;
|
|
132
|
+
/**
|
|
133
|
+
* Add a component to the scene.
|
|
134
|
+
*
|
|
135
|
+
* This method creates the necessary path entities and control points
|
|
136
|
+
* in the VsBuildInfo ledger based on the component type.
|
|
137
|
+
*
|
|
138
|
+
* # Arguments
|
|
139
|
+
*
|
|
140
|
+
* * `component_type` - Type of component: "RoundedRect", "Circle", "Path", etc.
|
|
141
|
+
* * `params_json` - JSON object with component parameters
|
|
142
|
+
*
|
|
143
|
+
* # Example JSON for RoundedRect
|
|
144
|
+
*
|
|
145
|
+
* ```json
|
|
146
|
+
* {
|
|
147
|
+
* "x": 100,
|
|
148
|
+
* "y": 100,
|
|
149
|
+
* "width": 200,
|
|
150
|
+
* "height": 150,
|
|
151
|
+
* "radius": 20,
|
|
152
|
+
* "fill": "#ff0000"
|
|
153
|
+
* }
|
|
154
|
+
* ```
|
|
155
|
+
*
|
|
156
|
+
* # Returns
|
|
157
|
+
*
|
|
158
|
+
* The entity ID of the created component.
|
|
159
|
+
*/
|
|
160
|
+
add_component(component_type: string, params_json: string): bigint;
|
|
161
|
+
/**
|
|
162
|
+
* Create a new ViewScript engine bound to a canvas element.
|
|
163
|
+
*
|
|
164
|
+
* This is an async operation that initializes the WebGPU pipeline
|
|
165
|
+
* and sets up the constraint solver.
|
|
166
|
+
*
|
|
167
|
+
* # Arguments
|
|
168
|
+
*
|
|
169
|
+
* * `canvas` - The HTML canvas element to render to
|
|
170
|
+
* * `device_pixel_ratio` - DPR for coordinate scaling (e.g., 2.0 for Retina)
|
|
171
|
+
*
|
|
172
|
+
* # Returns
|
|
173
|
+
*
|
|
174
|
+
* A `Promise` that resolves to `WasmViewScriptEngine` or rejects with an error.
|
|
175
|
+
*/
|
|
176
|
+
static create(canvas: HTMLCanvasElement, device_pixel_ratio: number): Promise<WasmViewScriptEngine>;
|
|
177
|
+
/**
|
|
178
|
+
* Register a static image texture.
|
|
179
|
+
*
|
|
180
|
+
* The pixel data must be in RGBA8 format with length `width * height * 4`.
|
|
181
|
+
* Returns the assigned texture ID for use with `FillSpec::ExternalTexture`.
|
|
182
|
+
*
|
|
183
|
+
* # Arguments
|
|
184
|
+
*
|
|
185
|
+
* * `width` - Texture width in pixels
|
|
186
|
+
* * `height` - Texture height in pixels
|
|
187
|
+
* * `pixels` - RGBA8 pixel data
|
|
188
|
+
*
|
|
189
|
+
* # Returns
|
|
190
|
+
*
|
|
191
|
+
* A unique texture ID that can be used in `FillSpec::ExternalTexture.handle_name`
|
|
192
|
+
* as `"resource.texture.<id>"`.
|
|
193
|
+
*/
|
|
194
|
+
register_image_texture(width: number, height: number, pixels: Uint8Array): bigint;
|
|
195
|
+
/**
|
|
196
|
+
* Register a video texture (requires per-frame updates).
|
|
197
|
+
*
|
|
198
|
+
* Unlike `register_image_texture`, this does not upload pixel data immediately.
|
|
199
|
+
* Call `update_texture_pixels()` each frame to update the video frame.
|
|
200
|
+
*
|
|
201
|
+
* # Arguments
|
|
202
|
+
*
|
|
203
|
+
* * `width` - Video frame width in pixels
|
|
204
|
+
* * `height` - Video frame height in pixels
|
|
205
|
+
*
|
|
206
|
+
* # Returns
|
|
207
|
+
*
|
|
208
|
+
* A unique texture ID for use with `update_texture_pixels()`.
|
|
209
|
+
*/
|
|
210
|
+
register_video_texture(width: number, height: number): bigint;
|
|
211
|
+
/**
|
|
212
|
+
* Remove a texture from the registry.
|
|
213
|
+
*
|
|
214
|
+
* Frees the GPU resources associated with the texture.
|
|
215
|
+
*
|
|
216
|
+
* # Arguments
|
|
217
|
+
*
|
|
218
|
+
* * `texture_id` - ID returned by `register_*_texture()`
|
|
219
|
+
*
|
|
220
|
+
* # Returns
|
|
221
|
+
*
|
|
222
|
+
* `true` if the texture was found and removed, `false` otherwise.
|
|
223
|
+
*/
|
|
224
|
+
remove_texture(texture_id: bigint): boolean;
|
|
225
|
+
/**
|
|
226
|
+
* Resize the rendering surface.
|
|
227
|
+
*
|
|
228
|
+
* # Arguments
|
|
229
|
+
*
|
|
230
|
+
* * `width` - New width in device pixels
|
|
231
|
+
* * `height` - New height in device pixels
|
|
232
|
+
*/
|
|
233
|
+
resize(width: number, height: number): void;
|
|
234
|
+
/**
|
|
235
|
+
* Set a component's fill to an external texture.
|
|
236
|
+
*
|
|
237
|
+
* This modifies the `PathEntityEntry` in `build_info.path_entities` to use
|
|
238
|
+
* `FillSpec::ExternalTexture` with the specified texture ID.
|
|
239
|
+
*
|
|
240
|
+
* # Arguments
|
|
241
|
+
*
|
|
242
|
+
* * `component_entity_id` - Entity ID of the component (path) to modify
|
|
243
|
+
* * `texture_id` - Texture ID returned by `register_image_texture()`
|
|
244
|
+
*
|
|
245
|
+
* # Returns
|
|
246
|
+
*
|
|
247
|
+
* `Ok(())` if the component was found and updated, `Err` otherwise.
|
|
248
|
+
*/
|
|
249
|
+
set_component_fill_texture(component_entity_id: bigint, texture_id: bigint): void;
|
|
250
|
+
/**
|
|
251
|
+
* Get the number of registered textures.
|
|
252
|
+
*/
|
|
253
|
+
texture_count(): number;
|
|
254
|
+
/**
|
|
255
|
+
* Execute one frame of the rendering pipeline.
|
|
256
|
+
*
|
|
257
|
+
* This method implements the Q→T→P pipeline with derived variable evaluation:
|
|
258
|
+
* 1. Phase 1: Inject Q-dimension values or apply legacy mutations
|
|
259
|
+
* 2. Phase 2: solve → derive → re-solve loop (max 2 iterations)
|
|
260
|
+
* - Run constraint solver
|
|
261
|
+
* - Build scene graph
|
|
262
|
+
* - Evaluate derived Q-variables (e.g., hover detection)
|
|
263
|
+
* - If derived values changed, re-inject and loop
|
|
264
|
+
* 3. Render the final scene
|
|
265
|
+
*
|
|
266
|
+
* # Arguments
|
|
267
|
+
*
|
|
268
|
+
* * `input_json` - Either:
|
|
269
|
+
* - New format: `{"values": {"input.pointer.x": {"type": "Float", "value": 100}}}`
|
|
270
|
+
* - Legacy format: `[{"type": "Translate", "entity_id": 1, "dx": 10, "dy": 5}]`
|
|
271
|
+
*
|
|
272
|
+
* # Returns
|
|
273
|
+
*
|
|
274
|
+
* `Ok(())` on success, or a JavaScript error on failure.
|
|
275
|
+
*/
|
|
276
|
+
tick(input_json: string): void;
|
|
277
|
+
/**
|
|
278
|
+
* Update texture pixel data.
|
|
279
|
+
*
|
|
280
|
+
* Use this for video textures (every frame) or animated images (on frame change).
|
|
281
|
+
* The pixel data must be RGBA8 format with length `width * height * 4`.
|
|
282
|
+
*
|
|
283
|
+
* # Arguments
|
|
284
|
+
*
|
|
285
|
+
* * `texture_id` - ID returned by `register_*_texture()`
|
|
286
|
+
* * `pixels` - RGBA8 pixel data
|
|
287
|
+
*
|
|
288
|
+
* # Returns
|
|
289
|
+
*
|
|
290
|
+
* `true` if the texture was found and updated, `false` otherwise.
|
|
291
|
+
*/
|
|
292
|
+
update_texture_pixels(texture_id: bigint, pixels: Uint8Array): boolean;
|
|
293
|
+
/**
|
|
294
|
+
* Get the current canvas height in device pixels.
|
|
295
|
+
*/
|
|
296
|
+
readonly height: number;
|
|
297
|
+
/**
|
|
298
|
+
* Get the current canvas width in device pixels.
|
|
299
|
+
*/
|
|
300
|
+
readonly width: number;
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
/**
|
|
304
|
+
* Get WebGPU adapter info as a JSON string.
|
|
305
|
+
*
|
|
306
|
+
* Returns information about the GPU adapter, or an error if WebGPU is not available.
|
|
307
|
+
*/
|
|
308
|
+
export function get_adapter_info(): Promise<string>;
|
|
309
|
+
|
|
310
|
+
/**
|
|
311
|
+
* Check if WebGPU is available in the current browser.
|
|
312
|
+
*
|
|
313
|
+
* Returns `true` if `navigator.gpu` exists and is not undefined.
|
|
314
|
+
*/
|
|
315
|
+
export function is_webgpu_available(): boolean;
|
|
316
|
+
|
|
317
|
+
export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
|
|
318
|
+
|
|
319
|
+
export interface InitOutput {
|
|
320
|
+
readonly memory: WebAssembly.Memory;
|
|
321
|
+
readonly __wbg_wasmgpurenderer_free: (a: number, b: number) => void;
|
|
322
|
+
readonly __wbg_wasmviewscriptengine_free: (a: number, b: number) => void;
|
|
323
|
+
readonly get_adapter_info: () => number;
|
|
324
|
+
readonly is_webgpu_available: () => number;
|
|
325
|
+
readonly wasmgpurenderer_create: (a: number) => number;
|
|
326
|
+
readonly wasmgpurenderer_height: (a: number) => number;
|
|
327
|
+
readonly wasmgpurenderer_resize: (a: number, b: number, c: number, d: number) => void;
|
|
328
|
+
readonly wasmgpurenderer_width: (a: number) => number;
|
|
329
|
+
readonly wasmviewscriptengine_add_component: (a: number, b: number, c: number, d: number, e: number, f: number) => void;
|
|
330
|
+
readonly wasmviewscriptengine_create: (a: number, b: number) => number;
|
|
331
|
+
readonly wasmviewscriptengine_height: (a: number) => number;
|
|
332
|
+
readonly wasmviewscriptengine_register_image_texture: (a: number, b: number, c: number, d: number, e: number) => bigint;
|
|
333
|
+
readonly wasmviewscriptengine_register_video_texture: (a: number, b: number, c: number) => bigint;
|
|
334
|
+
readonly wasmviewscriptengine_remove_texture: (a: number, b: bigint) => number;
|
|
335
|
+
readonly wasmviewscriptengine_resize: (a: number, b: number, c: number, d: number) => void;
|
|
336
|
+
readonly wasmviewscriptengine_set_component_fill_texture: (a: number, b: number, c: bigint, d: bigint) => void;
|
|
337
|
+
readonly wasmviewscriptengine_texture_count: (a: number) => number;
|
|
338
|
+
readonly wasmviewscriptengine_tick: (a: number, b: number, c: number, d: number) => void;
|
|
339
|
+
readonly wasmviewscriptengine_update_texture_pixels: (a: number, b: bigint, c: number, d: number) => number;
|
|
340
|
+
readonly wasmviewscriptengine_width: (a: number) => number;
|
|
341
|
+
readonly __wasm_bindgen_func_elem_3241: (a: number, b: number, c: number, d: number) => void;
|
|
342
|
+
readonly __wasm_bindgen_func_elem_3263: (a: number, b: number, c: number, d: number) => void;
|
|
343
|
+
readonly __wasm_bindgen_func_elem_1613: (a: number, b: number, c: number) => void;
|
|
344
|
+
readonly __wasm_bindgen_func_elem_1613_2: (a: number, b: number, c: number) => void;
|
|
345
|
+
readonly __wbindgen_export: (a: number, b: number) => number;
|
|
346
|
+
readonly __wbindgen_export2: (a: number, b: number, c: number, d: number) => number;
|
|
347
|
+
readonly __wbindgen_export3: (a: number) => void;
|
|
348
|
+
readonly __wbindgen_export4: (a: number, b: number, c: number) => void;
|
|
349
|
+
readonly __wbindgen_export5: (a: number, b: number) => void;
|
|
350
|
+
readonly __wbindgen_add_to_stack_pointer: (a: number) => number;
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
export type SyncInitInput = BufferSource | WebAssembly.Module;
|
|
354
|
+
|
|
355
|
+
/**
|
|
356
|
+
* Instantiates the given `module`, which can either be bytes or
|
|
357
|
+
* a precompiled `WebAssembly.Module`.
|
|
358
|
+
*
|
|
359
|
+
* @param {{ module: SyncInitInput }} module - Passing `SyncInitInput` directly is deprecated.
|
|
360
|
+
*
|
|
361
|
+
* @returns {InitOutput}
|
|
362
|
+
*/
|
|
363
|
+
export function initSync(module: { module: SyncInitInput } | SyncInitInput): InitOutput;
|
|
364
|
+
|
|
365
|
+
/**
|
|
366
|
+
* If `module_or_path` is {RequestInfo} or {URL}, makes a request and
|
|
367
|
+
* for everything else, calls `WebAssembly.instantiate` directly.
|
|
368
|
+
*
|
|
369
|
+
* @param {{ module_or_path: InitInput | Promise<InitInput> }} module_or_path - Passing `InitInput` directly is deprecated.
|
|
370
|
+
*
|
|
371
|
+
* @returns {Promise<InitOutput>}
|
|
372
|
+
*/
|
|
373
|
+
export default function __wbg_init (module_or_path?: { module_or_path: InitInput | Promise<InitInput> } | InitInput | Promise<InitInput>): Promise<InitOutput>;
|