{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "quiz-question",
  "type": "registry:ui",
  "title": "Quiz Question",
  "description": "A multiple-choice question with the energy of a live quiz and the manners of a form: big answer tiles you can tap, click or pick with a number key, an optional clock that rewards speed, and a reveal that marks the right answer, says in words how you did…",
  "author": "ofri-peretz <https://github.com/ofri-peretz>",
  "categories": [
    "games",
    "game"
  ],
  "dependencies": [
    "lucide-react"
  ],
  "registryDependencies": [
    "https://ds.interlace.tools/r/interlace-base.json",
    "https://ds.interlace.tools/r/button.json",
    "https://ds.interlace.tools/r/cn.json",
    "https://ds.interlace.tools/r/motion-token.json",
    "https://ds.interlace.tools/r/tally-bars.json",
    "https://ds.interlace.tools/r/timer-ring.json",
    "https://ds.interlace.tools/r/use-reduced-motion.json"
  ],
  "files": [
    {
      "path": "registry/interlace-ui/games/quiz-question.tsx",
      "target": "components/ui/games/quiz-question.tsx",
      "type": "registry:ui",
      "content": "'use client';\n\nimport * as React from 'react';\n\n// @interlace/quiz-question v1.0.1 — Interlace design system.\n// Docs, props and live preview: https://ds.interlace.tools/c/quiz-question\n// What changed since: https://ds.interlace.tools/c/quiz-question#history\n// Generated banner — keep it, the upgrade diff reads this version.\n\n/**\n * @interlace/ui — QuizQuestion\n *\n * A multiple-choice question with the energy of a live quiz and the manners\n * of a form: big answer tiles you can tap, click or pick with a number key,\n * an optional clock that rewards speed, and a reveal that marks the right\n * answer, says in words how you did, and shows how everyone else answered.\n * Scoring lives in `quiz-model.ts` and is exported, so a server can score\n * the same answer.\n *\n * ## Anatomy\n *\n *   QuizQuestion                     (div — data-slot=\"quiz-question\", data-state=asking|revealed, data-outcome)\n *     ├─ div                         (data-slot=\"quiz-question-header\")\n *     │   ├─ div                     (data-slot=\"quiz-question-meta\": e.g. \"Question 3 of 10\")\n *     │   └─ TimerRing + Button      (when timed: the clock, and \"Stop the clock\")\n *     ├─ p                           (data-slot=\"quiz-question-prompt\", id ← the choice group's label)\n *     ├─ div role=\"group\"            (data-slot=\"quiz-question-choices\")\n *     │   └─ button × n              (data-slot=\"quiz-question-choice\", data-key, data-mark=correct|wrong)\n *     ├─ p tabIndex=-1 aria-live     (data-slot=\"quiz-question-result\")\n *     ├─ TallyBars                   (data-slot=\"quiz-question-spread\": how others answered, optional)\n *     └─ div                         (data-slot=\"quiz-question-explanation\": opens on reveal)\n *\n * ## Picking an answer\n *\n * Every choice is a real button. While the question is open, the keys 1 to\n * 9 pick the matching choice from anywhere inside the component (each\n * button declares its key in `aria-keyshortcuts` and shows it on the\n * tile). The first pick is final, as in a live quiz.\n *\n * ## The clock\n *\n * `timeLimit` (seconds) starts a TimerRing when the question mounts; time\n * running out reveals the answer with no choice. A visible \"Stop the clock\"\n * button turns it off at any point (WCAG 2.2.1): the answer then scores\n * without the speed share, so stopping it never pays more than racing it.\n *\n * ## Controlled or not\n *\n * `result` / `defaultResult` hold the scored answer (null for none yet), so\n * a page that stored today's answer restores the revealed state on reload.\n * `onAnswer` fires once, with the scored result.\n *\n * ## Motion\n *\n * Tiles press in slightly. On the reveal the right tile settles with a\n * small lift and a wrong pick gives a short sideways shake (both 250ms,\n * transform only), and the spread's bars grow. Under reduced motion all of\n * it is simply in its end state.\n *\n * ## MIN_VIEWPORT — 320\n *\n * | Rule | Concept                   | Where in this file                                    |\n * | ---- | ------------------------- | ----------------------------------------------------- |\n * | R4   | Extends native el         | `React.ComponentProps<'div'>`                         |\n * | R6   | data-slot per part        | quiz-question / -header / -meta / -prompt / -choices / -choice / -result / -spread / -explanation |\n * | R7   | cn + ...rest              | `cn(…, className)` + `{...props}`                     |\n * | R9   | Controlled + uncontrolled | `result` / `defaultResult` / `onAnswer`               |\n * | R14  | Declares min viewport     | `data-min-viewport` + exported const                  |\n * | R19  | Tokens only               | success, destructive, primary, border, muted           |\n * | R26  | A11y                      | labelled button group; key shortcuts declared; outcome in words; result focused |\n */\n\nimport { Check, X } from 'lucide-react';\n\nimport { cn } from '@/lib/utils';\nimport { useReducedMotion } from '@/hooks/use-reduced-motion';\nimport { motionDuration, motionEase } from '@/lib/motion-token';\nimport { Button } from '@/components/ui/button';\nimport { scoreAnswer, type QuizOutcome, type QuizResult, type QuizScoreOptions } from '@/components/ui/games/quiz-model';\nimport { TallyBars, type TallyBarsLabels, type TallyMark } from '@/components/ui/games/tally-bars';\nimport { tally } from '@/components/ui/games/tally-model';\nimport { TimerRing, type TimerRingLabels } from '@/components/ui/games/timer-ring';\n\nexport const MIN_VIEWPORT = 320 as const;\n\ninterface QuizChoice {\n  id: string;\n  label: React.ReactNode;\n  /** Plain text for the result sentence, when `label` is not a string. */\n  text?: string;\n}\n\ninterface QuizQuestionLabels {\n  /** The result sentence. */\n  result?: (r: { outcome: QuizOutcome; points: number; answer: string }) => string;\n  /** The stop button. @default 'Stop the clock' */\n  stopClock?: string;\n  /** Shown where the clock was. @default 'Clock stopped' */\n  clockStopped?: string;\n  /** Names the spread. @default 'How everyone answered' */\n  spread?: string;\n  timer?: TimerRingLabels;\n  tally?: TallyBarsLabels;\n}\n\ntype QuizQuestionProps = Omit<React.ComponentProps<'div'>, 'children' | 'onChange'> & {\n  question: React.ReactNode;\n  choices: readonly QuizChoice[];\n  /** The right choice's id. Keep it off the client until the reveal if the game is competitive. */\n  correct: string;\n  /** Seconds to answer. Leave out for no clock. */\n  timeLimit?: number;\n  /** The scored answer, controlled. null for none yet. */\n  result?: QuizResult | null;\n  /** The scored answer, uncontrolled. */\n  defaultResult?: QuizResult | null;\n  /** Called once, when the player picks or time runs out. */\n  onAnswer?: (result: QuizResult) => void;\n  /** Votes per choice id from everyone else, shown after the reveal. */\n  distribution?: Readonly<Record<string, number>>;\n  /** `distribution` already includes this player's answer. @default false */\n  distributionIncludesAnswer?: boolean;\n  /** Above the question, e.g. \"Question 3 of 10\". */\n  meta?: React.ReactNode;\n  /** Shown after the reveal: why the answer is right, and where it comes from. */\n  explanation?: React.ReactNode;\n  score?: QuizScoreOptions;\n  locale?: string;\n  labels?: QuizQuestionLabels;\n};\n\nconst RESULT: NonNullable<QuizQuestionLabels['result']> = ({ outcome, points, answer }) =>\n  outcome === 'correct'\n    ? `Right. +${points} points.`\n    : outcome === 'timeout'\n      ? `Time's up. The answer is ${answer}.`\n      : `Not this time. The answer is ${answer}.`;\n\nconst textOf = (c: QuizChoice) =>\n  c.text ?? (typeof c.label === 'string' || typeof c.label === 'number' ? String(c.label) : c.id);\n\nfunction QuizQuestion({\n  question,\n  choices,\n  correct,\n  timeLimit,\n  result: resultProp,\n  defaultResult = null,\n  onAnswer,\n  distribution,\n  distributionIncludesAnswer = false,\n  meta,\n  explanation,\n  score,\n  locale,\n  labels,\n  className,\n  onKeyDown,\n  ...props\n}: QuizQuestionProps) {\n  const [uncontrolled, setUncontrolled] = React.useState<QuizResult | null>(defaultResult);\n  const result = resultProp === undefined ? uncontrolled : resultProp;\n  const revealed = result !== null && result !== undefined;\n  const reduced = useReducedMotion();\n  const timed = typeof timeLimit === 'number' && timeLimit > 0;\n  const [deadline, setDeadline] = React.useState<number | null>(null);\n  const [stopped, setStopped] = React.useState(false);\n  const startRef = React.useRef<number | null>(null);\n  const sent = React.useRef(revealed);\n  const moveFocus = React.useRef(false);\n  const animate = React.useRef(false);\n  const promptId = React.useId();\n  const explanationId = React.useId();\n  const groupRef = React.useRef<HTMLDivElement>(null);\n  const resultRef = React.useRef<HTMLParagraphElement>(null);\n\n  // The clock starts in the browser, when the question is on screen.\n  React.useEffect(() => {\n    if (!timed || revealed) return;\n    const start = Date.now();\n    startRef.current = start;\n    setDeadline(start + (timeLimit as number) * 1000);\n    // eslint-disable-next-line react-hooks/exhaustive-deps\n  }, [timed, timeLimit]);\n\n  React.useEffect(() => {\n    if (!revealed) sent.current = false;\n  }, [revealed]);\n\n  const answer = (choice: string | null) => {\n    if (revealed || sent.current) return;\n    sent.current = true;\n    animate.current = true;\n    moveFocus.current = !!groupRef.current?.contains(document.activeElement) || choice === null;\n    const limitMs = timed ? (timeLimit as number) * 1000 : undefined;\n    const elapsedMs = timed && !stopped && startRef.current !== null ? Date.now() - startRef.current : undefined;\n    const scored = scoreAnswer({ choice, limitMs, elapsedMs }, correct, score);\n    setDeadline(null);\n    if (resultProp === undefined) setUncontrolled(scored);\n    onAnswer?.(scored);\n  };\n\n  React.useEffect(() => {\n    if (!revealed || !moveFocus.current) return;\n    moveFocus.current = false;\n    // Only take focus from the tiles (or from nowhere, on a timeout); never from elsewhere on the page.\n    const active = document.activeElement;\n    if (active && active !== document.body && !groupRef.current?.contains(active)) return;\n    resultRef.current?.focus();\n  }, [revealed]);\n\n  // The reveal: the right tile lifts, a wrong pick shakes.\n  React.useEffect(() => {\n    if (!revealed || !animate.current) return;\n    animate.current = false;\n    if (reduced) return;\n    const group = groupRef.current;\n    const right = group?.querySelector<HTMLElement>('[data-mark=\"correct\"]');\n    const wrong = group?.querySelector<HTMLElement>('[data-mark=\"wrong\"]');\n    if (!group) return;\n    const timing = { duration: motionDuration(group, 'medium'), easing: motionEase(group, 'move') };\n    if (right && typeof right.animate === 'function') {\n      right.animate([{ transform: 'none' }, { transform: 'translateY(-3px) scale(1.02)' }, { transform: 'none' }], timing);\n    }\n    if (wrong && typeof wrong.animate === 'function') {\n      wrong.animate(\n        [\n          { transform: 'none' },\n          { transform: 'translateX(-4px)' },\n          { transform: 'translateX(4px)' },\n          { transform: 'translateX(-2px)' },\n          { transform: 'none' },\n        ],\n        timing,\n      );\n    }\n  }, [revealed, reduced]);\n\n  const handleKeyDown = (e: React.KeyboardEvent<HTMLDivElement>) => {\n    onKeyDown?.(e);\n    if (e.defaultPrevented || revealed || e.altKey || e.ctrlKey || e.metaKey) return;\n    const target = e.target as HTMLElement;\n    if (target.closest('input, textarea, select, [contenteditable=\"true\"]')) return;\n    const n = Number(e.key);\n    if (Number.isInteger(n) && n >= 1 && n <= Math.min(9, choices.length)) {\n      e.preventDefault();\n      answer((choices[n - 1] as QuizChoice).id);\n    }\n  };\n\n  const correctChoice = choices.find((c) => c.id === correct);\n  const markOf = (id: string): TallyMark | undefined =>\n    !revealed ? undefined : id === correct ? 'correct' : id === result.choice ? 'wrong' : undefined;\n  const spread =\n    revealed && distribution\n      ? tally(\n          choices.map((c) => c.id),\n          distribution,\n          { vote: result.choice, countsIncludeVote: distributionIncludesAnswer },\n        )\n      : null;\n\n  return (\n    <div\n      data-slot=\"quiz-question\"\n      data-state={revealed ? 'revealed' : 'asking'}\n      data-outcome={revealed ? result.outcome : undefined}\n      data-min-viewport={String(MIN_VIEWPORT)}\n      className={cn('@container grid gap-5', className)}\n      onKeyDown={handleKeyDown}\n      {...props}\n    >\n      {meta || timed ? (\n        <div data-slot=\"quiz-question-header\" className=\"flex min-h-10 flex-wrap items-center justify-between gap-3\">\n          <div data-slot=\"quiz-question-meta\" className=\"text-muted-foreground text-sm font-medium\">\n            {meta}\n          </div>\n          {timed && !revealed ? (\n            <div className=\"flex items-center gap-2\">\n              {stopped ? (\n                <span className=\"text-muted-foreground text-sm\">{labels?.clockStopped ?? 'Clock stopped'}</span>\n              ) : (\n                <>\n                  <Button\n                    type=\"button\"\n                    variant=\"ghost\"\n                    size=\"sm\"\n                    onClick={() => {\n                      setStopped(true);\n                      setDeadline(null);\n                    }}\n                  >\n                    {labels?.stopClock ?? 'Stop the clock'}\n                  </Button>\n                  <TimerRing\n                    seconds={timeLimit as number}\n                    deadline={deadline}\n                    onExpire={() => answer(null)}\n                    labels={labels?.timer}\n                  />\n                </>\n              )}\n            </div>\n          ) : null}\n        </div>\n      ) : null}\n\n      <p id={promptId} data-slot=\"quiz-question-prompt\" className=\"font-heading text-xl font-semibold text-balance\">\n        {question}\n      </p>\n\n      <div\n        ref={groupRef}\n        role=\"group\"\n        aria-labelledby={promptId}\n        data-slot=\"quiz-question-choices\"\n        className=\"grid grid-cols-1 gap-3 @md:grid-cols-2\"\n      >\n        {choices.map((c, i) => {\n          const mark = markOf(c.id);\n          const key = i < 9 ? String(i + 1) : undefined;\n          return (\n            <button\n              key={c.id}\n              type=\"button\"\n              data-slot=\"quiz-question-choice\"\n              data-key={key}\n              data-mark={mark}\n              aria-keyshortcuts={key}\n              disabled={revealed}\n              onClick={() => answer(c.id)}\n              className={cn(\n                'group/choice relative flex min-h-16 items-center gap-3 rounded-lg border-2 px-4 py-3 text-start text-base font-medium',\n                'bg-card text-card-foreground border-border',\n                'focus-visible:outline-ring outline-offset-2 focus-visible:outline-2',\n                'motion-safe:transition-[transform,background-color,border-color,opacity] motion-safe:duration-(--duration-fast)',\n                !revealed && 'hover:bg-accent hover:border-primary cursor-pointer motion-safe:active:scale-[0.98]',\n                mark === 'correct' && 'border-success bg-success/10',\n                mark === 'wrong' && 'border-destructive bg-destructive/10',\n                revealed && !mark && 'opacity-60',\n                'disabled:cursor-default',\n              )}\n            >\n              {key ? (\n                <span\n                  aria-hidden\n                  className={cn(\n                    'grid size-8 shrink-0 place-items-center rounded-md text-sm font-semibold tabular-nums',\n                    mark === 'correct'\n                      ? 'bg-success text-success-foreground'\n                      : mark === 'wrong'\n                        ? 'bg-destructive text-destructive-foreground'\n                        : 'bg-muted text-muted-foreground',\n                  )}\n                >\n                  {mark === 'correct' ? (\n                    <Check className=\"size-4\" strokeWidth={3} />\n                  ) : mark === 'wrong' ? (\n                    <X className=\"size-4\" strokeWidth={3} />\n                  ) : (\n                    key\n                  )}\n                </span>\n              ) : null}\n              <span className=\"min-w-0 flex-1\">{c.label}</span>\n              {mark ? (\n                <span className=\"sr-only\">\n                  {mark === 'correct' ? `, ${labels?.tally?.correct ?? 'Right answer'}` : `, ${labels?.tally?.mine ?? 'Your answer'}`}\n                </span>\n              ) : null}\n            </button>\n          );\n        })}\n      </div>\n\n      <p\n        ref={resultRef}\n        tabIndex={-1}\n        data-slot=\"quiz-question-result\"\n        aria-live=\"polite\"\n        aria-describedby={revealed && explanation ? explanationId : undefined}\n        className={cn(\n          'focus-visible:outline-ring rounded-sm text-base font-semibold outline-offset-4 empty:hidden focus-visible:outline-2',\n          revealed && result.outcome === 'correct' ? 'text-success' : 'text-foreground',\n        )}\n      >\n        {revealed\n          ? (labels?.result ?? RESULT)({\n              outcome: result.outcome,\n              points: result.points,\n              answer: correctChoice ? textOf(correctChoice) : correct,\n            })\n          : ''}\n      </p>\n\n      {spread ? (\n        <section data-slot=\"quiz-question-spread\" aria-label={labels?.spread ?? 'How everyone answered'} className=\"grid gap-2\">\n          <p className=\"text-muted-foreground text-xs font-semibold tracking-wide uppercase\">\n            {labels?.spread ?? 'How everyone answered'}\n          </p>\n          <TallyBars\n            rows={spread.rows}\n            optionLabels={Object.fromEntries(choices.map((c) => [c.id, c.label]))}\n            marks={Object.fromEntries(choices.flatMap((c) => (markOf(c.id) ? [[c.id, markOf(c.id) as TallyMark]] : [])))}\n            locale={locale}\n            labels={labels?.tally}\n          />\n        </section>\n      ) : null}\n\n      {explanation ? (\n        <div\n          data-slot=\"quiz-question-explanation\"\n          className={cn(\n            'grid',\n            'motion-safe:transition-[grid-template-rows,opacity] motion-safe:duration-(--duration-medium) motion-safe:ease-enter',\n            revealed ? 'grid-rows-[1fr] opacity-100' : 'grid-rows-[0fr] opacity-0',\n          )}\n          inert={revealed ? undefined : true}\n        >\n          <div id={explanationId} className=\"text-muted-foreground -m-1 min-h-0 overflow-hidden p-1 text-sm leading-relaxed\">\n            {explanation}\n          </div>\n        </div>\n      ) : null}\n    </div>\n  );\n}\nQuizQuestion.displayName = 'QuizQuestion';\n\nexport { QuizQuestion };\nexport type { QuizQuestionProps, QuizChoice, QuizQuestionLabels };\n"
    },
    {
      "path": "registry/interlace-ui/games/quiz-model.ts",
      "target": "components/ui/games/quiz-model.ts",
      "type": "registry:ui",
      "content": "export type QuizOutcome = 'correct' | 'wrong' | 'timeout';\n\nexport interface QuizScoreOptions {\n  /** Points for a right answer given at once. @default 1000 */\n  maxPoints?: number;\n  /** Share of the points that depends on speed, 0–1. @default 0.5 */\n  speedShare?: number;\n}\n\nexport interface QuizAnswerInput {\n  /** The chosen option's id; null when time ran out first. */\n  choice: string | null;\n  /** Milliseconds from the start to the answer. Leave out when the clock was stopped. */\n  elapsedMs?: number;\n  /** The question's time limit in milliseconds. Leave out for an untimed question. */\n  limitMs?: number;\n}\n\nexport interface QuizResult {\n  choice: string | null;\n  correct: string;\n  outcome: QuizOutcome;\n  points: number;\n  /** Whether the answer raced a running clock (the speed share was in play). */\n  timed: boolean;\n  elapsedMs?: number;\n}\n\nconst clamp01 = (n: number) => Math.min(1, Math.max(0, n));\n\n/** Score one answer against the right option's id. */\nexport function scoreAnswer(input: QuizAnswerInput, correct: string, options: QuizScoreOptions = {}): QuizResult {\n  // A host config that is NaN, infinite or negative would score NaN and poison the standings: use the defaults.\n  const maxPoints = Number.isFinite(options.maxPoints) && (options.maxPoints as number) >= 0 ? (options.maxPoints as number) : 1000;\n  const speedShare = clamp01(Number.isFinite(options.speedShare) ? (options.speedShare as number) : 0.5);\n  const { choice, elapsedMs, limitMs } = input;\n  const limited = typeof limitMs === 'number' && limitMs > 0;\n  const timed = limited && Number.isFinite(elapsedMs);\n  const outcome: QuizOutcome = choice === null ? 'timeout' : choice === correct ? 'correct' : 'wrong';\n  let points = 0;\n  if (outcome === 'correct') {\n    const base = limited ? maxPoints * (1 - speedShare) : maxPoints;\n    const speed = timed ? maxPoints * speedShare * (1 - clamp01((elapsedMs as number) / (limitMs as number))) : 0;\n    points = Math.round(base + speed);\n  }\n  return { choice, correct, outcome, points, timed, ...(timed ? { elapsedMs } : {}) };\n}\n\n/**\n * @interlace/ui — games/quiz-model\n *\n * Scoring for a multiple-choice question, with an optional clock. Pure, so a\n * server can score the same answer and a share card can show right or wrong\n * without the answer itself.\n *\n * ## Points\n *\n * A right answer is worth `maxPoints`. When the question was timed, part of\n * that (`speedShare`, half by default) depends on speed: answering at once\n * keeps all of it, answering as the clock runs out keeps none of it. A wrong\n * answer, or no answer before time ran out, is worth 0.\n *\n * A question with no time limit is worth the full `maxPoints`. When a timed\n * question's clock was stopped (a player can always stop it; see QuizQuestion)\n * the answer keeps the part that does not depend on speed, so stopping the\n * clock is always available and never pays more than racing it.\n */\n"
    },
    {
      "path": "registry/interlace-ui/games/tally-model.ts",
      "target": "components/ui/games/tally-model.ts",
      "type": "registry:ui",
      "content": "export interface TallyRow {\n  id: string;\n  count: number;\n  /** count / total, 0–1. 0 when nobody has voted. */\n  share: number;\n  /** Whole percent; the rows sum to 100 when total > 0. */\n  percent: number;\n  /** The viewer's own choice. */\n  mine: boolean;\n  /** Has the highest count (ties all lead). False when nobody has voted. */\n  leading: boolean;\n}\n\nexport interface TallyOptions {\n  /** The viewer's choice, if any. */\n  vote?: string | null;\n  /** The counts already include the viewer's vote. @default false */\n  countsIncludeVote?: boolean;\n}\n\nexport interface Tally {\n  rows: TallyRow[];\n  total: number;\n}\n\n/** Largest count kept per option, so a hostile 1e308 can never push a total to Infinity. */\nconst MAX_COUNT = 1e12;\n\nconst clampCount = (n: number): number =>\n  Number.isFinite(n) ? Math.min(Math.max(Math.floor(n), 0), MAX_COUNT) : 0;\n\n/** Whole percents that sum to 100 (largest remainder). All 0 when the total is 0. */\nexport function wholePercents(input: readonly number[]): number[] {\n  const counts = input.map(clampCount);\n  const total = counts.reduce((a, b) => a + b, 0);\n  if (!(total > 0)) return counts.map(() => 0);\n  const exact = counts.map((c) => (c / total) * 100);\n  const out = exact.map(Math.floor);\n  let left = 100 - out.reduce((a, b) => a + b, 0);\n  const order = exact\n    .map((e, i) => ({ i, rest: e - Math.floor(e) }))\n    // Biggest remainder first; on a tie the earlier option wins, so the result is stable.\n    .sort((a, b) => b.rest - a.rest || a.i - b.i);\n  for (const { i } of order) {\n    if (left <= 0) break;\n    out[i] = (out[i] as number) + 1;\n    left -= 1;\n  }\n  return out;\n}\n\n/** The rows for `ids`, in that order. Unknown ids count 0; negative or non-finite counts count 0. */\nexport function tally(\n  ids: readonly string[],\n  counts: Readonly<Record<string, number>> = {},\n  options: TallyOptions = {},\n): Tally {\n  const { vote = null, countsIncludeVote = false } = options;\n  // A repeated id would be counted twice; an inherited count is not a vote.\n  ids = [...new Set(ids)];\n  const raw = ids.map((id) => {\n    const n = Object.prototype.hasOwnProperty.call(counts, id) ? (counts[id] as number) : 0;\n    const base = clampCount(n);\n    return id === vote && !countsIncludeVote ? base + 1 : base;\n  });\n  const total = raw.reduce((a, b) => a + b, 0);\n  const percents = wholePercents(raw);\n  const top = raw.reduce((a, b) => Math.max(a, b), -Infinity);\n  return {\n    total,\n    rows: ids.map((id, i) => ({\n      id,\n      count: raw[i] as number,\n      share: total > 0 ? (raw[i] as number) / total : 0,\n      percent: percents[i] as number,\n      mine: vote !== null && id === vote,\n      leading: (raw[i] as number) > 0 && raw[i] === top,\n    })),\n  };\n}\n\n/**\n * @interlace/ui — games/tally-model\n *\n * Counts per option turned into shares a reader can trust: whole percents\n * that add up to exactly 100, the viewer's own choice included once, and the\n * leading option named. Pure, so a server can return the same numbers the\n * client draws, and a poll and a quiz share one rule.\n *\n * ## Percents that add up\n *\n * Rounding each share on its own can give 33 + 33 + 33 = 99. The largest\n * remainder method hands the missing points to the options that lost the\n * most to rounding, so the column always sums to 100 (or to 0 when nobody\n * has voted).\n *\n * ## The viewer's vote\n *\n * A poll usually knows the tally from the server and the viewer's choice\n * from the tap that just happened. Pass the server counts with\n * `countsIncludeVote: false` (the default) and the viewer's vote is added\n * once, so the bars move the moment they tap. When the server's counts\n * already hold it (a reload), pass `countsIncludeVote: true`.\n */\n"
    }
  ],
  "meta": {
    "tier": "game",
    "client": true,
    "minViewport": 320,
    "loading": false,
    "version": "1.0.1",
    "since": "2.0.0"
  },
  "docs": "## @interlace/quiz-question\n\nInstalled to `components/ui/games/quiz-question.tsx`.\n\n```tsx\nimport { /* … */ } from '@/components/ui/games/quiz-question';\n```\n\nProps, a11y contract, live preview and source: https://ds.interlace.tools/c/quiz-question\n\nRequires the `@interlace/interlace-base` CSS baseline (installed automatically as a registry dependency). For the Interlace look, also add `@interlace/theme`."
}
