{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"near-bold","type":"registry:ui","title":"Near Bold","description":"Letters grow bolder, larger and brighter the closer the pointer gets, with a tunable radius and falloff.","dependencies":[],"registryDependencies":[],"files":[{"path":"registry/ui/near-bold.tsx","type":"registry:ui","content":"\"use client\";\n\nimport { Fragment, useEffect, useRef } from \"react\";\n\nexport interface NearBoldProps {\n  text: string;\n  /** Px from the pointer where letters start reacting. */\n  radius?: number;\n  /** Shape of the response curve from the pointer outwards. */\n  falloff?: \"linear\" | \"exponential\" | \"gaussian\";\n  /** Weight far from the pointer. Use a variable font for smooth steps. */\n  fromWeight?: number;\n  /** Weight right under the pointer. */\n  toWeight?: number;\n  /** Scale right under the pointer. */\n  scale?: number;\n  /** Tint letters toward this color near the pointer. Empty to disable. */\n  activeColor?: string;\n  as?: \"p\" | \"h1\" | \"h2\" | \"h3\" | \"span\" | \"div\";\n  className?: string;\n}\n\nconst curves = {\n  linear: (t: number) => 1 - t,\n  exponential: (t: number) => (Math.exp(-4 * t) - Math.exp(-4)) / (1 - Math.exp(-4)),\n  gaussian: (t: number) => Math.exp(-(t * t) / 0.18),\n};\n\nexport function NearBold({\n  text,\n  radius = 140,\n  falloff = \"gaussian\",\n  fromWeight = 400,\n  toWeight = 900,\n  scale = 1.15,\n  activeColor = \"#bef264\",\n  as: Tag = \"p\",\n  className,\n}: NearBoldProps) {\n  const ref = useRef<HTMLElement>(null);\n\n  useEffect(() => {\n    const el = ref.current;\n    const area = el?.parentElement ?? el;\n    if (!el || !area || window.matchMedia(\"(prefers-reduced-motion: reduce)\").matches) return;\n    const letters = Array.from(el.querySelectorAll<HTMLElement>(\"[data-letter]\"));\n    const level = letters.map(() => 0);\n    const curve = curves[falloff] ?? curves.gaussian;\n    let pointer: { x: number; y: number } | null = null;\n    let raf = 0;\n\n    const tick = () => {\n      const rects = letters.map((l) => l.getBoundingClientRect());\n      let moving = false;\n      letters.forEach((l, i) => {\n        const r = rects[i];\n        const d = pointer ? Math.hypot(pointer.x - (r.left + r.width / 2), pointer.y - (r.top + r.height / 2)) : Infinity;\n        const target = d < radius ? curve(d / radius) : 0;\n        level[i] += (target - level[i]) * 0.2;\n        if (Math.abs(target - level[i]) > 0.002) moving = true;\n        const p = level[i];\n        l.style.fontWeight = String(Math.round(fromWeight + (toWeight - fromWeight) * p));\n        l.style.transform = p > 0.001 ? `scale(${(1 + (scale - 1) * p).toFixed(3)})` : \"\";\n        l.style.color = activeColor && p > 0.001 ? `color-mix(in oklab, ${activeColor} ${(p * 100).toFixed(1)}%, currentColor)` : \"\";\n      });\n      raf = moving || pointer ? requestAnimationFrame(tick) : 0;\n    };\n    const wake = () => {\n      if (!raf) raf = requestAnimationFrame(tick);\n    };\n    const onMove = (e: PointerEvent) => {\n      pointer = { x: e.clientX, y: e.clientY };\n      wake();\n    };\n    const onLeave = () => {\n      pointer = null;\n      wake();\n    };\n\n    area.addEventListener(\"pointermove\", onMove);\n    area.addEventListener(\"pointerleave\", onLeave);\n    return () => {\n      cancelAnimationFrame(raf);\n      area.removeEventListener(\"pointermove\", onMove);\n      area.removeEventListener(\"pointerleave\", onLeave);\n      letters.forEach((l) => {\n        l.style.fontWeight = \"\";\n        l.style.transform = \"\";\n        l.style.color = \"\";\n      });\n    };\n  }, [text, radius, falloff, fromWeight, toWeight, scale, activeColor]);\n\n  const words = text.split(\" \");\n  return (\n    <Tag ref={ref as never} className={className}>\n      <span className=\"sr-only\">{text}</span>\n      {words.map((word, w) => (\n        <Fragment key={w}>\n          <span aria-hidden style={{ display: \"inline-block\", whiteSpace: \"nowrap\" }}>\n            {Array.from(word).map((c, i) => (\n              <span\n                key={i}\n                data-letter\n                style={{ display: \"inline-block\", fontWeight: fromWeight, transformOrigin: \"50% 70%\" }}\n              >\n                {c}\n              </span>\n            ))}\n          </span>\n          {w < words.length - 1 && \" \"}\n        </Fragment>\n      ))}\n    </Tag>\n  );\n}\n"}]}