{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"photo-pile-settles-into-grid-on-scroll","type":"registry:block","title":"Photo Pile Settles Into a Grid","description":"","dependencies":["framer-motion"],"files":[{"path":"components/we-inc/photo-pile-settles-into-grid-on-scroll.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: the --x, --y and --r start values on each .w1pil-p (where the pile sits), --w1pil-bg, --w1pil-ink,\n     and animation-range on .w1pil-p (how much scrolling the sort takes). */\n  .w1pil { --w1pil-bg: #2a2b2e; --w1pil-ink: #f1efe9;\n    height: 620px; overflow-y: auto; overflow-x: hidden; position: relative; background: var(--w1pil-bg); color: var(--w1pil-ink);\n    font-family: ui-sans-serif, system-ui, -apple-system, \"Segoe UI\", Roboto, sans-serif; scrollbar-width: thin; scrollbar-color: #55575c transparent; }\n  /* To use page scroll: delete height and overflow above and set root: null in the script. */\n  .w1pil:focus-visible { outline: 3px solid #e3b67a; outline-offset: -3px; }\n  .w1pil-hint { position: sticky; top: 0; height: 0; z-index: 9; display: flex; align-items: flex-start; justify-content: flex-end; pointer-events: none; }\n  .w1pil-hint span { margin: 12px 12px 0 0; padding: 5px 12px; border-radius: 999px; background: rgba(241,239,233,.16); color: var(--w1pil-ink);\n    font-size: 12px; letter-spacing: .04em; transition: opacity .5s ease; }\n  .w1pil[data-touched] .w1pil-hint span { opacity: 0; }\n  .w1pil-wrap { max-width: 60rem; margin: 0 auto; padding: 60px 20px 88px; }\n  .w1pil-eyebrow { margin: 0; font-size: 12px; font-weight: 700; letter-spacing: .2em; text-transform: uppercase; color: #e3b67a; }\n  .w1pil-h { margin: 14px 0 0; max-width: 34rem; font-family: Georgia, \"Iowan Old Style\", serif; font-weight: 400; font-size: clamp(1.9rem, 4.4vw, 2.8rem); line-height: 1.1; letter-spacing: -.015em; }\n  .w1pil-lead { margin: 14px 0 0; max-width: 32rem; font-size: 1rem; line-height: 1.6; color: #c9c6be; }\n  .w1pil-grid { list-style: none; margin: 40px 0 0; padding: 0; display: grid; grid-template-columns: repeat(2, 1fr); gap: 14px; view-timeline: --w1pil-v block; }\n  .w1pil-p figure { margin: 0; padding: 8px 8px 0; background: #fbfaf7; border-radius: 3px; box-shadow: 0 18px 30px -14px rgba(0,0,0,.65), 0 2px 4px rgba(0,0,0,.25); }\n  .w1pil-p img { display: block; width: 100%; height: auto; aspect-ratio: 1; object-fit: cover; }\n  .w1pil-p figcaption { padding: 8px 2px 10px; font-size: .8125rem; color: #3a3b3e; }\n  /* Phone: two columns, the pile gathers in the middle row. */\n  .w1pil-p:nth-child(1) { --x: 52%; --y: 100%; --r: -9deg; }\n  .w1pil-p:nth-child(2) { --x: -48%; --y: 96%; --r: 7deg; }\n  .w1pil-p:nth-child(3) { --x: 56%; --y: 4%; --r: 4deg; }\n  .w1pil-p:nth-child(4) { --x: -52%; --y: -2%; --r: -6deg; }\n  .w1pil-p:nth-child(5) { --x: 46%; --y: -98%; --r: 10deg; }\n  .w1pil-p:nth-child(6) { --x: -54%; --y: -102%; --r: -3deg; }\n  @media (min-width: 720px) {\n    .w1pil-wrap { padding: 76px 40px 100px; }\n    .w1pil-grid { grid-template-columns: repeat(3, 1fr); gap: 22px; }\n    .w1pil-p:nth-child(1) { --x: 96%; --y: 50%; --r: -9deg; }\n    .w1pil-p:nth-child(2) { --x: 6%; --y: 58%; --r: 6deg; }\n    .w1pil-p:nth-child(3) { --x: -92%; --y: 46%; --r: -4deg; }\n    .w1pil-p:nth-child(4) { --x: 104%; --y: -48%; --r: 8deg; }\n    .w1pil-p:nth-child(5) { --x: -4%; --y: -54%; --r: -7deg; }\n    .w1pil-p:nth-child(6) { --x: -100%; --y: -44%; --r: 3deg; }\n  }\n  .w1pil-end { margin-top: 36px; display: flex; flex-wrap: wrap; gap: 16px 24px; align-items: center; justify-content: space-between; }\n  .w1pil-end p { margin: 0; font-size: 1rem; color: #dcd9d1; }\n  .w1pil-btn { display: inline-flex; min-height: 46px; align-items: center; padding: 0 22px; border-radius: 999px; background: var(--w1pil-ink);\n    color: #2a2b2e; font-weight: 600; font-size: .9375rem; text-decoration: none; }\n  .w1pil-btn:hover { background: #fff; }\n  .w1pil-btn:focus-visible { outline: 3px solid #e3b67a; outline-offset: 3px; }\n  @keyframes w1pil-sort { from { transform: translate(var(--x), var(--y)) rotate(var(--r)); } to { transform: none; } }\n  @supports (animation-timeline: view()) {\n    .w1pil:not([data-fb]) .w1pil-p { animation: w1pil-sort linear both; animation-timeline: --w1pil-v; animation-range: cover 18% cover 52%; }\n  }\n  /* Fallback set by the script: the pile sorts once when the grid is mostly in view. */\n  .w1pil[data-fb] .w1pil-p { transform: translate(var(--x), var(--y)) rotate(var(--r)); transition: transform 1.1s cubic-bezier(.2,.8,.2,1); }\n  .w1pil[data-fb] .w1pil-p:nth-child(even) { transition-delay: 90ms; }\n  .w1pil[data-fb] .w1pil-in .w1pil-p { transform: none; }\n  @media (prefers-reduced-motion: reduce) {\n    .w1pil .w1pil-p, .w1pil[data-fb] .w1pil-p { animation: none !important; transform: none; transition: none; }\n  }\n`;\n\nexport default function PhotoPileSettlesIntoGridOnScroll() {\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 = 40; // 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: sort the pile once when half the grid is in view.\n      if (!reduce && !native) {\n        root.setAttribute(\"data-fb\", \"\");\n        var io = keep(new IntersectionObserver(function (es) {\n          if (es[0].isIntersecting) { es[0].target.classList.add(\"w1pil-in\"); io.disconnect(); }\n        }, { root: root, threshold: 0.5 }));\n        io.observe(root.querySelector(\".w1pil-grid\"));\n      }\n    return () => off.forEach((f: any) => f());\n  }, [prefersReduced]);\n\n  return (\n    <section className=\"w1pil\" data-w1pil=\"\" ref={rootRef} tabIndex={0} aria-label=\"Fieldwork Prints coast series, scrollable\">\n    <style>{STYLES}</style>\n      <div className=\"w1pil-hint\" aria-hidden=\"true\"><span>Scroll inside</span></div>\n      <div className=\"w1pil-wrap\">\n        <p className=\"w1pil-eyebrow\">Fieldwork Prints</p>\n        <h2 className=\"w1pil-h\">The coast series, printed on cotton rag</h2>\n        <p className=\"w1pil-lead\">Six photographs from one winter on the shore. Scroll and the pile on the table sorts itself onto the wall.</p>\n        <ul className=\"w1pil-grid\">\n          <li className=\"w1pil-p\"><figure><img src=\"https://images.pexels.com/photos/10867143/pexels-photo-10867143.jpeg?auto=compress&cs=tinysrgb&w=800\" alt=\"Rugged sandstone cliffs above a calm sea under a pale blue sky\" loading=\"eager\" width=\"800\" height=\"800\" /><figcaption>Sandstone point</figcaption></figure></li>\n          <li className=\"w1pil-p\"><figure><img src=\"https://images.pexels.com/photos/8990439/pexels-photo-8990439.jpeg?auto=compress&cs=tinysrgb&w=800\" alt=\"Aerial view of a pale rocky headland ringed by white surf and deep turquoise water\" loading=\"eager\" width=\"800\" height=\"800\" /><figcaption>The headland</figcaption></figure></li>\n          <li className=\"w1pil-p\"><figure><img src=\"https://images.pexels.com/photos/39982422/pexels-photo-39982422.jpeg?auto=compress&cs=tinysrgb&w=800\" alt=\"Grassy dunes running down to a wide beach and a green headland\" loading=\"eager\" width=\"800\" height=\"800\" /><figcaption>Dune path</figcaption></figure></li>\n          <li className=\"w1pil-p\"><figure><img src=\"https://images.pexels.com/photos/3030015/pexels-photo-3030015.jpeg?auto=compress&cs=tinysrgb&w=800\" alt=\"Aerial view of rows of painted fishing boats moored tightly in a harbour\" loading=\"eager\" width=\"800\" height=\"800\" /><figcaption>Harbour at rest</figcaption></figure></li>\n          <li className=\"w1pil-p\"><figure><img src=\"https://images.pexels.com/photos/18163250/pexels-photo-18163250.jpeg?auto=compress&cs=tinysrgb&w=800\" alt=\"A small white lighthouse on a green cliff above a rocky shore and blue sea\" loading=\"eager\" width=\"800\" height=\"800\" /><figcaption>Lighthouse cliff</figcaption></figure></li>\n          <li className=\"w1pil-p\"><figure><img src=\"https://images.pexels.com/photos/17647534/pexels-photo-17647534.jpeg?auto=compress&cs=tinysrgb&w=800\" alt=\"Blue cornflowers and dry grasses against a soft blue summer sky\" loading=\"eager\" width=\"800\" height=\"800\" /><figcaption>Cornflowers</figcaption></figure></li>\n        </ul>\n        <div className=\"w1pil-end\">\n          <p>Each print is made to order and signed on the back.</p>\n          <a href=\"#\" className=\"w1pil-btn\">Browse the series</a>\n        </div>\n      </div>\n    </section>\n  );\n}\n"}]}
