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

Function generateV2CSS

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

Source from the content-addressed store, hash-verified

140};
141
142export const generateV2CSS = (
143 metadata: GenerateMetadataV2,
144 makeFontFilePath: (
145 id: string,
146 subset: string,
147 weight: string,
148 style: string,
149 extension: string,
150 ) => string,
151 tag?: string,
152): CSSGenerate => {
153 const cssGenerate: CSSGenerate = [];
154 const { id, family, styles, weights, variants, unicodeRange, subsets } =
155 metadata;
156
157 // Find the weight for index.css in the case weight 400 does not exist.
158 const indexWeight = findClosest(weights, 400);
159
160 // Generate CSS
161 const hasUnicode = Object.keys(unicodeRange).length > 0;
162 const unicodeKeys = hasUnicode ? Object.keys(unicodeRange) : subsets;
163
164 for (const weight of weights) {
165 for (const style of styles) {
166 const cssStyle: string[] = [];
167
168 for (const subset of unicodeKeys) {
169 // Some fonts may have variants 400, 400i, 700 but not 700i.
170 if (style in variants[weight]) {
171 const fontObj = {
172 family,
173 style,
174 display: 'swap',
175 weight,
176 unicodeRange: hasUnicode ? unicodeRange[subset] : undefined,
177 src: [
178 {
179 url: makeFontFilePath(
180 tag ?? id,
181 subset,
182 String(weight),
183 style,
184 'woff2',
185 ),
186 format: 'woff2' as const,
187 },
188 {
189 url: makeFontFilePath(
190 tag ?? id,
191 subset,
192 String(weight),
193 style,
194 'woff',
195 ),
196 format: 'woff' as const,
197 },
198 ],
199 comment: `${tag ?? id}-${subset}-${weight}-${style}`,

Callers 2

packagerV2Function · 0.90
updateCssFunction · 0.90

Calls 3

findClosestFunction · 0.90
generateFontFaceFunction · 0.90
makeFontFilePathFunction · 0.50

Tested by

no test coverage detected