Skip to content

Commit

Permalink
fix: capture max fonts
Browse files Browse the repository at this point in the history
  • Loading branch information
abrahamjuliot committed Aug 17, 2022
1 parent 1b07fe4 commit 6fe4fec
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions src/fonts/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,25 +183,24 @@ export default async function getFonts() {

const getFontFaceLoadFonts = async (fontList: string[]) => {
try {
let fontsChecked: string[] = []
if (!document.fonts.check(`0px "${getRandomValues()}"`)) {
const fontsChecked = fontList.reduce((acc, font) => {
fontsChecked = fontList.reduce((acc, font) => {
const found = document.fonts.check(`0px "${font}"`)
if (found) acc.push(font)
return acc
}, [] as string[])
return fontsChecked
}
const fontFaceList = fontList.map((font) => new FontFace(font, `local("${font}")`))
const responseCollection = await Promise
.allSettled(fontFaceList.map((font) => font.load()))
// @ts-ignore
const fonts = responseCollection.reduce((acc, font) => {
const fontsLoaded = responseCollection.reduce((acc, font) => {
if (font.status == 'fulfilled') {
return [...acc, font.value.family]
acc.push(font.value.family)
}
return acc
}, [])
return fonts
}, [] as string[])
return [...new Set([...fontsChecked, ...fontsLoaded])].sort()
} catch (error) {
console.error(error)
return []
Expand Down

0 comments on commit 6fe4fec

Please sign in to comment.