"use client"; import { useState } from "react"; import { cn } from "@/lib/utils"; import type { BackgroundType } from "@/types/editor"; interface ImageTimelineTreatmentProps { src: string; alt: string; targetAspectRatio?: number; // Default to 16:9 for video className?: string; backgroundType?: BackgroundType; backgroundColor?: string; } export function ImageTimelineTreatment({ src, alt, targetAspectRatio = 16 / 9, className, backgroundType = "blur", backgroundColor = "#000000", }: ImageTimelineTreatmentProps) { const [imageLoaded, setImageLoaded] = useState(false); const [imageDimensions, setImageDimensions] = useState<{ width: number; height: number; } | null>(null); const handleImageLoad = (e: React.SyntheticEvent) => { const img = e.currentTarget; setImageDimensions({ width: img.naturalWidth, height: img.naturalHeight, }); setImageLoaded(true); }; const imageAspectRatio = imageDimensions ? imageDimensions.width / imageDimensions.height : 1; const needsAspectRatioTreatment = imageAspectRatio !== targetAspectRatio; return (
{/* Background Layer */} {needsAspectRatioTreatment && imageLoaded && ( <> {backgroundType === "blur" && (
)} {backgroundType === "mirror" && (
)} {backgroundType === "color" && (
)} )} {/* Main Image Layer */}
{alt}
{/* Loading state */} {!imageLoaded && (
Loading...
)}
); }