@@ -15,7 +15,6 @@ import {
1515} from "../../config/types.ts" ;
1616import { ProjectContext } from "../../project/types.ts" ;
1717import {
18- BrandFont ,
1918 // BrandFontBunny,
2019 BrandFontCommon ,
2120 BrandFontFile ,
@@ -338,104 +337,6 @@ const brandTypographyLayer = (
338337 const typographyImports : Set < string > = new Set ( ) ;
339338 const fonts = brand . data ?. typography ?. fonts ?? [ ] ;
340339
341- const getFontFamilies = ( family : string | undefined ) => {
342- return fonts . filter ( ( font ) =>
343- typeof font !== "string" && font . family === family
344- ) ;
345- } ;
346-
347- const resolveGoogleFontFamily = (
348- font : BrandFont [ ] ,
349- ) : string | undefined => {
350- let googleFamily = "" ;
351- for ( const _resolvedFont of font ) {
352- const safeResolvedFont = Zod . BrandFontGoogle . safeParse ( _resolvedFont ) ;
353- if ( ! safeResolvedFont . success ) {
354- return undefined ;
355- }
356- const resolvedFont = safeResolvedFont . data ;
357- const thisFamily = resolvedFont . family ;
358- if ( ! thisFamily ) {
359- continue ;
360- }
361- if ( googleFamily === "" ) {
362- googleFamily = thisFamily ;
363- } else if ( googleFamily !== thisFamily ) {
364- throw new Error (
365- `Inconsistent Google font families found: ${ googleFamily } and ${ thisFamily } ` ,
366- ) ;
367- }
368- typographyImports . add ( googleFontImportString ( resolvedFont ) ) ;
369- }
370- if ( googleFamily === "" ) {
371- return undefined ;
372- }
373- return googleFamily ;
374- } ;
375-
376- const resolveBunnyFontFamily = (
377- font : BrandFont [ ] ,
378- ) : string | undefined => {
379- let bunnyFamily = "" ;
380- for ( const _resolvedFont of font ) {
381- const safeResolvedFont = Zod . BrandFontBunny . safeParse ( _resolvedFont ) ;
382- if ( ! safeResolvedFont . success ) {
383- return undefined ;
384- }
385- const resolvedFont = safeResolvedFont . data ;
386- // Typescript's type checker doesn't understand that it's ok to attempt
387- // to access a property that might not exist on a type when you're
388- // only testing for its existence.
389-
390- const thisFamily = resolvedFont . family ;
391- if ( ! thisFamily ) {
392- continue ;
393- }
394- if ( bunnyFamily === "" ) {
395- bunnyFamily = thisFamily ;
396- } else if ( bunnyFamily !== thisFamily ) {
397- throw new Error (
398- `Inconsistent Bunny font families found: ${ bunnyFamily } and ${ thisFamily } ` ,
399- ) ;
400- }
401- typographyImports . add ( bunnyFontImportString ( resolvedFont ) ) ;
402- }
403- if ( bunnyFamily === "" ) {
404- return undefined ;
405- }
406- return bunnyFamily ;
407- } ;
408-
409- const resolveFileFontFamily = (
410- brand : Brand ,
411- font : BrandFont [ ] ,
412- ) : string | undefined => {
413- let fileFamily = "" ;
414- for ( const _resolvedFont of font ) {
415- const safeResolvedFont = Zod . BrandFontFile . safeParse ( _resolvedFont ) ;
416- if ( ! safeResolvedFont . success ) {
417- return undefined ;
418- }
419- const resolvedFont = safeResolvedFont . data ;
420- const thisFamily = resolvedFont . family ;
421- if ( ! thisFamily ) {
422- continue ;
423- }
424- if ( fileFamily === "" ) {
425- fileFamily = thisFamily ;
426- } else if ( fileFamily !== thisFamily ) {
427- throw new Error (
428- `Inconsistent Files font families found: ${ fileFamily } and ${ thisFamily } ` ,
429- ) ;
430- }
431- typographyImports . add ( fileFontImportString ( brand , resolvedFont ) ) ;
432- }
433- if ( fileFamily === "" ) {
434- return undefined ;
435- }
436- return fileFamily ;
437- } ;
438-
439340 type HTMLFontInformation = { [ key : string ] : unknown } ;
440341
441342 type FontKind =
@@ -461,11 +362,7 @@ const brandTypographyLayer = (
461362 // that we can attempt to extract the family from.
462363 const family =
463364 ( resolvedFontOptions as Record < string , string | undefined > ) . family ;
464- const font = getFontFamilies ( family ) ;
465- result . family = resolveGoogleFontFamily ( font ) ??
466- resolveBunnyFontFamily ( font ) ??
467- resolveFileFontFamily ( brand , font ) ??
468- family ;
365+ result . family = family ;
469366 for (
470367 const entry of [
471368 "line-height" ,
@@ -576,6 +473,50 @@ const brandTypographyLayer = (
576473 ] ,
577474 } ;
578475
476+ for ( const font of fonts ) {
477+ switch ( font . source ) {
478+ case "google" : {
479+ const safeResolvedFont = Zod . BrandFontGoogle . safeParse ( font ) ;
480+ if ( ! safeResolvedFont . success ) {
481+ continue ;
482+ }
483+ const resolvedFont = safeResolvedFont . data ;
484+ const thisFamily = resolvedFont . family ;
485+ if ( ! thisFamily ) {
486+ continue ;
487+ }
488+ typographyImports . add ( googleFontImportString ( resolvedFont ) ) ;
489+ break ;
490+ }
491+ case "bunny" : {
492+ const safeResolvedFont = Zod . BrandFontBunny . safeParse ( font ) ;
493+ if ( ! safeResolvedFont . success ) {
494+ continue ;
495+ }
496+ const resolvedFont = safeResolvedFont . data ;
497+ const thisFamily = resolvedFont . family ;
498+ if ( ! thisFamily ) {
499+ continue ;
500+ }
501+ typographyImports . add ( bunnyFontImportString ( resolvedFont ) ) ;
502+ break ;
503+ }
504+ case "file" : {
505+ const safeResolvedFont = Zod . BrandFontFile . safeParse ( font ) ;
506+ if ( ! safeResolvedFont . success ) {
507+ continue ;
508+ }
509+ const resolvedFont = safeResolvedFont . data ;
510+ const thisFamily = resolvedFont . family ;
511+ if ( ! thisFamily ) {
512+ continue ;
513+ }
514+ typographyImports . add ( fileFontImportString ( brand , resolvedFont ) ) ;
515+ break ;
516+ }
517+ }
518+ }
519+
579520 for (
580521 const kind of [
581522 // more specific entries go first
0 commit comments