{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"reveal","type":"registry:ui","title":"Reveal","description":"Content that appears and disappears in place, its height growing so nothing below jumps.","dependencies":["radix-ui"],"registryDependencies":["https://dashral.com/r/utils.json","https://dashral.com/r/lib-motion.json","https://dashral.com/r/collapsible.json"],"files":[{"path":"registry/dashral/reveal.tsx","type":"registry:file","target":"components/dashral/reveal.tsx","content":"\"use client\"\n\nimport * as React from \"react\"\nimport { Collapsible as CollapsiblePrimitive } from \"radix-ui\"\n\nimport { reducedMotion } from \"./lib/motion\"\nimport { collapsibleContentClass } from \"./collapsible\"\n\ntype RevealProps = {\n  /** Shown while true: it grows in when it turns true and folds away when it turns false. Inside a RevealList, a row is shown while it's in the list. */\n  open?: boolean\n  /** The element it is: \"li\" for a row of a RevealList, \"span\" inside a line of text. */\n  as?: \"div\" | \"li\" | \"span\"\n  /** What appears: a message, a field, a hint, a row. */\n  children?: React.ReactNode\n  /** Its own id, e.g. for aria-describedby on the field it explains. */\n  id?: string\n  /** The classes of what's inside (the part that fades), e.g. its text color. */\n  className?: string\n}\n\ntype RevealListProps = Omit<React.HTMLAttributes<HTMLElement>, \"children\"> & {\n  /** The list's element. */\n  as?: \"ul\" | \"ol\" | \"div\"\n  /** Its rows: a Reveal each, as=\"li\", with a key. */\n  children?: React.ReactNode\n}\n\n/** Inside a RevealList: its rows are shown while they're in it, and arrive and leave on their own. */\nconst RevealListContext = React.createContext(false)\n\n/**\n * A list whose rows are Reveals: `<RevealList>{items.map((item) => <Reveal key={item.id} as=\"li\">…</Reveal>)}</RevealList>`.\n * Added rows grow in and removed ones fold away in the Motion edition; here they appear and go at once.\n */\nfunction RevealList({ as: Tag = \"ul\", children, ...props }: RevealListProps) {\n  return (\n    <RevealListContext.Provider value={true}>\n      <Tag data-slot=\"reveal-list\" {...props}>\n        {children}\n      </Tag>\n    </RevealListContext.Provider>\n  )\n}\n\n/**\n * The gap a Reveal brings to its parent's grid or flex column, and the neighbor whose margin takes it back while the\n * Reveal grows: the one before it (its bottom margin), or after it when it comes first (its top margin). A grid keeps\n * the gap around any item, even 0px tall, and won't let that item's own negative margin shrink its row, so the\n * neighbor's margin does it.\n */\ntype RevealGap = { neighbor: HTMLElement; side: \"marginBottom\" | \"marginTop\"; size: number }\n\nfunction revealGap(element: HTMLElement): RevealGap | null {\n  let parent = element.parentElement\n  while (parent && getComputedStyle(parent).display === \"contents\") parent = parent.parentElement\n  if (!parent) return null\n  const style = getComputedStyle(parent)\n  const column = style.display.includes(\"grid\") || (style.display.includes(\"flex\") && style.flexDirection.startsWith(\"column\"))\n  const size = column ? parseFloat(style.rowGap) || 0 : 0\n  if (!size) return null\n  // What the parent lays out: the element itself, or the contents wrapper it sits in.\n  let node: HTMLElement = element\n  while (node.parentElement && node.parentElement !== parent) node = node.parentElement\n  const before = node.previousElementSibling\n  if (before instanceof HTMLElement) return { neighbor: before, side: \"marginBottom\", size }\n  const after = node.nextElementSibling\n  return after instanceof HTMLElement ? { neighbor: after, side: \"marginTop\", size } : null\n}\n\n/**\n * Glides the neighbor's margin with the Reveal's height: from minus the gap to its own as it opens; from its own to\n * minus the gap as it closes, held there until the Reveal is gone (cancel it then, and the gap goes with it).\n */\nfunction glideRevealGap(gap: RevealGap | null, opening: boolean, timing: { duration: number; easing: string }) {\n  if (!gap) return undefined\n  const own = parseFloat(getComputedStyle(gap.neighbor)[gap.side]) || 0\n  const shut = { [gap.side]: `${own - gap.size}px` }\n  const full = { [gap.side]: `${own}px` }\n  return gap.neighbor.animate(opening ? [shut, full] : [full, shut], { ...timing, fill: opening ? \"none\" : \"forwards\" })\n}\n\n/**\n * Content that appears and disappears in place, in one tag: `<Reveal open={failed}>Couldn't reach the server.</Reveal>`.\n * Its height grows so what's below moves down smoothly instead of jumping, and it fades in as it does; in a grid or a\n * flex column, the gap it brings grows in with it. Closed, it's out of the page and of reach. For a section people open\n * themselves, with a title to click, use Collapsible.\n */\nfunction Reveal({ open: openProp, as: Tag = \"div\", children, id, className }: RevealProps) {\n  const inList = React.useContext(RevealListContext)\n  const open = openProp ?? true\n  const Inner = Tag === \"span\" ? \"span\" : \"div\"\n  // The content element, followed through a state ref: Radix sets it up a step after open first turns true.\n  const [content, setContent] = React.useState<HTMLElement | null>(null)\n  const gap = React.useRef<RevealGap | null>(null)\n  // Open from the start (or a row already in its list), it's simply there: no gap to glide in.\n  const shownAtStart = React.useRef(open)\n\n  // The gap glides with the height, on the same tokens as the height's animation.\n  React.useLayoutEffect(() => {\n    if (!content) return\n    if (open) gap.current = revealGap(content)\n    if (open && shownAtStart.current) {\n      shownAtStart.current = false\n      return\n    }\n    shownAtStart.current = false\n    if (reducedMotion() || inList) return\n    const token = (name: string) => getComputedStyle(content).getPropertyValue(name).trim()\n    const ms = (value: string) => (value.endsWith(\"ms\") ? parseFloat(value) : parseFloat(value) * 1000)\n    const glide = glideRevealGap(gap.current, open, {\n      duration: ms(token(open ? \"--duration-considered\" : \"--duration-standard\")),\n      easing: token(open ? \"--ease-standard\" : \"--ease-exit\"),\n    })\n    if (open || !glide) return () => glide?.cancel()\n    // Closed, Radix hides the content (its gap goes with it) rather than removing it: the neighbor's margin is let go\n    // in the same moment, before the next paint, so nothing jumps.\n    const hidden = new MutationObserver(() => {\n      if (content.hidden) glide.cancel()\n    })\n    hidden.observe(content, { attributes: true, attributeFilter: [\"hidden\"] })\n    return () => {\n      hidden.disconnect()\n      glide.cancel()\n    }\n  }, [open, content, inList])\n\n  // Root and Content are one element (asChild), so a row stays a direct child of its list.\n  return (\n    <CollapsiblePrimitive.Root open={open} asChild>\n      <CollapsiblePrimitive.Content ref={setContent} data-slot=\"reveal\" id={id} className={collapsibleContentClass} asChild>\n        <Tag>\n          <Inner className={className}>{children}</Inner>\n        </Tag>\n      </CollapsiblePrimitive.Content>\n    </CollapsiblePrimitive.Root>\n  )\n}\n\nexport { Reveal, RevealList, RevealListContext, revealGap, glideRevealGap, type RevealProps, type RevealListProps, type RevealGap }\n"}],"cssVars":{"theme":{"ease-standard":"var(--ease-standard)","ease-enter":"var(--ease-enter)","ease-exit":"var(--ease-exit)","ease-spring":"var(--ease-spring)"},"light":{"duration-fast":"160ms","duration-standard":"240ms","duration-considered":"480ms","ease-standard":"cubic-bezier(0.2, 0, 0, 1)","ease-enter":"cubic-bezier(0, 0, 0, 1)","ease-exit":"cubic-bezier(0.3, 0, 1, 1)","ease-spring":"linear(0, 0.071 4%, 0.234 8%, 0.433 12%, 0.626 17%, 0.791 21%, 0.917 25%, 1.004 29%, 1.055 33%, 1.079 38%, 1.083 42%, 1.075 46%, 1.06 50%, 1.043 54%, 1.027 58%, 1.015 62%, 1.005 67%, 0.998 71%, 0.995 75%, 0.993 79%, 0.993 83%, 0.994 88%, 0.995 92%, 0.997 96%, 1)"},"dark":{}}}