Adjust media sizing and URL preview layout

This commit is contained in:
wrigglebug committed 2026-03-08 03:47:13 -07:00
1 parent 2dd707b526
commit 14bcc4454c
5 files changed
+62 -65

No files matched your search

+1 -1
View File
@@ -4,7 +4,7 @@ import { DefaultReset } from 'folds';
export const Image = style([
DefaultReset,
{
objectFit: 'cover',
objectFit: 'contain',
width: '100%',
height: '100%',
},
@@ -250,19 +250,26 @@ export function MImage({ content, renderImageContent, outlined }: MImageProps) {
if (typeof mxcUrl !== 'string') {
return <BrokenContent />;
}
const height = scaleYDimension(imgInfo?.w || 400, 400, imgInfo?.h || 400);
const MAX_SIZE = 400;
const imgW = imgInfo?.w ?? MAX_SIZE;
const imgH = imgInfo?.h ?? MAX_SIZE;
const aspectRatio = imgInfo?.w && imgInfo?.h ? `${imgW} / ${imgH}` : undefined;
// this garbage is for portrait images, we cap the width so the card doesn't exceed the bounds of the image
const displayWidth = imgH > imgW ? Math.round(MAX_SIZE * (imgW / imgH)) : MAX_SIZE;
return (
<Attachment
style={{
flexGrow: 1,
flexShrink: 0,
width: toRem(displayWidth),
}}
outlined={outlined}
>
<AttachmentBox
style={{
height: toRem(height < 48 ? 48 : height),
aspectRatio,
maxHeight: toRem(MAX_SIZE),
}}
>
{renderImageContent({
@@ -306,7 +313,7 @@ export function MVideo({ content, renderAsFile, renderVideoContent, outlined }:
return <BrokenContent />;
}
const height = scaleYDimension(videoInfo.w || 400, 400, videoInfo.h || 400);
const height = Math.min(scaleYDimension(videoInfo.w || 400, 400, videoInfo.h || 400), 400);
const filename = content.filename ?? content.body ?? 'Video';
@@ -23,7 +23,7 @@ export const Attachment = recipe({
export type AttachmentVariants = RecipeVariants<typeof Attachment>;
export const AttachmentHeader = style({
padding: config.space.S300,
padding: config.space.S100,
});
export const AttachmentBox = style([
@@ -5,7 +5,6 @@ export const UrlPreview = style([
DefaultReset,
{
width: toRem(400),
minHeight: toRem(102),
backgroundColor: color.SurfaceVariant.Container,
color: color.SurfaceVariant.OnContainer,
border: `${config.borderWidth.B300} solid ${color.SurfaceVariant.ContainerLine}`,
@@ -54,69 +54,14 @@ export const UrlPreviewCard = as<'div', { url: string; ts: number; mediaType?: s
return (
<Box
grow="Yes"
direction={prev['og:video'] ? 'ColumnReverse' : 'Row'}
direction="Column"
style={{
display: 'flex',
alignItems: 'center',
overflow: 'hidden',
width: '100%',
}}
>
{(prev['og:video'] && (
<VideoContent
style={{
aspectRatio:
((prev['og:video:width'] as number) ?? 1) /
((prev['og:video:height'] as number) ?? 1),
}}
body={prev['og:title']}
info={{}}
url={prev['og:video'] as string}
mimeType={(prev['og:video:type'] as string) ?? ''}
renderVideo={(vidProps) => <Video style={{ objectFit: 'contain' }} {...vidProps} />}
renderThumbnail={() => <Image src={imgUrl ?? undefined} />}
/>
)) ||
(prev['og:image'] && (
<Box style={{ flexShrink: 0, height: '100px' }}>
{' '}
<ImageContent
style={{
height: '100%',
aspectRatio: (prev['og:image:width'] ?? 1) / (prev['og:image:height'] ?? 1),
position: 'relative',
width: 'auto',
}}
autoPlay
body={prev['og:title']}
url={prev['og:image']}
renderViewer={(p) => <ImageViewer {...p} />}
renderImage={(p) => (
<Image
{...p}
style={{
height: '100%',
width: 'auto',
objectFit: 'contain',
}}
/>
)}
/>
</Box>
)) ||
(prev['og:audio'] && (
<Box className={css.UrlPreviewAudio} style={{ flexShrink: 0 }}>
<AudioContent
url={(prev['og:audio'] as string) ?? ''}
mimeType={(prev['og:audio:type'] as string) ?? ''}
info={{}}
renderMediaControl={(p) => <MediaControl {...p} />}
/>
</Box>
))}
<UrlPreviewContent
style={{
flex: 1,
minWidth: 0,
display: 'flex',
flexDirection: 'column',
@@ -147,6 +92,54 @@ export const UrlPreviewCard = as<'div', { url: string; ts: number; mediaType?: s
</Text>
)}
</UrlPreviewContent>
{prev['og:video'] && (
<VideoContent
style={{
width: '100%',
aspectRatio:
((prev['og:video:width'] as number) ?? 1) /
((prev['og:video:height'] as number) ?? 1),
}}
body={prev['og:title']}
info={{}}
url={prev['og:video'] as string}
mimeType={(prev['og:video:type'] as string) ?? ''}
renderVideo={(vidProps) => <Video style={{ objectFit: 'contain' }} {...vidProps} />}
renderThumbnail={() => <Image src={imgUrl ?? undefined} />}
/>
)}
{!prev['og:video'] && prev['og:image'] && (
<Box style={{ width: '100%', height: '220px', flexShrink: 0, overflow: 'hidden' }}>
<ImageContent
style={{ width: '100%', height: '100%', position: 'relative' }}
autoPlay
body={prev['og:title']}
url={prev['og:image']}
renderViewer={(p) => <ImageViewer {...p} />}
renderImage={(p) => (
<Image
{...p}
style={{
width: '100%',
height: '100%',
objectFit: 'contain',
objectPosition: 'center',
}}
/>
)}
/>
</Box>
)}
{!prev['og:video'] && !prev['og:image'] && prev['og:audio'] && (
<Box className={css.UrlPreviewAudio} style={{ flexShrink: 0 }}>
<AudioContent
url={(prev['og:audio'] as string) ?? ''}
mimeType={(prev['og:audio:type'] as string) ?? ''}
info={{}}
renderMediaControl={(p) => <MediaControl {...p} />}
/>
</Box>
)}
</Box>
);
};
@@ -197,9 +190,7 @@ export const UrlPreviewCard = as<'div', { url: string; ts: number; mediaType?: s
maxWidth: '100%',
margin: 0,
}
: {
width: '600px',
}
: undefined
}
>
{previewContent}