import { tabbable } from 'tabbable';
export function getFocusableDescendants(selector, domElement, startIndex = 0) {
    const element = domElement ? domElement.querySelector(selector) : document.querySelector(selector);
    if (!element)
        return null;
    return getFirstAndLastFocusableDescendants(element, startIndex);
}
// A function to get the first and last tabbable elements of a container
export function getFirstAndLastFocusableDescendants(el, startIndex = 0) {
    const tabbableArray = tabbable(el, { includeContainer: true });
    if (tabbableArray.length === 0)
        return null;
    const safeStartIndex = Math.min(startIndex, tabbableArray.length - 1);
    return {
        first: tabbableArray[safeStartIndex],
        last: tabbableArray[tabbableArray.length - 1],
    };
}
//# sourceMappingURL=focusable.js.map