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