use std::sync::OnceLock;
use crate::node::{Node, View};
static OVERRIDES: OnceLock<Vec<(&'static Stylesheet, &'static Stylesheet)>> = OnceLock::new();
pub fn set_overrides(list: Vec<(&'static Stylesheet, &'static Stylesheet)>) {
let _ = OVERRIDES.set(list);
}
pub(crate) fn resolve(sheet: &'static Stylesheet) -> &'static Stylesheet {
OVERRIDES
.get()
.and_then(|list| list.iter().find(|(from, _)| std::ptr::eq(*from, sheet)))
.map_or(sheet, |(_, to)| to)
}
#[derive(Debug, PartialEq, Eq)]
pub struct Stylesheet {
pub id: &'static str,
pub css: &'static str,
pub per_class: Option<&'static [&'static str]>,
pub scripts: &'static [(&'static str, &'static [&'static str])],
}
impl View for &'static Stylesheet {
fn into_node(self) -> Node {
Node::Style(self)
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct CssClass {
pub name: &'static str,
pub sheet: &'static Stylesheet,
}
impl CssClass {
pub const fn new(name: &'static str, sheet: &'static Stylesheet) -> Self {
Self { name, sheet }
}
}
impl std::fmt::Display for CssClass {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_str(self.name)
}
}