export const getFocusableChildren = ($root) => {
  const depth = 0;
  const maxDepth = 20;
  const focusableElements = [];
  if (depth >= maxDepth) {
    return focusableElements;
  }
  const children = Array.from($root.children || []);
  for (const $child of children) {
    // skip if the elemnt is hidden
    if ($child.hasAttribute('hidden') || $child.style.display === 'none' || $child.style.visibility === 'hidden') {
      continue;
    }
    // add to the focusableElements if the element is focusable
    if ($child.tabIndex !== -1 || typeof $child.setFocus === 'function') {
      focusableElements.push($child);
    }
    // search for focusable elements in the shadow root if there is one
    if ($child.shadowRoot != null) {
      focusableElements.push(...getFocusableChildren($child.shadowRoot));
    }
    // search assigned nodes for focusable elements if the element is a slot
    else if ($child.tagName === 'SLOT') {
      focusableElements.push(...getFocusableChildrenInSlot($child));
    }
    // serch for focusable elements in the element's children
    else {
      focusableElements.push(...getFocusableChildren($child));
    }
  }
  return focusableElements;
};
const getFocusableChildrenInSlot = ($slot) => {
  const assignedNodes = $slot.assignedNodes().filter((node) => node.nodeType === 1);
  if (assignedNodes.length > 0) {
    const $slotParent = assignedNodes[0].parentElement;
    return getFocusableChildren($slotParent);
  }
  else
    return [];
};
//# sourceMappingURL=get-focusable-children.js.map