import { useEffect, useRef, useState } from "react" import { catColor } from "@/lib/category" import { DownloadButton } from "@/components/download-button" export function Section({ title, children, className = "" }: { title?: string; children: React.ReactNode; className?: string }) { return (
{title &&

{title}

} {children}
) } /** A card. With `download` (the file name) it gets a download button in its top right corner. */ export function Panel({ title, download, children }: { title?: string; download?: string; children: React.ReactNode }) { const ref = useRef(null) if (!download) return (
{title &&

{title}

} {children}
) return (
{title ? (

{title}

) : ( // level with the legend row; the legend leaves room for it )}
:first-child]:pr-12"}>{children}
) } /** Soft colour light behind the dark stage; `cats` picks the hues. */ export function Glow({ cats }: { cats: string[] }) { const spots = [ { left: "62%", top: "-18%", size: 620, o: 0.42 }, { left: "-12%", top: "8%", size: 520, o: 0.3 }, { left: "30%", top: "46%", size: 560, o: 0.22 }, { left: "84%", top: "52%", size: 420, o: 0.2 }, ] return (
{spots.map((s, i) => (
))}
) } /** A number that counts up once when it first appears. */ export function CountUp({ value, format, ms = 1600 }: { value: number; format: (n: number) => string; ms?: number }) { const [v, setV] = useState(0) const done = useRef(false) useEffect(() => { if (done.current || matchMedia("(prefers-reduced-motion: reduce)").matches) { setV(value) return } done.current = true let raf = 0 const t0 = performance.now() const tick = (t: number) => { const p = Math.min(1, (t - t0) / ms) setV(value * (1 - Math.pow(1 - p, 3))) if (p < 1) raf = requestAnimationFrame(tick) } raf = requestAnimationFrame(tick) return () => cancelAnimationFrame(raf) }, [value, ms]) return <>{format(v)} } /** Big value over its label, for the stat rows on the stage. */ export function Stat({ value, label }: { value: React.ReactNode; label: string }) { return (
{value}
{label}
) }