Declare the API once, in Rust. Generate the rest.
wasm-facade reads inert attributes on a crate compiled with wasm-bindgen and writes what a JavaScript user calls: a TypeScript facade, React hooks, a reference, and any target a plugin adds.
#[wasm_bindgen] stays as it is: the
crate still compiles to wasm with wasm-bindgen, and wasm-facade's attributes, in amber, sit beside it.filters/src/lib.rs written by hand
#[cfg_attr(wasm_facade, api(union))]
#[wasm_bindgen]
pub enum Edge { Clamp, Wrap }
#[cfg_attr(wasm_facade, api(options))]
pub struct BlurOptions {
#[cfg_attr(wasm_facade, api(default = "2"))]
pub radius: f64,
#[cfg_attr(wasm_facade, api(default = "'clamp'"))]
pub edge: Edge,
}
#[cfg_attr(wasm_facade, api(class, options = "BlurOptions"))]
#[wasm_bindgen]
impl Blur {
#[cfg_attr(wasm_facade, api(convert = "image=pixels"))]
pub fn apply(&self, image: &mut [u8], width: u32, height: u32)
#[wasm_bindgen(js_name = onProgress)]
#[cfg_attr(wasm_facade, api(event = "progress", payload = "number"))]
pub fn on_progress(&mut self, listener: js_sys::Function)
}
src/api.ts generated
export type Edge = 'clamp' | 'wrap';
export interface BlurOptions { radius: number; edge: Edge }
export const defaultBlurOptions = { radius: 2, edge: 'clamp' };
export class Blur {
constructor(options: BlurOptionsInit = {})
apply(image: ImageData, width: number, height: number): void
on(type: 'progress', listener): () => void
free(): void
}
src/hooks.ts generated
const blur = useBlur({ radius: 4, edge: 'wrap' });
useBlurEvent(blur, 'progress', setShare);
docs/api.md generated
new Blur(options) A box blur | ||
|---|---|---|
radius | number | 2 |
edge | 'clamp' | 'wrap' | 'clamp' |
progress | event | number |
The real blur, in this page
This image goes through the example crate, compiled to wasm and called through its generated
Blur. Drag the handle to compare.
The full demo adds the edges, the progress event, the histogram and every generated file.
orval, for Rust and wasm
orval writes a typed client from an OpenAPI document, so the client never drifts from the contract. wasm-facade does the same, with the Rust crate as the contract.
What wasm-bindgen writes
new Blur(radius: number, edge: Edge) // Edge = 0 | 1
blur.onProgress(listener: Function)
blur.apply(image: Uint8Array, w, h)
blur.free() // to rememberWhat wasm-facade adds on top
new Blur({ radius: 4, edge: 'wrap' }) // defaults filled
const stop = blur.on('progress', (share) => …)
blur.apply(imageData, w, h) // your converter
useBlur(options) // freed on unmountIn a repository
Declare in Rust
The attribute sits behind a cfg that is never set: no proc-macro, no dependency, no build time.
#[cfg_attr(wasm_facade, api(class, options = "BlurOptions"))] #[wasm_bindgen] impl Blur { … }Pick the targets
One file at the root says what to write and where.
# wasm-facade.toml wasm = "../pkg/filters.js" [targets.typescript] [targets.react] [targets.reference]Generate, check in CI
After a change to the Rust, and in the lint, which fails on any drift.
$ wasm-facade generate $ wasm-facade check
Next to the existing tools
Each covers part of what a facade needs. Read from their documentation in November 2026; a cell explains itself on hover. Corrections are welcome.
| Types | Functions, classes | Events, callbacks | Your conversions | On the web | React hooks | |
|---|---|---|---|---|---|---|
| wasm-bindgen | ◐ | ● | ◐ | ◐ | ● | ○ |
| ts-rs, tsify, schemars | ● | ○ | ○ | ◐ | ◐ | ○ |
| specta | ● | ● | ◐ | ○ | ○ | ○ |
| UniFFI | ● | ● | ● | ● | ◐ | ○ |
| diplomat | ● | ● | ○ | ○ | ● | ○ |
| wasm-facade | ● | ● | ● | ● | ● | ● |
● yes◐ partly○ no
Targets are plugins
A target is a module that takes the API and returns files. Three come built in; a project adds its own from the same patterns.
- typescriptbuilt in
- reactbuilt in
- referencebuilt in
- Python widgetisard's plugin
- React Nativeisard's plugin
- web componentisard's plugin