tailwind_css_fixes/systems/css_global/attribute/
mod.rs

1use super::*;
2
3mod traits;
4
5/// A css property is used to remove duplicates.
6///
7/// In principle, each css property will only appear once, and the one set later will override the previous one.
8#[derive(Debug, Clone, Default, Ord, PartialOrd, Eq, PartialEq, Hash)]
9pub struct CssAttributes {
10    /// Normal css attributes with property and value.
11    normal: ImportantMap,
12    transforms: ImportantSet,
13    backdrop_filter: ImportantSet,
14    filter: ImportantSet,
15    /// The key is the nested selector string, e.g., ":where(& > :not(:last-child))"
16    /// The value is a CssAttributes for that nested rule.
17    nested: BTreeMap<String, Box<CssAttributes>>, 
18}
19
20impl CssAttributes {
21    /// # Arguments
22    ///
23    /// * `key`: css class
24    /// * `value`: css property
25    ///
26    /// returns: [`CssAttribute`]
27    #[track_caller]
28    pub fn insert<K, V>(&mut self, key: K, value: V)
29    where
30        K: Into<String>,
31        V: Into<String>,
32    {
33        let key = key.into();
34        match key.as_str() {
35            "transform" => self.transforms.insert(value.into()),
36            "backdrop-filter" => self.backdrop_filter.insert(value.into()),
37            "filter" => self.filter.insert(value.into()),
38            _ => self.normal.insert(key, value.into()),
39        };
40    }
41
42    /// # Arguments
43    ///
44    /// * `items`:
45    ///
46    /// returns: ()
47    pub fn extend<T>(&mut self, items: T)
48    where
49        T: IntoIterator<Item = (String, String)>,
50    {
51        for i in items {
52            self.insert(i.0, i.1);
53        }
54    }
55
56    /// Inserts a nested selector and its attributes.
57    ///
58    /// # Arguments
59    /// * `selector`: The nested selector string (e.g., ":where(& > :not(:last-child))")
60    /// * `attributes`: The CssAttributes to associate with the selector
61    pub fn insert_nested<S>(&mut self, selector: S, attributes: CssAttributes)
62    where
63        S: Into<String>,
64    {
65        self.nested.insert(selector.into(), Box::new(attributes));
66    }
67}