atmos/os_lib/css/
flow_pseudo.rs1extern crate alloc;
5use alloc::collections::BTreeMap;
6use alloc::string::String;
7
8const INHERITED: &[&str] = &["color", "font-family", "font-size", "font-weight", "font-style", "line-height", "visibility"];
10
11pub fn flow_pseudo_values(parent: &BTreeMap<String, String>, which: &str) -> Option<BTreeMap<String, String>> {
19 let mut key = String::with_capacity(16);
20 key.push_str("x-");
21 key.push_str(which);
22 key.push('-');
23 let prefix_len = key.len();
24 key.push_str("content");
25 let content = parent.get(&key)?;
26 if !content.trim().is_empty() {
27 return None;
28 }
29 let mut out = BTreeMap::new();
30 for k in INHERITED {
31 if let Some(v) = parent.get(*k) {
32 out.insert(String::from(*k), v.clone());
33 }
34 }
35 key.truncate(prefix_len);
36 for (k, v) in parent.range(key.clone()..) {
37 let Some(name) = k.strip_prefix(key.as_str()) else { break };
38 out.insert(String::from(name), v.clone());
39 }
40 out.remove("content");
41 if matches!(out.get("position").map(|p| p.trim()), Some("absolute") | Some("fixed")) {
42 return None;
43 }
44 let floated = matches!(out.get("float").map(|f| f.trim()), Some("left") | Some("right") | Some("inline-start") | Some("inline-end"));
45 let display_ok = match out.get("display").map(|d| d.trim()) {
46 Some("block" | "flow-root" | "list-item" | "flex" | "grid" | "table" | "block flow" | "block flow-root" | "block flex" | "block grid" | "block table") => true,
47 Some("none") => return None,
48 Some(_) => floated,
49 None => floated,
50 };
51 if !display_ok {
52 return None;
53 }
54 if !out.contains_key("display") || out.get("display").map(|d| d.trim()) == Some("inline") {
55 out.insert(String::from("display"), String::from("block"));
56 }
57 Some(out)
58}
59
60pub fn flow_pseudo_parent_ok(tag: &str, display: &str) -> bool {
62 !matches!(
63 tag,
64 "img" | "iframe" | "input" | "textarea" | "select" | "video" | "canvas" | "progress" | "meter" | "svg" | "br"
65 | "hr" | "button" | "object" | "embed" | "table" | "thead" | "tbody" | "tfoot" | "tr" | "html"
66 ) && matches!(
67 display.trim(),
68 "block" | "flow-root" | "list-item" | "flex" | "grid" | "inline-block" | "table-cell" | "table-caption"
69 )
70}
71