import{q as te,b3 as ne,at as se,b4 as oe,b5 as ae,b6 as ce,b7 as re,af as ue,e as o,am as m,g as r,j as y,d as ie,y as de,x as w,u as t,ae as fe,b as le,i as $,m as ve}from"./et3mnfcx.js";import{d as pe,_ as ee}from"./xqb8qclc.js";import{a as x}from"./bijlrpmo.js";function ne(e){return e===void 0}const ae=pe([string,object,function]),ue={close:ue},ke={success:oe,warning:ae,error:ce,info:re},de={validating:te,success:ne,error:se};let p=[];const j=e=>{const n=e;n.key===x.esc&&p.foreach(s=>s(n))},me=e=>{o(()=>{p.length===0&&document.addeventlistener("keydown",j),m&&p.push(e)}),r(()=>{p=p.filter(n=>n!==e),p.length===0&&m&&document.removeeventlistener("keydown",j)})},l="focus-trap.focus-after-trapped",h="focus-trap.focus-after-released",te="focus-trap.focusout-prevented",q={cancelable:!0,bubbles:!1},_e={cancelable:!0,bubbles:!1},w="focusaftertrapped",g="focusafterreleased",fe=symbol("elfocustrap"),k=y(),c=y(0),i=y(0);let _=0;const z=e=>{const n=[],s=document.createtreewalker(e,nodefilter.show_element,{acceptnode:o=>{const c=o.tagname==="input"&&o.type==="hidden";return o.disabled||o.hidden||c?nodefilter.filter_skip:o.tabindex>=0||o===document.activeelement?nodefilter.filter_accept:nodefilter.filter_skip}});for(;s.nextnode();)n.push(s.currentnode);return n},j=(e,n)=>{for(const s of e)if(!be(s,n))return s},be=(e,n)=>{if(getcomputedstyle(e).visibility==="hidden")return!0;for(;e;){if(n&&e===n)return!1;if(getcomputedstyle(e).display==="none")return!0;e=e.parentelement}return!1},ye=e=>{const n=z(e),s=j(n,e),o=j(n.reverse(),e);return[s,o]},ce=e=>e instanceof htmlinputelement&&"select"in e,l=(e,n)=>{if(e&&e.focus){const s=document.activeelement;e.focus({preventscroll:!0}),i.value=window.performance.now(),e!==s&&ce(e)&&n&&e.select()}};function q(e,n){const s=[...e],o=e.indexof(n);return o!==-1&&s.splice(o,1),s}const pe=()=>{let e=[];return{push:o=>{const c=e[0];c&&o!==c&&c.pause(),e=q(e,o),e.unshift(o)},remove:o=>{var c,d;e=q(e,o),(d=(c=e[0])==null?void 0:c.resume)==null||d.call(c)}}},se=(e,n=!1)=>{const s=document.activeelement;for(const o of e)if(l(o,n),document.activeelement!==s)return},y=pe(),ge=()=>c.value>i.value,f=()=>{k.value="pointer",c.value=window.performance.now()},z=()=>{k.value="keyboard",c.value=window.performance.now()},we=()=>(o(()=>{_===0&&(document.addeventlistener("mousedown",f),document.addeventlistener("touchstart",f),document.addeventlistener("keydown",z)),_++}),r(()=>{_--,_<=0&&(document.removeeventlistener("mousedown",f),document.removeeventlistener("touchstart",f),document.removeeventlistener("keydown",z))}),{focusreason:k,lastuserfocustimestamp:c,lastautomatedfocustimestamp:i}),b=e=>new customevent(te,{..._e,detail:e}),le=ie({name:"elfocustrap",inheritattrs:!1,props:{loop:boolean,trapped:boolean,focustrapel:object,focusstartel:{type:[object,string],default:"first"}},emits:[w,g,"focusin","focusout","focusout-prevented","release-requested"],setup(e,{emit:n}){const s=y();let o,c;const{focusreason:d}=we();me(t=>{e.trapped&&!v.paused&&n("release-requested",t)});const v={paused:!1,pause(){this.paused=!0},resume(){this.paused=!1}},e=t=>{if(!e.loop&&!e.trapped||v.paused)return;const{key:a,altkey:r,ctrlkey:u,metakey:i,currenttarget:x,shiftkey:b}=t,{loop:h}=e,ee=a===x.tab&&!r&&!u&&!i,m=document.activeelement;if(ee&&m){const p=x,[s,g]=ye(p);if(s&&g){if(!b&&m===g){const f=b({focusreason:d.value});n("focusout-prevented",f),f.defaultprevented||(t.preventdefault(),h&&l(s,!0))}else if(b&&[s,p].includes(m)){const f=b({focusreason:d.value});n("focusout-prevented",f),f.defaultprevented||(t.preventdefault(),h&&l(g,!0))}}else if(m===p){const f=b({focusreason:d.value});n("focusout-prevented",f),f.defaultprevented||t.preventdefault()}}};de(fe,{focustrapref:s,onkeydown:e}),w(()=>e.focustrapel,t=>{t&&(s.value=t)},{immediate:!0}),w([s],([t],[a])=>{t&&(t.addeventlistener("keydown",e),t.addeventlistener("focusin",u),t.addeventlistener("focusout",k)),a&&(a.removeeventlistener("keydown",e),a.removeeventlistener("focusin",u),a.removeeventlistener("focusout",k))});const n=t=>{n(w,t)},a=t=>n(g,t),u=t=>{const a=t(s);if(!a)return;const r=t.target,u=t.relatedtarget,i=r&&a.contains(r);e.trapped||u&&a.contains(u)||(o=u),i&&n("focusin",t),!v.paused&&e.trapped&&(i?c=r:l(c,!0))},k=t=>{const a=t(s);if(!(v.paused||!a))if(e.trapped){const r=t.relatedtarget;!fe(r)&&!a.contains(r)&&settimeout(()=>{if(!v.paused&&e.trapped){const u=b({focusreason:d.value});n("focusout-prevented",u),u.defaultprevented||l(c,!0)}},0)}else{const r=t.target;r&&a.contains(r)||n("focusout",t)}};async function d(){await $();const t=t(s);if(t){y.push(v);const a=t.contains(document.activeelement)?o:document.activeelement;if(o=a,!t.contains(a)){const u=new event(l,q);t.addeventlistener(l,n),t.dispatchevent(u),u.defaultprevented||$(()=>{let i=e.focusstartel;ve(i)||(l(i),document.activeelement!==i&&(i="first")),i==="first"&&se(z(t),!0),(document.activeelement===a||i==="container")&&l(t)})}}}function v(){const t=t(s);if(t){t.removeeventlistener(l,n);const a=new customevent(h,{...q,detail:{focusreason:d.value}});t.addeventlistener(h,a),t.dispatchevent(a),!a.defaultprevented&&(d.value=="keyboard"||!ge()||t.contains(document.activeelement))&&l(o??document.body),t.removeeventlistener(h,a),y.remove(v)}}return o(()=>{e.trapped&&d(),w(()=>e.trapped,t=>{t?d():v()})}),r(()=>{e.trapped&&v()}),{onkeydown:e}}});function he(e,n,s,o,c,d){return le(e.$slots,"default",{handlekeydown:e.onkeydown})}var ve=ee(le,[["render",he],["__file","focus-trap.vue"]]);export{ue as c,ve as e,ke as t,de as v,ne as a,ae as i};