function attemptFocus(node) {
  try {
    node.focus();
  } catch (exception) {
    return false;
  }

  return document.activeElement === node;
}

function isElement(node) {
  return (node === null || node === void 0 ? void 0 : node.children) !== undefined;
}

export function isHTMLElement(node) {
  return (node === null || node === void 0 ? void 0 : node.focus) !== undefined;
}
export var focusOnFirstDescendent = function focusOnFirstDescendent(node) {
  if (isHTMLElement(node) && attemptFocus(node)) {
    return true;
  }

  return isElement(node) && Array.from(node.children).some(function (childNode) {
    return focusOnFirstDescendent(childNode);
  });
};
export var focusOnLastDescendent = function focusOnLastDescendent(node) {
  if (isHTMLElement(node) && attemptFocus(node)) {
    return true;
  }

  return isElement(node) && Array.from(node.children).reverse().some(function (childNode) {
    return focusOnLastDescendent(childNode);
  });
};