{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "text-hover-lens",
  "type": "registry:ui",
  "title": "Text Hover Lens",
  "author": "Rishabh Bose <https://theb0se.vercel.app/>",
  "description": "Interactive text component where hovering opens a circular lens under the cursor with spring physics, revealing a contrasting color layer with optional magnification.",
  "dependencies": [
    "framer-motion",
    "clsx",
    "tailwind-merge"
  ],
  "files": [
    {
      "path": "components/ui/text-hover-lens.tsx",
      "content": "\"use client\";\n\nimport React, { useRef } from \"react\";\nimport {\n  motion,\n  useMotionValue,\n  useSpring,\n  useTransform,\n  useReducedMotion,\n} from \"framer-motion\";\nimport { cn } from \"@/lib/utils\";\n\nexport interface TextHoverLensProps {\n  /**\n   * The text string to display and reveal through the interactive lens.\n   */\n  text: string;\n  /**\n   * Background color of the circular lens. Accepts any CSS color (hex, rgb, hsl, CSS variable).\n   * @default \"#000000\" (site accent teal)\n   */\n  lensColor?: string;\n  /**\n   * Color of the revealed text inside the lens. Must have AA contrast against lensColor.\n   * @default \"#ffffff\"\n   */\n  lensTextColor?: string;\n  /**\n   * Color of the text outside the lens.\n   * @default \"currentColor\"\n   */\n  textColor?: string;\n  /**\n   * Diameter of the circular lens in pixels when fully open.\n   * @default 120\n   */\n  lensSize?: number;\n  /**\n   * Scale multiplier for the text inside the lens. 1 = no zoom, 1.2 = slight magnification.\n   * @default 1\n   */\n  magnify?: number;\n  /**\n   * Hooke's Law spring stiffness coefficient for cursor following and radius expansion.\n   * Matches the Snappy spring preset.\n   * @default 380\n   */\n  stiffness?: number;\n  /**\n   * Spring damping coefficient controlling oscillation decay.\n   * Matches the Snappy spring preset.\n   * @default 24\n   */\n  damping?: number;\n  /**\n   * Additional Tailwind or CSS classes applied to the outer wrapper element.\n   * Allows typography sizing, font weight, line height, and tracking to be inherited from the parent.\n   */\n  className?: string;\n}\n\n/**\n * TextHoverLens renders an interactive text element where hovering opens a circular lens\n * under the cursor driven by physics springs. Inside the circle, a contrasting text layer\n * is revealed with optional magnification.\n */\nexport function TextHoverLens({\n  text,\n  lensColor = \"#000000\",\n  lensTextColor = \"#ffffff\",\n  textColor = \"currentColor\",\n  lensSize = 60,\n  magnify = 1,\n  stiffness = 380,\n  damping = 24,\n  className,\n}: TextHoverLensProps) {\n  const containerRef = useRef<HTMLSpanElement | null>(null);\n  const shouldReduceMotion = useReducedMotion();\n\n  // Pointer position motion values (relative to container bounding rect)\n  const mouseX = useMotionValue(0);\n  const mouseY = useMotionValue(0);\n  const targetRadius = useMotionValue(0);\n\n  // Snappy spring configuration for physics cursor follow and radius expansion\n  const springConfig = { stiffness, damping };\n  const springX = useSpring(mouseX, springConfig);\n  const springY = useSpring(mouseY, springConfig);\n  const springRadius = useSpring(targetRadius, springConfig);\n\n  // Fallback to instant coordinates when prefers-reduced-motion is active\n  const activeX = shouldReduceMotion ? mouseX : springX;\n  const activeY = shouldReduceMotion ? mouseY : springY;\n  const activeRadius = shouldReduceMotion ? targetRadius : springRadius;\n\n  // Clip-path string for the circular revealing lens (clamped to prevent negative radius)\n  const clipPath = useTransform(\n    [activeRadius, activeX, activeY],\n    ([r, x, y]) => {\n      const safeRadius = Math.max(0, Number(r));\n      return `circle(${safeRadius}px at ${x}px ${y}px)`;\n    }\n  );\n\n  // Transform origin pinned to current cursor position for seamless magnification\n  const transformOrigin = useTransform(\n    [activeX, activeY],\n    ([x, y]) => `${x}px ${y}px`\n  );\n\n  const updateCoordinates = (e: React.PointerEvent<HTMLElement>) => {\n    const el = containerRef.current;\n    if (!el) return null;\n    const rect = el.getBoundingClientRect();\n    const x = e.clientX - rect.left;\n    const y = e.clientY - rect.top;\n    mouseX.set(x);\n    mouseY.set(y);\n    return { x, y };\n  };\n\n  const handlePointerEnter = (e: React.PointerEvent<HTMLElement>) => {\n    if (e.pointerType === \"touch\") return;\n    const coords = updateCoordinates(e);\n    if (coords) {\n      if (typeof springX.jump === \"function\") {\n        springX.jump(coords.x);\n        springY.jump(coords.y);\n      }\n    }\n    targetRadius.set(lensSize / 2);\n  };\n\n  const handlePointerMove = (e: React.PointerEvent<HTMLElement>) => {\n    updateCoordinates(e);\n  };\n\n  const handlePointerLeave = (e: React.PointerEvent<HTMLElement>) => {\n    if (e.pointerType === \"touch\") return;\n    targetRadius.set(0);\n  };\n\n  const handlePointerDown = (e: React.PointerEvent<HTMLElement>) => {\n    if (e.pointerType === \"touch\") {\n      const coords = updateCoordinates(e);\n      if (coords && typeof springX.jump === \"function\") {\n        springX.jump(coords.x);\n        springY.jump(coords.y);\n      }\n      targetRadius.set(lensSize / 2);\n    }\n  };\n\n  const handlePointerUp = (e: React.PointerEvent<HTMLElement>) => {\n    if (e.pointerType === \"touch\") {\n      targetRadius.set(0);\n    }\n  };\n\n  const handlePointerCancel = (e: React.PointerEvent<HTMLElement>) => {\n    if (e.pointerType === \"touch\") {\n      targetRadius.set(0);\n    }\n  };\n\n  return (\n    <span\n      ref={containerRef}\n      onPointerEnter={handlePointerEnter}\n      onPointerMove={handlePointerMove}\n      onPointerLeave={handlePointerLeave}\n      onPointerDown={handlePointerDown}\n      onPointerUp={handlePointerUp}\n      onPointerCancel={handlePointerCancel}\n      className={cn(\n        \"relative inline-block select-text cursor-default leading-normal\",\n        className\n      )}\n      style={{ color: textColor }}\n    >\n      {/* 1. Base Layer: Screen-reader readable, selectable, standard color */}\n      <span className=\"block\">{text}</span>\n\n      {/* 2. Lens Layer: Clipped circular viewport revealing lens color and lensTextColor */}\n      <motion.span\n        aria-hidden=\"true\"\n        className=\"pointer-events-none absolute inset-0 block select-none overflow-hidden\"\n        style={{\n          clipPath,\n          backgroundColor: lensColor,\n          color: lensTextColor,\n        }}\n      >\n        <motion.span\n          className=\"block h-full w-full\"\n          style={{\n            transformOrigin,\n            transform: magnify !== 1 ? `scale(${magnify})` : undefined,\n          }}\n        >\n          {text}\n        </motion.span>\n      </motion.span>\n    </span>\n  );\n}\n\nexport default TextHoverLens;\n",
      "type": "registry:ui",
      "target": "components/ui/text-hover-lens.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"
    }
  ]
}
