use rdom_style::TuiStyle;
use rdom_style::property_dispatch;
pub(crate) fn css_text_of(style: &TuiStyle) -> String {
let mut out = String::new();
for &name in property_dispatch::property_names() {
if let Some(shorthand) = shorthand_family_of(name)
&& property_dispatch::serialize(shorthand, style).is_some()
{
continue;
}
if let Some(value) = property_dispatch::serialize(name, style) {
if !out.is_empty() {
out.push(' ');
}
out.push_str(name);
out.push_str(": ");
out.push_str(&value);
if let Some(mask) = property_dispatch::property_mask(name)
&& style.important.contains(mask)
{
out.push_str(" !important");
}
out.push(';');
}
}
for d in &style.custom_properties {
if !out.is_empty() {
out.push(' ');
}
out.push_str("--");
out.push_str(&d.name);
out.push_str(": ");
out.push_str(&d.value);
if d.important {
out.push_str(" !important");
}
out.push(';');
}
out
}
fn shorthand_family_of(name: &str) -> Option<&'static str> {
match name {
"padding-top" | "padding-right" | "padding-bottom" | "padding-left" => Some("padding"),
"top" | "right" | "bottom" | "left" => Some("inset"),
"overflow-x" | "overflow-y" => Some("overflow"),
"transition-property"
| "transition-duration"
| "transition-timing-function"
| "transition-delay" => Some("transition"),
_ => None,
}
}