{
  "$schema": "https://shadcn-vue.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": "registry/vue/kida/reveal.vue",
      "content": "<script setup lang=\"ts\">\nimport './reveal.css'\nimport { reveal, revealInitialStyle } from './reveal.motion.js'\nimport { type StyleValue, shallowRef, watch } from 'vue'\nimport type { RevealProps } from './reveal.types.js'\n\ndefineOptions({ name: 'KidaReveal', inheritAttrs: false })\n// Vue casts an absent Boolean prop to false. Keep omission undefined so the shared core's\n// once=true default applies while an explicit :once=\"false\" still requests repetition.\nconst props = withDefaults(defineProps<RevealProps>(), { once: undefined })\nconst element = shallowRef<HTMLElement | null>(null)\ndefineExpose({ element })\n\nwatch(\n  [\n    () => element.value,\n    () => props.as,\n    () => props.x,\n    () => props.y,\n    () => props.scale,\n    () => props.duration,\n    () => props.delay,\n    () => (Array.isArray(props.ease) ? props.ease.join(',') : props.ease),\n    () => props.once,\n    () => props.amount,\n    () => props.margin,\n  ],\n  (_, __, onCleanup) => {\n    if (element.value) onCleanup(reveal(element.value, { ...props }))\n  },\n  { flush: 'post' },\n)\n\nfunction motionStyle() {\n  // Vue patches every bound style on updates. Preserve the controller's current inline state\n  // so changing slot content, classes, or an equivalent easing tuple cannot re-hide a reveal.\n  const node = element.value\n  return node\n    ? {\n        opacity: node.style.opacity,\n        transform: node.style.transform,\n        willChange: node.style.willChange,\n      }\n    : revealInitialStyle(props)\n}\n</script>\n\n<template>\n  <component\n    :is=\"props.as ?? 'div'\"\n    v-bind=\"$attrs\"\n    ref=\"element\"\n    data-kida-reveal=\"\"\n    :style=\"[motionStyle(), $attrs.style as StyleValue]\"\n  >\n    <slot />\n  </component>\n</template>\n",
      "type": "registry:ui"
    },
    {
      "path": "registry/vue/kida/reveal.types.ts",
      "content": "import type { RevealOptions } from './reveal.motion.js';\n\nexport type RevealEase = NonNullable<RevealOptions['ease']>;\n\nexport interface RevealProps extends RevealOptions {\n    /** Semantic HTML root. @default 'div' */\n    as?: keyof HTMLElementTagNameMap;\n}\n\n/** Vue component refs expose the root DOM element, null when presence removes it. */\nexport interface KidaElement {\n    element: HTMLElement | null;\n}\n",
      "type": "registry:ui"
    },
    {
      "path": "registry/vue/kida/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"
    },
    {
      "path": "registry/vue/kida/reveal.motion.ts",
      "content": "import { animate, inView } from 'motion'\nimport { prefersReducedMotion } from './reduced-motion.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:ui"
    },
    {
      "path": "registry/vue/kida/reduced-motion.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:ui"
    }
  ],
  "meta": {
    "kida": {
      "package": {
        "name": "@kida-ui/vue",
        "exportName": "Reveal",
        "styleImports": [
          "@kida-ui/styles/kida.css"
        ]
      },
      "framework": "vue"
    }
  },
  "categories": [
    "primitives"
  ],
  "type": "registry:ui"
}
