fix: preserve result thumbnail aspect ratios

This commit is contained in:
2026-05-19 20:35:16 +08:00
parent ece4db338e
commit 6c3f5eda0a
2 changed files with 23 additions and 5 deletions

View File

@@ -11,7 +11,9 @@ type PreviewState = {
function parseRatio(aspectRatio?: string) {
if (!aspectRatio || aspectRatio === 'long') return aspectRatio === 'long' ? 1 / 3 : 1;
const [w, h] = aspectRatio.split(':').map(Number);
const [w, h] = aspectRatio.includes('/')
? aspectRatio.split('/').map(part => Number(part.trim()))
: aspectRatio.split(':').map(Number);
return w && h ? w / h : 1;
}
@@ -42,11 +44,13 @@ export function HoverImagePreview({
alt,
imageClassName,
aspectRatio,
onImageLoad,
}: {
src: string;
alt: string;
imageClassName?: string;
aspectRatio?: string;
onImageLoad?: (image: HTMLImageElement) => void;
}) {
const [preview, setPreview] = useState<PreviewState | null>(null);
@@ -61,6 +65,7 @@ export function HoverImagePreview({
setPreview(nextPreviewState(event, aspectRatio));
}}
onPointerLeave={() => setPreview(null)}
onLoad={event => onImageLoad?.(event.currentTarget)}
/>
{preview && (
<div