blinc_platform_web 0.5.1

Blinc Web platform — HtmlCanvasElement integration, browser event conversion, and fetch-based asset loading for wasm32-unknown-unknown
Documentation

Blinc Web Platform

HtmlCanvasElement integration, browser event conversion, and fetch-based asset loading for wasm32-unknown-unknown. The crate is a sibling of blinc_platform_desktop, blinc_platform_android, blinc_platform_ios, and blinc_platform_harmony — it owns everything that needs wasm-bindgen / web-sys so the rest of the Blinc workspace stays free of JS bindings. (Cross-crate references are plain code spans rather than intra-doc links because the sibling crates are workspace siblings, not dependencies of this crate, so rustdoc can't resolve them.)

Architecture

The web target is conceptually identical to the other platforms:

  • Surface: a <canvas> element passed to wgpu via SurfaceTarget::Canvas.
  • Input: browser DOM events (mousemove, mousedown, …) converted to blinc_platform::InputEvent and dispatched through the same EventRouter desktop / mobile use.
  • Frame loop: window.requestAnimationFrame(...) driving the same 5-phase pipeline as windowed.rs.
  • Assets: pre-loaded via fetch() into an in-memory cache, because AssetLoader::load is sync.

On non-wasm hosts every type still exists (so cargo check from a desktop box doesn't error), but the methods that touch web-sys return PlatformError::Unsupported.

Usage

use blinc_app::web::WebApp;

#[wasm_bindgen(start)]
pub async fn main() -> Result<(), wasm_bindgen::JsValue> {
    console_error_panic_hook::set_once();
    WebApp::run("blinc-canvas", |_ctx| {
        div()
            .w_full()
            .h_full()
            .bg(Color::rgba(0.07, 0.07, 0.10, 1.0))
            .items_center()
            .justify_center()
            .child(text("Hello, WebGPU!").size(24.0).color(Color::WHITE))
    })
    .await
    .map_err(|e| wasm_bindgen::JsValue::from_str(&format!("{e}")))
}

Building

wasm-pack build examples/web_hello --target web --release