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

Function Static

website/app/components/preview/CDN.tsx:162–291  ·  view source on GitHub ↗
({ metadata }: CDNProps)

Source from the content-addressed store, hash-verified

160};
161
162const Static = ({ metadata }: CDNProps) => {
163 // Active weights
164 const [isActiveWeight, setActiveWeight] = useState<Record<string, boolean>>({
165 400: true,
166 });
167 const handleActiveWeight = (value: string | number) => {
168 setActiveWeight((prev) => toggleKeyKeepOne(prev, value));
169 };
170
171 // Active italics
172 const [isItal, setIsItal] = useState(false);
173
174 // Displays
175 const [displayCurrent, setDisplay] = useState('swap');
176 const handleDisplay = (value: string) => {
177 setDisplay(value);
178 };
179
180 // Active subsets
181 const [subsets, setSubsets] = useState<string[]>([metadata.defSubset]);
182 const handleActiveSubset = (value: string) => {
183 if (subsets.length === 1 && subsets.includes(value)) return;
184
185 setSubsets((prev) => {
186 if (prev.includes(value)) {
187 return prev.filter((subset) => subset !== value);
188 }
189
190 return [...prev, value];
191 });
192 };
193
194 // Choose formats
195 const FORMATS = ['woff2', 'woff', 'ttf'] as const;
196 const [formats, setFormat] = useState<(typeof FORMATS)[number][]>([
197 'woff2',
198 'woff',
199 ]);
200 const handleFormat = (value: string) => {
201 if (!FORMATS.includes(value as (typeof FORMATS)[number])) return;
202 const selectedFormat = value as (typeof FORMATS)[number];
203
204 if (formats.length === 1 && formats.includes(selectedFormat)) return;
205
206 setFormat((prev) => {
207 if (prev.includes(selectedFormat)) {
208 return prev.filter((item) => item !== selectedFormat);
209 }
210
211 return [...prev, selectedFormat];
212 });
213 };
214
215 const css = buildStaticPreviewCSS(metadata, {
216 subsets,
217 weights: Object.keys(isActiveWeight).map((weight) => Number(weight)),
218 style: isItal ? 'italic' : 'normal',
219 formats,

Callers

nothing calls this directly

Calls 3

buildStaticPreviewCSSFunction · 0.90
jsDelivrResolverFunction · 0.90
handleActiveWeightFunction · 0.70

Tested by

no test coverage detected