@@ -3,6 +3,7 @@ import { Image } from '@/components/utils';
33import { type ResolvedContentRef , resolveContentRef } from '@/lib/references' ;
44import { tcls } from '@/lib/tailwind' ;
55import {
6+ type CardsImageObjectFit ,
67 type ContentRef ,
78 type DocumentTableViewCards ,
89 SiteInsightsLinkPosition ,
@@ -39,6 +40,14 @@ export async function RecordCard(
3940 const darkCoverIsSquareOrPortrait = isSquareOrPortrait ( darkCover ) ;
4041 const lightCoverIsSquareOrPortrait = isSquareOrPortrait ( lightCover ) ;
4142
43+ const darkObjectFit = dark . objectFit
44+ ? `dark:${ getObjectFitClass ( dark . objectFit as CardsImageObjectFit ) } `
45+ : '' ;
46+ const lightObjectFit = light . objectFit
47+ ? getObjectFitClass ( light . objectFit as CardsImageObjectFit )
48+ : '' ;
49+ const objectFits = `${ lightObjectFit } ${ darkObjectFit } ` ;
50+
4251 const body = (
4352 < div
4453 className = { tcls (
@@ -99,11 +108,6 @@ export async function RecordCard(
99108 'w-full' ,
100109 'h-full' ,
101110 'bg-tint-subtle' ,
102- getObjectFitClass ( light . objectFit ) ,
103- // Apply dark mode object-fit if different from light
104- dark . objectFit && dark . objectFit !== light . objectFit
105- ? `dark:${ getObjectFitClass ( dark . objectFit ) } `
106- : '' ,
107111 lightCoverIsSquareOrPortrait || darkCoverIsSquareOrPortrait
108112 ? [
109113 lightCoverIsSquareOrPortrait
@@ -113,7 +117,8 @@ export async function RecordCard(
113117 ? 'dark:min-[432px]:aspect-video dark:min-[432px]:h-auto'
114118 : '' ,
115119 ] . filter ( Boolean )
116- : [ 'h-auto' , 'aspect-video' ]
120+ : [ 'h-auto' , 'aspect-video' ] ,
121+ objectFits
117122 ) }
118123 priority = { isOffscreen ? 'lazy' : 'high' }
119124 preload
@@ -203,13 +208,15 @@ function isSquareOrPortrait(contentRef: ResolvedContentRef | null) {
203208/**
204209 * Get the CSS class for object-fit based on the objectFit value.
205210 */
206- function getObjectFitClass ( objectFit ?: string ) : string {
211+ function getObjectFitClass ( objectFit ?: CardsImageObjectFit ) : string {
207212 switch ( objectFit ) {
208213 case 'contain' :
209214 return 'object-contain' ;
210215 case 'fill' :
211216 return 'object-fill' ;
212- default :
217+ case 'cover' :
213218 return 'object-cover' ;
219+ default :
220+ throw new Error ( `Unsupported object fit: ${ objectFit } ` ) ;
214221 }
215222}
0 commit comments