"use client"; import { useState, useRef } from "react"; import { ZoomIn, ZoomOut, Maximize2, Image as ImageIcon } from "lucide-react"; import { cn } from "@/lib/utils"; interface ImageViewerProps { src: string; path: string; } export function ImageViewer({ src, path }: ImageViewerProps) { const [zoom, setZoom] = useState(1); const [fitMode, setFitMode] = useState<"fit" | "actual">("fit"); const [error, setError] = useState(false); const containerRef = useRef(null); const handleZoomIn = () => setZoom((z) => Math.min(z * 1.25, 8)); const handleZoomOut = () => setZoom((z) => Math.max(z / 1.25, 0.1)); const handleFitToggle = () => { setFitMode((m) => (m === "fit" ? "actual" : "fit")); setZoom(1); }; const isSvg = path.endsWith(".svg"); const hasTransparency = path.endsWith(".png") || path.endsWith(".gif") || path.endsWith(".webp") || path.endsWith(".svg"); if (error) { return (

Failed to load image

{path}

); } return (
{/* Toolbar */}
{Math.round(zoom * 100)}%
{/* Image container */}
{/* eslint-disable-next-line @next/next/no-img-element */} {path.split("/").pop()} setError(true)} style={{ transform: `scale(${zoom})`, transformOrigin: "center center", maxWidth: fitMode === "fit" ? "100%" : "none", maxHeight: fitMode === "fit" ? "100%" : "none", imageRendering: zoom > 2 ? "pixelated" : "auto", }} className="transition-transform duration-150 shadow-lg" draggable={false} />
); }