@@ -16,11 +16,12 @@ import {
1616import { ProjectContext } from "../../project/types.ts" ;
1717import {
1818 BrandFont ,
19- BrandFontBunny ,
19+ // BrandFontBunny,
2020 BrandFontCommon ,
2121 BrandFontGoogle ,
2222 BrandFontWeight ,
23- } from "../../resources/types/schema-types.ts" ;
23+ Zod ,
24+ } from "../../resources/types/zod/schema-types.ts" ;
2425import { Brand } from "../brand/brand.ts" ;
2526import { darkModeDefault } from "../../format/html/format-html-info.ts" ;
2627
@@ -323,10 +324,11 @@ const brandTypographyLayer = (
323324 ) : string | undefined => {
324325 let googleFamily = "" ;
325326 for ( const _resolvedFont of font ) {
326- const resolvedFont = _resolvedFont as ( BrandFontGoogle | BrandFontBunny ) ;
327- if ( resolvedFont . source !== "google" ) {
327+ const safeResolvedFont = Zod . BrandFontGoogle . safeParse ( _resolvedFont ) ;
328+ if ( ! safeResolvedFont . success ) {
328329 return undefined ;
329330 }
331+ const resolvedFont = safeResolvedFont . data ;
330332 const thisFamily = resolvedFont . family ;
331333 if ( ! thisFamily ) {
332334 continue ;
@@ -351,17 +353,15 @@ const brandTypographyLayer = (
351353 ) : string | undefined => {
352354 let googleFamily = "" ;
353355 for ( const _resolvedFont of font ) {
354- const resolvedFont =
355- _resolvedFont as ( BrandFont | BrandFontGoogle | BrandFontBunny ) ;
356+ const safeResolvedFont = Zod . BrandFontBunny . safeParse ( _resolvedFont ) ;
357+ if ( ! safeResolvedFont . success ) {
358+ return undefined ;
359+ }
360+ const resolvedFont = safeResolvedFont . data ;
356361 // Typescript's type checker doesn't understand that it's ok to attempt
357362 // to access a property that might not exist on a type when you're
358363 // only testing for its existence.
359364
360- // deno-lint-ignore no-explicit-any
361- const source = ( resolvedFont as any ) . source ;
362- if ( source && source !== "bunny" ) {
363- return undefined ;
364- }
365365 const thisFamily = resolvedFont . family ;
366366 if ( ! thisFamily ) {
367367 continue ;
@@ -384,6 +384,7 @@ const brandTypographyLayer = (
384384 type HTMLFontInformation = { [ key : string ] : unknown } ;
385385
386386 type FontKind =
387+ | "link"
387388 | "base"
388389 | "headings"
389390 | "monospace"
@@ -398,9 +399,14 @@ const brandTypographyLayer = (
398399 } else if ( typeof resolvedFontOptions === "string" ) {
399400 resolvedFontOptions = { family : resolvedFontOptions } ;
400401 }
401- const family = resolvedFontOptions . family ;
402- const font = getFontFamilies ( family ) ;
403402 const result : HTMLFontInformation = { } ;
403+ // This is an ugly hack:
404+ // resolvedFontOptions doesn't always have 'family', but at this
405+ // point in the code we know resolvedFontOptions is an object
406+ // that we can attempt to extract the family from.
407+ const family =
408+ ( resolvedFontOptions as Record < string , string | undefined > ) . family ;
409+ const font = getFontFamilies ( family ) ;
404410 result . family = resolveGoogleFontFamily ( font ) ??
405411 resolveBunnyFontFamily ( font ) ??
406412 // resolveFilesFontFamily(font) ??
@@ -524,11 +530,9 @@ const brandTypographyLayer = (
524530 "monospace" ,
525531 "headings" ,
526532 "base" ,
527- ]
533+ ] as const
528534 ) {
529- const fontInformation = resolveHTMLFontInformation (
530- kind as FontKind ,
531- ) ;
535+ const fontInformation = resolveHTMLFontInformation ( kind ) ;
532536 if ( ! fontInformation ) {
533537 continue ;
534538 }
0 commit comments