{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"reveal","type":"registry:ui","title":"Reveal","description":"A wrapper that fades, slides, unblurs or scales its content in as it scrolls into view.","dependencies":["motion"],"registryDependencies":["https://ui.mekaigames.com/r/theme.json"],"files":[{"path":"components/ui/reveal.tsx","type":"registry:ui","content":"\"use client\";\n\nimport { motion, useInView, useReducedMotion, type TargetAndTransition } from \"motion/react\";\nimport { Children, isValidElement, useRef, type ReactNode, type RefObject } from \"react\";\n\nexport type RevealVariant = \"fade\" | \"slide-up\" | \"slide-left\" | \"blur\" | \"scale\";\n\ntype RevealProps = {\n  children: ReactNode;\n  /** How the content arrives. */\n  variant?: RevealVariant;\n  /** Wait before playing, in seconds. */\n  delay?: number;\n  /** Length of the animation, in seconds. */\n  duration?: number;\n  /** How far slides travel, in pixels. Also sets the blur and scale strength. */\n  distance?: number;\n  /** Play only the first time; otherwise hide again when scrolled out. */\n  once?: boolean;\n  /** Seconds between direct children. 0 animates everything together. */\n  stagger?: number;\n  /** Share of the element that must be visible before it plays, from 0 to 1. */\n  amount?: number;\n  /** Scrolling element to watch instead of the page, such as a scrolling panel. */\n  root?: RefObject<Element | null>;\n  className?: string;\n};\n\nconst EASE = [0.22, 1, 0.36, 1] as const;\n\nfunction hiddenState(variant: RevealVariant, distance: number, reduce: boolean): TargetAndTransition {\n  if (reduce) return { opacity: 0 };\n  switch (variant) {\n    case \"slide-up\":\n      return { opacity: 0, y: distance };\n    case \"slide-left\":\n      return { opacity: 0, x: distance };\n    case \"blur\":\n      return { opacity: 0, filter: `blur(${Math.max(4, distance / 2)}px)` };\n    case \"scale\":\n      return { opacity: 0, scale: Math.max(0.5, 1 - distance / 240) };\n    default:\n      return { opacity: 0 };\n  }\n}\n\n/** The resting state for exactly the properties the hidden state touches. */\nfunction shownState(hidden: TargetAndTransition): TargetAndTransition {\n  return {\n    opacity: 1,\n    ...(\"x\" in hidden ? { x: 0 } : {}),\n    ...(\"y\" in hidden ? { y: 0 } : {}),\n    ...(\"scale\" in hidden ? { scale: 1 } : {}),\n    ...(\"filter\" in hidden ? { filter: \"blur(0px)\" } : {}),\n  };\n}\n\n/** A wrapper that animates its content in as it scrolls into view, with an optional stagger. */\nexport function Reveal({\n  children,\n  variant = \"slide-up\",\n  delay = 0,\n  duration = 0.6,\n  distance = 24,\n  once = true,\n  stagger = 0,\n  amount = 0.3,\n  root,\n  className = \"\",\n}: RevealProps) {\n  const reduce = Boolean(useReducedMotion());\n  const ref = useRef<HTMLDivElement>(null);\n  const inView = useInView(ref, { root, once, amount });\n  const hidden = hiddenState(variant, distance, reduce);\n  const shown = shownState(hidden);\n  const time = reduce ? Math.min(duration, 0.3) : duration;\n\n  if (stagger > 0) {\n    return (\n      <div ref={ref} className={className}>\n        {Children.toArray(children).map((child, i) => (\n          <motion.div\n            key={isValidElement(child) && child.key !== null ? child.key : i}\n            initial={hidden}\n            animate={inView ? shown : hidden}\n            transition={{ duration: time, delay: inView ? delay + i * stagger : 0, ease: EASE }}\n          >\n            {child}\n          </motion.div>\n        ))}\n      </div>\n    );\n  }\n\n  return (\n    <motion.div\n      ref={ref}\n      className={className}\n      initial={hidden}\n      animate={inView ? shown : hidden}\n      transition={{ duration: time, delay: inView ? delay : 0, ease: EASE }}\n    >\n      {children}\n    </motion.div>\n  );\n}\n"}]}