{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"kinetic-type-line-stretching-with-scroll","type":"registry:block","title":"Kinetic Type Line Stretching With Scroll","description":"","dependencies":["framer-motion"],"files":[{"path":"components/we-inc/kinetic-type-line-stretching-with-scroll.tsx","type":"registry:component","content":"import { useEffect, useRef } from \"react\";\nimport { useReducedMotion } from \"framer-motion\";\n\nconst WORD = \"LENGTHEN\";\nconst MAX_STRETCH = 0.55; // extra height at the peak of the wave (0.55 = 155% tall)\nconst SCROLL_BOOST = 0.4; // extra stretch added while the page is scrolling\nconst IDLE_SPEED = 0.0007; // how fast the stretch wanders when nobody scrolls\n\nexport default function KineticTypeLineStretchingWithScroll() {\n  const root = useRef<HTMLElement>(null);\n  const letters = useRef<(HTMLSpanElement | null)[]>([]);\n  const reduce = useReducedMotion();\n\n  useEffect(() => {\n    const el = root.current;\n    if (!el) return;\n    const spans = letters.current;\n    const n = WORD.length;\n    const apply = (focus: number, amp: number) => {\n      for (let i = 0; i < n; i += 1) {\n        const s = spans[i];\n        if (!s) continue;\n        const k = 1 + amp * Math.exp(-((i - focus) ** 2) / 2.4);\n        s.style.transform = `scaleY(${k.toFixed(3)})`;\n      }\n    };\n    if (reduce) {\n      apply((n - 1) / 2, MAX_STRETCH * 0.6);\n      return;\n    }\n    let frame = 0;\n    let visible = true;\n    let lastP = -1;\n    let boost = 0;\n    let amp = MAX_STRETCH;\n    const progress = () => {\n      const r = el.getBoundingClientRect();\n      const vh = window.innerHeight || 1;\n      return Math.min(1, Math.max(0, (vh - r.top) / (vh + r.height)));\n    };\n    const tick = (now: number) => {\n      const p = progress();\n      if (lastP >= 0) boost = Math.min(SCROLL_BOOST, boost + Math.abs(p - lastP) * 6);\n      lastP = p;\n      boost *= 0.93;\n      amp += (MAX_STRETCH + boost - amp) * 0.12;\n      const focus = (n - 1) / 2 + Math.sin(now * IDLE_SPEED - 1.2) * (n / 2) + (p - 0.5) * n;\n      apply(focus, amp);\n      frame = requestAnimationFrame(tick);\n    };\n    const play = () => {\n      if (!frame && visible) frame = requestAnimationFrame(tick);\n    };\n    const stop = () => {\n      cancelAnimationFrame(frame);\n      frame = 0;\n    };\n    const io = new IntersectionObserver(([entry]) => {\n      visible = entry.isIntersecting;\n      if (visible) play();\n      else stop();\n    });\n    io.observe(el);\n    play();\n    return () => {\n      stop();\n      io.disconnect();\n    };\n  }, [reduce]);\n\n  return (\n    <section ref={root} className=\"overflow-hidden bg-[#f1ece0] px-5 py-16 sm:px-10 sm:py-20\">\n      <style>{`\n        .w10kin-l { display: inline-block; transform-origin: 50% 100%; will-change: transform; }\n        @media (prefers-reduced-motion: reduce) { .w10kin-l { will-change: auto; } }\n      `}</style>\n      <div className=\"mx-auto max-w-5xl\">\n        <div className=\"flex items-center justify-between gap-4 text-xs font-semibold uppercase tracking-[0.28em] text-[#1f3d2b]\">\n          <span>Long Room Pilates</span>\n          <span className=\"hidden sm:inline\">Reformer · Mat · Barre</span>\n        </div>\n        <h1 className=\"mt-10 border-b-2 border-[#1f3d2b] pt-[0.6em] text-center text-[clamp(52px,13.2vw,172px)] font-black leading-[0.8] tracking-[-0.03em] text-[#1f3d2b]\">\n          <span className=\"sr-only\">Lengthen</span>\n          <span aria-hidden=\"true\" className=\"inline-flex items-end\">\n            {WORD.split(\"\").map((ch, i) => (\n              <span key={i} ref={(node) => { letters.current[i] = node; }} className=\"w10kin-l\">{ch}</span>\n            ))}\n          </span>\n        </h1>\n        <div className=\"mt-8 flex flex-col gap-6 sm:flex-row sm:items-end sm:justify-between\">\n          <p className=\"max-w-md text-base leading-relaxed text-[#3a4a3f] sm:text-lg\">\n            Slow, small-group classes that undo a week at the desk. Eight people per room, never more.\n          </p>\n          <a\n            href=\"#\"\n            className=\"inline-flex h-12 shrink-0 items-center self-start rounded-full bg-[#1f3d2b] px-7 text-sm font-semibold text-[#f1ece0] transition hover:bg-[#2c5a40] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[#1f3d2b] focus-visible:ring-offset-2 focus-visible:ring-offset-[#f1ece0] sm:self-auto\"\n          >\n            Book a first class\n          </a>\n        </div>\n      </div>\n    </section>\n  );\n}\n"}]}
