MCPcopy Create free account
hub / github.com/fontsource/fontsource / getFontPreviewCSS

Function getFontPreviewCSS

website/app/utils/font-preview.ts:129–158  ·  view source on GitHub ↗
(
	metadata: Omit<GetFontResponse, 'variants'>,
	variable?: GetVariableFontResponse,
)

Source from the content-addressed store, hash-verified

127 return [`"${family}"`, ...quotedFallbacks].join(', ');
128};
129export const getFontPreviewCSS = (
130 metadata: Omit<GetFontResponse, 'variants'>,
131 variable?: GetVariableFontResponse,
132) => {
133 const unicodeRange = Object.fromEntries(
134 Object.entries(metadata.unicodeRange).map(([key, range]) => [
135 key.replace('[', '').replace(']', ''),
136 range,
137 ]),
138 );
139 const unicodeKeys = Object.keys(unicodeRange);
140 const subsets = unicodeKeys.length > 0 ? unicodeKeys : metadata.subsets;
141 const faces = resolveFontFaces(
142 {
143 id: metadata.id,
144 family: metadata.family,
145 subsets,
146 weights: metadata.weights,
147 styles: metadata.styles,
148 unicodeRange,
149 variable: variable?.axes,
150 },
151 variable
152 ? [selectVariableAxisKey(variable.axes, Object.keys(variable.axes))]
153 : undefined,
154 );
155 return generateCSS(metadata.family, faces, {
156 resolver: jsDelivrResolver(metadata.id, !!variable),
157 });
158};

Callers 4

loaderFunction · 0.90
loaderFunction · 0.90
loaderFunction · 0.90

Calls 5

generateCSSFunction · 0.90
jsDelivrResolverFunction · 0.90
resolveFontFacesFunction · 0.85
selectVariableAxisKeyFunction · 0.85
replaceMethod · 0.65

Tested by

no test coverage detected