#[cfg(any(feature = "ssr", feature = "hydrate"))]
use std::sync::OnceLock;
#[cfg(any(feature = "ssr", feature = "hydrate"))]
use orbital_style::inject_style;
fn font_asset_prefix() -> String {
match option_env!("LEPTOS_BASE_PATH") {
Some(base) if !base.is_empty() => format!("{base}/fonts"),
_ => "/fonts".to_string(),
}
}
pub fn font_faces_css_with_asset_prefix(prefix: &str) -> String {
let prefix = prefix.trim_end_matches('/');
format!(
r#"
@font-face {{
font-family: 'League Spartan';
src: url('{prefix}/league-spartan/LeagueSpartan-VF.woff2') format('woff2-variations');
font-weight: 200 900;
font-style: normal;
font-display: swap;
}}
@font-face {{
font-family: 'League Mono';
src: url('{prefix}/league-mono/LeagueMono-VF.woff2') format('woff2-variations');
font-weight: 100 800;
font-style: normal;
font-display: swap;
}}
@font-face {{
font-family: 'Orbitron';
src: url('{prefix}/orbitron/latin-400-normal.woff2') format('woff2');
font-weight: 400;
font-style: normal;
font-display: swap;
}}
@font-face {{
font-family: 'Orbitron';
src: url('{prefix}/orbitron/latin-600-normal.woff2') format('woff2');
font-weight: 600;
font-style: normal;
font-display: swap;
}}
@font-face {{
font-family: 'Orbitron';
src: url('{prefix}/orbitron/latin-700-normal.woff2') format('woff2');
font-weight: 700;
font-style: normal;
font-display: swap;
}}
"#
)
}
pub fn font_faces_css() -> String {
font_faces_css_with_asset_prefix(&font_asset_prefix())
}
#[cfg(any(feature = "ssr", feature = "hydrate"))]
pub fn inject_font_faces() {
static CSS: OnceLock<&'static str> = OnceLock::new();
let css = CSS.get_or_init(|| Box::leak(font_faces_css().into_boxed_str()));
inject_style("orbital-font-faces", css);
}