{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"flip-card","type":"registry:ui","title":"Flip Card","description":"A two-sided card that turns over in 3D on hover or click to show its back.","dependencies":["motion"],"registryDependencies":["https://ui.mekaigames.com/r/theme.json"],"files":[{"path":"components/ui/flip-card.tsx","type":"registry:ui","content":"\"use client\";\n\nimport { motion, useReducedMotion } from \"motion/react\";\nimport { useState, type FocusEvent, type KeyboardEvent, type MouseEvent, type PointerEvent, type ReactNode } from \"react\";\n\ntype FlipCardProps = {\n  front: ReactNode;\n  back: ReactNode;\n  /** Flip while hovered, or toggle on click, Enter and Space. */\n  trigger?: \"hover\" | \"click\";\n  /** Length of the flip, in seconds. */\n  duration?: number;\n  className?: string;\n};\n\nconst CONTROLS = \"a, button, input, select, textarea, label, summary\";\n\nconst FACE =\n  \"[grid-area:1/1] overflow-hidden rounded-3xl border border-ink-600 bg-ink-800 shadow-[0_24px_50px_-28px_rgb(0_0_0/0.9)]\";\n\n/** A two-sided card that turns over in 3D to show its back. */\nexport function FlipCard({ front, back, trigger = \"hover\", duration = 0.7, className = \"\" }: FlipCardProps) {\n  const reduce = useReducedMotion();\n  const [hovered, setHovered] = useState(false);\n  const [focused, setFocused] = useState(false);\n  const [toggled, setToggled] = useState(false);\n  const clickMode = trigger === \"click\";\n  // Hover mode still flips for keyboard focus and for taps on touch screens.\n  const flipped = clickMode ? toggled : hovered || focused || toggled;\n\n  function onPointerDown(e: PointerEvent<HTMLDivElement>) {\n    if (!clickMode && e.pointerType !== \"mouse\") setToggled((v) => !v);\n  }\n\n  function onClick(e: MouseEvent<HTMLDivElement>) {\n    if (!clickMode) return;\n    // Let links and buttons inside the card do their own thing.\n    const control = e.target instanceof Element ? e.target.closest(CONTROLS) : null;\n    if (control && control !== e.currentTarget) return;\n    setToggled((v) => !v);\n  }\n\n  function onKeyDown(e: KeyboardEvent<HTMLDivElement>) {\n    if (!clickMode || e.target !== e.currentTarget) return;\n    if (e.key === \"Enter\" || e.key === \" \") {\n      e.preventDefault();\n      setToggled((v) => !v);\n    }\n  }\n\n  function onFocus(e: FocusEvent<HTMLDivElement>) {\n    if (!clickMode && e.target === e.currentTarget && e.currentTarget.matches(\":focus-visible\")) setFocused(true);\n  }\n\n  function onBlur(e: FocusEvent<HTMLDivElement>) {\n    if (!e.currentTarget.contains(e.relatedTarget as Node | null)) setFocused(false);\n  }\n\n  const hidden = { backfaceVisibility: \"hidden\", WebkitBackfaceVisibility: \"hidden\" } as const;\n  const transition = reduce ? { duration: 0.2 } : { type: \"spring\" as const, duration, bounce: 0.2 };\n\n  return (\n    <div\n      role={clickMode ? \"button\" : undefined}\n      aria-pressed={clickMode ? flipped : undefined}\n      tabIndex={0}\n      onPointerEnter={(e) => e.pointerType === \"mouse\" && setHovered(true)}\n      onPointerLeave={() => setHovered(false)}\n      onPointerDown={onPointerDown}\n      onClick={onClick}\n      onKeyDown={onKeyDown}\n      onFocus={onFocus}\n      onBlur={onBlur}\n      className={`grid cursor-pointer rounded-3xl ${className}`}\n      style={{ perspective: 1200 }}\n    >\n      <motion.div\n        className=\"grid [grid-area:1/1]\"\n        style={{ transformStyle: \"preserve-3d\" }}\n        initial={false}\n        animate={{ rotateY: !reduce && flipped ? 180 : 0 }}\n        transition={transition}\n      >\n        <motion.div\n          className={FACE}\n          style={hidden}\n          aria-hidden={flipped || undefined}\n          inert={flipped}\n          initial={false}\n          animate={{ opacity: reduce && flipped ? 0 : 1 }}\n          transition={{ duration: 0.2 }}\n        >\n          {front}\n        </motion.div>\n        <motion.div\n          className={FACE}\n          // With reduced motion the back sits flat on top and crossfades instead of turning over.\n          style={{ ...hidden, rotateY: reduce ? 0 : 180 }}\n          aria-hidden={!flipped || undefined}\n          inert={!flipped}\n          initial={false}\n          animate={{ opacity: reduce && !flipped ? 0 : 1 }}\n          transition={{ duration: 0.2 }}\n        >\n          {back}\n        </motion.div>\n      </motion.div>\n    </div>\n  );\n}\n"}]}