File size: 5,167 Bytes
2471af3
 
 
 
 
 
0953253
2471af3
 
 
 
 
61db3dc
2471af3
 
 
 
61db3dc
2471af3
 
 
 
 
 
 
 
 
 
 
 
 
0953253
 
 
 
2471af3
 
 
 
61db3dc
2471af3
 
0953253
61db3dc
2471af3
 
 
 
 
 
61db3dc
 
0953253
2471af3
61db3dc
2471af3
 
 
61db3dc
 
2471af3
 
 
 
 
 
 
 
 
61db3dc
2471af3
 
 
 
 
61db3dc
2471af3
 
61db3dc
2471af3
 
 
 
 
0953253
2471af3
 
 
 
 
61db3dc
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
93
94
95
import { ArrowUpRight } from "lucide-react"
import type { Site } from "@/lib/types"
import { catFrom, catTo } from "@/lib/category"
import { DAY, full, isoDay, num, toTime } from "@/lib/format"
import { href } from "@/lib/route"
import { Spark } from "@/components/sparkline"
import { catName, T } from "@/lib/i18n"

/** One block per modality: how big its community is, which releases it holds, who builds on it. */
export function CategoryBlocks({ site }: { site: Site }) {
  return (
    <div className="grid gap-5 lg:grid-cols-2">
      {site.categories.map((c, i) => <Block key={c.key} site={site} cat={c.key} wide={i < 2 || site.categories.length % 2 === 1 && i === site.categories.length - 1} />)}
    </div>
  )
}

function Block({ site, cat, wide }: { site: Site; cat: string; wide: boolean }) {
  const c = site.categories.find((x) => x.key === cat)!
  const rels = c.releases.map((k) => site.releases.find((r) => r.key === k)!)
  const n = rels.reduce((a, r) => a + r.n, 0)
  const dl = rels.reduce((a, r) => a + r.dlall, 0)
  const off = rels.reduce((a, r) => a + (r.official.dlall ?? 0), 0)
  const events = rels.flatMap((r) => r.growth)
  // The curve starts a week before the first community model, so a modality whose community
  // is new still gets a readable curve rather than a flat line and a cliff.
  const firstEvent = events.reduce((a, [d]) => (d < a ? d : a), "9999")
  const first = firstEvent < "9999" ? isoDay(toTime(firstEvent) - 7 * DAY) : rels.reduce((a, r) => (r.date < a ? r.date : a), rels[0].date)
  const repoCount = rels.reduce((a, r) => a + r.models.length, 0)

  const stats: [string, string][] = [
    [num(dl), T.communityDownloads],
    [full(c.builders), T.builders],
    [num(off), T.minimaxDownloads],
    [full(repoCount), T.openModels(repoCount)],
  ]

  return (
    <a href={href(cat)}
       className={`group relative flex flex-col overflow-hidden rounded-[24px] border border-border bg-white shadow-[var(--shadow-card)] transition-[transform,box-shadow] duration-300 ease-[cubic-bezier(.22,.61,.36,1)] hover:-translate-y-1 hover:shadow-[0_28px_56px_-24px_rgba(23,23,23,0.28)] focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-ring ${wide ? "lg:col-span-2" : ""}`}>
      <div className="flex-1 p-7 sm:p-10">
        <div className="flex items-start justify-between gap-4">
          <h2 className="font-display text-[30px] leading-none font-semibold tracking-[-0.01em] sm:text-[36px]">{catName(c)}</h2>
          <span className="grid size-11 shrink-0 place-items-center rounded-full border border-border transition-[background-color,color,border-color,transform] duration-200 group-hover:rotate-45 group-hover:border-[#171717] group-hover:bg-[#171717] group-hover:text-white">
            <ArrowUpRight className="size-5" />
          </span>
        </div>

        <div className={`mt-8 ${wide ? "lg:flex lg:items-end lg:justify-between lg:gap-10" : ""}`}>
          <div>
            <div className="gradient-text w-fit pb-1 font-display text-[72px] leading-[0.9] font-semibold tracking-[-0.04em] tabular-nums sm:text-[96px]"
                 style={{ "--from": catFrom(cat), "--to": catTo(cat) } as React.CSSProperties}>{full(n)}</div>
            <div className="mt-2 text-lg text-muted-foreground">{T.communityModels}</div>
          </div>
          <dl className={`mt-8 grid grid-cols-2 gap-x-8 gap-y-6 ${wide ? "sm:grid-cols-4 lg:mt-0 lg:gap-x-12" : ""}`}>
            {stats.map(([v, l]) => (
              <div key={l}>
                <dt className="sr-only">{l}</dt>
                <dd className="font-serif text-[26px] leading-none">{v}</dd>
                <dd className="mt-2.5 text-[15px] text-muted-foreground">{l}</dd>
              </div>
            ))}
          </dl>
        </div>

        <div className="mt-8 flex flex-wrap items-center gap-2">
          {rels.map((r) => (
            <span key={r.key} className="inline-flex h-9 items-center gap-2 rounded-full bg-muted px-3.5 text-[15px]">
              <span className="font-medium">{r.name}</span>
              {r.n > 0 && <span className="text-muted-foreground tabular-nums">{full(r.n)}</span>}
            </span>
          ))}
        </div>

        {c.top_authors.length > 0 && (
          <div className="mt-6 flex items-center gap-3">
            <div className="flex -space-x-2.5">
              {c.top_authors.map((a) => (
                <span key={a.id} title={a.n} className="grid size-9 place-items-center overflow-hidden rounded-full bg-muted text-sm font-medium ring-[3px] ring-white">
                  {a.a ? <img src={a.a} alt="" loading="lazy" className="size-full object-cover" /> : a.id.slice(0, 1).toUpperCase()}
                </span>
              ))}
            </div>
            {c.builders > c.top_authors.length && (
              <span className="text-[15px] text-muted-foreground">{T.moreBuilders(full(c.builders - c.top_authors.length))}</span>
            )}
          </div>
        )}
      </div>
      <Spark events={events} from={first} to={site.today} cat={cat} height={wide ? 120 : 100}
             dots={rels.map((r) => r.date)} ring="#fff" />
    </a>
  )
}