import { useEffect, useRef } from "react"; import type { RawImage } from "../imageConvert.ts"; import { drawRawToCanvas, rawToDataUrl } from "../imageLoad.ts"; interface Props { title: string; image: RawImage | null; placeholder?: string; /** When set, shows a download link for the image (PNG). */ downloadName?: string; overlay?: React.ReactNode; } export function ImageView({ title, image, placeholder, downloadName, overlay, }: Props) { const canvasRef = useRef(null); useEffect(() => { if (image && canvasRef.current) { drawRawToCanvas(canvasRef.current, image); } }, [image]); return (
{title} {image && ( {image.width} × {image.height} {downloadName && ( <> {" · "} download )} )}
{image ? ( ) : (
{placeholder ?? "—"}
)} {overlay}
); }