const trapFocusHandlers={};function getFocusableElements(container){return Array.from(container.querySelectorAll("summary, a[href], button:enabled, [tabindex]:not([tabindex^='-']), [draggable], area, input:not([type=hidden]):enabled, select:enabled, textarea:enabled, object, iframe"))}export function trapFocus(container){removeTrapFocus();const focusable=getFocusableElements(container);if(!focusable.length)return;const first=focusable[0],last=focusable[focusable.length-1];trapFocusHandlers.keydown=event=>{if(event.key!=="Tab")return;const activeEl=document.activeElement;!event.shiftKey&&activeEl===last?(event.preventDefault(),first?.focus()):event.shiftKey&&(activeEl===first||activeEl===container)&&(event.preventDefault(),last?.focus())},trapFocusHandlers.focusin=event=>{event.target instanceof Node&&!container.contains(event.target)&&(event.stopPropagation(),first?.focus())},document.addEventListener("keydown",trapFocusHandlers.keydown,!0),document.addEventListener("focusin",trapFocusHandlers.focusin,!0),container.focus()}export function removeTrapFocus(){trapFocusHandlers.keydown&&document.removeEventListener("keydown",trapFocusHandlers.keydown,!0),trapFocusHandlers.focusin&&document.removeEventListener("focusin",trapFocusHandlers.focusin,!0)}export function cycleFocus(items,increment){let targetIndex=items.findIndex(item=>item.matches(":focus"))+increment;targetIndex>=items.length?targetIndex=0:targetIndex<0&&(targetIndex=items.length-1);const targetItem=items[targetIndex];targetItem&&targetItem.focus()}
//# sourceMappingURL=/s/files/1/0677/1399/0759/t/1/assets/focus.js.map?v=1783078800
