{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "slide-up-reveal",
  "title": "Slide Up Reveal",
  "description": "A text reveal that slides characters, words or lines up into view, with stagger and scroll triggers.",
  "dependencies": [
    "motion"
  ],
  "files": [
    {
      "path": "packages/slide-up-reveal/slide-up-reveal.tsx",
      "content": "\"use client\";\n\nimport { MotionConfigContext, motion } from \"motion/react\";\nimport {\n  useCallback,\n  useEffect,\n  useMemo,\n  useRef,\n  useState,\n  useContext,\n  useSyncExternalStore,\n} from \"react\";\n\nimport { cn } from \"@/lib/utils\";\n\n/**\n * \"user\" (the default) follows a surrounding <MotionConfig reducedMotion>,\n * then the visitor's \"reduce motion\" device setting. \"always\" and \"never\"\n * force the calm or the full version.\n */\nexport type ReducedMotion = \"user\" | \"always\" | \"never\";\n\nconst REDUCED_MOTION_QUERY = \"(prefers-reduced-motion: reduce)\";\n\nfunction subscribeToReducedMotion(onChange: () => void) {\n  const query = window.matchMedia(REDUCED_MOTION_QUERY);\n  query.addEventListener(\"change\", onChange);\n  return () => query.removeEventListener(\"change\", onChange);\n}\n\n// The prop wins, then MotionConfig, then the device setting. The device is\n// read as \"no\" while server rendering, so hydration always matches.\nfunction useShouldReduceMotion(mode: ReducedMotion = \"user\") {\n  const device = useSyncExternalStore(\n    subscribeToReducedMotion,\n    () => window.matchMedia(REDUCED_MOTION_QUERY).matches,\n    () => false,\n  );\n  const config = useContext(MotionConfigContext).reducedMotion;\n  if (mode !== \"user\") return mode === \"always\";\n  if (config === \"always\" || config === \"never\") return config === \"always\";\n  return device;\n}\n\ninterface SlideUpRevealProps\n  extends Omit<\n    React.ComponentProps<\"span\">,\n    \"children\" | \"onAnimationStart\" | \"onAnimationEnd\" | \"onDrag\" | \"onDragStart\" | \"onDragEnd\"\n  > {\n  /** The text to reveal. Plain text works best: it is split into words, characters or lines. */\n  children: React.ReactNode;\n  /** What slides up as one piece. \"lines\" splits on line breaks in the text. */\n  split?: \"words\" | \"characters\" | \"lines\";\n  /** Seconds to wait before the first piece moves. */\n  delay?: number;\n  /** Seconds between one piece and the next. */\n  stagger?: number;\n  /** Seconds each piece takes to slide up. @default 0.5 */\n  duration?: number;\n  /** Where the stagger starts: the first piece, the last, or the middle outwards. */\n  from?: \"first\" | \"last\" | \"center\";\n  /** Classes for the wrapper. */\n  className?: string;\n  /** Classes for each word's mask. Useful to fix clipped descenders with a little padding. */\n  wordClassName?: string;\n  /** Classes for each character's mask, when split is \"characters\". */\n  charClassName?: string;\n  /**\n   * Show the text. Set to false to hide it, and to true again to play the reveal, for\n   * example after a form is sent. @default true\n   */\n  trigger?: boolean;\n  /** Called each time the reveal begins. */\n  onAnimationStart?: () => void;\n  /** Called when the last piece has arrived. */\n  onAnimationComplete?: () => void;\n  /** Wait until the text scrolls into view before revealing it. */\n  inView?: boolean;\n  /** With inView, reveal only the first time it comes into view. */\n  once?: boolean;\n  /**\n   * \"user\" follows a surrounding MotionConfig, then the visitor's reduce-motion setting.\n   * \"always\" and \"never\" force the calm or the full version.\n   */\n  reducedMotion?: ReducedMotion;\n}\n\ninterface WordObject {\n  characters: string[];\n  needsSpace: boolean;\n}\n\n/** A soft ease-out: quick to start, long to settle. */\nconst EASE = [0.625, 0.05, 0, 1] as const;\n\nconst SlideUpReveal = ({\n  children,\n  split = \"words\",\n  delay = 0,\n  stagger = 0.1,\n  duration = 0.5,\n  from = \"first\",\n  className,\n  wordClassName,\n  charClassName,\n  trigger = true,\n  onAnimationStart,\n  onAnimationComplete,\n  inView = false,\n  once = true,\n  reducedMotion = \"user\",\n  ...props\n}: SlideUpRevealProps) => {\n  const text = typeof children === \"string\" ? children : children?.toString() || \"\";\n  // With inView, the pieces wait until the wrapper has scrolled into view.\n  const [seen, setSeen] = useState(false);\n  const isAnimating = trigger && (!inView || seen);\n  // Reduced motion fades the text in where it stands, with no slide and no stagger.\n  const reduce = useShouldReduceMotion(reducedMotion);\n\n  const splitIntoCharacters = (text: string): string[] => {\n    if (typeof Intl !== \"undefined\" && \"Segmenter\" in Intl) {\n      const segmenter = new Intl.Segmenter(\"en\", { granularity: \"grapheme\" });\n      return Array.from(segmenter.segment(text), ({ segment }) => segment);\n    }\n    return Array.from(text);\n  };\n\n  const elements = useMemo(() => {\n    const words = text.split(\" \");\n    if (split === \"characters\") {\n      return words.map((word, i) => ({\n        characters: splitIntoCharacters(word),\n        needsSpace: i !== words.length - 1,\n      }));\n    }\n    return split === \"words\" ? text.split(\" \") : text.split(\"\\n\");\n  }, [text, split]);\n\n  const getStaggerDelay = useCallback(\n    (index: number) => {\n      const total =\n        split === \"characters\"\n          ? elements.reduce(\n              (acc, word) =>\n                acc +\n                (typeof word === \"string\"\n                  ? 1\n                  : word.characters.length + (word.needsSpace ? 1 : 0)),\n              0,\n            )\n          : elements.length;\n\n      if (from === \"first\") return index * stagger;\n      if (from === \"last\") return (total - 1 - index) * stagger;\n      if (from === \"center\") {\n        const center = Math.floor(total / 2);\n        return Math.abs(center - index) * stagger;\n      }\n      return index * stagger;\n    },\n    [elements, from, stagger, split],\n  );\n\n  // onAnimationStart fires each time the reveal begins, however it started.\n  const onStartRef = useRef(onAnimationStart);\n  useEffect(() => {\n    onStartRef.current = onAnimationStart;\n  });\n  useEffect(() => {\n    if (isAnimating) onStartRef.current?.();\n  }, [isAnimating]);\n\n  const variants = reduce\n    ? {\n        hidden: { opacity: 0 },\n        visible: { opacity: 1, transition: { duration: 0.3, delay } },\n      }\n    : {\n        hidden: { y: \"100%\" },\n        visible: (i: number) => ({\n          y: 0,\n          transition: { type: \"tween\" as const, ease: EASE, duration, delay: delay + getStaggerDelay(i) },\n        }),\n      };\n\n  return (\n    <motion.span\n      {...props}\n      className={cn(className, \"flex flex-wrap whitespace-pre-wrap\", split === \"lines\" && \"flex-col\")}\n      initial=\"hidden\"\n      whileInView={inView ? \"visible\" : undefined}\n      viewport={{ once }}\n      onViewportEnter={() => setSeen(true)}\n      onViewportLeave={() => {\n        if (!once) setSeen(false);\n      }}\n    >\n      <span className=\"sr-only\">{text}</span>\n\n      {(split === \"characters\"\n        ? (elements as WordObject[])\n        : (elements as string[]).map((el, i, arr) => ({\n            characters: [el],\n            needsSpace: split === \"words\" && i !== arr.length - 1,\n          }))\n      ).map((wordObj, wordIndex, array) => {\n        const previousCharsCount = array\n          .slice(0, wordIndex)\n          .reduce((sum, word) => sum + word.characters.length, 0);\n\n        return (\n          <span\n            key={wordIndex}\n            aria-hidden=\"true\"\n            className={cn(\"inline-flex overflow-hidden\", wordClassName)}\n          >\n            {wordObj.characters.map((char, charIndex) => (\n              <span\n                className={cn(charClassName, \"whitespace-pre-wrap relative overflow-hidden\")}\n                key={charIndex}\n              >\n                <motion.span\n                  custom={previousCharsCount + charIndex}\n                  initial=\"hidden\"\n                  animate={isAnimating ? \"visible\" : \"hidden\"}\n                  variants={variants}\n                  onAnimationComplete={\n                    isAnimating &&\n                    wordIndex === array.length - 1 &&\n                    charIndex === wordObj.characters.length - 1\n                      ? onAnimationComplete\n                      : undefined\n                  }\n                  className=\"inline-block\"\n                >\n                  {char}\n                </motion.span>\n              </span>\n            ))}\n            {wordObj.needsSpace && (\n              <span className=\"relative overflow-hidden\">\n                <motion.span\n                  custom={previousCharsCount + wordObj.characters.length}\n                  initial=\"hidden\"\n                  animate={isAnimating ? \"visible\" : \"hidden\"}\n                  variants={variants}\n                  className=\"inline-block\"\n                >\n                  {\" \"}\n                </motion.span>\n              </span>\n            )}\n          </span>\n        );\n      })}\n    </motion.span>\n  );\n};\n\nexport default SlideUpReveal;\nexport type { SlideUpRevealProps };\n",
      "type": "registry:component",
      "target": "components/satori-ui/slide-up-reveal.tsx"
    }
  ],
  "meta": {
    "usage": "<SlideUpReveal className=\"text-4xl font-semibold\">\n  Small details, done properly.\n</SlideUpReveal>"
  },
  "type": "registry:component"
}