feat(Layout): add font loading flag and change head links to prevent FOUT
This commit is contained in:
@@ -15,32 +15,69 @@ import GD from '$shared/assets/GD.svg';
|
|||||||
import { ResponsiveProvider } from '$shared/lib';
|
import { ResponsiveProvider } from '$shared/lib';
|
||||||
import { ScrollArea } from '$shared/shadcn/ui/scroll-area';
|
import { ScrollArea } from '$shared/shadcn/ui/scroll-area';
|
||||||
import { Provider as TooltipProvider } from '$shared/shadcn/ui/tooltip';
|
import { Provider as TooltipProvider } from '$shared/shadcn/ui/tooltip';
|
||||||
import type { Snippet } from 'svelte';
|
import {
|
||||||
|
type Snippet,
|
||||||
|
onMount,
|
||||||
|
} from 'svelte';
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
children: Snippet;
|
children: Snippet;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Slot content for route pages to render */
|
|
||||||
let { children }: Props = $props();
|
let { children }: Props = $props();
|
||||||
|
let fontsReady = $state(false);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets fontsReady flag to true when font for the page logo is loaded.
|
||||||
|
*/
|
||||||
|
onMount(async () => {
|
||||||
|
if (!('fonts' in document)) {
|
||||||
|
fontsReady = true;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const required = ['100'];
|
||||||
|
|
||||||
|
const missing = required.filter(
|
||||||
|
w => !document.fonts.check(`${w} 1em Barlow`),
|
||||||
|
);
|
||||||
|
|
||||||
|
if (missing.length > 0) {
|
||||||
|
await Promise.all(
|
||||||
|
missing.map(w => document.fonts.load(`${w} 1em Barlow`)),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
fontsReady = true;
|
||||||
|
});
|
||||||
|
|
||||||
|
$inspect(fontsReady);
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<svelte:head>
|
<svelte:head>
|
||||||
<link rel="icon" href={GD} />
|
<link rel="icon" href={GD} />
|
||||||
|
|
||||||
<link rel="preconnect" href="https://api.fontshare.com" />
|
<link rel="preconnect" href="https://api.fontshare.com" />
|
||||||
<link rel="preconnect" href="https://cdn.fontshare.com" crossorigin="anonymous" />
|
<link rel="preconnect" href="https://cdn.fontshare.com" crossorigin="anonymous" />
|
||||||
|
|
||||||
<link rel="preconnect" href="https://fonts.googleapis.com">
|
<link rel="preconnect" href="https://fonts.googleapis.com">
|
||||||
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin="anonymous">
|
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin="anonymous">
|
||||||
<link
|
<link
|
||||||
href="https://fonts.googleapis.com/css2?family=Karla:ital,wght@0,200..800;1,200..800&display=swap"
|
rel="preload"
|
||||||
rel="stylesheet"
|
as="style"
|
||||||
|
href="https://fonts.googleapis.com/css2?family=Barlow:ital,wght@0,100;0,200;1,100;1,200&family=Karla:wght@200..800&display=swap"
|
||||||
>
|
>
|
||||||
<link
|
<link
|
||||||
href="https://fonts.googleapis.com/css2?family=Barlow:ital,wght@0,100;0,200;0,300;0,400;0,500;0,600;0,700;0,800;0,900;1,100;1,200;1,300;1,400;1,500;1,600;1,700;1,800;1,900&family=Karla:wght@300&display=swap"
|
|
||||||
rel="stylesheet"
|
rel="stylesheet"
|
||||||
|
href="https://fonts.googleapis.com/css2?family=Barlow:ital,wght@0,100;0,200;1,100;1,200&family=Karla:wght@200..800&display=swap"
|
||||||
|
media="print"
|
||||||
|
onload={(e => ((e.currentTarget as HTMLLinkElement).media = 'all'))}
|
||||||
>
|
>
|
||||||
|
<noscript>
|
||||||
|
<link
|
||||||
|
rel="stylesheet"
|
||||||
|
href="https://fonts.googleapis.com/css2?family=Barlow:ital,wght@0,100;0,200;1,100;1,200&family=Karla:wght@200..800&display=swap"
|
||||||
|
>
|
||||||
|
</noscript>
|
||||||
<title>
|
<title>
|
||||||
Compare Typography & Typefaces | GlyphDiff
|
Compare Typography & Typefaces | GlyphDiff
|
||||||
</title>
|
</title>
|
||||||
@@ -55,7 +92,9 @@ let { children }: Props = $props();
|
|||||||
<!-- <ScrollArea class="h-screen w-screen"> -->
|
<!-- <ScrollArea class="h-screen w-screen"> -->
|
||||||
<main class="flex-1 h-full w-full max-w-6xl mx-auto px-0 pt-0 pb-10 sm:px-6 sm:pt-8 sm:pb-12 md:px-8 md:pt-10 md:pb-16 lg:px-10 lg:pt-12 lg:pb-20 xl:px-16 relative overflow-x-hidden">
|
<main class="flex-1 h-full w-full max-w-6xl mx-auto px-0 pt-0 pb-10 sm:px-6 sm:pt-8 sm:pb-12 md:px-8 md:pt-10 md:pb-16 lg:px-10 lg:pt-12 lg:pb-20 xl:px-16 relative overflow-x-hidden">
|
||||||
<TooltipProvider>
|
<TooltipProvider>
|
||||||
{@render children?.()}
|
{#if fontsReady}
|
||||||
|
{@render children?.()}
|
||||||
|
{/if}
|
||||||
</TooltipProvider>
|
</TooltipProvider>
|
||||||
</main>
|
</main>
|
||||||
<!-- </ScrollArea> -->
|
<!-- </ScrollArea> -->
|
||||||
|
|||||||
Reference in New Issue
Block a user