MCPcopy Index your code
hub / github.com/fontsource/fontsource / pickStaticIndexCSS

Function pickStaticIndexCSS

packages/core/src/css/planner.ts:11–33  ·  view source on GitHub ↗
(faces: FontFace[])

Source from the content-addressed store, hash-verified

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.
11const 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
35const pickVariableIndexCSS = (
36 variable: FontConfig['variable'],

Callers 2

generateFaceCSSAssetsFunction · 0.90

Calls 1

findClosestFaceFunction · 0.85

Tested by

no test coverage detected