diff --git a/src/components/DocumentView/InlineImage.tsx b/src/components/DocumentView/InlineImage.tsx index 24cafc897..919028da6 100644 --- a/src/components/DocumentView/InlineImage.tsx +++ b/src/components/DocumentView/InlineImage.tsx @@ -3,6 +3,7 @@ import assertNever from 'assert-never'; import { getImageSize } from '@/lib/images'; import { ResolvedContentRef } from '@/lib/references'; +import { tcls } from '@/lib/tailwind'; import { InlineProps } from './Inline'; import { Image } from '../utils'; @@ -21,41 +22,45 @@ export async function InlineImage(props: InlineProps) { } return ( - {inline.data.caption + /* Ensure images dont expand to the size of the container where this Image may be nested in. Now it's always nested in a size-restricted container */ + + {inline.data.caption + ); } async function getImageSizes(size: 'original' | 'line', src: ResolvedContentRef) { switch (size) { case 'line': { - // We estimate that the maximum height of the line will be 40px - // and from the aspect-ratio, we can deduce the width - const lineHeight = 40; const imageSize = src.fileDimensions ?? (await getImageSize(src.href, { dpr: 3, })); + // We estimate that the maximum height of the line will be 40px + // and from the aspect-ratio, we can deduce the width + const lineHeight = 40; + const aspectRatio = imageSize ? imageSize.width / imageSize.height : 1; return [ @@ -68,6 +73,7 @@ async function getImageSizes(size: 'original' | 'line', src: ResolvedContentRef) // The max-width is 300px return [ { + // if we know the image size and it is smaller than 300px use its width width: 300, }, ];