orbital_theme/baseline/
injection.rs1use crate::baseline::{default_first_paint_theme, theme_scoped_vars_css, ROOT_THEME_SCOPE_ID};
2use crate::options::Density;
3use crate::Theme;
4
5pub fn is_baseline_theme(theme: &Theme) -> bool {
7 if theme.mode != crate::ThemeMode::Light {
8 return false;
9 }
10
11 let options = &theme.options;
12 if options.brand.is_some() || options.density != Density::Default {
13 return false;
14 }
15
16 if (options.elevation.multiplier - 1.0).abs() > f32::EPSILON {
17 return false;
18 }
19
20 let baseline = default_first_paint_theme();
21 theme_scoped_vars_css(ROOT_THEME_SCOPE_ID, theme)
22 == theme_scoped_vars_css(ROOT_THEME_SCOPE_ID, &baseline)
23}
24
25#[cfg(feature = "hydrate")]
27pub fn baseline_active_in_document() -> bool {
28 use leptos::prelude::document;
29
30 document()
31 .query_selector(&format!(
32 r#"[data-orbital-theme-baseline="{ROOT_THEME_SCOPE_ID}"]"#
33 ))
34 .ok()
35 .flatten()
36 .is_some()
37}
38
39#[cfg(not(feature = "hydrate"))]
40pub fn baseline_active_in_document() -> bool {
41 false
42}
43
44pub fn should_skip_root_baseline_injection(scope_id: &str, theme: &Theme) -> bool {
46 scope_id == ROOT_THEME_SCOPE_ID && is_baseline_theme(theme)
47}