use topcoat_core::error::Result;
use topcoat_view::View;
use topcoat_view_macro::{component, view};
use crate::{Font, FontFormat, FontSource};
#[component]
pub async fn link(
font: Font,
#[default(true)]
preload: bool,
) -> Result<impl View> {
Ok(view! {
if preload {
for face in font.faces().iter() {
if let Some(source) = face.src().first() {
preload_link(source: source)
}
}
}
<link rel="stylesheet" href=(font)>
})
}
#[component]
pub async fn preload_link(
source: &FontSource,
) -> Result<impl View> {
Ok(view! {
if let FontSource::Url { url, format, .. } = source {
<link
rel="preload"
href=(url.clone())
as="font"
type=(format.map(FontFormat::mime_type))
crossorigin="true"
>
}
})
}