MCPcopy Create free account
hub / github.com/fontsource/fontsource / generateFaceCSSAssets

Function generateFaceCSSAssets

packages/core/src/css/assets.ts:10–41  ·  view source on GitHub ↗
(
	family: string,
	faces: FontFace[],
	options: FontFaceOptions & { variable?: FontConfig['variable'] } = {},
)

Source from the content-addressed store, hash-verified

8
9// Group resolved faces into published CSS assets.
10const generateFaceCSSAssets = (
11 family: string,
12 faces: FontFace[],
13 options: FontFaceOptions & { variable?: FontConfig['variable'] } = {},
14): CSSAsset[] => {
15 const { variable, ...fontFaceOptions } = options;
16 const facesByFile = groupFacesByCSSFile(faces);
17
18 const indexCSSFile = variable
19 ? pickVariableIndexCSS(variable, facesByFile)
20 : pickStaticIndexCSS(faces);
21
22 // If an index CSS file is selected, also publish it as `index.css`.
23 if (indexCSSFile) {
24 const indexFaces = facesByFile.get(indexCSSFile);
25 if (indexFaces) {
26 facesByFile.set('index.css', indexFaces);
27 }
28 }
29
30 // Render each CSS file with the appropriate faces.
31 const assets: CSSAsset[] = [];
32 for (const [filename, faces] of facesByFile) {
33 const content = faces
34 .map((face) => renderFontFace(face, family, fontFaceOptions))
35 .join('\n\n');
36
37 assets.push({ filename, content });
38 }
39
40 return assets;
41};
42
43export { generateFaceCSSAssets, renderFontFace };

Callers 3

buildFontFunction · 0.90
generateCSSAssetsFunction · 0.90
css.test.tsFile · 0.90

Calls 6

groupFacesByCSSFileFunction · 0.90
pickVariableIndexCSSFunction · 0.90
pickStaticIndexCSSFunction · 0.90
renderFontFaceFunction · 0.90
setMethod · 0.80
getMethod · 0.65

Tested by

no test coverage detected