{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"photo-zooms-out-as-it-scrolls-in","type":"registry:block","title":"Photo Zooms Out as It Scrolls In","description":"","dependencies":["framer-motion"],"files":[{"path":"components/we-inc/photo-zooms-out-as-it-scrolls-in.tsx","type":"registry:component","content":"import { useEffect, useRef } from \"react\";\nimport { useReducedMotion } from \"framer-motion\";\n\n// Same markup, styles and script as the plain HTML version; the comments in CSS name the values to change.\nconst STYLES = `\n  /* Change these: --w1zom-from (starting zoom), --w1zom-bg, --w1zom-ink, --w1zom-accent,\n     and animation-range on .w1zom-img (where in the box the zoom finishes). */\n  .w1zom { --w1zom-from: 1.15; --w1zom-bg: #efe7da; --w1zom-ink: #2b241d; --w1zom-accent: #7c5532;\n    height: 620px; overflow-y: auto; overflow-x: hidden; position: relative; background: var(--w1zom-bg); color: var(--w1zom-ink);\n    font-family: ui-sans-serif, system-ui, -apple-system, \"Segoe UI\", Roboto, sans-serif; scrollbar-width: thin; }\n  /* To use page scroll: delete height and overflow above and set root: null in the script. */\n  .w1zom:focus-visible { outline: 3px solid var(--w1zom-accent); outline-offset: -3px; }\n  .w1zom-hint { position: sticky; top: 0; height: 0; z-index: 3; display: flex; align-items: flex-start; justify-content: flex-end; pointer-events: none; }\n  .w1zom-hint span { margin: 12px 12px 0 0; padding: 5px 12px; border-radius: 999px; background: rgba(43,36,29,.82); color: #f6f0e6;\n    font-size: 12px; letter-spacing: .04em; transition: opacity .5s ease; }\n  .w1zom[data-touched] .w1zom-hint span { opacity: 0; }\n  .w1zom-wrap { max-width: 66rem; margin: 0 auto; padding: 64px 20px 88px; }\n  .w1zom-eyebrow { margin: 0; font-size: 12px; font-weight: 700; letter-spacing: .2em; text-transform: uppercase; color: var(--w1zom-accent); }\n  .w1zom-h { margin: 14px 0 0; max-width: 38rem; font-family: Georgia, \"Iowan Old Style\", serif; font-weight: 400; font-size: clamp(1.9rem, 4.6vw, 3.1rem); line-height: 1.1; letter-spacing: -.015em; }\n  .w1zom-lead { margin: 16px 0 0; max-width: 34rem; font-size: 1.0625rem; line-height: 1.65; color: #574a3c; }\n  .w1zom-fig { margin: 40px 0 0; }\n  .w1zom-frame { overflow: hidden; border-radius: 18px; aspect-ratio: 3 / 2; background: #d8cbb6; box-shadow: 0 30px 60px -30px rgba(60,40,20,.45); }\n  .w1zom-img { display: block; width: 100%; height: 100%; object-fit: cover; transform-origin: 50% 60%; }\n  .w1zom-cap { margin: 14px 0 0; font-size: .875rem; color: #6a5b4a; }\n  .w1zom-cols { margin-top: 48px; display: grid; gap: 28px; }\n  .w1zom-cols h3 { margin: 0; font-size: 1.125rem; font-weight: 600; }\n  .w1zom-cols p { margin: 8px 0 0; font-size: .96875rem; line-height: 1.65; color: #574a3c; }\n  .w1zom-btn { margin-top: 36px; display: inline-flex; min-height: 46px; align-items: center; padding: 0 22px; border-radius: 10px;\n    background: var(--w1zom-ink); color: #f6f0e6; font-weight: 600; font-size: .9375rem; text-decoration: none; }\n  .w1zom-btn:hover { background: #45392c; }\n  .w1zom-btn:focus-visible { outline: 3px solid var(--w1zom-accent); outline-offset: 3px; }\n  @media (min-width: 720px) { .w1zom-wrap { padding: 80px 40px 104px; } .w1zom-cols { grid-template-columns: 1fr 1fr; gap: 48px; } }\n  @keyframes w1zom-zoom { from { transform: scale(var(--w1zom-from)); } to { transform: none; } }\n  @keyframes w1zom-cap { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }\n  @supports (animation-timeline: view()) {\n    .w1zom-frame { view-timeline: --w1zom-v block; }\n    .w1zom:not([data-fb]) .w1zom-img { animation: w1zom-zoom linear both; animation-timeline: --w1zom-v; animation-range: entry 0% cover 55%; }\n    .w1zom:not([data-fb]) .w1zom-cap { animation: w1zom-cap linear both; animation-timeline: --w1zom-v; animation-range: cover 35% cover 55%; }\n  }\n  /* Fallback set by the script: the zoom is scrubbed from the scroll position. */\n  @media (prefers-reduced-motion: reduce) {\n    .w1zom .w1zom-img, .w1zom .w1zom-cap { animation: none !important; transform: none !important; opacity: 1; }\n  }\n`;\n\nexport default function PhotoZoomsOutAsItScrollsIn() {\n  const rootRef = useRef<any>(null);\n  const prefersReduced = useReducedMotion();\n\n  useEffect(() => {\n    const root: any = rootRef.current;\n    if (!root) return;\n    \n      var off = [];\n      var SPEED = 34; // demo scroll in px per second before anyone touches the box; 0 turns it off\n      var reduce = matchMedia(\"(prefers-reduced-motion: reduce)\").matches;\n      var frame = 0, last = 0, pos = 0, seen = true, done = reduce || !SPEED;\n      function on(el, n, f) { el.addEventListener(n, f, { passive: true }); off.push(function () { el.removeEventListener(n, f); }); }\n      function keep(o) { off.push(function () { o.disconnect(); }); return o; }\n    \n      // Slow demo scroll so the preview moves; any wheel, touch, click or key hands control back.\n      function step(t) {\n        var dt = last ? Math.min(t - last, 50) : 0;\n        last = t;\n        pos += SPEED * dt / 1000;\n        if (pos >= root.scrollHeight - root.clientHeight) pos = 0;\n        root.scrollTop = pos;\n        frame = requestAnimationFrame(step);\n      }\n      function play() { if (!done && seen && !frame) { last = 0; frame = requestAnimationFrame(step); } }\n      function stop() { cancelAnimationFrame(frame); frame = 0; }\n      off.push(stop);\n      keep(new IntersectionObserver(function (e) { seen = e[0].isIntersecting; if (seen) play(); else stop(); })).observe(root);\n      [\"wheel\", \"touchstart\", \"pointerdown\", \"keydown\"].forEach(function (n) {\n        on(root, n, function () { done = true; stop(); root.setAttribute(\"data-touched\", \"\"); });\n      });\n      play();\n      var native = window.CSS && CSS.supports(\"animation-timeline: view()\");\n    \n      // Without scroll-driven animations: scrub the zoom from the frame's position, once per frame at most.\n      if (!reduce && !native) {\n        root.setAttribute(\"data-fb\", \"\");\n        var FROM = 1.15; // keep in step with --w1zom-from\n        var frame2 = 0;\n        var fr = root.querySelector(\".w1zom-frame\"), img = root.querySelector(\".w1zom-img\");\n        var draw = function () {\n          frame2 = 0;\n          var a = root.getBoundingClientRect(), b = fr.getBoundingClientRect();\n          var p = Math.min(1, Math.max(0, (a.bottom - b.top) / (0.55 * (a.height + b.height))));\n          img.style.transform = \"scale(\" + (FROM - (FROM - 1) * p).toFixed(4) + \")\";\n        };\n        on(root, \"scroll\", function () { if (!frame2) frame2 = requestAnimationFrame(draw); });\n        off.push(function () { cancelAnimationFrame(frame2); });\n        draw();\n      }\n    return () => off.forEach((f: any) => f());\n  }, [prefersReduced]);\n\n  return (\n    <section className=\"w1zom\" data-w1zom=\"\" ref={rootRef} tabIndex={0} aria-label=\"Fenna Clay studio, scrollable\">\n    <style>{STYLES}</style>\n      <div className=\"w1zom-hint\" aria-hidden=\"true\"><span>Scroll inside</span></div>\n      <div className=\"w1zom-wrap\">\n        <p className=\"w1zom-eyebrow\">Fenna Clay · Pottery studio</p>\n        <h2 className=\"w1zom-h\">Thrown, trimmed and fired in one small room.</h2>\n        <p className=\"w1zom-lead\">Every mug and bowl on our shelves passes through the same two hands. Come for an evening class or pick a piece straight off the drying rack.</p>\n        <figure className=\"w1zom-fig\">\n          <div className=\"w1zom-frame\">\n            <img className=\"w1zom-img\" src=\"https://images.pexels.com/photos/37827282/pexels-photo-37827282.jpeg?auto=compress&cs=tinysrgb&w=1600\" alt=\"A potter arranging glazed bowls and cups on wooden shelves in a sunlit studio\" loading=\"eager\" width=\"1600\" height=\"1067\" />\n          </div>\n          <figcaption className=\"w1zom-cap\">The glaze shelf on a Thursday morning, after the second firing.</figcaption>\n        </figure>\n        <div className=\"w1zom-cols\">\n          <div>\n            <h3>Evening wheel classes</h3>\n            <p>Six people around three wheels, clay and firing included. You leave with two pieces of your own after the glaze week.</p>\n          </div>\n          <div>\n            <h3>The studio shelf</h3>\n            <p>Seconds and one-offs go on the front shelf every Saturday. When a piece is gone, it is gone.</p>\n          </div>\n        </div>\n        <a href=\"#\" className=\"w1zom-btn\">See class dates</a>\n      </div>\n    </section>\n  );\n}\n"}]}
