{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"nav-links-rescramble-on-hover-and-focus","type":"registry:block","title":"Nav Links Rescramble On Hover And Focus","description":"","dependencies":[],"files":[{"path":"components/we-inc/nav-links-rescramble-on-hover-and-focus.tsx","type":"registry:component","content":"import { useEffect, useRef } from \"react\";\n\nconst LINKS = [\"Projects\", \"Studio\", \"Journal\", \"Process\", \"Contact\"];\nconst WORK = [\"Hollin House, 2025\", \"Brae Studio, 2024\", \"Marl Lane Barn, 2024\"];\nconst GLYPHS = \"ABCDEFHKLMNPRSTVXZ0123456789/+#\"; // characters shown while scrambling\nconst STEP = 38; // ms between one letter settling and the next\nconst LEAD = 160; // ms of noise before the first letter settles\nconst IDLE = 2600; // ms between demo scrambles until a visitor arrives\n\nexport default function NavLinksRescrambleOnHoverAndFocus() {\n  const root = useRef<HTMLElement>(null);\n\n  useEffect(() => {\n    const el = root.current;\n    if (!el) return;\n    if (window.matchMedia(\"(prefers-reduced-motion: reduce)\").matches) return;\n    const links = Array.from(el.querySelectorAll<HTMLAnchorElement>(\".w3nvs-links a\"));\n    const frames = new Map<HTMLAnchorElement, number>();\n    const scramble = (a: HTMLAnchorElement, delay = 0) => {\n      const out = a.firstElementChild as HTMLElement;\n      const text = a.getAttribute(\"aria-label\") || \"\";\n      const t0 = performance.now() + delay;\n      cancelAnimationFrame(frames.get(a) || 0);\n      const frame = (now: number) => {\n        const t = now - t0;\n        let s = \"\";\n        let done = true;\n        for (let i = 0; i < text.length; i++) {\n          if (t > LEAD + i * STEP) s += text[i];\n          else {\n            done = false;\n            s += t < 0 && delay ? text[i] : GLYPHS[(Math.random() * GLYPHS.length) | 0];\n          }\n        }\n        out.textContent = s;\n        frames.set(a, done ? 0 : requestAnimationFrame(frame));\n      };\n      frame(t0);\n    };\n    let idle = 0;\n    let n = 0;\n    let live = false;\n    let seen = false;\n    const clearDemo = () => links.forEach((l) => l.removeAttribute(\"data-demo\"));\n    const demo = () => {\n      clearDemo();\n      const a = links[n++ % links.length];\n      a.setAttribute(\"data-demo\", \"\");\n      scramble(a);\n    };\n    const startDemo = () => {\n      const step = () => { demo(); idle = window.setTimeout(step, IDLE); };\n      idle = window.setTimeout(step, 1800);\n    };\n    const stopDemo = () => { live = true; clearTimeout(idle); clearDemo(); };\n    const offs = links.map((a) => {\n      const on = () => { stopDemo(); scramble(a); };\n      a.addEventListener(\"pointerenter\", on);\n      a.addEventListener(\"focus\", on);\n      return () => { a.removeEventListener(\"pointerenter\", on); a.removeEventListener(\"focus\", on); };\n    });\n    const io = new IntersectionObserver(([e]) => {\n      clearTimeout(idle);\n      if (!e.isIntersecting) return;\n      if (!seen) { seen = true; links.forEach((a, i) => scramble(a, i * 50)); }\n      if (!live) startDemo();\n    });\n    io.observe(el);\n    return () => {\n      io.disconnect();\n      clearTimeout(idle);\n      offs.forEach((f) => f());\n      frames.forEach((f) => cancelAnimationFrame(f));\n    };\n  }, []);\n\n  return (\n    <section ref={root} className=\"w3nvs bg-[#f3ede2] px-5 pb-24 text-[#1f1b16]\">\n      <style>{`\n        .w3nvs-links a { font: 500 13px/1 ui-monospace, \"SF Mono\", Menlo, Consolas, monospace; letter-spacing: .12em; white-space: pre; }\n        .w3nvs-links a::after { content: \"\"; position: absolute; left: 12px; right: 12px; bottom: 10px; height: 1px; background: #8f4528;\n          transform: scaleX(0); transform-origin: left; transition: transform .35s ease; }\n        .w3nvs-links a:hover::after, .w3nvs-links a:focus-visible::after, .w3nvs-links a[data-demo]::after { transform: scaleX(1); }\n        .w3nvs a:focus-visible { outline: 2px solid #8f4528; outline-offset: 2px; border-radius: 4px; }\n        .w3nvs-list a { letter-spacing: .06em; }\n        .w3nvs-list a::after { left: 0; right: auto; width: 2.5em; bottom: 14px; }\n        @media (prefers-reduced-motion: reduce) { .w3nvs-links a::after { transition: none; } }\n      `}</style>\n      <header className=\"mx-auto flex max-w-6xl flex-wrap items-center justify-between gap-x-6 gap-y-2 border-b border-[#d8cdbb] py-5\">\n        <a href=\"#\" className=\"inline-flex min-h-[40px] items-center text-[17px] font-semibold tracking-tight\">Ostrand Atelier</a>\n        <nav aria-label=\"Main\">\n          <ul className=\"w3nvs-links -mx-3 flex flex-wrap gap-x-1\">\n            {LINKS.map((l) => (\n              <li key={l}>\n                <a href=\"#\" aria-label={l} className=\"relative inline-flex min-h-[44px] items-center px-3 uppercase\">\n                  <span aria-hidden=\"true\">{l}</span>\n                </a>\n              </li>\n            ))}\n          </ul>\n        </nav>\n      </header>\n      <div className=\"mx-auto grid max-w-6xl gap-14 pt-[72px] min-[900px]:grid-cols-[1fr_300px] min-[900px]:items-end\">\n        <div>\n        <p className=\"font-mono text-xs font-medium uppercase tracking-[0.2em] text-[#6b5e4d]\">Architecture and interiors</p>\n        <h2 className=\"mt-[18px] max-w-[40rem] font-serif text-[clamp(34px,5.4vw,60px)] font-normal leading-[1.08] tracking-[-0.02em]\">\n          Houses drawn around the light of one plot.\n        </h2>\n        <p className=\"mt-[22px] max-w-[34rem] text-[17px] leading-relaxed text-[#4e4438]\">\n          A four-person practice working on homes, small studios and careful renovations, from the first site walk to the last coat of lime wash.\n        </p>\n        <a href=\"#\" className=\"mt-8 inline-flex min-h-[48px] items-center rounded-full bg-[#1f1b16] px-6 text-[15px] font-semibold text-[#f3ede2] hover:bg-[#8f4528]\">\n          See recent houses\n        </a>\n        </div>\n        <div>\n          <h3 className=\"mb-2 font-mono text-xs font-medium uppercase tracking-[0.2em] text-[#6b5e4d]\">Recent work</h3>\n          <ul className=\"w3nvs-links w3nvs-list border-t border-[#d8cdbb]\">\n            {WORK.map((w) => (\n              <li key={w} className=\"border-b border-[#d8cdbb]\">\n                <a href=\"#\" aria-label={w} className=\"relative flex min-h-[56px] items-center uppercase\">\n                  <span aria-hidden=\"true\">{w}</span>\n                </a>\n              </li>\n            ))}\n          </ul>\n        </div>\n      </div>\n    </section>\n  );\n}\n"}]}
