Expand description
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 viaSurfaceTarget::Canvas. - Input: browser DOM events (
mousemove,mousedown, …) converted toblinc_platform::InputEventand dispatched through the sameEventRouterdesktop / mobile use. - Frame loop:
window.requestAnimationFrame(...)driving the same 5-phase pipeline aswindowed.rs. - Assets: pre-loaded via
fetch()into an in-memory cache, becauseAssetLoader::loadis 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 --releaseRe-exports§
pub use assets::WebAssetLoader;pub use input::convert_key_from_dom;pub use input::modifiers_from_keyboard;pub use input::modifiers_from_mouse;pub use window::WebWindow;
Modules§
- assets
- Browser asset loader
- input
- Browser input →
blinc_platform::InputEventconversion - window
blinc_platform::Windowimplementation for an HtmlCanvasElement.