{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "focus-sweep-text",
  "title": "Focus Sweep Text",
  "description": "A paragraph with a moving point of focus: a few words stay sharp while the rest soften into blur, drifting along by itself or following the pointer.",
  "dependencies": [],
  "files": [
    {
      "path": "registry/new-york/focus-sweep-text/focus-sweep-text.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\n\nexport interface FocusSweepTextProps extends Omit<\n  React.ComponentPropsWithoutRef<\"p\">,\n  \"children\"\n> {\n  text?: string;\n  /** Blur at the far end of the text, in px. */\n  blur?: number;\n  /** Words either side of the focus that stay sharp. */\n  band?: number;\n  /** Seconds for the focus to travel across and back. */\n  seconds?: 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 FocusSweepText({\n  text = \"Reading is a small act of attention. Everything outside the line you are on falls away, and for a moment only these few words exist, sharp and close, while the rest of the page waits its turn.\",\n  blur = 5,\n  band = 5,\n  seconds = 6,\n  className,\n  style,\n  onPointerMove,\n  onPointerLeave,\n  ...props\n}: FocusSweepTextProps) {\n  const reduce = useReducedMotion();\n  const rootRef = React.useRef<HTMLParagraphElement>(null);\n  const wordRefs = React.useRef<(HTMLSpanElement | null)[]>([]);\n  const pointer = React.useRef<number | null>(null);\n  const words = text.split(/\\s+/).filter(Boolean);\n  const count = words.length;\n\n  // The focus travels through the words on a slow sine, or sits under the pointer while there is one.\n  React.useEffect(() => {\n    const root = rootRef.current;\n    if (!root || reduce) return;\n    let raf = 0;\n    let at = 0;\n    const cycle = Math.max(1, seconds) * 1000;\n    const frame = (now: number) => {\n      const wander =\n        (0.5 - 0.5 * Math.cos(((now % cycle) / cycle) * Math.PI * 2)) *\n        (count - 1);\n      at += ((pointer.current ?? wander) - at) * 0.12;\n      wordRefs.current.slice(0, count).forEach((el, i) => {\n        if (!el) return;\n        const off = Math.max(0, Math.abs(i - at) - band) / (band * 2);\n        const soft = Math.min(1, off);\n        el.style.filter =\n          soft > 0.01 ? `blur(${(soft * blur).toFixed(2)}px)` : \"\";\n        el.style.opacity = (1 - soft * 0.62).toFixed(3);\n      });\n      raf = requestAnimationFrame(frame);\n    };\n    const io = new IntersectionObserver(([entry]) => {\n      cancelAnimationFrame(raf);\n      if (entry.isIntersecting) raf = requestAnimationFrame(frame);\n    });\n    io.observe(root);\n    return () => {\n      io.disconnect();\n      cancelAnimationFrame(raf);\n    };\n  }, [reduce, seconds, band, blur, count]);\n\n  return (\n    <p\n      ref={rootRef}\n      aria-label={text}\n      className={className}\n      style={style}\n      onPointerMove={(e) => {\n        onPointerMove?.(e);\n        const hit = (e.target as HTMLElement).dataset?.word;\n        if (hit !== undefined) pointer.current = Number(hit);\n      }}\n      onPointerLeave={(e) => {\n        onPointerLeave?.(e);\n        pointer.current = null;\n      }}\n      {...props}\n    >\n      {words.map((word, i) => (\n        <React.Fragment key={i}>\n          <span\n            ref={(el) => {\n              wordRefs.current[i] = el;\n            }}\n            data-word={i}\n            aria-hidden=\"true\"\n            className=\"inline-block\"\n          >\n            {word}\n          </span>{\" \"}\n        </React.Fragment>\n      ))}\n    </p>\n  );\n}\n",
      "type": "registry:component"
    }
  ],
  "type": "registry:component"
}