{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"link-underline-sweeping-in-from-the-entry-side","type":"registry:block","title":"Link Underline Sweeping In From the Entry Side","description":"","dependencies":[],"files":[{"path":"components/we-inc/link-underline-sweeping-in-from-the-entry-side.tsx","type":"registry:component","content":"import { useEffect, useRef } from \"react\";\n\nconst DEMO_EVERY = 1500; // ms between idle demo steps\nconst groups = [\n  { title: \"Visit\", links: [\"Opening hours\", \"Find the shop\", \"Reading room\"] },\n  { title: \"Read\", links: [\"New this month\", \"Staff shelves\", \"Poetry corner\"] },\n  { title: \"Join\", links: [\"Book club\", \"Gift cards\", \"Write to us\"] },\n];\n\nexport default function LinkUnderlineSweepingInFromTheEntrySide() {\n  const root = useRef<HTMLElement>(null);\n\n  useEffect(() => {\n    const el = root.current;\n    if (!el) return;\n    const links = Array.from(el.querySelectorAll<HTMLAnchorElement>(\".w3und-a\"));\n    const side = (a: HTMLElement, e: PointerEvent) => {\n      const r = a.getBoundingClientRect();\n      return e.clientX < r.left + r.width / 2 ? \"left\" : \"right\";\n    };\n    const enter = (e: PointerEvent) => {\n      const a = e.currentTarget as HTMLElement;\n      a.style.setProperty(\"--w3und-o\", side(a, e));\n      a.setAttribute(\"data-on\", \"\");\n    };\n    const leave = (e: PointerEvent) => {\n      const a = e.currentTarget as HTMLElement;\n      a.style.setProperty(\"--w3und-o\", side(a, e));\n      a.removeAttribute(\"data-on\");\n    };\n    links.forEach((a) => { a.addEventListener(\"pointerenter\", enter); a.addEventListener(\"pointerleave\", leave); });\n    // idle demo: walks through the links, sweeping in from the left and out to the right\n    let i = 0, timer = 0, busy = false;\n    const reduce = window.matchMedia(\"(prefers-reduced-motion: reduce)\").matches;\n    const step = () => {\n      if (busy) return;\n      const prev = links[(i + links.length - 1) % links.length];\n      prev.style.setProperty(\"--w3und-o\", \"right\");\n      prev.removeAttribute(\"data-on\");\n      links[i].style.setProperty(\"--w3und-o\", \"left\");\n      links[i].setAttribute(\"data-on\", \"\");\n      i = (i + 1) % links.length;\n    };\n    const clear = () => { links.forEach((a) => a.removeAttribute(\"data-on\")); };\n    const hold = () => { if (!busy) { busy = true; clear(); } };\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) { step(); timer = window.setInterval(step, DEMO_EVERY); }\n    });\n    io.observe(el);\n    return () => {\n      window.clearInterval(timer);\n      io.disconnect();\n      links.forEach((a) => { a.removeEventListener(\"pointerenter\", enter); a.removeEventListener(\"pointerleave\", leave); });\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    <footer ref={root} className=\"bg-[#f4efe6] px-5 py-16 text-[#2b2620] sm:px-10 sm:py-20\">\n      <style>{`\n        .w3und-a { position: relative; display: inline-block; padding: 6px 0; }\n        .w3und-a::after { content: \"\"; position: absolute; left: 0; right: 0; bottom: 4px; height: 2px; background: #9a3b25; transform: scaleX(0); transform-origin: var(--w3und-o, left); transition: transform .45s cubic-bezier(.65,0,.35,1); }\n        .w3und-a[data-on]::after, .w3und-a:focus-visible::after { transform: scaleX(1); }\n        .w3und-a:focus-visible { outline: 2px solid #2b2620; outline-offset: 4px; border-radius: 2px; }\n        @media (hover: hover) and (pointer: fine) { .w3und-a:hover::after { transform: scaleX(1); } }\n        @media (prefers-reduced-motion: reduce) { .w3und-a::after { transition: none; } }\n      `}</style>\n      <div className=\"mx-auto grid max-w-4xl gap-12 md:grid-cols-[1.2fr_2fr]\">\n        <div>\n          <h2 className=\"font-serif text-3xl leading-tight\">Marrow &amp; Quill Books</h2>\n          <p className=\"mt-4 max-w-xs text-base leading-relaxed text-[#5b5248]\">A small shop of new and secondhand books on Ferry Lane. Kettle always on.</p>\n        </div>\n        <nav aria-label=\"Footer\" className=\"grid grid-cols-2 gap-8 sm:grid-cols-3\">\n          {groups.map((g) => (\n            <div key={g.title}>\n              <h3 className=\"text-xs font-semibold uppercase tracking-[0.2em] text-[#6b5f52]\">{g.title}</h3>\n              <ul className=\"mt-4 space-y-2\">\n                {g.links.map((l) => (\n                  <li key={l}><a href=\"#\" className=\"w3und-a text-lg\">{l}</a></li>\n                ))}\n              </ul>\n            </div>\n          ))}\n        </nav>\n      </div>\n    </footer>\n  );\n}\n"}]}
