{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "reveal",
  "title": "Reveal",
  "description": "Animates its children in when they enter the viewport.",
  "dependencies": [
    "motion@^13.1.0"
  ],
  "files": [
    {
      "path": "packages/react/src/reveal.tsx",
      "content": "'use client'\n\nimport './reveal.css'\nimport { type RevealOptions, reveal, revealInitialStyle } from './motion/reveal.js'\nimport type { ElementType, HTMLAttributes, ReactNode } from 'react'\nimport { forwardRef, useRef } from 'react'\nimport { composeRefs } from './compose-refs.js'\nimport { useIsomorphicLayoutEffect } from './use-isomorphic-layout-effect.js'\n\nexport interface RevealProps extends RevealOptions, Omit<HTMLAttributes<HTMLElement>, 'children'> {\n  children?: ReactNode\n  /** Element to render. @default 'div' */\n  as?: ElementType\n}\n\n/**\n * Animates its children in when scrolled into view.\n *\n * The pre-animation state is rendered inline on the very first paint — including during\n * SSR — so the content never flashes at full opacity before the effect runs.\n *\n * Changing a motion option re-arms the controller with the new behavior. Cubic-bezier arrays\n * are compared by value, so an equivalent inline tuple does not restart the reveal.\n */\nexport const Reveal = forwardRef<HTMLElement, RevealProps>(function Reveal(\n  {\n    as: Tag = 'div',\n    children,\n    y,\n    x,\n    scale,\n    duration,\n    delay,\n    ease,\n    once,\n    amount,\n    margin,\n    style,\n    ...props\n  },\n  forwardedRef,\n) {\n  const ref = useRef<HTMLElement>(null)\n  const options = { y, x, scale, duration, delay, ease, once, amount, margin }\n  const easeDependency = Array.isArray(ease) ? ease.join(',') : ease\n\n  useIsomorphicLayoutEffect(() => {\n    const element = ref.current\n    if (!element) return\n    return reveal(element, options)\n  }, [Tag, amount, delay, duration, easeDependency, margin, once, scale, x, y])\n\n  return (\n    <Tag\n      {...props}\n      ref={composeRefs(ref, forwardedRef)}\n      data-kida-reveal=\"\"\n      style={{ ...revealInitialStyle(options), ...style }}\n    >\n      {children}\n    </Tag>\n  )\n})\n",
      "type": "registry:ui",
      "target": "@ui/kida/reveal.tsx"
    },
    {
      "path": "packages/react/src/compose-refs.ts",
      "content": "import type { Ref } from 'react'\n\n/** Feed one node to several refs — ours for measuring, Zag's for animation detection. */\nexport function composeRefs<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 as { current: T | null }).current = node\n    }\n  }\n}\n",
      "type": "registry:lib",
      "target": "@ui/kida/compose-refs.ts"
    },
    {
      "path": "packages/react/src/use-isomorphic-layout-effect.ts",
      "content": "'use client'\n\nimport { useEffect, useLayoutEffect } from 'react'\n\n/**\n * `useLayoutEffect` in the browser, `useEffect` on the server.\n *\n * Motion has to be applied before paint or the user sees an unstyled frame, but React\n * warns when `useLayoutEffect` runs during SSR — where it does nothing anyway.\n */\nexport const useIsomorphicLayoutEffect = typeof window !== 'undefined' ? useLayoutEffect : useEffect\n",
      "type": "registry:hook",
      "target": "@ui/kida/use-isomorphic-layout-effect.ts"
    },
    {
      "path": "packages/styles/components/reveal.css",
      "content": "/* Server markup has the initial inline state before any adapter has hydrated. */\n@media (prefers-reduced-motion: reduce) {\n  [data-kida-reveal] {\n    /* biome-ignore lint/complexity/noImportantStyles: overrides the SSR inline initial state */\n    opacity: 1 !important;\n    /* biome-ignore lint/complexity/noImportantStyles: overrides the SSR inline initial state */\n    transform: none !important;\n    /* biome-ignore lint/complexity/noImportantStyles: clears the SSR animation hint before hydration */\n    will-change: auto !important;\n  }\n}\n",
      "type": "registry:ui",
      "target": "@ui/kida/reveal.css"
    },
    {
      "path": "packages/motion/src/reveal.ts",
      "content": "import { animate, inView } from 'motion'\nimport { prefersReducedMotion } from './reduced-motion.js'\n\n/** Derived from `motion` itself, so it can't drift from the engine's own accepted values. */\ntype InViewMargin = NonNullable<Parameters<typeof inView>[2]>['margin']\n\n/** The easings we expose. Deliberately narrower than what `motion` accepts. */\nexport type RevealEase =\n  | 'linear'\n  | 'easeIn'\n  | 'easeOut'\n  | 'easeInOut'\n  | [number, number, number, number]\n  | ((t: number) => number)\n\nexport interface RevealOptions {\n  /** Vertical travel in px. Positive = starts below and rises. @default 8 */\n  y?: number\n  /** Horizontal travel in px. @default 0 */\n  x?: number\n  /** Starting scale. @default 1 */\n  scale?: number\n  /** Seconds. @default 0.5 */\n  duration?: number\n  /** Seconds. @default 0 */\n  delay?: number\n  /** @default [0.16, 1, 0.3, 1] — the same curve as `--kida-ease-out` */\n  ease?: RevealEase\n  /** Animate only the first time it enters the viewport. @default true */\n  once?: boolean\n  /** How much must be visible before firing. @default 0.3 */\n  amount?: 'some' | 'all' | number\n  /** Margin around the viewport, CSS-style. e.g. '0px 0px -10% 0px' */\n  margin?: InViewMargin\n}\n\nconst DEFAULTS = {\n  y: 8,\n  x: 0,\n  scale: 1,\n  duration: 0.5,\n  delay: 0,\n  ease: [0.16, 1, 0.3, 1],\n  once: true,\n  amount: 0.3,\n} as const\n\n/**\n * The identity of {@link revealInitialStyle}'s transform, written in the same shape.\n *\n * Animating to the keyword `none` looks right but is not: the engine has no numbers to\n * interpolate towards and commits `matrix(0, 0, 0, 0, 0, 0)`, which collapses the element\n * to 0x0. Ending on the same function list we started from keeps the interpolation\n * componentwise and the final matrix an actual identity.\n */\nconst IDENTITY_TRANSFORM = 'translate3d(0px, 0px, 0) scale(1)'\n\n/** The pre-animation state. Exported so adapters can render it on the very first paint. */\nexport function revealInitialStyle(options: RevealOptions = {}) {\n  const { y = DEFAULTS.y, x = DEFAULTS.x, scale = DEFAULTS.scale } = options\n  return {\n    opacity: 0,\n    transform: `translate3d(${x}px, ${y}px, 0) scale(${scale})`,\n    willChange: 'transform, opacity',\n  } as const\n}\n\n/**\n * Animate an element into view when it is scrolled to.\n *\n * Framework-agnostic: takes an element, returns a cleanup function. Every adapter\n * (React today, Svelte later) is a ~20-line wrapper around this.\n *\n * Under `prefers-reduced-motion: reduce` the element is put into its final state\n * immediately — visible, unanimated. It is never left hidden.\n */\nexport function reveal(element: HTMLElement, options: RevealOptions = {}): () => void {\n  const {\n    duration = DEFAULTS.duration,\n    delay = DEFAULTS.delay,\n    ease = DEFAULTS.ease,\n    once = DEFAULTS.once,\n    amount = DEFAULTS.amount,\n    margin,\n  } = options\n\n  // `transform: none` rather than an identity matrix: any transform value other than\n  // `none` makes the element a containing block for fixed-position descendants, which\n  // would silently reposition a popover rendered inside a revealed card.\n  const settle = () => {\n    element.style.opacity = '1'\n    element.style.transform = 'none'\n    element.style.willChange = 'auto'\n  }\n\n  // Own the pre-animation state, so the engine works even when the adapter didn't set it.\n  const hide = () => {\n    Object.assign(element.style, revealInitialStyle(options))\n  }\n\n  if (prefersReducedMotion()) {\n    settle()\n    return () => {}\n  }\n\n  hide()\n\n  // Bumped on every entry and every exit, so a settle scheduled by a pass that has since\n  // been superseded — or re-hidden — is dropped instead of flashing the element visible.\n  let pass = 0\n  let animation: ReturnType<typeof animate> | undefined\n  let settleFrame = 0\n\n  const cancelSettle = () => {\n    if (!settleFrame) return\n    cancelAnimationFrame(settleFrame)\n    settleFrame = 0\n  }\n\n  const stop = inView(\n    element,\n    () => {\n      cancelSettle()\n      animation?.cancel()\n      const generation = ++pass\n      const from = revealInitialStyle(options)\n      const currentAnimation = animate(\n        element,\n        // Both ends spelled out. The engine caches what it last animated an element to, so\n        // after a completed reveal it believes opacity is already 1 — and `hide()` writing\n        // the style directly is invisible to that cache. Left to infer its own start, a\n        // re-entry would resolve instantly and never animate.\n        { opacity: [from.opacity, 1], transform: [from.transform, IDENTITY_TRANSFORM] },\n        // The engine commits its own final keyframe as an inline style, one `onComplete`\n        // per animated property, and settling from inside that callback loses the race\n        // against whichever property finishes last. A frame later nothing is left to\n        // overwrite us. `onComplete` also never fires on cancel, which is what we want:\n        // an interrupted reveal must not jump to visible.\n        {\n          duration,\n          delay,\n          ease,\n          onComplete: () => {\n            cancelSettle()\n            settleFrame = requestAnimationFrame(() => {\n              settleFrame = 0\n              if (generation === pass) settle()\n            })\n          },\n        },\n      )\n      animation = currentAnimation\n\n      if (once) {\n        stop()\n        return\n      }\n\n      // `inView` runs this when the element leaves again. Without re-arming, `once: false`\n      // would replay an animation from visible to visible, which is no animation at all.\n      return () => {\n        pass++\n        cancelSettle()\n        currentAnimation.cancel()\n        if (animation === currentAnimation) animation = undefined\n        hide()\n      }\n    },\n    { amount, ...(margin ? { margin } : {}) },\n  )\n\n  return () => {\n    pass++\n    stop()\n    cancelSettle()\n    animation?.cancel()\n    animation = undefined\n  }\n}\n",
      "type": "registry:lib",
      "target": "@ui/kida/motion/reveal.ts"
    },
    {
      "path": "packages/motion/src/reduced-motion.ts",
      "content": "const QUERY = '(prefers-reduced-motion: reduce)'\n\n/**\n * Whether the user has asked for reduced motion.\n *\n * SSR-safe: returns `false` when there is no `window`, matching the CSS default\n * (the `prefers-reduced-motion` media query in `@kida-ui/styles` is the real guard;\n * this is for the JS-driven paths that CSS cannot express).\n */\nexport function prefersReducedMotion(): boolean {\n  if (typeof window === 'undefined' || typeof window.matchMedia !== 'function') return false\n  return window.matchMedia(QUERY).matches\n}\n\n/**\n * Subscribe to changes of the reduced-motion preference.\n * Returns an unsubscribe function. No-op (and immediately unsubscribable) on the server.\n */\nexport function watchReducedMotion(onChange: (reduced: boolean) => void): () => void {\n  if (typeof window === 'undefined' || typeof window.matchMedia !== 'function') return () => {}\n\n  const list = window.matchMedia(QUERY)\n  const handler = (event: MediaQueryListEvent) => onChange(event.matches)\n  list.addEventListener('change', handler)\n  return () => list.removeEventListener('change', handler)\n}\n",
      "type": "registry:lib",
      "target": "@ui/kida/motion/reduced-motion.ts"
    }
  ],
  "meta": {
    "kida": {
      "package": {
        "name": "@kida-ui/react",
        "exportName": "Reveal",
        "styleImports": [
          "@kida-ui/styles/kida.css"
        ]
      }
    }
  },
  "categories": [
    "primitives"
  ],
  "type": "registry:ui"
}
