use alloc::vec::Vec;
#[derive(Debug, Clone)]
pub struct StyleInheritance<'a> {
pub name: &'a str,
pub parents: Vec<&'a str>,
pub children: Vec<&'a str>,
pub depth: usize,
pub has_circular_inheritance: bool,
}
impl<'a> StyleInheritance<'a> {
#[must_use]
pub const fn new(name: &'a str) -> Self {
Self {
name,
parents: Vec::new(),
children: Vec::new(),
depth: 0,
has_circular_inheritance: false,
}
}
pub fn add_parent(&mut self, parent: &'a str) {
if !self.parents.contains(&parent) {
self.parents.push(parent);
}
}
pub fn set_parent(&mut self, parent: &'a str) {
self.parents.clear();
self.parents.push(parent);
self.depth = 1; }
pub fn add_child(&mut self, child: &'a str) {
if !self.children.contains(&child) {
self.children.push(child);
}
}
#[must_use]
pub fn has_inheritance(&self) -> bool {
!self.parents.is_empty() || !self.children.is_empty()
}
#[must_use]
pub fn is_root(&self) -> bool {
self.parents.is_empty()
}
#[must_use]
pub fn is_leaf(&self) -> bool {
self.children.is_empty()
}
}