( metadata: GenerateIconStatic, makeFontFilePath: ( id: string, subset: string, weight: string, style: string, extension: string, ) => string, tag?: string, )
| 319 | }; |
| 320 | |
| 321 | export 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 |
no test coverage detected