#[cfg(feature = "editor")]
use web_sys::Document;
#[cfg(feature = "editor")]
#[allow(dead_code)]
pub fn get_document() -> Option<Document> {
#[cfg(target_arch = "wasm32")]
{
web_sys::window().and_then(|w| w.document())
}
#[cfg(not(target_arch = "wasm32"))]
{
None
}
}
#[must_use]
#[allow(dead_code)]
pub fn is_browser() -> bool {
#[cfg(target_arch = "wasm32")]
{
web_sys::window().is_some()
}
#[cfg(not(target_arch = "wasm32"))]
{
false
}
}
#[allow(dead_code)]
pub fn on_browser<F, T>(f: F) -> Option<T>
where
F: FnOnce() -> T,
{
if is_browser() { Some(f()) } else { None }
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_is_browser_in_tests() {
#[cfg(not(target_arch = "wasm32"))]
assert!(!is_browser());
}
}