{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"scroll-velocity-marquee-that-speeds-and-reverses","type":"registry:block","title":"Scroll Velocity Marquee That Speeds And Reverses","description":"","dependencies":[],"files":[{"path":"components/we-inc/scroll-velocity-marquee-that-speeds-and-reverses.tsx","type":"registry:component","content":"import { useEffect, useRef, useState } from \"react\";\n\nconst words = [\"Oak\", \"Limestone\", \"Daylight\", \"Lime plaster\", \"Reclaimed brick\", \"Larch\"];\nconst SPEED = 28; // seconds per loop at rest\nconst BOOST = 0.12; // how much each pixel of scroll per frame adds to the speed\nconst MAX = 7; // fastest playback multiple\n\nfunction Track({ dir }: { dir: \"l\" | \"r\" }) {\n  const group = (dup: boolean) => (\n    <span className=\"w3vel-group\" aria-hidden={dup ? \"true\" : undefined}>\n      {words.map((w, i) => (\n        <span key={w} className={i % 2 ? \"w3vel-ghost\" : \"\"}>{w}</span>\n      ))}\n    </span>\n  );\n  return (\n    <div className={`w3vel-track w3vel-${dir}`}>\n      {group(false)}\n      {group(true)}\n    </div>\n  );\n}\n\nexport default function ScrollVelocityMarqueeThatSpeedsAndReverses() {\n  const root = useRef<HTMLElement>(null);\n  const [paused, setPaused] = useState(false);\n  const [off, setOff] = useState(false);\n  const [scrolled, setScrolled] = useState(false);\n\n  useEffect(() => {\n    const el = root.current;\n    if (!el) return;\n    const io = new IntersectionObserver(([e]) => setOff(!e.isIntersecting));\n    io.observe(el);\n    if (window.matchMedia(\"(prefers-reduced-motion: reduce)\").matches) return () => io.disconnect();\n    // The box scrolls itself in the preview. On a real page, listen to window and read scrollY instead.\n    const anims = Array.from(el.querySelectorAll<HTMLElement>(\".w3vel-track\")).map((t) => t.getAnimations()[0]).filter(Boolean);\n    let last = el.scrollTop, push = 0, rate = 1, sign = 1, frame = 0;\n    const tick = () => {\n      const target = sign * (1 + Math.min(Math.abs(push) * BOOST, MAX - 1));\n      rate += (target - rate) * 0.12;\n      push *= 0.88;\n      anims.forEach((a) => (a.playbackRate = rate));\n      frame = Math.abs(push) > 0.1 || Math.abs(rate - target) > 0.01 ? requestAnimationFrame(tick) : 0;\n    };\n    const onScroll = () => {\n      const d = el.scrollTop - last;\n      last = el.scrollTop;\n      if (d) sign = d > 0 ? 1 : -1;\n      push += d;\n      setScrolled(true);\n      if (!frame) frame = requestAnimationFrame(tick);\n    };\n    el.addEventListener(\"scroll\", onScroll, { passive: true });\n    return () => {\n      io.disconnect();\n      el.removeEventListener(\"scroll\", onScroll);\n      cancelAnimationFrame(frame);\n    };\n  }, []);\n\n  return (\n    <section\n      ref={root}\n      data-paused={paused ? \"\" : undefined}\n      data-off={off ? \"\" : undefined}\n      className=\"w3vel relative h-[620px] overflow-y-auto bg-[#1c1d1f] text-[#ecebe7]\"\n      style={{ [\"--w3vel-speed\" as string]: `${SPEED}s` }}\n    >\n      <style>{`\n        .w3vel-view { overflow: hidden; border-block: 1px solid #36383c; padding: 14px 0; }\n        .w3vel-track { display: flex; width: max-content; animation: w3vel-run var(--w3vel-speed) linear infinite; }\n        .w3vel-r { animation-direction: reverse; }\n        .w3vel-group { display: flex; gap: 48px; padding-right: 48px; white-space: nowrap; font-size: clamp(40px, 7vw, 88px); font-weight: 600; letter-spacing: -0.04em; line-height: 1.05; }\n        .w3vel-ghost { color: transparent; -webkit-text-stroke: 1.2px #a8a6a0; }\n        .w3vel[data-paused] .w3vel-track, .w3vel[data-off] .w3vel-track { animation-play-state: paused; }\n        .w3vel-hint { transition: opacity .4s ease; }\n        @keyframes w3vel-run { to { transform: translateX(-50%); } }\n        @media (prefers-reduced-motion: reduce) {\n          .w3vel-track { animation: none; width: auto; padding: 0 20px; }\n          .w3vel-group { flex-wrap: wrap; white-space: normal; row-gap: 0; column-gap: 28px; font-size: clamp(32px, 5vw, 56px); }\n          .w3vel-group[aria-hidden], .w3vel-r, .w3vel-toggle { display: none; }\n        }\n      `}</style>\n      <div className=\"sticky top-0 z-10 flex items-center justify-between bg-[#1c1d1f]/95 px-5 py-3\">\n        <p className={`w3vel-hint text-xs font-medium uppercase tracking-[0.2em] text-[#a8a6a0] ${scrolled ? \"opacity-0\" : \"\"}`}>Scroll inside</p>\n        <button\n          type=\"button\"\n          aria-pressed={paused}\n          onClick={() => setPaused((p) => !p)}\n          className=\"w3vel-toggle inline-flex h-10 items-center rounded-full border border-[#4a4c50] px-4 text-sm font-medium hover:bg-[#2a2b2e] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[#ecebe7]\"\n        >\n          {paused ? \"Play words\" : \"Pause words\"}\n        </button>\n      </div>\n      <div className=\"mx-auto max-w-4xl px-5 pb-12 pt-8\">\n        <p className=\"text-xs font-semibold uppercase tracking-[0.25em] text-[#c9a46a]\">Arden and Pell Architects</p>\n        <h2 className=\"mt-4 max-w-2xl text-3xl font-semibold leading-tight tracking-tight sm:text-4xl\">Small buildings made from a short list of honest materials.</h2>\n      </div>\n      <div className=\"w3vel-view space-y-2\" aria-hidden=\"true\">\n        <Track dir=\"l\" />\n        <Track dir=\"r\" />\n      </div>\n      <div className=\"mx-auto max-w-4xl space-y-6 px-5 py-14 text-base leading-relaxed text-[#c4c2bc]\">\n        <p>We design houses, studios and small public rooms. Most of our work uses oak and larch frames, limestone bases, lime plaster walls and reclaimed brick, chosen so a building ages well and can be repaired by a local trade.</p>\n        <p>Every project starts with a site visit at two times of day, because daylight decides where we put the windows before anything else is drawn.</p>\n        <p>We take on a few commissions a year so each one keeps the same two partners from first sketch to handover.</p>\n        <p>Recent work includes a timber reading room for a village library, a pair of limestone holiday cottages and a brick workshop behind a terrace house.</p>\n        <p>Write to the studio with a rough budget and a photo of the site, and we will reply with whether we are the right fit.</p>\n      </div>\n    </section>\n  );\n}\n"}]}
