{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"weight-press","type":"registry:ui","title":"Weight Press","description":"A full-width headline whose letters swell in weight and stretch taller as the cursor presses close.","dependencies":[],"registryDependencies":["utils"],"files":[{"path":"registry/ui/weight-press.tsx","type":"registry:ui","content":"\"use client\";\n\nimport { useEffect, useRef } from \"react\";\nimport { cn } from \"@/lib/utils\";\n\nexport interface WeightPressProps {\n  text: string;\n  /** Weight at rest. Use a variable font for smooth steps. */\n  minWeight?: number;\n  /** Weight right under the cursor. */\n  maxWeight?: number;\n  /** Px around the cursor that applies pressure. */\n  radius?: number;\n  /** Extra vertical stretch at full pressure (0.4 = 40% taller). */\n  stretch?: number;\n  /** Fade letters that feel no pressure. */\n  alpha?: boolean;\n  /** 0-1, how quickly letters catch up with the cursor. */\n  smoothing?: number;\n  className?: string;\n}\n\nexport function WeightPress({\n  text,\n  minWeight = 300,\n  maxWeight = 900,\n  radius = 280,\n  stretch = 0.35,\n  alpha = false,\n  smoothing = 0.16,\n  className,\n}: WeightPressProps) {\n  const ref = useRef<HTMLDivElement>(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    let pointer: { x: number; y: number } | null = null;\n    let raf = 0;\n\n    const tick = () => {\n      // Read every rect first, then write, so each frame costs one layout.\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 ? 0.5 + 0.5 * Math.cos((Math.PI * d) / radius) : 0;\n        level[i] += (target - level[i]) * smoothing;\n        if (Math.abs(target - level[i]) > 0.002) moving = true;\n        const p = level[i];\n        l.style.fontWeight = String(Math.round(minWeight + (maxWeight - minWeight) * p));\n        l.style.transform = `scaleY(${(1 + stretch * p).toFixed(3)})`;\n        if (alpha) l.style.opacity = (0.3 + 0.7 * p).toFixed(3);\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    letters.forEach((l) => {\n      l.style.fontWeight = String(minWeight);\n      l.style.transform = \"\";\n      l.style.opacity = alpha ? \"0.3\" : \"\";\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    };\n  }, [text, minWeight, maxWeight, radius, stretch, alpha, smoothing]);\n\n  return (\n    <div ref={ref} className={cn(\"flex w-full select-none justify-between leading-none\", className)}>\n      <span className=\"sr-only\">{text}</span>\n      {Array.from(text).map((c, i) => (\n        <span\n          key={i}\n          data-letter\n          aria-hidden\n          style={{ display: \"inline-block\", whiteSpace: \"pre\", fontWeight: minWeight, transformOrigin: \"50% 100%\", willChange: \"transform\" }}\n        >\n          {c}\n        </span>\n      ))}\n    </div>\n  );\n}\n"}]}