{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "text-pressure",
  "type": "registry:component",
  "title": "Text Pressure",
  "description": "Every letter swells in weight and size as the pointer gets close, with a slow breathing wave when nothing is touching it.",
  "author": "Hyperblur <hello@hyperblur.dev>",
  "dependencies": [],
  "registryDependencies": [],
  "categories": [
    "text",
    "text",
    "variable font",
    "weight",
    "pointer",
    "hover",
    "typography"
  ],
  "docs": "https://hyperblur.dev/effects/text-pressure",
  "files": [
    {
      "path": "registry/hyperblur/text-pressure.tsx",
      "type": "registry:component",
      "target": "components/hyperblur/text-pressure.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\n\nexport interface TextPressureProps extends React.HTMLAttributes<HTMLSpanElement> {\n  text: string;\n  minWeight?: number;\n  maxWeight?: number;\n  maxScale?: number;\n  radius?: number;\n  breathe?: boolean;\n  align?: \"left\" | \"center\" | \"right\";\n}\n\nconst css = `\n.hb-qd1 {\n  position: relative;\n  display: block;\n  width: 100%;\n  box-sizing: border-box;\n  padding: 0.25em 0.15em;\n  line-height: 1.05;\n  text-align: var(--hb-qd1-align);\n  touch-action: pan-y;\n  cursor: default;\n  font-family: inherit;\n}\n.hb-qd1 *, .hb-qd1 *::before, .hb-qd1 *::after { box-sizing: border-box; }\n.hb-qd1-sr {\n  position: absolute;\n  width: 1px;\n  height: 1px;\n  margin: -1px;\n  padding: 0;\n  overflow: hidden;\n  clip: rect(0, 0, 0, 0);\n  white-space: nowrap;\n  border: 0;\n}\n.hb-qd1-w { display: inline-block; white-space: nowrap; }\n.hb-qd1-l {\n  display: inline-block;\n  font-weight: var(--hb-qd1-mid);\n  transform-origin: 50% 72%;\n  will-change: transform, font-weight;\n}\n`;\n\nfunction tokenize(text: string) {\n  let n = 0;\n  return text\n    .split(/(\\s+)/)\n    .filter((t) => t !== \"\")\n    .map((value) => {\n      if (/^\\s+$/.test(value)) return { space: true, letters: [] as { ch: string; n: number }[], value };\n      return { space: false, value, letters: Array.from(value).map((ch) => ({ ch, n: n++ })) };\n    });\n}\n\nexport function TextPressure({\n  text,\n  minWeight = 300,\n  maxWeight = 900,\n  maxScale = 1.18,\n  radius = 150,\n  breathe = true,\n  align = \"center\",\n  className = \"\",\n  style,\n  ...rest\n}: TextPressureProps) {\n  const ref = React.useRef<HTMLSpanElement>(null);\n  const tokens = React.useMemo(() => tokenize(text), [text]);\n\n  React.useEffect(() => {\n    const root = ref.current;\n    if (!root) return;\n    const letters = Array.from(root.querySelectorAll<HTMLElement>(\"[data-l]\"));\n    if (letters.length === 0) return;\n    const mid = Math.round((minWeight + maxWeight) / 2);\n    if (window.matchMedia(\"(prefers-reduced-motion: reduce)\").matches) {\n      for (const l of letters) l.style.fontWeight = String(mid);\n      return;\n    }\n\n    const pointer = { x: 0, y: 0, inside: false };\n    const sigma = Math.max(20, radius) / 2.2;\n    const span = maxWeight - minWeight;\n    const start = performance.now();\n    let blend = 0;\n    let visible = true;\n    let raf = 0;\n\n    const tick = (now: number) => {\n      raf = 0;\n      if (!visible) return;\n      const box = root.getBoundingClientRect();\n      const t = (now - start) / 1000;\n      blend += ((pointer.inside ? 1 : 0) - blend) * 0.12;\n      const ix = box.left + box.width * (0.5 + 0.44 * Math.sin(t * 0.85));\n      const iy = box.top + box.height * 0.5;\n      const px = ix + (pointer.x - ix) * blend;\n      const py = iy + (pointer.y - iy) * blend;\n      const rects = letters.map((l) => l.getBoundingClientRect());\n      for (let i = 0; i < letters.length; i++) {\n        const r = rects[i];\n        const dx = r.left + r.width / 2 - px;\n        const dy = (r.top + r.height / 2 - py) * 0.7;\n        const f = Math.exp(-(dx * dx + dy * dy) / (2 * sigma * sigma));\n        const wave = breathe ? 0.1 + 0.1 * Math.sin(t * 1.7 - i * 0.55) : 0;\n        const k = Math.min(1, f + wave * (1 - 0.6 * blend));\n        const el = letters[i];\n        el.style.fontWeight = (minWeight + span * k).toFixed(1);\n        el.style.transform = `scale(${(1 + (maxScale - 1) * k).toFixed(3)})`;\n      }\n      raf = requestAnimationFrame(tick);\n    };\n\n    const kick = () => {\n      if (!raf && visible) raf = requestAnimationFrame(tick);\n    };\n    const move = (e: PointerEvent) => {\n      pointer.x = e.clientX;\n      pointer.y = e.clientY;\n      pointer.inside = true;\n    };\n    const leave = () => {\n      pointer.inside = false;\n    };\n    const io = new IntersectionObserver(([entry]) => {\n      visible = entry.isIntersecting;\n      kick();\n    });\n    io.observe(root);\n    root.addEventListener(\"pointerenter\", move);\n    root.addEventListener(\"pointermove\", move);\n    root.addEventListener(\"pointerleave\", leave);\n    root.addEventListener(\"pointercancel\", leave);\n    kick();\n    return () => {\n      cancelAnimationFrame(raf);\n      io.disconnect();\n      root.removeEventListener(\"pointerenter\", move);\n      root.removeEventListener(\"pointermove\", move);\n      root.removeEventListener(\"pointerleave\", leave);\n      root.removeEventListener(\"pointercancel\", leave);\n    };\n  }, [tokens, minWeight, maxWeight, maxScale, radius, breathe]);\n\n  const vars = {\n    \"--hb-qd1-align\": align,\n    \"--hb-qd1-mid\": Math.round((minWeight + maxWeight) / 2),\n    ...style,\n  } as React.CSSProperties;\n\n  return (\n    <span ref={ref} className={`hb-qd1 ${className}`} style={vars} {...rest}>\n      <style href=\"hb-text-pressure\" precedence=\"default\">{css}</style>\n      <span className=\"hb-qd1-sr\">{text}</span>\n      <span aria-hidden=\"true\">\n        {tokens.map((tok, i) =>\n          tok.space ? (\n            \" \"\n          ) : (\n            <span key={i} className=\"hb-qd1-w\">\n              {tok.letters.map((l) => (\n                <span key={l.n} className=\"hb-qd1-l\" data-l=\"\">\n                  {l.ch}\n                </span>\n              ))}\n            </span>\n          ),\n        )}\n      </span>\n    </span>\n  );\n}\n"
    }
  ]
}