{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"tea-list-rows-stretch-with-scroll-speed","type":"registry:block","title":"Tea List Rows Stretch With Scroll Speed","description":"","dependencies":[],"files":[{"path":"components/we-inc/tea-list-rows-stretch-with-scroll-speed.tsx","type":"registry:component","content":"import { useEffect, useRef } from \"react\";\n\nconst STRETCH = 0.035; // extra height per pixel scrolled in one frame (0.035 = 3.5%)\nconst MAX = 0.22; // the most a row may stretch\nconst EASE = 0.14; // how quickly rows follow the speed and settle back\nconst IDLE = 160; // the self-scroll demo swings this many px down and back every 4.8 s; 0 turns it off\n\nconst TEAS = [\n  [\"Darjeeling first flush\", \"India, spring picking\", \"6.20\"],\n  [\"Assam breakfast\", \"India, malty and full\", \"4.80\"],\n  [\"Sencha\", \"Japan, steamed green\", \"5.60\"],\n  [\"Gyokuro\", \"Japan, shade grown\", \"8.40\"],\n  [\"Tie Guan Yin\", \"China, rolled oolong\", \"6.90\"],\n  [\"Keemun\", \"China, light smoke\", \"5.20\"],\n  [\"Silver needle\", \"China, white buds\", \"9.10\"],\n  [\"Ceylon high grown\", \"Sri Lanka, bright\", \"4.90\"],\n  [\"Rooibos\", \"South Africa, red bush\", \"4.40\"],\n  [\"Fresh mint\", \"From the garden\", \"3.80\"],\n];\n\nexport default function TeaListRowsStretchWithScrollSpeed() {\n  const root = useRef<HTMLElement>(null);\n\n  useEffect(() => {\n    const el = root.current;\n    if (!el) return;\n    // The box is the scroller here. On a normal page, read scrollY and innerHeight instead.\n    const sc = el;\n    const rows = Array.from(el.querySelectorAll<HTMLElement>(\".w3stl-row\"));\n    let tops: number[] = [];\n    const measure = () => {\n      const base = sc.getBoundingClientRect().top - sc.scrollTop;\n      tops = rows.map((r) => { const b = r.getBoundingClientRect(); return b.top - base + b.height / 2; });\n    };\n    let demo = IDLE > 0;\n    const used = () => { demo = false; el.setAttribute(\"data-used\", \"\"); };\n    const inputs = [\"wheel\", \"touchstart\", \"pointerdown\", \"keydown\"];\n    inputs.forEach((e) => el.addEventListener(e, used, { passive: true }));\n    const reduce = window.matchMedia(\"(prefers-reduced-motion: reduce)\").matches;\n    let last = sc.scrollTop;\n    let up = false;\n    let cur = 0;\n    let f = 0;\n    let on = false;\n    let t0 = 0;\n    const tick = (now: number) => {\n      if (demo && on) {\n        sc.scrollTop = IDLE * (1 - Math.cos((now - t0) / 764));\n      }\n      const p = sc.scrollTop;\n      const v = p - last;\n      const h = sc.clientHeight;\n      const mid = p + h / 2;\n      last = p;\n      if (v) up = v < 0;\n      cur += (Math.min(MAX, Math.abs(v) * STRETCH) - cur) * EASE;\n      if (cur < 0.001 && !v) cur = 0;\n      rows.forEach((r, i) => {\n        // rows near the middle of the box stretch most, rows at the edges barely\n        const k = cur * Math.max(0, 1 - Math.abs(tops[i] - mid) / (h * 0.75));\n        r.style.transformOrigin = up ? \"50% 100%\" : \"50% 0\";\n        r.style.transform = k > 0.001 ? `scaleY(${(1 + k).toFixed(3)})` : \"\";\n      });\n      f = on && (cur || v || demo) ? requestAnimationFrame(tick) : 0;\n    };\n    const run = () => { if (!f && on) f = requestAnimationFrame(tick); };\n    const io = new IntersectionObserver(([e]) => {\n      on = e.isIntersecting;\n      if (on) { measure(); t0 = performance.now(); run(); }\n      else { cancelAnimationFrame(f); f = 0; }\n    });\n    if (!reduce) {\n      sc.addEventListener(\"scroll\", run, { passive: true });\n      window.addEventListener(\"resize\", measure);\n      io.observe(el);\n    }\n    return () => {\n      io.disconnect();\n      cancelAnimationFrame(f);\n      sc.removeEventListener(\"scroll\", run);\n      window.removeEventListener(\"resize\", measure);\n      inputs.forEach((e) => el.removeEventListener(e, used));\n    };\n  }, []);\n\n  return (\n    <section\n      ref={root}\n      tabIndex={0}\n      aria-label=\"Hollow Lane Tea Room, tea list\"\n      className=\"w3stl relative h-[620px] overflow-y-auto overscroll-contain bg-[#eee3cf] text-[#2b2118] focus-visible:outline focus-visible:outline-2 focus-visible:-outline-offset-4 focus-visible:outline-[#7a5a2e]\"\n    >\n      <style>{`\n        .w3stl-hint { background: linear-gradient(#eee3cf 60%, transparent); transition: opacity .5s ease; }\n        .w3stl[data-used] .w3stl-hint { opacity: 0; }\n        .w3stl-row { will-change: transform; }\n        .w3stl-serif { font-family: Georgia, \"Times New Roman\", serif; }\n        @media (prefers-reduced-motion: reduce) { .w3stl-row { transform: none !important; } .w3stl-hint { transition: none; } }\n      `}</style>\n      <p aria-hidden=\"true\" className=\"w3stl-hint sticky top-0 z-[2] px-5 py-3 text-center text-[11px] font-semibold uppercase tracking-[0.22em] text-[#6a5843]\">\n        Scroll inside\n      </p>\n      <div className=\"mx-auto max-w-[52rem] px-5 pb-8 pt-4 text-center\">\n        <p className=\"text-xs font-semibold uppercase tracking-[0.24em] text-[#7a5a2e]\">Hollow Lane Tea Room</p>\n        <h2 className=\"w3stl-serif mt-3 text-[clamp(32px,4.6vw,48px)] font-normal leading-[1.1] tracking-[-0.02em]\">Loose leaf, brewed by the pot.</h2>\n        <p className=\"mx-auto mt-3.5 max-w-[30rem] text-base leading-relaxed text-[#5a4a38]\">\n          Each pot serves two to three cups. Ask for a second steep of any leaf.\n        </p>\n      </div>\n      <ol className=\"mx-auto max-w-[52rem] px-5 pb-7\">\n        {TEAS.map(([name, from, price]) => (\n          <li key={name} className=\"w3stl-row grid grid-cols-[1fr_auto] items-baseline gap-x-4 border-t border-[#d3c4a8] py-[18px] last:border-b\">\n            <span className=\"w3stl-serif text-[clamp(22px,3vw,30px)] leading-[1.15]\">{name}</span>\n            <span className=\"row-start-2 pt-1 text-sm text-[#5a4a38]\">{from}</span>\n            <span className=\"row-span-2 self-center text-[17px] font-semibold tabular-nums\">{price}</span>\n          </li>\n        ))}\n      </ol>\n      <p className=\"mx-auto max-w-[52rem] px-5 pb-[72px] text-center text-sm leading-relaxed text-[#5a4a38]\">\n        Prices per pot. Scones and the day's cake are listed on the board by the counter.\n      </p>\n    </section>\n  );\n}\n"}]}
