feat: add fontFamilies array

This commit is contained in:
Julien Calixte
2025-07-06 11:07:09 +02:00
parent 5341e6dcf0
commit b2250b2b95
8 changed files with 169 additions and 126 deletions

View File

@@ -1,4 +1,11 @@
import FontFaceObserver from 'fontfaceobserver'
import FontFaceObserver from "fontfaceobserver"
const assembleFontLink = (font: string) => {
return `https://fonts.googleapis.com/css2?display=swap&family=${font.replaceAll(
" ",
"+",
)}`
}
export const downloadGoogleFont = async (font: string): Promise<void> => {
const href = assembleFontLink(font)
@@ -7,21 +14,14 @@ export const downloadGoogleFont = async (font: string): Promise<void> => {
const existingLink = document.querySelector(`link[href="${href}"]`)
if (!existingLink) {
const link = document.createElement('link')
const link = document.createElement("link")
link.href = href
link.rel = 'stylesheet'
link.rel = "stylesheet"
document.head.appendChild(link)
}
await new FontFaceObserver(font).load()
document.documentElement.style.setProperty('--font-family', font)
}
const assembleFontLink = (font: string) => {
return `https://fonts.googleapis.com/css2?display=swap&family=${font.replaceAll(
' ',
'+'
)}`
document.documentElement.style.setProperty("--font-family", font)
}