{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "magnetic",
  "title": "Magnetic",
  "description": "Pulls its content toward the mouse while hovered and springs it back on leave.",
  "registryDependencies": [
    "@corsair-ui/utils"
  ],
  "files": [
    {
      "path": "registry/default/ui/magnetic.tsx",
      "content": "\"use client\";\n\nimport { useEffect, useRef, type ComponentProps } from \"react\";\n\nimport { cn } from \"@/registry/default/lib/utils\";\n\nconst FOLLOW = \"transform 200ms cubic-bezier(0.22, 1, 0.36, 1)\";\n// A slight overshoot on the way back, like a spring settling.\nconst RELEASE = \"transform 600ms cubic-bezier(0.34, 1.56, 0.64, 1)\";\n\nfunction prefersReducedMotion() {\n  return window.matchMedia?.(\"(prefers-reduced-motion: reduce)\").matches === true;\n}\n\ninterface MagneticProps extends ComponentProps<\"span\"> {\n  /** How far the content follows the pointer, as a fraction of its distance from the center. */\n  strength?: number;\n}\n\n/**\n * Pulls its content toward the mouse while hovered and springs it back on\n * leave. The outer element never moves, so the hit area stays put. Touch,\n * keyboard and `prefers-reduced-motion` get the content unchanged.\n *\n * @example\n * <Magnetic><Button>Get started</Button></Magnetic>\n */\nfunction Magnetic({\n  strength = 0.3,\n  className,\n  children,\n  onPointerMove,\n  onPointerLeave,\n  ...props\n}: MagneticProps) {\n  const content = useRef<HTMLSpanElement>(null);\n  const frame = useRef(0);\n\n  useEffect(() => () => cancelAnimationFrame(frame.current), []);\n\n  const moveTo = (x: number, y: number, transition: string) => {\n    const node = content.current;\n    if (!node) return;\n    node.style.transition = transition;\n    node.style.transform = x || y ? `translate3d(${x}px, ${y}px, 0)` : \"\";\n  };\n\n  return (\n    <span\n      data-slot=\"magnetic\"\n      className={cn(\"inline-block\", className)}\n      onPointerMove={(event) => {\n        onPointerMove?.(event);\n        if (event.pointerType === \"touch\" || prefersReducedMotion()) return;\n        const target = event.currentTarget;\n        const { clientX, clientY } = event;\n        cancelAnimationFrame(frame.current);\n        frame.current = requestAnimationFrame(() => {\n          const bounds = target.getBoundingClientRect();\n          moveTo(\n            (clientX - bounds.left - bounds.width / 2) * strength,\n            (clientY - bounds.top - bounds.height / 2) * strength,\n            FOLLOW\n          );\n        });\n      }}\n      onPointerLeave={(event) => {\n        onPointerLeave?.(event);\n        cancelAnimationFrame(frame.current);\n        moveTo(0, 0, RELEASE);\n      }}\n      {...props}\n    >\n      <span ref={content} data-slot=\"magnetic-content\" className=\"inline-block\">\n        {children}\n      </span>\n    </span>\n  );\n}\n\nexport { Magnetic, type MagneticProps };\n",
      "type": "registry:ui"
    }
  ],
  "categories": [
    "motion"
  ],
  "type": "registry:ui"
}