mod injection;
#[cfg(test)]
mod tests;
pub use injection::{
baseline_active_in_document, is_baseline_theme, should_skip_root_baseline_injection,
};
use crate::context::scoped_css;
use crate::fonts::{font_faces_css, font_faces_css_with_asset_prefix};
use crate::Theme;
pub const ROOT_THEME_SCOPE_ID: &str = "0";
pub const BASELINE_STYLESHEET_FILENAME: &str = "orbital-theme-baseline.css";
pub fn default_first_paint_theme() -> Theme {
Theme::light()
}
pub fn theme_scoped_vars_css(scope_id: &str, theme: &Theme) -> String {
let mut css_vars = String::new();
theme.write_css_vars(&mut css_vars);
scoped_css(scope_id, &css_vars)
}
pub fn theme_baseline_css(scope_id: &str, theme: &Theme) -> String {
let mut out = font_faces_css();
out.push('\n');
out.push_str(&theme_scoped_vars_css(scope_id, theme));
out
}
pub fn theme_baseline_css_with_font_prefix(
scope_id: &str,
theme: &Theme,
font_prefix: &str,
) -> String {
let mut out = font_faces_css_with_asset_prefix(font_prefix);
out.push('\n');
out.push_str(&theme_scoped_vars_css(scope_id, theme));
out
}
pub fn default_first_paint_baseline_css(scope_id: &str) -> String {
theme_baseline_css(scope_id, &default_first_paint_theme())
}
pub fn default_first_paint_baseline_css_with_font_prefix(
scope_id: &str,
font_prefix: &str,
) -> String {
theme_baseline_css_with_font_prefix(scope_id, &default_first_paint_theme(), font_prefix)
}
pub fn baseline_stylesheet_filename() -> &'static str {
BASELINE_STYLESHEET_FILENAME
}
pub fn baseline_asset_path(base_path: &str) -> String {
let base = base_path.trim_end_matches('/');
let file = BASELINE_STYLESHEET_FILENAME;
if base.is_empty() {
format!("/{file}")
} else {
format!("{base}/{file}")
}
}
pub fn baseline_primary_font_preload_path(base_path: &str) -> String {
let base = base_path.trim_end_matches('/');
let path = "fonts/league-spartan/LeagueSpartan-VF.woff2";
if base.is_empty() {
format!("/{path}")
} else {
format!("{base}/{path}")
}
}