textiler_core/theme/
baseline.rs1use crate::theme::sx::SxValue;
2use crate::theme::theme_mode::ThemeMode;
3use crate::theme::typography::TypographyLevel;
4use crate::theme::Theme;
5use crate::{sx, Sx};
6
7pub fn baseline(theme: &Theme, mode: &ThemeMode) -> Sx {
9 let mut emit = sx!();
10
11 let theme_system_class = theme.system_class();
12 for (typography_level, _) in theme.typography() {
13 if typography_level != &TypographyLevel::Star {
14 let sx = theme.typography().at(typography_level).unwrap();
15 emit.insert(format!("{theme_system_class}.{typography_level}"), sx);
16 }
17 }
18
19 for (palette_name, palette) in theme.palettes() {
20 let mut to_merge = sx!();
21 for selector_name in palette.selectors() {
22 let mut selector = palette.select(selector_name, mode).unwrap().clone();
23 if let Ok(adjusted) = selector.to_rgba_color() {
24 selector = adjusted;
25 }
26 to_merge.insert(
27 theme.palette_var(palette_name, selector_name),
28 SxValue::Color(selector),
29 )
30 }
31 emit = emit.merge(sx! {
32 "html": to_merge
33 })
34 }
35
36 emit.merge(sx! {
37 ":root, html": {
38 "color": "text.primary",
39 "bgcolor": "background.body",
40 },
41 "p, span, code, h1, h2, h3, h4": {
42 "margin-block-start": "0.1em",
43 "margin-block-end": "0.1em",
44 "margin-inline-start": "0px",
45 "margin-inline-end": "0px",
46 },
47 "body": {
48 "margin": "0",
49 },
50 (theme.system_class()): {
51 "&[color=success]": {
52 "color": "success.050",
53 },
54 "&[variant=outlined]": {
55 "borderWidth": "3px",
56 "borderStyle": "solid",
57 "padding": "3px",
58 "borderColor": "inherit",
59 "&[color=success]": {
60 "borderColor": "success.outlinedBorder",
61 "color": "success.outlinedColor",
62 "&[disabled]": {
63 "borderColor": "success.outlinedDisabledBorder",
64 "color": "success.outlinedDisabledColor",
65 }
66 }
67 }
68 }
69 })
70}
71
72#[cfg(test)]
73mod tests {
74 use crate::prelude::*;
75 use crate::theme::baseline::baseline;
76 use crate::theme::theme_mode::ThemeMode;
77
78 #[test]
79 fn create_light_baseline() {
80 let theme = Theme::default();
81 let baseline = baseline(&theme, &ThemeMode::Light);
82 println!("baseline: {baseline:#?}");
83 }
84}