{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"eased-inertia-scroll-inside-one-reading-panel","type":"registry:block","title":"Eased Inertia Scroll Inside One Reading Panel","description":"","dependencies":[],"files":[{"path":"components/we-inc/eased-inertia-scroll-inside-one-reading-panel.tsx","type":"registry:component","content":"import { useEffect, useRef, useState } from \"react\";\n\nconst EASE = 0.12; // share of the remaining distance covered each frame (lower = longer glide)\nconst TEAS = [\n  { name: \"First flush, upper slope\", origin: \"Darjeeling\", note: \"Thin as a white wine, with green grape and a dry, mineral finish.\" },\n  { name: \"Smoked pine souchong\", origin: \"Fujian\", note: \"Campfire on the nose, then longan sweetness once the cup cools.\" },\n  { name: \"Roasted stem hojicha\", origin: \"Kyoto\", note: \"Toasted barley and cocoa, low in caffeine, good after dinner.\" },\n  { name: \"Spring dragonwell\", origin: \"Hangzhou\", note: \"Flat jade leaves that taste of chestnut and fresh-cut peas.\" },\n  { name: \"Aged white peony\", origin: \"Fuding\", note: \"Five years in the tin have turned the hay notes to dried date.\" },\n  { name: \"High mountain oolong\", origin: \"Lishan\", note: \"Rolled pearls that open into lilac and a long, buttery finish.\" },\n  { name: \"Golden tips\", origin: \"Yunnan\", note: \"Malty and round, with a note of sweet potato that takes milk well.\" },\n  { name: \"Shaded gyokuro\", origin: \"Yame\", note: \"Brewed cool, it is brothy and deep, close to a light seaweed stock.\" },\n  { name: \"Ruby breakfast\", origin: \"Nantou\", note: \"Cinnamon and red fruit, strong enough to stand up to a long steep.\" },\n  { name: \"Wild leaf pu-erh\", origin: \"Lincang\", note: \"Earth, camphor and forest floor, and it changes over many infusions.\" },\n];\n\nexport default function EasedInertiaScrollInsideOneReadingPanel() {\n  const panel = useRef<HTMLDivElement>(null);\n  const bar = useRef<HTMLDivElement>(null);\n  const root = useRef<HTMLElement>(null);\n  const [enabled, setEnabled] = useState(true);\n  const [capable, setCapable] = useState(false);\n  const live = useRef(true);\n  live.current = enabled;\n\n  useEffect(() => {\n    const el = panel.current;\n    const sec = root.current;\n    if (!el || !sec) return;\n    const can = window.matchMedia(\"(hover: hover) and (pointer: fine)\").matches && !window.matchMedia(\"(prefers-reduced-motion: reduce)\").matches;\n    setCapable(can);\n    let cur = el.scrollTop;\n    let target = cur;\n    let frame = 0;\n    const max = () => el.scrollHeight - el.clientHeight;\n    const step = () => {\n      frame = 0;\n      cur += (target - cur) * EASE;\n      if (Math.abs(target - cur) < 0.5) cur = target;\n      el.scrollTop = cur;\n      if (cur !== target) frame = requestAnimationFrame(step);\n    };\n    const onWheel = (e: WheelEvent) => {\n      if (!can || !live.current || e.ctrlKey) return;\n      const d = e.deltaY * (e.deltaMode === 1 ? 16 : e.deltaMode === 2 ? el.clientHeight : 1);\n      const t = Math.max(0, Math.min(max(), target + d));\n      if (t === target && cur === target) return; // at an end: let the page take over\n      e.preventDefault();\n      target = t;\n      if (!frame) frame = requestAnimationFrame(step);\n    };\n    const onScroll = () => {\n      if (!frame) cur = target = el.scrollTop; // keyboard, scrollbar or touch moved it\n      const m = max();\n      if (bar.current) bar.current.style.transform = `scaleX(${m ? el.scrollTop / m : 0})`;\n      sec.classList.toggle(\"w6inr-moved\", el.scrollTop > 8);\n    };\n    const io = new IntersectionObserver(([e]) => {\n      if (!e.isIntersecting) {\n        cancelAnimationFrame(frame);\n        frame = 0;\n        cur = target = el.scrollTop;\n      }\n    });\n    io.observe(sec);\n    el.addEventListener(\"wheel\", onWheel, { passive: false });\n    el.addEventListener(\"scroll\", onScroll, { passive: true });\n    return () => {\n      cancelAnimationFrame(frame);\n      io.disconnect();\n      el.removeEventListener(\"wheel\", onWheel);\n      el.removeEventListener(\"scroll\", onScroll);\n    };\n  }, []);\n\n  return (\n    <section ref={root} className=\"bg-[#141a22] px-5 py-14 text-[#efe8dc] sm:px-10\">\n      <style>{`\n        .w6inr-bar { transform: scaleX(0); transform-origin: 0 50%; }\n        .w6inr-hint { transition: opacity .5s ease; }\n        .w6inr-moved .w6inr-hint { opacity: 0; }\n        .w6inr-panel { scrollbar-width: thin; scrollbar-color: #3b4656 transparent; }\n        @media (prefers-reduced-motion: reduce) { .w6inr-hint { transition: none; } }\n      `}</style>\n      <div className=\"mx-auto grid max-w-5xl gap-10 md:grid-cols-[1fr_1.4fr] md:items-start\">\n        <div>\n          <p className=\"text-xs font-semibold uppercase tracking-[0.24em] text-[#d9a95b]\">Kestrel Lane Tea Merchants</p>\n          <h2 className=\"mt-3 text-3xl font-semibold leading-tight\">This season's tasting notes</h2>\n          <p className=\"mt-4 max-w-sm text-sm leading-relaxed text-[#b9b2a6]\">Ten leaves we are pouring at the counter this month. Scroll the list with a mouse wheel and it glides to a stop.</p>\n          <button\n            type=\"button\"\n            aria-pressed={capable && enabled}\n            disabled={!capable}\n            onClick={() => setEnabled((v) => !v)}\n            className=\"mt-6 inline-flex h-11 items-center gap-3 rounded-full border border-[#efe8dc]/30 px-5 text-sm font-medium transition hover:border-[#efe8dc]/70 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[#d9a95b] disabled:opacity-70\"\n          >\n            <span aria-hidden=\"true\" className={`h-2.5 w-2.5 rounded-full ${capable && enabled ? \"bg-[#d9a95b]\" : \"bg-[#5b6573]\"}`} />\n            {capable ? `Eased scrolling ${enabled ? \"on\" : \"off\"}` : \"Native scrolling on this device\"}\n          </button>\n        </div>\n        <div className=\"relative overflow-hidden rounded-xl border border-[#efe8dc]/10 bg-[#1b232d]\">\n          <div aria-hidden=\"true\" className=\"absolute inset-x-0 top-0 z-10 h-0.5 bg-[#efe8dc]/10\">\n            <div ref={bar} className=\"w6inr-bar h-full bg-[#d9a95b]\" />\n          </div>\n          <div className=\"w6inr-hint pointer-events-none absolute right-4 top-4 z-10 rounded-full bg-[#efe8dc] px-3 py-1.5 text-xs font-medium text-[#141a22]\" aria-hidden=\"true\">Scroll inside</div>\n          <div ref={panel} tabIndex={0} role=\"region\" aria-label=\"Tasting notes, scrollable\" className=\"w6inr-panel h-[440px] overflow-y-auto overscroll-contain px-6 outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-[#d9a95b]\">\n            <ol className=\"py-4\">\n              {TEAS.map((t, i) => (\n                <li key={t.name} className=\"grid grid-cols-[2.5rem_1fr] gap-x-2 border-b border-[#efe8dc]/10 py-6 last:border-0\">\n                  <span className=\"pt-1 text-sm tabular-nums text-[#d9a95b]\">{String(i + 1).padStart(2, \"0\")}</span>\n                  <div>\n                    <h3 className=\"text-lg font-semibold\">{t.name}</h3>\n                    <p className=\"mt-0.5 text-xs uppercase tracking-[0.18em] text-[#9da6b2]\">{t.origin}</p>\n                    <p className=\"mt-2 text-sm leading-relaxed text-[#cfc7ba]\">{t.note}</p>\n                  </div>\n                </li>\n              ))}\n            </ol>\n          </div>\n        </div>\n      </div>\n    </section>\n  );\n}\n"}]}
