Skip to content

Commit

Permalink
fix(google): handle variable font weights
Browse files Browse the repository at this point in the history
  • Loading branch information
danielroe committed Feb 22, 2024
1 parent d2c9ac1 commit 4a9bc4d
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions src/providers/google.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ interface FontIndexMeta {
width: number | null
lineHeight: number | null
}>
axes: Array<{
tag: string
min: number
max: number
defaultValue: number
}>
}

/** internal */
Expand All @@ -57,16 +63,19 @@ function isGoogleFont (family: string) {
return fonts.some(font => font.family === family)
}

const styleMap = {
italic: '1',
oblique: '1',
normal: '0'
}
async function getFontDetails (family: string, variants: ResolveFontFacesOptions) {
const font = fonts.find(font => font.family === family)!
const weights = variants.weights.filter(weight => String(weight) in font.fonts)
const styleMap = {
italic: '1',
oblique: '1',
normal: '0'
}
const styles = [...new Set(variants.styles.map(i => styleMap[i]))].sort()

const styles = new Set(variants.styles.map(i => styleMap[i]))
const variableWeight = font.axes.find(a => a.tag === 'wght')
const weights = variableWeight
? [`${variableWeight.min}..${variableWeight.max}`]
: variants.weights.filter(weight => String(weight) in font.fonts)
const resolvedVariants = weights.flatMap(w => [...styles].map(s => `${s},${w}`))

let css = ''
Expand Down

0 comments on commit 4a9bc4d

Please sign in to comment.