{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"pinned-book-list-row-with-giant-word-parallax","type":"registry:block","title":"Pinned Book List Row with Giant Word Parallax","description":"","dependencies":[],"files":[{"path":"components/we-inc/pinned-book-list-row-with-giant-word-parallax.tsx","type":"registry:component","content":"import { useEffect, useRef } from \"react\";\n\nconst books = [\n  {\n    \"tone\": \"c1\",\n    \"title\": \"The Salt Road\",\n    \"author\": \"Ines Marlow\",\n    \"kind\": \"Novel, out in March\",\n    \"price\": \"$24\"\n  },\n  {\n    \"tone\": \"c2\",\n    \"title\": \"Small Hours\",\n    \"author\": \"Theo Garrick\",\n    \"kind\": \"Poems, out in March\",\n    \"price\": \"$18\"\n  },\n  {\n    \"tone\": \"c3\",\n    \"title\": \"A Field Guide to Fog\",\n    \"author\": \"Rhona Pell\",\n    \"kind\": \"Essays, out in April\",\n    \"price\": \"$22\"\n  },\n  {\n    \"tone\": \"c4\",\n    \"title\": \"Under the Viaduct\",\n    \"author\": \"Sami Okoro\",\n    \"kind\": \"Stories, out in April\",\n    \"price\": \"$20\"\n  },\n  {\n    \"tone\": \"c5\",\n    \"title\": \"Tending\",\n    \"author\": \"Mae Lindqvist\",\n    \"kind\": \"Memoir, out in May\",\n    \"price\": \"$26\"\n  },\n  {\n    \"tone\": \"c6\",\n    \"title\": \"The Ninth Lock\",\n    \"author\": \"Dara Finch\",\n    \"kind\": \"Crime, out in May\",\n    \"price\": \"$19\"\n  }\n];\n\nconst css = `\n.w5gwd-root { --w5gwd-h: 620px; --w5gwd-run: 1500px; position: relative; height: var(--w5gwd-h); overflow-x: hidden; overflow-y: auto; scrollbar-width: thin; }\n.w5gwd-root *, .w5gwd-root *::before, .w5gwd-root *::after { box-sizing: border-box; }\n.w5gwd-track { height: calc(var(--w5gwd-h) + var(--w5gwd-run)); }\n.w5gwd-stage { position: sticky; top: 0; height: var(--w5gwd-h); overflow: hidden; container-type: inline-size; }\n.w5gwd-row { position: relative; display: flex; width: max-content; will-change: transform; }\n.w5gwd-hint { position: absolute; top: 12px; left: 0; right: 0; z-index: 5; display: flex; justify-content: center; pointer-events: none; transition: opacity .4s ease; }\n.w5gwd-hint span { padding: 4px 12px; border-radius: 999px; font-size: 12px; font-weight: 600; letter-spacing: .04em; }\n.w5gwd-root[data-scrolled] .w5gwd-hint { opacity: 0; }\n@keyframes w5gwd-slide { to { transform: translateX(calc(-100% + 100cqi)); } }\n@supports (animation-timeline: view()) {\n  @media (min-width: 640px) and (prefers-reduced-motion: no-preference) {\n    .w5gwd-track { view-timeline: --w5gwd-tl block; }\n    .w5gwd-row { animation: w5gwd-slide linear both; animation-timeline: --w5gwd-tl; animation-range: contain 0% contain 100%; }\n  }\n}\n@media (max-width: 639px), (prefers-reduced-motion: reduce) {\n  .w5gwd-track { height: auto; }\n  .w5gwd-stage { position: static; height: auto; min-height: var(--w5gwd-h); overflow: visible; }\n  .w5gwd-hint { display: none; }\n  .w5gwd-row { width: auto; overflow-x: auto; scroll-snap-type: x mandatory; transform: none !important; animation: none !important; scrollbar-width: thin; scroll-padding-inline: clamp(20px, 5cqi, 64px); }\n  .w5gwd-panel { scroll-snap-align: start; }\n}\n.w5gwd-root { --w5gwd-ink: #1b1c1f; --w5gwd-amber: #e3a857; background: var(--w5gwd-ink); color: #ecebe6; font-family: ui-sans-serif, system-ui, sans-serif; scrollbar-color: #3a3b40 transparent; }\n.w5gwd-root:focus-visible { outline: 3px solid var(--w5gwd-amber); outline-offset: -3px; }\n.w5gwd-hint span { background: var(--w5gwd-amber); color: var(--w5gwd-ink); }\n.w5gwd-stage { display: flex; flex-direction: column; justify-content: flex-end; padding-bottom: 48px; }\n.w5gwd-head { position: absolute; top: 44px; left: clamp(20px, 5cqi, 64px); }\n.w5gwd-label { margin: 0; font-size: 12px; font-weight: 600; letter-spacing: .2em; text-transform: uppercase; color: var(--w5gwd-amber); }\n.w5gwd-title { margin: 8px 0 0; font-family: Georgia, \"Times New Roman\", serif; font-weight: 400; font-size: clamp(26px, 3.4cqi, 38px); line-height: 1.15; }\n.w5gwd-word { position: absolute; top: 120px; left: 0; margin: 0; padding: 0 clamp(20px, 5cqi, 64px); width: max-content; white-space: nowrap; font-family: Georgia, \"Times New Roman\", serif; font-style: italic; font-size: 210px; line-height: 1; color: transparent; -webkit-text-stroke: 1.5px rgba(236, 235, 230, .2); will-change: transform; pointer-events: none; }\n.w5gwd-row { margin: 0; padding: 0 clamp(20px, 5cqi, 64px); list-style: none; gap: 36px; align-items: flex-end; }\n.w5gwd-panel { flex: 0 0 auto; }\n.w5gwd-panel:nth-child(even) { margin-bottom: 44px; }\n.w5gwd-book { display: block; width: 210px; color: inherit; text-decoration: none; border-radius: 4px; }\n.w5gwd-book:focus-visible { outline: 3px solid var(--w5gwd-amber); outline-offset: 8px; }\n.w5gwd-cover { position: relative; display: flex; flex-direction: column; justify-content: space-between; height: 300px; padding: 22px 20px; overflow: hidden; border-radius: 3px 8px 8px 3px; box-shadow: inset 6px 0 0 rgba(0, 0, 0, .18), 0 24px 40px -22px rgba(0, 0, 0, .8); transition: transform .5s cubic-bezier(.2, .7, .2, 1); }\n.w5gwd-cover::before { content: \"\"; position: absolute; }\n.w5gwd-book:hover .w5gwd-cover, .w5gwd-book:focus-visible .w5gwd-cover { transform: translateY(-8px) rotate(-1deg); }\n.w5gwd-ct { position: relative; font-family: Georgia, \"Times New Roman\", serif; font-size: 25px; line-height: 1.12; }\n.w5gwd-ca { position: relative; font-size: 11px; font-weight: 600; letter-spacing: .16em; text-transform: uppercase; }\n.w5gwd-c1 { background: #b4532a; color: #f7e9d7; }\n.w5gwd-c1::before { width: 150px; height: 150px; right: -40px; bottom: 40px; border-radius: 50%; background: #e7b98f; opacity: .55; }\n.w5gwd-c2 { background: #1f4b48; color: #e5efe8; }\n.w5gwd-c2::before { inset: 110px 20px 70px; background: repeating-linear-gradient(0deg, rgba(229, 239, 232, .35) 0 1px, transparent 1px 12px); }\n.w5gwd-c3 { background: #d3a648; color: #2a2010; }\n.w5gwd-c3::before { left: -30px; right: -30px; top: 130px; height: 80px; background: rgba(255, 250, 235, .5); border-radius: 50%; }\n.w5gwd-c4 { background: #3b4e6d; color: #eef1f6; }\n.w5gwd-c4::before { left: 20px; right: 20px; bottom: 60px; height: 90px; border: 2px solid rgba(238, 241, 246, .45); border-bottom: 0; border-radius: 90px 90px 0 0; }\n.w5gwd-c5 { background: #e9e2d0; color: #3a3a24; }\n.w5gwd-c5::before { width: 10px; height: 120px; left: 50%; bottom: 84px; background: #6b7040; border-radius: 6px; box-shadow: -26px 30px 0 #8d915e, 26px 50px 0 #8d915e; }\n.w5gwd-c6 { background: #6b2330; color: #f4e3e3; }\n.w5gwd-c6::before { inset: 100px 60px 60px; border: 2px solid rgba(244, 227, 227, .5); border-radius: 4px; }\n.w5gwd-bt { display: block; margin-top: 16px; font-weight: 600; font-size: 15px; }\n.w5gwd-ba { display: block; margin-top: 2px; font-size: 14px; color: #b9b8b2; }\n.w5gwd-bk { display: flex; justify-content: space-between; margin-top: 8px; font-size: 13px; color: #a3a29c; }\n.w5gwd-end { align-self: center; width: 250px; padding-left: 28px; border-left: 1px solid #3a3b40; }\n.w5gwd-endtext { margin: 0; font-family: Georgia, \"Times New Roman\", serif; font-size: 20px; line-height: 1.4; }\n.w5gwd-btn { display: inline-flex; align-items: center; min-height: 44px; margin-top: 18px; padding: 0 20px; border-radius: 999px; background: var(--w5gwd-amber); color: var(--w5gwd-ink); font-size: 14px; font-weight: 600; text-decoration: none; }\n.w5gwd-btn:hover { background: #f0c488; }\n.w5gwd-btn:focus-visible { outline: 3px solid #ecebe6; outline-offset: 3px; }\n@supports (animation-timeline: view()) {\n  @media (min-width: 640px) and (prefers-reduced-motion: no-preference) {\n    .w5gwd-word { animation: w5gwd-slide linear both; animation-timeline: --w5gwd-tl; animation-range: contain 0% contain 100%; }\n  }\n}\n@media (max-width: 639px), (prefers-reduced-motion: reduce) {\n  .w5gwd-stage { justify-content: center; gap: 28px; padding: 36px 0; }\n  .w5gwd-head { position: static; padding: 0 20px; }\n  .w5gwd-word { display: none; }\n  .w5gwd-row { gap: 20px; padding-bottom: 12px; align-items: flex-start; }\n  .w5gwd-panel:nth-child(even) { margin-bottom: 0; }\n  .w5gwd-book { width: 180px; }\n  .w5gwd-cover { height: 258px; transition: none; }\n}\n`;\n\n// Same script as the HTML version. It also checks prefers-reduced-motion itself.\nfunction init(root: HTMLElement): () => void {\n  // The box scrolls itself. For page scroll: remove height and overflow from .w5gwd-root, set --w5gwd-h to 100vh,\n  // then use window scroll events and (scrollY minus the track's page top) instead of root.scrollTop.\n  var AUTO = 80; // demo scroll speed in px per second until someone scrolls; 0 turns it off\n  var $ = function (s: string): any { return root.querySelector(s); };\n  var track = $(\".w5gwd-track\"), stage = $(\".w5gwd-stage\"), row = $(\".w5gwd-row\");\n  var still = matchMedia(\"(prefers-reduced-motion: reduce), (max-width: 639px)\");\n  var css = window.CSS && CSS.supports(\"animation-timeline: view()\"); // CSS moves the row itself there\n  var af = requestAnimationFrame, caf = cancelAnimationFrame, raf = 0, demo = 0, last = 0, pos = 0, seen = true, done = !AUTO;\n  var word = $(\".w5gwd-word\");\n  function cl(x: number) { return Math.min(1, Math.max(0, x)) || 0; }\n  function span() { return track.offsetHeight - root.clientHeight; }\n  function shift(el: any, p: number, flat: boolean) {\n    if (!css) el.style.transform = flat ? \"\" : \"translateX(\" + -p * Math.max(0, el.offsetWidth - stage.clientWidth) + \"px)\";\n  }\n  function paint() {\n    raf = 0;\n    var p = cl((root.scrollTop - track.offsetTop) / span()), flat = still.matches;\n    root.toggleAttribute(\"data-scrolled\", root.scrollTop > 160);\n    shift(row, p, flat);\n    shift(word, p, flat);\n  }\n  function queue() { if (!raf) raf = af(paint); }\n  function step(now: number) {\n    var dt = last ? Math.min(now - last, 50) : 0;\n    last = now;\n    pos += (AUTO * dt) / 1000;\n    if (pos >= root.scrollHeight - root.clientHeight) { done = true; demo = 0; return; }\n    root.scrollTop = pos;\n    demo = af(step);\n  }\n  function start() { if (!done && seen && !demo && !still.matches) { last = 0; pos = root.scrollTop; demo = af(step); } }\n  function stop() { caf(demo); demo = 0; }\n  function hand() { done = true; stop(); }\n  // Tabbing to a card off to the side scrolls the box to the point where that card is in view.\n  function focusIn(e: any) {\n    var card = e.target.closest(\".w5gwd-panel\");\n    stage.scrollLeft = 0;\n    if (!card || still.matches) return;\n    hand();\n    var w = stage.clientWidth;\n    root.scrollTop = track.offsetTop + span() * cl((card.offsetLeft - (w - card.offsetWidth) / 2) / (row.offsetWidth - w));\n  }\n  var ac = new AbortController(), o = { passive: true, signal: ac.signal };\n  var io = new IntersectionObserver(function (e) { seen = e[0].isIntersecting; seen ? start() : stop(); });\n  io.observe(root);\n  [\"wheel\", \"touchstart\", \"pointerdown\", \"keydown\"].forEach(function (ev) { root.addEventListener(ev, hand, o); });\n  root.addEventListener(\"scroll\", queue, o);\n  row.addEventListener(\"focusin\", focusIn, o);\n  row.addEventListener(\"scroll\", queue, o);\n  window.addEventListener(\"resize\", queue, o);\n  paint();\n  start();\n  return function () {\n    stop();\n    caf(raf);\n    io.disconnect();\n    ac.abort();\n\n  };\n}\n\nexport default function PinnedBookListRowWithGiantWordParallax() {\n  const ref = useRef<HTMLElement>(null);\n  useEffect(() => (ref.current ? init(ref.current) : undefined), []);\n  return (\n    <section ref={ref} className=\"w5gwd-root\" data-w5gwd tabIndex=\"0\" aria-label=\"Spring books, scroll to move sideways\">\n    <style>{css}</style>\n      <div className=\"w5gwd-track\">\n        <div className=\"w5gwd-stage\">\n          <div className=\"w5gwd-hint\" aria-hidden=\"true\"><span>Scroll inside</span></div>\n          <p className=\"w5gwd-word\" aria-hidden=\"true\">New for spring</p>\n          <div className=\"w5gwd-head\">\n            <p className=\"w5gwd-label\">Oxbow Press</p>\n            <h2 className=\"w5gwd-title\">Six new books for spring</h2>\n          </div>\n          <ul className=\"w5gwd-row\" role=\"list\">\n            {books.map((it, i) => (\n    <li key={i} className=\"w5gwd-panel\">\n              <a href=\"#\" className=\"w5gwd-book\">\n                <span className={`w5gwd-cover w5gwd-${it.tone}`} aria-hidden=\"true\"><span className=\"w5gwd-ct\">{it.title}</span><span className=\"w5gwd-ca\">{it.author}</span></span>\n                <span className=\"w5gwd-bt\">{it.title}</span>\n                <span className=\"w5gwd-ba\">{it.author}</span>\n                <span className=\"w5gwd-bk\"><span>{it.kind}</span><span>{it.price}</span></span>\n              </a>\n            </li>\n    ))}\n            <li className=\"w5gwd-panel w5gwd-end\">\n              <p className=\"w5gwd-endtext\">Order any two before publication and we post them together, signed where we can.</p>\n              <a href=\"#\" className=\"w5gwd-btn\">See the full catalogue</a>\n            </li>\n          </ul>\n        </div>\n      </div>\n    </section>\n  );\n}\n"}]}
