{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"case-study-photo-cards-stacking-with-settling-zoom","type":"registry:block","title":"Case Study Photo Cards Stacking With Settling Zoom","description":"","dependencies":["framer-motion"],"files":[{"path":"components/we-inc/case-study-photo-cards-stacking-with-settling-zoom.tsx","type":"registry:component","content":"import { useEffect, useRef } from \"react\";\nimport { useReducedMotion } from \"framer-motion\";\n\nconst projects = [\n  { kind: \"Restaurant fit-out\", title: \"Cedar Row Kitchen\", text: \"A dark former print shop became a dining room of warm timber, with a sunken courtyard and a ceiling of slatted pine to soften the noise of a full Friday.\", facts: [\"Lisbon\", \"Interior and joinery\", \"2025\"], img: \"https://images.pexels.com/photos/14590691/pexels-photo-14590691.jpeg?auto=compress&cs=tinysrgb&w=1200\", alt: \"Restaurant interior with a slatted pine ceiling, round wooden tables and dark metal chairs\" },\n  { kind: \"Workshop\", title: \"Kilnhouse Ceramics\", text: \"We fitted out a working pottery with deep oak shelving for drying ware, a wash station by the window and storage that keeps finished pieces out of the dust.\", facts: [\"Porto\", \"Shelving and layout\", \"2024\"], img: \"https://images.pexels.com/photos/15122649/pexels-photo-15122649.jpeg?auto=compress&cs=tinysrgb&w=1200\", alt: \"A potter placing a wrapped bowl on tall wooden shelves in a bright ceramics studio\" },\n  { kind: \"Private house\", title: \"Ashgrove Residence\", text: \"A family home of pale stone and dark framing, set behind a low garden of clipped trees so the street side stays quiet and green through the year.\", facts: [\"Coimbra\", \"Facade and landscape\", \"2025\"], img: \"https://images.pexels.com/photos/18273285/pexels-photo-18273285.jpeg?auto=compress&cs=tinysrgb&w=1200\", alt: \"Modern two-storey house with stone cladding, a black gate and young trees in the front garden\" },\n];\nconst SCALE_STEP = 0.07; // shrink per covering card\nconst DIM_STEP = 0.3; // darkness per covering card\nconst ZOOM = 0.1; // extra photo zoom while a card is still arriving\nconst AUTO_PX_PER_SEC = 0; // demo scroll speed; 0 turns it off\n\nexport default function CaseStudyPhotoCardsStackingWithSettlingZoom() {\n  const reduce = useReducedMotion();\n  const boxRef = useRef<HTMLElement>(null);\n\n  useEffect(() => {\n    const box = boxRef.current;\n    if (!box || reduce) return;\n    const cards = Array.from(box.querySelectorAll<HTMLElement>(\".w4ccp-card\"));\n    let raf = 0;\n    const paint = () => {\n      raf = 0;\n      const top = box.getBoundingClientRect().top;\n      const cover = cards.map((c) => {\n        const d = c.getBoundingClientRect().top - top - parseFloat(getComputedStyle(c).top);\n        return Math.min(1, Math.max(0, 1 - d / c.offsetHeight));\n      });\n      cards.forEach((c, i) => {\n        let depth = 0;\n        for (let j = i + 1; j < cards.length; j++) depth += cover[j];\n        (c.firstElementChild as HTMLElement).style.transform = `scale(${1 - SCALE_STEP * depth})`;\n        c.querySelector<HTMLElement>(\".w4ccp-shade\")!.style.opacity = String(Math.min(0.6, DIM_STEP * depth));\n        c.querySelector<HTMLElement>(\"img\")!.style.transform = `scale(${1 + ZOOM * (1 - cover[i])})`;\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    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      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=\"Selected projects, scrollable\" className=\"w4ccp-root\">\n      <style>{`\n        .w4ccp-root { height: 660px; overflow-y: auto; position: relative; background: #ebe2d3; color: #2d221b; scrollbar-width: thin; scrollbar-color: #c7b79f transparent; }\n        .w4ccp-root:focus-visible { outline: 3px solid #9c4a2c; outline-offset: -3px; }\n        .w4ccp-hint { position: sticky; top: 0; z-index: 20; height: 0; display: flex; justify-content: center; pointer-events: none; transition: opacity .4s ease; }\n        .w4ccp-hint span { margin-top: 10px; padding: 4px 12px; border-radius: 999px; background: rgba(45,34,27,.85); color: #faf6ef; font-size: 12px; letter-spacing: .04em; }\n        .w4ccp-root[data-scrolled] .w4ccp-hint { opacity: 0; }\n        .w4ccp-card { position: sticky; top: 28px; }\n        .w4ccp-face { transform-origin: 50% 0; will-change: transform; }\n        .w4ccp-face img { transform: scale(1.1); will-change: transform; }\n        .w4ccp-shade { position: absolute; inset: 0; border-radius: inherit; background: #1d150f; opacity: 0; pointer-events: none; }\n        @media (prefers-reduced-motion: reduce) { .w4ccp-face, .w4ccp-face img { transform: none !important; } .w4ccp-shade { opacity: 0 !important; } .w4ccp-hint { display: none; } }\n      `}</style>\n      <div className=\"w4ccp-hint\" aria-hidden=\"true\"><span>Scroll inside</span></div>\n      <div className=\"mx-auto max-w-5xl px-5 pb-20 pt-10 sm:px-8\">\n        <div className=\"flex flex-wrap items-end justify-between gap-4\">\n          <div>\n            <p className=\"text-xs font-semibold uppercase tracking-[0.2em] text-[#8a3f24]\">Fenwick and Oduya, studio</p>\n            <h2 className=\"mt-2 font-serif text-3xl leading-tight sm:text-4xl\">Rooms we finished recently</h2>\n          </div>\n          <a href=\"#\" className=\"inline-flex min-h-[44px] items-center rounded-full border border-[#2d221b] px-5 text-sm font-semibold transition hover:bg-[#2d221b] hover:text-[#faf6ef] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[#9c4a2c] focus-visible:ring-offset-2 focus-visible:ring-offset-[#ebe2d3]\">All projects</a>\n        </div>\n        <ul className=\"mt-8 grid gap-6\">\n          {projects.map((p, n) => (\n            <li key={p.title} className=\"w4ccp-card\">\n              <article className=\"w4ccp-face relative grid overflow-hidden rounded-3xl bg-[#faf6ef] shadow-[0_30px_60px_-30px_rgba(45,34,27,0.55)] md:grid-cols-[1.15fr_1fr]\">\n                <div className=\"aspect-[16/10] overflow-hidden md:aspect-auto md:h-[440px]\">\n                  <img src={p.img} alt={p.alt} loading={n === 0 ? \"eager\" : \"lazy\"} width={1200} height={800} className=\"h-full w-full object-cover\" />\n                </div>\n                <div className=\"flex flex-col p-6 sm:p-8\">\n                  <p className=\"text-xs font-semibold uppercase tracking-[0.18em] text-[#8a3f24]\">{p.kind}</p>\n                  <h3 className=\"mt-2 font-serif text-2xl sm:text-3xl\">{p.title}</h3>\n                  <p className=\"mt-3 text-[15px] leading-relaxed text-[#5b4a3d]\">{p.text}</p>\n                  <dl className=\"mt-6 grid md:mt-auto grid-cols-3 gap-3 border-t border-[#e2d6c3] pt-5 text-sm\">\n                    {[\"Place\", \"Scope\", \"Year\"].map((k, i) => (\n                      <div key={k}><dt className=\"text-xs text-[#6b5847]\">{k}</dt><dd className=\"mt-1 font-medium\">{p.facts[i]}</dd></div>\n                    ))}\n                  </dl>\n                </div>\n                <span className=\"w4ccp-shade\" aria-hidden=\"true\" />\n              </article>\n            </li>\n          ))}\n        </ul>\n      </div>\n    </section>\n  );\n}\n"}]}
