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

Function generateIconStaticCSS

packages/cli/src/google/css.ts:321–422  ·  view source on GitHub ↗
(
	metadata: GenerateIconStatic,
	makeFontFilePath: (
		id: string,
		subset: string,
		weight: string,
		style: string,
		extension: string,
	) => string,
	tag?: string,
)

Source from the content-addressed store, hash-verified

319};
320
321export const generateIconStaticCSS = (
322 metadata: GenerateIconStatic,
323 makeFontFilePath: (
324 id: string,
325 subset: string,
326 weight: string,
327 style: string,
328 extension: string,
329 ) => string,
330 tag?: string,
331): CSSGenerate => {
332 const cssGenerate: CSSGenerate = [];
333 const { id, family, styles, weights, subsets, variants } = metadata;
334
335 // Find the weight for index.css in the case weight 400 does not exist.
336 const indexWeight = findClosest(weights, 400);
337
338 // Generate CSS
339 for (const subset of subsets) {
340 // Arrays of CSS blocks to be concatenated
341 const cssSubset: string[] = [];
342
343 for (const weight of weights) {
344 for (const style of styles) {
345 // Some fonts may have variants 400, 400i, 700 but not 700i
346 if (style in variants[weight]) {
347 const fontObj = {
348 family,
349 style,
350 display: 'swap',
351 weight,
352 src: [
353 {
354 url: makeFontFilePath(
355 tag ?? id,
356 subset,
357 String(weight),
358 style,
359 'woff2',
360 ),
361 format: 'woff2' as const,
362 },
363 {
364 url: makeFontFilePath(
365 tag ?? id,
366 subset,
367 String(weight),
368 style,
369 'woff',
370 ),
371 format: 'woff' as const,
372 },
373 ],
374 comment: `${tag ?? id}-${subset}-${weight}-${style}`,
375 };
376 // This takes in a font object and returns an @font-face block
377 const css = generateFontFace(fontObj);
378

Callers 2

packagerIconsStaticFunction · 0.90
updateCssFunction · 0.90

Calls 3

findClosestFunction · 0.90
generateFontFaceFunction · 0.90
makeFontFilePathFunction · 0.50

Tested by

no test coverage detected