File size: 3,797 Bytes
2471af3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
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 (
    <section className={`mt-24 ${className}`}>
      {title && <h2 className="mb-8 font-display text-[30px] leading-tight font-semibold tracking-[-0.01em] sm:text-[34px]">{title}</h2>}
      {children}
    </section>
  )
}

/** 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<HTMLDivElement>(null)
  if (!download)
    return (
      <div className="min-w-0 rounded-[20px] border border-border bg-card p-5 sm:p-8">
        {title && <h3 className="mb-6 text-lg font-medium">{title}</h3>}
        {children}
      </div>
    )
  return (
    <div ref={ref} className="relative min-w-0 rounded-[20px] border border-border bg-card p-5 sm:p-8">
      {title ? (
        <div className="mb-6 flex items-center justify-between gap-4">
          <h3 className="text-lg font-medium">{title}</h3>
          <DownloadButton target={ref} name={download} />
        </div>
      ) : (
        // level with the legend row; the legend leaves room for it
        <DownloadButton target={ref} name={download} className="absolute top-3.5 right-5 sm:top-[26px] sm:right-8" />
      )}
      <div className={title ? undefined : "[&>:first-child]:pr-12"}>{children}</div>
    </div>
  )
}

/** 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 (
    <div aria-hidden className="pointer-events-none absolute inset-0 -z-10 overflow-hidden">
      {spots.map((s, i) => (
        <div key={i} className="absolute rounded-full blur-[120px]"
             style={{ left: s.left, top: s.top, width: s.size, height: s.size, opacity: s.o,
                      background: catColor(cats[i % cats.length]) }} />
      ))}
      <div className="absolute inset-0 bg-[radial-gradient(rgba(255,255,255,0.07)_1px,transparent_1px)] [background-size:28px_28px] [mask-image:linear-gradient(180deg,#000,transparent_85%)]" />
    </div>
  )
}

/** 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 (
    <div className="min-w-0">
      <div className="font-display text-[34px] leading-none font-semibold tracking-[-0.02em] text-white tabular-nums sm:text-[44px]">{value}</div>
      <div className="mt-2.5 text-[15px] text-white/60 sm:text-base">{label}</div>
    </div>
  )
}