( config: FontConfig, axisKeys?: VariableAxisKey[], )
| 19 | * Omit axisKeys for every published bundle; an empty list selects none. |
| 20 | */ |
| 21 | export const resolveFontFaces = ( |
| 22 | config: FontConfig, |
| 23 | axisKeys?: VariableAxisKey[], |
| 24 | ): FontFace[] => { |
| 25 | const { |
| 26 | id, |
| 27 | family, |
| 28 | subsets, |
| 29 | weights, |
| 30 | styles, |
| 31 | unicodeRange = {}, |
| 32 | subsetSlices = {}, |
| 33 | variable, |
| 34 | formats = ['woff2'], |
| 35 | } = config; |
| 36 | |
| 37 | const faces: FontFace[] = []; |
| 38 | const isVariable = !!variable; |
| 39 | const familyId = id ?? normalizeKebabCase(family); |
| 40 | |
| 41 | if (isVariable) { |
| 42 | const requestedAxes = axisKeys ?? getVariableAxisKeys(variable); |
| 43 | |
| 44 | // Filter out ttf formats for variable fonts. |
| 45 | const variableFormats = formats.filter( |
| 46 | (format): format is WebFontFormat => format !== 'ttf', |
| 47 | ); |
| 48 | |
| 49 | // Generate one face per axis key, with the weight set to the closest available weight. |
| 50 | for (const axisKey of requestedAxes) { |
| 51 | const axisConfig = pickAxisConfig(variable, axisKey); |
| 52 | const cssWeight = axisConfig.wght |
| 53 | ? formatAxisValue(axisConfig.wght) |
| 54 | : `${findClosestWeight(weights)}`; |
| 55 | |
| 56 | const stretch = getFaceStretch(axisKey, axisConfig); |
| 57 | |
| 58 | for (const subset of subsets) { |
| 59 | const characterSets = subsetSlices[subset]?.length |
| 60 | ? subsetSlices[subset] |
| 61 | : [{ id: 0, unicodeRange: unicodeRange[subset] ?? '' }]; |
| 62 | for (const { |
| 63 | id: sliceIndex, |
| 64 | unicodeRange: faceRange, |
| 65 | } of characterSets) { |
| 66 | for (const style of styles) { |
| 67 | faces.push({ |
| 68 | subset, |
| 69 | weight: cssWeight, |
| 70 | style: getFaceStyle(axisKey, style, axisConfig), |
| 71 | isVariable: true, |
| 72 | unicodeRange: faceRange, |
| 73 | sources: variableFormats.map((format) => ({ |
| 74 | format, |
| 75 | filename: generateVariableFilename( |
| 76 | familyId, |
| 77 | subset, |
| 78 | axisKey, |
no test coverage detected