2026-01-18 12:57:56 +03:00
|
|
|
<!--
|
|
|
|
|
Component: FontApplicator
|
2026-04-20 22:20:44 +03:00
|
|
|
Applies a font to its children once the font file is loaded.
|
|
|
|
|
Shows the skeleton snippet while loading; falls back to system font if no skeleton is provided.
|
2026-01-18 12:57:56 +03:00
|
|
|
-->
|
|
|
|
|
<script lang="ts">
|
2026-04-23 09:48:32 +03:00
|
|
|
import { cn } from '$shared/lib';
|
2026-01-18 12:57:56 +03:00
|
|
|
import type { Snippet } from 'svelte';
|
2026-06-01 12:06:30 +03:00
|
|
|
import type {
|
|
|
|
|
FontLoadStatus,
|
|
|
|
|
UnifiedFont,
|
|
|
|
|
} from '../../model/types';
|
2026-01-18 12:57:56 +03:00
|
|
|
|
|
|
|
|
interface Props {
|
2026-01-18 15:55:07 +03:00
|
|
|
/**
|
2026-03-02 22:18:21 +03:00
|
|
|
* Font to apply
|
2026-01-18 15:55:07 +03:00
|
|
|
*/
|
2026-02-10 18:09:13 +03:00
|
|
|
font: UnifiedFont;
|
2026-01-20 14:21:07 +03:00
|
|
|
/**
|
2026-06-01 12:06:30 +03:00
|
|
|
* Current load status for this font, supplied by the composing layer.
|
|
|
|
|
* Kept out of the component so it does not depend on (and import) the
|
|
|
|
|
* lifecycle store — the owning widget reads the manager and passes the
|
|
|
|
|
* resolved status down. `undefined` means the font is not tracked yet and
|
|
|
|
|
* is treated as not-yet-revealed (skeleton / system-font fallback).
|
2026-01-20 14:21:07 +03:00
|
|
|
*/
|
2026-06-01 12:06:30 +03:00
|
|
|
status: FontLoadStatus | undefined;
|
2026-01-18 15:55:07 +03:00
|
|
|
/**
|
2026-03-02 22:18:21 +03:00
|
|
|
* CSS classes
|
2026-01-18 15:55:07 +03:00
|
|
|
*/
|
2026-01-18 12:57:56 +03:00
|
|
|
className?: string;
|
2026-01-18 15:55:07 +03:00
|
|
|
/**
|
2026-03-02 22:18:21 +03:00
|
|
|
* Content snippet
|
2026-01-18 15:55:07 +03:00
|
|
|
*/
|
2026-01-18 12:57:56 +03:00
|
|
|
children?: Snippet;
|
2026-04-20 22:20:44 +03:00
|
|
|
/**
|
|
|
|
|
* Shown while the font file is loading.
|
|
|
|
|
* When omitted, children render in system font until ready.
|
|
|
|
|
*/
|
|
|
|
|
skeleton?: Snippet;
|
2026-01-18 12:57:56 +03:00
|
|
|
}
|
|
|
|
|
|
2026-02-12 11:14:22 +03:00
|
|
|
let {
|
|
|
|
|
font,
|
2026-06-01 12:06:30 +03:00
|
|
|
status,
|
2026-02-12 11:14:22 +03:00
|
|
|
className,
|
|
|
|
|
children,
|
2026-04-20 22:20:44 +03:00
|
|
|
skeleton,
|
2026-02-12 11:14:22 +03:00
|
|
|
}: Props = $props();
|
2026-01-18 12:57:56 +03:00
|
|
|
|
2026-02-12 11:21:04 +03:00
|
|
|
const shouldReveal = $derived(status === 'loaded' || status === 'error');
|
2026-01-18 12:57:56 +03:00
|
|
|
</script>
|
|
|
|
|
|
2026-04-20 22:20:44 +03:00
|
|
|
{#if !shouldReveal && skeleton}
|
|
|
|
|
{@render skeleton()}
|
|
|
|
|
{:else}
|
|
|
|
|
<div
|
|
|
|
|
style:font-family={shouldReveal ? `'${font.name}'` : 'system-ui, -apple-system, sans-serif'}
|
2026-04-23 09:48:32 +03:00
|
|
|
class={cn(className)}
|
2026-04-20 22:20:44 +03:00
|
|
|
>
|
|
|
|
|
{@render children?.()}
|
|
|
|
|
</div>
|
|
|
|
|
{/if}
|