{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "now-playing-card",
  "type": "registry:ui",
  "title": "Now Playing Card",
  "description": "A music widget with spinning vinyl album art that morphs into the full cover on hover.",
  "files": [
    {
      "path": "src/registry/ui/now-playing-card.tsx",
      "type": "registry:ui",
      "content": "\"use client\";\n\nimport { isValidElement, useEffect, useState } from \"react\";\nimport Image from \"next/image\";\nimport {\n  animate,\n  motion,\n  useAnimationFrame,\n  useMotionValue,\n  useMotionTemplate,\n  useReducedMotion,\n} from \"motion/react\";\nimport { cn } from \"@/lib/utils\";\n\nexport type NowPlayingImage = { src: string; alt: string };\n\nexport type NowPlayingCardProps = Omit<React.ComponentProps<\"section\">, \"title\"> & {\n  title: React.ReactNode;\n  artist?: React.ReactNode;\n  /** Album art: an image, or any node such as a styled <div> or <svg>. */\n  cover: NowPlayingImage | React.ReactNode;\n  /** Track length in seconds. */\n  duration: number;\n  /** Starting position in seconds. */\n  defaultElapsed?: number;\n  /** Playing (controlled). When playing, the disc spins and the clock ticks. */\n  playing?: boolean;\n  defaultPlaying?: boolean;\n  /** Any CSS color for the progress bar and equalizer. */\n  accent?: string;\n};\n\n// Seconds per full turn of the disc.\nconst SPIN_PERIOD = 8;\nconst MORPH = { type: \"spring\", duration: 0.5, bounce: 0.15 } as const;\n// Opening keeps the art round while it turns upright (a spinning circle hides the turn),\n// then squares off. Closing rounds it quickly so it reads as a disc again.\nconst RADIUS_OPEN = { duration: 0.5, ease: [0.77, 0, 0.175, 1] } as const;\nconst RADIUS_CLOSE = { duration: 0.3, ease: [0.23, 1, 0.32, 1] } as const;\n\nconst isImage = (value: unknown): value is NowPlayingImage =>\n  typeof value === \"object\" && value !== null && !isValidElement(value) && \"src\" in value;\n\nexport function NowPlayingCard({\n  title,\n  artist,\n  cover,\n  duration,\n  defaultElapsed = 0,\n  playing,\n  defaultPlaying = true,\n  accent = \"#0A6EFF\",\n  className,\n  style,\n  ...props\n}: NowPlayingCardProps) {\n  const reduceMotion = useReducedMotion();\n  const isPlaying = playing ?? defaultPlaying;\n  const elapsed = useElapsed(duration, defaultElapsed, isPlaying);\n\n  // Hover opens the cover for mouse users; a click or tap pins it open or closed.\n  const [hovered, setHovered] = useState(false);\n  const [pinned, setPinned] = useState(false);\n  const expanded = hovered || pinned;\n\n  // The disc's angle lives in a motion value so spinning never re-renders React.\n  const rotate = useMotionValue(0);\n  const discTransform = useMotionTemplate`rotate(${rotate}deg)`;\n\n  useAnimationFrame((_, delta) => {\n    if (expanded || !isPlaying || reduceMotion) return;\n    rotate.set((rotate.get() + (delta / 1000) * (360 / SPIN_PERIOD)) % 360);\n  });\n\n  // Opening settles the art upright along the shorter way round.\n  useEffect(() => {\n    if (!expanded) return;\n    const angle = rotate.get();\n    const controls = animate(rotate, angle > 180 ? 360 : 0, reduceMotion ? { duration: 0 } : MORPH);\n    return () => controls.stop();\n  }, [expanded, reduceMotion, rotate]);\n\n  return (\n    <section\n      data-slot=\"now-playing-card\"\n      aria-label=\"Now playing\"\n      style={{ \"--now-playing-accent\": accent, ...style } as React.CSSProperties}\n      onPointerEnter={(event) => event.pointerType === \"mouse\" && setHovered(true)}\n      onPointerLeave={() => setHovered(false)}\n      className={cn(\n        \"relative isolate aspect-square w-full max-w-sm overflow-hidden rounded-[3rem]\",\n        \"bg-linear-to-b from-neutral-100 to-neutral-300 shadow-xl shadow-black/10 ring-1 ring-black/5\",\n        \"dark:from-neutral-800 dark:to-neutral-900 dark:ring-white/10\",\n        className\n      )}\n      {...props}\n    >\n      {/* The art is a full-card square. Collapsed, it shrinks into a circle centred on the\n          top edge (a disc peeking in); expanded, it becomes the card. Transform + radius only. */}\n      <motion.div\n        aria-hidden\n        initial={false}\n        animate={\n          expanded\n            ? { transform: \"translateY(0%) scale(1)\", borderRadius: \"0%\" }\n            : { transform: \"translateY(-48%) scale(0.9)\", borderRadius: \"50%\" }\n        }\n        transition={\n          reduceMotion\n            ? { duration: 0 }\n            : { ...MORPH, borderRadius: expanded ? RADIUS_OPEN : RADIUS_CLOSE }\n        }\n        className=\"absolute inset-0 z-10 overflow-hidden shadow-[0_24px_48px_-16px_rgb(0_0_0/0.45)]\"\n      >\n        <motion.div style={{ transform: discTransform }} className=\"absolute inset-0\">\n          {isImage(cover) ? (\n            <Image src={cover.src} alt=\"\" fill sizes=\"384px\" className=\"object-cover\" />\n          ) : (\n            cover\n          )}\n        </motion.div>\n\n        {/* Centre hole of the disc; gone once the art opens up. */}\n        <motion.span\n          initial={false}\n          animate={expanded ? { opacity: 0, transform: \"translate(-50%, -50%) scale(0.6)\" } : { opacity: 1, transform: \"translate(-50%, -50%) scale(1)\" }}\n          transition={{ duration: 0.2, ease: [0.23, 1, 0.32, 1] }}\n          className=\"absolute top-1/2 left-1/2 flex size-[30%] items-center justify-center rounded-full bg-neutral-200/90 ring-4 ring-neutral-400/40 dark:bg-neutral-700/90\"\n        >\n          <span className=\"size-1/2 rounded-full bg-neutral-100 ring-1 ring-black/10 dark:bg-neutral-800\" />\n        </motion.span>\n      </motion.div>\n\n      <div className=\"absolute inset-x-0 bottom-0 flex flex-col items-center gap-1.5 px-8 pb-12 text-center\">\n        <Equalizer playing={isPlaying} />\n        {artist && <p className=\"mt-3 truncate text-lg text-muted-foreground\">{artist}</p>}\n        <h3 className=\"max-w-full truncate text-xl font-semibold tracking-tight text-foreground\">{title}</h3>\n        <div\n          role=\"progressbar\"\n          aria-label=\"Playback position\"\n          aria-valuemin={0}\n          aria-valuemax={duration}\n          aria-valuenow={elapsed}\n          aria-valuetext={`${formatTime(elapsed)} of ${formatTime(duration)}`}\n          className=\"mt-1 h-1 w-10 overflow-hidden rounded-full bg-foreground/15\"\n        >\n          <div\n            className=\"h-full origin-left rounded-full bg-[var(--now-playing-accent)] transition-transform duration-1000 ease-linear motion-reduce:transition-none\"\n            style={{ transform: `scaleX(${elapsed / duration})` }}\n          />\n        </div>\n        <p aria-hidden className=\"text-lg font-medium text-foreground tabular-nums\">\n          {formatTime(elapsed)} <span className=\"text-muted-foreground\">/ {formatTime(duration)}</span>\n        </p>\n      </div>\n\n      {/* A full-card button so tap and keyboard users can open the cover too. */}\n      <button\n        type=\"button\"\n        aria-pressed={pinned}\n        aria-label={pinned ? \"Hide album cover\" : \"Show album cover\"}\n        onClick={() => setPinned((value) => !value)}\n        className=\"absolute inset-0 z-20 cursor-pointer rounded-[3rem] outline-none focus-visible:ring-2 focus-visible:ring-[var(--now-playing-accent)] focus-visible:ring-inset\"\n      />\n    </section>\n  );\n}\n\n// Four bars bouncing out of phase; frozen when paused or under reduced motion.\nfunction Equalizer({ playing }: { playing: boolean }) {\n  return (\n    <span aria-hidden className=\"flex h-5 items-center gap-[3px]\">\n      {[0.9, 0.55, 1, 0.7].map((height, i) => (\n        <span\n          key={i}\n          className={cn(\n            \"w-[2px] rounded-full bg-[var(--now-playing-accent)]\",\n            \"animate-[now-playing-bar_900ms_ease-in-out_infinite_alternate] motion-reduce:animate-none\",\n            !playing && \"[animation-play-state:paused]\"\n          )}\n          style={{ height: `${height * 100}%`, animationDelay: `${i * -220}ms` }}\n        />\n      ))}\n      {/* React hoists and dedupes this, so many cards share one rule. */}\n      <style href=\"now-playing-bar\" precedence=\"default\">\n        {`@keyframes now-playing-bar{from{transform:scaleY(.35)}to{transform:scaleY(1)}}`}\n      </style>\n    </span>\n  );\n}\n\n// Ticks once a second while playing and loops at the end of the track.\nfunction useElapsed(duration: number, start: number, playing: boolean) {\n  const [elapsed, setElapsed] = useState(() => Math.min(start, duration));\n  useEffect(() => {\n    if (!playing) return;\n    const timer = setInterval(() => setElapsed((value) => (value + 1) % (duration + 1)), 1000);\n    return () => clearInterval(timer);\n  }, [playing, duration]);\n  return elapsed;\n}\n\nfunction formatTime(seconds: number) {\n  const minutes = Math.floor(seconds / 60);\n  return `${minutes}:${String(Math.floor(seconds % 60)).padStart(2, \"0\")}`;\n}\n"
    }
  ],
  "dependencies": [
    "motion"
  ]
}
