{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "variable-proximity-text",
  "type": "registry:ui",
  "title": "Variable Proximity Text",
  "author": "Rishabh Bose <https://theb0se.vercel.app/>",
  "description": "Interactive kinetic typography where each glyph interpolates vertical lift, scale, and contrast based on real-time 2D cursor proximity.",
  "dependencies": [
    "framer-motion",
    "clsx",
    "tailwind-merge"
  ],
  "files": [
    {
      "path": "components/ui/variable-proximity-text.tsx",
      "content": "\"use client\";\n\nimport React, { useRef } from \"react\";\nimport {\n  motion,\n  useMotionValue,\n  useSpring,\n  useTransform,\n  useReducedMotion,\n  type MotionValue,\n} from \"framer-motion\";\nimport { cn } from \"@/lib/utils\";\n\nexport interface VariableProximityTextProps {\n  /** Text string to split into proximity-reactive kinetic glyphs. */\n  text?: string;\n  /** Pointer influence radius in pixels. Default: 120 */\n  radius?: number;\n  /** Peak vertical displacement in pixels at zero pointer distance. Default: -10 */\n  maxLift?: number;\n  /** Peak glyph scale factor at zero pointer distance. Default: 1.22 */\n  maxScale?: number;\n  /** Hooke's Law spring stiffness coefficient. Default: 300 */\n  stiffness?: number;\n  /** Spring damping coefficient. Default: 22 */\n  damping?: number;\n  className?: string;\n}\n\ninterface ProximityGlyphProps {\n  char: string;\n  mouseX: MotionValue<number>;\n  mouseY: MotionValue<number>;\n  radius: number;\n  maxLift: number;\n  maxScale: number;\n  stiffness: number;\n  damping: number;\n  shouldReduceMotion: boolean;\n}\n\nfunction ProximityGlyph({\n  char,\n  mouseX,\n  mouseY,\n  radius,\n  maxLift,\n  maxScale,\n  stiffness,\n  damping,\n  shouldReduceMotion,\n}: ProximityGlyphProps) {\n  const glyphRef = useRef<HTMLSpanElement | null>(null);\n\n  const proximityFactor = useTransform([mouseX, mouseY], ([x, y]) => {\n    const el = glyphRef.current;\n    if (!el || x === -Infinity || y === -Infinity) return 0;\n    const rect = el.getBoundingClientRect();\n    const centerX = rect.left + rect.width / 2;\n    const centerY = rect.top + rect.height / 2;\n    const dx = (x as number) - centerX;\n    const dy = (y as number) - centerY;\n    const dist = Math.sqrt(dx * dx + dy * dy);\n    if (dist >= radius) return 0;\n    return 1 - dist / radius;\n  });\n\n  const targetY = useTransform(proximityFactor, [0, 1], [0, maxLift]);\n  const targetScale = useTransform(proximityFactor, [0, 1], [1, maxScale]);\n  const targetOpacity = useTransform(proximityFactor, [0, 1], [0.68, 1]);\n\n  const springY = useSpring(targetY, { stiffness, damping, mass: 0.35 });\n  const springScale = useSpring(targetScale, { stiffness, damping, mass: 0.35 });\n\n  if (char === \" \") {\n    return <span className=\"inline-block w-[0.32em]\">&nbsp;</span>;\n  }\n\n  return (\n    <motion.span\n      ref={glyphRef}\n      aria-hidden=\"true\"\n      style={{\n        y: shouldReduceMotion ? 0 : springY,\n        scale: shouldReduceMotion ? 1 : springScale,\n        opacity: shouldReduceMotion ? 1 : targetOpacity,\n      }}\n      className=\"inline-block origin-bottom select-none will-change-transform\"\n    >\n      {char}\n    </motion.span>\n  );\n}\n\nexport function VariableProximityText({\n  text = \"Kinetic typography engineered with spring physics.\",\n  radius = 120,\n  maxLift = -10,\n  maxScale = 1.22,\n  stiffness = 300,\n  damping = 22,\n  className,\n}: VariableProximityTextProps) {\n  const shouldReduceMotion = useReducedMotion() ?? false;\n  const mouseX = useMotionValue(-Infinity);\n  const mouseY = useMotionValue(-Infinity);\n\n  const words = text.split(\" \");\n\n  return (\n    <div\n      onMouseMove={(e) => {\n        if (!shouldReduceMotion) {\n          mouseX.set(e.clientX);\n          mouseY.set(e.clientY);\n        }\n      }}\n      onMouseLeave={() => {\n        mouseX.set(-Infinity);\n        mouseY.set(-Infinity);\n      }}\n      className={cn(\n        \"relative cursor-default rounded-2xl border border-neutral-200 bg-white px-6 py-8 text-center dark:border-[#222222] dark:bg-[#0A0A0A]\",\n        className\n      )}\n    >\n      {/* Screen-reader accessible uninterrupted string */}\n      <span className=\"sr-only\">{text}</span>\n\n      <p\n        aria-hidden=\"true\"\n        className=\"text-xl font-semibold tracking-tight text-black sm:text-2xl dark:text-white\"\n      >\n        {words.map((word, wordIdx) => (\n          <span key={wordIdx} className=\"inline-block whitespace-nowrap\">\n            {word.split(\"\").map((char, charIdx) => (\n              <ProximityGlyph\n                key={`${wordIdx}-${charIdx}`}\n                char={char}\n                mouseX={mouseX}\n                mouseY={mouseY}\n                radius={radius}\n                maxLift={maxLift}\n                maxScale={maxScale}\n                stiffness={stiffness}\n                damping={damping}\n                shouldReduceMotion={shouldReduceMotion}\n              />\n            ))}\n            {wordIdx < words.length - 1 && (\n              <span className=\"inline-block w-[0.32em]\">&nbsp;</span>\n            )}\n          </span>\n        ))}\n      </p>\n\n      <div className=\"mt-3 text-[11px] font-medium uppercase tracking-widest text-neutral-400 dark:text-neutral-500\">\n        Sweep cursor across glyphs • Radius {radius}px\n      </div>\n    </div>\n  );\n}\n\nexport default VariableProximityText;\n",
      "type": "registry:ui",
      "target": "components/ui/variable-proximity-text.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"
    }
  ]
}
