{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"bounce-cards","type":"registry:ui","title":"Bounce Cards","description":"A fanned hand of cards that bounces in, then lifts a card and pushes its neighbors aside on hover or focus.","dependencies":["motion"],"registryDependencies":["https://ui.mekaigames.com/r/theme.json"],"files":[{"path":"components/ui/bounce-cards.tsx","type":"registry:ui","content":"\"use client\";\n\nimport { motion, useReducedMotion } from \"motion/react\";\nimport { useRef, useState, type KeyboardEvent, type ReactNode } from \"react\";\n\nexport type BounceCardItem = {\n  id?: string;\n  /** Image URL, shown as a cover. */\n  src?: string;\n  alt?: string;\n  /** Any card content. Takes priority over src. */\n  content?: ReactNode;\n  /** Accessible name of the card. */\n  label?: string;\n};\n\ntype BounceCardsProps = {\n  items: BounceCardItem[];\n  /** Degrees of rotation between neighboring cards. */\n  spread?: number;\n  /** Seconds between each card's entrance. */\n  stagger?: number;\n  cardWidth?: number;\n  cardHeight?: number;\n  /** How much each card hides under the next, 0 to 0.8. */\n  overlap?: number;\n  /** How far neighbors slide away from the hovered card, in pixels. */\n  push?: number;\n  /** How far the hovered card rises, in pixels. */\n  lift?: number;\n  /** Makes cards buttons and reports the chosen index. */\n  onSelect?: (index: number) => void;\n  /** Accessible name of the hand. */\n  label?: string;\n  className?: string;\n};\n\nfunction Media({ item }: { item: BounceCardItem }) {\n  if (item.content !== undefined) return <>{item.content}</>;\n  if (item.src) {\n    return <span role=\"img\" aria-label={item.alt ?? \"\"} className=\"block size-full bg-cover bg-center\" style={{ backgroundImage: `url(\"${item.src}\")` }} />;\n  }\n  return null;\n}\n\nexport function BounceCards({\n  items,\n  spread = 7,\n  stagger = 0.07,\n  cardWidth = 140,\n  cardHeight,\n  overlap = 0.42,\n  push = 36,\n  lift = 26,\n  onSelect,\n  label = \"Cards\",\n  className = \"\",\n}: BounceCardsProps) {\n  const reduce = Boolean(useReducedMotion());\n  const count = items.length;\n  const height = cardHeight ?? Math.round(cardWidth * 1.4);\n  const stepX = cardWidth * (1 - Math.max(0, Math.min(0.8, overlap)));\n  const mid = (count - 1) / 2;\n  const [hovered, setHovered] = useState<number | null>(null);\n  const [focused, setFocused] = useState<number | null>(null);\n  const [entered, setEntered] = useState(reduce);\n  const refs = useRef<(HTMLDivElement | null)[]>([]);\n  const active = hovered ?? focused;\n\n  const arc = (d: number) => d * d * 3.2;\n  const width = (count - 1) * stepX + cardWidth + push * 2 + 24;\n  const boxHeight = height + lift + arc(mid) + 36;\n\n  function pose(i: number) {\n    const d = i - mid;\n    let x = d * stepX;\n    let y = arc(d);\n    let rotate = d * spread;\n    let scale = 1;\n    if (active !== null) {\n      const off = i - active;\n      if (off === 0) {\n        y -= lift;\n        rotate *= 0.25;\n        scale = 1.06;\n      } else {\n        const far = Math.abs(off);\n        x += Math.sign(off) * push * (far === 1 ? 1 : far === 2 ? 0.55 : 0.3);\n      }\n    }\n    return { x, y, rotate, scale };\n  }\n\n  function onKeyDown(i: number, e: KeyboardEvent<HTMLDivElement>) {\n    if (e.key === \"ArrowRight\" || e.key === \"ArrowLeft\") {\n      e.preventDefault();\n      const next = (i + (e.key === \"ArrowRight\" ? 1 : -1) + count) % count;\n      refs.current[next]?.focus();\n    } else if (onSelect && (e.key === \"Enter\" || e.key === \" \")) {\n      e.preventDefault();\n      onSelect(i);\n    }\n  }\n\n  return (\n    <div\n      role=\"group\"\n      aria-label={label}\n      className={`relative mx-auto max-w-full ${className}`}\n      style={{ width, height: boxHeight }}\n      onPointerLeave={() => setHovered(null)}\n    >\n      {items.map((item, i) => {\n        const p = pose(i);\n        const isActive = active === i;\n        return (\n          <motion.div\n            key={item.id ?? i}\n            ref={(el) => {\n              refs.current[i] = el;\n            }}\n            role={onSelect ? \"button\" : \"group\"}\n            aria-roledescription={onSelect ? undefined : \"card\"}\n            aria-label={item.label ?? `Card ${i + 1} of ${count}`}\n            tabIndex={0}\n            onPointerEnter={(e) => {\n              if (e.pointerType === \"mouse\") setHovered(i);\n            }}\n            onFocus={() => setFocused(i)}\n            onBlur={() => setFocused((f) => (f === i ? null : f))}\n            onClick={() => onSelect?.(i)}\n            onKeyDown={(e) => onKeyDown(i, e)}\n            className={`absolute left-1/2 overflow-hidden rounded-2xl bg-ink-800 shadow-[0_18px_40px_-16px_rgb(0_0_0/0.9)] ring-1 ring-inset ring-white/10 focus-visible:outline-offset-4 ${\n              onSelect ? \"cursor-pointer\" : \"\"\n            }`}\n            style={{\n              top: lift + 12,\n              width: cardWidth,\n              height,\n              marginLeft: -cardWidth / 2,\n              zIndex: isActive ? count + 1 : i,\n              originX: 0.5,\n              originY: 1.15,\n            }}\n            initial={reduce ? false : { opacity: 0, x: 0, y: 140, rotate: 0, scale: 0.55 }}\n            animate={{ opacity: 1, ...p }}\n            transition={\n              reduce\n                ? { duration: 0.15 }\n                : entered\n                  ? { type: \"spring\", stiffness: 360, damping: 24 }\n                  : { type: \"spring\", stiffness: 260, damping: 12, mass: 0.9, delay: i * stagger }\n            }\n            onAnimationComplete={() => {\n              if (!entered && i === count - 1) setEntered(true);\n            }}\n          >\n            <div className=\"size-full\" inert={Boolean(onSelect)}>\n              <Media item={item} />\n            </div>\n          </motion.div>\n        );\n      })}\n    </div>\n  );\n}\n"}]}