Wait for font to load before rendering
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful

This commit is contained in:
Isaac Mills 2025-07-19 10:30:58 -06:00
parent 966d56972e
commit 6e687e5400
Signed by: fnmain
GPG key ID: B67D7410F33A0F61
5 changed files with 14 additions and 29 deletions

View file

@ -1,15 +0,0 @@
@font-face {
font-family: 'Fira Code';
src: url('/assets/FiraCode-Bold.woff2') format('woff2');
font-weight: bold;
font-style: normal;
font-display: swap;
}
@font-face {
font-family: 'Fira Code';
src: url('/assets/FiraCode-Regular.woff2') format('woff2');
font-weight: normal;
font-style: normal;
font-display: swap;
}

View file

@ -8,15 +8,17 @@
</x-section-head> </x-section-head>
<div id="cockpit-canvas" style="height: 80vh; margin: 8px; background-color: #000;"></div> <div id="cockpit-canvas" style="height: 80vh; margin: 8px; background-color: #000;"></div>
</x-tab.content> </x-tab.content>
<push name="head"> <script type="module">
<link rel="preload" href="/assets/FiraCode-Regular.woff2" as="font" type="font/woff2" crossorigin> const firaCodeFace = new FontFace('Fira Code', `url(${new URL('/assets/FiraCode-Regular.woff2', import.meta.url)})`, {style: "normal", weight: "normal"});
<link rel="preload" href="/assets/FiraCode-Bold.woff2" as="font" type="font/woff2" crossorigin> const firaCodeBoldFace = new FontFace('Fira Code', `url(${new URL('/assets/FiraCode-Bold.woff2', import.meta.url)})`, {style: "normal", weight: "bold"});
</push> Promise.all([firaCodeFace.load(), firaCodeBoldFace.load()]).then((faces) => {
<script> document.fonts.add(faces[0]);
var interval = setInterval(function () { document.fonts.add(faces[1]);
if (typeof window.run_cockpit === 'function') { var interval = setInterval(function () {
clearInterval(interval); if (typeof window.runCockpit === 'function') {
window.run_cockpit(); clearInterval(interval);
} window.runCockpit();
}, 100); }
}, 50);
});
</script> </script>

View file

@ -1,5 +1,4 @@
@import 'apex.css'; @import 'apex.css';
@import 'firacode.css';
@custom-media --tablet only screen and (max-width: 1200px); @custom-media --tablet only screen and (max-width: 1200px);
@custom-media --phone only screen and (max-width: 800px); @custom-media --phone only screen and (max-width: 800px);

View file

@ -1,5 +1,5 @@
import { default as init, run } from 'thecockpit' import { default as init, run } from 'thecockpit'
window.run_cockpit = async () => { window.runCockpit = async () => {
await init(); await init();
run("cockpit-canvas"); run("cockpit-canvas");
}; };

View file

@ -1,5 +1,4 @@
@import 'apex.css'; @import 'apex.css';
@import 'firacode.css';
@custom-media --tablet only screen and (max-width: 1200px); @custom-media --tablet only screen and (max-width: 1200px);
@custom-media --phone only screen and (max-width: 800px); @custom-media --phone only screen and (max-width: 800px);