function _instanceof(left, right) {
    if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
        return !!right[Symbol.hasInstance](left);
    } else {
        return left instanceof right;
    }
}
var tabbableNode = /input|select|textarea|button|object/;
export var focusSelector = [
    'input',
    'select',
    'textarea',
    'a',
    'button',
    'object',
    '[tabindex]',
    'audio[controls]',
    'video[controls]',
    '[contenteditable]:not([contenteditable="false"])'
].join(',');
var isHidden = function isHidden(el) {
    return el.offsetWidth <= 0 && el.offsetHeight <= 0 || el.style.display === 'none' || el.style.visibility === 'hidden' || el.style.opacity === '0';
};
export var isVisible = function isVisible(element, parentContainer) {
    var parentElement = element;
    while(parentElement){
        if (parentElement === parentContainer || parentElement === document.body) {
            break;
        }
        if (isHidden(parentElement)) {
            return false;
        }
        parentElement = parentElement.parentNode;
    }
    return true;
};
var getElementTabIndex = function getElementTabIndex(element) {
    var tabIndex = element.getAttribute('tabindex');
    return tabIndex === null ? NaN : parseInt(tabIndex, 10);
};
export var isFocusable = function isFocusable(element, parentContainer) {
    var nodeName = element.nodeName.toLowerCase();
    var isTabIndexNotNaN = !Number.isNaN(getElementTabIndex(element));
    var res = tabbableNode.test(nodeName) && !element.disabled || (_instanceof(element, HTMLAnchorElement) ? element.href || isTabIndexNotNaN : isTabIndexNotNaN);
    return Boolean(res) && isVisible(element, parentContainer);
};
export var isTabble = function isTabble(element, parentContainer) {
    var tabIndex = getElementTabIndex(element);
    var isTabIndexNaN = Number.isNaN(tabIndex);
    return (isTabIndexNaN || tabIndex >= 0) && isFocusable(element, parentContainer);
};
// Все элементы внутри данной ноды, до которых можно добраться табом
export var findTabbableDescendants = function findTabbableDescendants(element) {
    return Array.from(element.querySelectorAll(focusSelector)).filter(function(el) {
        return isTabble(el, element);
    });
};
