{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "cassette-player",
  "title": "Cassette Player",
  "author": "VenusUI",
  "description": "A cassette tape whose reels turn and wind the tape from one side to the other as it plays.",
  "dependencies": [
    "lucide-react"
  ],
  "files": [
    {
      "path": "registry/default/ui/cassette-player.tsx",
      "content": "\"use client\"\n\nimport * as React from \"react\"\nimport { Pause, Play, Rewind } from \"lucide-react\"\n\nimport { cn } from \"@/lib/utils\"\n\ninterface CassettePlayerProps extends React.ComponentProps<\"div\"> {\n  title: string\n  artist: string\n  /** Track length in seconds. */\n  duration?: number\n  /** e.g. \"A\" or \"B\". */\n  side?: string\n  /** Label stripe color: any CSS color. */\n  accent?: string\n  playing?: boolean\n  defaultPlaying?: boolean\n  onPlayingChange?: (playing: boolean) => void\n}\n\nconst HANDWRITING = '\"Segoe Print\", \"Bradley Hand\", \"Marker Felt\", \"Chalkboard SE\", cursive'\nconst TICK = 250\n\nconst time = (seconds: number) => `${Math.floor(seconds / 60)}:${String(Math.floor(seconds % 60)).padStart(2, \"0\")}`\n\n/** A reel: the tape wound on it (sized by how much it holds) and a toothed hub. */\nfunction Reel({ amount, spinning }: { amount: number; spinning: boolean }) {\n  // The tape pack grows from just around the hub (0) to nearly the window edge (1).\n  const pack = 48 + amount * 46\n  return (\n    <span className=\"relative grid aspect-square w-[24%] place-items-center\">\n      <span\n        aria-hidden=\"true\"\n        className=\"absolute rounded-full bg-[radial-gradient(circle,#4a2f1f_0%,#2b1a10_70%,#3a2416_100%)] transition-[width,height] duration-300\"\n        style={{ width: `${pack}%`, height: `${pack}%` }}\n      />\n      <span\n        aria-hidden=\"true\"\n        className=\"relative grid size-[44%] animate-spin place-items-center rounded-full bg-neutral-100 shadow-[0_0_0_2px_rgb(0_0_0/0.25)] motion-reduce:animate-none\"\n        style={{ animationDuration: \"2.4s\", animationPlayState: spinning ? \"running\" : \"paused\" }}\n      >\n        {[0, 60, 120, 180, 240, 300].map((angle) => (\n          <span key={angle} className=\"absolute h-[22%] w-[12%] rounded-sm bg-neutral-100\" style={{ transform: `rotate(${angle}deg) translateY(-155%)` }} />\n        ))}\n        <span className=\"size-[46%] rounded-full bg-neutral-800\" />\n      </span>\n    </span>\n  )\n}\n\n/**\n * A cassette tape. Press play and both reels turn while the tape winds from\n * one reel to the other. It plays no audio: connect `onPlayingChange` to\n * your own player.\n */\nfunction CassettePlayer({\n  title,\n  artist,\n  duration = 214,\n  side = \"A\",\n  accent = \"oklch(0.72 0.17 35)\",\n  playing: playingProp,\n  defaultPlaying = false,\n  onPlayingChange,\n  className,\n  ...props\n}: CassettePlayerProps) {\n  const [uncontrolled, setUncontrolled] = React.useState(defaultPlaying)\n  const playing = playingProp ?? uncontrolled\n  const [elapsed, setElapsedState] = React.useState(0)\n  const elapsedRef = React.useRef(0)\n  const setElapsed = (value: number) => {\n    elapsedRef.current = value\n    setElapsedState(value)\n  }\n\n  const setPlaying = React.useCallback(\n    (next: boolean) => {\n      setUncontrolled(next)\n      onPlayingChange?.(next)\n    },\n    [onPlayingChange]\n  )\n\n  React.useEffect(() => {\n    if (!playing) return\n    const id = setInterval(() => {\n      const next = elapsedRef.current + TICK / 1000\n      if (next >= duration) {\n        elapsedRef.current = 0\n        setElapsedState(0)\n        setPlaying(false)\n      } else {\n        elapsedRef.current = next\n        setElapsedState(next)\n      }\n    }, TICK)\n    return () => clearInterval(id)\n  }, [playing, duration, setPlaying])\n\n  const progress = elapsed / duration\n\n  return (\n    <div data-slot=\"cassette-player\" className={cn(\"@container flex w-full max-w-md flex-col items-center gap-5 select-none\", className)} {...props}>\n      {/* Shell */}\n      <div\n        className=\"relative aspect-[1.6] w-full rounded-[4%/6.5%] bg-linear-to-b from-neutral-800 to-neutral-900 p-[4%] shadow-[0_1px_0_rgb(255_255_255/0.08)_inset,0_24px_40px_-20px_rgb(0_0_0/0.6)]\"\n        style={{ \"--accent\": accent } as React.CSSProperties}\n      >\n        {/* Corner screws */}\n        {[\"top-[3%] left-[2.2%]\", \"top-[3%] right-[2.2%]\", \"bottom-[3%] left-[2.2%]\", \"bottom-[3%] right-[2.2%]\"].map((pos) => (\n          <span key={pos} aria-hidden=\"true\" className={cn(\"absolute size-[2.4%] rounded-full bg-neutral-500 shadow-inner\", pos)} />\n        ))}\n\n        {/* Label */}\n        <div className=\"relative flex h-[72%] flex-col overflow-hidden rounded-[3%/5%] bg-[#f3eee2] px-[5%] pt-[3%] text-neutral-800\">\n          <div className=\"flex items-baseline justify-between gap-3\">\n            <p className=\"truncate text-[clamp(0.9rem,4.4cqw,1.35rem)] leading-tight\" style={{ fontFamily: HANDWRITING }}>\n              {title}\n            </p>\n            <span className=\"shrink-0 font-mono text-[clamp(0.65rem,2.6cqw,0.85rem)] font-bold\">SIDE {side}</span>\n          </div>\n          <p className=\"truncate text-[clamp(0.7rem,3cqw,0.95rem)] text-neutral-600\" style={{ fontFamily: HANDWRITING }}>\n            {artist}\n          </p>\n          {/* Stripes */}\n          <span aria-hidden=\"true\" className=\"mt-[2%] h-[7%] bg-(--accent)\" />\n          <span aria-hidden=\"true\" className=\"mt-[1.5%] h-[4%] bg-(--accent) opacity-60\" />\n          {/* Window with the reels */}\n          <div aria-hidden=\"true\" className=\"mx-auto mt-[4%] flex h-[46%] w-[78%] items-center justify-between rounded-full bg-neutral-900/90 px-[6%] shadow-[inset_0_2px_6px_rgb(0_0_0/0.6)]\">\n            <Reel amount={1 - progress} spinning={playing} />\n            <span className=\"h-[2px] flex-1 bg-[#3a2416]\" />\n            <Reel amount={progress} spinning={playing} />\n          </div>\n        </div>\n\n        {/* Bottom edge with the tape guides */}\n        <div aria-hidden=\"true\" className=\"absolute inset-x-[18%] bottom-0 h-[18%] bg-neutral-700 [clip-path:polygon(8%_0,92%_0,100%_100%,0_100%)]\">\n          <span className=\"absolute top-[35%] left-[18%] size-[18%] rounded-full bg-neutral-900\" />\n          <span className=\"absolute top-[35%] right-[18%] size-[18%] rounded-full bg-neutral-900\" />\n        </div>\n      </div>\n\n      {/* Controls */}\n      <div className=\"flex w-full items-center justify-between gap-4 px-1\">\n        <div className=\"min-w-0\">\n          <p className=\"truncate text-sm font-medium\">{title}</p>\n          <p className=\"truncate text-sm text-muted-foreground\">{artist}</p>\n        </div>\n        <div className=\"flex shrink-0 items-center gap-2\">\n          <span className=\"font-mono text-xs text-muted-foreground tabular-nums\">\n            {time(elapsed)} / {time(duration)}\n          </span>\n          <button\n            type=\"button\"\n            aria-label=\"Rewind\"\n            onClick={() => setElapsed(0)}\n            className=\"grid size-9 place-items-center rounded-full border outline-none hover:bg-muted focus-visible:ring-3 focus-visible:ring-ring/50\"\n          >\n            <Rewind aria-hidden=\"true\" className=\"size-4 fill-current\" />\n          </button>\n          <button\n            type=\"button\"\n            aria-label={playing ? \"Pause\" : `Play ${title}`}\n            onClick={() => setPlaying(!playing)}\n            className=\"grid size-10 place-items-center rounded-full bg-foreground text-background outline-none hover:bg-foreground/90 focus-visible:ring-3 focus-visible:ring-ring/50\"\n          >\n            {playing ? <Pause aria-hidden=\"true\" className=\"size-4 fill-current\" /> : <Play aria-hidden=\"true\" className=\"ml-0.5 size-4 fill-current\" />}\n          </button>\n        </div>\n      </div>\n    </div>\n  )\n}\n\nexport { CassettePlayer }\n",
      "type": "registry:ui"
    }
  ],
  "meta": {
    "version": "0.1.0"
  },
  "categories": [
    "interactive",
    "animations"
  ],
  "type": "registry:ui"
}