{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "text-rack-focus",
  "type": "registry:component",
  "title": "Text Rack Focus",
  "description": "A camera focus pull across a line: the plane of focus travels in from the left, lands on a chosen word with a hint of chromatic fringe, then the depth of field opens until the whole line is sharp.",
  "author": "Hyperblur <hello@hyperblur.dev>",
  "dependencies": [],
  "registryDependencies": [],
  "categories": [
    "text",
    "focus",
    "blur",
    "camera",
    "cinematic",
    "depth",
    "headline"
  ],
  "docs": "https://hyperblur.dev/effects/text-rack-focus",
  "files": [
    {
      "path": "registry/hyperblur/text-rack-focus.tsx",
      "type": "registry:component",
      "target": "components/hyperblur/text-rack-focus.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\n\nexport interface TextRackFocusProps extends React.HTMLAttributes<HTMLSpanElement> {\n  text: string;\n  focus?: string;\n  duration?: number;\n  maxBlur?: number;\n  aberration?: boolean;\n  trigger?: \"view\" | \"mount\";\n  loop?: number;\n}\n\nconst css = `\n.hb-vi12 {\n  position: relative;\n  display: inline-block;\n  font-family: inherit;\n  white-space: pre-wrap;\n  box-sizing: border-box;\n}\n.hb-vi12 *, .hb-vi12 *::before, .hb-vi12 *::after { box-sizing: border-box; }\n.hb-vi12-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-vi12-w { display: inline-block; white-space: nowrap; }\n.hb-vi12-c {\n  display: inline-block;\n  filter: blur(var(--hb-vi12-max));\n  opacity: 0.55;\n  transform: scale(1.06);\n  will-change: filter, transform;\n}\n@media (prefers-reduced-motion: reduce) {\n  .hb-vi12 .hb-vi12-c { filter: none !important; opacity: 1 !important; transform: none !important; text-shadow: none !important; will-change: auto; }\n}\n`;\n\nfunction clamp(v: number) {\n  return Math.max(0, Math.min(1, v));\n}\n\nfunction easeOut(t: number) {\n  return 1 - Math.pow(1 - clamp(t), 3);\n}\n\nfunction easeInOut(t: number) {\n  const x = clamp(t);\n  return x < 0.5 ? 4 * x * x * x : 1 - Math.pow(-2 * x + 2, 3) / 2;\n}\n\nexport function TextRackFocus({\n  text,\n  focus,\n  duration = 2.2,\n  maxBlur = 10,\n  aberration = true,\n  trigger = \"view\",\n  loop = 0,\n  className = \"\",\n  style,\n  ...rest\n}: TextRackFocusProps) {\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 letters = React.useMemo(() => Array.from(text).filter((c) => c.trim() !== \"\"), [text]);\n  const total = letters.length;\n  const target = React.useMemo(() => {\n    if (total < 2) return 0.5;\n    if (focus) {\n      const at = text.toLowerCase().indexOf(focus.toLowerCase());\n      if (at >= 0) {\n        const before = Array.from(text.slice(0, at)).filter((c) => c.trim() !== \"\").length;\n        const len = Array.from(focus).filter((c) => c.trim() !== \"\").length;\n        return (before + (len - 1) / 2) / (total - 1);\n      }\n    }\n    return 0.5;\n  }, [text, focus, total]);\n\n  React.useEffect(() => {\n    const root = ref.current;\n    if (!root) return;\n    if (window.matchMedia(\"(prefers-reduced-motion: reduce)\").matches) return;\n    const list = cells.current.slice(0, total);\n    let raf = 0;\n    let timer = 0;\n    let begin = 0;\n    let phase: \"idle\" | \"in\" | \"out\" = \"idle\";\n\n    const paint = (f: number, w: number, k: number) => {\n      list.forEach((el, i) => {\n        if (!el) return;\n        const x = total > 1 ? i / (total - 1) : 0.5;\n        const off = clamp((Math.abs(x - f) - w) / 0.32);\n        const amt = Math.max(off, k);\n        const b = maxBlur * amt;\n        el.style.filter = b < 0.05 ? \"none\" : `blur(${b.toFixed(2)}px)`;\n        el.style.opacity = (0.5 + 0.5 * (1 - amt)).toFixed(3);\n        el.style.transform = `scale(${(1 + amt * 0.06).toFixed(4)})`;\n        if (aberration && b > 0.4) {\n          const a = (b * 0.32).toFixed(2);\n          el.style.textShadow = `-${a}px 0 rgba(255, 70, 110, 0.55), ${a}px 0 rgba(70, 180, 255, 0.55)`;\n        } else {\n          el.style.textShadow = \"none\";\n        }\n      });\n    };\n\n    const frame = (now: number) => {\n      if (!begin) begin = now;\n      const elapsed = (now - begin) / 1000;\n      if (phase === \"in\") {\n        const p = elapsed / duration;\n        const f = -0.35 + (target + 0.35) * easeOut(p / 0.55);\n        const w = 0.05 + 2 * easeInOut((p - 0.5) / 0.5);\n        paint(f, w, 0);\n        if (p < 1) raf = requestAnimationFrame(frame);\n        else {\n          paint(target, 3, 0);\n          if (loop > 0) {\n            timer = window.setTimeout(() => {\n              phase = \"out\";\n              begin = 0;\n              raf = requestAnimationFrame(frame);\n            }, loop * 1000);\n          }\n        }\n      } else if (phase === \"out\") {\n        const p = elapsed / 0.6;\n        paint(target, 3, easeInOut(p));\n        if (p < 1) raf = requestAnimationFrame(frame);\n        else {\n          timer = window.setTimeout(() => {\n            phase = \"in\";\n            begin = 0;\n            raf = requestAnimationFrame(frame);\n          }, 260);\n        }\n      }\n    };\n\n    const start = () => {\n      if (phase !== \"idle\") return;\n      phase = \"in\";\n      begin = 0;\n      raf = requestAnimationFrame(frame);\n    };\n\n    let io: IntersectionObserver | null = null;\n    if (trigger === \"mount\" || typeof IntersectionObserver === \"undefined\") start();\n    else {\n      io = new IntersectionObserver(\n        (entries) => {\n          if (entries.some((e) => e.isIntersecting)) {\n            start();\n            io?.disconnect();\n          }\n        },\n        { threshold: 0.4 },\n      );\n      io.observe(root);\n    }\n    return () => {\n      cancelAnimationFrame(raf);\n      clearTimeout(timer);\n      io?.disconnect();\n    };\n  }, [total, target, duration, maxBlur, aberration, trigger, loop, words]);\n\n  const vars = { \"--hb-vi12-max\": `${maxBlur}px`, ...style } as React.CSSProperties;\n  let n = 0;\n\n  return (\n    <span ref={ref} className={`hb-vi12 ${className}`} style={vars} {...rest}>\n      <style href=\"hb-text-rack-focus\" precedence=\"default\">{css}</style>\n      <span className=\"hb-vi12-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-vi12-w\" key={wi}>\n              {Array.from(word).map((ch, ci) => {\n                const i = n++;\n                return (\n                  <span\n                    key={ci}\n                    className=\"hb-vi12-c\"\n                    ref={(el) => {\n                      cells.current[i] = el;\n                    }}\n                  >\n                    {ch}\n                  </span>\n                );\n              })}\n            </span>\n          );\n        })}\n      </span>\n    </span>\n  );\n}\n"
    }
  ]
}