{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"rise-chars","type":"registry:ui","title":"Rise Chars","description":"Characters stretch, rise and fade into place one after another, scrubbed by scroll position inside any scroll container.","dependencies":[],"registryDependencies":[],"files":[{"path":"registry/ui/rise-chars.tsx","type":"registry:ui","content":"\"use client\";\n\nimport { Fragment, useEffect, useRef, type RefObject } from \"react\";\n\nexport interface RiseCharsProps {\n  text?: string;\n  /** Scrolling element; defaults to the window. */\n  scrollContainerRef?: RefObject<HTMLElement | null>;\n  /** Where the animation starts: element top at this fraction of the viewport height (1 = bottom edge). */\n  start?: number;\n  /** Where every character has landed, as a fraction of the viewport height. */\n  end?: number;\n  /** Progress offset between consecutive characters (0-0.2). */\n  stagger?: number;\n  as?: \"h1\" | \"h2\" | \"h3\" | \"p\" | \"div\";\n  className?: string;\n}\n\nconst easeOut = (t: number) => 1 - (1 - t) ** 3;\n\nexport function RiseChars({\n  text = \"Scroll to float\",\n  scrollContainerRef,\n  start = 0.95,\n  end = 0.45,\n  stagger = 0.04,\n  as: Tag = \"h2\",\n  className,\n}: RiseCharsProps) {\n  const ref = useRef<HTMLElement>(null);\n\n  useEffect(() => {\n    const el = ref.current!;\n    const chars = Array.from(el.querySelectorAll<HTMLSpanElement>(\"[data-sf]\"));\n    const scroller = scrollContainerRef?.current ?? null;\n    const target: HTMLElement | Window = scroller ?? window;\n    const reduced = window.matchMedia(\"(prefers-reduced-motion: reduce)\").matches;\n    const n = chars.length;\n    let raf = 0;\n\n    const update = () => {\n      raf = 0;\n      const vp = scroller ? scroller.getBoundingClientRect() : { top: 0, height: window.innerHeight };\n      const top = el.getBoundingClientRect().top - vp.top;\n      const from = vp.height * start;\n      const to = vp.height * end;\n      const p = reduced ? 1 : Math.min(1, Math.max(0, (from - top) / Math.max(1, from - to)));\n      const spread = stagger * Math.max(0, n - 1);\n      chars.forEach((c, i) => {\n        const e = easeOut(Math.min(1, Math.max(0, p * (1 + spread) - i * stagger)));\n        const k = 1 - e;\n        c.style.opacity = `${e}`;\n        c.style.transform = `translate3d(0, ${k * 110}%, 0) scale(${1 - k * 0.35}, ${1 + k * 1.2})`;\n      });\n    };\n    const schedule = () => {\n      if (!raf) raf = requestAnimationFrame(update);\n    };\n\n    update();\n    target.addEventListener(\"scroll\", schedule, { passive: true });\n    window.addEventListener(\"resize\", schedule);\n    return () => {\n      cancelAnimationFrame(raf);\n      target.removeEventListener(\"scroll\", schedule);\n      window.removeEventListener(\"resize\", schedule);\n    };\n  }, [text, scrollContainerRef, start, end, stagger]);\n\n  const words = text.split(\" \");\n  return (\n    <Tag ref={ref as never} className={className}>\n      <span className=\"sr-only\">{text}</span>\n      <span aria-hidden>\n        {words.map((word, w) => (\n          <Fragment key={w}>\n            <span style={{ display: \"inline-block\", whiteSpace: \"nowrap\" }}>\n              {Array.from(word).map((c, i) => (\n                <span\n                  key={i}\n                  data-sf=\"\"\n                  style={{ display: \"inline-block\", opacity: 0, transformOrigin: \"50% 0%\", willChange: \"transform, opacity\" }}\n                >\n                  {c}\n                </span>\n              ))}\n            </span>\n            {w < words.length - 1 && \" \"}\n          </Fragment>\n        ))}\n      </span>\n    </Tag>\n  );\n}\n"}]}