{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"magnetic-pill-button-with-parallax-label","type":"registry:block","title":"Magnetic Pill Button With Parallax Label","description":"","dependencies":[],"files":[{"path":"components/we-inc/magnetic-pill-button-with-parallax-label.tsx","type":"registry:component","content":"import { useEffect, useRef } from \"react\";\n\nconst PULL = 0.35; // how far the pill follows the pointer (0.35 = 35% of the distance)\nconst LABEL_PULL = 0.55; // the label follows further than the pill, which gives the depth\nconst REACH = 90; // px around the pill where the pull starts\n\nexport default function MagneticPillButtonWithParallaxLabel() {\n  const root = useRef<HTMLElement>(null);\n  const pill = useRef<HTMLAnchorElement>(null);\n  const label = useRef<HTMLSpanElement>(null);\n\n  useEffect(() => {\n    const el = root.current;\n    const p = pill.current;\n    const l = label.current;\n    if (!el || !p || !l) return;\n    if (window.matchMedia(\"(prefers-reduced-motion: reduce)\").matches) return;\n    const fine = window.matchMedia(\"(hover: hover) and (pointer: fine)\").matches;\n    let tx = 0, ty = 0, x = 0, y = 0, frame = 0, visible = true, live = false, hot = false;\n    const move = (e: PointerEvent) => {\n      if (e.pointerType !== \"mouse\") return;\n      live = true;\n      const r = p.getBoundingClientRect();\n      const dx = e.clientX - (r.left + r.width / 2);\n      const dy = e.clientY - (r.top + r.height / 2);\n      hot = Math.abs(dx) < r.width / 2 + REACH && Math.abs(dy) < r.height / 2 + REACH;\n      tx = hot ? dx : 0;\n      ty = hot ? dy : 0;\n    };\n    const leave = () => { live = false; hot = false; };\n    const tick = (now: number) => {\n      if (!live) {\n        // idle demo: the pointer seems to circle the pill until a real mouse arrives\n        tx = Math.sin(now / 1300) * 60;\n        ty = Math.cos(now / 1700) * 26;\n      } else if (!hot) { tx = 0; ty = 0; }\n      x += (tx - x) * 0.12;\n      y += (ty - y) * 0.12;\n      p.style.transform = `translate(${(x * PULL).toFixed(2)}px, ${(y * PULL).toFixed(2)}px)`;\n      l.style.transform = `translate(${(x * (LABEL_PULL - PULL)).toFixed(2)}px, ${(y * (LABEL_PULL - PULL)).toFixed(2)}px)`;\n      frame = requestAnimationFrame(tick);\n    };\n    const play = () => { if (!frame && visible) frame = requestAnimationFrame(tick); };\n    const stop = () => { cancelAnimationFrame(frame); frame = 0; };\n    const io = new IntersectionObserver(([en]) => { visible = en.isIntersecting; if (visible) play(); else stop(); });\n    io.observe(el);\n    if (fine) { el.addEventListener(\"pointermove\", move); el.addEventListener(\"pointerleave\", leave); }\n    play();\n    return () => {\n      stop();\n      io.disconnect();\n      el.removeEventListener(\"pointermove\", move);\n      el.removeEventListener(\"pointerleave\", leave);\n    };\n  }, []);\n\n  return (\n    <section ref={root} className=\"w3mag relative overflow-hidden bg-[#15171b] px-5 py-20 text-[#efe9df] sm:py-24\">\n      <style>{`\n        .w3mag-pill { will-change: transform; }\n        .w3mag-glow { opacity: 0; transition: opacity .35s ease; }\n        .w3mag-pill:focus-visible .w3mag-glow { opacity: 1; }\n        .w3mag-pill:focus-visible { outline: 2px solid #efe9df; outline-offset: 5px; }\n        @media (hover: hover) and (pointer: fine) {\n          .w3mag-pill:hover .w3mag-glow { opacity: 1; }\n        }\n        @media (prefers-reduced-motion: reduce) { .w3mag-pill, .w3mag-label { transform: none !important; will-change: auto; } }\n      `}</style>\n      <div className=\"mx-auto flex max-w-3xl flex-col items-center text-center\">\n        <p className=\"text-xs font-semibold uppercase tracking-[0.3em] text-[#c9b892]\">Halden Wine Room</p>\n        <h2 className=\"mt-5 text-3xl font-semibold leading-tight tracking-tight sm:text-5xl\">Twelve seats at the counter, open until one.</h2>\n        <p className=\"mt-5 max-w-lg text-base leading-relaxed text-[#bdb6aa]\">Natural wines by the glass, small plates from a wood oven, and a list that changes every Thursday.</p>\n        <div className=\"mt-14 flex h-40 w-full items-center justify-center\">\n          <a\n            ref={pill}\n            href=\"#\"\n            className=\"w3mag-pill relative inline-flex h-16 items-center justify-center overflow-hidden rounded-full bg-[#efe9df] px-12 text-base font-semibold text-[#15171b]\"\n          >\n            <span aria-hidden=\"true\" className=\"w3mag-glow absolute inset-0 rounded-full bg-[#c9b892]\" />\n            <span ref={label} className=\"w3mag-label relative inline-block\">Reserve a seat</span>\n          </a>\n        </div>\n        <p className=\"text-sm text-[#a39c90]\">Walk-ins welcome before seven.</p>\n      </div>\n    </section>\n  );\n}\n"}]}
