{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"follow-cursor","type":"registry:ui","title":"Follow Cursor","description":"A pill label that trails the cursor across a card on a spring, leans into motion and squishes on click.","dependencies":[],"registryDependencies":["utils"],"files":[{"path":"registry/ui/follow-cursor.tsx","type":"registry:ui","content":"\"use client\";\n\nimport { useEffect, useRef, type ReactNode } from \"react\";\nimport { cn } from \"@/lib/utils\";\n\nexport interface FollowCursorProps {\n  /** The area the label follows the cursor over. */\n  children: ReactNode;\n  /** Text on the pill. */\n  label?: string;\n  /** Spring pull toward the cursor (0-1). */\n  stiffness?: number;\n  /** Velocity kept per frame (0-1). Higher is bouncier. */\n  damping?: number;\n  /** Lean the pill into horizontal motion. */\n  tilt?: boolean;\n  /** Hide the system cursor over the area (mouse only). */\n  hideCursor?: boolean;\n  className?: string;\n}\n\nexport function FollowCursor({\n  children,\n  label = \"View project\",\n  stiffness = 0.12,\n  damping = 0.7,\n  tilt = true,\n  hideCursor = true,\n  className,\n}: FollowCursorProps) {\n  const root = useRef<HTMLDivElement>(null);\n  const pill = useRef<HTMLDivElement>(null);\n\n  useEffect(() => {\n    const el = root.current!;\n    const reduced = window.matchMedia(\"(prefers-reduced-motion: reduce)\").matches;\n    const s = { x: 0, y: 0, vx: 0, vy: 0, scale: 0 };\n    const goal = { x: 0, y: 0, scale: 0 };\n    let down = false;\n    let raf = 0;\n\n    const frame = () => {\n      if (!pill.current) return void (raf = 0); // unmounted\n      if (reduced) {\n        s.x = goal.x;\n        s.y = goal.y;\n        s.vx = s.vy = 0;\n      } else {\n        s.vx = (s.vx + (goal.x - s.x) * stiffness) * damping;\n        s.vy = (s.vy + (goal.y - s.y) * stiffness) * damping;\n        s.x += s.vx;\n        s.y += s.vy;\n      }\n      const targetScale = goal.scale * (down ? 0.82 : 1);\n      s.scale += (targetScale - s.scale) * (reduced ? 1 : 0.2);\n      const lean = tilt && !reduced ? Math.max(-18, Math.min(18, s.vx * 1.2)) : 0;\n      pill.current!.style.transform = `translate(${s.x}px,${s.y}px) translate(-50%,-50%) rotate(${lean}deg) scale(${s.scale})`;\n      const moving = Math.abs(s.vx) + Math.abs(s.vy) > 0.05 || Math.abs(targetScale - s.scale) > 0.002;\n      raf = moving ? requestAnimationFrame(frame) : 0;\n    };\n    const kick = () => {\n      if (!raf) raf = requestAnimationFrame(frame);\n    };\n    const local = (e: PointerEvent) => {\n      const r = el.getBoundingClientRect();\n      return [e.clientX - r.left, e.clientY - r.top];\n    };\n\n    const onEnter = (e: PointerEvent) => {\n      if (e.pointerType !== \"mouse\") return;\n      [goal.x, goal.y] = local(e);\n      // Pop in from where the cursor entered instead of flying across the card.\n      if (s.scale < 0.05) [s.x, s.y] = [goal.x, goal.y];\n      goal.scale = 1;\n      kick();\n    };\n    const onMove = (e: PointerEvent) => {\n      if (e.pointerType !== \"mouse\") return;\n      [goal.x, goal.y] = local(e);\n      goal.scale = 1;\n      kick();\n    };\n    const onLeave = () => {\n      goal.scale = 0;\n      down = false;\n      kick();\n    };\n    const onDown = () => {\n      down = true;\n      kick();\n    };\n    const onUp = () => {\n      down = false;\n      kick();\n    };\n\n    el.addEventListener(\"pointerenter\", onEnter);\n    el.addEventListener(\"pointermove\", onMove, { passive: true });\n    el.addEventListener(\"pointerleave\", onLeave);\n    el.addEventListener(\"pointerdown\", onDown);\n    el.addEventListener(\"pointerup\", onUp);\n    return () => {\n      cancelAnimationFrame(raf);\n      el.removeEventListener(\"pointerenter\", onEnter);\n      el.removeEventListener(\"pointermove\", onMove);\n      el.removeEventListener(\"pointerleave\", onLeave);\n      el.removeEventListener(\"pointerdown\", onDown);\n      el.removeEventListener(\"pointerup\", onUp);\n    };\n  }, [stiffness, damping, tilt]);\n\n  return (\n    <div ref={root} className={cn(\"relative\", hideCursor && \"[@media(pointer:fine)]:cursor-none\", className)}>\n      {children}\n      <div\n        ref={pill}\n        aria-hidden\n        className=\"pointer-events-none absolute left-0 top-0 z-10 flex items-center gap-1.5 whitespace-nowrap rounded-full bg-primary px-4 py-2 text-sm font-medium text-primary-foreground shadow-lg shadow-black/30\"\n        style={{ transform: \"scale(0)\", willChange: \"transform\" }}\n      >\n        {label}\n        <svg viewBox=\"0 0 24 24\" className=\"size-4\" fill=\"none\" stroke=\"currentColor\" strokeWidth={2.2} strokeLinecap=\"round\" strokeLinejoin=\"round\">\n          <path d=\"M7 17 17 7M8 7h9v9\" />\n        </svg>\n      </div>\n    </div>\n  );\n}\n"}]}