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

Function generateVariableVariants

api/cdn/src/util.ts:106–177  ·  view source on GitHub ↗
(
	metadata: IDResponse,
	variableMeta: VariableMetadata,
)

Source from the content-addressed store, hash-verified

104};
105
106export const generateVariableVariants = (
107 metadata: IDResponse,
108 variableMeta: VariableMetadata,
109): VariableMetadataWithVariants => {
110 const variants: VariableVariants = {};
111 // Remove ital from axes keys if it exists
112 const keys = Object.keys(variableMeta.axes).filter((key) => key !== 'ital');
113
114 for (const axis of keys) {
115 variants[axis] = {};
116
117 for (const style of metadata.styles) {
118 variants[axis][style] = {};
119
120 for (const unicodeKey of Object.keys(metadata.unicodeRange)) {
121 const subset = unicodeKey.replace('[', '').replace(']', '');
122 const value = makeFontFileVariablePath(
123 metadata.family,
124 style,
125 subset,
126 axis,
127 );
128 variants[axis][style][subset] = value;
129 }
130 }
131 }
132
133 // Check if axes have any of the following standard keys
134 const standardKeys = new Set(['wght', 'wdth', 'slnt', 'opsz']);
135 const isStandard = keys.some((key) => standardKeys.has(key));
136 if (isStandard) {
137 for (const style of metadata.styles) {
138 variants.standard = {};
139 variants.standard[style] = {};
140
141 for (const subset of metadata.subsets) {
142 const value = makeFontFileVariablePath(
143 metadata.family,
144 style,
145 subset,
146 'standard',
147 );
148 variants.standard[style][subset] = value;
149 }
150 }
151 }
152
153 // Check if axes do not match the standard keys
154 const isFull = keys.some((key) => !standardKeys.has(key));
155 if (isFull) {
156 for (const style of metadata.styles) {
157 variants.full = {};
158 variants.full[style] = {};
159
160 for (const unicodeKey of Object.keys(metadata.unicodeRange)) {
161 const subset = unicodeKey.replace('[', '').replace(']', '');
162 const value = makeFontFileVariablePath(
163 metadata.family,

Callers 1

updateVariableCSSFunction · 0.90

Calls 2

makeFontFileVariablePathFunction · 0.90
replaceMethod · 0.65

Tested by

no test coverage detected