layoutcss_parser/components/
center.rs1use indoc::formatdoc;
2use std::collections::HashSet;
3
4const CENTER_STYLE: &str = r#"
5center-l{
6 box-sizing: content-box;
7 max-inline-size: fit-content;
8 margin-inline: auto;
9 display: block;
10 text-align: initial;
11 }
12"#;
13
14const CENTER_AND_TEXT_STYLE: &str = r#"
15 center-l[layout~="and-text"]{
16 text-align:center;
17 }
18"#;
19
20const CENTER_RECURSIVE_STYLE: &str = r#"
21 center-l[layout~="recursive"]{
22 display:flex;
23 flex-direction:column;
24 align-items:center;
25 }
26"#;
27
28fn center_max_width_style(value: &str) -> String {
29 formatdoc!(
30 r#"
31 center-l[layout~="max-width:{value}"]{{
32 max-inline-size: {value};
33 --center-max-width: {value};
34 }}
35 "#,
36 )
37}
38
39pub fn center_css(
40 max_width: Option<&str>,
41 and_text: bool,
42 recursive: bool,
43 set: &mut HashSet<String>,
44) {
45 set.insert(CENTER_STYLE.to_string());
46 if let Some(value) = max_width {
47 set.insert(center_max_width_style(value));
48 }
49 if and_text {
50 set.insert(CENTER_AND_TEXT_STYLE.to_string());
51 }
52 if recursive {
53 set.insert(CENTER_RECURSIVE_STYLE.to_string());
54 }
55}