1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
//! Browser-WASM distribution of the Reflow runtime.
//!
//! This crate wires up `reflow_graph`, `reflow_actor`, and
//! `reflow_network` for the wasm32-unknown-unknown target via
//! `wasm-bindgen`. Building it produces a `.wasm` + JS glue that an
//! npm package can ship as `@offbit-ai/reflow-wasm`.
//!
//! Usage in JS:
//!
//! ```js
//! import init, { Graph, Network, Message } from "@offbit-ai/reflow-wasm";
//! await init();
//!
//! const g = new Graph("demo");
//! g.addNode("a", "tpl_doubler");
//! g.addNode("b", "tpl_collector");
//! g.addConnection("a", "out", "b", "in");
//!
//! const net = Network.fromGraph(g);
//! net.registerActorJs("tpl_doubler", { /* JS class with run(ctx) */ });
//! net.start();
//! ```
//!
//! For now the surface is intentionally narrow — Graph + Network +
//! Message + the existing `_*` wasm-bindgen exports inherited from
//! `reflow_graph`/`reflow_network`. The bundled component catalog
//! (`reflow_components`) is excluded because its native-only deps
//! (rquickjs, openh264, wgpu native backends, …) don't compile to
//! wasm32-unknown-unknown without significant feature-gating work.
//! Author actors as JS classes via `Network.registerActorJs(...)`.
use *;
/// Wire up `console.error_panic_hook` so Rust panics surface as
/// JS exceptions instead of "RuntimeError: unreachable executed".
/// Call once from your JS bootstrap.
/// Re-export the `Graph` and `GraphNetwork` wasm-bindgen surfaces
/// inherited from `reflow_graph` and `reflow_network`. wasm-bindgen
/// doesn't propagate `#[wasm_bindgen]` exports across crates
/// automatically — re-exporting here makes them visible in this
/// crate's generated JS module.
pub use Graph;
pub use GraphNetwork;
/// Library version string — useful for debug overlays.
/// Initialize the shared GPU context from a `<canvas>` element.
///
/// Must be awaited once during workflow startup before any GPU-backed
/// actor runs (SDF renderer, scene renderer, marching cubes, …).
/// `canvasSelector` is a CSS selector pointing at the `HTMLCanvasElement`
/// Reflow should render to. Pass `null`/`undefined` for off-screen-only
/// workloads where the result is read back to CPU and displayed
/// outside the wgpu pipeline.
///
/// On success, `wgpu::Adapter`, `Device`, and `Queue` are cached for
/// the life of the runtime; subsequent calls are no-ops.
pub async
// ─── .rflpack loading ──────────────────────────────────────────────────────
/// Extract the wasm32 binary from a `.rflpack` byte buffer.
///
/// Used by the JS `loadPack(url)` shim. Validates the manifest
/// (`manifest_version` + `reflow_pack_abi_version`) and pulls the
/// `wasm32-unknown-unknown` entry out of the zip. Returns a JS
/// object `{ manifestJson: string, wasm: Uint8Array }` so the
/// caller can compile via `WebAssembly.compile(result.wasm)`.
///
/// Errors:
/// - The zip can't be parsed.
/// - `manifest.json` is missing or malformed.
/// - The pack was built against a different `reflow_pack_abi_version`.
/// - The pack has no `wasm32-unknown-unknown` target (its `Reflow.pack.toml`
/// author didn't opt-in to a wasm build, or the build failed in CI).
/// The pack ABI version this runtime was built against. Packs whose
/// `manifest.reflow_pack_abi_version` doesn't match cannot be loaded.
/// Surfaced for diagnostics — `loadPack` already enforces it.