Skip to main content

orbital_theme/baseline/
injection.rs

1use crate::baseline::{default_first_paint_theme, theme_scoped_vars_css, ROOT_THEME_SCOPE_ID};
2use crate::options::Density;
3use crate::Theme;
4
5/// Returns true when `theme` matches the default first-paint baseline (light, no overrides).
6pub 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/// Returns true when shell baseline assets are present in the document (hydrate only).
26#[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
44/// Skip redundant font/theme StyleRegistry injection for the root provider when baseline covers it.
45pub fn should_skip_root_baseline_injection(scope_id: &str, theme: &Theme) -> bool {
46    scope_id == ROOT_THEME_SCOPE_ID && is_baseline_theme(theme)
47}