import { useState } from "react"; import { Button } from "~/ui/Button"; import { cn } from "~/utils/cn"; const MODES = ["side-by-side", "swipe"] as const; const IMAGE_PATH = /\.(png|jpe?g|gif|webp|avif|ico|bmp)$/i; const HALF = 50; export function isImagePath(path: string): boolean { return IMAGE_PATH.test(path); } /** Raw URL prefixes (`/owner/repo/raw/`) for the two sides of a diff. */ export type ImageSources = { base: string | null; head: string }; function Frame({ src, label, tone }: { src: string | null; label: string; tone: "danger" | "success" }) { return (
{label}
{src ? ( {label} ) : (
None
)}
); } function Swipe({ before, after }: { before: string; after: string }) { const [position, setPosition] = useState(HALF); return (
After
Before
); } export function ImageDiff({ path, before, after }: { path: string; before: string | null; after: string | null }) { const [mode, setMode] = useState<(typeof MODES)[number]>("side-by-side"); return (
{path} {before && after && (
{MODES.map((value) => ( ))}
)}
{before && after && mode === "swipe" ? ( ) : (
)}
); }