1use crate::imports::*;
2use web_sys::Element;
3use workflow_dom::inject::*;
4
5static mut DOM_INIT: bool = false;
6
7pub struct Container {
8 element: Element,
9}
10
11unsafe impl Sync for Container {}
12unsafe impl Send for Container {}
13
14impl Container {
15 pub async fn try_init() -> Result<()> {
16 if !unsafe { DOM_INIT } {
17 let layout_css = include_str!("container.css");
18 inject_css(None, layout_css)?;
19 unsafe {
20 DOM_INIT = true;
21 }
22 }
23
24 Ok(())
25 }
26
27 pub async fn try_new(window: &web_sys::Window) -> Result<Container> {
28 let document = window.document().unwrap();
29 let element = document.create_element("div").unwrap();
30 element.set_class_name("layout");
31
32 let body = document
33 .query_selector("body")
34 .unwrap()
35 .ok_or_else(|| "Unable to get body element".to_string())?;
36
37 body.append_child(&element).unwrap();
38
39 let layout = Container { element };
40
41 Ok(layout)
42 }
43
44 pub fn element(&self) -> &Element {
45 &self.element
46 }
47}