import{T as P,m as I,p as A,i as q,aS as Z,G as ee,h as te,$ as oe,L as y,A as m,aP as re,r as k,W as x,b6 as ae,f as ce,g as ue,o as ie,B as de,af as fe,a5 as le}from"./CPkpmJjI.js";function ke(e){return e===void 0}const g="focus-trap.focus-after-trapped",R="focus-trap.focus-after-released",ve="focus-trap.focusout-prevented",M={cancelable:!0,bubbles:!1},pe={cancelable:!0,bubbles:!1},W="focusAfterTrapped",G="focusAfterReleased",Ee=Symbol("elFocusTrap"),N=P(),L=P(0),U=P(0);let F=0;const ne=e=>{const n=[],s=document.createTreeWalker(e,NodeFilter.SHOW_ELEMENT,{acceptNode:o=>{const a=o.tagName==="INPUT"&&o.type==="hidden";return o.disabled||o.hidden||a?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(!me(s,n))return s},me=(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},Te=e=>{const n=ne(e),s=J(n,e),o=J(n.reverse(),e);return[s,o]},Fe=e=>e instanceof HTMLInputElement&&"select"in e,v=(e,n)=>{if(e&&e.focus){const s=document.activeElement;e.focus({preventScroll:!0}),U.value=window.performance.now(),e!==s&&Fe(e)&&n&&e.select()}};function Y(e,n){const s=[...e],o=e.indexOf(n);return o!==-1&&s.splice(o,1),s}const _e=()=>{let e=[];return{push:o=>{const a=e[0];a&&o!==a&&a.pause(),e=Y(e,o),e.unshift(o)},remove:o=>{var a,i;e=Y(e,o),(i=(a=e[0])==null?void 0:a.resume)==null||i.call(a)}}},be=(e,n=!1)=>{const s=document.activeElement;for(const o of e)if(v(o,n),document.activeElement!==s)return},z=_e(),ye=()=>L.value>U.value,_=()=>{N.value="pointer",L.value=window.performance.now()},Q=()=>{N.value="keyboard",L.value=window.performance.now()},Pe=()=>(I(()=>{F===0&&(document.addEventListener("mousedown",_),document.addEventListener("touchstart",_),document.addEventListener("keydown",Q)),F++}),A(()=>{F--,F<=0&&(document.removeEventListener("mousedown",_),document.removeEventListener("touchstart",_),document.removeEventListener("keydown",Q))}),{focusReason:N,lastUserFocusTimestamp:L,lastAutomatedFocusTimestamp:U}),b=e=>new CustomEvent(ve,{...pe,detail:e});let E=[];const X=e=>{e.code===Z.esc&&E.forEach(n=>n(e))},Le=e=>{I(()=>{E.length===0&&document.addEventListener("keydown",X),q&&E.push(e)}),A(()=>{E=E.filter(n=>n!==e),E.length===0&&q&&document.removeEventListener("keydown",X)})},Se=te({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=P();let o,a;const{focusReason:i}=Pe();Le(t=>{e.trapped&&!f.paused&&n("release-requested",t)});const f={paused:!1,pause(){this.paused=!0},resume(){this.paused=!1}},p=t=>{if(!e.loop&&!e.trapped||f.paused)return;const{code:r,altKey:c,ctrlKey:u,metaKey:d,currentTarget:H,shiftKey:V}=t,{loop:j}=e,se=r===Z.tab&&!c&&!u&&!d,T=document.activeElement;if(se&&T){const w=H,[C,O]=Te(w);if(C&&O){if(!V&&T===O){const l=b({focusReason:i.value});n("focusout-prevented",l),l.defaultPrevented||(t.preventDefault(),j&&v(C,!0))}else if(V&&[C,w].includes(T)){const l=b({focusReason:i.value});n("focusout-prevented",l),l.defaultPrevented||(t.preventDefault(),j&&v(O,!0))}}else if(T===w){const l=b({focusReason:i.value});n("focusout-prevented",l),l.defaultPrevented||t.preventDefault()}}};oe(Ee,{focusTrapRef:s,onKeydown:p}),y(()=>e.focusTrapEl,t=>{t&&(s.value=t)},{immediate:!0}),y([s],([t],[r])=>{t&&(t.addEventListener("keydown",p),t.addEventListener("focusin",S),t.addEventListener("focusout",h)),r&&(r.removeEventListener("keydown",p),r.removeEventListener("focusin",S),r.removeEventListener("focusout",h))});const K=t=>{n(W,t)},D=t=>n(G,t),S=t=>{const r=m(s);if(!r)return;const c=t.target,u=t.relatedTarget,d=c&&r.contains(c);e.trapped||u&&r.contains(u)||(o=u),d&&n("focusin",t),!f.paused&&e.trapped&&(d?a=c:v(a,!0))},h=t=>{const r=m(s);if(!(f.paused||!r))if(e.trapped){const c=t.relatedTarget;!re(c)&&!r.contains(c)&&setTimeout(()=>{if(!f.paused&&e.trapped){const u=b({focusReason:i.value});n("focusout-prevented",u),u.defaultPrevented||v(a,!0)}},0)}else{const c=t.target;c&&r.contains(c)||n("focusout",t)}};async function $(){await x();const t=m(s);if(t){z.push(f);const r=t.contains(document.activeElement)?o:document.activeElement;if(o=r,!t.contains(r)){const u=new Event(g,M);t.addEventListener(g,K),t.dispatchEvent(u),u.defaultPrevented||x(()=>{let d=e.focusStartEl;ae(d)||(v(d),document.activeElement!==d&&(d="first")),d==="first"&&be(ne(t),!0),(document.activeElement===r||d==="container")&&v(t)})}}}function B(){const t=m(s);if(t){t.removeEventListener(g,K);const r=new CustomEvent(R,{...M,detail:{focusReason:i.value}});t.addEventListener(R,D),t.dispatchEvent(r),!r.defaultPrevented&&(i.value=="keyboard"||!ye()||t.contains(document.activeElement))&&v(o??document.body),t.removeEventListener(R,D),z.remove(f)}}return I(()=>{e.trapped&&$(),y(()=>e.trapped,t=>{t?$():B()})}),A(()=>{e.trapped&&B(),s.value&&(s.value.removeEventListener("keydown",p),s.value.removeEventListener("focusin",S),s.value.removeEventListener("focusout",h),s.value=void 0)}),{onKeydown:p}}});function he(e,n,s,o,a,i){return k(e.$slots,"default",{handleKeydown:e.onKeydown})}var Ie=ee(Se,[["render",he],["__file","focus-trap.vue"]]);const we=ce({to:{type:ue([String,Object]),required:!0},disabled:Boolean}),Ce=te({__name:"teleport",props:we,setup(e){return(n,s)=>n.disabled?k(n.$slots,"default",{key:0}):(ie(),de(fe,{key:1,to:n.to},[k(n.$slots,"default")],8,["to"]))}});var Oe=ee(Ce,[["__file","teleport.vue"]]);const Ae=le(Oe),Ne=({from:e,replacement:n,scope:s,version:o,ref:a,type:i="API"},f)=>{y(()=>m(f),p=>{},{immediate:!0})};export{Ie as E,Ee as F,Ae as a,ke as i,Ne as u};
