(faces: FontFace[])
| 9 | // Packages prefer a 400 weight normal face for `index.css`, but there are fonts |
| 10 | // which do not have weight 400, or are only italic. |
| 11 | const pickStaticIndexCSS = (faces: FontFace[]): string | undefined => { |
| 12 | const findClosestFace = (candidates: readonly StaticFace[]) => { |
| 13 | if (candidates.length === 0) { |
| 14 | return undefined; |
| 15 | } |
| 16 | |
| 17 | const weight = findClosestWeight(candidates.map((face) => face.weight)); |
| 18 | return candidates.find((face) => face.weight === weight); |
| 19 | }; |
| 20 | |
| 21 | const staticFaces = faces.filter(isStaticFace); |
| 22 | const normalFaces = staticFaces.filter((face) => face.style === 'normal'); |
| 23 | |
| 24 | const index = findClosestFace(normalFaces) ?? findClosestFace(staticFaces); |
| 25 | |
| 26 | if (!index) { |
| 27 | return undefined; |
| 28 | } |
| 29 | |
| 30 | return index.style === 'normal' |
| 31 | ? `${index.weight}.css` |
| 32 | : `${index.weight}-${index.style}.css`; |
| 33 | }; |
| 34 | |
| 35 | const pickVariableIndexCSS = ( |
| 36 | variable: FontConfig['variable'], |
no test coverage detected