{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "proximity-weight-text",
  "title": "Proximity Weight Text",
  "description": "Letters that thicken and lift as the pointer gets near, in a soft wave that travels with it, without pushing the rest of the line around.",
  "dependencies": [],
  "files": [
    {
      "path": "registry/new-york/proximity-weight-text/proximity-weight-text.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\n\nexport interface ProximityWeightTextProps extends Omit<\n  React.ComponentPropsWithoutRef<\"div\">,\n  \"children\"\n> {\n  text?: string;\n  /** How far the pointer reaches, in px. */\n  radius?: number;\n  /** Extra thickness at the pointer, in em. */\n  weight?: number;\n  /** How far letters lift toward the pointer, in em. */\n  lift?: number;\n}\n\nfunction useReducedMotion() {\n  return React.useSyncExternalStore(\n    (callback) => {\n      const query = window.matchMedia(\"(prefers-reduced-motion: reduce)\");\n      query.addEventListener(\"change\", callback);\n      return () => query.removeEventListener(\"change\", callback);\n    },\n    () => window.matchMedia(\"(prefers-reduced-motion: reduce)\").matches,\n    () => false,\n  );\n}\n\nexport function ProximityWeightText({\n  text = \"Heavier as you get closer\",\n  radius = 150,\n  weight = 0.045,\n  lift = 0.08,\n  className,\n  style,\n  onPointerMove,\n  onPointerLeave,\n  ...props\n}: ProximityWeightTextProps) {\n  const reduce = useReducedMotion();\n  const letterRefs = React.useRef<(HTMLSpanElement | null)[]>([]);\n  const pointer = React.useRef<{ x: number; y: number } | null>(null);\n  const start = React.useRef<() => void>(() => {});\n  const chars = Array.from(text);\n  // Letters sit inside word wrappers, so a line can only break between words.\n  const words = text.split(\" \");\n  const starts = words.map((_, w) =>\n    words.slice(0, w).reduce((n, word) => n + Array.from(word).length + 1, 0),\n  );\n\n  // Thickness comes from a text stroke rather than font-weight, so letters grow without pushing their neighbours.\n  React.useEffect(() => {\n    if (reduce) return;\n    const levels = new Float32Array(chars.length);\n    let raf = 0;\n    const frame = () => {\n      let moving = false;\n      const at = pointer.current;\n      letterRefs.current.slice(0, chars.length).forEach((el, i) => {\n        if (!el) return;\n        let goal = 0;\n        if (at) {\n          const r = el.getBoundingClientRect();\n          const dx = at.x - (r.left + r.width / 2);\n          const dy = at.y - (r.top + r.height / 2);\n          goal = Math.exp(-(dx * dx + dy * dy) / (radius * radius));\n        }\n        const next = levels[i] + (goal - levels[i]) * 0.18;\n        levels[i] = Math.abs(goal - next) < 0.003 ? goal : next;\n        if (levels[i] !== goal) moving = true;\n        el.style.webkitTextStroke = `${(levels[i] * weight).toFixed(4)}em currentColor`;\n        el.style.opacity = (0.5 + levels[i] * 0.5).toFixed(3);\n        el.style.transform = `translateY(${(-levels[i] * lift).toFixed(4)}em)`;\n      });\n      raf = moving || at ? requestAnimationFrame(frame) : 0;\n    };\n    start.current = () => {\n      if (!raf) raf = requestAnimationFrame(frame);\n    };\n    return () => {\n      cancelAnimationFrame(raf);\n      raf = 0;\n    };\n  }, [reduce, chars.length, radius, weight, lift]);\n\n  return (\n    <div\n      className={className}\n      style={style}\n      role=\"text\"\n      aria-label={text}\n      onPointerMove={(e) => {\n        onPointerMove?.(e);\n        if (e.pointerType !== \"mouse\") return;\n        pointer.current = { x: e.clientX, y: e.clientY };\n        start.current();\n      }}\n      onPointerLeave={(e) => {\n        onPointerLeave?.(e);\n        pointer.current = null;\n        start.current();\n      }}\n      {...props}\n    >\n      <span aria-hidden=\"true\">\n        {words.map((word, w) => (\n          <React.Fragment key={w}>\n            <span className=\"inline-block whitespace-nowrap\">\n              {Array.from(word).map((c, j) => (\n                <span\n                  key={j}\n                  ref={(el) => {\n                    letterRefs.current[starts[w] + j] = el;\n                  }}\n                  className=\"inline-block\"\n                  style={{ opacity: reduce ? 1 : 0.5 }}\n                >\n                  {c}\n                </span>\n              ))}\n            </span>\n            {w < words.length - 1 && \" \"}\n          </React.Fragment>\n        ))}\n      </span>\n    </div>\n  );\n}\n",
      "type": "registry:component"
    }
  ],
  "type": "registry:component"
}