import { k as useState, u as useMemo } from './dom-context-hooks.module-50442785.js';
import { _ } from './index.module-b23fdad8.js';

function useChildElements() {
  const host = _();
  const initialState = host.children.length
    ? Array.from(host.children)
    : [];
  const [childElements, setChildElements] = useState(initialState);
  let observer;
  // Create observer once
  useMemo(() => {
    observer = new MutationObserver(() => {
      const children = Array.from(host.children);
      setChildElements([...children]);
    });
  }, []);
  // Listen to host and observe / disconnect
  useMemo(() => {
    if (!observer)
      return;
    observer.observe(host, { childList: true });
    return () => {
      observer.disconnect();
    };
  }, [host]);
  return childElements;
}

export { useChildElements as u };
