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

Function createGoogleDistribution

registry/scripts/google.ts:225–318  ·  view source on GitHub ↗
(
	google: GoogleFamily,
	sources: Family['sources'],
)

Source from the content-addressed store, hash-verified

223};
224
225const createGoogleDistribution = (
226 google: GoogleFamily,
227 sources: Family['sources'],
228): FamilyDistribution => {
229 const staticVariants = new Map<
230 string,
231 NonNullable<FamilyDistribution['static']>[number]
232 >();
233 const variableVariants = new Map<
234 string,
235 NonNullable<FamilyDistribution['variable']>[number]
236 >();
237
238 for (const source of sources) {
239 if (source.inspection.axes.length === 0) {
240 if (source.variant) {
241 staticVariants.set(
242 `${source.variant.weight}:${source.variant.style}`,
243 source.variant,
244 );
245 }
246 continue;
247 }
248
249 const italic = source.inspection.axes.find(
250 (axis) => axis.tag.toLowerCase() === 'ital',
251 );
252 const styles: Array<'normal' | 'italic'> =
253 italic && italic.min <= 0 && italic.max >= 1
254 ? ['italic', 'normal']
255 : [source.inspection.style === 'italic' ? 'italic' : 'normal'];
256 const weight = source.inspection.weight;
257 const weights =
258 typeof weight === 'number'
259 ? [weight]
260 : STATIC_WEIGHTS.filter(
261 (value) => value >= weight.min && value <= weight.max,
262 );
263 for (const value of weights) {
264 for (const style of styles) {
265 staticVariants.set(`${value}:${style}`, { weight: value, style });
266 }
267 }
268
269 const axes: VariableAxisConfig = Object.fromEntries(
270 source.inspection.axes.map((axis) => [
271 axis.tag,
272 { min: axis.min, max: axis.max, default: axis.default },
273 ]),
274 );
275 for (const axisKey of getVariableAxisKeys(axes)) {
276 for (const style of styles) {
277 variableVariants.set(`${axisKey.toLowerCase()}:${style}`, {
278 axisKey,
279 style,
280 });
281 }
282 }

Callers 1

writeFamilyFunction · 0.85

Calls 4

getVariableAxisKeysFunction · 0.90
compareStringsFunction · 0.90
setMethod · 0.65
valuesMethod · 0.65

Tested by

no test coverage detected