{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "dice-roller",
  "title": "Dice Roller",
  "author": "VenusUI",
  "description": "3D dice that tumble and land on a fair, random face, with the total announced.",
  "files": [
    {
      "path": "registry/default/ui/dice-roller.tsx",
      "content": "\"use client\"\n\nimport * as React from \"react\"\n\nimport { cn } from \"@/lib/utils\"\n\ninterface DiceRollerProps extends React.ComponentProps<\"div\"> {\n  /** How many dice. */\n  count?: number\n  onRoll?: (values: number[]) => void\n}\n\n/** Pip positions on a 3 × 3 grid for each face. */\nconst PIPS: Record<number, number[]> = { 1: [4], 2: [0, 8], 3: [0, 4, 8], 4: [0, 2, 6, 8], 5: [0, 2, 4, 6, 8], 6: [0, 2, 3, 5, 6, 8] }\n/** Rotation that brings each face to the front. */\nconst FACE: Record<number, [number, number]> = { 1: [0, 0], 2: [0, -90], 3: [-90, 0], 4: [90, 0], 5: [0, 90], 6: [0, 180] }\nconst SIDES: { value: number; transform: string }[] = [\n  { value: 1, transform: \"rotateY(0deg)\" },\n  { value: 2, transform: \"rotateY(90deg)\" },\n  { value: 3, transform: \"rotateX(90deg)\" },\n  { value: 4, transform: \"rotateX(-90deg)\" },\n  { value: 5, transform: \"rotateY(-90deg)\" },\n  { value: 6, transform: \"rotateY(180deg)\" },\n]\n\n/**\n * Dice that tumble in 3D. Press Roll (or a die) and each lands on a fair,\n * random face. The total is announced for screen readers.\n */\nfunction DiceRoller({ count = 2, onRoll, className, ...props }: DiceRollerProps) {\n  const [dice, setDice] = React.useState(() =>\n    Array.from({ length: count }, (_, i) => {\n      const value = ((i * 3 + 4) % 6) + 1\n      return { value, x: FACE[value][0], y: FACE[value][1] }\n    })\n  )\n  const [rolls, setRolls] = React.useState(0)\n\n  const roll = () => {\n    const next = dice.map((die) => {\n      const value = 1 + Math.floor(Math.random() * 6)\n      const [fx, fy] = FACE[value]\n      const spins = 2 + Math.floor(Math.random() * 2)\n      return { value, x: Math.ceil(die.x / 360) * 360 + spins * 360 + fx, y: Math.ceil(die.y / 360) * 360 + spins * 360 + fy }\n    })\n    setDice(next)\n    setRolls((value) => value + 1)\n    onRoll?.(next.map((die) => die.value))\n  }\n\n  const total = dice.reduce((sum, die) => sum + die.value, 0)\n\n  return (\n    <div data-slot=\"dice-roller\" className={cn(\"flex flex-col items-center gap-6\", className)} {...props}>\n      <div className=\"flex gap-8 [perspective:600px]\">\n        {dice.map((die, i) => (\n          <button\n            key={i}\n            type=\"button\"\n            onClick={roll}\n            aria-label={`Die ${i + 1}: ${die.value}. Press to roll.`}\n            className=\"relative size-16 outline-none [transform-style:preserve-3d] transition-transform duration-[1200ms] ease-[cubic-bezier(.2,.7,.3,1)] focus-visible:ring-3 focus-visible:ring-ring/60 motion-reduce:transition-none\"\n            style={{ transform: `rotateX(${die.x}deg) rotateY(${die.y}deg)` }}\n          >\n            {SIDES.map((side) => (\n              <span\n                key={side.value}\n                aria-hidden=\"true\"\n                className=\"absolute inset-0 grid grid-cols-3 grid-rows-3 place-items-center rounded-xl bg-linear-145 from-white to-neutral-200 p-2 shadow-[inset_0_0_0_1px_rgb(0_0_0/0.08),inset_0_-4px_8px_rgb(0_0_0/0.1)] [backface-visibility:hidden]\"\n                style={{ transform: `${side.transform} translateZ(32px)` }}\n              >\n                {Array.from({ length: 9 }, (_, cell) => (\n                  <span key={cell} className={cn(\"size-2.5 rounded-full\", PIPS[side.value].includes(cell) ? (side.value === 1 ? \"size-3.5 bg-red-600\" : \"bg-neutral-900\") : \"\")} />\n                ))}\n              </span>\n            ))}\n          </button>\n        ))}\n      </div>\n      <div className=\"flex items-center gap-3\">\n        <button type=\"button\" onClick={roll} className=\"rounded-md bg-primary px-4 py-1.5 text-sm font-medium text-primary-foreground outline-none hover:bg-primary/90 focus-visible:ring-3 focus-visible:ring-ring/50\">\n          Roll\n        </button>\n        <p role=\"status\" className=\"font-mono text-sm tabular-nums\">\n          {rolls ? `${dice.map((die) => die.value).join(\" + \")} = ${total}` : \"Ready\"}\n        </p>\n      </div>\n    </div>\n  )\n}\n\nexport { DiceRoller }\n",
      "type": "registry:ui"
    }
  ],
  "meta": {
    "version": "0.1.0"
  },
  "categories": [
    "interactive",
    "animations"
  ],
  "type": "registry:ui"
}