2023-03-30 17:12:58 +08:00
|
|
|
use leptos::document;
|
|
|
|
|
2023-10-07 21:41:03 +08:00
|
|
|
pub fn mount_style(id: &str, content: &str) {
|
2023-03-30 17:12:58 +08:00
|
|
|
let head = document().head().expect("head no exist");
|
|
|
|
let style = head
|
2023-11-05 16:03:58 +08:00
|
|
|
.query_selector(&format!("style[csr-id=\"thaw-{id}\"]"))
|
2023-03-30 17:12:58 +08:00
|
|
|
.expect("query style element error");
|
|
|
|
|
|
|
|
if style.is_some() {
|
2023-10-07 21:41:03 +08:00
|
|
|
return;
|
2023-03-30 17:12:58 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
let style = document()
|
|
|
|
.create_element("style")
|
|
|
|
.expect("create style element error");
|
2023-11-05 16:03:58 +08:00
|
|
|
_ = style.set_attribute("csr-id", &format!("thaw-{id}"));
|
2023-03-30 17:12:58 +08:00
|
|
|
style.set_text_content(Some(content));
|
|
|
|
|
|
|
|
_ = head.append_child(&style);
|
|
|
|
}
|