{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"button-fill-rising-from-the-pointer-entry-point","type":"registry:block","title":"Button Fill Rising From the Pointer Entry Point","description":"","dependencies":[],"files":[{"path":"components/we-inc/button-fill-rising-from-the-pointer-entry-point.tsx","type":"registry:component","content":"import { useEffect, useRef } from \"react\";\n\nconst DEMO_EVERY = 1800; // ms between idle fills on the first button\nconst buttons = [\"Book a garden visit\", \"See planting plans\", \"Ask about upkeep\"];\n\nexport default function ButtonFillRisingFromThePointerEntryPoint() {\n  const root = useRef<HTMLElement>(null);\n\n  useEffect(() => {\n    const el = root.current;\n    if (!el) return;\n    const btns = Array.from(el.querySelectorAll<HTMLAnchorElement>(\".w3fil-btn\"));\n    // puts the circle where the pointer crossed the edge, then lets CSS scale it\n    const place = (b: HTMLElement, x: number, y: number) => {\n      const dot = b.querySelector<HTMLElement>(\".w3fil-dot\");\n      if (dot) { dot.style.left = `${x}px`; dot.style.top = `${y}px`; }\n    };\n    const at = (e: PointerEvent) => {\n      const b = e.currentTarget as HTMLElement;\n      const r = b.getBoundingClientRect();\n      place(b, e.clientX - r.left, e.clientY - r.top);\n      return b;\n    };\n    const enter = (e: PointerEvent) => { if (e.pointerType === \"mouse\") at(e).setAttribute(\"data-on\", \"\"); };\n    const leave = (e: PointerEvent) => { if (e.pointerType === \"mouse\") at(e).removeAttribute(\"data-on\"); };\n    const focus = (e: FocusEvent) => { const b = e.currentTarget as HTMLElement; place(b, b.offsetWidth / 2, b.offsetHeight / 2); };\n    btns.forEach((b) => { b.addEventListener(\"pointerenter\", enter); b.addEventListener(\"pointerleave\", leave); b.addEventListener(\"focus\", focus); });\n\n    // idle demo: the first button fills from one edge, empties toward another\n    const demo = btns[0];\n    const edges = [[0, 0.5], [0.5, 0], [1, 0.5], [0.5, 1]];\n    let n = 0, timer = 0, busy = false;\n    const reduce = window.matchMedia(\"(prefers-reduced-motion: reduce)\").matches;\n    const step = () => {\n      if (busy) return;\n      const [ex, ey] = edges[n % 4];\n      place(demo, ex * demo.offsetWidth, ey * demo.offsetHeight);\n      demo.toggleAttribute(\"data-on\");\n      n += 1;\n    };\n    const hold = () => { if (!busy) { busy = true; demo.removeAttribute(\"data-on\"); } };\n    const resume = () => { busy = false; };\n    el.addEventListener(\"pointerenter\", hold);\n    el.addEventListener(\"pointerleave\", resume);\n    el.addEventListener(\"focusin\", hold);\n    el.addEventListener(\"focusout\", resume);\n    const io = new IntersectionObserver(([en]) => {\n      window.clearInterval(timer);\n      if (en.isIntersecting && !reduce) timer = window.setInterval(step, DEMO_EVERY);\n    });\n    io.observe(el);\n    if (!reduce) step();\n    return () => {\n      window.clearInterval(timer);\n      io.disconnect();\n      btns.forEach((b) => { b.removeEventListener(\"pointerenter\", enter); b.removeEventListener(\"pointerleave\", leave); b.removeEventListener(\"focus\", focus); });\n      el.removeEventListener(\"pointerenter\", hold);\n      el.removeEventListener(\"pointerleave\", resume);\n      el.removeEventListener(\"focusin\", hold);\n      el.removeEventListener(\"focusout\", resume);\n    };\n  }, []);\n\n  return (\n    <section ref={root} className=\"bg-[#f6ebe1] px-5 py-16 sm:py-20\">\n      <style>{`\n        .w3fil-btn { position: relative; isolation: isolate; overflow: hidden; }\n        .w3fil-dot { position: absolute; left: 50%; top: 50%; width: 230%; aspect-ratio: 1; border-radius: 50%; background: #a4452b; transform: translate(-50%, -50%) scale(0); transition: transform .55s cubic-bezier(.3,.7,.2,1); z-index: -1; }\n        .w3fil-on { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; color: #fdf6ef; opacity: 0; transition: opacity .3s ease; }\n        .w3fil-off { transition: opacity .3s ease; }\n        .w3fil-btn[data-on] .w3fil-dot, .w3fil-btn:focus-visible .w3fil-dot { transform: translate(-50%, -50%) scale(1); }\n        .w3fil-btn[data-on] .w3fil-on, .w3fil-btn:focus-visible .w3fil-on { opacity: 1; }\n        .w3fil-btn[data-on] .w3fil-off, .w3fil-btn:focus-visible .w3fil-off { opacity: 0; }\n        .w3fil-btn:focus-visible { outline: 2px solid #5a2414; outline-offset: 4px; }\n        @media (hover: hover) and (pointer: fine) {\n          .w3fil-btn:hover .w3fil-dot { transform: translate(-50%, -50%) scale(1); }\n          .w3fil-btn:hover .w3fil-on { opacity: 1; }\n          .w3fil-btn:hover .w3fil-off { opacity: 0; }\n        }\n        @media (prefers-reduced-motion: reduce) { .w3fil-dot, .w3fil-on, .w3fil-off { transition: none; } }\n      `}</style>\n      <div className=\"mx-auto max-w-3xl text-center\">\n        <p className=\"text-xs font-semibold uppercase tracking-[0.25em] text-[#8a3a24]\">Redclay Gardens</p>\n        <h2 className=\"mt-4 font-serif text-3xl leading-tight text-[#3a1d14] sm:text-5xl\">Dry gardens that look after themselves.</h2>\n        <p className=\"mx-auto mt-5 max-w-lg text-base leading-relaxed text-[#5e4136]\">Gravel beds, grasses and Mediterranean shrubs, planned for clay soil and hot summers, then left to settle.</p>\n        <div className=\"mt-10 flex flex-col items-center justify-center gap-3 sm:flex-row\">\n          {buttons.map((b) => (\n            <a key={b} href=\"#\" className=\"w3fil-btn inline-flex h-14 w-64 items-center justify-center rounded-full border-2 border-[#a4452b] text-base font-semibold text-[#5a2414] sm:w-auto sm:px-7\">\n              <span aria-hidden=\"true\" className=\"w3fil-dot\" />\n              <span className=\"w3fil-off\">{b}</span>\n              <span aria-hidden=\"true\" className=\"w3fil-on\">{b}</span>\n            </a>\n          ))}\n        </div>\n      </div>\n    </section>\n  );\n}\n"}]}
