From 6ee16f9df8aeabfef0ca533f9f5b13daab3a3758 Mon Sep 17 00:00:00 2001 From: Maze Winther Date: Sun, 22 Jun 2025 19:28:03 +0200 Subject: feat: so much stuff --- .../src/components/ui/image-timeline-treatment.tsx | 101 +++++++++++++++++++++ 1 file changed, 101 insertions(+) create mode 100644 apps/web/src/components/ui/image-timeline-treatment.tsx (limited to 'apps/web/src/components/ui') diff --git a/apps/web/src/components/ui/image-timeline-treatment.tsx b/apps/web/src/components/ui/image-timeline-treatment.tsx new file mode 100644 index 00000000..600dd243 --- /dev/null +++ b/apps/web/src/components/ui/image-timeline-treatment.tsx @@ -0,0 +1,101 @@ +"use client"; + +import { useState } from "react"; +import { cn } from "@/lib/utils"; + +interface ImageTimelineTreatmentProps { + src: string; + alt: string; + targetAspectRatio?: number; // Default to 16:9 for video + className?: string; + backgroundType?: "blur" | "mirror" | "color"; + 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... +
+
+ )} +
+ ); +} -- cgit v1.3.1