diff --git a/macros/src/lib.rs b/macros/src/lib.rs index aa72959..5b0c538 100644 --- a/macros/src/lib.rs +++ b/macros/src/lib.rs @@ -224,6 +224,19 @@ fn expand_wasm_shim(struct_name: &Ident) -> syn::ItemImpl { Self::default() } + #[::wasm_bindgen::prelude::wasm_bindgen] + #[doc = "Attach an open shadowroot to our element."] + pub fn attach_shadow(&self, element: &web_sys::HtmlElement, root: &str) { + self.attach_shadow_with_mode(element, root, web_sys::ShadowRootMode::Open); + } + + #[::wasm_bindgen::prelude::wasm_bindgen] + #[doc = "Attach a shadowroot with the given mode to our element."] + pub fn attach_shadow_with_mode(&self, element: &web_sys::HtmlElement, root: &str, mode: web_sys::ShadowRootMode) { + let shadow_root = element.attach_shadow(&web_sys::ShadowRootInit::new(mode)).unwrap(); + shadow_root.set_inner_html(root); + } + #[::wasm_bindgen::prelude::wasm_bindgen] pub fn init_impl(&mut self, element: &web_sys::HtmlElement) { use #trait_path;