function e(e){return e==="Enter"||e===" "||e==="Spacebar"}const t=["a[href]","button:not([disabled])","textarea:not([disabled])","input:not([disabled])","select:not([disabled])",'[tabindex]:not([tabindex="-1"])','[contenteditable="true"]'].join(",");function n(e){return Array.from(e.querySelectorAll(t)).filter((e=>e.getAttribute("aria-hidden")!=="true"&&e.style.display!=="none"))}function r(e){const{container:t,autoFocus:r=true,returnFocusTo:o}=e;let a=false;let c=null;const i=e=>{if(e.key!=="Tab")return;const r=n(t);if(r.length===0){e.preventDefault();t.focus();return}const o=r[0];const a=r[r.length-1];const c=document.activeElement;if(e.shiftKey){if(c===o||!t.contains(c)){e.preventDefault();a.focus()}}else{if(c===a){e.preventDefault();o.focus()}}};const s=()=>{if(a)return;a=true;c=o??document.activeElement;t.addEventListener("keydown",i);if(r){const e=n(t);(e[0]??t).focus()}};const u=()=>{if(!a)return;a=false;t.removeEventListener("keydown",i);if(c&&typeof c.focus==="function"){c.focus()}c=null};return{connect:s,disconnect:u}}function o(e,t){const{activeIndex:n,itemCount:r,loop:o=true}=t;if(r<=0)return{type:"none"};const a=e=>(e+r)%r;const c=e=>Math.max(0,Math.min(e,r-1));switch(e.key){case"ArrowDown":case"ArrowRight":return{type:"navigate",index:o?a(n+1):c(n+1)};case"ArrowUp":case"ArrowLeft":return{type:"navigate",index:o?a(n-1):c(n-1)};case"Home":return{type:"navigate",index:0};case"End":return{type:"navigate",index:r-1};case"Enter":case" ":case"Spacebar":return n>=0?{type:"select",index:n}:{type:"none"};case"Escape":return{type:"close"};default:return{type:"none"}}}export{r as c,o as h,e as i};
//# sourceMappingURL=p-cc0aeb50.js.map