{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "text-weight-trail",
  "type": "registry:component",
  "title": "Text Weight Trail",
  "description": "Letters gain weight and color from how fast the pointer moves across them, then cool back down, so a quick swipe leaves a bold trail that fades. Optional autoplay sweeps a ghost pointer when idle.",
  "author": "Hyperblur <hello@hyperblur.dev>",
  "dependencies": [],
  "registryDependencies": [],
  "categories": [
    "text",
    "pointer",
    "velocity",
    "variable font",
    "weight",
    "trail",
    "interactive"
  ],
  "docs": "https://hyperblur.dev/effects/text-weight-trail",
  "files": [
    {
      "path": "registry/hyperblur/text-weight-trail.tsx",
      "type": "registry:component",
      "target": "components/hyperblur/text-weight-trail.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\n\nexport interface TextWeightTrailProps extends React.HTMLAttributes<HTMLSpanElement> {\n  text: string;\n  minWeight?: number;\n  maxWeight?: number;\n  accent?: string;\n  radius?: number;\n  sensitivity?: number;\n  decay?: number;\n  autoPlay?: boolean;\n}\n\nconst css = `\n.hb-vi7 {\n  position: relative;\n  display: inline-block;\n  font-family: inherit;\n  white-space: pre-wrap;\n  box-sizing: border-box;\n  touch-action: pan-y;\n}\n.hb-vi7 *, .hb-vi7 *::before, .hb-vi7 *::after { box-sizing: border-box; }\n.hb-vi7-sr {\n  position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0;\n  overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;\n}\n.hb-vi7-w { display: inline-block; white-space: nowrap; }\n.hb-vi7-c {\n  position: relative;\n  display: inline-grid;\n  justify-items: center;\n}\n.hb-vi7-c > span { grid-area: 1 / 1; }\n.hb-vi7-g { visibility: hidden; font-weight: var(--hb-vi7-max); }\n.hb-vi7-l {\n  font-weight: var(--hb-vi7-min);\n  color: color-mix(in oklab, var(--hb-vi7-accent) calc(var(--hb-vi7-h, 0) * 100%), currentColor);\n}\n.hb-vi7-c::after {\n  content: \"\";\n  position: absolute;\n  left: 12%; right: 12%;\n  bottom: -0.12em;\n  height: 0.07em;\n  border-radius: 0.04em;\n  background: var(--hb-vi7-accent);\n  transform: scaleX(var(--hb-vi7-h, 0));\n  opacity: var(--hb-vi7-h, 0);\n}\n`;\n\nfunction smooth(x: number) {\n  const t = Math.max(0, Math.min(1, x));\n  return t * t * (3 - 2 * t);\n}\n\nexport function TextWeightTrail({\n  text,\n  minWeight = 250,\n  maxWeight = 900,\n  accent = \"#7fb3ff\",\n  radius = 70,\n  sensitivity = 1,\n  decay = 0.93,\n  autoPlay = false,\n  className = \"\",\n  style,\n  onPointerMove,\n  onPointerLeave,\n  ...rest\n}: TextWeightTrailProps) {\n  const ref = React.useRef<HTMLSpanElement>(null);\n  const cells = React.useRef<(HTMLSpanElement | null)[]>([]);\n  const words = React.useMemo(() => text.split(/(\\s+)/), [text]);\n  const total = React.useMemo(() => Array.from(text).filter((c) => c.trim() !== \"\").length, [text]);\n  const engine = React.useRef<{ kick: (x: number, y: number, speed: number) => void; wake: () => void } | null>(null);\n  const lastMove = React.useRef<{ x: number; y: number; t: number } | null>(null);\n  const userAt = React.useRef(0);\n\n  React.useEffect(() => {\n    const root = ref.current;\n    if (!root) return;\n    const reduced = window.matchMedia(\"(prefers-reduced-motion: reduce)\").matches;\n    if (reduced) return;\n    const list = cells.current.slice(0, total);\n    const heat = new Float32Array(total);\n    let centers: { x: number; y: number }[] = [];\n    let raf = 0;\n    let visible = true;\n    let ghostT = 0;\n    let ghostPrev: { x: number; y: number } | null = null;\n    let lastFrame = 0;\n\n    const measure = () => {\n      const r = root.getBoundingClientRect();\n      centers = list.map((el) => {\n        if (!el) return { x: -9999, y: -9999 };\n        const b = el.getBoundingClientRect();\n        return { x: b.left - r.left + b.width / 2, y: b.top - r.top + b.height / 2 };\n      });\n    };\n\n    const apply = () => {\n      list.forEach((el, i) => {\n        if (!el) return;\n        const h = smooth(heat[i]);\n        el.style.setProperty(\"--hb-vi7-h\", h.toFixed(3));\n        const label = el.lastElementChild as HTMLSpanElement | null;\n        if (label) label.style.fontWeight = String(Math.round(minWeight + (maxWeight - minWeight) * h));\n      });\n    };\n\n    const kick = (x: number, y: number, speed: number) => {\n      const s = Math.min(1.6, speed * sensitivity * 0.9);\n      for (let i = 0; i < centers.length; i++) {\n        const dx = centers[i].x - x;\n        const dy = (centers[i].y - y) * 1.6;\n        const d = Math.sqrt(dx * dx + dy * dy);\n        if (d > radius) continue;\n        const f = 1 - d / radius;\n        heat[i] = Math.min(1, heat[i] + s * f * f * 0.5);\n      }\n    };\n\n    const frame = (now: number) => {\n      const dt = lastFrame ? Math.min(48, now - lastFrame) : 16;\n      lastFrame = now;\n      const k = Math.pow(decay, dt / 16.67);\n      let active = false;\n      for (let i = 0; i < heat.length; i++) {\n        heat[i] *= k;\n        if (heat[i] > 0.002) active = true;\n        else heat[i] = 0;\n      }\n      if (autoPlay && visible && now - userAt.current > 1600) {\n        const w = root.clientWidth;\n        const hgt = root.clientHeight;\n        ghostT += dt / 1000;\n        const u = (Math.sin(ghostT * 1.25) + 1) / 2;\n        const x = w * (0.04 + u * 0.92);\n        const y = hgt * (0.5 + Math.sin(ghostT * 2.7) * 0.18);\n        if (ghostPrev) {\n          const sp = Math.hypot(x - ghostPrev.x, y - ghostPrev.y) / dt;\n          kick(x, y, sp * 1.4);\n        }\n        ghostPrev = { x, y };\n        active = true;\n      } else {\n        ghostPrev = null;\n      }\n      apply();\n      raf = active && visible ? requestAnimationFrame(frame) : 0;\n      if (!raf) lastFrame = 0;\n    };\n\n    const wake = () => {\n      if (!raf && visible) raf = requestAnimationFrame(frame);\n    };\n\n    engine.current = {\n      kick: (x, y, speed) => {\n        kick(x, y, speed);\n        wake();\n      },\n      wake,\n    };\n\n    measure();\n    const ro = typeof ResizeObserver !== \"undefined\" ? new ResizeObserver(measure) : null;\n    ro?.observe(root);\n    if (document.fonts?.ready) document.fonts.ready.then(measure).catch(() => undefined);\n    const io =\n      typeof IntersectionObserver !== \"undefined\"\n        ? new IntersectionObserver((entries) => {\n            visible = entries.some((e) => e.isIntersecting);\n            if (visible) wake();\n          })\n        : null;\n    io?.observe(root);\n    wake();\n    return () => {\n      cancelAnimationFrame(raf);\n      ro?.disconnect();\n      io?.disconnect();\n      engine.current = null;\n    };\n  }, [minWeight, maxWeight, radius, sensitivity, decay, autoPlay, words, total]);\n\n  const vars = {\n    \"--hb-vi7-min\": minWeight,\n    \"--hb-vi7-max\": maxWeight,\n    \"--hb-vi7-accent\": accent,\n    ...style,\n  } as React.CSSProperties;\n\n  let n = 0;\n\n  return (\n    <span\n      ref={ref}\n      className={`hb-vi7 ${className}`}\n      style={vars}\n      onPointerMove={(e) => {\n        const root = ref.current;\n        if (!root) return;\n        const r = root.getBoundingClientRect();\n        const x = e.clientX - r.left;\n        const y = e.clientY - r.top;\n        const now = e.timeStamp;\n        userAt.current = performance.now();\n        const prev = lastMove.current;\n        lastMove.current = { x, y, t: now };\n        if (prev) {\n          const dt = Math.max(8, now - prev.t);\n          const speed = Math.hypot(x - prev.x, y - prev.y) / dt;\n          engine.current?.kick(x, y, speed);\n        }\n        onPointerMove?.(e);\n      }}\n      onPointerLeave={(e) => {\n        lastMove.current = null;\n        onPointerLeave?.(e);\n      }}\n      {...rest}\n    >\n      <style href=\"hb-text-weight-trail\" precedence=\"default\">{css}</style>\n      <span className=\"hb-vi7-sr\">{text}</span>\n      <span aria-hidden=\"true\">\n        {words.map((word, wi) => {\n          if (word.trim() === \"\") return <React.Fragment key={wi}>{word}</React.Fragment>;\n          return (\n            <span className=\"hb-vi7-w\" key={wi}>\n              {Array.from(word).map((ch, ci) => {\n                const i = n++;\n                return (\n                  <span\n                    key={ci}\n                    className=\"hb-vi7-c\"\n                    ref={(el) => {\n                      cells.current[i] = el;\n                    }}\n                  >\n                    <span className=\"hb-vi7-g\">{ch}</span>\n                    <span className=\"hb-vi7-l\">{ch}</span>\n                  </span>\n                );\n              })}\n            </span>\n          );\n        })}\n      </span>\n    </span>\n  );\n}\n"
    }
  ]
}