{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "reveal",
  "title": "Reveal",
  "description": "Fades and moves content into place when it scrolls into view, alone or staggered in a group. Visible without JavaScript.",
  "dependencies": [
    "@radix-ui/react-slot"
  ],
  "registryDependencies": [
    "@corsair-ui/utils",
    "@corsair-ui/use-in-view"
  ],
  "files": [
    {
      "path": "registry/default/ui/reveal.tsx",
      "content": "\"use client\";\n\nimport { Slot } from \"@radix-ui/react-slot\";\nimport {\n  Children,\n  createContext,\n  useContext,\n  useMemo,\n  useRef,\n  useState,\n  type ComponentProps,\n  type CSSProperties,\n  type Ref,\n} from \"react\";\n\nimport { useInView } from \"@/registry/default/hooks/use-in-view\";\n\ntype RevealDirection = \"up\" | \"down\" | \"left\" | \"right\" | \"none\";\n\n/**\n * \"idle\" until the browser answers, \"hidden\" while waiting below the fold,\n * \"shown\" once scrolled in. Elements already on screen stay \"idle\" and are\n * shown as rendered, so nothing blinks on load.\n */\ntype RevealPhase = \"idle\" | \"hidden\" | \"shown\";\n\nconst EASE_OUT = \"cubic-bezier(0.22, 1, 0.36, 1)\";\n\nfunction prefersReducedMotion() {\n  return (\n    typeof window !== \"undefined\" &&\n    window.matchMedia?.(\"(prefers-reduced-motion: reduce)\").matches === true\n  );\n}\n\nfunction mergeRefs<T>(...refs: (Ref<T> | undefined)[]) {\n  return (node: T | null) => {\n    for (const ref of refs) {\n      if (typeof ref === \"function\") ref(node);\n      else if (ref) ref.current = node;\n    }\n  };\n}\n\nfunction hiddenTransform(direction: RevealDirection, distance: number) {\n  switch (direction) {\n    case \"up\":\n      return `translate3d(0, ${distance}px, 0)`;\n    case \"down\":\n      return `translate3d(0, ${-distance}px, 0)`;\n    case \"left\":\n      return `translate3d(${distance}px, 0, 0)`;\n    case \"right\":\n      return `translate3d(${-distance}px, 0, 0)`;\n    default:\n      return undefined;\n  }\n}\n\nfunction useRevealPhase<T extends Element>(once: boolean, amount: number, observe: boolean) {\n  const [phase, setPhase] = useState<RevealPhase>(\"idle\");\n  const answered = useRef(false);\n  const [ref] = useInView<T>({\n    once,\n    amount,\n    onChange: (inView) => {\n      const first = !answered.current;\n      answered.current = true;\n      if (prefersReducedMotion()) return;\n      if (first) {\n        if (!inView) setPhase(\"hidden\");\n      } else if (inView) {\n        setPhase((current) => (current === \"hidden\" ? \"shown\" : current));\n      } else if (!once) {\n        setPhase(\"hidden\");\n      }\n    },\n  });\n  return [observe ? ref : undefined, phase] as const;\n}\n\nconst RevealGroupContext = createContext<{ phase: RevealPhase; stagger: number } | null>(null);\nconst RevealIndexContext = createContext(0);\n\ninterface RevealOptions {\n  /** Where the element comes from: \"up\" rises into place. */\n  direction?: RevealDirection;\n  /** How far it travels, in px. */\n  distance?: number;\n  /** In ms. */\n  duration?: number;\n  /** In ms, added to the group's stagger. */\n  delay?: number;\n  /** Reveal only the first time; with `false` it hides again when scrolled out. */\n  once?: boolean;\n  /** Fraction of the element that has to be visible to start, from 0 to 1. */\n  amount?: number;\n}\n\ninterface RevealProps extends ComponentProps<\"div\">, RevealOptions {\n  /** Reveal the single child element instead of wrapping it in a div. */\n  asChild?: boolean;\n}\n\n/**\n * Fades and moves content into place when it scrolls into view. Server\n * rendered content stays visible until the browser confirms it is below the\n * fold, so it works without JavaScript and never blinks on load. With\n * `prefers-reduced-motion` it is simply shown.\n */\nfunction Reveal({\n  asChild = false,\n  direction = \"up\",\n  distance = 16,\n  duration = 600,\n  delay = 0,\n  once = true,\n  amount = 0.2,\n  style,\n  ref,\n  ...props\n}: RevealProps) {\n  const group = useContext(RevealGroupContext);\n  const index = useContext(RevealIndexContext);\n  const [observe, ownPhase] = useRevealPhase<HTMLDivElement>(once, amount, !group);\n  const phase = group ? group.phase : ownPhase;\n  const wait = delay + (group ? index * group.stagger : 0);\n  const mergedRef = useMemo(() => mergeRefs(ref, observe), [ref, observe]);\n  const Comp = asChild ? Slot : \"div\";\n\n  const motion: CSSProperties =\n    phase === \"hidden\"\n      ? { opacity: 0, transform: hiddenTransform(direction, distance) }\n      : phase === \"shown\"\n        ? {\n            transition: `opacity ${duration}ms ${EASE_OUT} ${wait}ms, transform ${duration}ms ${EASE_OUT} ${wait}ms`,\n          }\n        : {};\n\n  return (\n    <Comp\n      ref={mergedRef}\n      data-slot=\"reveal\"\n      data-state={phase === \"hidden\" ? \"hidden\" : \"visible\"}\n      style={{ ...motion, ...style }}\n      {...props}\n    />\n  );\n}\n\ninterface RevealGroupProps extends ComponentProps<\"div\">, Pick<RevealOptions, \"once\" | \"amount\"> {\n  /** Delay between one child and the next, in ms. */\n  stagger?: number;\n}\n\n/**\n * Reveals its children one after another when the group scrolls into view.\n * Put a Reveal in each child; they take the group's timing instead of\n * watching the viewport themselves.\n *\n * @example\n * <RevealGroup className=\"grid grid-cols-3 gap-4\" stagger={80}>\n *   {cards.map((card) => <Reveal key={card.id}><Card>…</Card></Reveal>)}\n * </RevealGroup>\n */\nfunction RevealGroup({\n  stagger = 80,\n  once = true,\n  amount = 0.2,\n  children,\n  ref,\n  ...props\n}: RevealGroupProps) {\n  const [observe, phase] = useRevealPhase<HTMLDivElement>(once, amount, true);\n  const mergedRef = useMemo(() => mergeRefs(ref, observe), [ref, observe]);\n  const context = useMemo(() => ({ phase, stagger }), [phase, stagger]);\n\n  return (\n    <RevealGroupContext.Provider value={context}>\n      <div\n        ref={mergedRef}\n        data-slot=\"reveal-group\"\n        data-state={phase === \"hidden\" ? \"hidden\" : \"visible\"}\n        {...props}\n      >\n        {Children.map(children, (child, index) => (\n          <RevealIndexContext.Provider value={index}>{child}</RevealIndexContext.Provider>\n        ))}\n      </div>\n    </RevealGroupContext.Provider>\n  );\n}\n\nexport { Reveal, RevealGroup, type RevealDirection, type RevealGroupProps, type RevealProps };\n",
      "type": "registry:ui"
    }
  ],
  "categories": [
    "motion"
  ],
  "type": "registry:ui"
}