{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "leaderboard",
  "type": "registry:component",
  "title": "Leaderboard",
  "description": "A ranked list with medals for the top three, proportional score bars that grow in, rank change arrows and a pinned row for the current user.",
  "author": "Hyperblur <hello@hyperblur.dev>",
  "dependencies": [],
  "registryDependencies": [],
  "categories": [
    "lists",
    "leaderboard",
    "ranking",
    "scores",
    "gamification",
    "medals",
    "bars"
  ],
  "docs": "https://hyperblur.dev/effects/leaderboard",
  "files": [
    {
      "path": "registry/hyperblur/leaderboard.tsx",
      "type": "registry:component",
      "target": "components/hyperblur/leaderboard.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\n\nexport interface LeaderboardEntry {\n  id: string;\n  name: string;\n  score: number;\n  change?: number;\n  you?: boolean;\n}\n\nexport const defaultLeaders: LeaderboardEntry[] = [\n  { id: \"l1\", name: \"Sofia Marchetti\", score: 12840, change: 0 },\n  { id: \"l2\", name: \"Kenji Watanabe\", score: 11975, change: 2 },\n  { id: \"l3\", name: \"Amara Nwosu\", score: 11320, change: -1 },\n  { id: \"l4\", name: \"Oliver Brandt\", score: 10410, change: 1 },\n  { id: \"l5\", name: \"Zara Haddad\", score: 9880, change: -2 },\n  { id: \"l6\", name: \"Mateo Ruiz\", score: 9215, change: 3 },\n  { id: \"l7\", name: \"Ingrid Larsen\", score: 8760, change: 0 },\n  { id: \"l8\", name: \"Noah Fischer\", score: 8105, change: -1 },\n  { id: \"l9\", name: \"Leila Karimi\", score: 7490, change: 4 },\n  { id: \"l10\", name: \"You\", score: 6930, change: 5, you: true },\n];\n\nexport interface LeaderboardProps extends Omit<React.HTMLAttributes<HTMLOListElement>, \"onSelect\"> {\n  entries?: LeaderboardEntry[];\n  topN?: number;\n  unit?: string;\n  accent?: string;\n  onSelect?: (entry: LeaderboardEntry, rank: number) => void;\n}\n\nconst css = `\n.hb-ldb {\n  --hb-ldb-accent: #2f7bff;\n  container-type: inline-size;\n  display: flex;\n  flex-direction: column;\n  gap: 2px;\n  width: 100%;\n  min-width: 0;\n  margin: 0;\n  padding: 0;\n  list-style: none;\n  box-sizing: border-box;\n  font-family: inherit;\n  font-size: 13px;\n  line-height: 1.4;\n  color: #ededed;\n}\n.hb-ldb *, .hb-ldb *::before, .hb-ldb *::after { box-sizing: border-box; font-family: inherit; }\n.hb-ldb-row {\n  position: relative;\n  min-width: 0;\n  border-radius: 11px;\n  animation: hb-ldb-in .4s cubic-bezier(.2, .8, .2, 1) both;\n  animation-delay: calc(var(--hb-ldb-i, 0) * 50ms);\n}\n.hb-ldb-body {\n  display: flex;\n  align-items: center;\n  gap: 10px;\n  width: 100%;\n  min-width: 0;\n  padding: 8px 10px 8px 8px;\n  border: 1px solid transparent;\n  border-radius: 11px;\n  background: none;\n  color: inherit;\n  font: inherit;\n  text-align: left;\n  transition: background-color .15s ease, border-color .15s ease;\n}\nbutton.hb-ldb-body { cursor: pointer; }\n.hb-ldb-row:hover .hb-ldb-body { background: rgba(255, 255, 255, .045); }\n.hb-ldb-body:focus-visible { outline: 2px solid color-mix(in srgb, var(--hb-ldb-accent) 80%, transparent); outline-offset: 1px; }\n.hb-ldb-row[data-you=\"true\"] .hb-ldb-body {\n  background: color-mix(in srgb, var(--hb-ldb-accent) 13%, transparent);\n  border-color: color-mix(in srgb, var(--hb-ldb-accent) 40%, transparent);\n}\n.hb-ldb-row[data-you=\"true\"]:hover .hb-ldb-body { background: color-mix(in srgb, var(--hb-ldb-accent) 18%, transparent); }\n.hb-ldb-rank {\n  flex: none;\n  display: grid;\n  place-items: center;\n  width: 24px;\n  height: 24px;\n  border-radius: 50%;\n  font-size: 12px;\n  font-weight: 600;\n  color: #8f8f8f;\n  font-variant-numeric: tabular-nums;\n}\n.hb-ldb-rank[data-medal] {\n  color: #1a1204;\n  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .5), 0 2px 8px var(--hb-ldb-glow);\n}\n.hb-ldb-rank[data-medal=\"1\"] { --hb-ldb-glow: rgba(245, 197, 66, .35); background: linear-gradient(145deg, #ffe08a, #e0a52a 60%, #b8860b); }\n.hb-ldb-rank[data-medal=\"2\"] { --hb-ldb-glow: rgba(200, 205, 215, .25); background: linear-gradient(145deg, #f2f4f8, #b4bac6 60%, #8a909c); color: #14161a; }\n.hb-ldb-rank[data-medal=\"3\"] { --hb-ldb-glow: rgba(205, 127, 50, .3); background: linear-gradient(145deg, #f0b27a, #cd7f32 60%, #96592a); color: #1c1008; }\n.hb-ldb-avatar {\n  flex: none;\n  display: grid;\n  place-items: center;\n  width: 30px;\n  height: 30px;\n  border-radius: 50%;\n  background: var(--hb-ldb-bg);\n  color: var(--hb-ldb-fg);\n  font-size: 11px;\n  font-weight: 600;\n}\n.hb-ldb-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 5px; }\n.hb-ldb-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 500; }\n.hb-ldb-row[data-you=\"true\"] .hb-ldb-name { color: #fff; }\n.hb-ldb-track { position: relative; height: 4px; overflow: hidden; border-radius: 999px; background: #1c1c1c; }\n.hb-ldb-bar {\n  position: absolute;\n  inset: 0;\n  border-radius: inherit;\n  background: linear-gradient(90deg, color-mix(in srgb, var(--hb-ldb-accent) 55%, #1c1c1c), var(--hb-ldb-accent));\n  transform-origin: left center;\n  transform: scaleX(var(--hb-ldb-w, 0));\n  animation: hb-ldb-grow .9s cubic-bezier(.2, .8, .2, 1) both;\n  animation-delay: calc(var(--hb-ldb-i, 0) * 50ms + 150ms);\n}\n.hb-ldb-row[data-medal=\"1\"] .hb-ldb-bar { background: linear-gradient(90deg, #8a6a1a, #f5c542); }\n.hb-ldb-row[data-medal=\"2\"] .hb-ldb-bar { background: linear-gradient(90deg, #5d626d, #cfd3dc); }\n.hb-ldb-row[data-medal=\"3\"] .hb-ldb-bar { background: linear-gradient(90deg, #6e4520, #d9894a); }\n.hb-ldb-side { flex: none; display: flex; flex-direction: column; align-items: flex-end; gap: 1px; min-width: 52px; }\n.hb-ldb-score { font-weight: 600; font-variant-numeric: tabular-nums; }\n.hb-ldb-unit { margin-left: 3px; font-size: 11px; font-weight: 400; color: #6b6b6b; }\n.hb-ldb-change {\n  display: inline-flex;\n  align-items: center;\n  gap: 2px;\n  font-size: 11px;\n  font-weight: 500;\n  font-variant-numeric: tabular-nums;\n  color: #6b6b6b;\n}\n.hb-ldb-change svg { width: 8px; height: 8px; }\n.hb-ldb-change[data-dir=\"up\"] { color: #3ecf8e; }\n.hb-ldb-change[data-dir=\"down\"] { color: #ff6b6b; }\n.hb-ldb-gap {\n  display: flex;\n  align-items: center;\n  gap: 8px;\n  padding: 2px 12px;\n  color: #4a4a4a;\n  list-style: none;\n}\n.hb-ldb-gap::before, .hb-ldb-gap::after { content: \"\"; flex: 1; height: 0; border-top: 1px dashed #2a2a2a; }\n.hb-ldb-gap span { font-size: 10px; letter-spacing: .12em; text-transform: uppercase; color: #6b6b6b; }\n.hb-ldb-sr {\n  position: absolute;\n  width: 1px;\n  height: 1px;\n  margin: -1px;\n  overflow: hidden;\n  clip: rect(0 0 0 0);\n  white-space: nowrap;\n}\n@container (max-width: 280px) {\n  .hb-ldb-avatar { display: none; }\n  .hb-ldb-unit { display: none; }\n}\n@keyframes hb-ldb-in {\n  from { opacity: 0; transform: translateY(8px); }\n  to { opacity: 1; transform: none; }\n}\n@keyframes hb-ldb-grow {\n  from { transform: scaleX(0); }\n  to { transform: scaleX(var(--hb-ldb-w, 0)); }\n}\n@media (prefers-reduced-motion: reduce) {\n  .hb-ldb-row, .hb-ldb-bar { animation: none !important; }\n  .hb-ldb-body { transition: none !important; }\n}\n`;\n\nfunction hash(input: string) {\n  let h = 0;\n  for (let i = 0; i < input.length; i++) h = (Math.imul(h, 31) + input.charCodeAt(i)) >>> 0;\n  return h;\n}\n\nfunction initials(name: string) {\n  const words = name.trim().split(/\\s+/).filter(Boolean);\n  if (words.length === 0) return \"?\";\n  const first = words[0][0] ?? \"\";\n  const last = words.length > 1 ? (words[words.length - 1][0] ?? \"\") : \"\";\n  return (first + last).toUpperCase();\n}\n\nfunction changeLabel(change: number) {\n  if (change > 0) return `Up ${change} ${change === 1 ? \"place\" : \"places\"}`;\n  if (change < 0) return `Down ${Math.abs(change)} ${Math.abs(change) === 1 ? \"place\" : \"places\"}`;\n  return \"No change\";\n}\n\nexport function Leaderboard({\n  entries = defaultLeaders,\n  topN = 5,\n  unit = \"pts\",\n  accent = \"#2f7bff\",\n  onSelect,\n  className = \"\",\n  style,\n  ...rest\n}: LeaderboardProps) {\n  const ranked = [...entries].sort((a, b) => b.score - a.score).map((entry, index) => ({ entry, rank: index + 1 }));\n  const limit = Math.max(1, Math.round(topN));\n  const top = ranked.slice(0, limit);\n  const pinned = ranked.slice(limit).find((r) => r.entry.you);\n  const max = Math.max(1, ...ranked.map((r) => r.entry.score));\n\n  const vars = { \"--hb-ldb-accent\": accent, ...style } as React.CSSProperties;\n\n  const renderRow = ({ entry, rank }: { entry: LeaderboardEntry; rank: number }, i: number) => {\n    const hue = hash(entry.name) % 360;\n    const change = entry.change ?? 0;\n    const dir = change > 0 ? \"up\" : change < 0 ? \"down\" : \"flat\";\n    const medal = rank <= 3 ? rank : undefined;\n    const Body = onSelect ? \"button\" : \"div\";\n    const colors = {\n      \"--hb-ldb-bg\": `hsl(${hue} 42% 30%)`,\n      \"--hb-ldb-fg\": `hsl(${hue} 70% 88%)`,\n      \"--hb-ldb-w\": (entry.score / max).toFixed(4),\n      \"--hb-ldb-i\": i,\n    } as React.CSSProperties;\n    return (\n      <li key={entry.id} className=\"hb-ldb-row\" data-you={entry.you ? \"true\" : \"false\"} data-medal={medal} style={colors}>\n        <Body\n          className=\"hb-ldb-body\"\n          {...(onSelect ? { type: \"button\" as const, onClick: () => onSelect(entry, rank) } : {})}\n        >\n          <span className=\"hb-ldb-rank\" data-medal={medal}>\n            <span className=\"hb-ldb-sr\">{`Rank `}</span>\n            {rank}\n          </span>\n          <span className=\"hb-ldb-avatar\" aria-hidden=\"true\">\n            {initials(entry.name)}\n          </span>\n          <span className=\"hb-ldb-main\">\n            <span className=\"hb-ldb-name\">{entry.you && entry.name !== \"You\" ? `${entry.name} (you)` : entry.name}</span>\n            <span className=\"hb-ldb-track\" aria-hidden=\"true\">\n              <span className=\"hb-ldb-bar\" />\n            </span>\n          </span>\n          <span className=\"hb-ldb-side\">\n            <span className=\"hb-ldb-score\">\n              {entry.score.toLocaleString(\"en-US\")}\n              {unit && <span className=\"hb-ldb-unit\">{unit}</span>}\n            </span>\n            <span className=\"hb-ldb-change\" data-dir={dir} aria-label={changeLabel(change)}>\n              {dir === \"up\" && (\n                <svg viewBox=\"0 0 8 8\" fill=\"currentColor\" aria-hidden=\"true\">\n                  <path d=\"M4 1l3.2 5.4H.8z\" />\n                </svg>\n              )}\n              {dir === \"down\" && (\n                <svg viewBox=\"0 0 8 8\" fill=\"currentColor\" aria-hidden=\"true\">\n                  <path d=\"M4 7L.8 1.6h6.4z\" />\n                </svg>\n              )}\n              {dir === \"flat\" ? \"–\" : Math.abs(change)}\n            </span>\n          </span>\n        </Body>\n      </li>\n    );\n  };\n\n  return (\n    <ol className={`hb-ldb ${className}`} style={vars} aria-label=\"Leaderboard\" {...rest}>\n      <style href=\"hb-leaderboard\" precedence=\"default\">{css}</style>\n      {top.map((r, i) => renderRow(r, i))}\n      {pinned && (\n        <>\n          <li className=\"hb-ldb-gap\" aria-hidden=\"true\">\n            <span>Your rank</span>\n          </li>\n          {renderRow(pinned, top.length)}\n        </>\n      )}\n    </ol>\n  );\n}\n"
    }
  ]
}