( metadata: GenerateMetadataV1, makeFontFilePath: ( id: string, subset: string, weight: string, style: string, extension: string, ) => string, tag?: string, )
| 48 | >; |
| 49 | |
| 50 | export const generateV1CSS = ( |
| 51 | metadata: GenerateMetadataV1, |
| 52 | makeFontFilePath: ( |
| 53 | id: string, |
| 54 | subset: string, |
| 55 | weight: string, |
| 56 | style: string, |
| 57 | extension: string, |
| 58 | ) => string, |
| 59 | tag?: string, |
| 60 | ): CSSGenerate => { |
| 61 | const cssGenerate: CSSGenerate = []; |
| 62 | const { id, family, styles, weights, subsets, variants } = metadata; |
| 63 | |
| 64 | for (const subset of subsets) { |
| 65 | // Arrays of CSS blocks to be concatenated |
| 66 | const cssSubset: string[] = []; |
| 67 | const cssSubsetItalic: string[] = []; |
| 68 | |
| 69 | for (const weight of weights) { |
| 70 | for (const style of styles) { |
| 71 | // Some fonts may have variants 400, 400i, 700 but not 700i |
| 72 | if (style in variants[weight]) { |
| 73 | const fontObj = { |
| 74 | family, |
| 75 | style, |
| 76 | display: 'swap', |
| 77 | weight, |
| 78 | src: [ |
| 79 | { |
| 80 | url: makeFontFilePath( |
| 81 | tag ?? id, |
| 82 | subset, |
| 83 | String(weight), |
| 84 | style, |
| 85 | 'woff2', |
| 86 | ), |
| 87 | format: 'woff2' as const, |
| 88 | }, |
| 89 | { |
| 90 | url: makeFontFilePath( |
| 91 | tag ?? id, |
| 92 | subset, |
| 93 | String(weight), |
| 94 | style, |
| 95 | 'woff', |
| 96 | ), |
| 97 | format: 'woff' as const, |
| 98 | }, |
| 99 | ], |
| 100 | comment: `${tag ?? id}-${subset}-${weight}-${style}`, |
| 101 | }; |
| 102 | // This takes in a font object and returns an @font-face block |
| 103 | const css = generateFontFace(fontObj); |
| 104 | |
| 105 | // Needed to differentiate filenames |
| 106 | if (style === 'normal') { |
| 107 | cssGenerate.push({ |
no test coverage detected