/*!
 * Custom elements for Nanopore-Digital Web applications
 */
import{g as t}from"./tabbable-BgopY-vd.js";let s=[];class i{element;tabDirection="forward";constructor(t){this.element=t,this.handleFocusIn=this.handleFocusIn.bind(this),this.handleKeyDown=this.handleKeyDown.bind(this)}activate(){s.push(this.element),document.addEventListener("focusin",this.handleFocusIn),document.addEventListener("keydown",this.handleKeyDown)}deactivate(){s=s.filter((t=>t!==this.element)),document.removeEventListener("focusin",this.handleFocusIn),document.removeEventListener("keydown",this.handleKeyDown)}isActive(){return s[s.length-1]===this.element}handleFocusIn(s){const i=s.composedPath();if(this.isActive()&&!i.includes(this.element)){const s=t(this.element),i="backward"===this.tabDirection?s.length-1:0;s[i]?.focus({preventScroll:!0})}}handleKeyDown(t){"Tab"===t.key&&t.shiftKey&&(this.tabDirection="backward",setTimeout((()=>this.tabDirection="forward")))}}export{i as M}