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

Function generateIconVariableCSS

packages/cli/src/google/css.ts:424–503  ·  view source on GitHub ↗
(
	metadata: GenerateIconVariable,
	makeFontFilePath: (
		id: string,
		subset: string,
		axesLower: string,
		style: string,
	) => string,
	tag?: string,
)

Source from the content-addressed store, hash-verified

422};
423
424export const generateIconVariableCSS = (
425 metadata: GenerateIconVariable,
426 makeFontFilePath: (
427 id: string,
428 subset: string,
429 axesLower: string,
430 style: string,
431 ) => string,
432 tag?: string,
433): CSSGenerate => {
434 const cssGenerate: CSSGenerate = [];
435 const { id, family, variants, axes } = metadata;
436
437 // Generate CSS
438 let indexCSS = '';
439
440 for (const axesKey of Object.keys(variants)) {
441 const variant = variants[axesKey];
442 const styles = Object.keys(variant);
443 const axesLower = axesKey.toLowerCase();
444
445 // These are variable modifiers to change specific CSS selectors
446 // for variable fonts.
447 const variableOpts: APIIconResponse['axes'] = {
448 wght: axes.wght,
449 };
450 if (axesKey === 'standard' || axesKey === 'full' || axesKey === 'wdth')
451 variableOpts.stretch = axes.wdth;
452
453 if (axesKey === 'standard' || axesKey === 'full' || axesKey === 'slnt')
454 variableOpts.slnt = axes.slnt;
455
456 // Generate variable CSS
457 for (const style of styles) {
458 const cssStyle: string[] = [];
459
460 for (const subset of Object.keys(variant[style])) {
461 const fontObj: FontObject = {
462 family: `${family} Variable`,
463 style,
464 display: 'swap',
465 weight: Number(axes.wght.default),
466 variable: variableOpts,
467 src: [
468 {
469 url: makeFontFilePath(tag ?? id, subset, axesLower, style),
470 format: 'woff2-variations',
471 },
472 ],
473 comment: `${tag ?? id}-${subset}-${axesLower}-${style}`,
474 };
475
476 // This takes in a font object and returns an @font-face block
477 const css = generateFontFace(fontObj);
478 cssStyle.push(css);
479 }
480
481 // Write down CSS

Callers 2

packagerIconsVariableFunction · 0.90
updateVariableCSSFunction · 0.90

Calls 2

generateFontFaceFunction · 0.90
makeFontFilePathFunction · 0.50

Tested by

no test coverage detected