{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"text-reveal","type":"registry:block","title":"Text reveal","description":"A heading whose words rise in with a soft blur-to-sharp, staggered as it enters the viewport, with the full text shown immediately under reduced motion.","dependencies":["motion"],"registryDependencies":["utils"],"files":[{"path":"registry/prequel/text-reveal/text-reveal.tsx","type":"registry:component","content":"\"use client\";\n\nimport { Fragment, createElement, useEffect, useRef, useState } from \"react\";\nimport {\n  motion,\n  useMotionValueEvent,\n  useReducedMotion,\n  useScroll,\n  useSpring,\n  useTransform,\n  type MotionValue,\n} from \"motion/react\";\nimport { cn } from \"@/lib/utils\";\n\nexport type TextRevealProps = {\n  className?: string;\n  /** The text that lights up, word by word, as it scrolls through the viewport. */\n  text?: string;\n  /** Semantic element used for the heading. Defaults to \"h2\". */\n  as?: \"h1\" | \"h2\" | \"h3\" | \"p\";\n};\n\nconst DEFAULT_TEXT =\n  \"A dashboard should feel like a place you return to, not a report you reopen.\";\n\ntype RevealWordProps = {\n  word: string;\n  index: number;\n  count: number;\n  progress: MotionValue<number>;\n  reduce: boolean;\n};\n\nfunction RevealWord({\n  word,\n  index,\n  count,\n  progress,\n  reduce,\n}: RevealWordProps) {\n  const start = index / count;\n  const end = (index + 1) / count;\n  const opacity = useTransform(progress, [start, end], [0.16, 1], {\n    clamp: true,\n  });\n\n  return (\n    <motion.span\n      className=\"inline-block will-change-[opacity]\"\n      style={{ opacity: reduce ? 1 : opacity }}\n    >\n      {word}\n    </motion.span>\n  );\n}\n\n/* ------------------------------------------------------------------ */\n/* the small readout at the end of the rail                            */\n/* ------------------------------------------------------------------ */\n\nfunction ProgressReadout({ value }: { value: MotionValue<number> }) {\n  const [percent, setPercent] = useState(0);\n  const last = useRef(-1);\n\n  useEffect(() => {\n    const next = Math.round(value.get() * 100);\n    last.current = next;\n    setPercent(next);\n  }, [value]);\n\n  useMotionValueEvent(value, \"change\", (latest) => {\n    const next = Math.round(latest * 100);\n    if (next === last.current) return;\n    last.current = next;\n    setPercent(next);\n  });\n\n  return <>{percent}%</>;\n}\n\n/* ------------------------------------------------------------------ */\n/* block                                                               */\n/* ------------------------------------------------------------------ */\n\nexport function TextReveal({\n  className,\n  text = DEFAULT_TEXT,\n  as = \"h2\",\n}: TextRevealProps) {\n  const reduce = Boolean(useReducedMotion());\n  const rootRef = useRef<HTMLDivElement>(null);\n\n  const { scrollYProgress } = useScroll({\n    target: rootRef,\n    offset: [\"start 0.9\", \"end 0.35\"],\n  });\n  const progress = useSpring(scrollYProgress, {\n    stiffness: 120,\n    damping: 30,\n    mass: 0.35,\n  });\n\n  const words = text.trim().split(/\\s+/).filter(Boolean);\n  const count = Math.max(1, words.length);\n\n  const classes = cn(\n    \"text-balance font-semibold tracking-tight text-foreground\",\n    as === \"h1\" && \"text-4xl sm:text-5xl md:text-6xl\",\n    as === \"h2\" && \"text-3xl sm:text-4xl md:text-5xl\",\n    as === \"h3\" && \"text-2xl sm:text-3xl\",\n    as === \"p\" &&\n      \"text-base font-normal leading-relaxed text-muted-foreground sm:text-lg\"\n  );\n\n  return (\n    <div ref={rootRef} className={cn(\"w-full max-w-3xl\", className)}>\n      {createElement(\n        as,\n        { className: classes },\n        words.map((word, index) => (\n          <Fragment key={`${word}-${index}`}>\n            <RevealWord\n              word={word}\n              index={index}\n              count={count}\n              progress={progress}\n              reduce={reduce}\n            />\n            {index < words.length - 1 ? \" \" : null}\n          </Fragment>\n        ))\n      )}\n\n      <div aria-hidden=\"true\" className=\"mt-6 flex items-center gap-3\">\n        <div className=\"relative h-px flex-1 overflow-hidden bg-border\">\n          <motion.div\n            className=\"h-px w-full origin-left bg-foreground\"\n            style={{ scaleX: reduce ? 1 : progress }}\n          />\n        </div>\n        <span className=\"w-9 text-right text-[11px] font-medium tabular-nums text-muted-foreground\">\n          {reduce ? \"100%\" : <ProgressReadout value={progress} />}\n        </span>\n      </div>\n    </div>\n  );\n}\n\nexport default TextReveal;\n"}]}