use beet_core::prelude::*;
use std::path::PathBuf;
#[derive(Debug, Clone, PartialEq, Resource, Reflect)]
pub struct HtmlConstants {
pub dom_idx_key: String,
pub span_key: String,
pub event_handler: String,
pub event_store: String,
pub style_id_key: String,
pub client_islands_script_type: String,
pub text_node_marker: String,
pub wasm_dir: PathBuf,
pub wasm_name: String,
pub raw_text_elements: std::collections::HashSet<&'static str>,
pub mend_raw_text_style_tags: bool,
pub ignore_style_id_tags: Vec<String>,
pub hoist_to_head_tags: Vec<String>,
pub self_closing_elements: std::collections::HashSet<&'static str>,
}
impl Default for HtmlConstants {
fn default() -> Self {
let hoist_to_head_tags = vec![
"title".into(),
"meta".into(),
"link".into(),
"style".into(),
"script".into(),
"base".into(),
];
Self {
dom_idx_key: "data-beet-dom-idx".into(),
span_key: "data-beet-span".into(),
event_handler: "_beet_event_handler".into(),
event_store: "_beet_event_store".into(),
style_id_key: "data-beet-style-id".into(),
client_islands_script_type: "beet/client-islands".into(),
text_node_marker: "bt".into(),
wasm_dir: "wasm".into(),
wasm_name: "main".into(),
raw_text_elements: ["script", "style", "code"]
.into_iter()
.collect(),
mend_raw_text_style_tags: true,
ignore_style_id_tags: hoist_to_head_tags
.iter()
.cloned()
.chain(["html".into(), "head".into()])
.collect(),
hoist_to_head_tags,
self_closing_elements: [
"area", "base", "br", "col", "embed", "hr", "img", "input",
"link", "meta", "param", "source", "track", "wbr",
]
.into_iter()
.collect(),
}
}
}
impl HtmlConstants {
pub fn default_bsx_constants() -> Self {
Self {
mend_raw_text_style_tags: false,
raw_text_elements: default(),
self_closing_elements: default(),
..default()
}
}
pub fn style_id_attribute(&self, id: u64) -> String {
format!("{}-{}", self.style_id_key, id)
}
pub fn style_id_attribute_placeholder(&self) -> String {
format!("{}-PLACEHOLDER", self.style_id_key)
}
pub fn wasm_bin_url(&self) -> String {
format!(
"/{}/{}_bg.wasm",
self.wasm_dir.to_string_lossy(),
self.wasm_name
)
}
pub fn wasm_js_url(&self) -> String {
format!("/{}/{}.js", self.wasm_dir.to_string_lossy(), self.wasm_name)
}
}