dioxus_document/
lib.rs

1use std::rc::Rc;
2
3mod document;
4mod elements;
5mod error;
6mod eval;
7
8pub use document::*;
9pub use elements::*;
10pub use error::*;
11pub use eval::*;
12
13/// Get the document provider for the current platform or a no-op provider if the platform doesn't document functionality.
14pub fn document() -> Rc<dyn Document> {
15    match dioxus_core::prelude::try_consume_context::<Rc<dyn Document>>() {
16        Some(document) => document,
17        None => {
18            tracing::error!(
19                "Unable to find a document in the renderer. Using the default no-op document."
20            );
21            Rc::new(NoOpDocument)
22        }
23    }
24}
25
26/// Evaluate some javascript in the current document
27#[doc = include_str!("../docs/eval.md")]
28#[doc(alias = "javascript")]
29pub fn eval(script: &str) -> Eval {
30    document().eval(script.to_string())
31}