{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "podium",
  "type": "registry:ui",
  "title": "Podium",
  "description": "The end of a game: the top three on steps, second and third rising first and the winner last, with a burst for first place. Below it, everyone else, so no one has to wonder where they came. Ranking is the leaderboard's (`rankEntries`), so ties share a…",
  "author": "ofri-peretz <https://github.com/ofri-peretz>",
  "categories": [
    "games",
    "game"
  ],
  "dependencies": [],
  "registryDependencies": [
    "https://ds.interlace.tools/r/interlace-base.json",
    "https://ds.interlace.tools/r/celebrate.json",
    "https://ds.interlace.tools/r/cn.json",
    "https://ds.interlace.tools/r/motion-token.json",
    "https://ds.interlace.tools/r/use-reduced-motion.json"
  ],
  "files": [
    {
      "path": "registry/interlace-ui/games/podium.tsx",
      "target": "components/ui/games/podium.tsx",
      "type": "registry:ui",
      "content": "'use client';\n\nimport * as React from 'react';\n\n// @interlace/podium v1.1.1 — Interlace design system.\n// Docs, props and live preview: https://ds.interlace.tools/c/podium\n// What changed since: https://ds.interlace.tools/c/podium#history\n// Generated banner — keep it, the upgrade diff reads this version.\n\n/**\n * @interlace/ui — Podium\n *\n * The end of a game: the top three on steps, second and third rising first\n * and the winner last, with a burst for first place. Below it, everyone\n * else, so no one has to wonder where they came. Ranking is the\n * leaderboard's (`rankEntries`), so ties share a place on both.\n *\n * ## Anatomy\n *\n *   Podium                         (section — data-slot=\"podium\")\n *     ├─ ol                        (data-slot=\"podium-steps\": 1st, 2nd, 3rd in reading order)\n *     │   └─ li × ≤3               (data-slot=\"podium-place\", data-place, data-current)\n *     │       ├─ span              (data-slot=\"podium-label\": name, \"You\", score)\n *     │       │   ├─ span          (data-slot=\"podium-name\")\n *     │       │   └─ span          (data-slot=\"podium-score\")\n *     │       └─ span aria-hidden  (data-slot=\"podium-step\": the block, its place on it)\n *     └─ ol                        (data-slot=\"podium-rest\": everyone after the top three)\n *\n * ## Order\n *\n * The list reads 1st, 2nd, 3rd for a screen reader and a phone; the steps\n * are placed 2nd, 1st, 3rd with grid columns, which mirror in RTL. Place\n * words come from `labels.place` (English ordinals by default), and the\n * viewer's row says \"You\" in words.\n *\n * ## Motion\n *\n * On mount (or when `play` changes), the steps grow up from the floor,\n * 3rd, 2nd, then 1st, 350ms apart, each name rising onto its step, and a\n * Celebrate burst on the winner. Transform only, so text never dips below\n * contrast mid-animation. Under reduced\n * motion, or with `animate={false}`, the podium is simply there. The text\n * is in the server HTML from the start.\n *\n * ## MIN_VIEWPORT — 320\n *\n * | Rule | Concept                   | Where in this file                                    |\n * | ---- | ------------------------- | ----------------------------------------------------- |\n * | R4   | Extends native el         | `React.ComponentProps<'section'>`                     |\n * | R6   | data-slot per part        | podium / -steps / -place / -name / -score / -step / -rest |\n * | R7   | cn + ...rest              | `cn(…, className)` + `{...props}`                     |\n * | R14  | Declares min viewport     | `data-min-viewport` + exported const                  |\n * | R19  | Tokens only               | primary, muted, border                                |\n * | R26  | A11y                      | ordered lists in rank order; \"You\" in words           |\n */\n\nimport { Celebrate } from '@/components/ui/effects/celebrate';\nimport { cn } from '@/lib/utils';\nimport { useReducedMotion } from '@/hooks/use-reduced-motion';\nimport { motionEase } from '@/lib/motion-token';\nimport { rankEntries, type LeaderboardEntry, type RankedEntry } from '@/components/ui/games/leaderboard-model';\n\nexport const MIN_VIEWPORT = 320 as const;\n\nconst ORDINAL: Record<string, string> = {\n  one: 'st',\n  two: 'nd',\n  few: 'rd',\n  other: 'th',\n};\nconst en = new Intl.PluralRules('en-US', { type: 'ordinal' });\nconst PLACE = (rank: number) => `${rank}${ORDINAL[en.select(rank)] ?? 'th'}`;\n\ninterface PodiumLabels {\n  /** A place in words. @default English ordinals: 1st, 2nd, 3rd */\n  place?: (rank: number) => string;\n  /** @default 'You' */\n  you?: string;\n  /** Names the top three. @default 'Top three' */\n  top?: string;\n  /** Names everyone else. @default 'Everyone else' */\n  rest?: string;\n}\n\ntype PodiumProps = Omit<React.ComponentProps<'section'>, 'children'> & {\n  entries: readonly LeaderboardEntry[];\n  /** The viewer's id, to mark their place. */\n  currentId?: string;\n  /** Rise on mount. @default true */\n  animate?: boolean;\n  /** Plays the rise again each time this changes. */\n  play?: string | number;\n  /** List everyone after the top three. @default true */\n  showRest?: boolean;\n  /** `Intl.NumberFormat` options for scores. */\n  format?: Intl.NumberFormatOptions;\n  locale?: string;\n  labels?: PodiumLabels;\n};\n\n// Column (2nd, 1st, 3rd) and height per place.\nconst STEP = [\n  {\n    col: 'col-start-2',\n    height: 'h-32',\n    tone: 'bg-primary text-primary-foreground',\n  },\n  {\n    col: 'col-start-1',\n    height: 'h-24',\n    tone: 'bg-muted text-foreground border-border border border-b-0',\n  },\n  { col: 'col-start-3', height: 'h-16', tone: 'bg-muted text-foreground border-border border border-b-0' },\n] as const;\nconst RISE_ORDER = [2, 1, 0];\nconst GAP = 350;\n\nfunction Podium({\n  entries,\n  currentId,\n  animate = true,\n  play,\n  showRest = true,\n  format,\n  locale,\n  labels,\n  className,\n  ...props\n}: PodiumProps) {\n  const reduced = useReducedMotion();\n  const ranked = rankEntries(entries);\n  const top = ranked.slice(0, 3);\n  const rest = ranked.slice(3);\n  const formatKey = JSON.stringify(format ?? null);\n  // eslint-disable-next-line react-hooks/exhaustive-deps -- keyed on the options' value, not their identity\n  const nf = React.useMemo(() => new Intl.NumberFormat(locale, format), [locale, formatKey]);\n  const place = labels?.place ?? PLACE;\n  const you = labels?.you ?? 'You';\n  const stepsRef = React.useRef<HTMLOListElement>(null);\n  const [cheer, setCheer] = React.useState(0);\n\n  React.useEffect(() => {\n    if (!animate || reduced) return;\n    const items = stepsRef.current?.querySelectorAll<HTMLElement>('[data-slot=\"podium-place\"]');\n    if (!items) return;\n    const running: Animation[] = [];\n    RISE_ORDER.forEach((index, order) => {\n      const item = items[index];\n      if (!item) return;\n      const delay = order * GAP - (3 - items.length) * GAP;\n      const step = item.querySelector<HTMLElement>('[data-slot=\"podium-step\"]');\n      const label = item.querySelector<HTMLElement>('[data-slot=\"podium-label\"]');\n      if (step && typeof step.animate === 'function') {\n        running.push(\n          step.animate([{ transform: 'scaleY(0)' }, { transform: 'scaleY(1)' }], {\n            duration: 500,\n            delay: Math.max(0, delay),\n            easing: motionEase(step, 'enter'),\n            fill: 'backwards',\n          }),\n        );\n      }\n      if (label && typeof label.animate === 'function') {\n        running.push(\n          label.animate(\n            // Movement only: a fading name or score would dip below text contrast.\n            [{ transform: 'translateY(0.5rem)' }, { transform: 'translateY(0)' }],\n            {\n              duration: 300,\n              delay: Math.max(0, delay) + 350,\n              easing: motionEase(label, 'enter'),\n              fill: 'backwards',\n            },\n          ),\n        );\n      }\n    });\n    const t = setTimeout(() => setCheer((c) => c + 1), (items.length - 1) * GAP + 650);\n    return () => {\n      clearTimeout(t);\n      running.forEach((a) => a.cancel());\n    };\n  }, [animate, reduced, play]);\n\n  return (\n    <section\n      data-slot=\"podium\"\n      data-min-viewport={String(MIN_VIEWPORT)}\n      className={cn('flex flex-col gap-6', className)}\n      {...props}\n    >\n      <ol\n        ref={stepsRef}\n        data-slot=\"podium-steps\"\n        aria-label={labels?.top ?? 'Top three'}\n        className=\"grid grid-cols-3 items-end gap-2\"\n      >\n        {top.map((e: RankedEntry, i) => {\n          const s = STEP[i]!;\n          const current = e.id === currentId;\n          return (\n            <li\n              key={e.id}\n              data-slot=\"podium-place\"\n              data-place={e.rank}\n              data-current={current ? '' : undefined}\n              className={cn('row-start-1 flex min-w-0 flex-col items-center gap-2 text-center', s.col)}\n            >\n              <span data-slot=\"podium-label\" className=\"flex w-full min-w-0 flex-col items-center gap-0.5\">\n                <span data-slot=\"podium-name\" className={cn('w-full wrap-anywhere font-semibold', i === 0 && 'text-lg')}>\n                  {e.name}\n                </span>\n                {current ? (\n                  <span className=\"border-primary text-primary rounded-full border px-2 text-xs leading-5 font-semibold\">\n                    {you}\n                  </span>\n                ) : null}\n                <span data-slot=\"podium-score\" className=\"text-muted-foreground text-sm tabular-nums\">\n                  {nf.format(e.score)}\n                </span>\n              </span>\n              <span\n                data-slot=\"podium-step\"\n                className={cn(\n                  'flex w-full origin-bottom items-start justify-center rounded-t-lg pt-3 text-xl font-semibold',\n                  s.height,\n                  s.tone,\n                )}\n              >\n                {i === 0 ? (\n                  <Celebrate play={cheer || null} tone=\"highlight\">\n                    <span className=\"px-2\">{place(e.rank)}</span>\n                  </Celebrate>\n                ) : (\n                  place(e.rank)\n                )}\n              </span>\n            </li>\n          );\n        })}\n      </ol>\n      {showRest && rest.length ? (\n        <ol\n          data-slot=\"podium-rest\"\n          aria-label={labels?.rest ?? 'Everyone else'}\n          className=\"border-border divide-border divide-y rounded-xl border text-sm\"\n        >\n          {rest.map((e) => {\n            const current = e.id === currentId;\n            return (\n              <li\n                key={e.id}\n                data-current={current ? '' : undefined}\n                className={cn('flex items-center gap-3 px-3 py-2.5', current && 'bg-primary/8')}\n              >\n                <span className=\"text-muted-foreground w-10 shrink-0 tabular-nums\">{place(e.rank)}</span>\n                <span data-slot=\"podium-rest-name\" className={cn('min-w-0 flex-1 wrap-anywhere', current && 'font-semibold')}>\n                  {e.name}\n                </span>\n                {current ? (\n                  <span className=\"border-primary text-primary shrink-0 rounded-full border px-2 text-xs leading-5 font-semibold\">\n                    {you}\n                  </span>\n                ) : null}\n                <span className={cn('shrink-0 tabular-nums', current && 'font-semibold')}>{nf.format(e.score)}</span>\n              </li>\n            );\n          })}\n        </ol>\n      ) : null}\n    </section>\n  );\n}\nPodium.displayName = 'Podium';\n\nexport { Podium };\nexport type { PodiumProps, PodiumLabels };\n"
    },
    {
      "path": "registry/interlace-ui/games/leaderboard-model.ts",
      "target": "components/ui/games/leaderboard-model.ts",
      "type": "registry:ui",
      "content": "export interface LeaderboardEntry {\n  /** Stable id: a player or a group. */\n  id: string;\n  /** What the board shows. */\n  name: string;\n  score: number;\n  /** Breaks ties on score: lower first (time taken, say). Equal or missing values share a rank. */\n  tiebreak?: number;\n}\n\nexport interface RankedEntry extends LeaderboardEntry {\n  /** 1-based; ties share a rank and the next rank skips (1, 2, 2, 4). */\n  rank: number;\n  /** True when another entry has the same rank. */\n  tied: boolean;\n}\n\nexport interface RankOptions {\n  /** `desc` when a higher score wins. @default 'desc' */\n  order?: 'desc' | 'asc';\n  /** Below this many entries the board is hidden. @default 1 */\n  minPlayers?: number;\n  /** Rows to show from the top. @default all */\n  limit?: number;\n  /** The viewing player's id: their row is kept even outside `limit`. */\n  currentId?: string;\n}\n\nexport interface RankedBoard {\n  /** False while fewer than `minPlayers` have played. */\n  visible: boolean;\n  /** Entries counted. */\n  players: number;\n  /** The top rows, within `limit`. Empty while hidden. */\n  top: RankedEntry[];\n  /** The viewing player's row when it falls outside `top`. */\n  current?: RankedEntry;\n}\n\n/** Rank every entry. */\nexport function rankEntries(entries: readonly LeaderboardEntry[], order: 'desc' | 'asc' = 'desc'): RankedEntry[] {\n  const sign = order === 'desc' ? -1 : 1;\n  // An id counts once: a repeated message must not add a row, and the latest report wins.\n  const sorted = [...new Map(entries.map((e) => [e.id, e])).values()]\n    .sort(\n      (a, b) =>\n        sign * (a.score - b.score) || (a.tiebreak ?? Infinity) - (b.tiebreak ?? Infinity) || a.name.localeCompare(b.name),\n    );\n  const same = (a: LeaderboardEntry, b: LeaderboardEntry) => a.score === b.score && (a.tiebreak ?? null) === (b.tiebreak ?? null);\n  const ranked: RankedEntry[] = [];\n  sorted.forEach((entry, i) => {\n    const prev = sorted[i - 1];\n    const rank = prev && same(prev, entry) ? (ranked[i - 1] as RankedEntry).rank : i + 1;\n    ranked.push({ ...entry, rank, tied: false });\n  });\n  for (let i = 0; i < ranked.length; i++) {\n    const r = ranked[i] as RankedEntry;\n    r.tied = ranked[i - 1]?.rank === r.rank || ranked[i + 1]?.rank === r.rank;\n  }\n  return ranked;\n}\n\n/** The board as a page shows it: hidden below the minimum, top rows, and the viewer's own row. */\nexport function buildBoard(entries: readonly LeaderboardEntry[], options: RankOptions = {}): RankedBoard {\n  const { order = 'desc', minPlayers = 1, limit, currentId } = options;\n  const ranked = rankEntries(entries, order);\n  const players = ranked.length;\n  if (players < Math.max(1, minPlayers)) return { visible: false, players, top: [] };\n  const top = limit === undefined ? ranked : ranked.slice(0, limit);\n  const mine = currentId === undefined ? undefined : ranked.find((e) => e.id === currentId);\n  const current = mine && !top.includes(mine) ? mine : undefined;\n  return { visible: true, players, top, current };\n}\n\n/**\n * @interlace/ui — games/leaderboard-model\n *\n * Ranking for a group's board: ties share a rank (1, 2, 2, 4), the board\n * stays hidden until enough people have played, and the player's own row is\n * found even when it falls outside the top rows. Pure, so the server that\n * stores scores ranks them the same way.\n *\n * ## Why a minimum\n *\n * A board of two people tells each of them exactly what the other scored.\n * `minPlayers` keeps a small group's scores private until there are enough\n * of them to stand in a crowd.\n */\n"
    }
  ],
  "meta": {
    "tier": "game",
    "client": true,
    "minViewport": 320,
    "loading": false,
    "version": "1.1.1",
    "since": "2.0.0"
  },
  "docs": "## @interlace/podium\n\nInstalled to `components/ui/games/podium.tsx`.\n\n```tsx\nimport { /* … */ } from '@/components/ui/games/podium';\n```\n\nProps, a11y contract, live preview and source: https://ds.interlace.tools/c/podium\n\nRequires the `@interlace/interlace-base` CSS baseline (installed automatically as a registry dependency). For the Interlace look, also add `@interlace/theme`."
}
