Merge pull request #241 from wrigglebug/embeddeningpt1

The embeddening part 1
This commit is contained in:
7w1 authored and GitHub committed 2026-03-08 13:19:09 -05:00
commit 7e7a56731a
6 files changed
+83 -65

No files matched your search

+5
View File
@@ -0,0 +1,5 @@
---
sable: patch
---
Adjust media sizing and URL preview layout
+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,70 @@ 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'] &&
(() => {
const ogW = prev['og:image:width'];
const ogH = prev['og:image:height'];
const aspectRatio = ogW && ogH ? `${ogW} / ${ogH}` : undefined;
return (
<Box
style={{
width: '100%',
maxHeight: '400px',
aspectRatio: aspectRatio ?? '16 / 9',
flexShrink: 0,
overflow: 'hidden',
position: 'relative',
}}
>
<ImageContent
style={{ width: '100%', height: '100%', position: 'absolute', inset: 0 }}
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 +206,7 @@ export const UrlPreviewCard = as<'div', { url: string; ts: number; mediaType?: s
maxWidth: '100%',
margin: 0,
}
: {
width: '600px',
}
: undefined
}
>
{previewContent}