{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"soft-spotlight-gradient-following-pointer-background","type":"registry:block","title":"Soft Spotlight That Follows the Pointer","description":"","dependencies":[],"files":[{"path":"components/we-inc/soft-spotlight-gradient-following-pointer-background.tsx","type":"registry:component","content":"import { useEffect, useRef } from \"react\";\n\n// How quickly the lamp catches up with the pointer (0 to 1; smaller is lazier).\nconst EASE = 0.06;\n// Seconds without pointer movement before the lamp starts drifting on its own.\nconst IDLE_AFTER = 2.5;\n\nconst css = `\n.spl-hero{--spl-light:255,222,184;--spl-size:900px}\n.spl-lamp{width:var(--spl-size);height:var(--spl-size);margin:calc(var(--spl-size) / -2) 0 0 calc(var(--spl-size) / -2);background:radial-gradient(closest-side,rgba(var(--spl-light),.34),rgba(var(--spl-light),.16) 38%,rgba(var(--spl-light),.05) 66%,transparent);mix-blend-mode:screen;will-change:transform;transform:translate3d(65vw,260px,0)}\n.spl-pool{width:70vw;height:200px;margin-left:-35vw;background:radial-gradient(closest-side,rgba(var(--spl-light),.14),transparent);will-change:transform;transform:translate3d(65vw,0,0)}\n.spl-sweep{background:linear-gradient(180deg,#23211e 0%,#2b2825 58%,#34302c 74%,#1c1a18 100%)}\n.spl-grain{background-image:url(\"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='180' height='180'%3E%3Cfilter id='g'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.8' numOctaves='3' stitchTiles='stitch'/%3E%3CfeColorMatrix type='saturate' values='0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url%28%23g%29'/%3E%3C/svg%3E\");mix-blend-mode:overlay;opacity:.34}\n`;\n\nexport default function SoftSpotlightFollowingPointer() {\n  const rootRef = useRef<HTMLElement>(null);\n  const lampRef = useRef<HTMLDivElement>(null);\n  const poolRef = useRef<HTMLDivElement>(null);\n\n  useEffect(() => {\n    const root = rootRef.current;\n    const lamp = lampRef.current;\n    const pool = poolRef.current;\n    if (!root || !lamp || !pool) return;\n    const still = window.matchMedia(\"(prefers-reduced-motion: reduce)\").matches;\n    let w = 0, h = 0, x = 0, y = 0, tx = 0, ty = 0, lastInput = -1e9, raf = 0, onScreen = true;\n\n    const place = () => {\n      lamp.style.transform = `translate3d(${x.toFixed(1)}px,${y.toFixed(1)}px,0)`;\n      pool.style.transform = `translate3d(${x.toFixed(1)}px,0,0)`;\n    };\n    const measure = () => {\n      const box = root.getBoundingClientRect();\n      w = box.width; h = box.height;\n      if (!x) { x = w * 0.68; y = h * 0.42; }\n      if (still) { x = w * 0.7; y = h * 0.4; }\n      place();\n    };\n    const frame = (now: number) => {\n      const t = now / 1000;\n      if (t - lastInput > IDLE_AFTER) {\n        // Idle: wander slowly in a loose figure of eight.\n        tx = w * (0.55 + 0.3 * Math.sin(t * 0.23));\n        ty = h * (0.45 + 0.22 * Math.sin(t * 0.37 + 1.2));\n      }\n      x += (tx - x) * EASE;\n      y += (ty - y) * EASE;\n      place();\n      if (onScreen) raf = requestAnimationFrame(frame);\n    };\n    const aim = (cx: number, cy: number) => {\n      const box = root.getBoundingClientRect();\n      tx = cx - box.left; ty = cy - box.top;\n      lastInput = performance.now() / 1000;\n    };\n    const onMove = (e: PointerEvent) => aim(e.clientX, e.clientY);\n    // Keyboard users: the lamp swings over whatever link or button has focus.\n    const onFocus = (e: FocusEvent) => {\n      const r = (e.target as HTMLElement).getBoundingClientRect();\n      aim(r.left + r.width / 2, r.top + r.height / 2);\n    };\n    const ro = new ResizeObserver(measure);\n    ro.observe(root);\n    measure();\n    if (still) return () => ro.disconnect();\n    root.addEventListener(\"pointermove\", onMove, { passive: true });\n    root.addEventListener(\"focusin\", onFocus);\n    const io = new IntersectionObserver(([entry]) => {\n      onScreen = entry.isIntersecting;\n      cancelAnimationFrame(raf);\n      if (onScreen) raf = requestAnimationFrame(frame);\n    });\n    io.observe(root);\n    return () => {\n      cancelAnimationFrame(raf);\n      ro.disconnect();\n      io.disconnect();\n      root.removeEventListener(\"pointermove\", onMove);\n      root.removeEventListener(\"focusin\", onFocus);\n    };\n  }, []);\n\n  return (\n    <section ref={rootRef} className=\"spl-hero relative isolate flex min-h-[600px] touch-pan-y items-center overflow-hidden bg-[#1b1a19]\">\n      <style>{css}</style>\n      <div aria-hidden=\"true\" className=\"pointer-events-none absolute inset-0 -z-10\">\n        <div className=\"spl-sweep absolute inset-0\" />\n        <div ref={lampRef} className=\"spl-lamp absolute left-0 top-0 rounded-full\" />\n        <div ref={poolRef} className=\"spl-pool absolute bottom-[-60px] left-0 rounded-full\" />\n        <div className=\"spl-grain absolute inset-0\" />\n      </div>\n      <div className=\"mx-auto w-full max-w-5xl px-6 py-24 sm:px-10 sm:py-[110px]\">\n        <p className=\"text-[13px] font-medium uppercase tracking-[0.2em] text-[#d9c6b0]\">Studio Ashgrove &middot; Portraits</p>\n        <h1 className=\"mt-[18px] max-w-[38rem] font-serif text-[34px] font-normal leading-[1.08] text-[#faf4ec] sm:text-[58px]\">Portraits lit the old way, one lamp at a time.</h1>\n        <p className=\"mt-5 max-w-[30rem] text-lg leading-relaxed text-[#d8cfc5]\">An hour in a quiet studio, a canvas backdrop that has seen forty years of sittings, and prints you choose together on the day.</p>\n        <a href=\"#\" className=\"mt-8 inline-flex h-12 items-center rounded-full bg-[#f4ebe0] px-[26px] text-[15px] font-semibold text-[#1f1b17] hover:bg-white focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[#f4ebe0] focus-visible:ring-offset-2 focus-visible:ring-offset-[#1b1a19]\">Book a sitting</a>\n      </div>\n    </section>\n  );\n}\n"}]}
