#[allow(warnings)]
#[macro_use]
pub mod macros {
#[macro_export]
macro_rules! document_base_uri {
() => {{
let window = web_sys::window().expect("no global `window` exists");
let document = window.document().expect("should have a document on window");
let uri = document
.base_uri()
.expect("should have a base URI on document");
uri
}};
}
#[macro_export]
macro_rules! location_assign {
($to:expr) => {{
let window = web_sys::window().expect("no global `window` exists");
window.location().assign(&format!("{}", $to));
}};
}
#[macro_export]
macro_rules! location_herf {
() => {{
let window = web_sys::window().expect("no global `window` exists");
let herf = window.location().href().unwrap();
herf
}};
}
#[macro_export]
macro_rules! location_reload {
() => {{
let window = web_sys::window().expect("no global `window` exists");
window.location().reload().unwrap();
}};
}
#[macro_export]
macro_rules! document_query_selector {
($selectors:expr) => {{
let window = web_sys::window().expect("no global `window` exists");
let document = window.document().expect("should have a document on window");
let dom = document
.query_selector($selectors)
.expect("failed to find the {$selectors} element");
dom
}};
}
#[macro_export]
macro_rules! document_query_selector_all {
($selectors:expr) => {{
let window = web_sys::window().expect("no global `window` exists");
let document = window.document().expect("should have a document on window");
let dom = document
.query_selector_all($selectors)
.expect("failed to find the {$selectors} element");
dom
}};
}
#[macro_export]
macro_rules! document_create_element {
($element_name:expr) => {{
let window = web_sys::window().expect("no global `window` exists");
let document = window.document().expect("should have a document on window");
let val = document
.create_element($element_name)
.expect("failed to create element `$element_name` on document");
val
}};
}
#[macro_export]
macro_rules! document_inner_html {
($element_name:expr) => {{
let element = document_query_selector!($element_name).expect("not font element");
element.inner_html()
}};
}
#[macro_export]
macro_rules! document_set_inner_html {
($element_name:expr,$val:expr) => {{
let element = document_query_selector!($element_name).expect("not font element");
element.set_inner_html($val);
}};
}
use wasm_bindgen::prelude::*;
#[wasm_bindgen]
extern "C" {
#[wasm_bindgen(js_namespace = console)]
fn log(s: &str);
}
#[macro_export]
macro_rules! console_log {
($($t:tt)*) => (log(&format_args!($($t)*).to_string()))
}
#[macro_export]
macro_rules! element_get_attribute {
($element:expr,$attribute:expr) => {{
let el = document_query_selector!($element).expect("not fontd element");
el.get_attribute($attribute).expect("not fond the attribute")
}};
}
#[macro_export]
macro_rules! demo {
($element:expr,$attribute:expr) => {{
let el = document_query_selector!($element).expect("not fontd element");
el.get_attribute($attribute).expect("not fond the attribute")
}};
}
}