{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"headline-rows-skew-with-scroll-speed","type":"registry:block","title":"Headline Rows Skew With Scroll Speed","description":"","dependencies":[],"files":[{"path":"components/we-inc/headline-rows-skew-with-scroll-speed.tsx","type":"registry:component","content":"import { useEffect, useRef } from \"react\";\n\nconst SKEW = 1; // degrees of slant per pixel scrolled in one frame\nconst MAX = 9; // the strongest slant, in degrees\nconst LAG = 0.06; // rows further down follow a little later, which makes the wave\nconst IDLE = 160; // the self-scroll demo swings this many px down and back every 4.8 s; 0 turns it off\n\nconst CLASSES = [\n  [\"Lindy Hop\", \"Mon 19:00\"],\n  [\"Argentine Tango\", \"Mon 20:30\"],\n  [\"Salsa\", \"Tue 19:30\"],\n  [\"Ballet Barre\", \"Wed 18:15\"],\n  [\"Contemporary\", \"Wed 20:00\"],\n  [\"Tap\", \"Thu 19:00\"],\n  [\"West Coast Swing\", \"Thu 20:30\"],\n  [\"Flamenco\", \"Fri 18:30\"],\n  [\"Social Dance\", \"Sat 20:00\"],\n];\n\nexport default function HeadlineRowsSkewWithScrollSpeed() {\n  const root = useRef<HTMLElement>(null);\n\n  useEffect(() => {\n    const el = root.current;\n    if (!el) return;\n    // The box is the scroller here. On a normal page, listen on window and read scrollY instead.\n    const sc = el;\n    const rows = Array.from(el.querySelectorAll<HTMLElement>(\".w3skh-row\"));\n    const cur = rows.map(() => 0);\n    let demo = IDLE > 0;\n    const used = () => { demo = false; el.setAttribute(\"data-used\", \"\"); };\n    const inputs = [\"wheel\", \"touchstart\", \"pointerdown\", \"keydown\"];\n    inputs.forEach((e) => el.addEventListener(e, used, { passive: true }));\n    const reduce = window.matchMedia(\"(prefers-reduced-motion: reduce)\").matches;\n    let last = sc.scrollTop;\n    let f = 0;\n    let on = false;\n    let t0 = 0;\n    const tick = (now: number) => {\n      if (demo && on) {\n        sc.scrollTop = IDLE * (1 - Math.cos((now - t0) / 764));\n      }\n      const p = sc.scrollTop;\n      const v = p - last;\n      last = p;\n      let moving = !!v || demo;\n      const target = Math.max(-MAX, Math.min(MAX, -v * SKEW));\n      rows.forEach((r, i) => {\n        let c = cur[i] + (target - cur[i]) * Math.max(0.04, 0.2 - (i * LAG) / 3);\n        if (Math.abs(c) < 0.01 && !v) c = 0;\n        cur[i] = c;\n        if (c) moving = true;\n        r.style.transform = c ? `skewX(${c.toFixed(2)}deg)` : \"\";\n      });\n      f = on && moving ? requestAnimationFrame(tick) : 0;\n    };\n    const run = () => { if (!f && on) f = requestAnimationFrame(tick); };\n    const io = new IntersectionObserver(([e]) => {\n      on = e.isIntersecting;\n      if (on) { t0 = performance.now(); run(); }\n      else { cancelAnimationFrame(f); f = 0; }\n    });\n    if (!reduce) {\n      sc.addEventListener(\"scroll\", run, { passive: true });\n      io.observe(el);\n    }\n    return () => {\n      io.disconnect();\n      cancelAnimationFrame(f);\n      sc.removeEventListener(\"scroll\", run);\n      inputs.forEach((e) => el.removeEventListener(e, used));\n    };\n  }, []);\n\n  return (\n    <section\n      ref={root}\n      tabIndex={0}\n      aria-label=\"Corva Dance Hall, weekly classes\"\n      className=\"w3skh relative h-[620px] overflow-y-auto overscroll-contain bg-[#a9472a] text-[#fbefe4] focus-visible:outline focus-visible:outline-2 focus-visible:-outline-offset-4 focus-visible:outline-[#fbefe4]\"\n    >\n      <style>{`\n        .w3skh-hint { background: linear-gradient(#a9472a 60%, transparent); transition: opacity .5s ease; }\n        .w3skh[data-used] .w3skh-hint { opacity: 0; }\n        .w3skh-row { transform-origin: 0 100%; will-change: transform; }\n        .w3skh-name { font: 400 clamp(40px, 8.4vw, 104px)/.95 Georgia, \"Times New Roman\", serif; letter-spacing: -.035em; }\n        .w3skh-row:hover .w3skh-name, .w3skh-row:focus-visible .w3skh-name { font-style: italic; }\n        .w3skh-row:focus-visible { outline: 2px solid #fbefe4; outline-offset: 4px; }\n        @media (prefers-reduced-motion: reduce) { .w3skh-row { transform: none !important; } .w3skh-hint { transition: none; } }\n      `}</style>\n      <p aria-hidden=\"true\" className=\"w3skh-hint sticky top-0 z-[2] px-5 py-3 text-center text-[11px] font-semibold uppercase tracking-[0.22em]\">\n        Scroll inside\n      </p>\n      <div className=\"mx-auto flex max-w-6xl flex-wrap justify-between gap-x-10 gap-y-3 px-5 pb-7 pt-4\">\n        <p className=\"text-xs font-bold uppercase tracking-[0.24em]\">Corva Dance Hall</p>\n        <p className=\"max-w-[26rem] text-base leading-relaxed\">\n          Evening classes in a sprung-floor hall above the old tram depot. Drop in, or book a term.\n        </p>\n      </div>\n      <h2 className=\"sr-only\">Weekly classes</h2>\n      <ul className=\"mx-auto max-w-6xl px-5 pb-8\">\n        {CLASSES.map(([name, when]) => (\n          <li key={name} className=\"border-t border-[#fbefe4]/30 last:border-b\">\n            <a href=\"#\" className=\"w3skh-row flex flex-col justify-between gap-1.5 pb-2.5 pt-3.5 min-[561px]:flex-row min-[561px]:items-baseline min-[561px]:gap-4\">\n              <span className=\"w3skh-name\">{name}</span>\n              <span className=\"flex-none text-[13px] font-semibold uppercase tabular-nums tracking-[0.08em]\">{when}</span>\n            </a>\n          </li>\n        ))}\n      </ul>\n      <p className=\"mx-auto max-w-6xl px-5 pb-[72px] text-[15px] leading-relaxed\">\n        Shoes with suede or leather soles, please. Changing rooms open half an hour before the first class.\n      </p>\n    </section>\n  );\n}\n"}]}
