Skip to main content

fret_runner_web/
lib.rs

1//! Web/wasm runner glue for Fret.
2//!
3//! On `wasm32`, this crate re-exports `fret-platform-web` services used by `fret-runtime::Effect`s
4//! and provides DOM-adjacent adapters (cursor, input event mapping, RAF/timers). It intentionally
5//! keeps non-wasm builds explicit via a stub module.
6//!
7//! For module ownership and “where should this go?” guidance, see `crates/fret-runner-web/README.md`.
8//!
9//! Long-term direction: a dedicated DOM adapter for IME/keyboard fidelity (see ADR 0089/0092).
10
11#[cfg(target_arch = "wasm32")]
12pub use fret_platform_web::*;
13
14#[cfg(target_arch = "wasm32")]
15mod cursor;
16#[cfg(target_arch = "wasm32")]
17mod events;
18#[cfg(target_arch = "wasm32")]
19mod raf;
20
21#[cfg(target_arch = "wasm32")]
22pub use cursor::{
23    RunnerError, WebCursorListener, canvas_by_id, install_canvas_cursor_listener,
24    last_cursor_offset_px,
25};
26#[cfg(target_arch = "wasm32")]
27pub use events::{WebInputState, WebPointerEventKind, map_keyboard_event};
28#[cfg(target_arch = "wasm32")]
29pub use raf::{cancel_animation_frame, request_animation_frame, set_timeout_ms};
30
31#[cfg(not(target_arch = "wasm32"))]
32mod native;
33#[cfg(not(target_arch = "wasm32"))]
34pub use native::*;
35
36#[cfg(all(test, not(target_arch = "wasm32")))]
37mod tests {
38    use super::*;
39
40    #[test]
41    fn runner_error_is_actionable_on_non_wasm_targets() {
42        let err = RunnerError;
43        assert_eq!(
44            err.to_string(),
45            "fret-runner-web is only available on wasm32"
46        );
47
48        fn assert_error(_err: &dyn std::error::Error) {}
49        assert_error(&err);
50    }
51}