{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"media-card","type":"registry:ui","title":"Media Card","description":"Music player card with cover art, a scrubbable progress bar, a morphing play/pause icon and a live equalizer.","dependencies":["motion","lucide-react"],"registryDependencies":["utils"],"files":[{"path":"registry/ui/media-card.tsx","type":"registry:ui","content":"\"use client\";\n\nimport { useEffect, useRef, useState, type CSSProperties } from \"react\";\nimport { AnimatePresence, motion, useReducedMotion } from \"motion/react\";\nimport { Heart, Repeat, Shuffle, SkipBack, SkipForward } from \"lucide-react\";\nimport { cn } from \"@/lib/utils\";\n\nexport interface MediaTrack {\n  title: string;\n  artist: string;\n  cover: string;\n  /** Length in seconds. */\n  duration: number;\n}\n\nexport interface MediaCardProps {\n  tracks: MediaTrack[];\n  /** Accent color for progress, play button and equalizer. */\n  accent?: string;\n  /** Start playing on mount. */\n  autoPlay?: boolean;\n  /** Number of equalizer bars. */\n  bars?: number;\n  /** Blurred cover glow behind the card. */\n  glow?: boolean;\n  className?: string;\n}\n\nconst css = `\n@keyframes media-card-eq{0%,100%{transform:scaleY(.25)}50%{transform:scaleY(1)}}\n.media-card-bar{transform:scaleY(.25);transform-origin:bottom;transition:transform .3s}\n.media-card-eq[data-on] .media-card-bar{animation:media-card-eq var(--d) ease-in-out infinite var(--delay)}\n@media (prefers-reduced-motion:reduce){.media-card-eq[data-on] .media-card-bar{animation:none;transform:scaleY(.6)}}\n.media-card-range{appearance:none;-webkit-appearance:none;background:transparent;cursor:pointer}\n.media-card-range::-webkit-slider-thumb{-webkit-appearance:none;width:14px;height:14px;opacity:0}\n.media-card-range::-moz-range-thumb{width:14px;height:14px;opacity:0;border:0}\n`;\n\n// Both icons are two 4-point shapes, so the path strings interpolate point by point.\nconst PLAY = [\"M8 5 L13 8.2 L13 15.8 L8 19 Z\", \"M13 8.2 L19 12 L19 12 L13 15.8 Z\"];\nconst PAUSE = [\"M7 5 L10.5 5 L10.5 19 L7 19 Z\", \"M13.5 5 L17 5 L17 19 L13.5 19 Z\"];\n\nconst fmt = (s: number) => `${Math.floor(s / 60)}:${String(Math.floor(s % 60)).padStart(2, \"0\")}`;\n// Deterministic pseudo-random timing per bar.\nconst barTiming = (i: number) => ({ d: 0.7 + ((i * 37) % 9) / 16, delay: -((i * 53) % 7) / 10 });\n\nexport function MediaCard({ tracks, accent = \"#a3e635\", autoPlay = false, bars = 4, glow = true, className }: MediaCardProps) {\n  const [index, setIndex] = useState(0);\n  const [playing, setPlaying] = useState(autoPlay);\n  const [time, setTime] = useState(0);\n  const [liked, setLiked] = useState<Set<number>>(() => new Set());\n  const [shuffle, setShuffle] = useState(false);\n  const [repeat, setRepeat] = useState(false);\n  const [scrubbing, setScrubbing] = useState(false);\n  const timeRef = useRef(0);\n  const reduce = useReducedMotion();\n  const n = tracks.length;\n  const i = Math.min(index, n - 1);\n  const track = tracks[i];\n\n  const seek = (t: number) => {\n    timeRef.current = t;\n    setTime(t);\n  };\n  const go = (step: number) => {\n    setIndex((cur) => {\n      if (repeat && step === 0) return cur;\n      if (shuffle && n > 1) return (cur + 1 + ((cur * 7 + 3) % (n - 1))) % n;\n      return (cur + (step || 1) + n) % n;\n    });\n    seek(0);\n  };\n  const goRef = useRef(go);\n  useEffect(() => {\n    goRef.current = go;\n  });\n\n  useEffect(() => {\n    if (!playing || scrubbing) return;\n    const id = window.setInterval(() => {\n      const next = timeRef.current + 0.25;\n      if (next >= track.duration) goRef.current(0);\n      else seek(next);\n    }, 250);\n    return () => window.clearInterval(id);\n  }, [playing, scrubbing, track.duration]);\n\n  const pct = (time / track.duration) * 100;\n  const isLiked = liked.has(i);\n  const iconBtn =\n    \"grid size-9 place-items-center rounded-full text-muted-foreground outline-none transition-colors hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring\";\n\n  return (\n    <div className={cn(\"relative w-80\", className)} style={{ \"--accent\": accent } as CSSProperties}>\n      <style href=\"media-card\" precedence=\"default\">\n        {css}\n      </style>\n      {glow && (\n        <AnimatePresence>\n          <motion.img\n            key={track.cover}\n            src={track.cover}\n            alt=\"\"\n            aria-hidden\n            className=\"pointer-events-none absolute inset-x-6 top-6 aspect-square w-[calc(100%-3rem)] rounded-full object-cover blur-3xl\"\n            initial={{ opacity: 0 }}\n            animate={{ opacity: playing ? 0.55 : 0.3 }}\n            exit={{ opacity: 0 }}\n            transition={{ duration: 0.8 }}\n          />\n        </AnimatePresence>\n      )}\n\n      <div className=\"relative rounded-[28px] border border-border bg-card/85 p-4 shadow-2xl backdrop-blur-xl\">\n        <div className=\"relative aspect-square overflow-hidden rounded-2xl bg-muted\">\n          <AnimatePresence initial={false}>\n            <motion.img\n              key={track.cover}\n              src={track.cover}\n              alt={`${track.title} cover art`}\n              draggable={false}\n              className=\"absolute inset-0 size-full object-cover\"\n              initial={reduce ? { opacity: 0 } : { opacity: 0, scale: 1.08 }}\n              animate={{ opacity: 1, scale: playing || reduce ? 1 : 0.96 }}\n              exit={{ opacity: 0 }}\n              transition={{ type: \"spring\", stiffness: 180, damping: 26 }}\n              style={{ borderRadius: 16 }}\n            />\n          </AnimatePresence>\n        </div>\n\n        <div className=\"mt-4 flex items-start gap-3\">\n          <div className=\"min-w-0 flex-1\">\n            <AnimatePresence mode=\"wait\" initial={false}>\n              <motion.div\n                key={i}\n                initial={reduce ? false : { opacity: 0, y: 6 }}\n                animate={{ opacity: 1, y: 0 }}\n                exit={{ opacity: 0, y: -6 }}\n                transition={{ duration: 0.2 }}\n              >\n                <p className=\"truncate text-base font-semibold tracking-tight text-foreground\">{track.title}</p>\n                <p className=\"truncate text-sm text-muted-foreground\">{track.artist}</p>\n              </motion.div>\n            </AnimatePresence>\n          </div>\n          <div aria-hidden className=\"media-card-eq mt-1.5 flex h-4 items-end gap-[3px]\" data-on={playing || undefined}>\n            {Array.from({ length: bars }, (_, b) => {\n              const t = barTiming(b);\n              return (\n                <span\n                  key={b}\n                  className=\"media-card-bar w-[3px] rounded-full\"\n                  style={{ height: \"100%\", background: \"var(--accent)\", \"--d\": `${t.d}s`, \"--delay\": `${t.delay}s` } as CSSProperties}\n                />\n              );\n            })}\n          </div>\n          <button\n            type=\"button\"\n            aria-pressed={isLiked}\n            aria-label={isLiked ? \"Remove from liked\" : \"Like\"}\n            onClick={() =>\n              setLiked((s) => {\n                const next = new Set(s);\n                if (next.has(i)) next.delete(i);\n                else next.add(i);\n                return next;\n              })\n            }\n            className={cn(iconBtn, \"-mt-1 -mr-1\")}\n          >\n            <motion.span\n              key={String(isLiked)}\n              initial={reduce || !isLiked ? false : { scale: 0.6 }}\n              animate={{ scale: 1 }}\n              transition={{ type: \"spring\", stiffness: 500, damping: 12 }}\n              className=\"grid\"\n            >\n              <Heart className={cn(\"size-5\", isLiked && \"fill-rose-500 text-rose-500\")} />\n            </motion.span>\n          </button>\n        </div>\n\n        <div className=\"group relative mt-4 h-4\">\n          <div className=\"absolute inset-x-0 top-1/2 h-1 -translate-y-1/2 overflow-hidden rounded-full bg-muted transition-[height] group-hover:h-1.5\">\n            <div\n              className=\"h-full rounded-full\"\n              style={{ width: `${pct}%`, background: \"var(--accent)\", transition: scrubbing || time === 0 ? \"none\" : \"width .25s linear\" }}\n            />\n          </div>\n          <div\n            aria-hidden\n            className=\"pointer-events-none absolute top-1/2 size-3 -translate-x-1/2 -translate-y-1/2 scale-0 rounded-full bg-foreground shadow transition-transform group-hover:scale-100 group-has-focus-visible:scale-100\"\n            style={{ left: `${pct}%`, transition: scrubbing || time === 0 ? \"transform .15s\" : \"left .25s linear, transform .15s\" }}\n          />\n          <input\n            type=\"range\"\n            min={0}\n            max={track.duration}\n            step={1}\n            value={Math.floor(time)}\n            aria-label=\"Seek\"\n            aria-valuetext={`${fmt(time)} of ${fmt(track.duration)}`}\n            onChange={(e) => seek(Number(e.target.value))}\n            onPointerDown={() => setScrubbing(true)}\n            onPointerUp={() => setScrubbing(false)}\n            onBlur={() => setScrubbing(false)}\n            className=\"media-card-range absolute inset-0 w-full outline-none\"\n          />\n        </div>\n        <div className=\"mt-1 flex justify-between text-[11px] tabular-nums text-muted-foreground\">\n          <span>{fmt(time)}</span>\n          <span>-{fmt(track.duration - time)}</span>\n        </div>\n\n        <div className=\"mt-2 flex items-center justify-between\">\n          <button type=\"button\" aria-label=\"Shuffle\" aria-pressed={shuffle} onClick={() => setShuffle((s) => !s)} className={iconBtn}>\n            <Shuffle className=\"size-4\" style={{ color: shuffle ? accent : undefined }} />\n          </button>\n          <button type=\"button\" aria-label=\"Previous track\" onClick={() => (time > 3 ? seek(0) : go(-1))} className={iconBtn}>\n            <SkipBack className=\"size-5 fill-current\" />\n          </button>\n          <motion.button\n            type=\"button\"\n            aria-label={playing ? \"Pause\" : \"Play\"}\n            onClick={() => setPlaying((p) => !p)}\n            whileTap={reduce ? undefined : { scale: 0.9 }}\n            className=\"grid size-14 place-items-center rounded-full text-black shadow-lg outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-card\"\n            style={{ background: accent, boxShadow: `0 10px 30px -8px ${accent}` }}\n          >\n            <svg viewBox=\"0 0 24 24\" className=\"size-6 fill-current\" aria-hidden>\n              {[0, 1].map((k) => (\n                <motion.path\n                  key={k}\n                  initial={false}\n                  animate={{ d: playing ? PAUSE[k] : PLAY[k] }}\n                  transition={reduce ? { duration: 0 } : { type: \"spring\", stiffness: 380, damping: 26 }}\n                />\n              ))}\n            </svg>\n          </motion.button>\n          <button type=\"button\" aria-label=\"Next track\" onClick={() => go(1)} className={iconBtn}>\n            <SkipForward className=\"size-5 fill-current\" />\n          </button>\n          <button type=\"button\" aria-label=\"Repeat track\" aria-pressed={repeat} onClick={() => setRepeat((r) => !r)} className={iconBtn}>\n            <Repeat className=\"size-4\" style={{ color: repeat ? accent : undefined }} />\n          </button>\n        </div>\n      </div>\n    </div>\n  );\n}\n"}]}