{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "refs",
  "title": "Refs",
  "description": "One ref for several, so a part can measure its own element and still hand it to a ref of yours, and a ref that marks an element mounted once it has painted, so an entrance never plays on page load.",
  "dependencies": [],
  "files": [
    {
      "path": "registry/lib/refs.ts",
      "content": "import type { Ref, RefCallback } from 'react'\n\n/**\n * One ref callback that sets every ref given, so a part can measure its own\n * element and still pass it to a ref of the caller's. Each ref's cleanup, a\n * callback's own or the null an object ref is set back to, runs when the\n * element goes.\n */\nexport function mergeRefs<T>(...refs: (Ref<T> | undefined)[]): RefCallback<T> {\n  return (node) => {\n    const cleanups = refs.map((ref) => {\n      if (typeof ref === 'function') {\n        const cleanup = ref(node)\n        return typeof cleanup === 'function' ? cleanup : () => ref(null)\n      }\n      if (ref) {\n        ref.current = node\n        return () => {\n          ref.current = null\n        }\n      }\n      return undefined\n    })\n    return () => {\n      for (const cleanup of cleanups) cleanup?.()\n    }\n  }\n}\n\n/**\n * Marks an element as mounted a frame after it first paints, so `data-mounted:`\n * can hold back entrances that would otherwise play on page load.\n */\nexport function markMounted(node: HTMLElement | null) {\n  if (!node) return undefined\n  const frame = requestAnimationFrame(() => {\n    node.dataset.mounted = ''\n  })\n  return () => cancelAnimationFrame(frame)\n}\n\n/**\n * Styles the document now, so what was just set is where a transition starts\n * from, or the look an element is painted with before it moves. Returns the\n * style it read, which no caller needs.\n */\nexport function commitStyles(el: Element) {\n  return getComputedStyle(el).transitionProperty\n}\n",
      "type": "registry:lib",
      "target": "@lib/refs.ts"
    }
  ],
  "type": "registry:lib"
}