{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"horizontal-card-deck-stacking-sideways-in-pinned-section","type":"registry:block","title":"Horizontal Card Deck Stacking Sideways in a Pinned Section","description":"","dependencies":["framer-motion"],"files":[{"path":"components/we-inc/horizontal-card-deck-stacking-sideways-in-pinned-section.tsx","type":"registry:component","content":"import { useEffect, useRef } from \"react\";\nimport { useReducedMotion } from \"framer-motion\";\n\nconst days = [\n  { day: \"Day 1\", title: \"Ashby Gate to Fellmoor\", km: \"16 km\", climb: \"340 m up\", text: \"A gentle start along the old drove road, through two farms and over a stone stile into open moor.\", stay: \"Fellmoor bunkhouse\" },\n  { day: \"Day 2\", title: \"Fellmoor to Tarn Hollow\", km: \"19 km\", climb: \"520 m up\", text: \"The longest climb of the week, rewarded with lunch beside a still tarn and a slow walk down.\", stay: \"The Hollow Inn\" },\n  { day: \"Day 3\", title: \"Tarn Hollow to Brindle\", km: \"12 km\", climb: \"180 m up\", text: \"A short, easy day through beech woods with time for the village bakery before it closes.\", stay: \"Mill House rooms\" },\n  { day: \"Day 4\", title: \"Brindle to Hawes Edge\", km: \"21 km\", climb: \"610 m up\", text: \"Ridge walking with wide views both ways. Carry water; there is no village until the end.\", stay: \"Edge Farm barn\" },\n  { day: \"Day 5\", title: \"Hawes Edge to Kirkby\", km: \"14 km\", climb: \"90 m up\", text: \"Downhill nearly all the way to the market square, with a train home from the station.\", stay: \"Your own bed\" },\n];\nconst PEEK = 56; // least amount of the next card that shows at the right edge\nconst STEP_PX = 380; // scroll distance that brings in one card\nconst AUTO_PX_PER_SEC = 60; // demo scroll speed; 0 turns it off\n\nexport default function HorizontalCardDeckStackingSidewaysInPinnedSection() {\n  const reduce = useReducedMotion();\n  const boxRef = useRef<HTMLElement>(null);\n  const deckRef = useRef<HTMLDivElement>(null);\n\n  useEffect(() => {\n    const box = boxRef.current;\n    const deck = deckRef.current;\n    if (!box || !deck || reduce) return;\n    const cards = Array.from(deck.querySelectorAll<HTMLElement>(\".w4hds-card\"));\n    const n = cards.length;\n    let raf = 0;\n    const paint = () => {\n      raf = 0;\n      const p = Math.min(n - 1, Math.max(0, box.scrollTop / STEP_PX));\n      const w = deck.clientWidth;\n      const cw = cards[0].offsetWidth;\n      const off = Math.min(28, Math.max(0, (w - cw - 8) / (n - 1)));\n      const wait = Math.min(w - PEEK, cw + 40); // where the next card waits\n      const enter = cards.map((_, k) => (k ? Math.min(1, p - (k - 1)) : 1));\n      cards.forEach((c, k) => {\n        const e = enter[k];\n        const target = k * off;\n        const ease = e > 0 ? 1 - Math.pow(1 - e, 3) : 0;\n        const x = e <= 0 ? w - (w - wait) * Math.max(0, 1 + e) : wait + (target - wait) * ease;\n        let depth = 0;\n        for (let j = k + 1; j < n; j++) depth += Math.max(0, enter[j]);\n        c.style.transform = `translateX(${x}px) scale(${1 - 0.05 * depth})`;\n        c.querySelector<HTMLElement>(\".w4hds-shade\")!.style.opacity = String(Math.min(0.55, 0.22 * depth));\n      });\n      box.toggleAttribute(\"data-scrolled\", box.scrollTop > 8);\n    };\n    const onScroll = () => { if (!raf) raf = requestAnimationFrame(paint); };\n    box.addEventListener(\"scroll\", onScroll, { passive: true });\n    const ro = new ResizeObserver(onScroll);\n    ro.observe(deck);\n    paint();\n\n    let demo = 0, last = 0, pos = box.scrollTop, seen = true, done = !AUTO_PX_PER_SEC;\n    const step = (now: number) => {\n      const dt = last ? Math.min(now - last, 50) : 0;\n      last = now;\n      pos += (AUTO_PX_PER_SEC * dt) / 1000;\n      if (pos >= box.scrollHeight - box.clientHeight) { done = true; demo = 0; return; }\n      box.scrollTop = pos;\n      demo = requestAnimationFrame(step);\n    };\n    const start = () => { if (!done && seen && !demo) { last = 0; demo = requestAnimationFrame(step); } };\n    const stop = () => { cancelAnimationFrame(demo); demo = 0; };\n    const handOver = () => { done = true; stop(); };\n    const io = new IntersectionObserver(([e]) => { seen = e.isIntersecting; if (seen) start(); else stop(); });\n    io.observe(box);\n    const evs = [\"wheel\", \"touchstart\", \"pointerdown\", \"keydown\"] as const;\n    evs.forEach((ev) => box.addEventListener(ev, handOver, { passive: true }));\n    start();\n    return () => {\n      stop();\n      cancelAnimationFrame(raf);\n      io.disconnect();\n      ro.disconnect();\n      box.removeEventListener(\"scroll\", onScroll);\n      evs.forEach((ev) => box.removeEventListener(ev, handOver));\n    };\n  }, [reduce]);\n\n  return (\n    <section ref={boxRef} tabIndex={0} aria-label=\"Five day walking route, scrollable\" className=\"w4hds-root\">\n      <style>{`\n        .w4hds-root { height: 620px; overflow-y: auto; overflow-x: hidden; position: relative; background: #6e3020; color: #f8efe3; scrollbar-width: thin; scrollbar-color: #9a5a44 transparent; }\n        .w4hds-root:focus-visible { outline: 3px solid #f3c99b; outline-offset: -3px; }\n        .w4hds-track { height: calc(620px + ${(days.length - 1) * STEP_PX}px); }\n        .w4hds-stage { position: sticky; top: 0; height: 620px; overflow: hidden; }\n        .w4hds-hint { position: absolute; top: 10px; left: 0; right: 0; z-index: 20; display: flex; justify-content: center; pointer-events: none; transition: opacity .4s ease; }\n        .w4hds-hint span { padding: 4px 12px; border-radius: 999px; background: #f8efe3; color: #6e3020; font-size: 12px; font-weight: 600; letter-spacing: .04em; }\n        .w4hds-root[data-scrolled] .w4hds-hint { opacity: 0; }\n        .w4hds-deck { overflow: hidden; }\n        .w4hds-card { position: absolute; left: 0; top: 0; will-change: transform; transform-origin: 0 50%; }\n        .w4hds-card:not(:first-child) { transform: translateX(200%); }\n        .w4hds-shade { position: absolute; inset: 0; border-radius: inherit; background: #2a120b; opacity: 0; pointer-events: none; }\n        @media (prefers-reduced-motion: reduce) {\n          .w4hds-track { height: auto; } .w4hds-stage { position: static; height: auto; } .w4hds-hint { display: none; }\n          .w4hds-deck { display: flex; gap: 16px; overflow-x: auto; height: auto !important; padding-bottom: 12px; }\n          .w4hds-card { position: relative; flex: 0 0 min(85%, 340px); transform: none !important; }\n        }\n      `}</style>\n      <div className=\"w4hds-track\">\n        <div className=\"w4hds-stage\">\n          <div className=\"w4hds-hint\" aria-hidden=\"true\"><span>Scroll inside</span></div>\n          <div className=\"mx-auto grid h-full max-w-6xl content-center gap-6 px-5 py-6 md:grid-cols-[260px_minmax(0,1fr)] md:items-center md:gap-10 md:px-10\">\n            <div>\n              <p className=\"text-xs font-semibold uppercase tracking-[0.22em] text-[#f3c99b]\">Coldharbour Walks</p>\n              <h2 className=\"mt-3 font-serif text-3xl leading-tight sm:text-4xl\">The Hollin Way in five days</h2>\n              <p className=\"mt-3 hidden text-[15px] leading-relaxed text-[#ecd9c6] md:block\">Bags carried between stops, rooms booked, a map for each morning. You only walk.</p>\n              <a href=\"#\" className=\"mt-5 inline-flex min-h-[44px] items-center rounded-full bg-[#f8efe3] px-5 text-sm font-semibold text-[#6e3020] transition hover:bg-white focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[#f3c99b] focus-visible:ring-offset-2 focus-visible:ring-offset-[#6e3020]\">Check spring dates</a>\n            </div>\n            <div ref={deckRef} className=\"w4hds-deck relative h-[330px] md:h-[380px]\">\n              {days.map((d) => (\n                <article key={d.day} className=\"w4hds-card flex h-[320px] w-[min(calc(100%_-_56px),420px)] flex-col rounded-3xl bg-[#fbf5ec] p-6 text-[#3a1d14] shadow-[-18px_0_40px_-24px_rgba(0,0,0,0.6)] sm:p-8 md:h-[380px]\">\n                  <p className=\"text-xs font-semibold uppercase tracking-[0.18em] text-[#9a4a2e]\">{d.day}</p>\n                  <h3 className=\"mt-2 font-serif text-2xl leading-snug sm:text-[28px]\">{d.title}</h3>\n                  <div className=\"mt-4 flex gap-2 text-xs font-semibold\">\n                    <span className=\"rounded-full bg-[#f1e2d0] px-3 py-1\">{d.km}</span>\n                    <span className=\"rounded-full bg-[#f1e2d0] px-3 py-1\">{d.climb}</span>\n                  </div>\n                  <p className=\"mt-4 text-[15px] leading-relaxed text-[#5c3a2d]\">{d.text}</p>\n                  <p className=\"mt-auto border-t border-[#ead8c4] pt-4 text-sm\"><span className=\"text-[#7a5444]\">Overnight: </span><span className=\"font-semibold\">{d.stay}</span></p>\n                  <span className=\"w4hds-shade\" aria-hidden=\"true\" />\n                </article>\n              ))}\n            </div>\n          </div>\n        </div>\n      </div>\n    </section>\n  );\n}\n"}]}
