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
use wasm_bindgen::closure::Closure; use wasm_bindgen::JsCast; use web_sys; pub fn window() -> web_sys::Window { web_sys::window().expect("no global `window` exists") } pub fn request_animation_frame(f: &Closure<FnMut()>) { window() .request_animation_frame(f.as_ref().unchecked_ref()) .expect("should register `requestAnimationFrame` OK"); } pub fn document() -> web_sys::Document { window() .document() .expect("should have a document on window") } pub fn body() -> web_sys::HtmlElement { document().body().expect("document should have a body") } pub fn log<S: Into<String>>(s: S) { web_sys::console::log_1(&s.into().into()); }