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
//! 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
//!
//! ```ignore
//! 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
//!
//! ```bash
//! wasm-pack build examples/web_hello --target web --release
//! ```
// Public API
pub use WebAssetLoader;
pub use ;
pub use WebWindow;
pub use install_panic_hook;