/**
 * Focuses the highest level heading element in a container, or the container itself if there are no headings.
 * @param container Node to query for a heading.
 * @param label Fallback label to apply to the container if focused.
 * @returns boolean whether the focus was successful or not (eg. element is not visible).
 */
const focusHeadingOrContainer = (container, label) => {
    const heading = ['h1', 'h2', 'h3', 'h4', 'h5', 'h6'].reduce((el, tag) => el ?? container.querySelector(tag), null);
    const target = heading ?? container;
    if (!(target instanceof HTMLElement || target instanceof SVGElement))
        return false;
    if (target === container && !target.hasAttribute('aria-label') && label) {
        target.setAttribute('aria-label', label);
        target.addEventListener('focusout', () => {
            target.removeAttribute('aria-label');
        }, { once: true });
    }
    if (target.hasAttribute('tabindex')) {
        target.focus();
    }
    else {
        target.setAttribute('tabindex', '-1');
        target.focus();
        target.addEventListener('focusout', () => {
            target.removeAttribute('tabindex');
        }, { once: true });
    }
    return document.activeElement === target;
};
export default focusHeadingOrContainer;
//# sourceMappingURL=focusHeadingOrContainer.js.map