@@ -7,7 +7,7 @@ type FontSpec = {
77 name : string ;
88 data : ArrayBuffer ;
99 weight : 400 | 600 | 700 | 800 ;
10- style : ' normal' ;
10+ style : " normal" ;
1111} ;
1212
1313// The css2 endpoint serves woff2 to modern UAs; spoofing an old UA makes it
@@ -18,31 +18,40 @@ export async function loadGoogleFont(
1818 text ?: string ,
1919) : Promise < ArrayBuffer > {
2020 const params = new URLSearchParams ( { family : `${ family } :wght@${ weight } ` } ) ;
21- if ( text ) params . set ( ' text' , text ) ;
21+ if ( text ) params . set ( " text" , text ) ;
2222 const cssUrl = `https://fonts.googleapis.com/css2?${ params . toString ( ) } ` ;
2323 const css = await fetch ( cssUrl , {
24- headers : { ' User-Agent' : ' Mozilla/5.0 (Windows NT 5.1)' } , // old UA → ttf
24+ headers : { " User-Agent" : " Mozilla/5.0 (Windows NT 5.1)" } , // old UA → ttf
2525 } ) . then ( ( r ) => r . text ( ) ) ;
26- const url = css . match ( / s r c : \s * u r l \( ( .+ ?) \) \s * f o r m a t \( ' (?: t r u e t y p e | o p e n t y p e ) ' \) / ) ?. [ 1 ] ;
26+ const url = css . match (
27+ / s r c : \s * u r l \( ( .+ ?) \) \s * f o r m a t \( ' (?: t r u e t y p e | o p e n t y p e ) ' \) / ,
28+ ) ?. [ 1 ] ;
2729 if ( ! url ) throw new Error ( `Could not resolve a TTF for ${ family } ${ weight } ` ) ;
2830 return fetch ( url ) . then ( ( r ) => r . arrayBuffer ( ) ) ;
2931}
3032
3133// Load everything Codú OG cards need. Pass it the text you're about to
3234// render to subset aggressively (smaller payloads); omit for full sets.
3335export async function coduFonts ( text ?: string ) : Promise < FontSpec [ ] > {
34- const [ bricolage , hanken400 , hanken600 , mono400 , mono600 ] = await Promise . all ( [
35- loadGoogleFont ( 'Bricolage Grotesque' , 800 , text ) ,
36- loadGoogleFont ( 'Hanken Grotesk' , 400 , text ) ,
37- loadGoogleFont ( 'Hanken Grotesk' , 600 , text ) ,
38- loadGoogleFont ( 'JetBrains Mono' , 400 , text ) ,
39- loadGoogleFont ( 'JetBrains Mono' , 600 , text ) ,
40- ] ) ;
36+ const [ bricolage , hanken400 , hanken600 , mono400 , mono600 ] = await Promise . all (
37+ [
38+ loadGoogleFont ( "Bricolage Grotesque" , 800 , text ) ,
39+ loadGoogleFont ( "Hanken Grotesk" , 400 , text ) ,
40+ loadGoogleFont ( "Hanken Grotesk" , 600 , text ) ,
41+ loadGoogleFont ( "JetBrains Mono" , 400 , text ) ,
42+ loadGoogleFont ( "JetBrains Mono" , 600 , text ) ,
43+ ] ,
44+ ) ;
4145 return [
42- { name : 'Bricolage Grotesque' , data : bricolage , weight : 800 , style : 'normal' } ,
43- { name : 'Hanken Grotesk' , data : hanken400 , weight : 400 , style : 'normal' } ,
44- { name : 'Hanken Grotesk' , data : hanken600 , weight : 600 , style : 'normal' } ,
45- { name : 'JetBrains Mono' , data : mono400 , weight : 400 , style : 'normal' } ,
46- { name : 'JetBrains Mono' , data : mono600 , weight : 600 , style : 'normal' } ,
46+ {
47+ name : "Bricolage Grotesque" ,
48+ data : bricolage ,
49+ weight : 800 ,
50+ style : "normal" ,
51+ } ,
52+ { name : "Hanken Grotesk" , data : hanken400 , weight : 400 , style : "normal" } ,
53+ { name : "Hanken Grotesk" , data : hanken600 , weight : 600 , style : "normal" } ,
54+ { name : "JetBrains Mono" , data : mono400 , weight : 400 , style : "normal" } ,
55+ { name : "JetBrains Mono" , data : mono600 , weight : 600 , style : "normal" } ,
4756 ] ;
4857}
0 commit comments