feat(appliedFontsStore): incorporate implemented font weight logic

This commit is contained in:
Ilia Mashkov
2026-01-20 14:21:07 +03:00
parent 55a560b785
commit d4d2d68d9a
4 changed files with 32 additions and 18 deletions

View File

@@ -20,6 +20,10 @@ interface Props {
* Font id to load
*/
id: string;
/**
* Font weight
*/
weight?: number;
/**
* Additional classes
*/
@@ -30,7 +34,7 @@ interface Props {
children?: Snippet;
}
let { name, id, className, children }: Props = $props();
let { name, id, weight = 400, className, children }: Props = $props();
let element: Element;
// Track if the user has actually scrolled this into view
@@ -40,7 +44,7 @@ $effect(() => {
const observer = new IntersectionObserver(entries => {
if (entries[0].isIntersecting) {
hasEnteredViewport = true;
appliedFontsManager.touch([id]);
appliedFontsManager.touch([{ slug: id, weight }]);
// Once it has entered, we can stop observing to save CPU
observer.unobserve(element);
@@ -50,7 +54,7 @@ $effect(() => {
return () => observer.disconnect();
});
const status = $derived(appliedFontsManager.getFontStatus(id));
const status = $derived(appliedFontsManager.getFontStatus(id, weight, false));
// The "Show" condition: Element is in view AND (Font is ready OR it errored out)
const shouldReveal = $derived(hasEnteredViewport && (status === 'loaded' || status === 'error'));