{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"eased-ring-cursor-that-grows-and-snaps-to-links","type":"registry:block","title":"Eased Ring Cursor That Snaps to Links","description":"","dependencies":["framer-motion"],"files":[{"path":"components/we-inc/eased-ring-cursor-that-grows-and-snaps-to-links.tsx","type":"registry:component","content":"import { useEffect, useRef } from \"react\";\nimport { useReducedMotion } from \"framer-motion\";\n\nconst EASE = 0.16; // how quickly the ring catches up (0 to 1)\nconst SIZE = 40; // ring diameter in px\nconst PULL = 0.18; // how far a snapped ring still leans toward the pointer\nconst projects = [\n  { name: \"Kettle Yard Library\", place: \"Ashby, 2025\" },\n  { name: \"Salt Store Housing\", place: \"Felixmouth, 2024\" },\n  { name: \"Orchard Lane School\", place: \"Brimley, 2023\" },\n  { name: \"Tidemill Studios\", place: \"Harwick, 2022\" },\n];\n\nexport default function EasedRingCursorThatGrowsAndSnapsToLinks() {\n  const reduce = useReducedMotion();\n  const rootRef = useRef<HTMLElement>(null);\n  const ringRef = useRef<HTMLSpanElement>(null);\n  const dotRef = useRef<HTMLSpanElement>(null);\n\n  useEffect(() => {\n    const root = rootRef.current, ring = ringRef.current, dot = dotRef.current;\n    if (!root || !ring || !dot || reduce || !matchMedia(\"(hover: hover) and (pointer: fine)\").matches) return;\n    const snaps = Array.from(root.querySelectorAll<HTMLElement>(\"[data-snap]\"));\n    root.setAttribute(\"data-on\", \"\");\n    let px = 0, py = 0, rx = 0, ry = 0, rs = 1, live = false, frame = 0, idle = 0;\n    let hot: HTMLElement | null = null, was: boolean | null = null;\n    const t0 = performance.now();\n    const box = (el: HTMLElement) => {\n      const a = (el.querySelector(\".w2rng-arrow\") || el).getBoundingClientRect(), o = root.getBoundingClientRect();\n      return { x: a.left - o.left + a.width / 2, y: a.top - o.top + a.height / 2, s: Math.min(Math.max(a.width, a.height) + 14, 84) / SIZE };\n    };\n    const loop = (now: number) => {\n      const target = live ? hot : snaps[Math.floor(Math.max(0, now - t0) / 1700) % snaps.length];\n      let tx = px, ty = py, ts = 1;\n      if (target) {\n        const b = box(target);\n        if (!live) { px += (b.x - px) * 0.1; py += (b.y - py) * 0.1; }\n        tx = b.x + (px - b.x) * PULL; ty = b.y + (py - b.y) * PULL; ts = b.s;\n      }\n      rx += (tx - rx) * EASE; ry += (ty - ry) * EASE; rs += (ts - rs) * EASE;\n      ring.style.transform = `translate(${rx}px, ${ry}px) scale(${rs})`;\n      dot.style.transform = `translate(${px}px, ${py}px)`;\n      if (!!target !== was) { was = !!target; root.toggleAttribute(\"data-hot\", was); }\n      frame = requestAnimationFrame(loop);\n    };\n    const start = () => { if (!frame) frame = requestAnimationFrame(loop); };\n    const stop = () => { cancelAnimationFrame(frame); frame = 0; };\n    const onMove = (e: PointerEvent) => {\n      if (e.pointerType === \"touch\") return;\n      const o = root.getBoundingClientRect();\n      px = e.clientX - o.left; py = e.clientY - o.top;\n      hot = (e.target as HTMLElement).closest<HTMLElement>(\"[data-snap]\");\n      live = true; clearTimeout(idle);\n      root.setAttribute(\"data-live\", \"\"); root.removeAttribute(\"data-kb\");\n    };\n    const onLeave = () => { hot = null; root.removeAttribute(\"data-live\"); idle = window.setTimeout(() => { live = false; }, 1500); };\n    const onFocus = () => { if (root.querySelector(\":focus-visible\")) root.setAttribute(\"data-kb\", \"\"); };\n    const onBlur = () => root.removeAttribute(\"data-kb\");\n    const io = new IntersectionObserver(([e]) => (e.isIntersecting ? start() : stop()));\n    io.observe(root);\n    root.addEventListener(\"pointermove\", onMove);\n    root.addEventListener(\"pointerleave\", onLeave);\n    root.addEventListener(\"focusin\", onFocus);\n    root.addEventListener(\"focusout\", onBlur);\n    return () => {\n      stop(); io.disconnect(); clearTimeout(idle);\n      [\"data-on\", \"data-live\", \"data-hot\", \"data-kb\"].forEach((a) => root.removeAttribute(a));\n      root.removeEventListener(\"pointermove\", onMove);\n      root.removeEventListener(\"pointerleave\", onLeave);\n      root.removeEventListener(\"focusin\", onFocus);\n      root.removeEventListener(\"focusout\", onBlur);\n    };\n  }, [reduce]);\n\n  const navLink = \"inline-flex min-h-[40px] items-center rounded-full px-3 text-sm text-slate-600 hover:text-slate-900 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-blue-600 focus-visible:ring-offset-2\";\n\n  return (\n    <section ref={rootRef} className=\"w2rng-root relative overflow-hidden bg-[#f6f7f9] px-5 pb-16 pt-12 text-slate-800 sm:px-10 sm:pb-[72px] sm:pt-14\">\n      <style>{`\n        .w2rng-ring, .w2rng-dot { position: absolute; left: 0; top: 0; pointer-events: none; opacity: 0; transition: opacity .3s ease; will-change: transform; }\n        .w2rng-ring { width: 40px; height: 40px; margin: -20px 0 0 -20px; border-radius: 50%; border: 1px solid #1e293b; }\n        .w2rng-fill { position: absolute; inset: 0; border-radius: 50%; background: rgba(30,41,59,.08); opacity: 0; transition: opacity .3s ease; }\n        .w2rng-root[data-hot] .w2rng-fill { opacity: 1; }\n        .w2rng-dot { width: 6px; height: 6px; margin: -3px 0 0 -3px; border-radius: 50%; background: #1e293b; }\n        .w2rng-root[data-on] .w2rng-ring, .w2rng-root[data-on] .w2rng-dot { opacity: 1; }\n        .w2rng-root[data-kb] .w2rng-ring, .w2rng-root[data-kb] .w2rng-dot { opacity: 0; }\n        .w2rng-name { transition: transform .4s cubic-bezier(.2,.8,.2,1); }\n        .w2rng-row:hover .w2rng-name, .w2rng-row:focus-visible .w2rng-name { transform: translateX(8px); }\n        @media (hover: hover) and (pointer: fine) and (prefers-reduced-motion: no-preference) {\n          .w2rng-root[data-on][data-live], .w2rng-root[data-on][data-live] * { cursor: none; }\n        }\n        @media (prefers-reduced-motion: reduce) { .w2rng-ring, .w2rng-dot { display: none; } .w2rng-name { transition: none; } }\n      `}</style>\n      <div className=\"mx-auto max-w-5xl\">\n        <nav aria-label=\"Halden Works\" className=\"flex flex-wrap items-center justify-between gap-3\">\n          <a href=\"#\" data-snap className=\"inline-flex min-h-[40px] items-center rounded font-bold tracking-tight text-slate-800 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-blue-600 focus-visible:ring-offset-2\">Halden Works</a>\n          <ul className=\"flex gap-1\">\n            {[\"Studio\", \"Journal\", \"Contact\"].map((l) => (\n              <li key={l}><a href=\"#\" data-snap className={navLink}>{l}</a></li>\n            ))}\n          </ul>\n        </nav>\n        <h2 className=\"mb-4 mt-12 text-xs font-semibold uppercase tracking-[0.2em] text-slate-600\">Selected buildings</h2>\n        <ul className=\"border-b border-[#d5dae1]\">\n          {projects.map((p) => (\n            <li key={p.name}>\n              <a href=\"#\" data-snap className=\"w2rng-row grid grid-cols-[1fr_auto] items-center gap-x-4 gap-y-1 border-t border-[#d5dae1] py-5 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-blue-600 focus-visible:ring-offset-4 focus-visible:ring-offset-[#f6f7f9] md:grid-cols-[1fr_200px_auto]\">\n                <span className=\"w2rng-name text-[clamp(1.4rem,3.6vw,2.4rem)] font-semibold leading-tight tracking-tight\">{p.name}</span>\n                <span className=\"col-start-1 text-sm text-slate-600 md:col-start-2 md:row-start-1\">{p.place}</span>\n                <span aria-hidden=\"true\" className=\"w2rng-arrow col-start-2 row-span-2 row-start-1 grid h-12 w-12 place-items-center rounded-full border border-[#c5ccd6] bg-white text-lg md:col-start-3 md:row-span-1\">→</span>\n              </a>\n            </li>\n          ))}\n        </ul>\n      </div>\n      <span ref={ringRef} className=\"w2rng-ring\" aria-hidden=\"true\"><span className=\"w2rng-fill\" /></span>\n      <span ref={dotRef} className=\"w2rng-dot\" aria-hidden=\"true\" />\n    </section>\n  );\n}\n"}]}
