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

Function determineAxisKey

packages/core/src/utils/variable.ts:17–47  ·  view source on GitHub ↗
(
	variableConfig: VariableAxisConfig,
)

Source from the content-addressed store, hash-verified

15 * Pick the default published axis key for a variable family.
16 */
17export const determineAxisKey = (
18 variableConfig: VariableAxisConfig,
19): VariableAxisKey => {
20 // Filter out any inactive axes and `ital` since it's always included.
21 const active = Object.keys(variableConfig).filter((axisKey) =>
22 Boolean(variableConfig[axisKey]),
23 );
24
25 if (active.length === 0) {
26 return 'wght'; // Default.
27 }
28
29 const standard = active.filter((axisKey) =>
30 STANDARD_VARIABLE_AXES.has(axisKey),
31 );
32 const custom = active.filter(
33 (axisKey) => !STANDARD_VARIABLE_AXES.has(axisKey),
34 );
35
36 // If there are any custom axes, we prefer those as the default entrypoint since they
37 // are more specific. If there's more than one custom axis, we fall back to `full`.
38 if (custom.length > 0) {
39 return standard.length > 0 || custom.length > 1
40 ? 'full'
41 : (custom[0] ?? '');
42 }
43
44 // If there are no custom axes, we prefer the standard axes.
45 // If there's more than one, we fall back to `standard`.
46 return standard.length > 1 ? 'standard' : (standard[0] ?? '');
47};
48
49/**
50 * Return every published axis key from a variable font config.

Callers 3

pickVariableIndexCSSFunction · 0.90
utils.test.tsFile · 0.90
selectVariableAxisKeyFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected