{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"photo-grid-leans-with-scroll-speed","type":"registry:block","title":"Photo Grid Leans With Scroll Speed","description":"","dependencies":[],"files":[{"path":"components/we-inc/photo-grid-leans-with-scroll-speed.tsx","type":"registry:component","content":"import { useEffect, useRef } from \"react\";\n\nconst LEAN = 0.6; // degrees of lean per pixel scrolled in one frame\nconst MAX = 6; // the most a column may lean, in degrees\nconst EASE = 0.12; // how quickly columns follow the speed and settle back\nconst IDLE = 55; // the self-scroll demo swings this many px down and back every 4.8 s; 0 turns it off\nconst MIX = [1, 0.55, 0.85]; // each column leans by a different share, so the grid ripples\n\nconst COLUMNS = [\n  [\n    [\"https://images.pexels.com/photos/15022475/pexels-photo-15022475.jpeg?auto=compress&cs=tinysrgb&w=700\", \"Harbour lighthouse\", \"01\", \"A stone lighthouse at the end of a rocky breakwater under a clear sky\"],\n    [\"https://images.pexels.com/photos/8933075/pexels-photo-8933075.jpeg?auto=compress&cs=tinysrgb&w=700\", \"Dune grass\", \"04\", \"Pale dune grass bending over sand under an overcast sky\"],\n    [\"https://images.pexels.com/photos/20799401/pexels-photo-20799401.jpeg?auto=compress&cs=tinysrgb&w=700\", \"Tide pool in a cove\", \"07\", \"Still water in a tide pool between rust coloured rocks\"],\n    [\"https://images.pexels.com/photos/2233362/pexels-photo-2233362.jpeg?auto=compress&cs=tinysrgb&w=700\", \"Trawlers hauled out\", \"10\", \"Fishing trawlers hauled out on a harbour hardstand\"],\n  ],\n  [\n    [\"https://images.pexels.com/photos/11363530/pexels-photo-11363530.jpeg?auto=compress&cs=tinysrgb&w=700\", \"Floats on the deck\", \"02\", \"Yellow floats and crates on the deck of a moored fishing boat\"],\n    [\"https://images.pexels.com/photos/15379643/pexels-photo-15379643.jpeg?auto=compress&cs=tinysrgb&w=700\", \"Surf between rocks\", \"05\", \"White surf breaking in a gap between sandstone rocks\"],\n    [\"https://images.pexels.com/photos/8970615/pexels-photo-8970615.jpeg?auto=compress&cs=tinysrgb&w=700\", \"Beach pebbles\", \"08\", \"Close view of smooth grey, green and brown beach pebbles\"],\n    [\"https://images.pexels.com/photos/11207937/pexels-photo-11207937.jpeg?auto=compress&cs=tinysrgb&w=700\", \"Black rock shore\", \"11\", \"Black volcanic rocks along a shoreline with a strip of water between them\"],\n  ],\n  [\n    [\"https://images.pexels.com/photos/16549060/pexels-photo-16549060.jpeg?auto=compress&cs=tinysrgb&w=700\", \"Headland, grey sea\", \"03\", \"A dark rocky headland running into a calm grey sea\"],\n    [\"https://images.pexels.com/photos/9435233/pexels-photo-9435233.jpeg?auto=compress&cs=tinysrgb&w=700\", \"Path through the dunes\", \"06\", \"A sandy path running between green grassy dunes\"],\n    [\"https://images.pexels.com/photos/4616317/pexels-photo-4616317.jpeg?auto=compress&cs=tinysrgb&w=700\", \"Wooded cliff\", \"09\", \"A wooded cliff dropping into still blue water\"],\n    [\"https://images.pexels.com/photos/11468623/pexels-photo-11468623.jpeg?auto=compress&cs=tinysrgb&w=700\", \"Marina pontoon\", \"12\", \"Small boats tied along a marina pontoon on a cloudy day\"],\n  ],\n] as const;\n\nexport default function PhotoGridLeansWithScrollSpeed() {\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 cols = Array.from(el.querySelectorAll<HTMLElement>(\".w3lgr-col\"));\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 cur = 0;\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      cur += (Math.max(-MAX, Math.min(MAX, v * LEAN)) - cur) * EASE;\n      if (Math.abs(cur) < 0.01 && !v) cur = 0;\n      cols.forEach((c, i) => { c.style.transform = cur ? `skewY(${(cur * MIX[i]).toFixed(2)}deg)` : \"\"; });\n      f = on && (cur || v || demo) ? 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=\"Saltline Print Room, coastal prints\"\n      className=\"w3lgr relative h-[640px] overflow-y-auto overscroll-contain bg-[#f4f5f6] text-[#1d232a] focus-visible:outline focus-visible:outline-2 focus-visible:-outline-offset-4 focus-visible:outline-[#2f6f9f]\"\n    >\n      <style>{`\n        .w3lgr-hint { background: linear-gradient(#f4f5f6 60%, transparent); transition: opacity .5s ease; }\n        .w3lgr[data-used] .w3lgr-hint { opacity: 0; }\n        .w3lgr-col { will-change: transform; }\n        @media (prefers-reduced-motion: reduce) { .w3lgr-col { transform: none !important; } .w3lgr-hint { transition: none; } }\n      `}</style>\n      <p aria-hidden=\"true\" className=\"w3lgr-hint sticky top-0 z-[2] px-5 py-3 text-center text-[11px] font-semibold uppercase tracking-[0.22em] text-[#5b6570]\">\n        Scroll inside\n      </p>\n      <div className=\"mx-auto max-w-[68rem] px-5 pb-10 pt-5\">\n        <p className=\"text-xs font-semibold uppercase tracking-[0.22em] text-[#2f6f9f]\">Saltline Print Room</p>\n        <h2 className=\"mt-3 max-w-[34rem] text-[clamp(28px,4vw,42px)] font-semibold leading-[1.12] tracking-[-0.025em]\">\n          Prints from a year of walking the north coast.\n        </h2>\n        <p className=\"mt-3.5 max-w-[34rem] text-base leading-relaxed text-[#4a535d]\">\n          Each photograph is printed on cotton rag paper in the studio and signed on the back. Pick a frame or take it rolled.\n        </p>\n      </div>\n      <div className=\"mx-auto grid max-w-[68rem] grid-cols-2 gap-4 px-5 pb-20 min-[760px]:grid-cols-3 min-[760px]:gap-6\">\n        {COLUMNS.map((col, c) => (\n          <div\n            key={c}\n            className={`w3lgr-col content-start gap-4 min-[760px]:gap-6 ${\n              c === 1 ? \"mt-14 grid\" : c === 2 ? \"hidden min-[760px]:mt-6 min-[760px]:grid\" : \"grid\"\n            }`}\n          >\n            {col.map(([src, label, no, alt]) => (\n              <figure key={src}>\n                <img\n                  src={src}\n                  alt={alt}\n                  loading=\"lazy\"\n                  width={700}\n                  height={875}\n                  className=\"block aspect-[4/5] h-auto w-full rounded-[10px] bg-[#dde1e5] object-cover\"\n                />\n                <figcaption className=\"flex justify-between gap-2 pt-2 text-sm font-medium\">\n                  {label} <span className=\"flex-none tabular-nums text-[#5b6570]\">No. {no}</span>\n                </figcaption>\n              </figure>\n            ))}\n          </div>\n        ))}\n      </div>\n    </section>\n  );\n}\n"}]}
