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

Function resolveFontFaces

packages/core/src/utils/faces.ts:22–114  ·  view source on GitHub ↗
(
	config: FontConfig,
	options: ResolveFontFaceOptions = {},
)

Source from the content-addressed store, hash-verified

20 * Get the full list of font faces to generate for a given font configuration.
21 */
22export const resolveFontFaces = (
23 config: FontConfig,
24 options: ResolveFontFaceOptions = {},
25): FontFace[] => {
26 const {
27 id,
28 family,
29 subsets,
30 weights,
31 styles,
32 unicodeRange = {},
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 axisKeys = getRequestedAxisKeys(variable, options.axisKeys);
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 axisKeys) {
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 for (const style of styles) {
60 faces.push({
61 subset,
62 weight: cssWeight,
63 style: getFaceStyle(axisKey, style, axisConfig),
64 isVariable: true,
65 unicodeRange: unicodeRange[subset] ?? '',
66 sources: variableFormats.map((format) => ({
67 format,
68 filename: generateVariableFilename(
69 familyId,
70 subset,
71 axisKey,
72 style,
73 0,
74 format,
75 ),
76 })),
77 axisKey,
78 stretch,
79 sliceIndex: 0,

Callers 3

generateCSSAssetsFunction · 0.90
generateCSSFunction · 0.90
utils.test.tsFile · 0.90

Calls 9

normalizeKebabCaseFunction · 0.90
getRequestedAxisKeysFunction · 0.90
pickAxisConfigFunction · 0.90
formatAxisValueFunction · 0.90
findClosestWeightFunction · 0.90
getFaceStretchFunction · 0.90
getFaceStyleFunction · 0.90
generateVariableFilenameFunction · 0.90
generateStaticFilenameFunction · 0.90

Tested by

no test coverage detected