2024-05-13 23:40:18 +02:00
|
|
|
// Copyright 2024, Command Line Inc.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
|
|
|
|
let isJetBrainsMonoLoaded = false;
|
|
|
|
let isLatoFontLoaded = false;
|
|
|
|
let isHackFontLoaded = false;
|
2024-07-05 23:23:39 +02:00
|
|
|
let isHackNerdFontLoaded = false;
|
2024-05-13 23:40:18 +02:00
|
|
|
let isBaseFontsLoaded = false;
|
|
|
|
let isFiraCodeLoaded = false;
|
2024-07-05 23:09:27 +02:00
|
|
|
let isInterFontLoaded = false;
|
2024-05-13 23:40:18 +02:00
|
|
|
|
|
|
|
function addToFontFaceSet(fontFaceSet: FontFaceSet, fontFace: FontFace) {
|
|
|
|
// any cast to work around typing issue
|
|
|
|
(fontFaceSet as any).add(fontFace);
|
|
|
|
}
|
|
|
|
|
|
|
|
function loadJetBrainsMonoFont() {
|
|
|
|
if (isJetBrainsMonoLoaded) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
isJetBrainsMonoLoaded = true;
|
2024-06-14 01:49:25 +02:00
|
|
|
const jbmFontNormal = new FontFace("JetBrains Mono", "url('fonts/jetbrains-mono-v13-latin-regular.woff2')", {
|
2024-05-13 23:40:18 +02:00
|
|
|
style: "normal",
|
|
|
|
weight: "400",
|
|
|
|
});
|
2024-06-14 01:49:25 +02:00
|
|
|
const jbmFont200 = new FontFace("JetBrains Mono", "url('fonts/jetbrains-mono-v13-latin-200.woff2')", {
|
2024-05-13 23:40:18 +02:00
|
|
|
style: "normal",
|
|
|
|
weight: "200",
|
|
|
|
});
|
2024-06-14 01:49:25 +02:00
|
|
|
const jbmFont700 = new FontFace("JetBrains Mono", "url('fonts/jetbrains-mono-v13-latin-700.woff2')", {
|
2024-05-13 23:40:18 +02:00
|
|
|
style: "normal",
|
|
|
|
weight: "700",
|
|
|
|
});
|
|
|
|
addToFontFaceSet(document.fonts, jbmFontNormal);
|
|
|
|
addToFontFaceSet(document.fonts, jbmFont200);
|
|
|
|
addToFontFaceSet(document.fonts, jbmFont700);
|
|
|
|
jbmFontNormal.load();
|
|
|
|
jbmFont200.load();
|
|
|
|
jbmFont700.load();
|
|
|
|
}
|
|
|
|
|
|
|
|
function loadLatoFont() {
|
|
|
|
if (isLatoFontLoaded) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
isLatoFontLoaded = true;
|
2024-06-14 01:49:25 +02:00
|
|
|
const latoFont = new FontFace("Lato", "url('fonts/lato-regular.woff')", {
|
2024-05-13 23:40:18 +02:00
|
|
|
style: "normal",
|
|
|
|
weight: "400",
|
|
|
|
});
|
2024-06-14 01:49:25 +02:00
|
|
|
const latoFontBold = new FontFace("Lato", "url('fonts/lato-bold.woff')", {
|
2024-05-13 23:40:18 +02:00
|
|
|
style: "normal",
|
|
|
|
weight: "700",
|
|
|
|
});
|
|
|
|
addToFontFaceSet(document.fonts, latoFont);
|
|
|
|
addToFontFaceSet(document.fonts, latoFontBold);
|
|
|
|
latoFont.load();
|
|
|
|
latoFontBold.load();
|
|
|
|
}
|
|
|
|
|
|
|
|
function loadFiraCodeFont() {
|
|
|
|
if (isFiraCodeLoaded) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
isFiraCodeLoaded = true;
|
2024-06-14 01:49:25 +02:00
|
|
|
const firaCodeRegular = new FontFace("Fira Code", "url('fonts/firacode-regular.woff2')", {
|
2024-05-13 23:40:18 +02:00
|
|
|
style: "normal",
|
|
|
|
weight: "400",
|
|
|
|
});
|
2024-06-14 01:49:25 +02:00
|
|
|
const firaCodeBold = new FontFace("Fira Code", "url('fonts/firacode-bold.woff2')", {
|
2024-05-13 23:40:18 +02:00
|
|
|
style: "normal",
|
|
|
|
weight: "700",
|
|
|
|
});
|
|
|
|
addToFontFaceSet(document.fonts, firaCodeRegular);
|
|
|
|
addToFontFaceSet(document.fonts, firaCodeBold);
|
|
|
|
firaCodeRegular.load();
|
|
|
|
firaCodeBold.load();
|
|
|
|
}
|
|
|
|
|
2024-07-05 23:23:39 +02:00
|
|
|
function loadHackNerdFont() {
|
|
|
|
if (isHackNerdFontLoaded) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
isHackFontLoaded = true;
|
|
|
|
const hackRegular = new FontFace("Hack", "url('fonts/hacknerdmono-regular.ttf')", {
|
|
|
|
style: "normal",
|
|
|
|
weight: "400",
|
|
|
|
});
|
|
|
|
const hackBold = new FontFace("Hack", "url('fonts/hacknerdmono-bold.ttf')", {
|
|
|
|
style: "normal",
|
|
|
|
weight: "700",
|
|
|
|
});
|
|
|
|
const hackItalic = new FontFace("Hack", "url('fonts/hacknerdmono-italic.ttf')", {
|
|
|
|
style: "italic",
|
|
|
|
weight: "400",
|
|
|
|
});
|
|
|
|
const hackBoldItalic = new FontFace("Hack", "url('fonts/hacknerdmono-bolditalic.ttf')", {
|
|
|
|
style: "italic",
|
|
|
|
weight: "700",
|
|
|
|
});
|
|
|
|
addToFontFaceSet(document.fonts, hackRegular);
|
|
|
|
addToFontFaceSet(document.fonts, hackBold);
|
|
|
|
addToFontFaceSet(document.fonts, hackItalic);
|
|
|
|
addToFontFaceSet(document.fonts, hackBoldItalic);
|
|
|
|
hackRegular.load();
|
|
|
|
hackBold.load();
|
|
|
|
hackItalic.load();
|
|
|
|
hackBoldItalic.load();
|
|
|
|
}
|
|
|
|
|
2024-05-13 23:40:18 +02:00
|
|
|
function loadHackFont() {
|
|
|
|
if (isHackFontLoaded) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
isHackFontLoaded = true;
|
2024-06-14 01:49:25 +02:00
|
|
|
const hackRegular = new FontFace("Hack", "url('fonts/hack-regular.woff2')", {
|
2024-05-13 23:40:18 +02:00
|
|
|
style: "normal",
|
|
|
|
weight: "400",
|
|
|
|
});
|
2024-06-14 01:49:25 +02:00
|
|
|
const hackBold = new FontFace("Hack", "url('fonts/hack-bold.woff2')", {
|
2024-05-13 23:40:18 +02:00
|
|
|
style: "normal",
|
|
|
|
weight: "700",
|
|
|
|
});
|
2024-06-14 01:49:25 +02:00
|
|
|
const hackItalic = new FontFace("Hack", "url('fonts/hack-italic.woff2')", {
|
2024-05-13 23:40:18 +02:00
|
|
|
style: "italic",
|
|
|
|
weight: "400",
|
|
|
|
});
|
2024-06-14 01:49:25 +02:00
|
|
|
const hackBoldItalic = new FontFace("Hack", "url('fonts/hack-bolditalic.woff2')", {
|
2024-05-13 23:40:18 +02:00
|
|
|
style: "italic",
|
|
|
|
weight: "700",
|
|
|
|
});
|
|
|
|
addToFontFaceSet(document.fonts, hackRegular);
|
|
|
|
addToFontFaceSet(document.fonts, hackBold);
|
|
|
|
addToFontFaceSet(document.fonts, hackItalic);
|
|
|
|
addToFontFaceSet(document.fonts, hackBoldItalic);
|
|
|
|
hackRegular.load();
|
|
|
|
hackBold.load();
|
|
|
|
hackItalic.load();
|
|
|
|
hackBoldItalic.load();
|
|
|
|
}
|
|
|
|
|
2024-07-05 23:09:27 +02:00
|
|
|
function loadInterFont() {
|
|
|
|
if (isInterFontLoaded) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
isInterFontLoaded = true;
|
|
|
|
const interFont = new FontFace("Inter", "url('fonts/inter-variable.woff2')", {
|
|
|
|
style: "normal",
|
2024-07-05 23:57:11 +02:00
|
|
|
weight: "100 900",
|
2024-07-05 23:09:27 +02:00
|
|
|
});
|
|
|
|
addToFontFaceSet(document.fonts, interFont);
|
|
|
|
interFont.load();
|
|
|
|
}
|
|
|
|
|
2024-05-13 23:40:18 +02:00
|
|
|
function loadBaseFonts() {
|
|
|
|
if (isBaseFontsLoaded) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
isBaseFontsLoaded = true;
|
2024-06-14 01:49:25 +02:00
|
|
|
const mmFont = new FontFace("Martian Mono", "url('fonts/MartianMono-VariableFont_wdth,wght.ttf')", {
|
2024-05-13 23:40:18 +02:00
|
|
|
style: "normal",
|
|
|
|
weight: "normal",
|
|
|
|
});
|
|
|
|
addToFontFaceSet(document.fonts, mmFont);
|
|
|
|
mmFont.load();
|
|
|
|
}
|
|
|
|
|
|
|
|
function loadFonts() {
|
|
|
|
loadBaseFonts();
|
2024-07-05 23:09:27 +02:00
|
|
|
loadInterFont();
|
2024-05-13 23:40:18 +02:00
|
|
|
loadJetBrainsMonoFont();
|
2024-07-05 23:23:39 +02:00
|
|
|
loadHackNerdFont();
|
2024-05-13 23:40:18 +02:00
|
|
|
loadFiraCodeFont();
|
|
|
|
}
|
|
|
|
|
|
|
|
export { loadFonts };
|