{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "color-sweep-heading",
  "title": "Color Sweep Heading",
  "description": "A dimmed heading that fills with a colour gradient from left to right as it comes into view, and follows the pointer back and forth.",
  "dependencies": [],
  "files": [
    {
      "path": "registry/new-york/color-sweep-heading/color-sweep-heading.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\n\nexport interface ColorSweepHeadingProps extends Omit<\n  React.HTMLAttributes<HTMLHeadingElement>,\n  \"children\"\n> {\n  text?: string;\n  as?: \"h1\" | \"h2\" | \"h3\" | \"p\";\n  /** Colours of the sweep, from left to right. */\n  colors?: string[];\n  /** Milliseconds the first sweep takes. */\n  duration?: 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\nconst COLORS = [\"#5E6AD2\", \"#4EA7FC\", \"#2EE6A8\"];\nconst EDGE = 14;\n\nexport function ColorSweepHeading({\n  text = \"Colour follows your hand\",\n  as: Tag = \"h2\",\n  colors = COLORS,\n  duration = 1600,\n  className,\n  style,\n  onPointerMove,\n  onPointerLeave,\n  ...props\n}: ColorSweepHeadingProps) {\n  const reduce = useReducedMotion();\n  const rootRef = React.useRef<HTMLHeadingElement>(null);\n  const fillRef = React.useRef<HTMLSpanElement>(null);\n  const goal = React.useRef(0);\n  const start = React.useRef<() => void>(() => {});\n\n  // The edge of the colour eases toward its goal: fully across at rest, or wherever the pointer is.\n  React.useEffect(() => {\n    const root = rootRef.current;\n    const fill = fillRef.current;\n    if (!root || !fill) return;\n    let raf = 0;\n    let at = reduce ? 100 + EDGE : -EDGE;\n    let prev = 0;\n    const write = () => fill.style.setProperty(\"--edge\", `${at.toFixed(2)}%`);\n    const frame = (now: number) => {\n      const dt = Math.min(0.05, prev ? (now - prev) / 1000 : 1 / 60);\n      prev = now;\n      at += (goal.current - at) * (1 - Math.exp(-dt * (3200 / duration)));\n      const done = Math.abs(goal.current - at) < 0.1;\n      if (done) at = goal.current;\n      write();\n      if (done) {\n        raf = 0;\n        prev = 0;\n      } else raf = requestAnimationFrame(frame);\n    };\n    start.current = () => {\n      if (reduce) {\n        at = goal.current;\n        write();\n      } else if (!raf) raf = requestAnimationFrame(frame);\n    };\n    write();\n    const io = new IntersectionObserver(\n      ([entry]) => {\n        if (!entry.isIntersecting) return;\n        io.disconnect();\n        goal.current = 100 + EDGE;\n        start.current();\n      },\n      { threshold: 0.3 },\n    );\n    io.observe(root);\n    return () => {\n      io.disconnect();\n      cancelAnimationFrame(raf);\n    };\n  }, [reduce, duration]);\n\n  const mask = `linear-gradient(90deg, #000 calc(var(--edge) - ${EDGE}%), transparent calc(var(--edge) + ${EDGE}%))`;\n  return (\n    <Tag\n      ref={rootRef}\n      className={`relative ${className ?? \"\"}`}\n      style={style}\n      onPointerMove={(e: React.PointerEvent<HTMLHeadingElement>) => {\n        onPointerMove?.(e);\n        if (e.pointerType !== \"mouse\") return;\n        const r = e.currentTarget.getBoundingClientRect();\n        goal.current = ((e.clientX - r.left) / r.width) * 100;\n        start.current();\n      }}\n      onPointerLeave={(e: React.PointerEvent<HTMLHeadingElement>) => {\n        onPointerLeave?.(e);\n        goal.current = 100 + EDGE;\n        start.current();\n      }}\n      {...props}\n    >\n      <span style={{ opacity: 0.22 }}>{text}</span>\n      <span\n        ref={fillRef}\n        aria-hidden=\"true\"\n        className=\"pointer-events-none absolute inset-0 block bg-clip-text\"\n        style={\n          {\n            \"--edge\": \"0%\",\n            WebkitTextFillColor: \"transparent\",\n            WebkitBackgroundClip: \"text\",\n            backgroundImage: `linear-gradient(90deg, ${colors.join(\", \")})`,\n            WebkitMaskImage: mask,\n            maskImage: mask,\n          } as React.CSSProperties\n        }\n      >\n        {text}\n      </span>\n    </Tag>\n  );\n}\n",
      "type": "registry:component"
    }
  ],
  "type": "registry:component"
}