feat: add fontFamilies array
This commit is contained in:
@@ -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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user