{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "magnetic-button",
  "type": "registry:ui",
  "title": "Magnetic Button",
  "author": "Rishabh Bose <https://theb0se.vercel.app/>",
  "description": "Tactile button with dual-layer spring attraction that gravitates toward the pointer with configurable mass, stiffness, and damping.",
  "dependencies": [
    "framer-motion",
    "clsx",
    "tailwind-merge"
  ],
  "files": [
    {
      "path": "components/ui/magnetic-button.tsx",
      "content": "\"use client\";\n\nimport React, { useRef, useState } from \"react\";\nimport {\n  motion,\n  useMotionValue,\n  useSpring,\n  useReducedMotion,\n  type HTMLMotionProps,\n} from \"framer-motion\";\nimport { cn } from \"@/lib/utils\";\n\nexport interface MagneticButtonProps\n  extends Omit<HTMLMotionProps<\"button\">, \"children\"> {\n  children: React.ReactNode;\n  /** Pull intensity multiplier (0.1 to 1). Default: 0.35 */\n  strength?: number;\n  /** Spring stiffness. Default: 180 */\n  stiffness?: number;\n  /** Spring damping. Default: 15 */\n  damping?: number;\n  /** Spring mass. Default: 0.2 */\n  mass?: number;\n  /** Visual style preset */\n  variant?: \"primary\" | \"secondary\" | \"outline\" | \"glow\";\n  /** Size preset */\n  size?: \"sm\" | \"md\" | \"lg\";\n}\n\nexport function MagneticButton({\n  children,\n  className,\n  strength = 0.35,\n  stiffness = 180,\n  damping = 15,\n  mass = 0.2,\n  variant = \"primary\",\n  size = \"md\",\n  onMouseMove,\n  onMouseLeave,\n  ...props\n}: MagneticButtonProps) {\n  const ref = useRef<HTMLButtonElement>(null);\n  const shouldReduceMotion = useReducedMotion();\n  const [isHovered, setIsHovered] = useState(false);\n\n  const rawX = useMotionValue(0);\n  const rawY = useMotionValue(0);\n\n  const springConfig = { stiffness, damping, mass };\n  const x = useSpring(rawX, springConfig);\n  const y = useSpring(rawY, springConfig);\n\n  const innerX = useSpring(useMotionValue(0), {\n    stiffness: stiffness * 1.2,\n    damping,\n    mass,\n  });\n  const innerY = useSpring(useMotionValue(0), {\n    stiffness: stiffness * 1.2,\n    damping,\n    mass,\n  });\n\n  const handleMouseMove = (e: React.MouseEvent<HTMLButtonElement>) => {\n    if (!ref.current || shouldReduceMotion) return;\n\n    const rect = ref.current.getBoundingClientRect();\n    const centerX = rect.left + rect.width / 2;\n    const centerY = rect.top + rect.height / 2;\n\n    const deltaX = (e.clientX - centerX) * strength;\n    const deltaY = (e.clientY - centerY) * strength;\n\n    rawX.set(deltaX);\n    rawY.set(deltaY);\n    innerX.set(deltaX * 0.35);\n    innerY.set(deltaY * 0.35);\n\n    onMouseMove?.(e);\n  };\n\n  const handleMouseLeave = (e: React.MouseEvent<HTMLButtonElement>) => {\n    setIsHovered(false);\n    rawX.set(0);\n    rawY.set(0);\n    innerX.set(0);\n    innerY.set(0);\n    onMouseLeave?.(e);\n  };\n\n  const variantStyles: Record<\n    NonNullable<MagneticButtonProps[\"variant\"]>,\n    string\n  > = {\n    primary:\n      \"bg-black text-white hover:bg-neutral-800 border border-black dark:bg-white dark:text-black dark:hover:bg-neutral-200 dark:border-white\",\n    secondary:\n      \"bg-neutral-100 text-black hover:bg-neutral-200 border border-neutral-200 dark:bg-[#141414] dark:text-white dark:hover:bg-[#1F1F1F] dark:border-[#262626]\",\n    outline:\n      \"bg-transparent text-black border border-neutral-300 hover:border-black hover:bg-black/5 dark:text-white dark:border-[#262626] dark:hover:border-white dark:hover:bg-white/5\",\n    glow:\n      \"bg-white text-black border border-black/40 hover:border-black shadow-sm dark:bg-[#0A0A0A] dark:text-white dark:border-white/40 dark:hover:border-white dark:shadow-[0_0_24px_-4px_rgba(255,255,255,0.22)]\",\n  };\n\n  const sizeStyles: Record<NonNullable<MagneticButtonProps[\"size\"]>, string> = {\n    sm: \"px-3.5 py-2 text-xs rounded-lg gap-1.5\",\n    md: \"px-5 py-2.5 text-sm rounded-xl gap-2\",\n    lg: \"px-6 py-3 text-sm rounded-xl gap-2.5\",\n  };\n\n  return (\n    <motion.button\n      ref={ref}\n      type=\"button\"\n      onMouseEnter={() => setIsHovered(true)}\n      onMouseMove={handleMouseMove}\n      onMouseLeave={handleMouseLeave}\n      style={{\n        x: shouldReduceMotion ? 0 : x,\n        y: shouldReduceMotion ? 0 : y,\n      }}\n      whileTap={shouldReduceMotion ? undefined : { scale: 0.97 }}\n      className={cn(\n        \"relative inline-flex items-center justify-center font-medium tracking-tight transition-colors duration-200 select-none focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-black dark:focus-visible:ring-white focus-visible:ring-offset-2\",\n        variantStyles[variant],\n        sizeStyles[size],\n        className\n      )}\n      {...props}\n    >\n      <span\n        aria-hidden=\"true\"\n        className={cn(\n          \"pointer-events-none absolute inset-0 rounded-[inherit] transition-opacity duration-300\",\n          isHovered ? \"opacity-100\" : \"opacity-0\"\n        )}\n        style={{\n          background:\n            \"radial-gradient(circle at center, rgba(128,128,128,0.12), transparent 70%)\",\n        }}\n      />\n\n      <motion.span\n        style={{\n          x: shouldReduceMotion ? 0 : innerX,\n          y: shouldReduceMotion ? 0 : innerY,\n        }}\n        className=\"relative z-10 inline-flex items-center gap-2\"\n      >\n        {children}\n      </motion.span>\n    </motion.button>\n  );\n}\n",
      "type": "registry:ui",
      "target": "components/ui/magnetic-button.tsx"
    },
    {
      "path": "lib/utils.ts",
      "content": "import { type ClassValue, clsx } from \"clsx\";\nimport { twMerge } from \"tailwind-merge\";\n\nexport function cn(...inputs: ClassValue[]) {\n  return twMerge(clsx(inputs));\n}\n\nexport async function copyToClipboard(text: string): Promise<boolean> {\n  if (typeof window === \"undefined\") return false;\n\n  try {\n    if (navigator.clipboard && window.isSecureContext) {\n      await navigator.clipboard.writeText(text);\n      return true;\n    }\n\n    const textArea = document.createElement(\"textarea\");\n    textArea.value = text;\n    textArea.style.position = \"fixed\";\n    textArea.style.left = \"-999999px\";\n    textArea.style.top = \"-999999px\";\n    document.body.appendChild(textArea);\n    textArea.focus();\n    textArea.select();\n    const succeeded = document.execCommand(\"copy\");\n    textArea.remove();\n    return succeeded;\n  } catch {\n    return false;\n  }\n}\n",
      "type": "registry:lib",
      "target": "lib/utils.ts"
    }
  ]
}
